You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

430 lines
12KB

  1. /*
  2. *
  3. * This file is part of Libav.
  4. *
  5. * Libav 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. * Libav 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 Libav; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #ifndef AVUTIL_FRAME_H
  20. #define AVUTIL_FRAME_H
  21. #include <stdint.h>
  22. #include "libavcodec/version.h"
  23. #include "avutil.h"
  24. #include "buffer.h"
  25. #include "rational.h"
  26. #include "samplefmt.h"
  27. /**
  28. * This structure describes decoded (raw) audio or video data.
  29. *
  30. * AVFrame must be allocated using av_frame_alloc(). Not that this only
  31. * allocates the AVFrame itself, the buffers for the data must be managed
  32. * through other means (see below).
  33. * AVFrame must be freed with av_frame_free().
  34. *
  35. * AVFrame is typically allocated once and then reused multiple times to hold
  36. * different data (e.g. a single AVFrame to hold frames received from a
  37. * decoder). In such a case, av_frame_unref() will free any references held by
  38. * the frame and reset it to its original clean state before it
  39. * is reused again.
  40. *
  41. * The data described by an AVFrame is usually reference counted through the
  42. * AVBuffer API. The underlying buffer references are stored in AVFrame.buf /
  43. * AVFrame.extended_buf. An AVFrame is considered to be reference counted if at
  44. * least one reference is set, i.e. if AVFrame.buf[0] != NULL. In such a case,
  45. * every single data plane must be contained in one of the buffers in
  46. * AVFrame.buf or AVFrame.extended_buf.
  47. * There may be a single buffer for all the data, or one separate buffer for
  48. * each plane, or anything in between.
  49. *
  50. * sizeof(AVFrame) is not a part of the public ABI, so new fields may be added
  51. * to the end with a minor bump.
  52. */
  53. typedef struct AVFrame {
  54. #define AV_NUM_DATA_POINTERS 8
  55. /**
  56. * pointer to the picture/channel planes.
  57. * This might be different from the first allocated byte
  58. */
  59. uint8_t *data[AV_NUM_DATA_POINTERS];
  60. /**
  61. * For video, size in bytes of each picture line.
  62. * For audio, size in bytes of each plane.
  63. *
  64. * For audio, only linesize[0] may be set. For planar audio, each channel
  65. * plane must be the same size.
  66. */
  67. int linesize[AV_NUM_DATA_POINTERS];
  68. /**
  69. * pointers to the data planes/channels.
  70. *
  71. * For video, this should simply point to data[].
  72. *
  73. * For planar audio, each channel has a separate data pointer, and
  74. * linesize[0] contains the size of each channel buffer.
  75. * For packed audio, there is just one data pointer, and linesize[0]
  76. * contains the total size of the buffer for all channels.
  77. *
  78. * Note: Both data and extended_data should always be set in a valid frame,
  79. * but for planar audio with more channels that can fit in data,
  80. * extended_data must be used in order to access all channels.
  81. */
  82. uint8_t **extended_data;
  83. /**
  84. * width and height of the video frame
  85. */
  86. int width, height;
  87. /**
  88. * number of audio samples (per channel) described by this frame
  89. */
  90. int nb_samples;
  91. /**
  92. * format of the frame, -1 if unknown or unset
  93. * Values correspond to enum AVPixelFormat for video frames,
  94. * enum AVSampleFormat for audio)
  95. */
  96. int format;
  97. /**
  98. * 1 -> keyframe, 0-> not
  99. */
  100. int key_frame;
  101. /**
  102. * Picture type of the frame.
  103. */
  104. enum AVPictureType pict_type;
  105. uint8_t *base[AV_NUM_DATA_POINTERS];
  106. /**
  107. * Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
  108. */
  109. AVRational sample_aspect_ratio;
  110. /**
  111. * Presentation timestamp in time_base units (time when frame should be shown to user).
  112. */
  113. int64_t pts;
  114. /**
  115. * PTS copied from the AVPacket that was decoded to produce this frame.
  116. */
  117. int64_t pkt_pts;
  118. /**
  119. * DTS copied from the AVPacket that triggered returning this frame.
  120. */
  121. int64_t pkt_dts;
  122. /**
  123. * picture number in bitstream order
  124. */
  125. int coded_picture_number;
  126. /**
  127. * picture number in display order
  128. */
  129. int display_picture_number;
  130. /**
  131. * quality (between 1 (good) and FF_LAMBDA_MAX (bad))
  132. */
  133. int quality;
  134. int reference;
  135. /**
  136. * QP table
  137. */
  138. int8_t *qscale_table;
  139. /**
  140. * QP store stride
  141. */
  142. int qstride;
  143. int qscale_type;
  144. /**
  145. * mbskip_table[mb]>=1 if MB didn't change
  146. * stride= mb_width = (width+15)>>4
  147. */
  148. uint8_t *mbskip_table;
  149. /**
  150. * motion vector table
  151. * @code
  152. * example:
  153. * int mv_sample_log2= 4 - motion_subsample_log2;
  154. * int mb_width= (width+15)>>4;
  155. * int mv_stride= (mb_width << mv_sample_log2) + 1;
  156. * motion_val[direction][x + y*mv_stride][0->mv_x, 1->mv_y];
  157. * @endcode
  158. */
  159. int16_t (*motion_val[2])[2];
  160. /**
  161. * macroblock type table
  162. * mb_type_base + mb_width + 2
  163. */
  164. uint32_t *mb_type;
  165. /**
  166. * DCT coefficients
  167. */
  168. short *dct_coeff;
  169. /**
  170. * motion reference frame index
  171. * the order in which these are stored can depend on the codec.
  172. */
  173. int8_t *ref_index[2];
  174. /**
  175. * for some private data of the user
  176. */
  177. void *opaque;
  178. /**
  179. * error
  180. */
  181. uint64_t error[AV_NUM_DATA_POINTERS];
  182. int type;
  183. /**
  184. * When decoding, this signals how much the picture must be delayed.
  185. * extra_delay = repeat_pict / (2*fps)
  186. */
  187. int repeat_pict;
  188. /**
  189. * The content of the picture is interlaced.
  190. */
  191. int interlaced_frame;
  192. /**
  193. * If the content is interlaced, is top field displayed first.
  194. */
  195. int top_field_first;
  196. /**
  197. * Tell user application that palette has changed from previous frame.
  198. */
  199. int palette_has_changed;
  200. int buffer_hints;
  201. /**
  202. * Pan scan.
  203. */
  204. struct AVPanScan *pan_scan;
  205. /**
  206. * reordered opaque 64bit (generally an integer or a double precision float
  207. * PTS but can be anything).
  208. * The user sets AVCodecContext.reordered_opaque to represent the input at
  209. * that time,
  210. * the decoder reorders values as needed and sets AVFrame.reordered_opaque
  211. * to exactly one of the values provided by the user through AVCodecContext.reordered_opaque
  212. * @deprecated in favor of pkt_pts
  213. */
  214. int64_t reordered_opaque;
  215. #if FF_API_AVFRAME_LAVC
  216. /**
  217. * @deprecated this field is unused
  218. */
  219. attribute_deprecated void *hwaccel_picture_private;
  220. #endif
  221. struct AVCodecContext *owner;
  222. void *thread_opaque;
  223. /**
  224. * log2 of the size of the block which a single vector in motion_val represents:
  225. * (4->16x16, 3->8x8, 2-> 4x4, 1-> 2x2)
  226. */
  227. uint8_t motion_subsample_log2;
  228. /**
  229. * Sample rate of the audio data.
  230. */
  231. int sample_rate;
  232. /**
  233. * Channel layout of the audio data.
  234. */
  235. uint64_t channel_layout;
  236. /**
  237. * AVBuffer references backing the data for this frame. If all elements of
  238. * this array are NULL, then this frame is not reference counted.
  239. *
  240. * There may be at most one AVBuffer per data plane, so for video this array
  241. * always contains all the references. For planar audio with more than
  242. * AV_NUM_DATA_POINTERS channels, there may be more buffers than can fit in
  243. * this array. Then the extra AVBufferRef pointers are stored in the
  244. * extended_buf array.
  245. */
  246. AVBufferRef *buf[AV_NUM_DATA_POINTERS];
  247. /**
  248. * For planar audio which requires more than AV_NUM_DATA_POINTERS
  249. * AVBufferRef pointers, this array will hold all the references which
  250. * cannot fit into AVFrame.buf.
  251. *
  252. * Note that this is different from AVFrame.extended_data, which always
  253. * contains all the pointers. This array only contains the extra pointers,
  254. * which cannot fit into AVFrame.buf.
  255. *
  256. * This array is always allocated using av_malloc() by whoever constructs
  257. * the frame. It is freed in av_frame_unref().
  258. */
  259. AVBufferRef **extended_buf;
  260. /**
  261. * Number of elements in extended_buf.
  262. */
  263. int nb_extended_buf;
  264. } AVFrame;
  265. /**
  266. * Allocate an AVFrame and set its fields to default values. The resulting
  267. * struct must be freed using av_frame_free().
  268. *
  269. * @return An AVFrame filled with default values or NULL on failure.
  270. *
  271. * @note this only allocates the AVFrame itself, not the data buffers. Those
  272. * must be allocated through other means, e.g. with av_frame_get_buffer() or
  273. * manually.
  274. */
  275. AVFrame *av_frame_alloc(void);
  276. /**
  277. * Free the frame and any dynamically allocated objects in it,
  278. * e.g. extended_data. If the frame is reference counted, it will be
  279. * unreferenced first.
  280. *
  281. * @param frame frame to be freed. The pointer will be set to NULL.
  282. */
  283. void av_frame_free(AVFrame **frame);
  284. /**
  285. * Setup a new reference to the data described by an given frame.
  286. *
  287. * Copy frame properties from src to dst and create a new reference for each
  288. * AVBufferRef from src.
  289. *
  290. * If src is not reference counted, new buffers are allocated and the data is
  291. * copied.
  292. *
  293. * @return 0 on success, a negative AVERROR on error
  294. */
  295. int av_frame_ref(AVFrame *dst, AVFrame *src);
  296. /**
  297. * Create a new frame that references the same data as src.
  298. *
  299. * This is a shortcut for av_frame_alloc()+av_frame_ref().
  300. *
  301. * @return newly created AVFrame on success, NULL on error.
  302. */
  303. AVFrame *av_frame_clone(AVFrame *src);
  304. /**
  305. * Unreference all the buffers referenced by frame and reset the frame fields.
  306. */
  307. void av_frame_unref(AVFrame *frame);
  308. /**
  309. * Move everythnig contained in src to dst and reset src.
  310. */
  311. void av_frame_move_ref(AVFrame *dst, AVFrame *src);
  312. /**
  313. * Allocate new buffer(s) for audio or video data.
  314. *
  315. * The following fields must be set on frame before calling this function:
  316. * - format (pixel format for video, sample format for audio)
  317. * - width and height for video
  318. * - nb_samples and channel_layout for audio
  319. *
  320. * This function will fill AVFrame.data and AVFrame.buf arrays and, if
  321. * necessary, allocate and fill AVFrame.extended_data and AVFrame.extended_buf.
  322. * For planar formats, one buffer will be allocated for each plane.
  323. *
  324. * @param frame frame in which to store the new buffers.
  325. * @param align required buffer size alignment
  326. *
  327. * @return 0 on success, a negative AVERROR on error.
  328. */
  329. int av_frame_get_buffer(AVFrame *frame, int align);
  330. /**
  331. * Check if the frame data is writable.
  332. *
  333. * @return A positive value if the frame data is writable (which is true if and
  334. * only if each of the underlying buffers has only one reference, namely the one
  335. * stored in this frame). Return 0 otherwise.
  336. *
  337. * If 1 is returned the answer is valid until av_buffer_ref() is called on any
  338. * of the underlying AVBufferRefs (e.g. through av_frame_ref() or directly).
  339. *
  340. * @see av_frame_make_writable(), av_buffer_is_writable()
  341. */
  342. int av_frame_is_writable(AVFrame *frame);
  343. /**
  344. * Ensure that the frame data is writable, avoiding data copy if possible.
  345. *
  346. * Do nothing if the frame is writable, allocate new buffers and copy the data
  347. * if it is not.
  348. *
  349. * @return 0 on success, a negative AVERROR on error.
  350. *
  351. * @see av_frame_is_writable(), av_buffer_is_writable(),
  352. * av_buffer_make_writable()
  353. */
  354. int av_frame_make_writable(AVFrame *frame);
  355. /**
  356. * Copy only "metadata" fields from src to dst.
  357. *
  358. * Metadata for the purpose of this function are those fields that do not affect
  359. * the data layout in the buffers. E.g. pts, sample rate (for audio) or sample
  360. * aspect ratio (for video), but not width/height or channel layout.
  361. */
  362. int av_frame_copy_props(AVFrame *dst, const AVFrame *src);
  363. /**
  364. * Get the buffer reference a given data plane is stored in.
  365. *
  366. * @param plane index of the data plane of interest in frame->extended_data.
  367. *
  368. * @return the buffer reference that contains the plane or NULL if the input
  369. * frame is not valid.
  370. */
  371. AVBufferRef *av_frame_get_plane_buffer(AVFrame *frame, int plane);
  372. #endif /* AVUTIL_FRAME_H */