static inline int coupling_strategy(AC3DecodeContext *s, int blk,

                                    uint8_t *bit_alloc_stages)

{

    GetBitContext *bc = &s->gbc;

    int fbw_channels = s->fbw_channels;

    int channel_mode = s->channel_mode;

    int ch;



    memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS);

    if (!s->eac3)

        s->cpl_in_use[blk] = get_bits1(bc);

    if (s->cpl_in_use[blk]) {

        /* coupling in use */

        int cpl_start_subband, cpl_end_subband;



        if (channel_mode < AC3_CHMODE_STEREO) {

            av_log(s->avctx, AV_LOG_ERROR, "coupling not allowed in mono or dual-mono\n");

            return AVERROR_INVALIDDATA;

        }



        /* check for enhanced coupling */

        if (s->eac3 && get_bits1(bc)) {

            /* TODO: parse enhanced coupling strategy info */

            avpriv_request_sample(s->avctx, "Enhanced coupling");

            return AVERROR_PATCHWELCOME;

        }



        /* determine which channels are coupled */

        if (s->eac3 && s->channel_mode == AC3_CHMODE_STEREO) {

            s->channel_in_cpl[1] = 1;

            s->channel_in_cpl[2] = 1;

        } else {

            for (ch = 1; ch <= fbw_channels; ch++)

                s->channel_in_cpl[ch] = get_bits1(bc);

        }



        /* phase flags in use */

        if (channel_mode == AC3_CHMODE_STEREO)

            s->phase_flags_in_use = get_bits1(bc);



        /* coupling frequency range */

        cpl_start_subband = get_bits(bc, 4);

        cpl_end_subband = s->spx_in_use ? (s->spx_src_start_freq - 37) / 12 :

                                          get_bits(bc, 4) + 3;

        if (cpl_start_subband >= cpl_end_subband) {

            av_log(s->avctx, AV_LOG_ERROR, "invalid coupling range (%d >= %d)\n",

                   cpl_start_subband, cpl_end_subband);

            return AVERROR_INVALIDDATA;

        }

        s->start_freq[CPL_CH] = cpl_start_subband * 12 + 37;

        s->end_freq[CPL_CH]   = cpl_end_subband   * 12 + 37;



        decode_band_structure(bc, blk, s->eac3, 0, cpl_start_subband,

                              cpl_end_subband,

                              ff_eac3_default_cpl_band_struct,

                              &s->num_cpl_bands, s->cpl_band_sizes);

    } else {

        /* coupling not in use */

        for (ch = 1; ch <= fbw_channels; ch++) {

            s->channel_in_cpl[ch] = 0;

            s->first_cpl_coords[ch] = 1;

        }

        s->first_cpl_leak = s->eac3;

        s->phase_flags_in_use = 0;

    }



    return 0;

}

static inline int coupling_strategy(AC3DecodeContext *s, int blk,

                                    uint8_t *bit_alloc_stages)

{

    GetBitContext *bc = &s->gbc;

    int fbw_channels = s->fbw_channels;

    int channel_mode = s->channel_mode;

    int ch;



    memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS);

    if (!s->eac3)

        s->cpl_in_use[blk] = get_bits1(bc);

    if (s->cpl_in_use[blk]) {

        

        int cpl_start_subband, cpl_end_subband;



        if (channel_mode < AC3_CHMODE_STEREO) {

            av_log(s->avctx, AV_LOG_ERROR, "coupling not allowed in mono or dual-mono\n");

            return AVERROR_INVALIDDATA;

        }



        

        if (s->eac3 && get_bits1(bc)) {

            

            avpriv_request_sample(s->avctx, "Enhanced coupling");

            return AVERROR_PATCHWELCOME;

        }



        

        if (s->eac3 && s->channel_mode == AC3_CHMODE_STEREO) {

            s->channel_in_cpl[1] = 1;

            s->channel_in_cpl[2] = 1;

        } else {

            for (ch = 1; ch <= fbw_channels; ch++)

                s->channel_in_cpl[ch] = get_bits1(bc);

        }



        

        if (channel_mode == AC3_CHMODE_STEREO)

            s->phase_flags_in_use = get_bits1(bc);



        

        cpl_start_subband = get_bits(bc, 4);

        cpl_end_subband = s->spx_in_use ? (s->spx_src_start_freq - 37) / 12 :

                                          get_bits(bc, 4) + 3;

        if (cpl_start_subband >= cpl_end_subband) {

            av_log(s->avctx, AV_LOG_ERROR, "invalid coupling range (%d >= %d)\n",

                   cpl_start_subband, cpl_end_subband);

            return AVERROR_INVALIDDATA;

        }

        s->start_freq[CPL_CH] = cpl_start_subband * 12 + 37;

        s->end_freq[CPL_CH]   = cpl_end_subband   * 12 + 37;



        decode_band_structure(bc, blk, s->eac3, 0, cpl_start_subband,

                              cpl_end_subband,

                              ff_eac3_default_cpl_band_struct,

                              &s->num_cpl_bands, s->cpl_band_sizes);

    } else {

        

        for (ch = 1; ch <= fbw_channels; ch++) {

            s->channel_in_cpl[ch] = 0;

            s->first_cpl_coords[ch] = 1;

        }

        s->first_cpl_leak = s->eac3;

        s->phase_flags_in_use = 0;

    }



    return 0;

}

    } else {                               &s->num_cpl_bands, s->cpl_band_sizes);
static inline int FUNC_0(AC3DecodeContext *VAR_0, int VAR_1,

                                    uint8_t *VAR_2)

{

    GetBitContext *bc = &VAR_0->gbc;

    int VAR_3 = VAR_0->VAR_3;

    int VAR_4 = VAR_0->VAR_4;

    int VAR_5;



    memset(VAR_2, 3, AC3_MAX_CHANNELS);

    if (!VAR_0->eac3)

        VAR_0->cpl_in_use[VAR_1] = get_bits1(bc);

    if (VAR_0->cpl_in_use[VAR_1]) {

        

        int VAR_6, VAR_7;



        if (VAR_4 < AC3_CHMODE_STEREO) {

            av_log(VAR_0->avctx, AV_LOG_ERROR, "coupling not allowed in mono or dual-mono\n");

            return AVERROR_INVALIDDATA;

        }



        

        if (VAR_0->eac3 && get_bits1(bc)) {

            

            avpriv_request_sample(VAR_0->avctx, "Enhanced coupling");

            return AVERROR_PATCHWELCOME;

        }



        

        if (VAR_0->eac3 && VAR_0->VAR_4 == AC3_CHMODE_STEREO) {

            VAR_0->channel_in_cpl[1] = 1;

            VAR_0->channel_in_cpl[2] = 1;

        } else {

            for (VAR_5 = 1; VAR_5 <= VAR_3; VAR_5++)

                VAR_0->channel_in_cpl[VAR_5] = get_bits1(bc);

        }



        

        if (VAR_4 == AC3_CHMODE_STEREO)

            VAR_0->phase_flags_in_use = get_bits1(bc);



        

        VAR_6 = get_bits(bc, 4);

        VAR_7 = VAR_0->spx_in_use ? (VAR_0->spx_src_start_freq - 37) / 12 :

                                          get_bits(bc, 4) + 3;

        if (VAR_6 >= VAR_7) {

            av_log(VAR_0->avctx, AV_LOG_ERROR, "invalid coupling range (%d >= %d)\n",

                   VAR_6, VAR_7);

            return AVERROR_INVALIDDATA;

        }

        VAR_0->start_freq[CPL_CH] = VAR_6 * 12 + 37;

        VAR_0->end_freq[CPL_CH]   = VAR_7   * 12 + 37;



        decode_band_structure(bc, VAR_1, VAR_0->eac3, 0, VAR_6,

                              VAR_7,

                              ff_eac3_default_cpl_band_struct,

                              &VAR_0->num_cpl_bands, VAR_0->cpl_band_sizes);

    } else {

        

        for (VAR_5 = 1; VAR_5 <= VAR_3; VAR_5++) {

            VAR_0->channel_in_cpl[VAR_5] = 0;

            VAR_0->first_cpl_coords[VAR_5] = 1;

        }

        VAR_0->first_cpl_leak = VAR_0->eac3;

        VAR_0->phase_flags_in_use = 0;

    }



    return 0;

}

static inline int FUNC_0(AC3DecodeContext *VAR_0, int VAR_1,
uint8_t *VAR_2)
{ GetBitContext *bc = &VAR_0->gbc; int VAR_3 = VAR_0->VAR_3; int VAR_4 = VAR_0->VAR_4; int VAR_5; memset(VAR_2, 3, AC3_MAX_CHANNELS); if (!VAR_0->eac3)
VAR_0->cpl_in_use[VAR_1] = get_bits1(bc); if (VAR_0->cpl_in_use[VAR_1]) { int VAR_6, VAR_7; if (VAR_4 < AC3_CHMODE_STEREO) { av_log(VAR_0->avctx, AV_LOG_ERROR, "coupling not allowed in mono or dual-mono\n"); return AVERROR_INVALIDDATA; } if (VAR_0->eac3 && get_bits1(bc)) { avpriv_request_sample(VAR_0->avctx, "Enhanced coupling"); return AVERROR_PATCHWELCOME; } if (VAR_0->eac3 && VAR_0->VAR_4 == AC3_CHMODE_STEREO) { VAR_0->channel_in_cpl[1] = 1; VAR_0->channel_in_cpl[2] = 1; } else { for (VAR_5 = 1; VAR_5 <= VAR_3; VAR_5++) VAR_0->channel_in_cpl[VAR_5] = get_bits1(bc); } if (VAR_4 == AC3_CHMODE_STEREO)
VAR_0->phase_flags_in_use = get_bits1(bc); VAR_6 = get_bits(bc, 4); VAR_7 = VAR_0->spx_in_use ? (VAR_0->spx_src_start_freq - 37) / 12 :
get_bits(bc, 4) + 3; if (VAR_6 >= VAR_7) { av_log(VAR_0->avctx, AV_LOG_ERROR, "invalid coupling range (%d >= %d)\n",
VAR_6, VAR_7); return AVERROR_INVALIDDATA; } VAR_0->start_freq[CPL_CH] = VAR_6 * 12 + 37; VAR_0->end_freq[CPL_CH]   = VAR_7   * 12 + 37; decode_band_structure(bc, VAR_1, VAR_0->eac3, 0, VAR_6,
VAR_7,
ff_eac3_default_cpl_band_struct,
&VAR_0->num_cpl_bands, VAR_0->cpl_band_sizes); } else { for (VAR_5 = 1; VAR_5 <= VAR_3; VAR_5++) { VAR_0->channel_in_cpl[VAR_5] = 0; VAR_0->first_cpl_coords[VAR_5] = 1; } VAR_0->first_cpl_leak = VAR_0->eac3; VAR_0->phase_flags_in_use = 0; } return 0; }