PageRenderTime 63ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/Avc/avcint_common.h

http://github.com/mbebenita/Broadway
C Header | 882 lines | 521 code | 101 blank | 260 comment | 0 complexity | 7ea9e0ea85c0e3ae3129da728989a904 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. /* ------------------------------------------------------------------
  2. * Copyright (C) 1998-2009 PacketVideo
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  13. * express or implied.
  14. * See the License for the specific language governing permissions
  15. * and limitations under the License.
  16. * -------------------------------------------------------------------
  17. */
  18. /**
  19. This file contains common code shared between AVC decoder and AVC encoder for
  20. internal use only.
  21. @publishedAll
  22. */
  23. #ifndef AVCINT_COMMON_H_INCLUDED
  24. #define AVCINT_COMMON_H_INCLUDED
  25. #ifndef AVCAPI_COMMON_H_INCLUDED
  26. #include "avcapi_common.h"
  27. #endif
  28. #ifndef TRUE
  29. #define TRUE 1
  30. #define FALSE 0
  31. #endif
  32. /**
  33. Mathematic functions defined in subclause 5.7.
  34. Can be replaced with assembly instructions for speedup.
  35. @publishedAll
  36. */
  37. #define AVC_ABS(x) (((x)<0)? -(x) : (x))
  38. #define AVC_SIGN(x) (((x)<0)? -1 : 1)
  39. #define AVC_SIGN0(x) (((x)<0)? -1 : (((x)>0) ? 1 : 0))
  40. #define AVC_MAX(x,y) ((x)>(y)? (x):(y))
  41. #define AVC_MIN(x,y) ((x)<(y)? (x):(y))
  42. #define AVC_MEDIAN(A,B,C) ((A) > (B) ? ((A) < (C) ? (A) : (B) > (C) ? (B) : (C)): (B) < (C) ? (B) : (C) > (A) ? (C) : (A))
  43. #define AVC_CLIP3(a,b,x) (AVC_MAX(a,AVC_MIN(x,b))) /* clip x between a and b */
  44. #define AVC_CLIP(x) AVC_CLIP3(0,255,x)
  45. #define AVC_FLOOR(x) ((int)(x))
  46. #define AVC_RASTER_SCAN(x,y,n) ((x)+(y)*(n))
  47. #define AVC_ROUND(x) (AVC_SIGN(x)*AVC_FLOOR(AVC_ABS(x)+0.5))
  48. #define AVC_INVERSE_RASTER_SCAN(a,b,c,d,e) (((e)==0)? (((a)%((d)/(b)))*(b)): (((a)/((d)/(b)))*(c)))
  49. /* a:block address, b:block width, c:block height, d:total_width, e:x or y coordinate */
  50. #define DEFAULT_ATTR 0 /* default memory attribute */
  51. #define FAST_MEM_ATTR 1 /* fast memory attribute */
  52. /* This section is for definition of constants. */
  53. #define MB_SIZE 16
  54. #define BLOCK_SIZE 4
  55. #define EMULATION_PREVENTION_THREE_BYTE 0x3
  56. #define NUM_PIXELS_IN_MB (24*16)
  57. #define NUM_BLKS_IN_MB 24
  58. #define AVCNumI4PredMode 9
  59. #define AVCNumI16PredMode 4
  60. #define AVCNumIChromaMode 4
  61. /* constants used in the structures below */
  62. #define MAXIMUMVALUEOFcpb_cnt 32 /* used in HRDParams */
  63. #define MAX_NUM_REF_FRAMES_IN_PIC_ORDER_CNT_CYCLE 255 /* used in SeqParamSet */
  64. #define MAX_NUM_SLICE_GROUP 8 /* used in PicParamSet */
  65. #define MAX_REF_PIC_LIST_REORDERING 32 /* 32 is maximum according to Annex A, SliceHeader */
  66. #define MAX_DEC_REF_PIC_MARKING 64 /* 64 is the maximum possible given the max num ref pictures to 31. */
  67. #define MAX_FS (16+1) /* pre-defined size of frame store array */
  68. #define MAX_LEVEL_IDX 15 /* only 15 levels defined for now */
  69. #define MAX_REF_PIC_LIST 33 /* max size of the RefPicList0 and RefPicList1 */
  70. /**
  71. Architectural related macros.
  72. @publishedAll
  73. */
  74. #ifdef USE_PRED_BLOCK
  75. #define MB_BASED_DEBLOCK
  76. #endif
  77. /**
  78. Picture type, PV created.
  79. @publishedAll
  80. */
  81. typedef enum
  82. {
  83. AVC_FRAME = 3
  84. } AVCPictureType;
  85. /**
  86. This slice type follows Table 7-3. The bottom 5 items may not needed.
  87. @publishedAll
  88. */
  89. typedef enum
  90. {
  91. AVC_P_SLICE = 0,
  92. AVC_B_SLICE = 1,
  93. AVC_I_SLICE = 2,
  94. AVC_SP_SLICE = 3,
  95. AVC_SI_SLICE = 4,
  96. AVC_P_ALL_SLICE = 5,
  97. AVC_B_ALL_SLICE = 6,
  98. AVC_I_ALL_SLICE = 7,
  99. AVC_SP_ALL_SLICE = 8,
  100. AVC_SI_ALL_SLICE = 9
  101. } AVCSliceType;
  102. /**
  103. Types of the macroblock and partition. PV Created.
  104. @publishedAll
  105. */
  106. typedef enum
  107. {
  108. /* intra */
  109. AVC_I4,
  110. AVC_I16,
  111. AVC_I_PCM,
  112. AVC_SI4,
  113. /* inter for both P and B*/
  114. AVC_BDirect16,
  115. AVC_P16,
  116. AVC_P16x8,
  117. AVC_P8x16,
  118. AVC_P8,
  119. AVC_P8ref0,
  120. AVC_SKIP
  121. } AVCMBMode;
  122. /**
  123. Enumeration for sub-macroblock mode, interpreted from sub_mb_type.
  124. @publishedAll
  125. */
  126. typedef enum
  127. {
  128. /* for sub-partition mode */
  129. AVC_BDirect8,
  130. AVC_8x8,
  131. AVC_8x4,
  132. AVC_4x8,
  133. AVC_4x4
  134. } AVCSubMBMode;
  135. /**
  136. Mode of prediction of partition or sub-partition. PV Created.
  137. Do not change the order!!! Used in table look-up mode prediction in
  138. vlc.c.
  139. @publishedAll
  140. */
  141. typedef enum
  142. {
  143. AVC_Pred_L0 = 0,
  144. AVC_Pred_L1,
  145. AVC_BiPred,
  146. AVC_Direct
  147. } AVCPredMode;
  148. /**
  149. Mode of intra 4x4 prediction. Table 8-2
  150. @publishedAll
  151. */
  152. typedef enum
  153. {
  154. AVC_I4_Vertical = 0,
  155. AVC_I4_Horizontal,
  156. AVC_I4_DC,
  157. AVC_I4_Diagonal_Down_Left,
  158. AVC_I4_Diagonal_Down_Right,
  159. AVC_I4_Vertical_Right,
  160. AVC_I4_Horizontal_Down,
  161. AVC_I4_Vertical_Left,
  162. AVC_I4_Horizontal_Up
  163. } AVCIntra4x4PredMode;
  164. /**
  165. Mode of intra 16x16 prediction. Table 8-3
  166. @publishedAll
  167. */
  168. typedef enum
  169. {
  170. AVC_I16_Vertical = 0,
  171. AVC_I16_Horizontal,
  172. AVC_I16_DC,
  173. AVC_I16_Plane
  174. } AVCIntra16x16PredMode;
  175. /**
  176. Mode of intra chroma prediction. Table 8-4
  177. @publishedAll
  178. */
  179. typedef enum
  180. {
  181. AVC_IC_DC = 0,
  182. AVC_IC_Horizontal,
  183. AVC_IC_Vertical,
  184. AVC_IC_Plane
  185. } AVCIntraChromaPredMode;
  186. /**
  187. Type of residual going to residual_block_cavlc function, PV created.
  188. @publishedAll
  189. */
  190. typedef enum
  191. {
  192. AVC_Luma,
  193. AVC_Intra16DC,
  194. AVC_Intra16AC,
  195. AVC_ChromaDC,
  196. AVC_ChromaAC
  197. } AVCResidualType;
  198. /**
  199. This structure contains VUI parameters as specified in Annex E.
  200. Some variables may be removed from the structure if they are found to be useless to store.
  201. @publishedAll
  202. */
  203. typedef struct tagHRDParams
  204. {
  205. uint cpb_cnt_minus1; /* ue(v), range 0..31 */
  206. uint bit_rate_scale; /* u(4) */
  207. uint cpb_size_scale; /* u(4) */
  208. uint32 bit_rate_value_minus1[MAXIMUMVALUEOFcpb_cnt];/* ue(v), range 0..2^32-2 */
  209. uint32 cpb_size_value_minus1[MAXIMUMVALUEOFcpb_cnt]; /* ue(v), range 0..2^32-2 */
  210. uint cbr_flag[MAXIMUMVALUEOFcpb_cnt]; /* u(1) */
  211. uint initial_cpb_removal_delay_length_minus1; /* u(5), default 23 */
  212. uint cpb_removal_delay_length_minus1; /* u(5), default 23 */
  213. uint dpb_output_delay_length_minus1; /* u(5), default 23 */
  214. uint time_offset_length; /* u(5), default 24 */
  215. } AVCHRDParams;
  216. /**
  217. This structure contains VUI parameters as specified in Annex E.
  218. Some variables may be removed from the structure if they are found to be useless to store.
  219. @publishedAll
  220. */
  221. typedef struct tagVUIParam
  222. {
  223. uint aspect_ratio_info_present_flag; /* u(1) */
  224. uint aspect_ratio_idc; /* u(8), table E-1 */
  225. uint sar_width; /* u(16) */
  226. uint sar_height; /* u(16) */
  227. uint overscan_info_present_flag; /* u(1) */
  228. uint overscan_appropriate_flag; /* u(1) */
  229. uint video_signal_type_present_flag; /* u(1) */
  230. uint video_format; /* u(3), Table E-2, default 5, unspecified */
  231. uint video_full_range_flag; /* u(1) */
  232. uint colour_description_present_flag; /* u(1) */
  233. uint colour_primaries; /* u(8), Table E-3, default 2, unspecified */
  234. uint transfer_characteristics; /* u(8), Table E-4, default 2, unspecified */
  235. uint matrix_coefficients; /* u(8), Table E-5, default 2, unspecified */
  236. uint chroma_location_info_present_flag; /* u(1) */
  237. uint chroma_sample_loc_type_top_field; /* ue(v), Fig. E-1range 0..5, default 0 */
  238. uint chroma_sample_loc_type_bottom_field; /* ue(v) */
  239. uint timing_info_present_flag; /* u(1) */
  240. uint num_units_in_tick; /* u(32), must be > 0 */
  241. uint time_scale; /* u(32), must be > 0 */
  242. uint fixed_frame_rate_flag; /* u(1), Eq. C-13 */
  243. uint nal_hrd_parameters_present_flag; /* u(1) */
  244. AVCHRDParams nal_hrd_parameters; /* hrd_paramters */
  245. uint vcl_hrd_parameters_present_flag; /* u(1) */
  246. AVCHRDParams vcl_hrd_parameters; /* hrd_paramters */
  247. /* if ((nal_hrd_parameters_present_flag || (vcl_hrd_parameters_present_flag)) */
  248. uint low_delay_hrd_flag; /* u(1) */
  249. uint pic_struct_present_flag;
  250. uint bitstream_restriction_flag; /* u(1) */
  251. uint motion_vectors_over_pic_boundaries_flag; /* u(1) */
  252. uint max_bytes_per_pic_denom; /* ue(v), default 2 */
  253. uint max_bits_per_mb_denom; /* ue(v), range 0..16, default 1 */
  254. uint log2_max_mv_length_vertical; /* ue(v), range 0..16, default 16 */
  255. uint log2_max_mv_length_horizontal; /* ue(v), range 0..16, default 16 */
  256. uint max_dec_frame_reordering; /* ue(v) */
  257. uint max_dec_frame_buffering; /* ue(v) */
  258. } AVCVUIParams;
  259. /**
  260. This structure contains information in a sequence parameter set NAL.
  261. Some variables may be removed from the structure if they are found to be useless to store.
  262. @publishedAll
  263. */
  264. typedef struct tagSeqParamSet
  265. {
  266. uint Valid; /* indicates the parameter set is valid */
  267. uint profile_idc; /* u(8) */
  268. uint constrained_set0_flag; /* u(1) */
  269. uint constrained_set1_flag; /* u(1) */
  270. uint constrained_set2_flag; /* u(1) */
  271. uint constrained_set3_flag; /* u(1) */
  272. uint level_idc; /* u(8) */
  273. uint seq_parameter_set_id; /* ue(v), range 0..31 */
  274. uint log2_max_frame_num_minus4; /* ue(v), range 0..12 */
  275. uint pic_order_cnt_type; /* ue(v), range 0..2 */
  276. /* if( pic_order_cnt_type == 0 ) */
  277. uint log2_max_pic_order_cnt_lsb_minus4; /* ue(v), range 0..12 */
  278. /* else if( pic_order_cnt_type == 1 ) */
  279. uint delta_pic_order_always_zero_flag; /* u(1) */
  280. int32 offset_for_non_ref_pic; /* se(v) */
  281. int32 offset_for_top_to_bottom_field; /* se(v) */
  282. uint num_ref_frames_in_pic_order_cnt_cycle; /* ue(v) , range 0..255 */
  283. /* for( i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; i++ ) */
  284. int32 offset_for_ref_frame[MAX_NUM_REF_FRAMES_IN_PIC_ORDER_CNT_CYCLE]; /* se(v) */
  285. uint num_ref_frames; /* ue(v), range 0..16 */
  286. uint gaps_in_frame_num_value_allowed_flag; /* u(1) */
  287. uint pic_width_in_mbs_minus1; /* ue(v) */
  288. uint pic_height_in_map_units_minus1; /* ue(v) */
  289. uint frame_mbs_only_flag; /* u(1) */
  290. /* if( !frame_mbs_only_flag ) */
  291. uint mb_adaptive_frame_field_flag; /* u(1) */
  292. uint direct_8x8_inference_flag; /* u(1), must be 1 when frame_mbs_only_flag is 0 */
  293. uint frame_cropping_flag; /* u(1) */
  294. /* if( frmae_cropping_flag) */
  295. uint frame_crop_left_offset; /* ue(v) */
  296. uint frame_crop_right_offset; /* ue(v) */
  297. uint frame_crop_top_offset; /* ue(v) */
  298. uint frame_crop_bottom_offset; /* ue(v) */
  299. uint vui_parameters_present_flag; /* u(1) */
  300. // uint nal_hrd_parameters_present_flag;
  301. // uint vcl_hrd_parameters_present_flag;
  302. // AVCHRDParams *nal_hrd_parameters;
  303. // AVCHRDParams *vcl_hrd_parameters;
  304. AVCVUIParams vui_parameters; /* AVCVUIParam */
  305. } AVCSeqParamSet;
  306. /**
  307. This structure contains information in a picture parameter set NAL.
  308. Some variables may be removed from the structure if they are found to be useless to store.
  309. @publishedAll
  310. */
  311. typedef struct tagPicParamSet
  312. {
  313. uint pic_parameter_set_id; /* ue(v), range 0..255 */
  314. uint seq_parameter_set_id; /* ue(v), range 0..31 */
  315. uint entropy_coding_mode_flag; /* u(1) */
  316. uint pic_order_present_flag; /* u(1) */
  317. uint num_slice_groups_minus1; /* ue(v), range in Annex A */
  318. /* if( num_slice_groups_minus1 > 0) */
  319. uint slice_group_map_type; /* ue(v), range 0..6 */
  320. /* if( slice_group_map_type = = 0 ) */
  321. /* for(0:1:num_slice_groups_minus1) */
  322. uint run_length_minus1[MAX_NUM_SLICE_GROUP]; /* ue(v) */
  323. /* else if( slice_group_map_type = = 2 ) */
  324. /* for(0:1:num_slice_groups_minus1-1) */
  325. uint top_left[MAX_NUM_SLICE_GROUP-1]; /* ue(v) */
  326. uint bottom_right[MAX_NUM_SLICE_GROUP-1]; /* ue(v) */
  327. /* else if( slice_group_map_type = = 3 || 4 || 5 */
  328. uint slice_group_change_direction_flag; /* u(1) */
  329. uint slice_group_change_rate_minus1; /* ue(v) */
  330. /* else if( slice_group_map_type = = 6 ) */
  331. uint pic_size_in_map_units_minus1; /* ue(v) */
  332. /* for(0:1:pic_size_in_map_units_minus1) */
  333. uint *slice_group_id; /* complete MBAmap u(v) */
  334. uint num_ref_idx_l0_active_minus1; /* ue(v), range 0..31 */
  335. uint num_ref_idx_l1_active_minus1; /* ue(v), range 0..31 */
  336. uint weighted_pred_flag; /* u(1) */
  337. uint weighted_bipred_idc; /* u(2), range 0..2 */
  338. int pic_init_qp_minus26; /* se(v), range -26..25 */
  339. int pic_init_qs_minus26; /* se(v), range -26..25 */
  340. int chroma_qp_index_offset; /* se(v), range -12..12 */
  341. uint deblocking_filter_control_present_flag; /* u(1) */
  342. uint constrained_intra_pred_flag; /* u(1) */
  343. uint redundant_pic_cnt_present_flag; /* u(1) */
  344. } AVCPicParamSet;
  345. /**
  346. This structure contains slice header information.
  347. Some variables may be removed from the structure if they are found to be useless to store.
  348. @publishedAll
  349. */
  350. typedef struct tagSliceHeader
  351. {
  352. uint first_mb_in_slice; /* ue(v) */
  353. AVCSliceType slice_type; /* ue(v), Table 7-3, range 0..9 */
  354. uint pic_parameter_set_id; /* ue(v), range 0..255 */
  355. uint frame_num; /* u(v), see log2max_frame_num_minus4 */
  356. /* if( !frame_mbs_only_flag) */
  357. uint field_pic_flag; /* u(1) */
  358. /* if(field_pic_flag) */
  359. uint bottom_field_flag; /* u(1) */
  360. /* if(nal_unit_type == 5) */
  361. uint idr_pic_id; /* ue(v), range 0..65535 */
  362. /* if(pic_order_cnt_type==0) */
  363. uint pic_order_cnt_lsb; /* u(v), range 0..MaxPicOrderCntLsb-1 */
  364. /* if(pic_order_present_flag && !field_pic_flag) */
  365. int32 delta_pic_order_cnt_bottom; /* se(v) */
  366. /* if(pic_order_cnt_type==1 && !delta_pic_order_always_zero_flag) */
  367. /* if(pic_order_present_flag && !field_pic_flag) */
  368. int32 delta_pic_order_cnt[2];
  369. /* if(redundant_pic_cnt_present_flag) */
  370. uint redundant_pic_cnt; /* ue(v), range 0..127 */
  371. /* if(slice_type == B) */
  372. uint direct_spatial_mv_pred_flag; /* u(1) */
  373. /* if(slice_type == P || slice_type==SP || slice_type==B) */
  374. uint num_ref_idx_active_override_flag; /* u(1) */
  375. /* if(num_ref_idx_active_override_flag) */
  376. uint num_ref_idx_l0_active_minus1; /* ue(v) */
  377. /* if(slie_type == B) */
  378. uint num_ref_idx_l1_active_minus1; /* ue(v) */
  379. /* ref_pic_list_reordering() */
  380. uint ref_pic_list_reordering_flag_l0; /* u(1) */
  381. uint reordering_of_pic_nums_idc_l0[MAX_REF_PIC_LIST_REORDERING]; /* ue(v), range 0..3 */
  382. uint abs_diff_pic_num_minus1_l0[MAX_REF_PIC_LIST_REORDERING]; /* ue(v) */
  383. uint long_term_pic_num_l0[MAX_REF_PIC_LIST_REORDERING]; /* ue(v) */
  384. uint ref_pic_list_reordering_flag_l1; /* u(1) */
  385. uint reordering_of_pic_nums_idc_l1[MAX_REF_PIC_LIST_REORDERING]; /* ue(v), range 0..3 */
  386. uint abs_diff_pic_num_minus1_l1[MAX_REF_PIC_LIST_REORDERING]; /* ue(v) */
  387. uint long_term_pic_num_l1[MAX_REF_PIC_LIST_REORDERING]; /* ue(v) */
  388. /* end ref_pic_list_reordering() */
  389. /* if(nal_ref_idc!=0) */
  390. /* dec_ref_pic_marking() */
  391. uint no_output_of_prior_pics_flag; /* u(1) */
  392. uint long_term_reference_flag; /* u(1) */
  393. uint adaptive_ref_pic_marking_mode_flag; /* u(1) */
  394. uint memory_management_control_operation[MAX_DEC_REF_PIC_MARKING]; /* ue(v), range 0..6 */
  395. uint difference_of_pic_nums_minus1[MAX_DEC_REF_PIC_MARKING]; /* ue(v) */
  396. uint long_term_pic_num[MAX_DEC_REF_PIC_MARKING]; /* ue(v) */
  397. uint long_term_frame_idx[MAX_DEC_REF_PIC_MARKING]; /* ue(v) */
  398. uint max_long_term_frame_idx_plus1[MAX_DEC_REF_PIC_MARKING]; /* ue(v) */
  399. /* end dec_ref_pic_marking() */
  400. /* if(entropy_coding_mode_flag && slice_type!=I && slice_type!=SI) */
  401. uint cabac_init_idc; /* ue(v), range 0..2 */
  402. int slice_qp_delta; /* se(v), range 0..51 */
  403. /* if(slice_type==SP || slice_type==SI) */
  404. /* if(slice_type==SP) */
  405. uint sp_for_switch_flag; /* u(1) */
  406. int slice_qs_delta; /* se(v) */
  407. /* if(deblocking_filter_control_present_flag)*/
  408. uint disable_deblocking_filter_idc; /* ue(v), range 0..2 */
  409. /* if(disable_deblocking_filter_idc!=1) */
  410. int slice_alpha_c0_offset_div2; /* se(v), range -6..6, default 0 */
  411. int slice_beta_offset_div_2; /* se(v), range -6..6, default 0 */
  412. /* if(num_slice_groups_minus1>0 && slice_group_map_type>=3 && slice_group_map_type<=5)*/
  413. uint slice_group_change_cycle; /* u(v), use ceil(log2(PicSizeInMapUnits/SliceGroupChangeRate + 1)) bits*/
  414. } AVCSliceHeader;
  415. /**
  416. This struct contains information about the neighboring pixel.
  417. @publishedAll
  418. */
  419. typedef struct tagPixPos
  420. {
  421. int available;
  422. int mb_addr; /* macroblock address of the current pixel, see below */
  423. int x; /* x,y positions of current pixel relative to the macroblock mb_addr */
  424. int y;
  425. int pos_x; /* x,y positions of current pixel relative to the picture. */
  426. int pos_y;
  427. } AVCPixelPos;
  428. typedef struct tagNeighborAvailability
  429. {
  430. int left;
  431. int top; /* macroblock address of the current pixel, see below */
  432. int top_right; /* x,y positions of current pixel relative to the macroblock mb_addr */
  433. } AVCNeighborAvailability;
  434. /**
  435. This structure contains picture data and related information necessary to be used as
  436. reference frame.
  437. @publishedAll
  438. */
  439. typedef struct tagPictureData
  440. {
  441. uint16 RefIdx; /* index used for reference frame */
  442. uint8 *Sl; /* derived from base_dpb in AVCFrameStore */
  443. uint8 *Scb; /* for complementary fields, YUV are interlaced */
  444. uint8 *Scr; /* Sl of top_field and bottom_fields will be one line apart and the
  445. stride will be 2 times the width. */
  446. /* For non-complementary field, the above still applies. A special
  447. output formatting is required. */
  448. /* Then, necessary variables that need to be stored */
  449. AVCPictureType picType; /* frame, top-field or bot-field */
  450. /*bool*/
  451. uint isReference;
  452. /*bool*/
  453. uint isLongTerm;
  454. int PicOrderCnt;
  455. int PicNum;
  456. int LongTermPicNum;
  457. int width; /* how many pixel per line */
  458. int height;/* how many line */
  459. int pitch; /* how many pixel between the line */
  460. uint padded; /* flag for being padded */
  461. } AVCPictureData;
  462. /**
  463. This structure contains information for frame storage.
  464. @publishedAll
  465. */
  466. typedef struct tagFrameStore
  467. {
  468. uint8 *base_dpb; /* base pointer for the YCbCr */
  469. int IsReference; /* 0=not used for ref; 1=top used; 2=bottom used; 3=both fields (or frame) used */
  470. int IsLongTerm; /* 0=not used for ref; 1=top used; 2=bottom used; 3=both fields (or frame) used */
  471. /* if IsLongTerm is true, IsReference can be ignored. */
  472. /* if IsReference is true, IsLongterm will be checked for short-term or long-term. */
  473. /* IsUsed must be true to enable the validity of IsReference and IsLongTerm */
  474. int IsOutputted; /* has it been outputted via AVCDecGetOutput API, then don't output it again,
  475. wait until it is returned. */
  476. AVCPictureData frame;
  477. int FrameNum;
  478. int FrameNumWrap;
  479. int LongTermFrameIdx;
  480. int PicOrderCnt; /* of the frame, smaller of the 2 fields */
  481. } AVCFrameStore;
  482. /**
  483. This structure maintains the actual memory for the decoded picture buffer (DPB) which is
  484. allocated at the beginning according to profile/level.
  485. Once decoded_picture_buffer is allocated, Sl,Scb,Scr in
  486. AVCPictureData structure just point to the address in decoded_picture_buffer.
  487. used_size maintains the used space.
  488. NOTE:: In order to maintain contiguous memory space, memory equal to a single frame is
  489. assigned at a time. Two opposite fields reside in the same frame memory.
  490. |-------|---|---|---|xxx|-------|xxx|---|-------| decoded_picture_buffer
  491. frame top bot top frame bot frame
  492. 0 1 1 2 3 4 5
  493. bot 2 and top 4 do not exist, the memory is not used.
  494. @publishedAll
  495. */
  496. typedef struct tagDecPicBuffer
  497. {
  498. uint8 *decoded_picture_buffer; /* actual memory */
  499. uint32 dpb_size; /* size of dpb in bytes */
  500. uint32 used_size; /* used size */
  501. struct tagFrameStore *fs[MAX_FS]; /* list of frame stored, actual buffer */
  502. int num_fs; /* size of fs */
  503. } AVCDecPicBuffer;
  504. /**
  505. This structure contains macroblock related variables.
  506. @publishedAll
  507. */
  508. typedef struct tagMacroblock
  509. {
  510. AVCIntraChromaPredMode intra_chroma_pred_mode; /* ue(v) */
  511. int32 mvL0[16]; /* motion vectors, 16 bit packed (x,y) per element */
  512. int32 mvL1[16];
  513. int16 ref_idx_L0[4];
  514. int16 ref_idx_L1[4];
  515. uint16 RefIdx[4]; /* ref index, has value of AVCPictureData->RefIdx */
  516. /* stored data */
  517. /*bool*/
  518. uint mb_intra; /* intra flag */
  519. /*bool*/
  520. uint mb_bottom_field;
  521. AVCMBMode mbMode; /* type of MB prediction */
  522. AVCSubMBMode subMbMode[4]; /* for each 8x8 partition */
  523. uint CBP; /* CodeBlockPattern */
  524. AVCIntra16x16PredMode i16Mode; /* Intra16x16PredMode */
  525. AVCIntra4x4PredMode i4Mode[16]; /* Intra4x4PredMode, in raster scan order */
  526. int NumMbPart; /* number of partition */
  527. AVCPredMode MBPartPredMode[4][4]; /* prediction mode [MBPartIndx][subMBPartIndx] */
  528. int MbPartWidth;
  529. int MbPartHeight;
  530. int NumSubMbPart[4]; /* for each 8x8 partition */
  531. int SubMbPartWidth[4]; /* for each 8x8 partition */
  532. int SubMbPartHeight[4]; /* for each 8x8 partition */
  533. uint8 nz_coeff[NUM_BLKS_IN_MB]; /* [blk_y][blk_x], Chroma is [4..5][0...3], see predict_nnz() function */
  534. int QPy; /* Luma QP */
  535. int QPc; /* Chroma QP */
  536. int QSc; /* Chroma QP S-picture */
  537. int slice_id; // MC slice
  538. } AVCMacroblock;
  539. /**
  540. This structure contains common internal variables between the encoder and decoder
  541. such that some functions can be shared among them.
  542. @publishedAll
  543. */
  544. typedef struct tagCommonObj
  545. {
  546. /* put these 2 up here to make sure they are word-aligned */
  547. int16 block[NUM_PIXELS_IN_MB]; /* for transformed residue coefficient */
  548. uint8 *pred_block; /* pointer to prediction block, could point to a frame */
  549. #ifdef USE_PRED_BLOCK
  550. uint8 pred[688]; /* for prediction */
  551. /* Luma [0-399], Cb [400-543], Cr[544-687] */
  552. #endif
  553. int pred_pitch; /* either equal to 20 or to frame pitch */
  554. /* temporary buffers for intra prediction */
  555. /* these variables should remain inside fast RAM */
  556. #ifdef MB_BASED_DEBLOCK
  557. uint8 *intra_pred_top; /* a row of pixel for intra prediction */
  558. uint8 intra_pred_left[17]; /* a column of pixel for intra prediction */
  559. uint8 *intra_pred_top_cb;
  560. uint8 intra_pred_left_cb[9];
  561. uint8 *intra_pred_top_cr;
  562. uint8 intra_pred_left_cr[9];
  563. #endif
  564. /* pointer to the prediction area for intra prediction */
  565. uint8 *pintra_pred_top; /* pointer to the top intra prediction value */
  566. uint8 *pintra_pred_left; /* pointer to the left intra prediction value */
  567. uint8 intra_pred_topleft; /* the [-1,-1] neighboring pixel */
  568. uint8 *pintra_pred_top_cb;
  569. uint8 *pintra_pred_left_cb;
  570. uint8 intra_pred_topleft_cb;
  571. uint8 *pintra_pred_top_cr;
  572. uint8 *pintra_pred_left_cr;
  573. uint8 intra_pred_topleft_cr;
  574. int QPy;
  575. int QPc;
  576. int QPy_div_6;
  577. int QPy_mod_6;
  578. int QPc_div_6;
  579. int QPc_mod_6;
  580. /**** nal_unit ******/
  581. /* previously in AVCNALUnit format */
  582. uint NumBytesInRBSP;
  583. int forbidden_bit;
  584. int nal_ref_idc;
  585. AVCNalUnitType nal_unit_type;
  586. AVCNalUnitType prev_nal_unit_type;
  587. /*bool*/
  588. uint slice_data_partitioning; /* flag when nal_unit_type is between 2 and 4 */
  589. /**** ******** ******/
  590. AVCSliceType slice_type;
  591. AVCDecPicBuffer *decPicBuf; /* decoded picture buffer */
  592. AVCSeqParamSet *currSeqParams; /* the currently used one */
  593. AVCPicParamSet *currPicParams; /* the currently used one */
  594. uint seq_parameter_set_id;
  595. /* slice header */
  596. AVCSliceHeader *sliceHdr; /* slice header param syntax variables */
  597. AVCPictureData *currPic; /* pointer to current picture */
  598. AVCFrameStore *currFS; /* pointer to current frame store */
  599. AVCPictureType currPicType; /* frame, top-field or bot-field */
  600. /*bool*/
  601. uint newPic; /* flag for new picture */
  602. uint newSlice; /* flag for new slice */
  603. AVCPictureData *prevRefPic; /* pointer to previous picture */
  604. AVCMacroblock *mblock; /* array of macroblocks covering entire picture */
  605. AVCMacroblock *currMB; /* pointer to current macroblock */
  606. uint mbNum; /* number of current MB */
  607. int mb_x; /* x-coordinate of the current mbNum */
  608. int mb_y; /* y-coordinate of the current mbNum */
  609. /* For internal operation, scratch memory for MV, prediction, transform, etc.*/
  610. uint32 cbp4x4; /* each bit represent nonzero 4x4 block in reverse raster scan order */
  611. /* starting from luma, Cb and Cr, lsb toward msb */
  612. int mvd_l0[4][4][2]; /* [mbPartIdx][subMbPartIdx][compIdx], se(v) */
  613. int mvd_l1[4][4][2]; /* [mbPartIdx][subMbPartIdx][compIdx], se(v) */
  614. int mbAddrA, mbAddrB, mbAddrC, mbAddrD; /* address of neighboring MBs */
  615. /*bool*/
  616. uint mbAvailA, mbAvailB, mbAvailC, mbAvailD; /* availability */
  617. /*bool*/
  618. uint intraAvailA, intraAvailB, intraAvailC, intraAvailD; /* for intra mode */
  619. /***********************************************/
  620. /* The following variables are defined in the draft. */
  621. /* They may need to be stored in PictureData structure and used for reference. */
  622. /* In that case, just move or copy it to AVCDecPictureData structure. */
  623. int padded_size; /* size of extra padding to a frame */
  624. uint MaxFrameNum; /*2^(log2_max_frame_num_minus4+4), range 0.. 2^16-1 */
  625. uint MaxPicOrderCntLsb; /*2^(log2_max_pic_order_cnt_lsb_minus4+4), 0..2^16-1 */
  626. uint PicWidthInMbs; /*pic_width_in_mbs_minus1+1 */
  627. uint PicWidthInSamplesL; /* PicWidthInMbs*16 */
  628. uint PicWidthInSamplesC; /* PicWIdthInMbs*8 */
  629. uint PicHeightInMapUnits; /* pic_height_in_map_units_minus1+1 */
  630. uint PicSizeInMapUnits; /* PicWidthInMbs*PicHeightInMapUnits */
  631. uint FrameHeightInMbs; /*(2-frame_mbs_only_flag)*PicHeightInMapUnits */
  632. uint SliceGroupChangeRate; /* slice_group_change_rate_minus1 + 1 */
  633. /* access unit */
  634. uint primary_pic_type; /* u(3), Table 7-2, kinda informative only */
  635. /* slice data partition */
  636. uint slice_id; /* ue(v) */
  637. uint UnusedShortTermFrameNum;
  638. uint PrevRefFrameNum;
  639. uint MbaffFrameFlag; /* (mb_adaptive_frame_field_flag && !field_pic_flag) */
  640. uint PicHeightInMbs; /* FrameHeightInMbs/(1+field_pic_flag) */
  641. int PicHeightInSamplesL; /* PicHeightInMbs*16 */
  642. int PicHeightInSamplesC; /* PicHeightInMbs*8 */
  643. uint PicSizeInMbs; /* PicWidthInMbs*PicHeightInMbs */
  644. uint level_idc;
  645. int numMBs;
  646. uint MaxPicNum;
  647. uint CurrPicNum;
  648. int QSy; /* 26+pic_init_qp_minus26+slice_qs_delta */
  649. int FilterOffsetA;
  650. int FilterOffsetB;
  651. uint MapUnitsInSliceGroup0; /* Min(slie_group_change_cycle*SliceGroupChangeRate,PicSizeInMapUnits) */
  652. /* dec_ref_pic_marking */
  653. int MaxLongTermFrameIdx;
  654. int LongTermFrameIdx;
  655. /* POC related variables */
  656. /*bool*/
  657. uint mem_mgr_ctrl_eq_5; /* if memory_management_control_operation equal to 5 flag */
  658. int PicOrderCnt;
  659. int BottomFieldOrderCnt, TopFieldOrderCnt;
  660. /* POC mode 0 */
  661. int prevPicOrderCntMsb;
  662. uint prevPicOrderCntLsb;
  663. int PicOrderCntMsb;
  664. /* POC mode 1 */
  665. int prevFrameNumOffset, FrameNumOffset;
  666. uint prevFrameNum;
  667. int absFrameNum;
  668. int picOrderCntCycleCnt, frameNumInPicOrderCntCycle;
  669. int expectedDeltaPerPicOrderCntCycle;
  670. int expectedPicOrderCnt;
  671. /* FMO */
  672. int *MbToSliceGroupMap; /* to be re-calculate at the beginning */
  673. /* ref pic list */
  674. AVCPictureData *RefPicList0[MAX_REF_PIC_LIST]; /* list 0 */
  675. AVCPictureData *RefPicList1[MAX_REF_PIC_LIST]; /* list 1 */
  676. AVCFrameStore *refFrameList0ShortTerm[32];
  677. AVCFrameStore *refFrameList1ShortTerm[32];
  678. AVCFrameStore *refFrameListLongTerm[32];
  679. int refList0Size;
  680. int refList1Size;
  681. /* slice data semantics*/
  682. int mb_skip_run; /* ue(v) */
  683. /*uint mb_skip_flag;*/ /* ae(v) */
  684. /* uint end_of_slice_flag;*//* ae(v) */
  685. /***********************************************/
  686. /* function pointers */
  687. int (*is_short_ref)(AVCPictureData *s);
  688. int (*is_long_ref)(AVCPictureData *s);
  689. } AVCCommonObj;
  690. /**
  691. Commonly used constant arrays.
  692. @publishedAll
  693. */
  694. /**
  695. Zigzag scan from 1-D to 2-D. */
  696. const static uint8 ZZ_SCAN[16] = {0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15};
  697. /* Zigzag scan from 1-D to 2-D output to block[24][16]. */
  698. const static uint8 ZZ_SCAN_BLOCK[16] = {0, 1, 16, 32, 17, 2, 3, 18, 33, 48, 49, 34, 19, 35, 50, 51};
  699. /**
  700. From zigzag to raster for luma DC value */
  701. const static uint8 ZIGZAG2RASTERDC[16] = {0, 4, 64, 128, 68, 8, 12, 72, 132, 192, 196, 136, 76, 140, 200, 204};
  702. /**
  703. Mapping from coding scan block indx to raster scan block index */
  704. const static int blkIdx2blkX[16] = {0, 1, 0, 1, 2, 3, 2, 3, 0, 1, 0, 1, 2, 3, 2, 3};
  705. const static int blkIdx2blkY[16] = {0, 0, 1, 1, 0, 0, 1, 1, 2, 2, 3, 3, 2, 2, 3, 3};
  706. /** from [blk8indx][blk4indx] to raster scan index */
  707. const static int blkIdx2blkXY[4][4] = {{0, 1, 4, 5}, {2, 3, 6, 7}, {8, 9, 12, 13}, {10, 11, 14, 15}};
  708. /*
  709. Availability of the neighboring top-right block relative to the current block. */
  710. const static int BlkTopRight[16] = {2, 2, 2, 3, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0};
  711. /**
  712. Table 8-13 Specification of QPc as a function of qPI. */
  713. const static uint8 mapQPi2QPc[52] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
  714. 21, 22, 23, 24, 25, 26, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 34, 35, 35, 36, 36,
  715. 37, 37, 37, 38, 38, 38, 39, 39, 39, 39
  716. };
  717. /**
  718. See 8.5.5 equation (8-252 and 8-253) the definition of v matrix. */
  719. /* in zigzag scan */
  720. const static int dequant_coefres[6][16] =
  721. {
  722. {10, 13, 13, 10, 16, 10, 13, 13, 13, 13, 16, 10, 16, 13, 13, 16},
  723. {11, 14, 14, 11, 18, 11, 14, 14, 14, 14, 18, 11, 18, 14, 14, 18},
  724. {13, 16, 16, 13, 20, 13, 16, 16, 16, 16, 20, 13, 20, 16, 16, 20},
  725. {14, 18, 18, 14, 23, 14, 18, 18, 18, 18, 23, 14, 23, 18, 18, 23},
  726. {16, 20, 20, 16, 25, 16, 20, 20, 20, 20, 25, 16, 25, 20, 20, 25},
  727. {18, 23, 23, 18, 29, 18, 23, 23, 23, 23, 29, 18, 29, 23, 23, 29}
  728. };
  729. /**
  730. From jm7.6 block.c. (in zigzag scan) */
  731. const static int quant_coef[6][16] =
  732. {
  733. {13107, 8066, 8066, 13107, 5243, 13107, 8066, 8066, 8066, 8066, 5243, 13107, 5243, 8066, 8066, 5243},
  734. {11916, 7490, 7490, 11916, 4660, 11916, 7490, 7490, 7490, 7490, 4660, 11916, 4660, 7490, 7490, 4660},
  735. {10082, 6554, 6554, 10082, 4194, 10082, 6554, 6554, 6554, 6554, 4194, 10082, 4194, 6554, 6554, 4194},
  736. {9362, 5825, 5825, 9362, 3647, 9362, 5825, 5825, 5825, 5825, 3647, 9362, 3647, 5825, 5825, 3647},
  737. {8192, 5243, 5243, 8192, 3355, 8192, 5243, 5243, 5243, 5243, 3355, 8192, 3355, 5243, 5243, 3355},
  738. {7282, 4559, 4559, 7282, 2893, 7282, 4559, 4559, 4559, 4559, 2893, 7282, 2893, 4559, 4559, 2893}
  739. };
  740. /**
  741. Convert scan from raster scan order to block decoding order and
  742. from block decoding order to raster scan order. Same table!!!
  743. */
  744. const static uint8 ras2dec[16] = {0, 1, 4, 5, 2, 3, 6, 7, 8, 9, 12, 13, 10, 11, 14, 15};
  745. /* mapping from level_idc to index map */
  746. const static uint8 mapLev2Idx[61] = {255, 255, 255, 255, 255, 255, 255, 255, 255, 1,
  747. 0, 1, 2, 3, 255, 255, 255, 255, 255, 255,
  748. 4, 5, 6, 255, 255, 255, 255, 255, 255, 255,
  749. 7, 8, 9, 255, 255, 255, 255, 255, 255, 255,
  750. 10, 11, 12, 255, 255, 255, 255, 255, 255, 255,
  751. 13, 14, 255, 255, 255, 255, 255, 255, 255, 255
  752. };
  753. /* map back from index to Level IDC */
  754. const static uint8 mapIdx2Lev[MAX_LEVEL_IDX] = {10, 11, 12, 13, 20, 21, 22, 30, 31, 32, 40, 41, 42, 50, 51};
  755. /**
  756. from the index map to the MaxDPB value times 2 */
  757. const static int32 MaxDPBX2[MAX_LEVEL_IDX] = {297, 675, 1782, 1782, 1782, 3564, 6075, 6075,
  758. 13500, 15360, 24576, 24576, 24576, 82620, 138240
  759. };
  760. /* map index to the max frame size */
  761. const static int MaxFS[MAX_LEVEL_IDX] = {99, 396, 396, 396, 396, 792, 1620, 1620, 3600, 5120,
  762. 8192, 8192, 8192, 22080, 36864
  763. };
  764. /* map index to max MB processing rate */
  765. const static int32 MaxMBPS[MAX_LEVEL_IDX] = {1485, 3000, 6000, 11880, 11880, 19800, 20250, 40500,
  766. 108000, 216000, 245760, 245760, 491520, 589824, 983040
  767. };
  768. /* map index to max video bit rate */
  769. const static uint32 MaxBR[MAX_LEVEL_IDX] = {64, 192, 384, 768, 2000, 4000, 4000, 10000, 14000, 20000,
  770. 20000, 50000, 50000, 135000, 240000
  771. };
  772. /* map index to max CPB size */
  773. const static uint32 MaxCPB[MAX_LEVEL_IDX] = {175, 500, 1000, 2000, 2000, 4000, 4000, 10000, 14000,
  774. 20000, 25000, 62500, 62500, 135000, 240000
  775. };
  776. /* map index to max vertical MV range */
  777. const static int MaxVmvR[MAX_LEVEL_IDX] = {64, 128, 128, 128, 128, 256, 256, 256, 512, 512, 512, 512, 512, 512, 512};
  778. #endif /* _AVCINT_COMMON_H_ */