FFmpeg: libavcodec/get_buffer.c Source File
Go to the documentation of this file. 1 /*
2 * The default get_buffer2() implementation
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <stdint.h>
22
32
36
38 /**
39 * Pools for each data plane. For audio all the planes have the same size,
40 * so only pools[0] is used.
41 */
43
44 /*
45 * Pool parameters
46 */
55
57 {
60
63 }
64
66 {
69
73 return 0;
77 return 0;
78 }
79
81 if (!pool)
83
86 int linesize[4];
89 int unaligned;
90 ptrdiff_t linesize1[4];
92
94
95 do {
96 // NOTE: do not align linesizes individually, this breaks e.g. assumptions
97 // that linesize[0] == 2*linesize[1] in the MPEG-encoder for 4:2:2
101 // increase alignment of w for next try (rhs gives the lowest bit set in w)
103
104 unaligned = 0;
105 for (
i = 0;
i < 4;
i++)
107 } while (unaligned);
108
109 for (
i = 0;
i < 4;
i++)
110 linesize1[
i] = linesize[
i];
114
115 for (
i = 0;
i < 4;
i++) {
121 }
123 CONFIG_MEMORY_POISONING ?
129 }
130 }
131 }
135
136 break;
137 }
140 frame->ch_layout.nb_channels,
144
146 CONFIG_MEMORY_POISONING ?
149 if (!pool->
pools[0]) {
152 }
153
158 break;
159 }
161 }
162
165
166 return 0;
170 }
171
173 {
177
179
184 sizeof(*
frame->extended_buf));
185 if (!
frame->extended_data || !
frame->extended_buf) {
189 }
190 } else {
193 }
194
200 }
201 for (
i = 0;
i <
frame->nb_extended_buf;
i++) {
203 if (!
frame->extended_buf[
i])
206 }
207
210
211 return 0;
215 }
216
218 {
221
224 return -1;
225 }
226
227 memset(pic->
data, 0,
sizeof(pic->
data));
229
230 for (
i = 0;
i < 4 && pool->
pools[
i];
i++) {
232
236
238 }
242 }
243
246
247 return 0;
251 }
252
254 {
256
265 "frame from a fixed pool of hardware frames.\n",
269 "extra_hw_frames to a larger value "
270 "(currently set to %d, giving a pool size of %d).\n",
273 }
274 }
278 }
279
282
288 default:
289 return -1;
290 }
291 }
AVBufferPool * av_buffer_pool_init(size_t size, AVBufferRef *(*alloc)(size_t size))
Allocate and initialize a buffer pool.
#define AV_LOG_WARNING
Something somehow does not look correct.
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 all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
uint8_t * data
The data buffer.
RefStruct is an API for creating reference-counted objects with minimal overhead.
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
static int video_get_buffer(AVCodecContext *s, AVFrame *pic)
static const struct @532 planes[]
This structure describes decoded (raw) audio or video data.
AVBufferPool * pools[4]
Pools for each data plane.
int stride_align[AV_NUM_DATA_POINTERS]
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
int av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width)
Fill plane linesizes for an image with pixel format pix_fmt and width width.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
static void * av_refstruct_alloc_ext(size_t size, unsigned flags, void *opaque, void(*free_cb)(AVRefStructOpaque opaque, void *obj))
A wrapper around av_refstruct_alloc_ext_c() for the common case of a non-const qualified opaque.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, int linesize_align[AV_NUM_DATA_POINTERS])
Modify width and height values so that they will result in a memory buffer that is acceptable for the...
static void frame_pool_free(AVRefStructOpaque unused, void *obj)
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
int av_image_fill_plane_sizes(size_t sizes[4], enum AVPixelFormat pix_fmt, int height, const ptrdiff_t linesizes[4])
Fill plane sizes for an image with pixel format pix_fmt and height height.
struct AVCodecInternal * internal
Private context used for internal data.
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame)
int extra_hw_frames
Video decoding only.
#define AV_NUM_DATA_POINTERS
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
int avcodec_default_get_buffer2(AVCodecContext *avctx, AVFrame *frame, int flags)
The default callback for AVCodecContext.get_buffer2().
#define i(width, name, range_min, range_max)
uint8_t ** extended_data
pointers to the data planes/channels.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align)
Get the required buffer size for the given audio parameters.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
void * av_calloc(size_t nmemb, size_t size)
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames.
This struct describes a set or pool of "hardware" frames (i.e.
AVBufferRef * av_buffer_allocz(size_t size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
main external API structure.
static int update_frame_pool(AVCodecContext *avctx, AVFrame *frame)
int coded_width
Bitstream width / height, may be different from width/height e.g.
int initial_pool_size
Initial size of the frame pool.
enum AVMediaType codec_type
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
int warned_on_failed_allocation_from_fixed_pool
Set when the user has been warned about a failed allocation from a fixed frame pool.
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Generated on Sat Oct 18 2025 19:22:05 for FFmpeg by
doxygen
1.8.17