frame.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. /*
  2. *
  3. * This file is part of FFmpeg.
  4. *
  5. * FFmpeg is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * FFmpeg is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with FFmpeg; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. /**
  20. * @file
  21. * @ingroup lavu_frame
  22. * reference-counted frame API
  23. */
  24. #ifndef AVUTIL_FRAME_H
  25. #define AVUTIL_FRAME_H
  26. #include <stdint.h>
  27. #include "avutil.h"
  28. #include "buffer.h"
  29. #include "dict.h"
  30. #include "rational.h"
  31. #include "samplefmt.h"
  32. #include "pixfmt.h"
  33. #include "version.h"
  34. /**
  35. * @defgroup lavu_frame AVFrame
  36. * @ingroup lavu_data
  37. *
  38. * @{
  39. * AVFrame is an abstraction for reference-counted raw multimedia data.
  40. */
  41. enum AVFrameSideDataType {
  42. /**
  43. * The data is the AVPanScan struct defined in libavcodec.
  44. */
  45. AV_FRAME_DATA_PANSCAN,
  46. /**
  47. * ATSC A53 Part 4 Closed Captions.
  48. * A53 CC bitstream is stored as uint8_t in AVFrameSideData.data.
  49. * The number of bytes of CC data is AVFrameSideData.size.
  50. */
  51. AV_FRAME_DATA_A53_CC,
  52. /**
  53. * Stereoscopic 3d metadata.
  54. * The data is the AVStereo3D struct defined in libavutil/stereo3d.h.
  55. */
  56. AV_FRAME_DATA_STEREO3D,
  57. /**
  58. * The data is the AVMatrixEncoding enum defined in libavutil/channel_layout.h.
  59. */
  60. AV_FRAME_DATA_MATRIXENCODING,
  61. /**
  62. * Metadata relevant to a downmix procedure.
  63. * The data is the AVDownmixInfo struct defined in libavutil/downmix_info.h.
  64. */
  65. AV_FRAME_DATA_DOWNMIX_INFO,
  66. /**
  67. * ReplayGain information in the form of the AVReplayGain struct.
  68. */
  69. AV_FRAME_DATA_REPLAYGAIN,
  70. /**
  71. * This side data contains a 3x3 transformation matrix describing an affine
  72. * transformation that needs to be applied to the frame for correct
  73. * presentation.
  74. *
  75. * See libavutil/display.h for a detailed description of the data.
  76. */
  77. AV_FRAME_DATA_DISPLAYMATRIX,
  78. /**
  79. * Active Format Description data consisting of a single byte as specified
  80. * in ETSI TS 101 154 using AVActiveFormatDescription enum.
  81. */
  82. AV_FRAME_DATA_AFD,
  83. /**
  84. * Motion vectors exported by some codecs (on demand through the export_mvs
  85. * flag set in the libavcodec AVCodecContext flags2 option).
  86. * The data is the AVMotionVector struct defined in
  87. * libavutil/motion_vector.h.
  88. */
  89. AV_FRAME_DATA_MOTION_VECTORS,
  90. /**
  91. * Recommmends skipping the specified number of samples. This is exported
  92. * only if the "skip_manual" AVOption is set in libavcodec.
  93. * This has the same format as AV_PKT_DATA_SKIP_SAMPLES.
  94. * @code
  95. * u32le number of samples to skip from start of this packet
  96. * u32le number of samples to skip from end of this packet
  97. * u8 reason for start skip
  98. * u8 reason for end skip (0=padding silence, 1=convergence)
  99. * @endcode
  100. */
  101. AV_FRAME_DATA_SKIP_SAMPLES,
  102. };
  103. enum AVActiveFormatDescription {
  104. AV_AFD_SAME = 8,
  105. AV_AFD_4_3 = 9,
  106. AV_AFD_16_9 = 10,
  107. AV_AFD_14_9 = 11,
  108. AV_AFD_4_3_SP_14_9 = 13,
  109. AV_AFD_16_9_SP_14_9 = 14,
  110. AV_AFD_SP_4_3 = 15,
  111. };
  112. typedef struct AVFrameSideData {
  113. enum AVFrameSideDataType type;
  114. uint8_t *data;
  115. int size;
  116. AVDictionary *metadata;
  117. } AVFrameSideData;
  118. /**
  119. * This structure describes decoded (raw) audio or video data.
  120. *
  121. * AVFrame must be allocated using av_frame_alloc(). Note that this only
  122. * allocates the AVFrame itself, the buffers for the data must be managed
  123. * through other means (see below).
  124. * AVFrame must be freed with av_frame_free().
  125. *
  126. * AVFrame is typically allocated once and then reused multiple times to hold
  127. * different data (e.g. a single AVFrame to hold frames received from a
  128. * decoder). In such a case, av_frame_unref() will free any references held by
  129. * the frame and reset it to its original clean state before it
  130. * is reused again.
  131. *
  132. * The data described by an AVFrame is usually reference counted through the
  133. * AVBuffer API. The underlying buffer references are stored in AVFrame.buf /
  134. * AVFrame.extended_buf. An AVFrame is considered to be reference counted if at
  135. * least one reference is set, i.e. if AVFrame.buf[0] != NULL. In such a case,
  136. * every single data plane must be contained in one of the buffers in
  137. * AVFrame.buf or AVFrame.extended_buf.
  138. * There may be a single buffer for all the data, or one separate buffer for
  139. * each plane, or anything in between.
  140. *
  141. * sizeof(AVFrame) is not a part of the public ABI, so new fields may be added
  142. * to the end with a minor bump.
  143. * Similarly fields that are marked as to be only accessed by
  144. * av_opt_ptr() can be reordered. This allows 2 forks to add fields
  145. * without breaking compatibility with each other.
  146. */
  147. typedef struct AVFrame {
  148. #define AV_NUM_DATA_POINTERS 8
  149. /**
  150. * pointer to the picture/channel planes.
  151. * This might be different from the first allocated byte
  152. *
  153. * Some decoders access areas outside 0,0 - width,height, please
  154. * see avcodec_align_dimensions2(). Some filters and swscale can read
  155. * up to 16 bytes beyond the planes, if these filters are to be used,
  156. * then 16 extra bytes must be allocated.
  157. */
  158. uint8_t *data[AV_NUM_DATA_POINTERS];
  159. /**
  160. * For video, size in bytes of each picture line.
  161. * For audio, size in bytes of each plane.
  162. *
  163. * For audio, only linesize[0] may be set. For planar audio, each channel
  164. * plane must be the same size.
  165. *
  166. * For video the linesizes should be multiples of the CPUs alignment
  167. * preference, this is 16 or 32 for modern desktop CPUs.
  168. * Some code requires such alignment other code can be slower without
  169. * correct alignment, for yet other it makes no difference.
  170. *
  171. * @note The linesize may be larger than the size of usable data -- there
  172. * may be extra padding present for performance reasons.
  173. */
  174. int linesize[AV_NUM_DATA_POINTERS];
  175. /**
  176. * pointers to the data planes/channels.
  177. *
  178. * For video, this should simply point to data[].
  179. *
  180. * For planar audio, each channel has a separate data pointer, and
  181. * linesize[0] contains the size of each channel buffer.
  182. * For packed audio, there is just one data pointer, and linesize[0]
  183. * contains the total size of the buffer for all channels.
  184. *
  185. * Note: Both data and extended_data should always be set in a valid frame,
  186. * but for planar audio with more channels that can fit in data,
  187. * extended_data must be used in order to access all channels.
  188. */
  189. uint8_t **extended_data;
  190. /**
  191. * width and height of the video frame
  192. */
  193. int width, height;
  194. /**
  195. * number of audio samples (per channel) described by this frame
  196. */
  197. int nb_samples;
  198. /**
  199. * format of the frame, -1 if unknown or unset
  200. * Values correspond to enum AVPixelFormat for video frames,
  201. * enum AVSampleFormat for audio)
  202. */
  203. int format;
  204. /**
  205. * 1 -> keyframe, 0-> not
  206. */
  207. int key_frame;
  208. /**
  209. * Picture type of the frame.
  210. */
  211. enum AVPictureType pict_type;
  212. #if FF_API_AVFRAME_LAVC
  213. attribute_deprecated
  214. uint8_t *base[AV_NUM_DATA_POINTERS];
  215. #endif
  216. /**
  217. * Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
  218. */
  219. AVRational sample_aspect_ratio;
  220. /**
  221. * Presentation timestamp in time_base units (time when frame should be shown to user).
  222. */
  223. int64_t pts;
  224. /**
  225. * PTS copied from the AVPacket that was decoded to produce this frame.
  226. */
  227. int64_t pkt_pts;
  228. /**
  229. * DTS copied from the AVPacket that triggered returning this frame. (if frame threading isn't used)
  230. * This is also the Presentation time of this AVFrame calculated from
  231. * only AVPacket.dts values without pts values.
  232. */
  233. int64_t pkt_dts;
  234. /**
  235. * picture number in bitstream order
  236. */
  237. int coded_picture_number;
  238. /**
  239. * picture number in display order
  240. */
  241. int display_picture_number;
  242. /**
  243. * quality (between 1 (good) and FF_LAMBDA_MAX (bad))
  244. */
  245. int quality;
  246. #if FF_API_AVFRAME_LAVC
  247. attribute_deprecated
  248. int reference;
  249. /**
  250. * QP table
  251. */
  252. attribute_deprecated
  253. int8_t *qscale_table;
  254. /**
  255. * QP store stride
  256. */
  257. attribute_deprecated
  258. int qstride;
  259. attribute_deprecated
  260. int qscale_type;
  261. /**
  262. * mbskip_table[mb]>=1 if MB didn't change
  263. * stride= mb_width = (width+15)>>4
  264. */
  265. attribute_deprecated
  266. uint8_t *mbskip_table;
  267. /**
  268. * motion vector table
  269. * @code
  270. * example:
  271. * int mv_sample_log2= 4 - motion_subsample_log2;
  272. * int mb_width= (width+15)>>4;
  273. * int mv_stride= (mb_width << mv_sample_log2) + 1;
  274. * motion_val[direction][x + y*mv_stride][0->mv_x, 1->mv_y];
  275. * @endcode
  276. */
  277. int16_t (*motion_val[2])[2];
  278. /**
  279. * macroblock type table
  280. * mb_type_base + mb_width + 2
  281. */
  282. attribute_deprecated
  283. uint32_t *mb_type;
  284. /**
  285. * DCT coefficients
  286. */
  287. attribute_deprecated
  288. short *dct_coeff;
  289. /**
  290. * motion reference frame index
  291. * the order in which these are stored can depend on the codec.
  292. */
  293. attribute_deprecated
  294. int8_t *ref_index[2];
  295. #endif
  296. /**
  297. * for some private data of the user
  298. */
  299. void *opaque;
  300. /**
  301. * error
  302. */
  303. uint64_t error[AV_NUM_DATA_POINTERS];
  304. #if FF_API_AVFRAME_LAVC
  305. attribute_deprecated
  306. int type;
  307. #endif
  308. /**
  309. * When decoding, this signals how much the picture must be delayed.
  310. * extra_delay = repeat_pict / (2*fps)
  311. */
  312. int repeat_pict;
  313. /**
  314. * The content of the picture is interlaced.
  315. */
  316. int interlaced_frame;
  317. /**
  318. * If the content is interlaced, is top field displayed first.
  319. */
  320. int top_field_first;
  321. /**
  322. * Tell user application that palette has changed from previous frame.
  323. */
  324. int palette_has_changed;
  325. #if FF_API_AVFRAME_LAVC
  326. attribute_deprecated
  327. int buffer_hints;
  328. /**
  329. * Pan scan.
  330. */
  331. attribute_deprecated
  332. struct AVPanScan *pan_scan;
  333. #endif
  334. /**
  335. * reordered opaque 64bit (generally an integer or a double precision float
  336. * PTS but can be anything).
  337. * The user sets AVCodecContext.reordered_opaque to represent the input at
  338. * that time,
  339. * the decoder reorders values as needed and sets AVFrame.reordered_opaque
  340. * to exactly one of the values provided by the user through AVCodecContext.reordered_opaque
  341. * @deprecated in favor of pkt_pts
  342. */
  343. int64_t reordered_opaque;
  344. #if FF_API_AVFRAME_LAVC
  345. /**
  346. * @deprecated this field is unused
  347. */
  348. attribute_deprecated void *hwaccel_picture_private;
  349. attribute_deprecated
  350. struct AVCodecContext *owner;
  351. attribute_deprecated
  352. void *thread_opaque;
  353. /**
  354. * log2 of the size of the block which a single vector in motion_val represents:
  355. * (4->16x16, 3->8x8, 2-> 4x4, 1-> 2x2)
  356. */
  357. uint8_t motion_subsample_log2;
  358. #endif
  359. /**
  360. * Sample rate of the audio data.
  361. */
  362. int sample_rate;
  363. /**
  364. * Channel layout of the audio data.
  365. */
  366. uint64_t channel_layout;
  367. /**
  368. * AVBuffer references backing the data for this frame. If all elements of
  369. * this array are NULL, then this frame is not reference counted.
  370. *
  371. * There may be at most one AVBuffer per data plane, so for video this array
  372. * always contains all the references. For planar audio with more than
  373. * AV_NUM_DATA_POINTERS channels, there may be more buffers than can fit in
  374. * this array. Then the extra AVBufferRef pointers are stored in the
  375. * extended_buf array.
  376. */
  377. AVBufferRef *buf[AV_NUM_DATA_POINTERS];
  378. /**
  379. * For planar audio which requires more than AV_NUM_DATA_POINTERS
  380. * AVBufferRef pointers, this array will hold all the references which
  381. * cannot fit into AVFrame.buf.
  382. *
  383. * Note that this is different from AVFrame.extended_data, which always
  384. * contains all the pointers. This array only contains the extra pointers,
  385. * which cannot fit into AVFrame.buf.
  386. *
  387. * This array is always allocated using av_malloc() by whoever constructs
  388. * the frame. It is freed in av_frame_unref().
  389. */
  390. AVBufferRef **extended_buf;
  391. /**
  392. * Number of elements in extended_buf.
  393. */
  394. int nb_extended_buf;
  395. AVFrameSideData **side_data;
  396. int nb_side_data;
  397. /**
  398. * @defgroup lavu_frame_flags AV_FRAME_FLAGS
  399. * Flags describing additional frame properties.
  400. *
  401. * @{
  402. */
  403. /**
  404. * The frame data may be corrupted, e.g. due to decoding errors.
  405. */
  406. #define AV_FRAME_FLAG_CORRUPT (1 << 0)
  407. /**
  408. * @}
  409. */
  410. /**
  411. * Frame flags, a combination of @ref lavu_frame_flags
  412. */
  413. int flags;
  414. /**
  415. * MPEG vs JPEG YUV range.
  416. * It must be accessed using av_frame_get_color_range() and
  417. * av_frame_set_color_range().
  418. * - encoding: Set by user
  419. * - decoding: Set by libavcodec
  420. */
  421. enum AVColorRange color_range;
  422. enum AVColorPrimaries color_primaries;
  423. enum AVColorTransferCharacteristic color_trc;
  424. /**
  425. * YUV colorspace type.
  426. * It must be accessed using av_frame_get_colorspace() and
  427. * av_frame_set_colorspace().
  428. * - encoding: Set by user
  429. * - decoding: Set by libavcodec
  430. */
  431. enum AVColorSpace colorspace;
  432. enum AVChromaLocation chroma_location;
  433. /**
  434. * frame timestamp estimated using various heuristics, in stream time base
  435. * Code outside libavcodec should access this field using:
  436. * av_frame_get_best_effort_timestamp(frame)
  437. * - encoding: unused
  438. * - decoding: set by libavcodec, read by user.
  439. */
  440. int64_t best_effort_timestamp;
  441. /**
  442. * reordered pos from the last AVPacket that has been input into the decoder
  443. * Code outside libavcodec should access this field using:
  444. * av_frame_get_pkt_pos(frame)
  445. * - encoding: unused
  446. * - decoding: Read by user.
  447. */
  448. int64_t pkt_pos;
  449. /**
  450. * duration of the corresponding packet, expressed in
  451. * AVStream->time_base units, 0 if unknown.
  452. * Code outside libavcodec should access this field using:
  453. * av_frame_get_pkt_duration(frame)
  454. * - encoding: unused
  455. * - decoding: Read by user.
  456. */
  457. int64_t pkt_duration;
  458. /**
  459. * metadata.
  460. * Code outside libavcodec should access this field using:
  461. * av_frame_get_metadata(frame)
  462. * - encoding: Set by user.
  463. * - decoding: Set by libavcodec.
  464. */
  465. AVDictionary *metadata;
  466. /**
  467. * decode error flags of the frame, set to a combination of
  468. * FF_DECODE_ERROR_xxx flags if the decoder produced a frame, but there
  469. * were errors during the decoding.
  470. * Code outside libavcodec should access this field using:
  471. * av_frame_get_decode_error_flags(frame)
  472. * - encoding: unused
  473. * - decoding: set by libavcodec, read by user.
  474. */
  475. int decode_error_flags;
  476. #define FF_DECODE_ERROR_INVALID_BITSTREAM 1
  477. #define FF_DECODE_ERROR_MISSING_REFERENCE 2
  478. /**
  479. * number of audio channels, only used for audio.
  480. * Code outside libavcodec should access this field using:
  481. * av_frame_get_channels(frame)
  482. * - encoding: unused
  483. * - decoding: Read by user.
  484. */
  485. int channels;
  486. /**
  487. * size of the corresponding packet containing the compressed
  488. * frame. It must be accessed using av_frame_get_pkt_size() and
  489. * av_frame_set_pkt_size().
  490. * It is set to a negative value if unknown.
  491. * - encoding: unused
  492. * - decoding: set by libavcodec, read by user.
  493. */
  494. int pkt_size;
  495. /**
  496. * Not to be accessed directly from outside libavutil
  497. */
  498. AVBufferRef *qp_table_buf;
  499. } AVFrame;
  500. /**
  501. * Accessors for some AVFrame fields.
  502. * The position of these field in the structure is not part of the ABI,
  503. * they should not be accessed directly outside libavcodec.
  504. */
  505. int64_t av_frame_get_best_effort_timestamp(const AVFrame *frame);
  506. void av_frame_set_best_effort_timestamp(AVFrame *frame, int64_t val);
  507. int64_t av_frame_get_pkt_duration (const AVFrame *frame);
  508. void av_frame_set_pkt_duration (AVFrame *frame, int64_t val);
  509. int64_t av_frame_get_pkt_pos (const AVFrame *frame);
  510. void av_frame_set_pkt_pos (AVFrame *frame, int64_t val);
  511. int64_t av_frame_get_channel_layout (const AVFrame *frame);
  512. void av_frame_set_channel_layout (AVFrame *frame, int64_t val);
  513. int av_frame_get_channels (const AVFrame *frame);
  514. void av_frame_set_channels (AVFrame *frame, int val);
  515. int av_frame_get_sample_rate (const AVFrame *frame);
  516. void av_frame_set_sample_rate (AVFrame *frame, int val);
  517. AVDictionary *av_frame_get_metadata (const AVFrame *frame);
  518. void av_frame_set_metadata (AVFrame *frame, AVDictionary *val);
  519. int av_frame_get_decode_error_flags (const AVFrame *frame);
  520. void av_frame_set_decode_error_flags (AVFrame *frame, int val);
  521. int av_frame_get_pkt_size(const AVFrame *frame);
  522. void av_frame_set_pkt_size(AVFrame *frame, int val);
  523. AVDictionary **avpriv_frame_get_metadatap(AVFrame *frame);
  524. int8_t *av_frame_get_qp_table(AVFrame *f, int *stride, int *type);
  525. int av_frame_set_qp_table(AVFrame *f, AVBufferRef *buf, int stride, int type);
  526. enum AVColorSpace av_frame_get_colorspace(const AVFrame *frame);
  527. void av_frame_set_colorspace(AVFrame *frame, enum AVColorSpace val);
  528. enum AVColorRange av_frame_get_color_range(const AVFrame *frame);
  529. void av_frame_set_color_range(AVFrame *frame, enum AVColorRange val);
  530. /**
  531. * Get the name of a colorspace.
  532. * @return a static string identifying the colorspace; can be NULL.
  533. */
  534. const char *av_get_colorspace_name(enum AVColorSpace val);
  535. /**
  536. * Allocate an AVFrame and set its fields to default values. The resulting
  537. * struct must be freed using av_frame_free().
  538. *
  539. * @return An AVFrame filled with default values or NULL on failure.
  540. *
  541. * @note this only allocates the AVFrame itself, not the data buffers. Those
  542. * must be allocated through other means, e.g. with av_frame_get_buffer() or
  543. * manually.
  544. */
  545. AVFrame *av_frame_alloc(void);
  546. /**
  547. * Free the frame and any dynamically allocated objects in it,
  548. * e.g. extended_data. If the frame is reference counted, it will be
  549. * unreferenced first.
  550. *
  551. * @param frame frame to be freed. The pointer will be set to NULL.
  552. */
  553. void av_frame_free(AVFrame **frame);
  554. /**
  555. * Set up a new reference to the data described by the source frame.
  556. *
  557. * Copy frame properties from src to dst and create a new reference for each
  558. * AVBufferRef from src.
  559. *
  560. * If src is not reference counted, new buffers are allocated and the data is
  561. * copied.
  562. *
  563. * @return 0 on success, a negative AVERROR on error
  564. */
  565. int av_frame_ref(AVFrame *dst, const AVFrame *src);
  566. /**
  567. * Create a new frame that references the same data as src.
  568. *
  569. * This is a shortcut for av_frame_alloc()+av_frame_ref().
  570. *
  571. * @return newly created AVFrame on success, NULL on error.
  572. */
  573. AVFrame *av_frame_clone(const AVFrame *src);
  574. /**
  575. * Unreference all the buffers referenced by frame and reset the frame fields.
  576. */
  577. void av_frame_unref(AVFrame *frame);
  578. /**
  579. * Move everythnig contained in src to dst and reset src.
  580. */
  581. void av_frame_move_ref(AVFrame *dst, AVFrame *src);
  582. /**
  583. * Allocate new buffer(s) for audio or video data.
  584. *
  585. * The following fields must be set on frame before calling this function:
  586. * - format (pixel format for video, sample format for audio)
  587. * - width and height for video
  588. * - nb_samples and channel_layout for audio
  589. *
  590. * This function will fill AVFrame.data and AVFrame.buf arrays and, if
  591. * necessary, allocate and fill AVFrame.extended_data and AVFrame.extended_buf.
  592. * For planar formats, one buffer will be allocated for each plane.
  593. *
  594. * @param frame frame in which to store the new buffers.
  595. * @param align required buffer size alignment
  596. *
  597. * @return 0 on success, a negative AVERROR on error.
  598. */
  599. int av_frame_get_buffer(AVFrame *frame, int align);
  600. /**
  601. * Check if the frame data is writable.
  602. *
  603. * @return A positive value if the frame data is writable (which is true if and
  604. * only if each of the underlying buffers has only one reference, namely the one
  605. * stored in this frame). Return 0 otherwise.
  606. *
  607. * If 1 is returned the answer is valid until av_buffer_ref() is called on any
  608. * of the underlying AVBufferRefs (e.g. through av_frame_ref() or directly).
  609. *
  610. * @see av_frame_make_writable(), av_buffer_is_writable()
  611. */
  612. int av_frame_is_writable(AVFrame *frame);
  613. /**
  614. * Ensure that the frame data is writable, avoiding data copy if possible.
  615. *
  616. * Do nothing if the frame is writable, allocate new buffers and copy the data
  617. * if it is not.
  618. *
  619. * @return 0 on success, a negative AVERROR on error.
  620. *
  621. * @see av_frame_is_writable(), av_buffer_is_writable(),
  622. * av_buffer_make_writable()
  623. */
  624. int av_frame_make_writable(AVFrame *frame);
  625. /**
  626. * Copy the frame data from src to dst.
  627. *
  628. * This function does not allocate anything, dst must be already initialized and
  629. * allocated with the same parameters as src.
  630. *
  631. * This function only copies the frame data (i.e. the contents of the data /
  632. * extended data arrays), not any other properties.
  633. *
  634. * @return >= 0 on success, a negative AVERROR on error.
  635. */
  636. int av_frame_copy(AVFrame *dst, const AVFrame *src);
  637. /**
  638. * Copy only "metadata" fields from src to dst.
  639. *
  640. * Metadata for the purpose of this function are those fields that do not affect
  641. * the data layout in the buffers. E.g. pts, sample rate (for audio) or sample
  642. * aspect ratio (for video), but not width/height or channel layout.
  643. * Side data is also copied.
  644. */
  645. int av_frame_copy_props(AVFrame *dst, const AVFrame *src);
  646. /**
  647. * Get the buffer reference a given data plane is stored in.
  648. *
  649. * @param plane index of the data plane of interest in frame->extended_data.
  650. *
  651. * @return the buffer reference that contains the plane or NULL if the input
  652. * frame is not valid.
  653. */
  654. AVBufferRef *av_frame_get_plane_buffer(AVFrame *frame, int plane);
  655. /**
  656. * Add a new side data to a frame.
  657. *
  658. * @param frame a frame to which the side data should be added
  659. * @param type type of the added side data
  660. * @param size size of the side data
  661. *
  662. * @return newly added side data on success, NULL on error
  663. */
  664. AVFrameSideData *av_frame_new_side_data(AVFrame *frame,
  665. enum AVFrameSideDataType type,
  666. int size);
  667. /**
  668. * @return a pointer to the side data of a given type on success, NULL if there
  669. * is no side data with such type in this frame.
  670. */
  671. AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
  672. enum AVFrameSideDataType type);
  673. /**
  674. * If side data of the supplied type exists in the frame, free it and remove it
  675. * from the frame.
  676. */
  677. void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type);
  678. /**
  679. * @return a string identifying the side data type
  680. */
  681. const char *av_frame_side_data_name(enum AVFrameSideDataType type);
  682. /**
  683. * @}
  684. */
  685. #endif /* AVUTIL_FRAME_H */