[FFmpeg-devel] [PATCH] Detect DNET/byte-swapped AC-3 and support decoding it directly.
Måns Rullgård
mans
Sat Mar 5 14:01:03 CET 2011
Reimar D?ffinger <Reimar.Doeffinger at gmx.de> writes:
> 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];
There are better ways of doing this. Let me dig out the old patch I had
adding a bswap16_buf function to dsputil.
> + }
> + } 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;
> --
> 1.7.4.1
And stop calling it dnet.
--
M?ns Rullg?rd
mans at mansr.com
More information about the ffmpeg-devel
mailing list