main_helper.c 130 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159
  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. #include <stdio.h>
  26. #include <stdarg.h>
  27. #include <string.h>
  28. #include <time.h>
  29. #include <errno.h>
  30. #include "vpuapifunc.h"
  31. #include "coda9/coda9_regdefine.h"
  32. #include "wave/wave5_regdefine.h"
  33. #include "vpuerror.h"
  34. #include "main_helper.h"
  35. #include "misc/debug.h"
  36. #if defined(PLATFORM_NON_OS) || defined (PLATFORM_LINUX)
  37. #include <getopt.h>
  38. #endif
  39. #if defined(PLATFORM_LINUX) || defined(PLATFORM_QNX) || defined(PLATFORM_NON_OS)
  40. #include <sys/stat.h>
  41. #include <unistd.h>
  42. #endif
  43. #define BIT_DUMMY_READ_GEN 0x06000000
  44. #define BIT_READ_LATENCY 0x06000004
  45. #define W5_SET_READ_DELAY 0x01000000
  46. #define W5_SET_WRITE_DELAY 0x01000004
  47. #define MAX_CODE_BUF_SIZE (512*1024)
  48. #ifdef PLATFORM_WIN32
  49. #pragma warning(disable : 4996) //!<< disable waring C4996: The POSIX name for this item is deprecated.
  50. #endif
  51. char* EncPicTypeStringH264[] = {
  52. "IDR/I",
  53. "P",
  54. };
  55. char* EncPicTypeStringMPEG4[] = {
  56. "I",
  57. "P",
  58. };
  59. static osal_mutex_t s_loadBalancerLock;
  60. static Uint32 s_nextInstance;
  61. static BOOL s_enableLoadBalance;
  62. static Uint32 s_instances[MAX_NUM_INSTANCE];
  63. enum {
  64. LB_STATE_NONE,
  65. LB_STATE_RUNNING
  66. };
  67. void LoadBalancerInit(void)
  68. {
  69. s_loadBalancerLock = osal_mutex_create();
  70. s_nextInstance = 0;
  71. s_enableLoadBalance = TRUE;
  72. osal_memset((void*)s_instances, 0x00, sizeof(s_instances));
  73. }
  74. void LoadBalancerRelease(void)
  75. {
  76. if (TRUE == s_enableLoadBalance) {
  77. osal_mutex_destroy(s_loadBalancerLock);
  78. }
  79. }
  80. void LoadBalancerAddInstance(Uint32 instanceIndex)
  81. {
  82. if (TRUE == s_enableLoadBalance) {
  83. osal_mutex_lock(s_loadBalancerLock);
  84. s_instances[instanceIndex] = LB_STATE_RUNNING;
  85. osal_mutex_unlock(s_loadBalancerLock);
  86. }
  87. }
  88. void LoadBalancerRemoveInstance(Uint32 instanceIndex)
  89. {
  90. if (TRUE == s_enableLoadBalance) {
  91. osal_mutex_lock(s_loadBalancerLock);
  92. s_instances[instanceIndex] = LB_STATE_NONE;
  93. if (s_nextInstance == instanceIndex) {
  94. Uint32 i = instanceIndex;
  95. Uint32 count=0;
  96. while (MAX_NUM_INSTANCE > count) {
  97. i = (i+1) % MAX_NUM_INSTANCE;
  98. if (LB_STATE_RUNNING == s_instances[i]) {
  99. s_nextInstance = i;
  100. break;
  101. }
  102. count++;
  103. }
  104. }
  105. osal_mutex_unlock(s_loadBalancerLock);
  106. }
  107. }
  108. BOOL LoadBalancerGetMyTurn(Uint32 myInstance)
  109. {
  110. BOOL myTurn = TRUE;
  111. if (TRUE == s_enableLoadBalance) {
  112. osal_mutex_lock(s_loadBalancerLock);
  113. myTurn = (BOOL)(myInstance == s_nextInstance);
  114. osal_mutex_unlock(s_loadBalancerLock);
  115. }
  116. return myTurn;
  117. }
  118. void LoadBalancerSetNextTurn(void)
  119. {
  120. if (TRUE == s_enableLoadBalance) {
  121. osal_mutex_lock(s_loadBalancerLock);
  122. do {
  123. s_nextInstance++;
  124. s_nextInstance %= MAX_NUM_INSTANCE;
  125. } while (LB_STATE_NONE == s_instances[s_nextInstance]);
  126. osal_mutex_unlock(s_loadBalancerLock);
  127. }
  128. }
  129. void SetDefaultDecTestConfig(TestDecConfig* testConfig)
  130. {
  131. osal_memset(testConfig, 0, sizeof(TestDecConfig));
  132. testConfig->bitstreamMode = BS_MODE_INTERRUPT;
  133. testConfig->feedingMode = FEEDING_METHOD_FIXED_SIZE;
  134. testConfig->streamEndian = VPU_STREAM_ENDIAN;
  135. testConfig->frameEndian = VPU_FRAME_ENDIAN;
  136. testConfig->cbcrInterleave = FALSE;
  137. testConfig->nv21 = FALSE;
  138. testConfig->bitFormat = STD_HEVC;
  139. testConfig->renderType = RENDER_DEVICE_NULL;
  140. testConfig->mapType = COMPRESSED_FRAME_MAP;
  141. testConfig->enableWTL = TRUE;
  142. testConfig->wtlMode = FF_FRAME;
  143. testConfig->wtlFormat = FORMAT_420; //!<< 8 bit YUV
  144. testConfig->wave.bwOptimization = FALSE; //!<< TRUE: non-ref pictures are not stored at reference picture buffer
  145. //!<< for saving bandwidth.
  146. testConfig->wave.av1Format = 0;
  147. testConfig->fps = 30;
  148. }
  149. void Coda9SetDefaultDecTestConfig(TestDecConfig* testConfig)
  150. {
  151. osal_memset(testConfig, 0, sizeof(TestDecConfig));
  152. testConfig->bitstreamMode = BS_MODE_INTERRUPT;
  153. testConfig->feedingMode = FEEDING_METHOD_FIXED_SIZE;
  154. testConfig->streamEndian = VPU_STREAM_ENDIAN;
  155. testConfig->frameEndian = VPU_FRAME_ENDIAN;
  156. testConfig->cbcrInterleave = FALSE;
  157. testConfig->nv21 = FALSE;
  158. testConfig->bitFormat = STD_AVC;
  159. testConfig->renderType = RENDER_DEVICE_NULL;
  160. testConfig->mapType = LINEAR_FRAME_MAP;
  161. testConfig->wtlMode = FF_NONE;
  162. testConfig->enableWTL = FALSE;
  163. testConfig->wtlFormat = FORMAT_420; //!<< 8 bit YUV
  164. testConfig->fps = 30;
  165. testConfig->coda9.frameCacheBypass = 0;
  166. testConfig->coda9.frameCacheBurst = 0;
  167. testConfig->coda9.frameCacheMerge = 3;
  168. testConfig->coda9.frameCacheWayShape = 15;
  169. testConfig->coda9.rotate = 0;
  170. testConfig->coda9.mirror = 0;
  171. testConfig->coda9.enableTiled2Linear = FALSE;
  172. testConfig->coda9.tiled2LinearMode = FF_NONE;
  173. testConfig->coda9.enableDering = FALSE;
  174. testConfig->coda9.enableBWB = VPU_ENABLE_BWB;
  175. }
  176. Uint32 randomSeed;
  177. static BOOL initializedRandom;
  178. Uint32 GetRandom(
  179. Uint32 start,
  180. Uint32 end
  181. )
  182. {
  183. Uint32 range = end-start+1;
  184. if (randomSeed == 0) {
  185. randomSeed = (Uint32)time(NULL);
  186. VLOG(INFO, "======= RANDOM SEED: %08x ======\n", randomSeed);
  187. }
  188. if (initializedRandom == FALSE) {
  189. srand(randomSeed);
  190. initializedRandom = TRUE;
  191. }
  192. if (range == 0) {
  193. VLOG(ERR, "%s:%d RANGE IS 0\n", __FUNCTION__, __LINE__);
  194. return 0;
  195. }
  196. else {
  197. return ((rand()%range) + start);
  198. }
  199. }
  200. Int32 LoadFirmware(
  201. Int32 productId,
  202. Uint8** retFirmware,
  203. Uint32* retSizeInWord,
  204. const char* path
  205. )
  206. {
  207. Int32 nread;
  208. Uint32 totalRead, allocSize, readSize = 1024*1024;
  209. Uint8* firmware = NULL;
  210. osal_file_t fp;
  211. if ((fp=osal_fopen(path, "rb")) == NULL)
  212. {
  213. VLOG(ERR, "Failed to open %s\n", path);
  214. return -1;
  215. }
  216. totalRead = 0;
  217. if (PRODUCT_ID_W_SERIES(productId))
  218. {
  219. firmware = (Uint8*)osal_malloc(readSize);
  220. allocSize = readSize;
  221. nread = 0;
  222. while (TRUE)
  223. {
  224. if (allocSize < (totalRead+readSize))
  225. {
  226. allocSize += 2*nread;
  227. firmware = (Uint8*)realloc(firmware, allocSize);
  228. }
  229. nread = osal_fread((void*)&firmware[totalRead], 1, readSize, fp);//lint !e613
  230. totalRead += nread;
  231. if (nread < (Int32)readSize)
  232. break;
  233. }
  234. *retSizeInWord = (totalRead+1)/2;
  235. }
  236. else
  237. {
  238. Uint16* pusBitCode;
  239. pusBitCode = (Uint16 *)osal_malloc(MAX_CODE_BUF_SIZE);
  240. firmware = (Uint8*)pusBitCode;
  241. if (pusBitCode)
  242. {
  243. int code;
  244. while (!osal_feof(fp) || totalRead < (MAX_CODE_BUF_SIZE/2)) {
  245. code = -1;
  246. if (fscanf(fp, "%x", &code) <= 0) {
  247. /* matching failure or EOF */
  248. break;
  249. }
  250. pusBitCode[totalRead++] = (Uint16)code;
  251. }
  252. }
  253. *retSizeInWord = totalRead;
  254. }
  255. osal_fclose(fp);
  256. *retFirmware = firmware;
  257. return 0;
  258. }
  259. void PrintVpuVersionInfo(
  260. Uint32 core_idx
  261. )
  262. {
  263. Uint32 version;
  264. Uint32 revision;
  265. Uint32 productId;
  266. VPU_GetVersionInfo(core_idx, &version, &revision, &productId);
  267. VLOG(INFO, "VPU coreNum : [%d]\n", core_idx);
  268. VLOG(INFO, "Firmware : CustomerCode: %04x | version : %d.%d.%d rev.%d\n",
  269. (Uint32)(version>>16), (Uint32)((version>>(12))&0x0f), (Uint32)((version>>(8))&0x0f), (Uint32)((version)&0xff), revision);
  270. VLOG(INFO, "Hardware : %04x\n", productId);
  271. VLOG(INFO, "API : %d.%d.%d\n\n", API_VERSION_MAJOR, API_VERSION_MINOR, API_VERSION_PATCH);
  272. }
  273. BOOL OpenDisplayBufferFile(CodStd codec, char *outputPath, VpuRect rcDisplay, TiledMapType mapType, FILE *fp[])
  274. {
  275. char strFile[MAX_FILE_PATH];
  276. int width;
  277. int height;
  278. width = rcDisplay.right - rcDisplay.left;
  279. height = rcDisplay.bottom - rcDisplay.top;
  280. if (mapType == LINEAR_FRAME_MAP) {
  281. if ((fp[0]=osal_fopen(outputPath, "wb")) == NULL) {
  282. VLOG(ERR, "%s:%d failed to open %s\n", __FUNCTION__, __LINE__, outputPath);
  283. goto ERR_OPEN_DISP_BUFFER_FILE;
  284. }
  285. }
  286. else {
  287. width = (codec == STD_HEVC || codec == STD_AVS2) ? VPU_ALIGN16(width) : VPU_ALIGN64(width);
  288. height = (codec == STD_HEVC || codec == STD_AVS2) ? VPU_ALIGN16(height) : VPU_ALIGN64(height);
  289. sprintf(strFile, "%s_%dx%d_fbc_data_y.bin", outputPath, width, height);
  290. if ((fp[0]=osal_fopen(strFile, "wb")) == NULL) {
  291. VLOG(ERR, "%s:%d failed to open %s\n", __FUNCTION__, __LINE__, strFile);
  292. goto ERR_OPEN_DISP_BUFFER_FILE;
  293. }
  294. sprintf(strFile, "%s_%dx%d_fbc_data_c.bin", outputPath, width, height);
  295. if ((fp[1]=osal_fopen(strFile, "wb")) == NULL) {
  296. VLOG(ERR, "%s:%d failed to open %s\n", __FUNCTION__, __LINE__, strFile);
  297. goto ERR_OPEN_DISP_BUFFER_FILE;
  298. }
  299. sprintf(strFile, "%s_%dx%d_fbc_table_y.bin", outputPath, width, height);
  300. if ((fp[2]=osal_fopen(strFile, "wb")) == NULL) {
  301. VLOG(ERR, "%s:%d failed to open %s\n", __FUNCTION__, __LINE__, strFile);
  302. goto ERR_OPEN_DISP_BUFFER_FILE;
  303. }
  304. sprintf(strFile, "%s_%dx%d_fbc_table_c.bin", outputPath, width, height);
  305. if ((fp[3]=osal_fopen(strFile, "wb")) == NULL) {
  306. VLOG(ERR, "%s:%d failed to open %s\n", __FUNCTION__, __LINE__, strFile);
  307. goto ERR_OPEN_DISP_BUFFER_FILE;
  308. }
  309. }
  310. return TRUE;
  311. ERR_OPEN_DISP_BUFFER_FILE:
  312. CloseDisplayBufferFile(fp);
  313. return FALSE;
  314. }
  315. void CloseDisplayBufferFile(FILE *fp[])
  316. {
  317. int i;
  318. for (i=0; i < OUTPUT_FP_NUMBER; i++) {
  319. if (fp[i] != NULL) {
  320. osal_fclose(fp[i]);
  321. fp[i] = NULL;
  322. }
  323. }
  324. }
  325. RetCode VPU_GetFBCOffsetTableSize(CodStd codStd, int width, int height, int* ysize, int* csize)
  326. {
  327. if (ysize == NULL || csize == NULL)
  328. return RETCODE_INVALID_PARAM;
  329. *ysize = ProductCalculateAuxBufferSize(AUX_BUF_TYPE_FBC_Y_OFFSET, codStd, width, height);
  330. *csize = ProductCalculateAuxBufferSize(AUX_BUF_TYPE_FBC_C_OFFSET, codStd, width, height);
  331. return RETCODE_SUCCESS;
  332. }
  333. RetCode VPU_GetPVRICRealSize(CodStd codStd, TiledMapType mapType, FrameBufferFormat format, int width, int height, int* ysize, int* csize)
  334. {
  335. Uint32 total_tile_num, hdr_size, data_size;
  336. if (ysize == NULL || csize == NULL)
  337. return RETCODE_INVALID_PARAM;
  338. switch (format) {
  339. case FORMAT_420:
  340. total_tile_num = (VPU_ALIGN64(width) >> 6) *(VPU_ALIGN4(height) >> 2);//width
  341. break;
  342. default: /* 10bit */
  343. total_tile_num = (width+47)/48 * (VPU_ALIGN4(height) >> 2);
  344. break;
  345. }
  346. hdr_size = VPU_ALIGN256(total_tile_num);
  347. if( mapType == PVRIC_COMPRESSED_FRAME_LOSSLESS_MAP ) {
  348. data_size = (total_tile_num*256); // byte
  349. }
  350. else {
  351. data_size = (total_tile_num*128); // byte
  352. }
  353. *ysize = (hdr_size + data_size);
  354. VLOG(ERR, "VPU_GetPVRICRealSize luma h=%d(%x), d=%d(%x)\n", hdr_size, hdr_size, data_size, data_size);
  355. switch (format) {
  356. case FORMAT_420:
  357. total_tile_num = (VPU_ALIGN64(width) >> 6) *(VPU_ALIGN4(height/2) >> 2);
  358. break;
  359. default: /* 10bit */
  360. total_tile_num = (width+47)/48 * (VPU_ALIGN4(height/2) >> 2);
  361. break;
  362. }
  363. hdr_size = VPU_ALIGN256(total_tile_num);
  364. if( mapType == PVRIC_COMPRESSED_FRAME_LOSSLESS_MAP ) {
  365. data_size = (total_tile_num*256); // byte
  366. }
  367. else {
  368. data_size = (total_tile_num*128); // byte
  369. }
  370. *csize = (hdr_size + data_size);
  371. VLOG(ERR, "VPU_GetPVRICRealSize chroma h=%d(%x), d=%d(%x)\n", hdr_size, hdr_size, data_size, data_size);
  372. return RETCODE_SUCCESS;
  373. }
  374. void SaveDisplayBufferToFile(DecHandle handle, CodStd codStd, FrameBuffer dispFrame, VpuRect rcDisplay, FILE *fp[])
  375. {
  376. Uint32 width;
  377. Uint32 height;
  378. Uint32 bpp;
  379. DecGetFramebufInfo fbInfo;
  380. CodecInst * pCodecInst;
  381. pCodecInst = handle;
  382. if (dispFrame.myIndex < 0)
  383. return;
  384. if (dispFrame.mapType != COMPRESSED_FRAME_MAP) {
  385. size_t sizeYuv;
  386. Uint8* pYuv;
  387. pYuv = GetYUVFromFrameBuffer(handle, &dispFrame, rcDisplay, &width, &height, &bpp, &sizeYuv);
  388. osal_fwrite(pYuv, 1, sizeYuv, fp[0]);
  389. osal_free(pYuv);
  390. }
  391. else {
  392. Uint32 lumaTblSize;
  393. Uint32 chromaTblSize;
  394. Uint32 lSize;
  395. Uint32 cSize;
  396. Uint32 addr;
  397. Uint32 endian;
  398. Uint8* buf;
  399. Uint32 coreIdx = VPU_HANDLE_CORE_INDEX(handle);
  400. Uint32 productId = VPU_HANDLE_PRODUCT_ID(handle);
  401. Uint32 cFrameStride;
  402. VPU_DecGiveCommand(handle, DEC_GET_FRAMEBUF_INFO, (void*)&fbInfo);
  403. width = rcDisplay.right - rcDisplay.left;
  404. width = (codStd == STD_HEVC || codStd == STD_AVS2) ? VPU_ALIGN16(width) : VPU_ALIGN64(width);
  405. height = rcDisplay.bottom - rcDisplay.top;
  406. height = (codStd == STD_HEVC || codStd == STD_AVS2) ? VPU_ALIGN16(height) : VPU_ALIGN64(height);
  407. cFrameStride = CalcStride(width, height, dispFrame.format, dispFrame.cbcrInterleave, dispFrame.mapType, (codStd == STD_VP9));
  408. lSize = CalcLumaSize(pCodecInst, productId, cFrameStride, height, dispFrame.format, dispFrame.cbcrInterleave, dispFrame.mapType, NULL);
  409. cSize = CalcChromaSize(pCodecInst, productId, cFrameStride, height, dispFrame.format, dispFrame.cbcrInterleave, dispFrame.mapType, NULL) * 2;
  410. // Invert the endian because the pixel order register doesn't affect the FBC data.
  411. endian = (~(Uint32)dispFrame.endian & 0xf) | 0x10;
  412. /* Dump Y compressed data */
  413. if ((buf=(Uint8*)osal_malloc(lSize)) != NULL) {
  414. vdi_read_memory(coreIdx, dispFrame.bufY, buf, lSize, endian);
  415. osal_fwrite((void *)buf, sizeof(Uint8), lSize, fp[0]);
  416. osal_fflush(fp[0]);
  417. osal_free(buf);
  418. }
  419. else {
  420. VLOG(ERR, "%s:%d Failed to save the luma compressed data!!\n", __FUNCTION__, __LINE__);
  421. }
  422. /* Dump C compressed data */
  423. if ((buf=(Uint8*)osal_malloc(cSize)) != NULL) {
  424. vdi_read_memory(coreIdx, dispFrame.bufCb, buf, cSize, endian);
  425. osal_fwrite((void *)buf, sizeof(Uint8), cSize, fp[1]);
  426. osal_fflush(fp[1]);
  427. osal_free(buf);
  428. }
  429. else {
  430. VLOG(ERR, "%s:%d Failed to save the chroma compressed data!!\n", __FUNCTION__, __LINE__);
  431. }
  432. /* Dump Y Offset table */
  433. VPU_GetFBCOffsetTableSize(codStd, (int)width, (int)height, (int*)&lumaTblSize, (int*)&chromaTblSize);
  434. addr = fbInfo.vbFbcYTbl[dispFrame.myIndex].phys_addr;
  435. if ((buf=(Uint8*)osal_malloc(lumaTblSize)) != NULL) {
  436. vdi_read_memory(coreIdx, addr, buf, lumaTblSize, endian);
  437. osal_fwrite((void *)buf, sizeof(Uint8), lumaTblSize, fp[2]);
  438. osal_fflush(fp[2]);
  439. osal_free(buf);
  440. }
  441. else {
  442. VLOG(ERR, "%s:%d Failed to save the offset table of luma!\n", __FUNCTION__, __LINE__);
  443. }
  444. /* Dump C Offset table */
  445. addr = fbInfo.vbFbcCTbl[dispFrame.myIndex].phys_addr;
  446. if ((buf=(Uint8*)osal_malloc(chromaTblSize)) != NULL) {
  447. vdi_read_memory(coreIdx, addr, buf, chromaTblSize, endian);
  448. osal_fwrite((void *)buf, sizeof(Uint8), chromaTblSize, fp[3]);
  449. osal_fflush(fp[3]);
  450. osal_free(buf);
  451. }
  452. else {
  453. VLOG(ERR, "%s:%d Failed to save the offset table of chroma!\n", __FUNCTION__, __LINE__);
  454. }
  455. }
  456. }
  457. void PrintDecSeqWarningMessages(
  458. Uint32 productId,
  459. DecInitialInfo* seqInfo
  460. )
  461. {
  462. if (PRODUCT_ID_W_SERIES(productId))
  463. {
  464. if (seqInfo->seqInitErrReason&0x00000001) VLOG(WARN, "sps_max_sub_layer_minus1 shall be 0 to 6\n");
  465. if (seqInfo->seqInitErrReason&0x00000002) VLOG(WARN, "general_reserved_zero_44bits shall be 0.\n");
  466. if (seqInfo->seqInitErrReason&0x00000004) VLOG(WARN, "reserved_zero_2bits shall be 0\n");
  467. if (seqInfo->seqInitErrReason&0x00000008) VLOG(WARN, "sub_layer_reserved_zero_44bits shall be 0");
  468. if (seqInfo->seqInitErrReason&0x00000010) VLOG(WARN, "general_level_idc shall have one of level of Table A.1\n");
  469. if (seqInfo->seqInitErrReason&0x00000020) VLOG(WARN, "sps_max_dec_pic_buffering[i] <= MaxDpbSize\n");
  470. if (seqInfo->seqInitErrReason&0x00000040) VLOG(WARN, "trailing bits shall be 1000... pattern, 7.3.2.1\n");
  471. if (seqInfo->seqInitErrReason&0x00100000) VLOG(WARN, "Not supported or undefined profile: %d\n", seqInfo->profile);
  472. if (seqInfo->seqInitErrReason&0x00200000) VLOG(WARN, "Spec over level(%d)\n", seqInfo->level);
  473. }
  474. }
  475. void DisplayDecodedInformationForHevc(
  476. DecHandle handle,
  477. Uint32 frameNo,
  478. BOOL performance,
  479. DecOutputInfo* decodedInfo
  480. )
  481. {
  482. Int32 logLevel;
  483. QueueStatusInfo queueStatus;
  484. VPU_DecGiveCommand(handle, DEC_GET_QUEUE_STATUS, &queueStatus);
  485. if (decodedInfo == NULL) {
  486. if ( performance == TRUE ) {
  487. VLOG(INFO, " | FRAME | HOST | SEEK_S SEEK_E SEEK | PARSE_S PARSE_E PARSE | DEC_S DEC_E DEC |\n");
  488. VLOG(INFO, "I NO T POC NAL DECO DISP DISPFLAG RD_PTR WR_PTR FRM_START FRM_END FRM_SIZE WxH SEQ TEMP | CYCLE | TICK | TICK TICK CYCLE | TICK TICK CYCLE | TICK TICK CYCLE | RQ IQ VCore\n");
  489. VLOG(INFO, "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n");
  490. }
  491. else {
  492. VLOG(INFO, "I NO T POC NAL DECO DISP DISPFLAG RD_PTR WR_PTR FRM_START FRM_END FRM_SIZE WxH SEQ TEMP CYCLE ( Seek, Parse, Dec) RQ IQ VCore\n");
  493. VLOG(INFO, "---------------------------------------------------------------------------------------------------------------------------------------------------------------------\n");
  494. }
  495. }
  496. else {
  497. logLevel = (decodedInfo->decodingSuccess&0x01) == 0 ? WARN : INFO;
  498. // Print informations
  499. if ( performance == TRUE ) {
  500. VLOG(logLevel, "%02d %5d %d %4d(%4d) %3d %2d(%2d) %2d(%2d) %08x %08x %08x %08x %08x %8d %4dx%-4d %4d %4d %8d %8d (%6d,%6d,%8d) (%6d,%6d,%8d) (%6d,%6d,%8d) %d %d %d\n",
  501. handle->instIndex, frameNo, decodedInfo->picType,
  502. decodedInfo->decodedPOC, decodedInfo->displayPOC, decodedInfo->nalType,
  503. decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled,
  504. decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled,
  505. decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr,
  506. decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, (decodedInfo->bytePosFrameEnd - decodedInfo->bytePosFrameStart),
  507. decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo,
  508. decodedInfo->temporalId,
  509. decodedInfo->frameCycle, decodedInfo->decHostCmdTick,
  510. decodedInfo->decSeekStartTick, decodedInfo->decSeekEndTick, decodedInfo->seekCycle,
  511. decodedInfo->decParseStartTick, decodedInfo->decParseEndTick, decodedInfo->parseCycle,
  512. decodedInfo->decDecodeStartTick, decodedInfo->decDecodeEndTick, decodedInfo->DecodedCycle,
  513. queueStatus.reportQueueCount, queueStatus.instanceQueueCount,
  514. 0
  515. );
  516. }
  517. else {
  518. VLOG(logLevel, "%02d %5d %d %4d(%4d) %3d %2d(%2d) %2d(%2d) %08x %08x %08x %08x %08x %8d %4dx%-4d %4d %4d %8d(%8d,%8d,%8d) %d %d %d\n",
  519. handle->instIndex, frameNo, decodedInfo->picType,
  520. decodedInfo->decodedPOC, decodedInfo->displayPOC, decodedInfo->nalType,
  521. decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled,
  522. decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled,
  523. decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr,
  524. decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, (decodedInfo->bytePosFrameEnd - decodedInfo->bytePosFrameStart),
  525. decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo,
  526. decodedInfo->temporalId,
  527. decodedInfo->frameCycle, decodedInfo->seekCycle, decodedInfo->parseCycle, decodedInfo->DecodedCycle,
  528. queueStatus.reportQueueCount, queueStatus.instanceQueueCount,
  529. 0
  530. );
  531. }
  532. if (logLevel == ERR) {
  533. VLOG(ERR, "\t>>ERROR REASON: 0x%08x(0x%08x)\n", decodedInfo->errorReason, decodedInfo->errorReasonExt);
  534. }
  535. if (decodedInfo->numOfErrMBs) {
  536. VLOG(WARN, "\t>> ErrorBlock: %d\n", decodedInfo->numOfErrMBs);
  537. }
  538. }
  539. }
  540. void DisplayDecodedInformationForAVS2(
  541. DecHandle handle,
  542. Uint32 frameNo,
  543. BOOL performance,
  544. DecOutputInfo* decodedInfo
  545. )
  546. {
  547. Int32 logLevel;
  548. QueueStatusInfo queueStatus;
  549. VPU_DecGiveCommand(handle, DEC_GET_QUEUE_STATUS, &queueStatus);
  550. if (decodedInfo == NULL) {
  551. if ( performance == TRUE ) {
  552. VLOG(INFO, " | FRAME | HOST | SEEK_S SEEK_E SEEK | PARSE_S PARSE_E PARSE | DEC_S DEC_E DEC |\n");
  553. VLOG(INFO, "I NO T POC NAL DECO DISP DISPFLAG RD_PTR WR_PTR FRM_START FRM_END FRM_SIZE WxH SEQ TEMP | CYCLE | TICK | TICK TICK CYCLE | TICK TICK CYCLE | TICK TICK CYCLE | RQ IQ\n");
  554. } else {
  555. VLOG(INFO, "I NO T POC NAL DECO DISP DISPFLAG RD_PTR WR_PTR FRM_START FRM_END FRM_SIZE WxH SEQ TEMP CYCLE (Seek, Parse, Dec) RQ IQ\n");
  556. }
  557. VLOG(INFO, "------------------------------------------------------------------------------------------------------------\n");
  558. }
  559. else {
  560. logLevel = (decodedInfo->decodingSuccess&0x01) == 0 ? ERR : TRACE;
  561. // Print informations
  562. if (performance == TRUE) {
  563. VLOG(logLevel, "%02d %5d %d %4d(%4d) %3d %2d(%2d) %2d(%2d) %08x %08x %08x %08x %08x %8d %4dx%-4d %4d %4d %8d %8d (%6d,%6d,%8d) (%6d,%6d,%8d) (%6d,%6d,%8d) %d %d\n",
  564. handle->instIndex, frameNo, decodedInfo->picType,
  565. decodedInfo->avs2Info.decodedPOI, decodedInfo->avs2Info.displayPOI, decodedInfo->nalType,
  566. decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled,
  567. decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled,
  568. decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr,
  569. decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, (decodedInfo->bytePosFrameEnd - decodedInfo->bytePosFrameStart),
  570. decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo,
  571. decodedInfo->temporalId,
  572. decodedInfo->frameCycle, decodedInfo->decHostCmdTick,
  573. decodedInfo->decSeekStartTick, decodedInfo->decSeekEndTick, decodedInfo->seekCycle,
  574. decodedInfo->decParseStartTick, decodedInfo->decParseEndTick, decodedInfo->parseCycle,
  575. decodedInfo->decDecodeStartTick, decodedInfo->decDecodeEndTick, decodedInfo->DecodedCycle,
  576. queueStatus.reportQueueCount, queueStatus.instanceQueueCount);
  577. }
  578. else {
  579. VLOG(logLevel, "%02d %5d %d %4d(%4d) %3d %2d(%2d) %2d(%2d) %08x %08x %08x %08x %08x %8d %4dx%-4d %4d %4d %8d(%8d,%8d,%8d) %d %d\n",
  580. handle->instIndex, frameNo, decodedInfo->picType,
  581. decodedInfo->avs2Info.decodedPOI, decodedInfo->avs2Info.displayPOI, decodedInfo->nalType,
  582. decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled,
  583. decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled,
  584. decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr,
  585. decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, (decodedInfo->bytePosFrameEnd - decodedInfo->bytePosFrameStart),
  586. decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo,
  587. decodedInfo->temporalId,
  588. decodedInfo->frameCycle, decodedInfo->seekCycle, decodedInfo->parseCycle, decodedInfo->DecodedCycle,
  589. queueStatus.reportQueueCount, queueStatus.instanceQueueCount);
  590. }
  591. if (logLevel == ERR) {
  592. VLOG(ERR, "\t>>ERROR REASON: 0x%08x(0x%08x)\n", decodedInfo->errorReason, decodedInfo->errorReasonExt);
  593. }
  594. if (decodedInfo->numOfErrMBs) {
  595. VLOG(WARN, "\t>> ErrorBlock: %d\n", decodedInfo->numOfErrMBs);
  596. }
  597. }
  598. }
  599. void DisplayDecodedInformationForVP9(
  600. DecHandle handle,
  601. Uint32 frameNo,
  602. BOOL performance,
  603. DecOutputInfo* decodedInfo)
  604. {
  605. Int32 logLevel;
  606. QueueStatusInfo queueStatus;
  607. VPU_DecGiveCommand(handle, DEC_GET_QUEUE_STATUS, &queueStatus);
  608. if (decodedInfo == NULL) {
  609. // Print header
  610. if ( performance == TRUE ) {
  611. VLOG(INFO, " | FRAME | HOST | SEEK_S SEEK_E SEEK | PARSE_S PARSE_E PARSE | DEC_S DEC_E DEC |\n");
  612. VLOG(INFO, "I NO T DECO DISP DISPFLAG RD_PTR WR_PTR FRM_START FRM_END FRM_SIZE WxH SEQ | CYCLE | TICK | TICK TICK CYCLE | TICK TICK CYCLE | TICK TICK CYCLE | RQ IQ\n");
  613. }
  614. else {
  615. VLOG(INFO, "I NO T DECO DISP DISPFLAG RD_PTR WR_PTR FRM_START FRM_END FRM_SIZE WxH SEQ CYCLE (Seek, Parse, Dec) RQ IQ\n");
  616. }
  617. VLOG(INFO, "--------------------------------------------------------------------------------------------\n");
  618. }
  619. else {
  620. logLevel = (decodedInfo->decodingSuccess&0x01) == 0 ? ERR : TRACE;
  621. // Print informations
  622. if (performance == TRUE) {
  623. VLOG(logLevel, "%02d %5d %d %2d(%2d) %2d(%2d) %08x %08x %08x %08x %08x %8d %4dx%-4d %4d %8d %8d (%6d,%6d,%8d) (%6d,%6d,%8d) (%6d,%6d,%8d) %d %d\n",
  624. handle->instIndex, frameNo, decodedInfo->picType,
  625. decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled,
  626. decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled,
  627. decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr,
  628. decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, (decodedInfo->bytePosFrameEnd - decodedInfo->bytePosFrameStart),
  629. decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo,
  630. decodedInfo->frameCycle, decodedInfo->decHostCmdTick,
  631. decodedInfo->decSeekStartTick, decodedInfo->decSeekEndTick, decodedInfo->seekCycle,
  632. decodedInfo->decParseStartTick, decodedInfo->decParseEndTick, decodedInfo->parseCycle,
  633. decodedInfo->decDecodeStartTick, decodedInfo->decDecodeEndTick, decodedInfo->DecodedCycle,
  634. queueStatus.reportQueueCount, queueStatus.instanceQueueCount);
  635. }
  636. else {
  637. VLOG(logLevel, "%02d %5d %d %2d(%2d) %2d(%2d) %08x %08x %08x %08x %08x %8d %4dx%-4d %4d %8d (%8d,%8d,%8d) %d %d\n",
  638. handle->instIndex, frameNo, decodedInfo->picType,
  639. decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled,
  640. decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled,
  641. decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr,
  642. decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, (decodedInfo->bytePosFrameEnd - decodedInfo->bytePosFrameStart),
  643. decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo,
  644. decodedInfo->frameCycle, decodedInfo->seekCycle, decodedInfo->parseCycle, decodedInfo->DecodedCycle,
  645. queueStatus.reportQueueCount, queueStatus.instanceQueueCount);
  646. }
  647. if (logLevel == ERR) {
  648. VLOG(ERR, "\t>>ERROR REASON: 0x%08x(0x%08x)\n", decodedInfo->errorReason, decodedInfo->errorReasonExt);
  649. }
  650. if (decodedInfo->numOfErrMBs) {
  651. VLOG(WARN, "\t>> ErrorBlock: %d\n", decodedInfo->numOfErrMBs);
  652. }
  653. }
  654. }
  655. void DisplayDecodedInformationForAVC(
  656. DecHandle handle,
  657. Uint32 frameNo,
  658. BOOL performance,
  659. DecOutputInfo* decodedInfo)
  660. {
  661. Int32 logLevel;
  662. QueueStatusInfo queueStatus;
  663. VPU_DecGiveCommand(handle, DEC_GET_QUEUE_STATUS, &queueStatus);
  664. if (decodedInfo == NULL) {
  665. // Print header
  666. if ( performance == TRUE ) {
  667. VLOG(INFO, " | FRAME | HOST | SEEK_S SEEK_E SEEK | PARSE_S PARSE_E PARSE | DEC_S DEC_E DEC |\n");
  668. VLOG(INFO, "I NO T POC NAL DECO DISP DISPFLAG RD_PTR WR_PTR FRM_START FRM_END FRM_SIZE WxH SEQ TEMP | CYCLE | TICK | TICK TICK CYCLE | TICK TICK CYCLE | TICK TICK CYCLE | RQ IQ VCore\n");
  669. }
  670. else {
  671. VLOG(INFO, "I NO T POC NAL DECO DISP DISPFLAG RD_PTR WR_PTR FRM_START FRM_END FRM_SIZE WxH SEQ TEMP CYCLE ( Seek, Parse, Dec) RQ IQ VCore\n");
  672. }
  673. VLOG(INFO, "-----------------------------------------------------------------------------------------------------------------------------------------------\n");
  674. }
  675. else {
  676. logLevel = (decodedInfo->decodingSuccess&0x01) == 0 ? ERR : INFO;
  677. // Print informations
  678. if (performance == TRUE) {
  679. VLOG(logLevel, "%02d %5d %d %4d(%4d) %3d %2d(%2d) %2d(%2d) %08x %08x %08x %08x %08x %8d %4dx%-4d %4d %4d %8d %8d (%6d,%6d,%8d) (%6d,%6d,%8d) (%6d,%6d,%8d) %d %d %d\n",
  680. handle->instIndex, frameNo, decodedInfo->picType, decodedInfo->decodedPOC, decodedInfo->displayPOC, decodedInfo->nalType,
  681. decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled,
  682. decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled,
  683. decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr,
  684. decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, (decodedInfo->bytePosFrameEnd - decodedInfo->bytePosFrameStart),
  685. decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo, decodedInfo->temporalId,
  686. decodedInfo->frameCycle, decodedInfo->decHostCmdTick,
  687. decodedInfo->decSeekStartTick, decodedInfo->decSeekEndTick, decodedInfo->seekCycle,
  688. decodedInfo->decParseStartTick, decodedInfo->decParseEndTick, decodedInfo->parseCycle,
  689. decodedInfo->decDecodeStartTick, decodedInfo->decDecodeEndTick, decodedInfo->DecodedCycle,
  690. queueStatus.reportQueueCount, queueStatus.instanceQueueCount,
  691. 0
  692. );
  693. }
  694. else {
  695. VLOG(logLevel, "%02d %5d %d %4d(%4d) %3d %2d(%2d) %2d(%2d) %08x %08x %08x %08x %08x %8d %4dx%-4d %4d %4d %8d(%8d,%8d,%8d) %d %d\n",
  696. handle->instIndex, frameNo, decodedInfo->picType, decodedInfo->decodedPOC, decodedInfo->displayPOC, decodedInfo->nalType,
  697. decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled,
  698. decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled,
  699. decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr,
  700. decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, (decodedInfo->bytePosFrameEnd - decodedInfo->bytePosFrameStart),
  701. decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo, decodedInfo->temporalId,
  702. decodedInfo->frameCycle, decodedInfo->seekCycle, decodedInfo->parseCycle, decodedInfo->DecodedCycle,
  703. queueStatus.reportQueueCount, queueStatus.instanceQueueCount,
  704. 0
  705. );
  706. }
  707. if (logLevel == ERR) {
  708. VLOG(ERR, "\t>>ERROR REASON: 0x%08x(0x%08x)\n", decodedInfo->errorReason, decodedInfo->errorReasonExt);
  709. }
  710. if (decodedInfo->numOfErrMBs) {
  711. VLOG(WARN, "\t>> ErrorBlock: %d\n", decodedInfo->numOfErrMBs);
  712. }
  713. }
  714. }
  715. void DisplayDecodedInformationForAV1(
  716. DecHandle handle,
  717. Uint32 frameNo,
  718. BOOL performance,
  719. DecOutputInfo* decodedInfo)
  720. {
  721. Int32 logLevel;
  722. QueueStatusInfo queueStatus;
  723. VPU_DecGiveCommand(handle, DEC_GET_QUEUE_STATUS, &queueStatus);
  724. if (decodedInfo == NULL) {
  725. // Print header
  726. if ( performance == TRUE ) {
  727. VLOG(INFO, " | FRAME | HOST | SEEK_S SEEK_E SEEK | PARSE_S PARSE_E PARSE | DEC_S DEC_E DEC |\n");
  728. VLOG(INFO, "I NO T DECO DISP DISPFLAG RD_PTR WR_PTR FRM_START FRM_END FRM_SIZE WxH SEQ | CYCLE | TICK | TICK TICK CYCLE | TICK TICK CYCLE | TICK TICK CYCLE | RQ IQ\n");
  729. }
  730. else {
  731. VLOG(INFO, "I NO T DECO DISP DISPFLAG RD_PTR WR_PTR FRM_START FRM_END FRM_SIZE WxH SEQ CYCLE (Seek, Parse, Dec) RQ IQ\n");
  732. }
  733. VLOG(INFO, "--------------------------------------------------------------------------------------------\n");
  734. }
  735. else {
  736. logLevel = (decodedInfo->decodingSuccess&0x01) == 0 ? ERR : TRACE;
  737. // Print informations
  738. if (performance == TRUE) {
  739. VLOG(logLevel, "%02d %5d %d %2d(%2d) %2d(%2d) %08x %08x %08x %08x %08x %8d %4dx%-4d %4d %8d %8d (%6d,%6d,%8d) (%6d,%6d,%8d) (%6d,%6d,%8d) %d %d\n",
  740. handle->instIndex, frameNo, decodedInfo->picType,
  741. decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled,
  742. decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled,
  743. decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr,
  744. decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, (decodedInfo->bytePosFrameEnd - decodedInfo->bytePosFrameStart),
  745. decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo,
  746. decodedInfo->frameCycle, decodedInfo->decHostCmdTick,
  747. decodedInfo->decSeekStartTick, decodedInfo->decSeekEndTick, decodedInfo->seekCycle,
  748. decodedInfo->decParseStartTick, decodedInfo->decParseEndTick, decodedInfo->parseCycle,
  749. decodedInfo->decDecodeStartTick, decodedInfo->decDecodeEndTick, decodedInfo->DecodedCycle,
  750. queueStatus.reportQueueCount, queueStatus.instanceQueueCount);
  751. }
  752. else {
  753. VLOG(logLevel, "%02d %5d %d %2d(%2d) %2d(%2d) %08x %08x %08x %08x %08x %8d %4dx%-4d %4d %8d (%8d,%8d,%8d) %d %d\n",
  754. handle->instIndex, frameNo, decodedInfo->picType,
  755. decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled,
  756. decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled,
  757. decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr,
  758. decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, (decodedInfo->bytePosFrameEnd - decodedInfo->bytePosFrameStart),
  759. decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo,
  760. decodedInfo->frameCycle, decodedInfo->seekCycle, decodedInfo->parseCycle, decodedInfo->DecodedCycle,
  761. queueStatus.reportQueueCount, queueStatus.instanceQueueCount);
  762. }
  763. if (logLevel == ERR) {
  764. VLOG(ERR, "\t>>ERROR REASON: 0x%08x(0x%08x)\n", decodedInfo->errorReason, decodedInfo->errorReasonExt);
  765. }
  766. if (decodedInfo->numOfErrMBs) {
  767. VLOG(WARN, "\t>> ErrorBlock: %d\n", decodedInfo->numOfErrMBs);
  768. }
  769. }
  770. }
  771. void DisplayDecodedInformationCommon(
  772. DecHandle handle,
  773. Uint32 frameNo,
  774. DecOutputInfo* decodedInfo)
  775. {
  776. Int32 logLevel;
  777. if (decodedInfo == NULL) {
  778. // Print header
  779. VLOG(TRACE, "I NO T DECO DISP DISPFLAG RD_PTR WR_PTR FRM_START FRM_END FRM_SIZE WxH \n");
  780. VLOG(TRACE, "---------------------------------------------------------------------------\n");
  781. }
  782. else {
  783. VpuRect rc = decodedInfo->rcDisplay;
  784. Uint32 width = rc.right - rc.left;
  785. Uint32 height = rc.bottom - rc.top;
  786. logLevel = (decodedInfo->decodingSuccess&0x01) == 0 ? WARN : INFO;
  787. // Print informations
  788. VLOG(logLevel, "%02d %5d %d %2d(%2d) %2d(%2d) %08x %08x %08x %08x %08x %8d %dx%d\n",
  789. handle->instIndex, frameNo, decodedInfo->picType,
  790. decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled,
  791. decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled,
  792. decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr,
  793. decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, (decodedInfo->bytePosFrameEnd - decodedInfo->bytePosFrameStart),
  794. width, height);
  795. if (logLevel == ERR) {
  796. VLOG(ERR, "\t>>ERROR REASON: 0x%08x(0x%08x)\n", decodedInfo->errorReason, decodedInfo->errorReasonExt);
  797. }
  798. if (decodedInfo->numOfErrMBs) {
  799. VLOG(WARN, "\t>> ErrorBlock: %d\n", decodedInfo->numOfErrMBs);
  800. }
  801. }
  802. }
  803. /**
  804. * \brief Print out decoded information such like RD_PTR, WR_PTR, PIC_TYPE, ..
  805. * \param decodedInfo If this parameter is not NULL then print out decoded informations
  806. * otherwise print out header.
  807. */
  808. void
  809. DisplayDecodedInformation(
  810. DecHandle handle,
  811. CodStd codec,
  812. Uint32 frameNo,
  813. DecOutputInfo* decodedInfo,
  814. ...
  815. )
  816. {
  817. int performance = FALSE;
  818. va_list ap;
  819. va_start(ap, decodedInfo);
  820. performance = va_arg(ap, Uint32);
  821. va_end(ap);
  822. switch (codec)
  823. {
  824. case STD_HEVC:
  825. DisplayDecodedInformationForHevc(handle, frameNo, performance, decodedInfo);
  826. break;
  827. case STD_VP9:
  828. DisplayDecodedInformationForVP9(handle, frameNo, performance, decodedInfo);
  829. break;
  830. case STD_AVS2:
  831. DisplayDecodedInformationForAVS2(handle, frameNo, performance, decodedInfo);
  832. break;
  833. case STD_AVC:
  834. DisplayDecodedInformationForAVC(handle, frameNo, performance, decodedInfo);
  835. break;
  836. case STD_AV1:
  837. DisplayDecodedInformationForAV1(handle, frameNo, performance, decodedInfo);
  838. break;
  839. default:
  840. DisplayDecodedInformationCommon(handle, frameNo, decodedInfo);
  841. break;
  842. }
  843. return;
  844. }
  845. void SetDefaultEncTestConfig(TestEncConfig* testConfig) {
  846. osal_memset(testConfig, 0, sizeof(TestEncConfig));
  847. testConfig->stdMode = STD_HEVC;
  848. testConfig->frame_endian = VPU_FRAME_ENDIAN;
  849. testConfig->stream_endian = VPU_STREAM_ENDIAN;
  850. testConfig->source_endian = VPU_SOURCE_ENDIAN;
  851. testConfig->mapType = COMPRESSED_FRAME_MAP;
  852. testConfig->lineBufIntEn = TRUE;
  853. #ifdef SUPPORT_SOURCE_RELEASE_INTERRUPT
  854. testConfig->srcReleaseIntEnable = FALSE;
  855. #endif
  856. testConfig->ringBufferEnable = FALSE;
  857. testConfig->ringBufferWrapEnable = FALSE;
  858. }
  859. void Coda9SetDefaultEncTestConfig(TestEncConfig* encConfig) {
  860. osal_memset(encConfig, 0, sizeof(TestEncConfig));
  861. encConfig->stdMode = STD_AVC;
  862. encConfig->frame_endian = VPU_FRAME_ENDIAN;
  863. encConfig->stream_endian = VPU_STREAM_ENDIAN;
  864. encConfig->source_endian = VPU_SOURCE_ENDIAN;
  865. encConfig->mapType = LINEAR_FRAME_MAP;
  866. encConfig->ringBufferEnable = FALSE;
  867. encConfig->yuv_mode = SOURCE_YUV;
  868. }
  869. static void Wave5DisplayEncodedInformation(
  870. EncHandle handle,
  871. CodStd codec,
  872. Uint32 frameNo,
  873. EncOutputInfo* encodedInfo,
  874. Int32 srcEndFlag,
  875. Int32 srcFrameIdx,
  876. Int32 performance
  877. )
  878. {
  879. QueueStatusInfo queueStatus;
  880. VPU_EncGiveCommand(handle, ENC_GET_QUEUE_STATUS, &queueStatus);
  881. if (encodedInfo == NULL) {
  882. if (performance == TRUE ) {
  883. VLOG(INFO, "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n");
  884. VLOG(INFO, " USEDSRC | FRAME | HOST | PREP_S PREP_E PREP | PROCE_S PROCE_E PROCE | ENC_S ENC_E ENC |\n");
  885. VLOG(INFO, "I NO T RECON RD_PTR WR_PTR BYTES SRCIDX IDX IDC Vcore | CYCLE | TICK | TICK TICK CYCLE | TICK TICK CYCLE | TICK TICK CYCLE | RQ IQ\n");
  886. VLOG(INFO, "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n");
  887. }
  888. else {
  889. VLOG(INFO, "---------------------------------------------------------------------------------------------------------------------------\n");
  890. VLOG(INFO, " USEDSRC | CYCLE\n");
  891. VLOG(INFO, "I NO T RECON RD_PTR WR_PTR BYTES SRCIDX IDX IDC Vcore | FRAME PREPARING PROCESSING ENCODING | RQ IQ\n");
  892. VLOG(INFO, "---------------------------------------------------------------------------------------------------------------------------\n");
  893. }
  894. } else {
  895. if (performance == TRUE) {
  896. VLOG(INFO, "%02d %5d %5d %5d %08x %08x %8x %2d %2d %08x %2d %8u %8u (%8u,%8u,%8u) (%8u,%8u,%8u) (%8u,%8u,%8u) %d %d\n",
  897. handle->instIndex, encodedInfo->encPicCnt, encodedInfo->picType, encodedInfo->reconFrameIndex, encodedInfo->rdPtr, encodedInfo->wrPtr,
  898. encodedInfo->bitstreamSize, (srcEndFlag == 1 ? -1 : srcFrameIdx), encodedInfo->encSrcIdx,
  899. encodedInfo->releaseSrcFlag,
  900. 0,
  901. encodedInfo->frameCycle, encodedInfo->encHostCmdTick,
  902. encodedInfo->encPrepareStartTick, encodedInfo->encPrepareEndTick, encodedInfo->prepareCycle,
  903. encodedInfo->encProcessingStartTick, encodedInfo->encProcessingEndTick, encodedInfo->processing,
  904. encodedInfo->encEncodeStartTick, encodedInfo->encEncodeEndTick, encodedInfo->EncodedCycle,
  905. queueStatus.reportQueueCount, queueStatus.instanceQueueCount);
  906. }
  907. else {
  908. VLOG(INFO, "%02d %5d %5d %5d %08x %08x %8x %2d %2d %04x %d %8d %8d %8d %8d %d %d\n",
  909. handle->instIndex, encodedInfo->encPicCnt, encodedInfo->picType, encodedInfo->reconFrameIndex, encodedInfo->rdPtr, encodedInfo->wrPtr,
  910. encodedInfo->bitstreamSize, (srcEndFlag == 1 ? -1 : srcFrameIdx), encodedInfo->encSrcIdx,
  911. encodedInfo->releaseSrcFlag,
  912. 0,
  913. encodedInfo->frameCycle, encodedInfo->prepareCycle, encodedInfo->processing, encodedInfo->EncodedCycle,
  914. queueStatus.reportQueueCount, queueStatus.instanceQueueCount);
  915. }
  916. }
  917. }
  918. static void Coda9DisplayEncodedInformation(
  919. DecHandle handle,
  920. CodStd codec,
  921. Uint32 frameNo,
  922. EncOutputInfo* encodedInfo
  923. )
  924. {
  925. if (encodedInfo == NULL) {
  926. // Print header
  927. VLOG(INFO, "I NO T RECON RD_PTR WR_PTR \n");
  928. VLOG(INFO, "-------------------------------------\n");
  929. }
  930. else {
  931. char** picTypeArray = (codec==STD_AVC ? EncPicTypeStringH264 : EncPicTypeStringMPEG4);
  932. char* strPicType;
  933. if (encodedInfo->picType > 2) strPicType = "?";
  934. else strPicType = picTypeArray[encodedInfo->picType];
  935. // Print informations
  936. VLOG(INFO, "%02d %5d %5s %5d %08x %08x\n",
  937. handle->instIndex, frameNo, strPicType,
  938. encodedInfo->reconFrameIndex, encodedInfo->rdPtr, encodedInfo->wrPtr);
  939. }
  940. }
  941. /*lint -esym(438, ap) */
  942. void
  943. DisplayEncodedInformation(
  944. EncHandle handle,
  945. CodStd codec,
  946. Uint32 frameNo,
  947. EncOutputInfo* encodedInfo,
  948. ...
  949. )
  950. {
  951. int srcEndFlag;
  952. int srcFrameIdx;
  953. int performance = FALSE;
  954. va_list ap;
  955. switch (codec) {
  956. case STD_HEVC:
  957. va_start(ap, encodedInfo);
  958. srcEndFlag = va_arg(ap, Uint32);
  959. srcFrameIdx = va_arg(ap, Uint32);
  960. performance = va_arg(ap, Uint32);
  961. va_end(ap);
  962. Wave5DisplayEncodedInformation(handle, codec, frameNo, encodedInfo, srcEndFlag , srcFrameIdx, performance);
  963. break;
  964. case STD_AVC:
  965. if(handle->productId == PRODUCT_ID_521) {
  966. va_start(ap, encodedInfo);
  967. srcEndFlag = va_arg(ap, Uint32);
  968. srcFrameIdx = va_arg(ap, Uint32);
  969. performance = va_arg(ap, Uint32);
  970. va_end(ap);
  971. Wave5DisplayEncodedInformation(handle, codec, frameNo, encodedInfo, srcEndFlag , srcFrameIdx, performance);
  972. }
  973. else
  974. Coda9DisplayEncodedInformation(handle, codec, frameNo, encodedInfo);
  975. break;
  976. default:
  977. Coda9DisplayEncodedInformation(handle, codec, frameNo, encodedInfo);
  978. break;
  979. }
  980. return;
  981. }
  982. /*lint +esym(438, ap) */
  983. void replace_character(char* str,
  984. char c,
  985. char r)
  986. {
  987. int i=0;
  988. int len;
  989. len = strlen(str);
  990. for(i=0; i<len; i++)
  991. {
  992. if (str[i] == c)
  993. str[i] = r;
  994. }
  995. }
  996. void ChangePathStyle(
  997. char *str
  998. )
  999. {
  1000. }
  1001. void ReleaseVideoMemory(
  1002. DecHandle handle,
  1003. vpu_buffer_t* memoryArr,
  1004. Uint32 count
  1005. )
  1006. {
  1007. Int32 coreIndex = handle->coreIdx;
  1008. Uint32 idx;
  1009. for (idx=0; idx<count; idx++) {
  1010. if (memoryArr[idx].size)
  1011. vdi_free_dma_memory(coreIndex, &memoryArr[idx], DEC_FBC, handle->instIndex);
  1012. }
  1013. }
  1014. BOOL AllocateLinerBuffer(
  1015. DecHandle decHandle,
  1016. vpu_buffer_t *pvb,
  1017. Uint32 size
  1018. )
  1019. {
  1020. Uint32 coreIndex = VPU_HANDLE_CORE_INDEX(decHandle);
  1021. if (vdi_allocate_dma_memory(coreIndex, pvb, DEC_FB_LINEAR, decHandle->instIndex) < 0) {
  1022. VLOG(ERR, "%s:%d fail to allocate frame buffer\n", __FUNCTION__, __LINE__);
  1023. return FALSE;
  1024. }
  1025. return TRUE;
  1026. }
  1027. FrameBufferAllocInfo frameBufferAllocInfo;
  1028. void *AllocateDecFrameBuffer2(DecHandle decHandle, TestDecConfig* config, Uint32 size, FrameBuffer* retFbArray, vpu_buffer_t* retFbAddrs)
  1029. {
  1030. RetCode ret;
  1031. vpu_buffer_t *vb = retFbAddrs;
  1032. Uint32 coreIndex = VPU_HANDLE_CORE_INDEX(decHandle);
  1033. vb->size = size;
  1034. frameBufferAllocInfo.num = 1;
  1035. vdi_allocate_dma_memory(coreIndex, vb, DEC_FB_LINEAR, decHandle->instIndex);
  1036. VLOG(INFO, "base = %lx virt_addr = %lx phys_addr = %lx\r\n", vb->base, vb->virt_addr, vb->phys_addr);
  1037. retFbArray->bufY = vb->phys_addr;
  1038. retFbArray->bufCb = (PhysicalAddress)-1;
  1039. retFbArray->bufCr = (PhysicalAddress)-1;
  1040. retFbArray->updateFbInfo = TRUE;
  1041. retFbArray->size = size;
  1042. // width = 0 not effect right now
  1043. retFbArray->width = 0;
  1044. ret = VPU_DecAllocateFrameBuffer(decHandle, frameBufferAllocInfo, retFbArray);
  1045. if (ret != RETCODE_SUCCESS) {
  1046. VLOG(ERR, "%s:%d failed to VPU_DecAllocateFrameBuffer() ret:%d\n",
  1047. __FUNCTION__, __LINE__, ret);
  1048. ReleaseVideoMemory(decHandle, vb, 1);
  1049. return NULL;
  1050. }
  1051. return (void *)vb->virt_addr;
  1052. }
  1053. BOOL AttachDecDMABuffer(DecHandle decHandle, TestDecConfig* config, Uint64 virtAddress, Uint32 size, FrameBuffer* retFbArray, vpu_buffer_t* retFbAddrs)
  1054. {
  1055. RetCode ret;
  1056. Uint32 coreIndex = VPU_HANDLE_CORE_INDEX(decHandle);
  1057. vpu_buffer_t *vb = retFbAddrs;
  1058. vb->virt_addr = virtAddress;
  1059. vb->size = size;
  1060. frameBufferAllocInfo.num = 1;
  1061. vdi_virt_to_phys(coreIndex, vb);
  1062. vdi_attach_dma_memory(coreIndex, vb);
  1063. VLOG(INFO, "base addr = %lx virt addr= %lx phys addr = %x\r\n", vb->base, vb->virt_addr, vb->phys_addr);
  1064. retFbArray->bufY = vb->phys_addr;
  1065. retFbArray->bufCb = (PhysicalAddress)-1;
  1066. retFbArray->bufCr = (PhysicalAddress)-1;
  1067. retFbArray->updateFbInfo = TRUE;
  1068. retFbArray->size = size;
  1069. // width = 0 not effect right now
  1070. retFbArray->width = 0;
  1071. ret = VPU_DecAllocateFrameBuffer(decHandle, frameBufferAllocInfo, retFbArray);
  1072. if (ret != RETCODE_SUCCESS) {
  1073. VLOG(ERR, "%s:%d failed to VPU_DecAllocateFrameBuffer() ret:%d\n",
  1074. __FUNCTION__, __LINE__, ret);
  1075. ReleaseVideoMemory(decHandle, vb, 1);
  1076. return FALSE;
  1077. }
  1078. return TRUE;
  1079. }
  1080. BOOL AllocateDecFrameBuffer(
  1081. DecHandle decHandle,
  1082. TestDecConfig* config,
  1083. Uint32 nonLinearFbCnt,
  1084. Uint32 linearFbCount,
  1085. FrameBuffer* retFbArray,
  1086. vpu_buffer_t* retFbAddrs,
  1087. Uint32* retStride
  1088. )
  1089. {
  1090. Uint32 framebufSize;
  1091. Uint32 totalFbCount, linearFbStartIdx = 0;
  1092. Uint32 coreIndex;
  1093. Uint32 idx;
  1094. FrameBufferFormat format = config->wtlFormat;
  1095. DecInitialInfo seqInfo;
  1096. FrameBufferAllocInfo fbAllocInfo;
  1097. RetCode ret;
  1098. vpu_buffer_t* pvb;
  1099. size_t framebufStride;
  1100. size_t framebufHeight;
  1101. Uint32 productId;
  1102. DRAMConfig* pDramCfg = NULL;
  1103. DRAMConfig dramCfg = {0};
  1104. DecInfo* pDecInfo = &decHandle->CodecInfo->decInfo;
  1105. coreIndex = VPU_HANDLE_CORE_INDEX(decHandle);
  1106. productId = VPU_HANDLE_PRODUCT_ID(decHandle);
  1107. VPU_DecGiveCommand(decHandle, DEC_GET_SEQ_INFO, (void*)&seqInfo);
  1108. if (pDecInfo->productCode == WAVE521C_DUAL_CODE) {
  1109. if ( seqInfo.lumaBitdepth == 8 && seqInfo.chromaBitdepth == 8) {
  1110. config->mapType = COMPRESSED_FRAME_MAP_DUAL_CORE_8BIT;
  1111. }
  1112. else {
  1113. config->mapType = COMPRESSED_FRAME_MAP_DUAL_CORE_10BIT;
  1114. }
  1115. }
  1116. totalFbCount = nonLinearFbCnt + linearFbCount;
  1117. if (PRODUCT_ID_W_SERIES(productId)) {
  1118. linearFbStartIdx = nonLinearFbCnt;
  1119. }
  1120. else { //CODA series
  1121. if (0 == nonLinearFbCnt) {
  1122. nonLinearFbCnt = linearFbCount;
  1123. linearFbCount = 0;
  1124. }
  1125. else {
  1126. linearFbStartIdx = nonLinearFbCnt;
  1127. }
  1128. }
  1129. if (PRODUCT_ID_W_SERIES(productId)) {
  1130. format = (seqInfo.lumaBitdepth > 8 || seqInfo.chromaBitdepth > 8) ? FORMAT_420_P10_16BIT_LSB : FORMAT_420;
  1131. }
  1132. else { //CODA series
  1133. pDramCfg = &dramCfg;
  1134. ret = VPU_DecGiveCommand(decHandle, GET_DRAM_CONFIG, pDramCfg);
  1135. if (RETCODE_SUCCESS != ret) {
  1136. VLOG(ERR, "%s:%d VPU_DecGiveCommand[GET_DRAM_CONFIG] failed Error code is 0x%x \n", __FUNCTION__, __LINE__, ret );
  1137. return FALSE;
  1138. }
  1139. }
  1140. #ifdef USE_FEEDING_METHOD_BUFFER
  1141. *retStride = seqInfo.picWidth;
  1142. framebufStride = CalcStride(seqInfo.picWidth, seqInfo.picHeight, format, config->cbcrInterleave, config->mapType, FALSE);
  1143. framebufHeight = seqInfo.picHeight;
  1144. framebufSize = VPU_GetFrameBufSize(decHandle, decHandle->coreIdx, framebufStride, framebufHeight,
  1145. config->mapType, format, config->cbcrInterleave, pDramCfg);
  1146. #else
  1147. if (config->bitFormat == STD_VP9) {
  1148. framebufStride = CalcStride(VPU_ALIGN64(seqInfo.picWidth), seqInfo.picHeight, format, config->cbcrInterleave, config->mapType, TRUE);
  1149. framebufHeight = VPU_ALIGN64(seqInfo.picHeight);
  1150. framebufSize = VPU_GetFrameBufSize(decHandle, decHandle->coreIdx, framebufStride, framebufHeight,
  1151. config->mapType, format, config->cbcrInterleave, NULL);
  1152. *retStride = framebufStride;
  1153. }
  1154. else if (config->bitFormat == STD_AVS2) {
  1155. framebufStride = CalcStride(seqInfo.picWidth, seqInfo.picHeight, format, config->cbcrInterleave, config->mapType, FALSE);
  1156. framebufHeight = VPU_ALIGN8(seqInfo.picHeight);
  1157. framebufSize = VPU_GetFrameBufSize(decHandle, decHandle->coreIdx, framebufStride, framebufHeight,
  1158. config->mapType, format, config->cbcrInterleave, pDramCfg);
  1159. *retStride = framebufStride;
  1160. }
  1161. else if (config->bitFormat == STD_AV1){
  1162. framebufStride = CalcStride(VPU_ALIGN64(seqInfo.picWidth), seqInfo.picHeight, format, config->cbcrInterleave, config->mapType, TRUE);
  1163. framebufHeight = VPU_ALIGN64(seqInfo.picHeight);
  1164. framebufSize = VPU_GetFrameBufSize(decHandle, decHandle->coreIdx, framebufStride, framebufHeight,
  1165. config->mapType, format, config->cbcrInterleave, NULL);
  1166. *retStride = framebufStride;
  1167. }
  1168. else {
  1169. *retStride = VPU_ALIGN32(seqInfo.picWidth);
  1170. framebufStride = CalcStride(seqInfo.picWidth, seqInfo.picHeight, format, config->cbcrInterleave, config->mapType, FALSE);
  1171. framebufHeight = VPU_ALIGN32(seqInfo.picHeight);
  1172. framebufSize = VPU_GetFrameBufSize(decHandle, decHandle->coreIdx, framebufStride, framebufHeight,
  1173. config->mapType, format, config->cbcrInterleave, pDramCfg);
  1174. }
  1175. #endif
  1176. osal_memset((void*)&fbAllocInfo, 0x00, sizeof(fbAllocInfo));
  1177. osal_memset((void*)retFbArray, 0x00, sizeof(FrameBuffer)*totalFbCount);
  1178. fbAllocInfo.format = format;
  1179. fbAllocInfo.cbcrInterleave = config->cbcrInterleave;
  1180. fbAllocInfo.mapType = config->mapType;
  1181. fbAllocInfo.stride = framebufStride;
  1182. fbAllocInfo.height = framebufHeight;
  1183. fbAllocInfo.size = framebufSize;
  1184. fbAllocInfo.lumaBitDepth = seqInfo.lumaBitdepth;
  1185. fbAllocInfo.chromaBitDepth = seqInfo.chromaBitdepth;
  1186. fbAllocInfo.num = nonLinearFbCnt;
  1187. fbAllocInfo.endian = PRODUCT_ID_NOT_W_SERIES(productId) ? config->frameEndian : VDI_128BIT_LITTLE_ENDIAN ; // FBC endian is not fixed.
  1188. fbAllocInfo.type = FB_TYPE_CODEC;
  1189. osal_memset((void*)retFbAddrs, 0x00, sizeof(vpu_buffer_t)*totalFbCount);
  1190. APIDPRINT("ALLOC MEM - FBC data\n");
  1191. for (idx=0; idx<nonLinearFbCnt; idx++) {
  1192. pvb = &retFbAddrs[idx];
  1193. pvb->size = framebufSize;
  1194. if (vdi_allocate_dma_memory(coreIndex, pvb, DEC_FBC, decHandle->instIndex) < 0) {
  1195. VLOG(ERR, "%s:%d fail to allocate frame buffer\n", __FUNCTION__, __LINE__);
  1196. ReleaseVideoMemory(decHandle, retFbAddrs, totalFbCount);
  1197. return FALSE;
  1198. }
  1199. retFbArray[idx].bufY = pvb->phys_addr;
  1200. retFbArray[idx].bufCb = (PhysicalAddress)-1;
  1201. retFbArray[idx].bufCr = (PhysicalAddress)-1;
  1202. retFbArray[idx].updateFbInfo = TRUE;
  1203. retFbArray[idx].size = framebufSize;
  1204. retFbArray[idx].width = seqInfo.picWidth;
  1205. }
  1206. if (nonLinearFbCnt != 0) {
  1207. if ((ret=VPU_DecAllocateFrameBuffer(decHandle, fbAllocInfo, retFbArray)) != RETCODE_SUCCESS) {
  1208. VLOG(ERR, "%s:%d failed to VPU_DecAllocateFrameBuffer(), ret(%d)\n",
  1209. __FUNCTION__, __LINE__, ret);
  1210. ReleaseVideoMemory(decHandle, retFbAddrs, totalFbCount);
  1211. return FALSE;
  1212. }
  1213. }
  1214. if (config->enableWTL == TRUE || linearFbCount != 0) {
  1215. size_t linearStride;
  1216. size_t picWidth;
  1217. size_t picHeight;
  1218. size_t fbHeight;
  1219. TiledMapType mapType = LINEAR_FRAME_MAP;
  1220. FrameBufferFormat outFormat = config->wtlFormat;
  1221. picWidth = seqInfo.picWidth;
  1222. picHeight = seqInfo.picHeight;
  1223. fbHeight = picHeight;
  1224. if (PRODUCT_ID_960 == productId || PRODUCT_ID_980 == productId) {
  1225. //wtl frame buffer
  1226. mapType = (FF_FRAME == config->wtlMode) ? LINEAR_FRAME_MAP : LINEAR_FIELD_MAP;
  1227. }
  1228. if (config->bitFormat == STD_VP9) {
  1229. fbHeight = VPU_ALIGN64(picHeight);
  1230. }
  1231. else if (config->bitFormat == STD_AVS2) {
  1232. fbHeight = VPU_ALIGN8(picHeight);
  1233. }
  1234. else if (productId == PRODUCT_ID_960 || productId == PRODUCT_ID_980)
  1235. {
  1236. fbHeight = VPU_ALIGN32(picHeight);
  1237. }
  1238. else if (config->bitFormat == STD_AV1)
  1239. {
  1240. fbHeight = VPU_ALIGN8(picHeight);
  1241. }
  1242. if (config->scaleDownWidth > 0 || config->scaleDownHeight > 0) {
  1243. ScalerInfo sclInfo;
  1244. VPU_DecGiveCommand(decHandle, DEC_GET_SCALER_INFO, (void*)&sclInfo);
  1245. if (sclInfo.enScaler == TRUE) {
  1246. picWidth = sclInfo.scaleWidth;
  1247. picHeight = sclInfo.scaleHeight;
  1248. if (config->bitFormat == STD_VP9) {
  1249. fbHeight = VPU_ALIGN64(picHeight);
  1250. }
  1251. else {
  1252. fbHeight = VPU_CEIL(picHeight, 2);
  1253. }
  1254. }
  1255. }
  1256. if (config->bitFormat == STD_VP9) {
  1257. linearStride = CalcStride(VPU_ALIGN64(picWidth), picHeight, outFormat, config->cbcrInterleave, (TiledMapType)mapType, TRUE);
  1258. }
  1259. else if (config->bitFormat == STD_AV1) {
  1260. linearStride = CalcStride(VPU_ALIGN16(picWidth), picHeight, outFormat, config->cbcrInterleave, (TiledMapType)mapType, TRUE);
  1261. }
  1262. else {
  1263. linearStride = CalcStride(picWidth, picHeight, outFormat, config->cbcrInterleave, (TiledMapType)mapType, FALSE);
  1264. }
  1265. framebufSize = VPU_GetFrameBufSize(decHandle, coreIndex, linearStride, fbHeight, (TiledMapType)mapType, outFormat, config->cbcrInterleave, pDramCfg);
  1266. fbAllocInfo.nv21 = config->nv21;
  1267. fbAllocInfo.format = outFormat;
  1268. fbAllocInfo.num = linearFbCount;
  1269. fbAllocInfo.mapType = (TiledMapType)mapType;
  1270. fbAllocInfo.stride = linearStride;
  1271. fbAllocInfo.height = fbHeight;
  1272. #ifdef USE_FEEDING_METHOD_BUFFER
  1273. memcpy(&frameBufferAllocInfo, &fbAllocInfo, sizeof(frameBufferAllocInfo));
  1274. #endif
  1275. for (idx=linearFbStartIdx; idx<totalFbCount; idx++) {
  1276. pvb = &retFbAddrs[idx];
  1277. pvb->size = framebufSize;
  1278. if (vdi_allocate_dma_memory(coreIndex, pvb, DEC_FB_LINEAR, decHandle->instIndex) < 0) {
  1279. VLOG(ERR, "%s:%d fail to allocate frame buffer\n", __FUNCTION__, __LINE__);
  1280. ReleaseVideoMemory(decHandle, retFbAddrs, totalFbCount);
  1281. return FALSE;
  1282. }
  1283. retFbArray[idx].bufY = pvb->phys_addr;
  1284. retFbArray[idx].bufCb = (PhysicalAddress)-1;
  1285. retFbArray[idx].bufCr = (PhysicalAddress)-1;
  1286. retFbArray[idx].updateFbInfo = TRUE;
  1287. retFbArray[idx].size = framebufSize;
  1288. retFbArray[idx].width = picWidth;
  1289. }
  1290. ret = VPU_DecAllocateFrameBuffer(decHandle, fbAllocInfo, &retFbArray[linearFbStartIdx]);
  1291. if (ret != RETCODE_SUCCESS) {
  1292. VLOG(ERR, "%s:%d failed to VPU_DecAllocateFrameBuffer() ret:%d\n",
  1293. __FUNCTION__, __LINE__, ret);
  1294. ReleaseVideoMemory(decHandle, retFbAddrs, totalFbCount);
  1295. return FALSE;
  1296. }
  1297. }
  1298. return TRUE;
  1299. }
  1300. BOOL AllocFBMemory(Uint32 coreIdx, vpu_buffer_t *pFbMem, FrameBuffer* pFb,Uint32 memSize, Uint32 memNum, Int32 memTypes, Int32 instIndex)
  1301. {
  1302. Uint32 i =0;
  1303. for (i = 0; i < memNum; i++) {
  1304. pFbMem[i].size = memSize;
  1305. if (vdi_allocate_dma_memory(coreIdx, &pFbMem[i], memTypes, instIndex) < 0) {
  1306. VLOG(ERR, "fail to allocate src buffer\n");
  1307. return FALSE;
  1308. }
  1309. pFb[i].bufY = pFbMem[i].phys_addr;
  1310. pFb[i].bufCb = (PhysicalAddress) - 1;
  1311. pFb[i].bufCr = (PhysicalAddress) - 1;
  1312. pFb[i].size = memSize;
  1313. pFb[i].updateFbInfo = TRUE;
  1314. }
  1315. return TRUE;
  1316. }
  1317. BOOL Coda9AllocateDecPPUFrameBuffer(
  1318. BOOL* pEnablePPU,
  1319. DecHandle decHandle,
  1320. TestDecConfig* config,
  1321. FrameBuffer* retFbArray,
  1322. vpu_buffer_t* retFbAddrs,
  1323. Queue* ppuQ
  1324. )
  1325. {
  1326. Uint32 stridePpu = 0;
  1327. Uint32 sizePPUFb = 0;
  1328. Uint32 rotate = config->coda9.rotate;
  1329. Uint32 rotateWidth = 0;
  1330. Uint32 rotateHeight = 0;
  1331. Uint32 coreIndex = 0;
  1332. const Uint32 ppuFbCount = 2; // #define PPU_FB_COUNT 2
  1333. Int32 idx = 0;
  1334. DecInitialInfo seqInfo;
  1335. BOOL enablePPU = FALSE;
  1336. vpu_buffer_t* pvb = NULL;
  1337. FrameBufferAllocInfo fbAllocInfo;
  1338. DRAMConfig* pDramCfg = NULL;
  1339. DRAMConfig dramCfg = {0};
  1340. osal_memset((void*)&fbAllocInfo, 0x00, sizeof(fbAllocInfo));
  1341. osal_memset((void*)retFbArray, 0x00, sizeof(FrameBuffer)*ppuFbCount);
  1342. enablePPU = (BOOL)(config->coda9.rotate > 0 || config->coda9.mirror > 0 ||
  1343. config->coda9.enableTiled2Linear == TRUE || config->coda9.enableDering == TRUE);
  1344. if(pEnablePPU) {
  1345. *pEnablePPU = enablePPU;
  1346. }
  1347. if(!enablePPU) {
  1348. VLOG(INFO, "<%s> No need PPU Buffers.\n", __FUNCTION__);
  1349. return TRUE;
  1350. }
  1351. else {
  1352. VLOG(INFO, "<%s> PPU Buffer : %d\n", __FUNCTION__, ppuFbCount);
  1353. }
  1354. pDramCfg = &dramCfg;
  1355. VPU_DecGiveCommand(decHandle, GET_DRAM_CONFIG, pDramCfg);
  1356. coreIndex = VPU_HANDLE_CORE_INDEX(decHandle);
  1357. VPU_DecGiveCommand(decHandle, DEC_GET_SEQ_INFO, (void*)&seqInfo);
  1358. rotateWidth = seqInfo.picWidth;
  1359. rotateHeight = seqInfo.picHeight;
  1360. if (rotate == 90 || rotate == 270) {
  1361. rotateWidth = seqInfo.picHeight;
  1362. rotateHeight = seqInfo.picWidth;
  1363. }
  1364. rotateWidth = VPU_ALIGN32(rotateWidth);
  1365. rotateHeight = VPU_ALIGN32(rotateHeight);
  1366. stridePpu = CalcStride(rotateWidth, rotateHeight, FORMAT_420, config->cbcrInterleave, LINEAR_FRAME_MAP, FALSE);
  1367. sizePPUFb = VPU_GetFrameBufSize(decHandle, coreIndex, stridePpu, rotateHeight, LINEAR_FRAME_MAP, FORMAT_420, config->cbcrInterleave, pDramCfg);
  1368. for (idx=0; idx<ppuFbCount; idx++) {
  1369. pvb = &(retFbAddrs[idx]);
  1370. pvb->size = sizePPUFb;
  1371. if (vdi_allocate_dma_memory(coreIndex, pvb, DEC_ETC, decHandle->instIndex) < 0) {
  1372. VLOG(ERR, "%s:%d fail to allocate frame buffer\n", __FUNCTION__, __LINE__);
  1373. return FALSE;
  1374. }
  1375. retFbArray[idx].bufY = pvb->phys_addr;
  1376. retFbArray[idx].bufCb = (PhysicalAddress)-1;
  1377. retFbArray[idx].bufCr = (PhysicalAddress)-1;
  1378. retFbArray[idx].updateFbInfo = TRUE;
  1379. retFbArray[idx].size = sizePPUFb;
  1380. }
  1381. fbAllocInfo.mapType = LINEAR_FRAME_MAP;
  1382. fbAllocInfo.cbcrInterleave = config->cbcrInterleave;
  1383. fbAllocInfo.format = FORMAT_420;
  1384. fbAllocInfo.stride = stridePpu;
  1385. fbAllocInfo.height = rotateHeight;
  1386. fbAllocInfo.endian = config->frameEndian;
  1387. fbAllocInfo.lumaBitDepth = 8;
  1388. fbAllocInfo.chromaBitDepth = 8;
  1389. fbAllocInfo.num = ppuFbCount;
  1390. fbAllocInfo.type = FB_TYPE_PPU;
  1391. fbAllocInfo.size = sizePPUFb;
  1392. if (RETCODE_SUCCESS != VPU_DecAllocateFrameBuffer(decHandle, fbAllocInfo, retFbArray)) {
  1393. VLOG(ERR, "%s:%d failed to VPU_DecAllocateFrameBuffer() ret:%d\n", __FUNCTION__, __LINE__);
  1394. return FALSE;
  1395. }
  1396. // Note: Please keep the below call sequence.
  1397. VPU_DecGiveCommand(decHandle, SET_ROTATION_ANGLE, (void*)&(config->coda9.rotate));
  1398. VPU_DecGiveCommand(decHandle, SET_MIRROR_DIRECTION, (void*)&(config->coda9.mirror));
  1399. VPU_DecGiveCommand(decHandle, SET_ROTATOR_STRIDE, (void*)&stridePpu);
  1400. for (idx=0; idx<ppuFbCount; idx++) {
  1401. Queue_Enqueue(ppuQ, (void*)&retFbArray[idx]);
  1402. }
  1403. PrepareDecoderTest(decHandle);
  1404. return TRUE;
  1405. }
  1406. RetCode SetUpDecoderOpenParam(
  1407. DecOpenParam* param,
  1408. TestDecConfig* config
  1409. )
  1410. {
  1411. RetCode ret = RETCODE_SUCCESS;
  1412. if (NULL == param || NULL == config) {
  1413. ret = RETCODE_INVALID_PARAM;
  1414. } else {
  1415. param->bitstreamFormat = config->bitFormat;
  1416. param->coreIdx = config->coreIdx;
  1417. param->bitstreamMode = config->bitstreamMode;
  1418. param->wtlEnable = config->enableWTL;
  1419. param->wtlMode = config->wtlMode;
  1420. param->cbcrInterleave = config->cbcrInterleave;
  1421. param->nv21 = config->nv21;
  1422. param->streamEndian = config->streamEndian;
  1423. param->frameEndian = config->frameEndian;
  1424. if (PRODUCT_ID_W_SERIES(config->productId)) {
  1425. //WAVE
  1426. param->bwOptimization = config->wave.bwOptimization;
  1427. param->av1Format = config->wave.av1Format;
  1428. } else {
  1429. //CODA
  1430. param->avcExtension = config->coda9.enableMvc;
  1431. param->bwbEnable = config->coda9.enableBWB;
  1432. param->mp4Class = config->coda9.mp4class;
  1433. param->tiled2LinearEnable = config->coda9.enableTiled2Linear;
  1434. param->tiled2LinearMode = config->coda9.tiled2LinearMode;
  1435. param->mp4DeblkEnable = config->coda9.enableDeblock;
  1436. }
  1437. }
  1438. return ret;
  1439. }
  1440. #if defined(_WIN32) || defined(__MSDOS__)
  1441. #define DOS_FILESYSTEM
  1442. #define IS_DIR_SEPARATOR(__c) ((__c == '/') || (__c == '\\'))
  1443. #else
  1444. /* UNIX style */
  1445. #define IS_DIR_SEPARATOR(__c) (__c == '/')
  1446. #endif
  1447. char* GetDirname(
  1448. const char* path
  1449. )
  1450. {
  1451. int length;
  1452. int i;
  1453. char* upper_dir;
  1454. if (path == NULL) return NULL;
  1455. length = strlen(path);
  1456. for (i=length-1; i>=0; i--) {
  1457. if (IS_DIR_SEPARATOR(path[i])) break;
  1458. }
  1459. if (i<0) {
  1460. upper_dir = strdup(".");
  1461. } else {
  1462. upper_dir = strdup(path);
  1463. upper_dir[i] = 0;
  1464. }
  1465. return upper_dir;
  1466. }
  1467. char* GetBasename(
  1468. const char* pathname
  1469. )
  1470. {
  1471. const char* base = NULL;
  1472. const char* p = pathname;
  1473. if (p == NULL) {
  1474. return NULL;
  1475. }
  1476. #if defined(DOS_FILESYSTEM)
  1477. if (isalpha((int)p[0]) && p[1] == ':') {
  1478. p += 2;
  1479. }
  1480. #endif
  1481. for (base=p; *p; p++) {//lint !e443
  1482. if (IS_DIR_SEPARATOR(*p)) {
  1483. base = p+1;
  1484. }
  1485. }
  1486. return (char*)base;
  1487. }
  1488. char* GetFileExtension(
  1489. const char* filename
  1490. )
  1491. {
  1492. Int32 len;
  1493. Int32 i;
  1494. len = strlen(filename);
  1495. for (i=len-1; i>=0; i--) {
  1496. if (filename[i] == '.') {
  1497. return (char*)&filename[i+1];
  1498. }
  1499. }
  1500. return NULL;
  1501. }
  1502. void byte_swap(unsigned char* data, int len)
  1503. {
  1504. Uint8 temp;
  1505. Int32 i;
  1506. for (i=0; i<len; i+=2) {
  1507. temp = data[i];
  1508. data[i] = data[i+1];
  1509. data[i+1] = temp;
  1510. }
  1511. }
  1512. void word_swap(unsigned char* data, int len)
  1513. {
  1514. Uint16 temp;
  1515. Uint16* ptr = (Uint16*)data;
  1516. Int32 i, size = len/(int)sizeof(Uint16);
  1517. for (i=0; i<size; i+=2) {
  1518. temp = ptr[i];
  1519. ptr[i] = ptr[i+1];
  1520. ptr[i+1] = temp;
  1521. }
  1522. }
  1523. void dword_swap(unsigned char* data, int len)
  1524. {
  1525. Uint32 temp;
  1526. Uint32* ptr = (Uint32*)data;
  1527. Int32 i, size = len/(int)sizeof(Uint32);
  1528. for (i=0; i<size; i+=2) {
  1529. temp = ptr[i];
  1530. ptr[i] = ptr[i+1];
  1531. ptr[i+1] = temp;
  1532. }
  1533. }
  1534. void lword_swap(unsigned char* data, int len)
  1535. {
  1536. Uint64 temp;
  1537. Uint64* ptr = (Uint64*)data;
  1538. Int32 i, size = len/(int)sizeof(Uint64);
  1539. for (i=0; i<size; i+=2) {
  1540. temp = ptr[i];
  1541. ptr[i] = ptr[i+1];
  1542. ptr[i+1] = temp;
  1543. }
  1544. }
  1545. BOOL IsEndOfFile(FILE* fp)
  1546. {
  1547. BOOL result = FALSE;
  1548. Int32 idx = 0;
  1549. char cTemp;
  1550. // Check current fp pos
  1551. if (osal_feof(fp) != 0) {
  1552. result = TRUE;
  1553. }
  1554. // Check next fp pos
  1555. // Ignore newline character
  1556. do {
  1557. cTemp = fgetc(fp);
  1558. idx++;
  1559. if (osal_feof(fp) != 0) {
  1560. result = TRUE;
  1561. break;
  1562. }
  1563. } while (cTemp == '\n' || cTemp == '\r');
  1564. // Revert fp pos
  1565. idx *= (-1);
  1566. osal_fseek(fp, idx, SEEK_CUR);
  1567. return result;
  1568. }
  1569. BOOL CalcYuvSize(
  1570. Int32 format,
  1571. Int32 picWidth,
  1572. Int32 picHeight,
  1573. Int32 cbcrInterleave,
  1574. size_t *lumaSize,
  1575. size_t *chromaSize,
  1576. size_t *frameSize,
  1577. Int32 *bitDepth,
  1578. Int32 *packedFormat,
  1579. Int32 *yuv3p4b)
  1580. {
  1581. Int32 temp_picWidth;
  1582. Int32 chromaWidth;
  1583. if ( bitDepth != 0)
  1584. *bitDepth = 0;
  1585. if ( packedFormat != 0)
  1586. *packedFormat = 0;
  1587. if ( yuv3p4b != 0)
  1588. *yuv3p4b = 0;
  1589. if (!lumaSize || !chromaSize || !frameSize )
  1590. return FALSE;
  1591. switch (format)
  1592. {
  1593. case FORMAT_420:
  1594. *lumaSize = picWidth * picHeight;
  1595. if (picWidth & 0x01) {
  1596. *chromaSize = (picWidth+1) * picHeight / 2;
  1597. } else {
  1598. *chromaSize = picWidth * picHeight / 2;
  1599. }
  1600. *frameSize = picWidth * picHeight * 3 /2;
  1601. break;
  1602. case FORMAT_YUYV:
  1603. case FORMAT_YVYU:
  1604. case FORMAT_UYVY:
  1605. case FORMAT_VYUY:
  1606. if ( packedFormat != 0)
  1607. *packedFormat = 1;
  1608. *lumaSize = picWidth * picHeight;
  1609. *chromaSize = picWidth * picHeight;
  1610. *frameSize = *lumaSize + *chromaSize;
  1611. break;
  1612. case FORMAT_224:
  1613. *lumaSize = picWidth * picHeight;
  1614. *chromaSize = picWidth * picHeight;
  1615. *frameSize = picWidth * picHeight * 4 / 2;
  1616. break;
  1617. case FORMAT_422:
  1618. *lumaSize = picWidth * picHeight;
  1619. *chromaSize = picWidth * picHeight;
  1620. *frameSize = picWidth * picHeight * 4 / 2;
  1621. break;
  1622. case FORMAT_444:
  1623. *lumaSize = picWidth * picHeight;
  1624. *chromaSize = picWidth * picHeight * 2;
  1625. *frameSize = picWidth * picHeight * 3;
  1626. break;
  1627. case FORMAT_400:
  1628. *lumaSize = picWidth * picHeight;
  1629. *chromaSize = 0;
  1630. *frameSize = picWidth * picHeight;
  1631. break;
  1632. case FORMAT_422_P10_16BIT_MSB:
  1633. case FORMAT_422_P10_16BIT_LSB:
  1634. if ( bitDepth != NULL) {
  1635. *bitDepth = 10;
  1636. }
  1637. *lumaSize = picWidth * picHeight * 2;
  1638. *chromaSize = *lumaSize;
  1639. *frameSize = *lumaSize + *chromaSize;
  1640. break;
  1641. case FORMAT_420_P10_16BIT_MSB:
  1642. case FORMAT_420_P10_16BIT_LSB:
  1643. if ( bitDepth != 0)
  1644. *bitDepth = 10;
  1645. *lumaSize = picWidth * picHeight * 2;
  1646. *chromaSize = picWidth * picHeight;
  1647. *frameSize = *lumaSize + *chromaSize;
  1648. break;
  1649. case FORMAT_YUYV_P10_16BIT_MSB: // 4:2:2 10bit packed
  1650. case FORMAT_YUYV_P10_16BIT_LSB:
  1651. case FORMAT_YVYU_P10_16BIT_MSB:
  1652. case FORMAT_YVYU_P10_16BIT_LSB:
  1653. case FORMAT_UYVY_P10_16BIT_MSB:
  1654. case FORMAT_UYVY_P10_16BIT_LSB:
  1655. case FORMAT_VYUY_P10_16BIT_MSB:
  1656. case FORMAT_VYUY_P10_16BIT_LSB:
  1657. if ( bitDepth != 0)
  1658. *bitDepth = 10;
  1659. if ( packedFormat != 0)
  1660. *packedFormat = 1;
  1661. *lumaSize = picWidth * picHeight * 2;
  1662. *chromaSize = picWidth * picHeight * 2;
  1663. *frameSize = *lumaSize + *chromaSize;
  1664. break;
  1665. case FORMAT_420_P10_32BIT_MSB:
  1666. case FORMAT_420_P10_32BIT_LSB:
  1667. if ( bitDepth != 0)
  1668. *bitDepth = 10;
  1669. if ( yuv3p4b != 0)
  1670. *yuv3p4b = 1;
  1671. temp_picWidth = VPU_ALIGN32(picWidth);
  1672. chromaWidth = ((VPU_ALIGN16(temp_picWidth/2*(1<<cbcrInterleave))+2)/3*4);
  1673. if ( cbcrInterleave == 1)
  1674. {
  1675. *lumaSize = (temp_picWidth+2)/3*4 * picHeight;
  1676. *chromaSize = chromaWidth * picHeight/2;
  1677. } else {
  1678. *lumaSize = (temp_picWidth+2)/3*4 * picHeight;
  1679. *chromaSize = chromaWidth * picHeight/2*2;
  1680. }
  1681. *frameSize = *lumaSize + *chromaSize;
  1682. break;
  1683. case FORMAT_YUYV_P10_32BIT_MSB:
  1684. case FORMAT_YUYV_P10_32BIT_LSB:
  1685. case FORMAT_YVYU_P10_32BIT_MSB:
  1686. case FORMAT_YVYU_P10_32BIT_LSB:
  1687. case FORMAT_UYVY_P10_32BIT_MSB:
  1688. case FORMAT_UYVY_P10_32BIT_LSB:
  1689. case FORMAT_VYUY_P10_32BIT_MSB:
  1690. case FORMAT_VYUY_P10_32BIT_LSB:
  1691. if ( bitDepth != 0)
  1692. *bitDepth = 10;
  1693. if ( packedFormat != 0)
  1694. *packedFormat = 1;
  1695. if ( yuv3p4b != 0)
  1696. *yuv3p4b = 1;
  1697. *frameSize = ((picWidth*2)+2)/3*4 * picHeight;
  1698. *lumaSize = *frameSize/2;
  1699. *chromaSize = *frameSize/2;
  1700. break;
  1701. default:
  1702. *frameSize = picWidth * picHeight * 3 / 2;
  1703. VLOG(ERR, "%s:%d Not supported format(%d)\n", __FILE__, __LINE__, format);
  1704. return FALSE;
  1705. }
  1706. return TRUE;
  1707. }
  1708. FrameBufferFormat GetPackedFormat (
  1709. int srcBitDepth,
  1710. int packedType,
  1711. int p10bits,
  1712. int msb)
  1713. {
  1714. FrameBufferFormat format = FORMAT_YUYV;
  1715. // default pixel format = P10_16BIT_LSB (p10bits = 16, msb = 0)
  1716. if (srcBitDepth == 8) {
  1717. switch(packedType) {
  1718. case PACKED_YUYV:
  1719. format = FORMAT_YUYV;
  1720. break;
  1721. case PACKED_YVYU:
  1722. format = FORMAT_YVYU;
  1723. break;
  1724. case PACKED_UYVY:
  1725. format = FORMAT_UYVY;
  1726. break;
  1727. case PACKED_VYUY:
  1728. format = FORMAT_VYUY;
  1729. break;
  1730. default:
  1731. format = FORMAT_ERR;
  1732. }
  1733. }
  1734. else if (srcBitDepth == 10) {
  1735. switch(packedType) {
  1736. case PACKED_YUYV:
  1737. if (p10bits == 16) {
  1738. format = (msb == 0) ? FORMAT_YUYV_P10_16BIT_LSB : FORMAT_YUYV_P10_16BIT_MSB;
  1739. }
  1740. else if (p10bits == 32) {
  1741. format = (msb == 0) ? FORMAT_YUYV_P10_32BIT_LSB : FORMAT_YUYV_P10_32BIT_MSB;
  1742. }
  1743. else {
  1744. format = FORMAT_ERR;
  1745. }
  1746. break;
  1747. case PACKED_YVYU:
  1748. if (p10bits == 16) {
  1749. format = (msb == 0) ? FORMAT_YVYU_P10_16BIT_LSB : FORMAT_YVYU_P10_16BIT_MSB;
  1750. }
  1751. else if (p10bits == 32) {
  1752. format = (msb == 0) ? FORMAT_YVYU_P10_32BIT_LSB : FORMAT_YVYU_P10_32BIT_MSB;
  1753. }
  1754. else {
  1755. format = FORMAT_ERR;
  1756. }
  1757. break;
  1758. case PACKED_UYVY:
  1759. if (p10bits == 16) {
  1760. format = (msb == 0) ? FORMAT_UYVY_P10_16BIT_LSB : FORMAT_UYVY_P10_16BIT_MSB;
  1761. }
  1762. else if (p10bits == 32) {
  1763. format = (msb == 0) ? FORMAT_UYVY_P10_32BIT_LSB : FORMAT_UYVY_P10_32BIT_MSB;
  1764. }
  1765. else {
  1766. format = FORMAT_ERR;
  1767. }
  1768. break;
  1769. case PACKED_VYUY:
  1770. if (p10bits == 16) {
  1771. format = (msb == 0) ? FORMAT_VYUY_P10_16BIT_LSB : FORMAT_VYUY_P10_16BIT_MSB;
  1772. }
  1773. else if (p10bits == 32) {
  1774. format = (msb == 0) ? FORMAT_VYUY_P10_32BIT_LSB : FORMAT_VYUY_P10_32BIT_MSB;
  1775. }
  1776. else {
  1777. format = FORMAT_ERR;
  1778. }
  1779. break;
  1780. default:
  1781. format = FORMAT_ERR;
  1782. }
  1783. }
  1784. else {
  1785. format = FORMAT_ERR;
  1786. }
  1787. return format;
  1788. }
  1789. BOOL SetupEncoderOpenParam(
  1790. EncOpenParam* param,
  1791. TestEncConfig* config,
  1792. ENC_CFG* encCfg
  1793. )
  1794. {
  1795. param->bitstreamFormat = config->stdMode;
  1796. if (strlen(config->cfgFileName) != 0) {
  1797. if (GetEncOpenParam(param, config, encCfg) == FALSE) {
  1798. VLOG(ERR, "[ERROR] Failed to parse CFG file(GetEncOpenParam)\n");
  1799. return FALSE;
  1800. }
  1801. }
  1802. else {
  1803. if (GetEncOpenParamDefault(param, config) == FALSE) {
  1804. VLOG(ERR, "[ERROR] Failed to parse CFG file(GetEncOpenParamDefault)\n");
  1805. return FALSE;
  1806. }
  1807. }
  1808. if (0 == param->streamBufCount) param->streamBufCount = ENC_STREAM_BUF_COUNT;
  1809. if (0 == param->streamBufSize) param->streamBufSize = ENC_STREAM_BUF_SIZE;
  1810. if (strlen(config->cfgFileName) != 0) {
  1811. if (param->srcBitDepth == 8) {
  1812. config->srcFormat = FORMAT_420;
  1813. }
  1814. else if (param->srcBitDepth == 10) {
  1815. if (config->srcFormat == FORMAT_420) {
  1816. config->srcFormat = FORMAT_420_P10_16BIT_MSB; //set srcFormat in ParseArgumentAndSetTestConfig function
  1817. return FALSE;
  1818. }
  1819. }
  1820. }
  1821. if (config->optYuvPath[0] != 0)
  1822. strcpy(config->yuvFileName, config->optYuvPath);
  1823. #ifdef SUPPORT_LOOK_AHEAD_RC
  1824. if ( config->larcPass == LOOK_AHEAD_RC_PASS1) {
  1825. if (config->optYuvPath_larc_pass1[0] != 0)
  1826. strcpy(config->yuvFileName, config->optYuvPath_larc_pass1);
  1827. }
  1828. #endif
  1829. if (config->packedFormat >= PACKED_YUYV) {
  1830. int p10bits = 0;
  1831. FrameBufferFormat packedFormat;
  1832. if (config->srcFormat == FORMAT_420_P10_16BIT_MSB || config->srcFormat == FORMAT_420_P10_16BIT_LSB )
  1833. p10bits = 16;
  1834. if (config->srcFormat == FORMAT_420_P10_32BIT_MSB || config->srcFormat == FORMAT_420_P10_32BIT_LSB )
  1835. p10bits = 32;
  1836. packedFormat = GetPackedFormat(param->srcBitDepth, config->packedFormat, p10bits, 1);
  1837. if (packedFormat == -1) {
  1838. VLOG(ERR, "[ERROR] Failed to GetPackedFormat\n");
  1839. return FALSE;
  1840. }
  1841. param->srcFormat = packedFormat;
  1842. param->nv21 = 0;
  1843. param->cbcrInterleave = 0;
  1844. }
  1845. else {
  1846. param->srcFormat = config->srcFormat;
  1847. param->nv21 = config->nv21;
  1848. }
  1849. param->packedFormat = config->packedFormat;
  1850. param->cbcrInterleave = config->cbcrInterleave;
  1851. param->frameEndian = config->frame_endian;
  1852. param->streamEndian = config->stream_endian;
  1853. param->sourceEndian = config->source_endian;
  1854. param->lineBufIntEn = config->lineBufIntEn;
  1855. param->coreIdx = config->coreIdx;
  1856. param->cbcrOrder = CBCR_ORDER_NORMAL;
  1857. param->lowLatencyMode = (config->lowLatencyMode&0x3); // 2bits lowlatency mode setting. bit[1]: low latency interrupt enable, bit[0]: fast bitstream-packing enable.
  1858. param->EncStdParam.waveParam.useLongTerm = (config->useAsLongtermPeriod > 0 && config->refLongtermPeriod > 0) ? 1 : 0;
  1859. if (PRODUCT_ID_W_SERIES(config->productId)) {
  1860. #ifdef SUPPORT_SOURCE_RELEASE_INTERRUPT
  1861. param->srcReleaseIntEnable = config->srcReleaseIntEnable;
  1862. #endif
  1863. param->ringBufferEnable = config->ringBufferEnable;
  1864. param->ringBufferWrapEnable = config->ringBufferWrapEnable;
  1865. if (config->ringBufferEnable == TRUE) {
  1866. param->streamBufCount = 1;
  1867. param->lineBufIntEn = FALSE;
  1868. }
  1869. }
  1870. if(PRODUCT_ID_NOT_W_SERIES(config->productId)) {
  1871. param->bwbEnable = VPU_ENABLE_BWB;
  1872. param->linear2TiledEnable = config->coda9.enableLinear2Tiled;
  1873. param->linear2TiledMode = config->coda9.linear2TiledMode;
  1874. param->ringBufferEnable = config->ringBufferEnable;
  1875. if (TRUE == config->ringBufferEnable) {
  1876. param->streamBufCount = 1;
  1877. }
  1878. #ifdef SUPPORT_NEW_SCHEDULER
  1879. param->ringBufferWrapEnable = config->ringBufferWrapEnable;
  1880. #endif
  1881. }
  1882. return TRUE;
  1883. }
  1884. void GenRegionToMap(
  1885. VpuRect *region, /**< The size of the ROI region for H.265 (start X/Y in CTU, end X/Y int CTU) */
  1886. int *roiQp,
  1887. int num,
  1888. Uint32 mapWidth,
  1889. Uint32 mapHeight,
  1890. Uint8 *roiCtuMap)
  1891. {
  1892. Int32 roi_id, blk_addr;
  1893. Uint32 roi_map_size = mapWidth * mapHeight;
  1894. //init roi map
  1895. for (blk_addr=0; blk_addr<(Int32)roi_map_size; blk_addr++)
  1896. roiCtuMap[blk_addr] = 0;
  1897. //set roi map. roi_entry[i] has higher priority than roi_entry[i+1]
  1898. for (roi_id=(Int32)num-1; roi_id>=0; roi_id--)
  1899. {
  1900. Uint32 x, y;
  1901. VpuRect *roi = region + roi_id;
  1902. for (y=roi->top; y<=roi->bottom; y++)
  1903. {
  1904. for (x=roi->left; x<=roi->right; x++)
  1905. {
  1906. roiCtuMap[y*mapWidth + x] = *(roiQp + roi_id);
  1907. }
  1908. }
  1909. }
  1910. }
  1911. void GenRegionToQpMap(
  1912. VpuRect *region, /**< The size of the ROI region for H.265 (start X/Y in CTU, end X/Y int CTU) */
  1913. int *roiQp,
  1914. int num,
  1915. int initQp,
  1916. Uint32 mapWidth,
  1917. Uint32 mapHeight,
  1918. Uint8 *roiCtuMap)
  1919. {
  1920. Int32 roi_id, blk_addr;
  1921. Uint32 roi_map_size = mapWidth * mapHeight;
  1922. //init roi map
  1923. for (blk_addr=0; blk_addr<(Int32)roi_map_size; blk_addr++)
  1924. roiCtuMap[blk_addr] = initQp;
  1925. //set roi map. roi_entry[i] has higher priority than roi_entry[i+1]
  1926. for (roi_id=(Int32)num-1; roi_id>=0; roi_id--)
  1927. {
  1928. Uint32 x, y;
  1929. VpuRect *roi = region + roi_id;
  1930. for (y=roi->top; y<=roi->bottom; y++)
  1931. {
  1932. for (x=roi->left; x<=roi->right; x++)
  1933. {
  1934. roiCtuMap[y*mapWidth + x] = *(roiQp + roi_id);
  1935. }
  1936. }
  1937. }
  1938. }
  1939. int openRoiMapFile(TestEncConfig *encConfig)
  1940. {
  1941. if (encConfig->roi_enable) {
  1942. if (encConfig->roi_file_name) {
  1943. ChangePathStyle(encConfig->roi_file_name);
  1944. if ((encConfig->roi_file = osal_fopen(encConfig->roi_file_name, "r")) == NULL) {
  1945. VLOG(ERR, "fail to open ROI file, %s\n", encConfig->roi_file_name);
  1946. return FALSE;
  1947. }
  1948. }
  1949. }
  1950. return TRUE;
  1951. }
  1952. int allocateRoiMapBuf(EncHandle handle, TestEncConfig encConfig, vpu_buffer_t *vbRoi, int srcFbNum, int ctuNum)
  1953. {
  1954. int i;
  1955. Int32 coreIdx = handle->coreIdx;
  1956. if (encConfig.roi_enable) {
  1957. //number of roi buffer should be the same as source buffer num.
  1958. for (i = 0; i < srcFbNum ; i++) {
  1959. vbRoi[i].size = ctuNum;
  1960. if (vdi_allocate_dma_memory(coreIdx, &vbRoi[i], ENC_ETC, handle->instIndex) < 0) {
  1961. VLOG(ERR, "fail to allocate ROI buffer\n" );
  1962. return FALSE;
  1963. }
  1964. }
  1965. }
  1966. return TRUE;
  1967. }
  1968. // Define tokens for parsing scaling list file
  1969. const char* MatrixType[SCALING_LIST_SIZE_NUM][SL_NUM_MATRIX] =
  1970. {
  1971. {"INTRA4X4_LUMA", "INTRA4X4_CHROMAU", "INTRA4X4_CHROMAV", "INTER4X4_LUMA", "INTER4X4_CHROMAU", "INTER4X4_CHROMAV"},
  1972. {"INTRA8X8_LUMA", "INTRA8X8_CHROMAU", "INTRA8X8_CHROMAV", "INTER8X8_LUMA", "INTER8X8_CHROMAU", "INTER8X8_CHROMAV"},
  1973. {"INTRA16X16_LUMA", "INTRA16X16_CHROMAU", "INTRA16X16_CHROMAV", "INTER16X16_LUMA", "INTER16X16_CHROMAU", "INTER16X16_CHROMAV"},
  1974. {"INTRA32X32_LUMA", "INTRA32X32_CHROMAU_FROM16x16_CHROMAU", "INTRA32X32_CHROMAV_FROM16x16_CHROMAV","INTER32X32_LUMA", "INTER32X32_CHROMAU_FROM16x16_CHROMAU", "INTER32X32_CHROMAV_FROM16x16_CHROMAV"}
  1975. };
  1976. const char* MatrixType_DC[SCALING_LIST_SIZE_NUM - 2][SL_NUM_MATRIX] =
  1977. {
  1978. {"INTRA16X16_LUMA_DC", "INTRA16X16_CHROMAU_DC", "INTRA16X16_CHROMAV_DC", "INTER16X16_LUMA_DC", "INTER16X16_CHROMAU_DC", "INTER16X16_CHROMAV_DC"},
  1979. {"INTRA32X32_LUMA_DC", "INTRA32X32_CHROMAU_DC_FROM16x16_CHROMAU", "INTRA32X32_CHROMAV_DC_FROM16x16_CHROMAV", "INTER32X32_LUMA_DC","INTER32X32_CHROMAU_DC_FROM16x16_CHROMAU","INTER32X32_CHROMAV_DC_FROM16x16_CHROMAV"},
  1980. };
  1981. static Uint8* get_sl_addr(UserScalingList* sl, Uint32 size_id, Uint32 mat_id)
  1982. {
  1983. Uint8* addr = NULL;
  1984. switch(size_id)
  1985. {
  1986. case SCALING_LIST_4x4:
  1987. addr = sl->s4[mat_id];
  1988. break;
  1989. case SCALING_LIST_8x8:
  1990. addr = sl->s8[mat_id];
  1991. break;
  1992. case SCALING_LIST_16x16:
  1993. addr = sl->s16[mat_id];
  1994. break;
  1995. case SCALING_LIST_32x32:
  1996. addr = sl->s32[mat_id];
  1997. break;
  1998. }
  1999. return addr;
  2000. }
  2001. int parse_user_scaling_list(UserScalingList* sl, FILE* fp_sl, CodStd stdMode)
  2002. {
  2003. #define LINE_SIZE (1024)
  2004. const Uint32 scaling_list_size[SCALING_LIST_SIZE_NUM] = {16, 64, 64, 64};
  2005. char line[LINE_SIZE];
  2006. Uint32 i;
  2007. Uint32 size_id, mat_id, data, num_coef = 0;
  2008. Uint8* src = NULL;
  2009. Uint8* ref = NULL;
  2010. char* ret;
  2011. const char* type_str;
  2012. if ( fp_sl == NULL)
  2013. return 0;
  2014. for(size_id = 0; size_id < SCALING_LIST_SIZE_NUM; size_id++) {// for 4, 8, 16, 32
  2015. num_coef = scaling_list_size[size_id];//lint !e644
  2016. if (stdMode == STD_AVC && size_id > SCALING_LIST_8x8)
  2017. break;
  2018. for(mat_id = 0; mat_id < SL_NUM_MATRIX; mat_id++) { // for intra_y, intra_cb, intra_cr, inter_y, inter_cb, inter_cr
  2019. src = get_sl_addr(sl, size_id, mat_id);
  2020. if(size_id == SCALING_LIST_32x32 && (mat_id % 3)) { // derive scaling list of chroma32x32 from that of chrom16x16
  2021. ref = get_sl_addr(sl, size_id - 1, mat_id);
  2022. for(i = 0; i < num_coef; i++)
  2023. src[i] = ref[i];
  2024. }
  2025. else {
  2026. fseek(fp_sl,0,0);
  2027. type_str = MatrixType[size_id][mat_id];
  2028. do {
  2029. ret = fgets(line, LINE_SIZE, fp_sl);
  2030. if((ret == NULL) || (strstr(line, type_str) == NULL && feof(fp_sl))) {
  2031. VLOG(ERR,"Error: can't read a scaling list matrix(%s)\n", type_str);
  2032. return 0;
  2033. }
  2034. } while (strstr(line, type_str) == NULL);
  2035. // get all coeff
  2036. for(i = 0; i < num_coef; i++) {
  2037. if(fscanf(fp_sl, "%d,", &data) != 1) {
  2038. VLOG(ERR,"Error: can't read a scaling list matrix(%s)\n", type_str);
  2039. return 0;
  2040. }
  2041. if (stdMode == STD_AVC && data < 4) {
  2042. VLOG(ERR,"Error: invald value in scaling list matrix(%s %d)\n", type_str, data);
  2043. return 0;
  2044. }
  2045. src[i] = data;
  2046. }
  2047. // get DC coeff for 16, 32
  2048. if(size_id > SCALING_LIST_8x8) {
  2049. fseek(fp_sl,0,0);
  2050. type_str = MatrixType_DC[size_id - 2][mat_id];
  2051. do {
  2052. ret = fgets(line, LINE_SIZE, fp_sl);
  2053. if((ret == NULL) || (strstr(line, type_str) == NULL && feof(fp_sl))) {
  2054. VLOG(ERR,"Error: can't read a scaling list matrix(%s)\n", type_str);
  2055. return 0;
  2056. }
  2057. } while (strstr(line, type_str) == NULL);
  2058. if(fscanf(fp_sl, "%d,", &data) != 1) {
  2059. VLOG(ERR,"Error: can't read a scaling list matrix(%s)\n", type_str);
  2060. return 0;
  2061. }
  2062. if (stdMode == STD_AVC && data < 4) {
  2063. VLOG(ERR,"Error: invald value in scaling list matrix(%s %d)\n", type_str, data);
  2064. return 0;
  2065. }
  2066. if(size_id == SCALING_LIST_16x16)
  2067. sl->s16dc[mat_id] = data;
  2068. else // SCALING_LIST_32x32
  2069. sl->s32dc[mat_id/3] = data;
  2070. }
  2071. }
  2072. } // for matrix id
  2073. } // for size id
  2074. return 1;
  2075. }
  2076. int parse_custom_lambda(Uint32 buf[NUM_CUSTOM_LAMBDA], FILE* fp)
  2077. {
  2078. int i, j = 0;
  2079. char lineStr[256] = {0, };
  2080. for(i = 0; i < 52; i++)
  2081. {
  2082. if( NULL == fgets(lineStr, 256, fp) )
  2083. {
  2084. VLOG(ERR,"Error: can't read custom_lambda\n");
  2085. return 0;
  2086. }
  2087. else
  2088. {
  2089. sscanf(lineStr, "%d\n", &buf[j++]);
  2090. }
  2091. }
  2092. for(i = 0; i < 52; i++)
  2093. {
  2094. if( NULL == fgets(lineStr, 256, fp) )
  2095. {
  2096. VLOG(ERR,"Error: can't read custom_lambda\n");
  2097. return 0;
  2098. }
  2099. else
  2100. sscanf(lineStr, "%d\n", &buf[j++]);
  2101. }
  2102. return 1;
  2103. }
  2104. #if defined(PLATFORM_NON_OS) || defined (PLATFORM_LINUX)
  2105. struct option* ConvertOptions(
  2106. struct OptionExt* cnmOpt,
  2107. Uint32 nItems
  2108. )
  2109. {
  2110. struct option* opt;
  2111. Uint32 i;
  2112. opt = (struct option*)osal_malloc(sizeof(struct option) * nItems);
  2113. if (opt == NULL) {
  2114. return NULL;
  2115. }
  2116. for (i=0; i<nItems; i++) {
  2117. osal_memcpy((void*)&opt[i], (void*)&cnmOpt[i], sizeof(struct option));
  2118. }
  2119. return opt;
  2120. }
  2121. #endif
  2122. #ifdef PLATFORM_LINUX
  2123. int mkdir_recursive(
  2124. char *path,
  2125. mode_t omode
  2126. )
  2127. {
  2128. struct stat sb;
  2129. mode_t numask, oumask;
  2130. int first, last, retval;
  2131. char *p;
  2132. p = path;
  2133. oumask = 0;
  2134. retval = 0;
  2135. if (p[0] == '/') /* Skip leading '/'. */
  2136. ++p;
  2137. for (first = 1, last = 0; !last ; ++p) {//lint !e441 !e443
  2138. if (p[0] == '\0')
  2139. last = 1;
  2140. else if (p[0] != '/')
  2141. continue;
  2142. *p = '\0';
  2143. if (p[1] == '\0')
  2144. last = 1;
  2145. if (first) {
  2146. /*
  2147. * POSIX 1003.2:
  2148. * For each dir operand that does not name an existing
  2149. * directory, effects equivalent to those cased by the
  2150. * following command shall occcur:
  2151. *
  2152. * mkdir -p -m $(umask -S),u+wx $(dirname dir) &&
  2153. * mkdir [-m mode] dir
  2154. *
  2155. * We change the user's umask and then restore it,
  2156. * instead of doing chmod's.
  2157. */
  2158. oumask = umask(0);
  2159. numask = oumask & ~(S_IWUSR | S_IXUSR);
  2160. (void)umask(numask);
  2161. first = 0;
  2162. }
  2163. if (last)
  2164. (void)umask(oumask);
  2165. if (mkdir(path, last ? omode : S_IRWXU | S_IRWXG | S_IRWXO) < 0) {
  2166. if (errno == EEXIST || errno == EISDIR) {
  2167. if (stat(path, &sb) < 0) {
  2168. VLOG(INFO, "%s", path);
  2169. retval = 1;
  2170. break;
  2171. } else if (!S_ISDIR(sb.st_mode)) {
  2172. if (last)
  2173. errno = EEXIST;
  2174. else
  2175. errno = ENOTDIR;
  2176. VLOG(INFO, "%s", path);
  2177. retval = 1;
  2178. break;
  2179. }
  2180. } else {
  2181. VLOG(INFO, "%s", path);
  2182. retval = 1;
  2183. break;
  2184. }
  2185. } else {
  2186. VLOG(INFO, "%s", path);
  2187. chmod(path, omode);
  2188. }
  2189. if (!last)
  2190. *p = '/';
  2191. }
  2192. if (!first && !last)
  2193. (void)umask(oumask);
  2194. return (retval);
  2195. }
  2196. #endif
  2197. int file_exist(
  2198. char* path
  2199. )
  2200. {
  2201. #ifdef _MSC_VER
  2202. DWORD attributes;
  2203. char temp[4096];
  2204. LPCTSTR lp_path = (LPCTSTR)temp;
  2205. if (path == NULL) {
  2206. return FALSE;
  2207. }
  2208. strcpy(temp, path);
  2209. replace_character(temp, '/', '\\');
  2210. attributes = GetFileAttributes(lp_path);
  2211. return (attributes != (DWORD)-1);
  2212. #else
  2213. return !access(path, F_OK);
  2214. #endif
  2215. }
  2216. BOOL MkDir(
  2217. char* path
  2218. )
  2219. {
  2220. #if defined(PLATFORM_NON_OS) || defined(PLATFORM_QNX)
  2221. /* need to implement */
  2222. return FALSE;
  2223. #else
  2224. #ifdef _MSC_VER
  2225. char cmd[4096];
  2226. #endif
  2227. if (file_exist(path))
  2228. return TRUE;
  2229. #ifdef _MSC_VER
  2230. sprintf(cmd, "mkdir %s", path);
  2231. replace_character(cmd, '/', '\\');
  2232. if (system(cmd)) {
  2233. return FALSE;
  2234. }
  2235. return TRUE;
  2236. #else
  2237. return mkdir_recursive(path, S_IRWXU | S_IRWXG | S_IRWXO);
  2238. #endif
  2239. #endif
  2240. }
  2241. void GetUserData(Int32 coreIdx, Uint8* pBase, vpu_buffer_t vbUserData, DecOutputInfo outputInfo)
  2242. {
  2243. int idx;
  2244. user_data_entry_t* pEntry = (user_data_entry_t*)pBase;
  2245. VpuReadMem(coreIdx, vbUserData.phys_addr, pBase, vbUserData.size, VPU_USER_DATA_ENDIAN);
  2246. VLOG(INFO, "===== USER DATA(SEI OR VUI) : NUM(%d) =====\n", outputInfo.decOutputExtData.userDataNum);
  2247. for (idx=0; idx<32; idx++) {
  2248. if (outputInfo.decOutputExtData.userDataHeader&(1<<idx)) {
  2249. VLOG(INFO, "\nUSERDATA INDEX: %02d offset: %8d size: %d\n", idx, pEntry[idx].offset, pEntry[idx].size);
  2250. if (idx == H265_USERDATA_FLAG_MASTERING_COLOR_VOL) {
  2251. h265_mastering_display_colour_volume_t* mastering;
  2252. int i;
  2253. mastering = (h265_mastering_display_colour_volume_t*)(pBase + pEntry[H265_USERDATA_FLAG_MASTERING_COLOR_VOL].offset);
  2254. VLOG(INFO, " MASTERING DISPLAY COLOR VOLUME\n");
  2255. for (i=0; i<3; i++) {
  2256. VLOG(INFO, " PRIMARIES_X%d : %10d PRIMARIES_Y%d : %10d\n", i, mastering->display_primaries_x[i], i, mastering->display_primaries_y[i]);
  2257. }
  2258. VLOG(INFO, " WHITE_POINT_X: %10d WHITE_POINT_Y: %10d\n", mastering->white_point_x, mastering->white_point_y);
  2259. VLOG(INFO, " MIN_LUMINANCE: %10d MAX_LUMINANCE: %10d\n", mastering->min_display_mastering_luminance, mastering->max_display_mastering_luminance);
  2260. }
  2261. if(idx == H265_USERDATA_FLAG_VUI)
  2262. {
  2263. h265_vui_param_t* vui;
  2264. vui = (h265_vui_param_t*)(pBase + pEntry[H265_USERDATA_FLAG_VUI].offset);
  2265. VLOG(INFO, " VUI SAR(%d, %d)\n", vui->sar_width, vui->sar_height);
  2266. VLOG(INFO, " VIDEO FORMAT(%d)\n", vui->video_format);
  2267. VLOG(INFO, " COLOUR PRIMARIES(%d)\n", vui->colour_primaries);
  2268. VLOG(INFO, "log2_max_mv_length_horizontal: %d\n", vui->log2_max_mv_length_horizontal);
  2269. VLOG(INFO, "log2_max_mv_length_vertical : %d\n", vui->log2_max_mv_length_vertical);
  2270. VLOG(INFO, "video_full_range_flag : %d\n", vui->video_full_range_flag);
  2271. VLOG(INFO, "transfer_characteristics : %d\n", vui->transfer_characteristics);
  2272. VLOG(INFO, "matrix_coeffs : %d\n", vui->matrix_coefficients);
  2273. }
  2274. if (idx == H265_USERDATA_FLAG_CHROMA_RESAMPLING_FILTER_HINT) {
  2275. h265_chroma_resampling_filter_hint_t* c_resampleing_filter_hint;
  2276. Uint32 i,j;
  2277. c_resampleing_filter_hint = (h265_chroma_resampling_filter_hint_t*)(pBase + pEntry[H265_USERDATA_FLAG_CHROMA_RESAMPLING_FILTER_HINT].offset);
  2278. VLOG(INFO, " CHROMA_RESAMPLING_FILTER_HINT\n");
  2279. VLOG(INFO, " VER_CHROMA_FILTER_IDC: %10d HOR_CHROMA_FILTER_IDC: %10d\n", c_resampleing_filter_hint->ver_chroma_filter_idc, c_resampleing_filter_hint->hor_chroma_filter_idc);
  2280. VLOG(INFO, " VER_FILTERING_FIELD_PROCESSING_FLAG: %d \n", c_resampleing_filter_hint->ver_filtering_field_processing_flag);
  2281. if (c_resampleing_filter_hint->ver_chroma_filter_idc == 1 || c_resampleing_filter_hint->hor_chroma_filter_idc == 1) {
  2282. VLOG(INFO, " TARGET_FORMAT_IDC: %d \n", c_resampleing_filter_hint->target_format_idc);
  2283. if (c_resampleing_filter_hint->ver_chroma_filter_idc == 1) {
  2284. VLOG(INFO, " NUM_VERTICAL_FILTERS: %d \n", c_resampleing_filter_hint->num_vertical_filters);
  2285. for (i=0; i<c_resampleing_filter_hint->num_vertical_filters; i++) {
  2286. VLOG(INFO, " VER_TAP_LENGTH_M1[%d]: %d \n", i, c_resampleing_filter_hint->ver_tap_length_minus1[i]);
  2287. for (j=0; j<c_resampleing_filter_hint->ver_tap_length_minus1[i]; j++) {
  2288. VLOG(INFO, " VER_FILTER_COEFF[%d][%d]: %d \n", i, j, c_resampleing_filter_hint->ver_filter_coeff[i][j]);
  2289. }
  2290. }
  2291. }
  2292. if (c_resampleing_filter_hint->hor_chroma_filter_idc == 1) {
  2293. VLOG(INFO, " NUM_HORIZONTAL_FILTERS: %d \n", c_resampleing_filter_hint->num_horizontal_filters);
  2294. for (i=0; i<c_resampleing_filter_hint->num_horizontal_filters; i++) {
  2295. VLOG(INFO, " HOR_TAP_LENGTH_M1[%d]: %d \n", i, c_resampleing_filter_hint->hor_tap_length_minus1[i]);
  2296. for (j=0; j<c_resampleing_filter_hint->hor_tap_length_minus1[i]; j++) {
  2297. VLOG(INFO, " HOR_FILTER_COEFF[%d][%d]: %d \n", i, j, c_resampleing_filter_hint->hor_filter_coeff[i][j]);
  2298. }
  2299. }
  2300. }
  2301. }
  2302. }
  2303. if (idx == H265_USERDATA_FLAG_KNEE_FUNCTION_INFO) {
  2304. h265_knee_function_info_t* knee_function;
  2305. knee_function = (h265_knee_function_info_t*)(pBase + pEntry[H265_USERDATA_FLAG_KNEE_FUNCTION_INFO].offset);
  2306. VLOG(INFO, " FLAG_KNEE_FUNCTION_INFO\n");
  2307. VLOG(INFO, " KNEE_FUNCTION_ID: %10d\n", knee_function->knee_function_id);
  2308. VLOG(INFO, " KNEE_FUNCTION_CANCEL_FLAG: %d\n", knee_function->knee_function_cancel_flag);
  2309. if (!knee_function->knee_function_cancel_flag) {
  2310. int i;
  2311. VLOG(INFO, " KNEE_FUNCTION_PERSISTENCE_FLAG: %10d\n", knee_function->knee_function_persistence_flag);
  2312. VLOG(INFO, " INPUT_D_RANGE: %d\n", knee_function->input_d_range);
  2313. VLOG(INFO, " INPUT_DISP_LUMINANCE: %d\n", knee_function->input_disp_luminance);
  2314. VLOG(INFO, " OUTPUT_D_RANGE: %d\n", knee_function->output_d_range);
  2315. VLOG(INFO, " OUTPUT_DISP_LUMINANCE: %d\n", knee_function->output_disp_luminance);
  2316. VLOG(INFO, " NUM_KNEE_POINTS_M1: %d\n", knee_function->num_knee_points_minus1);
  2317. for (i=0; i<knee_function->num_knee_points_minus1; i++) {
  2318. VLOG(INFO, " INPUT_KNEE_POINT: %10d OUTPUT_KNEE_POINT: %10d\n", knee_function->input_knee_point[i], knee_function->output_knee_point[i]);
  2319. }
  2320. }
  2321. }
  2322. if (idx == H265_USERDATA_FLAG_ITU_T_T35_PRE)
  2323. {
  2324. char* itu_t_t35 = (char*)(pBase + pEntry[H265_USERDATA_FLAG_ITU_T_T35_PRE].offset);
  2325. Uint32 i;
  2326. VLOG(INFO, "ITU_T_T35_PRE = %d bytes, offset = %d\n",pEntry[H265_USERDATA_FLAG_ITU_T_T35_PRE].size, pEntry[H265_USERDATA_FLAG_ITU_T_T35_PRE].offset);
  2327. for(i=0; i<pEntry[H265_USERDATA_FLAG_ITU_T_T35_PRE].size; i++)
  2328. {
  2329. VLOG(INFO, "%02X ", (unsigned char)(itu_t_t35[i]));
  2330. }
  2331. VLOG(INFO, "\n");
  2332. }
  2333. if (idx == H265_USERDATA_FLAG_ITU_T_T35_PRE_1)
  2334. {
  2335. char* itu_t_t35 = (char*)(pBase + pEntry[H265_USERDATA_FLAG_ITU_T_T35_PRE_1].offset);
  2336. Uint32 i;
  2337. VLOG(INFO, "ITU_T_T35_PRE = %d bytes, offset = %d\n",pEntry[H265_USERDATA_FLAG_ITU_T_T35_PRE_1].size, pEntry[H265_USERDATA_FLAG_ITU_T_T35_PRE_1].offset);
  2338. for(i=0; i<pEntry[H265_USERDATA_FLAG_ITU_T_T35_PRE_1].size; i++)
  2339. {
  2340. VLOG(INFO, "%02X ", (unsigned char)(itu_t_t35[i]));
  2341. }
  2342. VLOG(INFO, "\n");
  2343. }
  2344. if (idx == H265_USERDATA_FLAG_ITU_T_T35_PRE_2)
  2345. {
  2346. char* itu_t_t35 = (char*)(pBase + pEntry[H265_USERDATA_FLAG_ITU_T_T35_PRE_2].offset);
  2347. Uint32 i;
  2348. //user_data_entry_t* pEntry_prev;
  2349. VLOG(INFO, "ITU_T_T35_PRE = %d bytes, offset = %d\n",pEntry[H265_USERDATA_FLAG_ITU_T_T35_PRE_2].size, pEntry[H265_USERDATA_FLAG_ITU_T_T35_PRE_2].offset);
  2350. for(i=0; i<pEntry[H265_USERDATA_FLAG_ITU_T_T35_PRE_2].size; i++)
  2351. {
  2352. VLOG(INFO, "%02X ", (unsigned char)(itu_t_t35[i]));
  2353. }
  2354. VLOG(INFO, "\n");
  2355. //pEntry_prev = (user_data_entry_t*)(itu_t_t35 + pEntry[H265_USERDATA_FLAG_ITU_T_T35_PRE_2].size - sizeof(user_data_entry_t));
  2356. //pEntry[H265_USERDATA_FLAG_ITU_T_T35_PRE_2].size = pEntry_prev->size;
  2357. //pEntry[H265_USERDATA_FLAG_ITU_T_T35_PRE_2].offset = pEntry_prev->offset;
  2358. }
  2359. if (idx == H265_USERDATA_FLAG_COLOUR_REMAPPING_INFO) {
  2360. int c, i;
  2361. h265_colour_remapping_info_t* colour_remapping;
  2362. colour_remapping = (h265_colour_remapping_info_t*)(pBase + pEntry[H265_USERDATA_FLAG_COLOUR_REMAPPING_INFO].offset);
  2363. VLOG(INFO, " COLOUR_REMAPPING_INFO\n");
  2364. VLOG(INFO, " COLOUR_REMAP_ID: %10d\n", colour_remapping->colour_remap_id);
  2365. VLOG(INFO, " COLOUR_REMAP_CANCEL_FLAG: %d\n", colour_remapping->colour_remap_cancel_flag);
  2366. if (!colour_remapping->colour_remap_cancel_flag) {
  2367. VLOG(INFO, " COLOUR_REMAP_PERSISTENCE_FLAG: %d\n", colour_remapping->colour_remap_persistence_flag);
  2368. VLOG(INFO, " COLOUR_REMAP_VIDEO_SIGNAL_INFO_PRESENT_FLAG: %d\n", colour_remapping->colour_remap_video_signal_info_present_flag);
  2369. if (colour_remapping->colour_remap_video_signal_info_present_flag) {
  2370. VLOG(INFO, " COLOUR_REMAP_FULL_RANGE_FLAG: %d\n", colour_remapping->colour_remap_full_range_flag);
  2371. VLOG(INFO, " COLOUR_REMAP_PRIMARIES: %d\n", colour_remapping->colour_remap_primaries);
  2372. VLOG(INFO, " COLOUR_REMAP_TRANSFER_FUNCTION: %d\n", colour_remapping->colour_remap_transfer_function);
  2373. VLOG(INFO, " COLOUR_REMAP_MATRIX_COEFFICIENTS: %d\n", colour_remapping->colour_remap_matrix_coefficients);
  2374. }
  2375. VLOG(INFO, " COLOUR_REMAP_INPUT_BIT_DEPTH: %d\n", colour_remapping->colour_remap_input_bit_depth);
  2376. VLOG(INFO, " COLOUR_REMAP_BIT_DEPTH: %d\n", colour_remapping->colour_remap_bit_depth);
  2377. for( c = 0; c < H265_MAX_LUT_NUM_VAL; c++ )
  2378. {
  2379. VLOG(INFO, " PRE_LUT_NUM_VAL_MINUS1[%d]: %d\n", c, colour_remapping->pre_lut_num_val_minus1[c]);
  2380. if(colour_remapping->pre_lut_num_val_minus1[c] > 0)
  2381. {
  2382. for( i = 0; i <= colour_remapping->pre_lut_num_val_minus1[c]; i++ )
  2383. {
  2384. VLOG(INFO, " PRE_LUT_CODED_VALUE[%d][%d]: %d\n", c, i, colour_remapping->pre_lut_coded_value[c][i]);
  2385. VLOG(INFO, " PRE_LUT_TARGET_VALUE[%d][%d]: %d\n", c, i, colour_remapping->pre_lut_target_value[c][i]);
  2386. }
  2387. }
  2388. }
  2389. VLOG(INFO, " COLOUR_REMAP_MATRIX_PRESENT_FLAG: %d\n", colour_remapping->colour_remap_matrix_present_flag);
  2390. if(colour_remapping->colour_remap_matrix_present_flag) {
  2391. VLOG(INFO, " LOG2_MATRIX_DENOM: %d\n", colour_remapping->log2_matrix_denom);
  2392. for( c = 0; c < H265_MAX_COLOUR_REMAP_COEFFS; c++ )
  2393. for( i = 0; i < H265_MAX_COLOUR_REMAP_COEFFS; i++ )
  2394. VLOG(INFO, " LOG2_MATRIX_DENOM[%d][%d]: %d\n", c, i, colour_remapping->colour_remap_coeffs[c][i]);
  2395. }
  2396. for( c = 0; c < H265_MAX_LUT_NUM_VAL; c++ )
  2397. {
  2398. VLOG(INFO, " POST_LUT_NUM_VAL_MINUS1[%d]: %d\n", c, colour_remapping->post_lut_num_val_minus1[c]);
  2399. if(colour_remapping->post_lut_num_val_minus1[c] > 0)
  2400. {
  2401. for( i = 0; i <= colour_remapping->post_lut_num_val_minus1[c]; i++)
  2402. {
  2403. VLOG(INFO, " POST_LUT_CODED_VALUE[%d][%d]: %d\n", c, i, colour_remapping->post_lut_coded_value[c][i]);
  2404. VLOG(INFO, " POST_LUT_TARGET_VALUE[%d][%d]: %d\n", c, i, colour_remapping->post_lut_target_value[c][i]);
  2405. }
  2406. }
  2407. }
  2408. }
  2409. }
  2410. if (idx == H265_USERDATA_FLAG_TONE_MAPPING_INFO) {
  2411. h265_tone_mapping_info_t* tone_mapping;
  2412. tone_mapping = (h265_tone_mapping_info_t*)(pBase + pEntry[H265_USERDATA_FLAG_TONE_MAPPING_INFO].offset);
  2413. VLOG(INFO, " FLAG_TONE_MAPPING_INFO\n");
  2414. VLOG(INFO, " TONE_MAP_ID: %10d\n", tone_mapping->tone_map_id);
  2415. VLOG(INFO, " TONE_MAP_CANCEL_FLAG: %d\n", tone_mapping->tone_map_cancel_flag);
  2416. if (!tone_mapping->tone_map_cancel_flag) {
  2417. int i;
  2418. VLOG(INFO, " TONE_MAP_PERSISTENCE_FLAG: %10d\n", tone_mapping->tone_map_persistence_flag);
  2419. VLOG(INFO, " CODED_DATA_BIT_DEPTH : %d\n", tone_mapping->coded_data_bit_depth);
  2420. VLOG(INFO, " TARGET_BIT_DEPTH : %d\n", tone_mapping->target_bit_depth);
  2421. VLOG(INFO, " TONE_MAP_MODEL_ID : %d\n", tone_mapping->tone_map_model_id);
  2422. VLOG(INFO, " MIN_VALUE : %d\n", tone_mapping->min_value);
  2423. VLOG(INFO, " MAX_VALUE : %d\n", tone_mapping->max_value);
  2424. VLOG(INFO, " SIGMOID_MIDPOINT : %d\n", tone_mapping->sigmoid_midpoint);
  2425. VLOG(INFO, " SIGMOID_MIDPOINT : %d\n", tone_mapping->sigmoid_width);
  2426. for (i=0; i<(1<<tone_mapping->target_bit_depth); i++) {
  2427. VLOG(INFO, " START_OF_CODED_INTERVAL[%d] : %d\n", i, tone_mapping->start_of_coded_interval[i]); // [1 << target_bit_depth] // 10bits
  2428. }
  2429. VLOG(INFO, " NUM_PIVOTS : %d\n", tone_mapping->num_pivots); // [(1 << coded_data_bit_depth)?1][(1 << target_bit_depth)-1] // 10bits
  2430. for (i=0; i<tone_mapping->num_pivots; i++) {
  2431. VLOG(INFO, " CODED_PIVOT_VALUE[%d] : %d, TARGET_PIVOT_VALUE[%d] : %d\n", i, tone_mapping->coded_pivot_value[i]
  2432. , i, tone_mapping->target_pivot_value[i]);
  2433. }
  2434. VLOG(INFO, " CAMERA_ISO_SPEED_IDC : %d\n", tone_mapping->camera_iso_speed_idc);
  2435. VLOG(INFO, " CAMERA_ISO_SPEED_VALUE : %d\n", tone_mapping->camera_iso_speed_value);
  2436. VLOG(INFO, " EXPOSURE_INDEX_IDC : %d\n", tone_mapping->exposure_index_idc);
  2437. VLOG(INFO, " EXPOSURE_INDEX_VALUE : %d\n", tone_mapping->exposure_index_value);
  2438. VLOG(INFO, " EXPOSURE_INDEX_COMPESATION_VALUE_SIGN_FLAG : %d\n", tone_mapping->exposure_compensation_value_sign_flag);
  2439. VLOG(INFO, " EXPOSURE_INDEX_COMPESATION_VALUE_NUMERATOR : %d\n", tone_mapping->exposure_compensation_value_numerator);
  2440. VLOG(INFO, " EXPOSURE_INDEX_COMPESATION_VALUE_DENOM_IDC : %d\n", tone_mapping->exposure_compensation_value_denom_idc);
  2441. VLOG(INFO, " REF_SCREEN_LUMINANCE_WHITE : %d\n", tone_mapping->ref_screen_luminance_white);
  2442. VLOG(INFO, " EXTENDED_RANGE_WHITE_LEVEL : %d\n", tone_mapping->extended_range_white_level);
  2443. VLOG(INFO, " NOMINAL_BLACK_LEVEL_CODE_VALUE : %d\n", tone_mapping->nominal_black_level_code_value);
  2444. VLOG(INFO, " NOMINAL_WHITE_LEVEL_CODE_VALUE : %d\n", tone_mapping->nominal_white_level_code_value);
  2445. VLOG(INFO, " EXTENDED_WHITE_LEVEL_CODE_VALUE : %d\n", tone_mapping->extended_white_level_code_value);
  2446. }
  2447. VLOG(INFO, "\n");
  2448. }
  2449. if (idx == H265_USERDATA_FLAG_CONTENT_LIGHT_LEVEL_INFO) {
  2450. h265_content_light_level_info_t* content_light_level;
  2451. content_light_level = (h265_content_light_level_info_t*)(pBase + pEntry[H265_USERDATA_FLAG_CONTENT_LIGHT_LEVEL_INFO].offset);
  2452. VLOG(INFO, " CONTNET_LIGHT_INFO\n");
  2453. VLOG(INFO, " MAX_CONTENT_LIGHT_LEVEL : %d\n", content_light_level->max_content_light_level);
  2454. VLOG(INFO, " MAX_PIC_AVERAGE_LIGHT_LEVEL : %d\n", content_light_level->max_pic_average_light_level);
  2455. VLOG(INFO, "\n");
  2456. }
  2457. if (idx == H265_USERDATA_FLAG_FILM_GRAIN_CHARACTERISTICS_INFO) {
  2458. h265_film_grain_characteristics_t* film_grain_characteristics;
  2459. int i,j,c;
  2460. film_grain_characteristics = (h265_film_grain_characteristics_t*)(pBase + pEntry[H265_USERDATA_FLAG_FILM_GRAIN_CHARACTERISTICS_INFO].offset);
  2461. VLOG(INFO, " FILM_GRAIN_CHARACTERISTICS_INFO\n");
  2462. VLOG(INFO, " FILM_GRAIN_CHARACTERISTICS_CANCEL_FLAG: %d\n", film_grain_characteristics->film_grain_characteristics_cancel_flag);
  2463. if (!film_grain_characteristics->film_grain_characteristics_cancel_flag) {
  2464. VLOG(INFO, " FILM_GRAIN_MODEL_ID: %10d\n", film_grain_characteristics->film_grain_model_id);
  2465. VLOG(INFO, " SEPARATE_COLOUR_DESCRIPTION_PRESENT_FLAG: %d\n", film_grain_characteristics->separate_colour_description_present_flag);
  2466. if (film_grain_characteristics->separate_colour_description_present_flag)
  2467. {
  2468. VLOG(INFO, " FILM_GRAIN_BIT_DEPTH_LUMA_MINUS8: %d\n", film_grain_characteristics->film_grain_bit_depth_luma_minus8);
  2469. VLOG(INFO, " FILM_GRAIN_BIT_DEPTH_CHROMA_MINUS8: %d\n", film_grain_characteristics->film_grain_bit_depth_chroma_minus8);
  2470. VLOG(INFO, " FILM_GRAIN_FULL_RANGE_FLAG: %d\n", film_grain_characteristics->film_grain_full_range_flag);
  2471. VLOG(INFO, " FILM_GRAIN_COLOUR_PRIMARIES: %d\n", film_grain_characteristics->film_grain_colour_primaries);
  2472. VLOG(INFO, " FILM_GRAIN_TRANSFER_CHARACTERISTICS: %d\n", film_grain_characteristics->film_grain_transfer_characteristics);
  2473. VLOG(INFO, " FILM_GRAIN_MATRIX_COEFF: %d\n", film_grain_characteristics->film_grain_matrix_coeffs);
  2474. }
  2475. }
  2476. VLOG(INFO, " BLENDING_MODE_ID: %d\n", film_grain_characteristics->blending_mode_id);
  2477. VLOG(INFO, " LOG2_SCALE_FACTOR: %d\n", film_grain_characteristics->log2_scale_factor);
  2478. for(c=0; c < H265_MAX_NUM_FILM_GRAIN_COMPONENT; c++ )
  2479. {
  2480. VLOG(INFO, " COMP_MODEL_PRESENT_FLAG[%d]: %d\n", c, film_grain_characteristics->comp_model_present_flag[c]);
  2481. }
  2482. for(c=0; c < H265_MAX_NUM_FILM_GRAIN_COMPONENT; c++ )
  2483. {
  2484. if(film_grain_characteristics->comp_model_present_flag[c])
  2485. {
  2486. VLOG(INFO, " NUM_INTENSITY_INTERVALS_MINUS1[%d]: %d\n", c, film_grain_characteristics->num_intensity_intervals_minus1[c]);
  2487. VLOG(INFO, " NUM_MODEL_VALUES_MINUS1[%d]: %d\n", c, film_grain_characteristics->num_model_values_minus1[c]);
  2488. for(i=0; i <= film_grain_characteristics->num_intensity_intervals_minus1[c]; i++)
  2489. {
  2490. VLOG(INFO, " INTENSITY_INTERVAL_LOWER_BOUND[%d][%d]: %d\n", c, i, film_grain_characteristics->intensity_interval_lower_bound[c][i]);
  2491. VLOG(INFO, " INTENSITY_INTERVAL_UPPER_BOUND[%d][%d]: %d\n", c, i, film_grain_characteristics->intensity_interval_upper_bound[c][i]);
  2492. for(j=0; j <= film_grain_characteristics->num_model_values_minus1[c]; j++)
  2493. {
  2494. VLOG(INFO, " COMP_MODEL_VALUE[%d][%d][%d]: %d\n", c, i, j, film_grain_characteristics->comp_model_value[c][i][j]);
  2495. }
  2496. }
  2497. }
  2498. }
  2499. VLOG(INFO, " FILM_GRAIN_CHARACTERISTICS_PERSISTENCE_FLAG: %d\n", film_grain_characteristics->film_grain_characteristics_persistence_flag);
  2500. VLOG(INFO, "\n");
  2501. }
  2502. }
  2503. }
  2504. VLOG(INFO, "===========================================\n");
  2505. }
  2506. void SetMapData(int coreIdx, TestEncConfig encConfig, EncOpenParam encOP, EncParam *encParam, int srcFrameWidth, int srcFrameHeight, unsigned long addrCustomMap)
  2507. {
  2508. int productId = VPU_GetProductId(coreIdx);
  2509. if (productId == PRODUCT_ID_521 && encOP.bitstreamFormat == STD_AVC) {
  2510. Uint8 roiMapBuf[MAX_MB_NUM] = {0,};
  2511. Uint8 modeMapBuf[MAX_MB_NUM] = {0,};
  2512. AvcEncCustomMap customMapBuf[MAX_MB_NUM]; // custom map 1 MB data = 8bits
  2513. int MbWidth = VPU_ALIGN16(encOP.picWidth) >> 4;
  2514. int MbHeight = VPU_ALIGN16(encOP.picHeight) >> 4;
  2515. int h, w, mbAddr;
  2516. osal_memset(&customMapBuf[0], 0x00, MAX_MB_NUM);
  2517. if (encParam->customMapOpt.customRoiMapEnable == 1) {
  2518. int sumQp = 0;
  2519. int bufSize = MbWidth*MbHeight;
  2520. if (osal_fread(&roiMapBuf[0], 1, bufSize, encConfig.roi_file) != bufSize) {
  2521. osal_fseek(encConfig.roi_file, 0, SEEK_SET);
  2522. osal_fread(&roiMapBuf[0], 1, bufSize, encConfig.roi_file);
  2523. }
  2524. for (h = 0; h < MbHeight; h++) {
  2525. for (w = 0; w < MbWidth; w++) {
  2526. mbAddr = w + h*MbWidth;
  2527. customMapBuf[mbAddr].field.mb_qp = MAX(MIN(roiMapBuf[mbAddr]&0x3f, 51), 0);
  2528. sumQp += customMapBuf[mbAddr].field.mb_qp;
  2529. }
  2530. }
  2531. encParam->customMapOpt.roiAvgQp = (sumQp + (bufSize>>1)) / bufSize; // round off.
  2532. }
  2533. if (encParam->customMapOpt.customModeMapEnable == 1) {
  2534. int bufSize = MbWidth*MbHeight;
  2535. if (osal_fread(&modeMapBuf[0], 1, bufSize, encConfig.mode_map_file) != bufSize) {
  2536. osal_fseek(encConfig.mode_map_file, 0, SEEK_SET);
  2537. osal_fread(&modeMapBuf[0], 1, bufSize, encConfig.mode_map_file);
  2538. }
  2539. for (h = 0; h < MbHeight; h++) {
  2540. for (w = 0; w < MbWidth; w++) {
  2541. mbAddr = w + h*MbWidth;
  2542. customMapBuf[mbAddr].field.mb_force_mode = modeMapBuf[mbAddr] & 0x3;
  2543. }
  2544. }
  2545. }
  2546. encParam->customMapOpt.addrCustomMap = addrCustomMap;
  2547. vdi_write_memory(coreIdx, encParam->customMapOpt.addrCustomMap, (unsigned char*)customMapBuf, MAX_MB_NUM, VDI_LITTLE_ENDIAN);
  2548. }
  2549. else {
  2550. // for HEVC custom map.
  2551. Uint8 roiMapBuf[MAX_SUB_CTU_NUM] = {0,};
  2552. Uint8 lambdaMapBuf[MAX_SUB_CTU_NUM] = {0,};
  2553. Uint8 modeMapBuf[MAX_CTU_NUM] = {0,};
  2554. EncCustomMap customMapBuf[MAX_CTU_NUM]; // custom map 1 CTU data = 64bits
  2555. int ctuMapWidthCnt = VPU_ALIGN64(encOP.picWidth) >> 6;
  2556. int ctuMapHeightCnt = VPU_ALIGN64(encOP.picHeight) >> 6;
  2557. int ctuMapStride = VPU_ALIGN64(encOP.picWidth) >> 6;
  2558. int subCtuMapStride = VPU_ALIGN64(encOP.picWidth) >> 5;
  2559. int i, sumQp = 0;;
  2560. int h, w, ctuPos, initQp;
  2561. Uint8* src;
  2562. VpuRect region[MAX_ROI_NUMBER]; /**< The size of the ROI region for H.265 (start X/Y in CTU, end X/Y int CTU) */
  2563. int roiQp[MAX_ROI_NUMBER]; /**< An importance level for the given ROI region for H.265. The higher an ROI level is, the more important the region is with a lower QP. */
  2564. osal_memset(&customMapBuf[0], 0x00, MAX_CTU_NUM * 8);
  2565. if (encParam->customMapOpt.customRoiMapEnable == 1) {
  2566. int bufSize = (VPU_ALIGN64(encOP.picWidth) >> 5) * (VPU_ALIGN64(encOP.picHeight) >> 5);
  2567. if (productId == PRODUCT_ID_521) {
  2568. if (osal_fread(&roiMapBuf[0], 1, bufSize, encConfig.roi_file) != bufSize) {
  2569. osal_fseek(encConfig.roi_file, 0, SEEK_SET);
  2570. osal_fread(&roiMapBuf[0], 1, bufSize, encConfig.roi_file);
  2571. }
  2572. }
  2573. else {
  2574. int roiNum = 0;
  2575. // sample code to convert ROI coordinate to ROI map.
  2576. osal_memset(&region[0], 0, sizeof(VpuRect)*MAX_ROI_NUMBER);
  2577. osal_memset(&roiQp[0], 0, sizeof(int)*MAX_ROI_NUMBER);
  2578. if (encConfig.roi_file_name[0]) {
  2579. char lineStr[256] = {0,};
  2580. int val;
  2581. fgets(lineStr, 256, encConfig.roi_file);
  2582. sscanf(lineStr, "%x\n", &val);
  2583. if (val != 0xFFFF)
  2584. VLOG(ERR, "can't find the picture delimiter \n");
  2585. fgets(lineStr, 256, encConfig.roi_file);
  2586. sscanf(lineStr, "%d\n", &val); // picture index
  2587. fgets(lineStr, 256, encConfig.roi_file);
  2588. sscanf(lineStr, "%d\n", &roiNum); // number of roi regions
  2589. for (i = 0; i < roiNum; i++) {
  2590. fgets(lineStr, 256, encConfig.roi_file);
  2591. if (parseRoiCtuModeParam(lineStr, &region[i], &roiQp[i], srcFrameWidth, srcFrameHeight) == 0) {
  2592. VLOG(ERR, "CFG file error : %s value is not available. \n", encConfig.roi_file_name);
  2593. }
  2594. }
  2595. }
  2596. encParam->customMapOpt.customRoiMapEnable = (roiNum != 0) ? encParam->customMapOpt.customRoiMapEnable : 0;
  2597. if (encParam->customMapOpt.customRoiMapEnable) {
  2598. initQp = encConfig.roi_avg_qp;
  2599. GenRegionToQpMap(&region[0], &roiQp[0], roiNum, initQp, subCtuMapStride, VPU_ALIGN64(encOP.picHeight) >> 5, &roiMapBuf[0]);
  2600. }
  2601. }
  2602. for (h = 0; h < ctuMapHeightCnt; h++) {
  2603. src = &roiMapBuf[subCtuMapStride * h * 2];
  2604. for (w = 0; w < ctuMapWidthCnt; w++, src += 2) {
  2605. ctuPos = (h * ctuMapStride + w);
  2606. // store in the order of sub-ctu.
  2607. customMapBuf[ctuPos].field.sub_ctu_qp_0 = MAX(MIN(*src, 51), 0);
  2608. customMapBuf[ctuPos].field.sub_ctu_qp_1 = MAX(MIN(*(src + 1), 51), 0);
  2609. customMapBuf[ctuPos].field.sub_ctu_qp_2 = MAX(MIN(*(src + subCtuMapStride), 51), 0);
  2610. customMapBuf[ctuPos].field.sub_ctu_qp_3 = MAX(MIN(*(src + subCtuMapStride + 1), 51), 0);
  2611. sumQp += (customMapBuf[ctuPos].field.sub_ctu_qp_0 + customMapBuf[ctuPos].field.sub_ctu_qp_1 + customMapBuf[ctuPos].field.sub_ctu_qp_2 + customMapBuf[ctuPos].field.sub_ctu_qp_3);
  2612. }
  2613. }
  2614. if (productId == PRODUCT_ID_521)
  2615. encParam->customMapOpt.roiAvgQp = (sumQp + (bufSize>>1)) / bufSize; // round off.
  2616. }
  2617. if (encParam->customMapOpt.customLambdaMapEnable == 1) {
  2618. int bufSize = (VPU_ALIGN64(encOP.picWidth) >> 5) * (VPU_ALIGN64(encOP.picHeight) >> 5);
  2619. if (osal_fread(&lambdaMapBuf[0], 1, bufSize, encConfig.lambda_map_file) != bufSize) {
  2620. osal_fseek(encConfig.lambda_map_file, 0, SEEK_SET);
  2621. osal_fread(&lambdaMapBuf[0], 1, bufSize, encConfig.lambda_map_file);
  2622. }
  2623. for (h = 0; h < ctuMapHeightCnt; h++) {
  2624. src = &lambdaMapBuf[subCtuMapStride * 2 * h];
  2625. for (w = 0; w < ctuMapWidthCnt; w++, src += 2) {
  2626. ctuPos = (h * ctuMapStride + w);
  2627. // store in the order of sub-ctu.
  2628. customMapBuf[ctuPos].field.lambda_sad_0 = *src;
  2629. customMapBuf[ctuPos].field.lambda_sad_1 = *(src + 1);
  2630. customMapBuf[ctuPos].field.lambda_sad_2 = *(src + subCtuMapStride);
  2631. customMapBuf[ctuPos].field.lambda_sad_3 = *(src + subCtuMapStride + 1);
  2632. }
  2633. }
  2634. }
  2635. if ((encParam->customMapOpt.customModeMapEnable == 1)
  2636. || (encParam->customMapOpt.customCoefDropEnable == 1)) {
  2637. int bufSize = (VPU_ALIGN64(encOP.picWidth) >> 6) * (VPU_ALIGN64(encOP.picHeight) >> 6);
  2638. if (osal_fread(&modeMapBuf[0], 1, bufSize, encConfig.mode_map_file) != bufSize) {
  2639. osal_fseek(encConfig.mode_map_file, 0, SEEK_SET);
  2640. osal_fread(&modeMapBuf[0], 1, bufSize, encConfig.mode_map_file);
  2641. }
  2642. for (h = 0; h < ctuMapHeightCnt; h++) {
  2643. src = &modeMapBuf[ctuMapStride * h];
  2644. for (w = 0; w < ctuMapWidthCnt; w++, src++) {
  2645. ctuPos = (h * ctuMapStride + w);
  2646. customMapBuf[ctuPos].field.ctu_force_mode = (*src) & 0x3;
  2647. customMapBuf[ctuPos].field.ctu_coeff_drop = ((*src) >> 2) & 0x1;
  2648. }
  2649. }
  2650. }
  2651. encParam->customMapOpt.addrCustomMap = addrCustomMap;
  2652. vdi_write_memory(coreIdx, encParam->customMapOpt.addrCustomMap, (unsigned char*)customMapBuf, MAX_CTU_NUM * 8, VDI_LITTLE_ENDIAN);
  2653. }
  2654. }
  2655. RetCode SetChangeParam(EncHandle handle, TestEncConfig encConfig, EncOpenParam encOP, Int32 changedCount)
  2656. {
  2657. int i;
  2658. RetCode ret;
  2659. ENC_CFG ParaChagCfg;
  2660. EncChangeParam changeParam;
  2661. osal_memset(&ParaChagCfg, 0x00, sizeof(ENC_CFG));
  2662. osal_memset(&changeParam, 0x00, sizeof(EncChangeParam));
  2663. parseWaveChangeParamCfgFile(&ParaChagCfg, encConfig.changeParam[changedCount].cfgName);
  2664. changeParam.enable_option = encConfig.changeParam[changedCount].enableOption;
  2665. if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_PPS) {
  2666. changeParam.constIntraPredFlag = ParaChagCfg.waveCfg.constIntraPredFlag;
  2667. changeParam.lfCrossSliceBoundaryEnable = ParaChagCfg.waveCfg.lfCrossSliceBoundaryEnable;
  2668. changeParam.weightPredEnable = ParaChagCfg.waveCfg.weightPredEnable;
  2669. changeParam.disableDeblk = ParaChagCfg.waveCfg.disableDeblk;
  2670. changeParam.betaOffsetDiv2 = ParaChagCfg.waveCfg.betaOffsetDiv2;
  2671. changeParam.tcOffsetDiv2 = ParaChagCfg.waveCfg.tcOffsetDiv2;
  2672. changeParam.chromaCbQpOffset = ParaChagCfg.waveCfg.chromaCbQpOffset;
  2673. changeParam.chromaCrQpOffset = ParaChagCfg.waveCfg.chromaCrQpOffset;
  2674. if (encConfig.stdMode == STD_AVC) {
  2675. changeParam.transform8x8Enable = ParaChagCfg.waveCfg.transform8x8;
  2676. changeParam.entropyCodingMode = ParaChagCfg.waveCfg.entropyCodingMode;
  2677. }
  2678. }
  2679. if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_INDEPEND_SLICE) {
  2680. changeParam.independSliceMode = ParaChagCfg.waveCfg.independSliceMode;
  2681. changeParam.independSliceModeArg = ParaChagCfg.waveCfg.independSliceModeArg;
  2682. if (encConfig.stdMode == STD_AVC) {
  2683. changeParam.avcSliceMode = ParaChagCfg.waveCfg.avcSliceMode;
  2684. changeParam.avcSliceArg = ParaChagCfg.waveCfg.avcSliceArg;
  2685. }
  2686. }
  2687. if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_DEPEND_SLICE) {
  2688. changeParam.dependSliceMode = ParaChagCfg.waveCfg.dependSliceMode;
  2689. changeParam.dependSliceModeArg = ParaChagCfg.waveCfg.dependSliceModeArg;
  2690. }
  2691. if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_RDO) {
  2692. changeParam.coefClearDisable = ParaChagCfg.waveCfg.coefClearDisable;
  2693. changeParam.intraNxNEnable = ParaChagCfg.waveCfg.intraNxNEnable;
  2694. changeParam.maxNumMerge = ParaChagCfg.waveCfg.maxNumMerge;
  2695. changeParam.customLambdaEnable = ParaChagCfg.waveCfg.customLambdaEnable;
  2696. changeParam.customMDEnable = ParaChagCfg.waveCfg.customMDEnable;
  2697. if (encConfig.stdMode == STD_AVC) {
  2698. changeParam.rdoSkip = ParaChagCfg.waveCfg.rdoSkip;
  2699. changeParam.lambdaScalingEnable = ParaChagCfg.waveCfg.lambdaScalingEnable;
  2700. }
  2701. }
  2702. if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_RC_TARGET_RATE) {
  2703. changeParam.bitRate = ParaChagCfg.RcBitRate;
  2704. }
  2705. if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_RC) {
  2706. changeParam.hvsQPEnable = ParaChagCfg.waveCfg.hvsQPEnable;
  2707. changeParam.hvsQpScale = ParaChagCfg.waveCfg.hvsQpScale;
  2708. changeParam.vbvBufferSize = ParaChagCfg.VbvBufferSize;
  2709. }
  2710. if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_RC_MIN_MAX_QP) {
  2711. changeParam.minQpI = ParaChagCfg.waveCfg.minQp;
  2712. changeParam.maxQpI = ParaChagCfg.waveCfg.maxQp;
  2713. changeParam.hvsMaxDeltaQp = ParaChagCfg.waveCfg.maxDeltaQp;
  2714. }
  2715. if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_RC_INTER_MIN_MAX_QP) {
  2716. changeParam.minQpP = ParaChagCfg.waveCfg.minQp;
  2717. changeParam.minQpB = ParaChagCfg.waveCfg.minQp;
  2718. changeParam.maxQpP = ParaChagCfg.waveCfg.maxQp;
  2719. changeParam.maxQpB = ParaChagCfg.waveCfg.maxQp;
  2720. }
  2721. if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_RC_BIT_RATIO_LAYER) {
  2722. for (i=0 ; i<MAX_GOP_NUM; i++)
  2723. changeParam.fixedBitRatio[i] = ParaChagCfg.waveCfg.fixedBitRatio[i];
  2724. }
  2725. if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_BG) {
  2726. changeParam.s2fmeDisable = ParaChagCfg.waveCfg.s2fmeDisable;
  2727. changeParam.bgThrDiff = ParaChagCfg.waveCfg.bgThrDiff;
  2728. changeParam.bgThrMeanDiff = ParaChagCfg.waveCfg.bgThrMeanDiff;
  2729. changeParam.bgLambdaQp = ParaChagCfg.waveCfg.bgLambdaQp;
  2730. changeParam.bgDeltaQp = ParaChagCfg.waveCfg.bgDeltaQp;
  2731. changeParam.s2fmeDisable = ParaChagCfg.waveCfg.s2fmeDisable;
  2732. }
  2733. if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_NR) {
  2734. changeParam.nrYEnable = ParaChagCfg.waveCfg.nrYEnable;
  2735. changeParam.nrCbEnable = ParaChagCfg.waveCfg.nrCbEnable;
  2736. changeParam.nrCrEnable = ParaChagCfg.waveCfg.nrCrEnable;
  2737. changeParam.nrNoiseEstEnable = ParaChagCfg.waveCfg.nrNoiseEstEnable;
  2738. changeParam.nrNoiseSigmaY = ParaChagCfg.waveCfg.nrNoiseSigmaY;
  2739. changeParam.nrNoiseSigmaCb = ParaChagCfg.waveCfg.nrNoiseSigmaCb;
  2740. changeParam.nrNoiseSigmaCr = ParaChagCfg.waveCfg.nrNoiseSigmaCr;
  2741. changeParam.nrIntraWeightY = ParaChagCfg.waveCfg.nrIntraWeightY;
  2742. changeParam.nrIntraWeightCb = ParaChagCfg.waveCfg.nrIntraWeightCb;
  2743. changeParam.nrIntraWeightCr = ParaChagCfg.waveCfg.nrIntraWeightCr;
  2744. changeParam.nrInterWeightY = ParaChagCfg.waveCfg.nrInterWeightY;
  2745. changeParam.nrInterWeightCb = ParaChagCfg.waveCfg.nrInterWeightCb;
  2746. changeParam.nrInterWeightCr = ParaChagCfg.waveCfg.nrInterWeightCr;
  2747. }
  2748. if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_CUSTOM_MD) {
  2749. changeParam.pu04DeltaRate = ParaChagCfg.waveCfg.pu04DeltaRate;
  2750. changeParam.pu08DeltaRate = ParaChagCfg.waveCfg.pu08DeltaRate;
  2751. changeParam.pu16DeltaRate = ParaChagCfg.waveCfg.pu16DeltaRate;
  2752. changeParam.pu32DeltaRate = ParaChagCfg.waveCfg.pu32DeltaRate;
  2753. changeParam.pu04IntraPlanarDeltaRate = ParaChagCfg.waveCfg.pu04IntraPlanarDeltaRate;
  2754. changeParam.pu04IntraDcDeltaRate = ParaChagCfg.waveCfg.pu04IntraDcDeltaRate;
  2755. changeParam.pu04IntraAngleDeltaRate = ParaChagCfg.waveCfg.pu04IntraAngleDeltaRate;
  2756. changeParam.pu08IntraPlanarDeltaRate = ParaChagCfg.waveCfg.pu08IntraPlanarDeltaRate;
  2757. changeParam.pu08IntraDcDeltaRate = ParaChagCfg.waveCfg.pu08IntraDcDeltaRate;
  2758. changeParam.pu08IntraAngleDeltaRate = ParaChagCfg.waveCfg.pu08IntraAngleDeltaRate;
  2759. changeParam.pu16IntraPlanarDeltaRate = ParaChagCfg.waveCfg.pu16IntraPlanarDeltaRate;
  2760. changeParam.pu16IntraDcDeltaRate = ParaChagCfg.waveCfg.pu16IntraDcDeltaRate;
  2761. changeParam.pu16IntraAngleDeltaRate = ParaChagCfg.waveCfg.pu16IntraAngleDeltaRate;
  2762. changeParam.pu32IntraPlanarDeltaRate = ParaChagCfg.waveCfg.pu32IntraPlanarDeltaRate;
  2763. changeParam.pu32IntraDcDeltaRate = ParaChagCfg.waveCfg.pu32IntraDcDeltaRate;
  2764. changeParam.pu32IntraAngleDeltaRate = ParaChagCfg.waveCfg.pu32IntraAngleDeltaRate;
  2765. changeParam.cu08IntraDeltaRate = ParaChagCfg.waveCfg.cu08IntraDeltaRate;
  2766. changeParam.cu08InterDeltaRate = ParaChagCfg.waveCfg.cu08InterDeltaRate;
  2767. changeParam.cu08MergeDeltaRate = ParaChagCfg.waveCfg.cu08MergeDeltaRate;
  2768. changeParam.cu16IntraDeltaRate = ParaChagCfg.waveCfg.cu16IntraDeltaRate;
  2769. changeParam.cu16InterDeltaRate = ParaChagCfg.waveCfg.cu16InterDeltaRate;
  2770. changeParam.cu16MergeDeltaRate = ParaChagCfg.waveCfg.cu16MergeDeltaRate;
  2771. changeParam.cu32IntraDeltaRate = ParaChagCfg.waveCfg.cu32IntraDeltaRate;
  2772. changeParam.cu32InterDeltaRate = ParaChagCfg.waveCfg.cu32InterDeltaRate;
  2773. changeParam.cu32MergeDeltaRate = ParaChagCfg.waveCfg.cu32MergeDeltaRate;
  2774. }
  2775. if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_INTRA_PARAM) {
  2776. changeParam.intraQP = ParaChagCfg.waveCfg.intraQP;
  2777. changeParam.intraPeriod = ParaChagCfg.waveCfg.intraPeriod;
  2778. }
  2779. ret = VPU_EncGiveCommand(handle, ENC_SET_PARA_CHANGE, &changeParam);
  2780. return ret;
  2781. }
  2782. BOOL GetBitstreamToBuffer(
  2783. EncHandle handle,
  2784. Uint8* pBuffer,
  2785. PhysicalAddress rdAddr,
  2786. PhysicalAddress wrAddr,
  2787. PhysicalAddress streamBufStartAddr,
  2788. PhysicalAddress streamBufEndAddr,
  2789. Uint32 streamSize,
  2790. EndianMode endian,
  2791. BOOL ringbufferEnabled
  2792. )
  2793. {
  2794. Int32 coreIdx = -1;
  2795. Uint32 room = 0;
  2796. if (NULL == handle) {
  2797. VLOG(ERR, "<%s:%d> NULL point exception\n", __FUNCTION__, __LINE__);
  2798. return FALSE;
  2799. }
  2800. coreIdx = VPU_HANDLE_CORE_INDEX(handle);
  2801. if (0 == streamBufStartAddr || 0 == streamBufEndAddr) {
  2802. VLOG(ERR, "<%s:%d> Wrong Address, start or end Addr\n", __FUNCTION__, __LINE__);
  2803. return FALSE;
  2804. } else if (0 == rdAddr || 0 == wrAddr) {
  2805. VLOG(ERR, "<%s:%d> Wrong Address, read or write Addr\n", __FUNCTION__, __LINE__);
  2806. return FALSE;
  2807. }
  2808. if (TRUE == ringbufferEnabled) {
  2809. if ((rdAddr + streamSize) > streamBufEndAddr) {
  2810. //wrap around on ringbuffer
  2811. room = streamBufEndAddr - rdAddr;
  2812. vdi_read_memory(coreIdx, rdAddr, pBuffer, room, endian);
  2813. vdi_read_memory(coreIdx, streamBufStartAddr, pBuffer + room, (streamSize-room), endian);
  2814. }
  2815. else {
  2816. vdi_read_memory(coreIdx, rdAddr, pBuffer, streamSize, endian);
  2817. }
  2818. } else { //Line buffer
  2819. vdi_read_memory(coreIdx, rdAddr, pBuffer, streamSize, endian);
  2820. }
  2821. return TRUE;
  2822. }