From cb0b0d99a4ab04905f59ec1a9fcbf90635105d11 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 3 Nov 2012 14:06:53 +0100 Subject: ad_lavc: use fmt-conversion to map sample formats --- audio/decode/ad_lavc.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) (limited to 'audio/decode/ad_lavc.c') diff --git a/audio/decode/ad_lavc.c b/audio/decode/ad_lavc.c index 382d4eacc5..b7dec6bc71 100644 --- a/audio/decode/ad_lavc.c +++ b/audio/decode/ad_lavc.c @@ -35,6 +35,7 @@ #include "ad_internal.h" #include "audio/reorder_ch.h" +#include "audio/fmt-conversion.h" #include "compat/mpbswap.h" #include "compat/libav.h" @@ -144,17 +145,8 @@ static int preinit(sh_audio_t *sh) static int setup_format(sh_audio_t *sh_audio, const AVCodecContext *lavc_context) { - int sample_format = sh_audio->sample_format; - switch (av_get_packed_sample_fmt(lavc_context->sample_fmt)) { - case AV_SAMPLE_FMT_U8: sample_format = AF_FORMAT_U8; break; - case AV_SAMPLE_FMT_S16: sample_format = AF_FORMAT_S16_NE; break; - case AV_SAMPLE_FMT_S32: sample_format = AF_FORMAT_S32_NE; break; - case AV_SAMPLE_FMT_FLT: sample_format = AF_FORMAT_FLOAT_NE; break; - default: - mp_msg(MSGT_DECAUDIO, MSGL_FATAL, "Unsupported sample format\n"); - sample_format = AF_FORMAT_UNKNOWN; - } - + int sample_format = + af_from_avformat(av_get_packed_sample_fmt(lavc_context->sample_fmt)); bool broken_srate = false; int samplerate = lavc_context->sample_rate; int container_samplerate = sh_audio->container_out_samplerate; @@ -279,13 +271,9 @@ static int init(sh_audio_t *sh_audio, const char *decoder) if (sh_audio->wf && sh_audio->wf->nAvgBytesPerSec) sh_audio->i_bps = sh_audio->wf->nAvgBytesPerSec; - switch (av_get_packed_sample_fmt(lavc_context->sample_fmt)) { - case AV_SAMPLE_FMT_U8: - case AV_SAMPLE_FMT_S16: - case AV_SAMPLE_FMT_S32: - case AV_SAMPLE_FMT_FLT: - break; - default: + int af_sample_fmt = + af_from_avformat(av_get_packed_sample_fmt(lavc_context->sample_fmt)); + if (af_sample_fmt == AF_FORMAT_UNKNOWN) { uninit(sh_audio); return 0; } -- cgit v1.2.3 From 071a8f50b96758ced05e1eef3aba5ce915a56479 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 31 Mar 2013 04:24:53 +0200 Subject: options: add option to prevent decoder audio downmixing Also rename --a52drc to --ad-lavc-ac3drc, and add --ad-lavc-o. --- audio/decode/ad_lavc.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'audio/decode/ad_lavc.c') diff --git a/audio/decode/ad_lavc.c b/audio/decode/ad_lavc.c index b7dec6bc71..5c43c68d8a 100644 --- a/audio/decode/ad_lavc.c +++ b/audio/decode/ad_lavc.c @@ -32,6 +32,7 @@ #include "core/codecs.h" #include "core/mp_msg.h" #include "core/options.h" +#include "core/av_opts.h" #include "ad_internal.h" #include "audio/reorder_ch.h" @@ -52,6 +53,15 @@ struct priv { int previous_data_left; // input demuxer packet data }; +#define OPT_BASE_STRUCT struct MPOpts + +const m_option_t ad_lavc_decode_opts_conf[] = { + OPT_FLOATRANGE("ac3drc", ad_lavc_param.ac3drc, 0, 0, 2), + OPT_FLAG("downmix", ad_lavc_param.downmix, 0), + OPT_STRING("o", ad_lavc_param.avopt, 0), + {0} +}; + struct pcm_map { int tag; @@ -190,7 +200,8 @@ static void set_from_wf(AVCodecContext *avctx, WAVEFORMATEX *wf) static int init(sh_audio_t *sh_audio, const char *decoder) { - struct MPOpts *opts = sh_audio->opts; + struct MPOpts *mpopts = sh_audio->opts; + struct ad_lavc_param *opts = &mpopts->ad_lavc_param; AVCodecContext *lavc_context; AVCodec *lavc_codec; @@ -216,12 +227,22 @@ static int init(sh_audio_t *sh_audio, const char *decoder) lavc_context->codec_type = AVMEDIA_TYPE_AUDIO; lavc_context->codec_id = lavc_codec->id; - lavc_context->request_channels = opts->audio_output_channels; + if (opts->downmix) + lavc_context->request_channels = mpopts->audio_output_channels; // Always try to set - option only exists for AC3 at the moment - av_opt_set_double(lavc_context, "drc_scale", opts->drc_level, + av_opt_set_double(lavc_context, "drc_scale", opts->ac3drc, AV_OPT_SEARCH_CHILDREN); + if (opts->avopt) { + if (parse_avopts(lavc_context, opts->avopt) < 0) { + mp_msg(MSGT_DECVIDEO, MSGL_ERR, + "ad_lavc: setting AVOptions '%s' failed.\n", opts->avopt); + uninit(sh_audio); + return 0; + } + } + lavc_context->codec_tag = sh_audio->format; lavc_context->sample_rate = sh_audio->samplerate; lavc_context->bit_rate = sh_audio->i_bps * 8; -- cgit v1.2.3 From 586b75ad0840e154835ae67c7720b71bd36f8cc9 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 6 Apr 2013 01:02:45 +0200 Subject: reorder_ch: remove old channel reorder functions This is done in af_lavrresample now, and as part of format negotiation. Also remove the remaining reorder_channel calls. They were redundant and did nothing. --- audio/decode/ad_lavc.c | 7 ------- 1 file changed, 7 deletions(-) (limited to 'audio/decode/ad_lavc.c') diff --git a/audio/decode/ad_lavc.c b/audio/decode/ad_lavc.c index 5c43c68d8a..8177d9cde6 100644 --- a/audio/decode/ad_lavc.c +++ b/audio/decode/ad_lavc.c @@ -451,13 +451,6 @@ static int decode_audio(sh_audio_t *sh_audio, unsigned char *buf, int minlen, memcpy(buf, priv->output, size); priv->output += size; priv->output_left -= size; - if (avctx->channels >= 5) { - int samplesize = av_get_bytes_per_sample(avctx->sample_fmt); - reorder_channel_nch(buf, AF_CHANNEL_LAYOUT_LAVC_DEFAULT, - AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT, - avctx->channels, - size / samplesize, samplesize); - } if (len < 0) len = size; else -- cgit v1.2.3 From 4b5cee4617d0decbf93d06df4f45097fd7e00105 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 6 Apr 2013 22:43:12 +0200 Subject: core: use channel map on demuxer level too This helps passing the channel layout correctly from decoder to audio filter chain. (Because that part "reuses" the demuxer level codec parameters, which is very disgusting.) Note that ffmpeg stuff already passed the channel layout via mp_copy_lav_codec_headers(). So other than easier dealing with the demuxer/decoder parameters mess, there's no real advantage to doing this. Make the --channels option accept a channel map. Since simple numbers map to standard layouts with the given number of channels, this is downwards compatible. Likewise for demux_rawaudio. --- audio/decode/ad_lavc.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'audio/decode/ad_lavc.c') diff --git a/audio/decode/ad_lavc.c b/audio/decode/ad_lavc.c index 8177d9cde6..4997a66bc4 100644 --- a/audio/decode/ad_lavc.c +++ b/audio/decode/ad_lavc.c @@ -168,10 +168,16 @@ static int setup_format(sh_audio_t *sh_audio, else if (container_samplerate) samplerate = container_samplerate; - if (lavc_context->channels != sh_audio->channels || + struct mp_chmap lavc_chmap; + mp_chmap_from_lavc(&lavc_chmap, lavc_context->channel_layout); + // No channel layout or layout disagrees with channel count + if (lavc_chmap.num != lavc_context->channels) + mp_chmap_from_channels(&lavc_chmap, lavc_context->channels); + + if (!mp_chmap_equals(&lavc_chmap, &sh_audio->channels) || samplerate != sh_audio->samplerate || sample_format != sh_audio->sample_format) { - sh_audio->channels = lavc_context->channels; + sh_audio->channels = lavc_chmap; sh_audio->samplerate = samplerate; sh_audio->sample_format = sample_format; sh_audio->samplesize = af_fmt2bits(sh_audio->sample_format) / 8; @@ -227,8 +233,11 @@ static int init(sh_audio_t *sh_audio, const char *decoder) lavc_context->codec_type = AVMEDIA_TYPE_AUDIO; lavc_context->codec_id = lavc_codec->id; - if (opts->downmix) - lavc_context->request_channels = mpopts->audio_output_channels; + if (opts->downmix) { + lavc_context->request_channels = mpopts->audio_output_channels.num; + lavc_context->request_channel_layout = + mp_chmap_to_lavc(&mpopts->audio_output_channels); + } // Always try to set - option only exists for AC3 at the moment av_opt_set_double(lavc_context, "drc_scale", opts->ac3drc, @@ -246,6 +255,7 @@ static int init(sh_audio_t *sh_audio, const char *decoder) lavc_context->codec_tag = sh_audio->format; lavc_context->sample_rate = sh_audio->samplerate; lavc_context->bit_rate = sh_audio->i_bps * 8; + lavc_context->channel_layout = mp_chmap_to_lavc(&sh_audio->channels); if (sh_audio->wf) set_from_wf(lavc_context, sh_audio->wf); -- cgit v1.2.3 From 1c601e84ffc84ba8dcf4c7b51b880c2ec72bcebe Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 7 Apr 2013 01:27:33 +0200 Subject: ad_lavc: force channel layout pass-through with demux_rawaudio Using demux_rawaudio and the --rawaudio-channels option is useful for testing channel map stuff. The libavcodec PCM decoder normalizes the channel map to ffmpeg order, though. Prevent this by forcing the original channel map when using the mp-pcm pseudo decoder entry (used by demux_rawaudio and stream/tv.c only). --- audio/decode/ad_lavc.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'audio/decode/ad_lavc.c') diff --git a/audio/decode/ad_lavc.c b/audio/decode/ad_lavc.c index 4997a66bc4..e8960c4941 100644 --- a/audio/decode/ad_lavc.c +++ b/audio/decode/ad_lavc.c @@ -51,6 +51,7 @@ struct priv { int output_left; int unitsize; int previous_data_left; // input demuxer packet data + bool force_channel_map; }; #define OPT_BASE_STRUCT struct MPOpts @@ -155,6 +156,7 @@ static int preinit(sh_audio_t *sh) static int setup_format(sh_audio_t *sh_audio, const AVCodecContext *lavc_context) { + struct priv *priv = sh_audio->context; int sample_format = af_from_avformat(av_get_packed_sample_fmt(lavc_context->sample_fmt)); bool broken_srate = false; @@ -173,6 +175,10 @@ static int setup_format(sh_audio_t *sh_audio, // No channel layout or layout disagrees with channel count if (lavc_chmap.num != lavc_context->channels) mp_chmap_from_channels(&lavc_chmap, lavc_context->channels); + if (priv->force_channel_map) { + if (lavc_chmap.num == sh_audio->channels.num) + lavc_chmap = sh_audio->channels; + } if (!mp_chmap_equals(&lavc_chmap, &sh_audio->channels) || samplerate != sh_audio->samplerate || @@ -211,22 +217,25 @@ static int init(sh_audio_t *sh_audio, const char *decoder) AVCodecContext *lavc_context; AVCodec *lavc_codec; + struct priv *ctx = talloc_zero(NULL, struct priv); + sh_audio->context = ctx; + if (sh_audio->wf && strcmp(decoder, "pcm") == 0) { decoder = find_pcm_decoder(tag_map, sh_audio->format, sh_audio->wf->wBitsPerSample); } else if (sh_audio->wf && strcmp(decoder, "mp-pcm") == 0) { decoder = find_pcm_decoder(af_map, sh_audio->format, 0); + ctx->force_channel_map = true; } lavc_codec = avcodec_find_decoder_by_name(decoder); if (!lavc_codec) { mp_tmsg(MSGT_DECAUDIO, MSGL_ERR, "Cannot find codec '%s' in libavcodec...\n", decoder); + uninit(sh_audio); return 0; } - struct priv *ctx = talloc_zero(NULL, struct priv); - sh_audio->context = ctx; lavc_context = avcodec_alloc_context3(lavc_codec); ctx->avctx = lavc_context; ctx->avframe = avcodec_alloc_frame(); -- cgit v1.2.3