yading@11: /* yading@11: * yading@11: * This file is part of FFmpeg. yading@11: * yading@11: * FFmpeg is free software; you can redistribute it and/or yading@11: * modify it under the terms of the GNU Lesser General Public yading@11: * License as published by the Free Software Foundation; either yading@11: * version 2.1 of the License, or (at your option) any later version. yading@11: * yading@11: * FFmpeg is distributed in the hope that it will be useful, yading@11: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@11: * Lesser General Public License for more details. yading@11: * yading@11: * You should have received a copy of the GNU Lesser General Public yading@11: * License along with FFmpeg; if not, write to the Free Software yading@11: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@11: */ yading@11: yading@11: #ifndef AVUTIL_FRAME_H yading@11: #define AVUTIL_FRAME_H yading@11: yading@11: #include yading@11: yading@11: #include "libavcodec/version.h" yading@11: yading@11: #include "avutil.h" yading@11: #include "buffer.h" yading@11: #include "dict.h" yading@11: #include "rational.h" yading@11: #include "samplefmt.h" yading@11: yading@11: enum AVFrameSideDataType { yading@11: /** yading@11: * The data is the AVPanScan struct defined in libavcodec. yading@11: */ yading@11: AV_FRAME_DATA_PANSCAN, yading@11: }; yading@11: yading@11: typedef struct AVFrameSideData { yading@11: enum AVFrameSideDataType type; yading@11: uint8_t *data; yading@11: int size; yading@11: AVDictionary *metadata; yading@11: } AVFrameSideData; yading@11: yading@11: /** yading@11: * This structure describes decoded (raw) audio or video data. yading@11: * yading@11: * AVFrame must be allocated using av_frame_alloc(). Note that this only yading@11: * allocates the AVFrame itself, the buffers for the data must be managed yading@11: * through other means (see below). yading@11: * AVFrame must be freed with av_frame_free(). yading@11: * yading@11: * AVFrame is typically allocated once and then reused multiple times to hold yading@11: * different data (e.g. a single AVFrame to hold frames received from a yading@11: * decoder). In such a case, av_frame_unref() will free any references held by yading@11: * the frame and reset it to its original clean state before it yading@11: * is reused again. yading@11: * yading@11: * The data described by an AVFrame is usually reference counted through the yading@11: * AVBuffer API. The underlying buffer references are stored in AVFrame.buf / yading@11: * AVFrame.extended_buf. An AVFrame is considered to be reference counted if at yading@11: * least one reference is set, i.e. if AVFrame.buf[0] != NULL. In such a case, yading@11: * every single data plane must be contained in one of the buffers in yading@11: * AVFrame.buf or AVFrame.extended_buf. yading@11: * There may be a single buffer for all the data, or one separate buffer for yading@11: * each plane, or anything in between. yading@11: * yading@11: * sizeof(AVFrame) is not a part of the public ABI, so new fields may be added yading@11: * to the end with a minor bump. yading@11: * Similarly fields that are marked as to be only accessed by yading@11: * av_opt_ptr() can be reordered. This allows 2 forks to add fields yading@11: * without breaking compatibility with each other. yading@11: */ yading@11: typedef struct AVFrame { yading@11: #define AV_NUM_DATA_POINTERS 8 yading@11: /** yading@11: * pointer to the picture/channel planes. yading@11: * This might be different from the first allocated byte yading@11: * yading@11: * Some decoders access areas outside 0,0 - width,height, please yading@11: * see avcodec_align_dimensions2(). Some filters and swscale can read yading@11: * up to 16 bytes beyond the planes, if these filters are to be used, yading@11: * then 16 extra bytes must be allocated. yading@11: */ yading@11: uint8_t *data[AV_NUM_DATA_POINTERS]; yading@11: yading@11: /** yading@11: * For video, size in bytes of each picture line. yading@11: * For audio, size in bytes of each plane. yading@11: * yading@11: * For audio, only linesize[0] may be set. For planar audio, each channel yading@11: * plane must be the same size. yading@11: * yading@11: * For video the linesizes should be multiplies of the CPUs alignment yading@11: * preference, this is 16 or 32 for modern desktop CPUs. yading@11: * Some code requires such alignment other code can be slower without yading@11: * correct alignment, for yet other it makes no difference. yading@11: */ yading@11: int linesize[AV_NUM_DATA_POINTERS]; yading@11: yading@11: /** yading@11: * pointers to the data planes/channels. yading@11: * yading@11: * For video, this should simply point to data[]. yading@11: * yading@11: * For planar audio, each channel has a separate data pointer, and yading@11: * linesize[0] contains the size of each channel buffer. yading@11: * For packed audio, there is just one data pointer, and linesize[0] yading@11: * contains the total size of the buffer for all channels. yading@11: * yading@11: * Note: Both data and extended_data should always be set in a valid frame, yading@11: * but for planar audio with more channels that can fit in data, yading@11: * extended_data must be used in order to access all channels. yading@11: */ yading@11: uint8_t **extended_data; yading@11: yading@11: /** yading@11: * width and height of the video frame yading@11: */ yading@11: int width, height; yading@11: yading@11: /** yading@11: * number of audio samples (per channel) described by this frame yading@11: */ yading@11: int nb_samples; yading@11: yading@11: /** yading@11: * format of the frame, -1 if unknown or unset yading@11: * Values correspond to enum AVPixelFormat for video frames, yading@11: * enum AVSampleFormat for audio) yading@11: */ yading@11: int format; yading@11: yading@11: /** yading@11: * 1 -> keyframe, 0-> not yading@11: */ yading@11: int key_frame; yading@11: yading@11: /** yading@11: * Picture type of the frame. yading@11: */ yading@11: enum AVPictureType pict_type; yading@11: yading@11: #if FF_API_AVFRAME_LAVC yading@11: attribute_deprecated yading@11: uint8_t *base[AV_NUM_DATA_POINTERS]; yading@11: #endif yading@11: yading@11: /** yading@11: * Sample aspect ratio for the video frame, 0/1 if unknown/unspecified. yading@11: */ yading@11: AVRational sample_aspect_ratio; yading@11: yading@11: /** yading@11: * Presentation timestamp in time_base units (time when frame should be shown to user). yading@11: */ yading@11: int64_t pts; yading@11: yading@11: /** yading@11: * PTS copied from the AVPacket that was decoded to produce this frame. yading@11: */ yading@11: int64_t pkt_pts; yading@11: yading@11: /** yading@11: * DTS copied from the AVPacket that triggered returning this frame. (if frame threading isnt used) yading@11: * This is also the Presentation time of this AVFrame calculated from yading@11: * only AVPacket.dts values without pts values. yading@11: */ yading@11: int64_t pkt_dts; yading@11: yading@11: /** yading@11: * picture number in bitstream order yading@11: */ yading@11: int coded_picture_number; yading@11: /** yading@11: * picture number in display order yading@11: */ yading@11: int display_picture_number; yading@11: yading@11: /** yading@11: * quality (between 1 (good) and FF_LAMBDA_MAX (bad)) yading@11: */ yading@11: int quality; yading@11: yading@11: #if FF_API_AVFRAME_LAVC yading@11: attribute_deprecated yading@11: int reference; yading@11: yading@11: /** yading@11: * QP table yading@11: */ yading@11: attribute_deprecated yading@11: int8_t *qscale_table; yading@11: /** yading@11: * QP store stride yading@11: */ yading@11: attribute_deprecated yading@11: int qstride; yading@11: yading@11: attribute_deprecated yading@11: int qscale_type; yading@11: yading@11: /** yading@11: * mbskip_table[mb]>=1 if MB didn't change yading@11: * stride= mb_width = (width+15)>>4 yading@11: */ yading@11: attribute_deprecated yading@11: uint8_t *mbskip_table; yading@11: yading@11: /** yading@11: * motion vector table yading@11: * @code yading@11: * example: yading@11: * int mv_sample_log2= 4 - motion_subsample_log2; yading@11: * int mb_width= (width+15)>>4; yading@11: * int mv_stride= (mb_width << mv_sample_log2) + 1; yading@11: * motion_val[direction][x + y*mv_stride][0->mv_x, 1->mv_y]; yading@11: * @endcode yading@11: */ yading@11: attribute_deprecated yading@11: int16_t (*motion_val[2])[2]; yading@11: yading@11: /** yading@11: * macroblock type table yading@11: * mb_type_base + mb_width + 2 yading@11: */ yading@11: attribute_deprecated yading@11: uint32_t *mb_type; yading@11: yading@11: /** yading@11: * DCT coefficients yading@11: */ yading@11: attribute_deprecated yading@11: short *dct_coeff; yading@11: yading@11: /** yading@11: * motion reference frame index yading@11: * the order in which these are stored can depend on the codec. yading@11: */ yading@11: attribute_deprecated yading@11: int8_t *ref_index[2]; yading@11: #endif yading@11: yading@11: /** yading@11: * for some private data of the user yading@11: */ yading@11: void *opaque; yading@11: yading@11: /** yading@11: * error yading@11: */ yading@11: uint64_t error[AV_NUM_DATA_POINTERS]; yading@11: yading@11: #if FF_API_AVFRAME_LAVC yading@11: attribute_deprecated yading@11: int type; yading@11: #endif yading@11: yading@11: /** yading@11: * When decoding, this signals how much the picture must be delayed. yading@11: * extra_delay = repeat_pict / (2*fps) yading@11: */ yading@11: int repeat_pict; yading@11: yading@11: /** yading@11: * The content of the picture is interlaced. yading@11: */ yading@11: int interlaced_frame; yading@11: yading@11: /** yading@11: * If the content is interlaced, is top field displayed first. yading@11: */ yading@11: int top_field_first; yading@11: yading@11: /** yading@11: * Tell user application that palette has changed from previous frame. yading@11: */ yading@11: int palette_has_changed; yading@11: yading@11: #if FF_API_AVFRAME_LAVC yading@11: attribute_deprecated yading@11: int buffer_hints; yading@11: yading@11: /** yading@11: * Pan scan. yading@11: */ yading@11: attribute_deprecated yading@11: struct AVPanScan *pan_scan; yading@11: #endif yading@11: yading@11: /** yading@11: * reordered opaque 64bit (generally an integer or a double precision float yading@11: * PTS but can be anything). yading@11: * The user sets AVCodecContext.reordered_opaque to represent the input at yading@11: * that time, yading@11: * the decoder reorders values as needed and sets AVFrame.reordered_opaque yading@11: * to exactly one of the values provided by the user through AVCodecContext.reordered_opaque yading@11: * @deprecated in favor of pkt_pts yading@11: */ yading@11: int64_t reordered_opaque; yading@11: yading@11: #if FF_API_AVFRAME_LAVC yading@11: /** yading@11: * @deprecated this field is unused yading@11: */ yading@11: attribute_deprecated void *hwaccel_picture_private; yading@11: yading@11: attribute_deprecated yading@11: struct AVCodecContext *owner; yading@11: attribute_deprecated yading@11: void *thread_opaque; yading@11: yading@11: /** yading@11: * log2 of the size of the block which a single vector in motion_val represents: yading@11: * (4->16x16, 3->8x8, 2-> 4x4, 1-> 2x2) yading@11: */ yading@11: attribute_deprecated yading@11: uint8_t motion_subsample_log2; yading@11: #endif yading@11: yading@11: /** yading@11: * Sample rate of the audio data. yading@11: */ yading@11: int sample_rate; yading@11: yading@11: /** yading@11: * Channel layout of the audio data. yading@11: */ yading@11: uint64_t channel_layout; yading@11: yading@11: /** yading@11: * AVBuffer references backing the data for this frame. If all elements of yading@11: * this array are NULL, then this frame is not reference counted. yading@11: * yading@11: * There may be at most one AVBuffer per data plane, so for video this array yading@11: * always contains all the references. For planar audio with more than yading@11: * AV_NUM_DATA_POINTERS channels, there may be more buffers than can fit in yading@11: * this array. Then the extra AVBufferRef pointers are stored in the yading@11: * extended_buf array. yading@11: */ yading@11: AVBufferRef *buf[AV_NUM_DATA_POINTERS]; yading@11: yading@11: /** yading@11: * For planar audio which requires more than AV_NUM_DATA_POINTERS yading@11: * AVBufferRef pointers, this array will hold all the references which yading@11: * cannot fit into AVFrame.buf. yading@11: * yading@11: * Note that this is different from AVFrame.extended_data, which always yading@11: * contains all the pointers. This array only contains the extra pointers, yading@11: * which cannot fit into AVFrame.buf. yading@11: * yading@11: * This array is always allocated using av_malloc() by whoever constructs yading@11: * the frame. It is freed in av_frame_unref(). yading@11: */ yading@11: AVBufferRef **extended_buf; yading@11: /** yading@11: * Number of elements in extended_buf. yading@11: */ yading@11: int nb_extended_buf; yading@11: yading@11: AVFrameSideData **side_data; yading@11: int nb_side_data; yading@11: yading@11: /** yading@11: * frame timestamp estimated using various heuristics, in stream time base yading@11: * Code outside libavcodec should access this field using: yading@11: * av_frame_get_best_effort_timestamp(frame) yading@11: * - encoding: unused yading@11: * - decoding: set by libavcodec, read by user. yading@11: */ yading@11: int64_t best_effort_timestamp; yading@11: yading@11: /** yading@11: * reordered pos from the last AVPacket that has been input into the decoder yading@11: * Code outside libavcodec should access this field using: yading@11: * av_frame_get_pkt_pos(frame) yading@11: * - encoding: unused yading@11: * - decoding: Read by user. yading@11: */ yading@11: int64_t pkt_pos; yading@11: yading@11: /** yading@11: * duration of the corresponding packet, expressed in yading@11: * AVStream->time_base units, 0 if unknown. yading@11: * Code outside libavcodec should access this field using: yading@11: * av_frame_get_pkt_duration(frame) yading@11: * - encoding: unused yading@11: * - decoding: Read by user. yading@11: */ yading@11: int64_t pkt_duration; yading@11: yading@11: /** yading@11: * metadata. yading@11: * Code outside libavcodec should access this field using: yading@11: * av_frame_get_metadata(frame) yading@11: * - encoding: Set by user. yading@11: * - decoding: Set by libavcodec. yading@11: */ yading@11: AVDictionary *metadata; yading@11: yading@11: /** yading@11: * decode error flags of the frame, set to a combination of yading@11: * FF_DECODE_ERROR_xxx flags if the decoder produced a frame, but there yading@11: * were errors during the decoding. yading@11: * Code outside libavcodec should access this field using: yading@11: * av_frame_get_decode_error_flags(frame) yading@11: * - encoding: unused yading@11: * - decoding: set by libavcodec, read by user. yading@11: */ yading@11: int decode_error_flags; yading@11: #define FF_DECODE_ERROR_INVALID_BITSTREAM 1 yading@11: #define FF_DECODE_ERROR_MISSING_REFERENCE 2 yading@11: yading@11: /** yading@11: * number of audio channels, only used for audio. yading@11: * Code outside libavcodec should access this field using: yading@11: * av_frame_get_channels(frame) yading@11: * - encoding: unused yading@11: * - decoding: Read by user. yading@11: */ yading@11: int channels; yading@11: yading@11: /** yading@11: * size of the corresponding packet containing the compressed yading@11: * frame. It must be accessed using av_frame_get_pkt_size() and yading@11: * av_frame_set_pkt_size(). yading@11: * It is set to a negative value if unknown. yading@11: * - encoding: unused yading@11: * - decoding: set by libavcodec, read by user. yading@11: */ yading@11: int pkt_size; yading@11: yading@11: /** yading@11: * Not to be accessed directly from outside libavutil yading@11: */ yading@11: AVBufferRef *qp_table_buf; yading@11: } AVFrame; yading@11: yading@11: /** yading@11: * Accessors for some AVFrame fields. yading@11: * The position of these field in the structure is not part of the ABI, yading@11: * they should not be accessed directly outside libavcodec. yading@11: */ yading@11: int64_t av_frame_get_best_effort_timestamp(const AVFrame *frame); yading@11: void av_frame_set_best_effort_timestamp(AVFrame *frame, int64_t val); yading@11: int64_t av_frame_get_pkt_duration (const AVFrame *frame); yading@11: void av_frame_set_pkt_duration (AVFrame *frame, int64_t val); yading@11: int64_t av_frame_get_pkt_pos (const AVFrame *frame); yading@11: void av_frame_set_pkt_pos (AVFrame *frame, int64_t val); yading@11: int64_t av_frame_get_channel_layout (const AVFrame *frame); yading@11: void av_frame_set_channel_layout (AVFrame *frame, int64_t val); yading@11: int av_frame_get_channels (const AVFrame *frame); yading@11: void av_frame_set_channels (AVFrame *frame, int val); yading@11: int av_frame_get_sample_rate (const AVFrame *frame); yading@11: void av_frame_set_sample_rate (AVFrame *frame, int val); yading@11: AVDictionary *av_frame_get_metadata (const AVFrame *frame); yading@11: void av_frame_set_metadata (AVFrame *frame, AVDictionary *val); yading@11: int av_frame_get_decode_error_flags (const AVFrame *frame); yading@11: void av_frame_set_decode_error_flags (AVFrame *frame, int val); yading@11: int av_frame_get_pkt_size(const AVFrame *frame); yading@11: void av_frame_set_pkt_size(AVFrame *frame, int val); yading@11: AVDictionary **avpriv_frame_get_metadatap(AVFrame *frame); yading@11: int8_t *av_frame_get_qp_table(AVFrame *f, int *stride, int *type); yading@11: int av_frame_set_qp_table(AVFrame *f, AVBufferRef *buf, int stride, int type); yading@11: yading@11: /** yading@11: * Allocate an AVFrame and set its fields to default values. The resulting yading@11: * struct must be freed using av_frame_free(). yading@11: * yading@11: * @return An AVFrame filled with default values or NULL on failure. yading@11: * yading@11: * @note this only allocates the AVFrame itself, not the data buffers. Those yading@11: * must be allocated through other means, e.g. with av_frame_get_buffer() or yading@11: * manually. yading@11: */ yading@11: AVFrame *av_frame_alloc(void); yading@11: yading@11: /** yading@11: * Free the frame and any dynamically allocated objects in it, yading@11: * e.g. extended_data. If the frame is reference counted, it will be yading@11: * unreferenced first. yading@11: * yading@11: * @param frame frame to be freed. The pointer will be set to NULL. yading@11: */ yading@11: void av_frame_free(AVFrame **frame); yading@11: yading@11: /** yading@11: * Setup a new reference to the data described by an given frame. yading@11: * yading@11: * Copy frame properties from src to dst and create a new reference for each yading@11: * AVBufferRef from src. yading@11: * yading@11: * If src is not reference counted, new buffers are allocated and the data is yading@11: * copied. yading@11: * yading@11: * @return 0 on success, a negative AVERROR on error yading@11: */ yading@11: int av_frame_ref(AVFrame *dst, AVFrame *src); yading@11: yading@11: /** yading@11: * Create a new frame that references the same data as src. yading@11: * yading@11: * This is a shortcut for av_frame_alloc()+av_frame_ref(). yading@11: * yading@11: * @return newly created AVFrame on success, NULL on error. yading@11: */ yading@11: AVFrame *av_frame_clone(AVFrame *src); yading@11: yading@11: /** yading@11: * Unreference all the buffers referenced by frame and reset the frame fields. yading@11: */ yading@11: void av_frame_unref(AVFrame *frame); yading@11: yading@11: /** yading@11: * Move everythnig contained in src to dst and reset src. yading@11: */ yading@11: void av_frame_move_ref(AVFrame *dst, AVFrame *src); yading@11: yading@11: /** yading@11: * Allocate new buffer(s) for audio or video data. yading@11: * yading@11: * The following fields must be set on frame before calling this function: yading@11: * - format (pixel format for video, sample format for audio) yading@11: * - width and height for video yading@11: * - nb_samples and channel_layout for audio yading@11: * yading@11: * This function will fill AVFrame.data and AVFrame.buf arrays and, if yading@11: * necessary, allocate and fill AVFrame.extended_data and AVFrame.extended_buf. yading@11: * For planar formats, one buffer will be allocated for each plane. yading@11: * yading@11: * @param frame frame in which to store the new buffers. yading@11: * @param align required buffer size alignment yading@11: * yading@11: * @return 0 on success, a negative AVERROR on error. yading@11: */ yading@11: int av_frame_get_buffer(AVFrame *frame, int align); yading@11: yading@11: /** yading@11: * Check if the frame data is writable. yading@11: * yading@11: * @return A positive value if the frame data is writable (which is true if and yading@11: * only if each of the underlying buffers has only one reference, namely the one yading@11: * stored in this frame). Return 0 otherwise. yading@11: * yading@11: * If 1 is returned the answer is valid until av_buffer_ref() is called on any yading@11: * of the underlying AVBufferRefs (e.g. through av_frame_ref() or directly). yading@11: * yading@11: * @see av_frame_make_writable(), av_buffer_is_writable() yading@11: */ yading@11: int av_frame_is_writable(AVFrame *frame); yading@11: yading@11: /** yading@11: * Ensure that the frame data is writable, avoiding data copy if possible. yading@11: * yading@11: * Do nothing if the frame is writable, allocate new buffers and copy the data yading@11: * if it is not. yading@11: * yading@11: * @return 0 on success, a negative AVERROR on error. yading@11: * yading@11: * @see av_frame_is_writable(), av_buffer_is_writable(), yading@11: * av_buffer_make_writable() yading@11: */ yading@11: int av_frame_make_writable(AVFrame *frame); yading@11: yading@11: /** yading@11: * Copy only "metadata" fields from src to dst. yading@11: * yading@11: * Metadata for the purpose of this function are those fields that do not affect yading@11: * the data layout in the buffers. E.g. pts, sample rate (for audio) or sample yading@11: * aspect ratio (for video), but not width/height or channel layout. yading@11: * Side data is also copied. yading@11: */ yading@11: int av_frame_copy_props(AVFrame *dst, const AVFrame *src); yading@11: yading@11: /** yading@11: * Get the buffer reference a given data plane is stored in. yading@11: * yading@11: * @param plane index of the data plane of interest in frame->extended_data. yading@11: * yading@11: * @return the buffer reference that contains the plane or NULL if the input yading@11: * frame is not valid. yading@11: */ yading@11: AVBufferRef *av_frame_get_plane_buffer(AVFrame *frame, int plane); yading@11: yading@11: /** yading@11: * Add a new side data to a frame. yading@11: * yading@11: * @param frame a frame to which the side data should be added yading@11: * @param type type of the added side data yading@11: * @param size size of the side data yading@11: * yading@11: * @return newly added side data on success, NULL on error yading@11: */ yading@11: AVFrameSideData *av_frame_new_side_data(AVFrame *frame, yading@11: enum AVFrameSideDataType type, yading@11: int size); yading@11: yading@11: /** yading@11: * @return a pointer to the side data of a given type on success, NULL if there yading@11: * is no side data with such type in this frame. yading@11: */ yading@11: AVFrameSideData *av_frame_get_side_data(AVFrame *frame, yading@11: enum AVFrameSideDataType type); yading@11: yading@11: #endif /* AVUTIL_FRAME_H */