int ff_dca_core_parse(DCACoreDecoder *s, uint8_t *data, int size)

{

    int ret;



    s->ext_audio_mask = 0;

    s->xch_pos = s->xxch_pos = s->x96_pos = 0;



    if ((ret = init_get_bits8(&s->gb, data, size)) < 0)

        return ret;

    s->gb_in = s->gb;



    if ((ret = parse_frame_header(s)) < 0)

        return ret;

    if ((ret = alloc_sample_buffer(s)) < 0)

        return ret;

    if ((ret = parse_frame_data(s, HEADER_CORE, 0)) < 0)

        return ret;

    if ((ret = parse_optional_info(s)) < 0)

        return ret;



    // Workaround for DTS in WAV

    if (s->frame_size > size && s->frame_size < size + 4)

        s->frame_size = size;



    if (ff_dca_seek_bits(&s->gb, s->frame_size * 8)) {

        av_log(s->avctx, AV_LOG_ERROR, "Read past end of core frame\n");

        if (s->avctx->err_recognition & AV_EF_EXPLODE)

            return AVERROR_INVALIDDATA;

    }



    return 0;

}

int ff_dca_core_parse(DCACoreDecoder *s, uint8_t *data, int size)

{

    int ret;



    s->ext_audio_mask = 0;

    s->xch_pos = s->xxch_pos = s->x96_pos = 0;



    if ((ret = init_get_bits8(&s->gb, data, size)) < 0)

        return ret;

    s->gb_in = s->gb;



    if ((ret = parse_frame_header(s)) < 0)

        return ret;

    if ((ret = alloc_sample_buffer(s)) < 0)

        return ret;

    if ((ret = parse_frame_data(s, HEADER_CORE, 0)) < 0)

        return ret;

    if ((ret = parse_optional_info(s)) < 0)

        return ret;



    

    if (s->frame_size > size && s->frame_size < size + 4)

        s->frame_size = size;



    if (ff_dca_seek_bits(&s->gb, s->frame_size * 8)) {

        av_log(s->avctx, AV_LOG_ERROR, "Read past end of core frame\n");

        if (s->avctx->err_recognition & AV_EF_EXPLODE)

            return AVERROR_INVALIDDATA;

    }



    return 0;

}

int FUNC_0(DCACoreDecoder *VAR_0, uint8_t *VAR_1, int VAR_2)

{

    int VAR_3;



    VAR_0->ext_audio_mask = 0;

    VAR_0->xch_pos = VAR_0->xxch_pos = VAR_0->x96_pos = 0;



    if ((VAR_3 = init_get_bits8(&VAR_0->gb, VAR_1, VAR_2)) < 0)

        return VAR_3;

    VAR_0->gb_in = VAR_0->gb;



    if ((VAR_3 = parse_frame_header(VAR_0)) < 0)

        return VAR_3;

    if ((VAR_3 = alloc_sample_buffer(VAR_0)) < 0)

        return VAR_3;

    if ((VAR_3 = parse_frame_data(VAR_0, HEADER_CORE, 0)) < 0)

        return VAR_3;

    if ((VAR_3 = parse_optional_info(VAR_0)) < 0)

        return VAR_3;



    

    if (VAR_0->frame_size > VAR_2 && VAR_0->frame_size < VAR_2 + 4)

        VAR_0->frame_size = VAR_2;



    if (ff_dca_seek_bits(&VAR_0->gb, VAR_0->frame_size * 8)) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "Read past end of core frame\n");

        if (VAR_0->avctx->err_recognition & AV_EF_EXPLODE)

            return AVERROR_INVALIDDATA;

    }



    return 0;

}

int FUNC_0(DCACoreDecoder *VAR_0, uint8_t *VAR_1, int VAR_2)
{ int VAR_3; VAR_0->ext_audio_mask = 0; VAR_0->xch_pos = VAR_0->xxch_pos = VAR_0->x96_pos = 0; if ((VAR_3 = init_get_bits8(&VAR_0->gb, VAR_1, VAR_2)) < 0)
return VAR_3; VAR_0->gb_in = VAR_0->gb; if ((VAR_3 = parse_frame_header(VAR_0)) < 0)
return VAR_3; if ((VAR_3 = alloc_sample_buffer(VAR_0)) < 0)
return VAR_3; if ((VAR_3 = parse_frame_data(VAR_0, HEADER_CORE, 0)) < 0)
return VAR_3; if ((VAR_3 = parse_optional_info(VAR_0)) < 0)
return VAR_3; if (VAR_0->frame_size > VAR_2 && VAR_0->frame_size < VAR_2 + 4)
VAR_0->frame_size = VAR_2; if (ff_dca_seek_bits(&VAR_0->gb, VAR_0->frame_size * 8)) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Read past end of core frame\n"); if (VAR_0->avctx->err_recognition & AV_EF_EXPLODE)
return AVERROR_INVALIDDATA; } return 0; }