FFmpeg
Loading...
Searching...
No Matches
video.c
Go to the documentation of this file.
1/*
2 * Copyright 2007 Bobby Bingham
3 * Copyright Stefano Sabatini <stefasab gmail com>
4 * Copyright Vitor Sessak <vitor1001 gmail com>
5 *
6 * This file is part of FFmpeg.
7 *
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.
12 *
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.
17 *
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
21 */
22
23#include <string.h>
24#include <stdio.h>
25
26#include "libavutil/buffer.h"
27#include "libavutil/cpu.h"
28#include "libavutil/framepool.h"
29#include "libavutil/hwcontext.h"
30#include "libavutil/pixfmt.h"
31
32#include "avfilter.h"
33#include "avfilter_internal.h"
34#include "filters.h"
35#include "video.h"
36
38 {
39 .name = "default",
40 .type = AVMEDIA_TYPE_VIDEO,
41 }
42};
43
45{
46 return ff_get_video_buffer(link->dst->outputs[0], w, h);
47}
48
49static void set_link_props(AVFrame *frame, const AVFilterLink *link)
50{
51 frame->sample_aspect_ratio = link->sample_aspect_ratio;
52 frame->colorspace = link->colorspace;
53 frame->color_range = link->color_range;
54 frame->alpha_mode = link->alpha_mode;
55 frame->chroma_location = link->chroma_location;
56}
57
59{
60 FilterLinkInternal *const li = ff_link_internal(link);
62
63 if (li->l.hw_frames_ctx &&
64 ((AVHWFramesContext*)li->l.hw_frames_ctx->data)->format == link->format) {
65 int ret;
67
68 if (!frame)
69 return NULL;
70
72 if (ret < 0)
74
75 return frame;
76 }
77
78 if (ff_frame_pool_video_reinit(&li->frame_pool, w, h, link->format, align) < 0)
79 return NULL;
80
82 if (!frame)
83 return NULL;
84
85 set_link_props(frame, link);
86
87 return frame;
88}
89
94
96{
97 AVBufferRef *hw_frames_ctx = ff_filter_link(link->dst->outputs[0])->hw_frames_ctx;
99
100 if (!hw_frames_ctx || ff_filter_link(link)->hw_frames_ctx)
101 return ff_default_get_video_buffer(link, w, h);
102
104 if (!frame)
105 return NULL;
106
107 frame->format = link->format;
108 frame->width = w;
109 frame->height = h;
110 if (av_hwframe_get_transfer_buffer(hw_frames_ctx, frame) < 0) {
112 return NULL;
113 }
114
115 set_link_props(frame, link);
116
117 return frame;
118}
119
121{
122 AVFrame *ret = NULL;
123
125
126 if (link->dstpad->get_buffer.video)
127 ret = link->dstpad->get_buffer.video(link, w, h);
128
129 if (!ret)
131
132 return ret;
133}
static AVFrame * get_video_buffer(AVFilterLink *inlink, int w, int h)
Definition avf_concat.c:209
Main libavfilter public API header.
#define ff_tlog_link(ctx, link, end)
#define FF_TPRINTF_START(ctx, func)
static const uint8_t *BS_FUNC align(BSCTX *bc)
Skip bits to a byte boundary.
static BitStreamFilterLinkInternal * ff_link_internal(AVBitStreamFilterLink *link)
refcounted data buffer API
#define NULL
Definition coverity.c:32
static AVFrame * frame
int ret
Definition ffplay.c:391
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:65
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition frame.c:53
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
int av_hwframe_get_transfer_buffer(AVBufferRef *hwframe_ctx, AVFrame *frame)
Allocate the buffers of a software frame that data is transferred to or from frames of the given AVHW...
Definition hwcontext.c:442
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
Definition hwcontext.c:564
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition filters.h:199
size_t av_cpu_max_align(void)
Get the maximum data alignment that may be required by FFmpeg.
Definition cpu.c:289
AVFrame * ff_frame_pool_get(FFFramePool *pool)
Allocate a new AVFrame, reusing old buffers from the pool when available.
Definition framepool.c:128
int ff_frame_pool_video_reinit(FFFramePool *pool, int width, int height, enum AVPixelFormat format, int align)
Recreate the video frame pool if its current configuration differs from the provided configuration.
Definition framepool.c:223
uint8_t w
Definition llvidencdsp.c:39
pixel format definitions
A reference to a data buffer.
Definition buffer.h:82
uint8_t * data
The data buffer.
Definition buffer.h:90
AVFilterLink ** outputs
array of pointers to output links
Definition avfilter.h:291
A filter pad used for either input or output.
Definition filters.h:40
AVFrame *(* video)(AVFilterLink *link, int w, int h)
Definition filters.h:81
union AVFilterPad::@363170257351226013155122005037023043242205350137 get_buffer
Callback functions to get a video/audio buffers.
This structure describes decoded (raw) audio or video data.
Definition frame.h:479
This struct describes a set or pool of "hardware" frames (i.e.
Definition hwcontext.h:118
FFFramePool frame_pool
Pool of frames used for allocations.
AVFrame * ff_default_get_video_buffer2(AVFilterLink *link, int w, int h, int align)
Definition video.c:58
AVFrame * ff_null_get_video_buffer(AVFilterLink *link, int w, int h)
Definition video.c:44
static void set_link_props(AVFrame *frame, const AVFilterLink *link)
Definition video.c:49
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
Definition video.c:37
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition video.c:120
AVFrame * ff_hwupload_get_video_buffer(AVFilterLink *link, int w, int h)
get_buffer.video() of the input of a filter that uploads software frames to the hardware frames conte...
Definition video.c:95
AVFrame * ff_default_get_video_buffer(AVFilterLink *link, int w, int h)
Definition video.c:90