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 module ffmpeg.libavfilter.buffersink;
19 
20 import ffmpeg.libavutil;
21 import ffmpeg.libavfilter;
22 
23 extern (C) @nogc nothrow:
24 
25 /**
26  * @file
27  * @ingroup lavfi_buffersink
28  * memory buffer sink API for audio and video
29  */
30 
31 /**
32  * @defgroup lavfi_buffersink Buffer sink API
33  * @ingroup lavfi
34  * @{
35  *
36  * The buffersink and abuffersink filters are there to connect filter graphs
37  * to applications. They have a single input, connected to the graph, and no
38  * output. Frames must be extracted using av_buffersink_get_frame() or
39  * av_buffersink_get_samples().
40  *
41  * The format negotiated by the graph during configuration can be obtained
42  * using the accessor functions:
43  * - av_buffersink_get_time_base(),
44  * - av_buffersink_get_format(),
45  * - av_buffersink_get_frame_rate(),
46  * - av_buffersink_get_w(),
47  * - av_buffersink_get_h(),
48  * - av_buffersink_get_sample_aspect_ratio(),
49  * - av_buffersink_get_channels(),
50  * - av_buffersink_get_channel_layout(),
51  * - av_buffersink_get_sample_rate().
52  *
53  * The format can be constrained by setting options, using av_opt_set() and
54  * related functions with the AV_OPT_SEARCH_CHILDREN flag.
55  *  - pix_fmts (int list),
56  *  - sample_fmts (int list),
57  *  - sample_rates (int list),
58  *  - channel_layouts (int64_t),
59  *  - channel_counts (int list),
60  *  - all_channel_counts (bool).
61  * Most of these options are of type binary, and should be set using
62  * av_opt_set_int_list() or av_opt_set_bin(). If they are not set, all
63  * corresponding formats are accepted.
64  *
65  * As a special case, if neither channel_layouts nor channel_counts is set,
66  * all valid channel layouts are accepted, but channel counts without a
67  * layout are not, unless all_channel_counts is set.
68  * Also, channel_layouts must not contain a channel layout already accepted
69  * by a value in channel_counts; for example, if channel_counts contains 2,
70  * then channel_layouts must not contain stereo.
71  */
72 
73 /**
74  * Get a frame with filtered data from sink and put it in frame.
75  *
76  * @param ctx    pointer to a buffersink or abuffersink filter context.
77  * @param frame  pointer to an allocated frame that will be filled with data.
78  *               The data must be freed using av_frame_unref() / av_frame_free()
79  * @param flags  a combination of AV_BUFFERSINK_FLAG_* flags
80  *
81  * @return  >= 0 in for success, a negative AVERROR code for failure.
82  */
83 int av_buffersink_get_frame_flags (AVFilterContext* ctx, AVFrame* frame, int flags);
84 
85 /**
86  * Tell av_buffersink_get_buffer_ref() to read video/samples buffer
87  * reference, but not remove it from the buffer. This is useful if you
88  * need only to read a video/samples buffer, without to fetch it.
89  */
90 enum AV_BUFFERSINK_FLAG_PEEK = 1;
91 
92 /**
93  * Tell av_buffersink_get_buffer_ref() not to request a frame from its input.
94  * If a frame is already buffered, it is read (and removed from the buffer),
95  * but if no frame is present, return AVERROR(EAGAIN).
96  */
97 enum AV_BUFFERSINK_FLAG_NO_REQUEST = 2;
98 
99 /**
100  * Deprecated and unused struct to use for initializing a buffersink context.
101  */
102 struct AVBufferSinkParams
103 {
104     const(AVPixelFormat)* pixel_fmts; ///< list of allowed pixel formats, terminated by AV_PIX_FMT_NONE
105 }
106 
107 /**
108  * Create an AVBufferSinkParams structure.
109  *
110  * Must be freed with av_free().
111  */
112 AVBufferSinkParams* av_buffersink_params_alloc ();
113 
114 /**
115  * Deprecated and unused struct to use for initializing an abuffersink context.
116  */
117 struct AVABufferSinkParams
118 {
119     const(AVSampleFormat)* sample_fmts; ///< list of allowed sample formats, terminated by AV_SAMPLE_FMT_NONE
120     const(long)* channel_layouts; ///< list of allowed channel layouts, terminated by -1
121     const(int)* channel_counts; ///< list of allowed channel counts, terminated by -1
122     int all_channel_counts; ///< if not 0, accept any channel count or layout
123     int* sample_rates; ///< list of allowed sample rates, terminated by -1
124 }
125 
126 /**
127  * Create an AVABufferSinkParams structure.
128  *
129  * Must be freed with av_free().
130  */
131 AVABufferSinkParams* av_abuffersink_params_alloc ();
132 
133 /**
134  * Set the frame size for an audio buffer sink.
135  *
136  * All calls to av_buffersink_get_buffer_ref will return a buffer with
137  * exactly the specified number of samples, or AVERROR(EAGAIN) if there is
138  * not enough. The last buffer at EOF will be padded with 0.
139  */
140 void av_buffersink_set_frame_size (AVFilterContext* ctx, uint frame_size);
141 
142 /**
143  * @defgroup lavfi_buffersink_accessors Buffer sink accessors
144  * Get the properties of the stream
145  * @{
146  */
147 
148 AVMediaType av_buffersink_get_type (const(AVFilterContext)* ctx);
149 AVRational av_buffersink_get_time_base (const(AVFilterContext)* ctx);
150 int av_buffersink_get_format (const(AVFilterContext)* ctx);
151 
152 AVRational av_buffersink_get_frame_rate (const(AVFilterContext)* ctx);
153 int av_buffersink_get_w (const(AVFilterContext)* ctx);
154 int av_buffersink_get_h (const(AVFilterContext)* ctx);
155 AVRational av_buffersink_get_sample_aspect_ratio (const(AVFilterContext)* ctx);
156 
157 int av_buffersink_get_channels (const(AVFilterContext)* ctx);
158 ulong av_buffersink_get_channel_layout (const(AVFilterContext)* ctx);
159 int av_buffersink_get_sample_rate (const(AVFilterContext)* ctx);
160 
161 AVBufferRef* av_buffersink_get_hw_frames_ctx (const(AVFilterContext)* ctx);
162 
163 /** @} */
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  */
179 int av_buffersink_get_frame (AVFilterContext* ctx, AVFrame* frame);
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_frame().
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 /* AVFILTER_BUFFERSINK_H */