main_helper.h 44 KB

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