static int svq1_decode_frame(AVCodecContext *avctx, void *data,

                             int *data_size, AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    int buf_size       = avpkt->size;

    MpegEncContext *s  = avctx->priv_data;

    uint8_t *current, *previous;

    int result, i, x, y, width, height;

    AVFrame *pict = data;

    svq1_pmv *pmv;



    /* initialize bit buffer */

    init_get_bits(&s->gb, buf, buf_size * 8);



    /* decode frame header */

    s->f_code = get_bits(&s->gb, 22);



    if ((s->f_code & ~0x70) || !(s->f_code & 0x60))

        return AVERROR_INVALIDDATA;



    /* swap some header bytes (why?) */

    if (s->f_code != 0x20) {

        uint32_t *src = (uint32_t *)(buf + 4);



        if (buf_size < 36)

            return AVERROR_INVALIDDATA;



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

            src[i] = ((src[i] << 16) | (src[i] >> 16)) ^ src[7 - i];

    }



    result = svq1_decode_frame_header(&s->gb, s);



    if (result != 0) {

        av_dlog(s->avctx, "Error in svq1_decode_frame_header %i\n", result);

        return result;

    }

    avcodec_set_dimensions(avctx, s->width, s->height);



    /* FIXME: This avoids some confusion for "B frames" without 2 references.

     * This should be removed after libavcodec can handle more flexible

     * picture types & ordering */

    if (s->pict_type == AV_PICTURE_TYPE_B && s->last_picture_ptr == NULL)

        return buf_size;



    if ((avctx->skip_frame >= AVDISCARD_NONREF &&

         s->pict_type == AV_PICTURE_TYPE_B)    ||

        (avctx->skip_frame >= AVDISCARD_NONKEY &&

         s->pict_type != AV_PICTURE_TYPE_I)    ||

        avctx->skip_frame >= AVDISCARD_ALL)

        return buf_size;



    if ((result = ff_MPV_frame_start(s, avctx)) < 0)

        return result;



    pmv = av_malloc((FFALIGN(s->width, 16) / 8 + 3) * sizeof(*pmv));

    if (!pmv)

        return AVERROR(ENOMEM);



    /* decode y, u and v components */

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

        int linesize;

        if (i == 0) {

            width    = FFALIGN(s->width,  16);

            height   = FFALIGN(s->height, 16);

            linesize = s->linesize;

        } else {

            if (s->flags & CODEC_FLAG_GRAY)

                break;

            width    = FFALIGN(s->width  / 4, 16);

            height   = FFALIGN(s->height / 4, 16);

            linesize = s->uvlinesize;

        }



        current = s->current_picture.f.data[i];



        if (s->pict_type == AV_PICTURE_TYPE_B)

            previous = s->next_picture.f.data[i];

        else

            previous = s->last_picture.f.data[i];



        if (s->pict_type == AV_PICTURE_TYPE_I) {

            /* keyframe */

            for (y = 0; y < height; y += 16) {

                for (x = 0; x < width; x += 16) {

                    result = svq1_decode_block_intra(&s->gb, &current[x],

                                                     linesize);

                    if (result != 0) {

                        av_log(s->avctx, AV_LOG_INFO,

                               "Error in svq1_decode_block %i (keyframe)\n",

                               result);

                        goto err;

                    }

                }

                current += 16 * linesize;

            }

        } else {

            /* delta frame */

            memset(pmv, 0, ((width / 8) + 3) * sizeof(svq1_pmv));



            for (y = 0; y < height; y += 16) {

                for (x = 0; x < width; x += 16) {

                    result = svq1_decode_delta_block(s, &s->gb, &current[x],

                                                     previous, linesize,

                                                     pmv, x, y);

                    if (result != 0) {

                        av_dlog(s->avctx,

                                "Error in svq1_decode_delta_block %i\n",

                                result);

                        goto err;

                    }

                }



                pmv[0].x     =

                    pmv[0].y = 0;



                current += 16 * linesize;

            }

        }

    }



    *pict = s->current_picture.f;



    ff_MPV_frame_end(s);



    *data_size = sizeof(AVFrame);

    result     = buf_size;



err:

    av_free(pmv);

    return result;

}

static int svq1_decode_frame(AVCodecContext *avctx, void *data,

                             int *data_size, AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    int buf_size       = avpkt->size;

    MpegEncContext *s  = avctx->priv_data;

    uint8_t *current, *previous;

    int result, i, x, y, width, height;

    AVFrame *pict = data;

    svq1_pmv *pmv;



    

    init_get_bits(&s->gb, buf, buf_size * 8);



    

    s->f_code = get_bits(&s->gb, 22);



    if ((s->f_code & ~0x70) || !(s->f_code & 0x60))

        return AVERROR_INVALIDDATA;



    

    if (s->f_code != 0x20) {

        uint32_t *src = (uint32_t *)(buf + 4);



        if (buf_size < 36)

            return AVERROR_INVALIDDATA;



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

            src[i] = ((src[i] << 16) | (src[i] >> 16)) ^ src[7 - i];

    }



    result = svq1_decode_frame_header(&s->gb, s);



    if (result != 0) {

        av_dlog(s->avctx, "Error in svq1_decode_frame_header %i\n", result);

        return result;

    }

    avcodec_set_dimensions(avctx, s->width, s->height);



    





    if (s->pict_type == AV_PICTURE_TYPE_B && s->last_picture_ptr == NULL)

        return buf_size;



    if ((avctx->skip_frame >= AVDISCARD_NONREF &&

         s->pict_type == AV_PICTURE_TYPE_B)    ||

        (avctx->skip_frame >= AVDISCARD_NONKEY &&

         s->pict_type != AV_PICTURE_TYPE_I)    ||

        avctx->skip_frame >= AVDISCARD_ALL)

        return buf_size;



    if ((result = ff_MPV_frame_start(s, avctx)) < 0)

        return result;



    pmv = av_malloc((FFALIGN(s->width, 16) / 8 + 3) * sizeof(*pmv));

    if (!pmv)

        return AVERROR(ENOMEM);



    

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

        int linesize;

        if (i == 0) {

            width    = FFALIGN(s->width,  16);

            height   = FFALIGN(s->height, 16);

            linesize = s->linesize;

        } else {

            if (s->flags & CODEC_FLAG_GRAY)

                break;

            width    = FFALIGN(s->width  / 4, 16);

            height   = FFALIGN(s->height / 4, 16);

            linesize = s->uvlinesize;

        }



        current = s->current_picture.f.data[i];



        if (s->pict_type == AV_PICTURE_TYPE_B)

            previous = s->next_picture.f.data[i];

        else

            previous = s->last_picture.f.data[i];



        if (s->pict_type == AV_PICTURE_TYPE_I) {

            

            for (y = 0; y < height; y += 16) {

                for (x = 0; x < width; x += 16) {

                    result = svq1_decode_block_intra(&s->gb, &current[x],

                                                     linesize);

                    if (result != 0) {

                        av_log(s->avctx, AV_LOG_INFO,

                               "Error in svq1_decode_block %i (keyframe)\n",

                               result);

                        goto err;

                    }

                }

                current += 16 * linesize;

            }

        } else {

            

            memset(pmv, 0, ((width / 8) + 3) * sizeof(svq1_pmv));



            for (y = 0; y < height; y += 16) {

                for (x = 0; x < width; x += 16) {

                    result = svq1_decode_delta_block(s, &s->gb, &current[x],

                                                     previous, linesize,

                                                     pmv, x, y);

                    if (result != 0) {

                        av_dlog(s->avctx,

                                "Error in svq1_decode_delta_block %i\n",

                                result);

                        goto err;

                    }

                }



                pmv[0].x     =

                    pmv[0].y = 0;



                current += 16 * linesize;

            }

        }

    }



    *pict = s->current_picture.f;



    ff_MPV_frame_end(s);



    *data_size = sizeof(AVFrame);

    result     = buf_size;



err:

    av_free(pmv);

    return result;

}

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;

    MpegEncContext *s  = VAR_0->priv_data;

    uint8_t *current, *previous;

    int VAR_6, VAR_7, VAR_8, VAR_9, VAR_10, VAR_11;

    AVFrame *pict = VAR_1;

    svq1_pmv *pmv;



    

    init_get_bits(&s->gb, VAR_4, VAR_5 * 8);



    

    s->f_code = get_bits(&s->gb, 22);



    if ((s->f_code & ~0x70) || !(s->f_code & 0x60))

        return AVERROR_INVALIDDATA;



    

    if (s->f_code != 0x20) {

        uint32_t *src = (uint32_t *)(VAR_4 + 4);



        if (VAR_5 < 36)

            return AVERROR_INVALIDDATA;



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

            src[VAR_7] = ((src[VAR_7] << 16) | (src[VAR_7] >> 16)) ^ src[7 - VAR_7];

    }



    VAR_6 = svq1_decode_frame_header(&s->gb, s);



    if (VAR_6 != 0) {

        av_dlog(s->VAR_0, "Error in svq1_decode_frame_header %VAR_7\n", VAR_6);

        return VAR_6;

    }

    avcodec_set_dimensions(VAR_0, s->VAR_10, s->VAR_11);



    





    if (s->pict_type == AV_PICTURE_TYPE_B && s->last_picture_ptr == NULL)

        return VAR_5;



    if ((VAR_0->skip_frame >= AVDISCARD_NONREF &&

         s->pict_type == AV_PICTURE_TYPE_B)    ||

        (VAR_0->skip_frame >= AVDISCARD_NONKEY &&

         s->pict_type != AV_PICTURE_TYPE_I)    ||

        VAR_0->skip_frame >= AVDISCARD_ALL)

        return VAR_5;



    if ((VAR_6 = ff_MPV_frame_start(s, VAR_0)) < 0)

        return VAR_6;



    pmv = av_malloc((FFALIGN(s->VAR_10, 16) / 8 + 3) * sizeof(*pmv));

    if (!pmv)

        return AVERROR(ENOMEM);



    

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

        int VAR_12;

        if (VAR_7 == 0) {

            VAR_10    = FFALIGN(s->VAR_10,  16);

            VAR_11   = FFALIGN(s->VAR_11, 16);

            VAR_12 = s->VAR_12;

        } else {

            if (s->flags & CODEC_FLAG_GRAY)

                break;

            VAR_10    = FFALIGN(s->VAR_10  / 4, 16);

            VAR_11   = FFALIGN(s->VAR_11 / 4, 16);

            VAR_12 = s->uvlinesize;

        }



        current = s->current_picture.f.VAR_1[VAR_7];



        if (s->pict_type == AV_PICTURE_TYPE_B)

            previous = s->next_picture.f.VAR_1[VAR_7];

        else

            previous = s->last_picture.f.VAR_1[VAR_7];



        if (s->pict_type == AV_PICTURE_TYPE_I) {

            

            for (VAR_9 = 0; VAR_9 < VAR_11; VAR_9 += 16) {

                for (VAR_8 = 0; VAR_8 < VAR_10; VAR_8 += 16) {

                    VAR_6 = svq1_decode_block_intra(&s->gb, &current[VAR_8],

                                                     VAR_12);

                    if (VAR_6 != 0) {

                        av_log(s->VAR_0, AV_LOG_INFO,

                               "Error in svq1_decode_block %VAR_7 (keyframe)\n",

                               VAR_6);

                        goto err;

                    }

                }

                current += 16 * VAR_12;

            }

        } else {

            

            memset(pmv, 0, ((VAR_10 / 8) + 3) * sizeof(svq1_pmv));



            for (VAR_9 = 0; VAR_9 < VAR_11; VAR_9 += 16) {

                for (VAR_8 = 0; VAR_8 < VAR_10; VAR_8 += 16) {

                    VAR_6 = svq1_decode_delta_block(s, &s->gb, &current[VAR_8],

                                                     previous, VAR_12,

                                                     pmv, VAR_8, VAR_9);

                    if (VAR_6 != 0) {

                        av_dlog(s->VAR_0,

                                "Error in svq1_decode_delta_block %VAR_7\n",

                                VAR_6);

                        goto err;

                    }

                }



                pmv[0].VAR_8     =

                    pmv[0].VAR_9 = 0;



                current += 16 * VAR_12;

            }

        }

    }



    *pict = s->current_picture.f;



    ff_MPV_frame_end(s);



    *VAR_2 = sizeof(AVFrame);

    VAR_6     = VAR_5;



err:

    av_free(pmv);

    return VAR_6;

}

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; MpegEncContext *s  = VAR_0->priv_data; uint8_t *current, *previous; int VAR_6, VAR_7, VAR_8, VAR_9, VAR_10, VAR_11; AVFrame *pict = VAR_1; svq1_pmv *pmv; init_get_bits(&s->gb, VAR_4, VAR_5 * 8); s->f_code = get_bits(&s->gb, 22); if ((s->f_code & ~0x70) || !(s->f_code & 0x60))
return AVERROR_INVALIDDATA; if (s->f_code != 0x20) { uint32_t *src = (uint32_t *)(VAR_4 + 4); if (VAR_5 < 36)
return AVERROR_INVALIDDATA; for (VAR_7 = 0; VAR_7 < 4; VAR_7++) src[VAR_7] = ((src[VAR_7] << 16) | (src[VAR_7] >> 16)) ^ src[7 - VAR_7]; } VAR_6 = svq1_decode_frame_header(&s->gb, s); if (VAR_6 != 0) { av_dlog(s->VAR_0, "Error in svq1_decode_frame_header %VAR_7\n", VAR_6); return VAR_6; } avcodec_set_dimensions(VAR_0, s->VAR_10, s->VAR_11); if (s->pict_type == AV_PICTURE_TYPE_B && s->last_picture_ptr == NULL)
return VAR_5; if ((VAR_0->skip_frame >= AVDISCARD_NONREF &&
s->pict_type == AV_PICTURE_TYPE_B)    ||
(VAR_0->skip_frame >= AVDISCARD_NONKEY &&
s->pict_type != AV_PICTURE_TYPE_I)    ||
VAR_0->skip_frame >= AVDISCARD_ALL)
return VAR_5; if ((VAR_6 = ff_MPV_frame_start(s, VAR_0)) < 0)
return VAR_6; pmv = av_malloc((FFALIGN(s->VAR_10, 16) / 8 + 3) * sizeof(*pmv)); if (!pmv)
return AVERROR(ENOMEM); for (VAR_7 = 0; VAR_7 < 3; VAR_7++) { int VAR_12; if (VAR_7 == 0) { VAR_10    = FFALIGN(s->VAR_10,  16); VAR_11   = FFALIGN(s->VAR_11, 16); VAR_12 = s->VAR_12; } else { if (s->flags & CODEC_FLAG_GRAY)
break; VAR_10    = FFALIGN(s->VAR_10  / 4, 16); VAR_11   = FFALIGN(s->VAR_11 / 4, 16); VAR_12 = s->uvlinesize; } current = s->current_picture.f.VAR_1[VAR_7]; if (s->pict_type == AV_PICTURE_TYPE_B)
previous = s->next_picture.f.VAR_1[VAR_7]; else
previous = s->last_picture.f.VAR_1[VAR_7]; if (s->pict_type == AV_PICTURE_TYPE_I) { for (VAR_9 = 0; VAR_9 < VAR_11; VAR_9 += 16) { for (VAR_8 = 0; VAR_8 < VAR_10; VAR_8 += 16) { VAR_6 = svq1_decode_block_intra(&s->gb, &current[VAR_8],
VAR_12); if (VAR_6 != 0) { av_log(s->VAR_0, AV_LOG_INFO,
"Error in svq1_decode_block %VAR_7 (keyframe)\n",
VAR_6); goto err; } } current += 16 * VAR_12; } } else { memset(pmv, 0, ((VAR_10 / 8) + 3) * sizeof(svq1_pmv)); for (VAR_9 = 0; VAR_9 < VAR_11; VAR_9 += 16) { for (VAR_8 = 0; VAR_8 < VAR_10; VAR_8 += 16) { VAR_6 = svq1_decode_delta_block(s, &s->gb, &current[VAR_8],
previous, VAR_12,
pmv, VAR_8, VAR_9); if (VAR_6 != 0) { av_dlog(s->VAR_0,
"Error in svq1_decode_delta_block %VAR_7\n",
VAR_6); goto err; } } pmv[0].VAR_8     =
pmv[0].VAR_9 = 0; current += 16 * VAR_12; } } } *pict = s->current_picture.f; ff_MPV_frame_end(s); *VAR_2 = sizeof(AVFrame); VAR_6     = VAR_5; err:
av_free(pmv); return VAR_6; }