FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
buffersink.h
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #ifndef AVFILTER_BUFFERSINK_H
20 #define AVFILTER_BUFFERSINK_H
21 
22 /**
23  * @file
24  * @ingroup lavfi_buffersink
25  * memory buffer sink API for audio and video
26  */
27 
28 #include "avfilter.h"
29 
30 /**
31  * @defgroup lavfi_buffersink Buffer sink API
32  * @ingroup lavfi
33  * @{
34  */
35 
36 #if FF_API_AVFILTERBUFFER
37 /**
38  * Get an audio/video buffer data from buffer_sink and put it in bufref.
39  *
40  * This function works with both audio and video buffer sinks.
41  *
42  * @param buffer_sink pointer to a buffersink or abuffersink context
43  * @param flags a combination of AV_BUFFERSINK_FLAG_* flags
44  * @return >= 0 in case of success, a negative AVERROR code in case of
45  * failure
46  */
48 int av_buffersink_get_buffer_ref(AVFilterContext *buffer_sink,
49  AVFilterBufferRef **bufref, int flags);
50 
51 /**
52  * Get the number of immediately available frames.
53  */
56 
57 /**
58  * Get a buffer with filtered data from sink and put it in buf.
59  *
60  * @param ctx pointer to a context of a buffersink or abuffersink AVFilter.
61  * @param buf pointer to the buffer will be written here if buf is non-NULL. buf
62  * must be freed by the caller using avfilter_unref_buffer().
63  * Buf may also be NULL to query whether a buffer is ready to be
64  * output.
65  *
66  * @return >= 0 in case of success, a negative AVERROR code in case of
67  * failure.
68  */
70 int av_buffersink_read(AVFilterContext *ctx, AVFilterBufferRef **buf);
71 
72 /**
73  * Same as av_buffersink_read, but with the ability to specify the number of
74  * samples read. This function is less efficient than av_buffersink_read(),
75  * because it copies the data around.
76  *
77  * @param ctx pointer to a context of the abuffersink AVFilter.
78  * @param buf pointer to the buffer will be written here if buf is non-NULL. buf
79  * must be freed by the caller using avfilter_unref_buffer(). buf
80  * will contain exactly nb_samples audio samples, except at the end
81  * of stream, when it can contain less than nb_samples.
82  * Buf may also be NULL to query whether a buffer is ready to be
83  * output.
84  *
85  * @warning do not mix this function with av_buffersink_read(). Use only one or
86  * the other with a single sink, not both.
87  */
89 int av_buffersink_read_samples(AVFilterContext *ctx, AVFilterBufferRef **buf,
90  int nb_samples);
91 #endif
92 
93 /**
94  * Get a frame with filtered data from sink and put it in frame.
95  *
96  * @param ctx pointer to a buffersink or abuffersink filter context.
97  * @param frame pointer to an allocated frame that will be filled with data.
98  * The data must be freed using av_frame_unref() / av_frame_free()
99  * @param flags a combination of AV_BUFFERSINK_FLAG_* flags
100  *
101  * @return >= 0 in for success, a negative AVERROR code for failure.
102  */
104 
105 /**
106  * Tell av_buffersink_get_buffer_ref() to read video/samples buffer
107  * reference, but not remove it from the buffer. This is useful if you
108  * need only to read a video/samples buffer, without to fetch it.
109  */
110 #define AV_BUFFERSINK_FLAG_PEEK 1
111 
112 /**
113  * Tell av_buffersink_get_buffer_ref() not to request a frame from its input.
114  * If a frame is already buffered, it is read (and removed from the buffer),
115  * but if no frame is present, return AVERROR(EAGAIN).
116  */
117 #define AV_BUFFERSINK_FLAG_NO_REQUEST 2
118 
119 /**
120  * Struct to use for initializing a buffersink context.
121  */
122 typedef struct {
123  const enum AVPixelFormat *pixel_fmts; ///< list of allowed pixel formats, terminated by AV_PIX_FMT_NONE
125 
126 /**
127  * Create an AVBufferSinkParams structure.
128  *
129  * Must be freed with av_free().
130  */
132 
133 /**
134  * Struct to use for initializing an abuffersink context.
135  */
136 typedef struct {
137  const enum AVSampleFormat *sample_fmts; ///< list of allowed sample formats, terminated by AV_SAMPLE_FMT_NONE
138  const int64_t *channel_layouts; ///< list of allowed channel layouts, terminated by -1
139  const int *channel_counts; ///< list of allowed channel counts, terminated by -1
140  int all_channel_counts; ///< if not 0, accept any channel count or layout
141  int *sample_rates; ///< list of allowed sample rates, terminated by -1
143 
144 /**
145  * Create an AVABufferSinkParams structure.
146  *
147  * Must be freed with av_free().
148  */
150 
151 /**
152  * Set the frame size for an audio buffer sink.
153  *
154  * All calls to av_buffersink_get_buffer_ref will return a buffer with
155  * exactly the specified number of samples, or AVERROR(EAGAIN) if there is
156  * not enough. The last buffer at EOF will be padded with 0.
157  */
159 
160 /**
161  * Get the frame rate of the input.
162  */
164 
165 /**
166  * Get a frame with filtered data from sink and put it in frame.
167  *
168  * @param ctx pointer to a context of a buffersink or abuffersink AVFilter.
169  * @param frame pointer to an allocated frame that will be filled with data.
170  * The data must be freed using av_frame_unref() / av_frame_free()
171  *
172  * @return
173  * - >= 0 if a frame was successfully returned.
174  * - AVERROR(EAGAIN) if no frames are available at this point; more
175  * input frames must be added to the filtergraph to get more output.
176  * - AVERROR_EOF if there will be no more output frames on this sink.
177  * - A different negative AVERROR code in other failure cases.
178  */
180 
181 /**
182  * Same as av_buffersink_get_frame(), but with the ability to specify the number
183  * of samples read. This function is less efficient than
184  * av_buffersink_get_frame(), because it copies the data around.
185  *
186  * @param ctx pointer to a context of the abuffersink AVFilter.
187  * @param frame pointer to an allocated frame that will be filled with data.
188  * The data must be freed using av_frame_unref() / av_frame_free()
189  * frame will contain exactly nb_samples audio samples, except at
190  * the end of stream, when it can contain less than nb_samples.
191  *
192  * @return The return codes have the same meaning as for
193  * av_buffersink_get_samples().
194  *
195  * @warning do not mix this function with av_buffersink_get_frame(). Use only one or
196  * the other with a single sink, not both.
197  */
198 int av_buffersink_get_samples(AVFilterContext *ctx, AVFrame *frame, int nb_samples);
199 
200 /**
201  * @}
202  */
203 
204 #endif /* AVFILTER_BUFFERSINK_H */
This structure describes decoded (raw) audio or video data.
Definition: frame.h:171
AVBufferSinkParams * av_buffersink_params_alloc(void)
Create an AVBufferSinkParams structure.
Definition: buffersink.c:225
Main libavfilter public API header.
const int * channel_counts
list of allowed channel counts, terminated by -1
Definition: buffersink.h:139
AVABufferSinkParams * av_abuffersink_params_alloc(void)
Create an AVABufferSinkParams structure.
Definition: buffersink.c:236
enum AVSampleFormat * sample_fmts
list of allowed sample formats, terminated by AV_SAMPLE_FMT_NONE
Definition: buffersink.h:137
static AVFrame * frame
int attribute_align_arg av_buffersink_poll_frame(AVFilterContext *ctx)
Definition: buffersink.c:366
int * sample_rates
list of allowed sample rates, terminated by -1
Definition: buffersink.h:141
int av_buffersink_get_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags)
Get a frame with filtered data from sink and put it in frame.
Definition: buffersink.c:126
Struct to use for initializing an abuffersink context.
Definition: buffersink.h:136
int av_buffersink_get_samples(AVFilterContext *ctx, AVFrame *frame, int nb_samples)
Same as av_buffersink_get_frame(), but with the ability to specify the number of samples read...
Definition: buffersink.c:181
Struct to use for initializing a buffersink context.
Definition: buffersink.h:122
int frame_size
Definition: mxfenc.c:1803
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:59
void * buf
Definition: avisynth_c.h:553
int all_channel_counts
if not 0, accept any channel count or layout
Definition: buffersink.h:140
rational number numerator/denominator
Definition: rational.h:43
AVRational av_buffersink_get_frame_rate(AVFilterContext *ctx)
Get the frame rate of the input.
Definition: buffersink.c:358
static int flags
Definition: cpu.c:47
#define attribute_deprecated
Definition: attributes.h:86
enum AVPixelFormat * pixel_fmts
list of allowed pixel formats, terminated by AV_PIX_FMT_NONE
Definition: buffersink.h:123
void av_buffersink_set_frame_size(AVFilterContext *ctx, unsigned frame_size)
Set the frame size for an audio buffer sink.
Definition: buffersink.c:261
An instance of a filter.
Definition: avfilter.h:633
int av_buffersink_get_frame(AVFilterContext *ctx, AVFrame *frame)
Get a frame with filtered data from sink and put it in frame.
Definition: buffersink.c:121
const int64_t * channel_layouts
list of allowed channel layouts, terminated by -1
Definition: buffersink.h:138
AVPixelFormat
Pixel format.
Definition: pixfmt.h:61