static int cook_decode_init(AVCodecContext *avctx)
{
    COOKContext *q = avctx->priv_data;
    const uint8_t *edata_ptr = avctx->extradata;
    if (avctx->extradata_size <= 0) {
        av_log(avctx,AV_LOG_ERROR,"Necessary extradata missing!\n");
        return -1;
    } else {
        av_log(avctx,AV_LOG_DEBUG,"codecdata_length=%d\n",avctx->extradata_size);
        if (avctx->extradata_size >= 8){
            q->cookversion = bytestream_get_be32(&edata_ptr);
            q->samples_per_frame =  bytestream_get_be16(&edata_ptr);
            q->subbands = bytestream_get_be16(&edata_ptr);
        }
        if (avctx->extradata_size >= 16){
            bytestream_get_be32(&edata_ptr);
            q->js_subband_start = bytestream_get_be16(&edata_ptr);
            q->js_vlc_bits = bytestream_get_be16(&edata_ptr);
        }
    }
    q->sample_rate = avctx->sample_rate;
    q->nb_channels = avctx->channels;
    q->bit_rate = avctx->bit_rate;
    av_init_random(1, &q->random_state);
    q->samples_per_channel = q->samples_per_frame / q->nb_channels;
    q->bits_per_subpacket = avctx->block_align * 8;
    q->log2_numvector_size = 5;
    q->total_subbands = q->subbands;
    av_log(NULL,AV_LOG_DEBUG,"q->cookversion=%x\n",q->cookversion);
    q->joint_stereo = 0;
    switch (q->cookversion) {
        case MONO:
            if (q->nb_channels != 1) {
                av_log(avctx,AV_LOG_ERROR,"Container channels != 1, report sample!\n");
                return -1;
            }
            av_log(avctx,AV_LOG_DEBUG,"MONO\n");
            break;
        case STEREO:
            if (q->nb_channels != 1) {
                q->bits_per_subpacket = q->bits_per_subpacket/2;
            }
            av_log(avctx,AV_LOG_DEBUG,"STEREO\n");
            break;
        case JOINT_STEREO:
            if (q->nb_channels != 2) {
                av_log(avctx,AV_LOG_ERROR,"Container channels != 2, report sample!\n");
                return -1;
            }
            av_log(avctx,AV_LOG_DEBUG,"JOINT_STEREO\n");
            if (avctx->extradata_size >= 16){
                q->total_subbands = q->subbands + q->js_subband_start;
                q->joint_stereo = 1;
            }
            if (q->samples_per_channel > 256) {
                q->log2_numvector_size  = 6;
            }
            if (q->samples_per_channel > 512) {
                q->log2_numvector_size  = 7;
            }
            break;
        case MC_COOK:
            av_log(avctx,AV_LOG_ERROR,"MC_COOK not supported!\n");
            return -1;
            break;
        default:
            av_log(avctx,AV_LOG_ERROR,"Unknown Cook version, report sample!\n");
            return -1;
            break;
    }
    q->numvector_size = (1 << q->log2_numvector_size);
    init_rootpow2table(q);
    init_pow2table(q);
    init_gain_table(q);
    init_cplscales_table(q);
    if (init_cook_vlc_tables(q) != 0)
        return -1;
    if(avctx->block_align >= UINT_MAX/2)
        return -1;
    if (q->nb_channels==2 && q->joint_stereo==0) {
        q->decoded_bytes_buffer =
          av_mallocz(avctx->block_align/2
                     + DECODE_BYTES_PAD2(avctx->block_align/2)
                     + FF_INPUT_BUFFER_PADDING_SIZE);
    } else {
        q->decoded_bytes_buffer =
          av_mallocz(avctx->block_align
                     + DECODE_BYTES_PAD1(avctx->block_align)
                     + FF_INPUT_BUFFER_PADDING_SIZE);
    }
    if (q->decoded_bytes_buffer == NULL)
        return -1;
    q->gains1.now      = q->gain_1;
    q->gains1.previous = q->gain_2;
    q->gains2.now      = q->gain_3;
    q->gains2.previous = q->gain_4;
    if ( init_cook_mlt(q) != 0 )
        return -1;
    if (1) {
        q->scalar_dequant  = scalar_dequant_float;
        q->decouple        = decouple_float;
        q->imlt_window     = imlt_window_float;
        q->interpolate     = interpolate_float;
        q->saturate_output = saturate_output_float;
    }
    if (q->total_subbands > 53) {
        av_log(avctx,AV_LOG_ERROR,"total_subbands > 53, report sample!\n");
        return -1;
    }
    if (q->subbands > 50) {
        av_log(avctx,AV_LOG_ERROR,"subbands > 50, report sample!\n");
        return -1;
    }
    if ((q->samples_per_channel == 256) || (q->samples_per_channel == 512) || (q->samples_per_channel == 1024)) {
    } else {
        av_log(avctx,AV_LOG_ERROR,"unknown amount of samples_per_channel = %d, report sample!\n",q->samples_per_channel);
        return -1;
    }
    if ((q->js_vlc_bits > 6) || (q->js_vlc_bits < 0)) {
        av_log(avctx,AV_LOG_ERROR,"q->js_vlc_bits = %d, only >= 0 and <= 6 allowed!\n",q->js_vlc_bits);
        return -1;
    }
#ifdef COOKDEBUG
    dump_cook_context(q);
#endif
    return 0;
}
['static int cook_decode_init(AVCodecContext *avctx)\n{\n    COOKContext *q = avctx->priv_data;\n    const uint8_t *edata_ptr = avctx->extradata;\n    if (avctx->extradata_size <= 0) {\n        av_log(avctx,AV_LOG_ERROR,"Necessary extradata missing!\\n");\n        return -1;\n    } else {\n        av_log(avctx,AV_LOG_DEBUG,"codecdata_length=%d\\n",avctx->extradata_size);\n        if (avctx->extradata_size >= 8){\n            q->cookversion = bytestream_get_be32(&edata_ptr);\n            q->samples_per_frame =  bytestream_get_be16(&edata_ptr);\n            q->subbands = bytestream_get_be16(&edata_ptr);\n        }\n        if (avctx->extradata_size >= 16){\n            bytestream_get_be32(&edata_ptr);\n            q->js_subband_start = bytestream_get_be16(&edata_ptr);\n            q->js_vlc_bits = bytestream_get_be16(&edata_ptr);\n        }\n    }\n    q->sample_rate = avctx->sample_rate;\n    q->nb_channels = avctx->channels;\n    q->bit_rate = avctx->bit_rate;\n    av_init_random(1, &q->random_state);\n    q->samples_per_channel = q->samples_per_frame / q->nb_channels;\n    q->bits_per_subpacket = avctx->block_align * 8;\n    q->log2_numvector_size = 5;\n    q->total_subbands = q->subbands;\n    av_log(NULL,AV_LOG_DEBUG,"q->cookversion=%x\\n",q->cookversion);\n    q->joint_stereo = 0;\n    switch (q->cookversion) {\n        case MONO:\n            if (q->nb_channels != 1) {\n                av_log(avctx,AV_LOG_ERROR,"Container channels != 1, report sample!\\n");\n                return -1;\n            }\n            av_log(avctx,AV_LOG_DEBUG,"MONO\\n");\n            break;\n        case STEREO:\n            if (q->nb_channels != 1) {\n                q->bits_per_subpacket = q->bits_per_subpacket/2;\n            }\n            av_log(avctx,AV_LOG_DEBUG,"STEREO\\n");\n            break;\n        case JOINT_STEREO:\n            if (q->nb_channels != 2) {\n                av_log(avctx,AV_LOG_ERROR,"Container channels != 2, report sample!\\n");\n                return -1;\n            }\n            av_log(avctx,AV_LOG_DEBUG,"JOINT_STEREO\\n");\n            if (avctx->extradata_size >= 16){\n                q->total_subbands = q->subbands + q->js_subband_start;\n                q->joint_stereo = 1;\n            }\n            if (q->samples_per_channel > 256) {\n                q->log2_numvector_size  = 6;\n            }\n            if (q->samples_per_channel > 512) {\n                q->log2_numvector_size  = 7;\n            }\n            break;\n        case MC_COOK:\n            av_log(avctx,AV_LOG_ERROR,"MC_COOK not supported!\\n");\n            return -1;\n            break;\n        default:\n            av_log(avctx,AV_LOG_ERROR,"Unknown Cook version, report sample!\\n");\n            return -1;\n            break;\n    }\n    q->numvector_size = (1 << q->log2_numvector_size);\n    init_rootpow2table(q);\n    init_pow2table(q);\n    init_gain_table(q);\n    init_cplscales_table(q);\n    if (init_cook_vlc_tables(q) != 0)\n        return -1;\n    if(avctx->block_align >= UINT_MAX/2)\n        return -1;\n    if (q->nb_channels==2 && q->joint_stereo==0) {\n        q->decoded_bytes_buffer =\n          av_mallocz(avctx->block_align/2\n                     + DECODE_BYTES_PAD2(avctx->block_align/2)\n                     + FF_INPUT_BUFFER_PADDING_SIZE);\n    } else {\n        q->decoded_bytes_buffer =\n          av_mallocz(avctx->block_align\n                     + DECODE_BYTES_PAD1(avctx->block_align)\n                     + FF_INPUT_BUFFER_PADDING_SIZE);\n    }\n    if (q->decoded_bytes_buffer == NULL)\n        return -1;\n    q->gains1.now      = q->gain_1;\n    q->gains1.previous = q->gain_2;\n    q->gains2.now      = q->gain_3;\n    q->gains2.previous = q->gain_4;\n    if ( init_cook_mlt(q) != 0 )\n        return -1;\n    if (1) {\n        q->scalar_dequant  = scalar_dequant_float;\n        q->decouple        = decouple_float;\n        q->imlt_window     = imlt_window_float;\n        q->interpolate     = interpolate_float;\n        q->saturate_output = saturate_output_float;\n    }\n    if (q->total_subbands > 53) {\n        av_log(avctx,AV_LOG_ERROR,"total_subbands > 53, report sample!\\n");\n        return -1;\n    }\n    if (q->subbands > 50) {\n        av_log(avctx,AV_LOG_ERROR,"subbands > 50, report sample!\\n");\n        return -1;\n    }\n    if ((q->samples_per_channel == 256) || (q->samples_per_channel == 512) || (q->samples_per_channel == 1024)) {\n    } else {\n        av_log(avctx,AV_LOG_ERROR,"unknown amount of samples_per_channel = %d, report sample!\\n",q->samples_per_channel);\n        return -1;\n    }\n    if ((q->js_vlc_bits > 6) || (q->js_vlc_bits < 0)) {\n        av_log(avctx,AV_LOG_ERROR,"q->js_vlc_bits = %d, only >= 0 and <= 6 allowed!\\n",q->js_vlc_bits);\n        return -1;\n    }\n#ifdef COOKDEBUG\n    dump_cook_context(q);\n#endif\n    return 0;\n}']