mpegpicture.h (4838B)
1 /* 2 * Mpeg video formats-related defines and utility functions 3 * 4 * This file is part of FFmpeg. 5 * 6 * FFmpeg is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * FFmpeg is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with FFmpeg; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 */ 20 21 #ifndef AVCODEC_MPEGPICTURE_H 22 #define AVCODEC_MPEGPICTURE_H 23 24 #include <limits.h> 25 #include <stddef.h> 26 #include <stdint.h> 27 28 #include "avcodec.h" 29 #include "threadprogress.h" 30 31 #define MPV_MAX_PLANES 3 32 #define EDGE_WIDTH 16 33 34 typedef struct ScratchpadContext { 35 uint8_t *edge_emu_buffer; ///< temporary buffer for if MVs point to out-of-frame data 36 uint8_t *obmc_scratchpad; 37 union { 38 uint8_t *scratchpad_buf; ///< the other *_scratchpad point into this buffer 39 uint8_t *rd_scratchpad; ///< scratchpad for rate distortion mb decision 40 }; 41 int linesize; ///< linesize that the buffers in this context have been allocated for 42 } ScratchpadContext; 43 44 typedef struct BufferPoolContext { 45 struct AVRefStructPool *mbskip_table_pool; 46 struct AVRefStructPool *qscale_table_pool; 47 struct AVRefStructPool *mb_type_pool; 48 struct AVRefStructPool *motion_val_pool; 49 struct AVRefStructPool *ref_index_pool; 50 int alloc_mb_width; ///< mb_width used to allocate tables 51 int alloc_mb_height; ///< mb_height used to allocate tables 52 int alloc_mb_stride; ///< mb_stride used to allocate tables 53 } BufferPoolContext; 54 55 /** 56 * MPVPicture. 57 */ 58 typedef struct MPVPicture { 59 struct AVFrame *f; 60 61 int8_t *qscale_table_base; 62 int8_t *qscale_table; 63 64 int16_t (*motion_val_base[2])[2]; 65 int16_t (*motion_val[2])[2]; 66 67 uint32_t *mb_type_base; 68 uint32_t *mb_type; ///< types and macros are defined in mpegutils.h 69 70 uint8_t *mbskip_table; 71 72 int8_t *ref_index[2]; 73 74 /// RefStruct reference for hardware accelerator private data 75 void *hwaccel_picture_private; 76 77 int mb_width; ///< mb_width of the tables 78 int mb_height; ///< mb_height of the tables 79 int mb_stride; ///< mb_stride of the tables 80 81 int dummy; ///< Picture is a dummy and should not be output 82 int field_picture; ///< whether or not the picture was encoded in separate fields 83 84 int b_frame_score; 85 86 int reference; 87 int shared; 88 89 int display_picture_number; 90 int coded_picture_number; 91 92 ThreadProgress progress; 93 } MPVPicture; 94 95 typedef struct MPVWorkPicture { 96 uint8_t *data[MPV_MAX_PLANES]; 97 ptrdiff_t linesize[MPV_MAX_PLANES]; 98 99 MPVPicture *ptr; ///< RefStruct reference 100 101 int8_t *qscale_table; 102 103 int16_t (*motion_val[2])[2]; 104 105 uint32_t *mb_type; ///< types and macros are defined in mpegutils.h 106 107 uint8_t *mbskip_table; 108 109 int8_t *ref_index[2]; 110 111 int reference; 112 } MPVWorkPicture; 113 114 /** 115 * Allocate a pool of MPVPictures. 116 */ 117 struct AVRefStructPool *ff_mpv_alloc_pic_pool(int init_progress); 118 119 /** 120 * Allocate an MPVPicture's accessories (but not the AVFrame's buffer itself) 121 * and set the MPVWorkPicture's fields. 122 */ 123 int ff_mpv_alloc_pic_accessories(AVCodecContext *avctx, MPVWorkPicture *pic, 124 ScratchpadContext *sc, 125 BufferPoolContext *pools, int mb_height); 126 127 /** 128 * Check that the linesizes of an AVFrame are consistent with the requirements 129 * of mpegvideo. 130 * FIXME: There should be no need for this function. mpegvideo should be made 131 * to work with changing linesizes. 132 */ 133 int ff_mpv_pic_check_linesize(void *logctx, const struct AVFrame *f, 134 ptrdiff_t *linesizep, ptrdiff_t *uvlinesizep); 135 136 int ff_mpv_framesize_alloc(AVCodecContext *avctx, 137 ScratchpadContext *sc, int linesize); 138 139 /** 140 * Disable allocating the ScratchpadContext's buffers in future calls 141 * to ff_mpv_framesize_alloc(). 142 */ 143 static inline void ff_mpv_framesize_disable(ScratchpadContext *sc) 144 { 145 sc->linesize = INT_MAX; 146 } 147 148 void ff_mpv_unref_picture(MPVWorkPicture *pic); 149 void ff_mpv_workpic_from_pic(MPVWorkPicture *wpic, MPVPicture *pic); 150 void ff_mpv_replace_picture(MPVWorkPicture *dst, const MPVWorkPicture *src); 151 152 #endif /* AVCODEC_MPEGPICTURE_H */