2 * Copyright 2007 Bobby Bingham
3 * Copyright Stefano Sabatini <stefasab gmail com>
4 * Copyright Vitor Sessak <vitor1001 gmail com>
6 * This file is part of FFmpeg.
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #include "libavutil/avassert.h"
27 #include "libavutil/buffer.h"
28 #include "libavutil/hwcontext.h"
29 #include "libavutil/imgutils.h"
30 #include "libavutil/mem.h"
36 #define BUFFER_ALIGN 32
39 AVFrame *ff_null_get_video_buffer(AVFilterLink *link, int w, int h)
41 return ff_get_video_buffer(link->dst->outputs[0], w, h);
44 AVFrame *ff_default_get_video_buffer(AVFilterLink *link, int w, int h)
46 AVFrame *frame = NULL;
50 enum AVPixelFormat pool_format = AV_PIX_FMT_NONE;
52 if (link->hw_frames_ctx &&
53 ((AVHWFramesContext*)link->hw_frames_ctx->data)->format == link->format) {
55 AVFrame *frame = av_frame_alloc();
60 ret = av_hwframe_get_buffer(link->hw_frames_ctx, frame, 0);
62 av_frame_free(&frame);
67 if (!link->frame_pool) {
68 link->frame_pool = ff_frame_pool_video_init(av_buffer_allocz, w, h,
69 link->format, BUFFER_ALIGN);
70 if (!link->frame_pool)
73 if (ff_frame_pool_get_video_config(link->frame_pool,
74 &pool_width, &pool_height,
75 &pool_format, &pool_align) < 0) {
79 if (pool_width != w || pool_height != h ||
80 pool_format != link->format || pool_align != BUFFER_ALIGN) {
82 ff_frame_pool_uninit((FFFramePool **)&link->frame_pool);
83 link->frame_pool = ff_frame_pool_video_init(av_buffer_allocz, w, h,
84 link->format, BUFFER_ALIGN);
85 if (!link->frame_pool)
90 frame = ff_frame_pool_get(link->frame_pool);
94 frame->sample_aspect_ratio = link->sample_aspect_ratio;
99 AVFrame *ff_get_video_buffer(AVFilterLink *link, int w, int h)
103 FF_TPRINTF_START(NULL, get_video_buffer); ff_tlog_link(NULL, link, 0);
105 if (link->dstpad->get_video_buffer)
106 ret = link->dstpad->get_video_buffer(link, w, h);
109 ret = ff_default_get_video_buffer(link, w, h);