]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/wmadec.c
Typo
[ffmpeg] / libavcodec / wmadec.c
index da02f698248a95b4e8c1bae5070bc96e44ea0e47..9e195841938ffa590da082cd5f9c8dfcbdcf0663 100644 (file)
@@ -48,7 +48,7 @@
 static void wma_lsp_to_curve_init(WMACodecContext *s, int frame_len);
 
 #ifdef TRACE
-static void dump_shorts(WMADecodeContext *s, const char *name, const short *tab, int n)
+static void dump_shorts(WMACodecContext *s, const char *name, const short *tab, int n)
 {
     int i;
 
@@ -62,7 +62,7 @@ static void dump_shorts(WMADecodeContext *s, const char *name, const short *tab,
     }
 }
 
-static void dump_floats(WMADecodeContext *s, const char *name, int prec, const float *tab, int n)
+static void dump_floats(WMACodecContext *s, const char *name, int prec, const float *tab, int n)
 {
     int i;
 
@@ -92,12 +92,11 @@ static int wma_decode_init(AVCodecContext * avctx)
     flags2 = 0;
     extradata = avctx->extradata;
     if (avctx->codec->id == CODEC_ID_WMAV1 && avctx->extradata_size >= 4) {
-        flags1 = extradata[0] | (extradata[1] << 8);
-        flags2 = extradata[2] | (extradata[3] << 8);
+        flags1 = AV_RL16(extradata);
+        flags2 = AV_RL16(extradata+2);
     } else if (avctx->codec->id == CODEC_ID_WMAV2 && avctx->extradata_size >= 6) {
-        flags1 = extradata[0] | (extradata[1] << 8) |
-            (extradata[2] << 16) | (extradata[3] << 24);
-        flags2 = extradata[4] | (extradata[5] << 8);
+        flags1 = AV_RL32(extradata);
+        flags2 = AV_RL16(extradata+4);
     }
 // for(i=0; i<avctx->extradata_size; i++)
 //     av_log(NULL, AV_LOG_ERROR, "%02X ", extradata[i]);
@@ -394,11 +393,11 @@ static int wma_decode_block(WMACodecContext *s)
         return -1;
 
     if (s->nb_channels == 2) {
-        s->ms_stereo = get_bits(&s->gb, 1);
+        s->ms_stereo = get_bits1(&s->gb);
     }
     v = 0;
     for(ch = 0; ch < s->nb_channels; ch++) {
-        a = get_bits(&s->gb, 1);
+        a = get_bits1(&s->gb);
         s->channel_coded[ch] = a;
         v |= a;
     }
@@ -434,7 +433,7 @@ static int wma_decode_block(WMACodecContext *s)
                 int i, n, a;
                 n = s->exponent_high_sizes[bsize];
                 for(i=0;i<n;i++) {
-                    a = get_bits(&s->gb, 1);
+                    a = get_bits1(&s->gb);
                     s->high_band_coded[ch][i] = a;
                     /* if noise coding, the coefficients are not transmitted */
                     if (a)
@@ -467,7 +466,7 @@ static int wma_decode_block(WMACodecContext *s)
 
     /* exponents can be reused in short blocks. */
     if ((s->block_len_bits == s->frame_len_bits) ||
-        get_bits(&s->gb, 1)) {
+        get_bits1(&s->gb)) {
         for(ch = 0; ch < s->nb_channels; ch++) {
             if (s->channel_coded[ch]) {
                 if (s->use_exp_vlc) {
@@ -517,7 +516,7 @@ static int wma_decode_block(WMACodecContext *s)
                     run = run_table[code];
                     level = level_table[code];
                 }
-                sign = get_bits(&s->gb, 1);
+                sign = get_bits1(&s->gb);
                 if (!sign)
                     level = -level;
                 ptr += run;
@@ -713,7 +712,7 @@ static int wma_decode_block(WMACodecContext *s)
 /* decode a frame of frame_len samples */
 static int wma_decode_frame(WMACodecContext *s, int16_t *samples)
 {
-    int ret, i, n, a, ch, incr;
+    int ret, i, n, ch, incr;
     int16_t *ptr;
     float *iptr;
 
@@ -740,12 +739,7 @@ static int wma_decode_frame(WMACodecContext *s, int16_t *samples)
         iptr = s->frame_out[ch];
 
         for(i=0;i<n;i++) {
-            a = lrintf(*iptr++);
-            if (a > 32767)
-                a = 32767;
-            else if (a < -32768)
-                a = -32768;
-            *ptr = a;
+            *ptr = av_clip_int16(lrintf(*iptr++));
             ptr += incr;
         }
         /* prepare for next block */
@@ -761,7 +755,7 @@ static int wma_decode_frame(WMACodecContext *s, int16_t *samples)
 
 static int wma_decode_superframe(AVCodecContext *avctx,
                                  void *data, int *data_size,
-                                 uint8_t *buf, int buf_size)
+                                 const uint8_t *buf, int buf_size)
 {
     WMACodecContext *s = avctx->priv_data;
     int nb_frames, bit_offset, i, pos, len;
@@ -774,6 +768,9 @@ static int wma_decode_superframe(AVCodecContext *avctx,
         s->last_superframe_len = 0;
         return 0;
     }
+    if (buf_size < s->block_align)
+        return 0;
+    buf_size = s->block_align;
 
     samples = data;
 
@@ -781,7 +778,7 @@ static int wma_decode_superframe(AVCodecContext *avctx,
 
     if (s->use_bit_reservoir) {
         /* read super frame header */
-        get_bits(&s->gb, 4); /* super frame index */
+        skip_bits(&s->gb, 4); /* super frame index */
         nb_frames = get_bits(&s->gb, 4) - 1;
 
         bit_offset = get_bits(&s->gb, s->byte_offset_bits + 3);