vpuapifunc.h 32 KB

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