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

Reimar Döffinger Reimar.Doeffinger
Thu Mar 3 06:58:44 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 |   24 ++++++++++++++++++++++++
 libavcodec/allcodecs.c  |    1 +
 libavcodec/avcodec.h    |    5 +++--
 3 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/libavcodec/ac3_parser.c b/libavcodec/ac3_parser.c
index 301aadc..7c72fb4 100644
--- a/libavcodec/ac3_parser.c
+++ b/libavcodec/ac3_parser.c
@@ -169,6 +169,22 @@ 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)
+{
+    // byte-swap and right-shift state
+    state = (state & 0x00ff00ff00ff00ff) |
+            ((state & 0xff00ff00ff00ff00) >> 16);
+    return ac3_sync(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 +193,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/allcodecs.c b/libavcodec/allcodecs.c
index 108a3ab..150d258 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -378,6 +378,7 @@ void avcodec_register_all(void)
     REGISTER_PARSER  (CAVSVIDEO, cavsvideo);
     REGISTER_PARSER  (DCA, dca);
     REGISTER_PARSER  (DIRAC, dirac);
+    REGISTER_PARSER  (DNET, dnet);
     REGISTER_PARSER  (DNXHD, dnxhd);
     REGISTER_PARSER  (DVBSUB, dvbsub);
     REGISTER_PARSER  (DVDSUB, dvdsub);
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 07c9aad..c835c1a 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -32,8 +32,8 @@
 #include "libavutil/cpu.h"
 
 #define LIBAVCODEC_VERSION_MAJOR 52
-#define LIBAVCODEC_VERSION_MINOR 113
-#define LIBAVCODEC_VERSION_MICRO  2
+#define LIBAVCODEC_VERSION_MINOR 114
+#define LIBAVCODEC_VERSION_MICRO   0
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
                                                LIBAVCODEC_VERSION_MINOR, \
@@ -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