2 * This file is part of FFmpeg.
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.
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.
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
19 #ifndef AVFILTER_BUFFERSINK_H
20 #define AVFILTER_BUFFERSINK_H
24 * memory buffer sink API for audio and video
29 #if FF_API_AVFILTERBUFFER
31 * Get an audio/video buffer data from buffer_sink and put it in bufref.
33 * This function works with both audio and video buffer sinks.
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
41 int av_buffersink_get_buffer_ref(AVFilterContext *buffer_sink,
42 AVFilterBufferRef **bufref, int flags);
45 * Get the number of immediately available frames.
48 int av_buffersink_poll_frame(AVFilterContext *ctx);
51 * Get a buffer with filtered data from sink and put it in buf.
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
59 * @return >= 0 in case of success, a negative AVERROR code in case of
63 int av_buffersink_read(AVFilterContext *ctx, AVFilterBufferRef **buf);
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.
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
78 * @warning do not mix this function with av_buffersink_read(). Use only one or
79 * the other with a single sink, not both.
82 int av_buffersink_read_samples(AVFilterContext *ctx, AVFilterBufferRef **buf,
87 * Get a frame with filtered data from sink and put it in frame.
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
94 * @return >= 0 in for success, a negative AVERROR code for failure.
96 int av_buffersink_get_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags);
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.
103 #define AV_BUFFERSINK_FLAG_PEEK 1
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).
110 #define AV_BUFFERSINK_FLAG_NO_REQUEST 2
113 * Struct to use for initializing a buffersink context.
116 const enum AVPixelFormat *pixel_fmts; ///< list of allowed pixel formats, terminated by AV_PIX_FMT_NONE
117 } AVBufferSinkParams;
120 * Create an AVBufferSinkParams structure.
122 * Must be freed with av_free().
124 AVBufferSinkParams *av_buffersink_params_alloc(void);
127 * Struct to use for initializing an abuffersink context.
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
135 } AVABufferSinkParams;
138 * Create an AVABufferSinkParams structure.
140 * Must be freed with av_free().
142 AVABufferSinkParams *av_abuffersink_params_alloc(void);
145 * Set the frame size for an audio buffer sink.
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.
151 void av_buffersink_set_frame_size(AVFilterContext *ctx, unsigned frame_size);
154 * Get the frame rate of the input.
156 AVRational av_buffersink_get_frame_rate(AVFilterContext *ctx);
159 * Get a frame with filtered data from sink and put it in frame.
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()
165 * @return >= 0 in case of success, a negative AVERROR code in case of
168 int av_buffersink_get_frame(AVFilterContext *ctx, AVFrame *frame);
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.
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.
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.
184 int av_buffersink_get_samples(AVFilterContext *ctx, AVFrame *frame, int nb_samples);
186 #endif /* AVFILTER_BUFFERSINK_H */