static int decode_frame(AVCodecContext *avctx,

                             void *data, int *data_size,

                             AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    int buf_size = avpkt->size;

    H264Context *h = avctx->priv_data;

    MpegEncContext *s = &h->s;

    AVFrame *pict = data;

    int buf_index;



    s->flags= avctx->flags;

    s->flags2= avctx->flags2;



   /* end of stream, output what is still in the buffers */

 out:

    if (buf_size == 0) {

        Picture *out;

        int i, out_idx;



        s->current_picture_ptr = NULL;



//FIXME factorize this with the output code below

        out = h->delayed_pic[0];

        out_idx = 0;

        for(i=1; h->delayed_pic[i] && !h->delayed_pic[i]->key_frame && !h->delayed_pic[i]->mmco_reset; i++)

            if(h->delayed_pic[i]->poc < out->poc){

                out = h->delayed_pic[i];

                out_idx = i;

            }



        for(i=out_idx; h->delayed_pic[i]; i++)

            h->delayed_pic[i] = h->delayed_pic[i+1];



        if(out){

            *data_size = sizeof(AVFrame);

            *pict= *(AVFrame*)out;

        }



        return 0;

    }



    buf_index=decode_nal_units(h, buf, buf_size);

    if(buf_index < 0)

        return -1;



    if (!s->current_picture_ptr && h->nal_unit_type == NAL_END_SEQUENCE) {

        buf_size = 0;

        goto out;

    }



    if(!(s->flags2 & CODEC_FLAG2_CHUNKS) && !s->current_picture_ptr){

        if (avctx->skip_frame >= AVDISCARD_NONREF)

            return 0;

        av_log(avctx, AV_LOG_ERROR, "no frame!\n");

        return -1;

    }



    if(!(s->flags2 & CODEC_FLAG2_CHUNKS) || (s->mb_y >= s->mb_height && s->mb_height)){



        if(s->flags2 & CODEC_FLAG2_CHUNKS) decode_postinit(h);



        field_end(h, 0);



        if (!h->next_output_pic) {

            /* Wait for second field. */

            *data_size = 0;



        } else {

            *data_size = sizeof(AVFrame);

            *pict = *(AVFrame*)h->next_output_pic;

        }

    }



    assert(pict->data[0] || !*data_size);

    ff_print_debug_info(s, pict);

//printf("out %d\n", (int)pict->data[0]);



    return get_consumed_bytes(s, buf_index, buf_size);

}

static int decode_frame(AVCodecContext *avctx,

                             void *data, int *data_size,

                             AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    int buf_size = avpkt->size;

    H264Context *h = avctx->priv_data;

    MpegEncContext *s = &h->s;

    AVFrame *pict = data;

    int buf_index;



    s->flags= avctx->flags;

    s->flags2= avctx->flags2;



   

 out:

    if (buf_size == 0) {

        Picture *out;

        int i, out_idx;



        s->current_picture_ptr = NULL;





        out = h->delayed_pic[0];

        out_idx = 0;

        for(i=1; h->delayed_pic[i] && !h->delayed_pic[i]->key_frame && !h->delayed_pic[i]->mmco_reset; i++)

            if(h->delayed_pic[i]->poc < out->poc){

                out = h->delayed_pic[i];

                out_idx = i;

            }



        for(i=out_idx; h->delayed_pic[i]; i++)

            h->delayed_pic[i] = h->delayed_pic[i+1];



        if(out){

            *data_size = sizeof(AVFrame);

            *pict= *(AVFrame*)out;

        }



        return 0;

    }



    buf_index=decode_nal_units(h, buf, buf_size);

    if(buf_index < 0)

        return -1;



    if (!s->current_picture_ptr && h->nal_unit_type == NAL_END_SEQUENCE) {

        buf_size = 0;

        goto out;

    }



    if(!(s->flags2 & CODEC_FLAG2_CHUNKS) && !s->current_picture_ptr){

        if (avctx->skip_frame >= AVDISCARD_NONREF)

            return 0;

        av_log(avctx, AV_LOG_ERROR, "no frame!\n");

        return -1;

    }



    if(!(s->flags2 & CODEC_FLAG2_CHUNKS) || (s->mb_y >= s->mb_height && s->mb_height)){



        if(s->flags2 & CODEC_FLAG2_CHUNKS) decode_postinit(h);



        field_end(h, 0);



        if (!h->next_output_pic) {

            

            *data_size = 0;



        } else {

            *data_size = sizeof(AVFrame);

            *pict = *(AVFrame*)h->next_output_pic;

        }

    }



    assert(pict->data[0] || !*data_size);

    ff_print_debug_info(s, pict);





    return get_consumed_bytes(s, buf_index, buf_size);

}

        if(s->flags2 & CODEC_FLAG2_CHUNKS) decode_postinit(h);
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;

    H264Context *h = VAR_0->priv_data;

    MpegEncContext *s = &h->s;

    AVFrame *pict = VAR_1;

    int VAR_6;



    s->flags= VAR_0->flags;

    s->flags2= VAR_0->flags2;



   

 out:

    if (VAR_5 == 0) {

        Picture *out;

        int VAR_7, VAR_8;



        s->current_picture_ptr = NULL;





        out = h->delayed_pic[0];

        VAR_8 = 0;

        for(VAR_7=1; h->delayed_pic[VAR_7] && !h->delayed_pic[VAR_7]->key_frame && !h->delayed_pic[VAR_7]->mmco_reset; VAR_7++)

            if(h->delayed_pic[VAR_7]->poc < out->poc){

                out = h->delayed_pic[VAR_7];

                VAR_8 = VAR_7;

            }



        for(VAR_7=VAR_8; h->delayed_pic[VAR_7]; VAR_7++)

            h->delayed_pic[VAR_7] = h->delayed_pic[VAR_7+1];



        if(out){

            *VAR_2 = sizeof(AVFrame);

            *pict= *(AVFrame*)out;

        }



        return 0;

    }



    VAR_6=decode_nal_units(h, VAR_4, VAR_5);

    if(VAR_6 < 0)

        return -1;



    if (!s->current_picture_ptr && h->nal_unit_type == NAL_END_SEQUENCE) {

        VAR_5 = 0;

        goto out;

    }



    if(!(s->flags2 & CODEC_FLAG2_CHUNKS) && !s->current_picture_ptr){

        if (VAR_0->skip_frame >= AVDISCARD_NONREF)

            return 0;

        av_log(VAR_0, AV_LOG_ERROR, "no frame!\n");

        return -1;

    }



    if(!(s->flags2 & CODEC_FLAG2_CHUNKS) || (s->mb_y >= s->mb_height && s->mb_height)){



        if(s->flags2 & CODEC_FLAG2_CHUNKS) decode_postinit(h);



        field_end(h, 0);



        if (!h->next_output_pic) {

            

            *VAR_2 = 0;



        } else {

            *VAR_2 = sizeof(AVFrame);

            *pict = *(AVFrame*)h->next_output_pic;

        }

    }



    assert(pict->VAR_1[0] || !*VAR_2);

    ff_print_debug_info(s, pict);





    return get_consumed_bytes(s, VAR_6, 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; H264Context *h = VAR_0->priv_data; MpegEncContext *s = &h->s; AVFrame *pict = VAR_1; int VAR_6; s->flags= VAR_0->flags; s->flags2= VAR_0->flags2; out:
if (VAR_5 == 0) { Picture *out; int VAR_7, VAR_8; s->current_picture_ptr = NULL; out = h->delayed_pic[0]; VAR_8 = 0; for(VAR_7=1; h->delayed_pic[VAR_7] && !h->delayed_pic[VAR_7]->key_frame && !h->delayed_pic[VAR_7]->mmco_reset; VAR_7++) if(h->delayed_pic[VAR_7]->poc < out->poc){ out = h->delayed_pic[VAR_7]; VAR_8 = VAR_7; } for(VAR_7=VAR_8; h->delayed_pic[VAR_7]; VAR_7++) h->delayed_pic[VAR_7] = h->delayed_pic[VAR_7+1]; if(out){ *VAR_2 = sizeof(AVFrame); *pict= *(AVFrame*)out; } return 0; } VAR_6=decode_nal_units(h, VAR_4, VAR_5); if(VAR_6 < 0)
return -1; if (!s->current_picture_ptr && h->nal_unit_type == NAL_END_SEQUENCE) { VAR_5 = 0; goto out; } if(!(s->flags2 & CODEC_FLAG2_CHUNKS) && !s->current_picture_ptr){ if (VAR_0->skip_frame >= AVDISCARD_NONREF)
return 0; av_log(VAR_0, AV_LOG_ERROR, "no frame!\n"); return -1; } if(!(s->flags2 & CODEC_FLAG2_CHUNKS) || (s->mb_y >= s->mb_height && s->mb_height)){ if(s->flags2 & CODEC_FLAG2_CHUNKS) decode_postinit(h); field_end(h, 0); if (!h->next_output_pic) { *VAR_2 = 0; } else { *VAR_2 = sizeof(AVFrame); *pict = *(AVFrame*)h->next_output_pic; } } assert(pict->VAR_1[0] || !*VAR_2); ff_print_debug_info(s, pict); return get_consumed_bytes(s, VAR_6, VAR_5); }