main_helper.h 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790
  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 _MAIN_HELPER_H_
  27. #define _MAIN_HELPER_H_
  28. #ifdef USE_FEEDING_METHOD_BUFFER
  29. #include "wave511/config.h"
  30. #include "wave511/vpuapi/vpuapifunc.h"
  31. #include "wave511/vpuapi/vpuapi.h"
  32. #include "wave511/vpuapi/vputypes.h"
  33. #else
  34. #include "config.h"
  35. #include "vpuapifunc.h"
  36. #include "vpuapi.h"
  37. #include "vputypes.h"
  38. #endif
  39. #ifdef PLATFORM_QNX
  40. #include <sys/stat.h>
  41. #endif
  42. #define MATCH_OR_MISMATCH(_expected, _value, _ret) ((_ret=(_expected == _value)) ? "MATCH" : "MISMATCH")
  43. #if defined(WIN32) || defined(WIN64)
  44. /*
  45. ( _MSC_VER => 1200 ) 6.0 vs6
  46. ( _MSC_VER => 1310 ) 7.1 vs2003
  47. ( _MSC_VER => 1400 ) 8.0 vs2005
  48. ( _MSC_VER => 1500 ) 9.0 vs2008
  49. ( _MSC_VER => 1600 ) 10.0 vs2010
  50. */
  51. #if (_MSC_VER == 1200)
  52. #define strcasecmp stricmp
  53. #define strncasecmp strnicmp
  54. #else
  55. #define strcasecmp _stricmp
  56. #define strncasecmp _strnicmp
  57. #endif
  58. #define inline _inline
  59. #if (_MSC_VER == 1600)
  60. #define strdup _strdup
  61. #endif
  62. #endif
  63. #define MAX_GETOPT_OPTIONS 100
  64. //extension of option struct in getopt
  65. struct OptionExt
  66. {
  67. const char *name;
  68. int has_arg;
  69. int *flag;
  70. int val;
  71. const char *help;
  72. };
  73. #define MAX_FILE_PATH 256
  74. #define MAX_PIC_SKIP_NUM 5
  75. #define EXTRA_SRC_BUFFER_NUM 0
  76. #define VPU_WAIT_TIME_OUT 10 //should be less than normal decoding time to give a chance to fill stream. if this value happens some problem. we should fix VPU_WaitInterrupt function
  77. #define VPU_WAIT_TIME_OUT_CQ 1
  78. #define MAX_NOT_DEC_COUNT 2000
  79. #define COMPARE_RESOLUTION(_src, _dst) (_src->width == _dst->width && _src->height == _dst->height)
  80. typedef union {
  81. struct {
  82. Uint32 ctu_force_mode : 2; //[ 1: 0]
  83. Uint32 ctu_coeff_drop : 1; //[ 2]
  84. Uint32 reserved : 5; //[ 7: 3]
  85. Uint32 sub_ctu_qp_0 : 6; //[13: 8]
  86. Uint32 sub_ctu_qp_1 : 6; //[19:14]
  87. Uint32 sub_ctu_qp_2 : 6; //[25:20]
  88. Uint32 sub_ctu_qp_3 : 6; //[31:26]
  89. Uint32 lambda_sad_0 : 8; //[39:32]
  90. Uint32 lambda_sad_1 : 8; //[47:40]
  91. Uint32 lambda_sad_2 : 8; //[55:48]
  92. Uint32 lambda_sad_3 : 8; //[63:56]
  93. } field;
  94. } EncCustomMap; // for wave5xx custom map (1 CTU = 64bits)
  95. typedef union {
  96. struct {
  97. Uint8 mb_force_mode : 2; //lint !e46 [ 1: 0]
  98. Uint8 mb_qp : 6; //lint !e46 [ 7: 2]
  99. } field;
  100. } AvcEncCustomMap; // for AVC custom map on wave (1 MB = 8bits)
  101. typedef enum {
  102. MODE_YUV_LOAD = 0,
  103. MODE_COMP_JYUV,
  104. MODE_SAVE_JYUV,
  105. MODE_COMP_CONV_YUV,
  106. MODE_SAVE_CONV_YUV,
  107. MODE_SAVE_LOAD_YUV,
  108. MODE_COMP_RECON,
  109. MODE_SAVE_RECON,
  110. MODE_COMP_ENCODED,
  111. MODE_SAVE_ENCODED
  112. } CompSaveMode;
  113. typedef struct {
  114. int picX;
  115. int picY;
  116. int internalBitDepth;
  117. int losslessEnable;
  118. int constIntraPredFlag;
  119. int gopSize;
  120. int numTemporalLayers;
  121. int decodingRefreshType;
  122. int intraQP;
  123. int intraPeriod;
  124. int frameRate;
  125. int confWinTop;
  126. int confWinBot;
  127. int confWinLeft;
  128. int confWinRight;
  129. int independSliceMode;
  130. int independSliceModeArg;
  131. int dependSliceMode;
  132. int dependSliceModeArg;
  133. int intraRefreshMode;
  134. int intraRefreshArg;
  135. int useRecommendEncParam;
  136. int scalingListEnable;
  137. int cuSizeMode;
  138. int tmvpEnable;
  139. int wppenable;
  140. int maxNumMerge;
  141. int disableDeblk;
  142. int lfCrossSliceBoundaryEnable;
  143. int betaOffsetDiv2;
  144. int tcOffsetDiv2;
  145. int skipIntraTrans;
  146. int saoEnable;
  147. int intraNxNEnable;
  148. int rcEnable;
  149. int bitRate;
  150. int bitAllocMode;
  151. int fixedBitRatio[MAX_GOP_NUM];
  152. int cuLevelRCEnable;
  153. int hvsQPEnable;
  154. int hvsQpScale;
  155. int minQp;
  156. int maxQp;
  157. int maxDeltaQp;
  158. int gopPresetIdx;
  159. // CUSTOM_GOP
  160. CustomGopParam gopParam;
  161. // ROI / CTU mode
  162. int roiEnable; /**< It enables ROI map. NOTE: It is valid when rcEnable is on. */
  163. char roiFileName[MAX_FILE_PATH];
  164. char roiQpMapFile[MAX_FILE_PATH];
  165. // VUI
  166. Uint32 numUnitsInTick;
  167. Uint32 timeScale;
  168. Uint32 numTicksPocDiffOne;
  169. int encAUD;
  170. int encEOS;
  171. int encEOB;
  172. int chromaCbQpOffset;
  173. int chromaCrQpOffset;
  174. Uint32 initialRcQp;
  175. Uint32 nrYEnable;
  176. Uint32 nrCbEnable;
  177. Uint32 nrCrEnable;
  178. Uint32 nrNoiseEstEnable;
  179. Uint32 nrNoiseSigmaY;
  180. Uint32 nrNoiseSigmaCb;
  181. Uint32 nrNoiseSigmaCr;
  182. Uint32 nrIntraWeightY;
  183. Uint32 nrIntraWeightCb;
  184. Uint32 nrIntraWeightCr;
  185. Uint32 nrInterWeightY;
  186. Uint32 nrInterWeightCb;
  187. Uint32 nrInterWeightCr;
  188. Uint32 useAsLongtermPeriod;
  189. Uint32 refLongtermPeriod;
  190. // newly added for encoder
  191. Uint32 monochromeEnable;
  192. Uint32 strongIntraSmoothEnable;
  193. Uint32 roiAvgQp;
  194. Uint32 weightPredEnable;
  195. Uint32 bgDetectEnable;
  196. Uint32 bgThrDiff;
  197. Uint32 bgThrMeanDiff;
  198. Uint32 bgLambdaQp;
  199. int bgDeltaQp;
  200. Uint32 lambdaMapEnable;
  201. Uint32 customLambdaEnable;
  202. Uint32 customMDEnable;
  203. int pu04DeltaRate;
  204. int pu08DeltaRate;
  205. int pu16DeltaRate;
  206. int pu32DeltaRate;
  207. int pu04IntraPlanarDeltaRate;
  208. int pu04IntraDcDeltaRate;
  209. int pu04IntraAngleDeltaRate;
  210. int pu08IntraPlanarDeltaRate;
  211. int pu08IntraDcDeltaRate;
  212. int pu08IntraAngleDeltaRate;
  213. int pu16IntraPlanarDeltaRate;
  214. int pu16IntraDcDeltaRate;
  215. int pu16IntraAngleDeltaRate;
  216. int pu32IntraPlanarDeltaRate;
  217. int pu32IntraDcDeltaRate;
  218. int pu32IntraAngleDeltaRate;
  219. int cu08IntraDeltaRate;
  220. int cu08InterDeltaRate;
  221. int cu08MergeDeltaRate;
  222. int cu16IntraDeltaRate;
  223. int cu16InterDeltaRate;
  224. int cu16MergeDeltaRate;
  225. int cu32IntraDeltaRate;
  226. int cu32InterDeltaRate;
  227. int cu32MergeDeltaRate;
  228. int coefClearDisable;
  229. int forcePicSkipStart;
  230. int forcePicSkipEnd;
  231. int forceCoefDropStart;
  232. int forceCoefDropEnd;
  233. char scalingListFileName[MAX_FILE_PATH];
  234. char customLambdaFileName[MAX_FILE_PATH];
  235. Uint32 enStillPicture;
  236. // custom map
  237. int customLambdaMapEnable;
  238. char customLambdaMapFileName[MAX_FILE_PATH];
  239. int customModeMapFlag;
  240. char customModeMapFileName[MAX_FILE_PATH];
  241. char WpParamFileName[MAX_FILE_PATH];
  242. // for H.264 on WAVE
  243. int idrPeriod;
  244. int rdoSkip;
  245. int lambdaScalingEnable;
  246. int transform8x8;
  247. int avcSliceMode;
  248. int avcSliceArg;
  249. int intraMbRefreshMode;
  250. int intraMbRefreshArg;
  251. int mbLevelRc;
  252. int entropyCodingMode;
  253. int s2fmeDisable;
  254. int forceIdrPicIdx;
  255. int forcedIdrHeaderEnable;
  256. #ifdef SUPPORT_LOOK_AHEAD_RC
  257. int larcEnable;
  258. int larcPass;
  259. int larcSize;
  260. int larcWeight;
  261. #endif
  262. Uint32 rcWeightParam;
  263. Uint32 rcWeightBuf;
  264. } WAVE_ENC_CFG;
  265. typedef struct {
  266. // ChangePara
  267. int setParaChgFrmNum;
  268. int enableOption;
  269. char cfgName[MAX_FILE_PATH];
  270. } W5ChangeParam;
  271. typedef struct {
  272. char SrcFileName[MAX_FILE_PATH];
  273. char BitStreamFileName[MAX_FILE_PATH];
  274. BOOL srcCbCrInterleave;
  275. int NumFrame;
  276. int PicX;
  277. int PicY;
  278. int FrameRate;
  279. // MPEG4 ONLY
  280. int VerId;
  281. int DataPartEn;
  282. int RevVlcEn;
  283. int ShortVideoHeader;
  284. int AnnexI;
  285. int AnnexJ;
  286. int AnnexK;
  287. int AnnexT;
  288. int IntraDcVlcThr;
  289. int VopQuant;
  290. // H.264 ONLY
  291. int ConstIntraPredFlag;
  292. int DisableDeblk;
  293. int DeblkOffsetA;
  294. int DeblkOffsetB;
  295. int ChromaQpOffset;
  296. int PicQpY;
  297. // H.264 VUI information
  298. int VuiPresFlag;
  299. int VideoSignalTypePresFlag;
  300. char VideoFormat;
  301. char VideoFullRangeFlag;
  302. int ColourDescripPresFlag;
  303. char ColourPrimaries;
  304. char TransferCharacteristics;
  305. char MatrixCoeff;
  306. int NumReorderFrame;
  307. int MaxDecBuffering;
  308. int aud_en;
  309. int level;
  310. // COMMON
  311. int GopPicNum;
  312. int SliceMode;
  313. int SliceSizeMode;
  314. int SliceSizeNum;
  315. // COMMON - RC
  316. int RcEnable;
  317. int RcBitRate;
  318. int RcBitRateBL;
  319. int RcInitDelay;
  320. int VbvBufferSize;
  321. int RcBufSize;
  322. int IntraRefreshNum;
  323. int ConscIntraRefreshEnable;
  324. int frameSkipDisable;
  325. int ConstantIntraQPEnable;
  326. int MaxQpSetEnable;
  327. int MaxQp;
  328. int frameCroppingFlag;
  329. int frameCropLeft;
  330. int frameCropRight;
  331. int frameCropTop;
  332. int frameCropBottom;
  333. //H.264 only
  334. int MaxDeltaQpSetEnable;
  335. int MaxDeltaQp;
  336. int MinQpSetEnable;
  337. int MinQp;
  338. int MinDeltaQpSetEnable;
  339. int MinDeltaQp;
  340. int intraCostWeight;
  341. //MP4 Only
  342. int RCIntraQP;
  343. int HecEnable;
  344. int GammaSetEnable;
  345. int Gamma;
  346. // NEW RC Scheme
  347. int rcIntervalMode;
  348. int RcMBInterval;
  349. int skipPicNums[MAX_PIC_SKIP_NUM];
  350. int SearchRange; // for coda960
  351. int MeUseZeroPmv; // will be removed. must be 264 = 0, mpeg4 = 1 263 = 0
  352. int MeBlkModeEnable; // only api option
  353. int IDRInterval;
  354. int SrcBitDepth;
  355. WAVE_ENC_CFG waveCfg;
  356. int numChangeParam;
  357. W5ChangeParam changeParam[10];
  358. int rcWeightFactor;
  359. } ENC_CFG;
  360. void replace_character(char* str,
  361. char c,
  362. char r);
  363. extern Uint32 randomSeed;
  364. /* yuv & md5 */
  365. #define NO_COMPARE 0
  366. #define YUV_COMPARE 1
  367. #define MD5_COMPARE 2
  368. #define STREAM_COMPARE 3
  369. #ifdef __cplusplus
  370. extern "C" {
  371. #endif /* __cplusplus */
  372. /* The simple load balancer for performance measurement */
  373. void LoadBalancerInit(void);
  374. void LoadBalancerRelease(void);
  375. BOOL LoadBalancerGetMyTurn(Uint32 myInstance);
  376. void LoadBalancerSetNextTurn(void);
  377. void LoadBalancerAddInstance(Uint32 instanceIndex);
  378. void LoadBalancerRemoveInstance(Uint32 instanceIndex);
  379. /* Performance report */
  380. typedef void* PFCtx;
  381. PFCtx PFMonitorSetup(
  382. Uint32 coreIndex,
  383. Uint32 instanceIndex,
  384. Uint32 referenceClkInMHz,
  385. Uint32 fps,
  386. char* strLogDir,
  387. BOOL isEnc
  388. );
  389. void PFMonitorRelease(
  390. PFCtx context
  391. );
  392. void PFMonitorUpdate(
  393. Uint32 coreIndex,
  394. PFCtx context,
  395. Uint32 cycles,
  396. ...
  397. );
  398. void PrepareDecoderTest(
  399. DecHandle decHandle
  400. );
  401. void byte_swap(
  402. unsigned char* data,
  403. int len
  404. );
  405. void word_swap(
  406. unsigned char* data,
  407. int len
  408. );
  409. void dword_swap(
  410. unsigned char* data,
  411. int len
  412. );
  413. void lword_swap(
  414. unsigned char* data,
  415. int len
  416. );
  417. Int32 LoadFirmware(
  418. Int32 productId,
  419. Uint8** retFirmware,
  420. Uint32* retSizeInWord,
  421. const char* path
  422. );
  423. void PrintDecSeqWarningMessages(
  424. Uint32 productId,
  425. DecInitialInfo* seqInfo
  426. );
  427. void DisplayDecodedInformation(
  428. DecHandle handle,
  429. CodStd codec,
  430. Uint32 frameNo,
  431. DecOutputInfo* decodedInfo,
  432. ...
  433. );
  434. void
  435. DisplayEncodedInformation(
  436. EncHandle handle,
  437. CodStd codec,
  438. Uint32 frameNo,
  439. EncOutputInfo* encodedInfo,
  440. ...
  441. );
  442. void PrintEncSppStatus(
  443. Uint32 coreIdx,
  444. Uint32 productId
  445. );
  446. /*
  447. * VPU Helper functions
  448. */
  449. /************************************************************************/
  450. /* Video */
  451. /************************************************************************/
  452. #define PUT_BYTE(_p, _b) \
  453. *_p++ = (unsigned char)_b;
  454. #define PUT_BUFFER(_p, _buf, _len) \
  455. osal_memcpy(_p, _buf, _len); \
  456. (_p) += (_len);
  457. #define PUT_LE32(_p, _var) \
  458. *_p++ = (unsigned char)((_var)>>0); \
  459. *_p++ = (unsigned char)((_var)>>8); \
  460. *_p++ = (unsigned char)((_var)>>16); \
  461. *_p++ = (unsigned char)((_var)>>24);
  462. #define PUT_BE32(_p, _var) \
  463. *_p++ = (unsigned char)((_var)>>24); \
  464. *_p++ = (unsigned char)((_var)>>16); \
  465. *_p++ = (unsigned char)((_var)>>8); \
  466. *_p++ = (unsigned char)((_var)>>0);
  467. #define PUT_LE16(_p, _var) \
  468. *_p++ = (unsigned char)((_var)>>0); \
  469. *_p++ = (unsigned char)((_var)>>8);
  470. #define PUT_BE16(_p, _var) \
  471. *_p++ = (unsigned char)((_var)>>8); \
  472. *_p++ = (unsigned char)((_var)>>0);
  473. Int32 ConvFOURCCToMp4Class(
  474. Int32 fourcc
  475. );
  476. Int32 ConvFOURCCToCodStd(
  477. Uint32 fourcc
  478. );
  479. Int32 ConvCodecIdToMp4Class(
  480. Uint32 codecId
  481. );
  482. Int32 ConvCodecIdToCodStd(
  483. Int32 codecId
  484. );
  485. Int32 ConvCodecIdToFourcc(
  486. Int32 codecId
  487. );
  488. /*!
  489. * \brief wrapper function of StoreYuvImageBurstFormat()
  490. */
  491. Uint8* GetYUVFromFrameBuffer(
  492. DecHandle decHandle,
  493. FrameBuffer* fb,
  494. VpuRect rcFrame,
  495. Uint32* retWidth,
  496. Uint32* retHeight,
  497. Uint32* retBpp,
  498. size_t* retSize
  499. );
  500. BOOL GetYUVFromFrameBuffer2(
  501. Uint8* pYuv,
  502. Uint8** pYuv2,
  503. Uint32 size,
  504. DecHandle decHandle,
  505. FrameBuffer* fb,
  506. VpuRect rcFrame,
  507. Uint32* retWidth,
  508. Uint32* retHeight,
  509. Uint32* retBpp,
  510. size_t* retSize
  511. );
  512. /************************************************************************/
  513. /* Queue */
  514. /************************************************************************/
  515. typedef struct {
  516. void* data;
  517. } QueueData;
  518. typedef struct {
  519. Uint8* buffer;
  520. Uint32 size;
  521. Uint32 itemSize;
  522. Uint32 count;
  523. Uint32 front;
  524. Uint32 rear;
  525. osal_mutex_t lock;
  526. } Queue;
  527. Queue* Queue_Create(
  528. Uint32 itemCount,
  529. Uint32 itemSize
  530. );
  531. Queue* Queue_Create_With_Lock(
  532. Uint32 itemCount,
  533. Uint32 itemSize
  534. );
  535. void Queue_Destroy(
  536. Queue* queue
  537. );
  538. /**
  539. * \brief Enqueue with deep copy
  540. */
  541. BOOL Queue_Enqueue(
  542. Queue* queue,
  543. void* data
  544. );
  545. /**
  546. * \brief Caller has responsibility for releasing the returned data
  547. */
  548. void* Queue_Dequeue(
  549. Queue* queue
  550. );
  551. void Queue_Flush(
  552. Queue* queue
  553. );
  554. void* Queue_Peek(
  555. Queue* queue
  556. );
  557. Uint32 Queue_Get_Cnt(
  558. Queue* queue
  559. );
  560. /**
  561. * \brief @dstQ is NULL, it allocates Queue structure and then copy from @srcQ.
  562. */
  563. Queue* Queue_Copy(
  564. Queue* dstQ,
  565. Queue* srcQ
  566. );
  567. /**
  568. * \brief Check the queue is full or not.
  569. */
  570. BOOL Queue_IsFull(
  571. Queue* queue
  572. );
  573. /************************************************************************/
  574. /* ETC */
  575. /************************************************************************/
  576. Uint32 GetRandom(
  577. Uint32 start,
  578. Uint32 end
  579. );
  580. /************************************************************************/
  581. /* MD5 */
  582. /************************************************************************/
  583. typedef struct MD5state_st {
  584. Uint32 A,B,C,D;
  585. Uint32 Nl,Nh;
  586. Uint32 data[16];
  587. Uint32 num;
  588. } MD5_CTX;
  589. Int32 MD5_Init(
  590. MD5_CTX *c
  591. );
  592. Int32 MD5_Update(
  593. MD5_CTX* c,
  594. const void* data,
  595. size_t len);
  596. Int32 MD5_Final(
  597. Uint8* md,
  598. MD5_CTX* c
  599. );
  600. Uint8* MD5(
  601. const Uint8* d,
  602. size_t n,
  603. Uint8* md
  604. );
  605. void plane_md5(MD5_CTX *md5_ctx,
  606. Uint8 *src,
  607. int src_x,
  608. int src_y,
  609. int out_x,
  610. int out_y,
  611. int stride,
  612. int bpp,
  613. Uint16 zero
  614. );
  615. /************************************************************************/
  616. /* Comparator */
  617. /************************************************************************/
  618. #define COMPARATOR_SKIP 0xF0F0F0F0
  619. typedef enum {
  620. COMPARATOR_CONF_SET_GOLDEN_DATA_SIZE,
  621. COMPARATOR_CONF_SKIP_GOLDEN_DATA, /*!<< 2nd parameter pointer of Queue
  622. containing skip command */
  623. COMPARATOR_CONF_SET_PICINFO, //!<< This command is followed by YUVInfo structure.
  624. COMPARATOR_CONF_SET_MONOCHROME, //!<< It means a monochrome picture
  625. } ComparatorConfType;
  626. typedef void* Comparator;
  627. typedef struct ComparatorImpl {
  628. void* context;
  629. char* filename;
  630. Uint32 curIndex;
  631. Uint32 numOfFrames;
  632. BOOL (*Create)(struct ComparatorImpl* impl, char* path);
  633. BOOL (*Destroy)(struct ComparatorImpl* impl);
  634. BOOL (*Compare)(struct ComparatorImpl* impl, void* data, PhysicalAddress size);
  635. BOOL (*Configure)(struct ComparatorImpl* impl, ComparatorConfType type, void* val);
  636. BOOL (*Rewind)(struct ComparatorImpl* impl);
  637. BOOL eof;
  638. BOOL enableScanMode;
  639. BOOL usePrevDataOneTime;
  640. } ComparatorImpl;
  641. typedef struct {
  642. Uint32 totalFrames;
  643. ComparatorImpl* impl;
  644. } AbstractComparator;
  645. // YUV Comparator
  646. typedef struct {
  647. Uint32 width;
  648. Uint32 height;
  649. FrameBufferFormat format;
  650. BOOL cbcrInterleave;
  651. BOOL isVp9;
  652. } PictureInfo;
  653. Comparator Comparator_Create(
  654. Uint32 type, //!<< 1: yuv
  655. char* goldenPath,
  656. ...
  657. );
  658. BOOL Comparator_Destroy(
  659. Comparator comp
  660. );
  661. BOOL Comparator_Act(
  662. Comparator comp,
  663. void* data,
  664. Uint32 size
  665. );
  666. BOOL Comparator_CheckFrameCount(
  667. Comparator comp
  668. );
  669. BOOL Comparator_SetScanMode(
  670. Comparator comp,
  671. BOOL enable
  672. );
  673. BOOL Comparator_Rewind(
  674. Comparator comp
  675. );
  676. BOOL Comparator_CheckEOF(
  677. Comparator comp
  678. );
  679. Uint32 Comparator_GetFrameCount(
  680. Comparator comp
  681. );
  682. BOOL Comparator_Configure(
  683. Comparator comp,
  684. ComparatorConfType cmd,
  685. void* val
  686. );
  687. BOOL IsEndOfFile(
  688. FILE* fp
  689. );
  690. /************************************************************************/
  691. /* Bitstream Feeder */
  692. /************************************************************************/
  693. typedef enum {
  694. FEEDING_METHOD_FIXED_SIZE,
  695. FEEDING_METHOD_FRAME_SIZE,
  696. FEEDING_METHOD_SIZE_PLUS_ES,
  697. #ifdef USE_FEEDING_METHOD_BUFFER
  698. FEEDING_METHOD_BUFFER,
  699. #endif
  700. FEEDING_METHOD_MAX
  701. } FeedingMethod;
  702. typedef struct {
  703. void* data;
  704. Uint32 size;
  705. BOOL eos; //!<< End of stream
  706. int seqHeaderSize;
  707. } BSChunk;
  708. typedef void* BSFeeder;
  709. typedef void (*BSFeederHook)(BSFeeder feeder, void* data, Uint32 size, void* arg);
  710. /**
  711. * \brief BitstreamFeeder consumes bitstream and updates information of bitstream buffer of VPU.
  712. * \param handle handle of decoder
  713. * \param path bitstream path
  714. * \param method feeding method. see FeedingMethod.
  715. * \param loopCount If @loopCount is greater than 1 then BistreamFeeder reads the start of bitstream again
  716. * when it encounters the end of stream @loopCount times.
  717. * \param ... FEEDING_METHOD_FIXED_SIZE:
  718. * This value of parameter is size of chunk at a time.
  719. * If the size of chunk is equal to zero than the BitstreamFeeder reads bistream in random size.(1Byte ~ 4MB)
  720. * \return It returns the pointer of handle containing the context of the BitstreamFeeder.
  721. */
  722. void* BitstreamFeeder_Create(
  723. Uint32 coreIdx,
  724. const char* path,
  725. CodStd codecId,
  726. FeedingMethod method,
  727. EndianMode endian
  728. );
  729. /**
  730. * \brief This is helper function set to simplify the flow that update bit-stream
  731. * to the VPU.
  732. */
  733. Uint32 BitstreamFeeder_Act(
  734. BSFeeder feeder,
  735. vpu_buffer_t* bsBuffer,
  736. PhysicalAddress wrPtr,
  737. Uint32 room,
  738. PhysicalAddress* newWrPtr
  739. );
  740. BOOL BitstreamFeeder_SetFeedingSize(
  741. BSFeeder feeder,
  742. Uint32 size
  743. );
  744. /**
  745. * \brief Set filling bitstream as ringbuffer mode or linebuffer mode.
  746. * \param mode 0 : auto
  747. * 1 : ringbuffer
  748. * 2 : linebuffer.
  749. */
  750. #define BSF_FILLING_AUTO 0
  751. #define BSF_FILLING_RINGBUFFER 1
  752. #define BSF_FILLING_LINEBUFFER 2
  753. /* BSF_FILLING_RINBGUFFER_WITH_ENDFLAG:
  754. * Scenario:
  755. * - Application writes 1 ~ 10 frames into bitstream buffer.
  756. * - Set stream end flag by using VPU_DecUpdateBitstreamBuffer(handle, 0).
  757. * - Application clears stream end flag by using VPU_DecUpdateBitstreamBuffer(handle, -1).
  758. * when indexFrameDisplay is equal to -1.
  759. * NOTE:
  760. * - Last frame cannot be a complete frame.
  761. */
  762. #define BSF_FILLING_RINGBUFFER_WITH_ENDFLAG 3
  763. void BitstreamFeeder_SetFillMode(
  764. BSFeeder feeder,
  765. Uint32 mode
  766. );
  767. BOOL BitstreamFeeder_IsEos(
  768. BSFeeder feeder
  769. );
  770. Uint32 BitstreamFeeder_GetSeqHeaderSize(
  771. BSFeeder feeder
  772. );
  773. BOOL BitstreamFeeder_Destroy(
  774. BSFeeder feeder
  775. );
  776. BOOL BitstreamFeeder_Rewind(
  777. BSFeeder feeder
  778. );
  779. BOOL BitstreamFeeder_SetHook(
  780. BSFeeder feeder,
  781. BSFeederHook hookFunc,
  782. void* arg
  783. );
  784. /************************************************************************/
  785. /* YUV Feeder */
  786. /************************************************************************/
  787. #define SOURCE_YUV 0
  788. #define SOURCE_YUV_WITH_LOADER 2
  789. #ifdef USE_FEEDING_METHOD_BUFFER
  790. #define SOURCE_YUV_WITH_BUFFER 4
  791. #endif
  792. typedef struct {
  793. Uint32 cbcrInterleave;
  794. Uint32 nv21;
  795. Uint32 packedFormat;
  796. Uint32 srcFormat;
  797. Uint32 srcPlanar;
  798. Uint32 srcStride;
  799. Uint32 srcHeight;
  800. } YuvInfo;
  801. typedef void* YuvFeeder;
  802. typedef struct YuvFeederImpl {
  803. void* context;
  804. BOOL (*Create)(struct YuvFeederImpl* impl, const char* path, Uint32 packed, Uint32 fbStride, Uint32 fbHeight);
  805. BOOL (*Feed)(struct YuvFeederImpl* impl, Int32 coreIdx, FrameBuffer *fb, size_t picWidth, size_t picHeight, Uint32 srcFbIndex, void* arg);
  806. BOOL (*Destroy)(struct YuvFeederImpl* impl);
  807. BOOL (*Configure)(struct YuvFeederImpl* impl, Uint32 cmd, YuvInfo yuv);
  808. EncHandle handle;
  809. } YuvFeederImpl;
  810. typedef struct {
  811. YuvFeederImpl* impl;
  812. Uint8 pYuv;
  813. } AbstractYuvFeeder;
  814. typedef struct {
  815. osal_file_t* fp;
  816. Uint8* pYuv;
  817. size_t fbStride;
  818. size_t cbcrInterleave;
  819. BOOL srcPlanar;
  820. } yuvContext;
  821. YuvFeeder YuvFeeder_Create(
  822. Uint32 type,
  823. const char* srcFilePath,
  824. YuvInfo yuvInfo
  825. );
  826. BOOL YuvFeeder_Feed(
  827. YuvFeeder feeder,
  828. Uint32 coreIdx,
  829. FrameBuffer* fb,
  830. size_t picWidth,
  831. size_t picHeight,
  832. Uint32 srcFbIndex,
  833. void* arg
  834. );
  835. BOOL YuvFeeder_Destroy(
  836. YuvFeeder feeder
  837. );
  838. /************************************************************************/
  839. /* CNM video helper */
  840. /************************************************************************/
  841. /**
  842. * \param convertCbcrIntl If this value is TRUE, it stores YUV as NV12 or NV21 to @fb
  843. */
  844. BOOL LoadYuvImageByYCbCrLine(
  845. EncHandle handle,
  846. Uint32 coreIdx,
  847. Uint8* src,
  848. size_t picWidth,
  849. size_t picHeight,
  850. FrameBuffer* fb,
  851. Uint32 srcFbIndex
  852. );
  853. typedef enum {
  854. SRC_0LINE_WRITE = 0,
  855. SRC_64LINE_WRITE = 64,
  856. SRC_128LINE_WRITE = 128,
  857. SRC_192LINE_WRITE = 192,
  858. //...
  859. REMAIN_SRC_DATA_WRITE = 0x80000000
  860. } SOURCE_LINE_WRITE;
  861. BOOL LoadYuvImageBurstFormat(
  862. Uint32 coreIdx,
  863. Uint8* src,
  864. size_t picWidth,
  865. size_t picHeight,
  866. FrameBuffer *fb,
  867. BOOL convertCbcrIntl
  868. );
  869. int ProcessEncodedBitstreamBurst(
  870. Uint32 core_idx,
  871. osal_file_t fp,
  872. int targetAddr,
  873. PhysicalAddress bsBufStartAddr,
  874. PhysicalAddress bsBufEndAddr,
  875. int size,
  876. int endian,
  877. Comparator comparator
  878. );
  879. BOOL LoadTiledImageYuvBurst(
  880. VpuHandle handle,
  881. Uint32 coreIdx,
  882. BYTE* pYuv,
  883. size_t picWidth,
  884. size_t picHeight,
  885. FrameBuffer* fb,
  886. TiledMapConfig mapCfg
  887. );
  888. Uint32 StoreYuvImageBurstFormat(
  889. Uint32 coreIndex,
  890. FrameBuffer* fbSrc,
  891. TiledMapConfig mapCfg,
  892. Uint8* pDst,
  893. VpuRect cropRect,
  894. BOOL enableCrop
  895. );
  896. /************************************************************************/
  897. /* Bit Reader */
  898. /************************************************************************/
  899. #define BS_RESET_BUF 0
  900. #define BS_RING_BUF 1
  901. #define BUFFER_MODE_TYPE_LINEBUFFER 0
  902. #define BUFFER_MODE_TYPE_RINGBUFFER 1
  903. typedef void* BitstreamReader;
  904. typedef struct BitstreamReaderImpl {
  905. void* context;
  906. BOOL (*Create)(struct BitstreamReaderImpl* impl, const char* path);
  907. Uint32 (*Act)(struct BitstreamReaderImpl* impl, Int32 coreIdx, PhysicalAddress bitstreamBuffer, Uint32 bitstreamBufferSize, int endian, Comparator comparator);
  908. BOOL (*Destroy)(struct BitstreamReaderImpl* impl);
  909. BOOL (*Configure)(struct BitstreamReaderImpl* impl, Uint32 cmd, void* val);
  910. } BitstreamReaderImpl;
  911. /*!
  912. * \param type 0: Linebuffer, 1: Ringbuffer
  913. * \param path output filepath.
  914. * \param endian Endianness of bitstream buffer
  915. * \param handle Pointer of encoder handle
  916. */
  917. BitstreamReader BitstreamReader_Create(
  918. Uint32 type,
  919. char* path,
  920. EndianMode endian,
  921. EncHandle* handle
  922. );
  923. /*!
  924. * \param bitstreamBuffer base address of bitstream buffer
  925. * \param bitstreamBufferSize size of bitstream buffer
  926. */
  927. BOOL BitstreamReader_Act(
  928. BitstreamReader reader,
  929. PhysicalAddress bitstreamBuffer,
  930. Uint32 bitstreamBufferSize,
  931. Uint32 defaultsize,
  932. Comparator comparator
  933. );
  934. BOOL BitstreamReader_Destroy(
  935. BitstreamReader reader
  936. );
  937. /************************************************************************/
  938. /* Simple Renderer */
  939. /************************************************************************/
  940. typedef void* Renderer;
  941. typedef enum {
  942. RENDER_DEVICE_NULL,
  943. RENDER_DEVICE_FBDEV,
  944. RENDER_DEVICE_HDMI,
  945. RENDER_DEVICE_MAX
  946. } RenderDeviceType;
  947. typedef struct RenderDevice {
  948. void* context;
  949. DecHandle decHandle;
  950. BOOL (*Open)(struct RenderDevice* device);
  951. void (*Render)(struct RenderDevice* device, DecOutputInfo* fbInfo, Uint8* yuv, Uint32 width, Uint32 height);
  952. BOOL (*Close)(struct RenderDevice* device);
  953. } RenderDevice;
  954. Renderer SimpleRenderer_Create(
  955. DecHandle decHandle,
  956. RenderDeviceType deviceType,
  957. const char* yuvPath //!<< path to store yuv iamge.
  958. );
  959. Uint32 SimpleRenderer_Act(
  960. Renderer renderer,
  961. DecOutputInfo* fbInfo,
  962. Uint8* pYuv,
  963. Uint32 width,
  964. Uint32 height
  965. );
  966. void* SimpleRenderer_GetFreeFrameInfo(
  967. Renderer renderer
  968. );
  969. /* \brief Flush display queues and clear display indexes
  970. */
  971. void SimpleRenderer_Flush(
  972. Renderer renderer
  973. );
  974. BOOL SimpleRenderer_Destroy(
  975. Renderer renderer
  976. );
  977. BOOL SimpleRenderer_SetFrameRate(
  978. Renderer renderer,
  979. Uint32 fps
  980. );
  981. BOOL MkDir(
  982. char* path
  983. );
  984. /*******************************************************************************
  985. * DATATYPES AND FUNCTIONS RELATED TO REPORT
  986. *******************************************************************************/
  987. typedef struct
  988. {
  989. osal_file_t fpPicDispInfoLogfile;
  990. osal_file_t fpPicTypeLogfile;
  991. osal_file_t fpSeqDispInfoLogfile;
  992. osal_file_t fpUserDataLogfile;
  993. osal_file_t fpSeqUserDataLogfile;
  994. // encoder report file
  995. osal_file_t fpEncSliceBndInfo;
  996. osal_file_t fpEncQpInfo;
  997. osal_file_t fpEncmvInfo;
  998. osal_file_t fpEncsliceInfo;
  999. // Report Information
  1000. BOOL reportOpened;
  1001. Int32 decIndex;
  1002. vpu_buffer_t vb_rpt;
  1003. BOOL userDataEnable;
  1004. BOOL userDataReportMode;
  1005. Int32 profile;
  1006. Int32 level;
  1007. } vpu_rpt_info_t;
  1008. typedef struct VpuReportConfig_t {
  1009. PhysicalAddress userDataBufAddr;
  1010. BOOL userDataEnable;
  1011. Int32 userDataReportMode; // (0 : Int32errupt mode, 1 Int32errupt disable mode)
  1012. Int32 userDataBufSize;
  1013. } VpuReportConfig_t;
  1014. void OpenDecReport(
  1015. Uint32 core_idx,
  1016. VpuReportConfig_t* cfg
  1017. );
  1018. void CloseDecReport(
  1019. DecHandle handle
  1020. );
  1021. void ConfigDecReport(
  1022. Uint32 core_idx,
  1023. DecHandle handle,
  1024. CodStd bitstreamFormat
  1025. );
  1026. void SaveDecReport(
  1027. Uint32 core_idx,
  1028. DecHandle handle,
  1029. DecOutputInfo* pDecInfo,
  1030. CodStd bitstreamFormat,
  1031. Uint32 mbNumX,
  1032. Uint32 mbNumY
  1033. );
  1034. void CheckUserDataInterrupt(
  1035. Uint32 core_idx,
  1036. DecHandle handle,
  1037. Int32 decodeIdx,
  1038. CodStd bitstreamFormat,
  1039. Int32 int_reason
  1040. );
  1041. RetCode VPU_GetFBCOffsetTableSize(
  1042. CodStd codStd,
  1043. int width,
  1044. int height,
  1045. int* ysize,
  1046. int* csize
  1047. );
  1048. extern Int32 ProductCalculateAuxBufferSize(
  1049. AUX_BUF_TYPE type,
  1050. CodStd codStd,
  1051. Int32 width,
  1052. Int32 height
  1053. );
  1054. #if defined(SUPPORT_LOOK_AHEAD_RC)
  1055. #define MAX_CFG (187)
  1056. #else
  1057. #define MAX_CFG (183)
  1058. #endif
  1059. #define MAX_ROI_LEVEL (8)
  1060. #define LOG2_CTB_SIZE (5)
  1061. #define CTB_SIZE (1<<LOG2_CTB_SIZE)
  1062. #define LAMBDA_SCALE_FACTOR (100000)
  1063. #define FLOATING_POINT_LAMBDA (1)
  1064. #define TEMP_SCALABLE_RC (1)
  1065. #define UI16_MAX (0xFFFF)
  1066. #ifndef INT_MAX
  1067. #define INT_MAX (2147483647)
  1068. #endif
  1069. typedef struct {
  1070. char *name;
  1071. int min;
  1072. int max;
  1073. int def;
  1074. } WaveCfgInfo;
  1075. Int32 GetEncOpenParamChange(
  1076. EncOpenParam* pEncOP,
  1077. char* cfgFileName,
  1078. ENC_CFG* pEncCfg,
  1079. EncHandle handle
  1080. );
  1081. void PrintVpuVersionInfo(
  1082. Uint32 coreIdx
  1083. );
  1084. void ChangePathStyle(
  1085. char *str
  1086. );
  1087. BOOL CalcYuvSize(
  1088. Int32 format,
  1089. Int32 picWidth,
  1090. Int32 picHeight,
  1091. Int32 cbcrInterleave,
  1092. size_t *lumaSize,
  1093. size_t *chromaSize,
  1094. size_t *frameSize,
  1095. Int32 *bitDepth,
  1096. Int32 *packedFormat,
  1097. Int32 *yuv3p4b
  1098. );
  1099. FrameBufferFormat GetPackedFormat (
  1100. int srcBitDepth,
  1101. int packedType,
  1102. int p10bits,
  1103. int msb
  1104. );
  1105. char* GetDirname(
  1106. const char* path
  1107. );
  1108. char* GetBasename(
  1109. const char* pathname
  1110. );
  1111. char* GetFileExtension(
  1112. const char* filename
  1113. );
  1114. int parseAvcCfgFile(
  1115. ENC_CFG* pEncCfg,
  1116. char* filename
  1117. );
  1118. int parseMp4CfgFile(
  1119. ENC_CFG* pEncCfg,
  1120. char* filename
  1121. );
  1122. int parseWaveEncCfgFile(
  1123. ENC_CFG* pEncCfg,
  1124. char* FileName,
  1125. int bitFormat
  1126. );
  1127. int parseWaveChangeParamCfgFile(
  1128. ENC_CFG* pEncCfg,
  1129. char* FileName
  1130. );
  1131. int parseRoiCtuModeParam(
  1132. char* lineStr,
  1133. VpuRect* roiRegion,
  1134. int* roiLevel,
  1135. int picX,
  1136. int picY
  1137. );
  1138. #ifdef __cplusplus
  1139. }
  1140. #endif /* __cplusplus */
  1141. /************************************************************************/
  1142. /* Structure */
  1143. /************************************************************************/
  1144. typedef struct TestDecConfig_struct {
  1145. char outputPath[MAX_FILE_PATH];
  1146. char inputPath[MAX_FILE_PATH];
  1147. Int32 forceOutNum;
  1148. CodStd bitFormat;
  1149. Int32 reorder;
  1150. TiledMapType mapType;
  1151. BitStreamMode bitstreamMode;
  1152. BOOL enableWTL;
  1153. FrameFlag wtlMode;
  1154. FrameBufferFormat wtlFormat;
  1155. Int32 coreIdx;
  1156. ProductId productId;
  1157. BOOL enableCrop; //!<< option for saving yuv
  1158. BOOL cbcrInterleave; //!<< 0: None, 1: NV12, 2: NV21
  1159. BOOL nv21; //!<< FALSE: NV12, TRUE: NV21,
  1160. //!<< This variable is valid when cbcrInterleave is TRUE
  1161. EndianMode streamEndian;
  1162. EndianMode frameEndian;
  1163. Uint32 secondaryAXI;
  1164. Int32 compareType;
  1165. char md5Path[MAX_FILE_PATH];
  1166. char fwPath[MAX_FILE_PATH];
  1167. char refYuvPath[MAX_FILE_PATH];
  1168. RenderDeviceType renderType;
  1169. BOOL thumbnailMode;
  1170. Int32 skipMode;
  1171. size_t bsSize;
  1172. BOOL streamEndFlag;
  1173. Uint32 scaleDownWidth;
  1174. Uint32 scaleDownHeight;
  1175. struct {
  1176. BOOL enableMvc; //!<< H.264 MVC
  1177. BOOL enableTiled2Linear;
  1178. FrameFlag tiled2LinearMode;
  1179. BOOL enableBWB;
  1180. Uint32 rotate; //!<< 0, 90, 180, 270
  1181. Uint32 mirror;
  1182. BOOL enableDering; //!<< MPEG-2/4
  1183. BOOL enableDeblock; //!<< MPEG-2/4
  1184. Uint32 mp4class; //!<< MPEG_4
  1185. Uint32 frameCacheBypass;
  1186. Uint32 frameCacheBurst;
  1187. Uint32 frameCacheMerge;
  1188. Uint32 frameCacheWayShape;
  1189. LowDelayInfo lowDelay; //!<< H.264
  1190. } coda9;
  1191. struct {
  1192. Uint32 numVCores; //!<< This numVCores is valid on PRODUCT_ID_4102 multi-core version
  1193. BOOL bwOptimization; //!<< On/Off bandwidth optimization function
  1194. BOOL craAsBla;
  1195. Uint32 av1Format;
  1196. } wave;
  1197. Uint32 pfClock; //!<< performance clock in Hz
  1198. BOOL performance;
  1199. BOOL bandwidth;
  1200. Uint32 fps;
  1201. Uint32 enableUserData;
  1202. /* FEEDER */
  1203. FeedingMethod feedingMode;
  1204. Uint32 feedingSize;
  1205. Uint32 loopCount;
  1206. BOOL errorInject;
  1207. } TestDecConfig;
  1208. #ifdef __cplusplus
  1209. extern "C" {
  1210. #endif /* __cplusplus */
  1211. void SetDefaultDecTestConfig(
  1212. TestDecConfig* testConfig
  1213. );
  1214. void Coda9SetDefaultDecTestConfig(
  1215. TestDecConfig* testConfig
  1216. );
  1217. struct option* ConvertOptions(
  1218. struct OptionExt* cnmOpt,
  1219. Uint32 nItems
  1220. );
  1221. void ReleaseVideoMemory(
  1222. DecHandle handle,
  1223. vpu_buffer_t* memoryArr,
  1224. Uint32 count
  1225. );
  1226. void *AllocateDecFrameBuffer2(
  1227. DecHandle decHandle,
  1228. TestDecConfig* config,
  1229. Uint32 size,
  1230. FrameBuffer* retFbArray,
  1231. vpu_buffer_t* retFbAddrs
  1232. );
  1233. BOOL AttachDecDMABuffer(
  1234. DecHandle decHandle,
  1235. TestDecConfig* config,
  1236. Uint64 virtAddress,
  1237. Uint32 size,
  1238. FrameBuffer* retFbArray,
  1239. vpu_buffer_t* retFbAddrs
  1240. );
  1241. BOOL AllocateDecFrameBuffer(
  1242. DecHandle decHandle,
  1243. TestDecConfig* config,
  1244. Uint32 tiledFbCount,
  1245. Uint32 linearFbCount,
  1246. FrameBuffer* retFbArray,
  1247. vpu_buffer_t* retFbAddrs,
  1248. #if 0
  1249. vpu_buffer_t* inFbAddrs,
  1250. Uint32 inFbCount,
  1251. #endif
  1252. Uint32* retStride
  1253. );
  1254. BOOL AllocFBMemory(
  1255. Uint32 coreIdx,
  1256. vpu_buffer_t *pFbMem,
  1257. FrameBuffer *pFb,
  1258. Uint32 memSize,
  1259. Uint32 memNum,
  1260. Int32 memTypes,
  1261. Int32 instIndex
  1262. );
  1263. BOOL Coda9AllocateDecPPUFrameBuffer(
  1264. BOOL* pEnablePPU,
  1265. DecHandle decHandle,
  1266. TestDecConfig* config,
  1267. FrameBuffer* retFbArray,
  1268. vpu_buffer_t* retFbAddrs,
  1269. Queue* ppuQ
  1270. );
  1271. RetCode SetUpDecoderOpenParam(
  1272. DecOpenParam* param,
  1273. TestDecConfig* config
  1274. );
  1275. #define OUTPUT_FP_NUMBER 4
  1276. BOOL OpenDisplayBufferFile(
  1277. CodStd codec,
  1278. char *outputPath,
  1279. VpuRect rcDisplay,
  1280. TiledMapType mapType,
  1281. FILE *fp[]
  1282. );
  1283. void CloseDisplayBufferFile(
  1284. FILE *fp[]
  1285. );
  1286. void SaveDisplayBufferToFile(
  1287. DecHandle handle,
  1288. CodStd codStd,
  1289. FrameBuffer dispFrame,
  1290. VpuRect rcDisplay,
  1291. FILE *fp[]
  1292. );
  1293. void GetUserData(
  1294. Int32 coreIdx,
  1295. Uint8* pBase,
  1296. vpu_buffer_t vbUserData,
  1297. DecOutputInfo outputInfo
  1298. );
  1299. Uint32 CalcScaleDown(
  1300. Uint32 origin,
  1301. Uint32 scaledValue
  1302. );
  1303. Uint64 RemapVaddr(
  1304. DecHandle decHandle,
  1305. Uint64 virtAddress,
  1306. Uint32 size
  1307. );
  1308. #ifdef __cplusplus
  1309. }
  1310. #endif /* __cplusplus */
  1311. typedef struct TestEncConfig_struct {
  1312. char yuvSourceBaseDir[MAX_FILE_PATH];
  1313. char yuvFileName[MAX_FILE_PATH];
  1314. char cmdFileName[MAX_FILE_PATH];
  1315. char bitstreamFileName[MAX_FILE_PATH];
  1316. char huffFileName[MAX_FILE_PATH];
  1317. char cInfoFileName[MAX_FILE_PATH];
  1318. char qMatFileName[MAX_FILE_PATH];
  1319. char qpFileName[MAX_FILE_PATH];
  1320. char cfgFileName[MAX_FILE_PATH];
  1321. #ifdef SUPPORT_LOOK_AHEAD_RC
  1322. char cfgFileName_larc_pass1[MAX_FILE_PATH];
  1323. #endif
  1324. CodStd stdMode;
  1325. int picWidth;
  1326. int picHeight;
  1327. int kbps;
  1328. int rotAngle;
  1329. int mirDir;
  1330. int useRot;
  1331. int qpReport;
  1332. int ringBufferEnable;
  1333. int rcIntraQp;
  1334. int outNum;
  1335. int skipPicNums[MAX_PIC_SKIP_NUM];
  1336. Uint32 coreIdx;
  1337. TiledMapType mapType;
  1338. // 2D cache option
  1339. int lineBufIntEn;
  1340. int en_container; //enable container
  1341. int container_frame_rate; //framerate for container
  1342. int picQpY;
  1343. int cbcrInterleave;
  1344. int nv21;
  1345. BOOL needSourceConvert; //!<< If the format of YUV file is YUV planar mode and EncOpenParam::cbcrInterleave or EncOpenParam::nv21 is true
  1346. //!<< the value of needSourceConvert should be true.
  1347. int packedFormat;
  1348. FrameBufferFormat srcFormat;
  1349. #ifdef SUPPORT_LOOK_AHEAD_RC
  1350. int look_ahead_rc;
  1351. #endif
  1352. int bitdepth;
  1353. int secondaryAXI;
  1354. EndianMode stream_endian;
  1355. int frame_endian;
  1356. int source_endian;
  1357. ProductId productId;
  1358. int compareType;
  1359. #define YUV_MODE_YUV 0
  1360. #define YUV_MODE_YUV_LOADER 2
  1361. #define YUV_MODE_CFBC 3
  1362. int yuv_mode;
  1363. char ref_stream_path[MAX_FILE_PATH];
  1364. int loopCount;
  1365. char ref_recon_md5_path[MAX_FILE_PATH];
  1366. BOOL performance;
  1367. BOOL bandwidth;
  1368. Uint32 fps;
  1369. Uint32 pfClock;
  1370. char roi_file_name[MAX_FILE_PATH];
  1371. FILE *roi_file;
  1372. int roi_enable;
  1373. int encAUD;
  1374. int encEOS;
  1375. int encEOB;
  1376. struct {
  1377. BOOL enableLinear2Tiled;
  1378. FrameFlag linear2TiledMode;
  1379. } coda9;
  1380. int useAsLongtermPeriod;
  1381. int refLongtermPeriod;
  1382. // newly added for encoder
  1383. FILE* scaling_list_file;
  1384. char scaling_list_fileName[MAX_FILE_PATH];
  1385. FILE* custom_lambda_file;
  1386. char custom_lambda_fileName[MAX_FILE_PATH];
  1387. Uint32 roi_avg_qp;
  1388. FILE* lambda_map_file;
  1389. Uint32 lambda_map_enable;
  1390. char lambda_map_fileName[MAX_FILE_PATH];
  1391. FILE* mode_map_file;
  1392. Uint32 mode_map_flag;
  1393. char mode_map_fileName[MAX_FILE_PATH];
  1394. FILE* wp_param_file;
  1395. Uint32 wp_param_flag;
  1396. char wp_param_fileName[MAX_FILE_PATH];
  1397. Int32 force_picskip_start;
  1398. Int32 force_picskip_end;
  1399. Int32 force_coefdrop_start;
  1400. Int32 force_coefdrop_end;
  1401. Int32 numChangeParam;
  1402. W5ChangeParam changeParam[10];
  1403. int forceIdrPicIdx;
  1404. Int32 lowLatencyMode;
  1405. char optYuvPath[256];
  1406. #ifdef SUPPORT_SOURCE_RELEASE_INTERRUPT
  1407. int srcReleaseIntEnable;
  1408. #endif
  1409. int ringBufferWrapEnable;
  1410. #ifdef SUPPORT_LOOK_AHEAD_RC
  1411. #define LOOK_AHEAD_RC_PASS1 1
  1412. #define LOOK_AHEAD_RC_PASS2 2
  1413. char optYuvPath_larc_pass1[MAX_FILE_PATH];
  1414. int larcEnable; //look ahead RC
  1415. int larcPass; //look ahead RCPass. look ahead Rc is enabled if value is not 0
  1416. #endif
  1417. } TestEncConfig;
  1418. #ifdef __cplusplus
  1419. extern "C" {
  1420. #endif /* __cplusplus */
  1421. BOOL SetupEncoderOpenParam(
  1422. EncOpenParam* param,
  1423. TestEncConfig* config,
  1424. ENC_CFG* encConfig
  1425. );
  1426. Int32 GetEncOpenParam(
  1427. EncOpenParam* pEncOP,
  1428. TestEncConfig* pEncConfig,
  1429. ENC_CFG* pEncCfg
  1430. );
  1431. Int32 GetEncOpenParamDefault(
  1432. EncOpenParam* pEncOP,
  1433. TestEncConfig* pEncConfig
  1434. );
  1435. void GenRegionToMap(
  1436. VpuRect *region, /**< The size of the ROI region for H.265 (start X/Y in CTU, end X/Y in CTU) */
  1437. int *roiLevel,
  1438. int num,
  1439. Uint32 mapWidth,
  1440. Uint32 mapHeight,
  1441. Uint8 *roiCtuMap
  1442. );
  1443. int setRoiMap(
  1444. int coreIdx,
  1445. TestEncConfig *encConfig,
  1446. EncOpenParam encOP,
  1447. PhysicalAddress addrRoiMap,
  1448. Uint8 *roiMapBuf,
  1449. int srcFrameWidth,
  1450. int srcFrameHeight,
  1451. EncParam *encParam,
  1452. int maxCtuNum
  1453. );
  1454. void setEncBgMode(
  1455. EncParam *encParam,
  1456. TestEncConfig encConfig
  1457. );
  1458. void GenRegionToQpMap(
  1459. VpuRect *region, /**< The size of the ROI region for H.265 (start X/Y in CTU, end X/Y int CTU) */
  1460. int *roiLevel,
  1461. int num,
  1462. int initQp,
  1463. Uint32 mapWidth,
  1464. Uint32 mapHeight,
  1465. Uint8 *roiCtuMap
  1466. );
  1467. void CheckParamRestriction(
  1468. Uint32 productId,
  1469. TestEncConfig *encConfig
  1470. );
  1471. int openRoiMapFile(
  1472. TestEncConfig *encConfig
  1473. );
  1474. int allocateRoiMapBuf(
  1475. EncHandle handle,
  1476. TestEncConfig encConfig,
  1477. vpu_buffer_t *vbROi,
  1478. int srcFbNum,
  1479. int ctuNum
  1480. );
  1481. void SetMapData(
  1482. int coreIdx,
  1483. TestEncConfig encConfig,
  1484. EncOpenParam encOP,
  1485. EncParam *encParam,
  1486. int srcFrameWidth,
  1487. int srcFrameHeight,
  1488. unsigned long addrCustomMap
  1489. );
  1490. RetCode SetChangeParam(
  1491. EncHandle handle,
  1492. TestEncConfig encConfig,
  1493. EncOpenParam encOP,
  1494. Int32 changedCount
  1495. );
  1496. BOOL GetBitstreamToBuffer(
  1497. EncHandle handle,
  1498. Uint8* pBuffer,
  1499. PhysicalAddress rdAddr,
  1500. PhysicalAddress wrAddr,
  1501. PhysicalAddress streamBufStartAddr,
  1502. PhysicalAddress streamBufEndAddr,
  1503. Uint32 streamSize,
  1504. EndianMode endian,
  1505. BOOL enabledRinbuffer
  1506. );
  1507. void SetDefaultEncTestConfig(
  1508. TestEncConfig* testConfig
  1509. );
  1510. /************************************************************************/
  1511. /* User Parameters (ENCODER) */
  1512. /************************************************************************/
  1513. // user scaling list
  1514. #define SL_NUM_MATRIX (6)
  1515. typedef struct
  1516. {
  1517. Uint8 s4[SL_NUM_MATRIX][16]; // [INTRA_Y/U/V,INTER_Y/U/V][NUM_COEFF]
  1518. Uint8 s8[SL_NUM_MATRIX][64];
  1519. Uint8 s16[SL_NUM_MATRIX][64];
  1520. Uint8 s32[SL_NUM_MATRIX][64];
  1521. Uint8 s16dc[SL_NUM_MATRIX];
  1522. Uint8 s32dc[2];
  1523. }UserScalingList;
  1524. enum ScalingListSize
  1525. {
  1526. SCALING_LIST_4x4 = 0,
  1527. SCALING_LIST_8x8,
  1528. SCALING_LIST_16x16,
  1529. SCALING_LIST_32x32,
  1530. SCALING_LIST_SIZE_NUM
  1531. };
  1532. int parse_user_scaling_list(
  1533. UserScalingList* sl,
  1534. FILE* fp_sl,
  1535. CodStd stdMode
  1536. );
  1537. // custom lambda
  1538. #define NUM_CUSTOM_LAMBDA (2*52)
  1539. int parse_custom_lambda(Uint32 buf[NUM_CUSTOM_LAMBDA], FILE* fp);
  1540. #ifdef __cplusplus
  1541. }
  1542. #endif /* __cplusplus */
  1543. #endif /* _MAIN_HELPER_H_ */