1 /*
2  * copyright (c) 2001 Fabrice Bellard
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.avcodec;
21 
22 import ffmpeg.libavutil;
23 import ffmpeg.libavcodec;
24 
25 extern (C) @nogc nothrow:
26 
27 /**
28  * @file
29  * @ingroup libavc
30  * Libavcodec external API header
31  */
32 
33 /**
34  * @defgroup libavc libavcodec
35  * Encoding/Decoding Library
36  *
37  * @{
38  *
39  * @defgroup lavc_decoding Decoding
40  * @{
41  * @}
42  *
43  * @defgroup lavc_encoding Encoding
44  * @{
45  * @}
46  *
47  * @defgroup lavc_codec Codecs
48  * @{
49  * @defgroup lavc_codec_native Native Codecs
50  * @{
51  * @}
52  * @defgroup lavc_codec_wrappers External library wrappers
53  * @{
54  * @}
55  * @defgroup lavc_codec_hwaccel Hardware Accelerators bridge
56  * @{
57  * @}
58  * @}
59  * @defgroup lavc_internal Internal
60  * @{
61  * @}
62  * @}
63  */
64 
65 /**
66  * @ingroup libavc
67  * @defgroup lavc_encdec send/receive encoding and decoding API overview
68  * @{
69  *
70  * The avcodec_send_packet()/avcodec_receive_frame()/avcodec_send_frame()/
71  * avcodec_receive_packet() functions provide an encode/decode API, which
72  * decouples input and output.
73  *
74  * The API is very similar for encoding/decoding and audio/video, and works as
75  * follows:
76  * - Set up and open the AVCodecContext as usual.
77  * - Send valid input:
78  *   - For decoding, call avcodec_send_packet() to give the decoder raw
79  *     compressed data in an AVPacket.
80  *   - For encoding, call avcodec_send_frame() to give the encoder an AVFrame
81  *     containing uncompressed audio or video.
82  *
83  *   In both cases, it is recommended that AVPackets and AVFrames are
84  *   refcounted, or libavcodec might have to copy the input data. (libavformat
85  *   always returns refcounted AVPackets, and av_frame_get_buffer() allocates
86  *   refcounted AVFrames.)
87  * - Receive output in a loop. Periodically call one of the avcodec_receive_*()
88  *   functions and process their output:
89  *   - For decoding, call avcodec_receive_frame(). On success, it will return
90  *     an AVFrame containing uncompressed audio or video data.
91  *   - For encoding, call avcodec_receive_packet(). On success, it will return
92  *     an AVPacket with a compressed frame.
93  *
94  *   Repeat this call until it returns AVERROR(EAGAIN) or an error. The
95  *   AVERROR(EAGAIN) return value means that new input data is required to
96  *   return new output. In this case, continue with sending input. For each
97  *   input frame/packet, the codec will typically return 1 output frame/packet,
98  *   but it can also be 0 or more than 1.
99  *
100  * At the beginning of decoding or encoding, the codec might accept multiple
101  * input frames/packets without returning a frame, until its internal buffers
102  * are filled. This situation is handled transparently if you follow the steps
103  * outlined above.
104  *
105  * In theory, sending input can result in EAGAIN - this should happen only if
106  * not all output was received. You can use this to structure alternative decode
107  * or encode loops other than the one suggested above. For example, you could
108  * try sending new input on each iteration, and try to receive output if that
109  * returns EAGAIN.
110  *
111  * End of stream situations. These require "flushing" (aka draining) the codec,
112  * as the codec might buffer multiple frames or packets internally for
113  * performance or out of necessity (consider B-frames).
114  * This is handled as follows:
115  * - Instead of valid input, send NULL to the avcodec_send_packet() (decoding)
116  *   or avcodec_send_frame() (encoding) functions. This will enter draining
117  *   mode.
118  * - Call avcodec_receive_frame() (decoding) or avcodec_receive_packet()
119  *   (encoding) in a loop until AVERROR_EOF is returned. The functions will
120  *   not return AVERROR(EAGAIN), unless you forgot to enter draining mode.
121  * - Before decoding can be resumed again, the codec has to be reset with
122  *   avcodec_flush_buffers().
123  *
124  * Using the API as outlined above is highly recommended. But it is also
125  * possible to call functions outside of this rigid schema. For example, you can
126  * call avcodec_send_packet() repeatedly without calling
127  * avcodec_receive_frame(). In this case, avcodec_send_packet() will succeed
128  * until the codec's internal buffer has been filled up (which is typically of
129  * size 1 per output frame, after initial input), and then reject input with
130  * AVERROR(EAGAIN). Once it starts rejecting input, you have no choice but to
131  * read at least some output.
132  *
133  * Not all codecs will follow a rigid and predictable dataflow; the only
134  * guarantee is that an AVERROR(EAGAIN) return value on a send/receive call on
135  * one end implies that a receive/send call on the other end will succeed, or
136  * at least will not fail with AVERROR(EAGAIN). In general, no codec will
137  * permit unlimited buffering of input or output.
138  *
139  * This API replaces the following legacy functions:
140  * - avcodec_decode_video2() and avcodec_decode_audio4():
141  *   Use avcodec_send_packet() to feed input to the decoder, then use
142  *   avcodec_receive_frame() to receive decoded frames after each packet.
143  *   Unlike with the old video decoding API, multiple frames might result from
144  *   a packet. For audio, splitting the input packet into frames by partially
145  *   decoding packets becomes transparent to the API user. You never need to
146  *   feed an AVPacket to the API twice (unless it is rejected with AVERROR(EAGAIN) - then
147  *   no data was read from the packet).
148  *   Additionally, sending a flush/draining packet is required only once.
149  * - avcodec_encode_video2()/avcodec_encode_audio2():
150  *   Use avcodec_send_frame() to feed input to the encoder, then use
151  *   avcodec_receive_packet() to receive encoded packets.
152  *   Providing user-allocated buffers for avcodec_receive_packet() is not
153  *   possible.
154  * - The new API does not handle subtitles yet.
155  *
156  * Mixing new and old function calls on the same AVCodecContext is not allowed,
157  * and will result in undefined behavior.
158  *
159  * Some codecs might require using the new API; using the old API will return
160  * an error when calling it. All codecs support the new API.
161  *
162  * A codec is not allowed to return AVERROR(EAGAIN) for both sending and receiving. This
163  * would be an invalid state, which could put the codec user into an endless
164  * loop. The API has no concept of time either: it cannot happen that trying to
165  * do avcodec_send_packet() results in AVERROR(EAGAIN), but a repeated call 1 second
166  * later accepts the packet (with no other receive/flush API calls involved).
167  * The API is a strict state machine, and the passage of time is not supposed
168  * to influence it. Some timing-dependent behavior might still be deemed
169  * acceptable in certain cases. But it must never result in both send/receive
170  * returning EAGAIN at the same time at any point. It must also absolutely be
171  * avoided that the current state is "unstable" and can "flip-flop" between
172  * the send/receive APIs allowing progress. For example, it's not allowed that
173  * the codec randomly decides that it actually wants to consume a packet now
174  * instead of returning a frame, after it just returned AVERROR(EAGAIN) on an
175  * avcodec_send_packet() call.
176  * @}
177  */
178 
179 /**
180  * @defgroup lavc_core Core functions/structures.
181  * @ingroup libavc
182  *
183  * Basic definitions, functions for querying libavcodec capabilities,
184  * allocating core structures, etc.
185  * @{
186  */
187 
188 /**
189  * @ingroup lavc_decoding
190  * Required number of additionally allocated bytes at the end of the input bitstream for decoding.
191  * This is mainly needed because some optimized bitstream readers read
192  * 32 or 64 bit at once and could read over the end.<br>
193  * Note: If the first 23 bits of the additional bytes are not 0, then damaged
194  * MPEG bitstreams could cause overread and segfault.
195  */
196 enum AV_INPUT_BUFFER_PADDING_SIZE = 64;
197 
198 /**
199  * @ingroup lavc_encoding
200  * minimum encoding buffer size
201  * Used to avoid some checks during header writing.
202  */
203 enum AV_INPUT_BUFFER_MIN_SIZE = 16384;
204 
205 /**
206  * @ingroup lavc_decoding
207  */
208 enum AVDiscard
209 {
210     /* We leave some space between them for extensions (drop some
211      * keyframes for intra-only or drop just some bidir frames). */
212     AVDISCARD_NONE = -16, ///< discard nothing
213     AVDISCARD_DEFAULT = 0, ///< discard useless packets like 0 size packets in avi
214     AVDISCARD_NONREF = 8, ///< discard all non reference
215     AVDISCARD_BIDIR = 16, ///< discard all bidirectional frames
216     AVDISCARD_NONINTRA = 24, ///< discard all non intra frames
217     AVDISCARD_NONKEY = 32, ///< discard all frames except keyframes
218     AVDISCARD_ALL = 48 ///< discard all
219 }
220 
221 enum AVAudioServiceType
222 {
223     AV_AUDIO_SERVICE_TYPE_MAIN = 0,
224     AV_AUDIO_SERVICE_TYPE_EFFECTS = 1,
225     AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED = 2,
226     AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED = 3,
227     AV_AUDIO_SERVICE_TYPE_DIALOGUE = 4,
228     AV_AUDIO_SERVICE_TYPE_COMMENTARY = 5,
229     AV_AUDIO_SERVICE_TYPE_EMERGENCY = 6,
230     AV_AUDIO_SERVICE_TYPE_VOICE_OVER = 7,
231     AV_AUDIO_SERVICE_TYPE_KARAOKE = 8,
232     AV_AUDIO_SERVICE_TYPE_NB = 9 ///< Not part of ABI
233 }
234 
235 /**
236  * @ingroup lavc_encoding
237  */
238 struct RcOverride
239 {
240     int start_frame;
241     int end_frame;
242     int qscale; // If this is 0 then quality_factor will be used instead.
243     float quality_factor;
244 }
245 
246 /* encoding support
247    These flags can be passed in AVCodecContext.flags before initialization.
248    Note: Not everything is supported yet.
249 */
250 
251 /**
252  * Allow decoders to produce frames with data planes that are not aligned
253  * to CPU requirements (e.g. due to cropping).
254  */
255 enum AV_CODEC_FLAG_UNALIGNED = 1 << 0;
256 /**
257  * Use fixed qscale.
258  */
259 enum AV_CODEC_FLAG_QSCALE = 1 << 1;
260 /**
261  * 4 MV per MB allowed / advanced prediction for H.263.
262  */
263 enum AV_CODEC_FLAG_4MV = 1 << 2;
264 /**
265  * Output even those frames that might be corrupted.
266  */
267 enum AV_CODEC_FLAG_OUTPUT_CORRUPT = 1 << 3;
268 /**
269  * Use qpel MC.
270  */
271 enum AV_CODEC_FLAG_QPEL = 1 << 4;
272 /**
273  * Don't output frames whose parameters differ from first
274  * decoded frame in stream.
275  */
276 enum AV_CODEC_FLAG_DROPCHANGED = 1 << 5;
277 /**
278  * Use internal 2pass ratecontrol in first pass mode.
279  */
280 enum AV_CODEC_FLAG_PASS1 = 1 << 9;
281 /**
282  * Use internal 2pass ratecontrol in second pass mode.
283  */
284 enum AV_CODEC_FLAG_PASS2 = 1 << 10;
285 /**
286  * loop filter.
287  */
288 enum AV_CODEC_FLAG_LOOP_FILTER = 1 << 11;
289 /**
290  * Only decode/encode grayscale.
291  */
292 enum AV_CODEC_FLAG_GRAY = 1 << 13;
293 /**
294  * error[?] variables will be set during encoding.
295  */
296 enum AV_CODEC_FLAG_PSNR = 1 << 15;
297 /**
298  * Input bitstream might be truncated at a random location
299  * instead of only at frame boundaries.
300  */
301 enum AV_CODEC_FLAG_TRUNCATED = 1 << 16;
302 /**
303  * Use interlaced DCT.
304  */
305 enum AV_CODEC_FLAG_INTERLACED_DCT = 1 << 18;
306 /**
307  * Force low delay.
308  */
309 enum AV_CODEC_FLAG_LOW_DELAY = 1 << 19;
310 /**
311  * Place global headers in extradata instead of every keyframe.
312  */
313 enum AV_CODEC_FLAG_GLOBAL_HEADER = 1 << 22;
314 alias CODEC_FLAG_GLOBAL_HEADER = AV_CODEC_FLAG_GLOBAL_HEADER;
315 
316 enum AVFMT_RAWPICTURE = 0x0020;
317 /**
318  * Use only bitexact stuff (except (I)DCT).
319  */
320 enum AV_CODEC_FLAG_BITEXACT = 1 << 23;
321 /* Fx : Flag for H.263+ extra options */
322 /**
323  * H.263 advanced intra coding / MPEG-4 AC prediction
324  */
325 enum AV_CODEC_FLAG_AC_PRED = 1 << 24;
326 /**
327  * interlaced motion estimation
328  */
329 enum AV_CODEC_FLAG_INTERLACED_ME = 1 << 29;
330 enum AV_CODEC_FLAG_CLOSED_GOP = 1U << 31;
331 
332 /**
333  * Allow non spec compliant speedup tricks.
334  */
335 enum AV_CODEC_FLAG2_FAST = 1 << 0;
336 /**
337  * Skip bitstream encoding.
338  */
339 enum AV_CODEC_FLAG2_NO_OUTPUT = 1 << 2;
340 /**
341  * Place global headers at every keyframe instead of in extradata.
342  */
343 enum AV_CODEC_FLAG2_LOCAL_HEADER = 1 << 3;
344 
345 /**
346  * timecode is in drop frame format. DEPRECATED!!!!
347  */
348 enum AV_CODEC_FLAG2_DROP_FRAME_TIMECODE = 1 << 13;
349 
350 /**
351  * Input bitstream might be truncated at a packet boundaries
352  * instead of only at frame boundaries.
353  */
354 enum AV_CODEC_FLAG2_CHUNKS = 1 << 15;
355 /**
356  * Discard cropping information from SPS.
357  */
358 enum AV_CODEC_FLAG2_IGNORE_CROP = 1 << 16;
359 
360 /**
361  * Show all frames before the first keyframe
362  */
363 enum AV_CODEC_FLAG2_SHOW_ALL = 1 << 22;
364 /**
365  * Export motion vectors through frame side data
366  */
367 enum AV_CODEC_FLAG2_EXPORT_MVS = 1 << 28;
368 /**
369  * Do not skip samples and export skip information as frame side data
370  */
371 enum AV_CODEC_FLAG2_SKIP_MANUAL = 1 << 29;
372 /**
373  * Do not reset ASS ReadOrder field on flush (subtitles decoding)
374  */
375 enum AV_CODEC_FLAG2_RO_FLUSH_NOOP = 1 << 30;
376 
377 /* Unsupported options :
378  *              Syntax Arithmetic coding (SAC)
379  *              Reference Picture Selection
380  *              Independent Segment Decoding */
381 /* /Fx */
382 /* codec capabilities */
383 
384 /* Exported side data.
385    These flags can be passed in AVCodecContext.export_side_data before initialization.
386 */
387 /**
388  * Export motion vectors through frame side data
389  */
390 enum AV_CODEC_EXPORT_DATA_MVS = 1 << 0;
391 /**
392  * Export encoder Producer Reference Time through packet side data
393  */
394 enum AV_CODEC_EXPORT_DATA_PRFT = 1 << 1;
395 /**
396  * Decoding only.
397  * Export the AVVideoEncParams structure through frame side data.
398  */
399 enum AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS = 1 << 2;
400 /**
401  * Decoding only.
402  * Do not apply film grain, export it instead.
403  */
404 enum AV_CODEC_EXPORT_DATA_FILM_GRAIN = 1 << 3;
405 
406 /**
407  * Pan Scan area.
408  * This specifies the area which should be displayed.
409  * Note there may be multiple such areas for one frame.
410  */
411 struct AVPanScan
412 {
413     /**
414      * id
415      * - encoding: Set by user.
416      * - decoding: Set by libavcodec.
417      */
418     int id;
419 
420     /**
421      * width and height in 1/16 pel
422      * - encoding: Set by user.
423      * - decoding: Set by libavcodec.
424      */
425     int width;
426     int height;
427 
428     /**
429      * position of the top left corner in 1/16 pel for up to 3 fields/frames
430      * - encoding: Set by user.
431      * - decoding: Set by libavcodec.
432      */
433     short[2][3] position;
434 }
435 
436 /**
437  * This structure describes the bitrate properties of an encoded bitstream. It
438  * roughly corresponds to a subset the VBV parameters for MPEG-2 or HRD
439  * parameters for H.264/HEVC.
440  */
441 struct AVCPBProperties
442 {
443     /**
444      * Maximum bitrate of the stream, in bits per second.
445      * Zero if unknown or unspecified.
446      */
447 
448     int max_bitrate;
449 
450     /**
451      * Minimum bitrate of the stream, in bits per second.
452      * Zero if unknown or unspecified.
453      */
454 
455     int min_bitrate;
456 
457     /**
458      * Average bitrate of the stream, in bits per second.
459      * Zero if unknown or unspecified.
460      */
461 
462     int avg_bitrate;
463 
464     /**
465      * The size of the buffer to which the ratecontrol is applied, in bits.
466      * Zero if unknown or unspecified.
467      */
468     int buffer_size;
469 
470     /**
471      * The delay between the time the packet this structure is associated with
472      * is received and the time when it should be decoded, in periods of a 27MHz
473      * clock.
474      *
475      * UINT64_MAX when unknown or unspecified.
476      */
477     ulong vbv_delay;
478 }
479 
480 /**
481  * This structure supplies correlation between a packet timestamp and a wall clock
482  * production time. The definition follows the Producer Reference Time ('prft')
483  * as defined in ISO/IEC 14496-12
484  */
485 struct AVProducerReferenceTime
486 {
487     /**
488      * A UTC timestamp, in microseconds, since Unix epoch (e.g, av_gettime()).
489      */
490     long wallclock;
491     int flags;
492 }
493 
494 /**
495  * The decoder will keep a reference to the frame and may reuse it later.
496  */
497 enum AV_GET_BUFFER_FLAG_REF = 1 << 0;
498 
499 /**
500  * The encoder will keep a reference to the packet and may reuse it later.
501  */
502 enum AV_GET_ENCODE_BUFFER_FLAG_REF = 1 << 0;
503 
504 struct AVCodecInternal;
505 
506 /**
507  * main external API structure.
508  * New fields can be added to the end with minor version bumps.
509  * Removal, reordering and changes to existing fields require a major
510  * version bump.
511  * You can use AVOptions (av_opt* / av_set/get*()) to access these fields from user
512  * applications.
513  * The name string for AVOptions options matches the associated command line
514  * parameter name and can be found in libavcodec/options_table.h
515  * The AVOption/command line parameter names differ in some cases from the C
516  * structure field names for historic reasons or brevity.
517  * sizeof(AVCodecContext) must not be used outside libav*.
518  */
519 struct AVCodecContext
520 {
521     /**
522      * information on struct for av_log
523      * - set by avcodec_alloc_context3
524      */
525     const(AVClass)* av_class;
526     int log_level_offset;
527 
528     AVMediaType codec_type; /* see AVMEDIA_TYPE_xxx */
529     const(AVCodec)* codec;
530     AVCodecID codec_id; /* see AV_CODEC_ID_xxx */
531 
532     /**
533      * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
534      * This is used to work around some encoder bugs.
535      * A demuxer should set this to what is stored in the field used to identify the codec.
536      * If there are multiple such fields in a container then the demuxer should choose the one
537      * which maximizes the information about the used codec.
538      * If the codec tag field in a container is larger than 32 bits then the demuxer should
539      * remap the longer ID to 32 bits with a table or other structure. Alternatively a new
540      * extra_codec_tag + size could be added but for this a clear advantage must be demonstrated
541      * first.
542      * - encoding: Set by user, if not then the default based on codec_id will be used.
543      * - decoding: Set by user, will be converted to uppercase by libavcodec during init.
544      */
545     uint codec_tag;
546 
547     void* priv_data;
548 
549     /**
550      * Private context used for internal data.
551      *
552      * Unlike priv_data, this is not codec-specific. It is used in general
553      * libavcodec functions.
554      */
555     AVCodecInternal* internal;
556 
557     /**
558      * Private data of the user, can be used to carry app specific stuff.
559      * - encoding: Set by user.
560      * - decoding: Set by user.
561      */
562     void* opaque;
563 
564     /**
565      * the average bitrate
566      * - encoding: Set by user; unused for constant quantizer encoding.
567      * - decoding: Set by user, may be overwritten by libavcodec
568      *             if this info is available in the stream
569      */
570     long bit_rate;
571 
572     /**
573      * number of bits the bitstream is allowed to diverge from the reference.
574      *           the reference can be CBR (for CBR pass1) or VBR (for pass2)
575      * - encoding: Set by user; unused for constant quantizer encoding.
576      * - decoding: unused
577      */
578     int bit_rate_tolerance;
579 
580     /**
581      * Global quality for codecs which cannot change it per frame.
582      * This should be proportional to MPEG-1/2/4 qscale.
583      * - encoding: Set by user.
584      * - decoding: unused
585      */
586     int global_quality;
587 
588     /**
589      * - encoding: Set by user.
590      * - decoding: unused
591      */
592     int compression_level;
593 
594     /**
595      * AV_CODEC_FLAG_*.
596      * - encoding: Set by user.
597      * - decoding: Set by user.
598      */
599     int flags;
600 
601     /**
602      * AV_CODEC_FLAG2_*
603      * - encoding: Set by user.
604      * - decoding: Set by user.
605      */
606     int flags2;
607 
608     /**
609      * some codecs need / can use extradata like Huffman tables.
610      * MJPEG: Huffman tables
611      * rv10: additional flags
612      * MPEG-4: global headers (they can be in the bitstream or here)
613      * The allocated memory should be AV_INPUT_BUFFER_PADDING_SIZE bytes larger
614      * than extradata_size to avoid problems if it is read with the bitstream reader.
615      * The bytewise contents of extradata must not depend on the architecture or CPU endianness.
616      * Must be allocated with the av_malloc() family of functions.
617      * - encoding: Set/allocated/freed by libavcodec.
618      * - decoding: Set/allocated/freed by user.
619      */
620     ubyte* extradata;
621     int extradata_size;
622 
623     /**
624      * This is the fundamental unit of time (in seconds) in terms
625      * of which frame timestamps are represented. For fixed-fps content,
626      * timebase should be 1/framerate and timestamp increments should be
627      * identically 1.
628      * This often, but not always is the inverse of the frame rate or field rate
629      * for video. 1/time_base is not the average frame rate if the frame rate is not
630      * constant.
631      *
632      * Like containers, elementary streams also can store timestamps, 1/time_base
633      * is the unit in which these timestamps are specified.
634      * As example of such codec time base see ISO/IEC 14496-2:2001(E)
635      * vop_time_increment_resolution and fixed_vop_rate
636      * (fixed_vop_rate == 0 implies that it is different from the framerate)
637      *
638      * - encoding: MUST be set by user.
639      * - decoding: the use of this field for decoding is deprecated.
640      *             Use framerate instead.
641      */
642     AVRational time_base;
643 
644     /**
645      * For some codecs, the time base is closer to the field rate than the frame rate.
646      * Most notably, H.264 and MPEG-2 specify time_base as half of frame duration
647      * if no telecine is used ...
648      *
649      * Set to time_base ticks per frame. Default 1, e.g., H.264/MPEG-2 set it to 2.
650      */
651     int ticks_per_frame;
652 
653     /**
654      * Codec delay.
655      *
656      * Encoding: Number of frames delay there will be from the encoder input to
657      *           the decoder output. (we assume the decoder matches the spec)
658      * Decoding: Number of frames delay in addition to what a standard decoder
659      *           as specified in the spec would produce.
660      *
661      * Video:
662      *   Number of frames the decoded output will be delayed relative to the
663      *   encoded input.
664      *
665      * Audio:
666      *   For encoding, this field is unused (see initial_padding).
667      *
668      *   For decoding, this is the number of samples the decoder needs to
669      *   output before the decoder's output is valid. When seeking, you should
670      *   start decoding this many samples prior to your desired seek point.
671      *
672      * - encoding: Set by libavcodec.
673      * - decoding: Set by libavcodec.
674      */
675     int delay;
676 
677     /* video only */
678     /**
679      * picture width / height.
680      *
681      * @note Those fields may not match the values of the last
682      * AVFrame output by avcodec_decode_video2 due frame
683      * reordering.
684      *
685      * - encoding: MUST be set by user.
686      * - decoding: May be set by the user before opening the decoder if known e.g.
687      *             from the container. Some decoders will require the dimensions
688      *             to be set by the caller. During decoding, the decoder may
689      *             overwrite those values as required while parsing the data.
690      */
691     int width;
692     int height;
693 
694     /**
695      * Bitstream width / height, may be different from width/height e.g. when
696      * the decoded frame is cropped before being output or lowres is enabled.
697      *
698      * @note Those field may not match the value of the last
699      * AVFrame output by avcodec_receive_frame() due frame
700      * reordering.
701      *
702      * - encoding: unused
703      * - decoding: May be set by the user before opening the decoder if known
704      *             e.g. from the container. During decoding, the decoder may
705      *             overwrite those values as required while parsing the data.
706      */
707     int coded_width;
708     int coded_height;
709 
710     /**
711      * the number of pictures in a group of pictures, or 0 for intra_only
712      * - encoding: Set by user.
713      * - decoding: unused
714      */
715     int gop_size;
716 
717     /**
718      * Pixel format, see AV_PIX_FMT_xxx.
719      * May be set by the demuxer if known from headers.
720      * May be overridden by the decoder if it knows better.
721      *
722      * @note This field may not match the value of the last
723      * AVFrame output by avcodec_receive_frame() due frame
724      * reordering.
725      *
726      * - encoding: Set by user.
727      * - decoding: Set by user if known, overridden by libavcodec while
728      *             parsing the data.
729      */
730     AVPixelFormat pix_fmt;
731 
732     /**
733      * If non NULL, 'draw_horiz_band' is called by the libavcodec
734      * decoder to draw a horizontal band. It improves cache usage. Not
735      * all codecs can do that. You must check the codec capabilities
736      * beforehand.
737      * When multithreading is used, it may be called from multiple threads
738      * at the same time; threads might draw different parts of the same AVFrame,
739      * or multiple AVFrames, and there is no guarantee that slices will be drawn
740      * in order.
741      * The function is also used by hardware acceleration APIs.
742      * It is called at least once during frame decoding to pass
743      * the data needed for hardware render.
744      * In that mode instead of pixel data, AVFrame points to
745      * a structure specific to the acceleration API. The application
746      * reads the structure and can change some fields to indicate progress
747      * or mark state.
748      * - encoding: unused
749      * - decoding: Set by user.
750      * @param height the height of the slice
751      * @param y the y position of the slice
752      * @param type 1->top field, 2->bottom field, 3->frame
753      * @param offset offset into the AVFrame.data from which the slice should be read
754      */
755     void function (
756         AVCodecContext* s,
757         const(AVFrame)* src,
758         int[AV_NUM_DATA_POINTERS] offset,
759         int y,
760         int type,
761         int height) draw_horiz_band;
762 
763     /**
764      * callback to negotiate the pixelFormat
765      * @param fmt is the list of formats which are supported by the codec,
766      * it is terminated by -1 as 0 is a valid format, the formats are ordered by quality.
767      * The first is always the native one.
768      * @note The callback may be called again immediately if initialization for
769      * the selected (hardware-accelerated) pixel format failed.
770      * @warning Behavior is undefined if the callback returns a value not
771      * in the fmt list of formats.
772      * @return the chosen format
773      * - encoding: unused
774      * - decoding: Set by user, if not set the native format will be chosen.
775      */
776     AVPixelFormat function (AVCodecContext* s, const(AVPixelFormat)* fmt) get_format;
777 
778     /**
779      * maximum number of B-frames between non-B-frames
780      * Note: The output will be delayed by max_b_frames+1 relative to the input.
781      * - encoding: Set by user.
782      * - decoding: unused
783      */
784     int max_b_frames;
785 
786     /**
787      * qscale factor between IP and B-frames
788      * If > 0 then the last P-frame quantizer will be used (q= lastp_q*factor+offset).
789      * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
790      * - encoding: Set by user.
791      * - decoding: unused
792      */
793     float b_quant_factor;
794 
795     /** @deprecated use encoder private options instead */
796     int b_frame_strategy;
797 
798     /**
799      * qscale offset between IP and B-frames
800      * - encoding: Set by user.
801      * - decoding: unused
802      */
803     float b_quant_offset;
804 
805     /**
806      * Size of the frame reordering buffer in the decoder.
807      * For MPEG-2 it is 1 IPB or 0 low delay IP.
808      * - encoding: Set by libavcodec.
809      * - decoding: Set by libavcodec.
810      */
811     int has_b_frames;
812 
813     /** @deprecated use encoder private options instead */
814     int mpeg_quant;
815 
816     /**
817      * qscale factor between P- and I-frames
818      * If > 0 then the last P-frame quantizer will be used (q = lastp_q * factor + offset).
819      * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset).
820      * - encoding: Set by user.
821      * - decoding: unused
822      */
823     float i_quant_factor;
824 
825     /**
826      * qscale offset between P and I-frames
827      * - encoding: Set by user.
828      * - decoding: unused
829      */
830     float i_quant_offset;
831 
832     /**
833      * luminance masking (0-> disabled)
834      * - encoding: Set by user.
835      * - decoding: unused
836      */
837     float lumi_masking;
838 
839     /**
840      * temporary complexity masking (0-> disabled)
841      * - encoding: Set by user.
842      * - decoding: unused
843      */
844     float temporal_cplx_masking;
845 
846     /**
847      * spatial complexity masking (0-> disabled)
848      * - encoding: Set by user.
849      * - decoding: unused
850      */
851     float spatial_cplx_masking;
852 
853     /**
854      * p block masking (0-> disabled)
855      * - encoding: Set by user.
856      * - decoding: unused
857      */
858     float p_masking;
859 
860     /**
861      * darkness masking (0-> disabled)
862      * - encoding: Set by user.
863      * - decoding: unused
864      */
865     float dark_masking;
866 
867     /**
868      * slice count
869      * - encoding: Set by libavcodec.
870      * - decoding: Set by user (or 0).
871      */
872     int slice_count;
873 
874     /** @deprecated use encoder private options instead */
875     int prediction_method;
876 
877     /**
878      * slice offsets in the frame in bytes
879      * - encoding: Set/allocated by libavcodec.
880      * - decoding: Set/allocated by user (or NULL).
881      */
882     int* slice_offset;
883 
884     /**
885      * sample aspect ratio (0 if unknown)
886      * That is the width of a pixel divided by the height of the pixel.
887      * Numerator and denominator must be relatively prime and smaller than 256 for some video standards.
888      * - encoding: Set by user.
889      * - decoding: Set by libavcodec.
890      */
891     AVRational sample_aspect_ratio;
892 
893     /**
894      * motion estimation comparison function
895      * - encoding: Set by user.
896      * - decoding: unused
897      */
898     int me_cmp;
899     /**
900      * subpixel motion estimation comparison function
901      * - encoding: Set by user.
902      * - decoding: unused
903      */
904     int me_sub_cmp;
905     /**
906      * macroblock comparison function (not supported yet)
907      * - encoding: Set by user.
908      * - decoding: unused
909      */
910     int mb_cmp;
911     /**
912      * interlaced DCT comparison function
913      * - encoding: Set by user.
914      * - decoding: unused
915      */
916     int ildct_cmp;
917 
918     /**
919      * ME diamond size & shape
920      * - encoding: Set by user.
921      * - decoding: unused
922      */
923     int dia_size;
924 
925     /**
926      * amount of previous MV predictors (2a+1 x 2a+1 square)
927      * - encoding: Set by user.
928      * - decoding: unused
929      */
930     int last_predictor_count;
931 
932     /** @deprecated use encoder private options instead */
933     int pre_me;
934 
935     /**
936      * motion estimation prepass comparison function
937      * - encoding: Set by user.
938      * - decoding: unused
939      */
940     int me_pre_cmp;
941 
942     /**
943      * ME prepass diamond size & shape
944      * - encoding: Set by user.
945      * - decoding: unused
946      */
947     int pre_dia_size;
948 
949     /**
950      * subpel ME quality
951      * - encoding: Set by user.
952      * - decoding: unused
953      */
954     int me_subpel_quality;
955 
956     /**
957      * maximum motion estimation search range in subpel units
958      * If 0 then no limit.
959      *
960      * - encoding: Set by user.
961      * - decoding: unused
962      */
963     int me_range;
964 
965     /**
966      * slice flags
967      * - encoding: unused
968      * - decoding: Set by user.
969      */
970     int slice_flags;
971     ///< draw_horiz_band() is called in coded order instead of display
972     ///< allow draw_horiz_band() with field slices (MPEG-2 field pics)
973     ///< allow draw_horiz_band() with 1 component at a time (SVQ1)
974 
975     /**
976      * macroblock decision mode
977      * - encoding: Set by user.
978      * - decoding: unused
979      */
980     int mb_decision;
981     ///< uses mb_cmp
982     ///< chooses the one which needs the fewest bits
983     ///< rate distortion
984 
985     /**
986      * custom intra quantization matrix
987      * Must be allocated with the av_malloc() family of functions, and will be freed in
988      * avcodec_free_context().
989      * - encoding: Set/allocated by user, freed by libavcodec. Can be NULL.
990      * - decoding: Set/allocated/freed by libavcodec.
991      */
992     ushort* intra_matrix;
993 
994     /**
995      * custom inter quantization matrix
996      * Must be allocated with the av_malloc() family of functions, and will be freed in
997      * avcodec_free_context().
998      * - encoding: Set/allocated by user, freed by libavcodec. Can be NULL.
999      * - decoding: Set/allocated/freed by libavcodec.
1000      */
1001     ushort* inter_matrix;
1002 
1003     /** @deprecated use encoder private options instead */
1004     int scenechange_threshold;
1005 
1006     /** @deprecated use encoder private options instead */
1007     int noise_reduction;
1008 
1009     /**
1010      * precision of the intra DC coefficient - 8
1011      * - encoding: Set by user.
1012      * - decoding: Set by libavcodec
1013      */
1014     int intra_dc_precision;
1015 
1016     /**
1017      * Number of macroblock rows at the top which are skipped.
1018      * - encoding: unused
1019      * - decoding: Set by user.
1020      */
1021     int skip_top;
1022 
1023     /**
1024      * Number of macroblock rows at the bottom which are skipped.
1025      * - encoding: unused
1026      * - decoding: Set by user.
1027      */
1028     int skip_bottom;
1029 
1030     /**
1031      * minimum MB Lagrange multiplier
1032      * - encoding: Set by user.
1033      * - decoding: unused
1034      */
1035     int mb_lmin;
1036 
1037     /**
1038      * maximum MB Lagrange multiplier
1039      * - encoding: Set by user.
1040      * - decoding: unused
1041      */
1042     int mb_lmax;
1043 
1044     /**
1045      * @deprecated use encoder private options instead
1046      */
1047     int me_penalty_compensation;
1048 
1049     /**
1050      * - encoding: Set by user.
1051      * - decoding: unused
1052      */
1053     int bidir_refine;
1054 
1055     /** @deprecated use encoder private options instead */
1056     int brd_scale;
1057 
1058     /**
1059      * minimum GOP size
1060      * - encoding: Set by user.
1061      * - decoding: unused
1062      */
1063     int keyint_min;
1064 
1065     /**
1066      * number of reference frames
1067      * - encoding: Set by user.
1068      * - decoding: Set by lavc.
1069      */
1070     int refs;
1071 
1072     /** @deprecated use encoder private options instead */
1073     int chromaoffset;
1074 
1075     /**
1076      * Note: Value depends upon the compare function used for fullpel ME.
1077      * - encoding: Set by user.
1078      * - decoding: unused
1079      */
1080     int mv0_threshold;
1081 
1082     /** @deprecated use encoder private options instead */
1083     int b_sensitivity;
1084 
1085     /**
1086      * Chromaticity coordinates of the source primaries.
1087      * - encoding: Set by user
1088      * - decoding: Set by libavcodec
1089      */
1090     AVColorPrimaries color_primaries;
1091 
1092     /**
1093      * Color Transfer Characteristic.
1094      * - encoding: Set by user
1095      * - decoding: Set by libavcodec
1096      */
1097     AVColorTransferCharacteristic color_trc;
1098 
1099     /**
1100      * YUV colorspace type.
1101      * - encoding: Set by user
1102      * - decoding: Set by libavcodec
1103      */
1104     AVColorSpace colorspace;
1105 
1106     /**
1107      * MPEG vs JPEG YUV range.
1108      * - encoding: Set by user
1109      * - decoding: Set by libavcodec
1110      */
1111     AVColorRange color_range;
1112 
1113     /**
1114      * This defines the location of chroma samples.
1115      * - encoding: Set by user
1116      * - decoding: Set by libavcodec
1117      */
1118     AVChromaLocation chroma_sample_location;
1119 
1120     /**
1121      * Number of slices.
1122      * Indicates number of picture subdivisions. Used for parallelized
1123      * decoding.
1124      * - encoding: Set by user
1125      * - decoding: unused
1126      */
1127     int slices;
1128 
1129     /** Field order
1130      * - encoding: set by libavcodec
1131      * - decoding: Set by user.
1132      */
1133     AVFieldOrder field_order;
1134 
1135     /* audio only */
1136     int sample_rate; ///< samples per second
1137     int channels; ///< number of audio channels
1138 
1139     /**
1140      * audio sample format
1141      * - encoding: Set by user.
1142      * - decoding: Set by libavcodec.
1143      */
1144     AVSampleFormat sample_fmt; ///< sample format
1145 
1146     /* The following data should not be initialized. */
1147     /**
1148      * Number of samples per channel in an audio frame.
1149      *
1150      * - encoding: set by libavcodec in avcodec_open2(). Each submitted frame
1151      *   except the last must contain exactly frame_size samples per channel.
1152      *   May be 0 when the codec has AV_CODEC_CAP_VARIABLE_FRAME_SIZE set, then the
1153      *   frame size is not restricted.
1154      * - decoding: may be set by some decoders to indicate constant frame size
1155      */
1156     int frame_size;
1157 
1158     /**
1159      * Frame counter, set by libavcodec.
1160      *
1161      * - decoding: total number of frames returned from the decoder so far.
1162      * - encoding: total number of frames passed to the encoder so far.
1163      *
1164      *   @note the counter is not incremented if encoding/decoding resulted in
1165      *   an error.
1166      */
1167     int frame_number;
1168 
1169     /**
1170      * number of bytes per packet if constant and known or 0
1171      * Used by some WAV based audio codecs.
1172      */
1173     int block_align;
1174 
1175     /**
1176      * Audio cutoff bandwidth (0 means "automatic")
1177      * - encoding: Set by user.
1178      * - decoding: unused
1179      */
1180     int cutoff;
1181 
1182     /**
1183      * Audio channel layout.
1184      * - encoding: set by user.
1185      * - decoding: set by user, may be overwritten by libavcodec.
1186      */
1187     ulong channel_layout;
1188 
1189     /**
1190      * Request decoder to use this channel layout if it can (0 for default)
1191      * - encoding: unused
1192      * - decoding: Set by user.
1193      */
1194     ulong request_channel_layout;
1195 
1196     /**
1197      * Type of service that the audio stream conveys.
1198      * - encoding: Set by user.
1199      * - decoding: Set by libavcodec.
1200      */
1201     AVAudioServiceType audio_service_type;
1202 
1203     /**
1204      * desired sample format
1205      * - encoding: Not used.
1206      * - decoding: Set by user.
1207      * Decoder will decode to this format if it can.
1208      */
1209     AVSampleFormat request_sample_fmt;
1210 
1211     /**
1212      * This callback is called at the beginning of each frame to get data
1213      * buffer(s) for it. There may be one contiguous buffer for all the data or
1214      * there may be a buffer per each data plane or anything in between. What
1215      * this means is, you may set however many entries in buf[] you feel necessary.
1216      * Each buffer must be reference-counted using the AVBuffer API (see description
1217      * of buf[] below).
1218      *
1219      * The following fields will be set in the frame before this callback is
1220      * called:
1221      * - format
1222      * - width, height (video only)
1223      * - sample_rate, channel_layout, nb_samples (audio only)
1224      * Their values may differ from the corresponding values in
1225      * AVCodecContext. This callback must use the frame values, not the codec
1226      * context values, to calculate the required buffer size.
1227      *
1228      * This callback must fill the following fields in the frame:
1229      * - data[]
1230      * - linesize[]
1231      * - extended_data:
1232      *   * if the data is planar audio with more than 8 channels, then this
1233      *     callback must allocate and fill extended_data to contain all pointers
1234      *     to all data planes. data[] must hold as many pointers as it can.
1235      *     extended_data must be allocated with av_malloc() and will be freed in
1236      *     av_frame_unref().
1237      *   * otherwise extended_data must point to data
1238      * - buf[] must contain one or more pointers to AVBufferRef structures. Each of
1239      *   the frame's data and extended_data pointers must be contained in these. That
1240      *   is, one AVBufferRef for each allocated chunk of memory, not necessarily one
1241      *   AVBufferRef per data[] entry. See: av_buffer_create(), av_buffer_alloc(),
1242      *   and av_buffer_ref().
1243      * - extended_buf and nb_extended_buf must be allocated with av_malloc() by
1244      *   this callback and filled with the extra buffers if there are more
1245      *   buffers than buf[] can hold. extended_buf will be freed in
1246      *   av_frame_unref().
1247      *
1248      * If AV_CODEC_CAP_DR1 is not set then get_buffer2() must call
1249      * avcodec_default_get_buffer2() instead of providing buffers allocated by
1250      * some other means.
1251      *
1252      * Each data plane must be aligned to the maximum required by the target
1253      * CPU.
1254      *
1255      * @see avcodec_default_get_buffer2()
1256      *
1257      * Video:
1258      *
1259      * If AV_GET_BUFFER_FLAG_REF is set in flags then the frame may be reused
1260      * (read and/or written to if it is writable) later by libavcodec.
1261      *
1262      * avcodec_align_dimensions2() should be used to find the required width and
1263      * height, as they normally need to be rounded up to the next multiple of 16.
1264      *
1265      * Some decoders do not support linesizes changing between frames.
1266      *
1267      * If frame multithreading is used, this callback may be called from a
1268      * different thread, but not from more than one at once. Does not need to be
1269      * reentrant.
1270      *
1271      * @see avcodec_align_dimensions2()
1272      *
1273      * Audio:
1274      *
1275      * Decoders request a buffer of a particular size by setting
1276      * AVFrame.nb_samples prior to calling get_buffer2(). The decoder may,
1277      * however, utilize only part of the buffer by setting AVFrame.nb_samples
1278      * to a smaller value in the output frame.
1279      *
1280      * As a convenience, av_samples_get_buffer_size() and
1281      * av_samples_fill_arrays() in libavutil may be used by custom get_buffer2()
1282      * functions to find the required data size and to fill data pointers and
1283      * linesize. In AVFrame.linesize, only linesize[0] may be set for audio
1284      * since all planes must be the same size.
1285      *
1286      * @see av_samples_get_buffer_size(), av_samples_fill_arrays()
1287      *
1288      * - encoding: unused
1289      * - decoding: Set by libavcodec, user can override.
1290      */
1291     int function (AVCodecContext* s, AVFrame* frame, int flags) get_buffer2;
1292 
1293     /**
1294      * If non-zero, the decoded audio and video frames returned from
1295      * avcodec_decode_video2() and avcodec_decode_audio4() are reference-counted
1296      * and are valid indefinitely. The caller must free them with
1297      * av_frame_unref() when they are not needed anymore.
1298      * Otherwise, the decoded frames must not be freed by the caller and are
1299      * only valid until the next decode call.
1300      *
1301      * This is always automatically enabled if avcodec_receive_frame() is used.
1302      *
1303      * - encoding: unused
1304      * - decoding: set by the caller before avcodec_open2().
1305      */
1306     int refcounted_frames;
1307 
1308     /* - encoding parameters */
1309     float qcompress; ///< amount of qscale change between easy & hard scenes (0.0-1.0)
1310     float qblur; ///< amount of qscale smoothing over time (0.0-1.0)
1311 
1312     /**
1313      * minimum quantizer
1314      * - encoding: Set by user.
1315      * - decoding: unused
1316      */
1317     int qmin;
1318 
1319     /**
1320      * maximum quantizer
1321      * - encoding: Set by user.
1322      * - decoding: unused
1323      */
1324     int qmax;
1325 
1326     /**
1327      * maximum quantizer difference between frames
1328      * - encoding: Set by user.
1329      * - decoding: unused
1330      */
1331     int max_qdiff;
1332 
1333     /**
1334      * decoder bitstream buffer size
1335      * - encoding: Set by user.
1336      * - decoding: unused
1337      */
1338     int rc_buffer_size;
1339 
1340     /**
1341      * ratecontrol override, see RcOverride
1342      * - encoding: Allocated/set/freed by user.
1343      * - decoding: unused
1344      */
1345     int rc_override_count;
1346     RcOverride* rc_override;
1347 
1348     /**
1349      * maximum bitrate
1350      * - encoding: Set by user.
1351      * - decoding: Set by user, may be overwritten by libavcodec.
1352      */
1353     long rc_max_rate;
1354 
1355     /**
1356      * minimum bitrate
1357      * - encoding: Set by user.
1358      * - decoding: unused
1359      */
1360     long rc_min_rate;
1361 
1362     /**
1363      * Ratecontrol attempt to use, at maximum, <value> of what can be used without an underflow.
1364      * - encoding: Set by user.
1365      * - decoding: unused.
1366      */
1367     float rc_max_available_vbv_use;
1368 
1369     /**
1370      * Ratecontrol attempt to use, at least, <value> times the amount needed to prevent a vbv overflow.
1371      * - encoding: Set by user.
1372      * - decoding: unused.
1373      */
1374     float rc_min_vbv_overflow_use;
1375 
1376     /**
1377      * Number of bits which should be loaded into the rc buffer before decoding starts.
1378      * - encoding: Set by user.
1379      * - decoding: unused
1380      */
1381     int rc_initial_buffer_occupancy;
1382 
1383     /**
1384      * @deprecated use encoder private options instead
1385      */
1386     int coder_type;
1387     /* FF_API_CODER_TYPE */
1388 
1389     /** @deprecated use encoder private options instead */
1390     int context_model;
1391 
1392     /** @deprecated use encoder private options instead */
1393     int frame_skip_threshold;
1394 
1395     /** @deprecated use encoder private options instead */
1396     int frame_skip_factor;
1397 
1398     /** @deprecated use encoder private options instead */
1399     int frame_skip_exp;
1400 
1401     /** @deprecated use encoder private options instead */
1402     int frame_skip_cmp;
1403     /* FF_API_PRIVATE_OPT */
1404 
1405     /**
1406      * trellis RD quantization
1407      * - encoding: Set by user.
1408      * - decoding: unused
1409      */
1410     int trellis;
1411 
1412     /** @deprecated use encoder private options instead */
1413     int min_prediction_order;
1414 
1415     /** @deprecated use encoder private options instead */
1416     int max_prediction_order;
1417 
1418     /** @deprecated use encoder private options instead */
1419     long timecode_frame_start;
1420 
1421     /**
1422      * @deprecated unused
1423      */
1424     /* The RTP callback: This function is called    */
1425     /* every time the encoder has a packet to send. */
1426     /* It depends on the encoder if the data starts */
1427     /* with a Start Code (it should). H.263 does.   */
1428     /* mb_nb contains the number of macroblocks     */
1429     /* encoded in the RTP payload.                  */
1430     void function (
1431         AVCodecContext* avctx,
1432         void* data,
1433         int size,
1434         int mb_nb) rtp_callback;
1435 
1436     /** @deprecated use encoder private options instead */
1437     int rtp_payload_size; /* The size of the RTP payload: the coder will  */
1438     /* do its best to deliver a chunk with size     */
1439     /* below rtp_payload_size, the chunk will start */
1440     /* with a start code on some codecs like H.263. */
1441     /* This doesn't take account of any particular  */
1442     /* headers inside the transmitted RTP payload.  */
1443 
1444     /* statistics, used for 2-pass encoding */
1445     int mv_bits;
1446     int header_bits;
1447     int i_tex_bits;
1448     int p_tex_bits;
1449     int i_count;
1450     int p_count;
1451     int skip_count;
1452     int misc_bits;
1453 
1454     /** @deprecated this field is unused */
1455     int frame_bits;
1456 
1457     /**
1458      * pass1 encoding statistics output buffer
1459      * - encoding: Set by libavcodec.
1460      * - decoding: unused
1461      */
1462     char* stats_out;
1463 
1464     /**
1465      * pass2 encoding statistics input buffer
1466      * Concatenated stuff from stats_out of pass1 should be placed here.
1467      * - encoding: Allocated/set/freed by user.
1468      * - decoding: unused
1469      */
1470     char* stats_in;
1471 
1472     /**
1473      * Work around bugs in encoders which sometimes cannot be detected automatically.
1474      * - encoding: Set by user
1475      * - decoding: Set by user
1476      */
1477     int workaround_bugs;
1478     ///< autodetection
1479 
1480     ///< Work around various bugs in Microsoft's broken decoders.
1481 
1482     /**
1483      * strictly follow the standard (MPEG-4, ...).
1484      * - encoding: Set by user.
1485      * - decoding: Set by user.
1486      * Setting this to STRICT or higher means the encoder and decoder will
1487      * generally do stupid things, whereas setting it to unofficial or lower
1488      * will mean the encoder might produce output that is not supported by all
1489      * spec-compliant decoders. Decoders don't differentiate between normal,
1490      * unofficial and experimental (that is, they always try to decode things
1491      * when they can) unless they are explicitly asked to behave stupidly
1492      * (=strictly conform to the specs)
1493      */
1494     int strict_std_compliance;
1495     ///< Strictly conform to an older more strict version of the spec or reference software.
1496     ///< Strictly conform to all the things in the spec no matter what consequences.
1497 
1498     ///< Allow unofficial extensions
1499     ///< Allow nonstandardized experimental things.
1500 
1501     /**
1502      * error concealment flags
1503      * - encoding: unused
1504      * - decoding: Set by user.
1505      */
1506     int error_concealment;
1507 
1508     /**
1509      * debug
1510      * - encoding: Set by user.
1511      * - decoding: Set by user.
1512      */
1513     int debug_;
1514 
1515     /**
1516      * Error recognition; may misdetect some more or less valid parts as errors.
1517      * - encoding: Set by user.
1518      * - decoding: Set by user.
1519      */
1520     int err_recognition;
1521 
1522     /**
1523      * Verify checksums embedded in the bitstream (could be of either encoded or
1524      * decoded data, depending on the codec) and print an error message on mismatch.
1525      * If AV_EF_EXPLODE is also set, a mismatching checksum will result in the
1526      * decoder returning an error.
1527      */
1528 
1529     ///< detect bitstream specification deviations
1530     ///< detect improper bitstream length
1531     ///< abort decoding on minor error detection
1532 
1533     ///< ignore errors and continue
1534     ///< consider things that violate the spec, are fast to calculate and have not been seen in the wild as errors
1535     ///< consider all spec non compliances as errors
1536     ///< consider things that a sane encoder should not do as an error
1537 
1538     /**
1539      * opaque 64-bit number (generally a PTS) that will be reordered and
1540      * output in AVFrame.reordered_opaque
1541      * - encoding: Set by libavcodec to the reordered_opaque of the input
1542      *             frame corresponding to the last returned packet. Only
1543      *             supported by encoders with the
1544      *             AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE capability.
1545      * - decoding: Set by user.
1546      */
1547     long reordered_opaque;
1548 
1549     /**
1550      * Hardware accelerator in use
1551      * - encoding: unused.
1552      * - decoding: Set by libavcodec
1553      */
1554     const(AVHWAccel)* hwaccel;
1555 
1556     /**
1557      * Hardware accelerator context.
1558      * For some hardware accelerators, a global context needs to be
1559      * provided by the user. In that case, this holds display-dependent
1560      * data FFmpeg cannot instantiate itself. Please refer to the
1561      * FFmpeg HW accelerator documentation to know how to fill this
1562      * is. e.g. for VA API, this is a struct vaapi_context.
1563      * - encoding: unused
1564      * - decoding: Set by user
1565      */
1566     void* hwaccel_context;
1567 
1568     /**
1569      * error
1570      * - encoding: Set by libavcodec if flags & AV_CODEC_FLAG_PSNR.
1571      * - decoding: unused
1572      */
1573     ulong[AV_NUM_DATA_POINTERS] error;
1574 
1575     /**
1576      * DCT algorithm, see FF_DCT_* below
1577      * - encoding: Set by user.
1578      * - decoding: unused
1579      */
1580     int dct_algo;
1581 
1582     /**
1583      * IDCT algorithm, see FF_IDCT_* below.
1584      * - encoding: Set by user.
1585      * - decoding: Set by user.
1586      */
1587     int idct_algo;
1588 
1589     /* Used by XvMC to extract IDCT coefficients with FF_IDCT_PERM_NONE */
1590 
1591     /**
1592      * bits per sample/pixel from the demuxer (needed for huffyuv).
1593      * - encoding: Set by libavcodec.
1594      * - decoding: Set by user.
1595      */
1596     int bits_per_coded_sample;
1597 
1598     /**
1599      * Bits per sample/pixel of internal libavcodec pixel/sample format.
1600      * - encoding: set by user.
1601      * - decoding: set by libavcodec.
1602      */
1603     int bits_per_raw_sample;
1604 
1605     /**
1606      * low resolution decoding, 1-> 1/2 size, 2->1/4 size
1607      * - encoding: unused
1608      * - decoding: Set by user.
1609      */
1610     int lowres;
1611 
1612     /**
1613      * the picture in the bitstream
1614      * - encoding: Set by libavcodec.
1615      * - decoding: unused
1616      *
1617      * @deprecated use the quality factor packet side data instead
1618      */
1619     AVFrame* coded_frame;
1620 
1621     /**
1622      * thread count
1623      * is used to decide how many independent tasks should be passed to execute()
1624      * - encoding: Set by user.
1625      * - decoding: Set by user.
1626      */
1627     int thread_count;
1628 
1629     /**
1630      * Which multithreading methods to use.
1631      * Use of FF_THREAD_FRAME will increase decoding delay by one frame per thread,
1632      * so clients which cannot provide future frames should not use it.
1633      *
1634      * - encoding: Set by user, otherwise the default is used.
1635      * - decoding: Set by user, otherwise the default is used.
1636      */
1637     int thread_type;
1638     ///< Decode more than one frame at once
1639     ///< Decode more than one part of a single frame at once
1640 
1641     /**
1642      * Which multithreading methods are in use by the codec.
1643      * - encoding: Set by libavcodec.
1644      * - decoding: Set by libavcodec.
1645      */
1646     int active_thread_type;
1647 
1648     /**
1649      * Set by the client if its custom get_buffer() callback can be called
1650      * synchronously from another thread, which allows faster multithreaded decoding.
1651      * draw_horiz_band() will be called from other threads regardless of this setting.
1652      * Ignored if the default get_buffer() is used.
1653      * - encoding: Set by user.
1654      * - decoding: Set by user.
1655      *
1656      * @deprecated the custom get_buffer2() callback should always be
1657      *   thread-safe. Thread-unsafe get_buffer2() implementations will be
1658      *   invalid starting with LIBAVCODEC_VERSION_MAJOR=60; in other words,
1659      *   libavcodec will behave as if this field was always set to 1.
1660      *   Callers that want to be forward compatible with future libavcodec
1661      *   versions should wrap access to this field in
1662      *     #if LIBAVCODEC_VERSION_MAJOR < 60
1663      */
1664     int thread_safe_callbacks;
1665 
1666     /**
1667      * The codec may call this to execute several independent things.
1668      * It will return only after finishing all tasks.
1669      * The user may replace this with some multithreaded implementation,
1670      * the default implementation will execute the parts serially.
1671      * @param count the number of things to execute
1672      * - encoding: Set by libavcodec, user can override.
1673      * - decoding: Set by libavcodec, user can override.
1674      */
1675     int function (AVCodecContext* c, int function (AVCodecContext* c2, void* arg) func, void* arg2, int* ret, int count, int size) execute;
1676 
1677     /**
1678      * The codec may call this to execute several independent things.
1679      * It will return only after finishing all tasks.
1680      * The user may replace this with some multithreaded implementation,
1681      * the default implementation will execute the parts serially.
1682      * Also see avcodec_thread_init and e.g. the --enable-pthread configure option.
1683      * @param c context passed also to func
1684      * @param count the number of things to execute
1685      * @param arg2 argument passed unchanged to func
1686      * @param ret return values of executed functions, must have space for "count" values. May be NULL.
1687      * @param func function that will be called count times, with jobnr from 0 to count-1.
1688      *             threadnr will be in the range 0 to c->thread_count-1 < MAX_THREADS and so that no
1689      *             two instances of func executing at the same time will have the same threadnr.
1690      * @return always 0 currently, but code should handle a future improvement where when any call to func
1691      *         returns < 0 no further calls to func may be done and < 0 is returned.
1692      * - encoding: Set by libavcodec, user can override.
1693      * - decoding: Set by libavcodec, user can override.
1694      */
1695     int function (AVCodecContext* c, int function (AVCodecContext* c2, void* arg, int jobnr, int threadnr) func, void* arg2, int* ret, int count) execute2;
1696 
1697     /**
1698      * noise vs. sse weight for the nsse comparison function
1699      * - encoding: Set by user.
1700      * - decoding: unused
1701      */
1702     int nsse_weight;
1703 
1704     /**
1705      * profile
1706      * - encoding: Set by user.
1707      * - decoding: Set by libavcodec.
1708      */
1709     int profile;
1710 
1711     // 8+1; constraint_set1_flag
1712     // 8+3; constraint_set3_flag
1713 
1714     /**
1715      * level
1716      * - encoding: Set by user.
1717      * - decoding: Set by libavcodec.
1718      */
1719     int level;
1720 
1721     /**
1722      * Skip loop filtering for selected frames.
1723      * - encoding: unused
1724      * - decoding: Set by user.
1725      */
1726     AVDiscard skip_loop_filter;
1727 
1728     /**
1729      * Skip IDCT/dequantization for selected frames.
1730      * - encoding: unused
1731      * - decoding: Set by user.
1732      */
1733     AVDiscard skip_idct;
1734 
1735     /**
1736      * Skip decoding for selected frames.
1737      * - encoding: unused
1738      * - decoding: Set by user.
1739      */
1740     AVDiscard skip_frame;
1741 
1742     /**
1743      * Header containing style information for text subtitles.
1744      * For SUBTITLE_ASS subtitle type, it should contain the whole ASS
1745      * [Script Info] and [V4+ Styles] section, plus the [Events] line and
1746      * the Format line following. It shouldn't include any Dialogue line.
1747      * - encoding: Set/allocated/freed by user (before avcodec_open2())
1748      * - decoding: Set/allocated/freed by libavcodec (by avcodec_open2())
1749      */
1750     ubyte* subtitle_header;
1751     int subtitle_header_size;
1752 
1753     /**
1754      * VBV delay coded in the last frame (in periods of a 27 MHz clock).
1755      * Used for compliant TS muxing.
1756      * - encoding: Set by libavcodec.
1757      * - decoding: unused.
1758      * @deprecated this value is now exported as a part of
1759      * AV_PKT_DATA_CPB_PROPERTIES packet side data
1760      */
1761     ulong vbv_delay;
1762 
1763     /**
1764      * Encoding only and set by default. Allow encoders to output packets
1765      * that do not contain any encoded data, only side data.
1766      *
1767      * Some encoders need to output such packets, e.g. to update some stream
1768      * parameters at the end of encoding.
1769      *
1770      * @deprecated this field disables the default behaviour and
1771      *             it is kept only for compatibility.
1772      */
1773     int side_data_only_packets;
1774 
1775     /**
1776      * Audio only. The number of "priming" samples (padding) inserted by the
1777      * encoder at the beginning of the audio. I.e. this number of leading
1778      * decoded samples must be discarded by the caller to get the original audio
1779      * without leading padding.
1780      *
1781      * - decoding: unused
1782      * - encoding: Set by libavcodec. The timestamps on the output packets are
1783      *             adjusted by the encoder so that they always refer to the
1784      *             first sample of the data actually contained in the packet,
1785      *             including any added padding.  E.g. if the timebase is
1786      *             1/samplerate and the timestamp of the first input sample is
1787      *             0, the timestamp of the first output packet will be
1788      *             -initial_padding.
1789      */
1790     int initial_padding;
1791 
1792     /**
1793      * - decoding: For codecs that store a framerate value in the compressed
1794      *             bitstream, the decoder may export it here. { 0, 1} when
1795      *             unknown.
1796      * - encoding: May be used to signal the framerate of CFR content to an
1797      *             encoder.
1798      */
1799     AVRational framerate;
1800 
1801     /**
1802      * Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
1803      * - encoding: unused.
1804      * - decoding: Set by libavcodec before calling get_format()
1805      */
1806     AVPixelFormat sw_pix_fmt;
1807 
1808     /**
1809      * Timebase in which pkt_dts/pts and AVPacket.dts/pts are.
1810      * - encoding unused.
1811      * - decoding set by user.
1812      */
1813     AVRational pkt_timebase;
1814 
1815     /**
1816      * AVCodecDescriptor
1817      * - encoding: unused.
1818      * - decoding: set by libavcodec.
1819      */
1820     const(AVCodecDescriptor)* codec_descriptor;
1821 
1822     /**
1823      * Current statistics for PTS correction.
1824      * - decoding: maintained and used by libavcodec, not intended to be used by user apps
1825      * - encoding: unused
1826      */
1827     long pts_correction_num_faulty_pts; /// Number of incorrect PTS values so far
1828     long pts_correction_num_faulty_dts; /// Number of incorrect DTS values so far
1829     long pts_correction_last_pts; /// PTS of the last frame
1830     long pts_correction_last_dts; /// DTS of the last frame
1831 
1832     /**
1833      * Character encoding of the input subtitles file.
1834      * - decoding: set by user
1835      * - encoding: unused
1836      */
1837     char* sub_charenc;
1838 
1839     /**
1840      * Subtitles character encoding mode. Formats or codecs might be adjusting
1841      * this setting (if they are doing the conversion themselves for instance).
1842      * - decoding: set by libavcodec
1843      * - encoding: unused
1844      */
1845     int sub_charenc_mode;
1846     ///< do nothing (demuxer outputs a stream supposed to be already in UTF-8, or the codec is bitmap for instance)
1847     ///< libavcodec will select the mode itself
1848     ///< the AVPacket data needs to be recoded to UTF-8 before being fed to the decoder, requires iconv
1849     ///< neither convert the subtitles, nor check them for valid UTF-8
1850 
1851     /**
1852      * Skip processing alpha if supported by codec.
1853      * Note that if the format uses pre-multiplied alpha (common with VP6,
1854      * and recommended due to better video quality/compression)
1855      * the image will look as if alpha-blended onto a black background.
1856      * However for formats that do not use pre-multiplied alpha
1857      * there might be serious artefacts (though e.g. libswscale currently
1858      * assumes pre-multiplied alpha anyway).
1859      *
1860      * - decoding: set by user
1861      * - encoding: unused
1862      */
1863     int skip_alpha;
1864 
1865     /**
1866      * Number of samples to skip after a discontinuity
1867      * - decoding: unused
1868      * - encoding: set by libavcodec
1869      */
1870     int seek_preroll;
1871 
1872     /**
1873      * @deprecated unused
1874      */
1875     int debug_mv;
1876     //visualize forward predicted MVs of P frames
1877     //visualize forward predicted MVs of B frames
1878     //visualize backward predicted MVs of B frames
1879 
1880     /**
1881      * custom intra quantization matrix
1882      * - encoding: Set by user, can be NULL.
1883      * - decoding: unused.
1884      */
1885     ushort* chroma_intra_matrix;
1886 
1887     /**
1888      * dump format separator.
1889      * can be ", " or "\n      " or anything else
1890      * - encoding: Set by user.
1891      * - decoding: Set by user.
1892      */
1893     ubyte* dump_separator;
1894 
1895     /**
1896      * ',' separated list of allowed decoders.
1897      * If NULL then all are allowed
1898      * - encoding: unused
1899      * - decoding: set by user
1900      */
1901     char* codec_whitelist;
1902 
1903     /**
1904      * Properties of the stream that gets decoded
1905      * - encoding: unused
1906      * - decoding: set by libavcodec
1907      */
1908     uint properties;
1909 
1910     /**
1911      * Additional data associated with the entire coded stream.
1912      *
1913      * - decoding: unused
1914      * - encoding: may be set by libavcodec after avcodec_open2().
1915      */
1916     AVPacketSideData* coded_side_data;
1917     int nb_coded_side_data;
1918 
1919     /**
1920      * A reference to the AVHWFramesContext describing the input (for encoding)
1921      * or output (decoding) frames. The reference is set by the caller and
1922      * afterwards owned (and freed) by libavcodec - it should never be read by
1923      * the caller after being set.
1924      *
1925      * - decoding: This field should be set by the caller from the get_format()
1926      *             callback. The previous reference (if any) will always be
1927      *             unreffed by libavcodec before the get_format() call.
1928      *
1929      *             If the default get_buffer2() is used with a hwaccel pixel
1930      *             format, then this AVHWFramesContext will be used for
1931      *             allocating the frame buffers.
1932      *
1933      * - encoding: For hardware encoders configured to use a hwaccel pixel
1934      *             format, this field should be set by the caller to a reference
1935      *             to the AVHWFramesContext describing input frames.
1936      *             AVHWFramesContext.format must be equal to
1937      *             AVCodecContext.pix_fmt.
1938      *
1939      *             This field should be set before avcodec_open2() is called.
1940      */
1941     AVBufferRef* hw_frames_ctx;
1942 
1943     /**
1944      * Control the form of AVSubtitle.rects[N]->ass
1945      * - decoding: set by user
1946      * - encoding: unused
1947      */
1948     int sub_text_format;
1949 
1950     /**
1951      * Audio only. The amount of padding (in samples) appended by the encoder to
1952      * the end of the audio. I.e. this number of decoded samples must be
1953      * discarded by the caller from the end of the stream to get the original
1954      * audio without any trailing padding.
1955      *
1956      * - decoding: unused
1957      * - encoding: unused
1958      */
1959     int trailing_padding;
1960 
1961     /**
1962      * The number of pixels per image to maximally accept.
1963      *
1964      * - decoding: set by user
1965      * - encoding: set by user
1966      */
1967     long max_pixels;
1968 
1969     /**
1970      * A reference to the AVHWDeviceContext describing the device which will
1971      * be used by a hardware encoder/decoder.  The reference is set by the
1972      * caller and afterwards owned (and freed) by libavcodec.
1973      *
1974      * This should be used if either the codec device does not require
1975      * hardware frames or any that are used are to be allocated internally by
1976      * libavcodec.  If the user wishes to supply any of the frames used as
1977      * encoder input or decoder output then hw_frames_ctx should be used
1978      * instead.  When hw_frames_ctx is set in get_format() for a decoder, this
1979      * field will be ignored while decoding the associated stream segment, but
1980      * may again be used on a following one after another get_format() call.
1981      *
1982      * For both encoders and decoders this field should be set before
1983      * avcodec_open2() is called and must not be written to thereafter.
1984      *
1985      * Note that some decoders may require this field to be set initially in
1986      * order to support hw_frames_ctx at all - in that case, all frames
1987      * contexts used must be created on the same device.
1988      */
1989     AVBufferRef* hw_device_ctx;
1990 
1991     /**
1992      * Bit set of AV_HWACCEL_FLAG_* flags, which affect hardware accelerated
1993      * decoding (if active).
1994      * - encoding: unused
1995      * - decoding: Set by user (either before avcodec_open2(), or in the
1996      *             AVCodecContext.get_format callback)
1997      */
1998     int hwaccel_flags;
1999 
2000     /**
2001      * Video decoding only. Certain video codecs support cropping, meaning that
2002      * only a sub-rectangle of the decoded frame is intended for display.  This
2003      * option controls how cropping is handled by libavcodec.
2004      *
2005      * When set to 1 (the default), libavcodec will apply cropping internally.
2006      * I.e. it will modify the output frame width/height fields and offset the
2007      * data pointers (only by as much as possible while preserving alignment, or
2008      * by the full amount if the AV_CODEC_FLAG_UNALIGNED flag is set) so that
2009      * the frames output by the decoder refer only to the cropped area. The
2010      * crop_* fields of the output frames will be zero.
2011      *
2012      * When set to 0, the width/height fields of the output frames will be set
2013      * to the coded dimensions and the crop_* fields will describe the cropping
2014      * rectangle. Applying the cropping is left to the caller.
2015      *
2016      * @warning When hardware acceleration with opaque output frames is used,
2017      * libavcodec is unable to apply cropping from the top/left border.
2018      *
2019      * @note when this option is set to zero, the width/height fields of the
2020      * AVCodecContext and output AVFrames have different meanings. The codec
2021      * context fields store display dimensions (with the coded dimensions in
2022      * coded_width/height), while the frame fields store the coded dimensions
2023      * (with the display dimensions being determined by the crop_* fields).
2024      */
2025     int apply_cropping;
2026 
2027     /*
2028      * Video decoding only.  Sets the number of extra hardware frames which
2029      * the decoder will allocate for use by the caller.  This must be set
2030      * before avcodec_open2() is called.
2031      *
2032      * Some hardware decoders require all frames that they will use for
2033      * output to be defined in advance before decoding starts.  For such
2034      * decoders, the hardware frame pool must therefore be of a fixed size.
2035      * The extra frames set here are on top of any number that the decoder
2036      * needs internally in order to operate normally (for example, frames
2037      * used as reference pictures).
2038      */
2039     int extra_hw_frames;
2040 
2041     /**
2042      * The percentage of damaged samples to discard a frame.
2043      *
2044      * - decoding: set by user
2045      * - encoding: unused
2046      */
2047     int discard_damaged_percentage;
2048 
2049     /**
2050      * The number of samples per frame to maximally accept.
2051      *
2052      * - decoding: set by user
2053      * - encoding: set by user
2054      */
2055     long max_samples;
2056 
2057     /**
2058      * Bit set of AV_CODEC_EXPORT_DATA_* flags, which affects the kind of
2059      * metadata exported in frame, packet, or coded stream side data by
2060      * decoders and encoders.
2061      *
2062      * - decoding: set by user
2063      * - encoding: set by user
2064      */
2065     int export_side_data;
2066 
2067     /**
2068      * This callback is called at the beginning of each packet to get a data
2069      * buffer for it.
2070      *
2071      * The following field will be set in the packet before this callback is
2072      * called:
2073      * - size
2074      * This callback must use the above value to calculate the required buffer size,
2075      * which must padded by at least AV_INPUT_BUFFER_PADDING_SIZE bytes.
2076      *
2077      * This callback must fill the following fields in the packet:
2078      * - data: alignment requirements for AVPacket apply, if any. Some architectures and
2079      *   encoders may benefit from having aligned data.
2080      * - buf: must contain a pointer to an AVBufferRef structure. The packet's
2081      *   data pointer must be contained in it. See: av_buffer_create(), av_buffer_alloc(),
2082      *   and av_buffer_ref().
2083      *
2084      * If AV_CODEC_CAP_DR1 is not set then get_encode_buffer() must call
2085      * avcodec_default_get_encode_buffer() instead of providing a buffer allocated by
2086      * some other means.
2087      *
2088      * The flags field may contain a combination of AV_GET_ENCODE_BUFFER_FLAG_ flags.
2089      * They may be used for example to hint what use the buffer may get after being
2090      * created.
2091      * Implementations of this callback may ignore flags they don't understand.
2092      * If AV_GET_ENCODE_BUFFER_FLAG_REF is set in flags then the packet may be reused
2093      * (read and/or written to if it is writable) later by libavcodec.
2094      *
2095      * This callback must be thread-safe, as when frame threading is used, it may
2096      * be called from multiple threads simultaneously.
2097      *
2098      * @see avcodec_default_get_encode_buffer()
2099      *
2100      * - encoding: Set by libavcodec, user can override.
2101      * - decoding: unused
2102      */
2103     int function (AVCodecContext* s, AVPacket* pkt, int flags) get_encode_buffer;
2104 }
2105 
2106 enum FF_COMPRESSION_DEFAULT = -1;
2107 enum FF_PRED_LEFT = 0;
2108 enum FF_PRED_PLANE = 1;
2109 enum FF_PRED_MEDIAN = 2;
2110 enum FF_CMP_SAD = 0;
2111 enum FF_CMP_SSE = 1;
2112 enum FF_CMP_SATD = 2;
2113 enum FF_CMP_DCT = 3;
2114 enum FF_CMP_PSNR = 4;
2115 enum FF_CMP_BIT = 5;
2116 enum FF_CMP_RD = 6;
2117 enum FF_CMP_ZERO = 7;
2118 enum FF_CMP_VSAD = 8;
2119 enum FF_CMP_VSSE = 9;
2120 enum FF_CMP_NSSE = 10;
2121 enum FF_CMP_W53 = 11;
2122 enum FF_CMP_W97 = 12;
2123 enum FF_CMP_DCTMAX = 13;
2124 enum FF_CMP_DCT264 = 14;
2125 enum FF_CMP_MEDIAN_SAD = 15;
2126 enum FF_CMP_CHROMA = 256;
2127 enum SLICE_FLAG_CODED_ORDER = 0x0001;
2128 enum SLICE_FLAG_ALLOW_FIELD = 0x0002;
2129 enum SLICE_FLAG_ALLOW_PLANE = 0x0004;
2130 enum FF_MB_DECISION_SIMPLE = 0;
2131 enum FF_MB_DECISION_BITS = 1;
2132 enum FF_MB_DECISION_RD = 2;
2133 enum FF_CODER_TYPE_VLC = 0;
2134 enum FF_CODER_TYPE_AC = 1;
2135 enum FF_CODER_TYPE_RAW = 2;
2136 enum FF_CODER_TYPE_RLE = 3;
2137 enum FF_BUG_AUTODETECT = 1;
2138 enum FF_BUG_XVID_ILACE = 4;
2139 enum FF_BUG_UMP4 = 8;
2140 enum FF_BUG_NO_PADDING = 16;
2141 enum FF_BUG_AMV = 32;
2142 enum FF_BUG_QPEL_CHROMA = 64;
2143 enum FF_BUG_STD_QPEL = 128;
2144 enum FF_BUG_QPEL_CHROMA2 = 256;
2145 enum FF_BUG_DIRECT_BLOCKSIZE = 512;
2146 enum FF_BUG_EDGE = 1024;
2147 enum FF_BUG_HPEL_CHROMA = 2048;
2148 enum FF_BUG_DC_CLIP = 4096;
2149 enum FF_BUG_MS = 8192;
2150 enum FF_BUG_TRUNCATED = 16384;
2151 enum FF_BUG_IEDGE = 32768;
2152 enum FF_COMPLIANCE_VERY_STRICT = 2;
2153 enum FF_COMPLIANCE_STRICT = 1;
2154 enum FF_COMPLIANCE_NORMAL = 0;
2155 enum FF_COMPLIANCE_UNOFFICIAL = -1;
2156 enum FF_COMPLIANCE_EXPERIMENTAL = -2;
2157 enum FF_EC_GUESS_MVS = 1;
2158 enum FF_EC_DEBLOCK = 2;
2159 enum FF_EC_FAVOR_INTER = 256;
2160 enum FF_DEBUG_PICT_INFO = 1;
2161 enum FF_DEBUG_RC = 2;
2162 enum FF_DEBUG_BITSTREAM = 4;
2163 enum FF_DEBUG_MB_TYPE = 8;
2164 enum FF_DEBUG_QP = 16;
2165 enum FF_DEBUG_DCT_COEFF = 0x00000040;
2166 enum FF_DEBUG_SKIP = 0x00000080;
2167 enum FF_DEBUG_STARTCODE = 0x00000100;
2168 enum FF_DEBUG_ER = 0x00000400;
2169 enum FF_DEBUG_MMCO = 0x00000800;
2170 enum FF_DEBUG_BUGS = 0x00001000;
2171 enum FF_DEBUG_BUFFERS = 0x00008000;
2172 enum FF_DEBUG_THREADS = 0x00010000;
2173 enum FF_DEBUG_GREEN_MD = 0x00800000;
2174 enum FF_DEBUG_NOMC = 0x01000000;
2175 enum AV_EF_CRCCHECK = 1 << 0;
2176 enum AV_EF_BITSTREAM = 1 << 1;
2177 enum AV_EF_BUFFER = 1 << 2;
2178 enum AV_EF_EXPLODE = 1 << 3;
2179 enum AV_EF_IGNORE_ERR = 1 << 15;
2180 enum AV_EF_CAREFUL = 1 << 16;
2181 enum AV_EF_COMPLIANT = 1 << 17;
2182 enum AV_EF_AGGRESSIVE = 1 << 18;
2183 enum FF_DCT_AUTO = 0;
2184 enum FF_DCT_FASTINT = 1;
2185 enum FF_DCT_INT = 2;
2186 enum FF_DCT_MMX = 3;
2187 enum FF_DCT_ALTIVEC = 5;
2188 enum FF_DCT_FAAN = 6;
2189 enum FF_IDCT_AUTO = 0;
2190 enum FF_IDCT_INT = 1;
2191 enum FF_IDCT_SIMPLE = 2;
2192 enum FF_IDCT_SIMPLEMMX = 3;
2193 enum FF_IDCT_ARM = 7;
2194 enum FF_IDCT_ALTIVEC = 8;
2195 enum FF_IDCT_SIMPLEARM = 10;
2196 enum FF_IDCT_XVID = 14;
2197 enum FF_IDCT_SIMPLEARMV5TE = 16;
2198 enum FF_IDCT_SIMPLEARMV6 = 17;
2199 enum FF_IDCT_FAAN = 20;
2200 enum FF_IDCT_SIMPLENEON = 22;
2201 enum FF_IDCT_NONE = 24;
2202 enum FF_IDCT_SIMPLEAUTO = 128;
2203 enum FF_THREAD_FRAME = 1;
2204 enum FF_THREAD_SLICE = 2;
2205 enum FF_PROFILE_UNKNOWN = -99;
2206 enum FF_PROFILE_RESERVED = -100;
2207 enum FF_PROFILE_AAC_MAIN = 0;
2208 enum FF_PROFILE_AAC_LOW = 1;
2209 enum FF_PROFILE_AAC_SSR = 2;
2210 enum FF_PROFILE_AAC_LTP = 3;
2211 enum FF_PROFILE_AAC_HE = 4;
2212 enum FF_PROFILE_AAC_HE_V2 = 28;
2213 enum FF_PROFILE_AAC_LD = 22;
2214 enum FF_PROFILE_AAC_ELD = 38;
2215 enum FF_PROFILE_MPEG2_AAC_LOW = 128;
2216 enum FF_PROFILE_MPEG2_AAC_HE = 131;
2217 enum FF_PROFILE_DNXHD = 0;
2218 enum FF_PROFILE_DNXHR_LB = 1;
2219 enum FF_PROFILE_DNXHR_SQ = 2;
2220 enum FF_PROFILE_DNXHR_HQ = 3;
2221 enum FF_PROFILE_DNXHR_HQX = 4;
2222 enum FF_PROFILE_DNXHR_444 = 5;
2223 enum FF_PROFILE_DTS = 20;
2224 enum FF_PROFILE_DTS_ES = 30;
2225 enum FF_PROFILE_DTS_96_24 = 40;
2226 enum FF_PROFILE_DTS_HD_HRA = 50;
2227 enum FF_PROFILE_DTS_HD_MA = 60;
2228 enum FF_PROFILE_DTS_EXPRESS = 70;
2229 enum FF_PROFILE_MPEG2_422 = 0;
2230 enum FF_PROFILE_MPEG2_HIGH = 1;
2231 enum FF_PROFILE_MPEG2_SS = 2;
2232 enum FF_PROFILE_MPEG2_SNR_SCALABLE = 3;
2233 enum FF_PROFILE_MPEG2_MAIN = 4;
2234 enum FF_PROFILE_MPEG2_SIMPLE = 5;
2235 enum FF_PROFILE_H264_CONSTRAINED = 1 << 9;
2236 enum FF_PROFILE_H264_INTRA = 1 << 11;
2237 enum FF_PROFILE_H264_BASELINE = 66;
2238 enum FF_PROFILE_H264_CONSTRAINED_BASELINE = 66 | FF_PROFILE_H264_CONSTRAINED;
2239 enum FF_PROFILE_H264_MAIN = 77;
2240 enum FF_PROFILE_H264_EXTENDED = 88;
2241 enum FF_PROFILE_H264_HIGH = 100;
2242 enum FF_PROFILE_H264_HIGH_10 = 110;
2243 enum FF_PROFILE_H264_HIGH_10_INTRA = 110 | FF_PROFILE_H264_INTRA;
2244 enum FF_PROFILE_H264_MULTIVIEW_HIGH = 118;
2245 enum FF_PROFILE_H264_HIGH_422 = 122;
2246 enum FF_PROFILE_H264_HIGH_422_INTRA = 122 | FF_PROFILE_H264_INTRA;
2247 enum FF_PROFILE_H264_STEREO_HIGH = 128;
2248 enum FF_PROFILE_H264_HIGH_444 = 144;
2249 enum FF_PROFILE_H264_HIGH_444_PREDICTIVE = 244;
2250 enum FF_PROFILE_H264_HIGH_444_INTRA = 244 | FF_PROFILE_H264_INTRA;
2251 enum FF_PROFILE_H264_CAVLC_444 = 44;
2252 enum FF_PROFILE_VC1_SIMPLE = 0;
2253 enum FF_PROFILE_VC1_MAIN = 1;
2254 enum FF_PROFILE_VC1_COMPLEX = 2;
2255 enum FF_PROFILE_VC1_ADVANCED = 3;
2256 enum FF_PROFILE_MPEG4_SIMPLE = 0;
2257 enum FF_PROFILE_MPEG4_SIMPLE_SCALABLE = 1;
2258 enum FF_PROFILE_MPEG4_CORE = 2;
2259 enum FF_PROFILE_MPEG4_MAIN = 3;
2260 enum FF_PROFILE_MPEG4_N_BIT = 4;
2261 enum FF_PROFILE_MPEG4_SCALABLE_TEXTURE = 5;
2262 enum FF_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION = 6;
2263 enum FF_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE = 7;
2264 enum FF_PROFILE_MPEG4_HYBRID = 8;
2265 enum FF_PROFILE_MPEG4_ADVANCED_REAL_TIME = 9;
2266 enum FF_PROFILE_MPEG4_CORE_SCALABLE = 10;
2267 enum FF_PROFILE_MPEG4_ADVANCED_CODING = 11;
2268 enum FF_PROFILE_MPEG4_ADVANCED_CORE = 12;
2269 enum FF_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE = 13;
2270 enum FF_PROFILE_MPEG4_SIMPLE_STUDIO = 14;
2271 enum FF_PROFILE_MPEG4_ADVANCED_SIMPLE = 15;
2272 enum FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_0 = 1;
2273 enum FF_PROFILE_JPEG2000_CSTREAM_RESTRICTION_1 = 2;
2274 enum FF_PROFILE_JPEG2000_CSTREAM_NO_RESTRICTION = 32768;
2275 enum FF_PROFILE_JPEG2000_DCINEMA_2K = 3;
2276 enum FF_PROFILE_JPEG2000_DCINEMA_4K = 4;
2277 enum FF_PROFILE_VP9_0 = 0;
2278 enum FF_PROFILE_VP9_1 = 1;
2279 enum FF_PROFILE_VP9_2 = 2;
2280 enum FF_PROFILE_VP9_3 = 3;
2281 enum FF_PROFILE_HEVC_MAIN = 1;
2282 enum FF_PROFILE_HEVC_MAIN_10 = 2;
2283 enum FF_PROFILE_HEVC_MAIN_STILL_PICTURE = 3;
2284 enum FF_PROFILE_HEVC_REXT = 4;
2285 enum FF_PROFILE_VVC_MAIN_10 = 1;
2286 enum FF_PROFILE_VVC_MAIN_10_444 = 33;
2287 enum FF_PROFILE_AV1_MAIN = 0;
2288 enum FF_PROFILE_AV1_HIGH = 1;
2289 enum FF_PROFILE_AV1_PROFESSIONAL = 2;
2290 enum FF_PROFILE_MJPEG_HUFFMAN_BASELINE_DCT = 0xc0;
2291 enum FF_PROFILE_MJPEG_HUFFMAN_EXTENDED_SEQUENTIAL_DCT = 0xc1;
2292 enum FF_PROFILE_MJPEG_HUFFMAN_PROGRESSIVE_DCT = 0xc2;
2293 enum FF_PROFILE_MJPEG_HUFFMAN_LOSSLESS = 0xc3;
2294 enum FF_PROFILE_MJPEG_JPEG_LS = 0xf7;
2295 enum FF_PROFILE_SBC_MSBC = 1;
2296 enum FF_PROFILE_PRORES_PROXY = 0;
2297 enum FF_PROFILE_PRORES_LT = 1;
2298 enum FF_PROFILE_PRORES_STANDARD = 2;
2299 enum FF_PROFILE_PRORES_HQ = 3;
2300 enum FF_PROFILE_PRORES_4444 = 4;
2301 enum FF_PROFILE_PRORES_XQ = 5;
2302 enum FF_PROFILE_ARIB_PROFILE_A = 0;
2303 enum FF_PROFILE_ARIB_PROFILE_C = 1;
2304 enum FF_PROFILE_KLVA_SYNC = 0;
2305 enum FF_PROFILE_KLVA_ASYNC = 1;
2306 enum FF_LEVEL_UNKNOWN = -99;
2307 enum FF_SUB_CHARENC_MODE_DO_NOTHING = -1;
2308 enum FF_SUB_CHARENC_MODE_AUTOMATIC = 0;
2309 enum FF_SUB_CHARENC_MODE_PRE_DECODER = 1;
2310 enum FF_SUB_CHARENC_MODE_IGNORE = 2;
2311 enum FF_DEBUG_VIS_MV_P_FOR = 0x00000001;
2312 enum FF_DEBUG_VIS_MV_B_FOR = 0x00000002;
2313 enum FF_DEBUG_VIS_MV_B_BACK = 0x00000004;
2314 enum FF_CODEC_PROPERTY_LOSSLESS = 0x00000001;
2315 enum FF_CODEC_PROPERTY_CLOSED_CAPTIONS = 0x00000002;
2316 enum FF_SUB_TEXT_FMT_ASS = 0;
2317 enum FF_SUB_TEXT_FMT_ASS_WITH_TIMINGS = 1;
2318 
2319 /**
2320  * Accessors for some AVCodecContext fields. These used to be provided for ABI
2321  * compatibility, and do not need to be used anymore.
2322  */
2323 AVRational av_codec_get_pkt_timebase (const(AVCodecContext)* avctx);
2324 void av_codec_set_pkt_timebase (AVCodecContext* avctx, AVRational val);
2325 
2326 const(AVCodecDescriptor)* av_codec_get_codec_descriptor (
2327     const(AVCodecContext)* avctx);
2328 void av_codec_set_codec_descriptor (
2329     AVCodecContext* avctx,
2330     const(AVCodecDescriptor)* desc);
2331 
2332 uint av_codec_get_codec_properties (const(AVCodecContext)* avctx);
2333 
2334 int av_codec_get_lowres (const(AVCodecContext)* avctx);
2335 void av_codec_set_lowres (AVCodecContext* avctx, int val);
2336 
2337 int av_codec_get_seek_preroll (const(AVCodecContext)* avctx);
2338 void av_codec_set_seek_preroll (AVCodecContext* avctx, int val);
2339 
2340 ushort* av_codec_get_chroma_intra_matrix (const(AVCodecContext)* avctx);
2341 void av_codec_set_chroma_intra_matrix (AVCodecContext* avctx, ushort* val);
2342 
2343 int av_codec_get_max_lowres (const(AVCodec)* codec);
2344 
2345 struct MpegEncContext;
2346 
2347 /**
2348  * @defgroup lavc_hwaccel AVHWAccel
2349  *
2350  * @note  Nothing in this structure should be accessed by the user.  At some
2351  *        point in future it will not be externally visible at all.
2352  *
2353  * @{
2354  */
2355 struct AVHWAccel
2356 {
2357     /**
2358      * Name of the hardware accelerated codec.
2359      * The name is globally unique among encoders and among decoders (but an
2360      * encoder and a decoder can share the same name).
2361      */
2362     const(char)* name;
2363 
2364     /**
2365      * Type of codec implemented by the hardware accelerator.
2366      *
2367      * See AVMEDIA_TYPE_xxx
2368      */
2369     AVMediaType type;
2370 
2371     /**
2372      * Codec implemented by the hardware accelerator.
2373      *
2374      * See AV_CODEC_ID_xxx
2375      */
2376     AVCodecID id;
2377 
2378     /**
2379      * Supported pixel format.
2380      *
2381      * Only hardware accelerated formats are supported here.
2382      */
2383     AVPixelFormat pix_fmt;
2384 
2385     /**
2386      * Hardware accelerated codec capabilities.
2387      * see AV_HWACCEL_CODEC_CAP_*
2388      */
2389     int capabilities;
2390 
2391     /*****************************************************************
2392      * No fields below this line are part of the public API. They
2393      * may not be used outside of libavcodec and can be changed and
2394      * removed at will.
2395      * New public fields should be added right above.
2396      *****************************************************************
2397      */
2398 
2399     /**
2400      * Allocate a custom buffer
2401      */
2402     int function (AVCodecContext* avctx, AVFrame* frame) alloc_frame;
2403 
2404     /**
2405      * Called at the beginning of each frame or field picture.
2406      *
2407      * Meaningful frame information (codec specific) is guaranteed to
2408      * be parsed at this point. This function is mandatory.
2409      *
2410      * Note that buf can be NULL along with buf_size set to 0.
2411      * Otherwise, this means the whole frame is available at this point.
2412      *
2413      * @param avctx the codec context
2414      * @param buf the frame data buffer base
2415      * @param buf_size the size of the frame in bytes
2416      * @return zero if successful, a negative value otherwise
2417      */
2418     int function (AVCodecContext* avctx, const(ubyte)* buf, uint buf_size) start_frame;
2419 
2420     /**
2421      * Callback for parameter data (SPS/PPS/VPS etc).
2422      *
2423      * Useful for hardware decoders which keep persistent state about the
2424      * video parameters, and need to receive any changes to update that state.
2425      *
2426      * @param avctx the codec context
2427      * @param type the nal unit type
2428      * @param buf the nal unit data buffer
2429      * @param buf_size the size of the nal unit in bytes
2430      * @return zero if successful, a negative value otherwise
2431      */
2432     int function (AVCodecContext* avctx, int type, const(ubyte)* buf, uint buf_size) decode_params;
2433 
2434     /**
2435      * Callback for each slice.
2436      *
2437      * Meaningful slice information (codec specific) is guaranteed to
2438      * be parsed at this point. This function is mandatory.
2439      * The only exception is XvMC, that works on MB level.
2440      *
2441      * @param avctx the codec context
2442      * @param buf the slice data buffer base
2443      * @param buf_size the size of the slice in bytes
2444      * @return zero if successful, a negative value otherwise
2445      */
2446     int function (AVCodecContext* avctx, const(ubyte)* buf, uint buf_size) decode_slice;
2447 
2448     /**
2449      * Called at the end of each frame or field picture.
2450      *
2451      * The whole picture is parsed at this point and can now be sent
2452      * to the hardware accelerator. This function is mandatory.
2453      *
2454      * @param avctx the codec context
2455      * @return zero if successful, a negative value otherwise
2456      */
2457     int function (AVCodecContext* avctx) end_frame;
2458 
2459     /**
2460      * Size of per-frame hardware accelerator private data.
2461      *
2462      * Private data is allocated with av_mallocz() before
2463      * AVCodecContext.get_buffer() and deallocated after
2464      * AVCodecContext.release_buffer().
2465      */
2466     int frame_priv_data_size;
2467 
2468     /**
2469      * Called for every Macroblock in a slice.
2470      *
2471      * XvMC uses it to replace the ff_mpv_reconstruct_mb().
2472      * Instead of decoding to raw picture, MB parameters are
2473      * stored in an array provided by the video driver.
2474      *
2475      * @param s the mpeg context
2476      */
2477     void function (MpegEncContext* s) decode_mb;
2478 
2479     /**
2480      * Initialize the hwaccel private data.
2481      *
2482      * This will be called from ff_get_format(), after hwaccel and
2483      * hwaccel_context are set and the hwaccel private data in AVCodecInternal
2484      * is allocated.
2485      */
2486     int function (AVCodecContext* avctx) init;
2487 
2488     /**
2489      * Uninitialize the hwaccel private data.
2490      *
2491      * This will be called from get_format() or avcodec_close(), after hwaccel
2492      * and hwaccel_context are already uninitialized.
2493      */
2494     int function (AVCodecContext* avctx) uninit;
2495 
2496     /**
2497      * Size of the private data to allocate in
2498      * AVCodecInternal.hwaccel_priv_data.
2499      */
2500     int priv_data_size;
2501 
2502     /**
2503      * Internal hwaccel capabilities.
2504      */
2505     int caps_internal;
2506 
2507     /**
2508      * Fill the given hw_frames context with current codec parameters. Called
2509      * from get_format. Refer to avcodec_get_hw_frames_parameters() for
2510      * details.
2511      *
2512      * This CAN be called before AVHWAccel.init is called, and you must assume
2513      * that avctx->hwaccel_priv_data is invalid.
2514      */
2515     int function (AVCodecContext* avctx, AVBufferRef* hw_frames_ctx) frame_params;
2516 }
2517 
2518 /**
2519  * HWAccel is experimental and is thus avoided in favor of non experimental
2520  * codecs
2521  */
2522 enum AV_HWACCEL_CODEC_CAP_EXPERIMENTAL = 0x0200;
2523 
2524 /**
2525  * Hardware acceleration should be used for decoding even if the codec level
2526  * used is unknown or higher than the maximum supported level reported by the
2527  * hardware driver.
2528  *
2529  * It's generally a good idea to pass this flag unless you have a specific
2530  * reason not to, as hardware tends to under-report supported levels.
2531  */
2532 enum AV_HWACCEL_FLAG_IGNORE_LEVEL = 1 << 0;
2533 
2534 /**
2535  * Hardware acceleration can output YUV pixel formats with a different chroma
2536  * sampling than 4:2:0 and/or other than 8 bits per component.
2537  */
2538 enum AV_HWACCEL_FLAG_ALLOW_HIGH_DEPTH = 1 << 1;
2539 
2540 /**
2541  * Hardware acceleration should still be attempted for decoding when the
2542  * codec profile does not match the reported capabilities of the hardware.
2543  *
2544  * For example, this can be used to try to decode baseline profile H.264
2545  * streams in hardware - it will often succeed, because many streams marked
2546  * as baseline profile actually conform to constrained baseline profile.
2547  *
2548  * @warning If the stream is actually not supported then the behaviour is
2549  *          undefined, and may include returning entirely incorrect output
2550  *          while indicating success.
2551  */
2552 enum AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH = 1 << 2;
2553 
2554 /**
2555  * @}
2556  */
2557 
2558 /**
2559  * @defgroup lavc_picture AVPicture
2560  *
2561  * Functions for working with AVPicture
2562  * @{
2563  */
2564 
2565 /**
2566  * Picture data structure.
2567  *
2568  * Up to four components can be stored into it, the last component is
2569  * alpha.
2570  * @deprecated use AVFrame or imgutils functions instead
2571  */
2572 struct AVPicture
2573 {
2574     ubyte*[AV_NUM_DATA_POINTERS] data; ///< pointers to the image data planes
2575     int[AV_NUM_DATA_POINTERS] linesize; ///< number of bytes per line
2576 }
2577 
2578 /**
2579  * @}
2580  */
2581 
2582 enum AVSubtitleType
2583 {
2584     SUBTITLE_NONE = 0,
2585 
2586     SUBTITLE_BITMAP = 1, ///< A bitmap, pict will be set
2587 
2588     /**
2589      * Plain text, the text field must be set by the decoder and is
2590      * authoritative. ass and pict fields may contain approximations.
2591      */
2592     SUBTITLE_TEXT = 2,
2593 
2594     /**
2595      * Formatted text, the ass field must be set by the decoder and is
2596      * authoritative. pict and text fields may contain approximations.
2597      */
2598     SUBTITLE_ASS = 3
2599 }
2600 
2601 enum AV_SUBTITLE_FLAG_FORCED = 0x00000001;
2602 
2603 struct AVSubtitleRect
2604 {
2605     int x; ///< top left corner  of pict, undefined when pict is not set
2606     int y; ///< top left corner  of pict, undefined when pict is not set
2607     int w; ///< width            of pict, undefined when pict is not set
2608     int h; ///< height           of pict, undefined when pict is not set
2609     int nb_colors; ///< number of colors in pict, undefined when pict is not set
2610 
2611     /**
2612      * @deprecated unused
2613      */
2614     AVPicture pict;
2615 
2616     /**
2617      * data+linesize for the bitmap of this subtitle.
2618      * Can be set for text/ass as well once they are rendered.
2619      */
2620     ubyte*[4] data;
2621     int[4] linesize;
2622 
2623     AVSubtitleType type;
2624 
2625     char* text; ///< 0 terminated plain UTF-8 text
2626 
2627     /**
2628      * 0 terminated ASS/SSA compatible event line.
2629      * The presentation of this is unaffected by the other values in this
2630      * struct.
2631      */
2632     char* ass;
2633 
2634     int flags;
2635 }
2636 
2637 struct AVSubtitle
2638 {
2639     ushort format; /* 0 = graphics */
2640     uint start_display_time; /* relative to packet pts, in ms */
2641     uint end_display_time; /* relative to packet pts, in ms */
2642     uint num_rects;
2643     AVSubtitleRect** rects;
2644     long pts; ///< Same as packet pts, in AV_TIME_BASE
2645 }
2646 
2647 /**
2648  * If c is NULL, returns the first registered codec,
2649  * if c is non-NULL, returns the next registered codec after c,
2650  * or NULL if c is the last one.
2651  */
2652 AVCodec* av_codec_next (const(AVCodec)* c);
2653 
2654 /**
2655  * Return the LIBAVCODEC_VERSION_INT constant.
2656  */
2657 uint avcodec_version ();
2658 
2659 /**
2660  * Return the libavcodec build-time configuration.
2661  */
2662 const(char)* avcodec_configuration ();
2663 
2664 /**
2665  * Return the libavcodec license.
2666  */
2667 const(char)* avcodec_license ();
2668 
2669 /**
2670  * @deprecated Calling this function is unnecessary.
2671  */
2672 void avcodec_register (AVCodec* codec);
2673 
2674 /**
2675  * @deprecated Calling this function is unnecessary.
2676  */
2677 void avcodec_register_all ();
2678 
2679 /**
2680  * Allocate an AVCodecContext and set its fields to default values. The
2681  * resulting struct should be freed with avcodec_free_context().
2682  *
2683  * @param codec if non-NULL, allocate private data and initialize defaults
2684  *              for the given codec. It is illegal to then call avcodec_open2()
2685  *              with a different codec.
2686  *              If NULL, then the codec-specific defaults won't be initialized,
2687  *              which may result in suboptimal default settings (this is
2688  *              important mainly for encoders, e.g. libx264).
2689  *
2690  * @return An AVCodecContext filled with default values or NULL on failure.
2691  */
2692 AVCodecContext* avcodec_alloc_context3 (const(AVCodec)* codec);
2693 
2694 /**
2695  * Free the codec context and everything associated with it and write NULL to
2696  * the provided pointer.
2697  */
2698 void avcodec_free_context (AVCodecContext** avctx);
2699 
2700 /**
2701  * @deprecated This function should not be used, as closing and opening a codec
2702  * context multiple time is not supported. A new codec context should be
2703  * allocated for each new use.
2704  */
2705 int avcodec_get_context_defaults3 (AVCodecContext* s, const(AVCodec)* codec);
2706 
2707 /**
2708  * Get the AVClass for AVCodecContext. It can be used in combination with
2709  * AV_OPT_SEARCH_FAKE_OBJ for examining options.
2710  *
2711  * @see av_opt_find().
2712  */
2713 const(AVClass)* avcodec_get_class ();
2714 
2715 /**
2716  * @deprecated This function should not be used.
2717  */
2718 const(AVClass)* avcodec_get_frame_class ();
2719 
2720 /**
2721  * Get the AVClass for AVSubtitleRect. It can be used in combination with
2722  * AV_OPT_SEARCH_FAKE_OBJ for examining options.
2723  *
2724  * @see av_opt_find().
2725  */
2726 const(AVClass)* avcodec_get_subtitle_rect_class ();
2727 
2728 /**
2729  * Copy the settings of the source AVCodecContext into the destination
2730  * AVCodecContext. The resulting destination codec context will be
2731  * unopened, i.e. you are required to call avcodec_open2() before you
2732  * can use this AVCodecContext to decode/encode video/audio data.
2733  *
2734  * @param dest target codec context, should be initialized with
2735  *             avcodec_alloc_context3(NULL), but otherwise uninitialized
2736  * @param src source codec context
2737  * @return AVERROR() on error (e.g. memory allocation error), 0 on success
2738  *
2739  * @deprecated The semantics of this function are ill-defined and it should not
2740  * be used. If you need to transfer the stream parameters from one codec context
2741  * to another, use an intermediate AVCodecParameters instance and the
2742  * avcodec_parameters_from_context() / avcodec_parameters_to_context()
2743  * functions.
2744  */
2745 int avcodec_copy_context (AVCodecContext* dest, const(AVCodecContext)* src);
2746 
2747 /**
2748  * Fill the parameters struct based on the values from the supplied codec
2749  * context. Any allocated fields in par are freed and replaced with duplicates
2750  * of the corresponding fields in codec.
2751  *
2752  * @return >= 0 on success, a negative AVERROR code on failure
2753  */
2754 int avcodec_parameters_from_context (
2755     AVCodecParameters* par,
2756     const(AVCodecContext)* codec);
2757 
2758 /**
2759  * Fill the codec context based on the values from the supplied codec
2760  * parameters. Any allocated fields in codec that have a corresponding field in
2761  * par are freed and replaced with duplicates of the corresponding field in par.
2762  * Fields in codec that do not have a counterpart in par are not touched.
2763  *
2764  * @return >= 0 on success, a negative AVERROR code on failure.
2765  */
2766 int avcodec_parameters_to_context (
2767     AVCodecContext* codec,
2768     const(AVCodecParameters)* par);
2769 
2770 /**
2771  * Initialize the AVCodecContext to use the given AVCodec. Prior to using this
2772  * function the context has to be allocated with avcodec_alloc_context3().
2773  *
2774  * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(),
2775  * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for
2776  * retrieving a codec.
2777  *
2778  * @warning This function is not thread safe!
2779  *
2780  * @note Always call this function before using decoding routines (such as
2781  * @ref avcodec_receive_frame()).
2782  *
2783  * @code
2784  * av_dict_set(&opts, "b", "2.5M", 0);
2785  * codec = avcodec_find_decoder(AV_CODEC_ID_H264);
2786  * if (!codec)
2787  *     exit(1);
2788  *
2789  * context = avcodec_alloc_context3(codec);
2790  *
2791  * if (avcodec_open2(context, codec, opts) < 0)
2792  *     exit(1);
2793  * @endcode
2794  *
2795  * @param avctx The context to initialize.
2796  * @param codec The codec to open this context for. If a non-NULL codec has been
2797  *              previously passed to avcodec_alloc_context3() or
2798  *              for this context, then this parameter MUST be either NULL or
2799  *              equal to the previously passed codec.
2800  * @param options A dictionary filled with AVCodecContext and codec-private options.
2801  *                On return this object will be filled with options that were not found.
2802  *
2803  * @return zero on success, a negative value on error
2804  * @see avcodec_alloc_context3(), avcodec_find_decoder(), avcodec_find_encoder(),
2805  *      av_dict_set(), av_opt_find().
2806  */
2807 int avcodec_open2 (AVCodecContext* avctx, const(AVCodec)* codec, AVDictionary** options);
2808 
2809 /**
2810  * Close a given AVCodecContext and free all the data associated with it
2811  * (but not the AVCodecContext itself).
2812  *
2813  * Calling this function on an AVCodecContext that hasn't been opened will free
2814  * the codec-specific data allocated in avcodec_alloc_context3() with a non-NULL
2815  * codec. Subsequent calls will do nothing.
2816  *
2817  * @note Do not use this function. Use avcodec_free_context() to destroy a
2818  * codec context (either open or closed). Opening and closing a codec context
2819  * multiple times is not supported anymore -- use multiple codec contexts
2820  * instead.
2821  */
2822 int avcodec_close (AVCodecContext* avctx);
2823 
2824 /**
2825  * Free all allocated data in the given subtitle struct.
2826  *
2827  * @param sub AVSubtitle to free.
2828  */
2829 void avsubtitle_free (AVSubtitle* sub);
2830 
2831 /**
2832  * @}
2833  */
2834 
2835 /**
2836  * @addtogroup lavc_decoding
2837  * @{
2838  */
2839 
2840 /**
2841  * The default callback for AVCodecContext.get_buffer2(). It is made public so
2842  * it can be called by custom get_buffer2() implementations for decoders without
2843  * AV_CODEC_CAP_DR1 set.
2844  */
2845 int avcodec_default_get_buffer2 (AVCodecContext* s, AVFrame* frame, int flags);
2846 
2847 /**
2848  * The default callback for AVCodecContext.get_encode_buffer(). It is made public so
2849  * it can be called by custom get_encode_buffer() implementations for encoders without
2850  * AV_CODEC_CAP_DR1 set.
2851  */
2852 int avcodec_default_get_encode_buffer (AVCodecContext* s, AVPacket* pkt, int flags);
2853 
2854 /**
2855  * Modify width and height values so that they will result in a memory
2856  * buffer that is acceptable for the codec if you do not use any horizontal
2857  * padding.
2858  *
2859  * May only be used if a codec with AV_CODEC_CAP_DR1 has been opened.
2860  */
2861 void avcodec_align_dimensions (AVCodecContext* s, int* width, int* height);
2862 
2863 /**
2864  * Modify width and height values so that they will result in a memory
2865  * buffer that is acceptable for the codec if you also ensure that all
2866  * line sizes are a multiple of the respective linesize_align[i].
2867  *
2868  * May only be used if a codec with AV_CODEC_CAP_DR1 has been opened.
2869  */
2870 void avcodec_align_dimensions2 (
2871     AVCodecContext* s,
2872     int* width,
2873     int* height,
2874     ref int[AV_NUM_DATA_POINTERS] linesize_align);
2875 
2876 /**
2877  * Converts AVChromaLocation to swscale x/y chroma position.
2878  *
2879  * The positions represent the chroma (0,0) position in a coordinates system
2880  * with luma (0,0) representing the origin and luma(1,1) representing 256,256
2881  *
2882  * @param xpos  horizontal chroma sample position
2883  * @param ypos  vertical   chroma sample position
2884  */
2885 int avcodec_enum_to_chroma_pos (int* xpos, int* ypos, AVChromaLocation pos);
2886 
2887 /**
2888  * Converts swscale x/y chroma position to AVChromaLocation.
2889  *
2890  * The positions represent the chroma (0,0) position in a coordinates system
2891  * with luma (0,0) representing the origin and luma(1,1) representing 256,256
2892  *
2893  * @param xpos  horizontal chroma sample position
2894  * @param ypos  vertical   chroma sample position
2895  */
2896 AVChromaLocation avcodec_chroma_pos_to_enum (int xpos, int ypos);
2897 
2898 /**
2899  * Decode the audio frame of size avpkt->size from avpkt->data into frame.
2900  *
2901  * Some decoders may support multiple frames in a single AVPacket. Such
2902  * decoders would then just decode the first frame and the return value would be
2903  * less than the packet size. In this case, avcodec_decode_audio4 has to be
2904  * called again with an AVPacket containing the remaining data in order to
2905  * decode the second frame, etc...  Even if no frames are returned, the packet
2906  * needs to be fed to the decoder with remaining data until it is completely
2907  * consumed or an error occurs.
2908  *
2909  * Some decoders (those marked with AV_CODEC_CAP_DELAY) have a delay between input
2910  * and output. This means that for some packets they will not immediately
2911  * produce decoded output and need to be flushed at the end of decoding to get
2912  * all the decoded data. Flushing is done by calling this function with packets
2913  * with avpkt->data set to NULL and avpkt->size set to 0 until it stops
2914  * returning samples. It is safe to flush even those decoders that are not
2915  * marked with AV_CODEC_CAP_DELAY, then no samples will be returned.
2916  *
2917  * @warning The input buffer, avpkt->data must be AV_INPUT_BUFFER_PADDING_SIZE
2918  *          larger than the actual read bytes because some optimized bitstream
2919  *          readers read 32 or 64 bits at once and could read over the end.
2920  *
2921  * @note The AVCodecContext MUST have been opened with @ref avcodec_open2()
2922  * before packets may be fed to the decoder.
2923  *
2924  * @param      avctx the codec context
2925  * @param[out] frame The AVFrame in which to store decoded audio samples.
2926  *                   The decoder will allocate a buffer for the decoded frame by
2927  *                   calling the AVCodecContext.get_buffer2() callback.
2928  *                   When AVCodecContext.refcounted_frames is set to 1, the frame is
2929  *                   reference counted and the returned reference belongs to the
2930  *                   caller. The caller must release the frame using av_frame_unref()
2931  *                   when the frame is no longer needed. The caller may safely write
2932  *                   to the frame if av_frame_is_writable() returns 1.
2933  *                   When AVCodecContext.refcounted_frames is set to 0, the returned
2934  *                   reference belongs to the decoder and is valid only until the
2935  *                   next call to this function or until closing or flushing the
2936  *                   decoder. The caller may not write to it.
2937  * @param[out] got_frame_ptr Zero if no frame could be decoded, otherwise it is
2938  *                           non-zero. Note that this field being set to zero
2939  *                           does not mean that an error has occurred. For
2940  *                           decoders with AV_CODEC_CAP_DELAY set, no given decode
2941  *                           call is guaranteed to produce a frame.
2942  * @param[in]  avpkt The input AVPacket containing the input buffer.
2943  *                   At least avpkt->data and avpkt->size should be set. Some
2944  *                   decoders might also require additional fields to be set.
2945  * @return A negative error code is returned if an error occurred during
2946  *         decoding, otherwise the number of bytes consumed from the input
2947  *         AVPacket is returned.
2948  *
2949 * @deprecated Use avcodec_send_packet() and avcodec_receive_frame().
2950  */
2951 int avcodec_decode_audio4 (
2952     AVCodecContext* avctx,
2953     AVFrame* frame,
2954     int* got_frame_ptr,
2955     const(AVPacket)* avpkt);
2956 
2957 /**
2958  * Decode the video frame of size avpkt->size from avpkt->data into picture.
2959  * Some decoders may support multiple frames in a single AVPacket, such
2960  * decoders would then just decode the first frame.
2961  *
2962  * @warning The input buffer must be AV_INPUT_BUFFER_PADDING_SIZE larger than
2963  * the actual read bytes because some optimized bitstream readers read 32 or 64
2964  * bits at once and could read over the end.
2965  *
2966  * @warning The end of the input buffer buf should be set to 0 to ensure that
2967  * no overreading happens for damaged MPEG streams.
2968  *
2969  * @note Codecs which have the AV_CODEC_CAP_DELAY capability set have a delay
2970  * between input and output, these need to be fed with avpkt->data=NULL,
2971  * avpkt->size=0 at the end to return the remaining frames.
2972  *
2973  * @note The AVCodecContext MUST have been opened with @ref avcodec_open2()
2974  * before packets may be fed to the decoder.
2975  *
2976  * @param avctx the codec context
2977  * @param[out] picture The AVFrame in which the decoded video frame will be stored.
2978  *             Use av_frame_alloc() to get an AVFrame. The codec will
2979  *             allocate memory for the actual bitmap by calling the
2980  *             AVCodecContext.get_buffer2() callback.
2981  *             When AVCodecContext.refcounted_frames is set to 1, the frame is
2982  *             reference counted and the returned reference belongs to the
2983  *             caller. The caller must release the frame using av_frame_unref()
2984  *             when the frame is no longer needed. The caller may safely write
2985  *             to the frame if av_frame_is_writable() returns 1.
2986  *             When AVCodecContext.refcounted_frames is set to 0, the returned
2987  *             reference belongs to the decoder and is valid only until the
2988  *             next call to this function or until closing or flushing the
2989  *             decoder. The caller may not write to it.
2990  *
2991  * @param[in] avpkt The input AVPacket containing the input buffer.
2992  *            You can create such packet with av_init_packet() and by then setting
2993  *            data and size, some decoders might in addition need other fields like
2994  *            flags&AV_PKT_FLAG_KEY. All decoders are designed to use the least
2995  *            fields possible.
2996  * @param[in,out] got_picture_ptr Zero if no frame could be decompressed, otherwise, it is nonzero.
2997  * @return On error a negative value is returned, otherwise the number of bytes
2998  * used or zero if no frame could be decompressed.
2999  *
3000  * @deprecated Use avcodec_send_packet() and avcodec_receive_frame().
3001  */
3002 int avcodec_decode_video2 (
3003     AVCodecContext* avctx,
3004     AVFrame* picture,
3005     int* got_picture_ptr,
3006     const(AVPacket)* avpkt);
3007 
3008 /**
3009  * Decode a subtitle message.
3010  * Return a negative value on error, otherwise return the number of bytes used.
3011  * If no subtitle could be decompressed, got_sub_ptr is zero.
3012  * Otherwise, the subtitle is stored in *sub.
3013  * Note that AV_CODEC_CAP_DR1 is not available for subtitle codecs. This is for
3014  * simplicity, because the performance difference is expected to be negligible
3015  * and reusing a get_buffer written for video codecs would probably perform badly
3016  * due to a potentially very different allocation pattern.
3017  *
3018  * Some decoders (those marked with AV_CODEC_CAP_DELAY) have a delay between input
3019  * and output. This means that for some packets they will not immediately
3020  * produce decoded output and need to be flushed at the end of decoding to get
3021  * all the decoded data. Flushing is done by calling this function with packets
3022  * with avpkt->data set to NULL and avpkt->size set to 0 until it stops
3023  * returning subtitles. It is safe to flush even those decoders that are not
3024  * marked with AV_CODEC_CAP_DELAY, then no subtitles will be returned.
3025  *
3026  * @note The AVCodecContext MUST have been opened with @ref avcodec_open2()
3027  * before packets may be fed to the decoder.
3028  *
3029  * @param avctx the codec context
3030  * @param[out] sub The preallocated AVSubtitle in which the decoded subtitle will be stored,
3031  *                 must be freed with avsubtitle_free if *got_sub_ptr is set.
3032  * @param[in,out] got_sub_ptr Zero if no subtitle could be decompressed, otherwise, it is nonzero.
3033  * @param[in] avpkt The input AVPacket containing the input buffer.
3034  */
3035 int avcodec_decode_subtitle2 (
3036     AVCodecContext* avctx,
3037     AVSubtitle* sub,
3038     int* got_sub_ptr,
3039     AVPacket* avpkt);
3040 
3041 /**
3042  * Supply raw packet data as input to a decoder.
3043  *
3044  * Internally, this call will copy relevant AVCodecContext fields, which can
3045  * influence decoding per-packet, and apply them when the packet is actually
3046  * decoded. (For example AVCodecContext.skip_frame, which might direct the
3047  * decoder to drop the frame contained by the packet sent with this function.)
3048  *
3049  * @warning The input buffer, avpkt->data must be AV_INPUT_BUFFER_PADDING_SIZE
3050  *          larger than the actual read bytes because some optimized bitstream
3051  *          readers read 32 or 64 bits at once and could read over the end.
3052  *
3053  * @warning Do not mix this API with the legacy API (like avcodec_decode_video2())
3054  *          on the same AVCodecContext. It will return unexpected results now
3055  *          or in future libavcodec versions.
3056  *
3057  * @note The AVCodecContext MUST have been opened with @ref avcodec_open2()
3058  *       before packets may be fed to the decoder.
3059  *
3060  * @param avctx codec context
3061  * @param[in] avpkt The input AVPacket. Usually, this will be a single video
3062  *                  frame, or several complete audio frames.
3063  *                  Ownership of the packet remains with the caller, and the
3064  *                  decoder will not write to the packet. The decoder may create
3065  *                  a reference to the packet data (or copy it if the packet is
3066  *                  not reference-counted).
3067  *                  Unlike with older APIs, the packet is always fully consumed,
3068  *                  and if it contains multiple frames (e.g. some audio codecs),
3069  *                  will require you to call avcodec_receive_frame() multiple
3070  *                  times afterwards before you can send a new packet.
3071  *                  It can be NULL (or an AVPacket with data set to NULL and
3072  *                  size set to 0); in this case, it is considered a flush
3073  *                  packet, which signals the end of the stream. Sending the
3074  *                  first flush packet will return success. Subsequent ones are
3075  *                  unnecessary and will return AVERROR_EOF. If the decoder
3076  *                  still has frames buffered, it will return them after sending
3077  *                  a flush packet.
3078  *
3079  * @return 0 on success, otherwise negative error code:
3080  *      AVERROR(EAGAIN):   input is not accepted in the current state - user
3081  *                         must read output with avcodec_receive_frame() (once
3082  *                         all output is read, the packet should be resent, and
3083  *                         the call will not fail with EAGAIN).
3084  *      AVERROR_EOF:       the decoder has been flushed, and no new packets can
3085  *                         be sent to it (also returned if more than 1 flush
3086  *                         packet is sent)
3087  *      AVERROR(EINVAL):   codec not opened, it is an encoder, or requires flush
3088  *      AVERROR(ENOMEM):   failed to add packet to internal queue, or similar
3089  *      other errors: legitimate decoding errors
3090  */
3091 int avcodec_send_packet (AVCodecContext* avctx, const(AVPacket)* avpkt);
3092 
3093 /**
3094  * Return decoded output data from a decoder.
3095  *
3096  * @param avctx codec context
3097  * @param frame This will be set to a reference-counted video or audio
3098  *              frame (depending on the decoder type) allocated by the
3099  *              decoder. Note that the function will always call
3100  *              av_frame_unref(frame) before doing anything else.
3101  *
3102  * @return
3103  *      0:                 success, a frame was returned
3104  *      AVERROR(EAGAIN):   output is not available in this state - user must try
3105  *                         to send new input
3106  *      AVERROR_EOF:       the decoder has been fully flushed, and there will be
3107  *                         no more output frames
3108  *      AVERROR(EINVAL):   codec not opened, or it is an encoder
3109  *      AVERROR_INPUT_CHANGED:   current decoded frame has changed parameters
3110  *                               with respect to first decoded frame. Applicable
3111  *                               when flag AV_CODEC_FLAG_DROPCHANGED is set.
3112  *      other negative values: legitimate decoding errors
3113  */
3114 int avcodec_receive_frame (AVCodecContext* avctx, AVFrame* frame);
3115 
3116 /**
3117  * Supply a raw video or audio frame to the encoder. Use avcodec_receive_packet()
3118  * to retrieve buffered output packets.
3119  *
3120  * @param avctx     codec context
3121  * @param[in] frame AVFrame containing the raw audio or video frame to be encoded.
3122  *                  Ownership of the frame remains with the caller, and the
3123  *                  encoder will not write to the frame. The encoder may create
3124  *                  a reference to the frame data (or copy it if the frame is
3125  *                  not reference-counted).
3126  *                  It can be NULL, in which case it is considered a flush
3127  *                  packet.  This signals the end of the stream. If the encoder
3128  *                  still has packets buffered, it will return them after this
3129  *                  call. Once flushing mode has been entered, additional flush
3130  *                  packets are ignored, and sending frames will return
3131  *                  AVERROR_EOF.
3132  *
3133  *                  For audio:
3134  *                  If AV_CODEC_CAP_VARIABLE_FRAME_SIZE is set, then each frame
3135  *                  can have any number of samples.
3136  *                  If it is not set, frame->nb_samples must be equal to
3137  *                  avctx->frame_size for all frames except the last.
3138  *                  The final frame may be smaller than avctx->frame_size.
3139  * @return 0 on success, otherwise negative error code:
3140  *      AVERROR(EAGAIN):   input is not accepted in the current state - user
3141  *                         must read output with avcodec_receive_packet() (once
3142  *                         all output is read, the packet should be resent, and
3143  *                         the call will not fail with EAGAIN).
3144  *      AVERROR_EOF:       the encoder has been flushed, and no new frames can
3145  *                         be sent to it
3146  *      AVERROR(EINVAL):   codec not opened, refcounted_frames not set, it is a
3147  *                         decoder, or requires flush
3148  *      AVERROR(ENOMEM):   failed to add packet to internal queue, or similar
3149  *      other errors: legitimate encoding errors
3150  */
3151 int avcodec_send_frame (AVCodecContext* avctx, const(AVFrame)* frame);
3152 
3153 /**
3154  * Read encoded data from the encoder.
3155  *
3156  * @param avctx codec context
3157  * @param avpkt This will be set to a reference-counted packet allocated by the
3158  *              encoder. Note that the function will always call
3159  *              av_packet_unref(avpkt) before doing anything else.
3160  * @return 0 on success, otherwise negative error code:
3161  *      AVERROR(EAGAIN):   output is not available in the current state - user
3162  *                         must try to send input
3163  *      AVERROR_EOF:       the encoder has been fully flushed, and there will be
3164  *                         no more output packets
3165  *      AVERROR(EINVAL):   codec not opened, or it is a decoder
3166  *      other errors: legitimate encoding errors
3167  */
3168 int avcodec_receive_packet (AVCodecContext* avctx, AVPacket* avpkt);
3169 
3170 /**
3171  * Create and return a AVHWFramesContext with values adequate for hardware
3172  * decoding. This is meant to get called from the get_format callback, and is
3173  * a helper for preparing a AVHWFramesContext for AVCodecContext.hw_frames_ctx.
3174  * This API is for decoding with certain hardware acceleration modes/APIs only.
3175  *
3176  * The returned AVHWFramesContext is not initialized. The caller must do this
3177  * with av_hwframe_ctx_init().
3178  *
3179  * Calling this function is not a requirement, but makes it simpler to avoid
3180  * codec or hardware API specific details when manually allocating frames.
3181  *
3182  * Alternatively to this, an API user can set AVCodecContext.hw_device_ctx,
3183  * which sets up AVCodecContext.hw_frames_ctx fully automatically, and makes
3184  * it unnecessary to call this function or having to care about
3185  * AVHWFramesContext initialization at all.
3186  *
3187  * There are a number of requirements for calling this function:
3188  *
3189  * - It must be called from get_format with the same avctx parameter that was
3190  *   passed to get_format. Calling it outside of get_format is not allowed, and
3191  *   can trigger undefined behavior.
3192  * - The function is not always supported (see description of return values).
3193  *   Even if this function returns successfully, hwaccel initialization could
3194  *   fail later. (The degree to which implementations check whether the stream
3195  *   is actually supported varies. Some do this check only after the user's
3196  *   get_format callback returns.)
3197  * - The hw_pix_fmt must be one of the choices suggested by get_format. If the
3198  *   user decides to use a AVHWFramesContext prepared with this API function,
3199  *   the user must return the same hw_pix_fmt from get_format.
3200  * - The device_ref passed to this function must support the given hw_pix_fmt.
3201  * - After calling this API function, it is the user's responsibility to
3202  *   initialize the AVHWFramesContext (returned by the out_frames_ref parameter),
3203  *   and to set AVCodecContext.hw_frames_ctx to it. If done, this must be done
3204  *   before returning from get_format (this is implied by the normal
3205  *   AVCodecContext.hw_frames_ctx API rules).
3206  * - The AVHWFramesContext parameters may change every time time get_format is
3207  *   called. Also, AVCodecContext.hw_frames_ctx is reset before get_format. So
3208  *   you are inherently required to go through this process again on every
3209  *   get_format call.
3210  * - It is perfectly possible to call this function without actually using
3211  *   the resulting AVHWFramesContext. One use-case might be trying to reuse a
3212  *   previously initialized AVHWFramesContext, and calling this API function
3213  *   only to test whether the required frame parameters have changed.
3214  * - Fields that use dynamically allocated values of any kind must not be set
3215  *   by the user unless setting them is explicitly allowed by the documentation.
3216  *   If the user sets AVHWFramesContext.free and AVHWFramesContext.user_opaque,
3217  *   the new free callback must call the potentially set previous free callback.
3218  *   This API call may set any dynamically allocated fields, including the free
3219  *   callback.
3220  *
3221  * The function will set at least the following fields on AVHWFramesContext
3222  * (potentially more, depending on hwaccel API):
3223  *
3224  * - All fields set by av_hwframe_ctx_alloc().
3225  * - Set the format field to hw_pix_fmt.
3226  * - Set the sw_format field to the most suited and most versatile format. (An
3227  *   implication is that this will prefer generic formats over opaque formats
3228  *   with arbitrary restrictions, if possible.)
3229  * - Set the width/height fields to the coded frame size, rounded up to the
3230  *   API-specific minimum alignment.
3231  * - Only _if_ the hwaccel requires a pre-allocated pool: set the initial_pool_size
3232  *   field to the number of maximum reference surfaces possible with the codec,
3233  *   plus 1 surface for the user to work (meaning the user can safely reference
3234  *   at most 1 decoded surface at a time), plus additional buffering introduced
3235  *   by frame threading. If the hwaccel does not require pre-allocation, the
3236  *   field is left to 0, and the decoder will allocate new surfaces on demand
3237  *   during decoding.
3238  * - Possibly AVHWFramesContext.hwctx fields, depending on the underlying
3239  *   hardware API.
3240  *
3241  * Essentially, out_frames_ref returns the same as av_hwframe_ctx_alloc(), but
3242  * with basic frame parameters set.
3243  *
3244  * The function is stateless, and does not change the AVCodecContext or the
3245  * device_ref AVHWDeviceContext.
3246  *
3247  * @param avctx The context which is currently calling get_format, and which
3248  *              implicitly contains all state needed for filling the returned
3249  *              AVHWFramesContext properly.
3250  * @param device_ref A reference to the AVHWDeviceContext describing the device
3251  *                   which will be used by the hardware decoder.
3252  * @param hw_pix_fmt The hwaccel format you are going to return from get_format.
3253  * @param out_frames_ref On success, set to a reference to an _uninitialized_
3254  *                       AVHWFramesContext, created from the given device_ref.
3255  *                       Fields will be set to values required for decoding.
3256  *                       Not changed if an error is returned.
3257  * @return zero on success, a negative value on error. The following error codes
3258  *         have special semantics:
3259  *      AVERROR(ENOENT): the decoder does not support this functionality. Setup
3260  *                       is always manual, or it is a decoder which does not
3261  *                       support setting AVCodecContext.hw_frames_ctx at all,
3262  *                       or it is a software format.
3263  *      AVERROR(EINVAL): it is known that hardware decoding is not supported for
3264  *                       this configuration, or the device_ref is not supported
3265  *                       for the hwaccel referenced by hw_pix_fmt.
3266  */
3267 int avcodec_get_hw_frames_parameters (
3268     AVCodecContext* avctx,
3269     AVBufferRef* device_ref,
3270     AVPixelFormat hw_pix_fmt,
3271     AVBufferRef** out_frames_ref);
3272 
3273 /**
3274  * @defgroup lavc_parsing Frame parsing
3275  * @{
3276  */
3277 
3278 enum AVPictureStructure
3279 {
3280     AV_PICTURE_STRUCTURE_UNKNOWN = 0, //< unknown
3281     AV_PICTURE_STRUCTURE_TOP_FIELD = 1, //< coded as top field
3282     AV_PICTURE_STRUCTURE_BOTTOM_FIELD = 2, //< coded as bottom field
3283     AV_PICTURE_STRUCTURE_FRAME = 3 //< coded as frame
3284 }
3285 
3286 struct AVCodecParserContext
3287 {
3288     void* priv_data;
3289     AVCodecParser* parser;
3290     long frame_offset; /* offset of the current frame */
3291     long cur_offset; /* current offset
3292        (incremented by each av_parser_parse()) */
3293     long next_frame_offset; /* offset of the next frame */
3294     /* video info */
3295     int pict_type; /* XXX: Put it back in AVCodecContext. */
3296     /**
3297      * This field is used for proper frame duration computation in lavf.
3298      * It signals, how much longer the frame duration of the current frame
3299      * is compared to normal frame duration.
3300      *
3301      * frame_duration = (1 + repeat_pict) * time_base
3302      *
3303      * It is used by codecs like H.264 to display telecined material.
3304      */
3305     int repeat_pict; /* XXX: Put it back in AVCodecContext. */
3306     long pts; /* pts of the current frame */
3307     long dts; /* dts of the current frame */
3308 
3309     /* private data */
3310     long last_pts;
3311     long last_dts;
3312     int fetch_timestamp;
3313 
3314     int cur_frame_start_index;
3315     long[AV_PARSER_PTS_NB] cur_frame_offset;
3316     long[AV_PARSER_PTS_NB] cur_frame_pts;
3317     long[AV_PARSER_PTS_NB] cur_frame_dts;
3318 
3319     int flags;
3320 
3321     /// Set if the parser has a valid file offset
3322 
3323     long offset; ///< byte offset from starting packet start
3324     long[AV_PARSER_PTS_NB] cur_frame_end;
3325 
3326     /**
3327      * Set by parser to 1 for key frames and 0 for non-key frames.
3328      * It is initialized to -1, so if the parser doesn't set this flag,
3329      * old-style fallback using AV_PICTURE_TYPE_I picture type as key frames
3330      * will be used.
3331      */
3332     int key_frame;
3333 
3334     /**
3335      * @deprecated unused
3336      */
3337     long convergence_duration;
3338 
3339     // Timestamp generation support:
3340     /**
3341      * Synchronization point for start of timestamp generation.
3342      *
3343      * Set to >0 for sync point, 0 for no sync point and <0 for undefined
3344      * (default).
3345      *
3346      * For example, this corresponds to presence of H.264 buffering period
3347      * SEI message.
3348      */
3349     int dts_sync_point;
3350 
3351     /**
3352      * Offset of the current timestamp against last timestamp sync point in
3353      * units of AVCodecContext.time_base.
3354      *
3355      * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
3356      * contain a valid timestamp offset.
3357      *
3358      * Note that the timestamp of sync point has usually a nonzero
3359      * dts_ref_dts_delta, which refers to the previous sync point. Offset of
3360      * the next frame after timestamp sync point will be usually 1.
3361      *
3362      * For example, this corresponds to H.264 cpb_removal_delay.
3363      */
3364     int dts_ref_dts_delta;
3365 
3366     /**
3367      * Presentation delay of current frame in units of AVCodecContext.time_base.
3368      *
3369      * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
3370      * contain valid non-negative timestamp delta (presentation time of a frame
3371      * must not lie in the past).
3372      *
3373      * This delay represents the difference between decoding and presentation
3374      * time of the frame.
3375      *
3376      * For example, this corresponds to H.264 dpb_output_delay.
3377      */
3378     int pts_dts_delta;
3379 
3380     /**
3381      * Position of the packet in file.
3382      *
3383      * Analogous to cur_frame_pts/dts
3384      */
3385     long[AV_PARSER_PTS_NB] cur_frame_pos;
3386 
3387     /**
3388      * Byte position of currently parsed frame in stream.
3389      */
3390     long pos;
3391 
3392     /**
3393      * Previous frame byte position.
3394      */
3395     long last_pos;
3396 
3397     /**
3398      * Duration of the current frame.
3399      * For audio, this is in units of 1 / AVCodecContext.sample_rate.
3400      * For all other types, this is in units of AVCodecContext.time_base.
3401      */
3402     int duration;
3403 
3404     AVFieldOrder field_order;
3405 
3406     /**
3407      * Indicate whether a picture is coded as a frame, top field or bottom field.
3408      *
3409      * For example, H.264 field_pic_flag equal to 0 corresponds to
3410      * AV_PICTURE_STRUCTURE_FRAME. An H.264 picture with field_pic_flag
3411      * equal to 1 and bottom_field_flag equal to 0 corresponds to
3412      * AV_PICTURE_STRUCTURE_TOP_FIELD.
3413      */
3414     AVPictureStructure picture_structure;
3415 
3416     /**
3417      * Picture number incremented in presentation or output order.
3418      * This field may be reinitialized at the first picture of a new sequence.
3419      *
3420      * For example, this corresponds to H.264 PicOrderCnt.
3421      */
3422     int output_picture_number;
3423 
3424     /**
3425      * Dimensions of the decoded video intended for presentation.
3426      */
3427     int width;
3428     int height;
3429 
3430     /**
3431      * Dimensions of the coded video.
3432      */
3433     int coded_width;
3434     int coded_height;
3435 
3436     /**
3437      * The format of the coded data, corresponds to enum AVPixelFormat for video
3438      * and for enum AVSampleFormat for audio.
3439      *
3440      * Note that a decoder can have considerable freedom in how exactly it
3441      * decodes the data, so the format reported here might be different from the
3442      * one returned by a decoder.
3443      */
3444     int format;
3445 }
3446 
3447 enum AV_PARSER_PTS_NB = 4;
3448 enum PARSER_FLAG_COMPLETE_FRAMES = 0x0001;
3449 enum PARSER_FLAG_ONCE = 0x0002;
3450 enum PARSER_FLAG_FETCHED_OFFSET = 0x0004;
3451 enum PARSER_FLAG_USE_CODEC_TS = 0x1000;
3452 
3453 struct AVCodecParser
3454 {
3455     int[5] codec_ids; /* several codec IDs are permitted */
3456     int priv_data_size;
3457     int function (AVCodecParserContext* s) parser_init;
3458     /* This callback never returns an error, a negative value means that
3459      * the frame start was in a previous packet. */
3460     int function (
3461         AVCodecParserContext* s,
3462         AVCodecContext* avctx,
3463         const(ubyte*)* poutbuf,
3464         int* poutbuf_size,
3465         const(ubyte)* buf,
3466         int buf_size) parser_parse;
3467     void function (AVCodecParserContext* s) parser_close;
3468     int function (AVCodecContext* avctx, const(ubyte)* buf, int buf_size) split;
3469 
3470     AVCodecParser* next;
3471 }
3472 
3473 /**
3474  * Iterate over all registered codec parsers.
3475  *
3476  * @param opaque a pointer where libavcodec will store the iteration state. Must
3477  *               point to NULL to start the iteration.
3478  *
3479  * @return the next registered codec parser or NULL when the iteration is
3480  *         finished
3481  */
3482 const(AVCodecParser)* av_parser_iterate (void** opaque);
3483 
3484 AVCodecParser* av_parser_next (const(AVCodecParser)* c);
3485 
3486 void av_register_codec_parser (AVCodecParser* parser);
3487 
3488 AVCodecParserContext* av_parser_init (int codec_id);
3489 
3490 /**
3491  * Parse a packet.
3492  *
3493  * @param s             parser context.
3494  * @param avctx         codec context.
3495  * @param poutbuf       set to pointer to parsed buffer or NULL if not yet finished.
3496  * @param poutbuf_size  set to size of parsed buffer or zero if not yet finished.
3497  * @param buf           input buffer.
3498  * @param buf_size      buffer size in bytes without the padding. I.e. the full buffer
3499                         size is assumed to be buf_size + AV_INPUT_BUFFER_PADDING_SIZE.
3500                         To signal EOF, this should be 0 (so that the last frame
3501                         can be output).
3502  * @param pts           input presentation timestamp.
3503  * @param dts           input decoding timestamp.
3504  * @param pos           input byte position in stream.
3505  * @return the number of bytes of the input bitstream used.
3506  *
3507  * Example:
3508  * @code
3509  *   while(in_len){
3510  *       len = av_parser_parse2(myparser, AVCodecContext, &data, &size,
3511  *                                        in_data, in_len,
3512  *                                        pts, dts, pos);
3513  *       in_data += len;
3514  *       in_len  -= len;
3515  *
3516  *       if(size)
3517  *          decode_frame(data, size);
3518  *   }
3519  * @endcode
3520  */
3521 int av_parser_parse2 (
3522     AVCodecParserContext* s,
3523     AVCodecContext* avctx,
3524     ubyte** poutbuf,
3525     int* poutbuf_size,
3526     const(ubyte)* buf,
3527     int buf_size,
3528     long pts,
3529     long dts,
3530     long pos);
3531 
3532 /**
3533  * @return 0 if the output buffer is a subset of the input, 1 if it is allocated and must be freed
3534  * @deprecated Use dump_extradata, remove_extra or extract_extradata
3535  *             bitstream filters instead.
3536  */
3537 int av_parser_change (
3538     AVCodecParserContext* s,
3539     AVCodecContext* avctx,
3540     ubyte** poutbuf,
3541     int* poutbuf_size,
3542     const(ubyte)* buf,
3543     int buf_size,
3544     int keyframe);
3545 
3546 void av_parser_close (AVCodecParserContext* s);
3547 
3548 /**
3549  * @}
3550  * @}
3551  */
3552 
3553 /**
3554  * @addtogroup lavc_encoding
3555  * @{
3556  */
3557 
3558 /**
3559  * Encode a frame of audio.
3560  *
3561  * Takes input samples from frame and writes the next output packet, if
3562  * available, to avpkt. The output packet does not necessarily contain data for
3563  * the most recent frame, as encoders can delay, split, and combine input frames
3564  * internally as needed.
3565  *
3566  * @param avctx     codec context
3567  * @param avpkt     output AVPacket.
3568  *                  The user can supply an output buffer by setting
3569  *                  avpkt->data and avpkt->size prior to calling the
3570  *                  function, but if the size of the user-provided data is not
3571  *                  large enough, encoding will fail. If avpkt->data and
3572  *                  avpkt->size are set, avpkt->destruct must also be set. All
3573  *                  other AVPacket fields will be reset by the encoder using
3574  *                  av_init_packet(). If avpkt->data is NULL, the encoder will
3575  *                  allocate it. The encoder will set avpkt->size to the size
3576  *                  of the output packet.
3577  *
3578  *                  If this function fails or produces no output, avpkt will be
3579  *                  freed using av_packet_unref().
3580  * @param[in] frame AVFrame containing the raw audio data to be encoded.
3581  *                  May be NULL when flushing an encoder that has the
3582  *                  AV_CODEC_CAP_DELAY capability set.
3583  *                  If AV_CODEC_CAP_VARIABLE_FRAME_SIZE is set, then each frame
3584  *                  can have any number of samples.
3585  *                  If it is not set, frame->nb_samples must be equal to
3586  *                  avctx->frame_size for all frames except the last.
3587  *                  The final frame may be smaller than avctx->frame_size.
3588  * @param[out] got_packet_ptr This field is set to 1 by libavcodec if the
3589  *                            output packet is non-empty, and to 0 if it is
3590  *                            empty. If the function returns an error, the
3591  *                            packet can be assumed to be invalid, and the
3592  *                            value of got_packet_ptr is undefined and should
3593  *                            not be used.
3594  * @return          0 on success, negative error code on failure
3595  *
3596  * @deprecated use avcodec_send_frame()/avcodec_receive_packet() instead.
3597  *             If allowed and required, set AVCodecContext.get_encode_buffer to
3598  *             a custom function to pass user supplied output buffers.
3599  */
3600 int avcodec_encode_audio2 (
3601     AVCodecContext* avctx,
3602     AVPacket* avpkt,
3603     const(AVFrame)* frame,
3604     int* got_packet_ptr);
3605 
3606 /**
3607  * Encode a frame of video.
3608  *
3609  * Takes input raw video data from frame and writes the next output packet, if
3610  * available, to avpkt. The output packet does not necessarily contain data for
3611  * the most recent frame, as encoders can delay and reorder input frames
3612  * internally as needed.
3613  *
3614  * @param avctx     codec context
3615  * @param avpkt     output AVPacket.
3616  *                  The user can supply an output buffer by setting
3617  *                  avpkt->data and avpkt->size prior to calling the
3618  *                  function, but if the size of the user-provided data is not
3619  *                  large enough, encoding will fail. All other AVPacket fields
3620  *                  will be reset by the encoder using av_init_packet(). If
3621  *                  avpkt->data is NULL, the encoder will allocate it.
3622  *                  The encoder will set avpkt->size to the size of the
3623  *                  output packet. The returned data (if any) belongs to the
3624  *                  caller, he is responsible for freeing it.
3625  *
3626  *                  If this function fails or produces no output, avpkt will be
3627  *                  freed using av_packet_unref().
3628  * @param[in] frame AVFrame containing the raw video data to be encoded.
3629  *                  May be NULL when flushing an encoder that has the
3630  *                  AV_CODEC_CAP_DELAY capability set.
3631  * @param[out] got_packet_ptr This field is set to 1 by libavcodec if the
3632  *                            output packet is non-empty, and to 0 if it is
3633  *                            empty. If the function returns an error, the
3634  *                            packet can be assumed to be invalid, and the
3635  *                            value of got_packet_ptr is undefined and should
3636  *                            not be used.
3637  * @return          0 on success, negative error code on failure
3638  *
3639  * @deprecated use avcodec_send_frame()/avcodec_receive_packet() instead.
3640  *             If allowed and required, set AVCodecContext.get_encode_buffer to
3641  *             a custom function to pass user supplied output buffers.
3642  */
3643 int avcodec_encode_video2 (
3644     AVCodecContext* avctx,
3645     AVPacket* avpkt,
3646     const(AVFrame)* frame,
3647     int* got_packet_ptr);
3648 
3649 int avcodec_encode_subtitle (
3650     AVCodecContext* avctx,
3651     ubyte* buf,
3652     int buf_size,
3653     const(AVSubtitle)* sub);
3654 
3655 /**
3656  * @}
3657  */
3658 
3659 /**
3660  * @addtogroup lavc_picture
3661  * @{
3662  */
3663 
3664 /**
3665  * @deprecated unused
3666  */
3667 int avpicture_alloc (
3668     AVPicture* picture,
3669     AVPixelFormat pix_fmt,
3670     int width,
3671     int height);
3672 
3673 /**
3674  * @deprecated unused
3675  */
3676 void avpicture_free (AVPicture* picture);
3677 
3678 /**
3679  * @deprecated use av_image_fill_arrays() instead.
3680  */
3681 int avpicture_fill (
3682     AVPicture* picture,
3683     const(ubyte)* ptr,
3684     AVPixelFormat pix_fmt,
3685     int width,
3686     int height);
3687 
3688 /**
3689  * @deprecated use av_image_copy_to_buffer() instead.
3690  */
3691 int avpicture_layout (
3692     const(AVPicture)* src,
3693     AVPixelFormat pix_fmt,
3694     int width,
3695     int height,
3696     ubyte* dest,
3697     int dest_size);
3698 
3699 /**
3700  * @deprecated use av_image_get_buffer_size() instead.
3701  */
3702 int avpicture_get_size (AVPixelFormat pix_fmt, int width, int height);
3703 
3704 /**
3705  * @deprecated av_image_copy() instead.
3706  */
3707 void av_picture_copy (
3708     AVPicture* dst,
3709     const(AVPicture)* src,
3710     AVPixelFormat pix_fmt,
3711     int width,
3712     int height);
3713 
3714 /**
3715  * @deprecated unused
3716  */
3717 int av_picture_crop (
3718     AVPicture* dst,
3719     const(AVPicture)* src,
3720     AVPixelFormat pix_fmt,
3721     int top_band,
3722     int left_band);
3723 
3724 /**
3725  * @deprecated unused
3726  */
3727 int av_picture_pad (
3728     AVPicture* dst,
3729     const(AVPicture)* src,
3730     int height,
3731     int width,
3732     AVPixelFormat pix_fmt,
3733     int padtop,
3734     int padbottom,
3735     int padleft,
3736     int padright,
3737     int* color);
3738 
3739 /**
3740  * @}
3741  */
3742 
3743 /**
3744  * @defgroup lavc_misc Utility functions
3745  * @ingroup libavc
3746  *
3747  * Miscellaneous utility functions related to both encoding and decoding
3748  * (or neither).
3749  * @{
3750  */
3751 
3752 /**
3753  * @defgroup lavc_misc_pixfmt Pixel formats
3754  *
3755  * Functions for working with pixel formats.
3756  * @{
3757  */
3758 
3759 /**
3760  * @deprecated Use av_pix_fmt_get_chroma_sub_sample
3761  */
3762 
3763 void avcodec_get_chroma_sub_sample (
3764     AVPixelFormat pix_fmt,
3765     int* h_shift,
3766     int* v_shift);
3767 
3768 /**
3769  * Return a value representing the fourCC code associated to the
3770  * pixel format pix_fmt, or 0 if no associated fourCC code can be
3771  * found.
3772  */
3773 uint avcodec_pix_fmt_to_codec_tag (AVPixelFormat pix_fmt);
3774 
3775 /**
3776  * Find the best pixel format to convert to given a certain source pixel
3777  * format.  When converting from one pixel format to another, information loss
3778  * may occur.  For example, when converting from RGB24 to GRAY, the color
3779  * information will be lost. Similarly, other losses occur when converting from
3780  * some formats to other formats. avcodec_find_best_pix_fmt_of_2() searches which of
3781  * the given pixel formats should be used to suffer the least amount of loss.
3782  * The pixel formats from which it chooses one, are determined by the
3783  * pix_fmt_list parameter.
3784  *
3785  *
3786  * @param[in] pix_fmt_list AV_PIX_FMT_NONE terminated array of pixel formats to choose from
3787  * @param[in] src_pix_fmt source pixel format
3788  * @param[in] has_alpha Whether the source pixel format alpha channel is used.
3789  * @param[out] loss_ptr Combination of flags informing you what kind of losses will occur.
3790  * @return The best pixel format to convert to or -1 if none was found.
3791  */
3792 AVPixelFormat avcodec_find_best_pix_fmt_of_list (
3793     const(AVPixelFormat)* pix_fmt_list,
3794     AVPixelFormat src_pix_fmt,
3795     int has_alpha,
3796     int* loss_ptr);
3797 
3798 /**
3799  * @deprecated see av_get_pix_fmt_loss()
3800  */
3801 int avcodec_get_pix_fmt_loss (
3802     AVPixelFormat dst_pix_fmt,
3803     AVPixelFormat src_pix_fmt,
3804     int has_alpha);
3805 /**
3806  * @deprecated see av_find_best_pix_fmt_of_2()
3807  */
3808 AVPixelFormat avcodec_find_best_pix_fmt_of_2 (
3809     AVPixelFormat dst_pix_fmt1,
3810     AVPixelFormat dst_pix_fmt2,
3811     AVPixelFormat src_pix_fmt,
3812     int has_alpha,
3813     int* loss_ptr);
3814 
3815 AVPixelFormat avcodec_find_best_pix_fmt2 (
3816     AVPixelFormat dst_pix_fmt1,
3817     AVPixelFormat dst_pix_fmt2,
3818     AVPixelFormat src_pix_fmt,
3819     int has_alpha,
3820     int* loss_ptr);
3821 
3822 AVPixelFormat avcodec_default_get_format (AVCodecContext* s, const(AVPixelFormat)* fmt);
3823 
3824 /**
3825  * @}
3826  */
3827 
3828 /**
3829  * Put a string representing the codec tag codec_tag in buf.
3830  *
3831  * @param buf       buffer to place codec tag in
3832  * @param buf_size size in bytes of buf
3833  * @param codec_tag codec tag to assign
3834  * @return the length of the string that would have been generated if
3835  * enough space had been available, excluding the trailing null
3836  *
3837  * @deprecated see av_fourcc_make_string() and av_fourcc2str().
3838  */
3839 size_t av_get_codec_tag_string (char* buf, size_t buf_size, uint codec_tag);
3840 
3841 void avcodec_string (char* buf, int buf_size, AVCodecContext* enc, int encode);
3842 
3843 /**
3844  * Return a name for the specified profile, if available.
3845  *
3846  * @param codec the codec that is searched for the given profile
3847  * @param profile the profile value for which a name is requested
3848  * @return A name for the profile if found, NULL otherwise.
3849  */
3850 const(char)* av_get_profile_name (const(AVCodec)* codec, int profile);
3851 
3852 /**
3853  * Return a name for the specified profile, if available.
3854  *
3855  * @param codec_id the ID of the codec to which the requested profile belongs
3856  * @param profile the profile value for which a name is requested
3857  * @return A name for the profile if found, NULL otherwise.
3858  *
3859  * @note unlike av_get_profile_name(), which searches a list of profiles
3860  *       supported by a specific decoder or encoder implementation, this
3861  *       function searches the list of profiles from the AVCodecDescriptor
3862  */
3863 const(char)* avcodec_profile_name (AVCodecID codec_id, int profile);
3864 
3865 int avcodec_default_execute (AVCodecContext* c, int function (AVCodecContext* c2, void* arg2) func, void* arg, int* ret, int count, int size);
3866 int avcodec_default_execute2 (AVCodecContext* c, int function (AVCodecContext* c2, void* arg2, int, int) func, void* arg, int* ret, int count);
3867 //FIXME func typedef
3868 
3869 /**
3870  * Fill AVFrame audio data and linesize pointers.
3871  *
3872  * The buffer buf must be a preallocated buffer with a size big enough
3873  * to contain the specified samples amount. The filled AVFrame data
3874  * pointers will point to this buffer.
3875  *
3876  * AVFrame extended_data channel pointers are allocated if necessary for
3877  * planar audio.
3878  *
3879  * @param frame       the AVFrame
3880  *                    frame->nb_samples must be set prior to calling the
3881  *                    function. This function fills in frame->data,
3882  *                    frame->extended_data, frame->linesize[0].
3883  * @param nb_channels channel count
3884  * @param sample_fmt  sample format
3885  * @param buf         buffer to use for frame data
3886  * @param buf_size    size of buffer
3887  * @param align       plane size sample alignment (0 = default)
3888  * @return            >=0 on success, negative error code on failure
3889  * @todo return the size in bytes required to store the samples in
3890  * case of success, at the next libavutil bump
3891  */
3892 int avcodec_fill_audio_frame (
3893     AVFrame* frame,
3894     int nb_channels,
3895     AVSampleFormat sample_fmt,
3896     const(ubyte)* buf,
3897     int buf_size,
3898     int align_);
3899 
3900 /**
3901  * Reset the internal codec state / flush internal buffers. Should be called
3902  * e.g. when seeking or when switching to a different stream.
3903  *
3904  * @note for decoders, when refcounted frames are not used
3905  * (i.e. avctx->refcounted_frames is 0), this invalidates the frames previously
3906  * returned from the decoder. When refcounted frames are used, the decoder just
3907  * releases any references it might keep internally, but the caller's reference
3908  * remains valid.
3909  *
3910  * @note for encoders, this function will only do something if the encoder
3911  * declares support for AV_CODEC_CAP_ENCODER_FLUSH. When called, the encoder
3912  * will drain any remaining packets, and can then be re-used for a different
3913  * stream (as opposed to sending a null frame which will leave the encoder
3914  * in a permanent EOF state after draining). This can be desirable if the
3915  * cost of tearing down and replacing the encoder instance is high.
3916  */
3917 void avcodec_flush_buffers (AVCodecContext* avctx);
3918 
3919 /**
3920  * Return codec bits per sample.
3921  *
3922  * @param[in] codec_id the codec
3923  * @return Number of bits per sample or zero if unknown for the given codec.
3924  */
3925 int av_get_bits_per_sample (AVCodecID codec_id);
3926 
3927 /**
3928  * Return the PCM codec associated with a sample format.
3929  * @param be  endianness, 0 for little, 1 for big,
3930  *            -1 (or anything else) for native
3931  * @return  AV_CODEC_ID_PCM_* or AV_CODEC_ID_NONE
3932  */
3933 AVCodecID av_get_pcm_codec (AVSampleFormat fmt, int be);
3934 
3935 /**
3936  * Return codec bits per sample.
3937  * Only return non-zero if the bits per sample is exactly correct, not an
3938  * approximation.
3939  *
3940  * @param[in] codec_id the codec
3941  * @return Number of bits per sample or zero if unknown for the given codec.
3942  */
3943 int av_get_exact_bits_per_sample (AVCodecID codec_id);
3944 
3945 /**
3946  * Return audio frame duration.
3947  *
3948  * @param avctx        codec context
3949  * @param frame_bytes  size of the frame, or 0 if unknown
3950  * @return             frame duration, in samples, if known. 0 if not able to
3951  *                     determine.
3952  */
3953 int av_get_audio_frame_duration (AVCodecContext* avctx, int frame_bytes);
3954 
3955 /**
3956  * This function is the same as av_get_audio_frame_duration(), except it works
3957  * with AVCodecParameters instead of an AVCodecContext.
3958  */
3959 int av_get_audio_frame_duration2 (AVCodecParameters* par, int frame_bytes);
3960 
3961 struct AVBitStreamFilterContext
3962 {
3963     void* priv_data;
3964     const(AVBitStreamFilter)* filter;
3965     AVCodecParserContext* parser;
3966     AVBitStreamFilterContext* next;
3967     /**
3968      * Internal default arguments, used if NULL is passed to av_bitstream_filter_filter().
3969      * Not for access by library users.
3970      */
3971     char* args;
3972 }
3973 
3974 /**
3975  * @deprecated the old bitstream filtering API (using AVBitStreamFilterContext)
3976  * is deprecated. Use the new bitstream filtering API (using AVBSFContext).
3977  */
3978 void av_register_bitstream_filter (AVBitStreamFilter* bsf);
3979 /**
3980  * @deprecated the old bitstream filtering API (using AVBitStreamFilterContext)
3981  * is deprecated. Use av_bsf_get_by_name(), av_bsf_alloc(), and av_bsf_init()
3982  * from the new bitstream filtering API (using AVBSFContext).
3983  */
3984 AVBitStreamFilterContext* av_bitstream_filter_init (const(char)* name);
3985 /**
3986  * @deprecated the old bitstream filtering API (using AVBitStreamFilterContext)
3987  * is deprecated. Use av_bsf_send_packet() and av_bsf_receive_packet() from the
3988  * new bitstream filtering API (using AVBSFContext).
3989  */
3990 int av_bitstream_filter_filter (
3991     AVBitStreamFilterContext* bsfc,
3992     AVCodecContext* avctx,
3993     const(char)* args,
3994     ubyte** poutbuf,
3995     int* poutbuf_size,
3996     const(ubyte)* buf,
3997     int buf_size,
3998     int keyframe);
3999 /**
4000  * @deprecated the old bitstream filtering API (using AVBitStreamFilterContext)
4001  * is deprecated. Use av_bsf_free() from the new bitstream filtering API (using
4002  * AVBSFContext).
4003  */
4004 void av_bitstream_filter_close (AVBitStreamFilterContext* bsf);
4005 /**
4006  * @deprecated the old bitstream filtering API (using AVBitStreamFilterContext)
4007  * is deprecated. Use av_bsf_iterate() from the new bitstream filtering API (using
4008  * AVBSFContext).
4009  */
4010 const(AVBitStreamFilter)* av_bitstream_filter_next (
4011     const(AVBitStreamFilter)* f);
4012 
4013 const(AVBitStreamFilter)* av_bsf_next (void** opaque);
4014 
4015 /* memory */
4016 
4017 /**
4018  * Same behaviour av_fast_malloc but the buffer has additional
4019  * AV_INPUT_BUFFER_PADDING_SIZE at the end which will always be 0.
4020  *
4021  * In addition the whole buffer will initially and after resizes
4022  * be 0-initialized so that no uninitialized data will ever appear.
4023  */
4024 void av_fast_padded_malloc (void* ptr, uint* size, size_t min_size);
4025 
4026 /**
4027  * Same behaviour av_fast_padded_malloc except that buffer will always
4028  * be 0-initialized after call.
4029  */
4030 void av_fast_padded_mallocz (void* ptr, uint* size, size_t min_size);
4031 
4032 /**
4033  * Encode extradata length to a buffer. Used by xiph codecs.
4034  *
4035  * @param s buffer to write to; must be at least (v/255+1) bytes long
4036  * @param v size of extradata in bytes
4037  * @return number of bytes written to the buffer.
4038  */
4039 uint av_xiphlacing (ubyte* s, uint v);
4040 
4041 /**
4042  * Register the hardware accelerator hwaccel.
4043  *
4044  * @deprecated  This function doesn't do anything.
4045  */
4046 void av_register_hwaccel (AVHWAccel* hwaccel);
4047 
4048 /**
4049  * If hwaccel is NULL, returns the first registered hardware accelerator,
4050  * if hwaccel is non-NULL, returns the next registered hardware accelerator
4051  * after hwaccel, or NULL if hwaccel is the last one.
4052  *
4053  * @deprecated  AVHWaccel structures contain no user-serviceable parts, so
4054  *              this function should not be used.
4055  */
4056 AVHWAccel* av_hwaccel_next (const(AVHWAccel)* hwaccel);
4057 
4058 /**
4059  * Lock operation used by lockmgr
4060  *
4061  * @deprecated Deprecated together with av_lockmgr_register().
4062  */
4063 enum AVLockOp
4064 {
4065     AV_LOCK_CREATE = 0, ///< Create a mutex
4066     AV_LOCK_OBTAIN = 1, ///< Lock the mutex
4067     AV_LOCK_RELEASE = 2, ///< Unlock the mutex
4068     AV_LOCK_DESTROY = 3 ///< Free mutex resources
4069 }
4070 
4071 /**
4072  * Register a user provided lock manager supporting the operations
4073  * specified by AVLockOp. The "mutex" argument to the function points
4074  * to a (void *) where the lockmgr should store/get a pointer to a user
4075  * allocated mutex. It is NULL upon AV_LOCK_CREATE and equal to the
4076  * value left by the last call for all other ops. If the lock manager is
4077  * unable to perform the op then it should leave the mutex in the same
4078  * state as when it was called and return a non-zero value. However,
4079  * when called with AV_LOCK_DESTROY the mutex will always be assumed to
4080  * have been successfully destroyed. If av_lockmgr_register succeeds
4081  * it will return a non-negative value, if it fails it will return a
4082  * negative value and destroy all mutex and unregister all callbacks.
4083  * av_lockmgr_register is not thread-safe, it must be called from a
4084  * single thread before any calls which make use of locking are used.
4085  *
4086  * @param cb User defined callback. av_lockmgr_register invokes calls
4087  *           to this callback and the previously registered callback.
4088  *           The callback will be used to create more than one mutex
4089  *           each of which must be backed by its own underlying locking
4090  *           mechanism (i.e. do not use a single static object to
4091  *           implement your lock manager). If cb is set to NULL the
4092  *           lockmgr will be unregistered.
4093  *
4094  * @deprecated This function does nothing, and always returns 0. Be sure to
4095  *             build with thread support to get basic thread safety.
4096  */
4097 int av_lockmgr_register (int function (void** mutex, AVLockOp op) cb);
4098 
4099 /**
4100  * @return a positive value if s is open (i.e. avcodec_open2() was called on it
4101  * with no corresponding avcodec_close()), 0 otherwise.
4102  */
4103 int avcodec_is_open (AVCodecContext* s);
4104 
4105 /**
4106  * Allocate a CPB properties structure and initialize its fields to default
4107  * values.
4108  *
4109  * @param size if non-NULL, the size of the allocated struct will be written
4110  *             here. This is useful for embedding it in side data.
4111  *
4112  * @return the newly allocated struct or NULL on failure
4113  */
4114 AVCPBProperties* av_cpb_properties_alloc (size_t* size);
4115 
4116 /**
4117  * @}
4118  */
4119 
4120 /* AVCODEC_AVCODEC_H */