static int dca_subframe_footer(DCAContext *s, int base_channel)

{

    int in, out, aux_data_count, aux_data_end, reserved;

    uint32_t nsyncaux;



    /*

     * Unpack optional information

     */



    /* presumably optional information only appears in the core? */

    if (!base_channel) {

        if (s->timestamp)

            skip_bits_long(&s->gb, 32);



        if (s->aux_data) {

            aux_data_count = get_bits(&s->gb, 6);



            // align (32-bit)

            skip_bits_long(&s->gb, (-get_bits_count(&s->gb)) & 31);



            aux_data_end = 8 * aux_data_count + get_bits_count(&s->gb);



            if ((nsyncaux = get_bits_long(&s->gb, 32)) != DCA_NSYNCAUX) {

                av_log(s->avctx, AV_LOG_ERROR, "nSYNCAUX mismatch %#"PRIx32"\n",

                       nsyncaux);

                return AVERROR_INVALIDDATA;

            }



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

                avpriv_request_sample(s->avctx,

                                      "Auxiliary Decode Time Stamp Flag");

                // align (4-bit)

                skip_bits(&s->gb, (-get_bits_count(&s->gb)) & 4);

                // 44 bits: nMSByte (8), nMarker (4), nLSByte (28), nMarker (4)

                skip_bits_long(&s->gb, 44);

            }



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

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

                switch (am) {

                case 0:

                    s->core_downmix_amode = DCA_MONO;

                    break;

                case 1:

                    s->core_downmix_amode = DCA_STEREO;

                    break;

                case 2:

                    s->core_downmix_amode = DCA_STEREO_TOTAL;

                    break;

                case 3:

                    s->core_downmix_amode = DCA_3F;

                    break;

                case 4:

                    s->core_downmix_amode = DCA_2F1R;

                    break;

                case 5:

                    s->core_downmix_amode = DCA_2F2R;

                    break;

                case 6:

                    s->core_downmix_amode = DCA_3F1R;

                    break;

                default:

                    av_log(s->avctx, AV_LOG_ERROR,

                           "Invalid mode %d for embedded downmix coefficients\n",

                           am);

                    return AVERROR_INVALIDDATA;

                }

                for (out = 0; out < ff_dca_channels[s->core_downmix_amode]; out++) {

                    for (in = 0; in < s->audio_header.prim_channels + !!s->lfe; in++) {

                        uint16_t tmp = get_bits(&s->gb, 9);

                        if ((tmp & 0xFF) > 241) {

                            av_log(s->avctx, AV_LOG_ERROR,

                                   "Invalid downmix coefficient code %"PRIu16"\n",

                                   tmp);

                            return AVERROR_INVALIDDATA;

                        }

                        s->core_downmix_codes[in][out] = tmp;

                    }

                }

            }



            align_get_bits(&s->gb); // byte align

            skip_bits(&s->gb, 16);  // nAUXCRC16



            // additional data (reserved, cf. ETSI TS 102 114 V1.4.1)

            if ((reserved = (aux_data_end - get_bits_count(&s->gb))) < 0) {

                av_log(s->avctx, AV_LOG_ERROR,

                       "Overread auxiliary data by %d bits\n", -reserved);

                return AVERROR_INVALIDDATA;

            } else if (reserved) {

                avpriv_request_sample(s->avctx,

                                      "Core auxiliary data reserved content");

                skip_bits_long(&s->gb, reserved);

            }

        }



        if (s->crc_present && s->dynrange)

            get_bits(&s->gb, 16);

    }



    return 0;

}

static int dca_subframe_footer(DCAContext *s, int base_channel)

{

    int in, out, aux_data_count, aux_data_end, reserved;

    uint32_t nsyncaux;



    







    

    if (!base_channel) {

        if (s->timestamp)

            skip_bits_long(&s->gb, 32);



        if (s->aux_data) {

            aux_data_count = get_bits(&s->gb, 6);



            

            skip_bits_long(&s->gb, (-get_bits_count(&s->gb)) & 31);



            aux_data_end = 8 * aux_data_count + get_bits_count(&s->gb);



            if ((nsyncaux = get_bits_long(&s->gb, 32)) != DCA_NSYNCAUX) {

                av_log(s->avctx, AV_LOG_ERROR, "nSYNCAUX mismatch %#"PRIx32"\n",

                       nsyncaux);

                return AVERROR_INVALIDDATA;

            }



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

                avpriv_request_sample(s->avctx,

                                      "Auxiliary Decode Time Stamp Flag");

                

                skip_bits(&s->gb, (-get_bits_count(&s->gb)) & 4);

                

                skip_bits_long(&s->gb, 44);

            }



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

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

                switch (am) {

                case 0:

                    s->core_downmix_amode = DCA_MONO;

                    break;

                case 1:

                    s->core_downmix_amode = DCA_STEREO;

                    break;

                case 2:

                    s->core_downmix_amode = DCA_STEREO_TOTAL;

                    break;

                case 3:

                    s->core_downmix_amode = DCA_3F;

                    break;

                case 4:

                    s->core_downmix_amode = DCA_2F1R;

                    break;

                case 5:

                    s->core_downmix_amode = DCA_2F2R;

                    break;

                case 6:

                    s->core_downmix_amode = DCA_3F1R;

                    break;

                default:

                    av_log(s->avctx, AV_LOG_ERROR,

                           "Invalid mode %d for embedded downmix coefficients\n",

                           am);

                    return AVERROR_INVALIDDATA;

                }

                for (out = 0; out < ff_dca_channels[s->core_downmix_amode]; out++) {

                    for (in = 0; in < s->audio_header.prim_channels + !!s->lfe; in++) {

                        uint16_t tmp = get_bits(&s->gb, 9);

                        if ((tmp & 0xFF) > 241) {

                            av_log(s->avctx, AV_LOG_ERROR,

                                   "Invalid downmix coefficient code %"PRIu16"\n",

                                   tmp);

                            return AVERROR_INVALIDDATA;

                        }

                        s->core_downmix_codes[in][out] = tmp;

                    }

                }

            }



            align_get_bits(&s->gb); 

            skip_bits(&s->gb, 16);  



            

            if ((reserved = (aux_data_end - get_bits_count(&s->gb))) < 0) {

                av_log(s->avctx, AV_LOG_ERROR,

                       "Overread auxiliary data by %d bits\n", -reserved);

                return AVERROR_INVALIDDATA;

            } else if (reserved) {

                avpriv_request_sample(s->avctx,

                                      "Core auxiliary data reserved content");

                skip_bits_long(&s->gb, reserved);

            }

        }



        if (s->crc_present && s->dynrange)

            get_bits(&s->gb, 16);

    }



    return 0;

}

            if ((reserved = (aux_data_end - get_bits_count(&s->gb))) < 0) {                 av_log(s->avctx, AV_LOG_ERROR,                        "Overread auxiliary data by %d bits\n", -reserved);                 return AVERROR_INVALIDDATA;             } else if (reserved) {
static int FUNC_0(DCAContext *VAR_0, int VAR_1)

{

    int VAR_2, VAR_3, VAR_4, VAR_5, VAR_6;

    uint32_t nsyncaux;



    







    

    if (!VAR_1) {

        if (VAR_0->timestamp)

            skip_bits_long(&VAR_0->gb, 32);



        if (VAR_0->aux_data) {

            VAR_4 = get_bits(&VAR_0->gb, 6);



            

            skip_bits_long(&VAR_0->gb, (-get_bits_count(&VAR_0->gb)) & 31);



            VAR_5 = 8 * VAR_4 + get_bits_count(&VAR_0->gb);



            if ((nsyncaux = get_bits_long(&VAR_0->gb, 32)) != DCA_NSYNCAUX) {

                av_log(VAR_0->avctx, AV_LOG_ERROR, "nSYNCAUX mismatch %#"PRIx32"\n",

                       nsyncaux);

                return AVERROR_INVALIDDATA;

            }



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

                avpriv_request_sample(VAR_0->avctx,

                                      "Auxiliary Decode Time Stamp Flag");

                

                skip_bits(&VAR_0->gb, (-get_bits_count(&VAR_0->gb)) & 4);

                

                skip_bits_long(&VAR_0->gb, 44);

            }



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

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

                switch (VAR_7) {

                case 0:

                    VAR_0->core_downmix_amode = DCA_MONO;

                    break;

                case 1:

                    VAR_0->core_downmix_amode = DCA_STEREO;

                    break;

                case 2:

                    VAR_0->core_downmix_amode = DCA_STEREO_TOTAL;

                    break;

                case 3:

                    VAR_0->core_downmix_amode = DCA_3F;

                    break;

                case 4:

                    VAR_0->core_downmix_amode = DCA_2F1R;

                    break;

                case 5:

                    VAR_0->core_downmix_amode = DCA_2F2R;

                    break;

                case 6:

                    VAR_0->core_downmix_amode = DCA_3F1R;

                    break;

                default:

                    av_log(VAR_0->avctx, AV_LOG_ERROR,

                           "Invalid mode %d for embedded downmix coefficients\n",

                           VAR_7);

                    return AVERROR_INVALIDDATA;

                }

                for (VAR_3 = 0; VAR_3 < ff_dca_channels[VAR_0->core_downmix_amode]; VAR_3++) {

                    for (VAR_2 = 0; VAR_2 < VAR_0->audio_header.prim_channels + !!VAR_0->lfe; VAR_2++) {

                        uint16_t tmp = get_bits(&VAR_0->gb, 9);

                        if ((tmp & 0xFF) > 241) {

                            av_log(VAR_0->avctx, AV_LOG_ERROR,

                                   "Invalid downmix coefficient code %"PRIu16"\n",

                                   tmp);

                            return AVERROR_INVALIDDATA;

                        }

                        VAR_0->core_downmix_codes[VAR_2][VAR_3] = tmp;

                    }

                }

            }



            align_get_bits(&VAR_0->gb); 

            skip_bits(&VAR_0->gb, 16);  



            

            if ((VAR_6 = (VAR_5 - get_bits_count(&VAR_0->gb))) < 0) {

                av_log(VAR_0->avctx, AV_LOG_ERROR,

                       "Overread auxiliary data by %d bits\n", -VAR_6);

                return AVERROR_INVALIDDATA;

            } else if (VAR_6) {

                avpriv_request_sample(VAR_0->avctx,

                                      "Core auxiliary data VAR_6 content");

                skip_bits_long(&VAR_0->gb, VAR_6);

            }

        }



        if (VAR_0->crc_present && VAR_0->dynrange)

            get_bits(&VAR_0->gb, 16);

    }



    return 0;

}

static int FUNC_0(DCAContext *VAR_0, int VAR_1)
{ int VAR_2, VAR_3, VAR_4, VAR_5, VAR_6; uint32_t nsyncaux; if (!VAR_1) { if (VAR_0->timestamp)
skip_bits_long(&VAR_0->gb, 32); if (VAR_0->aux_data) { VAR_4 = get_bits(&VAR_0->gb, 6); skip_bits_long(&VAR_0->gb, (-get_bits_count(&VAR_0->gb)) & 31); VAR_5 = 8 * VAR_4 + get_bits_count(&VAR_0->gb); if ((nsyncaux = get_bits_long(&VAR_0->gb, 32)) != DCA_NSYNCAUX) { av_log(VAR_0->avctx, AV_LOG_ERROR, "nSYNCAUX mismatch %#"PRIx32"\n",
nsyncaux); return AVERROR_INVALIDDATA; } if (get_bits1(&VAR_0->gb)) { avpriv_request_sample(VAR_0->avctx,
"Auxiliary Decode Time Stamp Flag"); skip_bits(&VAR_0->gb, (-get_bits_count(&VAR_0->gb)) & 4); skip_bits_long(&VAR_0->gb, 44); } if ((VAR_0->core_downmix = get_bits1(&VAR_0->gb))) { int VAR_7 = get_bits(&VAR_0->gb, 3); switch (VAR_7) { case 0:
VAR_0->core_downmix_amode = DCA_MONO; break; case 1:
VAR_0->core_downmix_amode = DCA_STEREO; break; case 2:
VAR_0->core_downmix_amode = DCA_STEREO_TOTAL; break; case 3:
VAR_0->core_downmix_amode = DCA_3F; break; case 4:
VAR_0->core_downmix_amode = DCA_2F1R; break; case 5:
VAR_0->core_downmix_amode = DCA_2F2R; break; case 6:
VAR_0->core_downmix_amode = DCA_3F1R; break; default:
av_log(VAR_0->avctx, AV_LOG_ERROR,
"Invalid mode %d for embedded downmix coefficients\n",
VAR_7); return AVERROR_INVALIDDATA; } for (VAR_3 = 0; VAR_3 < ff_dca_channels[VAR_0->core_downmix_amode]; VAR_3++) { for (VAR_2 = 0; VAR_2 < VAR_0->audio_header.prim_channels + !!VAR_0->lfe; VAR_2++) { uint16_t tmp = get_bits(&VAR_0->gb, 9); if ((tmp & 0xFF) > 241) { av_log(VAR_0->avctx, AV_LOG_ERROR,
"Invalid downmix coefficient code %"PRIu16"\n",
tmp); return AVERROR_INVALIDDATA; } VAR_0->core_downmix_codes[VAR_2][VAR_3] = tmp; } } } align_get_bits(&VAR_0->gb); skip_bits(&VAR_0->gb, 16); if ((VAR_6 = (VAR_5 - get_bits_count(&VAR_0->gb))) < 0) { av_log(VAR_0->avctx, AV_LOG_ERROR,
"Overread auxiliary data by %d bits\n", -VAR_6); return AVERROR_INVALIDDATA; } else if (VAR_6) { avpriv_request_sample(VAR_0->avctx,
"Core auxiliary data VAR_6 content"); skip_bits_long(&VAR_0->gb, VAR_6); } } if (VAR_0->crc_present && VAR_0->dynrange)
get_bits(&VAR_0->gb, 16); } return 0; }