1 /*
2  * AVCodec public API
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 module ffmpeg.libavcodec.codec;
21 
22 import ffmpeg.libavcodec;
23 import ffmpeg.libavutil;
24 
25 extern (C) @nogc nothrow:
26 
27 /**
28  * @addtogroup lavc_core
29  * @{
30  */
31 
32 /**
33  * Decoder can use draw_horiz_band callback.
34  */
35 enum AV_CODEC_CAP_DRAW_HORIZ_BAND = 1 << 0;
36 /**
37  * Codec uses get_buffer() or get_encode_buffer() for allocating buffers and
38  * supports custom allocators.
39  * If not set, it might not use get_buffer() or get_encode_buffer() at all, or
40  * use operations that assume the buffer was allocated by
41  * avcodec_default_get_buffer2 or avcodec_default_get_encode_buffer.
42  */
43 enum AV_CODEC_CAP_DR1 = 1 << 1;
44 enum AV_CODEC_CAP_TRUNCATED = 1 << 3;
45 /**
46  * Encoder or decoder requires flushing with NULL input at the end in order to
47  * give the complete and correct output.
48  *
49  * NOTE: If this flag is not set, the codec is guaranteed to never be fed with
50  *       with NULL data. The user can still send NULL data to the public encode
51  *       or decode function, but libavcodec will not pass it along to the codec
52  *       unless this flag is set.
53  *
54  * Decoders:
55  * The decoder has a non-zero delay and needs to be fed with avpkt->data=NULL,
56  * avpkt->size=0 at the end to get the delayed data until the decoder no longer
57  * returns frames.
58  *
59  * Encoders:
60  * The encoder needs to be fed with NULL data at the end of encoding until the
61  * encoder no longer returns data.
62  *
63  * NOTE: For encoders implementing the AVCodec.encode2() function, setting this
64  *       flag also means that the encoder must set the pts and duration for
65  *       each output packet. If this flag is not set, the pts and duration will
66  *       be determined by libavcodec from the input frame.
67  */
68 enum AV_CODEC_CAP_DELAY = 1 << 5;
69 /**
70  * Codec can be fed a final frame with a smaller size.
71  * This can be used to prevent truncation of the last audio samples.
72  */
73 enum AV_CODEC_CAP_SMALL_LAST_FRAME = 1 << 6;
74 
75 /**
76  * Codec can output multiple frames per AVPacket
77  * Normally demuxers return one frame at a time, demuxers which do not do
78  * are connected to a parser to split what they return into proper frames.
79  * This flag is reserved to the very rare category of codecs which have a
80  * bitstream that cannot be split into frames without timeconsuming
81  * operations like full decoding. Demuxers carrying such bitstreams thus
82  * may return multiple frames in a packet. This has many disadvantages like
83  * prohibiting stream copy in many cases thus it should only be considered
84  * as a last resort.
85  */
86 enum AV_CODEC_CAP_SUBFRAMES = 1 << 8;
87 /**
88  * Codec is experimental and is thus avoided in favor of non experimental
89  * encoders
90  */
91 enum AV_CODEC_CAP_EXPERIMENTAL = 1 << 9;
92 /**
93  * Codec should fill in channel configuration and samplerate instead of container
94  */
95 enum AV_CODEC_CAP_CHANNEL_CONF = 1 << 10;
96 /**
97  * Codec supports frame-level multithreading.
98  */
99 enum AV_CODEC_CAP_FRAME_THREADS = 1 << 12;
100 /**
101  * Codec supports slice-based (or partition-based) multithreading.
102  */
103 enum AV_CODEC_CAP_SLICE_THREADS = 1 << 13;
104 /**
105  * Codec supports changed parameters at any point.
106  */
107 enum AV_CODEC_CAP_PARAM_CHANGE = 1 << 14;
108 /**
109  * Codec supports multithreading through a method other than slice- or
110  * frame-level multithreading. Typically this marks wrappers around
111  * multithreading-capable external libraries.
112  */
113 enum AV_CODEC_CAP_OTHER_THREADS = 1 << 15;
114 enum AV_CODEC_CAP_AUTO_THREADS = AV_CODEC_CAP_OTHER_THREADS;
115 
116 /**
117  * Audio encoder supports receiving a different number of samples in each call.
118  */
119 enum AV_CODEC_CAP_VARIABLE_FRAME_SIZE = 1 << 16;
120 /**
121  * Decoder is not a preferred choice for probing.
122  * This indicates that the decoder is not a good choice for probing.
123  * It could for example be an expensive to spin up hardware decoder,
124  * or it could simply not provide a lot of useful information about
125  * the stream.
126  * A decoder marked with this flag should only be used as last resort
127  * choice for probing.
128  */
129 enum AV_CODEC_CAP_AVOID_PROBING = 1 << 17;
130 
131 /**
132  * Deprecated and unused. Use AVCodecDescriptor.props instead
133  */
134 enum AV_CODEC_CAP_INTRA_ONLY = 0x40000000;
135 /**
136  * Deprecated and unused. Use AVCodecDescriptor.props instead
137  */
138 enum AV_CODEC_CAP_LOSSLESS = 0x80000000;
139 
140 /**
141  * Codec is backed by a hardware implementation. Typically used to
142  * identify a non-hwaccel hardware decoder. For information about hwaccels, use
143  * avcodec_get_hw_config() instead.
144  */
145 enum AV_CODEC_CAP_HARDWARE = 1 << 18;
146 
147 /**
148  * Codec is potentially backed by a hardware implementation, but not
149  * necessarily. This is used instead of AV_CODEC_CAP_HARDWARE, if the
150  * implementation provides some sort of internal fallback.
151  */
152 enum AV_CODEC_CAP_HYBRID = 1 << 19;
153 
154 /**
155  * This codec takes the reordered_opaque field from input AVFrames
156  * and returns it in the corresponding field in AVCodecContext after
157  * encoding.
158  */
159 enum AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE = 1 << 20;
160 
161 /**
162  * This encoder can be flushed using avcodec_flush_buffers(). If this flag is
163  * not set, the encoder must be closed and reopened to ensure that no frames
164  * remain pending.
165  */
166 enum AV_CODEC_CAP_ENCODER_FLUSH = 1 << 21;
167 
168 /**
169  * AVProfile.
170  */
171 struct AVProfile
172 {
173     int profile;
174     const(char)* name; ///< short name for the profile
175 }
176 
177 struct AVCodecDefault;
178 
179 //struct AVCodecContext;
180 struct AVSubtitle;
181 
182 /**
183  * AVCodec.
184  */
185 struct AVCodec
186 {
187     /**
188      * Name of the codec implementation.
189      * The name is globally unique among encoders and among decoders (but an
190      * encoder and a decoder can share the same name).
191      * This is the primary way to find a codec from the user perspective.
192      */
193     const(char)* name;
194     /**
195      * Descriptive name for the codec, meant to be more human readable than name.
196      * You should use the NULL_IF_CONFIG_SMALL() macro to define it.
197      */
198     const(char)* long_name;
199     AVMediaType type;
200     AVCodecID id;
201     /**
202      * Codec capabilities.
203      * see AV_CODEC_CAP_*
204      */
205     int capabilities;
206     const(AVRational)* supported_framerates; ///< array of supported framerates, or NULL if any, array is terminated by {0,0}
207     const(AVPixelFormat)* pix_fmts; ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1
208     const(int)* supported_samplerates; ///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0
209     const(AVSampleFormat)* sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1
210     const(ulong)* channel_layouts; ///< array of support channel layouts, or NULL if unknown. array is terminated by 0
211     ubyte max_lowres; ///< maximum value for lowres supported by the decoder
212     const(AVClass)* priv_class; ///< AVClass for the private context
213     const(AVProfile)* profiles; ///< array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN}
214 
215     /**
216      * Group name of the codec implementation.
217      * This is a short symbolic name of the wrapper backing this codec. A
218      * wrapper uses some kind of external implementation for the codec, such
219      * as an external library, or a codec implementation provided by the OS or
220      * the hardware.
221      * If this field is NULL, this is a builtin, libavcodec native codec.
222      * If non-NULL, this will be the suffix in AVCodec.name in most cases
223      * (usually AVCodec.name will be of the form "<codec_name>_<wrapper_name>").
224      */
225     const(char)* wrapper_name;
226 
227     /*****************************************************************
228      * No fields below this line are part of the public API. They
229      * may not be used outside of libavcodec and can be changed and
230      * removed at will.
231      * New public fields should be added right above.
232      *****************************************************************
233      */
234     int priv_data_size;
235 
236     AVCodec* next;
237 
238     /**
239      * @name Frame-level threading support functions
240      * @{
241      */
242     /**
243      * Copy necessary context variables from a previous thread context to the current one.
244      * If not defined, the next thread will start automatically; otherwise, the codec
245      * must call ff_thread_finish_setup().
246      *
247      * dst and src will (rarely) point to the same context, in which case memcpy should be skipped.
248      */
249     int function (AVCodecContext* dst, const(AVCodecContext)* src) update_thread_context;
250     /** @} */
251 
252     /**
253      * Private codec-specific defaults.
254      */
255     const(AVCodecDefault)* defaults;
256 
257     /**
258      * Initialize codec static data, called from av_codec_iterate().
259      *
260      * This is not intended for time consuming operations as it is
261      * run for every codec regardless of that codec being used.
262      */
263     void function (AVCodec* codec) init_static_data;
264 
265     int function (AVCodecContext*) init;
266     int function (
267         AVCodecContext*,
268         ubyte* buf,
269         int buf_size,
270         const(AVSubtitle)* sub) encode_sub;
271     /**
272      * Encode data to an AVPacket.
273      *
274      * @param      avctx          codec context
275      * @param      avpkt          output AVPacket
276      * @param[in]  frame          AVFrame containing the raw data to be encoded
277      * @param[out] got_packet_ptr encoder sets to 0 or 1 to indicate that a
278      *                            non-empty packet was returned in avpkt.
279      * @return 0 on success, negative error code on failure
280      */
281     int function (
282         AVCodecContext* avctx,
283         AVPacket* avpkt,
284         const(AVFrame)* frame,
285         int* got_packet_ptr) encode2;
286     /**
287      * Decode picture or subtitle data.
288      *
289      * @param      avctx          codec context
290      * @param      outdata        codec type dependent output struct
291      * @param[out] got_frame_ptr  decoder sets to 0 or 1 to indicate that a
292      *                            non-empty frame or subtitle was returned in
293      *                            outdata.
294      * @param[in]  avpkt          AVPacket containing the data to be decoded
295      * @return amount of bytes read from the packet on success, negative error
296      *         code on failure
297      */
298     int function (
299         AVCodecContext* avctx,
300         void* outdata,
301         int* got_frame_ptr,
302         AVPacket* avpkt) decode;
303     int function (AVCodecContext*) close;
304     /**
305      * Encode API with decoupled frame/packet dataflow. This function is called
306      * to get one output packet. It should call ff_encode_get_frame() to obtain
307      * input data.
308      */
309     int function (AVCodecContext* avctx, AVPacket* avpkt) receive_packet;
310 
311     /**
312      * Decode API with decoupled packet/frame dataflow. This function is called
313      * to get one output frame. It should call ff_decode_get_packet() to obtain
314      * input data.
315      */
316     int function (AVCodecContext* avctx, AVFrame* frame) receive_frame;
317     /**
318      * Flush buffers.
319      * Will be called when seeking
320      */
321     void function (AVCodecContext*) flush;
322     /**
323      * Internal codec capabilities.
324      * See FF_CODEC_CAP_* in internal.h
325      */
326     int caps_internal;
327 
328     /**
329      * Decoding only, a comma-separated list of bitstream filters to apply to
330      * packets before decoding.
331      */
332     const(char)* bsfs;
333 
334     /**
335      * Array of pointers to hardware configurations supported by the codec,
336      * or NULL if no hardware supported.  The array is terminated by a NULL
337      * pointer.
338      *
339      * The user can only access this field via avcodec_get_hw_config().
340      */
341     struct AVCodecHWConfigInternal;
342     const(AVCodecHWConfigInternal*)* hw_configs;
343 
344     /**
345      * List of supported codec_tags, terminated by FF_CODEC_TAGS_END.
346      */
347     const(uint)* codec_tags;
348 }
349 
350 /**
351  * Iterate over all registered codecs.
352  *
353  * @param opaque a pointer where libavcodec will store the iteration state. Must
354  *               point to NULL to start the iteration.
355  *
356  * @return the next registered codec or NULL when the iteration is
357  *         finished
358  */
359 const(AVCodec)* av_codec_iterate (void** opaque);
360 
361 /**
362  * Find a registered decoder with a matching codec ID.
363  *
364  * @param id AVCodecID of the requested decoder
365  * @return A decoder if one was found, NULL otherwise.
366  */
367 AVCodec* avcodec_find_decoder (AVCodecID id);
368 
369 /**
370  * Find a registered decoder with the specified name.
371  *
372  * @param name name of the requested decoder
373  * @return A decoder if one was found, NULL otherwise.
374  */
375 AVCodec* avcodec_find_decoder_by_name (const(char)* name);
376 
377 /**
378  * Find a registered encoder with a matching codec ID.
379  *
380  * @param id AVCodecID of the requested encoder
381  * @return An encoder if one was found, NULL otherwise.
382  */
383 AVCodec* avcodec_find_encoder (AVCodecID id);
384 
385 /**
386  * Find a registered encoder with the specified name.
387  *
388  * @param name name of the requested encoder
389  * @return An encoder if one was found, NULL otherwise.
390  */
391 AVCodec* avcodec_find_encoder_by_name (const(char)* name);
392 /**
393  * @return a non-zero number if codec is an encoder, zero otherwise
394  */
395 int av_codec_is_encoder (const(AVCodec)* codec);
396 
397 /**
398  * @return a non-zero number if codec is a decoder, zero otherwise
399  */
400 int av_codec_is_decoder (const(AVCodec)* codec);
401 
402 enum
403 {
404     /**
405      * The codec supports this format via the hw_device_ctx interface.
406      *
407      * When selecting this format, AVCodecContext.hw_device_ctx should
408      * have been set to a device of the specified type before calling
409      * avcodec_open2().
410      */
411     AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX = 0x01,
412     /**
413      * The codec supports this format via the hw_frames_ctx interface.
414      *
415      * When selecting this format for a decoder,
416      * AVCodecContext.hw_frames_ctx should be set to a suitable frames
417      * context inside the get_format() callback.  The frames context
418      * must have been created on a device of the specified type.
419      *
420      * When selecting this format for an encoder,
421      * AVCodecContext.hw_frames_ctx should be set to the context which
422      * will be used for the input frames before calling avcodec_open2().
423      */
424     AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX = 0x02,
425     /**
426      * The codec supports this format by some internal method.
427      *
428      * This format can be selected without any additional configuration -
429      * no device or frames context is required.
430      */
431     AV_CODEC_HW_CONFIG_METHOD_INTERNAL = 0x04,
432     /**
433      * The codec supports this format by some ad-hoc method.
434      *
435      * Additional settings and/or function calls are required.  See the
436      * codec-specific documentation for details.  (Methods requiring
437      * this sort of configuration are deprecated and others should be
438      * used in preference.)
439      */
440     AV_CODEC_HW_CONFIG_METHOD_AD_HOC = 0x08
441 }
442 
443 struct AVCodecHWConfig
444 {
445     /**
446      * For decoders, a hardware pixel format which that decoder may be
447      * able to decode to if suitable hardware is available.
448      *
449      * For encoders, a pixel format which the encoder may be able to
450      * accept.  If set to AV_PIX_FMT_NONE, this applies to all pixel
451      * formats supported by the codec.
452      */
453     AVPixelFormat pix_fmt;
454     /**
455      * Bit set of AV_CODEC_HW_CONFIG_METHOD_* flags, describing the possible
456      * setup methods which can be used with this configuration.
457      */
458     int methods;
459     /**
460      * The device type associated with the configuration.
461      *
462      * Must be set for AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX and
463      * AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX, otherwise unused.
464      */
465     AVHWDeviceType device_type;
466 }
467 
468 /**
469  * Retrieve supported hardware configurations for a codec.
470  *
471  * Values of index from zero to some maximum return the indexed configuration
472  * descriptor; all other values return NULL.  If the codec does not support
473  * any hardware configurations then it will always return NULL.
474  */
475 const(AVCodecHWConfig)* avcodec_get_hw_config (const(AVCodec)* codec, int index);
476 
477 /**
478  * @}
479  */
480 
481 /* AVCODEC_CODEC_H */