]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/parser.c
CAVS decoder by (Stefan Gehrer stefan.gehrer gmx.de)
[ffmpeg] / libavcodec / parser.c
index 2c896d85c89d9cd831fb28d1f5b65419531562dd..1977dd4943f77ed9eb4048e2928bd54605fb45af 100644 (file)
@@ -533,6 +533,30 @@ static int mpeg4video_parse(AVCodecParserContext *s,
     return next;
 }
 
+static int cavsvideo_parse(AVCodecParserContext *s,
+                           AVCodecContext *avctx,
+                           uint8_t **poutbuf, int *poutbuf_size,
+                           const uint8_t *buf, int buf_size)
+{
+    ParseContext *pc = s->priv_data;
+    int next;
+
+    if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){
+        next= buf_size;
+    }else{
+        next= ff_cavs_find_frame_end(pc, buf, buf_size);
+
+        if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
+            *poutbuf = NULL;
+            *poutbuf_size = 0;
+            return buf_size;
+        }
+    }
+    *poutbuf = (uint8_t *)buf;
+    *poutbuf_size = buf_size;
+    return next;
+}
+
 static int mpeg4video_split(AVCodecContext *avctx,
                            const uint8_t *buf, int buf_size)
 {
@@ -729,16 +753,16 @@ static int mpegaudio_parse(AVCodecParserContext *s1,
 
 /* also used for ADTS AAC */
 typedef struct AC3ParseContext {
-    uint8_t inbuf[4096]; /* input buffer */
     uint8_t *inbuf_ptr;
     int frame_size;
     int header_size;
     int (*sync)(const uint8_t *buf, int *channels, int *sample_rate,
                 int *bit_rate, int *samples);
+    uint8_t inbuf[8192]; /* input buffer */
 } AC3ParseContext;
 
 #define AC3_HEADER_SIZE 7
-#define AAC_HEADER_SIZE 8
+#define AAC_HEADER_SIZE 7
 
 static const int ac3_sample_rates[4] = {
     48000, 44100, 32000, 0
@@ -815,7 +839,7 @@ static int ac3_sync(const uint8_t *buf, int *channels, int *sample_rate,
     if(get_bits(&bits, 16) != 0x0b77)
         return 0;
 
-    get_bits(&bits, 16);    /* crc */
+    skip_bits(&bits, 16);       /* crc */
     fscod = get_bits(&bits, 2);
     frmsizecod = get_bits(&bits, 6);
 
@@ -825,15 +849,15 @@ static int ac3_sync(const uint8_t *buf, int *channels, int *sample_rate,
     bsid = get_bits(&bits, 5);
     if(bsid > 8)
         return 0;
-    get_bits(&bits, 3);     /* bsmod */
+    skip_bits(&bits, 3);        /* bsmod */
     acmod = get_bits(&bits, 3);
     if(acmod & 1 && acmod != 1)
-        get_bits(&bits, 2); /* cmixlev */
+        skip_bits(&bits, 2);    /* cmixlev */
     if(acmod & 4)
-        get_bits(&bits, 2); /* surmixlev */
+        skip_bits(&bits, 2);    /* surmixlev */
     if(acmod & 2)
-        get_bits(&bits, 2); /* dsurmod */
-    lfeon = get_bits(&bits, 1);
+        skip_bits(&bits, 2);    /* dsurmod */
+    lfeon = get_bits1(&bits);
 
     *sample_rate = ac3_sample_rates[fscod];
     *bit_rate = ac3_bitrates[frmsizecod] * 1000;
@@ -854,26 +878,26 @@ static int aac_sync(const uint8_t *buf, int *channels, int *sample_rate,
     if(get_bits(&bits, 12) != 0xfff)
         return 0;
 
-    get_bits(&bits, 1);
-    get_bits(&bits, 2);
-    get_bits(&bits, 1);         /* protection_absent */
-    get_bits(&bits, 2);
-    sr = get_bits(&bits, 4);
+    skip_bits1(&bits);          /* id */
+    skip_bits(&bits, 2);        /* layer */
+    skip_bits1(&bits);          /* protection_absent */
+    skip_bits(&bits, 2);        /* profile_objecttype */
+    sr = get_bits(&bits, 4);    /* sample_frequency_index */
     if(!aac_sample_rates[sr])
         return 0;
-    get_bits(&bits, 1);         /* private_bit */
-    ch = get_bits(&bits, 3);
+    skip_bits1(&bits);          /* private_bit */
+    ch = get_bits(&bits, 3);    /* channel_configuration */
     if(!aac_channels[ch])
         return 0;
-    get_bits(&bits, 1);         /* original/copy */
-    get_bits(&bits, 1);         /* home */
+    skip_bits1(&bits);          /* original/copy */
+    skip_bits1(&bits);          /* home */
 
     /* adts_variable_header */
-    get_bits(&bits, 1);         /* copyright_identification_bit */
-    get_bits(&bits, 1);         /* copyright_identification_start */
-    size = get_bits(&bits, 13);
-    get_bits(&bits, 11);        /* adts_buffer_fullness */
-    rdb = get_bits(&bits, 2);
+    skip_bits1(&bits);          /* copyright_identification_bit */
+    skip_bits1(&bits);          /* copyright_identification_start */
+    size = get_bits(&bits, 13); /* aac_frame_length */
+    skip_bits(&bits, 11);       /* adts_buffer_fullness */
+    rdb = get_bits(&bits, 2);   /* number_of_raw_data_blocks_in_frame */
 
     *channels = aac_channels[ch];
     *sample_rate = aac_sample_rates[sr];
@@ -987,6 +1011,15 @@ AVCodecParser mpeg4video_parser = {
     mpeg4video_split,
 };
 
+AVCodecParser cavsvideo_parser = {
+    { CODEC_ID_CAVS },
+    sizeof(ParseContext1),
+    NULL,
+    cavsvideo_parse,
+    parse1_close,
+    mpeg4video_split,
+};
+
 AVCodecParser mpegaudio_parser = {
     { CODEC_ID_MP2, CODEC_ID_MP3 },
     sizeof(MpegAudioParseContext),