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

Reimar Döffinger Reimar.Doeffinger
Thu Mar 3 21:40:50 CET 2011


On Thu, Mar 03, 2011 at 12:11:05PM -0500, Justin Ruggles wrote:
> On 03/03/2011 12:58 AM, Reimar D?ffinger wrote:
> > 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;
> > +}
> 
> 
> Why does s->header_size need to be 8 instead of 7?

Because we need to swap the bytes. That works badly with 7 bytes
(more precisely if we get 7 bytes in and swap we lose the last
non-matched byte and then have only 6 which is too little).

> > @@ -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,
> 
> 
> And I still don't like the name CODEC_ID_DNET.

Well, it's the most common name for it.
MPlayer has also a "sac3" fourcc for it.
AC3_LE might be an option, though a bit strange.



More information about the ffmpeg-devel mailing list