vpuapifunc.h 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  1. /*
  2. * Copyright (c) 2019, Chips&Media
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  18. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #ifndef VPUAPI_UTIL_H_INCLUDED
  26. #define VPUAPI_UTIL_H_INCLUDED
  27. #ifdef USE_FEEDING_METHOD_BUFFER
  28. #include "wave511/vpuapi/vpuapi.h"
  29. #else
  30. #include "vpuapi.h"
  31. #endif
  32. // COD_STD
  33. enum {
  34. AVC_DEC = 0,
  35. VC1_DEC = 1,
  36. MP2_DEC = 2,
  37. MP4_DEC = 3,
  38. DV3_DEC = 3,
  39. RV_DEC = 4,
  40. AVS_DEC = 5,
  41. VPX_DEC = 7,
  42. MAX_DEC = 7,
  43. AVC_ENC = 8,
  44. MP4_ENC = 11,
  45. MAX_CODECS,
  46. };
  47. // new COD_STD since WAVE series
  48. enum {
  49. W_HEVC_DEC = 0x00,
  50. W_HEVC_ENC = 0x01,
  51. W_AVC_DEC = 0x02,
  52. W_AVC_ENC = 0x03,
  53. W_VP9_DEC = 0x16,
  54. W_AVS2_DEC = 0x18,
  55. W_SVAC_DEC = 0x20,
  56. W_SVAC_ENC = 0x21,
  57. W_AV1_DEC = 0x1A,
  58. STD_UNKNOWN = 0xFF
  59. };
  60. // AUX_COD_STD
  61. enum {
  62. MP4_AUX_MPEG4 = 0,
  63. MP4_AUX_DIVX3 = 1
  64. };
  65. enum {
  66. VPX_AUX_THO = 0,
  67. VPX_AUX_VP6 = 1,
  68. VPX_AUX_VP8 = 2,
  69. VPX_AUX_NUM
  70. };
  71. enum {
  72. AVC_AUX_AVC = 0,
  73. AVC_AUX_MVC = 1
  74. };
  75. // BIT_RUN command
  76. enum {
  77. DEC_SEQ_INIT = 1,
  78. ENC_SEQ_INIT = 1,
  79. DEC_SEQ_END = 2,
  80. ENC_SEQ_END = 2,
  81. PIC_RUN = 3,
  82. SET_FRAME_BUF = 4,
  83. ENCODE_HEADER = 5,
  84. ENC_PARA_SET = 6,
  85. DEC_PARA_SET = 7,
  86. DEC_BUF_FLUSH = 8,
  87. RC_CHANGE_PARAMETER = 9,
  88. VPU_SLEEP = 10,
  89. VPU_WAKE = 11,
  90. ENC_ROI_INIT = 12,
  91. FIRMWARE_GET = 0xf
  92. };
  93. enum {
  94. SRC_BUFFER_EMPTY = 0, //!< source buffer doesn't allocated.
  95. SRC_BUFFER_ALLOCATED = 1, //!< source buffer has been allocated.
  96. SRC_BUFFER_SRC_LOADED = 2, //!< source buffer has been allocated.
  97. SRC_BUFFER_USE_ENCODE = 3 //!< source buffer was sent to VPU. but it was not used for encoding.
  98. };
  99. typedef enum {
  100. AUX_BUF_TYPE_MVCOL,
  101. AUX_BUF_TYPE_FBC_Y_OFFSET,
  102. AUX_BUF_TYPE_FBC_C_OFFSET
  103. } AUX_BUF_TYPE;
  104. #ifndef MAX
  105. #define MAX(a, b) (((a) > (b)) ? (a) : (b))
  106. #endif
  107. #ifndef MIN
  108. #define MIN(a,b) (((a) < (b)) ? (a) : (b))
  109. #endif
  110. #define HEVC_MAX_SUB_LAYER_ID 6
  111. #define AVS2_MAX_SUB_LAYER_ID 7
  112. #define SVAC_MAX_SUB_LAYER_ID 3
  113. #define DECODE_ALL_TEMPORAL_LAYERS -1
  114. //#define API_DEBUG
  115. #ifdef API_DEBUG
  116. #ifdef _MSC_VER
  117. #define APIDPRINT(_fmt, ...) printf(_fmt, __VA_ARGS__)
  118. #else
  119. #define APIDPRINT(_fmt, ...) printf(_fmt, ##__VA_ARGS__)
  120. #endif
  121. #else
  122. #define APIDPRINT(_fmt, ...)
  123. #endif
  124. extern Uint32 __VPU_BUSY_TIMEOUT;
  125. /**
  126. * PRODUCT: CODA960/CODA980/WAVE320
  127. */
  128. typedef struct {
  129. union {
  130. struct {
  131. int useBitEnable;
  132. int useIpEnable;
  133. int useDbkYEnable;
  134. int useDbkCEnable;
  135. int useOvlEnable;
  136. int useBtpEnable;
  137. PhysicalAddress bufBitUse;
  138. PhysicalAddress bufIpAcDcUse;
  139. PhysicalAddress bufDbkYUse;
  140. PhysicalAddress bufDbkCUse;
  141. PhysicalAddress bufOvlUse;
  142. PhysicalAddress bufBtpUse;
  143. } coda9;
  144. struct {
  145. int useIpEnable;
  146. int useSclEnable;
  147. int useLfRowEnable;
  148. int useBitEnable;
  149. PhysicalAddress bufIp;
  150. PhysicalAddress bufLfRow;
  151. PhysicalAddress bufBit;
  152. PhysicalAddress bufScaler;
  153. PhysicalAddress bufScalerPackedData;
  154. int useEncImdEnable;
  155. int useEncRdoEnable;
  156. int useEncLfEnable;
  157. PhysicalAddress bufImd;
  158. PhysicalAddress bufRdo;
  159. PhysicalAddress bufLf;
  160. } wave;
  161. } u;
  162. int bufSize;
  163. PhysicalAddress bufBase;
  164. } SecAxiInfo;
  165. typedef struct {
  166. DecOpenParam openParam;
  167. DecInitialInfo initialInfo;
  168. DecInitialInfo newSeqInfo; /* Temporal new sequence information */
  169. PhysicalAddress streamWrPtr;
  170. PhysicalAddress streamRdPtr;
  171. Int32 streamBufFull;
  172. int streamEndflag;
  173. int frameDisplayFlag;
  174. int clearDisplayIndexes;
  175. int setDisplayIndexes;
  176. PhysicalAddress streamRdPtrRegAddr;
  177. PhysicalAddress streamWrPtrRegAddr;
  178. PhysicalAddress streamBufStartAddr;
  179. PhysicalAddress streamBufEndAddr;
  180. PhysicalAddress frameDisplayFlagRegAddr;
  181. PhysicalAddress currentPC;
  182. PhysicalAddress busyFlagAddr;
  183. int streamBufSize;
  184. FrameBuffer frameBufPool[MAX_REG_FRAME];
  185. vpu_buffer_t vbFrame;
  186. vpu_buffer_t vbWTL;
  187. vpu_buffer_t vbPPU;
  188. vpu_buffer_t vbMV[MAX_REG_FRAME];
  189. vpu_buffer_t vbFbcYTbl[MAX_REG_FRAME];
  190. vpu_buffer_t vbFbcCTbl[MAX_REG_FRAME];
  191. int chBwbFrameIdx;
  192. int chFbcFrameIdx;
  193. BOOL interResChange;
  194. int frameAllocExt;
  195. int ppuAllocExt;
  196. int numFrameBuffers;
  197. int numFbsForDecoding; /*!<< number of framebuffers used in decoding */
  198. int numFbsForWTL; /*!<< number of linear framebuffer for displaying when DecInfo::wtlEnable is set to 1 */
  199. int stride;
  200. int frameBufferHeight;
  201. int rotationEnable;
  202. int mirrorEnable;
  203. int deringEnable;
  204. MirrorDirection mirrorDirection;
  205. int rotationAngle;
  206. FrameBuffer rotatorOutput;
  207. int rotatorStride;
  208. int rotatorOutputValid;
  209. int initialInfoObtained;
  210. int vc1BframeDisplayValid;
  211. int mapType;
  212. int tiled2LinearEnable;
  213. int tiled2LinearMode;
  214. int wtlEnable;
  215. int wtlMode;
  216. FrameBufferFormat wtlFormat; /*!<< default value: FORMAT_420 8bit */
  217. SecAxiInfo secAxiInfo;
  218. MaverickCacheConfig cacheConfig;
  219. int chunkSize;
  220. int seqInitEscape;
  221. // Report Information
  222. PhysicalAddress userDataBufAddr;
  223. vpu_buffer_t vbUserData;
  224. Uint32 userDataEnable; /* User Data Enable Flag
  225. CODA9xx: TRUE or FALSE
  226. WAVExxx: Refer to H265_USERDATA_FLAG_xxx values in vpuapi.h */
  227. int userDataBufSize;
  228. int userDataReportMode; // User Data report mode (0 : interrupt mode, 1 interrupt disable mode)
  229. LowDelayInfo lowDelayInfo;
  230. int frameStartPos;
  231. int frameEndPos;
  232. int frameDelay;
  233. vpu_buffer_t vbSlice; // AVC, VP8 only
  234. vpu_buffer_t vbWork;
  235. vpu_buffer_t vbTemp;
  236. vpu_buffer_t vbReport;
  237. vpu_buffer_t vbTask;
  238. int workBufferAllocExt;
  239. DecOutputInfo decOutInfo[MAX_GDI_IDX];
  240. TiledMapConfig mapCfg;
  241. int reorderEnable;
  242. Uint32 avcErrorConcealMode;
  243. DRAMConfig dramCfg; //coda960 only
  244. int thumbnailMode;
  245. int seqChangeMask; // WAVE410
  246. Uint32 prevFrameEndPos; //!<< WAVE410v2: end position of previous frame
  247. BOOL scalerEnable;
  248. Uint32 scaleWidth;
  249. Uint32 scaleHeight;
  250. Int32 tempIdSelectMode;
  251. Int32 targetSubLayerId; //!<< temporal scalability
  252. Int32 relTargetLayerId;
  253. int rdPtrValidFlag;
  254. Int32 instanceQueueCount;
  255. Int32 reportQueueCount;
  256. Uint32 firstCycleCheck;
  257. Uint32 cyclePerTick;
  258. Uint32 productCode;
  259. Uint32 vlcBufSize;
  260. Uint32 paramBufSize;
  261. } DecInfo;
  262. typedef struct {
  263. EncOpenParam openParam;
  264. EncInitialInfo initialInfo;
  265. PhysicalAddress streamRdPtr;
  266. PhysicalAddress streamWrPtr;
  267. int streamEndflag;
  268. PhysicalAddress streamRdPtrRegAddr;
  269. PhysicalAddress streamWrPtrRegAddr;
  270. PhysicalAddress streamBufStartAddr;
  271. PhysicalAddress streamBufEndAddr;
  272. PhysicalAddress currentPC;
  273. PhysicalAddress busyFlagAddr;
  274. int streamBufSize;
  275. int linear2TiledEnable;
  276. int linear2TiledMode; // coda980 only
  277. TiledMapType mapType;
  278. int userMapEnable;
  279. FrameBuffer frameBufPool[MAX_REG_FRAME];
  280. vpu_buffer_t vbFrame;
  281. vpu_buffer_t vbPPU;
  282. int frameAllocExt;
  283. int ppuAllocExt;
  284. vpu_buffer_t vbSubSampFrame; /*!<< CODA960 only */
  285. vpu_buffer_t vbMvcSubSampFrame; /*!<< CODA960 only */
  286. int numFrameBuffers;
  287. int stride;
  288. int frameBufferHeight;
  289. int rotationEnable;
  290. int mirrorEnable;
  291. MirrorDirection mirrorDirection;
  292. int rotationAngle;
  293. int initialInfoObtained;
  294. int ringBufferEnable;
  295. SecAxiInfo secAxiInfo;
  296. MaverickCacheConfig cacheConfig;
  297. int sliceIntEnable; /*!<< WAVE420 only */
  298. int ActivePPSIdx; /*!<< CODA980 */
  299. int frameIdx; /*!<< CODA980 */
  300. int fieldDone; /*!<< CODA980 */
  301. int lineBufIntEn;
  302. vpu_buffer_t vbWork;
  303. vpu_buffer_t vbScratch;
  304. vpu_buffer_t vbTemp; //!< Temp buffer (WAVE encoder )
  305. vpu_buffer_t vbMV; //!< colMV buffer (WAVE encoder)
  306. vpu_buffer_t vbMVBL; //!< colMV buffer (WAVE encoder)
  307. vpu_buffer_t vbFbcYTbl; //!< FBC Luma table buffer (WAVE encoder)
  308. vpu_buffer_t vbFbcCTbl; //!< FBC Chroma table buffer (WAVE encoder)
  309. vpu_buffer_t vbFbcYTblBL; //!< FBC Luma table buffer (WAVE encoder)
  310. vpu_buffer_t vbFbcCTblBL; //!< FBC Chroma table buffer (WAVE encoder)
  311. vpu_buffer_t vbSubSamBuf; //!< Sub-sampled buffer for ME (WAVE encoder)
  312. vpu_buffer_t vbSubSamBufBL; //!< Sub-sampled buffer for ME (WAVE encoder)
  313. vpu_buffer_t vbTask;
  314. TiledMapConfig mapCfg;
  315. DRAMConfig dramCfg; /*!<< CODA960 */
  316. Int32 errorReasonCode;
  317. Uint64 curPTS; /**! Current timestamp in 90KHz */
  318. Uint64 ptsMap[32]; /**! PTS mapped with source frame index */
  319. Uint32 instanceQueueCount;
  320. Uint32 reportQueueCount;
  321. Uint32 encWrPtrSel;
  322. Uint32 firstCycleCheck;
  323. Uint32 cyclePerTick;
  324. Uint32 productCode;
  325. Uint32 vlcBufSize;
  326. Uint32 paramBufSize;
  327. Int32 ringBufferWrapEnable;
  328. PhysicalAddress streamBufTobeReadStartAddr;
  329. PhysicalAddress streamBufTobeReadEndAddr;
  330. Int32 streamBufTobeReadSize;
  331. } EncInfo;
  332. typedef struct CodecInst {
  333. Int32 inUse;
  334. Int32 instIndex;
  335. Int32 coreIdx;
  336. Int32 codecMode;
  337. Int32 codecModeAux;
  338. Int32 productId;
  339. Int32 loggingEnable;
  340. Uint32 isDecoder;
  341. union {
  342. EncInfo encInfo;
  343. DecInfo decInfo;
  344. }* CodecInfo;
  345. } CodecInst;
  346. /*******************************************************************************
  347. * H.265 USER DATA(VUI and SEI) *
  348. *******************************************************************************/
  349. #define H265_MAX_DPB_SIZE 17
  350. #define H265_MAX_NUM_SUB_LAYER 8
  351. #define H265_MAX_NUM_ST_RPS 64
  352. #define H265_MAX_CPB_CNT 32
  353. #define H265_MAX_NUM_VERTICAL_FILTERS 5
  354. #define H265_MAX_NUM_HORIZONTAL_FILTERS 3
  355. #define H265_MAX_TAP_LENGTH 32
  356. #define H265_MAX_NUM_KNEE_POINT 999
  357. #define H265_MAX_NUM_TONE_VALUE 1024
  358. #define H265_MAX_NUM_FILM_GRAIN_COMPONENT 3
  359. #define H265_MAX_NUM_INTENSITY_INTERVALS 256
  360. #define H265_MAX_NUM_MODEL_VALUES 5
  361. #define H265_MAX_LUT_NUM_VAL 3
  362. #define H265_MAX_LUT_NUM_VAL_MINUS1 33
  363. #define H265_MAX_COLOUR_REMAP_COEFFS 3
  364. typedef struct
  365. {
  366. Uint32 offset;
  367. Uint32 size;
  368. } user_data_entry_t;
  369. typedef struct
  370. {
  371. Int16 left;
  372. Int16 right;
  373. Int16 top;
  374. Int16 bottom;
  375. } win_t;
  376. typedef struct
  377. {
  378. Uint8 nal_hrd_param_present_flag;
  379. Uint8 vcl_hrd_param_present_flag;
  380. Uint8 sub_pic_hrd_params_present_flag;
  381. Uint8 tick_divisor_minus2;
  382. Int8 du_cpb_removal_delay_inc_length_minus1;
  383. Int8 sub_pic_cpb_params_in_pic_timing_sei_flag;
  384. Int8 dpb_output_delay_du_length_minus1;
  385. Int8 bit_rate_scale;
  386. Int8 cpb_size_scale;
  387. Int8 initial_cpb_removal_delay_length_minus1;
  388. Int8 cpb_removal_delay_length_minus1;
  389. Int8 dpb_output_delay_length_minus1;
  390. Uint8 fixed_pic_rate_gen_flag[H265_MAX_NUM_SUB_LAYER];
  391. Uint8 fixed_pic_rate_within_cvs_flag[H265_MAX_NUM_SUB_LAYER];
  392. Uint8 low_delay_hrd_flag[H265_MAX_NUM_SUB_LAYER];
  393. Int8 cpb_cnt_minus1[H265_MAX_NUM_SUB_LAYER];
  394. Int16 elemental_duration_in_tc_minus1[H265_MAX_NUM_SUB_LAYER];
  395. Uint32 nal_bit_rate_value_minus1[H265_MAX_NUM_SUB_LAYER][H265_MAX_CPB_CNT];
  396. Uint32 nal_cpb_size_value_minus1[H265_MAX_NUM_SUB_LAYER][H265_MAX_CPB_CNT];
  397. Uint32 nal_cpb_size_du_value_minus1[H265_MAX_NUM_SUB_LAYER];
  398. Uint32 nal_bit_rate_du_value_minus1[H265_MAX_NUM_SUB_LAYER];
  399. Uint8 nal_cbr_flag[H265_MAX_NUM_SUB_LAYER][H265_MAX_CPB_CNT];
  400. Uint32 vcl_bit_rate_value_minus1[H265_MAX_NUM_SUB_LAYER][H265_MAX_CPB_CNT];
  401. Uint32 vcl_cpb_size_value_minus1[H265_MAX_NUM_SUB_LAYER][H265_MAX_CPB_CNT];
  402. Uint32 vcl_cpb_size_du_value_minus1[H265_MAX_NUM_SUB_LAYER];
  403. Uint32 vcl_bit_rate_du_value_minus1[H265_MAX_NUM_SUB_LAYER];
  404. Uint8 vcl_cbr_flag[H265_MAX_NUM_SUB_LAYER][H265_MAX_CPB_CNT];
  405. } h265_hrd_param_t;
  406. typedef struct
  407. {
  408. Uint8 aspect_ratio_info_present_flag;
  409. Uint8 aspect_ratio_idc;
  410. Uint8 overscan_info_present_flag;
  411. Uint8 overscan_appropriate_flag;
  412. Uint8 video_signal_type_present_flag;
  413. Int8 video_format;
  414. Uint8 video_full_range_flag;
  415. Uint8 colour_description_present_flag;
  416. Uint16 sar_width;
  417. Uint16 sar_height;
  418. Uint8 colour_primaries;
  419. Uint8 transfer_characteristics;
  420. Uint8 matrix_coefficients;
  421. Uint8 chroma_loc_info_present_flag;
  422. Int8 chroma_sample_loc_type_top_field;
  423. Int8 chroma_sample_loc_type_bottom_field;
  424. Uint8 neutral_chroma_indication_flag;
  425. Uint8 field_seq_flag;
  426. Uint8 frame_field_info_present_flag;
  427. Uint8 default_display_window_flag;
  428. Uint8 vui_timing_info_present_flag;
  429. Uint8 vui_poc_proportional_to_timing_flag;
  430. Uint32 vui_num_units_in_tick;
  431. Uint32 vui_time_scale;
  432. Uint8 vui_hrd_parameters_present_flag;
  433. Uint8 bitstream_restriction_flag;
  434. Uint8 tiles_fixed_structure_flag;
  435. Uint8 motion_vectors_over_pic_boundaries_flag;
  436. Uint8 restricted_ref_pic_lists_flag;
  437. Int8 min_spatial_segmentation_idc;
  438. Int8 max_bytes_per_pic_denom;
  439. Int8 max_bits_per_mincu_denom;
  440. Int16 vui_num_ticks_poc_diff_one_minus1;
  441. Int8 log2_max_mv_length_horizontal;
  442. Int8 log2_max_mv_length_vertical;
  443. win_t def_disp_win;
  444. h265_hrd_param_t hrd_param;
  445. } h265_vui_param_t;
  446. typedef struct
  447. {
  448. Uint32 display_primaries_x[3];
  449. Uint32 display_primaries_y[3];
  450. Uint32 white_point_x : 16;
  451. Uint32 white_point_y : 16;
  452. Uint32 max_display_mastering_luminance : 32;
  453. Uint32 min_display_mastering_luminance : 32;
  454. } h265_mastering_display_colour_volume_t;
  455. typedef struct
  456. {
  457. Uint32 ver_chroma_filter_idc : 8;
  458. Uint32 hor_chroma_filter_idc : 8;
  459. Uint32 ver_filtering_field_processing_flag : 1;
  460. Uint32 target_format_idc : 2;
  461. Uint32 num_vertical_filters : 3;
  462. Uint32 num_horizontal_filters : 3;
  463. Uint8 ver_tap_length_minus1[ H265_MAX_NUM_VERTICAL_FILTERS ];
  464. Uint8 hor_tap_length_minus1[ H265_MAX_NUM_HORIZONTAL_FILTERS ];
  465. Int32 ver_filter_coeff[ H265_MAX_NUM_VERTICAL_FILTERS ][ H265_MAX_TAP_LENGTH ];
  466. Int32 hor_filter_coeff[ H265_MAX_NUM_HORIZONTAL_FILTERS ][ H265_MAX_TAP_LENGTH ];
  467. } h265_chroma_resampling_filter_hint_t;
  468. typedef struct
  469. {
  470. Uint32 knee_function_id;
  471. Uint8 knee_function_cancel_flag;
  472. Uint8 knee_function_persistence_flag;
  473. Uint32 input_disp_luminance;
  474. Uint32 input_d_range;
  475. Uint32 output_d_range;
  476. Uint32 output_disp_luminance;
  477. Uint16 num_knee_points_minus1;
  478. Uint16 input_knee_point[ H265_MAX_NUM_KNEE_POINT ];
  479. Uint16 output_knee_point[ H265_MAX_NUM_KNEE_POINT ];
  480. } h265_knee_function_info_t;
  481. typedef struct
  482. {
  483. Uint16 max_content_light_level;
  484. Uint16 max_pic_average_light_level;
  485. } h265_content_light_level_info_t;
  486. typedef struct
  487. {
  488. Uint32 colour_remap_id;
  489. Uint8 colour_remap_cancel_flag;
  490. Uint8 colour_remap_persistence_flag;
  491. Uint8 colour_remap_video_signal_info_present_flag;
  492. Uint8 colour_remap_full_range_flag;
  493. Uint8 colour_remap_primaries;
  494. Uint8 colour_remap_transfer_function;
  495. Uint8 colour_remap_matrix_coefficients;
  496. Uint8 colour_remap_input_bit_depth;
  497. Uint8 colour_remap_bit_depth;
  498. Uint8 pre_lut_num_val_minus1[H265_MAX_LUT_NUM_VAL];
  499. Uint16 pre_lut_coded_value[H265_MAX_LUT_NUM_VAL][H265_MAX_LUT_NUM_VAL_MINUS1];
  500. Uint16 pre_lut_target_value[H265_MAX_LUT_NUM_VAL][H265_MAX_LUT_NUM_VAL_MINUS1];
  501. Uint8 colour_remap_matrix_present_flag;
  502. Uint8 log2_matrix_denom;
  503. Uint8 colour_remap_coeffs[H265_MAX_COLOUR_REMAP_COEFFS][H265_MAX_COLOUR_REMAP_COEFFS];
  504. Uint8 post_lut_num_val_minus1[H265_MAX_LUT_NUM_VAL];
  505. Uint16 post_lut_coded_value[H265_MAX_LUT_NUM_VAL][H265_MAX_LUT_NUM_VAL_MINUS1];
  506. Uint16 post_lut_target_value[H265_MAX_LUT_NUM_VAL][H265_MAX_LUT_NUM_VAL_MINUS1];
  507. } h265_colour_remapping_info_t;
  508. typedef struct
  509. {
  510. Uint8 film_grain_characteristics_cancel_flag;
  511. Uint8 film_grain_model_id;
  512. Uint8 separate_colour_description_present_flag;
  513. Uint8 film_grain_bit_depth_luma_minus8;
  514. Uint8 film_grain_bit_depth_chroma_minus8;
  515. Uint8 film_grain_full_range_flag;
  516. Uint8 film_grain_colour_primaries;
  517. Uint8 film_grain_transfer_characteristics;
  518. Uint8 film_grain_matrix_coeffs;
  519. Uint8 blending_mode_id;
  520. Uint8 log2_scale_factor;
  521. Uint8 comp_model_present_flag[H265_MAX_NUM_FILM_GRAIN_COMPONENT];
  522. Uint8 num_intensity_intervals_minus1[H265_MAX_NUM_FILM_GRAIN_COMPONENT];
  523. Uint8 num_model_values_minus1[H265_MAX_NUM_FILM_GRAIN_COMPONENT];
  524. Uint8 intensity_interval_lower_bound[H265_MAX_NUM_FILM_GRAIN_COMPONENT][H265_MAX_NUM_INTENSITY_INTERVALS];
  525. Uint8 intensity_interval_upper_bound[H265_MAX_NUM_FILM_GRAIN_COMPONENT][H265_MAX_NUM_INTENSITY_INTERVALS];
  526. Uint32 comp_model_value[H265_MAX_NUM_FILM_GRAIN_COMPONENT][H265_MAX_NUM_INTENSITY_INTERVALS][H265_MAX_NUM_MODEL_VALUES];
  527. Uint8 film_grain_characteristics_persistence_flag;
  528. } h265_film_grain_characteristics_t;
  529. typedef struct
  530. {
  531. Uint32 tone_map_id;
  532. Uint8 tone_map_cancel_flag;
  533. Uint8 tone_map_persistence_flag;
  534. Uint32 coded_data_bit_depth;
  535. Uint32 target_bit_depth;
  536. Uint8 tone_map_model_id;
  537. Uint32 min_value;
  538. Uint32 max_value;
  539. Uint32 sigmoid_midpoint;
  540. Uint32 sigmoid_width;
  541. Uint16 start_of_coded_interval[H265_MAX_NUM_TONE_VALUE]; // [1 << target_bit_depth] // 10bits
  542. Uint16 num_pivots; // [(1 << coded_data_bit_depth)?1][(1 << target_bit_depth)-1] // 10bits
  543. Uint16 coded_pivot_value[H265_MAX_NUM_TONE_VALUE];
  544. Uint16 target_pivot_value[H265_MAX_NUM_TONE_VALUE];
  545. Uint8 camera_iso_speed_idc;
  546. Uint32 camera_iso_speed_value;
  547. Uint8 exposure_index_idc;
  548. Uint32 exposure_index_value;
  549. Uint8 exposure_compensation_value_sign_flag;
  550. Uint16 exposure_compensation_value_numerator;
  551. Uint16 exposure_compensation_value_denom_idc;
  552. Uint32 ref_screen_luminance_white;
  553. Uint32 extended_range_white_level;
  554. Uint16 nominal_black_level_code_value;
  555. Uint16 nominal_white_level_code_value;
  556. Uint16 extended_white_level_code_value;
  557. } h265_tone_mapping_info_t;
  558. typedef struct
  559. {
  560. Int8 status; // 0 : empty, 1 : occupied
  561. Int8 pic_struct;
  562. Int8 source_scan_type;
  563. Int8 duplicate_flag;
  564. } h265_sei_pic_timing_t;
  565. /*******************************************************************************
  566. * H.264 USER DATA(VUI and SEI) *
  567. *******************************************************************************/
  568. typedef struct
  569. {
  570. Int16 cpb_cnt;
  571. Uint8 bit_rate_scale;
  572. Uint8 cbp_size_scale;
  573. Int16 initial_cpb_removal_delay_length;
  574. Int16 cpb_removal_delay_length;
  575. Int16 dpb_output_delay_length;
  576. Int16 time_offset_length;
  577. Uint32 bit_rate_value[32];
  578. Uint32 cpb_size_value[32];
  579. Uint8 cbr_flag[32];
  580. } avc_hrd_param_t;
  581. typedef struct
  582. {
  583. Uint8 aspect_ratio_info_present_flag;
  584. Uint8 aspect_ratio_idc;
  585. Uint16 sar_width;
  586. Uint16 sar_height;
  587. Uint8 overscan_info_present_flag;
  588. Uint8 overscan_appropriate_flag;
  589. Uint8 video_signal_type_present_flag;
  590. Int8 video_format;
  591. Uint8 video_full_range_flag;
  592. Uint8 colour_description_present_flag;
  593. Uint8 colour_primaries;
  594. Uint8 transfer_characteristics;
  595. Uint8 matrix_coefficients;
  596. Uint8 chroma_loc_info_present_flag;
  597. Int8 chroma_sample_loc_type_top_field;
  598. Int8 chroma_sample_loc_type_bottom_field;
  599. Uint8 vui_timing_info_present_flag;
  600. Uint32 vui_num_units_in_tick;
  601. Uint32 vui_time_scale;
  602. Uint8 vui_fixed_frame_rate_flag;
  603. Uint8 vcl_hrd_parameters_present_flag;
  604. Uint8 nal_hrd_parameters_present_flag;
  605. Uint8 low_delay_hrd_flag;
  606. Uint8 pic_struct_present_flag;
  607. Uint8 bitstream_restriction_flag;
  608. Uint8 motion_vectors_over_pic_boundaries_flag;
  609. Int8 max_bytes_per_pic_denom;
  610. Int8 max_bits_per_mincu_denom;
  611. Int8 log2_max_mv_length_horizontal;
  612. Int8 log2_max_mv_length_vertical;
  613. Int8 max_num_reorder_frames;
  614. Int8 max_dec_frame_buffering;
  615. avc_hrd_param_t vcl_hrd;
  616. avc_hrd_param_t nal_hrd;
  617. } avc_vui_info_t;
  618. typedef struct
  619. {
  620. Uint32 cpb_removal_delay;
  621. Uint32 dpb_output_delay;
  622. Uint8 pic_struct;
  623. Uint8 num_clock_ts;
  624. } avc_sei_pic_timing_t;
  625. #define AVC_MAX_NUM_FILM_GRAIN_COMPONENT 3
  626. #define AVC_MAX_NUM_INTENSITY_INTERVALS 256
  627. #define AVC_MAX_NUM_MODEL_VALUES 5
  628. #define AVC_MAX_NUM_TONE_VALUE 1024
  629. typedef struct
  630. {
  631. Uint8 film_grain_characteristics_cancel_flag;
  632. Uint8 film_grain_model_id;
  633. Uint8 separate_colour_description_present_flag;
  634. Uint8 film_grain_bit_depth_luma_minus8;
  635. Uint8 film_grain_bit_depth_chroma_minus8;
  636. Uint8 film_grain_full_range_flag;
  637. Uint8 film_grain_colour_primaries;
  638. Uint8 film_grain_transfer_characteristics;
  639. Uint8 film_grain_matrix_coeffs;
  640. Uint8 blending_mode_id;
  641. Uint8 log2_scale_factor;
  642. Uint8 comp_model_present_flag[AVC_MAX_NUM_FILM_GRAIN_COMPONENT];
  643. Uint8 num_intensity_intervals_minus1[AVC_MAX_NUM_FILM_GRAIN_COMPONENT];
  644. Uint8 num_model_values_minus1[AVC_MAX_NUM_FILM_GRAIN_COMPONENT];
  645. Uint8 intensity_interval_lower_bound[AVC_MAX_NUM_FILM_GRAIN_COMPONENT][AVC_MAX_NUM_INTENSITY_INTERVALS];
  646. Uint8 intensity_interval_upper_bound[AVC_MAX_NUM_FILM_GRAIN_COMPONENT][AVC_MAX_NUM_INTENSITY_INTERVALS];
  647. Uint32 comp_model_value[AVC_MAX_NUM_FILM_GRAIN_COMPONENT][AVC_MAX_NUM_INTENSITY_INTERVALS][AVC_MAX_NUM_MODEL_VALUES];
  648. Uint8 film_grain_characteristics_persistence_flag;
  649. } avc_sei_film_grain_t;
  650. typedef struct
  651. {
  652. Uint32 tone_map_id;
  653. Uint8 tone_map_cancel_flag;
  654. Uint32 tone_map_repetition_period;
  655. Uint32 coded_data_bit_depth;
  656. Uint32 target_bit_depth;
  657. Uint8 tone_map_model_id;
  658. Uint32 min_value;
  659. Uint32 max_value;
  660. Uint32 sigmoid_midpoint;
  661. Uint32 sigmoid_width;
  662. Uint16 start_of_coded_interval[AVC_MAX_NUM_TONE_VALUE];
  663. Uint16 num_pivots;
  664. Uint16 coded_pivot_value[AVC_MAX_NUM_TONE_VALUE];
  665. Uint16 target_pivot_value[AVC_MAX_NUM_TONE_VALUE];
  666. Uint8 camera_iso_speed_idc;
  667. Uint32 camera_iso_speed_value;
  668. Uint8 exposure_index_idc;
  669. Uint32 exposure_index_value;
  670. Uint8 exposure_compensation_value_sign_flag;
  671. Uint16 exposure_compensation_value_numerator;
  672. Uint16 exposure_compensation_value_denom_idc;
  673. Uint32 ref_screen_luminance_white;
  674. Uint32 extended_range_white_level;
  675. Uint16 nominal_black_level_code_value;
  676. Uint16 nominal_white_level_code_value;
  677. Uint16 extended_white_level_code_value;
  678. } avc_sei_tone_mapping_info_t;
  679. typedef struct
  680. {
  681. Uint32 colour_remap_id;
  682. Uint8 colour_cancel_flag;
  683. Uint16 colour_remap_repetition_period;
  684. Uint8 colour_remap_video_signal_info_present_flag;
  685. Uint8 colour_remap_full_range_flag;
  686. Uint8 colour_remap_primaries;
  687. Uint8 colour_remap_transfer_function;
  688. Uint8 colour_remap_matrix_coefficients;
  689. Uint8 colour_remap_input_bit_depth;
  690. Uint8 colour_remap_output_bit_depth;
  691. Uint8 pre_lut_num_val_minus1[3];
  692. Uint16 pre_lut_coded_value[3][33];
  693. Uint16 pre_lut_target_value[3][33];
  694. Uint8 colour_remap_matrix_present_flag;
  695. Uint8 log2_matrix_denom;
  696. Uint8 colour_remap_coeffs[3][3];
  697. Uint8 post_lut_num_val_minus1[3];
  698. Uint16 post_lut_coded_value[3][33];
  699. Uint16 post_lut_target_value[3][33];
  700. } avc_sei_colour_remap_info_t;
  701. #ifdef __cplusplus
  702. extern "C" {
  703. #endif
  704. RetCode InitCodecInstancePool(Uint32 coreIdx);
  705. RetCode GetCodecInstance(Uint32 coreIdx, CodecInst ** ppInst);
  706. void FreeCodecInstance(CodecInst * pCodecInst);
  707. RetCode CheckDecOpenParam(DecOpenParam * pop);
  708. int DecBitstreamBufEmpty(DecInfo * pDecInfo);
  709. RetCode SetParaSet(DecHandle handle, int paraSetType, DecParamSet * para);
  710. void DecSetHostParaAddr(Uint32 coreIdx, PhysicalAddress baseAddr, PhysicalAddress paraAddr);
  711. RetCode CheckInstanceValidity(
  712. CodecInst * pCodecInst
  713. );
  714. Int32 ConfigSecAXICoda9(
  715. Uint32 coreIdx,
  716. Int32 codecMode,
  717. SecAxiInfo* sa,
  718. Uint32 width,
  719. Uint32 height,
  720. Uint32 profile
  721. );
  722. Int32 ConfigSecAXIWave(
  723. Uint32 coreIdx,
  724. Int32 codecMode,
  725. SecAxiInfo* sa,
  726. Uint32 width,
  727. Uint32 height,
  728. Uint32 profile,
  729. Uint32 level
  730. );
  731. RetCode UpdateFrameBufferAddr(
  732. TiledMapType mapType,
  733. FrameBuffer* fbArr,
  734. Uint32 numOfFrameBuffers,
  735. Uint32 sizeLuma,
  736. Uint32 sizeChroma
  737. );
  738. RetCode AllocateTiledFrameBufferGdiV1(
  739. TiledMapType mapType,
  740. PhysicalAddress tiledBaseAddr,
  741. FrameBuffer* fbArr,
  742. Uint32 numOfFrameBuffers,
  743. Uint32 sizeLuma,
  744. Uint32 sizeChroma,
  745. DRAMConfig* pDramCfg
  746. );
  747. RetCode AllocateTiledFrameBufferGdiV2(
  748. TiledMapType mapType,
  749. FrameBuffer* fbArr,
  750. Uint32 numOfFrameBuffers,
  751. Uint32 sizeLuma,
  752. Uint32 sizeChroma
  753. );
  754. RetCode CheckEncInstanceValidity(EncHandle handle);
  755. RetCode CheckEncOpenParam(EncOpenParam * pop);
  756. RetCode CheckEncParam(EncHandle handle, EncParam * param);
  757. RetCode GetEncHeader(EncHandle handle, EncHeaderParam * encHeaderParam);
  758. RetCode EncParaSet(EncHandle handle, int paraSetType);
  759. RetCode SetGopNumber(EncHandle handle, Uint32 *gopNumber);
  760. RetCode SetIntraQp(EncHandle handle, Uint32 *intraQp);
  761. RetCode SetBitrate(EncHandle handle, Uint32 *bitrate);
  762. RetCode SetFramerate(EncHandle handle, Uint32 *frameRate);
  763. RetCode SetIntraRefreshNum(EncHandle handle, Uint32 *pIntraRefreshNum);
  764. RetCode SetSliceMode(EncHandle handle, EncSliceMode *pSliceMode);
  765. RetCode SetHecMode(EncHandle handle, int mode);
  766. RetCode EnterLock(Uint32 coreIdx);
  767. RetCode LeaveLock(Uint32 coreIdx);
  768. RetCode SetClockGate(Uint32 coreIdx, Uint32 on);
  769. RetCode EnterDispFlagLock(Uint32 coreIdx);
  770. RetCode LeaveDispFlagLock(Uint32 coreIdx);
  771. void SetPendingInst(Uint32 coreIdx, CodecInst *inst);
  772. void ClearPendingInst(Uint32 coreIdx);
  773. CodecInst *GetPendingInst(Uint32 coreIdx);
  774. int GetPendingInstIdx(Uint32 coreIdx);
  775. Int32 MaverickCache2Config(
  776. MaverickCacheConfig* pCache,
  777. BOOL decoder ,
  778. BOOL interleave,
  779. Uint32 bypass,
  780. Uint32 burst,
  781. Uint32 merge,
  782. TiledMapType mapType,
  783. Uint32 wayshape
  784. );
  785. int SetTiledMapType(Uint32 coreIdx, TiledMapConfig *pMapCfg, int mapType, int stride, int interleave, DRAMConfig *dramCfg);
  786. int GetXY2AXIAddr(TiledMapConfig *pMapCfg, int ycbcr, int posY, int posX, int stride, FrameBuffer *fb);
  787. int GetLowDelayOutput(CodecInst *pCodecInst, DecOutputInfo *lowDelayOutput);
  788. //for GDI 1.0
  789. void SetTiledFrameBase(Uint32 coreIdx, PhysicalAddress baseAddr);
  790. PhysicalAddress GetTiledFrameBase(Uint32 coreIdx, FrameBuffer *frame, int num);
  791. /**
  792. * \brief It returns the stride of framebuffer in byte.
  793. *
  794. * \param width picture width in pixel.
  795. * \param format YUV format. see FrameBufferFormat structure in vpuapi.h
  796. * \param cbcrInterleave
  797. * \param mapType map type. see TiledMapType in vpuapi.h
  798. */
  799. Int32 CalcStride(
  800. Uint32 width,
  801. Uint32 height,
  802. FrameBufferFormat format,
  803. BOOL cbcrInterleave,
  804. TiledMapType mapType,
  805. BOOL isVP9
  806. );
  807. Int32 CalcLumaSize(
  808. CodecInst* inst,
  809. Int32 productId,
  810. Int32 stride,
  811. Int32 height,
  812. FrameBufferFormat format,
  813. BOOL cbcrIntl,
  814. TiledMapType mapType,
  815. DRAMConfig* pDramCfg
  816. );
  817. Int32 CalcChromaSize(
  818. CodecInst* inst,
  819. Int32 productId,
  820. Int32 stride,
  821. Int32 height,
  822. FrameBufferFormat format,
  823. BOOL cbcrIntl,
  824. TiledMapType mapType,
  825. DRAMConfig* pDramCfg
  826. );
  827. /**
  828. * @brief This structure is used for reporting bandwidth (only for WAVE5).
  829. */
  830. typedef struct {
  831. Uint32 prpBwRead;
  832. Uint32 prpBwWrite;
  833. Uint32 fbdYRead;
  834. Uint32 fbcYWrite;
  835. Uint32 fbdCRead;
  836. Uint32 fbcCWrite;
  837. Uint32 priBwRead;
  838. Uint32 priBwWrite;
  839. Uint32 secBwRead;
  840. Uint32 secBwWrite;
  841. Uint32 procBwRead;
  842. Uint32 procBwWrite;
  843. } VPUBWData;
  844. typedef struct {
  845. Uint32 priReason;
  846. Uint32 debugInfo0;
  847. Uint32 debugInfo1;
  848. } VPUDebugInfo;
  849. int LevelCalculation(int MbNumX, int MbNumY, int frameRateInfo, int interlaceFlag, int BitRate, int SliceNum);
  850. /* timescale: 1/90000 */
  851. Uint64 GetTimestamp(
  852. EncHandle handle
  853. );
  854. RetCode CalcEncCropInfo(
  855. CodecInst* instance,
  856. EncWaveParam* param,
  857. int rotMode,
  858. int srcWidth,
  859. int srcHeight
  860. );
  861. #if defined(SUPPORT_SW_UART) || defined(SUPPORT_SW_UART_V2)
  862. void SwUartHandler(void *context);
  863. int create_sw_uart_thread(unsigned long coreIdx);
  864. void destory_sw_uart_thread();
  865. #endif
  866. #ifdef __cplusplus
  867. }
  868. #endif
  869. #endif // endif VPUAPI_UTIL_H_INCLUDED