1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 /**
20  * @file
21  * @ingroup lavu_frame
22  * reference-counted frame API
23  */
24 
25 module ffmpeg.libavutil.frame;
26 
27 import ffmpeg.libavutil.avutil;
28 import ffmpeg.libavutil.buffer;
29 import ffmpeg.libavutil.dict;
30 import ffmpeg.libavutil.pixfmt;
31 import ffmpeg.libavutil.rational;
32 
33 extern (C):
34 import ffmpeg; @nogc nothrow:
35 
36 /**
37  * @defgroup lavu_frame AVFrame
38  * @ingroup lavu_data
39  *
40  * @{
41  * AVFrame is an abstraction for reference-counted raw multimedia data.
42  */
43 
44 enum AVFrameSideDataType
45 {
46     /**
47      * The data is the AVPanScan struct defined in libavcodec.
48      */
49     AV_FRAME_DATA_PANSCAN = 0,
50     /**
51      * ATSC A53 Part 4 Closed Captions.
52      * A53 CC bitstream is stored as uint8_t in AVFrameSideData.data.
53      * The number of bytes of CC data is AVFrameSideData.size.
54      */
55     AV_FRAME_DATA_A53_CC = 1,
56     /**
57      * Stereoscopic 3d metadata.
58      * The data is the AVStereo3D struct defined in libavutil/stereo3d.h.
59      */
60     AV_FRAME_DATA_STEREO3D = 2,
61     /**
62      * The data is the AVMatrixEncoding enum defined in libavutil/channel_layout.h.
63      */
64     AV_FRAME_DATA_MATRIXENCODING = 3,
65     /**
66      * Metadata relevant to a downmix procedure.
67      * The data is the AVDownmixInfo struct defined in libavutil/downmix_info.h.
68      */
69     AV_FRAME_DATA_DOWNMIX_INFO = 4,
70     /**
71      * ReplayGain information in the form of the AVReplayGain struct.
72      */
73     AV_FRAME_DATA_REPLAYGAIN = 5,
74     /**
75      * This side data contains a 3x3 transformation matrix describing an affine
76      * transformation that needs to be applied to the frame for correct
77      * presentation.
78      *
79      * See libavutil/display.h for a detailed description of the data.
80      */
81     AV_FRAME_DATA_DISPLAYMATRIX = 6,
82     /**
83      * Active Format Description data consisting of a single byte as specified
84      * in ETSI TS 101 154 using AVActiveFormatDescription enum.
85      */
86     AV_FRAME_DATA_AFD = 7,
87     /**
88      * Motion vectors exported by some codecs (on demand through the export_mvs
89      * flag set in the libavcodec AVCodecContext flags2 option).
90      * The data is the AVMotionVector struct defined in
91      * libavutil/motion_vector.h.
92      */
93     AV_FRAME_DATA_MOTION_VECTORS = 8,
94     /**
95      * Recommmends skipping the specified number of samples. This is exported
96      * only if the "skip_manual" AVOption is set in libavcodec.
97      * This has the same format as AV_PKT_DATA_SKIP_SAMPLES.
98      * @code
99      * u32le number of samples to skip from start of this packet
100      * u32le number of samples to skip from end of this packet
101      * u8    reason for start skip
102      * u8    reason for end   skip (0=padding silence, 1=convergence)
103      * @endcode
104      */
105     AV_FRAME_DATA_SKIP_SAMPLES = 9,
106     /**
107      * This side data must be associated with an audio frame and corresponds to
108      * enum AVAudioServiceType defined in avcodec.h.
109      */
110     AV_FRAME_DATA_AUDIO_SERVICE_TYPE = 10,
111     /**
112      * Mastering display metadata associated with a video frame. The payload is
113      * an AVMasteringDisplayMetadata type and contains information about the
114      * mastering display color volume.
115      */
116     AV_FRAME_DATA_MASTERING_DISPLAY_METADATA = 11,
117     /**
118      * The GOP timecode in 25 bit timecode format. Data format is 64-bit integer.
119      * This is set on the first frame of a GOP that has a temporal reference of 0.
120      */
121     AV_FRAME_DATA_GOP_TIMECODE = 12,
122 
123     /**
124      * The data represents the AVSphericalMapping structure defined in
125      * libavutil/spherical.h.
126      */
127     AV_FRAME_DATA_SPHERICAL = 13,
128 
129     /**
130      * Content light level (based on CTA-861.3). This payload contains data in
131      * the form of the AVContentLightMetadata struct.
132      */
133     AV_FRAME_DATA_CONTENT_LIGHT_LEVEL = 14,
134 
135     /**
136      * The data contains an ICC profile as an opaque octet buffer following the
137      * format described by ISO 15076-1 with an optional name defined in the
138      * metadata key entry "name".
139      */
140     AV_FRAME_DATA_ICC_PROFILE = 15,
141 
142     /**
143      * Implementation-specific description of the format of AV_FRAME_QP_TABLE_DATA.
144      * The contents of this side data are undocumented and internal; use
145      * av_frame_set_qp_table() and av_frame_get_qp_table() to access this in a
146      * meaningful way instead.
147      */
148     AV_FRAME_DATA_QP_TABLE_PROPERTIES = 16,
149 
150     /**
151      * Raw QP table data. Its format is described by
152      * AV_FRAME_DATA_QP_TABLE_PROPERTIES. Use av_frame_set_qp_table() and
153      * av_frame_get_qp_table() to access this instead.
154      */
155     AV_FRAME_DATA_QP_TABLE_DATA = 17,
156 
157     /**
158      * Timecode which conforms to SMPTE ST 12-1. The data is an array of 4 uint32_t
159      * where the first uint32_t describes how many (1-3) of the other timecodes are used.
160      * The timecode format is described in the av_timecode_get_smpte_from_framenum()
161      * function in libavutil/timecode.c.
162      */
163     AV_FRAME_DATA_S12M_TIMECODE = 18
164 }
165 
166 enum AVActiveFormatDescription
167 {
168     AV_AFD_SAME = 8,
169     AV_AFD_4_3 = 9,
170     AV_AFD_16_9 = 10,
171     AV_AFD_14_9 = 11,
172     AV_AFD_4_3_SP_14_9 = 13,
173     AV_AFD_16_9_SP_14_9 = 14,
174     AV_AFD_SP_4_3 = 15
175 }
176 
177 /**
178  * Structure to hold side data for an AVFrame.
179  *
180  * sizeof(AVFrameSideData) is not a part of the public ABI, so new fields may be added
181  * to the end with a minor bump.
182  */
183 struct AVFrameSideData
184 {
185     AVFrameSideDataType type;
186     ubyte* data;
187     int size;
188     AVDictionary* metadata;
189     AVBufferRef* buf;
190 }
191 
192 /**
193  * This structure describes decoded (raw) audio or video data.
194  *
195  * AVFrame must be allocated using av_frame_alloc(). Note that this only
196  * allocates the AVFrame itself, the buffers for the data must be managed
197  * through other means (see below).
198  * AVFrame must be freed with av_frame_free().
199  *
200  * AVFrame is typically allocated once and then reused multiple times to hold
201  * different data (e.g. a single AVFrame to hold frames received from a
202  * decoder). In such a case, av_frame_unref() will free any references held by
203  * the frame and reset it to its original clean state before it
204  * is reused again.
205  *
206  * The data described by an AVFrame is usually reference counted through the
207  * AVBuffer API. The underlying buffer references are stored in AVFrame.buf /
208  * AVFrame.extended_buf. An AVFrame is considered to be reference counted if at
209  * least one reference is set, i.e. if AVFrame.buf[0] != NULL. In such a case,
210  * every single data plane must be contained in one of the buffers in
211  * AVFrame.buf or AVFrame.extended_buf.
212  * There may be a single buffer for all the data, or one separate buffer for
213  * each plane, or anything in between.
214  *
215  * sizeof(AVFrame) is not a part of the public ABI, so new fields may be added
216  * to the end with a minor bump.
217  *
218  * Fields can be accessed through AVOptions, the name string used, matches the
219  * C structure field name for fields accessible through AVOptions. The AVClass
220  * for AVFrame can be obtained from avcodec_get_frame_class()
221  */
222 struct AVFrame
223 {
224     /**
225      * pointer to the picture/channel planes.
226      * This might be different from the first allocated byte
227      *
228      * Some decoders access areas outside 0,0 - width,height, please
229      * see avcodec_align_dimensions2(). Some filters and swscale can read
230      * up to 16 bytes beyond the planes, if these filters are to be used,
231      * then 16 extra bytes must be allocated.
232      *
233      * NOTE: Except for hwaccel formats, pointers not needed by the format
234      * MUST be set to NULL.
235      */
236     ubyte*[AV_NUM_DATA_POINTERS] data;
237 
238     /**
239      * For video, size in bytes of each picture line.
240      * For audio, size in bytes of each plane.
241      *
242      * For audio, only linesize[0] may be set. For planar audio, each channel
243      * plane must be the same size.
244      *
245      * For video the linesizes should be multiples of the CPUs alignment
246      * preference, this is 16 or 32 for modern desktop CPUs.
247      * Some code requires such alignment other code can be slower without
248      * correct alignment, for yet other it makes no difference.
249      *
250      * @note The linesize may be larger than the size of usable data -- there
251      * may be extra padding present for performance reasons.
252      */
253     int[AV_NUM_DATA_POINTERS] linesize;
254 
255     /**
256      * pointers to the data planes/channels.
257      *
258      * For video, this should simply point to data[].
259      *
260      * For planar audio, each channel has a separate data pointer, and
261      * linesize[0] contains the size of each channel buffer.
262      * For packed audio, there is just one data pointer, and linesize[0]
263      * contains the total size of the buffer for all channels.
264      *
265      * Note: Both data and extended_data should always be set in a valid frame,
266      * but for planar audio with more channels that can fit in data,
267      * extended_data must be used in order to access all channels.
268      */
269     ubyte** extended_data;
270 
271     /**
272      * @name Video dimensions
273      * Video frames only. The coded dimensions (in pixels) of the video frame,
274      * i.e. the size of the rectangle that contains some well-defined values.
275      *
276      * @note The part of the frame intended for display/presentation is further
277      * restricted by the @ref cropping "Cropping rectangle".
278      * @{
279      */
280     int width;
281     int height;
282     /**
283      * @}
284      */
285 
286     /**
287      * number of audio samples (per channel) described by this frame
288      */
289     int nb_samples;
290 
291     /**
292      * format of the frame, -1 if unknown or unset
293      * Values correspond to enum AVPixelFormat for video frames,
294      * enum AVSampleFormat for audio)
295      */
296     int format;
297 
298     /**
299      * 1 -> keyframe, 0-> not
300      */
301     int key_frame;
302 
303     /**
304      * Picture type of the frame.
305      */
306     AVPictureType pict_type;
307 
308     /**
309      * Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
310      */
311     AVRational sample_aspect_ratio;
312 
313     /**
314      * Presentation timestamp in time_base units (time when frame should be shown to user).
315      */
316     long pts;
317 
318     /**
319      * PTS copied from the AVPacket that was decoded to produce this frame.
320      * @deprecated use the pts field instead
321      */
322     long pkt_pts;
323 
324     /**
325      * DTS copied from the AVPacket that triggered returning this frame. (if frame threading isn't used)
326      * This is also the Presentation time of this AVFrame calculated from
327      * only AVPacket.dts values without pts values.
328      */
329     long pkt_dts;
330 
331     /**
332      * picture number in bitstream order
333      */
334     int coded_picture_number;
335     /**
336      * picture number in display order
337      */
338     int display_picture_number;
339 
340     /**
341      * quality (between 1 (good) and FF_LAMBDA_MAX (bad))
342      */
343     int quality;
344 
345     /**
346      * for some private data of the user
347      */
348     void* opaque;
349 
350     /**
351      * @deprecated unused
352      */
353     ulong[AV_NUM_DATA_POINTERS] error;
354 
355     /**
356      * When decoding, this signals how much the picture must be delayed.
357      * extra_delay = repeat_pict / (2*fps)
358      */
359     int repeat_pict;
360 
361     /**
362      * The content of the picture is interlaced.
363      */
364     int interlaced_frame;
365 
366     /**
367      * If the content is interlaced, is top field displayed first.
368      */
369     int top_field_first;
370 
371     /**
372      * Tell user application that palette has changed from previous frame.
373      */
374     int palette_has_changed;
375 
376     /**
377      * reordered opaque 64 bits (generally an integer or a double precision float
378      * PTS but can be anything).
379      * The user sets AVCodecContext.reordered_opaque to represent the input at
380      * that time,
381      * the decoder reorders values as needed and sets AVFrame.reordered_opaque
382      * to exactly one of the values provided by the user through AVCodecContext.reordered_opaque
383      * @deprecated in favor of pkt_pts
384      */
385     long reordered_opaque;
386 
387     /**
388      * Sample rate of the audio data.
389      */
390     int sample_rate;
391 
392     /**
393      * Channel layout of the audio data.
394      */
395     ulong channel_layout;
396 
397     /**
398      * AVBuffer references backing the data for this frame. If all elements of
399      * this array are NULL, then this frame is not reference counted. This array
400      * must be filled contiguously -- if buf[i] is non-NULL then buf[j] must
401      * also be non-NULL for all j < i.
402      *
403      * There may be at most one AVBuffer per data plane, so for video this array
404      * always contains all the references. For planar audio with more than
405      * AV_NUM_DATA_POINTERS channels, there may be more buffers than can fit in
406      * this array. Then the extra AVBufferRef pointers are stored in the
407      * extended_buf array.
408      */
409     AVBufferRef*[AV_NUM_DATA_POINTERS] buf;
410 
411     /**
412      * For planar audio which requires more than AV_NUM_DATA_POINTERS
413      * AVBufferRef pointers, this array will hold all the references which
414      * cannot fit into AVFrame.buf.
415      *
416      * Note that this is different from AVFrame.extended_data, which always
417      * contains all the pointers. This array only contains the extra pointers,
418      * which cannot fit into AVFrame.buf.
419      *
420      * This array is always allocated using av_malloc() by whoever constructs
421      * the frame. It is freed in av_frame_unref().
422      */
423     AVBufferRef** extended_buf;
424     /**
425      * Number of elements in extended_buf.
426      */
427     int nb_extended_buf;
428 
429     AVFrameSideData** side_data;
430     int nb_side_data;
431 
432     /**
433      * @defgroup lavu_frame_flags AV_FRAME_FLAGS
434      * @ingroup lavu_frame
435      * Flags describing additional frame properties.
436      *
437      * @{
438      */
439 
440     /**
441      * The frame data may be corrupted, e.g. due to decoding errors.
442      */
443 
444     /**
445      * A flag to mark the frames which need to be decoded, but shouldn't be output.
446      */
447 
448     /**
449      * @}
450      */
451 
452     /**
453      * Frame flags, a combination of @ref lavu_frame_flags
454      */
455     int flags;
456 
457     /**
458      * MPEG vs JPEG YUV range.
459      * - encoding: Set by user
460      * - decoding: Set by libavcodec
461      */
462     AVColorRange color_range;
463 
464     AVColorPrimaries color_primaries;
465 
466     AVColorTransferCharacteristic color_trc;
467 
468     /**
469      * YUV colorspace type.
470      * - encoding: Set by user
471      * - decoding: Set by libavcodec
472      */
473     AVColorSpace colorspace;
474 
475     AVChromaLocation chroma_location;
476 
477     /**
478      * frame timestamp estimated using various heuristics, in stream time base
479      * - encoding: unused
480      * - decoding: set by libavcodec, read by user.
481      */
482     long best_effort_timestamp;
483 
484     /**
485      * reordered pos from the last AVPacket that has been input into the decoder
486      * - encoding: unused
487      * - decoding: Read by user.
488      */
489     long pkt_pos;
490 
491     /**
492      * duration of the corresponding packet, expressed in
493      * AVStream->time_base units, 0 if unknown.
494      * - encoding: unused
495      * - decoding: Read by user.
496      */
497     long pkt_duration;
498 
499     /**
500      * metadata.
501      * - encoding: Set by user.
502      * - decoding: Set by libavcodec.
503      */
504     AVDictionary* metadata;
505 
506     /**
507      * decode error flags of the frame, set to a combination of
508      * FF_DECODE_ERROR_xxx flags if the decoder produced a frame, but there
509      * were errors during the decoding.
510      * - encoding: unused
511      * - decoding: set by libavcodec, read by user.
512      */
513     int decode_error_flags;
514 
515     /**
516      * number of audio channels, only used for audio.
517      * - encoding: unused
518      * - decoding: Read by user.
519      */
520     int channels;
521 
522     /**
523      * size of the corresponding packet containing the compressed
524      * frame.
525      * It is set to a negative value if unknown.
526      * - encoding: unused
527      * - decoding: set by libavcodec, read by user.
528      */
529     int pkt_size;
530 
531     /**
532      * QP table
533      */
534     byte* qscale_table;
535     /**
536      * QP store stride
537      */
538     int qstride;
539 
540     int qscale_type;
541 
542     AVBufferRef* qp_table_buf;
543 
544     /**
545      * For hwaccel-format frames, this should be a reference to the
546      * AVHWFramesContext describing the frame.
547      */
548     AVBufferRef* hw_frames_ctx;
549 
550     /**
551      * AVBufferRef for free use by the API user. FFmpeg will never check the
552      * contents of the buffer ref. FFmpeg calls av_buffer_unref() on it when
553      * the frame is unreferenced. av_frame_copy_props() calls create a new
554      * reference with av_buffer_ref() for the target frame's opaque_ref field.
555      *
556      * This is unrelated to the opaque field, although it serves a similar
557      * purpose.
558      */
559     AVBufferRef* opaque_ref;
560 
561     /**
562      * @anchor cropping
563      * @name Cropping
564      * Video frames only. The number of pixels to discard from the the
565      * top/bottom/left/right border of the frame to obtain the sub-rectangle of
566      * the frame intended for presentation.
567      * @{
568      */
569     size_t crop_top;
570     size_t crop_bottom;
571     size_t crop_left;
572     size_t crop_right;
573     /**
574      * @}
575      */
576 
577     /**
578      * AVBufferRef for internal use by a single libav* library.
579      * Must not be used to transfer data between libraries.
580      * Has to be NULL when ownership of the frame leaves the respective library.
581      *
582      * Code outside the FFmpeg libs should never check or change the contents of the buffer ref.
583      *
584      * FFmpeg calls av_buffer_unref() on it when the frame is unreferenced.
585      * av_frame_copy_props() calls create a new reference with av_buffer_ref()
586      * for the target frame's private_ref field.
587      */
588     AVBufferRef* private_ref;
589 }
590 
591 enum AV_NUM_DATA_POINTERS = 8;
592 enum AV_FRAME_FLAG_CORRUPT = 1 << 0;
593 enum AV_FRAME_FLAG_DISCARD = 1 << 2;
594 enum FF_DECODE_ERROR_INVALID_BITSTREAM = 1;
595 enum FF_DECODE_ERROR_MISSING_REFERENCE = 2;
596 
597 /**
598  * Accessors for some AVFrame fields. These used to be provided for ABI
599  * compatibility, and do not need to be used anymore.
600  */
601 long av_frame_get_best_effort_timestamp (const(AVFrame)* frame);
602 void av_frame_set_best_effort_timestamp (AVFrame* frame, long val);
603 long av_frame_get_pkt_duration (const(AVFrame)* frame);
604 void av_frame_set_pkt_duration (AVFrame* frame, long val);
605 long av_frame_get_pkt_pos (const(AVFrame)* frame);
606 void av_frame_set_pkt_pos (AVFrame* frame, long val);
607 long av_frame_get_channel_layout (const(AVFrame)* frame);
608 void av_frame_set_channel_layout (AVFrame* frame, long val);
609 int av_frame_get_channels (const(AVFrame)* frame);
610 void av_frame_set_channels (AVFrame* frame, int val);
611 int av_frame_get_sample_rate (const(AVFrame)* frame);
612 void av_frame_set_sample_rate (AVFrame* frame, int val);
613 AVDictionary* av_frame_get_metadata (const(AVFrame)* frame);
614 void av_frame_set_metadata (AVFrame* frame, AVDictionary* val);
615 int av_frame_get_decode_error_flags (const(AVFrame)* frame);
616 void av_frame_set_decode_error_flags (AVFrame* frame, int val);
617 int av_frame_get_pkt_size (const(AVFrame)* frame);
618 void av_frame_set_pkt_size (AVFrame* frame, int val);
619 byte* av_frame_get_qp_table (AVFrame* f, int* stride, int* type);
620 int av_frame_set_qp_table (AVFrame* f, AVBufferRef* buf, int stride, int type);
621 
622 AVColorSpace av_frame_get_colorspace (const(AVFrame)* frame);
623 void av_frame_set_colorspace (AVFrame* frame, AVColorSpace val);
624 AVColorRange av_frame_get_color_range (const(AVFrame)* frame);
625 void av_frame_set_color_range (AVFrame* frame, AVColorRange val);
626 
627 /**
628  * Get the name of a colorspace.
629  * @return a static string identifying the colorspace; can be NULL.
630  */
631 const(char)* av_get_colorspace_name (AVColorSpace val);
632 
633 /**
634  * Allocate an AVFrame and set its fields to default values.  The resulting
635  * struct must be freed using av_frame_free().
636  *
637  * @return An AVFrame filled with default values or NULL on failure.
638  *
639  * @note this only allocates the AVFrame itself, not the data buffers. Those
640  * must be allocated through other means, e.g. with av_frame_get_buffer() or
641  * manually.
642  */
643 AVFrame* av_frame_alloc ();
644 
645 /**
646  * Free the frame and any dynamically allocated objects in it,
647  * e.g. extended_data. If the frame is reference counted, it will be
648  * unreferenced first.
649  *
650  * @param frame frame to be freed. The pointer will be set to NULL.
651  */
652 void av_frame_free (AVFrame** frame);
653 
654 /**
655  * Set up a new reference to the data described by the source frame.
656  *
657  * Copy frame properties from src to dst and create a new reference for each
658  * AVBufferRef from src.
659  *
660  * If src is not reference counted, new buffers are allocated and the data is
661  * copied.
662  *
663  * @warning: dst MUST have been either unreferenced with av_frame_unref(dst),
664  *           or newly allocated with av_frame_alloc() before calling this
665  *           function, or undefined behavior will occur.
666  *
667  * @return 0 on success, a negative AVERROR on error
668  */
669 int av_frame_ref (AVFrame* dst, const(AVFrame)* src);
670 
671 /**
672  * Create a new frame that references the same data as src.
673  *
674  * This is a shortcut for av_frame_alloc()+av_frame_ref().
675  *
676  * @return newly created AVFrame on success, NULL on error.
677  */
678 AVFrame* av_frame_clone (const(AVFrame)* src);
679 
680 /**
681  * Unreference all the buffers referenced by frame and reset the frame fields.
682  */
683 void av_frame_unref (AVFrame* frame);
684 
685 /**
686  * Move everything contained in src to dst and reset src.
687  *
688  * @warning: dst is not unreferenced, but directly overwritten without reading
689  *           or deallocating its contents. Call av_frame_unref(dst) manually
690  *           before calling this function to ensure that no memory is leaked.
691  */
692 void av_frame_move_ref (AVFrame* dst, AVFrame* src);
693 
694 /**
695  * Allocate new buffer(s) for audio or video data.
696  *
697  * The following fields must be set on frame before calling this function:
698  * - format (pixel format for video, sample format for audio)
699  * - width and height for video
700  * - nb_samples and channel_layout for audio
701  *
702  * This function will fill AVFrame.data and AVFrame.buf arrays and, if
703  * necessary, allocate and fill AVFrame.extended_data and AVFrame.extended_buf.
704  * For planar formats, one buffer will be allocated for each plane.
705  *
706  * @warning: if frame already has been allocated, calling this function will
707  *           leak memory. In addition, undefined behavior can occur in certain
708  *           cases.
709  *
710  * @param frame frame in which to store the new buffers.
711  * @param align Required buffer size alignment. If equal to 0, alignment will be
712  *              chosen automatically for the current CPU. It is highly
713  *              recommended to pass 0 here unless you know what you are doing.
714  *
715  * @return 0 on success, a negative AVERROR on error.
716  */
717 int av_frame_get_buffer (AVFrame* frame, int align_);
718 
719 /**
720  * Check if the frame data is writable.
721  *
722  * @return A positive value if the frame data is writable (which is true if and
723  * only if each of the underlying buffers has only one reference, namely the one
724  * stored in this frame). Return 0 otherwise.
725  *
726  * If 1 is returned the answer is valid until av_buffer_ref() is called on any
727  * of the underlying AVBufferRefs (e.g. through av_frame_ref() or directly).
728  *
729  * @see av_frame_make_writable(), av_buffer_is_writable()
730  */
731 int av_frame_is_writable (AVFrame* frame);
732 
733 /**
734  * Ensure that the frame data is writable, avoiding data copy if possible.
735  *
736  * Do nothing if the frame is writable, allocate new buffers and copy the data
737  * if it is not.
738  *
739  * @return 0 on success, a negative AVERROR on error.
740  *
741  * @see av_frame_is_writable(), av_buffer_is_writable(),
742  * av_buffer_make_writable()
743  */
744 int av_frame_make_writable (AVFrame* frame);
745 
746 /**
747  * Copy the frame data from src to dst.
748  *
749  * This function does not allocate anything, dst must be already initialized and
750  * allocated with the same parameters as src.
751  *
752  * This function only copies the frame data (i.e. the contents of the data /
753  * extended data arrays), not any other properties.
754  *
755  * @return >= 0 on success, a negative AVERROR on error.
756  */
757 int av_frame_copy (AVFrame* dst, const(AVFrame)* src);
758 
759 /**
760  * Copy only "metadata" fields from src to dst.
761  *
762  * Metadata for the purpose of this function are those fields that do not affect
763  * the data layout in the buffers.  E.g. pts, sample rate (for audio) or sample
764  * aspect ratio (for video), but not width/height or channel layout.
765  * Side data is also copied.
766  */
767 int av_frame_copy_props (AVFrame* dst, const(AVFrame)* src);
768 
769 /**
770  * Get the buffer reference a given data plane is stored in.
771  *
772  * @param plane index of the data plane of interest in frame->extended_data.
773  *
774  * @return the buffer reference that contains the plane or NULL if the input
775  * frame is not valid.
776  */
777 AVBufferRef* av_frame_get_plane_buffer (AVFrame* frame, int plane);
778 
779 /**
780  * Add a new side data to a frame.
781  *
782  * @param frame a frame to which the side data should be added
783  * @param type type of the added side data
784  * @param size size of the side data
785  *
786  * @return newly added side data on success, NULL on error
787  */
788 AVFrameSideData* av_frame_new_side_data (
789     AVFrame* frame,
790     AVFrameSideDataType type,
791     int size);
792 
793 /**
794  * Add a new side data to a frame from an existing AVBufferRef
795  *
796  * @param frame a frame to which the side data should be added
797  * @param type  the type of the added side data
798  * @param buf   an AVBufferRef to add as side data. The ownership of
799  *              the reference is transferred to the frame.
800  *
801  * @return newly added side data on success, NULL on error. On failure
802  *         the frame is unchanged and the AVBufferRef remains owned by
803  *         the caller.
804  */
805 AVFrameSideData* av_frame_new_side_data_from_buf (
806     AVFrame* frame,
807     AVFrameSideDataType type,
808     AVBufferRef* buf);
809 
810 /**
811  * @return a pointer to the side data of a given type on success, NULL if there
812  * is no side data with such type in this frame.
813  */
814 AVFrameSideData* av_frame_get_side_data (
815     const(AVFrame)* frame,
816     AVFrameSideDataType type);
817 
818 /**
819  * If side data of the supplied type exists in the frame, free it and remove it
820  * from the frame.
821  */
822 void av_frame_remove_side_data (AVFrame* frame, AVFrameSideDataType type);
823 
824 /**
825  * Flags for frame cropping.
826  */
827 enum
828 {
829     /**
830      * Apply the maximum possible cropping, even if it requires setting the
831      * AVFrame.data[] entries to unaligned pointers. Passing unaligned data
832      * to FFmpeg API is generally not allowed, and causes undefined behavior
833      * (such as crashes). You can pass unaligned data only to FFmpeg APIs that
834      * are explicitly documented to accept it. Use this flag only if you
835      * absolutely know what you are doing.
836      */
837     AV_FRAME_CROP_UNALIGNED = 1 << 0
838 }
839 
840 /**
841  * Crop the given video AVFrame according to its crop_left/crop_top/crop_right/
842  * crop_bottom fields. If cropping is successful, the function will adjust the
843  * data pointers and the width/height fields, and set the crop fields to 0.
844  *
845  * In all cases, the cropping boundaries will be rounded to the inherent
846  * alignment of the pixel format. In some cases, such as for opaque hwaccel
847  * formats, the left/top cropping is ignored. The crop fields are set to 0 even
848  * if the cropping was rounded or ignored.
849  *
850  * @param frame the frame which should be cropped
851  * @param flags Some combination of AV_FRAME_CROP_* flags, or 0.
852  *
853  * @return >= 0 on success, a negative AVERROR on error. If the cropping fields
854  * were invalid, AVERROR(ERANGE) is returned, and nothing is changed.
855  */
856 int av_frame_apply_cropping (AVFrame* frame, int flags);
857 
858 /**
859  * @return a string identifying the side data type
860  */
861 const(char)* av_frame_side_data_name (AVFrameSideDataType type);
862 
863 /**
864  * @}
865  */
866 
867 /* AVUTIL_FRAME_H */