12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167 |
- // SPDX-License-Identifier: LGPL-2.1 OR BSD-3-Clause
- /*
- * Copyright (c) 2019, Chips&Media
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- #include <stdio.h>
- #include <stdarg.h>
- #include <string.h>
- #include <time.h>
- #include <errno.h>
- #include "vpuapifunc.h"
- #include "coda9/coda9_regdefine.h"
- #include "wave/wave5_regdefine.h"
- #include "vpuerror.h"
- #include "main_helper.h"
- #include "misc/debug.h"
- #if defined(PLATFORM_NON_OS) || defined (PLATFORM_LINUX)
- #include <getopt.h>
- #endif
- #if defined(PLATFORM_LINUX) || defined(PLATFORM_QNX) || defined(PLATFORM_NON_OS)
- #include <sys/stat.h>
- #include <unistd.h>
- #endif
- #define BIT_DUMMY_READ_GEN 0x06000000
- #define BIT_READ_LATENCY 0x06000004
- #define W5_SET_READ_DELAY 0x01000000
- #define W5_SET_WRITE_DELAY 0x01000004
- #define MAX_CODE_BUF_SIZE (512*1024)
- #ifdef PLATFORM_WIN32
- #pragma warning(disable : 4996) //!<< disable waring C4996: The POSIX name for this item is deprecated.
- #endif
- char* EncPicTypeStringH264[] = {
- "IDR/I",
- "P",
- };
- char* EncPicTypeStringMPEG4[] = {
- "I",
- "P",
- };
- static osal_mutex_t s_loadBalancerLock;
- static Uint32 s_nextInstance;
- static BOOL s_enableLoadBalance;
- static Uint32 s_instances[MAX_NUM_INSTANCE];
- enum {
- LB_STATE_NONE,
- LB_STATE_RUNNING
- };
- void LoadBalancerInit(void)
- {
- s_loadBalancerLock = osal_mutex_create();
- s_nextInstance = 0;
- s_enableLoadBalance = TRUE;
- osal_memset((void*)s_instances, 0x00, sizeof(s_instances));
- }
- void LoadBalancerRelease(void)
- {
- if (TRUE == s_enableLoadBalance) {
- osal_mutex_destroy(s_loadBalancerLock);
- }
- }
- void LoadBalancerAddInstance(Uint32 instanceIndex)
- {
- if (TRUE == s_enableLoadBalance) {
- osal_mutex_lock(s_loadBalancerLock);
- s_instances[instanceIndex] = LB_STATE_RUNNING;
- osal_mutex_unlock(s_loadBalancerLock);
- }
- }
- void LoadBalancerRemoveInstance(Uint32 instanceIndex)
- {
- if (TRUE == s_enableLoadBalance) {
- osal_mutex_lock(s_loadBalancerLock);
- s_instances[instanceIndex] = LB_STATE_NONE;
- if (s_nextInstance == instanceIndex) {
- Uint32 i = instanceIndex;
- Uint32 count=0;
- while (MAX_NUM_INSTANCE > count) {
- i = (i+1) % MAX_NUM_INSTANCE;
- if (LB_STATE_RUNNING == s_instances[i]) {
- s_nextInstance = i;
- break;
- }
- count++;
- }
- }
- osal_mutex_unlock(s_loadBalancerLock);
- }
- }
- BOOL LoadBalancerGetMyTurn(Uint32 myInstance)
- {
- BOOL myTurn = TRUE;
- if (TRUE == s_enableLoadBalance) {
- osal_mutex_lock(s_loadBalancerLock);
- myTurn = (BOOL)(myInstance == s_nextInstance);
- osal_mutex_unlock(s_loadBalancerLock);
- }
- return myTurn;
- }
- void LoadBalancerSetNextTurn(void)
- {
- if (TRUE == s_enableLoadBalance) {
- osal_mutex_lock(s_loadBalancerLock);
- do {
- s_nextInstance++;
- s_nextInstance %= MAX_NUM_INSTANCE;
- } while (LB_STATE_NONE == s_instances[s_nextInstance]);
- osal_mutex_unlock(s_loadBalancerLock);
- }
- }
- void SetDefaultDecTestConfig(TestDecConfig* testConfig)
- {
- osal_memset(testConfig, 0, sizeof(TestDecConfig));
- testConfig->bitstreamMode = BS_MODE_INTERRUPT;
- testConfig->feedingMode = FEEDING_METHOD_FIXED_SIZE;
- testConfig->streamEndian = VPU_STREAM_ENDIAN;
- testConfig->frameEndian = VPU_FRAME_ENDIAN;
- testConfig->cbcrInterleave = FALSE;
- testConfig->nv21 = FALSE;
- testConfig->bitFormat = STD_HEVC;
- testConfig->renderType = RENDER_DEVICE_NULL;
- testConfig->mapType = COMPRESSED_FRAME_MAP;
- testConfig->enableWTL = TRUE;
- testConfig->wtlMode = FF_FRAME;
- testConfig->wtlFormat = FORMAT_420; //!<< 8 bit YUV
- testConfig->wave.bwOptimization = FALSE; //!<< TRUE: non-ref pictures are not stored at reference picture buffer
- //!<< for saving bandwidth.
- testConfig->wave.av1Format = 0;
- testConfig->fps = 30;
- }
- void Coda9SetDefaultDecTestConfig(TestDecConfig* testConfig)
- {
- osal_memset(testConfig, 0, sizeof(TestDecConfig));
- testConfig->bitstreamMode = BS_MODE_INTERRUPT;
- testConfig->feedingMode = FEEDING_METHOD_FIXED_SIZE;
- testConfig->streamEndian = VPU_STREAM_ENDIAN;
- testConfig->frameEndian = VPU_FRAME_ENDIAN;
- testConfig->cbcrInterleave = FALSE;
- testConfig->nv21 = FALSE;
- testConfig->bitFormat = STD_AVC;
- testConfig->renderType = RENDER_DEVICE_NULL;
- testConfig->mapType = LINEAR_FRAME_MAP;
- testConfig->wtlMode = FF_NONE;
- testConfig->enableWTL = FALSE;
- testConfig->wtlFormat = FORMAT_420; //!<< 8 bit YUV
- testConfig->fps = 30;
- testConfig->coda9.frameCacheBypass = 0;
- testConfig->coda9.frameCacheBurst = 0;
- testConfig->coda9.frameCacheMerge = 3;
- testConfig->coda9.frameCacheWayShape = 15;
- testConfig->coda9.rotate = 0;
- testConfig->coda9.mirror = 0;
- testConfig->coda9.enableTiled2Linear = FALSE;
- testConfig->coda9.tiled2LinearMode = FF_NONE;
- testConfig->coda9.enableDering = FALSE;
- testConfig->coda9.enableBWB = VPU_ENABLE_BWB;
- }
- Uint32 randomSeed;
- static BOOL initializedRandom;
- Uint32 GetRandom(
- Uint32 start,
- Uint32 end
- )
- {
- Uint32 range = end-start+1;
- if (randomSeed == 0) {
- randomSeed = (Uint32)time(NULL);
- VLOG(INFO, "======= RANDOM SEED: %08x ======\n", randomSeed);
- }
- if (initializedRandom == FALSE) {
- srand(randomSeed);
- initializedRandom = TRUE;
- }
- if (range == 0) {
- VLOG(ERR, "%s:%d RANGE IS 0\n", __FUNCTION__, __LINE__);
- return 0;
- }
- else {
- return ((rand()%range) + start);
- }
- }
- Int32 LoadFirmware(
- Int32 productId,
- Uint8** retFirmware,
- Uint32* retSizeInWord,
- const char* path
- )
- {
- Int32 nread;
- Uint32 totalRead, allocSize, readSize = 1024*1024;
- Uint8* firmware = NULL;
- osal_file_t fp;
- if ((fp=osal_fopen(path, "rb")) == NULL)
- {
- VLOG(ERR, "Failed to open %s\n", path);
- return -1;
- }
- totalRead = 0;
- if (PRODUCT_ID_W_SERIES(productId))
- {
- firmware = (Uint8*)osal_malloc(readSize);
- allocSize = readSize;
- nread = 0;
- while (TRUE)
- {
- if (allocSize < (totalRead+readSize))
- {
- allocSize += 2*nread;
- firmware = (Uint8*)realloc(firmware, allocSize);
- }
- nread = osal_fread((void*)&firmware[totalRead], 1, readSize, fp);//lint !e613
- totalRead += nread;
- if (nread < (Int32)readSize)
- break;
- }
- *retSizeInWord = (totalRead+1)/2;
- }
- else
- {
- Uint16* pusBitCode;
- pusBitCode = (Uint16 *)osal_malloc(MAX_CODE_BUF_SIZE);
- firmware = (Uint8*)pusBitCode;
- if (pusBitCode)
- {
- int code;
- while (!osal_feof(fp) || totalRead < (MAX_CODE_BUF_SIZE/2)) {
- code = -1;
- if (fscanf(fp, "%x", &code) <= 0) {
- /* matching failure or EOF */
- break;
- }
- pusBitCode[totalRead++] = (Uint16)code;
- }
- }
- *retSizeInWord = totalRead;
- }
- osal_fclose(fp);
- *retFirmware = firmware;
- return 0;
- }
- void PrintVpuVersionInfo(
- Uint32 core_idx
- )
- {
- Uint32 version;
- Uint32 revision;
- Uint32 productId;
- VPU_GetVersionInfo(core_idx, &version, &revision, &productId);
- VLOG(INFO, "VPU coreNum : [%d]\n", core_idx);
- VLOG(INFO, "Firmware : CustomerCode: %04x | version : %d.%d.%d rev.%d\n",
- (Uint32)(version>>16), (Uint32)((version>>(12))&0x0f), (Uint32)((version>>(8))&0x0f), (Uint32)((version)&0xff), revision);
- VLOG(INFO, "Hardware : %04x\n", productId);
- VLOG(INFO, "API : %d.%d.%d\n\n", API_VERSION_MAJOR, API_VERSION_MINOR, API_VERSION_PATCH);
- }
- BOOL OpenDisplayBufferFile(CodStd codec, char *outputPath, VpuRect rcDisplay, TiledMapType mapType, FILE *fp[])
- {
- char strFile[MAX_FILE_PATH];
- int width;
- int height;
- width = rcDisplay.right - rcDisplay.left;
- height = rcDisplay.bottom - rcDisplay.top;
- if (mapType == LINEAR_FRAME_MAP) {
- if ((fp[0]=osal_fopen(outputPath, "wb")) == NULL) {
- VLOG(ERR, "%s:%d failed to open %s\n", __FUNCTION__, __LINE__, outputPath);
- goto ERR_OPEN_DISP_BUFFER_FILE;
- }
- }
- else {
- width = (codec == STD_HEVC || codec == STD_AVS2) ? VPU_ALIGN16(width) : VPU_ALIGN64(width);
- height = (codec == STD_HEVC || codec == STD_AVS2) ? VPU_ALIGN16(height) : VPU_ALIGN64(height);
- sprintf(strFile, "%s_%dx%d_fbc_data_y.bin", outputPath, width, height);
- if ((fp[0]=osal_fopen(strFile, "wb")) == NULL) {
- VLOG(ERR, "%s:%d failed to open %s\n", __FUNCTION__, __LINE__, strFile);
- goto ERR_OPEN_DISP_BUFFER_FILE;
- }
- sprintf(strFile, "%s_%dx%d_fbc_data_c.bin", outputPath, width, height);
- if ((fp[1]=osal_fopen(strFile, "wb")) == NULL) {
- VLOG(ERR, "%s:%d failed to open %s\n", __FUNCTION__, __LINE__, strFile);
- goto ERR_OPEN_DISP_BUFFER_FILE;
- }
- sprintf(strFile, "%s_%dx%d_fbc_table_y.bin", outputPath, width, height);
- if ((fp[2]=osal_fopen(strFile, "wb")) == NULL) {
- VLOG(ERR, "%s:%d failed to open %s\n", __FUNCTION__, __LINE__, strFile);
- goto ERR_OPEN_DISP_BUFFER_FILE;
- }
- sprintf(strFile, "%s_%dx%d_fbc_table_c.bin", outputPath, width, height);
- if ((fp[3]=osal_fopen(strFile, "wb")) == NULL) {
- VLOG(ERR, "%s:%d failed to open %s\n", __FUNCTION__, __LINE__, strFile);
- goto ERR_OPEN_DISP_BUFFER_FILE;
- }
- }
- return TRUE;
- ERR_OPEN_DISP_BUFFER_FILE:
- CloseDisplayBufferFile(fp);
- return FALSE;
- }
- void CloseDisplayBufferFile(FILE *fp[])
- {
- int i;
- for (i=0; i < OUTPUT_FP_NUMBER; i++) {
- if (fp[i] != NULL) {
- osal_fclose(fp[i]);
- fp[i] = NULL;
- }
- }
- }
- RetCode VPU_GetFBCOffsetTableSize(CodStd codStd, int width, int height, int* ysize, int* csize)
- {
- if (ysize == NULL || csize == NULL)
- return RETCODE_INVALID_PARAM;
- *ysize = ProductCalculateAuxBufferSize(AUX_BUF_TYPE_FBC_Y_OFFSET, codStd, width, height);
- *csize = ProductCalculateAuxBufferSize(AUX_BUF_TYPE_FBC_C_OFFSET, codStd, width, height);
- return RETCODE_SUCCESS;
- }
- RetCode VPU_GetPVRICRealSize(CodStd codStd, TiledMapType mapType, FrameBufferFormat format, int width, int height, int* ysize, int* csize)
- {
- Uint32 total_tile_num, hdr_size, data_size;
- if (ysize == NULL || csize == NULL)
- return RETCODE_INVALID_PARAM;
- switch (format) {
- case FORMAT_420:
- total_tile_num = (VPU_ALIGN64(width) >> 6) *(VPU_ALIGN4(height) >> 2);//width
- break;
- default: /* 10bit */
- total_tile_num = (width+47)/48 * (VPU_ALIGN4(height) >> 2);
- break;
- }
- hdr_size = VPU_ALIGN256(total_tile_num);
- if( mapType == PVRIC_COMPRESSED_FRAME_LOSSLESS_MAP ) {
- data_size = (total_tile_num*256); // byte
- }
- else {
- data_size = (total_tile_num*128); // byte
- }
- *ysize = (hdr_size + data_size);
- VLOG(ERR, "VPU_GetPVRICRealSize luma h=%d(%x), d=%d(%x)\n", hdr_size, hdr_size, data_size, data_size);
- switch (format) {
- case FORMAT_420:
- total_tile_num = (VPU_ALIGN64(width) >> 6) *(VPU_ALIGN4(height/2) >> 2);
- break;
- default: /* 10bit */
- total_tile_num = (width+47)/48 * (VPU_ALIGN4(height/2) >> 2);
- break;
- }
- hdr_size = VPU_ALIGN256(total_tile_num);
- if( mapType == PVRIC_COMPRESSED_FRAME_LOSSLESS_MAP ) {
- data_size = (total_tile_num*256); // byte
- }
- else {
- data_size = (total_tile_num*128); // byte
- }
- *csize = (hdr_size + data_size);
- VLOG(ERR, "VPU_GetPVRICRealSize chroma h=%d(%x), d=%d(%x)\n", hdr_size, hdr_size, data_size, data_size);
- return RETCODE_SUCCESS;
- }
- void SaveDisplayBufferToFile(DecHandle handle, CodStd codStd, FrameBuffer dispFrame, VpuRect rcDisplay, FILE *fp[])
- {
- Uint32 width;
- Uint32 height;
- Uint32 bpp;
- DecGetFramebufInfo fbInfo;
- CodecInst * pCodecInst;
- pCodecInst = handle;
- if (dispFrame.myIndex < 0)
- return;
- if (dispFrame.mapType != COMPRESSED_FRAME_MAP) {
- size_t sizeYuv;
- Uint8* pYuv;
- pYuv = GetYUVFromFrameBuffer(handle, &dispFrame, rcDisplay, &width, &height, &bpp, &sizeYuv);
- osal_fwrite(pYuv, 1, sizeYuv, fp[0]);
- osal_free(pYuv);
- }
- else {
- Uint32 lumaTblSize;
- Uint32 chromaTblSize;
- Uint32 lSize;
- Uint32 cSize;
- Uint32 addr;
- Uint32 endian;
- Uint8* buf;
- Uint32 coreIdx = VPU_HANDLE_CORE_INDEX(handle);
- Uint32 productId = VPU_HANDLE_PRODUCT_ID(handle);
- Uint32 cFrameStride;
- VPU_DecGiveCommand(handle, DEC_GET_FRAMEBUF_INFO, (void*)&fbInfo);
- width = rcDisplay.right - rcDisplay.left;
- width = (codStd == STD_HEVC || codStd == STD_AVS2) ? VPU_ALIGN16(width) : VPU_ALIGN64(width);
- height = rcDisplay.bottom - rcDisplay.top;
- height = (codStd == STD_HEVC || codStd == STD_AVS2) ? VPU_ALIGN16(height) : VPU_ALIGN64(height);
- cFrameStride = CalcStride(width, height, dispFrame.format, dispFrame.cbcrInterleave, dispFrame.mapType, (codStd == STD_VP9));
- lSize = CalcLumaSize(pCodecInst, productId, cFrameStride, height, dispFrame.format, dispFrame.cbcrInterleave, dispFrame.mapType, NULL);
- cSize = CalcChromaSize(pCodecInst, productId, cFrameStride, height, dispFrame.format, dispFrame.cbcrInterleave, dispFrame.mapType, NULL) * 2;
- // Invert the endian because the pixel order register doesn't affect the FBC data.
- endian = (~(Uint32)dispFrame.endian & 0xf) | 0x10;
- /* Dump Y compressed data */
- if ((buf=(Uint8*)osal_malloc(lSize)) != NULL) {
- vdi_read_memory(coreIdx, dispFrame.bufY, buf, lSize, endian);
- osal_fwrite((void *)buf, sizeof(Uint8), lSize, fp[0]);
- osal_fflush(fp[0]);
- osal_free(buf);
- }
- else {
- VLOG(ERR, "%s:%d Failed to save the luma compressed data!!\n", __FUNCTION__, __LINE__);
- }
- /* Dump C compressed data */
- if ((buf=(Uint8*)osal_malloc(cSize)) != NULL) {
- vdi_read_memory(coreIdx, dispFrame.bufCb, buf, cSize, endian);
- osal_fwrite((void *)buf, sizeof(Uint8), cSize, fp[1]);
- osal_fflush(fp[1]);
- osal_free(buf);
- }
- else {
- VLOG(ERR, "%s:%d Failed to save the chroma compressed data!!\n", __FUNCTION__, __LINE__);
- }
- /* Dump Y Offset table */
- VPU_GetFBCOffsetTableSize(codStd, (int)width, (int)height, (int*)&lumaTblSize, (int*)&chromaTblSize);
- addr = fbInfo.vbFbcYTbl[dispFrame.myIndex].phys_addr;
- if ((buf=(Uint8*)osal_malloc(lumaTblSize)) != NULL) {
- vdi_read_memory(coreIdx, addr, buf, lumaTblSize, endian);
- osal_fwrite((void *)buf, sizeof(Uint8), lumaTblSize, fp[2]);
- osal_fflush(fp[2]);
- osal_free(buf);
- }
- else {
- VLOG(ERR, "%s:%d Failed to save the offset table of luma!\n", __FUNCTION__, __LINE__);
- }
- /* Dump C Offset table */
- addr = fbInfo.vbFbcCTbl[dispFrame.myIndex].phys_addr;
- if ((buf=(Uint8*)osal_malloc(chromaTblSize)) != NULL) {
- vdi_read_memory(coreIdx, addr, buf, chromaTblSize, endian);
- osal_fwrite((void *)buf, sizeof(Uint8), chromaTblSize, fp[3]);
- osal_fflush(fp[3]);
- osal_free(buf);
- }
- else {
- VLOG(ERR, "%s:%d Failed to save the offset table of chroma!\n", __FUNCTION__, __LINE__);
- }
- }
- }
- void PrintDecSeqWarningMessages(
- Uint32 productId,
- DecInitialInfo* seqInfo
- )
- {
- if (PRODUCT_ID_W_SERIES(productId))
- {
- if (seqInfo->seqInitErrReason&0x00000001) VLOG(WARN, "sps_max_sub_layer_minus1 shall be 0 to 6\n");
- if (seqInfo->seqInitErrReason&0x00000002) VLOG(WARN, "general_reserved_zero_44bits shall be 0.\n");
- if (seqInfo->seqInitErrReason&0x00000004) VLOG(WARN, "reserved_zero_2bits shall be 0\n");
- if (seqInfo->seqInitErrReason&0x00000008) VLOG(WARN, "sub_layer_reserved_zero_44bits shall be 0");
- if (seqInfo->seqInitErrReason&0x00000010) VLOG(WARN, "general_level_idc shall have one of level of Table A.1\n");
- if (seqInfo->seqInitErrReason&0x00000020) VLOG(WARN, "sps_max_dec_pic_buffering[i] <= MaxDpbSize\n");
- if (seqInfo->seqInitErrReason&0x00000040) VLOG(WARN, "trailing bits shall be 1000... pattern, 7.3.2.1\n");
- if (seqInfo->seqInitErrReason&0x00100000) VLOG(WARN, "Not supported or undefined profile: %d\n", seqInfo->profile);
- if (seqInfo->seqInitErrReason&0x00200000) VLOG(WARN, "Spec over level(%d)\n", seqInfo->level);
- }
- }
- void DisplayDecodedInformationForHevc(
- DecHandle handle,
- Uint32 frameNo,
- BOOL performance,
- DecOutputInfo* decodedInfo
- )
- {
- Int32 logLevel;
- QueueStatusInfo queueStatus;
- VPU_DecGiveCommand(handle, DEC_GET_QUEUE_STATUS, &queueStatus);
- if (decodedInfo == NULL) {
- if ( performance == TRUE ) {
- VLOG(INFO, " | FRAME | HOST | SEEK_S SEEK_E SEEK | PARSE_S PARSE_E PARSE | DEC_S DEC_E DEC |\n");
- 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");
- VLOG(INFO, "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n");
- }
- else {
- 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");
- VLOG(INFO, "---------------------------------------------------------------------------------------------------------------------------------------------------------------------\n");
- }
- }
- else {
- logLevel = (decodedInfo->decodingSuccess&0x01) == 0 ? WARN : INFO;
- // Print informations
- if ( performance == TRUE ) {
- 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",
- handle->instIndex, frameNo, decodedInfo->picType,
- decodedInfo->decodedPOC, decodedInfo->displayPOC, decodedInfo->nalType,
- decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled,
- decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled,
- decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr,
- decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, (decodedInfo->bytePosFrameEnd - decodedInfo->bytePosFrameStart),
- decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo,
- decodedInfo->temporalId,
- decodedInfo->frameCycle, decodedInfo->decHostCmdTick,
- decodedInfo->decSeekStartTick, decodedInfo->decSeekEndTick, decodedInfo->seekCycle,
- decodedInfo->decParseStartTick, decodedInfo->decParseEndTick, decodedInfo->parseCycle,
- decodedInfo->decDecodeStartTick, decodedInfo->decDecodeEndTick, decodedInfo->DecodedCycle,
- queueStatus.reportQueueCount, queueStatus.instanceQueueCount,
- 0
- );
- }
- else {
- 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",
- handle->instIndex, frameNo, decodedInfo->picType,
- decodedInfo->decodedPOC, decodedInfo->displayPOC, decodedInfo->nalType,
- decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled,
- decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled,
- decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr,
- decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, (decodedInfo->bytePosFrameEnd - decodedInfo->bytePosFrameStart),
- decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo,
- decodedInfo->temporalId,
- decodedInfo->frameCycle, decodedInfo->seekCycle, decodedInfo->parseCycle, decodedInfo->DecodedCycle,
- queueStatus.reportQueueCount, queueStatus.instanceQueueCount,
- 0
- );
- }
- if (logLevel == ERR) {
- VLOG(ERR, "\t>>ERROR REASON: 0x%08x(0x%08x)\n", decodedInfo->errorReason, decodedInfo->errorReasonExt);
- }
- if (decodedInfo->numOfErrMBs) {
- VLOG(WARN, "\t>> ErrorBlock: %d\n", decodedInfo->numOfErrMBs);
- }
- }
- }
- void DisplayDecodedInformationForAVS2(
- DecHandle handle,
- Uint32 frameNo,
- BOOL performance,
- DecOutputInfo* decodedInfo
- )
- {
- Int32 logLevel;
- QueueStatusInfo queueStatus;
- VPU_DecGiveCommand(handle, DEC_GET_QUEUE_STATUS, &queueStatus);
- if (decodedInfo == NULL) {
- if ( performance == TRUE ) {
- VLOG(INFO, " | FRAME | HOST | SEEK_S SEEK_E SEEK | PARSE_S PARSE_E PARSE | DEC_S DEC_E DEC |\n");
- 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");
- } else {
- 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");
- }
- VLOG(INFO, "------------------------------------------------------------------------------------------------------------\n");
- }
- else {
- logLevel = (decodedInfo->decodingSuccess&0x01) == 0 ? ERR : TRACE;
- // Print informations
- if (performance == TRUE) {
- 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",
- handle->instIndex, frameNo, decodedInfo->picType,
- decodedInfo->avs2Info.decodedPOI, decodedInfo->avs2Info.displayPOI, decodedInfo->nalType,
- decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled,
- decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled,
- decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr,
- decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, (decodedInfo->bytePosFrameEnd - decodedInfo->bytePosFrameStart),
- decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo,
- decodedInfo->temporalId,
- decodedInfo->frameCycle, decodedInfo->decHostCmdTick,
- decodedInfo->decSeekStartTick, decodedInfo->decSeekEndTick, decodedInfo->seekCycle,
- decodedInfo->decParseStartTick, decodedInfo->decParseEndTick, decodedInfo->parseCycle,
- decodedInfo->decDecodeStartTick, decodedInfo->decDecodeEndTick, decodedInfo->DecodedCycle,
- queueStatus.reportQueueCount, queueStatus.instanceQueueCount);
- }
- else {
- 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",
- handle->instIndex, frameNo, decodedInfo->picType,
- decodedInfo->avs2Info.decodedPOI, decodedInfo->avs2Info.displayPOI, decodedInfo->nalType,
- decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled,
- decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled,
- decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr,
- decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, (decodedInfo->bytePosFrameEnd - decodedInfo->bytePosFrameStart),
- decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo,
- decodedInfo->temporalId,
- decodedInfo->frameCycle, decodedInfo->seekCycle, decodedInfo->parseCycle, decodedInfo->DecodedCycle,
- queueStatus.reportQueueCount, queueStatus.instanceQueueCount);
- }
- if (logLevel == ERR) {
- VLOG(ERR, "\t>>ERROR REASON: 0x%08x(0x%08x)\n", decodedInfo->errorReason, decodedInfo->errorReasonExt);
- }
- if (decodedInfo->numOfErrMBs) {
- VLOG(WARN, "\t>> ErrorBlock: %d\n", decodedInfo->numOfErrMBs);
- }
- }
- }
- void DisplayDecodedInformationForVP9(
- DecHandle handle,
- Uint32 frameNo,
- BOOL performance,
- DecOutputInfo* decodedInfo)
- {
- Int32 logLevel;
- QueueStatusInfo queueStatus;
- VPU_DecGiveCommand(handle, DEC_GET_QUEUE_STATUS, &queueStatus);
- if (decodedInfo == NULL) {
- // Print header
- if ( performance == TRUE ) {
- VLOG(INFO, " | FRAME | HOST | SEEK_S SEEK_E SEEK | PARSE_S PARSE_E PARSE | DEC_S DEC_E DEC |\n");
- 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");
- }
- else {
- 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");
- }
- VLOG(INFO, "--------------------------------------------------------------------------------------------\n");
- }
- else {
- logLevel = (decodedInfo->decodingSuccess&0x01) == 0 ? ERR : TRACE;
- // Print informations
- if (performance == TRUE) {
- 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",
- handle->instIndex, frameNo, decodedInfo->picType,
- decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled,
- decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled,
- decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr,
- decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, (decodedInfo->bytePosFrameEnd - decodedInfo->bytePosFrameStart),
- decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo,
- decodedInfo->frameCycle, decodedInfo->decHostCmdTick,
- decodedInfo->decSeekStartTick, decodedInfo->decSeekEndTick, decodedInfo->seekCycle,
- decodedInfo->decParseStartTick, decodedInfo->decParseEndTick, decodedInfo->parseCycle,
- decodedInfo->decDecodeStartTick, decodedInfo->decDecodeEndTick, decodedInfo->DecodedCycle,
- queueStatus.reportQueueCount, queueStatus.instanceQueueCount);
- }
- else {
- 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",
- handle->instIndex, frameNo, decodedInfo->picType,
- decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled,
- decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled,
- decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr,
- decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, (decodedInfo->bytePosFrameEnd - decodedInfo->bytePosFrameStart),
- decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo,
- decodedInfo->frameCycle, decodedInfo->seekCycle, decodedInfo->parseCycle, decodedInfo->DecodedCycle,
- queueStatus.reportQueueCount, queueStatus.instanceQueueCount);
- }
- if (logLevel == ERR) {
- VLOG(ERR, "\t>>ERROR REASON: 0x%08x(0x%08x)\n", decodedInfo->errorReason, decodedInfo->errorReasonExt);
- }
- if (decodedInfo->numOfErrMBs) {
- VLOG(WARN, "\t>> ErrorBlock: %d\n", decodedInfo->numOfErrMBs);
- }
- }
- }
- void DisplayDecodedInformationForAVC(
- DecHandle handle,
- Uint32 frameNo,
- BOOL performance,
- DecOutputInfo* decodedInfo)
- {
- Int32 logLevel;
- QueueStatusInfo queueStatus;
- VPU_DecGiveCommand(handle, DEC_GET_QUEUE_STATUS, &queueStatus);
- if (decodedInfo == NULL) {
- // Print header
- if ( performance == TRUE ) {
- VLOG(INFO, " | FRAME | HOST | SEEK_S SEEK_E SEEK | PARSE_S PARSE_E PARSE | DEC_S DEC_E DEC |\n");
- 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");
- }
- else {
- 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");
- }
- VLOG(INFO, "-----------------------------------------------------------------------------------------------------------------------------------------------\n");
- }
- else {
- logLevel = (decodedInfo->decodingSuccess&0x01) == 0 ? ERR : INFO;
- // Print informations
- if (performance == TRUE) {
- 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",
- handle->instIndex, frameNo, decodedInfo->picType, decodedInfo->decodedPOC, decodedInfo->displayPOC, decodedInfo->nalType,
- decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled,
- decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled,
- decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr,
- decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, (decodedInfo->bytePosFrameEnd - decodedInfo->bytePosFrameStart),
- decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo, decodedInfo->temporalId,
- decodedInfo->frameCycle, decodedInfo->decHostCmdTick,
- decodedInfo->decSeekStartTick, decodedInfo->decSeekEndTick, decodedInfo->seekCycle,
- decodedInfo->decParseStartTick, decodedInfo->decParseEndTick, decodedInfo->parseCycle,
- decodedInfo->decDecodeStartTick, decodedInfo->decDecodeEndTick, decodedInfo->DecodedCycle,
- queueStatus.reportQueueCount, queueStatus.instanceQueueCount,
- 0
- );
- }
- else {
- 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",
- handle->instIndex, frameNo, decodedInfo->picType, decodedInfo->decodedPOC, decodedInfo->displayPOC, decodedInfo->nalType,
- decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled,
- decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled,
- decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr,
- decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, (decodedInfo->bytePosFrameEnd - decodedInfo->bytePosFrameStart),
- decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo, decodedInfo->temporalId,
- decodedInfo->frameCycle, decodedInfo->seekCycle, decodedInfo->parseCycle, decodedInfo->DecodedCycle,
- queueStatus.reportQueueCount, queueStatus.instanceQueueCount,
- 0
- );
- }
- if (logLevel == ERR) {
- VLOG(ERR, "\t>>ERROR REASON: 0x%08x(0x%08x)\n", decodedInfo->errorReason, decodedInfo->errorReasonExt);
- }
- if (decodedInfo->numOfErrMBs) {
- VLOG(WARN, "\t>> ErrorBlock: %d\n", decodedInfo->numOfErrMBs);
- }
- }
- }
- void DisplayDecodedInformationForAV1(
- DecHandle handle,
- Uint32 frameNo,
- BOOL performance,
- DecOutputInfo* decodedInfo)
- {
- Int32 logLevel;
- QueueStatusInfo queueStatus;
- VPU_DecGiveCommand(handle, DEC_GET_QUEUE_STATUS, &queueStatus);
- if (decodedInfo == NULL) {
- // Print header
- if ( performance == TRUE ) {
- VLOG(INFO, " | FRAME | HOST | SEEK_S SEEK_E SEEK | PARSE_S PARSE_E PARSE | DEC_S DEC_E DEC |\n");
- 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");
- }
- else {
- 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");
- }
- VLOG(INFO, "--------------------------------------------------------------------------------------------\n");
- }
- else {
- logLevel = (decodedInfo->decodingSuccess&0x01) == 0 ? ERR : TRACE;
- // Print informations
- if (performance == TRUE) {
- 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",
- handle->instIndex, frameNo, decodedInfo->picType,
- decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled,
- decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled,
- decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr,
- decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, (decodedInfo->bytePosFrameEnd - decodedInfo->bytePosFrameStart),
- decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo,
- decodedInfo->frameCycle, decodedInfo->decHostCmdTick,
- decodedInfo->decSeekStartTick, decodedInfo->decSeekEndTick, decodedInfo->seekCycle,
- decodedInfo->decParseStartTick, decodedInfo->decParseEndTick, decodedInfo->parseCycle,
- decodedInfo->decDecodeStartTick, decodedInfo->decDecodeEndTick, decodedInfo->DecodedCycle,
- queueStatus.reportQueueCount, queueStatus.instanceQueueCount);
- }
- else {
- 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",
- handle->instIndex, frameNo, decodedInfo->picType,
- decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled,
- decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled,
- decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr,
- decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, (decodedInfo->bytePosFrameEnd - decodedInfo->bytePosFrameStart),
- decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo,
- decodedInfo->frameCycle, decodedInfo->seekCycle, decodedInfo->parseCycle, decodedInfo->DecodedCycle,
- queueStatus.reportQueueCount, queueStatus.instanceQueueCount);
- }
- if (logLevel == ERR) {
- VLOG(ERR, "\t>>ERROR REASON: 0x%08x(0x%08x)\n", decodedInfo->errorReason, decodedInfo->errorReasonExt);
- }
- if (decodedInfo->numOfErrMBs) {
- VLOG(WARN, "\t>> ErrorBlock: %d\n", decodedInfo->numOfErrMBs);
- }
- }
- }
- void DisplayDecodedInformationCommon(
- DecHandle handle,
- Uint32 frameNo,
- DecOutputInfo* decodedInfo)
- {
- Int32 logLevel;
- if (decodedInfo == NULL) {
- // Print header
- VLOG(TRACE, "I NO T DECO DISP DISPFLAG RD_PTR WR_PTR FRM_START FRM_END FRM_SIZE WxH \n");
- VLOG(TRACE, "---------------------------------------------------------------------------\n");
- }
- else {
- VpuRect rc = decodedInfo->rcDisplay;
- Uint32 width = rc.right - rc.left;
- Uint32 height = rc.bottom - rc.top;
- logLevel = (decodedInfo->decodingSuccess&0x01) == 0 ? WARN : INFO;
- // Print informations
- VLOG(logLevel, "%02d %5d %d %2d(%2d) %2d(%2d) %08x %08x %08x %08x %08x %8d %dx%d\n",
- handle->instIndex, frameNo, decodedInfo->picType,
- decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled,
- decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled,
- decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr,
- decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, (decodedInfo->bytePosFrameEnd - decodedInfo->bytePosFrameStart),
- width, height);
- if (logLevel == ERR) {
- VLOG(ERR, "\t>>ERROR REASON: 0x%08x(0x%08x)\n", decodedInfo->errorReason, decodedInfo->errorReasonExt);
- }
- if (decodedInfo->numOfErrMBs) {
- VLOG(WARN, "\t>> ErrorBlock: %d\n", decodedInfo->numOfErrMBs);
- }
- }
- }
- /**
- * \brief Print out decoded information such like RD_PTR, WR_PTR, PIC_TYPE, ..
- * \param decodedInfo If this parameter is not NULL then print out decoded informations
- * otherwise print out header.
- */
- void
- DisplayDecodedInformation(
- DecHandle handle,
- CodStd codec,
- Uint32 frameNo,
- DecOutputInfo* decodedInfo,
- ...
- )
- {
- int performance = FALSE;
- va_list ap;
- va_start(ap, decodedInfo);
- performance = va_arg(ap, Uint32);
- va_end(ap);
- switch (codec)
- {
- case STD_HEVC:
- DisplayDecodedInformationForHevc(handle, frameNo, performance, decodedInfo);
- break;
- case STD_VP9:
- DisplayDecodedInformationForVP9(handle, frameNo, performance, decodedInfo);
- break;
- case STD_AVS2:
- DisplayDecodedInformationForAVS2(handle, frameNo, performance, decodedInfo);
- break;
- case STD_AVC:
- DisplayDecodedInformationForAVC(handle, frameNo, performance, decodedInfo);
- break;
- case STD_AV1:
- DisplayDecodedInformationForAV1(handle, frameNo, performance, decodedInfo);
- break;
- default:
- DisplayDecodedInformationCommon(handle, frameNo, decodedInfo);
- break;
- }
- return;
- }
- void SetDefaultEncTestConfig(TestEncConfig* testConfig) {
- osal_memset(testConfig, 0, sizeof(TestEncConfig));
- testConfig->stdMode = STD_HEVC;
- testConfig->frame_endian = VPU_FRAME_ENDIAN;
- testConfig->stream_endian = VPU_STREAM_ENDIAN;
- testConfig->source_endian = VPU_SOURCE_ENDIAN;
- testConfig->mapType = COMPRESSED_FRAME_MAP;
- testConfig->lineBufIntEn = TRUE;
- #ifdef SUPPORT_SOURCE_RELEASE_INTERRUPT
- testConfig->srcReleaseIntEnable = FALSE;
- #endif
- testConfig->ringBufferEnable = FALSE;
- testConfig->ringBufferWrapEnable = FALSE;
- }
- void Coda9SetDefaultEncTestConfig(TestEncConfig* encConfig) {
- osal_memset(encConfig, 0, sizeof(TestEncConfig));
- encConfig->stdMode = STD_AVC;
- encConfig->frame_endian = VPU_FRAME_ENDIAN;
- encConfig->stream_endian = VPU_STREAM_ENDIAN;
- encConfig->source_endian = VPU_SOURCE_ENDIAN;
- encConfig->mapType = LINEAR_FRAME_MAP;
- encConfig->ringBufferEnable = FALSE;
- encConfig->yuv_mode = SOURCE_YUV;
- }
- static void Wave5DisplayEncodedInformation(
- EncHandle handle,
- CodStd codec,
- Uint32 frameNo,
- EncOutputInfo* encodedInfo,
- Int32 srcEndFlag,
- Int32 srcFrameIdx,
- Int32 performance
- )
- {
- QueueStatusInfo queueStatus;
- VPU_EncGiveCommand(handle, ENC_GET_QUEUE_STATUS, &queueStatus);
- if (encodedInfo == NULL) {
- if (performance == TRUE ) {
- VLOG(INFO, "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n");
- VLOG(INFO, " USEDSRC | FRAME | HOST | PREP_S PREP_E PREP | PROCE_S PROCE_E PROCE | ENC_S ENC_E ENC |\n");
- 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");
- VLOG(INFO, "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n");
- }
- else {
- VLOG(INFO, "---------------------------------------------------------------------------------------------------------------------------\n");
- VLOG(INFO, " USEDSRC | CYCLE\n");
- VLOG(INFO, "I NO T RECON RD_PTR WR_PTR BYTES SRCIDX IDX IDC Vcore | FRAME PREPARING PROCESSING ENCODING | RQ IQ\n");
- VLOG(INFO, "---------------------------------------------------------------------------------------------------------------------------\n");
- }
- } else {
- if (performance == TRUE) {
- 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",
- handle->instIndex, encodedInfo->encPicCnt, encodedInfo->picType, encodedInfo->reconFrameIndex, encodedInfo->rdPtr, encodedInfo->wrPtr,
- encodedInfo->bitstreamSize, (srcEndFlag == 1 ? -1 : srcFrameIdx), encodedInfo->encSrcIdx,
- encodedInfo->releaseSrcFlag,
- 0,
- encodedInfo->frameCycle, encodedInfo->encHostCmdTick,
- encodedInfo->encPrepareStartTick, encodedInfo->encPrepareEndTick, encodedInfo->prepareCycle,
- encodedInfo->encProcessingStartTick, encodedInfo->encProcessingEndTick, encodedInfo->processing,
- encodedInfo->encEncodeStartTick, encodedInfo->encEncodeEndTick, encodedInfo->EncodedCycle,
- queueStatus.reportQueueCount, queueStatus.instanceQueueCount);
- }
- else {
- VLOG(INFO, "%02d %5d %5d %5d %08x %08x %8x %2d %2d %04x %d %8d %8d %8d %8d %d %d\n",
- handle->instIndex, encodedInfo->encPicCnt, encodedInfo->picType, encodedInfo->reconFrameIndex, encodedInfo->rdPtr, encodedInfo->wrPtr,
- encodedInfo->bitstreamSize, (srcEndFlag == 1 ? -1 : srcFrameIdx), encodedInfo->encSrcIdx,
- encodedInfo->releaseSrcFlag,
- 0,
- encodedInfo->frameCycle, encodedInfo->prepareCycle, encodedInfo->processing, encodedInfo->EncodedCycle,
- queueStatus.reportQueueCount, queueStatus.instanceQueueCount);
- }
- }
- }
- static void Coda9DisplayEncodedInformation(
- DecHandle handle,
- CodStd codec,
- Uint32 frameNo,
- EncOutputInfo* encodedInfo
- )
- {
- if (encodedInfo == NULL) {
- // Print header
- VLOG(INFO, "I NO T RECON RD_PTR WR_PTR \n");
- VLOG(INFO, "-------------------------------------\n");
- }
- else {
- char** picTypeArray = (codec==STD_AVC ? EncPicTypeStringH264 : EncPicTypeStringMPEG4);
- char* strPicType;
- if (encodedInfo->picType > 2) strPicType = "?";
- else strPicType = picTypeArray[encodedInfo->picType];
- // Print informations
- VLOG(INFO, "%02d %5d %5s %5d %08x %08x\n",
- handle->instIndex, frameNo, strPicType,
- encodedInfo->reconFrameIndex, encodedInfo->rdPtr, encodedInfo->wrPtr);
- }
- }
- /*lint -esym(438, ap) */
- void
- DisplayEncodedInformation(
- EncHandle handle,
- CodStd codec,
- Uint32 frameNo,
- EncOutputInfo* encodedInfo,
- ...
- )
- {
- int srcEndFlag;
- int srcFrameIdx;
- int performance = FALSE;
- va_list ap;
- switch (codec) {
- case STD_HEVC:
- va_start(ap, encodedInfo);
- srcEndFlag = va_arg(ap, Uint32);
- srcFrameIdx = va_arg(ap, Uint32);
- performance = va_arg(ap, Uint32);
- va_end(ap);
- Wave5DisplayEncodedInformation(handle, codec, frameNo, encodedInfo, srcEndFlag , srcFrameIdx, performance);
- break;
- case STD_AVC:
- if(handle->productId == PRODUCT_ID_521) {
- va_start(ap, encodedInfo);
- srcEndFlag = va_arg(ap, Uint32);
- srcFrameIdx = va_arg(ap, Uint32);
- performance = va_arg(ap, Uint32);
- va_end(ap);
- Wave5DisplayEncodedInformation(handle, codec, frameNo, encodedInfo, srcEndFlag , srcFrameIdx, performance);
- }
- else
- Coda9DisplayEncodedInformation(handle, codec, frameNo, encodedInfo);
- break;
- default:
- Coda9DisplayEncodedInformation(handle, codec, frameNo, encodedInfo);
- break;
- }
- return;
- }
- /*lint +esym(438, ap) */
- void replace_character(char* str,
- char c,
- char r)
- {
- int i=0;
- int len;
- len = strlen(str);
- for(i=0; i<len; i++)
- {
- if (str[i] == c)
- str[i] = r;
- }
- }
- void ChangePathStyle(
- char *str
- )
- {
- }
- void ReleaseVideoMemory(
- DecHandle handle,
- vpu_buffer_t* memoryArr,
- Uint32 count
- )
- {
- Int32 coreIndex = handle->coreIdx;
- Uint32 idx;
- for (idx=0; idx<count; idx++) {
- if (memoryArr[idx].size)
- vdi_free_dma_memory(coreIndex, &memoryArr[idx], DEC_FBC, handle->instIndex);
- }
- }
- BOOL AllocateLinerBuffer(
- DecHandle decHandle,
- vpu_buffer_t *pvb,
- Uint32 size
- )
- {
- Uint32 coreIndex = VPU_HANDLE_CORE_INDEX(decHandle);
- if (vdi_allocate_dma_memory(coreIndex, pvb, DEC_FB_LINEAR, decHandle->instIndex) < 0) {
- VLOG(ERR, "%s:%d fail to allocate frame buffer\n", __FUNCTION__, __LINE__);
- return FALSE;
- }
- return TRUE;
- }
- FrameBufferAllocInfo frameBufferAllocInfo;
- void *AllocateDecFrameBuffer2(DecHandle decHandle, TestDecConfig* config, Uint32 size, FrameBuffer* retFbArray, vpu_buffer_t* retFbAddrs)
- {
- RetCode ret;
- vpu_buffer_t *vb = retFbAddrs;
- Uint32 coreIndex = VPU_HANDLE_CORE_INDEX(decHandle);
- vb->size = size;
- frameBufferAllocInfo.num = 1;
- vdi_allocate_dma_memory(coreIndex, vb, DEC_FB_LINEAR, decHandle->instIndex);
- VLOG(INFO, "base = %lx virt_addr = %lx phys_addr = %lx\r\n", vb->base, vb->virt_addr, vb->phys_addr);
- retFbArray->bufY = vb->phys_addr;
- retFbArray->bufCb = (PhysicalAddress)-1;
- retFbArray->bufCr = (PhysicalAddress)-1;
- retFbArray->updateFbInfo = TRUE;
- retFbArray->size = size;
- // width = 0 not effect right now
- retFbArray->width = 0;
- ret = VPU_DecAllocateFrameBuffer(decHandle, frameBufferAllocInfo, retFbArray);
- if (ret != RETCODE_SUCCESS) {
- VLOG(ERR, "%s:%d failed to VPU_DecAllocateFrameBuffer() ret:%d\n",
- __FUNCTION__, __LINE__, ret);
- ReleaseVideoMemory(decHandle, vb, 1);
- return NULL;
- }
- return (void *)vb->virt_addr;
- }
- Uint64 RemapVaddr(DecHandle decHandle, Uint64 virtAddress, Uint32 size)
- {
- Uint32 coreIndex = VPU_HANDLE_CORE_INDEX(decHandle);
- return (Uint64)vdi_remap_vaddr(coreIndex, virtAddress, size);
- }
- BOOL AttachDecDMABuffer(DecHandle decHandle, TestDecConfig* config, Uint64 virtAddress, Uint32 size, FrameBuffer* retFbArray, vpu_buffer_t* retFbAddrs)
- {
- RetCode ret;
- Uint32 coreIndex = VPU_HANDLE_CORE_INDEX(decHandle);
- vpu_buffer_t *vb = retFbAddrs;
- vb->virt_addr = virtAddress;
- vb->size = size;
- frameBufferAllocInfo.num = 1;
- vdi_virt_to_phys(coreIndex, vb);
- vdi_attach_dma_memory(coreIndex, vb);
- VLOG(INFO, "base addr = %lx virt addr= %lx phys addr = %x\r\n", vb->base, vb->virt_addr, vb->phys_addr);
- retFbArray->bufY = vb->phys_addr;
- retFbArray->bufCb = (PhysicalAddress)-1;
- retFbArray->bufCr = (PhysicalAddress)-1;
- retFbArray->updateFbInfo = TRUE;
- retFbArray->size = size;
- // width = 0 not effect right now
- retFbArray->width = 0;
- ret = VPU_DecAllocateFrameBuffer(decHandle, frameBufferAllocInfo, retFbArray);
- if (ret != RETCODE_SUCCESS) {
- VLOG(ERR, "%s:%d failed to VPU_DecAllocateFrameBuffer() ret:%d\n",
- __FUNCTION__, __LINE__, ret);
- ReleaseVideoMemory(decHandle, vb, 1);
- return FALSE;
- }
- return TRUE;
- }
- BOOL AllocateDecFrameBuffer(
- DecHandle decHandle,
- TestDecConfig* config,
- Uint32 nonLinearFbCnt,
- Uint32 linearFbCount,
- FrameBuffer* retFbArray,
- vpu_buffer_t* retFbAddrs,
- Uint32* retStride
- )
- {
- Uint32 framebufSize;
- Uint32 totalFbCount, linearFbStartIdx = 0;
- Uint32 coreIndex;
- Uint32 idx;
- FrameBufferFormat format = config->wtlFormat;
- DecInitialInfo seqInfo;
- FrameBufferAllocInfo fbAllocInfo;
- RetCode ret;
- vpu_buffer_t* pvb;
- size_t framebufStride;
- size_t framebufHeight;
- Uint32 productId;
- DRAMConfig* pDramCfg = NULL;
- DRAMConfig dramCfg = {0};
- DecInfo* pDecInfo = &decHandle->CodecInfo->decInfo;
- coreIndex = VPU_HANDLE_CORE_INDEX(decHandle);
- productId = VPU_HANDLE_PRODUCT_ID(decHandle);
- VPU_DecGiveCommand(decHandle, DEC_GET_SEQ_INFO, (void*)&seqInfo);
- if (pDecInfo->productCode == WAVE521C_DUAL_CODE) {
- if ( seqInfo.lumaBitdepth == 8 && seqInfo.chromaBitdepth == 8) {
- config->mapType = COMPRESSED_FRAME_MAP_DUAL_CORE_8BIT;
- }
- else {
- config->mapType = COMPRESSED_FRAME_MAP_DUAL_CORE_10BIT;
- }
- }
- totalFbCount = nonLinearFbCnt + linearFbCount;
- if (PRODUCT_ID_W_SERIES(productId)) {
- linearFbStartIdx = nonLinearFbCnt;
- }
- else { //CODA series
- if (0 == nonLinearFbCnt) {
- nonLinearFbCnt = linearFbCount;
- linearFbCount = 0;
- }
- else {
- linearFbStartIdx = nonLinearFbCnt;
- }
- }
- if (PRODUCT_ID_W_SERIES(productId)) {
- format = (seqInfo.lumaBitdepth > 8 || seqInfo.chromaBitdepth > 8) ? FORMAT_420_P10_16BIT_LSB : FORMAT_420;
- }
- else { //CODA series
- pDramCfg = &dramCfg;
- ret = VPU_DecGiveCommand(decHandle, GET_DRAM_CONFIG, pDramCfg);
- if (RETCODE_SUCCESS != ret) {
- VLOG(ERR, "%s:%d VPU_DecGiveCommand[GET_DRAM_CONFIG] failed Error code is 0x%x \n", __FUNCTION__, __LINE__, ret );
- return FALSE;
- }
- }
- #ifdef USE_FEEDING_METHOD_BUFFER
- *retStride = seqInfo.picWidth;
- framebufStride = CalcStride(seqInfo.picWidth, seqInfo.picHeight, format, config->cbcrInterleave, config->mapType, FALSE);
- framebufHeight = seqInfo.picHeight;
- framebufSize = VPU_GetFrameBufSize(decHandle, decHandle->coreIdx, framebufStride, framebufHeight,
- config->mapType, format, config->cbcrInterleave, pDramCfg);
- #else
- if (config->bitFormat == STD_VP9) {
- framebufStride = CalcStride(VPU_ALIGN64(seqInfo.picWidth), seqInfo.picHeight, format, config->cbcrInterleave, config->mapType, TRUE);
- framebufHeight = VPU_ALIGN64(seqInfo.picHeight);
- framebufSize = VPU_GetFrameBufSize(decHandle, decHandle->coreIdx, framebufStride, framebufHeight,
- config->mapType, format, config->cbcrInterleave, NULL);
- *retStride = framebufStride;
- }
- else if (config->bitFormat == STD_AVS2) {
- framebufStride = CalcStride(seqInfo.picWidth, seqInfo.picHeight, format, config->cbcrInterleave, config->mapType, FALSE);
- framebufHeight = VPU_ALIGN8(seqInfo.picHeight);
- framebufSize = VPU_GetFrameBufSize(decHandle, decHandle->coreIdx, framebufStride, framebufHeight,
- config->mapType, format, config->cbcrInterleave, pDramCfg);
- *retStride = framebufStride;
- }
- else if (config->bitFormat == STD_AV1){
- framebufStride = CalcStride(VPU_ALIGN64(seqInfo.picWidth), seqInfo.picHeight, format, config->cbcrInterleave, config->mapType, TRUE);
- framebufHeight = VPU_ALIGN64(seqInfo.picHeight);
- framebufSize = VPU_GetFrameBufSize(decHandle, decHandle->coreIdx, framebufStride, framebufHeight,
- config->mapType, format, config->cbcrInterleave, NULL);
- *retStride = framebufStride;
- }
- else {
- *retStride = VPU_ALIGN32(seqInfo.picWidth);
- framebufStride = CalcStride(seqInfo.picWidth, seqInfo.picHeight, format, config->cbcrInterleave, config->mapType, FALSE);
- framebufHeight = VPU_ALIGN32(seqInfo.picHeight);
- framebufSize = VPU_GetFrameBufSize(decHandle, decHandle->coreIdx, framebufStride, framebufHeight,
- config->mapType, format, config->cbcrInterleave, pDramCfg);
- }
- #endif
- osal_memset((void*)&fbAllocInfo, 0x00, sizeof(fbAllocInfo));
- osal_memset((void*)retFbArray, 0x00, sizeof(FrameBuffer)*totalFbCount);
- fbAllocInfo.format = format;
- fbAllocInfo.cbcrInterleave = config->cbcrInterleave;
- fbAllocInfo.mapType = config->mapType;
- fbAllocInfo.stride = framebufStride;
- fbAllocInfo.height = framebufHeight;
- fbAllocInfo.size = framebufSize;
- fbAllocInfo.lumaBitDepth = seqInfo.lumaBitdepth;
- fbAllocInfo.chromaBitDepth = seqInfo.chromaBitdepth;
- fbAllocInfo.num = nonLinearFbCnt;
- fbAllocInfo.endian = PRODUCT_ID_NOT_W_SERIES(productId) ? config->frameEndian : VDI_128BIT_LITTLE_ENDIAN ; // FBC endian is not fixed.
- fbAllocInfo.type = FB_TYPE_CODEC;
- osal_memset((void*)retFbAddrs, 0x00, sizeof(vpu_buffer_t)*totalFbCount);
- APIDPRINT("ALLOC MEM - FBC data\n");
- for (idx=0; idx<nonLinearFbCnt; idx++) {
- pvb = &retFbAddrs[idx];
- pvb->size = framebufSize;
- if (vdi_allocate_dma_memory(coreIndex, pvb, DEC_FBC, decHandle->instIndex) < 0) {
- VLOG(ERR, "%s:%d fail to allocate frame buffer\n", __FUNCTION__, __LINE__);
- ReleaseVideoMemory(decHandle, retFbAddrs, totalFbCount);
- return FALSE;
- }
- retFbArray[idx].bufY = pvb->phys_addr;
- retFbArray[idx].bufCb = (PhysicalAddress)-1;
- retFbArray[idx].bufCr = (PhysicalAddress)-1;
- retFbArray[idx].updateFbInfo = TRUE;
- retFbArray[idx].size = framebufSize;
- retFbArray[idx].width = seqInfo.picWidth;
- }
- if (nonLinearFbCnt != 0) {
- if ((ret=VPU_DecAllocateFrameBuffer(decHandle, fbAllocInfo, retFbArray)) != RETCODE_SUCCESS) {
- VLOG(ERR, "%s:%d failed to VPU_DecAllocateFrameBuffer(), ret(%d)\n",
- __FUNCTION__, __LINE__, ret);
- ReleaseVideoMemory(decHandle, retFbAddrs, totalFbCount);
- return FALSE;
- }
- }
- if (config->enableWTL == TRUE || linearFbCount != 0) {
- size_t linearStride;
- size_t picWidth;
- size_t picHeight;
- size_t fbHeight;
- TiledMapType mapType = LINEAR_FRAME_MAP;
- FrameBufferFormat outFormat = config->wtlFormat;
- picWidth = seqInfo.picWidth;
- picHeight = seqInfo.picHeight;
- fbHeight = picHeight;
- if (PRODUCT_ID_960 == productId || PRODUCT_ID_980 == productId) {
- //wtl frame buffer
- mapType = (FF_FRAME == config->wtlMode) ? LINEAR_FRAME_MAP : LINEAR_FIELD_MAP;
- }
- if (config->bitFormat == STD_VP9) {
- fbHeight = VPU_ALIGN64(picHeight);
- }
- else if (config->bitFormat == STD_AVS2) {
- fbHeight = VPU_ALIGN8(picHeight);
- }
- else if (productId == PRODUCT_ID_960 || productId == PRODUCT_ID_980)
- {
- fbHeight = VPU_ALIGN32(picHeight);
- }
- else if (config->bitFormat == STD_AV1)
- {
- fbHeight = VPU_ALIGN8(picHeight);
- }
- if (config->scaleDownWidth > 0 || config->scaleDownHeight > 0) {
- ScalerInfo sclInfo;
- VPU_DecGiveCommand(decHandle, DEC_GET_SCALER_INFO, (void*)&sclInfo);
- if (sclInfo.enScaler == TRUE) {
- picWidth = sclInfo.scaleWidth;
- picHeight = sclInfo.scaleHeight;
- if (config->bitFormat == STD_VP9) {
- fbHeight = VPU_ALIGN64(picHeight);
- }
- else {
- fbHeight = VPU_CEIL(picHeight, 2);
- }
- }
- }
- if (config->bitFormat == STD_VP9) {
- linearStride = CalcStride(VPU_ALIGN64(picWidth), picHeight, outFormat, config->cbcrInterleave, (TiledMapType)mapType, TRUE);
- }
- else if (config->bitFormat == STD_AV1) {
- linearStride = CalcStride(VPU_ALIGN16(picWidth), picHeight, outFormat, config->cbcrInterleave, (TiledMapType)mapType, TRUE);
- }
- else {
- linearStride = CalcStride(picWidth, picHeight, outFormat, config->cbcrInterleave, (TiledMapType)mapType, FALSE);
- }
- framebufSize = VPU_GetFrameBufSize(decHandle, coreIndex, linearStride, fbHeight, (TiledMapType)mapType, outFormat, config->cbcrInterleave, pDramCfg);
- fbAllocInfo.nv21 = config->nv21;
- fbAllocInfo.format = outFormat;
- fbAllocInfo.num = linearFbCount;
- fbAllocInfo.mapType = (TiledMapType)mapType;
- fbAllocInfo.stride = linearStride;
- fbAllocInfo.height = fbHeight;
- #ifdef USE_FEEDING_METHOD_BUFFER
- memcpy(&frameBufferAllocInfo, &fbAllocInfo, sizeof(frameBufferAllocInfo));
- #endif
- for (idx=linearFbStartIdx; idx<totalFbCount; idx++) {
- pvb = &retFbAddrs[idx];
- pvb->size = framebufSize;
- if (vdi_allocate_dma_memory(coreIndex, pvb, DEC_FB_LINEAR, decHandle->instIndex) < 0) {
- VLOG(ERR, "%s:%d fail to allocate frame buffer\n", __FUNCTION__, __LINE__);
- ReleaseVideoMemory(decHandle, retFbAddrs, totalFbCount);
- return FALSE;
- }
- retFbArray[idx].bufY = pvb->phys_addr;
- retFbArray[idx].bufCb = (PhysicalAddress)-1;
- retFbArray[idx].bufCr = (PhysicalAddress)-1;
- retFbArray[idx].updateFbInfo = TRUE;
- retFbArray[idx].size = framebufSize;
- retFbArray[idx].width = picWidth;
- }
- ret = VPU_DecAllocateFrameBuffer(decHandle, fbAllocInfo, &retFbArray[linearFbStartIdx]);
- if (ret != RETCODE_SUCCESS) {
- VLOG(ERR, "%s:%d failed to VPU_DecAllocateFrameBuffer() ret:%d\n",
- __FUNCTION__, __LINE__, ret);
- ReleaseVideoMemory(decHandle, retFbAddrs, totalFbCount);
- return FALSE;
- }
- }
- return TRUE;
- }
- BOOL AllocFBMemory(Uint32 coreIdx, vpu_buffer_t *pFbMem, FrameBuffer* pFb,Uint32 memSize, Uint32 memNum, Int32 memTypes, Int32 instIndex)
- {
- Uint32 i =0;
- for (i = 0; i < memNum; i++) {
- pFbMem[i].size = memSize;
- if (vdi_allocate_dma_memory(coreIdx, &pFbMem[i], memTypes, instIndex) < 0) {
- VLOG(ERR, "fail to allocate src buffer\n");
- return FALSE;
- }
- pFb[i].bufY = pFbMem[i].phys_addr;
- pFb[i].bufCb = (PhysicalAddress) - 1;
- pFb[i].bufCr = (PhysicalAddress) - 1;
- pFb[i].size = memSize;
- pFb[i].updateFbInfo = TRUE;
- }
- return TRUE;
- }
- BOOL Coda9AllocateDecPPUFrameBuffer(
- BOOL* pEnablePPU,
- DecHandle decHandle,
- TestDecConfig* config,
- FrameBuffer* retFbArray,
- vpu_buffer_t* retFbAddrs,
- Queue* ppuQ
- )
- {
- Uint32 stridePpu = 0;
- Uint32 sizePPUFb = 0;
- Uint32 rotate = config->coda9.rotate;
- Uint32 rotateWidth = 0;
- Uint32 rotateHeight = 0;
- Uint32 coreIndex = 0;
- const Uint32 ppuFbCount = 2; // #define PPU_FB_COUNT 2
- Int32 idx = 0;
- DecInitialInfo seqInfo;
- BOOL enablePPU = FALSE;
- vpu_buffer_t* pvb = NULL;
- FrameBufferAllocInfo fbAllocInfo;
- DRAMConfig* pDramCfg = NULL;
- DRAMConfig dramCfg = {0};
- osal_memset((void*)&fbAllocInfo, 0x00, sizeof(fbAllocInfo));
- osal_memset((void*)retFbArray, 0x00, sizeof(FrameBuffer)*ppuFbCount);
- enablePPU = (BOOL)(config->coda9.rotate > 0 || config->coda9.mirror > 0 ||
- config->coda9.enableTiled2Linear == TRUE || config->coda9.enableDering == TRUE);
- if(pEnablePPU) {
- *pEnablePPU = enablePPU;
- }
- if(!enablePPU) {
- VLOG(INFO, "<%s> No need PPU Buffers.\n", __FUNCTION__);
- return TRUE;
- }
- else {
- VLOG(INFO, "<%s> PPU Buffer : %d\n", __FUNCTION__, ppuFbCount);
- }
- pDramCfg = &dramCfg;
- VPU_DecGiveCommand(decHandle, GET_DRAM_CONFIG, pDramCfg);
- coreIndex = VPU_HANDLE_CORE_INDEX(decHandle);
- VPU_DecGiveCommand(decHandle, DEC_GET_SEQ_INFO, (void*)&seqInfo);
- rotateWidth = seqInfo.picWidth;
- rotateHeight = seqInfo.picHeight;
- if (rotate == 90 || rotate == 270) {
- rotateWidth = seqInfo.picHeight;
- rotateHeight = seqInfo.picWidth;
- }
- rotateWidth = VPU_ALIGN32(rotateWidth);
- rotateHeight = VPU_ALIGN32(rotateHeight);
- stridePpu = CalcStride(rotateWidth, rotateHeight, FORMAT_420, config->cbcrInterleave, LINEAR_FRAME_MAP, FALSE);
- sizePPUFb = VPU_GetFrameBufSize(decHandle, coreIndex, stridePpu, rotateHeight, LINEAR_FRAME_MAP, FORMAT_420, config->cbcrInterleave, pDramCfg);
- for (idx=0; idx<ppuFbCount; idx++) {
- pvb = &(retFbAddrs[idx]);
- pvb->size = sizePPUFb;
- if (vdi_allocate_dma_memory(coreIndex, pvb, DEC_ETC, decHandle->instIndex) < 0) {
- VLOG(ERR, "%s:%d fail to allocate frame buffer\n", __FUNCTION__, __LINE__);
- return FALSE;
- }
- retFbArray[idx].bufY = pvb->phys_addr;
- retFbArray[idx].bufCb = (PhysicalAddress)-1;
- retFbArray[idx].bufCr = (PhysicalAddress)-1;
- retFbArray[idx].updateFbInfo = TRUE;
- retFbArray[idx].size = sizePPUFb;
- }
- fbAllocInfo.mapType = LINEAR_FRAME_MAP;
- fbAllocInfo.cbcrInterleave = config->cbcrInterleave;
- fbAllocInfo.format = FORMAT_420;
- fbAllocInfo.stride = stridePpu;
- fbAllocInfo.height = rotateHeight;
- fbAllocInfo.endian = config->frameEndian;
- fbAllocInfo.lumaBitDepth = 8;
- fbAllocInfo.chromaBitDepth = 8;
- fbAllocInfo.num = ppuFbCount;
- fbAllocInfo.type = FB_TYPE_PPU;
- fbAllocInfo.size = sizePPUFb;
- if (RETCODE_SUCCESS != VPU_DecAllocateFrameBuffer(decHandle, fbAllocInfo, retFbArray)) {
- VLOG(ERR, "%s:%d failed to VPU_DecAllocateFrameBuffer() ret:%d\n", __FUNCTION__, __LINE__);
- return FALSE;
- }
- // Note: Please keep the below call sequence.
- VPU_DecGiveCommand(decHandle, SET_ROTATION_ANGLE, (void*)&(config->coda9.rotate));
- VPU_DecGiveCommand(decHandle, SET_MIRROR_DIRECTION, (void*)&(config->coda9.mirror));
- VPU_DecGiveCommand(decHandle, SET_ROTATOR_STRIDE, (void*)&stridePpu);
- for (idx=0; idx<ppuFbCount; idx++) {
- Queue_Enqueue(ppuQ, (void*)&retFbArray[idx]);
- }
- PrepareDecoderTest(decHandle);
- return TRUE;
- }
- RetCode SetUpDecoderOpenParam(
- DecOpenParam* param,
- TestDecConfig* config
- )
- {
- RetCode ret = RETCODE_SUCCESS;
- if (NULL == param || NULL == config) {
- ret = RETCODE_INVALID_PARAM;
- } else {
- param->bitstreamFormat = config->bitFormat;
- param->coreIdx = config->coreIdx;
- param->bitstreamMode = config->bitstreamMode;
- param->wtlEnable = config->enableWTL;
- param->wtlMode = config->wtlMode;
- param->cbcrInterleave = config->cbcrInterleave;
- param->nv21 = config->nv21;
- param->streamEndian = config->streamEndian;
- param->frameEndian = config->frameEndian;
- if (PRODUCT_ID_W_SERIES(config->productId)) {
- //WAVE
- param->bwOptimization = config->wave.bwOptimization;
- param->av1Format = config->wave.av1Format;
- } else {
- //CODA
- param->avcExtension = config->coda9.enableMvc;
- param->bwbEnable = config->coda9.enableBWB;
- param->mp4Class = config->coda9.mp4class;
- param->tiled2LinearEnable = config->coda9.enableTiled2Linear;
- param->tiled2LinearMode = config->coda9.tiled2LinearMode;
- param->mp4DeblkEnable = config->coda9.enableDeblock;
- }
- }
- return ret;
- }
- #if defined(_WIN32) || defined(__MSDOS__)
- #define DOS_FILESYSTEM
- #define IS_DIR_SEPARATOR(__c) ((__c == '/') || (__c == '\\'))
- #else
- /* UNIX style */
- #define IS_DIR_SEPARATOR(__c) (__c == '/')
- #endif
- char* GetDirname(
- const char* path
- )
- {
- int length;
- int i;
- char* upper_dir;
- if (path == NULL) return NULL;
- length = strlen(path);
- for (i=length-1; i>=0; i--) {
- if (IS_DIR_SEPARATOR(path[i])) break;
- }
- if (i<0) {
- upper_dir = strdup(".");
- } else {
- upper_dir = strdup(path);
- upper_dir[i] = 0;
- }
- return upper_dir;
- }
- char* GetBasename(
- const char* pathname
- )
- {
- const char* base = NULL;
- const char* p = pathname;
- if (p == NULL) {
- return NULL;
- }
- #if defined(DOS_FILESYSTEM)
- if (isalpha((int)p[0]) && p[1] == ':') {
- p += 2;
- }
- #endif
- for (base=p; *p; p++) {//lint !e443
- if (IS_DIR_SEPARATOR(*p)) {
- base = p+1;
- }
- }
- return (char*)base;
- }
- char* GetFileExtension(
- const char* filename
- )
- {
- Int32 len;
- Int32 i;
- len = strlen(filename);
- for (i=len-1; i>=0; i--) {
- if (filename[i] == '.') {
- return (char*)&filename[i+1];
- }
- }
- return NULL;
- }
- void byte_swap(unsigned char* data, int len)
- {
- Uint8 temp;
- Int32 i;
- for (i=0; i<len; i+=2) {
- temp = data[i];
- data[i] = data[i+1];
- data[i+1] = temp;
- }
- }
- void word_swap(unsigned char* data, int len)
- {
- Uint16 temp;
- Uint16* ptr = (Uint16*)data;
- Int32 i, size = len/(int)sizeof(Uint16);
- for (i=0; i<size; i+=2) {
- temp = ptr[i];
- ptr[i] = ptr[i+1];
- ptr[i+1] = temp;
- }
- }
- void dword_swap(unsigned char* data, int len)
- {
- Uint32 temp;
- Uint32* ptr = (Uint32*)data;
- Int32 i, size = len/(int)sizeof(Uint32);
- for (i=0; i<size; i+=2) {
- temp = ptr[i];
- ptr[i] = ptr[i+1];
- ptr[i+1] = temp;
- }
- }
- void lword_swap(unsigned char* data, int len)
- {
- Uint64 temp;
- Uint64* ptr = (Uint64*)data;
- Int32 i, size = len/(int)sizeof(Uint64);
- for (i=0; i<size; i+=2) {
- temp = ptr[i];
- ptr[i] = ptr[i+1];
- ptr[i+1] = temp;
- }
- }
- BOOL IsEndOfFile(FILE* fp)
- {
- BOOL result = FALSE;
- Int32 idx = 0;
- char cTemp;
- // Check current fp pos
- if (osal_feof(fp) != 0) {
- result = TRUE;
- }
- // Check next fp pos
- // Ignore newline character
- do {
- cTemp = fgetc(fp);
- idx++;
- if (osal_feof(fp) != 0) {
- result = TRUE;
- break;
- }
- } while (cTemp == '\n' || cTemp == '\r');
- // Revert fp pos
- idx *= (-1);
- osal_fseek(fp, idx, SEEK_CUR);
- return result;
- }
- BOOL CalcYuvSize(
- Int32 format,
- Int32 picWidth,
- Int32 picHeight,
- Int32 cbcrInterleave,
- size_t *lumaSize,
- size_t *chromaSize,
- size_t *frameSize,
- Int32 *bitDepth,
- Int32 *packedFormat,
- Int32 *yuv3p4b)
- {
- Int32 temp_picWidth;
- Int32 chromaWidth;
- if ( bitDepth != 0)
- *bitDepth = 0;
- if ( packedFormat != 0)
- *packedFormat = 0;
- if ( yuv3p4b != 0)
- *yuv3p4b = 0;
- if (!lumaSize || !chromaSize || !frameSize )
- return FALSE;
- switch (format)
- {
- case FORMAT_420:
- *lumaSize = picWidth * picHeight;
- if (picWidth & 0x01) {
- *chromaSize = (picWidth+1) * picHeight / 2;
- } else {
- *chromaSize = picWidth * picHeight / 2;
- }
- *frameSize = picWidth * picHeight * 3 /2;
- break;
- case FORMAT_YUYV:
- case FORMAT_YVYU:
- case FORMAT_UYVY:
- case FORMAT_VYUY:
- if ( packedFormat != 0)
- *packedFormat = 1;
- *lumaSize = picWidth * picHeight;
- *chromaSize = picWidth * picHeight;
- *frameSize = *lumaSize + *chromaSize;
- break;
- case FORMAT_224:
- *lumaSize = picWidth * picHeight;
- *chromaSize = picWidth * picHeight;
- *frameSize = picWidth * picHeight * 4 / 2;
- break;
- case FORMAT_422:
- *lumaSize = picWidth * picHeight;
- *chromaSize = picWidth * picHeight;
- *frameSize = picWidth * picHeight * 4 / 2;
- break;
- case FORMAT_444:
- *lumaSize = picWidth * picHeight;
- *chromaSize = picWidth * picHeight * 2;
- *frameSize = picWidth * picHeight * 3;
- break;
- case FORMAT_400:
- *lumaSize = picWidth * picHeight;
- *chromaSize = 0;
- *frameSize = picWidth * picHeight;
- break;
- case FORMAT_422_P10_16BIT_MSB:
- case FORMAT_422_P10_16BIT_LSB:
- if ( bitDepth != NULL) {
- *bitDepth = 10;
- }
- *lumaSize = picWidth * picHeight * 2;
- *chromaSize = *lumaSize;
- *frameSize = *lumaSize + *chromaSize;
- break;
- case FORMAT_420_P10_16BIT_MSB:
- case FORMAT_420_P10_16BIT_LSB:
- if ( bitDepth != 0)
- *bitDepth = 10;
- *lumaSize = picWidth * picHeight * 2;
- *chromaSize = picWidth * picHeight;
- *frameSize = *lumaSize + *chromaSize;
- break;
- case FORMAT_YUYV_P10_16BIT_MSB: // 4:2:2 10bit packed
- case FORMAT_YUYV_P10_16BIT_LSB:
- case FORMAT_YVYU_P10_16BIT_MSB:
- case FORMAT_YVYU_P10_16BIT_LSB:
- case FORMAT_UYVY_P10_16BIT_MSB:
- case FORMAT_UYVY_P10_16BIT_LSB:
- case FORMAT_VYUY_P10_16BIT_MSB:
- case FORMAT_VYUY_P10_16BIT_LSB:
- if ( bitDepth != 0)
- *bitDepth = 10;
- if ( packedFormat != 0)
- *packedFormat = 1;
- *lumaSize = picWidth * picHeight * 2;
- *chromaSize = picWidth * picHeight * 2;
- *frameSize = *lumaSize + *chromaSize;
- break;
- case FORMAT_420_P10_32BIT_MSB:
- case FORMAT_420_P10_32BIT_LSB:
- if ( bitDepth != 0)
- *bitDepth = 10;
- if ( yuv3p4b != 0)
- *yuv3p4b = 1;
- temp_picWidth = VPU_ALIGN32(picWidth);
- chromaWidth = ((VPU_ALIGN16(temp_picWidth/2*(1<<cbcrInterleave))+2)/3*4);
- if ( cbcrInterleave == 1)
- {
- *lumaSize = (temp_picWidth+2)/3*4 * picHeight;
- *chromaSize = chromaWidth * picHeight/2;
- } else {
- *lumaSize = (temp_picWidth+2)/3*4 * picHeight;
- *chromaSize = chromaWidth * picHeight/2*2;
- }
- *frameSize = *lumaSize + *chromaSize;
- break;
- case FORMAT_YUYV_P10_32BIT_MSB:
- case FORMAT_YUYV_P10_32BIT_LSB:
- case FORMAT_YVYU_P10_32BIT_MSB:
- case FORMAT_YVYU_P10_32BIT_LSB:
- case FORMAT_UYVY_P10_32BIT_MSB:
- case FORMAT_UYVY_P10_32BIT_LSB:
- case FORMAT_VYUY_P10_32BIT_MSB:
- case FORMAT_VYUY_P10_32BIT_LSB:
- if ( bitDepth != 0)
- *bitDepth = 10;
- if ( packedFormat != 0)
- *packedFormat = 1;
- if ( yuv3p4b != 0)
- *yuv3p4b = 1;
- *frameSize = ((picWidth*2)+2)/3*4 * picHeight;
- *lumaSize = *frameSize/2;
- *chromaSize = *frameSize/2;
- break;
- default:
- *frameSize = picWidth * picHeight * 3 / 2;
- VLOG(ERR, "%s:%d Not supported format(%d)\n", __FILE__, __LINE__, format);
- return FALSE;
- }
- return TRUE;
- }
- FrameBufferFormat GetPackedFormat (
- int srcBitDepth,
- int packedType,
- int p10bits,
- int msb)
- {
- FrameBufferFormat format = FORMAT_YUYV;
- // default pixel format = P10_16BIT_LSB (p10bits = 16, msb = 0)
- if (srcBitDepth == 8) {
- switch(packedType) {
- case PACKED_YUYV:
- format = FORMAT_YUYV;
- break;
- case PACKED_YVYU:
- format = FORMAT_YVYU;
- break;
- case PACKED_UYVY:
- format = FORMAT_UYVY;
- break;
- case PACKED_VYUY:
- format = FORMAT_VYUY;
- break;
- default:
- format = FORMAT_ERR;
- }
- }
- else if (srcBitDepth == 10) {
- switch(packedType) {
- case PACKED_YUYV:
- if (p10bits == 16) {
- format = (msb == 0) ? FORMAT_YUYV_P10_16BIT_LSB : FORMAT_YUYV_P10_16BIT_MSB;
- }
- else if (p10bits == 32) {
- format = (msb == 0) ? FORMAT_YUYV_P10_32BIT_LSB : FORMAT_YUYV_P10_32BIT_MSB;
- }
- else {
- format = FORMAT_ERR;
- }
- break;
- case PACKED_YVYU:
- if (p10bits == 16) {
- format = (msb == 0) ? FORMAT_YVYU_P10_16BIT_LSB : FORMAT_YVYU_P10_16BIT_MSB;
- }
- else if (p10bits == 32) {
- format = (msb == 0) ? FORMAT_YVYU_P10_32BIT_LSB : FORMAT_YVYU_P10_32BIT_MSB;
- }
- else {
- format = FORMAT_ERR;
- }
- break;
- case PACKED_UYVY:
- if (p10bits == 16) {
- format = (msb == 0) ? FORMAT_UYVY_P10_16BIT_LSB : FORMAT_UYVY_P10_16BIT_MSB;
- }
- else if (p10bits == 32) {
- format = (msb == 0) ? FORMAT_UYVY_P10_32BIT_LSB : FORMAT_UYVY_P10_32BIT_MSB;
- }
- else {
- format = FORMAT_ERR;
- }
- break;
- case PACKED_VYUY:
- if (p10bits == 16) {
- format = (msb == 0) ? FORMAT_VYUY_P10_16BIT_LSB : FORMAT_VYUY_P10_16BIT_MSB;
- }
- else if (p10bits == 32) {
- format = (msb == 0) ? FORMAT_VYUY_P10_32BIT_LSB : FORMAT_VYUY_P10_32BIT_MSB;
- }
- else {
- format = FORMAT_ERR;
- }
- break;
- default:
- format = FORMAT_ERR;
- }
- }
- else {
- format = FORMAT_ERR;
- }
- return format;
- }
- BOOL SetupEncoderOpenParam(
- EncOpenParam* param,
- TestEncConfig* config,
- ENC_CFG* encCfg
- )
- {
- param->bitstreamFormat = config->stdMode;
- if (strlen(config->cfgFileName) != 0) {
- if (GetEncOpenParam(param, config, encCfg) == FALSE) {
- VLOG(ERR, "[ERROR] Failed to parse CFG file(GetEncOpenParam)\n");
- return FALSE;
- }
- }
- else {
- if (GetEncOpenParamDefault(param, config) == FALSE) {
- VLOG(ERR, "[ERROR] Failed to parse CFG file(GetEncOpenParamDefault)\n");
- return FALSE;
- }
- }
- if (0 == param->streamBufCount) param->streamBufCount = ENC_STREAM_BUF_COUNT;
- if (0 == param->streamBufSize) param->streamBufSize = ENC_STREAM_BUF_SIZE;
- if (strlen(config->cfgFileName) != 0) {
- if (param->srcBitDepth == 8) {
- config->srcFormat = FORMAT_420;
- }
- else if (param->srcBitDepth == 10) {
- if (config->srcFormat == FORMAT_420) {
- config->srcFormat = FORMAT_420_P10_16BIT_MSB; //set srcFormat in ParseArgumentAndSetTestConfig function
- return FALSE;
- }
- }
- }
- if (config->optYuvPath[0] != 0)
- strcpy(config->yuvFileName, config->optYuvPath);
- #ifdef SUPPORT_LOOK_AHEAD_RC
- if ( config->larcPass == LOOK_AHEAD_RC_PASS1) {
- if (config->optYuvPath_larc_pass1[0] != 0)
- strcpy(config->yuvFileName, config->optYuvPath_larc_pass1);
- }
- #endif
- if (config->packedFormat >= PACKED_YUYV) {
- int p10bits = 0;
- FrameBufferFormat packedFormat;
- if (config->srcFormat == FORMAT_420_P10_16BIT_MSB || config->srcFormat == FORMAT_420_P10_16BIT_LSB )
- p10bits = 16;
- if (config->srcFormat == FORMAT_420_P10_32BIT_MSB || config->srcFormat == FORMAT_420_P10_32BIT_LSB )
- p10bits = 32;
- packedFormat = GetPackedFormat(param->srcBitDepth, config->packedFormat, p10bits, 1);
- if (packedFormat == -1) {
- VLOG(ERR, "[ERROR] Failed to GetPackedFormat\n");
- return FALSE;
- }
- param->srcFormat = packedFormat;
- param->nv21 = 0;
- param->cbcrInterleave = 0;
- }
- else {
- param->srcFormat = config->srcFormat;
- param->nv21 = config->nv21;
- }
- param->packedFormat = config->packedFormat;
- param->cbcrInterleave = config->cbcrInterleave;
- param->frameEndian = config->frame_endian;
- param->streamEndian = config->stream_endian;
- param->sourceEndian = config->source_endian;
- param->lineBufIntEn = config->lineBufIntEn;
- param->coreIdx = config->coreIdx;
- param->cbcrOrder = CBCR_ORDER_NORMAL;
- param->lowLatencyMode = (config->lowLatencyMode&0x3); // 2bits lowlatency mode setting. bit[1]: low latency interrupt enable, bit[0]: fast bitstream-packing enable.
- param->EncStdParam.waveParam.useLongTerm = (config->useAsLongtermPeriod > 0 && config->refLongtermPeriod > 0) ? 1 : 0;
- if (PRODUCT_ID_W_SERIES(config->productId)) {
- #ifdef SUPPORT_SOURCE_RELEASE_INTERRUPT
- param->srcReleaseIntEnable = config->srcReleaseIntEnable;
- #endif
- param->ringBufferEnable = config->ringBufferEnable;
- param->ringBufferWrapEnable = config->ringBufferWrapEnable;
- if (config->ringBufferEnable == TRUE) {
- param->streamBufCount = 1;
- param->lineBufIntEn = FALSE;
- }
- }
- if(PRODUCT_ID_NOT_W_SERIES(config->productId)) {
- param->bwbEnable = VPU_ENABLE_BWB;
- param->linear2TiledEnable = config->coda9.enableLinear2Tiled;
- param->linear2TiledMode = config->coda9.linear2TiledMode;
- param->ringBufferEnable = config->ringBufferEnable;
- if (TRUE == config->ringBufferEnable) {
- param->streamBufCount = 1;
- }
- #ifdef SUPPORT_NEW_SCHEDULER
- param->ringBufferWrapEnable = config->ringBufferWrapEnable;
- #endif
- }
- return TRUE;
- }
- void GenRegionToMap(
- VpuRect *region, /**< The size of the ROI region for H.265 (start X/Y in CTU, end X/Y int CTU) */
- int *roiQp,
- int num,
- Uint32 mapWidth,
- Uint32 mapHeight,
- Uint8 *roiCtuMap)
- {
- Int32 roi_id, blk_addr;
- Uint32 roi_map_size = mapWidth * mapHeight;
- //init roi map
- for (blk_addr=0; blk_addr<(Int32)roi_map_size; blk_addr++)
- roiCtuMap[blk_addr] = 0;
- //set roi map. roi_entry[i] has higher priority than roi_entry[i+1]
- for (roi_id=(Int32)num-1; roi_id>=0; roi_id--)
- {
- Uint32 x, y;
- VpuRect *roi = region + roi_id;
- for (y=roi->top; y<=roi->bottom; y++)
- {
- for (x=roi->left; x<=roi->right; x++)
- {
- roiCtuMap[y*mapWidth + x] = *(roiQp + roi_id);
- }
- }
- }
- }
- void GenRegionToQpMap(
- VpuRect *region, /**< The size of the ROI region for H.265 (start X/Y in CTU, end X/Y int CTU) */
- int *roiQp,
- int num,
- int initQp,
- Uint32 mapWidth,
- Uint32 mapHeight,
- Uint8 *roiCtuMap)
- {
- Int32 roi_id, blk_addr;
- Uint32 roi_map_size = mapWidth * mapHeight;
- //init roi map
- for (blk_addr=0; blk_addr<(Int32)roi_map_size; blk_addr++)
- roiCtuMap[blk_addr] = initQp;
- //set roi map. roi_entry[i] has higher priority than roi_entry[i+1]
- for (roi_id=(Int32)num-1; roi_id>=0; roi_id--)
- {
- Uint32 x, y;
- VpuRect *roi = region + roi_id;
- for (y=roi->top; y<=roi->bottom; y++)
- {
- for (x=roi->left; x<=roi->right; x++)
- {
- roiCtuMap[y*mapWidth + x] = *(roiQp + roi_id);
- }
- }
- }
- }
- int openRoiMapFile(TestEncConfig *encConfig)
- {
- if (encConfig->roi_enable) {
- if (encConfig) {
- ChangePathStyle(encConfig->roi_file_name);
- if ((encConfig->roi_file = osal_fopen(encConfig->roi_file_name, "r")) == NULL) {
- VLOG(ERR, "fail to open ROI file, %s\n", encConfig->roi_file_name);
- return FALSE;
- }
- }
- }
- return TRUE;
- }
- int allocateRoiMapBuf(EncHandle handle, TestEncConfig encConfig, vpu_buffer_t *vbRoi, int srcFbNum, int ctuNum)
- {
- int i;
- Int32 coreIdx = handle->coreIdx;
- if (encConfig.roi_enable) {
- //number of roi buffer should be the same as source buffer num.
- for (i = 0; i < srcFbNum ; i++) {
- vbRoi[i].size = ctuNum;
- if (vdi_allocate_dma_memory(coreIdx, &vbRoi[i], ENC_ETC, handle->instIndex) < 0) {
- VLOG(ERR, "fail to allocate ROI buffer\n" );
- return FALSE;
- }
- }
- }
- return TRUE;
- }
- // Define tokens for parsing scaling list file
- const char* MatrixType[SCALING_LIST_SIZE_NUM][SL_NUM_MATRIX] =
- {
- {"INTRA4X4_LUMA", "INTRA4X4_CHROMAU", "INTRA4X4_CHROMAV", "INTER4X4_LUMA", "INTER4X4_CHROMAU", "INTER4X4_CHROMAV"},
- {"INTRA8X8_LUMA", "INTRA8X8_CHROMAU", "INTRA8X8_CHROMAV", "INTER8X8_LUMA", "INTER8X8_CHROMAU", "INTER8X8_CHROMAV"},
- {"INTRA16X16_LUMA", "INTRA16X16_CHROMAU", "INTRA16X16_CHROMAV", "INTER16X16_LUMA", "INTER16X16_CHROMAU", "INTER16X16_CHROMAV"},
- {"INTRA32X32_LUMA", "INTRA32X32_CHROMAU_FROM16x16_CHROMAU", "INTRA32X32_CHROMAV_FROM16x16_CHROMAV","INTER32X32_LUMA", "INTER32X32_CHROMAU_FROM16x16_CHROMAU", "INTER32X32_CHROMAV_FROM16x16_CHROMAV"}
- };
- const char* MatrixType_DC[SCALING_LIST_SIZE_NUM - 2][SL_NUM_MATRIX] =
- {
- {"INTRA16X16_LUMA_DC", "INTRA16X16_CHROMAU_DC", "INTRA16X16_CHROMAV_DC", "INTER16X16_LUMA_DC", "INTER16X16_CHROMAU_DC", "INTER16X16_CHROMAV_DC"},
- {"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"},
- };
- static Uint8* get_sl_addr(UserScalingList* sl, Uint32 size_id, Uint32 mat_id)
- {
- Uint8* addr = NULL;
- switch(size_id)
- {
- case SCALING_LIST_4x4:
- addr = sl->s4[mat_id];
- break;
- case SCALING_LIST_8x8:
- addr = sl->s8[mat_id];
- break;
- case SCALING_LIST_16x16:
- addr = sl->s16[mat_id];
- break;
- case SCALING_LIST_32x32:
- addr = sl->s32[mat_id];
- break;
- }
- return addr;
- }
- int parse_user_scaling_list(UserScalingList* sl, FILE* fp_sl, CodStd stdMode)
- {
- #define LINE_SIZE (1024)
- const Uint32 scaling_list_size[SCALING_LIST_SIZE_NUM] = {16, 64, 64, 64};
- char line[LINE_SIZE];
- Uint32 i;
- Uint32 size_id, mat_id, data, num_coef = 0;
- Uint8* src = NULL;
- Uint8* ref = NULL;
- char* ret;
- const char* type_str;
- if ( fp_sl == NULL)
- return 0;
- for(size_id = 0; size_id < SCALING_LIST_SIZE_NUM; size_id++) {// for 4, 8, 16, 32
- num_coef = scaling_list_size[size_id];//lint !e644
- if (stdMode == STD_AVC && size_id > SCALING_LIST_8x8)
- break;
- for(mat_id = 0; mat_id < SL_NUM_MATRIX; mat_id++) { // for intra_y, intra_cb, intra_cr, inter_y, inter_cb, inter_cr
- src = get_sl_addr(sl, size_id, mat_id);
- if(size_id == SCALING_LIST_32x32 && (mat_id % 3)) { // derive scaling list of chroma32x32 from that of chrom16x16
- ref = get_sl_addr(sl, size_id - 1, mat_id);
- for(i = 0; i < num_coef; i++)
- src[i] = ref[i];
- }
- else {
- fseek(fp_sl,0,0);
- type_str = MatrixType[size_id][mat_id];
- do {
- ret = fgets(line, LINE_SIZE, fp_sl);
- if((ret == NULL) || (strstr(line, type_str) == NULL && feof(fp_sl))) {
- VLOG(ERR,"Error: can't read a scaling list matrix(%s)\n", type_str);
- return 0;
- }
- } while (strstr(line, type_str) == NULL);
- // get all coeff
- for(i = 0; i < num_coef; i++) {
- if(fscanf(fp_sl, "%d,", &data) != 1) {
- VLOG(ERR,"Error: can't read a scaling list matrix(%s)\n", type_str);
- return 0;
- }
- if (stdMode == STD_AVC && data < 4) {
- VLOG(ERR,"Error: invald value in scaling list matrix(%s %d)\n", type_str, data);
- return 0;
- }
- src[i] = data;
- }
- // get DC coeff for 16, 32
- if(size_id > SCALING_LIST_8x8) {
- fseek(fp_sl,0,0);
- type_str = MatrixType_DC[size_id - 2][mat_id];
- do {
- ret = fgets(line, LINE_SIZE, fp_sl);
- if((ret == NULL) || (strstr(line, type_str) == NULL && feof(fp_sl))) {
- VLOG(ERR,"Error: can't read a scaling list matrix(%s)\n", type_str);
- return 0;
- }
- } while (strstr(line, type_str) == NULL);
- if(fscanf(fp_sl, "%d,", &data) != 1) {
- VLOG(ERR,"Error: can't read a scaling list matrix(%s)\n", type_str);
- return 0;
- }
- if (stdMode == STD_AVC && data < 4) {
- VLOG(ERR,"Error: invald value in scaling list matrix(%s %d)\n", type_str, data);
- return 0;
- }
- if(size_id == SCALING_LIST_16x16)
- sl->s16dc[mat_id] = data;
- else // SCALING_LIST_32x32
- sl->s32dc[mat_id/3] = data;
- }
- }
- } // for matrix id
- } // for size id
- return 1;
- }
- int parse_custom_lambda(Uint32 buf[NUM_CUSTOM_LAMBDA], FILE* fp)
- {
- int i, j = 0;
- char lineStr[256] = {0, };
- for(i = 0; i < 52; i++)
- {
- if( NULL == fgets(lineStr, 256, fp) )
- {
- VLOG(ERR,"Error: can't read custom_lambda\n");
- return 0;
- }
- else
- {
- sscanf(lineStr, "%d\n", &buf[j++]);
- }
- }
- for(i = 0; i < 52; i++)
- {
- if( NULL == fgets(lineStr, 256, fp) )
- {
- VLOG(ERR,"Error: can't read custom_lambda\n");
- return 0;
- }
- else
- sscanf(lineStr, "%d\n", &buf[j++]);
- }
- return 1;
- }
- #if defined(PLATFORM_NON_OS) || defined (PLATFORM_LINUX)
- struct option* ConvertOptions(
- struct OptionExt* cnmOpt,
- Uint32 nItems
- )
- {
- struct option* opt;
- Uint32 i;
- opt = (struct option*)osal_malloc(sizeof(struct option) * nItems);
- if (opt == NULL) {
- return NULL;
- }
- for (i=0; i<nItems; i++) {
- osal_memcpy((void*)&opt[i], (void*)&cnmOpt[i], sizeof(struct option));
- }
- return opt;
- }
- #endif
- #ifdef PLATFORM_LINUX
- int mkdir_recursive(
- char *path,
- mode_t omode
- )
- {
- struct stat sb;
- mode_t numask, oumask;
- int first, last, retval;
- char *p;
- p = path;
- oumask = 0;
- retval = 0;
- if (p[0] == '/') /* Skip leading '/'. */
- ++p;
- for (first = 1, last = 0; !last ; ++p) {//lint !e441 !e443
- if (p[0] == '\0')
- last = 1;
- else if (p[0] != '/')
- continue;
- *p = '\0';
- if (p[1] == '\0')
- last = 1;
- if (first) {
- /*
- * POSIX 1003.2:
- * For each dir operand that does not name an existing
- * directory, effects equivalent to those cased by the
- * following command shall occcur:
- *
- * mkdir -p -m $(umask -S),u+wx $(dirname dir) &&
- * mkdir [-m mode] dir
- *
- * We change the user's umask and then restore it,
- * instead of doing chmod's.
- */
- oumask = umask(0);
- numask = oumask & ~(S_IWUSR | S_IXUSR);
- (void)umask(numask);
- first = 0;
- }
- if (last)
- (void)umask(oumask);
- if (mkdir(path, last ? omode : S_IRWXU | S_IRWXG | S_IRWXO) < 0) {
- if (errno == EEXIST || errno == EISDIR) {
- if (stat(path, &sb) < 0) {
- VLOG(INFO, "%s", path);
- retval = 1;
- break;
- } else if (!S_ISDIR(sb.st_mode)) {
- if (last)
- errno = EEXIST;
- else
- errno = ENOTDIR;
- VLOG(INFO, "%s", path);
- retval = 1;
- break;
- }
- } else {
- VLOG(INFO, "%s", path);
- retval = 1;
- break;
- }
- } else {
- VLOG(INFO, "%s", path);
- chmod(path, omode);
- }
- if (!last)
- *p = '/';
- }
- if (!first && !last)
- (void)umask(oumask);
- return (retval);
- }
- #endif
- int file_exist(
- char* path
- )
- {
- #ifdef _MSC_VER
- DWORD attributes;
- char temp[4096];
- LPCTSTR lp_path = (LPCTSTR)temp;
- if (path == NULL) {
- return FALSE;
- }
- strcpy(temp, path);
- replace_character(temp, '/', '\\');
- attributes = GetFileAttributes(lp_path);
- return (attributes != (DWORD)-1);
- #else
- return !access(path, F_OK);
- #endif
- }
- BOOL MkDir(
- char* path
- )
- {
- #if defined(PLATFORM_NON_OS) || defined(PLATFORM_QNX)
- /* need to implement */
- return FALSE;
- #else
- #ifdef _MSC_VER
- char cmd[4096];
- #endif
- if (file_exist(path))
- return TRUE;
- #ifdef _MSC_VER
- sprintf(cmd, "mkdir %s", path);
- replace_character(cmd, '/', '\\');
- if (system(cmd)) {
- return FALSE;
- }
- return TRUE;
- #else
- return mkdir_recursive(path, S_IRWXU | S_IRWXG | S_IRWXO);
- #endif
- #endif
- }
- void GetUserData(Int32 coreIdx, Uint8* pBase, vpu_buffer_t vbUserData, DecOutputInfo outputInfo)
- {
- int idx;
- user_data_entry_t* pEntry = (user_data_entry_t*)pBase;
- VpuReadMem(coreIdx, vbUserData.phys_addr, pBase, vbUserData.size, VPU_USER_DATA_ENDIAN);
- VLOG(INFO, "===== USER DATA(SEI OR VUI) : NUM(%d) =====\n", outputInfo.decOutputExtData.userDataNum);
- for (idx=0; idx<32; idx++) {
- if (outputInfo.decOutputExtData.userDataHeader&(1<<idx)) {
- VLOG(INFO, "\nUSERDATA INDEX: %02d offset: %8d size: %d\n", idx, pEntry[idx].offset, pEntry[idx].size);
- if (idx == H265_USERDATA_FLAG_MASTERING_COLOR_VOL) {
- h265_mastering_display_colour_volume_t* mastering;
- int i;
- mastering = (h265_mastering_display_colour_volume_t*)(pBase + pEntry[H265_USERDATA_FLAG_MASTERING_COLOR_VOL].offset);
- VLOG(INFO, " MASTERING DISPLAY COLOR VOLUME\n");
- for (i=0; i<3; i++) {
- VLOG(INFO, " PRIMARIES_X%d : %10d PRIMARIES_Y%d : %10d\n", i, mastering->display_primaries_x[i], i, mastering->display_primaries_y[i]);
- }
- VLOG(INFO, " WHITE_POINT_X: %10d WHITE_POINT_Y: %10d\n", mastering->white_point_x, mastering->white_point_y);
- VLOG(INFO, " MIN_LUMINANCE: %10d MAX_LUMINANCE: %10d\n", mastering->min_display_mastering_luminance, mastering->max_display_mastering_luminance);
- }
- if(idx == H265_USERDATA_FLAG_VUI)
- {
- h265_vui_param_t* vui;
- vui = (h265_vui_param_t*)(pBase + pEntry[H265_USERDATA_FLAG_VUI].offset);
- VLOG(INFO, " VUI SAR(%d, %d)\n", vui->sar_width, vui->sar_height);
- VLOG(INFO, " VIDEO FORMAT(%d)\n", vui->video_format);
- VLOG(INFO, " COLOUR PRIMARIES(%d)\n", vui->colour_primaries);
- VLOG(INFO, "log2_max_mv_length_horizontal: %d\n", vui->log2_max_mv_length_horizontal);
- VLOG(INFO, "log2_max_mv_length_vertical : %d\n", vui->log2_max_mv_length_vertical);
- VLOG(INFO, "video_full_range_flag : %d\n", vui->video_full_range_flag);
- VLOG(INFO, "transfer_characteristics : %d\n", vui->transfer_characteristics);
- VLOG(INFO, "matrix_coeffs : %d\n", vui->matrix_coefficients);
- }
- if (idx == H265_USERDATA_FLAG_CHROMA_RESAMPLING_FILTER_HINT) {
- h265_chroma_resampling_filter_hint_t* c_resampleing_filter_hint;
- Uint32 i,j;
- c_resampleing_filter_hint = (h265_chroma_resampling_filter_hint_t*)(pBase + pEntry[H265_USERDATA_FLAG_CHROMA_RESAMPLING_FILTER_HINT].offset);
- VLOG(INFO, " CHROMA_RESAMPLING_FILTER_HINT\n");
- 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);
- VLOG(INFO, " VER_FILTERING_FIELD_PROCESSING_FLAG: %d \n", c_resampleing_filter_hint->ver_filtering_field_processing_flag);
- if (c_resampleing_filter_hint->ver_chroma_filter_idc == 1 || c_resampleing_filter_hint->hor_chroma_filter_idc == 1) {
- VLOG(INFO, " TARGET_FORMAT_IDC: %d \n", c_resampleing_filter_hint->target_format_idc);
- if (c_resampleing_filter_hint->ver_chroma_filter_idc == 1) {
- VLOG(INFO, " NUM_VERTICAL_FILTERS: %d \n", c_resampleing_filter_hint->num_vertical_filters);
- for (i=0; i<c_resampleing_filter_hint->num_vertical_filters; i++) {
- VLOG(INFO, " VER_TAP_LENGTH_M1[%d]: %d \n", i, c_resampleing_filter_hint->ver_tap_length_minus1[i]);
- for (j=0; j<c_resampleing_filter_hint->ver_tap_length_minus1[i]; j++) {
- VLOG(INFO, " VER_FILTER_COEFF[%d][%d]: %d \n", i, j, c_resampleing_filter_hint->ver_filter_coeff[i][j]);
- }
- }
- }
- if (c_resampleing_filter_hint->hor_chroma_filter_idc == 1) {
- VLOG(INFO, " NUM_HORIZONTAL_FILTERS: %d \n", c_resampleing_filter_hint->num_horizontal_filters);
- for (i=0; i<c_resampleing_filter_hint->num_horizontal_filters; i++) {
- VLOG(INFO, " HOR_TAP_LENGTH_M1[%d]: %d \n", i, c_resampleing_filter_hint->hor_tap_length_minus1[i]);
- for (j=0; j<c_resampleing_filter_hint->hor_tap_length_minus1[i]; j++) {
- VLOG(INFO, " HOR_FILTER_COEFF[%d][%d]: %d \n", i, j, c_resampleing_filter_hint->hor_filter_coeff[i][j]);
- }
- }
- }
- }
- }
- if (idx == H265_USERDATA_FLAG_KNEE_FUNCTION_INFO) {
- h265_knee_function_info_t* knee_function;
- knee_function = (h265_knee_function_info_t*)(pBase + pEntry[H265_USERDATA_FLAG_KNEE_FUNCTION_INFO].offset);
- VLOG(INFO, " FLAG_KNEE_FUNCTION_INFO\n");
- VLOG(INFO, " KNEE_FUNCTION_ID: %10d\n", knee_function->knee_function_id);
- VLOG(INFO, " KNEE_FUNCTION_CANCEL_FLAG: %d\n", knee_function->knee_function_cancel_flag);
- if (!knee_function->knee_function_cancel_flag) {
- int i;
- VLOG(INFO, " KNEE_FUNCTION_PERSISTENCE_FLAG: %10d\n", knee_function->knee_function_persistence_flag);
- VLOG(INFO, " INPUT_D_RANGE: %d\n", knee_function->input_d_range);
- VLOG(INFO, " INPUT_DISP_LUMINANCE: %d\n", knee_function->input_disp_luminance);
- VLOG(INFO, " OUTPUT_D_RANGE: %d\n", knee_function->output_d_range);
- VLOG(INFO, " OUTPUT_DISP_LUMINANCE: %d\n", knee_function->output_disp_luminance);
- VLOG(INFO, " NUM_KNEE_POINTS_M1: %d\n", knee_function->num_knee_points_minus1);
- for (i=0; i<knee_function->num_knee_points_minus1; i++) {
- VLOG(INFO, " INPUT_KNEE_POINT: %10d OUTPUT_KNEE_POINT: %10d\n", knee_function->input_knee_point[i], knee_function->output_knee_point[i]);
- }
- }
- }
- if (idx == H265_USERDATA_FLAG_ITU_T_T35_PRE)
- {
- char* itu_t_t35 = (char*)(pBase + pEntry[H265_USERDATA_FLAG_ITU_T_T35_PRE].offset);
- Uint32 i;
- 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);
- for(i=0; i<pEntry[H265_USERDATA_FLAG_ITU_T_T35_PRE].size; i++)
- {
- VLOG(INFO, "%02X ", (unsigned char)(itu_t_t35[i]));
- }
- VLOG(INFO, "\n");
- }
- if (idx == H265_USERDATA_FLAG_ITU_T_T35_PRE_1)
- {
- char* itu_t_t35 = (char*)(pBase + pEntry[H265_USERDATA_FLAG_ITU_T_T35_PRE_1].offset);
- Uint32 i;
- 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);
- for(i=0; i<pEntry[H265_USERDATA_FLAG_ITU_T_T35_PRE_1].size; i++)
- {
- VLOG(INFO, "%02X ", (unsigned char)(itu_t_t35[i]));
- }
- VLOG(INFO, "\n");
- }
- if (idx == H265_USERDATA_FLAG_ITU_T_T35_PRE_2)
- {
- char* itu_t_t35 = (char*)(pBase + pEntry[H265_USERDATA_FLAG_ITU_T_T35_PRE_2].offset);
- Uint32 i;
- //user_data_entry_t* pEntry_prev;
- 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);
- for(i=0; i<pEntry[H265_USERDATA_FLAG_ITU_T_T35_PRE_2].size; i++)
- {
- VLOG(INFO, "%02X ", (unsigned char)(itu_t_t35[i]));
- }
- VLOG(INFO, "\n");
- //pEntry_prev = (user_data_entry_t*)(itu_t_t35 + pEntry[H265_USERDATA_FLAG_ITU_T_T35_PRE_2].size - sizeof(user_data_entry_t));
- //pEntry[H265_USERDATA_FLAG_ITU_T_T35_PRE_2].size = pEntry_prev->size;
- //pEntry[H265_USERDATA_FLAG_ITU_T_T35_PRE_2].offset = pEntry_prev->offset;
- }
- if (idx == H265_USERDATA_FLAG_COLOUR_REMAPPING_INFO) {
- int c, i;
- h265_colour_remapping_info_t* colour_remapping;
- colour_remapping = (h265_colour_remapping_info_t*)(pBase + pEntry[H265_USERDATA_FLAG_COLOUR_REMAPPING_INFO].offset);
- VLOG(INFO, " COLOUR_REMAPPING_INFO\n");
- VLOG(INFO, " COLOUR_REMAP_ID: %10d\n", colour_remapping->colour_remap_id);
- VLOG(INFO, " COLOUR_REMAP_CANCEL_FLAG: %d\n", colour_remapping->colour_remap_cancel_flag);
- if (!colour_remapping->colour_remap_cancel_flag) {
- VLOG(INFO, " COLOUR_REMAP_PERSISTENCE_FLAG: %d\n", colour_remapping->colour_remap_persistence_flag);
- VLOG(INFO, " COLOUR_REMAP_VIDEO_SIGNAL_INFO_PRESENT_FLAG: %d\n", colour_remapping->colour_remap_video_signal_info_present_flag);
- if (colour_remapping->colour_remap_video_signal_info_present_flag) {
- VLOG(INFO, " COLOUR_REMAP_FULL_RANGE_FLAG: %d\n", colour_remapping->colour_remap_full_range_flag);
- VLOG(INFO, " COLOUR_REMAP_PRIMARIES: %d\n", colour_remapping->colour_remap_primaries);
- VLOG(INFO, " COLOUR_REMAP_TRANSFER_FUNCTION: %d\n", colour_remapping->colour_remap_transfer_function);
- VLOG(INFO, " COLOUR_REMAP_MATRIX_COEFFICIENTS: %d\n", colour_remapping->colour_remap_matrix_coefficients);
- }
- VLOG(INFO, " COLOUR_REMAP_INPUT_BIT_DEPTH: %d\n", colour_remapping->colour_remap_input_bit_depth);
- VLOG(INFO, " COLOUR_REMAP_BIT_DEPTH: %d\n", colour_remapping->colour_remap_bit_depth);
- for( c = 0; c < H265_MAX_LUT_NUM_VAL; c++ )
- {
- VLOG(INFO, " PRE_LUT_NUM_VAL_MINUS1[%d]: %d\n", c, colour_remapping->pre_lut_num_val_minus1[c]);
- if(colour_remapping->pre_lut_num_val_minus1[c] > 0)
- {
- for( i = 0; i <= colour_remapping->pre_lut_num_val_minus1[c]; i++ )
- {
- VLOG(INFO, " PRE_LUT_CODED_VALUE[%d][%d]: %d\n", c, i, colour_remapping->pre_lut_coded_value[c][i]);
- VLOG(INFO, " PRE_LUT_TARGET_VALUE[%d][%d]: %d\n", c, i, colour_remapping->pre_lut_target_value[c][i]);
- }
- }
- }
- VLOG(INFO, " COLOUR_REMAP_MATRIX_PRESENT_FLAG: %d\n", colour_remapping->colour_remap_matrix_present_flag);
- if(colour_remapping->colour_remap_matrix_present_flag) {
- VLOG(INFO, " LOG2_MATRIX_DENOM: %d\n", colour_remapping->log2_matrix_denom);
- for( c = 0; c < H265_MAX_COLOUR_REMAP_COEFFS; c++ )
- for( i = 0; i < H265_MAX_COLOUR_REMAP_COEFFS; i++ )
- VLOG(INFO, " LOG2_MATRIX_DENOM[%d][%d]: %d\n", c, i, colour_remapping->colour_remap_coeffs[c][i]);
- }
- for( c = 0; c < H265_MAX_LUT_NUM_VAL; c++ )
- {
- VLOG(INFO, " POST_LUT_NUM_VAL_MINUS1[%d]: %d\n", c, colour_remapping->post_lut_num_val_minus1[c]);
- if(colour_remapping->post_lut_num_val_minus1[c] > 0)
- {
- for( i = 0; i <= colour_remapping->post_lut_num_val_minus1[c]; i++)
- {
- VLOG(INFO, " POST_LUT_CODED_VALUE[%d][%d]: %d\n", c, i, colour_remapping->post_lut_coded_value[c][i]);
- VLOG(INFO, " POST_LUT_TARGET_VALUE[%d][%d]: %d\n", c, i, colour_remapping->post_lut_target_value[c][i]);
- }
- }
- }
- }
- }
- if (idx == H265_USERDATA_FLAG_TONE_MAPPING_INFO) {
- h265_tone_mapping_info_t* tone_mapping;
- tone_mapping = (h265_tone_mapping_info_t*)(pBase + pEntry[H265_USERDATA_FLAG_TONE_MAPPING_INFO].offset);
- VLOG(INFO, " FLAG_TONE_MAPPING_INFO\n");
- VLOG(INFO, " TONE_MAP_ID: %10d\n", tone_mapping->tone_map_id);
- VLOG(INFO, " TONE_MAP_CANCEL_FLAG: %d\n", tone_mapping->tone_map_cancel_flag);
- if (!tone_mapping->tone_map_cancel_flag) {
- int i;
- VLOG(INFO, " TONE_MAP_PERSISTENCE_FLAG: %10d\n", tone_mapping->tone_map_persistence_flag);
- VLOG(INFO, " CODED_DATA_BIT_DEPTH : %d\n", tone_mapping->coded_data_bit_depth);
- VLOG(INFO, " TARGET_BIT_DEPTH : %d\n", tone_mapping->target_bit_depth);
- VLOG(INFO, " TONE_MAP_MODEL_ID : %d\n", tone_mapping->tone_map_model_id);
- VLOG(INFO, " MIN_VALUE : %d\n", tone_mapping->min_value);
- VLOG(INFO, " MAX_VALUE : %d\n", tone_mapping->max_value);
- VLOG(INFO, " SIGMOID_MIDPOINT : %d\n", tone_mapping->sigmoid_midpoint);
- VLOG(INFO, " SIGMOID_MIDPOINT : %d\n", tone_mapping->sigmoid_width);
- for (i=0; i<(1<<tone_mapping->target_bit_depth); i++) {
- VLOG(INFO, " START_OF_CODED_INTERVAL[%d] : %d\n", i, tone_mapping->start_of_coded_interval[i]); // [1 << target_bit_depth] // 10bits
- }
- VLOG(INFO, " NUM_PIVOTS : %d\n", tone_mapping->num_pivots); // [(1 << coded_data_bit_depth)?1][(1 << target_bit_depth)-1] // 10bits
- for (i=0; i<tone_mapping->num_pivots; i++) {
- VLOG(INFO, " CODED_PIVOT_VALUE[%d] : %d, TARGET_PIVOT_VALUE[%d] : %d\n", i, tone_mapping->coded_pivot_value[i]
- , i, tone_mapping->target_pivot_value[i]);
- }
- VLOG(INFO, " CAMERA_ISO_SPEED_IDC : %d\n", tone_mapping->camera_iso_speed_idc);
- VLOG(INFO, " CAMERA_ISO_SPEED_VALUE : %d\n", tone_mapping->camera_iso_speed_value);
- VLOG(INFO, " EXPOSURE_INDEX_IDC : %d\n", tone_mapping->exposure_index_idc);
- VLOG(INFO, " EXPOSURE_INDEX_VALUE : %d\n", tone_mapping->exposure_index_value);
- VLOG(INFO, " EXPOSURE_INDEX_COMPESATION_VALUE_SIGN_FLAG : %d\n", tone_mapping->exposure_compensation_value_sign_flag);
- VLOG(INFO, " EXPOSURE_INDEX_COMPESATION_VALUE_NUMERATOR : %d\n", tone_mapping->exposure_compensation_value_numerator);
- VLOG(INFO, " EXPOSURE_INDEX_COMPESATION_VALUE_DENOM_IDC : %d\n", tone_mapping->exposure_compensation_value_denom_idc);
- VLOG(INFO, " REF_SCREEN_LUMINANCE_WHITE : %d\n", tone_mapping->ref_screen_luminance_white);
- VLOG(INFO, " EXTENDED_RANGE_WHITE_LEVEL : %d\n", tone_mapping->extended_range_white_level);
- VLOG(INFO, " NOMINAL_BLACK_LEVEL_CODE_VALUE : %d\n", tone_mapping->nominal_black_level_code_value);
- VLOG(INFO, " NOMINAL_WHITE_LEVEL_CODE_VALUE : %d\n", tone_mapping->nominal_white_level_code_value);
- VLOG(INFO, " EXTENDED_WHITE_LEVEL_CODE_VALUE : %d\n", tone_mapping->extended_white_level_code_value);
- }
- VLOG(INFO, "\n");
- }
- if (idx == H265_USERDATA_FLAG_CONTENT_LIGHT_LEVEL_INFO) {
- h265_content_light_level_info_t* content_light_level;
- content_light_level = (h265_content_light_level_info_t*)(pBase + pEntry[H265_USERDATA_FLAG_CONTENT_LIGHT_LEVEL_INFO].offset);
- VLOG(INFO, " CONTNET_LIGHT_INFO\n");
- VLOG(INFO, " MAX_CONTENT_LIGHT_LEVEL : %d\n", content_light_level->max_content_light_level);
- VLOG(INFO, " MAX_PIC_AVERAGE_LIGHT_LEVEL : %d\n", content_light_level->max_pic_average_light_level);
- VLOG(INFO, "\n");
- }
- if (idx == H265_USERDATA_FLAG_FILM_GRAIN_CHARACTERISTICS_INFO) {
- h265_film_grain_characteristics_t* film_grain_characteristics;
- int i,j,c;
- film_grain_characteristics = (h265_film_grain_characteristics_t*)(pBase + pEntry[H265_USERDATA_FLAG_FILM_GRAIN_CHARACTERISTICS_INFO].offset);
- VLOG(INFO, " FILM_GRAIN_CHARACTERISTICS_INFO\n");
- VLOG(INFO, " FILM_GRAIN_CHARACTERISTICS_CANCEL_FLAG: %d\n", film_grain_characteristics->film_grain_characteristics_cancel_flag);
- if (!film_grain_characteristics->film_grain_characteristics_cancel_flag) {
- VLOG(INFO, " FILM_GRAIN_MODEL_ID: %10d\n", film_grain_characteristics->film_grain_model_id);
- VLOG(INFO, " SEPARATE_COLOUR_DESCRIPTION_PRESENT_FLAG: %d\n", film_grain_characteristics->separate_colour_description_present_flag);
- if (film_grain_characteristics->separate_colour_description_present_flag)
- {
- VLOG(INFO, " FILM_GRAIN_BIT_DEPTH_LUMA_MINUS8: %d\n", film_grain_characteristics->film_grain_bit_depth_luma_minus8);
- VLOG(INFO, " FILM_GRAIN_BIT_DEPTH_CHROMA_MINUS8: %d\n", film_grain_characteristics->film_grain_bit_depth_chroma_minus8);
- VLOG(INFO, " FILM_GRAIN_FULL_RANGE_FLAG: %d\n", film_grain_characteristics->film_grain_full_range_flag);
- VLOG(INFO, " FILM_GRAIN_COLOUR_PRIMARIES: %d\n", film_grain_characteristics->film_grain_colour_primaries);
- VLOG(INFO, " FILM_GRAIN_TRANSFER_CHARACTERISTICS: %d\n", film_grain_characteristics->film_grain_transfer_characteristics);
- VLOG(INFO, " FILM_GRAIN_MATRIX_COEFF: %d\n", film_grain_characteristics->film_grain_matrix_coeffs);
- }
- }
- VLOG(INFO, " BLENDING_MODE_ID: %d\n", film_grain_characteristics->blending_mode_id);
- VLOG(INFO, " LOG2_SCALE_FACTOR: %d\n", film_grain_characteristics->log2_scale_factor);
- for(c=0; c < H265_MAX_NUM_FILM_GRAIN_COMPONENT; c++ )
- {
- VLOG(INFO, " COMP_MODEL_PRESENT_FLAG[%d]: %d\n", c, film_grain_characteristics->comp_model_present_flag[c]);
- }
- for(c=0; c < H265_MAX_NUM_FILM_GRAIN_COMPONENT; c++ )
- {
- if(film_grain_characteristics->comp_model_present_flag[c])
- {
- VLOG(INFO, " NUM_INTENSITY_INTERVALS_MINUS1[%d]: %d\n", c, film_grain_characteristics->num_intensity_intervals_minus1[c]);
- VLOG(INFO, " NUM_MODEL_VALUES_MINUS1[%d]: %d\n", c, film_grain_characteristics->num_model_values_minus1[c]);
- for(i=0; i <= film_grain_characteristics->num_intensity_intervals_minus1[c]; i++)
- {
- VLOG(INFO, " INTENSITY_INTERVAL_LOWER_BOUND[%d][%d]: %d\n", c, i, film_grain_characteristics->intensity_interval_lower_bound[c][i]);
- VLOG(INFO, " INTENSITY_INTERVAL_UPPER_BOUND[%d][%d]: %d\n", c, i, film_grain_characteristics->intensity_interval_upper_bound[c][i]);
- for(j=0; j <= film_grain_characteristics->num_model_values_minus1[c]; j++)
- {
- VLOG(INFO, " COMP_MODEL_VALUE[%d][%d][%d]: %d\n", c, i, j, film_grain_characteristics->comp_model_value[c][i][j]);
- }
- }
- }
- }
- VLOG(INFO, " FILM_GRAIN_CHARACTERISTICS_PERSISTENCE_FLAG: %d\n", film_grain_characteristics->film_grain_characteristics_persistence_flag);
- VLOG(INFO, "\n");
- }
- }
- }
- VLOG(INFO, "===========================================\n");
- }
- void SetMapData(int coreIdx, TestEncConfig encConfig, EncOpenParam encOP, EncParam *encParam, int srcFrameWidth, int srcFrameHeight, unsigned long addrCustomMap)
- {
- int productId = VPU_GetProductId(coreIdx);
- if (productId == PRODUCT_ID_521 && encOP.bitstreamFormat == STD_AVC) {
- Uint8 roiMapBuf[MAX_MB_NUM] = {0,};
- Uint8 modeMapBuf[MAX_MB_NUM] = {0,};
- AvcEncCustomMap customMapBuf[MAX_MB_NUM]; // custom map 1 MB data = 8bits
- int MbWidth = VPU_ALIGN16(encOP.picWidth) >> 4;
- int MbHeight = VPU_ALIGN16(encOP.picHeight) >> 4;
- int h, w, mbAddr;
- osal_memset(&customMapBuf[0], 0x00, MAX_MB_NUM);
- if (encParam->customMapOpt.customRoiMapEnable == 1) {
- int sumQp = 0;
- int bufSize = MbWidth*MbHeight;
- if (osal_fread(&roiMapBuf[0], 1, bufSize, encConfig.roi_file) != bufSize) {
- osal_fseek(encConfig.roi_file, 0, SEEK_SET);
- osal_fread(&roiMapBuf[0], 1, bufSize, encConfig.roi_file);
- }
- for (h = 0; h < MbHeight; h++) {
- for (w = 0; w < MbWidth; w++) {
- mbAddr = w + h*MbWidth;
- customMapBuf[mbAddr].field.mb_qp = MAX(MIN(roiMapBuf[mbAddr]&0x3f, 51), 0);
- sumQp += customMapBuf[mbAddr].field.mb_qp;
- }
- }
- encParam->customMapOpt.roiAvgQp = (sumQp + (bufSize>>1)) / bufSize; // round off.
- }
- if (encParam->customMapOpt.customModeMapEnable == 1) {
- int bufSize = MbWidth*MbHeight;
- if (osal_fread(&modeMapBuf[0], 1, bufSize, encConfig.mode_map_file) != bufSize) {
- osal_fseek(encConfig.mode_map_file, 0, SEEK_SET);
- osal_fread(&modeMapBuf[0], 1, bufSize, encConfig.mode_map_file);
- }
- for (h = 0; h < MbHeight; h++) {
- for (w = 0; w < MbWidth; w++) {
- mbAddr = w + h*MbWidth;
- customMapBuf[mbAddr].field.mb_force_mode = modeMapBuf[mbAddr] & 0x3;
- }
- }
- }
- encParam->customMapOpt.addrCustomMap = addrCustomMap;
- vdi_write_memory(coreIdx, encParam->customMapOpt.addrCustomMap, (unsigned char*)customMapBuf, MAX_MB_NUM, VDI_LITTLE_ENDIAN);
- }
- else {
- // for HEVC custom map.
- Uint8 roiMapBuf[MAX_SUB_CTU_NUM] = {0,};
- Uint8 lambdaMapBuf[MAX_SUB_CTU_NUM] = {0,};
- Uint8 modeMapBuf[MAX_CTU_NUM] = {0,};
- EncCustomMap customMapBuf[MAX_CTU_NUM]; // custom map 1 CTU data = 64bits
- int ctuMapWidthCnt = VPU_ALIGN64(encOP.picWidth) >> 6;
- int ctuMapHeightCnt = VPU_ALIGN64(encOP.picHeight) >> 6;
- int ctuMapStride = VPU_ALIGN64(encOP.picWidth) >> 6;
- int subCtuMapStride = VPU_ALIGN64(encOP.picWidth) >> 5;
- int i, sumQp = 0;;
- int h, w, ctuPos, initQp;
- Uint8* src;
- VpuRect region[MAX_ROI_NUMBER]; /**< The size of the ROI region for H.265 (start X/Y in CTU, end X/Y int CTU) */
- 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. */
- osal_memset(&customMapBuf[0], 0x00, MAX_CTU_NUM * 8);
- if (encParam->customMapOpt.customRoiMapEnable == 1) {
- int bufSize = (VPU_ALIGN64(encOP.picWidth) >> 5) * (VPU_ALIGN64(encOP.picHeight) >> 5);
- if (productId == PRODUCT_ID_521) {
- if (osal_fread(&roiMapBuf[0], 1, bufSize, encConfig.roi_file) != bufSize) {
- osal_fseek(encConfig.roi_file, 0, SEEK_SET);
- osal_fread(&roiMapBuf[0], 1, bufSize, encConfig.roi_file);
- }
- }
- else {
- int roiNum = 0;
- // sample code to convert ROI coordinate to ROI map.
- osal_memset(®ion[0], 0, sizeof(VpuRect)*MAX_ROI_NUMBER);
- osal_memset(&roiQp[0], 0, sizeof(int)*MAX_ROI_NUMBER);
- if (encConfig.roi_file_name[0]) {
- char lineStr[256] = {0,};
- int val;
- fgets(lineStr, 256, encConfig.roi_file);
- sscanf(lineStr, "%x\n", &val);
- if (val != 0xFFFF)
- VLOG(ERR, "can't find the picture delimiter \n");
- fgets(lineStr, 256, encConfig.roi_file);
- sscanf(lineStr, "%d\n", &val); // picture index
- fgets(lineStr, 256, encConfig.roi_file);
- sscanf(lineStr, "%d\n", &roiNum); // number of roi regions
- for (i = 0; i < roiNum; i++) {
- fgets(lineStr, 256, encConfig.roi_file);
- if (parseRoiCtuModeParam(lineStr, ®ion[i], &roiQp[i], srcFrameWidth, srcFrameHeight) == 0) {
- VLOG(ERR, "CFG file error : %s value is not available. \n", encConfig.roi_file_name);
- }
- }
- }
- encParam->customMapOpt.customRoiMapEnable = (roiNum != 0) ? encParam->customMapOpt.customRoiMapEnable : 0;
- if (encParam->customMapOpt.customRoiMapEnable) {
- initQp = encConfig.roi_avg_qp;
- GenRegionToQpMap(®ion[0], &roiQp[0], roiNum, initQp, subCtuMapStride, VPU_ALIGN64(encOP.picHeight) >> 5, &roiMapBuf[0]);
- }
- }
- for (h = 0; h < ctuMapHeightCnt; h++) {
- src = &roiMapBuf[subCtuMapStride * h * 2];
- for (w = 0; w < ctuMapWidthCnt; w++, src += 2) {
- ctuPos = (h * ctuMapStride + w);
- // store in the order of sub-ctu.
- customMapBuf[ctuPos].field.sub_ctu_qp_0 = MAX(MIN(*src, 51), 0);
- customMapBuf[ctuPos].field.sub_ctu_qp_1 = MAX(MIN(*(src + 1), 51), 0);
- customMapBuf[ctuPos].field.sub_ctu_qp_2 = MAX(MIN(*(src + subCtuMapStride), 51), 0);
- customMapBuf[ctuPos].field.sub_ctu_qp_3 = MAX(MIN(*(src + subCtuMapStride + 1), 51), 0);
- 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);
- }
- }
- if (productId == PRODUCT_ID_521)
- encParam->customMapOpt.roiAvgQp = (sumQp + (bufSize>>1)) / bufSize; // round off.
- }
- if (encParam->customMapOpt.customLambdaMapEnable == 1) {
- int bufSize = (VPU_ALIGN64(encOP.picWidth) >> 5) * (VPU_ALIGN64(encOP.picHeight) >> 5);
- if (osal_fread(&lambdaMapBuf[0], 1, bufSize, encConfig.lambda_map_file) != bufSize) {
- osal_fseek(encConfig.lambda_map_file, 0, SEEK_SET);
- osal_fread(&lambdaMapBuf[0], 1, bufSize, encConfig.lambda_map_file);
- }
- for (h = 0; h < ctuMapHeightCnt; h++) {
- src = &lambdaMapBuf[subCtuMapStride * 2 * h];
- for (w = 0; w < ctuMapWidthCnt; w++, src += 2) {
- ctuPos = (h * ctuMapStride + w);
- // store in the order of sub-ctu.
- customMapBuf[ctuPos].field.lambda_sad_0 = *src;
- customMapBuf[ctuPos].field.lambda_sad_1 = *(src + 1);
- customMapBuf[ctuPos].field.lambda_sad_2 = *(src + subCtuMapStride);
- customMapBuf[ctuPos].field.lambda_sad_3 = *(src + subCtuMapStride + 1);
- }
- }
- }
- if ((encParam->customMapOpt.customModeMapEnable == 1)
- || (encParam->customMapOpt.customCoefDropEnable == 1)) {
- int bufSize = (VPU_ALIGN64(encOP.picWidth) >> 6) * (VPU_ALIGN64(encOP.picHeight) >> 6);
- if (osal_fread(&modeMapBuf[0], 1, bufSize, encConfig.mode_map_file) != bufSize) {
- osal_fseek(encConfig.mode_map_file, 0, SEEK_SET);
- osal_fread(&modeMapBuf[0], 1, bufSize, encConfig.mode_map_file);
- }
- for (h = 0; h < ctuMapHeightCnt; h++) {
- src = &modeMapBuf[ctuMapStride * h];
- for (w = 0; w < ctuMapWidthCnt; w++, src++) {
- ctuPos = (h * ctuMapStride + w);
- customMapBuf[ctuPos].field.ctu_force_mode = (*src) & 0x3;
- customMapBuf[ctuPos].field.ctu_coeff_drop = ((*src) >> 2) & 0x1;
- }
- }
- }
- encParam->customMapOpt.addrCustomMap = addrCustomMap;
- vdi_write_memory(coreIdx, encParam->customMapOpt.addrCustomMap, (unsigned char*)customMapBuf, MAX_CTU_NUM * 8, VDI_LITTLE_ENDIAN);
- }
- }
- RetCode SetChangeParam(EncHandle handle, TestEncConfig encConfig, EncOpenParam encOP, Int32 changedCount)
- {
- int i;
- RetCode ret;
- ENC_CFG ParaChagCfg;
- EncChangeParam changeParam;
- osal_memset(&ParaChagCfg, 0x00, sizeof(ENC_CFG));
- osal_memset(&changeParam, 0x00, sizeof(EncChangeParam));
- parseWaveChangeParamCfgFile(&ParaChagCfg, encConfig.changeParam[changedCount].cfgName);
- changeParam.enable_option = encConfig.changeParam[changedCount].enableOption;
- if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_PPS) {
- changeParam.constIntraPredFlag = ParaChagCfg.waveCfg.constIntraPredFlag;
- changeParam.lfCrossSliceBoundaryEnable = ParaChagCfg.waveCfg.lfCrossSliceBoundaryEnable;
- changeParam.weightPredEnable = ParaChagCfg.waveCfg.weightPredEnable;
- changeParam.disableDeblk = ParaChagCfg.waveCfg.disableDeblk;
- changeParam.betaOffsetDiv2 = ParaChagCfg.waveCfg.betaOffsetDiv2;
- changeParam.tcOffsetDiv2 = ParaChagCfg.waveCfg.tcOffsetDiv2;
- changeParam.chromaCbQpOffset = ParaChagCfg.waveCfg.chromaCbQpOffset;
- changeParam.chromaCrQpOffset = ParaChagCfg.waveCfg.chromaCrQpOffset;
- if (encConfig.stdMode == STD_AVC) {
- changeParam.transform8x8Enable = ParaChagCfg.waveCfg.transform8x8;
- changeParam.entropyCodingMode = ParaChagCfg.waveCfg.entropyCodingMode;
- }
- }
- if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_INDEPEND_SLICE) {
- changeParam.independSliceMode = ParaChagCfg.waveCfg.independSliceMode;
- changeParam.independSliceModeArg = ParaChagCfg.waveCfg.independSliceModeArg;
- if (encConfig.stdMode == STD_AVC) {
- changeParam.avcSliceMode = ParaChagCfg.waveCfg.avcSliceMode;
- changeParam.avcSliceArg = ParaChagCfg.waveCfg.avcSliceArg;
- }
- }
- if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_DEPEND_SLICE) {
- changeParam.dependSliceMode = ParaChagCfg.waveCfg.dependSliceMode;
- changeParam.dependSliceModeArg = ParaChagCfg.waveCfg.dependSliceModeArg;
- }
- if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_RDO) {
- changeParam.coefClearDisable = ParaChagCfg.waveCfg.coefClearDisable;
- changeParam.intraNxNEnable = ParaChagCfg.waveCfg.intraNxNEnable;
- changeParam.maxNumMerge = ParaChagCfg.waveCfg.maxNumMerge;
- changeParam.customLambdaEnable = ParaChagCfg.waveCfg.customLambdaEnable;
- changeParam.customMDEnable = ParaChagCfg.waveCfg.customMDEnable;
- if (encConfig.stdMode == STD_AVC) {
- changeParam.rdoSkip = ParaChagCfg.waveCfg.rdoSkip;
- changeParam.lambdaScalingEnable = ParaChagCfg.waveCfg.lambdaScalingEnable;
- }
- }
- if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_RC_TARGET_RATE) {
- changeParam.bitRate = ParaChagCfg.RcBitRate;
- }
- if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_RC) {
- changeParam.hvsQPEnable = ParaChagCfg.waveCfg.hvsQPEnable;
- changeParam.hvsQpScale = ParaChagCfg.waveCfg.hvsQpScale;
- changeParam.vbvBufferSize = ParaChagCfg.VbvBufferSize;
- }
- if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_RC_MIN_MAX_QP) {
- changeParam.minQpI = ParaChagCfg.waveCfg.minQp;
- changeParam.maxQpI = ParaChagCfg.waveCfg.maxQp;
- changeParam.hvsMaxDeltaQp = ParaChagCfg.waveCfg.maxDeltaQp;
- }
- if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_RC_INTER_MIN_MAX_QP) {
- changeParam.minQpP = ParaChagCfg.waveCfg.minQp;
- changeParam.minQpB = ParaChagCfg.waveCfg.minQp;
- changeParam.maxQpP = ParaChagCfg.waveCfg.maxQp;
- changeParam.maxQpB = ParaChagCfg.waveCfg.maxQp;
- }
- if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_RC_BIT_RATIO_LAYER) {
- for (i=0 ; i<MAX_GOP_NUM; i++)
- changeParam.fixedBitRatio[i] = ParaChagCfg.waveCfg.fixedBitRatio[i];
- }
- if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_BG) {
- changeParam.s2fmeDisable = ParaChagCfg.waveCfg.s2fmeDisable;
- changeParam.bgThrDiff = ParaChagCfg.waveCfg.bgThrDiff;
- changeParam.bgThrMeanDiff = ParaChagCfg.waveCfg.bgThrMeanDiff;
- changeParam.bgLambdaQp = ParaChagCfg.waveCfg.bgLambdaQp;
- changeParam.bgDeltaQp = ParaChagCfg.waveCfg.bgDeltaQp;
- changeParam.s2fmeDisable = ParaChagCfg.waveCfg.s2fmeDisable;
- }
- if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_NR) {
- changeParam.nrYEnable = ParaChagCfg.waveCfg.nrYEnable;
- changeParam.nrCbEnable = ParaChagCfg.waveCfg.nrCbEnable;
- changeParam.nrCrEnable = ParaChagCfg.waveCfg.nrCrEnable;
- changeParam.nrNoiseEstEnable = ParaChagCfg.waveCfg.nrNoiseEstEnable;
- changeParam.nrNoiseSigmaY = ParaChagCfg.waveCfg.nrNoiseSigmaY;
- changeParam.nrNoiseSigmaCb = ParaChagCfg.waveCfg.nrNoiseSigmaCb;
- changeParam.nrNoiseSigmaCr = ParaChagCfg.waveCfg.nrNoiseSigmaCr;
- changeParam.nrIntraWeightY = ParaChagCfg.waveCfg.nrIntraWeightY;
- changeParam.nrIntraWeightCb = ParaChagCfg.waveCfg.nrIntraWeightCb;
- changeParam.nrIntraWeightCr = ParaChagCfg.waveCfg.nrIntraWeightCr;
- changeParam.nrInterWeightY = ParaChagCfg.waveCfg.nrInterWeightY;
- changeParam.nrInterWeightCb = ParaChagCfg.waveCfg.nrInterWeightCb;
- changeParam.nrInterWeightCr = ParaChagCfg.waveCfg.nrInterWeightCr;
- }
- if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_CUSTOM_MD) {
- changeParam.pu04DeltaRate = ParaChagCfg.waveCfg.pu04DeltaRate;
- changeParam.pu08DeltaRate = ParaChagCfg.waveCfg.pu08DeltaRate;
- changeParam.pu16DeltaRate = ParaChagCfg.waveCfg.pu16DeltaRate;
- changeParam.pu32DeltaRate = ParaChagCfg.waveCfg.pu32DeltaRate;
- changeParam.pu04IntraPlanarDeltaRate = ParaChagCfg.waveCfg.pu04IntraPlanarDeltaRate;
- changeParam.pu04IntraDcDeltaRate = ParaChagCfg.waveCfg.pu04IntraDcDeltaRate;
- changeParam.pu04IntraAngleDeltaRate = ParaChagCfg.waveCfg.pu04IntraAngleDeltaRate;
- changeParam.pu08IntraPlanarDeltaRate = ParaChagCfg.waveCfg.pu08IntraPlanarDeltaRate;
- changeParam.pu08IntraDcDeltaRate = ParaChagCfg.waveCfg.pu08IntraDcDeltaRate;
- changeParam.pu08IntraAngleDeltaRate = ParaChagCfg.waveCfg.pu08IntraAngleDeltaRate;
- changeParam.pu16IntraPlanarDeltaRate = ParaChagCfg.waveCfg.pu16IntraPlanarDeltaRate;
- changeParam.pu16IntraDcDeltaRate = ParaChagCfg.waveCfg.pu16IntraDcDeltaRate;
- changeParam.pu16IntraAngleDeltaRate = ParaChagCfg.waveCfg.pu16IntraAngleDeltaRate;
- changeParam.pu32IntraPlanarDeltaRate = ParaChagCfg.waveCfg.pu32IntraPlanarDeltaRate;
- changeParam.pu32IntraDcDeltaRate = ParaChagCfg.waveCfg.pu32IntraDcDeltaRate;
- changeParam.pu32IntraAngleDeltaRate = ParaChagCfg.waveCfg.pu32IntraAngleDeltaRate;
- changeParam.cu08IntraDeltaRate = ParaChagCfg.waveCfg.cu08IntraDeltaRate;
- changeParam.cu08InterDeltaRate = ParaChagCfg.waveCfg.cu08InterDeltaRate;
- changeParam.cu08MergeDeltaRate = ParaChagCfg.waveCfg.cu08MergeDeltaRate;
- changeParam.cu16IntraDeltaRate = ParaChagCfg.waveCfg.cu16IntraDeltaRate;
- changeParam.cu16InterDeltaRate = ParaChagCfg.waveCfg.cu16InterDeltaRate;
- changeParam.cu16MergeDeltaRate = ParaChagCfg.waveCfg.cu16MergeDeltaRate;
- changeParam.cu32IntraDeltaRate = ParaChagCfg.waveCfg.cu32IntraDeltaRate;
- changeParam.cu32InterDeltaRate = ParaChagCfg.waveCfg.cu32InterDeltaRate;
- changeParam.cu32MergeDeltaRate = ParaChagCfg.waveCfg.cu32MergeDeltaRate;
- }
- if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_INTRA_PARAM) {
- changeParam.intraQP = ParaChagCfg.waveCfg.intraQP;
- changeParam.intraPeriod = ParaChagCfg.waveCfg.intraPeriod;
- }
- ret = VPU_EncGiveCommand(handle, ENC_SET_PARA_CHANGE, &changeParam);
- return ret;
- }
- BOOL GetBitstreamToBuffer(
- EncHandle handle,
- Uint8* pBuffer,
- PhysicalAddress rdAddr,
- PhysicalAddress wrAddr,
- PhysicalAddress streamBufStartAddr,
- PhysicalAddress streamBufEndAddr,
- Uint32 streamSize,
- EndianMode endian,
- BOOL ringbufferEnabled
- )
- {
- Int32 coreIdx = -1;
- Uint32 room = 0;
- if (NULL == handle) {
- VLOG(ERR, "<%s:%d> NULL point exception\n", __FUNCTION__, __LINE__);
- return FALSE;
- }
- coreIdx = VPU_HANDLE_CORE_INDEX(handle);
- if (0 == streamBufStartAddr || 0 == streamBufEndAddr) {
- VLOG(ERR, "<%s:%d> Wrong Address, start or end Addr\n", __FUNCTION__, __LINE__);
- return FALSE;
- } else if (0 == rdAddr || 0 == wrAddr) {
- VLOG(ERR, "<%s:%d> Wrong Address, read or write Addr\n", __FUNCTION__, __LINE__);
- return FALSE;
- }
- if (TRUE == ringbufferEnabled) {
- if ((rdAddr + streamSize) > streamBufEndAddr) {
- //wrap around on ringbuffer
- room = streamBufEndAddr - rdAddr;
- vdi_read_memory(coreIdx, rdAddr, pBuffer, room, endian);
- vdi_read_memory(coreIdx, streamBufStartAddr, pBuffer + room, (streamSize-room), endian);
- }
- else {
- vdi_read_memory(coreIdx, rdAddr, pBuffer, streamSize, endian);
- }
- } else { //Line buffer
- vdi_read_memory(coreIdx, rdAddr, pBuffer, streamSize, endian);
- }
- return TRUE;
- }
|