static int vp7_decode_frame_header(VP8Context *s, const uint8_t *buf, int buf_size)

{

    VP56RangeCoder *c = &s->c;

    int part1_size, hscale, vscale, i, j, ret;

    int width  = s->avctx->width;

    int height = s->avctx->height;



    s->profile = (buf[0] >> 1) & 7;

    if (s->profile > 1) {

        avpriv_request_sample(s->avctx, "Unknown profile %d", s->profile);

        return AVERROR_INVALIDDATA;

    }



    s->keyframe  = !(buf[0] & 1);

    s->invisible = 0;

    part1_size   = AV_RL24(buf) >> 4;



    buf      += 4 - s->profile;

    buf_size -= 4 - s->profile;



    memcpy(s->put_pixels_tab, s->vp8dsp.put_vp8_epel_pixels_tab, sizeof(s->put_pixels_tab));



    ff_vp56_init_range_decoder(c, buf, part1_size);

    buf      += part1_size;

    buf_size -= part1_size;



    /* A. Dimension information (keyframes only) */

    if (s->keyframe) {

        width  = vp8_rac_get_uint(c, 12);

        height = vp8_rac_get_uint(c, 12);

        hscale = vp8_rac_get_uint(c, 2);

        vscale = vp8_rac_get_uint(c, 2);

        if (hscale || vscale)

            avpriv_request_sample(s->avctx, "Upscaling");



        s->update_golden = s->update_altref = VP56_FRAME_CURRENT;

        vp78_reset_probability_tables(s);

        memcpy(s->prob->pred16x16, vp8_pred16x16_prob_inter,

               sizeof(s->prob->pred16x16));

        memcpy(s->prob->pred8x8c, vp8_pred8x8c_prob_inter,

               sizeof(s->prob->pred8x8c));

        for (i = 0; i < 2; i++)

            memcpy(s->prob->mvc[i], vp7_mv_default_prob[i],

                   sizeof(vp7_mv_default_prob[i]));

        memset(&s->segmentation, 0, sizeof(s->segmentation));

        memset(&s->lf_delta, 0, sizeof(s->lf_delta));

        memcpy(s->prob[0].scan, zigzag_scan, sizeof(s->prob[0].scan));

    }



    if (s->keyframe || s->profile > 0)

        memset(s->inter_dc_pred, 0 , sizeof(s->inter_dc_pred));



    /* B. Decoding information for all four macroblock-level features */

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

        s->feature_enabled[i] = vp8_rac_get(c);

        if (s->feature_enabled[i]) {

             s->feature_present_prob[i] = vp8_rac_get_uint(c, 8);



             for (j = 0; j < 3; j++)

                 s->feature_index_prob[i][j] =

                     vp8_rac_get(c) ? vp8_rac_get_uint(c, 8) : 255;



             if (vp7_feature_value_size[i])

                 for (j = 0; j < 4; j++)

                     s->feature_value[i][j] =

                         vp8_rac_get(c) ? vp8_rac_get_uint(c, vp7_feature_value_size[s->profile][i]) : 0;

        }

    }



    s->segmentation.enabled    = 0;

    s->segmentation.update_map = 0;

    s->lf_delta.enabled        = 0;



    s->num_coeff_partitions = 1;

    ff_vp56_init_range_decoder(&s->coeff_partition[0], buf, buf_size);



    if (!s->macroblocks_base || /* first frame */

        width != s->avctx->width || height != s->avctx->height ||

        (width + 15) / 16 != s->mb_width || (height + 15) / 16 != s->mb_height) {

        if ((ret = vp7_update_dimensions(s, width, height)) < 0)

            return ret;

    }



    /* C. Dequantization indices */

    vp7_get_quants(s);



    /* D. Golden frame update flag (a Flag) for interframes only */

    if (!s->keyframe) {

        s->update_golden = vp8_rac_get(c) ? VP56_FRAME_CURRENT : VP56_FRAME_NONE;

        s->sign_bias[VP56_FRAME_GOLDEN] = 0;

    }



    s->update_last          = 1;

    s->update_probabilities = 1;

    s->fade_present         = 1;



    if (s->profile > 0) {

        s->update_probabilities = vp8_rac_get(c);

        if (!s->update_probabilities)

            s->prob[1] = s->prob[0];



        if (!s->keyframe)

            s->fade_present = vp8_rac_get(c);

    }



    /* E. Fading information for previous frame */

    if (s->fade_present && vp8_rac_get(c)) {

        if ((ret = vp7_fade_frame(s ,c)) < 0)

            return ret;

    }



    /* F. Loop filter type */

    if (!s->profile)

        s->filter.simple = vp8_rac_get(c);



    /* G. DCT coefficient ordering specification */

    if (vp8_rac_get(c))

        for (i = 1; i < 16; i++)

            s->prob[0].scan[i] = zigzag_scan[vp8_rac_get_uint(c, 4)];



    /* H. Loop filter levels  */

    if (s->profile > 0)

        s->filter.simple = vp8_rac_get(c);

    s->filter.level     = vp8_rac_get_uint(c, 6);

    s->filter.sharpness = vp8_rac_get_uint(c, 3);



    /* I. DCT coefficient probability update; 13.3 Token Probability Updates */

    vp78_update_probability_tables(s);



    s->mbskip_enabled = 0;



    /* J. The remaining frame header data occurs ONLY FOR INTERFRAMES */

    if (!s->keyframe) {

        s->prob->intra  = vp8_rac_get_uint(c, 8);

        s->prob->last   = vp8_rac_get_uint(c, 8);

        vp78_update_pred16x16_pred8x8_mvc_probabilities(s, VP7_MVC_SIZE);

    }



    return 0;

}

static int vp7_decode_frame_header(VP8Context *s, const uint8_t *buf, int buf_size)

{

    VP56RangeCoder *c = &s->c;

    int part1_size, hscale, vscale, i, j, ret;

    int width  = s->avctx->width;

    int height = s->avctx->height;



    s->profile = (buf[0] >> 1) & 7;

    if (s->profile > 1) {

        avpriv_request_sample(s->avctx, "Unknown profile %d", s->profile);

        return AVERROR_INVALIDDATA;

    }



    s->keyframe  = !(buf[0] & 1);

    s->invisible = 0;

    part1_size   = AV_RL24(buf) >> 4;



    buf      += 4 - s->profile;

    buf_size -= 4 - s->profile;



    memcpy(s->put_pixels_tab, s->vp8dsp.put_vp8_epel_pixels_tab, sizeof(s->put_pixels_tab));



    ff_vp56_init_range_decoder(c, buf, part1_size);

    buf      += part1_size;

    buf_size -= part1_size;



    

    if (s->keyframe) {

        width  = vp8_rac_get_uint(c, 12);

        height = vp8_rac_get_uint(c, 12);

        hscale = vp8_rac_get_uint(c, 2);

        vscale = vp8_rac_get_uint(c, 2);

        if (hscale || vscale)

            avpriv_request_sample(s->avctx, "Upscaling");



        s->update_golden = s->update_altref = VP56_FRAME_CURRENT;

        vp78_reset_probability_tables(s);

        memcpy(s->prob->pred16x16, vp8_pred16x16_prob_inter,

               sizeof(s->prob->pred16x16));

        memcpy(s->prob->pred8x8c, vp8_pred8x8c_prob_inter,

               sizeof(s->prob->pred8x8c));

        for (i = 0; i < 2; i++)

            memcpy(s->prob->mvc[i], vp7_mv_default_prob[i],

                   sizeof(vp7_mv_default_prob[i]));

        memset(&s->segmentation, 0, sizeof(s->segmentation));

        memset(&s->lf_delta, 0, sizeof(s->lf_delta));

        memcpy(s->prob[0].scan, zigzag_scan, sizeof(s->prob[0].scan));

    }



    if (s->keyframe || s->profile > 0)

        memset(s->inter_dc_pred, 0 , sizeof(s->inter_dc_pred));



    

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

        s->feature_enabled[i] = vp8_rac_get(c);

        if (s->feature_enabled[i]) {

             s->feature_present_prob[i] = vp8_rac_get_uint(c, 8);



             for (j = 0; j < 3; j++)

                 s->feature_index_prob[i][j] =

                     vp8_rac_get(c) ? vp8_rac_get_uint(c, 8) : 255;



             if (vp7_feature_value_size[i])

                 for (j = 0; j < 4; j++)

                     s->feature_value[i][j] =

                         vp8_rac_get(c) ? vp8_rac_get_uint(c, vp7_feature_value_size[s->profile][i]) : 0;

        }

    }



    s->segmentation.enabled    = 0;

    s->segmentation.update_map = 0;

    s->lf_delta.enabled        = 0;



    s->num_coeff_partitions = 1;

    ff_vp56_init_range_decoder(&s->coeff_partition[0], buf, buf_size);



    if (!s->macroblocks_base || 

        width != s->avctx->width || height != s->avctx->height ||

        (width + 15) / 16 != s->mb_width || (height + 15) / 16 != s->mb_height) {

        if ((ret = vp7_update_dimensions(s, width, height)) < 0)

            return ret;

    }



    

    vp7_get_quants(s);



    

    if (!s->keyframe) {

        s->update_golden = vp8_rac_get(c) ? VP56_FRAME_CURRENT : VP56_FRAME_NONE;

        s->sign_bias[VP56_FRAME_GOLDEN] = 0;

    }



    s->update_last          = 1;

    s->update_probabilities = 1;

    s->fade_present         = 1;



    if (s->profile > 0) {

        s->update_probabilities = vp8_rac_get(c);

        if (!s->update_probabilities)

            s->prob[1] = s->prob[0];



        if (!s->keyframe)

            s->fade_present = vp8_rac_get(c);

    }



    

    if (s->fade_present && vp8_rac_get(c)) {

        if ((ret = vp7_fade_frame(s ,c)) < 0)

            return ret;

    }



    

    if (!s->profile)

        s->filter.simple = vp8_rac_get(c);



    

    if (vp8_rac_get(c))

        for (i = 1; i < 16; i++)

            s->prob[0].scan[i] = zigzag_scan[vp8_rac_get_uint(c, 4)];



    

    if (s->profile > 0)

        s->filter.simple = vp8_rac_get(c);

    s->filter.level     = vp8_rac_get_uint(c, 6);

    s->filter.sharpness = vp8_rac_get_uint(c, 3);



    

    vp78_update_probability_tables(s);



    s->mbskip_enabled = 0;



    

    if (!s->keyframe) {

        s->prob->intra  = vp8_rac_get_uint(c, 8);

        s->prob->last   = vp8_rac_get_uint(c, 8);

        vp78_update_pred16x16_pred8x8_mvc_probabilities(s, VP7_MVC_SIZE);

    }



    return 0;

}

static int FUNC_0(VP8Context *VAR_0, const uint8_t *VAR_1, int VAR_2)

{

    VP56RangeCoder *c = &VAR_0->c;

    int VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, VAR_8;

    int VAR_9  = VAR_0->avctx->VAR_9;

    int VAR_10 = VAR_0->avctx->VAR_10;



    VAR_0->profile = (VAR_1[0] >> 1) & 7;

    if (VAR_0->profile > 1) {

        avpriv_request_sample(VAR_0->avctx, "Unknown profile %d", VAR_0->profile);

        return AVERROR_INVALIDDATA;

    }



    VAR_0->keyframe  = !(VAR_1[0] & 1);

    VAR_0->invisible = 0;

    VAR_3   = AV_RL24(VAR_1) >> 4;



    VAR_1      += 4 - VAR_0->profile;

    VAR_2 -= 4 - VAR_0->profile;



    memcpy(VAR_0->put_pixels_tab, VAR_0->vp8dsp.put_vp8_epel_pixels_tab, sizeof(VAR_0->put_pixels_tab));



    ff_vp56_init_range_decoder(c, VAR_1, VAR_3);

    VAR_1      += VAR_3;

    VAR_2 -= VAR_3;



    

    if (VAR_0->keyframe) {

        VAR_9  = vp8_rac_get_uint(c, 12);

        VAR_10 = vp8_rac_get_uint(c, 12);

        VAR_4 = vp8_rac_get_uint(c, 2);

        VAR_5 = vp8_rac_get_uint(c, 2);

        if (VAR_4 || VAR_5)

            avpriv_request_sample(VAR_0->avctx, "Upscaling");



        VAR_0->update_golden = VAR_0->update_altref = VP56_FRAME_CURRENT;

        vp78_reset_probability_tables(VAR_0);

        memcpy(VAR_0->prob->pred16x16, vp8_pred16x16_prob_inter,

               sizeof(VAR_0->prob->pred16x16));

        memcpy(VAR_0->prob->pred8x8c, vp8_pred8x8c_prob_inter,

               sizeof(VAR_0->prob->pred8x8c));

        for (VAR_6 = 0; VAR_6 < 2; VAR_6++)

            memcpy(VAR_0->prob->mvc[VAR_6], vp7_mv_default_prob[VAR_6],

                   sizeof(vp7_mv_default_prob[VAR_6]));

        memset(&VAR_0->segmentation, 0, sizeof(VAR_0->segmentation));

        memset(&VAR_0->lf_delta, 0, sizeof(VAR_0->lf_delta));

        memcpy(VAR_0->prob[0].scan, zigzag_scan, sizeof(VAR_0->prob[0].scan));

    }



    if (VAR_0->keyframe || VAR_0->profile > 0)

        memset(VAR_0->inter_dc_pred, 0 , sizeof(VAR_0->inter_dc_pred));



    

    for (VAR_6 = 0; VAR_6 < 4; VAR_6++) {

        VAR_0->feature_enabled[VAR_6] = vp8_rac_get(c);

        if (VAR_0->feature_enabled[VAR_6]) {

             VAR_0->feature_present_prob[VAR_6] = vp8_rac_get_uint(c, 8);



             for (VAR_7 = 0; VAR_7 < 3; VAR_7++)

                 VAR_0->feature_index_prob[VAR_6][VAR_7] =

                     vp8_rac_get(c) ? vp8_rac_get_uint(c, 8) : 255;



             if (vp7_feature_value_size[VAR_6])

                 for (VAR_7 = 0; VAR_7 < 4; VAR_7++)

                     VAR_0->feature_value[VAR_6][VAR_7] =

                         vp8_rac_get(c) ? vp8_rac_get_uint(c, vp7_feature_value_size[VAR_0->profile][VAR_6]) : 0;

        }

    }



    VAR_0->segmentation.enabled    = 0;

    VAR_0->segmentation.update_map = 0;

    VAR_0->lf_delta.enabled        = 0;



    VAR_0->num_coeff_partitions = 1;

    ff_vp56_init_range_decoder(&VAR_0->coeff_partition[0], VAR_1, VAR_2);



    if (!VAR_0->macroblocks_base || 

        VAR_9 != VAR_0->avctx->VAR_9 || VAR_10 != VAR_0->avctx->VAR_10 ||

        (VAR_9 + 15) / 16 != VAR_0->mb_width || (VAR_10 + 15) / 16 != VAR_0->mb_height) {

        if ((VAR_8 = vp7_update_dimensions(VAR_0, VAR_9, VAR_10)) < 0)

            return VAR_8;

    }



    

    vp7_get_quants(VAR_0);



    

    if (!VAR_0->keyframe) {

        VAR_0->update_golden = vp8_rac_get(c) ? VP56_FRAME_CURRENT : VP56_FRAME_NONE;

        VAR_0->sign_bias[VP56_FRAME_GOLDEN] = 0;

    }



    VAR_0->update_last          = 1;

    VAR_0->update_probabilities = 1;

    VAR_0->fade_present         = 1;



    if (VAR_0->profile > 0) {

        VAR_0->update_probabilities = vp8_rac_get(c);

        if (!VAR_0->update_probabilities)

            VAR_0->prob[1] = VAR_0->prob[0];



        if (!VAR_0->keyframe)

            VAR_0->fade_present = vp8_rac_get(c);

    }



    

    if (VAR_0->fade_present && vp8_rac_get(c)) {

        if ((VAR_8 = vp7_fade_frame(VAR_0 ,c)) < 0)

            return VAR_8;

    }



    

    if (!VAR_0->profile)

        VAR_0->filter.simple = vp8_rac_get(c);



    

    if (vp8_rac_get(c))

        for (VAR_6 = 1; VAR_6 < 16; VAR_6++)

            VAR_0->prob[0].scan[VAR_6] = zigzag_scan[vp8_rac_get_uint(c, 4)];



    

    if (VAR_0->profile > 0)

        VAR_0->filter.simple = vp8_rac_get(c);

    VAR_0->filter.level     = vp8_rac_get_uint(c, 6);

    VAR_0->filter.sharpness = vp8_rac_get_uint(c, 3);



    

    vp78_update_probability_tables(VAR_0);



    VAR_0->mbskip_enabled = 0;



    

    if (!VAR_0->keyframe) {

        VAR_0->prob->intra  = vp8_rac_get_uint(c, 8);

        VAR_0->prob->last   = vp8_rac_get_uint(c, 8);

        vp78_update_pred16x16_pred8x8_mvc_probabilities(VAR_0, VP7_MVC_SIZE);

    }



    return 0;

}

static int FUNC_0(VP8Context *VAR_0, const uint8_t *VAR_1, int VAR_2)
{ VP56RangeCoder *c = &VAR_0->c; int VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, VAR_8; int VAR_9  = VAR_0->avctx->VAR_9; int VAR_10 = VAR_0->avctx->VAR_10; VAR_0->profile = (VAR_1[0] >> 1) & 7; if (VAR_0->profile > 1) { avpriv_request_sample(VAR_0->avctx, "Unknown profile %d", VAR_0->profile); return AVERROR_INVALIDDATA; } VAR_0->keyframe  = !(VAR_1[0] & 1); VAR_0->invisible = 0; VAR_3   = AV_RL24(VAR_1) >> 4; VAR_1      += 4 - VAR_0->profile; VAR_2 -= 4 - VAR_0->profile; memcpy(VAR_0->put_pixels_tab, VAR_0->vp8dsp.put_vp8_epel_pixels_tab, sizeof(VAR_0->put_pixels_tab)); ff_vp56_init_range_decoder(c, VAR_1, VAR_3); VAR_1      += VAR_3; VAR_2 -= VAR_3; if (VAR_0->keyframe) { VAR_9  = vp8_rac_get_uint(c, 12); VAR_10 = vp8_rac_get_uint(c, 12); VAR_4 = vp8_rac_get_uint(c, 2); VAR_5 = vp8_rac_get_uint(c, 2); if (VAR_4 || VAR_5)
avpriv_request_sample(VAR_0->avctx, "Upscaling"); VAR_0->update_golden = VAR_0->update_altref = VP56_FRAME_CURRENT; vp78_reset_probability_tables(VAR_0); memcpy(VAR_0->prob->pred16x16, vp8_pred16x16_prob_inter,
sizeof(VAR_0->prob->pred16x16)); memcpy(VAR_0->prob->pred8x8c, vp8_pred8x8c_prob_inter,
sizeof(VAR_0->prob->pred8x8c)); for (VAR_6 = 0; VAR_6 < 2; VAR_6++) memcpy(VAR_0->prob->mvc[VAR_6], vp7_mv_default_prob[VAR_6],
sizeof(vp7_mv_default_prob[VAR_6])); memset(&VAR_0->segmentation, 0, sizeof(VAR_0->segmentation)); memset(&VAR_0->lf_delta, 0, sizeof(VAR_0->lf_delta)); memcpy(VAR_0->prob[0].scan, zigzag_scan, sizeof(VAR_0->prob[0].scan)); } if (VAR_0->keyframe || VAR_0->profile > 0)
memset(VAR_0->inter_dc_pred, 0 , sizeof(VAR_0->inter_dc_pred)); for (VAR_6 = 0; VAR_6 < 4; VAR_6++) { VAR_0->feature_enabled[VAR_6] = vp8_rac_get(c); if (VAR_0->feature_enabled[VAR_6]) { VAR_0->feature_present_prob[VAR_6] = vp8_rac_get_uint(c, 8); for (VAR_7 = 0; VAR_7 < 3; VAR_7++) VAR_0->feature_index_prob[VAR_6][VAR_7] =
vp8_rac_get(c) ? vp8_rac_get_uint(c, 8) : 255; if (vp7_feature_value_size[VAR_6])
for (VAR_7 = 0; VAR_7 < 4; VAR_7++) VAR_0->feature_value[VAR_6][VAR_7] =
vp8_rac_get(c) ? vp8_rac_get_uint(c, vp7_feature_value_size[VAR_0->profile][VAR_6]) : 0; } } VAR_0->segmentation.enabled    = 0; VAR_0->segmentation.update_map = 0; VAR_0->lf_delta.enabled        = 0; VAR_0->num_coeff_partitions = 1; ff_vp56_init_range_decoder(&VAR_0->coeff_partition[0], VAR_1, VAR_2); if (!VAR_0->macroblocks_base ||
VAR_9 != VAR_0->avctx->VAR_9 || VAR_10 != VAR_0->avctx->VAR_10 ||
(VAR_9 + 15) / 16 != VAR_0->mb_width || (VAR_10 + 15) / 16 != VAR_0->mb_height) { if ((VAR_8 = vp7_update_dimensions(VAR_0, VAR_9, VAR_10)) < 0)
return VAR_8; } vp7_get_quants(VAR_0); if (!VAR_0->keyframe) { VAR_0->update_golden = vp8_rac_get(c) ? VP56_FRAME_CURRENT : VP56_FRAME_NONE; VAR_0->sign_bias[VP56_FRAME_GOLDEN] = 0; } VAR_0->update_last          = 1; VAR_0->update_probabilities = 1; VAR_0->fade_present         = 1; if (VAR_0->profile > 0) { VAR_0->update_probabilities = vp8_rac_get(c); if (!VAR_0->update_probabilities)
VAR_0->prob[1] = VAR_0->prob[0]; if (!VAR_0->keyframe)
VAR_0->fade_present = vp8_rac_get(c); } if (VAR_0->fade_present && vp8_rac_get(c)) { if ((VAR_8 = vp7_fade_frame(VAR_0 ,c)) < 0)
return VAR_8; } if (!VAR_0->profile)
VAR_0->filter.simple = vp8_rac_get(c); if (vp8_rac_get(c))
for (VAR_6 = 1; VAR_6 < 16; VAR_6++) VAR_0->prob[0].scan[VAR_6] = zigzag_scan[vp8_rac_get_uint(c, 4)]; if (VAR_0->profile > 0)
VAR_0->filter.simple = vp8_rac_get(c); VAR_0->filter.level     = vp8_rac_get_uint(c, 6); VAR_0->filter.sharpness = vp8_rac_get_uint(c, 3); vp78_update_probability_tables(VAR_0); VAR_0->mbskip_enabled = 0; if (!VAR_0->keyframe) { VAR_0->prob->intra  = vp8_rac_get_uint(c, 8); VAR_0->prob->last   = vp8_rac_get_uint(c, 8); vp78_update_pred16x16_pred8x8_mvc_probabilities(VAR_0, VP7_MVC_SIZE); } return 0; }