FFmpeg
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/hwcontext.h"
29 #include "libavutil/imgutils.h"
30 
31 #include "avfilter.h"
32 #include "avfilter_internal.h"
33 #include "framepool.h"
34 #include "internal.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 
50 {
52  AVFrame *frame = NULL;
53  int pool_width = 0;
54  int pool_height = 0;
55  int pool_align = 0;
56  enum AVPixelFormat pool_format = AV_PIX_FMT_NONE;
57 
58  if (link->hw_frames_ctx &&
59  ((AVHWFramesContext*)link->hw_frames_ctx->data)->format == link->format) {
60  int ret;
62 
63  if (!frame)
64  return NULL;
65 
67  if (ret < 0)
69 
70  return frame;
71  }
72 
73  if (!li->frame_pool) {
75  link->format, align);
76  if (!li->frame_pool)
77  return NULL;
78  } else {
80  &pool_width, &pool_height,
81  &pool_format, &pool_align) < 0) {
82  return NULL;
83  }
84 
85  if (pool_width != w || pool_height != h ||
86  pool_format != link->format || pool_align != align) {
87 
90  link->format, align);
91  if (!li->frame_pool)
92  return NULL;
93  }
94  }
95 
97  if (!frame)
98  return NULL;
99 
103 
104  return frame;
105 }
106 
108 {
110 }
111 
113 {
114  AVFrame *ret = NULL;
115 
117 
118  if (link->dstpad->get_buffer.video)
119  ret = link->dstpad->get_buffer.video(link, w, h);
120 
121  if (!ret)
123 
124  return ret;
125 }
ff_default_get_video_buffer2
AVFrame * ff_default_get_video_buffer2(AVFilterLink *link, int w, int h, int align)
Definition: video.c:49
ff_get_video_buffer
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:112
AVFrame::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: frame.h:623
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
ff_link_internal
static FilterLinkInternal * ff_link_internal(AVFilterLink *link)
Definition: avfilter_internal.h:82
ff_frame_pool_video_init
FFFramePool * ff_frame_pool_video_init(AVBufferRef *(*alloc)(size_t size), int width, int height, enum AVPixelFormat format, int align)
Allocate and initialize a video frame pool.
Definition: framepool.c:51
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:130
AVFrame::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: frame.h:634
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:344
w
uint8_t w
Definition: llviddspenc.c:38
video.h
FilterLinkInternal
Definition: avfilter_internal.h:33
ff_default_get_video_buffer
AVFrame * ff_default_get_video_buffer(AVFilterLink *link, int w, int h)
Definition: video.c:107
ff_frame_pool_get_video_config
int ff_frame_pool_get_video_config(FFFramePool *pool, int *width, int *height, enum AVPixelFormat *format, int *align)
Get the video frame pool configuration.
Definition: framepool.c:152
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:33
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:118
ff_video_default_filterpad
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
ff_frame_pool_get
AVFrame * ff_frame_pool_get(FFFramePool *pool)
Allocate a new AVFrame, reussing old buffers from the pool when available.
Definition: framepool.c:190
link
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a link
Definition: filter_design.txt:23
frame
static AVFrame * frame
Definition: demux_decode.c:54
NULL
#define NULL
Definition: coverity.c:32
av_cpu_max_align
size_t av_cpu_max_align(void)
Get the maximum data alignment that may be required by FFmpeg.
Definition: cpu.c:268
avfilter_internal.h
ff_tlog_link
#define ff_tlog_link(ctx, link, end)
Definition: internal.h:268
ff_frame_pool_uninit
void ff_frame_pool_uninit(FFFramePool **pool)
Deallocate the frame pool.
Definition: framepool.c:278
FF_TPRINTF_START
#define FF_TPRINTF_START(ctx, func)
Definition: internal.h:263
cpu.h
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:431
buffer.h
align
static const uint8_t *BS_FUNC() align(BSCTX *bc)
Skip bits to a byte boundary.
Definition: bitstream_template.h:411
ff_null_get_video_buffer
AVFrame * ff_null_get_video_buffer(AVFilterLink *link, int w, int h)
Definition: video.c:44
internal.h
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:39
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:115
av_buffer_allocz
AVBufferRef * av_buffer_allocz(size_t size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
Definition: buffer.c:93
ret
ret
Definition: filter_design.txt:187
framepool.h
AVFrame::sample_aspect_ratio
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:451
AVFrame::hw_frames_ctx
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
Definition: frame.h:695
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
avfilter.h
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
FilterLinkInternal::frame_pool
struct FFFramePool * frame_pool
Definition: avfilter_internal.h:36
imgutils.h
hwcontext.h
h
h
Definition: vp9dsp_template.c:2038
av_hwframe_get_buffer
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
Definition: hwcontext.c:491
get_video_buffer
static AVFrame * get_video_buffer(AVFilterLink *inlink, int w, int h)
Definition: avf_concat.c:200