int AAC_RENAME(ff_ps_read_data)(AVCodecContext *avctx, GetBitContext *gb_host, PSContext *ps, int bits_left)

{

    int e;

    int bit_count_start = get_bits_count(gb_host);

    int header;

    int bits_consumed;

    GetBitContext gbc = *gb_host, *gb = &gbc;



    header = get_bits1(gb);

    if (header) {     //enable_ps_header

        ps->enable_iid = get_bits1(gb);

        if (ps->enable_iid) {

            int iid_mode = get_bits(gb, 3);

            if (iid_mode > 5) {

                av_log(avctx, AV_LOG_ERROR, "iid_mode %d is reserved.\n",

                       iid_mode);

                goto err;

            }

            ps->nr_iid_par    = nr_iidicc_par_tab[iid_mode];

            ps->iid_quant     = iid_mode > 2;

            ps->nr_ipdopd_par = nr_iidopd_par_tab[iid_mode];

        }

        ps->enable_icc = get_bits1(gb);

        if (ps->enable_icc) {

            ps->icc_mode = get_bits(gb, 3);

            if (ps->icc_mode > 5) {

                av_log(avctx, AV_LOG_ERROR, "icc_mode %d is reserved.\n",

                       ps->icc_mode);

                goto err;

            }

            ps->nr_icc_par = nr_iidicc_par_tab[ps->icc_mode];

        }

        ps->enable_ext = get_bits1(gb);

    }



    ps->frame_class = get_bits1(gb);

    ps->num_env_old = ps->num_env;

    ps->num_env     = num_env_tab[ps->frame_class][get_bits(gb, 2)];



    ps->border_position[0] = -1;

    if (ps->frame_class) {

        for (e = 1; e <= ps->num_env; e++)

            ps->border_position[e] = get_bits(gb, 5);

    } else

        for (e = 1; e <= ps->num_env; e++)

            ps->border_position[e] = (e * numQMFSlots >> ff_log2_tab[ps->num_env]) - 1;



    if (ps->enable_iid) {

        for (e = 0; e < ps->num_env; e++) {

            int dt = get_bits1(gb);

            if (read_iid_data(avctx, gb, ps, ps->iid_par, huff_iid[2*dt+ps->iid_quant], e, dt))

                goto err;

        }

    } else

        memset(ps->iid_par, 0, sizeof(ps->iid_par));



    if (ps->enable_icc)

        for (e = 0; e < ps->num_env; e++) {

            int dt = get_bits1(gb);

            if (read_icc_data(avctx, gb, ps, ps->icc_par, dt ? huff_icc_dt : huff_icc_df, e, dt))

                goto err;

        }

    else

        memset(ps->icc_par, 0, sizeof(ps->icc_par));



    if (ps->enable_ext) {

        int cnt = get_bits(gb, 4);

        if (cnt == 15) {

            cnt += get_bits(gb, 8);

        }

        cnt *= 8;

        while (cnt > 7) {

            int ps_extension_id = get_bits(gb, 2);

            cnt -= 2 + ps_read_extension_data(gb, ps, ps_extension_id);

        }

        if (cnt < 0) {

            av_log(avctx, AV_LOG_ERROR, "ps extension overflow %d\n", cnt);

            goto err;

        }

        skip_bits(gb, cnt);

    }



    ps->enable_ipdopd &= !PS_BASELINE;



    //Fix up envelopes

    if (!ps->num_env || ps->border_position[ps->num_env] < numQMFSlots - 1) {

        //Create a fake envelope

        int source = ps->num_env ? ps->num_env - 1 : ps->num_env_old - 1;

        int b;

        if (source >= 0 && source != ps->num_env) {

            if (ps->enable_iid) {

                memcpy(ps->iid_par+ps->num_env, ps->iid_par+source, sizeof(ps->iid_par[0]));

            }

            if (ps->enable_icc) {

                memcpy(ps->icc_par+ps->num_env, ps->icc_par+source, sizeof(ps->icc_par[0]));

            }

            if (ps->enable_ipdopd) {

                memcpy(ps->ipd_par+ps->num_env, ps->ipd_par+source, sizeof(ps->ipd_par[0]));

                memcpy(ps->opd_par+ps->num_env, ps->opd_par+source, sizeof(ps->opd_par[0]));

            }

        }

        if (ps->enable_iid){

            for (b = 0; b < ps->nr_iid_par; b++) {

                if (FFABS(ps->iid_par[ps->num_env][b]) > 7 + 8 * ps->iid_quant) {

                    av_log(avctx, AV_LOG_ERROR, "iid_par invalid\n");

                    goto err;

                }

            }

        }

        if (ps->enable_icc){

            for (b = 0; b < ps->nr_iid_par; b++) {

                if (ps->icc_par[ps->num_env][b] > 7U) {

                    av_log(avctx, AV_LOG_ERROR, "icc_par invalid\n");

                    goto err;

                }

            }

        }

        ps->num_env++;

        ps->border_position[ps->num_env] = numQMFSlots - 1;

    }





    ps->is34bands_old = ps->is34bands;

    if (!PS_BASELINE && (ps->enable_iid || ps->enable_icc))

        ps->is34bands = (ps->enable_iid && ps->nr_iid_par == 34) ||

                        (ps->enable_icc && ps->nr_icc_par == 34);



    //Baseline

    if (!ps->enable_ipdopd) {

        memset(ps->ipd_par, 0, sizeof(ps->ipd_par));

        memset(ps->opd_par, 0, sizeof(ps->opd_par));

    }



    if (header)

        ps->start = 1;



    bits_consumed = get_bits_count(gb) - bit_count_start;

    if (bits_consumed <= bits_left) {

        skip_bits_long(gb_host, bits_consumed);

        return bits_consumed;

    }

    av_log(avctx, AV_LOG_ERROR, "Expected to read %d PS bits actually read %d.\n", bits_left, bits_consumed);

err:

    ps->start = 0;

    skip_bits_long(gb_host, bits_left);

    memset(ps->iid_par, 0, sizeof(ps->iid_par));

    memset(ps->icc_par, 0, sizeof(ps->icc_par));

    memset(ps->ipd_par, 0, sizeof(ps->ipd_par));

    memset(ps->opd_par, 0, sizeof(ps->opd_par));

    return bits_left;

}

int AAC_RENAME(ff_ps_read_data)(AVCodecContext *avctx, GetBitContext *gb_host, PSContext *ps, int bits_left)

{

    int e;

    int bit_count_start = get_bits_count(gb_host);

    int header;

    int bits_consumed;

    GetBitContext gbc = *gb_host, *gb = &gbc;



    header = get_bits1(gb);

    if (header) {     

        ps->enable_iid = get_bits1(gb);

        if (ps->enable_iid) {

            int iid_mode = get_bits(gb, 3);

            if (iid_mode > 5) {

                av_log(avctx, AV_LOG_ERROR, "iid_mode %d is reserved.\n",

                       iid_mode);

                goto err;

            }

            ps->nr_iid_par    = nr_iidicc_par_tab[iid_mode];

            ps->iid_quant     = iid_mode > 2;

            ps->nr_ipdopd_par = nr_iidopd_par_tab[iid_mode];

        }

        ps->enable_icc = get_bits1(gb);

        if (ps->enable_icc) {

            ps->icc_mode = get_bits(gb, 3);

            if (ps->icc_mode > 5) {

                av_log(avctx, AV_LOG_ERROR, "icc_mode %d is reserved.\n",

                       ps->icc_mode);

                goto err;

            }

            ps->nr_icc_par = nr_iidicc_par_tab[ps->icc_mode];

        }

        ps->enable_ext = get_bits1(gb);

    }



    ps->frame_class = get_bits1(gb);

    ps->num_env_old = ps->num_env;

    ps->num_env     = num_env_tab[ps->frame_class][get_bits(gb, 2)];



    ps->border_position[0] = -1;

    if (ps->frame_class) {

        for (e = 1; e <= ps->num_env; e++)

            ps->border_position[e] = get_bits(gb, 5);

    } else

        for (e = 1; e <= ps->num_env; e++)

            ps->border_position[e] = (e * numQMFSlots >> ff_log2_tab[ps->num_env]) - 1;



    if (ps->enable_iid) {

        for (e = 0; e < ps->num_env; e++) {

            int dt = get_bits1(gb);

            if (read_iid_data(avctx, gb, ps, ps->iid_par, huff_iid[2*dt+ps->iid_quant], e, dt))

                goto err;

        }

    } else

        memset(ps->iid_par, 0, sizeof(ps->iid_par));



    if (ps->enable_icc)

        for (e = 0; e < ps->num_env; e++) {

            int dt = get_bits1(gb);

            if (read_icc_data(avctx, gb, ps, ps->icc_par, dt ? huff_icc_dt : huff_icc_df, e, dt))

                goto err;

        }

    else

        memset(ps->icc_par, 0, sizeof(ps->icc_par));



    if (ps->enable_ext) {

        int cnt = get_bits(gb, 4);

        if (cnt == 15) {

            cnt += get_bits(gb, 8);

        }

        cnt *= 8;

        while (cnt > 7) {

            int ps_extension_id = get_bits(gb, 2);

            cnt -= 2 + ps_read_extension_data(gb, ps, ps_extension_id);

        }

        if (cnt < 0) {

            av_log(avctx, AV_LOG_ERROR, "ps extension overflow %d\n", cnt);

            goto err;

        }

        skip_bits(gb, cnt);

    }



    ps->enable_ipdopd &= !PS_BASELINE;



    

    if (!ps->num_env || ps->border_position[ps->num_env] < numQMFSlots - 1) {

        

        int source = ps->num_env ? ps->num_env - 1 : ps->num_env_old - 1;

        int b;

        if (source >= 0 && source != ps->num_env) {

            if (ps->enable_iid) {

                memcpy(ps->iid_par+ps->num_env, ps->iid_par+source, sizeof(ps->iid_par[0]));

            }

            if (ps->enable_icc) {

                memcpy(ps->icc_par+ps->num_env, ps->icc_par+source, sizeof(ps->icc_par[0]));

            }

            if (ps->enable_ipdopd) {

                memcpy(ps->ipd_par+ps->num_env, ps->ipd_par+source, sizeof(ps->ipd_par[0]));

                memcpy(ps->opd_par+ps->num_env, ps->opd_par+source, sizeof(ps->opd_par[0]));

            }

        }

        if (ps->enable_iid){

            for (b = 0; b < ps->nr_iid_par; b++) {

                if (FFABS(ps->iid_par[ps->num_env][b]) > 7 + 8 * ps->iid_quant) {

                    av_log(avctx, AV_LOG_ERROR, "iid_par invalid\n");

                    goto err;

                }

            }

        }

        if (ps->enable_icc){

            for (b = 0; b < ps->nr_iid_par; b++) {

                if (ps->icc_par[ps->num_env][b] > 7U) {

                    av_log(avctx, AV_LOG_ERROR, "icc_par invalid\n");

                    goto err;

                }

            }

        }

        ps->num_env++;

        ps->border_position[ps->num_env] = numQMFSlots - 1;

    }





    ps->is34bands_old = ps->is34bands;

    if (!PS_BASELINE && (ps->enable_iid || ps->enable_icc))

        ps->is34bands = (ps->enable_iid && ps->nr_iid_par == 34) ||

                        (ps->enable_icc && ps->nr_icc_par == 34);



    

    if (!ps->enable_ipdopd) {

        memset(ps->ipd_par, 0, sizeof(ps->ipd_par));

        memset(ps->opd_par, 0, sizeof(ps->opd_par));

    }



    if (header)

        ps->start = 1;



    bits_consumed = get_bits_count(gb) - bit_count_start;

    if (bits_consumed <= bits_left) {

        skip_bits_long(gb_host, bits_consumed);

        return bits_consumed;

    }

    av_log(avctx, AV_LOG_ERROR, "Expected to read %d PS bits actually read %d.\n", bits_left, bits_consumed);

err:

    ps->start = 0;

    skip_bits_long(gb_host, bits_left);

    memset(ps->iid_par, 0, sizeof(ps->iid_par));

    memset(ps->icc_par, 0, sizeof(ps->icc_par));

    memset(ps->ipd_par, 0, sizeof(ps->ipd_par));

    memset(ps->opd_par, 0, sizeof(ps->opd_par));

    return bits_left;

}

        for (e = 1; e <= ps->num_env; e++)
int FUNC_0(ff_ps_read_data)(AVCodecContext *avctx, GetBitContext *gb_host, PSContext *ps, int bits_left)

{

    int VAR_0;

    int VAR_1 = get_bits_count(gb_host);

    int VAR_2;

    int VAR_3;

    GetBitContext gbc = *gb_host, *gb = &gbc;



    VAR_2 = get_bits1(gb);

    if (VAR_2) {     

        ps->enable_iid = get_bits1(gb);

        if (ps->enable_iid) {

            int VAR_4 = get_bits(gb, 3);

            if (VAR_4 > 5) {

                av_log(avctx, AV_LOG_ERROR, "VAR_4 %d is reserved.\n",

                       VAR_4);

                goto err;

            }

            ps->nr_iid_par    = nr_iidicc_par_tab[VAR_4];

            ps->iid_quant     = VAR_4 > 2;

            ps->nr_ipdopd_par = nr_iidopd_par_tab[VAR_4];

        }

        ps->enable_icc = get_bits1(gb);

        if (ps->enable_icc) {

            ps->icc_mode = get_bits(gb, 3);

            if (ps->icc_mode > 5) {

                av_log(avctx, AV_LOG_ERROR, "icc_mode %d is reserved.\n",

                       ps->icc_mode);

                goto err;

            }

            ps->nr_icc_par = nr_iidicc_par_tab[ps->icc_mode];

        }

        ps->enable_ext = get_bits1(gb);

    }



    ps->frame_class = get_bits1(gb);

    ps->num_env_old = ps->num_env;

    ps->num_env     = num_env_tab[ps->frame_class][get_bits(gb, 2)];



    ps->border_position[0] = -1;

    if (ps->frame_class) {

        for (VAR_0 = 1; VAR_0 <= ps->num_env; VAR_0++)

            ps->border_position[VAR_0] = get_bits(gb, 5);

    } else

        for (VAR_0 = 1; VAR_0 <= ps->num_env; VAR_0++)

            ps->border_position[VAR_0] = (VAR_0 * numQMFSlots >> ff_log2_tab[ps->num_env]) - 1;



    if (ps->enable_iid) {

        for (VAR_0 = 0; VAR_0 < ps->num_env; VAR_0++) {

            int dt = get_bits1(gb);

            if (read_iid_data(avctx, gb, ps, ps->iid_par, huff_iid[2*dt+ps->iid_quant], VAR_0, dt))

                goto err;

        }

    } else

        memset(ps->iid_par, 0, sizeof(ps->iid_par));



    if (ps->enable_icc)

        for (VAR_0 = 0; VAR_0 < ps->num_env; VAR_0++) {

            int dt = get_bits1(gb);

            if (read_icc_data(avctx, gb, ps, ps->icc_par, dt ? huff_icc_dt : huff_icc_df, VAR_0, dt))

                goto err;

        }

    else

        memset(ps->icc_par, 0, sizeof(ps->icc_par));



    if (ps->enable_ext) {

        int VAR_5 = get_bits(gb, 4);

        if (VAR_5 == 15) {

            VAR_5 += get_bits(gb, 8);

        }

        VAR_5 *= 8;

        while (VAR_5 > 7) {

            int VAR_6 = get_bits(gb, 2);

            VAR_5 -= 2 + ps_read_extension_data(gb, ps, VAR_6);

        }

        if (VAR_5 < 0) {

            av_log(avctx, AV_LOG_ERROR, "ps extension overflow %d\n", VAR_5);

            goto err;

        }

        skip_bits(gb, VAR_5);

    }



    ps->enable_ipdopd &= !PS_BASELINE;



    

    if (!ps->num_env || ps->border_position[ps->num_env] < numQMFSlots - 1) {

        

        int VAR_7 = ps->num_env ? ps->num_env - 1 : ps->num_env_old - 1;

        int VAR_8;

        if (VAR_7 >= 0 && VAR_7 != ps->num_env) {

            if (ps->enable_iid) {

                memcpy(ps->iid_par+ps->num_env, ps->iid_par+VAR_7, sizeof(ps->iid_par[0]));

            }

            if (ps->enable_icc) {

                memcpy(ps->icc_par+ps->num_env, ps->icc_par+VAR_7, sizeof(ps->icc_par[0]));

            }

            if (ps->enable_ipdopd) {

                memcpy(ps->ipd_par+ps->num_env, ps->ipd_par+VAR_7, sizeof(ps->ipd_par[0]));

                memcpy(ps->opd_par+ps->num_env, ps->opd_par+VAR_7, sizeof(ps->opd_par[0]));

            }

        }

        if (ps->enable_iid){

            for (VAR_8 = 0; VAR_8 < ps->nr_iid_par; VAR_8++) {

                if (FFABS(ps->iid_par[ps->num_env][VAR_8]) > 7 + 8 * ps->iid_quant) {

                    av_log(avctx, AV_LOG_ERROR, "iid_par invalid\n");

                    goto err;

                }

            }

        }

        if (ps->enable_icc){

            for (VAR_8 = 0; VAR_8 < ps->nr_iid_par; VAR_8++) {

                if (ps->icc_par[ps->num_env][VAR_8] > 7U) {

                    av_log(avctx, AV_LOG_ERROR, "icc_par invalid\n");

                    goto err;

                }

            }

        }

        ps->num_env++;

        ps->border_position[ps->num_env] = numQMFSlots - 1;

    }





    ps->is34bands_old = ps->is34bands;

    if (!PS_BASELINE && (ps->enable_iid || ps->enable_icc))

        ps->is34bands = (ps->enable_iid && ps->nr_iid_par == 34) ||

                        (ps->enable_icc && ps->nr_icc_par == 34);



    

    if (!ps->enable_ipdopd) {

        memset(ps->ipd_par, 0, sizeof(ps->ipd_par));

        memset(ps->opd_par, 0, sizeof(ps->opd_par));

    }



    if (VAR_2)

        ps->start = 1;



    VAR_3 = get_bits_count(gb) - VAR_1;

    if (VAR_3 <= bits_left) {

        skip_bits_long(gb_host, VAR_3);

        return VAR_3;

    }

    av_log(avctx, AV_LOG_ERROR, "Expected to read %d PS bits actually read %d.\n", bits_left, VAR_3);

err:

    ps->start = 0;

    skip_bits_long(gb_host, bits_left);

    memset(ps->iid_par, 0, sizeof(ps->iid_par));

    memset(ps->icc_par, 0, sizeof(ps->icc_par));

    memset(ps->ipd_par, 0, sizeof(ps->ipd_par));

    memset(ps->opd_par, 0, sizeof(ps->opd_par));

    return bits_left;

}

int FUNC_0(ff_ps_read_data)(AVCodecContext *avctx, GetBitContext *gb_host, PSContext *ps, int bits_left)
{ int VAR_0; int VAR_1 = get_bits_count(gb_host); int VAR_2; int VAR_3; GetBitContext gbc = *gb_host, *gb = &gbc; VAR_2 = get_bits1(gb); if (VAR_2) { ps->enable_iid = get_bits1(gb); if (ps->enable_iid) { int VAR_4 = get_bits(gb, 3); if (VAR_4 > 5) { av_log(avctx, AV_LOG_ERROR, "VAR_4 %d is reserved.\n",
VAR_4); goto err; } ps->nr_iid_par    = nr_iidicc_par_tab[VAR_4]; ps->iid_quant     = VAR_4 > 2; ps->nr_ipdopd_par = nr_iidopd_par_tab[VAR_4]; } ps->enable_icc = get_bits1(gb); if (ps->enable_icc) { ps->icc_mode = get_bits(gb, 3); if (ps->icc_mode > 5) { av_log(avctx, AV_LOG_ERROR, "icc_mode %d is reserved.\n",
ps->icc_mode); goto err; } ps->nr_icc_par = nr_iidicc_par_tab[ps->icc_mode]; } ps->enable_ext = get_bits1(gb); } ps->frame_class = get_bits1(gb); ps->num_env_old = ps->num_env; ps->num_env     = num_env_tab[ps->frame_class][get_bits(gb, 2)]; ps->border_position[0] = -1; if (ps->frame_class) { for (VAR_0 = 1; VAR_0 <= ps->num_env; VAR_0++) ps->border_position[VAR_0] = get_bits(gb, 5); } else for (VAR_0 = 1; VAR_0 <= ps->num_env; VAR_0++) ps->border_position[VAR_0] = (VAR_0 * numQMFSlots >> ff_log2_tab[ps->num_env]) - 1; if (ps->enable_iid) { for (VAR_0 = 0; VAR_0 < ps->num_env; VAR_0++) { int dt = get_bits1(gb); if (read_iid_data(avctx, gb, ps, ps->iid_par, huff_iid[2*dt+ps->iid_quant], VAR_0, dt))
goto err; } } else memset(ps->iid_par, 0, sizeof(ps->iid_par)); if (ps->enable_icc)
for (VAR_0 = 0; VAR_0 < ps->num_env; VAR_0++) { int dt = get_bits1(gb); if (read_icc_data(avctx, gb, ps, ps->icc_par, dt ? huff_icc_dt : huff_icc_df, VAR_0, dt))
goto err; } else
memset(ps->icc_par, 0, sizeof(ps->icc_par)); if (ps->enable_ext) { int VAR_5 = get_bits(gb, 4); if (VAR_5 == 15) { VAR_5 += get_bits(gb, 8); } VAR_5 *= 8; while (VAR_5 > 7) { int VAR_6 = get_bits(gb, 2); VAR_5 -= 2 + ps_read_extension_data(gb, ps, VAR_6); } if (VAR_5 < 0) { av_log(avctx, AV_LOG_ERROR, "ps extension overflow %d\n", VAR_5); goto err; } skip_bits(gb, VAR_5); } ps->enable_ipdopd &= !PS_BASELINE; if (!ps->num_env || ps->border_position[ps->num_env] < numQMFSlots - 1) { int VAR_7 = ps->num_env ? ps->num_env - 1 : ps->num_env_old - 1; int VAR_8; if (VAR_7 >= 0 && VAR_7 != ps->num_env) { if (ps->enable_iid) { memcpy(ps->iid_par+ps->num_env, ps->iid_par+VAR_7, sizeof(ps->iid_par[0])); } if (ps->enable_icc) { memcpy(ps->icc_par+ps->num_env, ps->icc_par+VAR_7, sizeof(ps->icc_par[0])); } if (ps->enable_ipdopd) { memcpy(ps->ipd_par+ps->num_env, ps->ipd_par+VAR_7, sizeof(ps->ipd_par[0])); memcpy(ps->opd_par+ps->num_env, ps->opd_par+VAR_7, sizeof(ps->opd_par[0])); } } if (ps->enable_iid){ for (VAR_8 = 0; VAR_8 < ps->nr_iid_par; VAR_8++) { if (FFABS(ps->iid_par[ps->num_env][VAR_8]) > 7 + 8 * ps->iid_quant) { av_log(avctx, AV_LOG_ERROR, "iid_par invalid\n"); goto err; } } } if (ps->enable_icc){ for (VAR_8 = 0; VAR_8 < ps->nr_iid_par; VAR_8++) { if (ps->icc_par[ps->num_env][VAR_8] > 7U) { av_log(avctx, AV_LOG_ERROR, "icc_par invalid\n"); goto err; } } } ps->num_env++; ps->border_position[ps->num_env] = numQMFSlots - 1; } ps->is34bands_old = ps->is34bands; if (!PS_BASELINE && (ps->enable_iid || ps->enable_icc))
ps->is34bands = (ps->enable_iid && ps->nr_iid_par == 34) ||
(ps->enable_icc && ps->nr_icc_par == 34); if (!ps->enable_ipdopd) { memset(ps->ipd_par, 0, sizeof(ps->ipd_par)); memset(ps->opd_par, 0, sizeof(ps->opd_par)); } if (VAR_2)
ps->start = 1; VAR_3 = get_bits_count(gb) - VAR_1; if (VAR_3 <= bits_left) { skip_bits_long(gb_host, VAR_3); return VAR_3; } av_log(avctx, AV_LOG_ERROR, "Expected to read %d PS bits actually read %d.\n", bits_left, VAR_3); err:
ps->start = 0; skip_bits_long(gb_host, bits_left); memset(ps->iid_par, 0, sizeof(ps->iid_par)); memset(ps->icc_par, 0, sizeof(ps->icc_par)); memset(ps->ipd_par, 0, sizeof(ps->ipd_par)); memset(ps->opd_par, 0, sizeof(ps->opd_par)); return bits_left; }