Browse code

sipr: fix the output data size check and only calculate it once.

Justin Ruggles authored on 2011/09/21 04:27:44
Showing 1 changed files
... ...
@@ -509,7 +509,7 @@ static int sipr_decode_frame(AVCodecContext *avctx, void *datap,
509 509
     GetBitContext gb;
510 510
     float *data = datap;
511 511
     int subframe_size = ctx->mode == MODE_16k ? L_SUBFR_16k : SUBFR_SIZE;
512
-    int i;
512
+    int i, out_size;
513 513
 
514 514
     ctx->avctx = avctx;
515 515
     if (avpkt->size < (mode_par->bits_per_frame >> 3)) {
... ...
@@ -520,7 +520,11 @@ static int sipr_decode_frame(AVCodecContext *avctx, void *datap,
520 520
         *data_size = 0;
521 521
         return -1;
522 522
     }
523
-    if (*data_size < subframe_size * mode_par->subframe_count * sizeof(float)) {
523
+
524
+    out_size = mode_par->frames_per_packet * subframe_size *
525
+               mode_par->subframe_count *
526
+               av_get_bytes_per_sample(avctx->sample_fmt);
527
+    if (*data_size < out_size) {
524 528
         av_log(avctx, AV_LOG_ERROR,
525 529
                "Error processing packet: output buffer (%d) too small\n",
526 530
                *data_size);
... ...
@@ -542,8 +546,7 @@ static int sipr_decode_frame(AVCodecContext *avctx, void *datap,
542 542
         data += subframe_size * mode_par->subframe_count;
543 543
     }
544 544
 
545
-    *data_size = mode_par->frames_per_packet * subframe_size *
546
-        mode_par->subframe_count * sizeof(float);
545
+    *data_size = out_size;
547 546
 
548 547
     return mode_par->bits_per_frame >> 3;
549 548
 }