[FFmpeg-devel] [PATCH] let ac3dec.c use request_channels

Justin Ruggles justinruggles
Wed Dec 12 23:26:08 CET 2007


Andreas ?man wrote:
> Hi
> 
> This makes the ac3decoder honor avctx->request_channels (just as dca
> does).
> 
> This fixes the old bug where content that switches from stereo to 5.1
> wont continue with downmixed the 5.1 audio. (Typically DVB broadcasts)

Great. I've been meaning to look into this.  Thank you for sending a 
patch for it.

> 
> Index: libavcodec/ac3dec.c
> ===================================================================
> --- libavcodec/ac3dec.c	(revision 11202)
> +++ libavcodec/ac3dec.c	(working copy)
> @@ -1127,24 +1127,19 @@
>      }
>  
>      /* channel config */
> -    ctx->out_channels = ctx->channels;
> -    if (avctx->channels == 0) {
> -        avctx->channels = ctx->out_channels;
> -    } else if(ctx->out_channels < avctx->channels) {
> -        av_log(avctx, AV_LOG_ERROR, "Cannot upmix AC3 from %d to %d channels.\n",
> -               ctx->out_channels, avctx->channels);
> -        return -1;
> +    if (avctx->request_channels > 0) {
> +        if (avctx->request_channels > ctx->channels ||
> +            avctx->request_channels > 2) {

I'm pretty sure this should be:

if (avctx->requested_channels > ctx->channels ||
(avctx->requested_channels != ctx->channels &&
avctx->requested_channels > 2))

Because it doesn't matter if requested_channels is more than 2 if it 
matches the number of source channels.  The way you have it, you could 
get something like "Cannot mix AC3 from 6 to 6 channels."

> +            av_log(avctx, AV_LOG_ERROR,
> +                   "Cannot mix AC3 from %d to %d channels.\n",
> +                   ctx->channels, avctx->request_channels);
> +            return -1;
> +        }
> +        ctx->out_channels = avctx->request_channels;
> +    } else {
> +        ctx->out_channels = ctx->channels;
>      }
> -    if(avctx->channels == 2) {
> -        ctx->output_mode = AC3_CHMODE_STEREO;
> -    } else if(avctx->channels == 1) {
> -        ctx->output_mode = AC3_CHMODE_MONO;
> -    } else if(avctx->channels != ctx->out_channels) {
> -        av_log(avctx, AV_LOG_ERROR, "Cannot downmix AC3 from %d to %d channels.\n",
> -               ctx->out_channels, avctx->channels);
> -        return -1;
> -    }
> -    ctx->out_channels = avctx->channels;
> +    avctx->channels = ctx->out_channels;

If downmixing is done to 2 or 1 channels, ctx->output_mode still needs 
to be set accordingly.

Thanks,
Justin




More information about the ffmpeg-devel mailing list