hi_buffer.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. /******************************************************************************
  2. Copyright (C), 2016, Hisilicon Tech. Co., Ltd.
  3. ******************************************************************************
  4. File Name : hi_buffer.h
  5. Version : Initial Draft
  6. Author : Hisilicon multimedia software group
  7. Created : 2016/11/15
  8. Last Modified :
  9. Description : The count defination of buffer size
  10. Function List :
  11. ******************************************************************************/
  12. #ifndef __HI_BUFFER_H__
  13. #define __HI_BUFFER_H__
  14. #ifdef __cplusplus
  15. #if __cplusplus
  16. extern "C" {
  17. #endif
  18. #endif /* __cplusplus */
  19. #include "hi_math.h"
  20. #include "hi_type.h"
  21. #include "hi_common.h"
  22. #include "hi_comm_video.h"
  23. __inline static HI_VOID COMMON_GetPicBufferConfig(HI_U32 u32Width, HI_U32 u32Height,PIXEL_FORMAT_E enPixelFormat,
  24. DATA_BITWIDTH_E enBitWidth, COMPRESS_MODE_E enCmpMode, HI_U32 u32Align, VB_CAL_CONFIG_S* pstCalConfig)
  25. {
  26. HI_U32 u32TailInBytes = 0;
  27. HI_U32 u32BitWidth = 0;
  28. HI_U32 u32HeadStride = 0;
  29. HI_U32 u32VBSize = 0;
  30. HI_U32 u32HeadSize = 0;
  31. HI_U32 u32AlignHeight = 0;
  32. HI_U32 u32MainStride = 0;
  33. HI_U32 u32MainSize = 0;
  34. HI_U32 u32ExtStride = 0;
  35. HI_U32 u32ExtSize = 0;
  36. HI_U32 u32ExtYSize = 0;
  37. HI_U32 u32HeadYSize = 0;
  38. HI_U32 u32YSize = 0;
  39. /* u32Align: 0 is automatic mode, alignment size following system. Non-0 for specified alignment size */
  40. if(0 == u32Align)
  41. {
  42. u32Align = DEFAULT_ALIGN;
  43. }
  44. else if(u32Align > MAX_ALIGN)
  45. {
  46. u32Align = MAX_ALIGN;
  47. }
  48. else
  49. {
  50. u32Align = (ALIGN_UP(u32Align, DEFAULT_ALIGN));
  51. }
  52. switch (enBitWidth)
  53. {
  54. case DATA_BITWIDTH_8:
  55. {
  56. u32BitWidth = 8;
  57. break;
  58. }
  59. case DATA_BITWIDTH_10:
  60. {
  61. u32BitWidth = 10;
  62. break;
  63. }
  64. case DATA_BITWIDTH_12:
  65. {
  66. u32BitWidth = 12;
  67. break;
  68. }
  69. case DATA_BITWIDTH_14:
  70. {
  71. u32BitWidth = 14;
  72. break;
  73. }
  74. case DATA_BITWIDTH_16:
  75. {
  76. u32BitWidth = 16;
  77. break;
  78. }
  79. default:
  80. {
  81. u32BitWidth = 0;
  82. break;
  83. }
  84. }
  85. u32AlignHeight = ALIGN_UP(u32Height, 2);
  86. if (COMPRESS_MODE_NONE == enCmpMode)
  87. {
  88. u32MainStride = ALIGN_UP((u32Width * u32BitWidth + 7) >> 3, u32Align);
  89. u32YSize = u32MainStride * u32AlignHeight;
  90. if(PIXEL_FORMAT_YVU_SEMIPLANAR_420 == enPixelFormat || PIXEL_FORMAT_YUV_SEMIPLANAR_420 == enPixelFormat)
  91. {
  92. u32MainSize = (u32MainStride * u32AlignHeight)*3 >> 1;
  93. }
  94. else if (PIXEL_FORMAT_YVU_SEMIPLANAR_422 == enPixelFormat || PIXEL_FORMAT_YUV_SEMIPLANAR_422 == enPixelFormat)
  95. {
  96. u32MainSize = u32MainStride * u32AlignHeight * 2;
  97. }
  98. else if ((PIXEL_FORMAT_YUV_400 == enPixelFormat) || (PIXEL_FORMAT_S16C1 == enPixelFormat))
  99. {
  100. u32MainSize = u32MainStride * u32AlignHeight;
  101. }
  102. else
  103. {
  104. u32MainSize = u32MainStride * u32AlignHeight * 3;
  105. }
  106. u32VBSize = u32MainSize;
  107. }
  108. else
  109. {
  110. if (u32Width <= 4096)
  111. {
  112. u32HeadStride = 16;
  113. }
  114. else if (u32Width <= 8192)
  115. {
  116. u32HeadStride = 32;
  117. }
  118. else
  119. {
  120. u32HeadStride = 64;
  121. }
  122. if (u32BitWidth == 8)
  123. {
  124. u32MainStride = ALIGN_UP(u32Width, u32Align);
  125. u32HeadYSize = u32HeadStride * u32AlignHeight;
  126. u32YSize = u32MainStride * u32AlignHeight;
  127. if(PIXEL_FORMAT_YVU_SEMIPLANAR_420 == enPixelFormat || PIXEL_FORMAT_YUV_SEMIPLANAR_420 == enPixelFormat)
  128. {
  129. u32HeadSize = (u32HeadStride * u32AlignHeight * 3) >> 1;
  130. u32MainSize = (u32MainStride * u32AlignHeight * 3) >> 1;
  131. }
  132. else if (PIXEL_FORMAT_YVU_SEMIPLANAR_422 == enPixelFormat || PIXEL_FORMAT_YUV_SEMIPLANAR_422 == enPixelFormat)
  133. {
  134. u32HeadSize = u32HeadStride * u32AlignHeight * 2;
  135. u32MainSize = u32MainStride * u32AlignHeight * 2;
  136. }
  137. else if (PIXEL_FORMAT_YUV_400 == enPixelFormat)
  138. {
  139. u32HeadSize = u32HeadStride * u32AlignHeight;
  140. u32MainSize = u32MainStride * u32AlignHeight;
  141. }
  142. else
  143. {
  144. u32HeadSize = u32HeadStride * u32AlignHeight * 3;
  145. u32MainSize = u32MainStride * u32AlignHeight * 3;
  146. }
  147. }
  148. else if (u32BitWidth == 10)
  149. {
  150. u32TailInBytes = DIV_UP(u32Width%SEG_CMP_LENGTH*u32BitWidth, 8);
  151. u32MainStride = ALIGN_DOWN(u32Width, SEG_CMP_LENGTH) + ((u32TailInBytes > SEG_CMP_LENGTH) ? SEG_CMP_LENGTH : u32TailInBytes);
  152. u32MainStride = ALIGN_UP(u32MainStride, u32Align);
  153. u32ExtStride = (u32TailInBytes > SEG_CMP_LENGTH) ? (ALIGN_UP(DIV_UP(u32Width,4), u32Align)) :\
  154. ALIGN_UP((ALIGN_DOWN(u32Width, SEG_CMP_LENGTH)/4), u32Align);
  155. u32HeadYSize = u32HeadStride * u32AlignHeight;
  156. u32YSize = u32MainStride * u32AlignHeight;
  157. u32ExtYSize = u32ExtStride * u32AlignHeight;
  158. if(PIXEL_FORMAT_YVU_SEMIPLANAR_420 == enPixelFormat || PIXEL_FORMAT_YUV_SEMIPLANAR_420 == enPixelFormat)
  159. {
  160. u32HeadSize = (u32HeadStride * u32AlignHeight * 3) >> 1;
  161. u32MainSize = (u32MainStride * u32AlignHeight * 3) >> 1;
  162. u32ExtSize = (u32ExtStride * u32AlignHeight * 3) >> 1;
  163. }
  164. else if (PIXEL_FORMAT_YVU_SEMIPLANAR_422 == enPixelFormat || PIXEL_FORMAT_YUV_SEMIPLANAR_422 == enPixelFormat)
  165. {
  166. u32HeadSize = u32HeadStride * u32AlignHeight * 2;
  167. u32MainSize = u32MainStride * u32AlignHeight * 2;
  168. u32ExtSize = u32ExtStride * u32AlignHeight * 2;
  169. }
  170. else if (PIXEL_FORMAT_YUV_400 == enPixelFormat)
  171. {
  172. u32HeadSize = u32HeadStride * u32AlignHeight;
  173. u32MainSize = u32MainStride * u32AlignHeight;
  174. u32ExtSize = u32ExtStride * u32AlignHeight;
  175. }
  176. else
  177. {
  178. u32HeadSize = u32HeadStride * u32AlignHeight * 3;
  179. u32MainSize = u32MainStride * u32AlignHeight * 3;
  180. u32ExtSize = u32ExtStride * u32AlignHeight * 3;
  181. }
  182. }
  183. else
  184. {
  185. u32VBSize = 0;
  186. u32HeadYSize = 0;
  187. u32HeadSize = 0;
  188. u32HeadStride = 0;
  189. u32MainStride = 0;
  190. u32YSize = 0;
  191. u32MainSize = 0;
  192. u32ExtStride = 0;
  193. u32ExtYSize = 0;
  194. }
  195. u32HeadSize = ALIGN_UP(u32HeadSize, u32Align);
  196. u32VBSize = u32HeadSize + u32MainSize + u32ExtSize;
  197. }
  198. pstCalConfig->u32VBSize = u32VBSize;
  199. pstCalConfig->u32HeadYSize = u32HeadYSize;
  200. pstCalConfig->u32HeadSize = u32HeadSize;
  201. pstCalConfig->u32HeadStride = u32HeadStride;
  202. pstCalConfig->u32MainStride = u32MainStride;
  203. pstCalConfig->u32MainYSize = u32YSize;
  204. pstCalConfig->u32MainSize = u32MainSize;
  205. pstCalConfig->u32ExtStride = u32ExtStride;
  206. pstCalConfig->u32ExtYSize = u32ExtYSize;
  207. return;
  208. }
  209. __inline static HI_U32 COMMON_GetPicBufferSize(HI_U32 u32Width, HI_U32 u32Height,
  210. PIXEL_FORMAT_E enPixelFormat, DATA_BITWIDTH_E enBitWidth, COMPRESS_MODE_E enCmpMode, HI_U32 u32Align)
  211. {
  212. VB_CAL_CONFIG_S stCalConfig;
  213. COMMON_GetPicBufferConfig(u32Width, u32Height,enPixelFormat,enBitWidth, enCmpMode, u32Align, &stCalConfig);
  214. return stCalConfig.u32VBSize;
  215. }
  216. __inline static HI_U32 VI_GetRawBufferSize(HI_U32 u32Width, HI_U32 u32Height,
  217. PIXEL_FORMAT_E enPixelFormat, COMPRESS_MODE_E enCmpMode, HI_U32 u32Align)
  218. {
  219. HI_U32 u32BitWidth;
  220. HI_U32 u32Size = 0;
  221. HI_U32 u32Stride = 0;
  222. HI_U32 u32CmpRatioLine = 2000;
  223. HI_U32 u32CmpRatioFrame = 3000;
  224. /* u32Align: 0 is automatic mode, alignment size following system. Non-0 for specified alignment size */
  225. if(0 == u32Align)
  226. {
  227. u32Align = DEFAULT_ALIGN;
  228. }
  229. else if(u32Align > MAX_ALIGN)
  230. {
  231. u32Align = MAX_ALIGN;
  232. }
  233. else
  234. {
  235. u32Align = (ALIGN_UP(u32Align, DEFAULT_ALIGN));
  236. }
  237. switch (enPixelFormat)
  238. {
  239. case PIXEL_FORMAT_RGB_BAYER_8BPP:
  240. {
  241. u32BitWidth = 8;
  242. break;
  243. }
  244. case PIXEL_FORMAT_RGB_BAYER_10BPP:
  245. {
  246. u32BitWidth = 10;
  247. break;
  248. }
  249. case PIXEL_FORMAT_RGB_BAYER_12BPP:
  250. {
  251. u32BitWidth = 12;
  252. break;
  253. }
  254. case PIXEL_FORMAT_RGB_BAYER_14BPP:
  255. {
  256. u32BitWidth = 14;
  257. break;
  258. }
  259. case PIXEL_FORMAT_RGB_BAYER_16BPP:
  260. {
  261. u32BitWidth = 16;
  262. break;
  263. }
  264. default:
  265. {
  266. u32BitWidth = 0;
  267. break;
  268. }
  269. }
  270. if(COMPRESS_MODE_NONE == enCmpMode)
  271. {
  272. u32Stride = ALIGN_UP(ALIGN_UP(u32Width * u32BitWidth, 8)/8, u32Align);
  273. u32Size = u32Stride * u32Height;
  274. }
  275. else if(COMPRESS_MODE_LINE == enCmpMode)
  276. {
  277. HI_U32 u32Tmp;
  278. u32Tmp = ALIGN_UP( (16 + u32Width*u32BitWidth*1000ULL/u32CmpRatioLine + 8192 + 127)/128, 2);
  279. u32Stride = ALIGN_UP(u32Tmp * 16, u32Align);
  280. u32Size = u32Stride * u32Height;
  281. }
  282. else if(COMPRESS_MODE_FRAME == enCmpMode)
  283. {
  284. u32Size = ALIGN_UP(u32Height*u32Width*u32BitWidth*1000ULL/(u32CmpRatioFrame*8), u32Align);
  285. }
  286. return u32Size;
  287. }
  288. __inline static HI_U32 AVS_GetPicBufferSize(HI_U32 u32Width, HI_U32 u32Height, COMPRESS_MODE_E enCmpMode, HI_U32 u32Align)
  289. {
  290. HI_U32 u32Size = 0;
  291. u32Size = ALIGN_UP(u32Width, 128) * ALIGN_UP(u32Height, 64) * 2;
  292. return u32Size;
  293. }
  294. __inline static HI_U32 VDEC_GetPicBufferSize(PAYLOAD_TYPE_E enType, HI_U32 u32Width,
  295. HI_U32 u32Height, PIXEL_FORMAT_E enPixelFormat, DATA_BITWIDTH_E enBitWidth, HI_U32 u32Align)
  296. {
  297. HI_U32 u32AlignWidth, u32AlignHeight;
  298. HI_U32 u32HeaderSize = 0, u32HeaderStride = 0;
  299. HI_U32 u32ExtraSize = 0;
  300. HI_U32 u32Size = 0;
  301. if (PT_H264 == enType)
  302. {
  303. u32AlignWidth = ALIGN_UP(u32Width, H264D_ALIGN_W);
  304. u32AlignHeight = ALIGN_UP(u32Height, H264D_ALIGN_H);
  305. if(u32Width <= 8192)
  306. {
  307. u32HeaderStride = ALIGN_UP(u32AlignWidth, 2048) >> 6;
  308. }
  309. else
  310. {
  311. u32HeaderStride = ALIGN_UP(u32AlignWidth, 8192) >> 6;
  312. }
  313. u32HeaderSize = u32HeaderStride * (ALIGN_UP(u32AlignHeight, H264D_ALIGN_H) >> 2);
  314. u32Size = ( (u32HeaderSize + u32AlignWidth * u32AlignHeight ) * 3 ) >> 1;
  315. }
  316. else if (PT_H265 == enType)
  317. {
  318. u32AlignWidth = ALIGN_UP(u32Width, H265D_ALIGN_W);
  319. u32AlignHeight = ALIGN_UP(u32Height, H265D_ALIGN_H);
  320. if(u32Width <= 8192)
  321. {
  322. u32HeaderStride = ALIGN_UP(u32AlignWidth, 2048) >> 6;
  323. }
  324. else
  325. {
  326. u32HeaderStride = ALIGN_UP(u32AlignWidth, 8192) >> 6;
  327. }
  328. u32HeaderSize = u32HeaderStride * (ALIGN_UP(u32AlignHeight, H265D_ALIGN_H) >> 2);
  329. if (DATA_BITWIDTH_10 == enBitWidth)
  330. {
  331. u32ExtraSize = ALIGN_UP(u32AlignWidth * 2 >> 3, 16) * ALIGN_UP(u32AlignHeight, 32);
  332. }
  333. u32Size = ( (u32HeaderSize + u32AlignWidth * u32AlignHeight + u32ExtraSize) * 3 ) >> 1;
  334. }
  335. else if ( (PT_JPEG == enType) || (PT_MJPEG == enType))
  336. {
  337. if ( (PIXEL_FORMAT_ARGB_1555 == enPixelFormat) || (PIXEL_FORMAT_ABGR_1555 == enPixelFormat) ||
  338. (PIXEL_FORMAT_RGB_565 == enPixelFormat) || (PIXEL_FORMAT_BGR_565 == enPixelFormat) )
  339. {
  340. u32AlignWidth = ALIGN_UP(u32Width * 2, JPEGD_RGB_ALIGN);
  341. u32AlignHeight = ALIGN_UP(u32Height, JPEGD_RGB_ALIGN);
  342. u32Size = u32AlignWidth * u32AlignHeight;
  343. }
  344. else if ( (PIXEL_FORMAT_RGB_888 == enPixelFormat) || (PIXEL_FORMAT_BGR_888 == enPixelFormat) )
  345. {
  346. u32AlignWidth = ALIGN_UP(u32Width * 3, JPEGD_RGB_ALIGN);
  347. u32AlignHeight = ALIGN_UP(u32Height, JPEGD_RGB_ALIGN);
  348. u32Size = u32AlignWidth * u32AlignHeight;
  349. }
  350. else if ( (PIXEL_FORMAT_ARGB_8888 == enPixelFormat) || (PIXEL_FORMAT_ABGR_8888 == enPixelFormat) )
  351. {
  352. u32AlignWidth = ALIGN_UP(u32Width * 4, JPEGD_RGB_ALIGN);
  353. u32AlignHeight = ALIGN_UP(u32Height, JPEGD_RGB_ALIGN);
  354. u32Size = u32AlignWidth * u32AlignHeight;
  355. }
  356. else
  357. {
  358. /* for PIXEL_FORMAT_YVU_SEMIPLANAR_420 */
  359. u32AlignWidth = ALIGN_UP(u32Width, JPEGD_ALIGN_W);
  360. u32AlignHeight = ALIGN_UP(u32Height, JPEGD_ALIGN_H);
  361. u32Size = (u32AlignWidth * u32AlignHeight * 3) >> 1;
  362. }
  363. }
  364. else
  365. {
  366. u32Size = 0;
  367. }
  368. return u32Size;
  369. }
  370. __inline static HI_U32 VDEC_GetTmvBufferSize(PAYLOAD_TYPE_E enType, HI_U32 u32Width, HI_U32 u32Height)
  371. {
  372. HI_U32 WidthInMb, HeightInMb;
  373. HI_U32 ColMbSize;
  374. HI_U32 u32Size = 0;
  375. if (PT_H264 == enType)
  376. {
  377. WidthInMb = ALIGN_UP(u32Width, 16) >> 4;
  378. HeightInMb = ALIGN_UP(u32Height, 16) >> 4;
  379. ColMbSize = 16 * 4;
  380. u32Size = ALIGN_UP((ColMbSize * WidthInMb * HeightInMb), 128);
  381. }
  382. else if (PT_H265 == enType)
  383. {
  384. WidthInMb = ALIGN_UP(u32Width, 64) >> 4;
  385. HeightInMb = ALIGN_UP(u32Height, 64) >> 4;
  386. ColMbSize = 4 * 4;
  387. u32Size = ALIGN_UP((ColMbSize * WidthInMb * HeightInMb), 128);
  388. }
  389. else
  390. {
  391. u32Size = 0;
  392. }
  393. return u32Size;
  394. }
  395. __inline static HI_U32 VENC_GetRefPicInfoBufferSize(PAYLOAD_TYPE_E enType,HI_U32 u32Width, HI_U32 u32Height, HI_U32 u32Align)
  396. {
  397. HI_U32 u32Size;
  398. HI_U32 u32AlignWidth, u32AlignHeight;
  399. HI_U32 u32TmvSize,u32PmeSize,u32PmeInfoSize;
  400. if( (0 == u32Width) || (0 == u32Height) )
  401. {
  402. return 0;
  403. }
  404. if(PT_H265 == enType)
  405. {
  406. u32AlignWidth = ALIGN_UP(u32Width,64)>>6;
  407. u32AlignHeight = ALIGN_UP(u32Height,64)>>6;
  408. u32TmvSize = u32AlignWidth * u32AlignHeight <<7;
  409. u32PmeSize = (u32AlignWidth<<4) * (u32AlignHeight<<4);
  410. u32AlignWidth = ALIGN_UP(u32Width,128)>>7;
  411. u32AlignHeight = ALIGN_UP(u32Height,256)>>8;
  412. u32PmeInfoSize = (u32AlignWidth * u32AlignHeight)<<5;
  413. u32Size = u32TmvSize + u32PmeSize + u32PmeInfoSize;
  414. }
  415. else if(PT_H264 == enType)
  416. {
  417. u32AlignWidth = ALIGN_UP(u32Width,16)>>4;
  418. u32AlignHeight = ALIGN_UP(u32Height,16)>>4;
  419. u32TmvSize = u32AlignWidth * u32AlignHeight <<5;
  420. u32AlignWidth = ALIGN_UP(u32Width,64)>>6;
  421. u32AlignHeight = ALIGN_UP(u32Height,64)>>6;
  422. u32PmeSize = (u32AlignWidth<<4)*(u32AlignHeight<<4);
  423. u32AlignWidth = ALIGN_UP(u32Width,4096)>>12;
  424. u32AlignHeight = ALIGN_UP(u32Height,16)>>4;
  425. u32PmeInfoSize = (u32AlignWidth*u32AlignHeight)<<5;
  426. u32Size = u32TmvSize + u32PmeSize + u32PmeInfoSize;
  427. }
  428. else
  429. {
  430. u32Size = 0;
  431. }
  432. return u32Size;
  433. }
  434. __inline static HI_U32 VENC_GetRefBufferSize(PAYLOAD_TYPE_E enType, HI_U32 u32Width, HI_U32 u32Height,
  435. DATA_BITWIDTH_E enBitWidth, HI_U32 u32Align)
  436. {
  437. HI_U32 u32Size = 0;
  438. HI_U32 u32AlignWidth, u32AlignHeight,u32BitWidth;
  439. HI_U32 u32YHeaderSize,u32CHeaderSize,u32YSize,u32CSize;
  440. if( (0 == u32Width) || (0 == u32Height) )
  441. {
  442. return 0;
  443. }
  444. if (DATA_BITWIDTH_8 == enBitWidth)
  445. {
  446. u32BitWidth = 8;
  447. }
  448. else if(DATA_BITWIDTH_10 == enBitWidth)
  449. {
  450. u32BitWidth = 10;
  451. }
  452. else
  453. {
  454. return 0;
  455. }
  456. if(PT_H265 == enType)
  457. {
  458. u32AlignWidth = ALIGN_UP(u32Width, 128);
  459. u32AlignHeight = ALIGN_UP(u32Height,64)>>6;
  460. u32YHeaderSize = u32AlignWidth/64*32*u32AlignHeight;
  461. u32CHeaderSize = u32YHeaderSize;
  462. u32AlignWidth = ALIGN_UP(u32Width, 64);
  463. u32AlignHeight = ALIGN_UP(u32Height, 16);
  464. u32YSize = (u32AlignWidth * u32AlignHeight*u32BitWidth)>>3;
  465. u32CSize = u32YSize>>1;
  466. u32Size = u32YHeaderSize + u32CHeaderSize + u32YSize + u32CSize;
  467. }
  468. else if(PT_H264 == enType)
  469. {
  470. u32AlignWidth = ALIGN_UP(u32Width, 512);
  471. u32AlignHeight = ALIGN_UP(u32Height, 16)>>4;
  472. u32YHeaderSize = ((u32AlignWidth>>8)<<4)*u32AlignHeight ;
  473. u32CHeaderSize = u32YHeaderSize;
  474. u32AlignWidth = ALIGN_UP(u32Width, 64);
  475. u32AlignHeight = ALIGN_UP(u32Height, 16);
  476. u32YSize = u32AlignWidth * u32AlignHeight;
  477. u32CSize = u32YSize>>1;
  478. u32Size = u32YHeaderSize + u32CHeaderSize + u32YSize + u32CSize;
  479. }
  480. else
  481. {
  482. u32Size = 0;
  483. }
  484. return u32Size;
  485. }
  486. __inline static HI_U32 VENC_GetQpmapSizeStride(HI_U32 u32Width)
  487. {
  488. return DIV_UP(u32Width, 512) * 32;
  489. }
  490. __inline static HI_U32 VENC_GetQpmapSize(HI_U32 u32Width,HI_U32 u32Height)
  491. {
  492. HI_U32 u32Stride,u32AlignHeight;
  493. u32Stride = VENC_GetQpmapSizeStride(u32Width);
  494. u32AlignHeight = DIV_UP(u32Height,16);
  495. return u32Stride * u32AlignHeight;
  496. }
  497. __inline static HI_U32 VENC_GetSkipWeightSizeStride(PAYLOAD_TYPE_E enType,HI_U32 u32Width)
  498. {
  499. HI_U32 u32Stride;
  500. if(PT_H265 == enType)
  501. {
  502. u32Stride = DIV_UP(u32Width, 2048) * 16;
  503. }
  504. else if(PT_H264 == enType)
  505. {
  506. u32Stride = DIV_UP(u32Width, 512) * 16;
  507. }
  508. else
  509. {
  510. u32Stride = 0;
  511. }
  512. return u32Stride;
  513. }
  514. __inline static HI_U32 VENC_GetSkipWeightSize(PAYLOAD_TYPE_E enType,HI_U32 u32Width,HI_U32 u32Height)
  515. {
  516. HI_U32 u32Stride,u32AlignHeight;
  517. u32Stride = VENC_GetSkipWeightSizeStride(enType, u32Width);
  518. if(PT_H265 == enType)
  519. {
  520. u32AlignHeight = DIV_UP(u32Height,64);
  521. }
  522. else if(PT_H264 == enType)
  523. {
  524. u32AlignHeight = DIV_UP(u32Height,16);
  525. }
  526. else
  527. {
  528. u32AlignHeight = 0;
  529. }
  530. return u32Stride * u32AlignHeight;
  531. }
  532. #ifdef __cplusplus
  533. #if __cplusplus
  534. }
  535. #endif
  536. #endif /* __cplusplus */
  537. #endif /* __HI_BUFFER_H__ */