demux: merge sh_video/sh_audio/sh_sub

This is mainly a refactor. I'm hoping it will make some things easier
in the future due to cleanly separating codec metadata and stream
metadata.

Also, declare that the "codec" field can not be NULL anymore. demux.c
will set it to "" if it's NULL when added. This gets rid of a corner
case everything had to handle, but which rarely happened.
This commit is contained in:
wm4
2016-01-12 23:48:19 +01:00
parent 81f3b3aafe
commit 671df54e4d
24 changed files with 232 additions and 247 deletions

View File

@@ -79,12 +79,12 @@ static int init(struct dec_audio *da, const char *decoder)
AVCodecContext *lavc_context;
AVCodec *lavc_codec;
struct sh_stream *sh = da->header;
struct sh_audio *sh_audio = sh->audio;
struct mp_codec_params *c = sh->codec;
struct priv *ctx = talloc_zero(NULL, struct priv);
da->priv = ctx;
ctx->force_channel_map = sh_audio->force_channels;
ctx->force_channel_map = c->force_channels;
lavc_codec = avcodec_find_decoder_by_name(decoder);
if (!lavc_codec) {
@@ -116,20 +116,20 @@ static int init(struct dec_audio *da, const char *decoder)
mp_set_avopts(da->log, lavc_context, opts->avopts);
lavc_context->codec_tag = sh->codec_tag;
lavc_context->sample_rate = sh_audio->samplerate;
lavc_context->bit_rate = sh_audio->bitrate;
lavc_context->block_align = sh_audio->block_align;
lavc_context->bits_per_coded_sample = sh_audio->bits_per_coded_sample;
lavc_context->channels = sh_audio->channels.num;
if (!mp_chmap_is_unknown(&sh_audio->channels))
lavc_context->channel_layout = mp_chmap_to_lavc(&sh_audio->channels);
lavc_context->codec_tag = c->codec_tag;
lavc_context->sample_rate = c->samplerate;
lavc_context->bit_rate = c->bitrate;
lavc_context->block_align = c->block_align;
lavc_context->bits_per_coded_sample = c->bits_per_coded_sample;
lavc_context->channels = c->channels.num;
if (!mp_chmap_is_unknown(&c->channels))
lavc_context->channel_layout = mp_chmap_to_lavc(&c->channels);
// demux_mkv
mp_lavc_set_extradata(lavc_context, sh->extradata, sh->extradata_size);
mp_lavc_set_extradata(lavc_context, c->extradata, c->extradata_size);
if (sh->lav_headers)
mp_copy_lav_codec_headers(lavc_context, sh->lav_headers);
if (c->lav_headers)
mp_copy_lav_codec_headers(lavc_context, c->lav_headers);
mp_set_avcodec_threads(da->log, lavc_context, opts->threads);
@@ -228,9 +228,8 @@ static int decode_packet(struct dec_audio *da, struct mp_audio **out)
if (lavc_chmap.num != avctx->channels)
mp_chmap_from_channels(&lavc_chmap, avctx->channels);
if (priv->force_channel_map) {
struct sh_audio *sh_audio = da->header->audio;
if (lavc_chmap.num == sh_audio->channels.num)
lavc_chmap = sh_audio->channels;
if (lavc_chmap.num == da->header->codec->channels.num)
lavc_chmap = da->header->codec->channels;
}
mp_audio_set_channels(mpframe, &lavc_chmap);

View File

@@ -88,7 +88,7 @@ struct mp_decoder_list *audio_decoder_list(void)
static struct mp_decoder_list *audio_select_decoders(struct dec_audio *d_audio)
{
struct MPOpts *opts = d_audio->opts;
const char *codec = d_audio->header->codec;
const char *codec = d_audio->header->codec->codec;
struct mp_decoder_list *list = audio_decoder_list();
struct mp_decoder_list *new =
@@ -146,7 +146,7 @@ int audio_init_best_codec(struct dec_audio *d_audio)
MP_VERBOSE(d_audio, "Selected audio codec: %s\n", d_audio->decoder_desc);
} else {
MP_ERR(d_audio, "Failed to initialize an audio decoder for codec '%s'.\n",
d_audio->header->codec ? d_audio->header->codec : "<unknown>");
d_audio->header->codec->codec);
}
talloc_free(list);