main_helper.c 130 KB

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