main_helper.h 44 KB

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