static int get_video_buffer(AVFrame *frame, int align)

{

    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);

    int ret, i;



    if (!desc)

        return AVERROR(EINVAL);



    if ((ret = av_image_check_size(frame->width, frame->height, 0, NULL)) < 0)

        return ret;



    if (!frame->linesize[0]) {

        ret = av_image_fill_linesizes(frame->linesize, frame->format,

                                      frame->width);

        if (ret < 0)

            return ret;



        for (i = 0; i < 4 && frame->linesize[i]; i++)

            frame->linesize[i] = FFALIGN(frame->linesize[i], align);

    }



    for (i = 0; i < 4 && frame->linesize[i]; i++) {

        int h = FFALIGN(frame->height, 32);

        if (i == 1 || i == 2)

            h = -((-h) >> desc->log2_chroma_h);



        frame->buf[i] = av_buffer_alloc(frame->linesize[i] * h);

        if (!frame->buf[i])

            goto fail;



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

    }

    if (desc->flags & PIX_FMT_PAL || desc->flags & PIX_FMT_PSEUDOPAL) {

        av_buffer_unref(&frame->buf[1]);

        frame->buf[1] = av_buffer_alloc(1024);

        if (!frame->buf[1])

            goto fail;

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

    }



    frame->extended_data = frame->data;



    return 0;

fail:

    av_frame_unref(frame);

    return AVERROR(ENOMEM);

}

static int get_video_buffer(AVFrame *frame, int align)

{

    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);

    int ret, i;



    if (!desc)

        return AVERROR(EINVAL);



    if ((ret = av_image_check_size(frame->width, frame->height, 0, NULL)) < 0)

        return ret;



    if (!frame->linesize[0]) {

        ret = av_image_fill_linesizes(frame->linesize, frame->format,

                                      frame->width);

        if (ret < 0)

            return ret;



        for (i = 0; i < 4 && frame->linesize[i]; i++)

            frame->linesize[i] = FFALIGN(frame->linesize[i], align);

    }



    for (i = 0; i < 4 && frame->linesize[i]; i++) {

        int h = FFALIGN(frame->height, 32);

        if (i == 1 || i == 2)

            h = -((-h) >> desc->log2_chroma_h);



        frame->buf[i] = av_buffer_alloc(frame->linesize[i] * h);

        if (!frame->buf[i])

            goto fail;



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

    }

    if (desc->flags & PIX_FMT_PAL || desc->flags & PIX_FMT_PSEUDOPAL) {

        av_buffer_unref(&frame->buf[1]);

        frame->buf[1] = av_buffer_alloc(1024);

        if (!frame->buf[1])

            goto fail;

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

    }



    frame->extended_data = frame->data;



    return 0;

fail:

    av_frame_unref(frame);

    return AVERROR(ENOMEM);

}

static int FUNC_0(AVFrame *VAR_0, int VAR_1)

{

    const AVPixFmtDescriptor *VAR_2 = av_pix_fmt_desc_get(VAR_0->format);

    int VAR_3, VAR_4;



    if (!VAR_2)

        return AVERROR(EINVAL);



    if ((VAR_3 = av_image_check_size(VAR_0->width, VAR_0->height, 0, NULL)) < 0)

        return VAR_3;



    if (!VAR_0->linesize[0]) {

        VAR_3 = av_image_fill_linesizes(VAR_0->linesize, VAR_0->format,

                                      VAR_0->width);

        if (VAR_3 < 0)

            return VAR_3;



        for (VAR_4 = 0; VAR_4 < 4 && VAR_0->linesize[VAR_4]; VAR_4++)

            VAR_0->linesize[VAR_4] = FFALIGN(VAR_0->linesize[VAR_4], VAR_1);

    }



    for (VAR_4 = 0; VAR_4 < 4 && VAR_0->linesize[VAR_4]; VAR_4++) {

        int h = FFALIGN(VAR_0->height, 32);

        if (VAR_4 == 1 || VAR_4 == 2)

            h = -((-h) >> VAR_2->log2_chroma_h);



        VAR_0->buf[VAR_4] = av_buffer_alloc(VAR_0->linesize[VAR_4] * h);

        if (!VAR_0->buf[VAR_4])

            goto fail;



        VAR_0->data[VAR_4] = VAR_0->buf[VAR_4]->data;

    }

    if (VAR_2->flags & PIX_FMT_PAL || VAR_2->flags & PIX_FMT_PSEUDOPAL) {

        av_buffer_unref(&VAR_0->buf[1]);

        VAR_0->buf[1] = av_buffer_alloc(1024);

        if (!VAR_0->buf[1])

            goto fail;

        VAR_0->data[1] = VAR_0->buf[1]->data;

    }



    VAR_0->extended_data = VAR_0->data;



    return 0;

fail:

    av_frame_unref(VAR_0);

    return AVERROR(ENOMEM);

}

static int FUNC_0(AVFrame *VAR_0, int VAR_1)
{ const AVPixFmtDescriptor *VAR_2 = av_pix_fmt_desc_get(VAR_0->format); int VAR_3, VAR_4; if (!VAR_2)
return AVERROR(EINVAL); if ((VAR_3 = av_image_check_size(VAR_0->width, VAR_0->height, 0, NULL)) < 0)
return VAR_3; if (!VAR_0->linesize[0]) { VAR_3 = av_image_fill_linesizes(VAR_0->linesize, VAR_0->format,
VAR_0->width); if (VAR_3 < 0)
return VAR_3; for (VAR_4 = 0; VAR_4 < 4 && VAR_0->linesize[VAR_4]; VAR_4++) VAR_0->linesize[VAR_4] = FFALIGN(VAR_0->linesize[VAR_4], VAR_1); } for (VAR_4 = 0; VAR_4 < 4 && VAR_0->linesize[VAR_4]; VAR_4++) { int h = FFALIGN(VAR_0->height, 32); if (VAR_4 == 1 || VAR_4 == 2)
h = -((-h) >> VAR_2->log2_chroma_h); VAR_0->buf[VAR_4] = av_buffer_alloc(VAR_0->linesize[VAR_4] * h); if (!VAR_0->buf[VAR_4])
goto fail; VAR_0->data[VAR_4] = VAR_0->buf[VAR_4]->data; } if (VAR_2->flags & PIX_FMT_PAL || VAR_2->flags & PIX_FMT_PSEUDOPAL) { av_buffer_unref(&VAR_0->buf[1]); VAR_0->buf[1] = av_buffer_alloc(1024); if (!VAR_0->buf[1])
goto fail; VAR_0->data[1] = VAR_0->buf[1]->data; } VAR_0->extended_data = VAR_0->data; return 0; fail:
av_frame_unref(VAR_0); return AVERROR(ENOMEM); }