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

Reimar Döffinger Reimar.Doeffinger
Sat Mar 5 13:51:47 CET 2011


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;
-- 
1.7.4.1




More information about the ffmpeg-devel mailing list