FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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/avassert.h"
27 #include "libavutil/buffer.h"
28 #include "libavutil/hwcontext.h"
29 #include "libavutil/imgutils.h"
30 #include "libavutil/mem.h"
31 
32 #include "avfilter.h"
33 #include "internal.h"
34 #include "video.h"
35 
36 #define BUFFER_ALIGN 32
37 
38 
40 {
41  return ff_get_video_buffer(link->dst->outputs[0], w, h);
42 }
43 
45 {
46  int pool_width = 0;
47  int pool_height = 0;
48  int pool_align = 0;
49  enum AVPixelFormat pool_format = AV_PIX_FMT_NONE;
50 
51  if (link->hw_frames_ctx &&
52  ((AVHWFramesContext*)link->hw_frames_ctx->data)->format == link->format) {
53  int ret;
55 
56  if (!frame)
57  return NULL;
58 
59  ret = av_hwframe_get_buffer(link->hw_frames_ctx, frame, 0);
60  if (ret < 0)
61  av_frame_free(&frame);
62 
63  return frame;
64  }
65 
66  if (!link->frame_pool) {
68  link->format, BUFFER_ALIGN);
69  if (!link->frame_pool)
70  return NULL;
71  } else {
73  &pool_width, &pool_height,
74  &pool_format, &pool_align) < 0) {
75  return NULL;
76  }
77 
78  if (pool_width != w || pool_height != h ||
79  pool_format != link->format || pool_align != BUFFER_ALIGN) {
80 
83  link->format, BUFFER_ALIGN);
84  if (!link->frame_pool)
85  return NULL;
86  }
87  }
88 
89  return ff_frame_pool_get(link->frame_pool);
90 }
91 
93 {
94  AVFrame *ret = NULL;
95 
97 
98  if (link->dstpad->get_video_buffer)
99  ret = link->dstpad->get_video_buffer(link, w, h);
100 
101  if (!ret)
102  ret = ff_default_get_video_buffer(link, w, h);
103 
104  return ret;
105 }
#define NULL
Definition: coverity.c:32
This structure describes decoded (raw) audio or video data.
Definition: frame.h:201
misc image utilities
AVFrame * ff_frame_pool_get(FFFramePool *pool)
Allocate a new AVFrame, reussing old buffers from the pool when available.
Definition: framepool.c:195
Main libavfilter public API header.
Memory handling functions.
AVFrame * ff_null_get_video_buffer(AVFilterLink *link, int w, int h)
Definition: video.c:39
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:92
void ff_frame_pool_uninit(FFFramePool **pool)
Deallocate the frame pool.
Definition: framepool.c:284
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:150
static AVFrame * get_video_buffer(AVFilterLink *inlink, int w, int h)
Definition: avf_concat.c:206
static AVFrame * frame
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:163
simple assert() macros that are a bit more flexible than ISO C assert().
#define FF_TPRINTF_START(ctx, func)
Definition: internal.h:250
FFFramePool * ff_frame_pool_video_init(AVBufferRef *(*alloc)(int size), int width, int height, enum AVPixelFormat format, int align)
Allocate and initialize a video frame pool.
Definition: framepool.c:51
Frame pool.
Definition: framepool.c:30
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
Definition: hwcontext.c:459
AVFrame *(* get_video_buffer)(AVFilterLink *link, int w, int h)
Callback function to get a video buffer.
Definition: internal.h:73
void ff_tlog_link(void *ctx, AVFilterLink *link, int end)
Definition: avfilter.c:381
uint8_t * data
The data buffer.
Definition: buffer.h:89
AVBufferRef * av_buffer_allocz(int size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
Definition: buffer.c:83
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:121
refcounted data buffer API
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
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:157
AVFrame * ff_default_get_video_buffer(AVFilterLink *link, int w, int h)
Definition: video.c:44
#define BUFFER_ALIGN
Definition: video.c:36
internal API functions
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60