[FFmpeg-cvslog] ra288: use a more descriptive calculation for output data size

Justin Ruggles git at videolan.org
Tue Oct 11 03:52:32 CEST 2011


ffmpeg | branch: master | Justin Ruggles <justin.ruggles at gmail.com> | Wed Sep 14 14:46:02 2011 -0400| [fa6be04bf7121042ccac24bae2c2dfffba400920] | committer: Justin Ruggles

ra288: use a more descriptive calculation for output data size

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=fa6be04bf7121042ccac24bae2c2dfffba400920
---

 libavcodec/ra288.c |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/libavcodec/ra288.c b/libavcodec/ra288.c
index a0b86a2..f14c28d 100644
--- a/libavcodec/ra288.c
+++ b/libavcodec/ra288.c
@@ -31,6 +31,9 @@
 #define MAX_BACKWARD_FILTER_LEN    40
 #define MAX_BACKWARD_FILTER_NONREC 35
 
+#define RA288_BLOCK_SIZE        5
+#define RA288_BLOCKS_PER_FRAME 32
+
 typedef struct {
     float sp_lpc[36];      ///< LPC coefficients for speech data (spec: A)
     float gain_lpc[10];    ///< LPC coefficients for gain        (spec: GB)
@@ -165,7 +168,7 @@ static int ra288_decode_frame(AVCodecContext * avctx, void *data,
     const uint8_t *buf = avpkt->data;
     int buf_size = avpkt->size;
     float *out = data;
-    int i, j;
+    int i, j, out_size;
     RA288Context *ractx = avctx->priv_data;
     GetBitContext gb;
 
@@ -176,18 +179,20 @@ static int ra288_decode_frame(AVCodecContext * avctx, void *data,
         return 0;
     }
 
-    if (*data_size < 32*5*4)
+    out_size = RA288_BLOCK_SIZE * RA288_BLOCKS_PER_FRAME *
+               av_get_bytes_per_sample(avctx->sample_fmt);
+    if (*data_size < out_size)
         return -1;
 
     init_get_bits(&gb, buf, avctx->block_align * 8);
 
-    for (i=0; i < 32; i++) {
+    for (i=0; i < RA288_BLOCKS_PER_FRAME; i++) {
         float gain = amptable[get_bits(&gb, 3)];
         int cb_coef = get_bits(&gb, 6 + (i&1));
 
         decode(ractx, gain, cb_coef);
 
-        for (j=0; j < 5; j++)
+        for (j=0; j < RA288_BLOCK_SIZE; j++)
             *(out++) = ractx->sp_hist[70 + 36 + j];
 
         if ((i & 7) == 3) {
@@ -199,7 +204,7 @@ static int ra288_decode_frame(AVCodecContext * avctx, void *data,
         }
     }
 
-    *data_size = (char *)out - (char *)data;
+    *data_size = out_size;
     return avctx->block_align;
 }
 



More information about the ffmpeg-cvslog mailing list