Revision 560b10a6

View differences:

libavcodec/cook.c
113 113
    /* gain buffers */
114 114
    COOKgain*           gain_now_ptr;
115 115
    COOKgain*           gain_previous_ptr;
116
    COOKgain            gain_copy;
117 116
    COOKgain            gain_current;
118 117
    COOKgain            gain_now;
119 118
    COOKgain            gain_previous;
119
    COOKgain            gain_channel1[2];
120
    COOKgain            gain_channel2[2];
120 121

  
121 122
    /* VLC data */
122 123
    int                 js_vlc_bits;
......
138 139
    float               mono_previous_buffer1[1024];
139 140
    float               mono_previous_buffer2[1024];
140 141
    float*              decode_buf_ptr[4];
142
    float*              decode_buf_ptr2[2];
141 143
    float               decode_buffer_1[1024];
142 144
    float               decode_buffer_2[1024];
143 145
    float               decode_buffer_3[1024];
......
206 208
        q->gain_table[i] = pow((double)q->pow2tab[i+52] ,
207 209
                               (1.0/(double)q->gain_size_factor));
208 210
    }
209
    memset(&q->gain_copy, 0, sizeof(COOKgain));
210
    memset(&q->gain_current, 0, sizeof(COOKgain));
211
    memset(&q->gain_now, 0, sizeof(COOKgain));
212
    memset(&q->gain_previous, 0, sizeof(COOKgain));
213 211
}
214 212

  
215 213

  
......
975 973
    decode_bytes(inbuffer, q->decoded_bytes_buffer, sub_packet_size);
976 974
    init_get_bits(&q->gb, q->decoded_bytes_buffer, sub_packet_size*8);
977 975
    decode_gain_info(&q->gb, &q->gain_current);
978
    memcpy(&q->gain_copy, &q->gain_current ,sizeof(COOKgain));  //This copy does not seem to be used. FIXME
979 976

  
980 977
    if(q->nb_channels==2 && q->joint_stereo==1){
981 978
        joint_decode(q, q->decode_buf_ptr[0], q->decode_buf_ptr[2]);
......
1017 1014

  
1018 1015
    } else if (q->nb_channels==2 && q->joint_stereo==0) {
1019 1016
            /* channel 0 */
1020
            mono_decode(q, q->decode_buf_ptr[0]);
1017
            mono_decode(q, q->decode_buf_ptr2[0]);
1021 1018

  
1022
            tmp_ptr = q->decode_buf_ptr[0];
1023
            q->decode_buf_ptr[0] = q->decode_buf_ptr[1];
1024
            q->decode_buf_ptr[1] = q->decode_buf_ptr[2];
1025
            q->decode_buf_ptr[2] = q->decode_buf_ptr[3];
1026
            q->decode_buf_ptr[3] = tmp_ptr;
1019
            tmp_ptr = q->decode_buf_ptr2[0];
1020
            q->decode_buf_ptr2[0] = q->decode_buf_ptr2[1];
1021
            q->decode_buf_ptr2[1] = tmp_ptr;
1027 1022

  
1028
            q->gain_now_ptr = &q->gain_now;
1029
            q->gain_previous_ptr = &q->gain_previous;
1023
            memcpy(&q->gain_channel1[0], &q->gain_current ,sizeof(COOKgain));
1024
            q->gain_now_ptr = &q->gain_channel1[0];
1025
            q->gain_previous_ptr = &q->gain_channel1[1];
1030 1026

  
1031
            cook_imlt(q, q->decode_buf_ptr[0], q->mono_mdct_output,q->mlt_tmp);
1027
            cook_imlt(q, q->decode_buf_ptr2[0], q->mono_mdct_output,q->mlt_tmp);
1032 1028
            gain_compensate(q, q->mono_mdct_output, q->gain_now_ptr,
1033
                            q->gain_previous_ptr, q->previous_buffer_ptr[0]);
1034
            /* Swap out the previous buffer. */
1035
            tmp_ptr = q->previous_buffer_ptr[0];
1036
            q->previous_buffer_ptr[0] = q->previous_buffer_ptr[1];
1037
            q->previous_buffer_ptr[1] = tmp_ptr;
1029
                            q->gain_previous_ptr, q->mono_previous_buffer1);
1030

  
1031
            memcpy(&q->gain_channel1[1], &q->gain_channel1[0],sizeof(COOKgain));
1032

  
1038 1033

  
1039 1034
            for (j=0 ; j<q->samples_per_frame ; j++){
1040 1035
                value = lrintf(q->mono_mdct_output[j]);
......
1046 1041
            /* channel 1 */
1047 1042
            //av_log(NULL,AV_LOG_ERROR,"bits = %d\n",get_bits_count(&q->gb));
1048 1043
            init_get_bits(&q->gb, q->decoded_bytes_buffer, sub_packet_size*8+q->bits_per_subpacket);
1049
            decode_gain_info(&q->gb, &q->gain_current);
1050
            //memcpy(&q->gain_copy, &q->gain_current ,sizeof(COOKgain));
1044

  
1045
            q->gain_now_ptr = &q->gain_channel2[0];
1046
            q->gain_previous_ptr = &q->gain_channel2[1];
1047

  
1048
            decode_gain_info(&q->gb, &q->gain_channel2[0]);
1051 1049
            mono_decode(q, q->decode_buf_ptr[0]);
1052
            tmp_ptr = q->decode_buf_ptr[0];
1053
            q->decode_buf_ptr[1] = q->decode_buf_ptr[2];
1054
            q->decode_buf_ptr[2] = q->decode_buf_ptr[3];
1055
            q->decode_buf_ptr[3] = tmp_ptr;
1056 1050

  
1057
            q->gain_now_ptr = &q->gain_now;
1058
            q->gain_previous_ptr = &q->gain_previous;
1051
            tmp_ptr = q->decode_buf_ptr[0];
1052
            q->decode_buf_ptr[0] = q->decode_buf_ptr[1];
1053
            q->decode_buf_ptr[1] = tmp_ptr;
1059 1054

  
1060 1055
            cook_imlt(q, q->decode_buf_ptr[0], q->mono_mdct_output,q->mlt_tmp);
1061
            gain_compensate(q, q->mono_mdct_output, q->gain_now_ptr, q->gain_previous_ptr, q->previous_buffer_ptr[0]);
1056
            gain_compensate(q, q->mono_mdct_output, q->gain_now_ptr,
1057
                            q->gain_previous_ptr, q->mono_previous_buffer2);
1062 1058

  
1063 1059
            /* Swap out the previous buffer. */
1064 1060
            tmp_ptr = q->previous_buffer_ptr[0];
1065 1061
            q->previous_buffer_ptr[0] = q->previous_buffer_ptr[1];
1066 1062
            q->previous_buffer_ptr[1] = tmp_ptr;
1067 1063

  
1064
            memcpy(&q->gain_channel2[1], &q->gain_channel2[0] ,sizeof(COOKgain));
1065

  
1068 1066
            for (j=0 ; j<q->samples_per_frame ; j++){
1069 1067
                value = lrintf(q->mono_mdct_output[j]);
1070 1068
                if(value < -32768) value = -32768;
......
1072 1070
                outbuffer[2*j] = value;
1073 1071
            }
1074 1072

  
1075

  
1076
            /* Swap out the previous buffer. */
1077
            memcpy(&q->gain_now, &q->gain_previous, sizeof(COOKgain));
1078
            memcpy(&q->gain_previous, &q->gain_current, sizeof(COOKgain));
1079

  
1080 1073
    } else {
1081 1074
        mono_decode(q, q->decode_buf_ptr[0]);
1082 1075

  
......
1214 1207
        case MONO_COOK2:
1215 1208
            if (q->nb_channels != 1) {
1216 1209
                q->joint_stereo = 0;
1217
                av_log(NULL,AV_LOG_ERROR,"Non-joint-stereo files are decoded with wrong gain at the moment!\n");
1218 1210
                q->bits_per_subpacket = q->bits_per_subpacket/2;
1219

  
1220 1211
            }
1221 1212
            av_log(NULL,AV_LOG_DEBUG,"MONO_COOK2\n");
1222 1213
            break;
......
1271 1262
    q->decode_buf_ptr[2] = q->decode_buffer_3;
1272 1263
    q->decode_buf_ptr[3] = q->decode_buffer_4;
1273 1264

  
1265
    q->decode_buf_ptr2[0] = q->decode_buffer_3;
1266
    q->decode_buf_ptr2[1] = q->decode_buffer_4;
1267

  
1274 1268
    q->previous_buffer_ptr[0] = q->mono_previous_buffer1;
1275 1269
    q->previous_buffer_ptr[1] = q->mono_previous_buffer2;
1276 1270

  
1277
    memset(q->decode_buffer_1,0,1024*sizeof(float));
1278
    memset(q->decode_buffer_2,0,1024*sizeof(float));
1279
    memset(q->decode_buffer_3,0,1024*sizeof(float));
1280
    memset(q->decode_buffer_4,0,1024*sizeof(float));
1281

  
1282 1271
    /* Initialize transform. */
1283 1272
    if ( init_cook_mlt(q) == 0 )
1284 1273
        return -1;
1274

  
1275
    /* Try to catch some obviously faulty streams, othervise it might be exploitable */
1276
    if (q->total_subbands > 53) {
1277
        av_log(NULL,AV_LOG_ERROR,"total_subbands > 53, report sample!\n");
1278
        return -1;
1279
    }
1280
    if (((q->subbands > 34) || (q->js_subband_start > 19)) && (q->joint_stereo)) {
1281
        av_log(NULL,AV_LOG_ERROR,"subbands > 34 or js_subband_start > 19, report sample!\n");
1282
        return -1;
1283
    }
1284
    if (q->subbands > 50) {
1285
        av_log(NULL,AV_LOG_ERROR,"subbands > 50, report sample!\n");
1286
        return -1;
1287
    }
1288

  
1285 1289
#ifdef COOKDEBUG
1286 1290
    dump_cook_context(q,e);
1287 1291
#endif

Also available in: Unified diff