static int codec_get_buffer(AVCodecContext *s, AVFrame *frame)

{

    InputStream *ist = s->opaque;

    FrameBuffer *buf;

    int ret, i;



    if(av_image_check_size(s->width, s->height, 0, s))

        return -1;



    if (!ist->buffer_pool && (ret = alloc_buffer(s, ist, &ist->buffer_pool)) < 0)

        return ret;



    buf              = ist->buffer_pool;

    ist->buffer_pool = buf->next;

    buf->next        = NULL;

    if (buf->w != s->width || buf->h != s->height || buf->pix_fmt != s->pix_fmt) {

        av_freep(&buf->base[0]);

        av_free(buf);

        ist->dr1 = 0;

        if ((ret = alloc_buffer(s, ist, &buf)) < 0)

            return ret;

    }

    buf->refcount++;



    frame->opaque        = buf;

    frame->type          = FF_BUFFER_TYPE_USER;

    frame->extended_data = frame->data;

    frame->pkt_pts       = s->pkt ? s->pkt->pts : AV_NOPTS_VALUE;



    for (i = 0; i < FF_ARRAY_ELEMS(buf->data); i++) {

        frame->base[i]     = buf->base[i];  // XXX h264.c uses base though it shouldn't

        frame->data[i]     = buf->data[i];

        frame->linesize[i] = buf->linesize[i];

    }



    return 0;

}

static int codec_get_buffer(AVCodecContext *s, AVFrame *frame)

{

    InputStream *ist = s->opaque;

    FrameBuffer *buf;

    int ret, i;



    if(av_image_check_size(s->width, s->height, 0, s))

        return -1;



    if (!ist->buffer_pool && (ret = alloc_buffer(s, ist, &ist->buffer_pool)) < 0)

        return ret;



    buf              = ist->buffer_pool;

    ist->buffer_pool = buf->next;

    buf->next        = NULL;

    if (buf->w != s->width || buf->h != s->height || buf->pix_fmt != s->pix_fmt) {

        av_freep(&buf->base[0]);

        av_free(buf);

        ist->dr1 = 0;

        if ((ret = alloc_buffer(s, ist, &buf)) < 0)

            return ret;

    }

    buf->refcount++;



    frame->opaque        = buf;

    frame->type          = FF_BUFFER_TYPE_USER;

    frame->extended_data = frame->data;

    frame->pkt_pts       = s->pkt ? s->pkt->pts : AV_NOPTS_VALUE;



    for (i = 0; i < FF_ARRAY_ELEMS(buf->data); i++) {

        frame->base[i]     = buf->base[i];  

        frame->data[i]     = buf->data[i];

        frame->linesize[i] = buf->linesize[i];

    }



    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, AVFrame *VAR_1)

{

    InputStream *ist = VAR_0->opaque;

    FrameBuffer *buf;

    int VAR_2, VAR_3;



    if(av_image_check_size(VAR_0->width, VAR_0->height, 0, VAR_0))

        return -1;



    if (!ist->buffer_pool && (VAR_2 = alloc_buffer(VAR_0, ist, &ist->buffer_pool)) < 0)

        return VAR_2;



    buf              = ist->buffer_pool;

    ist->buffer_pool = buf->next;

    buf->next        = NULL;

    if (buf->w != VAR_0->width || buf->h != VAR_0->height || buf->pix_fmt != VAR_0->pix_fmt) {

        av_freep(&buf->base[0]);

        av_free(buf);

        ist->dr1 = 0;

        if ((VAR_2 = alloc_buffer(VAR_0, ist, &buf)) < 0)

            return VAR_2;

    }

    buf->refcount++;



    VAR_1->opaque        = buf;

    VAR_1->type          = FF_BUFFER_TYPE_USER;

    VAR_1->extended_data = VAR_1->data;

    VAR_1->pkt_pts       = VAR_0->pkt ? VAR_0->pkt->pts : AV_NOPTS_VALUE;



    for (VAR_3 = 0; VAR_3 < FF_ARRAY_ELEMS(buf->data); VAR_3++) {

        VAR_1->base[VAR_3]     = buf->base[VAR_3];  

        VAR_1->data[VAR_3]     = buf->data[VAR_3];

        VAR_1->linesize[VAR_3] = buf->linesize[VAR_3];

    }



    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, AVFrame *VAR_1)
{ InputStream *ist = VAR_0->opaque; FrameBuffer *buf; int VAR_2, VAR_3; if(av_image_check_size(VAR_0->width, VAR_0->height, 0, VAR_0))
return -1; if (!ist->buffer_pool && (VAR_2 = alloc_buffer(VAR_0, ist, &ist->buffer_pool)) < 0)
return VAR_2; buf              = ist->buffer_pool; ist->buffer_pool = buf->next; buf->next        = NULL; if (buf->w != VAR_0->width || buf->h != VAR_0->height || buf->pix_fmt != VAR_0->pix_fmt) { av_freep(&buf->base[0]); av_free(buf); ist->dr1 = 0; if ((VAR_2 = alloc_buffer(VAR_0, ist, &buf)) < 0)
return VAR_2; } buf->refcount++; VAR_1->opaque        = buf; VAR_1->type          = FF_BUFFER_TYPE_USER; VAR_1->extended_data = VAR_1->data; VAR_1->pkt_pts       = VAR_0->pkt ? VAR_0->pkt->pts : AV_NOPTS_VALUE; for (VAR_3 = 0; VAR_3 < FF_ARRAY_ELEMS(buf->data); VAR_3++) { VAR_1->base[VAR_3]     = buf->base[VAR_3]; VAR_1->data[VAR_3]     = buf->data[VAR_3]; VAR_1->linesize[VAR_3] = buf->linesize[VAR_3]; } return 0; }