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 module ffmpeg.libavfilter.buffersink;
20 
21 import ffmpeg.libavfilter.avfilter;
22 
23 extern (C):
24 import ffmpeg; @nogc nothrow:
25 
26 /**
27  * @file
28  * @ingroup lavfi_buffersink
29  * memory buffer sink API for audio and video
30  */
31 
32 /**
33  * @defgroup lavfi_buffersink Buffer sink API
34  * @ingroup lavfi
35  * @{
36  */
37 
38 /**
39  * Get a frame with filtered data from sink and put it in frame.
40  *
41  * @param ctx    pointer to a buffersink or abuffersink filter context.
42  * @param frame  pointer to an allocated frame that will be filled with data.
43  *               The data must be freed using av_frame_unref() / av_frame_free()
44  * @param flags  a combination of AV_BUFFERSINK_FLAG_* flags
45  *
46  * @return  >= 0 in for success, a negative AVERROR code for failure.
47  */
48 int av_buffersink_get_frame_flags (AVFilterContext* ctx, AVFrame* frame, int flags);
49 
50 /**
51  * Tell av_buffersink_get_buffer_ref() to read video/samples buffer
52  * reference, but not remove it from the buffer. This is useful if you
53  * need only to read a video/samples buffer, without to fetch it.
54  */
55 enum AV_BUFFERSINK_FLAG_PEEK = 1;
56 
57 /**
58  * Tell av_buffersink_get_buffer_ref() not to request a frame from its input.
59  * If a frame is already buffered, it is read (and removed from the buffer),
60  * but if no frame is present, return AVERROR(EAGAIN).
61  */
62 enum AV_BUFFERSINK_FLAG_NO_REQUEST = 2;
63 
64 /**
65  * Struct to use for initializing a buffersink context.
66  */
67 struct AVBufferSinkParams
68 {
69     const(AVPixelFormat)* pixel_fmts; ///< list of allowed pixel formats, terminated by AV_PIX_FMT_NONE
70 }
71 
72 /**
73  * Create an AVBufferSinkParams structure.
74  *
75  * Must be freed with av_free().
76  */
77 AVBufferSinkParams* av_buffersink_params_alloc ();
78 
79 /**
80  * Struct to use for initializing an abuffersink context.
81  */
82 struct AVABufferSinkParams
83 {
84     const(AVSampleFormat)* sample_fmts; ///< list of allowed sample formats, terminated by AV_SAMPLE_FMT_NONE
85     const(long)* channel_layouts; ///< list of allowed channel layouts, terminated by -1
86     const(int)* channel_counts; ///< list of allowed channel counts, terminated by -1
87     int all_channel_counts; ///< if not 0, accept any channel count or layout
88     int* sample_rates; ///< list of allowed sample rates, terminated by -1
89 }
90 
91 /**
92  * Create an AVABufferSinkParams structure.
93  *
94  * Must be freed with av_free().
95  */
96 AVABufferSinkParams* av_abuffersink_params_alloc ();
97 
98 /**
99  * Set the frame size for an audio buffer sink.
100  *
101  * All calls to av_buffersink_get_buffer_ref will return a buffer with
102  * exactly the specified number of samples, or AVERROR(EAGAIN) if there is
103  * not enough. The last buffer at EOF will be padded with 0.
104  */
105 void av_buffersink_set_frame_size (AVFilterContext* ctx, uint frame_size);
106 
107 /**
108  * @defgroup lavfi_buffersink_accessors Buffer sink accessors
109  * Get the properties of the stream
110  * @{
111  */
112 
113 AVMediaType av_buffersink_get_type (const(AVFilterContext)* ctx);
114 AVRational av_buffersink_get_time_base (const(AVFilterContext)* ctx);
115 int av_buffersink_get_format (const(AVFilterContext)* ctx);
116 
117 AVRational av_buffersink_get_frame_rate (const(AVFilterContext)* ctx);
118 int av_buffersink_get_w (const(AVFilterContext)* ctx);
119 int av_buffersink_get_h (const(AVFilterContext)* ctx);
120 AVRational av_buffersink_get_sample_aspect_ratio (const(AVFilterContext)* ctx);
121 
122 int av_buffersink_get_channels (const(AVFilterContext)* ctx);
123 ulong av_buffersink_get_channel_layout (const(AVFilterContext)* ctx);
124 int av_buffersink_get_sample_rate (const(AVFilterContext)* ctx);
125 
126 AVBufferRef* av_buffersink_get_hw_frames_ctx (const(AVFilterContext)* ctx);
127 
128 /** @} */
129 
130 /**
131  * Get a frame with filtered data from sink and put it in frame.
132  *
133  * @param ctx pointer to a context of a buffersink or abuffersink AVFilter.
134  * @param frame pointer to an allocated frame that will be filled with data.
135  *              The data must be freed using av_frame_unref() / av_frame_free()
136  *
137  * @return
138  *         - >= 0 if a frame was successfully returned.
139  *         - AVERROR(EAGAIN) if no frames are available at this point; more
140  *           input frames must be added to the filtergraph to get more output.
141  *         - AVERROR_EOF if there will be no more output frames on this sink.
142  *         - A different negative AVERROR code in other failure cases.
143  */
144 int av_buffersink_get_frame (AVFilterContext* ctx, AVFrame* frame);
145 
146 /**
147  * Same as av_buffersink_get_frame(), but with the ability to specify the number
148  * of samples read. This function is less efficient than
149  * av_buffersink_get_frame(), because it copies the data around.
150  *
151  * @param ctx pointer to a context of the abuffersink AVFilter.
152  * @param frame pointer to an allocated frame that will be filled with data.
153  *              The data must be freed using av_frame_unref() / av_frame_free()
154  *              frame will contain exactly nb_samples audio samples, except at
155  *              the end of stream, when it can contain less than nb_samples.
156  *
157  * @return The return codes have the same meaning as for
158  *         av_buffersink_get_frame().
159  *
160  * @warning do not mix this function with av_buffersink_get_frame(). Use only one or
161  * the other with a single sink, not both.
162  */
163 int av_buffersink_get_samples (AVFilterContext* ctx, AVFrame* frame, int nb_samples);
164 
165 /**
166  * @}
167  */
168 
169 /* AVFILTER_BUFFERSINK_H */