static int input_get_buffer(AVCodecContext *codec, AVFrame *pic)

{

    AVFilterContext *ctx = codec->opaque;

    AVFilterBufferRef  *ref;

    int perms = AV_PERM_WRITE;

    int i, w, h, stride[4];

    unsigned edge;

    int pixel_size;



    av_assert0(codec->flags & CODEC_FLAG_EMU_EDGE);



    if (codec->codec->capabilities & CODEC_CAP_NEG_LINESIZES)

        perms |= AV_PERM_NEG_LINESIZES;



    if(pic->buffer_hints & FF_BUFFER_HINTS_VALID) {

        if(pic->buffer_hints & FF_BUFFER_HINTS_READABLE) perms |= AV_PERM_READ;

        if(pic->buffer_hints & FF_BUFFER_HINTS_PRESERVE) perms |= AV_PERM_PRESERVE;

        if(pic->buffer_hints & FF_BUFFER_HINTS_REUSABLE) perms |= AV_PERM_REUSE2;

    }

    if(pic->reference) perms |= AV_PERM_READ | AV_PERM_PRESERVE;



    w = codec->width;

    h = codec->height;



    if(av_image_check_size(w, h, 0, codec))

        return -1;



    avcodec_align_dimensions2(codec, &w, &h, stride);

    edge = codec->flags & CODEC_FLAG_EMU_EDGE ? 0 : avcodec_get_edge_width();

    w += edge << 1;

    h += edge << 1;



    if(!(ref = avfilter_get_video_buffer(ctx->outputs[0], perms, w, h)))

        return -1;



    pixel_size = av_pix_fmt_descriptors[ref->format].comp[0].step_minus1+1;

    ref->video->w = codec->width;

    ref->video->h = codec->height;

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

        unsigned hshift = (i == 1 || i == 2) ? av_pix_fmt_descriptors[ref->format].log2_chroma_w : 0;

        unsigned vshift = (i == 1 || i == 2) ? av_pix_fmt_descriptors[ref->format].log2_chroma_h : 0;



        if (ref->data[i]) {

            ref->data[i]    += ((edge * pixel_size) >> hshift) + ((edge * ref->linesize[i]) >> vshift);

        }

        pic->data[i]     = ref->data[i];

        pic->linesize[i] = ref->linesize[i];

    }

    pic->opaque = ref;

    pic->age    = INT_MAX;

    pic->type   = FF_BUFFER_TYPE_USER;

    pic->reordered_opaque = codec->reordered_opaque;

    if(codec->pkt) pic->pkt_pts = codec->pkt->pts;

    else           pic->pkt_pts = AV_NOPTS_VALUE;

    return 0;

}

static int input_get_buffer(AVCodecContext *codec, AVFrame *pic)

{

    AVFilterContext *ctx = codec->opaque;

    AVFilterBufferRef  *ref;

    int perms = AV_PERM_WRITE;

    int i, w, h, stride[4];

    unsigned edge;

    int pixel_size;



    av_assert0(codec->flags & CODEC_FLAG_EMU_EDGE);



    if (codec->codec->capabilities & CODEC_CAP_NEG_LINESIZES)

        perms |= AV_PERM_NEG_LINESIZES;



    if(pic->buffer_hints & FF_BUFFER_HINTS_VALID) {

        if(pic->buffer_hints & FF_BUFFER_HINTS_READABLE) perms |= AV_PERM_READ;

        if(pic->buffer_hints & FF_BUFFER_HINTS_PRESERVE) perms |= AV_PERM_PRESERVE;

        if(pic->buffer_hints & FF_BUFFER_HINTS_REUSABLE) perms |= AV_PERM_REUSE2;

    }

    if(pic->reference) perms |= AV_PERM_READ | AV_PERM_PRESERVE;



    w = codec->width;

    h = codec->height;



    if(av_image_check_size(w, h, 0, codec))

        return -1;



    avcodec_align_dimensions2(codec, &w, &h, stride);

    edge = codec->flags & CODEC_FLAG_EMU_EDGE ? 0 : avcodec_get_edge_width();

    w += edge << 1;

    h += edge << 1;



    if(!(ref = avfilter_get_video_buffer(ctx->outputs[0], perms, w, h)))

        return -1;



    pixel_size = av_pix_fmt_descriptors[ref->format].comp[0].step_minus1+1;

    ref->video->w = codec->width;

    ref->video->h = codec->height;

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

        unsigned hshift = (i == 1 || i == 2) ? av_pix_fmt_descriptors[ref->format].log2_chroma_w : 0;

        unsigned vshift = (i == 1 || i == 2) ? av_pix_fmt_descriptors[ref->format].log2_chroma_h : 0;



        if (ref->data[i]) {

            ref->data[i]    += ((edge * pixel_size) >> hshift) + ((edge * ref->linesize[i]) >> vshift);

        }

        pic->data[i]     = ref->data[i];

        pic->linesize[i] = ref->linesize[i];

    }

    pic->opaque = ref;

    pic->age    = INT_MAX;

    pic->type   = FF_BUFFER_TYPE_USER;

    pic->reordered_opaque = codec->reordered_opaque;

    if(codec->pkt) pic->pkt_pts = codec->pkt->pts;

    else           pic->pkt_pts = AV_NOPTS_VALUE;

    return 0;

}

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

{

    AVFilterContext *ctx = VAR_0->opaque;

    AVFilterBufferRef  *ref;

    int VAR_2 = AV_PERM_WRITE;

    int VAR_3, VAR_4, VAR_5, VAR_6[4];

    unsigned VAR_7;

    int VAR_8;



    av_assert0(VAR_0->flags & CODEC_FLAG_EMU_EDGE);



    if (VAR_0->VAR_0->capabilities & CODEC_CAP_NEG_LINESIZES)

        VAR_2 |= AV_PERM_NEG_LINESIZES;



    if(VAR_1->buffer_hints & FF_BUFFER_HINTS_VALID) {

        if(VAR_1->buffer_hints & FF_BUFFER_HINTS_READABLE) VAR_2 |= AV_PERM_READ;

        if(VAR_1->buffer_hints & FF_BUFFER_HINTS_PRESERVE) VAR_2 |= AV_PERM_PRESERVE;

        if(VAR_1->buffer_hints & FF_BUFFER_HINTS_REUSABLE) VAR_2 |= AV_PERM_REUSE2;

    }

    if(VAR_1->reference) VAR_2 |= AV_PERM_READ | AV_PERM_PRESERVE;



    VAR_4 = VAR_0->width;

    VAR_5 = VAR_0->height;



    if(av_image_check_size(VAR_4, VAR_5, 0, VAR_0))

        return -1;



    avcodec_align_dimensions2(VAR_0, &VAR_4, &VAR_5, VAR_6);

    VAR_7 = VAR_0->flags & CODEC_FLAG_EMU_EDGE ? 0 : avcodec_get_edge_width();

    VAR_4 += VAR_7 << 1;

    VAR_5 += VAR_7 << 1;



    if(!(ref = avfilter_get_video_buffer(ctx->outputs[0], VAR_2, VAR_4, VAR_5)))

        return -1;



    VAR_8 = av_pix_fmt_descriptors[ref->format].comp[0].step_minus1+1;

    ref->video->VAR_4 = VAR_0->width;

    ref->video->VAR_5 = VAR_0->height;

    for(VAR_3 = 0; VAR_3 < 4; VAR_3 ++) {

        unsigned VAR_9 = (VAR_3 == 1 || VAR_3 == 2) ? av_pix_fmt_descriptors[ref->format].log2_chroma_w : 0;

        unsigned VAR_10 = (VAR_3 == 1 || VAR_3 == 2) ? av_pix_fmt_descriptors[ref->format].log2_chroma_h : 0;



        if (ref->data[VAR_3]) {

            ref->data[VAR_3]    += ((VAR_7 * VAR_8) >> VAR_9) + ((VAR_7 * ref->linesize[VAR_3]) >> VAR_10);

        }

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

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

    }

    VAR_1->opaque = ref;

    VAR_1->age    = INT_MAX;

    VAR_1->type   = FF_BUFFER_TYPE_USER;

    VAR_1->reordered_opaque = VAR_0->reordered_opaque;

    if(VAR_0->pkt) VAR_1->pkt_pts = VAR_0->pkt->pts;

    else           VAR_1->pkt_pts = AV_NOPTS_VALUE;

    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, AVFrame *VAR_1)
{ AVFilterContext *ctx = VAR_0->opaque; AVFilterBufferRef  *ref; int VAR_2 = AV_PERM_WRITE; int VAR_3, VAR_4, VAR_5, VAR_6[4]; unsigned VAR_7; int VAR_8; av_assert0(VAR_0->flags & CODEC_FLAG_EMU_EDGE); if (VAR_0->VAR_0->capabilities & CODEC_CAP_NEG_LINESIZES)
VAR_2 |= AV_PERM_NEG_LINESIZES; if(VAR_1->buffer_hints & FF_BUFFER_HINTS_VALID) { if(VAR_1->buffer_hints & FF_BUFFER_HINTS_READABLE) VAR_2 |= AV_PERM_READ; if(VAR_1->buffer_hints & FF_BUFFER_HINTS_PRESERVE) VAR_2 |= AV_PERM_PRESERVE; if(VAR_1->buffer_hints & FF_BUFFER_HINTS_REUSABLE) VAR_2 |= AV_PERM_REUSE2; } if(VAR_1->reference) VAR_2 |= AV_PERM_READ | AV_PERM_PRESERVE; VAR_4 = VAR_0->width; VAR_5 = VAR_0->height; if(av_image_check_size(VAR_4, VAR_5, 0, VAR_0))
return -1; avcodec_align_dimensions2(VAR_0, &VAR_4, &VAR_5, VAR_6); VAR_7 = VAR_0->flags & CODEC_FLAG_EMU_EDGE ? 0 : avcodec_get_edge_width(); VAR_4 += VAR_7 << 1; VAR_5 += VAR_7 << 1; if(!(ref = avfilter_get_video_buffer(ctx->outputs[0], VAR_2, VAR_4, VAR_5)))
return -1; VAR_8 = av_pix_fmt_descriptors[ref->format].comp[0].step_minus1+1; ref->video->VAR_4 = VAR_0->width; ref->video->VAR_5 = VAR_0->height; for(VAR_3 = 0; VAR_3 < 4; VAR_3 ++) { unsigned VAR_9 = (VAR_3 == 1 || VAR_3 == 2) ? av_pix_fmt_descriptors[ref->format].log2_chroma_w : 0; unsigned VAR_10 = (VAR_3 == 1 || VAR_3 == 2) ? av_pix_fmt_descriptors[ref->format].log2_chroma_h : 0; if (ref->data[VAR_3]) { ref->data[VAR_3]    += ((VAR_7 * VAR_8) >> VAR_9) + ((VAR_7 * ref->linesize[VAR_3]) >> VAR_10); } VAR_1->data[VAR_3]     = ref->data[VAR_3]; VAR_1->linesize[VAR_3] = ref->linesize[VAR_3]; } VAR_1->opaque = ref; VAR_1->age    = INT_MAX; VAR_1->type   = FF_BUFFER_TYPE_USER; VAR_1->reordered_opaque = VAR_0->reordered_opaque; if(VAR_0->pkt) VAR_1->pkt_pts = VAR_0->pkt->pts; else           VAR_1->pkt_pts = AV_NOPTS_VALUE; return 0; }