static int alloc_frame_buffer(AVCodecContext *avctx,  Picture *pic,

                              MotionEstContext *me, ScratchpadContext *sc,

                              int chroma_x_shift, int chroma_y_shift,

                              int linesize, int uvlinesize)

{

    int edges_needed = av_codec_is_encoder(avctx->codec);

    int r, ret;



    pic->tf.f = pic->f;

    if (avctx->codec_id != AV_CODEC_ID_WMV3IMAGE &&

        avctx->codec_id != AV_CODEC_ID_VC1IMAGE  &&

        avctx->codec_id != AV_CODEC_ID_MSS2) {

        if (edges_needed) {

            pic->f->width  = avctx->width  + 2 * EDGE_WIDTH;

            pic->f->height = avctx->height + 2 * EDGE_WIDTH;

        }



        r = ff_thread_get_buffer(avctx, &pic->tf,

                                 pic->reference ? AV_GET_BUFFER_FLAG_REF : 0);

    } else {

        pic->f->width  = avctx->width;

        pic->f->height = avctx->height;

        pic->f->format = avctx->pix_fmt;

        r = avcodec_default_get_buffer2(avctx, pic->f, 0);

    }



    if (r < 0 || !pic->f->buf[0]) {

        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed (%d %p)\n",

               r, pic->f->data[0]);

        return -1;

    }



    if (edges_needed) {

        int i;

        for (i = 0; pic->f->data[i]; i++) {

            int offset = (EDGE_WIDTH >> (i ? chroma_y_shift : 0)) *

                         pic->f->linesize[i] +

                         (EDGE_WIDTH >> (i ? chroma_x_shift : 0));

            pic->f->data[i] += offset;

        }

        pic->f->width  = avctx->width;

        pic->f->height = avctx->height;

    }



    if (avctx->hwaccel) {

        assert(!pic->hwaccel_picture_private);

        if (avctx->hwaccel->frame_priv_data_size) {

            pic->hwaccel_priv_buf = av_buffer_allocz(avctx->hwaccel->frame_priv_data_size);

            if (!pic->hwaccel_priv_buf) {

                av_log(avctx, AV_LOG_ERROR, "alloc_frame_buffer() failed (hwaccel private data allocation)\n");

                return -1;

            }

            pic->hwaccel_picture_private = pic->hwaccel_priv_buf->data;

        }

    }



    if (linesize && (linesize   != pic->f->linesize[0] ||

                     uvlinesize != pic->f->linesize[1])) {

        av_log(avctx, AV_LOG_ERROR,

               "get_buffer() failed (stride changed)\n");

        ff_mpeg_unref_picture(avctx, pic);

        return -1;

    }



    if (pic->f->linesize[1] != pic->f->linesize[2]) {

        av_log(avctx, AV_LOG_ERROR,

               "get_buffer() failed (uv stride mismatch)\n");

        ff_mpeg_unref_picture(avctx, pic);

        return -1;

    }



    if (!sc->edge_emu_buffer &&

        (ret = ff_mpeg_framesize_alloc(avctx, me, sc,

                                       pic->f->linesize[0])) < 0) {

        av_log(avctx, AV_LOG_ERROR,

               "get_buffer() failed to allocate context scratch buffers.\n");

        ff_mpeg_unref_picture(avctx, pic);

        return ret;

    }



    return 0;

}

static int alloc_frame_buffer(AVCodecContext *avctx,  Picture *pic,

                              MotionEstContext *me, ScratchpadContext *sc,

                              int chroma_x_shift, int chroma_y_shift,

                              int linesize, int uvlinesize)

{

    int edges_needed = av_codec_is_encoder(avctx->codec);

    int r, ret;



    pic->tf.f = pic->f;

    if (avctx->codec_id != AV_CODEC_ID_WMV3IMAGE &&

        avctx->codec_id != AV_CODEC_ID_VC1IMAGE  &&

        avctx->codec_id != AV_CODEC_ID_MSS2) {

        if (edges_needed) {

            pic->f->width  = avctx->width  + 2 * EDGE_WIDTH;

            pic->f->height = avctx->height + 2 * EDGE_WIDTH;

        }



        r = ff_thread_get_buffer(avctx, &pic->tf,

                                 pic->reference ? AV_GET_BUFFER_FLAG_REF : 0);

    } else {

        pic->f->width  = avctx->width;

        pic->f->height = avctx->height;

        pic->f->format = avctx->pix_fmt;

        r = avcodec_default_get_buffer2(avctx, pic->f, 0);

    }



    if (r < 0 || !pic->f->buf[0]) {

        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed (%d %p)\n",

               r, pic->f->data[0]);

        return -1;

    }



    if (edges_needed) {

        int i;

        for (i = 0; pic->f->data[i]; i++) {

            int offset = (EDGE_WIDTH >> (i ? chroma_y_shift : 0)) *

                         pic->f->linesize[i] +

                         (EDGE_WIDTH >> (i ? chroma_x_shift : 0));

            pic->f->data[i] += offset;

        }

        pic->f->width  = avctx->width;

        pic->f->height = avctx->height;

    }



    if (avctx->hwaccel) {

        assert(!pic->hwaccel_picture_private);

        if (avctx->hwaccel->frame_priv_data_size) {

            pic->hwaccel_priv_buf = av_buffer_allocz(avctx->hwaccel->frame_priv_data_size);

            if (!pic->hwaccel_priv_buf) {

                av_log(avctx, AV_LOG_ERROR, "alloc_frame_buffer() failed (hwaccel private data allocation)\n");

                return -1;

            }

            pic->hwaccel_picture_private = pic->hwaccel_priv_buf->data;

        }

    }



    if (linesize && (linesize   != pic->f->linesize[0] ||

                     uvlinesize != pic->f->linesize[1])) {

        av_log(avctx, AV_LOG_ERROR,

               "get_buffer() failed (stride changed)\n");

        ff_mpeg_unref_picture(avctx, pic);

        return -1;

    }



    if (pic->f->linesize[1] != pic->f->linesize[2]) {

        av_log(avctx, AV_LOG_ERROR,

               "get_buffer() failed (uv stride mismatch)\n");

        ff_mpeg_unref_picture(avctx, pic);

        return -1;

    }



    if (!sc->edge_emu_buffer &&

        (ret = ff_mpeg_framesize_alloc(avctx, me, sc,

                                       pic->f->linesize[0])) < 0) {

        av_log(avctx, AV_LOG_ERROR,

               "get_buffer() failed to allocate context scratch buffers.\n");

        ff_mpeg_unref_picture(avctx, pic);

        return ret;

    }



    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0,  Picture *VAR_1,

                              MotionEstContext *VAR_2, ScratchpadContext *VAR_3,

                              int VAR_4, int VAR_5,

                              int VAR_6, int VAR_7)

{

    int VAR_8 = av_codec_is_encoder(VAR_0->codec);

    int VAR_9, VAR_10;



    VAR_1->tf.f = VAR_1->f;

    if (VAR_0->codec_id != AV_CODEC_ID_WMV3IMAGE &&

        VAR_0->codec_id != AV_CODEC_ID_VC1IMAGE  &&

        VAR_0->codec_id != AV_CODEC_ID_MSS2) {

        if (VAR_8) {

            VAR_1->f->width  = VAR_0->width  + 2 * EDGE_WIDTH;

            VAR_1->f->height = VAR_0->height + 2 * EDGE_WIDTH;

        }



        VAR_9 = ff_thread_get_buffer(VAR_0, &VAR_1->tf,

                                 VAR_1->reference ? AV_GET_BUFFER_FLAG_REF : 0);

    } else {

        VAR_1->f->width  = VAR_0->width;

        VAR_1->f->height = VAR_0->height;

        VAR_1->f->format = VAR_0->pix_fmt;

        VAR_9 = avcodec_default_get_buffer2(VAR_0, VAR_1->f, 0);

    }



    if (VAR_9 < 0 || !VAR_1->f->buf[0]) {

        av_log(VAR_0, AV_LOG_ERROR, "get_buffer() failed (%d %p)\n",

               VAR_9, VAR_1->f->data[0]);

        return -1;

    }



    if (VAR_8) {

        int VAR_11;

        for (VAR_11 = 0; VAR_1->f->data[VAR_11]; VAR_11++) {

            int offset = (EDGE_WIDTH >> (VAR_11 ? VAR_5 : 0)) *

                         VAR_1->f->VAR_6[VAR_11] +

                         (EDGE_WIDTH >> (VAR_11 ? VAR_4 : 0));

            VAR_1->f->data[VAR_11] += offset;

        }

        VAR_1->f->width  = VAR_0->width;

        VAR_1->f->height = VAR_0->height;

    }



    if (VAR_0->hwaccel) {

        assert(!VAR_1->hwaccel_picture_private);

        if (VAR_0->hwaccel->frame_priv_data_size) {

            VAR_1->hwaccel_priv_buf = av_buffer_allocz(VAR_0->hwaccel->frame_priv_data_size);

            if (!VAR_1->hwaccel_priv_buf) {

                av_log(VAR_0, AV_LOG_ERROR, "FUNC_0() failed (hwaccel private data allocation)\n");

                return -1;

            }

            VAR_1->hwaccel_picture_private = VAR_1->hwaccel_priv_buf->data;

        }

    }



    if (VAR_6 && (VAR_6   != VAR_1->f->VAR_6[0] ||

                     VAR_7 != VAR_1->f->VAR_6[1])) {

        av_log(VAR_0, AV_LOG_ERROR,

               "get_buffer() failed (stride changed)\n");

        ff_mpeg_unref_picture(VAR_0, VAR_1);

        return -1;

    }



    if (VAR_1->f->VAR_6[1] != VAR_1->f->VAR_6[2]) {

        av_log(VAR_0, AV_LOG_ERROR,

               "get_buffer() failed (uv stride mismatch)\n");

        ff_mpeg_unref_picture(VAR_0, VAR_1);

        return -1;

    }



    if (!VAR_3->edge_emu_buffer &&

        (VAR_10 = ff_mpeg_framesize_alloc(VAR_0, VAR_2, VAR_3,

                                       VAR_1->f->VAR_6[0])) < 0) {

        av_log(VAR_0, AV_LOG_ERROR,

               "get_buffer() failed to allocate context scratch buffers.\n");

        ff_mpeg_unref_picture(VAR_0, VAR_1);

        return VAR_10;

    }



    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0,  Picture *VAR_1,
MotionEstContext *VAR_2, ScratchpadContext *VAR_3,
int VAR_4, int VAR_5,
int VAR_6, int VAR_7)
{ int VAR_8 = av_codec_is_encoder(VAR_0->codec); int VAR_9, VAR_10; VAR_1->tf.f = VAR_1->f; if (VAR_0->codec_id != AV_CODEC_ID_WMV3IMAGE &&
VAR_0->codec_id != AV_CODEC_ID_VC1IMAGE  &&
VAR_0->codec_id != AV_CODEC_ID_MSS2) { if (VAR_8) { VAR_1->f->width  = VAR_0->width  + 2 * EDGE_WIDTH; VAR_1->f->height = VAR_0->height + 2 * EDGE_WIDTH; } VAR_9 = ff_thread_get_buffer(VAR_0, &VAR_1->tf,
VAR_1->reference ? AV_GET_BUFFER_FLAG_REF : 0); } else { VAR_1->f->width  = VAR_0->width; VAR_1->f->height = VAR_0->height; VAR_1->f->format = VAR_0->pix_fmt; VAR_9 = avcodec_default_get_buffer2(VAR_0, VAR_1->f, 0); } if (VAR_9 < 0 || !VAR_1->f->buf[0]) { av_log(VAR_0, AV_LOG_ERROR, "get_buffer() failed (%d %p)\n",
VAR_9, VAR_1->f->data[0]); return -1; } if (VAR_8) { int VAR_11; for (VAR_11 = 0; VAR_1->f->data[VAR_11]; VAR_11++) { int offset = (EDGE_WIDTH >> (VAR_11 ? VAR_5 : 0)) *
VAR_1->f->VAR_6[VAR_11] +
(EDGE_WIDTH >> (VAR_11 ? VAR_4 : 0)); VAR_1->f->data[VAR_11] += offset; } VAR_1->f->width  = VAR_0->width; VAR_1->f->height = VAR_0->height; } if (VAR_0->hwaccel) { assert(!VAR_1->hwaccel_picture_private); if (VAR_0->hwaccel->frame_priv_data_size) { VAR_1->hwaccel_priv_buf = av_buffer_allocz(VAR_0->hwaccel->frame_priv_data_size); if (!VAR_1->hwaccel_priv_buf) { av_log(VAR_0, AV_LOG_ERROR, "FUNC_0() failed (hwaccel private data allocation)\n"); return -1; } VAR_1->hwaccel_picture_private = VAR_1->hwaccel_priv_buf->data; } } if (VAR_6 && (VAR_6   != VAR_1->f->VAR_6[0] ||
VAR_7 != VAR_1->f->VAR_6[1])) { av_log(VAR_0, AV_LOG_ERROR,
"get_buffer() failed (stride changed)\n"); ff_mpeg_unref_picture(VAR_0, VAR_1); return -1; } if (VAR_1->f->VAR_6[1] != VAR_1->f->VAR_6[2]) { av_log(VAR_0, AV_LOG_ERROR,
"get_buffer() failed (uv stride mismatch)\n"); ff_mpeg_unref_picture(VAR_0, VAR_1); return -1; } if (!VAR_3->edge_emu_buffer &&
(VAR_10 = ff_mpeg_framesize_alloc(VAR_0, VAR_2, VAR_3,
VAR_1->f->VAR_6[0])) < 0) { av_log(VAR_0, AV_LOG_ERROR,
"get_buffer() failed to allocate context scratch buffers.\n"); ff_mpeg_unref_picture(VAR_0, VAR_1); return VAR_10; } return 0; }