core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 14:15:19 +00:00
|
|
|
/*
|
|
|
|
* This file is part of mpv.
|
|
|
|
*
|
|
|
|
* mpv is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* mpv is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with mpv. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
2013-02-14 13:02:47 +00:00
|
|
|
#include <libavutil/common.h>
|
|
|
|
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 14:15:19 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "core/mp_talloc.h"
|
|
|
|
#include "av_common.h"
|
|
|
|
#include "codecs.h"
|
|
|
|
|
|
|
|
|
demux_lavf, ad_lavc, vd_lavc: pass codec header data directly
Instead of putting codec header data into WAVEFORMATEX and
BITMAPINFOHEADER, pass it directly via AVCodecContext. To do this, we
add mp_copy_lav_codec_headers(), which copies the codec header data
from one AVCodecContext to another (originally, the plan was to use
avcodec_copy_context() for this, but it looks like this would turn
decoder initialization into an even worse mess).
Get rid of the silly CodecID <-> codec_tag mapping. This was originally
needed for codecs.conf: codec tags were used to identify codecs, but
libavformat didn't always return useful codec tags (different file
formats can have different, overlapping tag numbers). Since we don't
go through WAVEFORMATEX etc. and pass all header data directly via
AVCodecContext, we can be absolutely sure that the codec tag mapping is
not needed anymore.
Note that this also destroys the "standard" MPlayer method of exporting
codec header data. WAVEFORMATEX and BITMAPINFOHEADER made sure that
other non-libavcodec decoders could be initialized. However, all these
decoders have been removed, so this is just cruft full of old hacks that
are not needed anymore. There's still ad_spdif and ad_mpg123, bu neither
of these need codec header data. Should we ever add non-libavcodec
decoders, better data structures without the past hacks could be added
to export the headers.
2013-02-09 14:15:37 +00:00
|
|
|
// Copy the codec-related fields from st into avctx. This does not set the
|
|
|
|
// codec itself, only codec related header data provided by libavformat.
|
|
|
|
// The goal is to initialize a new decoder with the header data provided by
|
|
|
|
// libavformat, and unlike avcodec_copy_context(), allow the user to create
|
|
|
|
// a clean AVCodecContext for a manually selected AVCodec.
|
|
|
|
// This is strictly for decoding only.
|
|
|
|
void mp_copy_lav_codec_headers(AVCodecContext *avctx, AVCodecContext *st)
|
|
|
|
{
|
|
|
|
if (st->extradata_size) {
|
|
|
|
av_free(avctx->extradata);
|
|
|
|
avctx->extradata_size = 0;
|
|
|
|
avctx->extradata =
|
|
|
|
av_mallocz(st->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
|
|
|
|
if (avctx->extradata) {
|
|
|
|
avctx->extradata_size = st->extradata_size;
|
|
|
|
memcpy(avctx->extradata, st->extradata, st->extradata_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
avctx->codec_tag = st->codec_tag;
|
|
|
|
avctx->stream_codec_tag = st->stream_codec_tag;
|
|
|
|
avctx->bit_rate = st->bit_rate;
|
|
|
|
avctx->width = st->width;
|
|
|
|
avctx->height = st->height;
|
|
|
|
avctx->pix_fmt = st->pix_fmt;
|
|
|
|
avctx->sample_aspect_ratio = st->sample_aspect_ratio;
|
|
|
|
avctx->chroma_sample_location = st->chroma_sample_location;
|
|
|
|
avctx->sample_rate = st->sample_rate;
|
|
|
|
avctx->channels = st->channels;
|
|
|
|
avctx->block_align = st->block_align;
|
|
|
|
avctx->channel_layout = st->channel_layout;
|
|
|
|
avctx->audio_service_type = st->audio_service_type;
|
|
|
|
avctx->bits_per_coded_sample = st->bits_per_coded_sample;
|
|
|
|
}
|
|
|
|
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 14:15:19 +00:00
|
|
|
#if !HAVE_AVCODEC_IS_DECODER_API
|
|
|
|
static int av_codec_is_decoder(AVCodec *codec)
|
|
|
|
{
|
|
|
|
return !!codec->decode;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void mp_add_lavc_decoders(struct mp_decoder_list *list, enum AVMediaType type)
|
|
|
|
{
|
|
|
|
AVCodec *cur = NULL;
|
|
|
|
for (;;) {
|
|
|
|
cur = av_codec_next(cur);
|
|
|
|
if (!cur)
|
|
|
|
break;
|
|
|
|
if (av_codec_is_decoder(cur) && cur->type == type) {
|
|
|
|
struct mp_decoder_entry entry = {
|
|
|
|
.family = "lavc",
|
|
|
|
.codec = mp_codec_from_av_codec_id(cur->id),
|
|
|
|
.decoder = cur->name,
|
|
|
|
.desc = cur->long_name,
|
|
|
|
};
|
|
|
|
assert(entry.family);
|
|
|
|
MP_TARRAY_APPEND(list, list->entries, list->num_entries, entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if HAVE_AVCODEC_CODEC_DESC_API
|
|
|
|
|
|
|
|
int mp_codec_to_av_codec_id(const char *codec)
|
|
|
|
{
|
|
|
|
|
|
|
|
const AVCodecDescriptor *desc = avcodec_descriptor_get_by_name(codec);
|
|
|
|
return desc ? desc->id : CODEC_ID_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *mp_codec_from_av_codec_id(int codec_id)
|
|
|
|
{
|
|
|
|
const AVCodecDescriptor *desc = avcodec_descriptor_get(codec_id);
|
|
|
|
return desc ? desc->name : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
struct mp_av_codec {
|
|
|
|
const char *name;
|
|
|
|
int codec_id;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Some decoders have a different name from the canonical codec name, for
|
|
|
|
// example the codec "dts" CODEC_ID_DTS has the decoder named "dca", and
|
|
|
|
// avcodec_find_decoder_by_name("dts") would return 0. We always want the
|
|
|
|
// canonical name.
|
|
|
|
// On newer lavc versions, avcodec_descriptor_get_by_name("dts") will return
|
|
|
|
// CODEC_ID_DTS, which is what we want, but for older versions we need this
|
|
|
|
// lookup table.
|
|
|
|
struct mp_av_codec mp_av_codec_id_list[] = {
|
|
|
|
{"ra_144", CODEC_ID_RA_144},
|
|
|
|
{"ra_288", CODEC_ID_RA_288},
|
|
|
|
{"smackaudio", CODEC_ID_SMACKAUDIO},
|
|
|
|
{"dts", CODEC_ID_DTS},
|
|
|
|
{"musepack7", CODEC_ID_MUSEPACK7},
|
|
|
|
{"musepack8", CODEC_ID_MUSEPACK8},
|
|
|
|
{"amr_nb", CODEC_ID_AMR_NB},
|
|
|
|
{"amr_wb", CODEC_ID_AMR_WB},
|
|
|
|
{"adpcm_g722", CODEC_ID_ADPCM_G722},
|
|
|
|
{"adpcm_g726", CODEC_ID_ADPCM_G726},
|
|
|
|
{"westwood_snd1", CODEC_ID_WESTWOOD_SND1},
|
|
|
|
{"mp4als", CODEC_ID_MP4ALS},
|
|
|
|
{"vixl", CODEC_ID_VIXL},
|
|
|
|
{"flv1", CODEC_ID_FLV1},
|
|
|
|
{"msmpeg4v3", CODEC_ID_MSMPEG4V3},
|
|
|
|
{"jpeg2000", CODEC_ID_JPEG2000},
|
|
|
|
{"ulti", CODEC_ID_ULTI},
|
|
|
|
{"smackvideo", CODEC_ID_SMACKVIDEO},
|
|
|
|
{"tscc", CODEC_ID_TSCC},
|
|
|
|
{"cscd", CODEC_ID_CSCD},
|
|
|
|
{"tgv", CODEC_ID_TGV},
|
|
|
|
{"roq", CODEC_ID_ROQ},
|
|
|
|
{"idcin", CODEC_ID_IDCIN},
|
|
|
|
{"ws_vqa", CODEC_ID_WS_VQA},
|
|
|
|
{0},
|
|
|
|
};
|
|
|
|
|
|
|
|
int mp_codec_to_av_codec_id(const char *codec)
|
|
|
|
{
|
|
|
|
for (int n = 0; mp_av_codec_id_list[n].name; n++) {
|
|
|
|
if (strcmp(mp_av_codec_id_list[n].name, codec) == 0)
|
|
|
|
return mp_av_codec_id_list[n].codec_id;
|
|
|
|
}
|
|
|
|
AVCodec *avcodec = avcodec_find_decoder_by_name(codec);
|
|
|
|
return avcodec ? avcodec->id : CODEC_ID_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *mp_codec_from_av_codec_id(int codec_id)
|
|
|
|
{
|
|
|
|
for (int n = 0; mp_av_codec_id_list[n].name; n++) {
|
|
|
|
if (mp_av_codec_id_list[n].codec_id == codec_id)
|
|
|
|
return mp_av_codec_id_list[n].name;
|
|
|
|
}
|
|
|
|
AVCodec *avcodec = avcodec_find_decoder(codec_id);
|
|
|
|
return avcodec ? avcodec->name : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|