1 2 /*! 3 *********************************************************************** 4 * \file 5 * mbuffer.h 6 * 7 * \brief 8 * Frame buffer functions 9 * 10 * \author 11 * Main contributors (see contributors.h for copyright, address and affiliation details) 12 * - Karsten Suehring 13 * - Alexis Michael Tourapis <alexismt@ieee.org> 14 * - Yuwen He <yhe@dolby.com> 15 *********************************************************************** 16 */ 17 #ifndef _MBUFFERENC_H_ 18 #define _MBUFFERENC_H_ 19 20 #include "global.h" 21 #include "enc_statistics.h" 22 23 #define MAX_LIST_SIZE 33 24 25 typedef struct frame_store FrameStore; 26 typedef struct distortion_estimation Dist_Estm; 27 typedef struct picture_stats PictureStats; 28 typedef struct pic_motion_params_old PicMotionParamsOld; 29 30 struct picture_stats 31 { 32 double dsum[3]; 33 double dvar[3]; 34 }; 35 36 37 //! definition of pic motion parameters 38 struct pic_motion_params_old 39 { 40 byte * mb_field; //!< field macroblock indicator 41 }; 42 43 44 //! definition of pic motion parameters 45 typedef struct pic_motion_params 46 { 47 struct storable_picture *ref_pic[2]; //!< referrence picture pointer 48 char ref_idx[2]; //!< reference picture [list][subblock_y][subblock_x] 49 MotionVector mv[2]; //!< motion vector 50 byte field_frame; //!< indicates if co_located is field or frame. Will be removed at some point 51 } PicMotionParams; 52 53 54 //! definition a picture (field or frame) 55 typedef struct storable_picture 56 { 57 PictureStructure structure; 58 59 int poc; 60 int top_poc; 61 int bottom_poc; 62 int frame_poc; 63 int order_num; 64 unsigned frame_num; 65 int pic_num; 66 int long_term_pic_num; 67 int long_term_frame_idx; 68 int temporal_layer; 69 70 byte is_long_term; 71 int used_for_reference; 72 int is_output; 73 int non_existing; 74 75 int size_x, size_y, size_x_cr, size_y_cr; 76 int size_x_padded, size_y_padded; 77 int size_x_pad, size_y_pad; 78 int size_x_cr_pad, size_y_cr_pad; 79 int pad_size_uv_y, pad_size_uv_x; 80 int chroma_vector_adjustment; 81 int coded_frame; 82 int mb_aff_frame_flag; 83 84 imgpel ** imgY; //!< Y picture component 85 imgpel **** imgY_sub; //!< Y picture component upsampled (Quarter pel) 86 imgpel *** imgUV; //!< U and V picture components 87 imgpel *****imgUV_sub; //!< UV picture component upsampled (Quarter/One-Eighth pel) 88 89 imgpel *** p_dec_img[MAX_PLANE]; //!< pointer array for accessing decoded pictures in hypothetical decoders 90 91 imgpel ** p_img[MAX_PLANE]; //!< pointer array for accessing imgY/imgUV[] 92 imgpel **** p_img_sub[MAX_PLANE]; //!< pointer array for storing top address of imgY_sub/imgUV_sub[] 93 imgpel ** p_curr_img; //!< current int-pel ref. picture area to be used for motion estimation 94 imgpel **** p_curr_img_sub; //!< current sub-pel ref. picture area to be used for motion estimation 95 96 // Hierarchical ME Image buffer 97 imgpel *** pHmeImage; //!< Array allocated with dimensions [level][y][x]; 98 int * pHmeWidth; //!< Width of hierarchical image at each level 99 int * pHmeHeight; //!< Height of hierarchical image at each level 100 101 Dist_Estm * de_mem; 102 103 PicMotionParams **mv_info; //!< Motion info 104 PicMotionParams **JVmv_info[MAX_PLANE]; //!< Motion info for 4:4:4 independent coding 105 PicMotionParamsOld motion; //!< Motion info 106 PicMotionParamsOld JVmotion[MAX_PLANE]; //!< Motion info for 4:4:4 independent coding 107 108 int colour_plane_id; //!< colour_plane_id to be used for 4:4:4 independent mode encoding 109 110 struct storable_picture *top_field; // for mb aff, if frame for referencing the top field 111 struct storable_picture *bottom_field; // for mb aff, if frame for referencing the bottom field 112 struct storable_picture *frame; // for mb aff, if field for referencing the combined frame 113 114 int chroma_format_idc; 115 int chroma_mask_mv_x; 116 int chroma_mask_mv_y; 117 int chroma_shift_y; 118 int chroma_shift_x; 119 int frame_mbs_only_flag; 120 int frame_cropping_flag; 121 int frame_crop_left_offset; 122 int frame_crop_right_offset; 123 int frame_crop_top_offset; 124 int frame_crop_bottom_offset; 125 126 PictureStats p_stats; 127 StatParameters stats; 128 129 int type; 130 131 #if (MVC_EXTENSION_ENABLE) 132 int view_id; 133 int inter_view_flag[2]; 134 int anchor_pic_flag[2]; 135 #endif 136 137 int bInterpolated; 138 int ref_pic_na[6]; 139 int otf_flag; 140 //int separate_colour_plane_flag; 141 } StorablePicture; 142 143 typedef StorablePicture *StorablePicturePtr; 144 145 //! Frame Stores for Decoded Picture Buffer 146 struct frame_store 147 { 148 int is_used; //!< 0=empty; 1=top; 2=bottom; 3=both fields (or frame) 149 int is_reference; //!< 0=not used for ref; 1=top used; 2=bottom used; 3=both fields (or frame) used 150 int is_long_term; //!< 0=not used for ref; 1=top used; 2=bottom used; 3=both fields (or frame) used 151 int is_orig_reference; //!< original marking by nal_ref_idc: 0=not used for ref; 1=top used; 2=bottom used; 3=both fields (or frame) used 152 153 int is_non_existent; 154 155 unsigned frame_num; 156 int frame_num_wrap; 157 int long_term_frame_idx; 158 int is_output; 159 int poc; 160 161 StorablePicture *frame; 162 StorablePicture *top_field; 163 StorablePicture *bottom_field; 164 165 Boolean is_inter_layer; 166 167 #if (MVC_EXTENSION_ENABLE) 168 int view_id; 169 int inter_view_flag[2]; 170 int anchor_pic_flag[2]; 171 #endif 172 }; 173 174 175 176 //! Decoded Picture Buffer 177 typedef struct decoded_picture_buffer 178 { 179 VideoParameters *p_Vid; 180 InputParameters *p_Inp; 181 FrameStore **fs; 182 FrameStore **fs_ref; 183 FrameStore **fs_ltref; 184 FrameStore **fs_ilref; 185 int num_ref_frames; 186 unsigned size; 187 unsigned used_size; 188 unsigned ref_frames_in_buffer; 189 unsigned ltref_frames_in_buffer; 190 int last_output_poc; 191 #if (MVC_EXTENSION_ENABLE) 192 int last_output_view_id; 193 #endif 194 int max_long_term_pic_idx; 195 196 int init_done; 197 198 FrameStore *last_picture; 199 int layer_id; 200 unsigned used_size_il; 201 202 FrameFormat storage_format; 203 204 void (*pf_GetHMEIntImagesLuma)( VideoParameters *p_Vid, int size_x, int size_y, imgpel ***cImgInt); 205 206 207 void (*pf_luma_prediction) ( Macroblock* currMB, int, int, int, int, int, int[2], char *, short ); 208 void (*pf_luma_prediction_bi) ( Macroblock* currMB, int, int, int, int, int, int, short, short, int ); 209 void (*pf_chroma_prediction) ( Macroblock* currMB, int, int, int, int, int, int, int, int, short, short, short ); 210 void (*pf_get_block_luma) ( struct video_par *, imgpel*, int*, int, int, int, int, struct storable_picture*, int ); 211 void (*pf_get_block_chroma[2]) ( struct video_par *, imgpel*, int*, int, int, int, int, struct storable_picture*, int ); 212 void (*pf_OneComponentChromaPrediction4x4_regenerate)(Macroblock *currMB, imgpel* , int , int , MotionVector ** , StorablePicture *listX, int ); 213 void (*pf_OneComponentChromaPrediction4x4_retrieve) (Macroblock *currMB, imgpel* , int , int , MotionVector ** , StorablePicture *listX, int ); 214 distblk (*pf_computeSAD) (StorablePicture *ref1, MEBlock*, distblk, MotionVector *); 215 distblk (*pf_computeSADWP) (StorablePicture *ref1, MEBlock*, distblk, MotionVector *); 216 distblk (*pf_computeSATD) (StorablePicture *ref1, MEBlock*, distblk, MotionVector *); 217 distblk (*pf_computeSATDWP) (StorablePicture *ref1, MEBlock*, distblk, MotionVector *); 218 distblk (*pf_computeBiPredSAD1)(StorablePicture *ref1, StorablePicture *ref2, MEBlock*, distblk, MotionVector *, MotionVector *); 219 distblk (*pf_computeBiPredSAD2)(StorablePicture *ref1, StorablePicture *ref2, MEBlock*, distblk, MotionVector *, MotionVector *); 220 distblk (*pf_computeBiPredSATD1) (StorablePicture *ref1, StorablePicture *ref2, MEBlock*, distblk, MotionVector *, MotionVector *); 221 distblk (*pf_computeBiPredSATD2) (StorablePicture *ref1, StorablePicture *ref2, MEBlock*, distblk, MotionVector *, MotionVector *); 222 distblk (*pf_computeSSE) (StorablePicture *ref1, MEBlock*, distblk, MotionVector *); 223 distblk (*pf_computeSSEWP) (StorablePicture *ref1, MEBlock*, distblk, MotionVector *); 224 distblk (*pf_computeBiPredSSE1) (StorablePicture *ref1, StorablePicture *ref2, MEBlock*, distblk, MotionVector *, MotionVector *); 225 distblk (*pf_computeBiPredSSE2) (StorablePicture *ref1, StorablePicture *ref2, MEBlock*, distblk, MotionVector *, MotionVector *); 226 }DecodedPictureBuffer; 227 228 extern void init_dpb (VideoParameters *p_Vid, DecodedPictureBuffer *dpb); 229 extern void free_dpb (DecodedPictureBuffer *p_Dpb); 230 extern FrameStore* alloc_frame_store(void); 231 extern void free_frame_store (VideoParameters *p_Vid, FrameStore* f); 232 extern StorablePicture* alloc_storable_picture (VideoParameters *p_Vid, PictureStructure type, int size_x, int size_y, int size_x_cr, int size_y_cr); 233 extern void free_storable_picture (VideoParameters *p_Vid, StorablePicture* p); 234 extern void store_picture_in_dpb (DecodedPictureBuffer *p_Dpb, StorablePicture* p, FrameFormat *output); 235 extern void replace_top_pic_with_frame(DecodedPictureBuffer *p_Dpb, StorablePicture* p, FrameFormat *output); 236 extern void flush_dpb (DecodedPictureBuffer *p_Dpb, FrameFormat *output); 237 extern void dpb_split_field (VideoParameters *p_Vid, FrameStore *fs); 238 extern void dpb_combine_field (VideoParameters *p_Vid, FrameStore *fs); 239 extern void dpb_combine_field_yuv (VideoParameters *p_Vid, FrameStore *fs); 240 extern void init_lists_p_slice (Slice *currSlice); 241 extern void init_lists_b_slice (Slice *currSlice); 242 extern void init_lists_i_slice (Slice *currSlice); 243 extern void update_pic_num (Slice *currSlice); 244 extern void reorder_ref_pic_list (Slice *currSlice, int cur_list); 245 extern void init_mbaff_lists (Slice *currSlice); 246 extern void alloc_ref_pic_list_reordering_buffer (Slice *currSlice); 247 extern void free_ref_pic_list_reordering_buffer (Slice *currSlice); 248 extern void fill_frame_num_gap (VideoParameters *p_Vid, FrameFormat *output); 249 extern void compute_colocated (Slice *currSlice, StorablePicture **listX[6]); 250 extern void reorder_short_term(Slice *currSlice, DecodedPictureBuffer *p_Dpb, int cur_list, int picNumLX, int *refIdxLX); 251 252 extern void unmark_for_reference(FrameStore* fs); 253 extern void unmark_for_long_term_reference(FrameStore* fs); 254 extern void remove_frame_from_dpb(DecodedPictureBuffer *p_Dpb, int pos); 255 256 #if (MVC_EXTENSION_ENABLE) 257 void check_num_ref(DecodedPictureBuffer *p_Dpb); 258 extern void replace_top_proc_pic_with_frame(DecodedPictureBuffer *p_Dpb, StorablePicture* p); 259 extern void store_proc_picture_in_dpb(DecodedPictureBuffer *p_Dpb, StorablePicture* p, FrameFormat *output); 260 #endif 261 262 #endif 263 264