int ff_xvmc_field_start(MpegEncContext *s, AVCodecContext *avctx)

{

    struct xvmc_pix_fmt *last, *next, *render = (struct xvmc_pix_fmt*)s->current_picture.f.data[2];

    const int mb_block_count = 4 + (1 << s->chroma_format);



    assert(avctx);

    if (!render || render->xvmc_id != AV_XVMC_ID ||

        !render->data_blocks || !render->mv_blocks ||

        (unsigned int)render->allocated_mv_blocks   > INT_MAX/(64*6) ||

        (unsigned int)render->allocated_data_blocks > INT_MAX/64     ||

        !render->p_surface) {

        av_log(avctx, AV_LOG_ERROR,

               "Render token doesn't look as expected.\n");

        return -1; // make sure that this is a render packet

    }



    if (render->filled_mv_blocks_num) {

        av_log(avctx, AV_LOG_ERROR,

               "Rendering surface contains %i unprocessed blocks.\n",

               render->filled_mv_blocks_num);

        return -1;

    }

    if (render->allocated_mv_blocks   < 1 ||

        render->allocated_data_blocks <  render->allocated_mv_blocks*mb_block_count ||

        render->start_mv_blocks_num   >= render->allocated_mv_blocks                ||

        render->next_free_data_block_num >

                        render->allocated_data_blocks -

                        mb_block_count*(render->allocated_mv_blocks-render->start_mv_blocks_num)) {

        av_log(avctx, AV_LOG_ERROR,

               "Rendering surface doesn't provide enough block structures to work with.\n");

        return -1;

    }



    render->picture_structure = s->picture_structure;

    render->flags             = s->first_field ? 0 : XVMC_SECOND_FIELD;

    render->p_future_surface  = NULL;

    render->p_past_surface    = NULL;



    switch(s->pict_type) {

        case  AV_PICTURE_TYPE_I:

            return 0; // no prediction from other frames

        case  AV_PICTURE_TYPE_B:

            next = (struct xvmc_pix_fmt*)s->next_picture.f.data[2];

            if (!next)

                return -1;

            if (next->xvmc_id != AV_XVMC_ID)

                return -1;

            render->p_future_surface = next->p_surface;

            // no return here, going to set forward prediction

        case  AV_PICTURE_TYPE_P:

            last = (struct xvmc_pix_fmt*)s->last_picture.f.data[2];

            if (!last)

                last = render; // predict second field from the first

            if (last->xvmc_id != AV_XVMC_ID)

                return -1;

            render->p_past_surface = last->p_surface;

            return 0;

    }



return -1;

}

int ff_xvmc_field_start(MpegEncContext *s, AVCodecContext *avctx)

{

    struct xvmc_pix_fmt *last, *next, *render = (struct xvmc_pix_fmt*)s->current_picture.f.data[2];

    const int mb_block_count = 4 + (1 << s->chroma_format);



    assert(avctx);

    if (!render || render->xvmc_id != AV_XVMC_ID ||

        !render->data_blocks || !render->mv_blocks ||

        (unsigned int)render->allocated_mv_blocks   > INT_MAX/(64*6) ||

        (unsigned int)render->allocated_data_blocks > INT_MAX/64     ||

        !render->p_surface) {

        av_log(avctx, AV_LOG_ERROR,

               "Render token doesn't look as expected.\n");

        return -1; 

    }



    if (render->filled_mv_blocks_num) {

        av_log(avctx, AV_LOG_ERROR,

               "Rendering surface contains %i unprocessed blocks.\n",

               render->filled_mv_blocks_num);

        return -1;

    }

    if (render->allocated_mv_blocks   < 1 ||

        render->allocated_data_blocks <  render->allocated_mv_blocks*mb_block_count ||

        render->start_mv_blocks_num   >= render->allocated_mv_blocks                ||

        render->next_free_data_block_num >

                        render->allocated_data_blocks -

                        mb_block_count*(render->allocated_mv_blocks-render->start_mv_blocks_num)) {

        av_log(avctx, AV_LOG_ERROR,

               "Rendering surface doesn't provide enough block structures to work with.\n");

        return -1;

    }



    render->picture_structure = s->picture_structure;

    render->flags             = s->first_field ? 0 : XVMC_SECOND_FIELD;

    render->p_future_surface  = NULL;

    render->p_past_surface    = NULL;



    switch(s->pict_type) {

        case  AV_PICTURE_TYPE_I:

            return 0; 

        case  AV_PICTURE_TYPE_B:

            next = (struct xvmc_pix_fmt*)s->next_picture.f.data[2];

            if (!next)

                return -1;

            if (next->xvmc_id != AV_XVMC_ID)

                return -1;

            render->p_future_surface = next->p_surface;

            

        case  AV_PICTURE_TYPE_P:

            last = (struct xvmc_pix_fmt*)s->last_picture.f.data[2];

            if (!last)

                last = render; 

            if (last->xvmc_id != AV_XVMC_ID)

                return -1;

            render->p_past_surface = last->p_surface;

            return 0;

    }



return -1;

}

    struct xvmc_pix_fmt *last, *next, *render = (struct xvmc_pix_fmt*)s->current_picture.f.data[2];             next = (struct xvmc_pix_fmt*)s->next_picture.f.data[2];             last = (struct xvmc_pix_fmt*)s->last_picture.f.data[2];
int FUNC_0(MpegEncContext *VAR_0, AVCodecContext *VAR_1)

{

    struct xvmc_pix_fmt *VAR_2, *VAR_3, *VAR_4 = (struct xvmc_pix_fmt*)VAR_0->current_picture.f.data[2];

    const int VAR_5 = 4 + (1 << VAR_0->chroma_format);



    assert(VAR_1);

    if (!VAR_4 || VAR_4->xvmc_id != AV_XVMC_ID ||

        !VAR_4->data_blocks || !VAR_4->mv_blocks ||

        (unsigned int)VAR_4->allocated_mv_blocks   > INT_MAX/(64*6) ||

        (unsigned int)VAR_4->allocated_data_blocks > INT_MAX/64     ||

        !VAR_4->p_surface) {

        av_log(VAR_1, AV_LOG_ERROR,

               "Render token doesn't look as expected.\n");

        return -1; 

    }



    if (VAR_4->filled_mv_blocks_num) {

        av_log(VAR_1, AV_LOG_ERROR,

               "Rendering surface contains %i unprocessed blocks.\n",

               VAR_4->filled_mv_blocks_num);

        return -1;

    }

    if (VAR_4->allocated_mv_blocks   < 1 ||

        VAR_4->allocated_data_blocks <  VAR_4->allocated_mv_blocks*VAR_5 ||

        VAR_4->start_mv_blocks_num   >= VAR_4->allocated_mv_blocks                ||

        VAR_4->next_free_data_block_num >

                        VAR_4->allocated_data_blocks -

                        VAR_5*(VAR_4->allocated_mv_blocks-VAR_4->start_mv_blocks_num)) {

        av_log(VAR_1, AV_LOG_ERROR,

               "Rendering surface doesn't provide enough block structures to work with.\n");

        return -1;

    }



    VAR_4->picture_structure = VAR_0->picture_structure;

    VAR_4->flags             = VAR_0->first_field ? 0 : XVMC_SECOND_FIELD;

    VAR_4->p_future_surface  = NULL;

    VAR_4->p_past_surface    = NULL;



    switch(VAR_0->pict_type) {

        case  AV_PICTURE_TYPE_I:

            return 0; 

        case  AV_PICTURE_TYPE_B:

            VAR_3 = (struct xvmc_pix_fmt*)VAR_0->next_picture.f.data[2];

            if (!VAR_3)

                return -1;

            if (VAR_3->xvmc_id != AV_XVMC_ID)

                return -1;

            VAR_4->p_future_surface = VAR_3->p_surface;

            

        case  AV_PICTURE_TYPE_P:

            VAR_2 = (struct xvmc_pix_fmt*)VAR_0->last_picture.f.data[2];

            if (!VAR_2)

                VAR_2 = VAR_4; 

            if (VAR_2->xvmc_id != AV_XVMC_ID)

                return -1;

            VAR_4->p_past_surface = VAR_2->p_surface;

            return 0;

    }



return -1;

}

int FUNC_0(MpegEncContext *VAR_0, AVCodecContext *VAR_1)
{ struct xvmc_pix_fmt *VAR_2, *VAR_3, *VAR_4 = (struct xvmc_pix_fmt*)VAR_0->current_picture.f.data[2]; const int VAR_5 = 4 + (1 << VAR_0->chroma_format); assert(VAR_1); if (!VAR_4 || VAR_4->xvmc_id != AV_XVMC_ID ||
!VAR_4->data_blocks || !VAR_4->mv_blocks ||
(unsigned int)VAR_4->allocated_mv_blocks   > INT_MAX/(64*6) ||
(unsigned int)VAR_4->allocated_data_blocks > INT_MAX/64     ||
!VAR_4->p_surface) { av_log(VAR_1, AV_LOG_ERROR,
"Render token doesn't look as expected.\n"); return -1; } if (VAR_4->filled_mv_blocks_num) { av_log(VAR_1, AV_LOG_ERROR,
"Rendering surface contains %i unprocessed blocks.\n",
VAR_4->filled_mv_blocks_num); return -1; } if (VAR_4->allocated_mv_blocks   < 1 ||
VAR_4->allocated_data_blocks <  VAR_4->allocated_mv_blocks*VAR_5 ||
VAR_4->start_mv_blocks_num   >= VAR_4->allocated_mv_blocks                ||
VAR_4->next_free_data_block_num >
VAR_4->allocated_data_blocks -
VAR_5*(VAR_4->allocated_mv_blocks-VAR_4->start_mv_blocks_num)) { av_log(VAR_1, AV_LOG_ERROR,
"Rendering surface doesn't provide enough block structures to work with.\n"); return -1; } VAR_4->picture_structure = VAR_0->picture_structure; VAR_4->flags             = VAR_0->first_field ? 0 : XVMC_SECOND_FIELD; VAR_4->p_future_surface  = NULL; VAR_4->p_past_surface    = NULL; switch(VAR_0->pict_type) { case  AV_PICTURE_TYPE_I:
return 0; case  AV_PICTURE_TYPE_B:
VAR_3 = (struct xvmc_pix_fmt*)VAR_0->next_picture.f.data[2]; if (!VAR_3)
return -1; if (VAR_3->xvmc_id != AV_XVMC_ID)
return -1; VAR_4->p_future_surface = VAR_3->p_surface; case  AV_PICTURE_TYPE_P:
VAR_2 = (struct xvmc_pix_fmt*)VAR_0->last_picture.f.data[2]; if (!VAR_2)
VAR_2 = VAR_4; if (VAR_2->xvmc_id != AV_XVMC_ID)
return -1; VAR_4->p_past_surface = VAR_2->p_surface; return 0; } return -1; }