[FFmpeg-devel] [PATCH] Add a parser for DNET (byte-swapped AC3).

Reimar Döffinger Reimar.Doeffinger
Mon Feb 28 22:22:14 CET 2011


Currently we simply byte-swap DNET directly in the Real demuxer,
however this is not generally possible/correct since which two bytes we
need to swap depends on whether the header starts on an even or an odd
byte.
Not useful on its own within FFmpeg, but could e.g. be used together
with a byte-swap bitstream filter or a modified AC3-decoder to implement
more robust DNET support.
---
 libavcodec/ac3_parser.c |   25 +++++++++++++++++++++++++
 libavcodec/avcodec.h    |    1 +
 2 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/libavcodec/ac3_parser.c b/libavcodec/ac3_parser.c
index 301aadc..77ba142 100644
--- a/libavcodec/ac3_parser.c
+++ b/libavcodec/ac3_parser.c
@@ -169,6 +169,23 @@ static av_cold int ac3_parse_init(AVCodecParserContext *s1)
     return 0;
 }
 
+static int dnet_sync(uint64_t state, AACAC3ParseContext *hdr_info,
+        int *need_next_header, int *new_frame_start)
+{
+    uint64_t swapped_state = av_bswap16(state >> 48);
+    swapped_state = (swapped_state << 16) | av_bswap16(state >> 32);
+    swapped_state = (swapped_state << 16) | av_bswap16(state >> 16);
+    swapped_state = (swapped_state << 16) | av_bswap16(state);
+    return ac3_sync(swapped_state, hdr_info, need_next_header, new_frame_start);
+}
+
+static av_cold int dnet_parse_init(AVCodecParserContext *s1)
+{
+    AACAC3ParseContext *s = s1->priv_data;
+    s->header_size = 8;
+    s->sync = dnet_sync;
+    return 0;
+}
 
 AVCodecParser ff_ac3_parser = {
     { CODEC_ID_AC3, CODEC_ID_EAC3 },
@@ -177,3 +194,11 @@ AVCodecParser ff_ac3_parser = {
     ff_aac_ac3_parse,
     ff_parse_close,
 };
+
+AVCodecParser ff_dnet_parser = {
+    { CODEC_ID_DNET },
+    sizeof(AACAC3ParseContext),
+    dnet_parse_init,
+    ff_aac_ac3_parse,
+    ff_parse_close,
+};
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 07c9aad..3cfa3c9 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -390,6 +390,7 @@ enum CodecID {
     CODEC_ID_BINKAUDIO_DCT,
     CODEC_ID_AAC_LATM,
     CODEC_ID_QDMC,
+    CODEC_ID_DNET,
 
     /* subtitle codecs */
     CODEC_ID_DVD_SUBTITLE= 0x17000,
-- 
1.7.4.1




More information about the ffmpeg-devel mailing list