main_helper.h 43 KB

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