[FFmpeg-soc] [soc]: r3804 - dirac/libavcodec/diracdec.c

conrad subversion at mplayerhq.hu
Tue Nov 11 09:37:54 CET 2008


Author: conrad
Date: Tue Nov 11 09:37:54 2008
New Revision: 3804

Log:
Allow for multiple data units in the same buffer


Modified:
   dirac/libavcodec/diracdec.c

Modified: dirac/libavcodec/diracdec.c
==============================================================================
--- dirac/libavcodec/diracdec.c	(original)
+++ dirac/libavcodec/diracdec.c	Tue Nov 11 09:37:54 2008
@@ -830,6 +830,7 @@ int dirac_decode_frame(AVCodecContext *a
     AVFrame *picture = data;
     int i;
     int parse_code;
+    unsigned data_unit_size, buf_read = 0;
 
     if (buf_size == 0) {
         int idx = dirac_reference_frame_idx(s, avctx->frame_number);
@@ -843,12 +844,17 @@ int dirac_decode_frame(AVCodecContext *a
         return 0;
     }
 
+    // read through data units until we find a picture
+    while (buf_read < buf_size) {
     parse_code = buf[4];
+    data_unit_size = AV_RB32(buf+5);
+    if (data_unit_size > buf_size - buf_read)
+        return -1;
 
     dprintf(avctx, "Decoding frame: size=%d head=%c%c%c%c parse=%02x\n",
             buf_size, buf[0], buf[1], buf[2], buf[3], buf[4]);
 
-    init_get_bits(&s->gb, &buf[13], (buf_size - 13) * 8);
+    init_get_bits(&s->gb, &buf[13], (data_unit_size - 13) * 8);
     s->avctx = avctx;
 
     if (parse_code ==  pc_seq_header) {
@@ -860,7 +866,12 @@ int dirac_decode_frame(AVCodecContext *a
         dirac_dump_source_parameters(avctx);
 #endif
 
-        return 0;
+    } else if (parse_code & 0x8)
+        // we found a picture
+        break;
+
+    buf += data_unit_size;
+    buf_read += data_unit_size;
     }
 
     /* If this is not a picture, return. */
@@ -993,7 +1004,7 @@ int dirac_decode_frame(AVCodecContext *a
         || s->picture.display_picture_number < avctx->frame_number)
         avcodec_get_frame_defaults(&s->picture);
 
-    return buf_size;
+    return buf_read + data_unit_size;
 }
 
 AVCodec dirac_decoder = {



More information about the FFmpeg-soc mailing list