[FFmpeg-devel] [PATCH 2/2] avcodev/libdcadec: implement request_channel_layout
wm4
nfxjfg at googlemail.com
Thu Jul 9 13:32:31 CEST 2015
On Tue, 7 Jul 2015 03:06:24 -0300
James Almer <jamrial at gmail.com> wrote:
> Signed-off-by: James Almer <jamrial at gmail.com>
> ---
> libavcodec/libdcadec.c | 34 ++++++++++++++++++++++++++++++++++
> 1 file changed, 34 insertions(+)
>
> diff --git a/libavcodec/libdcadec.c b/libavcodec/libdcadec.c
> index 4bc3765..796826e 100644
> --- a/libavcodec/libdcadec.c
> +++ b/libavcodec/libdcadec.c
> @@ -36,6 +36,8 @@ typedef struct DCADecContext {
> int buffer_size;
> } DCADecContext;
>
> +static int downmix_warned = 0;
> +
> static int dcadec_decode_frame(AVCodecContext *avctx, void *data,
> int *got_frame_ptr, AVPacket *avpkt)
> {
> @@ -131,6 +133,17 @@ static int dcadec_decode_frame(AVCodecContext *avctx, void *data,
> if (exss = dcadec_context_get_exss_info(s->ctx)) {
> enum AVMatrixEncoding matrix_encoding = AV_MATRIX_ENCODING_NONE;
>
> + if (!downmix_warned) {
> + uint64_t layout = avctx->request_channel_layout;
> +
> + if (((layout == AV_CH_LAYOUT_STEREO_DOWNMIX || layout == AV_CH_LAYOUT_STEREO) && !exss->embedded_stereo) ||
> + ( layout == AV_CH_LAYOUT_5POINT1 && !exss->embedded_6ch))
> + av_log(avctx, AV_LOG_WARNING, "%s downmix was requested but no custom coefficients are available, "
> + "this may result in clipping\n",
> + layout == AV_CH_LAYOUT_5POINT1 ? "5.1" : "stereo");
> + downmix_warned = 1;
> + }
> +
What does this mean? Does this happen with FFmpeg's DCA decoder too?
> switch(exss->matrix_encoding) {
> case DCADEC_MATRIX_ENCODING_SURROUND:
> matrix_encoding = AV_MATRIX_ENCODING_DOLBY;
> @@ -195,6 +208,27 @@ static av_cold int dcadec_init(AVCodecContext *avctx)
> if (avctx->flags & CODEC_FLAG_BITEXACT)
> flags |= DCADEC_FLAG_CORE_BIT_EXACT;
>
> + if (avctx->request_channel_layout > 0 && avctx->request_channel_layout != AV_CH_LAYOUT_NATIVE) {
> + switch (avctx->request_channel_layout) {
> + case AV_CH_LAYOUT_STEREO:
> + case AV_CH_LAYOUT_STEREO_DOWNMIX:
> + /* libdcadec ignores the 2ch flag if used alone when no custom downmix coefficients
> + are available, silently outputting a 5.1 downmix if possible instead.
> + Using both the 2ch and 6ch flags together forces a 2ch downmix using default
> + coefficients in such cases. This matches the behavior of the 6ch flag when used
> + alone, where a 5.1 downmix is generated if possible, regardless of custom
> + coefficients being available or not. */
> + flags |= DCADEC_FLAG_KEEP_DMIX_2CH | DCADEC_FLAG_KEEP_DMIX_6CH;
> + break;
> + case AV_CH_LAYOUT_5POINT1:
> + flags |= DCADEC_FLAG_KEEP_DMIX_6CH;
> + break;
> + default:
> + av_log(avctx, AV_LOG_WARNING, "Invalid request_channel_layout\n");
> + break;
> + }
> + }
> +
> s->ctx = dcadec_context_create(flags);
> if (!s->ctx)
> return AVERROR(ENOMEM);
More information about the ffmpeg-devel
mailing list