]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/hcadec.c
avcodec: Constify AVCodecs
[ffmpeg] / libavcodec / hcadec.c
index f25d6c39b66b3e1a60b9f4a88e83fea72ed2e45c..c98f8eb37905c4294f83d02967c5f87cf796f439 100644 (file)
@@ -19,6 +19,7 @@
 #include "libavutil/crc.h"
 #include "libavutil/float_dsp.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/mem_internal.h"
 #include "libavutil/tx.h"
 
 #include "avcodec.h"
@@ -157,6 +158,10 @@ static av_cold int decode_init(AVCodecContext *avctx)
     } else
         return AVERROR_INVALIDDATA;
 
+    if (c->total_band_count > FF_ARRAY_ELEMS(c->ch->imdct_in))
+        return AVERROR_INVALIDDATA;
+
+
     while (get_bits_left(gb) >= 32) {
         chunk = get_bits_long(gb, 32);
         if (chunk == MKBETAG('v', 'b', 'r', 0)) {
@@ -263,7 +268,7 @@ static void apply_intensity_stereo(HCAContext *s, ChannelContext *ch1, ChannelCo
                                    int index, unsigned band_count, unsigned base_band_count,
                                    unsigned stereo_band_count)
 {
-    float ratio_l = intensity_ratio_table[ch1->intensity[index]];
+    float ratio_l = intensity_ratio_table[ch2->intensity[index]];
     float ratio_r = ratio_l - 2.0f;
     float *c1 = &ch1->imdct_in[base_band_count];
     float *c2 = &ch2->imdct_in[base_band_count];
@@ -286,8 +291,9 @@ static void reconstruct_hfr(HCAContext *s, ChannelContext *ch,
         return;
 
     for (int i = 0, k = start_band, l = start_band - 1; i < hfr_group_count; i++){
-        for (int j = 0; j < bands_per_hfr_group && k < total_band_count; j++, k++, l--){
-            ch->imdct_in[k] = scale_conversion_table[ch->hfr_scale[i] - ch->scale_factors[l]] * ch->imdct_in[l];
+        for (int j = 0; j < bands_per_hfr_group && k < total_band_count && l >= 0; j++, k++, l--){
+            ch->imdct_in[k] = scale_conversion_table[ scale_conv_bias +
+                av_clip_intp2(ch->hfr_scale[i] - ch->scale_factors[l], 6) ] * ch->imdct_in[l];
         }
     }
 
@@ -439,7 +445,7 @@ static av_cold int decode_close(AVCodecContext *avctx)
     return 0;
 }
 
-AVCodec ff_hca_decoder = {
+const AVCodec ff_hca_decoder = {
     .name           = "hca",
     .long_name      = NULL_IF_CONFIG_SMALL("CRI HCA"),
     .type           = AVMEDIA_TYPE_AUDIO,