frame: Simplify the video allocation
This commit is contained in:
parent
e1e3a12242
commit
f89ec87afa
@ -89,12 +89,8 @@ void av_frame_free(AVFrame **frame)
|
|||||||
|
|
||||||
static int get_video_buffer(AVFrame *frame, int align)
|
static int get_video_buffer(AVFrame *frame, int align)
|
||||||
{
|
{
|
||||||
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
|
|
||||||
int ret, i;
|
int ret, i;
|
||||||
|
|
||||||
if (!desc)
|
|
||||||
return AVERROR(EINVAL);
|
|
||||||
|
|
||||||
if ((ret = av_image_check_size(frame->width, frame->height, 0, NULL)) < 0)
|
if ((ret = av_image_check_size(frame->width, frame->height, 0, NULL)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
@ -111,24 +107,17 @@ static int get_video_buffer(AVFrame *frame, int align)
|
|||||||
frame->linesize[i] = FFALIGN(frame->linesize[i], align);
|
frame->linesize[i] = FFALIGN(frame->linesize[i], align);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < 4 && frame->linesize[i]; i++) {
|
if ((ret = av_image_fill_pointers(frame->data, frame->format, frame->height,
|
||||||
int h = frame->height;
|
NULL, frame->linesize)) < 0)
|
||||||
if (i == 1 || i == 2)
|
return ret;
|
||||||
h = AV_CEIL_RSHIFT(h, desc->log2_chroma_h);
|
|
||||||
|
|
||||||
frame->buf[i] = av_buffer_alloc(frame->linesize[i] * h);
|
frame->buf[0] = av_buffer_alloc(ret);
|
||||||
if (!frame->buf[i])
|
if (!frame->buf[0])
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
frame->data[i] = frame->buf[i]->data;
|
if (av_image_fill_pointers(frame->data, frame->format, frame->height,
|
||||||
}
|
frame->buf[0]->data, frame->linesize) < 0)
|
||||||
if (desc->flags & AV_PIX_FMT_FLAG_PAL || desc->flags & AV_PIX_FMT_FLAG_PSEUDOPAL) {
|
goto fail;
|
||||||
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;
|
frame->extended_data = frame->data;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user