[FFmpeg-devel] [PATCH] Detect DNET/byte-swapped AC-3 and support decoding it directly.

Justin Ruggles justin.ruggles
Sat Mar 5 17:10:24 CET 2011


On 03/05/2011 07:51 AM, Reimar D?ffinger wrote:

> This allows the AC-3 decoder to be used directly with RealMedia
> decoders that unlike the libavformat one do not byte-swap automatically.
> Since the new code is only used in case we would fail directly otherwise
> there should be no risk for regressions.
> The "buf" pointer needs to be overwritten since otherwise the CRC check fails.
> ---
>  libavcodec/ac3dec.c |   13 ++++++++++---
>  1 files changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
> index 5ebee19..05b1115 100644
> --- a/libavcodec/ac3dec.c
> +++ b/libavcodec/ac3dec.c
> @@ -1317,11 +1317,18 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size,
>      if (s->input_buffer) {
>          /* copy input buffer to decoder context to avoid reading past the end
>             of the buffer, which can be caused by a damaged input stream. */
> +        if (buf_size >= 2 && AV_RB16(buf) == 0x770B) {
> +            // seems to be byte-swapped (dnet) format
> +            int i;
> +            for (i = 0; i < FFMIN(buf_size, AC3_FRAME_BUFFER_SIZE) - 1; i += 2) {
> +                s->input_buffer[i]     = buf[i + 1];
> +                s->input_buffer[i + 1] = buf[i];
> +            }
> +        } else
>          memcpy(s->input_buffer, buf, FFMIN(buf_size, AC3_FRAME_BUFFER_SIZE));
> -        init_get_bits(&s->gbc, s->input_buffer, buf_size * 8);
> -    } else {
> -        init_get_bits(&s->gbc, buf, buf_size * 8);
> +        buf = s->input_buffer;
>      }
> +    init_get_bits(&s->gbc, buf, buf_size * 8);
>  
>      /* parse the syncinfo */
>      *data_size = 0;


This will only work if avctx->error_recognition >= FF_ER_CAREFUL because
otherwise s->input_buffer is not allocated and the original buffer is
used directly.

We could move the allocation from ac3_decode_init() to
ac3_decode_frame() based on both error_recognition and detection of
byte-swapped header.

-Justin





More information about the ffmpeg-devel mailing list