[FFmpeg-cvslog] Detect byte-swapped AC-3 and support decoding it directly.

Joakim Plate elupus at ecce.se
Wed Mar 23 10:15:00 CET 2011

Reimar Döffinger <git <at> videolan.org> writes:

>      /* 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 AC-3
> +        int cnt = FFMIN(buf_size, AC3_FRAME_BUFFER_SIZE) >> 1;
> +        s->dsp.bswap16_buf((uint16_t *)s->input_buffer, 
(const uint16_t *)buf, cnt);
> +    } else

There is a problem here. I seem to recall from mplayer days (on the xbox) that 
there are AC3 samples that have odd packet counts. With ffmin, these would
chop of the last byte of data.

With some luck i may have that sample around still. But i'm not 100% sure.
The fix back then was to padd the data with a 0 to get an even swap-able

The data in the input buffer should be padded anyway so just aligning
it up should work (or copy the last byte over after).


More information about the ffmpeg-cvslog mailing list