static int dca_exss_parse_asset_header(DCAContext *s)

{

    int header_pos = get_bits_count(&s->gb);

    int header_size;

    int channels;

    int embedded_stereo = 0;

    int embedded_6ch    = 0;

    int drc_code_present;

    int extensions_mask;

    int i, j;



    if (get_bits_left(&s->gb) < 16)

        return -1;



    /* We will parse just enough to get to the extensions bitmask with which

     * we can set the profile value. */



    header_size = get_bits(&s->gb, 9) + 1;

    skip_bits(&s->gb, 3); // asset index



    if (s->static_fields) {

        if (get_bits1(&s->gb))

            skip_bits(&s->gb, 4); // asset type descriptor

        if (get_bits1(&s->gb))

            skip_bits_long(&s->gb, 24); // language descriptor



        if (get_bits1(&s->gb)) {

            /* How can one fit 1024 bytes of text here if the maximum value

             * for the asset header size field above was 512 bytes? */

            int text_length = get_bits(&s->gb, 10) + 1;

            if (get_bits_left(&s->gb) < text_length * 8)

                return -1;

            skip_bits_long(&s->gb, text_length * 8); // info text

        }



        skip_bits(&s->gb, 5); // bit resolution - 1

        skip_bits(&s->gb, 4); // max sample rate code

        channels = get_bits(&s->gb, 8) + 1;



        if (get_bits1(&s->gb)) { // 1-to-1 channels to speakers

            int spkr_remap_sets;

            int spkr_mask_size = 16;

            int num_spkrs[7];



            if (channels > 2)

                embedded_stereo = get_bits1(&s->gb);

            if (channels > 6)

                embedded_6ch = get_bits1(&s->gb);



            if (get_bits1(&s->gb)) {

                spkr_mask_size = (get_bits(&s->gb, 2) + 1) << 2;

                skip_bits(&s->gb, spkr_mask_size); // spkr activity mask

            }



            spkr_remap_sets = get_bits(&s->gb, 3);



            for (i = 0; i < spkr_remap_sets; i++) {

                /* std layout mask for each remap set */

                num_spkrs[i] = dca_exss_mask2count(get_bits(&s->gb, spkr_mask_size));

            }



            for (i = 0; i < spkr_remap_sets; i++) {

                int num_dec_ch_remaps = get_bits(&s->gb, 5) + 1;

                if (get_bits_left(&s->gb) < 0)

                    return -1;



                for (j = 0; j < num_spkrs[i]; j++) {

                    int remap_dec_ch_mask = get_bits_long(&s->gb, num_dec_ch_remaps);

                    int num_dec_ch = av_popcount(remap_dec_ch_mask);

                    skip_bits_long(&s->gb, num_dec_ch * 5); // remap codes

                }

            }

        } else {

            skip_bits(&s->gb, 3); // representation type

        }

    }



    drc_code_present = get_bits1(&s->gb);

    if (drc_code_present)

        get_bits(&s->gb, 8); // drc code



    if (get_bits1(&s->gb))

        skip_bits(&s->gb, 5); // dialog normalization code



    if (drc_code_present && embedded_stereo)

        get_bits(&s->gb, 8); // drc stereo code



    if (s->mix_metadata && get_bits1(&s->gb)) {

        skip_bits(&s->gb, 1); // external mix

        skip_bits(&s->gb, 6); // post mix gain code



        if (get_bits(&s->gb, 2) != 3) // mixer drc code

            skip_bits(&s->gb, 3); // drc limit

        else

            skip_bits(&s->gb, 8); // custom drc code



        if (get_bits1(&s->gb)) // channel specific scaling

            for (i = 0; i < s->num_mix_configs; i++)

                skip_bits_long(&s->gb, s->mix_config_num_ch[i] * 6); // scale codes

        else

            skip_bits_long(&s->gb, s->num_mix_configs * 6); // scale codes



        for (i = 0; i < s->num_mix_configs; i++) {

            if (get_bits_left(&s->gb) < 0)

                return -1;

            dca_exss_skip_mix_coeffs(&s->gb, channels, s->mix_config_num_ch[i]);

            if (embedded_6ch)

                dca_exss_skip_mix_coeffs(&s->gb, 6, s->mix_config_num_ch[i]);

            if (embedded_stereo)

                dca_exss_skip_mix_coeffs(&s->gb, 2, s->mix_config_num_ch[i]);

        }

    }



    switch (get_bits(&s->gb, 2)) {

    case 0:

        extensions_mask = get_bits(&s->gb, 12);

        break;

    case 1:

        extensions_mask = DCA_EXT_EXSS_XLL;

        break;

    case 2:

        extensions_mask = DCA_EXT_EXSS_LBR;

        break;

    case 3:

        extensions_mask = 0; /* aux coding */

        break;

    }



    /* not parsed further, we were only interested in the extensions mask */



    if (get_bits_left(&s->gb) < 0)

        return -1;



    if (get_bits_count(&s->gb) - header_pos > header_size * 8) {

        av_log(s->avctx, AV_LOG_WARNING, "Asset header size mismatch.\n");

        return -1;

    }

    skip_bits_long(&s->gb, header_pos + header_size * 8 - get_bits_count(&s->gb));



    if (extensions_mask & DCA_EXT_EXSS_XLL)

        s->profile = FF_PROFILE_DTS_HD_MA;

    else if (extensions_mask & (DCA_EXT_EXSS_XBR | DCA_EXT_EXSS_X96 |

                                DCA_EXT_EXSS_XXCH))

        s->profile = FF_PROFILE_DTS_HD_HRA;



    if (!(extensions_mask & DCA_EXT_CORE))

        av_log(s->avctx, AV_LOG_WARNING, "DTS core detection mismatch.\n");

    if ((extensions_mask & DCA_CORE_EXTS) != s->core_ext_mask)

        av_log(s->avctx, AV_LOG_WARNING,

               "DTS extensions detection mismatch (%d, %d)\n",

               extensions_mask & DCA_CORE_EXTS, s->core_ext_mask);



    return 0;

}

static int dca_exss_parse_asset_header(DCAContext *s)

{

    int header_pos = get_bits_count(&s->gb);

    int header_size;

    int channels;

    int embedded_stereo = 0;

    int embedded_6ch    = 0;

    int drc_code_present;

    int extensions_mask;

    int i, j;



    if (get_bits_left(&s->gb) < 16)

        return -1;



    





    header_size = get_bits(&s->gb, 9) + 1;

    skip_bits(&s->gb, 3); 



    if (s->static_fields) {

        if (get_bits1(&s->gb))

            skip_bits(&s->gb, 4); 

        if (get_bits1(&s->gb))

            skip_bits_long(&s->gb, 24); 



        if (get_bits1(&s->gb)) {

            



            int text_length = get_bits(&s->gb, 10) + 1;

            if (get_bits_left(&s->gb) < text_length * 8)

                return -1;

            skip_bits_long(&s->gb, text_length * 8); 

        }



        skip_bits(&s->gb, 5); 

        skip_bits(&s->gb, 4); 

        channels = get_bits(&s->gb, 8) + 1;



        if (get_bits1(&s->gb)) { 

            int spkr_remap_sets;

            int spkr_mask_size = 16;

            int num_spkrs[7];



            if (channels > 2)

                embedded_stereo = get_bits1(&s->gb);

            if (channels > 6)

                embedded_6ch = get_bits1(&s->gb);



            if (get_bits1(&s->gb)) {

                spkr_mask_size = (get_bits(&s->gb, 2) + 1) << 2;

                skip_bits(&s->gb, spkr_mask_size); 

            }



            spkr_remap_sets = get_bits(&s->gb, 3);



            for (i = 0; i < spkr_remap_sets; i++) {

                

                num_spkrs[i] = dca_exss_mask2count(get_bits(&s->gb, spkr_mask_size));

            }



            for (i = 0; i < spkr_remap_sets; i++) {

                int num_dec_ch_remaps = get_bits(&s->gb, 5) + 1;

                if (get_bits_left(&s->gb) < 0)

                    return -1;



                for (j = 0; j < num_spkrs[i]; j++) {

                    int remap_dec_ch_mask = get_bits_long(&s->gb, num_dec_ch_remaps);

                    int num_dec_ch = av_popcount(remap_dec_ch_mask);

                    skip_bits_long(&s->gb, num_dec_ch * 5); 

                }

            }

        } else {

            skip_bits(&s->gb, 3); 

        }

    }



    drc_code_present = get_bits1(&s->gb);

    if (drc_code_present)

        get_bits(&s->gb, 8); 



    if (get_bits1(&s->gb))

        skip_bits(&s->gb, 5); 



    if (drc_code_present && embedded_stereo)

        get_bits(&s->gb, 8); 



    if (s->mix_metadata && get_bits1(&s->gb)) {

        skip_bits(&s->gb, 1); 

        skip_bits(&s->gb, 6); 



        if (get_bits(&s->gb, 2) != 3) 

            skip_bits(&s->gb, 3); 

        else

            skip_bits(&s->gb, 8); 



        if (get_bits1(&s->gb)) 

            for (i = 0; i < s->num_mix_configs; i++)

                skip_bits_long(&s->gb, s->mix_config_num_ch[i] * 6); 

        else

            skip_bits_long(&s->gb, s->num_mix_configs * 6); 



        for (i = 0; i < s->num_mix_configs; i++) {

            if (get_bits_left(&s->gb) < 0)

                return -1;

            dca_exss_skip_mix_coeffs(&s->gb, channels, s->mix_config_num_ch[i]);

            if (embedded_6ch)

                dca_exss_skip_mix_coeffs(&s->gb, 6, s->mix_config_num_ch[i]);

            if (embedded_stereo)

                dca_exss_skip_mix_coeffs(&s->gb, 2, s->mix_config_num_ch[i]);

        }

    }



    switch (get_bits(&s->gb, 2)) {

    case 0:

        extensions_mask = get_bits(&s->gb, 12);

        break;

    case 1:

        extensions_mask = DCA_EXT_EXSS_XLL;

        break;

    case 2:

        extensions_mask = DCA_EXT_EXSS_LBR;

        break;

    case 3:

        extensions_mask = 0; 

        break;

    }



    



    if (get_bits_left(&s->gb) < 0)

        return -1;



    if (get_bits_count(&s->gb) - header_pos > header_size * 8) {

        av_log(s->avctx, AV_LOG_WARNING, "Asset header size mismatch.\n");

        return -1;

    }

    skip_bits_long(&s->gb, header_pos + header_size * 8 - get_bits_count(&s->gb));



    if (extensions_mask & DCA_EXT_EXSS_XLL)

        s->profile = FF_PROFILE_DTS_HD_MA;

    else if (extensions_mask & (DCA_EXT_EXSS_XBR | DCA_EXT_EXSS_X96 |

                                DCA_EXT_EXSS_XXCH))

        s->profile = FF_PROFILE_DTS_HD_HRA;



    if (!(extensions_mask & DCA_EXT_CORE))

        av_log(s->avctx, AV_LOG_WARNING, "DTS core detection mismatch.\n");

    if ((extensions_mask & DCA_CORE_EXTS) != s->core_ext_mask)

        av_log(s->avctx, AV_LOG_WARNING,

               "DTS extensions detection mismatch (%d, %d)\n",

               extensions_mask & DCA_CORE_EXTS, s->core_ext_mask);



    return 0;

}

static int FUNC_0(DCAContext *VAR_0)

{

    int VAR_1 = get_bits_count(&VAR_0->gb);

    int VAR_2;

    int VAR_3;

    int VAR_4 = 0;

    int VAR_5    = 0;

    int VAR_6;

    int VAR_7;

    int VAR_8, VAR_9;



    if (get_bits_left(&VAR_0->gb) < 16)

        return -1;



    





    VAR_2 = get_bits(&VAR_0->gb, 9) + 1;

    skip_bits(&VAR_0->gb, 3); 



    if (VAR_0->static_fields) {

        if (get_bits1(&VAR_0->gb))

            skip_bits(&VAR_0->gb, 4); 

        if (get_bits1(&VAR_0->gb))

            skip_bits_long(&VAR_0->gb, 24); 



        if (get_bits1(&VAR_0->gb)) {

            



            int VAR_10 = get_bits(&VAR_0->gb, 10) + 1;

            if (get_bits_left(&VAR_0->gb) < VAR_10 * 8)

                return -1;

            skip_bits_long(&VAR_0->gb, VAR_10 * 8); 

        }



        skip_bits(&VAR_0->gb, 5); 

        skip_bits(&VAR_0->gb, 4); 

        VAR_3 = get_bits(&VAR_0->gb, 8) + 1;



        if (get_bits1(&VAR_0->gb)) { 

            int VAR_11;

            int VAR_12 = 16;

            int VAR_13[7];



            if (VAR_3 > 2)

                VAR_4 = get_bits1(&VAR_0->gb);

            if (VAR_3 > 6)

                VAR_5 = get_bits1(&VAR_0->gb);



            if (get_bits1(&VAR_0->gb)) {

                VAR_12 = (get_bits(&VAR_0->gb, 2) + 1) << 2;

                skip_bits(&VAR_0->gb, VAR_12); 

            }



            VAR_11 = get_bits(&VAR_0->gb, 3);



            for (VAR_8 = 0; VAR_8 < VAR_11; VAR_8++) {

                

                VAR_13[VAR_8] = dca_exss_mask2count(get_bits(&VAR_0->gb, VAR_12));

            }



            for (VAR_8 = 0; VAR_8 < VAR_11; VAR_8++) {

                int VAR_14 = get_bits(&VAR_0->gb, 5) + 1;

                if (get_bits_left(&VAR_0->gb) < 0)

                    return -1;



                for (VAR_9 = 0; VAR_9 < VAR_13[VAR_8]; VAR_9++) {

                    int VAR_15 = get_bits_long(&VAR_0->gb, VAR_14);

                    int VAR_16 = av_popcount(VAR_15);

                    skip_bits_long(&VAR_0->gb, VAR_16 * 5); 

                }

            }

        } else {

            skip_bits(&VAR_0->gb, 3); 

        }

    }



    VAR_6 = get_bits1(&VAR_0->gb);

    if (VAR_6)

        get_bits(&VAR_0->gb, 8); 



    if (get_bits1(&VAR_0->gb))

        skip_bits(&VAR_0->gb, 5); 



    if (VAR_6 && VAR_4)

        get_bits(&VAR_0->gb, 8); 



    if (VAR_0->mix_metadata && get_bits1(&VAR_0->gb)) {

        skip_bits(&VAR_0->gb, 1); 

        skip_bits(&VAR_0->gb, 6); 



        if (get_bits(&VAR_0->gb, 2) != 3) 

            skip_bits(&VAR_0->gb, 3); 

        else

            skip_bits(&VAR_0->gb, 8); 



        if (get_bits1(&VAR_0->gb)) 

            for (VAR_8 = 0; VAR_8 < VAR_0->num_mix_configs; VAR_8++)

                skip_bits_long(&VAR_0->gb, VAR_0->mix_config_num_ch[VAR_8] * 6); 

        else

            skip_bits_long(&VAR_0->gb, VAR_0->num_mix_configs * 6); 



        for (VAR_8 = 0; VAR_8 < VAR_0->num_mix_configs; VAR_8++) {

            if (get_bits_left(&VAR_0->gb) < 0)

                return -1;

            dca_exss_skip_mix_coeffs(&VAR_0->gb, VAR_3, VAR_0->mix_config_num_ch[VAR_8]);

            if (VAR_5)

                dca_exss_skip_mix_coeffs(&VAR_0->gb, 6, VAR_0->mix_config_num_ch[VAR_8]);

            if (VAR_4)

                dca_exss_skip_mix_coeffs(&VAR_0->gb, 2, VAR_0->mix_config_num_ch[VAR_8]);

        }

    }



    switch (get_bits(&VAR_0->gb, 2)) {

    case 0:

        VAR_7 = get_bits(&VAR_0->gb, 12);

        break;

    case 1:

        VAR_7 = DCA_EXT_EXSS_XLL;

        break;

    case 2:

        VAR_7 = DCA_EXT_EXSS_LBR;

        break;

    case 3:

        VAR_7 = 0; 

        break;

    }



    



    if (get_bits_left(&VAR_0->gb) < 0)

        return -1;



    if (get_bits_count(&VAR_0->gb) - VAR_1 > VAR_2 * 8) {

        av_log(VAR_0->avctx, AV_LOG_WARNING, "Asset header size mismatch.\n");

        return -1;

    }

    skip_bits_long(&VAR_0->gb, VAR_1 + VAR_2 * 8 - get_bits_count(&VAR_0->gb));



    if (VAR_7 & DCA_EXT_EXSS_XLL)

        VAR_0->profile = FF_PROFILE_DTS_HD_MA;

    else if (VAR_7 & (DCA_EXT_EXSS_XBR | DCA_EXT_EXSS_X96 |

                                DCA_EXT_EXSS_XXCH))

        VAR_0->profile = FF_PROFILE_DTS_HD_HRA;



    if (!(VAR_7 & DCA_EXT_CORE))

        av_log(VAR_0->avctx, AV_LOG_WARNING, "DTS core detection mismatch.\n");

    if ((VAR_7 & DCA_CORE_EXTS) != VAR_0->core_ext_mask)

        av_log(VAR_0->avctx, AV_LOG_WARNING,

               "DTS extensions detection mismatch (%d, %d)\n",

               VAR_7 & DCA_CORE_EXTS, VAR_0->core_ext_mask);



    return 0;

}

static int FUNC_0(DCAContext *VAR_0)
{ int VAR_1 = get_bits_count(&VAR_0->gb); int VAR_2; int VAR_3; int VAR_4 = 0; int VAR_5    = 0; int VAR_6; int VAR_7; int VAR_8, VAR_9; if (get_bits_left(&VAR_0->gb) < 16)
return -1; VAR_2 = get_bits(&VAR_0->gb, 9) + 1; skip_bits(&VAR_0->gb, 3); if (VAR_0->static_fields) { if (get_bits1(&VAR_0->gb))
skip_bits(&VAR_0->gb, 4); if (get_bits1(&VAR_0->gb))
skip_bits_long(&VAR_0->gb, 24); if (get_bits1(&VAR_0->gb)) { int VAR_10 = get_bits(&VAR_0->gb, 10) + 1; if (get_bits_left(&VAR_0->gb) < VAR_10 * 8)
return -1; skip_bits_long(&VAR_0->gb, VAR_10 * 8); } skip_bits(&VAR_0->gb, 5); skip_bits(&VAR_0->gb, 4); VAR_3 = get_bits(&VAR_0->gb, 8) + 1; if (get_bits1(&VAR_0->gb)) { int VAR_11; int VAR_12 = 16; int VAR_13[7]; if (VAR_3 > 2)
VAR_4 = get_bits1(&VAR_0->gb); if (VAR_3 > 6)
VAR_5 = get_bits1(&VAR_0->gb); if (get_bits1(&VAR_0->gb)) { VAR_12 = (get_bits(&VAR_0->gb, 2) + 1) << 2; skip_bits(&VAR_0->gb, VAR_12); } VAR_11 = get_bits(&VAR_0->gb, 3); for (VAR_8 = 0; VAR_8 < VAR_11; VAR_8++) { VAR_13[VAR_8] = dca_exss_mask2count(get_bits(&VAR_0->gb, VAR_12)); } for (VAR_8 = 0; VAR_8 < VAR_11; VAR_8++) { int VAR_14 = get_bits(&VAR_0->gb, 5) + 1; if (get_bits_left(&VAR_0->gb) < 0)
return -1; for (VAR_9 = 0; VAR_9 < VAR_13[VAR_8]; VAR_9++) { int VAR_15 = get_bits_long(&VAR_0->gb, VAR_14); int VAR_16 = av_popcount(VAR_15); skip_bits_long(&VAR_0->gb, VAR_16 * 5); } } } else { skip_bits(&VAR_0->gb, 3); } } VAR_6 = get_bits1(&VAR_0->gb); if (VAR_6)
get_bits(&VAR_0->gb, 8); if (get_bits1(&VAR_0->gb))
skip_bits(&VAR_0->gb, 5); if (VAR_6 && VAR_4)
get_bits(&VAR_0->gb, 8); if (VAR_0->mix_metadata && get_bits1(&VAR_0->gb)) { skip_bits(&VAR_0->gb, 1); skip_bits(&VAR_0->gb, 6); if (get_bits(&VAR_0->gb, 2) != 3)
skip_bits(&VAR_0->gb, 3); else
skip_bits(&VAR_0->gb, 8); if (get_bits1(&VAR_0->gb))
for (VAR_8 = 0; VAR_8 < VAR_0->num_mix_configs; VAR_8++) skip_bits_long(&VAR_0->gb, VAR_0->mix_config_num_ch[VAR_8] * 6); else
skip_bits_long(&VAR_0->gb, VAR_0->num_mix_configs * 6); for (VAR_8 = 0; VAR_8 < VAR_0->num_mix_configs; VAR_8++) { if (get_bits_left(&VAR_0->gb) < 0)
return -1; dca_exss_skip_mix_coeffs(&VAR_0->gb, VAR_3, VAR_0->mix_config_num_ch[VAR_8]); if (VAR_5)
dca_exss_skip_mix_coeffs(&VAR_0->gb, 6, VAR_0->mix_config_num_ch[VAR_8]); if (VAR_4)
dca_exss_skip_mix_coeffs(&VAR_0->gb, 2, VAR_0->mix_config_num_ch[VAR_8]); } } switch (get_bits(&VAR_0->gb, 2)) { case 0:
VAR_7 = get_bits(&VAR_0->gb, 12); break; case 1:
VAR_7 = DCA_EXT_EXSS_XLL; break; case 2:
VAR_7 = DCA_EXT_EXSS_LBR; break; case 3:
VAR_7 = 0; break; } if (get_bits_left(&VAR_0->gb) < 0)
return -1; if (get_bits_count(&VAR_0->gb) - VAR_1 > VAR_2 * 8) { av_log(VAR_0->avctx, AV_LOG_WARNING, "Asset header size mismatch.\n"); return -1; } skip_bits_long(&VAR_0->gb, VAR_1 + VAR_2 * 8 - get_bits_count(&VAR_0->gb)); if (VAR_7 & DCA_EXT_EXSS_XLL)
VAR_0->profile = FF_PROFILE_DTS_HD_MA; else if (VAR_7 & (DCA_EXT_EXSS_XBR | DCA_EXT_EXSS_X96 |
DCA_EXT_EXSS_XXCH))
VAR_0->profile = FF_PROFILE_DTS_HD_HRA; if (!(VAR_7 & DCA_EXT_CORE))
av_log(VAR_0->avctx, AV_LOG_WARNING, "DTS core detection mismatch.\n"); if ((VAR_7 & DCA_CORE_EXTS) != VAR_0->core_ext_mask)
av_log(VAR_0->avctx, AV_LOG_WARNING,
"DTS extensions detection mismatch (%d, %d)\n",
VAR_7 & DCA_CORE_EXTS, VAR_0->core_ext_mask); return 0; }