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

{

    VP56RangeCoder *c = &s->c;

    int header_size, hscale, vscale, ret;

    int width  = s->avctx->width;

    int height = s->avctx->height;



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

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

    s->invisible = !(buf[0] & 0x10);

    header_size  = AV_RL24(buf) >> 5;

    buf      += 3;

    buf_size -= 3;



    if (s->profile > 3)

        av_log(s->avctx, AV_LOG_WARNING, "Unknown profile %d\n", s->profile);



    if (!s->profile)

        memcpy(s->put_pixels_tab, s->vp8dsp.put_vp8_epel_pixels_tab,

               sizeof(s->put_pixels_tab));

    else    // profile 1-3 use bilinear, 4+ aren't defined so whatever

        memcpy(s->put_pixels_tab, s->vp8dsp.put_vp8_bilinear_pixels_tab,

               sizeof(s->put_pixels_tab));



    if (header_size > buf_size - 7 * s->keyframe) {

        av_log(s->avctx, AV_LOG_ERROR, "Header size larger than data provided\n");

        return AVERROR_INVALIDDATA;

    }



    if (s->keyframe) {

        if (AV_RL24(buf) != 0x2a019d) {

            av_log(s->avctx, AV_LOG_ERROR,

                   "Invalid start code 0x%x\n", AV_RL24(buf));

            return AVERROR_INVALIDDATA;

        }

        width     = AV_RL16(buf + 3) & 0x3fff;

        height    = AV_RL16(buf + 5) & 0x3fff;

        hscale    = buf[4] >> 6;

        vscale    = buf[6] >> 6;

        buf      += 7;

        buf_size -= 7;



        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));

        memcpy(s->prob->mvc, vp8_mv_default_prob,

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

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

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

    }



    ff_vp56_init_range_decoder(c, buf, header_size);

    buf      += header_size;

    buf_size -= header_size;



    if (s->keyframe) {

        if (vp8_rac_get(c))

            av_log(s->avctx, AV_LOG_WARNING, "Unspecified colorspace\n");

        vp8_rac_get(c); // whether we can skip clamping in dsp functions

    }



    if ((s->segmentation.enabled = vp8_rac_get(c)))

        parse_segment_info(s);

    else

        s->segmentation.update_map = 0; // FIXME: move this to some init function?



    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);



    if ((s->lf_delta.enabled = vp8_rac_get(c)))

        if (vp8_rac_get(c))

            update_lf_deltas(s);



    if (setup_partitions(s, buf, buf_size)) {

        av_log(s->avctx, AV_LOG_ERROR, "Invalid partitions\n");

        return AVERROR_INVALIDDATA;

    }



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

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

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

            return ret;



    get_quants(s);



    if (!s->keyframe) {

        update_refs(s);

        s->sign_bias[VP56_FRAME_GOLDEN]               = vp8_rac_get(c);

        s->sign_bias[VP56_FRAME_GOLDEN2 /* altref */] = vp8_rac_get(c);

    }



    // if we aren't saving this frame's probabilities for future frames,

    // make a copy of the current probabilities

    if (!(s->update_probabilities = vp8_rac_get(c)))

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



    s->update_last = s->keyframe || vp8_rac_get(c);



    vp78_update_probability_tables(s);



    if ((s->mbskip_enabled = vp8_rac_get(c)))

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



    if (!s->keyframe) {

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

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

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

        vp78_update_pred16x16_pred8x8_mvc_probabilities(s, VP8_MVC_SIZE);

    }



    return 0;

}

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

{

    VP56RangeCoder *c = &s->c;

    int header_size, hscale, vscale, ret;

    int width  = s->avctx->width;

    int height = s->avctx->height;



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

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

    s->invisible = !(buf[0] & 0x10);

    header_size  = AV_RL24(buf) >> 5;

    buf      += 3;

    buf_size -= 3;



    if (s->profile > 3)

        av_log(s->avctx, AV_LOG_WARNING, "Unknown profile %d\n", s->profile);



    if (!s->profile)

        memcpy(s->put_pixels_tab, s->vp8dsp.put_vp8_epel_pixels_tab,

               sizeof(s->put_pixels_tab));

    else    

        memcpy(s->put_pixels_tab, s->vp8dsp.put_vp8_bilinear_pixels_tab,

               sizeof(s->put_pixels_tab));



    if (header_size > buf_size - 7 * s->keyframe) {

        av_log(s->avctx, AV_LOG_ERROR, "Header size larger than data provided\n");

        return AVERROR_INVALIDDATA;

    }



    if (s->keyframe) {

        if (AV_RL24(buf) != 0x2a019d) {

            av_log(s->avctx, AV_LOG_ERROR,

                   "Invalid start code 0x%x\n", AV_RL24(buf));

            return AVERROR_INVALIDDATA;

        }

        width     = AV_RL16(buf + 3) & 0x3fff;

        height    = AV_RL16(buf + 5) & 0x3fff;

        hscale    = buf[4] >> 6;

        vscale    = buf[6] >> 6;

        buf      += 7;

        buf_size -= 7;



        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));

        memcpy(s->prob->mvc, vp8_mv_default_prob,

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

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

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

    }



    ff_vp56_init_range_decoder(c, buf, header_size);

    buf      += header_size;

    buf_size -= header_size;



    if (s->keyframe) {

        if (vp8_rac_get(c))

            av_log(s->avctx, AV_LOG_WARNING, "Unspecified colorspace\n");

        vp8_rac_get(c); 

    }



    if ((s->segmentation.enabled = vp8_rac_get(c)))

        parse_segment_info(s);

    else

        s->segmentation.update_map = 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);



    if ((s->lf_delta.enabled = vp8_rac_get(c)))

        if (vp8_rac_get(c))

            update_lf_deltas(s);



    if (setup_partitions(s, buf, buf_size)) {

        av_log(s->avctx, AV_LOG_ERROR, "Invalid partitions\n");

        return AVERROR_INVALIDDATA;

    }



    if (!s->macroblocks_base || 

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

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

            return ret;



    get_quants(s);



    if (!s->keyframe) {

        update_refs(s);

        s->sign_bias[VP56_FRAME_GOLDEN]               = vp8_rac_get(c);

        s->sign_bias[VP56_FRAME_GOLDEN2 ] = vp8_rac_get(c);

    }



    

    

    if (!(s->update_probabilities = vp8_rac_get(c)))

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



    s->update_last = s->keyframe || vp8_rac_get(c);



    vp78_update_probability_tables(s);



    if ((s->mbskip_enabled = vp8_rac_get(c)))

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



    if (!s->keyframe) {

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

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

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

        vp78_update_pred16x16_pred8x8_mvc_probabilities(s, VP8_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;

    int VAR_7  = VAR_0->avctx->VAR_7;

    int VAR_8 = VAR_0->avctx->VAR_8;



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

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

    VAR_0->invisible = !(VAR_1[0] & 0x10);

    VAR_3  = AV_RL24(VAR_1) >> 5;

    VAR_1      += 3;

    VAR_2 -= 3;



    if (VAR_0->profile > 3)

        av_log(VAR_0->avctx, AV_LOG_WARNING, "Unknown profile %d\n", VAR_0->profile);



    if (!VAR_0->profile)

        memcpy(VAR_0->put_pixels_tab, VAR_0->vp8dsp.put_vp8_epel_pixels_tab,

               sizeof(VAR_0->put_pixels_tab));

    else    

        memcpy(VAR_0->put_pixels_tab, VAR_0->vp8dsp.put_vp8_bilinear_pixels_tab,

               sizeof(VAR_0->put_pixels_tab));



    if (VAR_3 > VAR_2 - 7 * VAR_0->keyframe) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "Header size larger than data provided\n");

        return AVERROR_INVALIDDATA;

    }



    if (VAR_0->keyframe) {

        if (AV_RL24(VAR_1) != 0x2a019d) {

            av_log(VAR_0->avctx, AV_LOG_ERROR,

                   "Invalid start code 0x%x\n", AV_RL24(VAR_1));

            return AVERROR_INVALIDDATA;

        }

        VAR_7     = AV_RL16(VAR_1 + 3) & 0x3fff;

        VAR_8    = AV_RL16(VAR_1 + 5) & 0x3fff;

        VAR_4    = VAR_1[4] >> 6;

        VAR_5    = VAR_1[6] >> 6;

        VAR_1      += 7;

        VAR_2 -= 7;



        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));

        memcpy(VAR_0->prob->mvc, vp8_mv_default_prob,

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

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

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

    }



    ff_vp56_init_range_decoder(c, VAR_1, VAR_3);

    VAR_1      += VAR_3;

    VAR_2 -= VAR_3;



    if (VAR_0->keyframe) {

        if (vp8_rac_get(c))

            av_log(VAR_0->avctx, AV_LOG_WARNING, "Unspecified colorspace\n");

        vp8_rac_get(c); 

    }



    if ((VAR_0->segmentation.enabled = vp8_rac_get(c)))

        parse_segment_info(VAR_0);

    else

        VAR_0->segmentation.update_map = 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);



    if ((VAR_0->lf_delta.enabled = vp8_rac_get(c)))

        if (vp8_rac_get(c))

            update_lf_deltas(VAR_0);



    if (setup_partitions(VAR_0, VAR_1, VAR_2)) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "Invalid partitions\n");

        return AVERROR_INVALIDDATA;

    }



    if (!VAR_0->macroblocks_base || 

        VAR_7 != VAR_0->avctx->VAR_7 || VAR_8 != VAR_0->avctx->VAR_8)

        if ((VAR_6 = vp8_update_dimensions(VAR_0, VAR_7, VAR_8)) < 0)

            return VAR_6;



    get_quants(VAR_0);



    if (!VAR_0->keyframe) {

        update_refs(VAR_0);

        VAR_0->sign_bias[VP56_FRAME_GOLDEN]               = vp8_rac_get(c);

        VAR_0->sign_bias[VP56_FRAME_GOLDEN2 ] = vp8_rac_get(c);

    }



    

    

    if (!(VAR_0->update_probabilities = vp8_rac_get(c)))

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



    VAR_0->update_last = VAR_0->keyframe || vp8_rac_get(c);



    vp78_update_probability_tables(VAR_0);



    if ((VAR_0->mbskip_enabled = vp8_rac_get(c)))

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



    if (!VAR_0->keyframe) {

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

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

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

        vp78_update_pred16x16_pred8x8_mvc_probabilities(VAR_0, VP8_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; int VAR_7  = VAR_0->avctx->VAR_7; int VAR_8 = VAR_0->avctx->VAR_8; VAR_0->keyframe  = !(VAR_1[0] & 1); VAR_0->profile   =  (VAR_1[0]>>1) & 7; VAR_0->invisible = !(VAR_1[0] & 0x10); VAR_3  = AV_RL24(VAR_1) >> 5; VAR_1      += 3; VAR_2 -= 3; if (VAR_0->profile > 3)
av_log(VAR_0->avctx, AV_LOG_WARNING, "Unknown profile %d\n", VAR_0->profile); if (!VAR_0->profile)
memcpy(VAR_0->put_pixels_tab, VAR_0->vp8dsp.put_vp8_epel_pixels_tab,
sizeof(VAR_0->put_pixels_tab)); else
memcpy(VAR_0->put_pixels_tab, VAR_0->vp8dsp.put_vp8_bilinear_pixels_tab,
sizeof(VAR_0->put_pixels_tab)); if (VAR_3 > VAR_2 - 7 * VAR_0->keyframe) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Header size larger than data provided\n"); return AVERROR_INVALIDDATA; } if (VAR_0->keyframe) { if (AV_RL24(VAR_1) != 0x2a019d) { av_log(VAR_0->avctx, AV_LOG_ERROR,
"Invalid start code 0x%x\n", AV_RL24(VAR_1)); return AVERROR_INVALIDDATA; } VAR_7     = AV_RL16(VAR_1 + 3) & 0x3fff; VAR_8    = AV_RL16(VAR_1 + 5) & 0x3fff; VAR_4    = VAR_1[4] >> 6; VAR_5    = VAR_1[6] >> 6; VAR_1      += 7; VAR_2 -= 7; 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)); memcpy(VAR_0->prob->mvc, vp8_mv_default_prob,
sizeof(VAR_0->prob->mvc)); memset(&VAR_0->segmentation, 0, sizeof(VAR_0->segmentation)); memset(&VAR_0->lf_delta, 0, sizeof(VAR_0->lf_delta)); } ff_vp56_init_range_decoder(c, VAR_1, VAR_3); VAR_1      += VAR_3; VAR_2 -= VAR_3; if (VAR_0->keyframe) { if (vp8_rac_get(c))
av_log(VAR_0->avctx, AV_LOG_WARNING, "Unspecified colorspace\n"); vp8_rac_get(c); } if ((VAR_0->segmentation.enabled = vp8_rac_get(c)))
parse_segment_info(VAR_0); else
VAR_0->segmentation.update_map = 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); if ((VAR_0->lf_delta.enabled = vp8_rac_get(c)))
if (vp8_rac_get(c))
update_lf_deltas(VAR_0); if (setup_partitions(VAR_0, VAR_1, VAR_2)) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Invalid partitions\n"); return AVERROR_INVALIDDATA; } if (!VAR_0->macroblocks_base ||
VAR_7 != VAR_0->avctx->VAR_7 || VAR_8 != VAR_0->avctx->VAR_8)
if ((VAR_6 = vp8_update_dimensions(VAR_0, VAR_7, VAR_8)) < 0)
return VAR_6; get_quants(VAR_0); if (!VAR_0->keyframe) { update_refs(VAR_0); VAR_0->sign_bias[VP56_FRAME_GOLDEN]               = vp8_rac_get(c); VAR_0->sign_bias[VP56_FRAME_GOLDEN2 ] = vp8_rac_get(c); } if (!(VAR_0->update_probabilities = vp8_rac_get(c)))
VAR_0->prob[1] = VAR_0->prob[0]; VAR_0->update_last = VAR_0->keyframe || vp8_rac_get(c); vp78_update_probability_tables(VAR_0); if ((VAR_0->mbskip_enabled = vp8_rac_get(c)))
VAR_0->prob->mbskip = vp8_rac_get_uint(c, 8); if (!VAR_0->keyframe) { VAR_0->prob->intra  = vp8_rac_get_uint(c, 8); VAR_0->prob->last   = vp8_rac_get_uint(c, 8); VAR_0->prob->golden = vp8_rac_get_uint(c, 8); vp78_update_pred16x16_pred8x8_mvc_probabilities(VAR_0, VP8_MVC_SIZE); } return 0; }