static int X264_frame(AVCodecContext *ctx, uint8_t *buf,

                      int bufsize, void *data)

{

    X264Context *x4 = ctx->priv_data;

    AVFrame *frame = data;

    x264_nal_t *nal;

    int nnal, i;

    x264_picture_t pic_out;



    x4->pic.img.i_csp   = X264_CSP_I420;

    x4->pic.img.i_plane = 3;



    if (frame) {

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

            x4->pic.img.plane[i]    = frame->data[i];

            x4->pic.img.i_stride[i] = frame->linesize[i];

        }



        x4->pic.i_pts  = frame->pts;

        x4->pic.i_type = X264_TYPE_AUTO;

    }



    if (x264_encoder_encode(x4->enc, &nal, &nnal, frame? &x4->pic: NULL, &pic_out) < 0)

        return -1;



    bufsize = encode_nals(ctx, buf, bufsize, nal, nnal, 0);

    if (bufsize < 0)

        return -1;



    /* FIXME: dts */

    x4->out_pic.pts = pic_out.i_pts;



    switch (pic_out.i_type) {

    case X264_TYPE_IDR:

    case X264_TYPE_I:

        x4->out_pic.pict_type = FF_I_TYPE;

        break;

    case X264_TYPE_P:

        x4->out_pic.pict_type = FF_P_TYPE;

        break;

    case X264_TYPE_B:

    case X264_TYPE_BREF:

        x4->out_pic.pict_type = FF_B_TYPE;

        break;

    }



    x4->out_pic.key_frame = pic_out.i_type == X264_TYPE_IDR;

    x4->out_pic.quality   = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA;



    return bufsize;

}

static int X264_frame(AVCodecContext *ctx, uint8_t *buf,

                      int bufsize, void *data)

{

    X264Context *x4 = ctx->priv_data;

    AVFrame *frame = data;

    x264_nal_t *nal;

    int nnal, i;

    x264_picture_t pic_out;



    x4->pic.img.i_csp   = X264_CSP_I420;

    x4->pic.img.i_plane = 3;



    if (frame) {

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

            x4->pic.img.plane[i]    = frame->data[i];

            x4->pic.img.i_stride[i] = frame->linesize[i];

        }



        x4->pic.i_pts  = frame->pts;

        x4->pic.i_type = X264_TYPE_AUTO;

    }



    if (x264_encoder_encode(x4->enc, &nal, &nnal, frame? &x4->pic: NULL, &pic_out) < 0)

        return -1;



    bufsize = encode_nals(ctx, buf, bufsize, nal, nnal, 0);

    if (bufsize < 0)

        return -1;



    

    x4->out_pic.pts = pic_out.i_pts;



    switch (pic_out.i_type) {

    case X264_TYPE_IDR:

    case X264_TYPE_I:

        x4->out_pic.pict_type = FF_I_TYPE;

        break;

    case X264_TYPE_P:

        x4->out_pic.pict_type = FF_P_TYPE;

        break;

    case X264_TYPE_B:

    case X264_TYPE_BREF:

        x4->out_pic.pict_type = FF_B_TYPE;

        break;

    }



    x4->out_pic.key_frame = pic_out.i_type == X264_TYPE_IDR;

    x4->out_pic.quality   = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA;



    return bufsize;

}

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

                      int VAR_2, void *VAR_3)

{

    X264Context *x4 = VAR_0->priv_data;

    AVFrame *frame = VAR_3;

    x264_nal_t *nal;

    int VAR_4, VAR_5;

    x264_picture_t pic_out;



    x4->pic.img.i_csp   = X264_CSP_I420;

    x4->pic.img.i_plane = 3;



    if (frame) {

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

            x4->pic.img.plane[VAR_5]    = frame->VAR_3[VAR_5];

            x4->pic.img.i_stride[VAR_5] = frame->linesize[VAR_5];

        }



        x4->pic.i_pts  = frame->pts;

        x4->pic.i_type = X264_TYPE_AUTO;

    }



    if (x264_encoder_encode(x4->enc, &nal, &VAR_4, frame? &x4->pic: NULL, &pic_out) < 0)

        return -1;



    VAR_2 = encode_nals(VAR_0, VAR_1, VAR_2, nal, VAR_4, 0);

    if (VAR_2 < 0)

        return -1;



    

    x4->out_pic.pts = pic_out.i_pts;



    switch (pic_out.i_type) {

    case X264_TYPE_IDR:

    case X264_TYPE_I:

        x4->out_pic.pict_type = FF_I_TYPE;

        break;

    case X264_TYPE_P:

        x4->out_pic.pict_type = FF_P_TYPE;

        break;

    case X264_TYPE_B:

    case X264_TYPE_BREF:

        x4->out_pic.pict_type = FF_B_TYPE;

        break;

    }



    x4->out_pic.key_frame = pic_out.i_type == X264_TYPE_IDR;

    x4->out_pic.quality   = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA;



    return VAR_2;

}

static int FUNC_0(AVCodecContext *VAR_0, uint8_t *VAR_1,
int VAR_2, void *VAR_3)
{ X264Context *x4 = VAR_0->priv_data; AVFrame *frame = VAR_3; x264_nal_t *nal; int VAR_4, VAR_5; x264_picture_t pic_out; x4->pic.img.i_csp   = X264_CSP_I420; x4->pic.img.i_plane = 3; if (frame) { for (VAR_5 = 0; VAR_5 < 3; VAR_5++) { x4->pic.img.plane[VAR_5]    = frame->VAR_3[VAR_5]; x4->pic.img.i_stride[VAR_5] = frame->linesize[VAR_5]; } x4->pic.i_pts  = frame->pts; x4->pic.i_type = X264_TYPE_AUTO; } if (x264_encoder_encode(x4->enc, &nal, &VAR_4, frame? &x4->pic: NULL, &pic_out) < 0)
return -1; VAR_2 = encode_nals(VAR_0, VAR_1, VAR_2, nal, VAR_4, 0); if (VAR_2 < 0)
return -1; x4->out_pic.pts = pic_out.i_pts; switch (pic_out.i_type) { case X264_TYPE_IDR:
case X264_TYPE_I:
x4->out_pic.pict_type = FF_I_TYPE; break; case X264_TYPE_P:
x4->out_pic.pict_type = FF_P_TYPE; break; case X264_TYPE_B:
case X264_TYPE_BREF:
x4->out_pic.pict_type = FF_B_TYPE; break; } x4->out_pic.key_frame = pic_out.i_type == X264_TYPE_IDR; x4->out_pic.quality   = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA; return VAR_2; }