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  * memory buffer sink API for audio and video
25  */
26 
27 #include "avfilter.h"
28 
29 #if FF_API_AVFILTERBUFFER
30 /**
31  * Get an audio/video buffer data from buffer_sink and put it in bufref.
32  *
33  * This function works with both audio and video buffer sinks.
34  *
35  * @param buffer_sink pointer to a buffersink or abuffersink context
36  * @param flags a combination of AV_BUFFERSINK_FLAG_* flags
37  * @return >= 0 in case of success, a negative AVERROR code in case of
38  * failure
39  */
41 int av_buffersink_get_buffer_ref(AVFilterContext *buffer_sink,
42  AVFilterBufferRef **bufref, int flags);
43 
44 /**
45  * Get the number of immediately available frames.
46  */
49 
50 /**
51  * Get a buffer with filtered data from sink and put it in buf.
52  *
53  * @param ctx pointer to a context of a buffersink or abuffersink AVFilter.
54  * @param buf pointer to the buffer will be written here if buf is non-NULL. buf
55  * must be freed by the caller using avfilter_unref_buffer().
56  * Buf may also be NULL to query whether a buffer is ready to be
57  * output.
58  *
59  * @return >= 0 in case of success, a negative AVERROR code in case of
60  * failure.
61  */
63 int av_buffersink_read(AVFilterContext *ctx, AVFilterBufferRef **buf);
64 
65 /**
66  * Same as av_buffersink_read, but with the ability to specify the number of
67  * samples read. This function is less efficient than av_buffersink_read(),
68  * because it copies the data around.
69  *
70  * @param ctx pointer to a context of the abuffersink AVFilter.
71  * @param buf pointer to the buffer will be written here if buf is non-NULL. buf
72  * must be freed by the caller using avfilter_unref_buffer(). buf
73  * will contain exactly nb_samples audio samples, except at the end
74  * of stream, when it can contain less than nb_samples.
75  * Buf may also be NULL to query whether a buffer is ready to be
76  * output.
77  *
78  * @warning do not mix this function with av_buffersink_read(). Use only one or
79  * the other with a single sink, not both.
80  */
82 int av_buffersink_read_samples(AVFilterContext *ctx, AVFilterBufferRef **buf,
83  int nb_samples);
84 #endif
85 
86 /**
87  * Get a frame with filtered data from sink and put it in frame.
88  *
89  * @param ctx pointer to a buffersink or abuffersink filter context.
90  * @param frame pointer to an allocated frame that will be filled with data.
91  * The data must be freed using av_frame_unref() / av_frame_free()
92  * @param flags a combination of AV_BUFFERSINK_FLAG_* flags
93  *
94  * @return >= 0 in for success, a negative AVERROR code for failure.
95  */
97 
98 /**
99  * Tell av_buffersink_get_buffer_ref() to read video/samples buffer
100  * reference, but not remove it from the buffer. This is useful if you
101  * need only to read a video/samples buffer, without to fetch it.
102  */
103 #define AV_BUFFERSINK_FLAG_PEEK 1
104 
105 /**
106  * Tell av_buffersink_get_buffer_ref() not to request a frame from its input.
107  * If a frame is already buffered, it is read (and removed from the buffer),
108  * but if no frame is present, return AVERROR(EAGAIN).
109  */
110 #define AV_BUFFERSINK_FLAG_NO_REQUEST 2
111 
112 /**
113  * Struct to use for initializing a buffersink context.
114  */
115 typedef struct {
116  const enum AVPixelFormat *pixel_fmts; ///< list of allowed pixel formats, terminated by AV_PIX_FMT_NONE
118 
119 /**
120  * Create an AVBufferSinkParams structure.
121  *
122  * Must be freed with av_free().
123  */
125 
126 /**
127  * Struct to use for initializing an abuffersink context.
128  */
129 typedef struct {
130  const enum AVSampleFormat *sample_fmts; ///< list of allowed sample formats, terminated by AV_SAMPLE_FMT_NONE
131  const int64_t *channel_layouts; ///< list of allowed channel layouts, terminated by -1
132  const int *channel_counts; ///< list of allowed channel counts, terminated by -1
133  int all_channel_counts; ///< if not 0, accept any channel count or layout
134  int *sample_rates; ///< list of allowed sample rates, terminated by -1
136 
137 /**
138  * Create an AVABufferSinkParams structure.
139  *
140  * Must be freed with av_free().
141  */
143 
144 /**
145  * Set the frame size for an audio buffer sink.
146  *
147  * All calls to av_buffersink_get_buffer_ref will return a buffer with
148  * exactly the specified number of samples, or AVERROR(EAGAIN) if there is
149  * not enough. The last buffer at EOF will be padded with 0.
150  */
152 
153 /**
154  * Get the frame rate of the input.
155  */
157 
158 /**
159  * Get a frame with filtered data from sink and put it in frame.
160  *
161  * @param ctx pointer to a context of a buffersink or abuffersink AVFilter.
162  * @param frame pointer to an allocated frame that will be filled with data.
163  * The data must be freed using av_frame_unref() / av_frame_free()
164  *
165  * @return >= 0 in case of success, a negative AVERROR code in case of
166  * failure.
167  */
169 
170 /**
171  * Same as av_buffersink_get_frame(), but with the ability to specify the number
172  * of samples read. This function is less efficient than
173  * av_buffersink_get_frame(), because it copies the data around.
174  *
175  * @param ctx pointer to a context of the abuffersink AVFilter.
176  * @param frame pointer to an allocated frame that will be filled with data.
177  * The data must be freed using av_frame_unref() / av_frame_free()
178  * frame will contain exactly nb_samples audio samples, except at
179  * the end of stream, when it can contain less than nb_samples.
180  *
181  * @warning do not mix this function with av_buffersink_get_frame(). Use only one or
182  * the other with a single sink, not both.
183  */
184 int av_buffersink_get_samples(AVFilterContext *ctx, AVFrame *frame, int nb_samples);
185 
186 #endif /* AVFILTER_BUFFERSINK_H */
AVBufferSinkParams * av_buffersink_params_alloc(void)
Create an AVBufferSinkParams structure.
Definition: buffersink.c:223
This structure describes decoded (raw) audio or video data.
Definition: frame.h:76
external API header
const int * channel_counts
list of allowed channel counts, terminated by -1
Definition: buffersink.h:132
enum AVSampleFormat * sample_fmts
list of allowed sample formats, terminated by AV_SAMPLE_FMT_NONE
Definition: buffersink.h:130
frame
Definition: stft.m:14
static const uint8_t frame_size[4]
Definition: g723_1_data.h:58
int attribute_align_arg av_buffersink_poll_frame(AVFilterContext *ctx)
Definition: buffersink.c:360
int * sample_rates
list of allowed sample rates, terminated by -1
Definition: buffersink.h:134
Struct to use for initializing an abuffersink context.
Definition: buffersink.h:129
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
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
Struct to use for initializing a buffersink context.
Definition: buffersink.h:115
void * buf
Definition: avisynth_c.h:594
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:179
int all_channel_counts
if not 0, accept any channel count or layout
Definition: buffersink.h:133
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:352
static int flags
Definition: cpu.c:23
#define attribute_deprecated
Definition: attributes.h:90
AVABufferSinkParams * av_abuffersink_params_alloc(void)
Create an AVABufferSinkParams structure.
Definition: buffersink.c:234
enum AVPixelFormat * pixel_fmts
list of allowed pixel formats, terminated by AV_PIX_FMT_NONE
Definition: buffersink.h:116
AVSampleFormat
Audio Sample Formats.
Definition: samplefmt.h:49
void av_buffersink_set_frame_size(AVFilterContext *ctx, unsigned frame_size)
Set the frame size for an audio buffer sink.
Definition: buffersink.c:258
An instance of a filter.
Definition: avfilter.h:524
const int64_t * channel_layouts
list of allowed channel layouts, terminated by -1
Definition: buffersink.h:131
AVPixelFormat
Pixel format.
Definition: pixfmt.h:66