static int vp3_decode_frame(AVCodecContext *avctx,

                            void *data, int *data_size,

                            AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    int buf_size = avpkt->size;

    Vp3DecodeContext *s = avctx->priv_data;

    GetBitContext gb;

    static int counter = 0;

    int i;



    init_get_bits(&gb, buf, buf_size * 8);



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

    {

        av_log(avctx, AV_LOG_ERROR, "Header packet passed to frame decoder, skipping\n");

        return -1;

    }



    s->keyframe = !get_bits1(&gb);

    if (!s->theora)

        skip_bits(&gb, 1);

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

        s->last_qps[i] = s->qps[i];



    s->nqps=0;

    do{

        s->qps[s->nqps++]= get_bits(&gb, 6);

    } while(s->theora >= 0x030200 && s->nqps<3 && get_bits1(&gb));

    for (i = s->nqps; i < 3; i++)

        s->qps[i] = -1;



    if (s->avctx->debug & FF_DEBUG_PICT_INFO)

        av_log(s->avctx, AV_LOG_INFO, " VP3 %sframe #%d: Q index = %d\n",

            s->keyframe?"key":"", counter, s->qps[0]);

    counter++;



    if (s->qps[0] != s->last_qps[0])

        init_loop_filter(s);



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

        // reinit all dequantizers if the first one changed, because

        // the DC of the first quantizer must be used for all matrices

        if (s->qps[i] != s->last_qps[i] || s->qps[0] != s->last_qps[0])

            init_dequantizer(s, i);



    if (avctx->skip_frame >= AVDISCARD_NONKEY && !s->keyframe)

        return buf_size;



    if (s->keyframe) {

        if (!s->theora)

        {

            skip_bits(&gb, 4); /* width code */

            skip_bits(&gb, 4); /* height code */

            if (s->version)

            {

                s->version = get_bits(&gb, 5);

                if (counter == 1)

                    av_log(s->avctx, AV_LOG_DEBUG, "VP version: %d\n", s->version);

            }

        }

        if (s->version || s->theora)

        {

                if (get_bits1(&gb))

                    av_log(s->avctx, AV_LOG_ERROR, "Warning, unsupported keyframe coding type?!\n");

            skip_bits(&gb, 2); /* reserved? */

        }



        if (s->last_frame.data[0] == s->golden_frame.data[0]) {

            if (s->golden_frame.data[0])

                avctx->release_buffer(avctx, &s->golden_frame);

            s->last_frame= s->golden_frame; /* ensure that we catch any access to this released frame */

        } else {

            if (s->golden_frame.data[0])

                avctx->release_buffer(avctx, &s->golden_frame);

            if (s->last_frame.data[0])

                avctx->release_buffer(avctx, &s->last_frame);

        }



        s->golden_frame.reference = 3;

        if(avctx->get_buffer(avctx, &s->golden_frame) < 0) {

            av_log(s->avctx, AV_LOG_ERROR, "vp3: get_buffer() failed\n");

            return -1;

        }



        /* golden frame is also the current frame */

        s->current_frame= s->golden_frame;



        /* time to figure out pixel addresses? */

        if (!s->pixel_addresses_initialized)

        {

            vp3_calculate_pixel_addresses(s);

            s->pixel_addresses_initialized = 1;

        }

    } else {

        /* allocate a new current frame */

        s->current_frame.reference = 3;

        if (!s->pixel_addresses_initialized) {

            av_log(s->avctx, AV_LOG_ERROR, "vp3: first frame not a keyframe\n");

            return -1;

        }

        if(avctx->get_buffer(avctx, &s->current_frame) < 0) {

            av_log(s->avctx, AV_LOG_ERROR, "vp3: get_buffer() failed\n");

            return -1;

        }

    }



    s->current_frame.qscale_table= s->qscale_table; //FIXME allocate individual tables per AVFrame

    s->current_frame.qstride= 0;



    init_frame(s, &gb);



    if (unpack_superblocks(s, &gb)){

        av_log(s->avctx, AV_LOG_ERROR, "error in unpack_superblocks\n");

        return -1;

    }

    if (unpack_modes(s, &gb)){

        av_log(s->avctx, AV_LOG_ERROR, "error in unpack_modes\n");

        return -1;

    }

    if (unpack_vectors(s, &gb)){

        av_log(s->avctx, AV_LOG_ERROR, "error in unpack_vectors\n");

        return -1;

    }

    if (unpack_block_qpis(s, &gb)){

        av_log(s->avctx, AV_LOG_ERROR, "error in unpack_block_qpis\n");

        return -1;

    }

    if (unpack_dct_coeffs(s, &gb)){

        av_log(s->avctx, AV_LOG_ERROR, "error in unpack_dct_coeffs\n");

        return -1;

    }



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

        render_slice(s, i);



    apply_loop_filter(s);



    *data_size=sizeof(AVFrame);

    *(AVFrame*)data= s->current_frame;



    /* release the last frame, if it is allocated and if it is not the

     * golden frame */

    if ((s->last_frame.data[0]) &&

        (s->last_frame.data[0] != s->golden_frame.data[0]))

        avctx->release_buffer(avctx, &s->last_frame);



    /* shuffle frames (last = current) */

    s->last_frame= s->current_frame;

    s->current_frame.data[0]= NULL; /* ensure that we catch any access to this released frame */



    return buf_size;

}

static int vp3_decode_frame(AVCodecContext *avctx,

                            void *data, int *data_size,

                            AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    int buf_size = avpkt->size;

    Vp3DecodeContext *s = avctx->priv_data;

    GetBitContext gb;

    static int counter = 0;

    int i;



    init_get_bits(&gb, buf, buf_size * 8);



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

    {

        av_log(avctx, AV_LOG_ERROR, "Header packet passed to frame decoder, skipping\n");

        return -1;

    }



    s->keyframe = !get_bits1(&gb);

    if (!s->theora)

        skip_bits(&gb, 1);

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

        s->last_qps[i] = s->qps[i];



    s->nqps=0;

    do{

        s->qps[s->nqps++]= get_bits(&gb, 6);

    } while(s->theora >= 0x030200 && s->nqps<3 && get_bits1(&gb));

    for (i = s->nqps; i < 3; i++)

        s->qps[i] = -1;



    if (s->avctx->debug & FF_DEBUG_PICT_INFO)

        av_log(s->avctx, AV_LOG_INFO, " VP3 %sframe #%d: Q index = %d\n",

            s->keyframe?"key":"", counter, s->qps[0]);

    counter++;



    if (s->qps[0] != s->last_qps[0])

        init_loop_filter(s);



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

        

        

        if (s->qps[i] != s->last_qps[i] || s->qps[0] != s->last_qps[0])

            init_dequantizer(s, i);



    if (avctx->skip_frame >= AVDISCARD_NONKEY && !s->keyframe)

        return buf_size;



    if (s->keyframe) {

        if (!s->theora)

        {

            skip_bits(&gb, 4); 

            skip_bits(&gb, 4); 

            if (s->version)

            {

                s->version = get_bits(&gb, 5);

                if (counter == 1)

                    av_log(s->avctx, AV_LOG_DEBUG, "VP version: %d\n", s->version);

            }

        }

        if (s->version || s->theora)

        {

                if (get_bits1(&gb))

                    av_log(s->avctx, AV_LOG_ERROR, "Warning, unsupported keyframe coding type?!\n");

            skip_bits(&gb, 2); 

        }



        if (s->last_frame.data[0] == s->golden_frame.data[0]) {

            if (s->golden_frame.data[0])

                avctx->release_buffer(avctx, &s->golden_frame);

            s->last_frame= s->golden_frame; 

        } else {

            if (s->golden_frame.data[0])

                avctx->release_buffer(avctx, &s->golden_frame);

            if (s->last_frame.data[0])

                avctx->release_buffer(avctx, &s->last_frame);

        }



        s->golden_frame.reference = 3;

        if(avctx->get_buffer(avctx, &s->golden_frame) < 0) {

            av_log(s->avctx, AV_LOG_ERROR, "vp3: get_buffer() failed\n");

            return -1;

        }



        

        s->current_frame= s->golden_frame;



        

        if (!s->pixel_addresses_initialized)

        {

            vp3_calculate_pixel_addresses(s);

            s->pixel_addresses_initialized = 1;

        }

    } else {

        

        s->current_frame.reference = 3;

        if (!s->pixel_addresses_initialized) {

            av_log(s->avctx, AV_LOG_ERROR, "vp3: first frame not a keyframe\n");

            return -1;

        }

        if(avctx->get_buffer(avctx, &s->current_frame) < 0) {

            av_log(s->avctx, AV_LOG_ERROR, "vp3: get_buffer() failed\n");

            return -1;

        }

    }



    s->current_frame.qscale_table= s->qscale_table; 

    s->current_frame.qstride= 0;



    init_frame(s, &gb);



    if (unpack_superblocks(s, &gb)){

        av_log(s->avctx, AV_LOG_ERROR, "error in unpack_superblocks\n");

        return -1;

    }

    if (unpack_modes(s, &gb)){

        av_log(s->avctx, AV_LOG_ERROR, "error in unpack_modes\n");

        return -1;

    }

    if (unpack_vectors(s, &gb)){

        av_log(s->avctx, AV_LOG_ERROR, "error in unpack_vectors\n");

        return -1;

    }

    if (unpack_block_qpis(s, &gb)){

        av_log(s->avctx, AV_LOG_ERROR, "error in unpack_block_qpis\n");

        return -1;

    }

    if (unpack_dct_coeffs(s, &gb)){

        av_log(s->avctx, AV_LOG_ERROR, "error in unpack_dct_coeffs\n");

        return -1;

    }



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

        render_slice(s, i);



    apply_loop_filter(s);



    *data_size=sizeof(AVFrame);

    *(AVFrame*)data= s->current_frame;



    



    if ((s->last_frame.data[0]) &&

        (s->last_frame.data[0] != s->golden_frame.data[0]))

        avctx->release_buffer(avctx, &s->last_frame);



    

    s->last_frame= s->current_frame;

    s->current_frame.data[0]= NULL; 



    return buf_size;

}

static int FUNC_0(AVCodecContext *VAR_0,

                            void *VAR_1, int *VAR_2,

                            AVPacket *VAR_3)

{

    const uint8_t *VAR_4 = VAR_3->VAR_1;

    int VAR_5 = VAR_3->size;

    Vp3DecodeContext *s = VAR_0->priv_data;

    GetBitContext gb;

    static int VAR_6 = 0;

    int VAR_7;



    init_get_bits(&gb, VAR_4, VAR_5 * 8);



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

    {

        av_log(VAR_0, AV_LOG_ERROR, "Header packet passed to frame decoder, skipping\n");

        return -1;

    }



    s->keyframe = !get_bits1(&gb);

    if (!s->theora)

        skip_bits(&gb, 1);

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

        s->last_qps[VAR_7] = s->qps[VAR_7];



    s->nqps=0;

    do{

        s->qps[s->nqps++]= get_bits(&gb, 6);

    } while(s->theora >= 0x030200 && s->nqps<3 && get_bits1(&gb));

    for (VAR_7 = s->nqps; VAR_7 < 3; VAR_7++)

        s->qps[VAR_7] = -1;



    if (s->VAR_0->debug & FF_DEBUG_PICT_INFO)

        av_log(s->VAR_0, AV_LOG_INFO, " VP3 %sframe #%d: Q index = %d\n",

            s->keyframe?"key":"", VAR_6, s->qps[0]);

    VAR_6++;



    if (s->qps[0] != s->last_qps[0])

        init_loop_filter(s);



    for (VAR_7 = 0; VAR_7 < s->nqps; VAR_7++)

        

        

        if (s->qps[VAR_7] != s->last_qps[VAR_7] || s->qps[0] != s->last_qps[0])

            init_dequantizer(s, VAR_7);



    if (VAR_0->skip_frame >= AVDISCARD_NONKEY && !s->keyframe)

        return VAR_5;



    if (s->keyframe) {

        if (!s->theora)

        {

            skip_bits(&gb, 4); 

            skip_bits(&gb, 4); 

            if (s->version)

            {

                s->version = get_bits(&gb, 5);

                if (VAR_6 == 1)

                    av_log(s->VAR_0, AV_LOG_DEBUG, "VP version: %d\n", s->version);

            }

        }

        if (s->version || s->theora)

        {

                if (get_bits1(&gb))

                    av_log(s->VAR_0, AV_LOG_ERROR, "Warning, unsupported keyframe coding type?!\n");

            skip_bits(&gb, 2); 

        }



        if (s->last_frame.VAR_1[0] == s->golden_frame.VAR_1[0]) {

            if (s->golden_frame.VAR_1[0])

                VAR_0->release_buffer(VAR_0, &s->golden_frame);

            s->last_frame= s->golden_frame; 

        } else {

            if (s->golden_frame.VAR_1[0])

                VAR_0->release_buffer(VAR_0, &s->golden_frame);

            if (s->last_frame.VAR_1[0])

                VAR_0->release_buffer(VAR_0, &s->last_frame);

        }



        s->golden_frame.reference = 3;

        if(VAR_0->get_buffer(VAR_0, &s->golden_frame) < 0) {

            av_log(s->VAR_0, AV_LOG_ERROR, "vp3: get_buffer() failed\n");

            return -1;

        }



        

        s->current_frame= s->golden_frame;



        

        if (!s->pixel_addresses_initialized)

        {

            vp3_calculate_pixel_addresses(s);

            s->pixel_addresses_initialized = 1;

        }

    } else {

        

        s->current_frame.reference = 3;

        if (!s->pixel_addresses_initialized) {

            av_log(s->VAR_0, AV_LOG_ERROR, "vp3: first frame not a keyframe\n");

            return -1;

        }

        if(VAR_0->get_buffer(VAR_0, &s->current_frame) < 0) {

            av_log(s->VAR_0, AV_LOG_ERROR, "vp3: get_buffer() failed\n");

            return -1;

        }

    }



    s->current_frame.qscale_table= s->qscale_table; 

    s->current_frame.qstride= 0;



    init_frame(s, &gb);



    if (unpack_superblocks(s, &gb)){

        av_log(s->VAR_0, AV_LOG_ERROR, "error in unpack_superblocks\n");

        return -1;

    }

    if (unpack_modes(s, &gb)){

        av_log(s->VAR_0, AV_LOG_ERROR, "error in unpack_modes\n");

        return -1;

    }

    if (unpack_vectors(s, &gb)){

        av_log(s->VAR_0, AV_LOG_ERROR, "error in unpack_vectors\n");

        return -1;

    }

    if (unpack_block_qpis(s, &gb)){

        av_log(s->VAR_0, AV_LOG_ERROR, "error in unpack_block_qpis\n");

        return -1;

    }

    if (unpack_dct_coeffs(s, &gb)){

        av_log(s->VAR_0, AV_LOG_ERROR, "error in unpack_dct_coeffs\n");

        return -1;

    }



    for (VAR_7 = 0; VAR_7 < s->macroblock_height; VAR_7++)

        render_slice(s, VAR_7);



    apply_loop_filter(s);



    *VAR_2=sizeof(AVFrame);

    *(AVFrame*)VAR_1= s->current_frame;



    



    if ((s->last_frame.VAR_1[0]) &&

        (s->last_frame.VAR_1[0] != s->golden_frame.VAR_1[0]))

        VAR_0->release_buffer(VAR_0, &s->last_frame);



    

    s->last_frame= s->current_frame;

    s->current_frame.VAR_1[0]= NULL; 



    return VAR_5;

}

static int FUNC_0(AVCodecContext *VAR_0,
void *VAR_1, int *VAR_2,
AVPacket *VAR_3)
{ const uint8_t *VAR_4 = VAR_3->VAR_1; int VAR_5 = VAR_3->size; Vp3DecodeContext *s = VAR_0->priv_data; GetBitContext gb; static int VAR_6 = 0; int VAR_7; init_get_bits(&gb, VAR_4, VAR_5 * 8); if (s->theora && get_bits1(&gb))
{ av_log(VAR_0, AV_LOG_ERROR, "Header packet passed to frame decoder, skipping\n"); return -1; } s->keyframe = !get_bits1(&gb); if (!s->theora)
skip_bits(&gb, 1); for (VAR_7 = 0; VAR_7 < 3; VAR_7++) s->last_qps[VAR_7] = s->qps[VAR_7]; s->nqps=0; do{ s->qps[s->nqps++]= get_bits(&gb, 6); } while(s->theora >= 0x030200 && s->nqps<3 && get_bits1(&gb)); for (VAR_7 = s->nqps; VAR_7 < 3; VAR_7++) s->qps[VAR_7] = -1; if (s->VAR_0->debug & FF_DEBUG_PICT_INFO)
av_log(s->VAR_0, AV_LOG_INFO, " VP3 %sframe #%d: Q index = %d\n",
s->keyframe?"key":"", VAR_6, s->qps[0]); VAR_6++; if (s->qps[0] != s->last_qps[0])
init_loop_filter(s); for (VAR_7 = 0; VAR_7 < s->nqps; VAR_7++) if (s->qps[VAR_7] != s->last_qps[VAR_7] || s->qps[0] != s->last_qps[0])
init_dequantizer(s, VAR_7); if (VAR_0->skip_frame >= AVDISCARD_NONKEY && !s->keyframe)
return VAR_5; if (s->keyframe) { if (!s->theora)
{ skip_bits(&gb, 4); skip_bits(&gb, 4); if (s->version)
{ s->version = get_bits(&gb, 5); if (VAR_6 == 1)
av_log(s->VAR_0, AV_LOG_DEBUG, "VP version: %d\n", s->version); } } if (s->version || s->theora)
{ if (get_bits1(&gb))
av_log(s->VAR_0, AV_LOG_ERROR, "Warning, unsupported keyframe coding type?!\n"); skip_bits(&gb, 2); } if (s->last_frame.VAR_1[0] == s->golden_frame.VAR_1[0]) { if (s->golden_frame.VAR_1[0])
VAR_0->release_buffer(VAR_0, &s->golden_frame); s->last_frame= s->golden_frame; } else { if (s->golden_frame.VAR_1[0])
VAR_0->release_buffer(VAR_0, &s->golden_frame); if (s->last_frame.VAR_1[0])
VAR_0->release_buffer(VAR_0, &s->last_frame); } s->golden_frame.reference = 3; if(VAR_0->get_buffer(VAR_0, &s->golden_frame) < 0) { av_log(s->VAR_0, AV_LOG_ERROR, "vp3: get_buffer() failed\n"); return -1; } s->current_frame= s->golden_frame; if (!s->pixel_addresses_initialized)
{ vp3_calculate_pixel_addresses(s); s->pixel_addresses_initialized = 1; } } else { s->current_frame.reference = 3; if (!s->pixel_addresses_initialized) { av_log(s->VAR_0, AV_LOG_ERROR, "vp3: first frame not a keyframe\n"); return -1; } if(VAR_0->get_buffer(VAR_0, &s->current_frame) < 0) { av_log(s->VAR_0, AV_LOG_ERROR, "vp3: get_buffer() failed\n"); return -1; } } s->current_frame.qscale_table= s->qscale_table; s->current_frame.qstride= 0; init_frame(s, &gb); if (unpack_superblocks(s, &gb)){ av_log(s->VAR_0, AV_LOG_ERROR, "error in unpack_superblocks\n"); return -1; } if (unpack_modes(s, &gb)){ av_log(s->VAR_0, AV_LOG_ERROR, "error in unpack_modes\n"); return -1; } if (unpack_vectors(s, &gb)){ av_log(s->VAR_0, AV_LOG_ERROR, "error in unpack_vectors\n"); return -1; } if (unpack_block_qpis(s, &gb)){ av_log(s->VAR_0, AV_LOG_ERROR, "error in unpack_block_qpis\n"); return -1; } if (unpack_dct_coeffs(s, &gb)){ av_log(s->VAR_0, AV_LOG_ERROR, "error in unpack_dct_coeffs\n"); return -1; } for (VAR_7 = 0; VAR_7 < s->macroblock_height; VAR_7++) render_slice(s, VAR_7); apply_loop_filter(s); *VAR_2=sizeof(AVFrame); *(AVFrame*)VAR_1= s->current_frame; if ((s->last_frame.VAR_1[0]) &&
(s->last_frame.VAR_1[0] != s->golden_frame.VAR_1[0]))
VAR_0->release_buffer(VAR_0, &s->last_frame); s->last_frame= s->current_frame; s->current_frame.VAR_1[0]= NULL; return VAR_5; }