libavcodec/dca.c:1671: error: Buffer Overrun L2
  Offset: [0, -1+max(7, `avctx->priv_data->prim_channels`)] Size: 5 by call to `dca_decode_block`.

libavcodec/dca.c:1631:1: Parameter `avctx->priv_data->prim_channels`
1629.  * FIXME add arguments
1630.  */
1631. static int dca_decode_frame(AVCodecContext * avctx,
      ^
1632.                             void *data, int *data_size,
1633.                             AVPacket *avpkt)

libavcodec/dca.c:1659:16: Call
1657. 
1658.     init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8);
1659.     if ((ret = dca_parse_frame_header(s)) < 0) {
                     ^
1660.         //seems like the frame is corrupt, try with the next one
1661.         return ret;

libavcodec/dca.c:518:1: Parameter `s->prim_channels`
  516. }
  517. 
  518. static int dca_parse_frame_header(DCAContext * s)
       ^
  519. {
  520.     init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8);

libavcodec/dca.c:1671:20: Call
1669. 
1670.     for (i = 0; i < (s->sample_blocks / 8); i++) {
1671.         if ((ret = dca_decode_block(s, 0, i))) {
                         ^
1672.             av_log(avctx, AV_LOG_ERROR, "error decoding block\n");
1673.             return ret;

libavcodec/dca.c:1275:1: Parameter `base_channel`
  1273.  */
  1274. 
  1275. static int dca_decode_block(DCAContext * s, int base_channel, int block_index)
        ^
  1276. {
  1277.     int ret;

libavcodec/dca.c:1291:20: Call
  1289. #endif
  1290.         /* Read subframe header */
  1291.         if ((ret = dca_subframe_header(s, base_channel, block_index)))
                           ^
  1292.             return ret;
  1293.     }

libavcodec/dca.c:624:1: <Offset trace>
622. }
623. 
624. static int dca_subframe_header(DCAContext * s, int base_channel, int block_index)
     ^
625. {
626.     /* Primary audio coding side information */

libavcodec/dca.c:624:1: Parameter `s->prim_channels`
    622. }
    623. 
    624. static int dca_subframe_header(DCAContext * s, int base_channel, int block_index)
         ^
    625. {
    626.     /* Primary audio coding side information */

libavcodec/dcadata.h:7531:1: <Length trace>
7529. };
7530. 
7531. static const uint8_t dca_default_coeffs[16][5][2] = {
      ^
7532.     { { 13, 13 },                                                 },
7533.     { {  0, 64 }, { 64,  0 },                                     },

libavcodec/dcadata.h:7531:1: Array declaration
    7529. };
    7530. 
    7531. static const uint8_t dca_default_coeffs[16][5][2] = {
          ^
    7532.     { { 13, 13 },                                                 },
    7533.     { {  0, 64 }, { 64,  0 },                                     },

libavcodec/dca.c:765:41: Array access: Offset: [0, -1+max(7, avctx->priv_data->prim_channels)] Size: 5 by call to `dca_decode_block` 
    763.             int am = s->amode & DCA_CHANNEL_MASK;
    764.             for (j = base_channel; j < s->prim_channels; j++) {
    765.                 s->downmix_coef[j][0] = dca_default_coeffs[am][j][0];
                                                 ^
    766.                 s->downmix_coef[j][1] = dca_default_coeffs[am][j][1];
    767.             }

static int dca_subframe_header(DCAContext * s, int base_channel, int block_index)
{
    int j, k;
    if (get_bits_left(&s->gb) < 0)
        return AVERROR_INVALIDDATA;
    if (!base_channel) {
        s->subsubframes[s->current_subframe] = get_bits(&s->gb, 2) + 1;
        s->partial_samples[s->current_subframe] = get_bits(&s->gb, 3);
    }
    for (j = base_channel; j < s->prim_channels; j++) {
        for (k = 0; k < s->subband_activity[j]; k++)
            s->prediction_mode[j][k] = get_bits(&s->gb, 1);
    }
    for (j = base_channel; j < s->prim_channels; j++) {
        for (k = 0; k < s->subband_activity[j]; k++) {
            if (s->prediction_mode[j][k] > 0) {
                s->prediction_vq[j][k] = get_bits(&s->gb, 12);
            }
        }
    }
    for (j = base_channel; j < s->prim_channels; j++) {
        for (k = 0; k < s->vq_start_subband[j]; k++) {
            if (s->bitalloc_huffman[j] == 6)
                s->bitalloc[j][k] = get_bits(&s->gb, 5);
            else if (s->bitalloc_huffman[j] == 5)
                s->bitalloc[j][k] = get_bits(&s->gb, 4);
            else if (s->bitalloc_huffman[j] == 7) {
                av_log(s->avctx, AV_LOG_ERROR,
                       "Invalid bit allocation index\n");
                return AVERROR_INVALIDDATA;
            } else {
                s->bitalloc[j][k] =
                    get_bitalloc(&s->gb, &dca_bitalloc_index, s->bitalloc_huffman[j]);
            }
            if (s->bitalloc[j][k] > 26) {
                return AVERROR_INVALIDDATA;
            }
        }
    }
    for (j = base_channel; j < s->prim_channels; j++) {
        for (k = 0; k < s->subband_activity[j]; k++) {
            s->transition_mode[j][k] = 0;
            if (s->subsubframes[s->current_subframe] > 1 &&
                k < s->vq_start_subband[j] && s->bitalloc[j][k] > 0) {
                s->transition_mode[j][k] =
                    get_bitalloc(&s->gb, &dca_tmode, s->transient_huffman[j]);
            }
        }
    }
    if (get_bits_left(&s->gb) < 0)
        return AVERROR_INVALIDDATA;
    for (j = base_channel; j < s->prim_channels; j++) {
        const uint32_t *scale_table;
        int scale_sum;
        memset(s->scale_factor[j], 0, s->subband_activity[j] * sizeof(s->scale_factor[0][0][0]) * 2);
        if (s->scalefactor_huffman[j] == 6)
            scale_table = scale_factor_quant7;
        else
            scale_table = scale_factor_quant6;
        scale_sum = 0;
        for (k = 0; k < s->subband_activity[j]; k++) {
            if (k >= s->vq_start_subband[j] || s->bitalloc[j][k] > 0) {
                scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], scale_sum);
                s->scale_factor[j][k][0] = scale_table[scale_sum];
            }
            if (k < s->vq_start_subband[j] && s->transition_mode[j][k]) {
                scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], scale_sum);
                s->scale_factor[j][k][1] = scale_table[scale_sum];
            }
        }
    }
    for (j = base_channel; j < s->prim_channels; j++) {
        if (s->joint_intensity[j] > 0)
            s->joint_huff[j] = get_bits(&s->gb, 3);
    }
    if (get_bits_left(&s->gb) < 0)
        return AVERROR_INVALIDDATA;
    for (j = base_channel; j < s->prim_channels; j++) {
        int source_channel;
        if (s->joint_intensity[j] > 0) {
            int scale = 0;
            source_channel = s->joint_intensity[j] - 1;
            for (k = s->subband_activity[j]; k < s->subband_activity[source_channel]; k++) {
                scale = get_scale(&s->gb, s->joint_huff[j], 0);
                scale += 64;
                s->joint_scale_factor[j][k] = scale;
            }
            if (!(s->debug_flag & 0x02)) {
                av_log(s->avctx, AV_LOG_DEBUG,
                       "Joint stereo coding not supported\n");
                s->debug_flag |= 0x02;
            }
        }
    }
    if (!base_channel && s->prim_channels > 2) {
        if (s->downmix) {
            for (j = base_channel; j < s->prim_channels; j++) {
                s->downmix_coef[j][0] = get_bits(&s->gb, 7);
                s->downmix_coef[j][1] = get_bits(&s->gb, 7);
            }
        } else {
            int am = s->amode & DCA_CHANNEL_MASK;
            for (j = base_channel; j < s->prim_channels; j++) {
                s->downmix_coef[j][0] = dca_default_coeffs[am][j][0];
                s->downmix_coef[j][1] = dca_default_coeffs[am][j][1];
            }
        }
    }
    if (!base_channel && s->dynrange)
        s->dynrange_coef = get_bits(&s->gb, 8);
    if (s->crc_present) {
        get_bits(&s->gb, 16);
    }
    for (j = base_channel; j < s->prim_channels; j++)
        for (k = s->vq_start_subband[j]; k < s->subband_activity[j]; k++)
            s->high_freq_vq[j][k] = get_bits(&s->gb, 10);
    if (!base_channel && s->lfe) {
        int lfe_samples = 2 * s->lfe * (4 + block_index);
        int lfe_end_sample = 2 * s->lfe * (4 + block_index + s->subsubframes[s->current_subframe]);
        float lfe_scale;
        for (j = lfe_samples; j < lfe_end_sample; j++) {
            s->lfe_data[j] = get_sbits(&s->gb, 8);
        }
        s->lfe_scale_factor = scale_factor_quant7[get_bits(&s->gb, 8)];
        lfe_scale = 0.035 * s->lfe_scale_factor;
        for (j = lfe_samples; j < lfe_end_sample; j++)
            s->lfe_data[j] *= lfe_scale;
    }
#ifdef TRACE
    av_log(s->avctx, AV_LOG_DEBUG, "subsubframes: %i\n", s->subsubframes[s->current_subframe]);
    av_log(s->avctx, AV_LOG_DEBUG, "partial samples: %i\n",
           s->partial_samples[s->current_subframe]);
    for (j = base_channel; j < s->prim_channels; j++) {
        av_log(s->avctx, AV_LOG_DEBUG, "prediction mode:");
        for (k = 0; k < s->subband_activity[j]; k++)
            av_log(s->avctx, AV_LOG_DEBUG, " %i", s->prediction_mode[j][k]);
        av_log(s->avctx, AV_LOG_DEBUG, "\n");
    }
    for (j = base_channel; j < s->prim_channels; j++) {
        for (k = 0; k < s->subband_activity[j]; k++)
                av_log(s->avctx, AV_LOG_DEBUG,
                       "prediction coefs: %f, %f, %f, %f\n",
                       (float) adpcm_vb[s->prediction_vq[j][k]][0] / 8192,
                       (float) adpcm_vb[s->prediction_vq[j][k]][1] / 8192,
                       (float) adpcm_vb[s->prediction_vq[j][k]][2] / 8192,
                       (float) adpcm_vb[s->prediction_vq[j][k]][3] / 8192);
    }
    for (j = base_channel; j < s->prim_channels; j++) {
        av_log(s->avctx, AV_LOG_DEBUG, "bitalloc index: ");
        for (k = 0; k < s->vq_start_subband[j]; k++)
            av_log(s->avctx, AV_LOG_DEBUG, "%2.2i ", s->bitalloc[j][k]);
        av_log(s->avctx, AV_LOG_DEBUG, "\n");
    }
    for (j = base_channel; j < s->prim_channels; j++) {
        av_log(s->avctx, AV_LOG_DEBUG, "Transition mode:");
        for (k = 0; k < s->subband_activity[j]; k++)
            av_log(s->avctx, AV_LOG_DEBUG, " %i", s->transition_mode[j][k]);
        av_log(s->avctx, AV_LOG_DEBUG, "\n");
    }
    for (j = base_channel; j < s->prim_channels; j++) {
        av_log(s->avctx, AV_LOG_DEBUG, "Scale factor:");
        for (k = 0; k < s->subband_activity[j]; k++) {
            if (k >= s->vq_start_subband[j] || s->bitalloc[j][k] > 0)
                av_log(s->avctx, AV_LOG_DEBUG, " %i", s->scale_factor[j][k][0]);
            if (k < s->vq_start_subband[j] && s->transition_mode[j][k])
                av_log(s->avctx, AV_LOG_DEBUG, " %i(t)", s->scale_factor[j][k][1]);
        }
        av_log(s->avctx, AV_LOG_DEBUG, "\n");
    }
    for (j = base_channel; j < s->prim_channels; j++) {
        if (s->joint_intensity[j] > 0) {
            int source_channel = s->joint_intensity[j] - 1;
            av_log(s->avctx, AV_LOG_DEBUG, "Joint scale factor index:\n");
            for (k = s->subband_activity[j]; k < s->subband_activity[source_channel]; k++)
                av_log(s->avctx, AV_LOG_DEBUG, " %i", s->joint_scale_factor[j][k]);
            av_log(s->avctx, AV_LOG_DEBUG, "\n");
        }
    }
    if (!base_channel && s->prim_channels > 2 && s->downmix) {
        av_log(s->avctx, AV_LOG_DEBUG, "Downmix coeffs:\n");
        for (j = 0; j < s->prim_channels; j++) {
            av_log(s->avctx, AV_LOG_DEBUG, "Channel 0,%d = %f\n", j, dca_downmix_coeffs[s->downmix_coef[j][0]]);
            av_log(s->avctx, AV_LOG_DEBUG, "Channel 1,%d = %f\n", j, dca_downmix_coeffs[s->downmix_coef[j][1]]);
        }
        av_log(s->avctx, AV_LOG_DEBUG, "\n");
    }
    for (j = base_channel; j < s->prim_channels; j++)
        for (k = s->vq_start_subband[j]; k < s->subband_activity[j]; k++)
            av_log(s->avctx, AV_LOG_DEBUG, "VQ index: %i\n", s->high_freq_vq[j][k]);
    if (!base_channel && s->lfe) {
        int lfe_samples = 2 * s->lfe * (4 + block_index);
        int lfe_end_sample = 2 * s->lfe * (4 + block_index + s->subsubframes[s->current_subframe]);
        av_log(s->avctx, AV_LOG_DEBUG, "LFE samples:\n");
        for (j = lfe_samples; j < lfe_end_sample; j++)
            av_log(s->avctx, AV_LOG_DEBUG, " %f", s->lfe_data[j]);
        av_log(s->avctx, AV_LOG_DEBUG, "\n");
    }
#endif
    return 0;
}
['static int dca_decode_frame(AVCodecContext * avctx,\n                            void *data, int *data_size,\n                            AVPacket *avpkt)\n{\n    const uint8_t *buf = avpkt->data;\n    int buf_size = avpkt->size;\n    int lfe_samples;\n    int num_core_channels = 0;\n    int i, ret;\n    float   *samples_flt = data;\n    int16_t *samples_s16 = data;\n    int out_size;\n    DCAContext *s = avctx->priv_data;\n    int channels;\n    int core_ss_end;\n    s->xch_present = 0;\n    s->dca_buffer_size = dca_convert_bitstream(buf, buf_size, s->dca_buffer,\n                                               DCA_MAX_FRAME_SIZE + DCA_MAX_EXSS_HEADER_SIZE);\n    if (s->dca_buffer_size == AVERROR_INVALIDDATA) {\n        av_log(avctx, AV_LOG_ERROR, "Not a valid DCA frame\\n");\n        return AVERROR_INVALIDDATA;\n    }\n    init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8);\n    if ((ret = dca_parse_frame_header(s)) < 0) {\n        return ret;\n    }\n    avctx->sample_rate = s->sample_rate;\n    avctx->bit_rate = s->bit_rate;\n    avctx->frame_size = s->sample_blocks * 32;\n    s->profile = FF_PROFILE_DTS;\n    for (i = 0; i < (s->sample_blocks / 8); i++) {\n        if ((ret = dca_decode_block(s, 0, i))) {\n            av_log(avctx, AV_LOG_ERROR, "error decoding block\\n");\n            return ret;\n        }\n    }\n    num_core_channels = s->prim_channels;\n    if (s->ext_coding)\n        s->core_ext_mask = dca_ext_audio_descr_mask[s->ext_descr];\n    else\n        s->core_ext_mask = 0;\n    core_ss_end = FFMIN(s->frame_size, s->dca_buffer_size) * 8;\n    if (s->core_ext_mask < 0 || s->core_ext_mask & DCA_EXT_XCH) {\n        s->core_ext_mask = FFMAX(s->core_ext_mask, 0);\n        skip_bits_long(&s->gb, (-get_bits_count(&s->gb)) & 31);\n    while(core_ss_end - get_bits_count(&s->gb) >= 32) {\n        uint32_t bits = get_bits_long(&s->gb, 32);\n        switch(bits) {\n        case 0x5a5a5a5a: {\n            int ext_amode, xch_fsize;\n            s->xch_base_channel = s->prim_channels;\n            xch_fsize = show_bits(&s->gb, 10);\n            if((s->frame_size != (get_bits_count(&s->gb) >> 3) - 4 + xch_fsize) &&\n               (s->frame_size != (get_bits_count(&s->gb) >> 3) - 4 + xch_fsize + 1))\n                continue;\n            skip_bits(&s->gb, 10);\n            s->core_ext_mask |= DCA_EXT_XCH;\n            if ((ext_amode = get_bits(&s->gb, 4)) != 1) {\n                av_log(avctx, AV_LOG_ERROR, "XCh extension amode %d not"\n                       " supported!\\n",ext_amode);\n                continue;\n            }\n            dca_parse_audio_coding_header(s, s->xch_base_channel);\n            for (i = 0; i < (s->sample_blocks / 8); i++) {\n                if ((ret = dca_decode_block(s, s->xch_base_channel, i))) {\n                    av_log(avctx, AV_LOG_ERROR, "error decoding XCh extension\\n");\n                    continue;\n                }\n            }\n            s->xch_present = 1;\n            break;\n        }\n        case 0x47004a03:\n            s->core_ext_mask |= DCA_EXT_XXCH;\n            break;\n        case 0x1d95f262: {\n            int fsize96 = show_bits(&s->gb, 12) + 1;\n            if (s->frame_size != (get_bits_count(&s->gb) >> 3) - 4 + fsize96)\n                continue;\n            av_log(avctx, AV_LOG_DEBUG, "X96 extension found at %d bits\\n", get_bits_count(&s->gb));\n            skip_bits(&s->gb, 12);\n            av_log(avctx, AV_LOG_DEBUG, "FSIZE96 = %d bytes\\n", fsize96);\n            av_log(avctx, AV_LOG_DEBUG, "REVNO = %d\\n", get_bits(&s->gb, 4));\n            s->core_ext_mask |= DCA_EXT_X96;\n            break;\n        }\n        }\n        skip_bits_long(&s->gb, (-get_bits_count(&s->gb)) & 31);\n    }\n    } else {\n        skip_bits_long(&s->gb, core_ss_end - get_bits_count(&s->gb));\n    }\n    if (s->core_ext_mask & DCA_EXT_X96)\n        s->profile = FF_PROFILE_DTS_96_24;\n    else if (s->core_ext_mask & (DCA_EXT_XCH | DCA_EXT_XXCH))\n        s->profile = FF_PROFILE_DTS_ES;\n    if (s->dca_buffer_size - s->frame_size > 32\n        && get_bits_long(&s->gb, 32) == DCA_HD_MARKER)\n        dca_exss_parse_header(s);\n    avctx->profile = s->profile;\n    channels = s->prim_channels + !!s->lfe;\n    if (s->amode<16) {\n        avctx->channel_layout = dca_core_channel_layout[s->amode];\n        if (s->xch_present && (!avctx->request_channels ||\n                               avctx->request_channels > num_core_channels + !!s->lfe)) {\n            avctx->channel_layout |= AV_CH_BACK_CENTER;\n            if (s->lfe) {\n                avctx->channel_layout |= AV_CH_LOW_FREQUENCY;\n                s->channel_order_tab = dca_channel_reorder_lfe_xch[s->amode];\n            } else {\n                s->channel_order_tab = dca_channel_reorder_nolfe_xch[s->amode];\n            }\n        } else {\n            channels = num_core_channels + !!s->lfe;\n            s->xch_present = 0;\n            if (s->lfe) {\n                avctx->channel_layout |= AV_CH_LOW_FREQUENCY;\n                s->channel_order_tab = dca_channel_reorder_lfe[s->amode];\n            } else\n                s->channel_order_tab = dca_channel_reorder_nolfe[s->amode];\n        }\n        if (channels > !!s->lfe &&\n            s->channel_order_tab[channels - 1 - !!s->lfe] < 0)\n            return AVERROR_INVALIDDATA;\n        if (avctx->request_channels == 2 && s->prim_channels > 2) {\n            channels = 2;\n            s->output = DCA_STEREO;\n            avctx->channel_layout = AV_CH_LAYOUT_STEREO;\n        }\n    } else {\n        av_log(avctx, AV_LOG_ERROR, "Non standard configuration %d !\\n",s->amode);\n        return AVERROR_INVALIDDATA;\n    }\n    if (s->is_channels_set == 0) {\n        s->is_channels_set = 1;\n        avctx->channels = channels;\n    }\n    if (avctx->channels != channels) {\n        av_log(avctx, AV_LOG_ERROR, "DCA decoder does not support number of "\n               "channels changing in stream. Skipping frame.\\n");\n        return AVERROR_PATCHWELCOME;\n    }\n    out_size = 256 / 8 * s->sample_blocks * channels *\n               av_get_bytes_per_sample(avctx->sample_fmt);\n    if (*data_size < out_size)\n        return AVERROR(EINVAL);\n    *data_size = out_size;\n    for (i = 0; i < (s->sample_blocks / 8); i++) {\n        dca_filter_channels(s, i);\n        if((s->source_pcm_res & 1) && s->xch_present) {\n            float* back_chan = s->samples + s->channel_order_tab[s->xch_base_channel] * 256;\n            float* lt_chan   = s->samples + s->channel_order_tab[s->xch_base_channel - 2] * 256;\n            float* rt_chan   = s->samples + s->channel_order_tab[s->xch_base_channel - 1] * 256;\n            s->dsp.vector_fmac_scalar(lt_chan, back_chan, -M_SQRT1_2, 256);\n            s->dsp.vector_fmac_scalar(rt_chan, back_chan, -M_SQRT1_2, 256);\n        }\n        if (avctx->sample_fmt == AV_SAMPLE_FMT_FLT) {\n            s->fmt_conv.float_interleave(samples_flt, s->samples_chanptr, 256,\n                                         channels);\n            samples_flt += 256 * channels;\n        } else {\n            s->fmt_conv.float_to_int16_interleave(samples_s16,\n                                                  s->samples_chanptr, 256,\n                                                  channels);\n            samples_s16 += 256 * channels;\n        }\n    }\n    lfe_samples = 2 * s->lfe * (s->sample_blocks / 8);\n    for (i = 0; i < 2 * s->lfe * 4; i++) {\n        s->lfe_data[i] = s->lfe_data[i + lfe_samples];\n    }\n    return buf_size;\n}', 'static int dca_parse_frame_header(DCAContext * s)\n{\n    init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8);\n    get_bits(&s->gb, 32);\n    s->frame_type        = get_bits(&s->gb, 1);\n    s->samples_deficit   = get_bits(&s->gb, 5) + 1;\n    s->crc_present       = get_bits(&s->gb, 1);\n    s->sample_blocks     = get_bits(&s->gb, 7) + 1;\n    s->frame_size        = get_bits(&s->gb, 14) + 1;\n    if (s->frame_size < 95)\n        return AVERROR_INVALIDDATA;\n    s->amode             = get_bits(&s->gb, 6);\n    s->sample_rate       = dca_sample_rates[get_bits(&s->gb, 4)];\n    if (!s->sample_rate)\n        return AVERROR_INVALIDDATA;\n    s->bit_rate_index    = get_bits(&s->gb, 5);\n    s->bit_rate          = dca_bit_rates[s->bit_rate_index];\n    if (!s->bit_rate)\n        return AVERROR_INVALIDDATA;\n    s->downmix           = get_bits(&s->gb, 1);\n    s->dynrange          = get_bits(&s->gb, 1);\n    s->timestamp         = get_bits(&s->gb, 1);\n    s->aux_data          = get_bits(&s->gb, 1);\n    s->hdcd              = get_bits(&s->gb, 1);\n    s->ext_descr         = get_bits(&s->gb, 3);\n    s->ext_coding        = get_bits(&s->gb, 1);\n    s->aspf              = get_bits(&s->gb, 1);\n    s->lfe               = get_bits(&s->gb, 2);\n    s->predictor_history = get_bits(&s->gb, 1);\n    if (s->crc_present)\n        s->header_crc    = get_bits(&s->gb, 16);\n    s->multirate_inter   = get_bits(&s->gb, 1);\n    s->version           = get_bits(&s->gb, 4);\n    s->copy_history      = get_bits(&s->gb, 2);\n    s->source_pcm_res    = get_bits(&s->gb, 3);\n    s->front_sum         = get_bits(&s->gb, 1);\n    s->surround_sum      = get_bits(&s->gb, 1);\n    s->dialog_norm       = get_bits(&s->gb, 4);\n    s->output = s->amode;\n    if (s->lfe) s->output |= DCA_LFE;\n#ifdef TRACE\n    av_log(s->avctx, AV_LOG_DEBUG, "frame type: %i\\n", s->frame_type);\n    av_log(s->avctx, AV_LOG_DEBUG, "samples deficit: %i\\n", s->samples_deficit);\n    av_log(s->avctx, AV_LOG_DEBUG, "crc present: %i\\n", s->crc_present);\n    av_log(s->avctx, AV_LOG_DEBUG, "sample blocks: %i (%i samples)\\n",\n           s->sample_blocks, s->sample_blocks * 32);\n    av_log(s->avctx, AV_LOG_DEBUG, "frame size: %i bytes\\n", s->frame_size);\n    av_log(s->avctx, AV_LOG_DEBUG, "amode: %i (%i channels)\\n",\n           s->amode, dca_channels[s->amode]);\n    av_log(s->avctx, AV_LOG_DEBUG, "sample rate: %i Hz\\n",\n           s->sample_rate);\n    av_log(s->avctx, AV_LOG_DEBUG, "bit rate: %i bits/s\\n",\n           s->bit_rate);\n    av_log(s->avctx, AV_LOG_DEBUG, "downmix: %i\\n", s->downmix);\n    av_log(s->avctx, AV_LOG_DEBUG, "dynrange: %i\\n", s->dynrange);\n    av_log(s->avctx, AV_LOG_DEBUG, "timestamp: %i\\n", s->timestamp);\n    av_log(s->avctx, AV_LOG_DEBUG, "aux_data: %i\\n", s->aux_data);\n    av_log(s->avctx, AV_LOG_DEBUG, "hdcd: %i\\n", s->hdcd);\n    av_log(s->avctx, AV_LOG_DEBUG, "ext descr: %i\\n", s->ext_descr);\n    av_log(s->avctx, AV_LOG_DEBUG, "ext coding: %i\\n", s->ext_coding);\n    av_log(s->avctx, AV_LOG_DEBUG, "aspf: %i\\n", s->aspf);\n    av_log(s->avctx, AV_LOG_DEBUG, "lfe: %i\\n", s->lfe);\n    av_log(s->avctx, AV_LOG_DEBUG, "predictor history: %i\\n",\n           s->predictor_history);\n    av_log(s->avctx, AV_LOG_DEBUG, "header crc: %i\\n", s->header_crc);\n    av_log(s->avctx, AV_LOG_DEBUG, "multirate inter: %i\\n",\n           s->multirate_inter);\n    av_log(s->avctx, AV_LOG_DEBUG, "version number: %i\\n", s->version);\n    av_log(s->avctx, AV_LOG_DEBUG, "copy history: %i\\n", s->copy_history);\n    av_log(s->avctx, AV_LOG_DEBUG,\n           "source pcm resolution: %i (%i bits/sample)\\n",\n           s->source_pcm_res, dca_bits_per_sample[s->source_pcm_res]);\n    av_log(s->avctx, AV_LOG_DEBUG, "front sum: %i\\n", s->front_sum);\n    av_log(s->avctx, AV_LOG_DEBUG, "surround sum: %i\\n", s->surround_sum);\n    av_log(s->avctx, AV_LOG_DEBUG, "dialog norm: %i\\n", s->dialog_norm);\n    av_log(s->avctx, AV_LOG_DEBUG, "\\n");\n#endif\n    s->subframes         = get_bits(&s->gb, 4) + 1;\n    return dca_parse_audio_coding_header(s, 0);\n}', 'static int dca_decode_block(DCAContext * s, int base_channel, int block_index)\n{\n    int ret;\n    if (s->current_subframe >= s->subframes) {\n        av_log(s->avctx, AV_LOG_DEBUG, "check failed: %i>%i",\n               s->current_subframe, s->subframes);\n        return AVERROR_INVALIDDATA;\n    }\n    if (!s->current_subsubframe) {\n#ifdef TRACE\n        av_log(s->avctx, AV_LOG_DEBUG, "DSYNC dca_subframe_header\\n");\n#endif\n        if ((ret = dca_subframe_header(s, base_channel, block_index)))\n            return ret;\n    }\n#ifdef TRACE\n    av_log(s->avctx, AV_LOG_DEBUG, "DSYNC dca_subsubframe\\n");\n#endif\n    if ((ret = dca_subsubframe(s, base_channel, block_index)))\n        return ret;\n    s->current_subsubframe++;\n    if (s->current_subsubframe >= s->subsubframes[s->current_subframe]) {\n        s->current_subsubframe = 0;\n        s->current_subframe++;\n    }\n    if (s->current_subframe >= s->subframes) {\n#ifdef TRACE\n        av_log(s->avctx, AV_LOG_DEBUG, "DSYNC dca_subframe_footer\\n");\n#endif\n        if ((ret = dca_subframe_footer(s, base_channel)))\n            return ret;\n    }\n    return 0;\n}', 'static int dca_subframe_header(DCAContext * s, int base_channel, int block_index)\n{\n    int j, k;\n    if (get_bits_left(&s->gb) < 0)\n        return AVERROR_INVALIDDATA;\n    if (!base_channel) {\n        s->subsubframes[s->current_subframe] = get_bits(&s->gb, 2) + 1;\n        s->partial_samples[s->current_subframe] = get_bits(&s->gb, 3);\n    }\n    for (j = base_channel; j < s->prim_channels; j++) {\n        for (k = 0; k < s->subband_activity[j]; k++)\n            s->prediction_mode[j][k] = get_bits(&s->gb, 1);\n    }\n    for (j = base_channel; j < s->prim_channels; j++) {\n        for (k = 0; k < s->subband_activity[j]; k++) {\n            if (s->prediction_mode[j][k] > 0) {\n                s->prediction_vq[j][k] = get_bits(&s->gb, 12);\n            }\n        }\n    }\n    for (j = base_channel; j < s->prim_channels; j++) {\n        for (k = 0; k < s->vq_start_subband[j]; k++) {\n            if (s->bitalloc_huffman[j] == 6)\n                s->bitalloc[j][k] = get_bits(&s->gb, 5);\n            else if (s->bitalloc_huffman[j] == 5)\n                s->bitalloc[j][k] = get_bits(&s->gb, 4);\n            else if (s->bitalloc_huffman[j] == 7) {\n                av_log(s->avctx, AV_LOG_ERROR,\n                       "Invalid bit allocation index\\n");\n                return AVERROR_INVALIDDATA;\n            } else {\n                s->bitalloc[j][k] =\n                    get_bitalloc(&s->gb, &dca_bitalloc_index, s->bitalloc_huffman[j]);\n            }\n            if (s->bitalloc[j][k] > 26) {\n                return AVERROR_INVALIDDATA;\n            }\n        }\n    }\n    for (j = base_channel; j < s->prim_channels; j++) {\n        for (k = 0; k < s->subband_activity[j]; k++) {\n            s->transition_mode[j][k] = 0;\n            if (s->subsubframes[s->current_subframe] > 1 &&\n                k < s->vq_start_subband[j] && s->bitalloc[j][k] > 0) {\n                s->transition_mode[j][k] =\n                    get_bitalloc(&s->gb, &dca_tmode, s->transient_huffman[j]);\n            }\n        }\n    }\n    if (get_bits_left(&s->gb) < 0)\n        return AVERROR_INVALIDDATA;\n    for (j = base_channel; j < s->prim_channels; j++) {\n        const uint32_t *scale_table;\n        int scale_sum;\n        memset(s->scale_factor[j], 0, s->subband_activity[j] * sizeof(s->scale_factor[0][0][0]) * 2);\n        if (s->scalefactor_huffman[j] == 6)\n            scale_table = scale_factor_quant7;\n        else\n            scale_table = scale_factor_quant6;\n        scale_sum = 0;\n        for (k = 0; k < s->subband_activity[j]; k++) {\n            if (k >= s->vq_start_subband[j] || s->bitalloc[j][k] > 0) {\n                scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], scale_sum);\n                s->scale_factor[j][k][0] = scale_table[scale_sum];\n            }\n            if (k < s->vq_start_subband[j] && s->transition_mode[j][k]) {\n                scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], scale_sum);\n                s->scale_factor[j][k][1] = scale_table[scale_sum];\n            }\n        }\n    }\n    for (j = base_channel; j < s->prim_channels; j++) {\n        if (s->joint_intensity[j] > 0)\n            s->joint_huff[j] = get_bits(&s->gb, 3);\n    }\n    if (get_bits_left(&s->gb) < 0)\n        return AVERROR_INVALIDDATA;\n    for (j = base_channel; j < s->prim_channels; j++) {\n        int source_channel;\n        if (s->joint_intensity[j] > 0) {\n            int scale = 0;\n            source_channel = s->joint_intensity[j] - 1;\n            for (k = s->subband_activity[j]; k < s->subband_activity[source_channel]; k++) {\n                scale = get_scale(&s->gb, s->joint_huff[j], 0);\n                scale += 64;\n                s->joint_scale_factor[j][k] = scale;\n            }\n            if (!(s->debug_flag & 0x02)) {\n                av_log(s->avctx, AV_LOG_DEBUG,\n                       "Joint stereo coding not supported\\n");\n                s->debug_flag |= 0x02;\n            }\n        }\n    }\n    if (!base_channel && s->prim_channels > 2) {\n        if (s->downmix) {\n            for (j = base_channel; j < s->prim_channels; j++) {\n                s->downmix_coef[j][0] = get_bits(&s->gb, 7);\n                s->downmix_coef[j][1] = get_bits(&s->gb, 7);\n            }\n        } else {\n            int am = s->amode & DCA_CHANNEL_MASK;\n            for (j = base_channel; j < s->prim_channels; j++) {\n                s->downmix_coef[j][0] = dca_default_coeffs[am][j][0];\n                s->downmix_coef[j][1] = dca_default_coeffs[am][j][1];\n            }\n        }\n    }\n    if (!base_channel && s->dynrange)\n        s->dynrange_coef = get_bits(&s->gb, 8);\n    if (s->crc_present) {\n        get_bits(&s->gb, 16);\n    }\n    for (j = base_channel; j < s->prim_channels; j++)\n        for (k = s->vq_start_subband[j]; k < s->subband_activity[j]; k++)\n            s->high_freq_vq[j][k] = get_bits(&s->gb, 10);\n    if (!base_channel && s->lfe) {\n        int lfe_samples = 2 * s->lfe * (4 + block_index);\n        int lfe_end_sample = 2 * s->lfe * (4 + block_index + s->subsubframes[s->current_subframe]);\n        float lfe_scale;\n        for (j = lfe_samples; j < lfe_end_sample; j++) {\n            s->lfe_data[j] = get_sbits(&s->gb, 8);\n        }\n        s->lfe_scale_factor = scale_factor_quant7[get_bits(&s->gb, 8)];\n        lfe_scale = 0.035 * s->lfe_scale_factor;\n        for (j = lfe_samples; j < lfe_end_sample; j++)\n            s->lfe_data[j] *= lfe_scale;\n    }\n#ifdef TRACE\n    av_log(s->avctx, AV_LOG_DEBUG, "subsubframes: %i\\n", s->subsubframes[s->current_subframe]);\n    av_log(s->avctx, AV_LOG_DEBUG, "partial samples: %i\\n",\n           s->partial_samples[s->current_subframe]);\n    for (j = base_channel; j < s->prim_channels; j++) {\n        av_log(s->avctx, AV_LOG_DEBUG, "prediction mode:");\n        for (k = 0; k < s->subband_activity[j]; k++)\n            av_log(s->avctx, AV_LOG_DEBUG, " %i", s->prediction_mode[j][k]);\n        av_log(s->avctx, AV_LOG_DEBUG, "\\n");\n    }\n    for (j = base_channel; j < s->prim_channels; j++) {\n        for (k = 0; k < s->subband_activity[j]; k++)\n                av_log(s->avctx, AV_LOG_DEBUG,\n                       "prediction coefs: %f, %f, %f, %f\\n",\n                       (float) adpcm_vb[s->prediction_vq[j][k]][0] / 8192,\n                       (float) adpcm_vb[s->prediction_vq[j][k]][1] / 8192,\n                       (float) adpcm_vb[s->prediction_vq[j][k]][2] / 8192,\n                       (float) adpcm_vb[s->prediction_vq[j][k]][3] / 8192);\n    }\n    for (j = base_channel; j < s->prim_channels; j++) {\n        av_log(s->avctx, AV_LOG_DEBUG, "bitalloc index: ");\n        for (k = 0; k < s->vq_start_subband[j]; k++)\n            av_log(s->avctx, AV_LOG_DEBUG, "%2.2i ", s->bitalloc[j][k]);\n        av_log(s->avctx, AV_LOG_DEBUG, "\\n");\n    }\n    for (j = base_channel; j < s->prim_channels; j++) {\n        av_log(s->avctx, AV_LOG_DEBUG, "Transition mode:");\n        for (k = 0; k < s->subband_activity[j]; k++)\n            av_log(s->avctx, AV_LOG_DEBUG, " %i", s->transition_mode[j][k]);\n        av_log(s->avctx, AV_LOG_DEBUG, "\\n");\n    }\n    for (j = base_channel; j < s->prim_channels; j++) {\n        av_log(s->avctx, AV_LOG_DEBUG, "Scale factor:");\n        for (k = 0; k < s->subband_activity[j]; k++) {\n            if (k >= s->vq_start_subband[j] || s->bitalloc[j][k] > 0)\n                av_log(s->avctx, AV_LOG_DEBUG, " %i", s->scale_factor[j][k][0]);\n            if (k < s->vq_start_subband[j] && s->transition_mode[j][k])\n                av_log(s->avctx, AV_LOG_DEBUG, " %i(t)", s->scale_factor[j][k][1]);\n        }\n        av_log(s->avctx, AV_LOG_DEBUG, "\\n");\n    }\n    for (j = base_channel; j < s->prim_channels; j++) {\n        if (s->joint_intensity[j] > 0) {\n            int source_channel = s->joint_intensity[j] - 1;\n            av_log(s->avctx, AV_LOG_DEBUG, "Joint scale factor index:\\n");\n            for (k = s->subband_activity[j]; k < s->subband_activity[source_channel]; k++)\n                av_log(s->avctx, AV_LOG_DEBUG, " %i", s->joint_scale_factor[j][k]);\n            av_log(s->avctx, AV_LOG_DEBUG, "\\n");\n        }\n    }\n    if (!base_channel && s->prim_channels > 2 && s->downmix) {\n        av_log(s->avctx, AV_LOG_DEBUG, "Downmix coeffs:\\n");\n        for (j = 0; j < s->prim_channels; j++) {\n            av_log(s->avctx, AV_LOG_DEBUG, "Channel 0,%d = %f\\n", j, dca_downmix_coeffs[s->downmix_coef[j][0]]);\n            av_log(s->avctx, AV_LOG_DEBUG, "Channel 1,%d = %f\\n", j, dca_downmix_coeffs[s->downmix_coef[j][1]]);\n        }\n        av_log(s->avctx, AV_LOG_DEBUG, "\\n");\n    }\n    for (j = base_channel; j < s->prim_channels; j++)\n        for (k = s->vq_start_subband[j]; k < s->subband_activity[j]; k++)\n            av_log(s->avctx, AV_LOG_DEBUG, "VQ index: %i\\n", s->high_freq_vq[j][k]);\n    if (!base_channel && s->lfe) {\n        int lfe_samples = 2 * s->lfe * (4 + block_index);\n        int lfe_end_sample = 2 * s->lfe * (4 + block_index + s->subsubframes[s->current_subframe]);\n        av_log(s->avctx, AV_LOG_DEBUG, "LFE samples:\\n");\n        for (j = lfe_samples; j < lfe_end_sample; j++)\n            av_log(s->avctx, AV_LOG_DEBUG, " %f", s->lfe_data[j]);\n        av_log(s->avctx, AV_LOG_DEBUG, "\\n");\n    }\n#endif\n    return 0;\n}']