Browse code

do not decode more than one audio frame in a decode packet call

Originally committed as revision 19778 to svn://svn.ffmpeg.org/ffmpeg/trunk

Sascha Sommer authored on 2009/09/06 17:16:26
Showing 1 changed files
... ...
@@ -195,13 +195,12 @@ typedef struct WMAProDecodeCtx {
195 195
     int              frame_offset;                  ///< frame offset in the bit reservoir
196 196
     int              subframe_offset;               ///< subframe offset in the bit reservoir
197 197
     uint8_t          packet_loss;                   ///< set in case of bitstream error
198
-    uint8_t          output_buffer_full;            ///< flag indicating that the output buffer is full
198
+    uint8_t          packet_done;                   ///< set when a packet is fully decoded
199 199
 
200 200
     /* frame decode state */
201 201
     uint32_t         frame_num;                     ///< current frame number (not used for decoding)
202 202
     GetBitContext    gb;                            ///< bitstream reader context
203 203
     int              buf_bit_size;                  ///< buffer size in bits
204
-    float*           samples_start;                 ///< start samplebuffer pointer
205 204
     float*           samples;                       ///< current samplebuffer pointer
206 205
     float*           samples_end;                   ///< maximum samplebuffer pointer
207 206
     uint8_t          drc_gain;                      ///< gain for the DRC tool
... ...
@@ -1258,12 +1257,9 @@ static int decode_frame(WMAProDecodeCtx *s)
1258 1258
     /** check for potential output buffer overflow */
1259 1259
     if (s->num_channels * s->samples_per_frame > s->samples_end - s->samples) {
1260 1260
         /** return an error if no frame could be decoded at all */
1261
-        if (s->samples_start == s->samples) {
1262
-            av_log(s->avctx, AV_LOG_ERROR,
1263
-                   "not enough space for the output samples\n");
1264
-            s->packet_loss = 1;
1265
-        } else
1266
-            s->output_buffer_full = 1;
1261
+        av_log(s->avctx, AV_LOG_ERROR,
1262
+               "not enough space for the output samples\n");
1263
+        s->packet_loss = 1;
1267 1264
         return 0;
1268 1265
     }
1269 1266
 
... ...
@@ -1451,17 +1447,15 @@ static int decode_packet(AVCodecContext *avctx,
1451 1451
     GetBitContext* gb  = &s->pgb;
1452 1452
     const uint8_t* buf = avpkt->data;
1453 1453
     int buf_size       = avpkt->size;
1454
-    int more_frames    = 1;
1455 1454
     int num_bits_prev_frame;
1456 1455
     int packet_sequence_number;
1457 1456
 
1458 1457
     s->samples       = data;
1459
-    s->samples_start = data;
1460 1458
     s->samples_end   = (float*)((int8_t*)data + *data_size);
1461 1459
     *data_size = 0;
1462 1460
 
1463
-    if (!s->output_buffer_full || s->packet_loss) {
1464
-        s->output_buffer_full = 0;
1461
+    if (s->packet_done || s->packet_loss) {
1462
+        s->packet_done = 0;
1465 1463
         s->buf_bit_size = buf_size << 3;
1466 1464
 
1467 1465
         /** sanity check for the buffer length */
... ...
@@ -1507,28 +1501,17 @@ static int decode_packet(AVCodecContext *avctx,
1507 1507
         s->packet_loss = 0;
1508 1508
 
1509 1509
     } else {
1510
-        /** continue decoding */
1511
-        s->output_buffer_full = 0;
1512
-        more_frames = decode_frame(s);
1513
-    }
1514
-
1515
-    /** decode the rest of the packet */
1516
-    while (!s->packet_loss && !s->output_buffer_full && more_frames &&
1517
-           remaining_bits(s, gb) > s->log2_frame_size) {
1518
-        int frame_size = show_bits(gb, s->log2_frame_size);
1519
-
1520
-        /** there is enough data for a full frame */
1521
-        if (remaining_bits(s, gb) >= frame_size && frame_size > 0) {
1510
+        int frame_size;
1511
+        if (remaining_bits(s, gb) > s->log2_frame_size &&
1512
+            (frame_size = show_bits(gb, s->log2_frame_size)) &&
1513
+            frame_size <= remaining_bits(s, gb)) {
1522 1514
             save_bits(s, gb, frame_size, 0);
1523
-
1524
-            /** decode the frame */
1525
-            more_frames = decode_frame(s);
1526
-
1515
+            s->packet_done = !decode_frame(s);
1527 1516
         } else
1528
-            more_frames = 0;
1517
+            s->packet_done = 1;
1529 1518
     }
1530 1519
 
1531
-    if (!s->output_buffer_full && !s->packet_loss &&
1520
+    if (s->packet_done && !s->packet_loss &&
1532 1521
         remaining_bits(s, gb) > 0) {
1533 1522
         /** save the rest of the data so that it can be decoded
1534 1523
             with the next packet */
... ...
@@ -1537,7 +1520,7 @@ static int decode_packet(AVCodecContext *avctx,
1537 1537
 
1538 1538
     *data_size = (int8_t *)s->samples - (int8_t *)data;
1539 1539
 
1540
-    return (s->output_buffer_full && !s->packet_loss)?0: avctx->block_align;
1540
+    return (!s->packet_done && !s->packet_loss)?0: avctx->block_align;
1541 1541
 }
1542 1542
 
1543 1543
 /**