vpuapi.c 114 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566
  1. /*
  2. * Copyright (c) 2019, Chips&Media
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  18. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include "vpuapifunc.h"
  26. #include "product.h"
  27. #include "wave/wave5_regdefine.h"
  28. #include "wave/wave5.h"
  29. #define W5_RET_DEC_DISPLAY_SIZE (W5_REG_BASE + 0x01D8) // [FIX ME] delete ? or not?
  30. #define INVALID_CORE_INDEX_RETURN_ERROR(_coreIdx) \
  31. if (_coreIdx >= MAX_NUM_VPU_CORE) \
  32. return -1;
  33. static const Uint16* s_pusBitCode[MAX_NUM_VPU_CORE] = {NULL,};
  34. static int s_bitCodeSize[MAX_NUM_VPU_CORE] = {0,};
  35. Uint32 __VPU_BUSY_TIMEOUT = VPU_BUSY_CHECK_TIMEOUT;
  36. static RetCode CheckDecInstanceValidity(CodecInst* pCodecInst)
  37. {
  38. RetCode ret;
  39. if (pCodecInst == NULL)
  40. return RETCODE_INVALID_HANDLE;
  41. ret = CheckInstanceValidity(pCodecInst);
  42. if (ret != RETCODE_SUCCESS) {
  43. return RETCODE_INVALID_HANDLE;
  44. }
  45. if (!pCodecInst->inUse) {
  46. return RETCODE_INVALID_HANDLE;
  47. }
  48. return ProductVpuDecCheckCapability(pCodecInst);
  49. }
  50. Int32 VPU_IsInit(Uint32 coreIdx)
  51. {
  52. Int32 pc;
  53. INVALID_CORE_INDEX_RETURN_ERROR(coreIdx);
  54. pc = ProductVpuIsInit(coreIdx);
  55. return pc;
  56. }
  57. Int32 VPU_WaitInterrupt(Uint32 coreIdx, int timeout)
  58. {
  59. Int32 ret;
  60. CodecInst* instance;
  61. INVALID_CORE_INDEX_RETURN_ERROR(coreIdx);
  62. if ((instance=GetPendingInst(coreIdx)) != NULL) {
  63. ret = ProductVpuWaitInterrupt(instance, timeout);
  64. }
  65. else {
  66. ret = -1;
  67. }
  68. return ret;
  69. }
  70. Int32 VPU_WaitInterruptEx(VpuHandle handle, int timeout)
  71. {
  72. Int32 ret;
  73. CodecInst *pCodecInst;
  74. pCodecInst = handle;
  75. INVALID_CORE_INDEX_RETURN_ERROR(pCodecInst->coreIdx);
  76. ret = ProductVpuWaitInterrupt(pCodecInst, timeout);
  77. return ret;
  78. }
  79. void VPU_ClearInterrupt(Uint32 coreIdx)
  80. {
  81. /* clear all interrupt flags */
  82. ProductVpuClearInterrupt(coreIdx, 0xffff);
  83. }
  84. void VPU_ClearInterruptEx(VpuHandle handle, Int32 intrFlag)
  85. {
  86. CodecInst *pCodecInst;
  87. pCodecInst = handle;
  88. ProductVpuClearInterrupt(pCodecInst->coreIdx, intrFlag);
  89. }
  90. int VPU_GetFrameBufSize(VpuHandle handle, int coreIdx, int stride, int height, int mapType, int format, int interleave, DRAMConfig *pDramCfg)
  91. {
  92. int productId;
  93. CodecInst *pCodecInst;
  94. pCodecInst = handle;
  95. UNREFERENCED_PARAMETER(interleave); /*!<< for backward compatiblity */
  96. if (coreIdx < 0 || coreIdx >= MAX_NUM_VPU_CORE)
  97. return -1;
  98. productId = ProductVpuGetId(coreIdx);
  99. return ProductCalculateFrameBufSize(pCodecInst, productId, stride, height, (TiledMapType)mapType, (FrameBufferFormat)format, (BOOL)interleave, pDramCfg);
  100. }
  101. int VPU_GetProductId(int coreIdx)
  102. {
  103. Int32 productId;
  104. INVALID_CORE_INDEX_RETURN_ERROR(coreIdx);
  105. if ((productId=ProductVpuGetId(coreIdx)) != PRODUCT_ID_NONE) {
  106. return productId;
  107. }
  108. if (vdi_init(coreIdx) < 0)
  109. return -1;
  110. EnterLock(coreIdx);
  111. if (ProductVpuScan(coreIdx) == FALSE)
  112. productId = -1;
  113. else
  114. productId = ProductVpuGetId(coreIdx);
  115. LeaveLock((coreIdx));
  116. vdi_release(coreIdx);
  117. return productId;
  118. }
  119. int VPU_GetOpenInstanceNum(Uint32 coreIdx)
  120. {
  121. INVALID_CORE_INDEX_RETURN_ERROR(coreIdx);
  122. return vdi_get_instance_num(coreIdx);
  123. }
  124. static RetCode InitializeVPU(Uint32 coreIdx, const Uint16* code, Uint32 size)
  125. {
  126. RetCode ret;
  127. if (vdi_init(coreIdx) < 0)
  128. return RETCODE_FAILURE;
  129. EnterLock(coreIdx);
  130. if (vdi_get_instance_num(coreIdx) > 0) {
  131. if (ProductVpuScan(coreIdx) == 0) {
  132. LeaveLock(coreIdx);
  133. return RETCODE_NOT_FOUND_VPU_DEVICE;
  134. }
  135. }
  136. /* force to reset vpu, so that the vpu in a clean state */
  137. #if 0
  138. if (VPU_IsInit(coreIdx) != 0) {
  139. ProductVpuReInit(coreIdx, (void *)code, size);
  140. LeaveLock(coreIdx);
  141. return RETCODE_CALLED_BEFORE;
  142. }
  143. #endif
  144. InitCodecInstancePool(coreIdx);
  145. ret = ProductVpuReset(coreIdx, SW_RESET_ON_BOOT);
  146. if (ret != RETCODE_SUCCESS) {
  147. LeaveLock(coreIdx);
  148. return ret;
  149. }
  150. #if defined(SUPPORT_SW_UART) || defined(SUPPORT_SW_UART_V2)
  151. create_sw_uart_thread(coreIdx);
  152. usleep(500*1000);
  153. #endif
  154. ret = ProductVpuInit(coreIdx, (void*)code, size);
  155. if (ret != RETCODE_SUCCESS) {
  156. LeaveLock(coreIdx);
  157. return ret;
  158. }
  159. LeaveLock(coreIdx);
  160. return RETCODE_SUCCESS;
  161. }
  162. RetCode VPU_Init(Uint32 coreIdx)
  163. {
  164. if (coreIdx >= MAX_NUM_VPU_CORE)
  165. return RETCODE_INVALID_PARAM;
  166. if (s_bitCodeSize[coreIdx] == 0)
  167. return RETCODE_NOT_FOUND_BITCODE_PATH;
  168. return InitializeVPU(coreIdx, s_pusBitCode[coreIdx], s_bitCodeSize[coreIdx]);
  169. }
  170. RetCode VPU_InitWithBitcode(Uint32 coreIdx, const Uint16* code, Uint32 size)
  171. {
  172. if (coreIdx >= MAX_NUM_VPU_CORE)
  173. return RETCODE_INVALID_PARAM;
  174. if (code == NULL || size == 0)
  175. return RETCODE_INVALID_PARAM;
  176. s_pusBitCode[coreIdx] = NULL;
  177. s_pusBitCode[coreIdx] = (Uint16 *)osal_malloc(size*sizeof(Uint16));
  178. if (!s_pusBitCode[coreIdx])
  179. return RETCODE_INSUFFICIENT_RESOURCE;
  180. osal_memcpy((void *)s_pusBitCode[coreIdx], (const void *)code, size*sizeof(Uint16));
  181. s_bitCodeSize[coreIdx] = size;
  182. return InitializeVPU(coreIdx, code, size);
  183. }
  184. RetCode VPU_DeInit(Uint32 coreIdx)
  185. {
  186. int ret;
  187. if (coreIdx >= MAX_NUM_VPU_CORE)
  188. return RETCODE_INVALID_PARAM;
  189. EnterLock(coreIdx);
  190. if (s_pusBitCode[coreIdx]) {
  191. osal_free((void *)s_pusBitCode[coreIdx]);
  192. }
  193. s_pusBitCode[coreIdx] = NULL;
  194. s_bitCodeSize[coreIdx] = 0;
  195. LeaveLock(coreIdx);
  196. #if defined(SUPPORT_SW_UART) || defined(SUPPORT_SW_UART_V2)
  197. destory_sw_uart_thread();
  198. #endif
  199. ret = vdi_release(coreIdx);
  200. if (ret != 0)
  201. return RETCODE_FAILURE;
  202. return RETCODE_SUCCESS;
  203. }
  204. RetCode VPU_GetVersionInfo(Uint32 coreIdx, Uint32 *versionInfo, Uint32 *revision, Uint32 *productId)
  205. {
  206. RetCode ret;
  207. if (coreIdx >= MAX_NUM_VPU_CORE)
  208. return RETCODE_INVALID_PARAM;
  209. EnterLock(coreIdx);
  210. if (ProductVpuIsInit(coreIdx) == 0) {
  211. LeaveLock(coreIdx);
  212. return RETCODE_NOT_INITIALIZED;
  213. }
  214. if (GetPendingInst(coreIdx)) {
  215. LeaveLock(coreIdx);
  216. return RETCODE_FRAME_NOT_COMPLETE;
  217. }
  218. if (productId != NULL) {
  219. *productId = ProductVpuGetId(coreIdx);
  220. }
  221. ret = ProductVpuGetVersion(coreIdx, versionInfo, revision);
  222. LeaveLock(coreIdx);
  223. return ret;
  224. }
  225. RetCode VPU_GetProductInfo(Uint32 coreIdx, VpuAttr *productInfo)
  226. {
  227. RetCode ret;
  228. if (coreIdx >= MAX_NUM_VPU_CORE)
  229. return RETCODE_INVALID_PARAM;
  230. EnterLock(coreIdx);
  231. if (ProductVpuIsInit(coreIdx) == 0) {
  232. LeaveLock(coreIdx);
  233. return RETCODE_NOT_INITIALIZED;
  234. }
  235. if (GetPendingInst(coreIdx)) {
  236. LeaveLock(coreIdx);
  237. return RETCODE_FRAME_NOT_COMPLETE;
  238. }
  239. productInfo->productId = ProductVpuGetId(coreIdx);
  240. ret = ProductVpuGetProductInfo(coreIdx, productInfo);
  241. LeaveLock(coreIdx);
  242. return ret;
  243. }
  244. RetCode VPU_DecOpen(DecHandle* pHandle, DecOpenParam* pop)
  245. {
  246. CodecInst * pCodecInst;
  247. DecInfo* pDecInfo;
  248. RetCode ret;
  249. ret = ProductCheckDecOpenParam(pop);
  250. if (ret != RETCODE_SUCCESS)
  251. return ret;
  252. EnterLock(pop->coreIdx);
  253. if (VPU_IsInit(pop->coreIdx) == 0) {
  254. LeaveLock(pop->coreIdx);
  255. return RETCODE_NOT_INITIALIZED;
  256. }
  257. ret = GetCodecInstance(pop->coreIdx, &pCodecInst);
  258. if (ret != RETCODE_SUCCESS)
  259. {
  260. *pHandle = 0;
  261. LeaveLock(pop->coreIdx);
  262. return ret;
  263. }
  264. pCodecInst->isDecoder = TRUE;
  265. *pHandle = pCodecInst;
  266. pDecInfo = &pCodecInst->CodecInfo->decInfo;
  267. osal_memset(pDecInfo, 0x00, sizeof(DecInfo));
  268. osal_memcpy((void*)&pDecInfo->openParam, pop, sizeof(DecOpenParam));
  269. if (pop->bitstreamFormat == STD_MPEG4) {
  270. pCodecInst->codecMode = MP4_DEC;
  271. pCodecInst->codecModeAux = MP4_AUX_MPEG4;
  272. }
  273. else if (pop->bitstreamFormat == STD_AVC) {
  274. if (pCodecInst->productId == PRODUCT_ID_521 || pCodecInst->productId == PRODUCT_ID_511 || pCodecInst->productId == PRODUCT_ID_517) {
  275. pCodecInst->codecMode = W_AVC_DEC;
  276. }
  277. else {
  278. pCodecInst->codecMode = AVC_DEC;
  279. pCodecInst->codecModeAux = pop->avcExtension;
  280. }
  281. }
  282. else if (pop->bitstreamFormat == STD_VC1) {
  283. pCodecInst->codecMode = VC1_DEC;
  284. }
  285. else if (pop->bitstreamFormat == STD_MPEG2) {
  286. pCodecInst->codecMode = MP2_DEC;
  287. }
  288. else if (pop->bitstreamFormat == STD_H263) {
  289. pCodecInst->codecMode = MP4_DEC;
  290. pCodecInst->codecModeAux = MP4_AUX_MPEG4;
  291. }
  292. else if (pop->bitstreamFormat == STD_DIV3) {
  293. pCodecInst->codecMode = DV3_DEC;
  294. pCodecInst->codecModeAux = MP4_AUX_DIVX3;
  295. }
  296. else if (pop->bitstreamFormat == STD_RV) {
  297. pCodecInst->codecMode = RV_DEC;
  298. }
  299. else if (pop->bitstreamFormat == STD_AVS) {
  300. pCodecInst->codecMode = AVS_DEC;
  301. }
  302. else if (pop->bitstreamFormat == STD_THO) {
  303. pCodecInst->codecMode = VPX_DEC;
  304. pCodecInst->codecModeAux = VPX_AUX_THO;
  305. }
  306. else if (pop->bitstreamFormat == STD_VP3) {
  307. pCodecInst->codecMode = VPX_DEC;
  308. pCodecInst->codecModeAux = VPX_AUX_THO;
  309. }
  310. else if (pop->bitstreamFormat == STD_VP8) {
  311. pCodecInst->codecMode = VPX_DEC;
  312. pCodecInst->codecModeAux = VPX_AUX_VP8;
  313. }
  314. else if (pop->bitstreamFormat == STD_HEVC) {
  315. pCodecInst->codecMode = W_HEVC_DEC;
  316. }
  317. else if (pop->bitstreamFormat == STD_VP9) {
  318. pCodecInst->codecMode = W_VP9_DEC;
  319. }
  320. else if (pop->bitstreamFormat == STD_AVS2) {
  321. pCodecInst->codecMode = W_AVS2_DEC;
  322. }
  323. else if (pop->bitstreamFormat == STD_SVAC) {
  324. pCodecInst->codecMode = W_SVAC_DEC;
  325. }
  326. else if (pop->bitstreamFormat == STD_AV1) {
  327. pCodecInst->codecMode = W_AV1_DEC;
  328. }
  329. else {
  330. LeaveLock(pop->coreIdx);
  331. return RETCODE_INVALID_PARAM;
  332. }
  333. pDecInfo->wtlEnable = pop->wtlEnable;
  334. pDecInfo->wtlMode = pop->wtlMode;
  335. if (!pDecInfo->wtlEnable)
  336. pDecInfo->wtlMode = 0;
  337. pDecInfo->streamWrPtr = pop->bitstreamBuffer;
  338. pDecInfo->streamRdPtr = pop->bitstreamBuffer;
  339. pDecInfo->frameDelay = -1;
  340. pDecInfo->streamBufStartAddr = pop->bitstreamBuffer;
  341. pDecInfo->streamBufSize = pop->bitstreamBufferSize;
  342. pDecInfo->streamBufEndAddr = pop->bitstreamBuffer + pop->bitstreamBufferSize;
  343. pDecInfo->reorderEnable = VPU_REORDER_ENABLE;
  344. pDecInfo->mirrorDirection = MIRDIR_NONE;
  345. pDecInfo->prevFrameEndPos = pop->bitstreamBuffer;
  346. pDecInfo->tempIdSelectMode = pop->tempIdSelectMode;
  347. pDecInfo->targetSubLayerId = DECODE_ALL_TEMPORAL_LAYERS;
  348. pDecInfo->relTargetLayerId = 0;
  349. if ((ret=ProductVpuDecBuildUpOpenParam(pCodecInst, pop)) != RETCODE_SUCCESS) {
  350. *pHandle = 0;
  351. LeaveLock(pCodecInst->coreIdx);
  352. return ret;
  353. }
  354. pDecInfo->tiled2LinearEnable = pop->tiled2LinearEnable;
  355. pDecInfo->tiled2LinearMode = pop->tiled2LinearMode;
  356. if (!pDecInfo->tiled2LinearEnable)
  357. pDecInfo->tiled2LinearMode = 0; //coda980 only
  358. if (!pDecInfo->wtlEnable) //coda980, wave320, wave410 only
  359. pDecInfo->wtlMode = 0;
  360. osal_memset((void*)&pDecInfo->cacheConfig, 0x00, sizeof(MaverickCacheConfig));
  361. LeaveLock(pCodecInst->coreIdx);
  362. return RETCODE_SUCCESS;
  363. }
  364. RetCode VPU_DecClose(DecHandle handle)
  365. {
  366. CodecInst * pCodecInst;
  367. DecInfo * pDecInfo;
  368. RetCode ret;
  369. int i;
  370. ret = CheckDecInstanceValidity(handle);
  371. if (ret != RETCODE_SUCCESS) {
  372. return ret;
  373. }
  374. pCodecInst = handle;
  375. if (!pCodecInst) {
  376. return RETCODE_INVALID_HANDLE;
  377. }
  378. pDecInfo = &pCodecInst->CodecInfo->decInfo;
  379. EnterLock(pCodecInst->coreIdx);
  380. if ((ret=ProductVpuDecFiniSeq(pCodecInst)) != RETCODE_SUCCESS) {
  381. if (pCodecInst->loggingEnable)
  382. vdi_log(pCodecInst->coreIdx, DEC_SEQ_END, 2);
  383. if (ret == RETCODE_VPU_STILL_RUNNING) {
  384. LeaveLock(pCodecInst->coreIdx);
  385. return ret;
  386. }
  387. }
  388. if (pCodecInst->loggingEnable)
  389. vdi_log(pCodecInst->coreIdx, DEC_SEQ_END, 0);
  390. if (pDecInfo->vbSlice.size)
  391. vdi_free_dma_memory(pCodecInst->coreIdx, &pDecInfo->vbSlice, DEC_ETC, pCodecInst->instIndex);
  392. if (pDecInfo->vbWork.size) {
  393. if (pDecInfo->workBufferAllocExt == 0) {
  394. vdi_free_dma_memory(pCodecInst->coreIdx, &pDecInfo->vbWork, DEC_WORK, pCodecInst->instIndex);
  395. }
  396. else {
  397. vdi_dettach_dma_memory(pCodecInst->coreIdx, &pDecInfo->vbWork);
  398. }
  399. }
  400. if (pDecInfo->vbFrame.size) {
  401. if (pDecInfo->frameAllocExt == 0) {
  402. vdi_free_dma_memory(pCodecInst->coreIdx, &pDecInfo->vbFrame, DEC_ETC, pCodecInst->instIndex);
  403. }
  404. }
  405. for ( i=0 ; i<MAX_REG_FRAME; i++) {
  406. if (pDecInfo->vbMV[i].size)
  407. vdi_free_dma_memory(pCodecInst->coreIdx, &pDecInfo->vbMV[i], DEC_MV, pCodecInst->instIndex);
  408. if (pDecInfo->vbFbcYTbl[i].size)
  409. vdi_free_dma_memory(pCodecInst->coreIdx, &pDecInfo->vbFbcYTbl[i], DEC_FBCY_TBL, pCodecInst->instIndex);
  410. if (pDecInfo->vbFbcCTbl[i].size)
  411. vdi_free_dma_memory(pCodecInst->coreIdx, &pDecInfo->vbFbcCTbl[i], DEC_FBCC_TBL, pCodecInst->instIndex);
  412. }
  413. if (pDecInfo->vbTemp.size)
  414. vdi_dettach_dma_memory(pCodecInst->coreIdx, &pDecInfo->vbTemp);
  415. if (pDecInfo->vbPPU.size) {
  416. if (pDecInfo->ppuAllocExt == 0)
  417. vdi_free_dma_memory(pCodecInst->coreIdx, &pDecInfo->vbPPU, DEC_ETC, pCodecInst->instIndex);
  418. }
  419. if (pDecInfo->vbWTL.size)
  420. vdi_free_dma_memory(pCodecInst->coreIdx, &pDecInfo->vbWTL, DEC_FB_LINEAR, pCodecInst->instIndex);
  421. if (pDecInfo->vbUserData.size)
  422. vdi_dettach_dma_memory(pCodecInst->coreIdx, &pDecInfo->vbUserData);
  423. if (pDecInfo->vbReport.size)
  424. vdi_free_dma_memory(pCodecInst->coreIdx, &pDecInfo->vbReport, DEC_ETC, pCodecInst->instIndex);
  425. if (pDecInfo->vbTask.size)
  426. vdi_free_dma_memory(pCodecInst->coreIdx, &pDecInfo->vbTask, DEC_TASK, pCodecInst->instIndex);
  427. if (GetPendingInst(pCodecInst->coreIdx) == pCodecInst)
  428. ClearPendingInst(pCodecInst->coreIdx);
  429. LeaveLock(pCodecInst->coreIdx);
  430. FreeCodecInstance(pCodecInst);
  431. return ret;
  432. }
  433. RetCode VPU_DecSetEscSeqInit(DecHandle handle, int escape)
  434. {
  435. CodecInst * pCodecInst;
  436. DecInfo * pDecInfo;
  437. RetCode ret;
  438. ret = CheckDecInstanceValidity(handle);
  439. if (ret != RETCODE_SUCCESS)
  440. return ret;
  441. pCodecInst = handle;
  442. pDecInfo = &pCodecInst->CodecInfo->decInfo;
  443. if (pDecInfo->openParam.bitstreamMode != BS_MODE_INTERRUPT)
  444. return RETCODE_INVALID_PARAM;
  445. pDecInfo->seqInitEscape = escape;
  446. return RETCODE_SUCCESS;
  447. }
  448. RetCode VPU_DecGetInitialInfo(DecHandle handle, DecInitialInfo* info)
  449. {
  450. CodecInst* pCodecInst;
  451. DecInfo* pDecInfo;
  452. RetCode ret;
  453. Int32 flags;
  454. Uint32 interruptBit;
  455. VpuAttr* pAttr;
  456. if (PRODUCT_ID_W_SERIES(handle->productId)) {
  457. if (handle->productId == PRODUCT_ID_512 || handle->productId == PRODUCT_ID_515 || handle->productId == PRODUCT_ID_517 || handle->productId == PRODUCT_ID_521 || handle->productId == PRODUCT_ID_511) {
  458. interruptBit = INT_WAVE5_INIT_SEQ;
  459. }
  460. else
  461. return RETCODE_INVALID_PARAM;
  462. }
  463. else {
  464. /* CODA9xx */
  465. interruptBit = INT_BIT_SEQ_INIT;
  466. }
  467. ret = CheckDecInstanceValidity(handle);
  468. if (ret != RETCODE_SUCCESS)
  469. return ret;
  470. if (info == NULL)
  471. return RETCODE_INVALID_PARAM;
  472. pCodecInst = handle;
  473. pDecInfo = &pCodecInst->CodecInfo->decInfo;
  474. ret = ProductVpuDecCheckCapability(pCodecInst);
  475. if (ret != RETCODE_SUCCESS)
  476. return ret;
  477. EnterLock(pCodecInst->coreIdx);
  478. pAttr = &g_VpuCoreAttributes[pCodecInst->coreIdx];
  479. if (GetPendingInst(pCodecInst->coreIdx)) {
  480. /* The other instance is running */
  481. LeaveLock(pCodecInst->coreIdx);
  482. return RETCODE_FRAME_NOT_COMPLETE;
  483. }
  484. if (DecBitstreamBufEmpty(pDecInfo)) {
  485. LeaveLock(pCodecInst->coreIdx);
  486. return RETCODE_WRONG_CALL_SEQUENCE;
  487. }
  488. ret = ProductVpuDecInitSeq(handle);
  489. if (ret != RETCODE_SUCCESS) {
  490. LeaveLock(pCodecInst->coreIdx);
  491. return ret;
  492. }
  493. if (pAttr->supportCommandQueue == TRUE) {
  494. LeaveLock(pCodecInst->coreIdx);
  495. }
  496. flags = ProductVpuWaitInterrupt(pCodecInst, __VPU_BUSY_TIMEOUT);
  497. if (pAttr->supportCommandQueue == TRUE) {
  498. EnterLock(pCodecInst->coreIdx);
  499. }
  500. if (flags == -1) {
  501. info->rdPtr = VpuReadReg(pCodecInst->coreIdx, pDecInfo->streamRdPtrRegAddr);
  502. info->wrPtr = VpuReadReg(pCodecInst->coreIdx, pDecInfo->streamWrPtrRegAddr);
  503. ret = RETCODE_VPU_RESPONSE_TIMEOUT;
  504. }
  505. else {
  506. if (flags&(1<<interruptBit))
  507. ProductVpuClearInterrupt(pCodecInst->coreIdx, (1<<interruptBit));
  508. if (flags != (1<<interruptBit))
  509. ret = RETCODE_FAILURE;
  510. else
  511. ret = ProductVpuDecGetSeqInfo(handle, info);
  512. }
  513. info->rdPtr = VpuReadReg(pCodecInst->coreIdx, pDecInfo->streamRdPtrRegAddr);
  514. info->wrPtr = VpuReadReg(pCodecInst->coreIdx, pDecInfo->streamWrPtrRegAddr);
  515. pDecInfo->initialInfo = *info;
  516. if (ret == RETCODE_SUCCESS) {
  517. pDecInfo->initialInfoObtained = 1;
  518. }
  519. SetPendingInst(pCodecInst->coreIdx, 0);
  520. LeaveLock(pCodecInst->coreIdx);
  521. return ret;
  522. }
  523. RetCode VPU_DecIssueSeqInit(DecHandle handle)
  524. {
  525. CodecInst* pCodecInst;
  526. RetCode ret;
  527. VpuAttr* pAttr;
  528. ret = CheckDecInstanceValidity(handle);
  529. if (ret != RETCODE_SUCCESS)
  530. return ret;
  531. pCodecInst = handle;
  532. EnterLock(pCodecInst->coreIdx);
  533. pAttr = &g_VpuCoreAttributes[pCodecInst->coreIdx];
  534. if (GetPendingInst(pCodecInst->coreIdx)) {
  535. LeaveLock(pCodecInst->coreIdx);
  536. return RETCODE_FRAME_NOT_COMPLETE;
  537. }
  538. ret = ProductVpuDecInitSeq(handle);
  539. if (ret == RETCODE_SUCCESS) {
  540. SetPendingInst(pCodecInst->coreIdx, pCodecInst);
  541. }
  542. if (pAttr->supportCommandQueue == TRUE) {
  543. SetPendingInst(pCodecInst->coreIdx, NULL);
  544. LeaveLock(pCodecInst->coreIdx);
  545. }
  546. return ret;
  547. }
  548. RetCode VPU_DecCompleteSeqInit(DecHandle handle, DecInitialInfo * info)
  549. {
  550. CodecInst* pCodecInst;
  551. DecInfo* pDecInfo;
  552. RetCode ret;
  553. VpuAttr* pAttr;
  554. ret = CheckDecInstanceValidity(handle);
  555. if (ret != RETCODE_SUCCESS) {
  556. return ret;
  557. }
  558. if (info == 0) {
  559. return RETCODE_INVALID_PARAM;
  560. }
  561. pCodecInst = handle;
  562. pDecInfo = &pCodecInst->CodecInfo->decInfo;
  563. pAttr = &g_VpuCoreAttributes[pCodecInst->coreIdx];
  564. if (pAttr->supportCommandQueue == TRUE) {
  565. EnterLock(pCodecInst->coreIdx);
  566. }
  567. else {
  568. if (pCodecInst != GetPendingInst(pCodecInst->coreIdx)) {
  569. SetPendingInst(pCodecInst->coreIdx, 0);
  570. LeaveLock(pCodecInst->coreIdx);
  571. return RETCODE_WRONG_CALL_SEQUENCE;
  572. }
  573. }
  574. ret = ProductVpuDecGetSeqInfo(handle, info);
  575. if (ret == RETCODE_SUCCESS) {
  576. pDecInfo->initialInfoObtained = 1;
  577. }
  578. info->rdPtr = ProductVpuDecGetRdPtr(pCodecInst);
  579. info->wrPtr = pDecInfo->streamWrPtr;
  580. pDecInfo->prevFrameEndPos = info->rdPtr;
  581. pDecInfo->initialInfo = *info;
  582. SetPendingInst(pCodecInst->coreIdx, NULL);
  583. LeaveLock(pCodecInst->coreIdx);
  584. return ret;
  585. }
  586. static RetCode DecRegisterFrameBuffer(DecHandle handle, FrameBuffer *bufArray, int numFbsForDecoding, int numFbsForWTL, int stride, int height, int mapType)
  587. {
  588. CodecInst* pCodecInst;
  589. DecInfo* pDecInfo;
  590. Int32 i;
  591. RetCode ret;
  592. FrameBuffer* fb, nullFb;
  593. vpu_buffer_t* vb;
  594. FrameBufferFormat format = FORMAT_420;
  595. Int32 totalNumOfFbs;
  596. ret = CheckDecInstanceValidity(handle);
  597. if (ret != RETCODE_SUCCESS)
  598. return ret;
  599. if (numFbsForDecoding > MAX_FRAMEBUFFER_COUNT || numFbsForWTL > MAX_FRAMEBUFFER_COUNT) {
  600. return RETCODE_INVALID_PARAM;
  601. }
  602. osal_memset(&nullFb, 0x00, sizeof(FrameBuffer));
  603. pCodecInst = handle;
  604. pDecInfo = &pCodecInst->CodecInfo->decInfo;
  605. pDecInfo->numFbsForDecoding = numFbsForDecoding;
  606. pDecInfo->numFbsForWTL = numFbsForWTL;
  607. pDecInfo->numFrameBuffers = numFbsForDecoding + numFbsForWTL;
  608. pDecInfo->stride = stride;
  609. if (pCodecInst->codecMode == VPX_DEC)
  610. pDecInfo->frameBufferHeight = VPU_ALIGN64(height);
  611. else if (pCodecInst->codecMode == W_VP9_DEC)
  612. pDecInfo->frameBufferHeight = VPU_ALIGN64(height);
  613. else
  614. pDecInfo->frameBufferHeight = height;
  615. pDecInfo->mapType = mapType;
  616. pDecInfo->mapCfg.productId = pCodecInst->productId;
  617. ret = ProductVpuDecCheckCapability(pCodecInst);
  618. if (ret != RETCODE_SUCCESS)
  619. return ret;
  620. if (!pDecInfo->initialInfoObtained)
  621. return RETCODE_WRONG_CALL_SEQUENCE;
  622. if ( (stride < pDecInfo->initialInfo.picWidth) || (stride % 8 != 0) || (height<pDecInfo->initialInfo.picHeight) ) {
  623. return RETCODE_INVALID_STRIDE;
  624. }
  625. EnterLock(pCodecInst->coreIdx);
  626. if (GetPendingInst(pCodecInst->coreIdx)) {
  627. LeaveLock(pCodecInst->coreIdx);
  628. return RETCODE_FRAME_NOT_COMPLETE;
  629. }
  630. /* clear frameBufPool */
  631. for (i=0; i<(int)(sizeof(pDecInfo->frameBufPool)/sizeof(FrameBuffer)); i++) {
  632. pDecInfo->frameBufPool[i] = nullFb;
  633. }
  634. /* LinearMap or TiledMap, compressed framebuffer inclusive. */
  635. if (pDecInfo->initialInfo.lumaBitdepth > 8 || pDecInfo->initialInfo.chromaBitdepth > 8)
  636. format = FORMAT_420_P10_16BIT_LSB;
  637. totalNumOfFbs = numFbsForDecoding + numFbsForWTL;
  638. if (pCodecInst->codecMode == W_SVAC_DEC && pDecInfo->initialInfo.spatialSvcEnable == TRUE)
  639. totalNumOfFbs = numFbsForDecoding + numFbsForDecoding + numFbsForWTL; // (EL + BL + linear)
  640. if (bufArray) {
  641. for(i=0; i<totalNumOfFbs; i++)
  642. pDecInfo->frameBufPool[i] = bufArray[i];
  643. }
  644. else {
  645. vb = &pDecInfo->vbFrame;
  646. fb = &pDecInfo->frameBufPool[0];
  647. ret = ProductVpuAllocateFramebuffer(
  648. (CodecInst*)handle, fb, (TiledMapType)mapType, numFbsForDecoding, stride, height, format,
  649. pDecInfo->openParam.cbcrInterleave,
  650. pDecInfo->openParam.nv21,
  651. pDecInfo->openParam.frameEndian, vb, 0, FB_TYPE_CODEC);
  652. if (ret != RETCODE_SUCCESS) {
  653. LeaveLock(pCodecInst->coreIdx);
  654. return ret;
  655. }
  656. }
  657. if (pCodecInst->productId != PRODUCT_ID_960) {
  658. pDecInfo->mapCfg.tiledBaseAddr = pDecInfo->frameBufPool[0].bufY;
  659. }
  660. /* LinearMap */
  661. if (pDecInfo->wtlEnable == TRUE || numFbsForWTL != 0) {
  662. pDecInfo->stride = stride;
  663. if (!bufArray) {
  664. TiledMapType map;
  665. map = pDecInfo->wtlMode==FF_FRAME ? LINEAR_FRAME_MAP : LINEAR_FIELD_MAP;
  666. vb = &pDecInfo->vbWTL;
  667. fb = &pDecInfo->frameBufPool[numFbsForDecoding];
  668. ret = ProductVpuAllocateFramebuffer(
  669. (CodecInst*)handle, fb, map, numFbsForWTL, stride, height,
  670. pDecInfo->wtlFormat,
  671. pDecInfo->openParam.cbcrInterleave,
  672. pDecInfo->openParam.nv21,
  673. pDecInfo->openParam.frameEndian, vb, 0, FB_TYPE_PPU);
  674. if (ret != RETCODE_SUCCESS) {
  675. LeaveLock(pCodecInst->coreIdx);
  676. return ret;
  677. }
  678. }
  679. }
  680. ret = ProductVpuRegisterFramebuffer(pCodecInst);
  681. LeaveLock(pCodecInst->coreIdx);
  682. return ret;
  683. }
  684. RetCode VPU_DecRegisterFrameBuffer(DecHandle handle, FrameBuffer *bufArray, int num, int stride, int height, int mapType)
  685. {
  686. DecInfo* pDecInfo = &handle->CodecInfo->decInfo;
  687. Uint32 numWTL = 0;
  688. if (pDecInfo->wtlEnable == TRUE) numWTL = num;
  689. return DecRegisterFrameBuffer(handle, bufArray, num, numWTL, stride, height, mapType);
  690. }
  691. RetCode VPU_DecRegisterFrameBufferEx(DecHandle handle, FrameBuffer *bufArray, int numOfDecFbs, int numOfDisplayFbs, int stride, int height, int mapType)
  692. {
  693. return DecRegisterFrameBuffer(handle, bufArray, numOfDecFbs, numOfDisplayFbs, stride, height, mapType);
  694. }
  695. RetCode VPU_DecGetFrameBuffer(DecHandle handle, int frameIdx, FrameBuffer* frameBuf)
  696. {
  697. CodecInst * pCodecInst;
  698. DecInfo * pDecInfo;
  699. RetCode ret;
  700. ret = CheckDecInstanceValidity(handle);
  701. if (ret != RETCODE_SUCCESS)
  702. return ret;
  703. if (frameBuf == 0)
  704. return RETCODE_INVALID_PARAM;
  705. pCodecInst = handle;
  706. pDecInfo = &pCodecInst->CodecInfo->decInfo;
  707. if (frameIdx < 0 || frameIdx >= pDecInfo->numFrameBuffers)
  708. return RETCODE_INVALID_PARAM;
  709. *frameBuf = pDecInfo->frameBufPool[frameIdx];
  710. return RETCODE_SUCCESS;
  711. }
  712. RetCode VPU_DecUpdateFrameBuffer(
  713. DecHandle handle,
  714. FrameBuffer* fbcFb,
  715. FrameBuffer* linearFb,
  716. Int32 mvColIndex,
  717. Int32 picWidth,
  718. Int32 picHeight
  719. )
  720. {
  721. if (handle == NULL) {
  722. return RETCODE_INVALID_HANDLE;
  723. }
  724. return ProductVpuDecUpdateFrameBuffer((CodecInst*)handle, fbcFb, linearFb, mvColIndex, picWidth, picHeight);
  725. }
  726. RetCode VPU_DecGetBitstreamBuffer(DecHandle handle, PhysicalAddress* prdPtr, PhysicalAddress* pwrPtr, Uint32* size)
  727. {
  728. CodecInst* pCodecInst;
  729. DecInfo* pDecInfo;
  730. PhysicalAddress rdPtr;
  731. PhysicalAddress wrPtr;
  732. PhysicalAddress tempPtr;
  733. int room;
  734. Int32 coreIdx;
  735. VpuAttr* pAttr;
  736. coreIdx = handle->coreIdx;
  737. pAttr = &g_VpuCoreAttributes[coreIdx];
  738. pCodecInst = handle;
  739. pDecInfo = &pCodecInst->CodecInfo->decInfo;
  740. if (pAttr->supportCommandQueue == TRUE) {
  741. if (pDecInfo->rdPtrValidFlag == TRUE) { // when RdPtr has been updated by calling SetRdPtr.
  742. rdPtr = pDecInfo->streamRdPtr;
  743. }
  744. else {
  745. EnterLock(pCodecInst->coreIdx);
  746. rdPtr = ProductVpuDecGetRdPtr(pCodecInst);
  747. LeaveLock(pCodecInst->coreIdx);
  748. }
  749. }
  750. else {
  751. if (GetPendingInst(coreIdx) == pCodecInst) {
  752. if (pCodecInst->codecMode == AVC_DEC && pCodecInst->codecModeAux == AVC_AUX_MVC) {
  753. rdPtr = pDecInfo->streamRdPtr;
  754. }
  755. else {
  756. rdPtr = VpuReadReg(coreIdx, pDecInfo->streamRdPtrRegAddr);
  757. }
  758. }
  759. else {
  760. rdPtr = pDecInfo->streamRdPtr;
  761. }
  762. }
  763. wrPtr = pDecInfo->streamWrPtr;
  764. pAttr = &g_VpuCoreAttributes[coreIdx];
  765. tempPtr = rdPtr;
  766. if (pDecInfo->openParam.bitstreamMode != BS_MODE_PIC_END) {
  767. if (wrPtr < tempPtr) {
  768. room = tempPtr - wrPtr - pAttr->bitstreamBufferMargin*2;
  769. }
  770. else {
  771. room = (pDecInfo->streamBufEndAddr - wrPtr) + (tempPtr - pDecInfo->streamBufStartAddr) - pAttr->bitstreamBufferMargin*2;
  772. }
  773. room--;
  774. }
  775. else {
  776. room = (pDecInfo->streamBufEndAddr - wrPtr);
  777. }
  778. if (prdPtr) *prdPtr = tempPtr;
  779. if (pwrPtr) *pwrPtr = wrPtr;
  780. if (size) *size = room;
  781. return RETCODE_SUCCESS;
  782. }
  783. RetCode VPU_DecUpdateBitstreamBuffer(DecHandle handle, int size)
  784. {
  785. CodecInst* pCodecInst;
  786. DecInfo* pDecInfo;
  787. PhysicalAddress wrPtr;
  788. PhysicalAddress rdPtr;
  789. RetCode ret;
  790. BOOL running;
  791. VpuAttr* pAttr;
  792. ret = CheckDecInstanceValidity(handle);
  793. if (ret != RETCODE_SUCCESS)
  794. return ret;
  795. pCodecInst = handle;
  796. if (!pCodecInst)
  797. return RETCODE_INVALID_HANDLE;
  798. pAttr = &g_VpuCoreAttributes[pCodecInst->coreIdx];
  799. pDecInfo = &pCodecInst->CodecInfo->decInfo;
  800. wrPtr = pDecInfo->streamWrPtr;
  801. if (pAttr->supportCommandQueue == TRUE) {
  802. running = FALSE;
  803. }
  804. else {
  805. running = (BOOL)(GetPendingInst(pCodecInst->coreIdx) == pCodecInst);
  806. }
  807. if (size > 0) {
  808. Uint32 room = 0;
  809. if (running == TRUE)
  810. rdPtr = VpuReadReg(pCodecInst->coreIdx, pDecInfo->streamRdPtrRegAddr);
  811. else
  812. rdPtr = pDecInfo->streamRdPtr;
  813. if (wrPtr < rdPtr) {
  814. if (rdPtr <= wrPtr + size) {
  815. return RETCODE_INVALID_PARAM;
  816. }
  817. }
  818. wrPtr += size;
  819. if (pDecInfo->openParam.bitstreamMode != BS_MODE_PIC_END) {
  820. if (wrPtr > pDecInfo->streamBufEndAddr) {
  821. room = wrPtr - pDecInfo->streamBufEndAddr;
  822. wrPtr = pDecInfo->streamBufStartAddr;
  823. wrPtr += room;
  824. }
  825. else if (wrPtr == pDecInfo->streamBufEndAddr) {
  826. wrPtr = pDecInfo->streamBufStartAddr;
  827. }
  828. }
  829. pDecInfo->streamWrPtr = wrPtr;
  830. pDecInfo->streamRdPtr = rdPtr;
  831. if (running == TRUE) {
  832. VpuWriteReg(pCodecInst->coreIdx, pDecInfo->streamWrPtrRegAddr, wrPtr);
  833. }
  834. }
  835. if (running == FALSE) {
  836. EnterLock(pCodecInst->coreIdx);
  837. }
  838. ret = ProductVpuDecSetBitstreamFlag(pCodecInst, running, size);
  839. if (running == FALSE) {
  840. LeaveLock(pCodecInst->coreIdx);
  841. }
  842. return ret;
  843. }
  844. RetCode VPU_HWReset(Uint32 coreIdx)
  845. {
  846. if (vdi_hw_reset(coreIdx) < 0 )
  847. return RETCODE_FAILURE;
  848. if (GetPendingInst(coreIdx))
  849. {
  850. SetPendingInst(coreIdx, 0);
  851. LeaveLock(coreIdx); //if vpu is in a lock state. release the state;
  852. }
  853. return RETCODE_SUCCESS;
  854. }
  855. /**
  856. * VPU_SWReset
  857. * IN
  858. * forcedReset : 1 if there is no need to waiting for BUS transaction,
  859. * 0 for otherwise
  860. * OUT
  861. * RetCode : RETCODE_FAILURE if failed to reset,
  862. * RETCODE_SUCCESS for otherwise
  863. */
  864. RetCode VPU_SWReset(Uint32 coreIdx, SWResetMode resetMode, void *pendingInst)
  865. {
  866. CodecInst *pCodecInst = (CodecInst *)pendingInst;
  867. RetCode ret = RETCODE_SUCCESS;
  868. VpuAttr* attr = &g_VpuCoreAttributes[coreIdx];
  869. if (attr->supportCommandQueue == TRUE) {
  870. if (pCodecInst && pCodecInst->loggingEnable) {
  871. vdi_log(pCodecInst->coreIdx, 0x10000, 1);
  872. }
  873. EnterLock(coreIdx);
  874. ret = ProductVpuReset(coreIdx, resetMode);
  875. LeaveLock(coreIdx);
  876. if (pCodecInst && pCodecInst->loggingEnable) {
  877. vdi_log(pCodecInst->coreIdx, 0x10000, 0);
  878. }
  879. }
  880. else {
  881. if (pCodecInst) {
  882. if (pCodecInst->loggingEnable) {
  883. vdi_log(pCodecInst->coreIdx, (pCodecInst->productId == PRODUCT_ID_960 || pCodecInst->productId == PRODUCT_ID_980)?0x10:0x10000, 1);
  884. }
  885. }
  886. else {
  887. EnterLock(coreIdx);
  888. }
  889. ret = ProductVpuReset(coreIdx, resetMode);
  890. if (pCodecInst) {
  891. if (pCodecInst->loggingEnable) {
  892. vdi_log(pCodecInst->coreIdx, (pCodecInst->productId == PRODUCT_ID_960 || pCodecInst->productId == PRODUCT_ID_980)?0x10:0x10000, 0);
  893. }
  894. SetPendingInst(pCodecInst->coreIdx, 0);
  895. LeaveLock(coreIdx);
  896. }
  897. else {
  898. LeaveLock(coreIdx);
  899. }
  900. }
  901. return ret;
  902. }
  903. //---- VPU_SLEEP/WAKE
  904. RetCode VPU_SleepWake(Uint32 coreIdx, int iSleepWake)
  905. {
  906. RetCode ret;
  907. EnterLock(coreIdx);
  908. ret = ProductVpuSleepWake(coreIdx, iSleepWake, s_pusBitCode[coreIdx], s_bitCodeSize[coreIdx]);
  909. LeaveLock(coreIdx);
  910. return ret;
  911. }
  912. RetCode VPU_DecStartOneFrame(DecHandle handle, DecParam *param)
  913. {
  914. CodecInst* pCodecInst;
  915. DecInfo* pDecInfo;
  916. Uint32 val = 0;
  917. RetCode ret = RETCODE_SUCCESS;
  918. VpuAttr* pAttr = NULL;
  919. ret = CheckDecInstanceValidity(handle);
  920. if (ret != RETCODE_SUCCESS) {
  921. return ret;
  922. }
  923. pCodecInst = (CodecInst*)handle;
  924. pDecInfo = &pCodecInst->CodecInfo->decInfo;
  925. if (pDecInfo->stride == 0) { // This means frame buffers have not been registered.
  926. return RETCODE_WRONG_CALL_SEQUENCE;
  927. }
  928. pAttr = &g_VpuCoreAttributes[pCodecInst->coreIdx];
  929. EnterLock(pCodecInst->coreIdx);
  930. if (GetPendingInst(pCodecInst->coreIdx)) {
  931. LeaveLock(pCodecInst->coreIdx);
  932. return RETCODE_FRAME_NOT_COMPLETE;
  933. }
  934. if (pAttr->supportCommandQueue == FALSE) {
  935. EnterDispFlagLock(pCodecInst->coreIdx);
  936. val = pDecInfo->frameDisplayFlag;
  937. val |= pDecInfo->setDisplayIndexes;
  938. val &= ~(Uint32)(pDecInfo->clearDisplayIndexes);
  939. VpuWriteReg(pCodecInst->coreIdx, pDecInfo->frameDisplayFlagRegAddr, val);
  940. pDecInfo->clearDisplayIndexes = 0;
  941. pDecInfo->setDisplayIndexes = 0;
  942. LeaveDispFlagLock(pCodecInst->coreIdx);
  943. }
  944. pDecInfo->frameStartPos = pDecInfo->streamRdPtr;
  945. ret = ProductVpuDecode(pCodecInst, param);
  946. if (pAttr->supportCommandQueue == TRUE) {
  947. SetPendingInst(pCodecInst->coreIdx, NULL);
  948. LeaveLock(pCodecInst->coreIdx);
  949. }
  950. else {
  951. SetPendingInst(pCodecInst->coreIdx, pCodecInst);
  952. }
  953. return ret;
  954. }
  955. RetCode VPU_DecGetOutputInfo(DecHandle handle, DecOutputInfo* info)
  956. {
  957. CodecInst* pCodecInst;
  958. DecInfo* pDecInfo;
  959. RetCode ret;
  960. VpuRect rectInfo;
  961. Uint32 val;
  962. Int32 decodedIndex;
  963. Int32 displayIndex;
  964. Uint32 maxDecIndex;
  965. VpuAttr* pAttr;
  966. ret = CheckDecInstanceValidity(handle);
  967. if (ret != RETCODE_SUCCESS) {
  968. return ret;
  969. }
  970. if (info == 0) {
  971. return RETCODE_INVALID_PARAM;
  972. }
  973. pCodecInst = handle;
  974. pDecInfo = &pCodecInst->CodecInfo->decInfo;
  975. pAttr = &g_VpuCoreAttributes[pCodecInst->coreIdx];
  976. if (pAttr->supportCommandQueue == TRUE) {
  977. EnterLock(pCodecInst->coreIdx);
  978. }
  979. else {
  980. if (pCodecInst != GetPendingInst(pCodecInst->coreIdx)) {
  981. SetPendingInst(pCodecInst->coreIdx, 0);
  982. LeaveLock(pCodecInst->coreIdx);
  983. return RETCODE_WRONG_CALL_SEQUENCE;
  984. }
  985. }
  986. osal_memset((void*)info, 0x00, sizeof(DecOutputInfo));
  987. ret = ProductVpuDecGetResult(pCodecInst, info);
  988. if (ret != RETCODE_SUCCESS) {
  989. info->rdPtr = pDecInfo->streamRdPtr;
  990. info->wrPtr = pDecInfo->streamWrPtr;
  991. SetPendingInst(pCodecInst->coreIdx, 0);
  992. LeaveLock(pCodecInst->coreIdx);
  993. return ret;
  994. }
  995. decodedIndex = info->indexFrameDecoded;
  996. // Calculate display frame region
  997. val = 0;
  998. if (decodedIndex >= 0 && decodedIndex < MAX_GDI_IDX) {
  999. //default value
  1000. rectInfo.left = 0;
  1001. rectInfo.right = info->decPicWidth;
  1002. rectInfo.top = 0;
  1003. rectInfo.bottom = info->decPicHeight;
  1004. if (pCodecInst->codecMode == W_HEVC_DEC || pCodecInst->codecMode == AVC_DEC || pCodecInst->codecMode == AVS_DEC)
  1005. rectInfo = pDecInfo->initialInfo.picCropRect;
  1006. if (pCodecInst->codecMode == W_HEVC_DEC)
  1007. pDecInfo->decOutInfo[decodedIndex].decodedPOC = info->decodedPOC;
  1008. if (pCodecInst->codecMode == W_AVS2_DEC)
  1009. pDecInfo->decOutInfo[decodedIndex].avs2Info.decodedPOI = info->avs2Info.decodedPOI;
  1010. info->rcDecoded.left = pDecInfo->decOutInfo[decodedIndex].rcDecoded.left = rectInfo.left;
  1011. info->rcDecoded.right = pDecInfo->decOutInfo[decodedIndex].rcDecoded.right = rectInfo.right;
  1012. info->rcDecoded.top = pDecInfo->decOutInfo[decodedIndex].rcDecoded.top = rectInfo.top;
  1013. info->rcDecoded.bottom = pDecInfo->decOutInfo[decodedIndex].rcDecoded.bottom = rectInfo.bottom;
  1014. }
  1015. else
  1016. {
  1017. info->rcDecoded.left = 0;
  1018. info->rcDecoded.right = info->decPicWidth;
  1019. info->rcDecoded.top = 0;
  1020. info->rcDecoded.bottom = info->decPicHeight;
  1021. }
  1022. displayIndex = info->indexFrameDisplay;
  1023. if (info->indexFrameDisplay >= 0 && info->indexFrameDisplay < MAX_GDI_IDX)
  1024. {
  1025. if (pCodecInst->codecMode == VC1_DEC) // vc1 rotates decoded frame buffer region. the other std rotated whole frame buffer region.
  1026. {
  1027. if (pDecInfo->rotationEnable && (pDecInfo->rotationAngle==90 || pDecInfo->rotationAngle==270))
  1028. {
  1029. info->rcDisplay.left = pDecInfo->decOutInfo[displayIndex].rcDecoded.top;
  1030. info->rcDisplay.right = pDecInfo->decOutInfo[displayIndex].rcDecoded.bottom;
  1031. info->rcDisplay.top = pDecInfo->decOutInfo[displayIndex].rcDecoded.left;
  1032. info->rcDisplay.bottom = pDecInfo->decOutInfo[displayIndex].rcDecoded.right;
  1033. }
  1034. else
  1035. {
  1036. info->rcDisplay.left = pDecInfo->decOutInfo[displayIndex].rcDecoded.left;
  1037. info->rcDisplay.right = pDecInfo->decOutInfo[displayIndex].rcDecoded.right;
  1038. info->rcDisplay.top = pDecInfo->decOutInfo[displayIndex].rcDecoded.top;
  1039. info->rcDisplay.bottom = pDecInfo->decOutInfo[displayIndex].rcDecoded.bottom;
  1040. }
  1041. }
  1042. else
  1043. {
  1044. if (pDecInfo->rotationEnable)
  1045. {
  1046. switch(pDecInfo->rotationAngle)
  1047. {
  1048. case 90:
  1049. info->rcDisplay.left = pDecInfo->decOutInfo[displayIndex].rcDecoded.top;
  1050. info->rcDisplay.right = pDecInfo->decOutInfo[displayIndex].rcDecoded.bottom;
  1051. info->rcDisplay.top = info->decPicWidth - pDecInfo->decOutInfo[displayIndex].rcDecoded.right;
  1052. info->rcDisplay.bottom = info->decPicWidth - pDecInfo->decOutInfo[displayIndex].rcDecoded.left;
  1053. break;
  1054. case 270:
  1055. info->rcDisplay.left = info->decPicHeight - pDecInfo->decOutInfo[displayIndex].rcDecoded.bottom;
  1056. info->rcDisplay.right = info->decPicHeight - pDecInfo->decOutInfo[displayIndex].rcDecoded.top;
  1057. info->rcDisplay.top = pDecInfo->decOutInfo[displayIndex].rcDecoded.left;
  1058. info->rcDisplay.bottom = pDecInfo->decOutInfo[displayIndex].rcDecoded.right;
  1059. break;
  1060. case 180:
  1061. info->rcDisplay.left = pDecInfo->decOutInfo[displayIndex].rcDecoded.left;
  1062. info->rcDisplay.right = pDecInfo->decOutInfo[displayIndex].rcDecoded.right;
  1063. info->rcDisplay.top = info->decPicHeight - pDecInfo->decOutInfo[displayIndex].rcDecoded.bottom;
  1064. info->rcDisplay.bottom = info->decPicHeight - pDecInfo->decOutInfo[displayIndex].rcDecoded.top;
  1065. break;
  1066. default:
  1067. info->rcDisplay.left = pDecInfo->decOutInfo[displayIndex].rcDecoded.left;
  1068. info->rcDisplay.right = pDecInfo->decOutInfo[displayIndex].rcDecoded.right;
  1069. info->rcDisplay.top = pDecInfo->decOutInfo[displayIndex].rcDecoded.top;
  1070. info->rcDisplay.bottom = pDecInfo->decOutInfo[displayIndex].rcDecoded.bottom;
  1071. break;
  1072. }
  1073. }
  1074. else
  1075. {
  1076. info->rcDisplay.left = pDecInfo->decOutInfo[displayIndex].rcDecoded.left;
  1077. info->rcDisplay.right = pDecInfo->decOutInfo[displayIndex].rcDecoded.right;
  1078. info->rcDisplay.top = pDecInfo->decOutInfo[displayIndex].rcDecoded.top;
  1079. info->rcDisplay.bottom = pDecInfo->decOutInfo[displayIndex].rcDecoded.bottom;
  1080. }
  1081. if (pDecInfo->mirrorEnable) {
  1082. Uint32 temp;
  1083. Uint32 width = (pDecInfo->rotationAngle == 90 || pDecInfo->rotationAngle == 270) ? info->decPicHeight: info->decPicWidth;
  1084. Uint32 height = (pDecInfo->rotationAngle == 90 || pDecInfo->rotationAngle == 270) ? info->decPicWidth : info->decPicHeight;
  1085. if (pDecInfo->mirrorDirection & MIRDIR_VER) {
  1086. temp = info->rcDisplay.top;
  1087. info->rcDisplay.top = height - info->rcDisplay.bottom;
  1088. info->rcDisplay.bottom = height - temp;
  1089. }
  1090. if (pDecInfo->mirrorDirection & MIRDIR_HOR) {
  1091. temp = info->rcDisplay.left;
  1092. info->rcDisplay.left = width - info->rcDisplay.right;
  1093. info->rcDisplay.right = width - temp;
  1094. }
  1095. }
  1096. switch (pCodecInst->codecMode) {
  1097. case W_HEVC_DEC:
  1098. info->displayPOC = pDecInfo->decOutInfo[displayIndex].decodedPOC;
  1099. break;
  1100. case W_AVS2_DEC:
  1101. info->avs2Info.displayPOI = pDecInfo->decOutInfo[displayIndex].avs2Info.decodedPOI;
  1102. break;
  1103. case W_AVC_DEC:
  1104. if (TRUE == PRODUCT_ID_W_SERIES(pCodecInst->productId)) {
  1105. info->displayPOC = pDecInfo->decOutInfo[displayIndex].decodedPOC;
  1106. }
  1107. break;
  1108. default:
  1109. break;
  1110. }
  1111. }
  1112. if (info->indexFrameDisplay == info->indexFrameDecoded)
  1113. {
  1114. info->dispPicWidth = info->decPicWidth;
  1115. info->dispPicHeight = info->decPicHeight;
  1116. }
  1117. else
  1118. {
  1119. /*
  1120. When indexFrameDecoded < 0, and indexFrameDisplay >= 0
  1121. info->decPicWidth and info->decPicHeight are still valid
  1122. But those of pDecInfo->decOutInfo[displayIndex] are invalid in VP9
  1123. */
  1124. info->dispPicWidth = pDecInfo->decOutInfo[displayIndex].decPicWidth;
  1125. info->dispPicHeight = pDecInfo->decOutInfo[displayIndex].decPicHeight;
  1126. }
  1127. if (pDecInfo->scalerEnable == TRUE) {
  1128. if ((pDecInfo->scaleWidth != 0) && (pDecInfo->scaleHeight != 0)) {
  1129. info->dispPicWidth = pDecInfo->scaleWidth;
  1130. info->dispPicHeight = pDecInfo->scaleHeight;
  1131. info->rcDisplay.right = pDecInfo->scaleWidth;
  1132. info->rcDisplay.bottom = pDecInfo->scaleHeight;
  1133. }
  1134. }
  1135. }
  1136. else
  1137. {
  1138. info->rcDisplay.left = 0;
  1139. info->rcDisplay.right = 0;
  1140. info->rcDisplay.top = 0;
  1141. info->rcDisplay.bottom = 0;
  1142. if (pDecInfo->rotationEnable || pDecInfo->mirrorEnable || pDecInfo->tiled2LinearEnable || pDecInfo->deringEnable) {
  1143. info->dispPicWidth = info->decPicWidth;
  1144. info->dispPicHeight = info->decPicHeight;
  1145. }
  1146. else {
  1147. info->dispPicWidth = 0;
  1148. info->dispPicHeight = 0;
  1149. }
  1150. }
  1151. if ( (pCodecInst->codecMode == VC1_DEC ) && info->indexFrameDisplay != -3) {
  1152. if (pDecInfo->vc1BframeDisplayValid == 0) {
  1153. if (info->picType == 2)
  1154. info->indexFrameDisplay = -3;
  1155. else
  1156. pDecInfo->vc1BframeDisplayValid = 1;
  1157. }
  1158. }
  1159. pDecInfo->streamRdPtr = ProductVpuDecGetRdPtr(pCodecInst);
  1160. pDecInfo->frameDisplayFlag = VpuReadReg(pCodecInst->coreIdx, pDecInfo->frameDisplayFlagRegAddr);
  1161. if (pCodecInst->codecMode == W_VP9_DEC) {
  1162. pDecInfo->frameDisplayFlag &= 0xFFFF;
  1163. }
  1164. pDecInfo->frameEndPos = pDecInfo->streamRdPtr;
  1165. if (pDecInfo->frameEndPos < pDecInfo->frameStartPos)
  1166. info->consumedByte = pDecInfo->frameEndPos + pDecInfo->streamBufSize - pDecInfo->frameStartPos;
  1167. else
  1168. info->consumedByte = pDecInfo->frameEndPos - pDecInfo->frameStartPos;
  1169. if (pDecInfo->deringEnable || pDecInfo->mirrorEnable || pDecInfo->rotationEnable || pDecInfo->tiled2LinearEnable) {
  1170. info->dispFrame = pDecInfo->rotatorOutput;
  1171. info->dispFrame.stride = pDecInfo->rotatorStride;
  1172. }
  1173. else {
  1174. Int32 SvacSvcFlag = (pCodecInst->codecMode == W_SVAC_DEC && pDecInfo->initialInfo.spatialSvcEnable == TRUE);
  1175. val = (pDecInfo->openParam.wtlEnable == TRUE ? pDecInfo->numFbsForDecoding: 0); //fbOffset
  1176. if (SvacSvcFlag && pDecInfo->openParam.wtlEnable == TRUE)
  1177. val = pDecInfo->numFbsForDecoding*2;
  1178. maxDecIndex = (pDecInfo->numFbsForDecoding > pDecInfo->numFbsForWTL) ? (SvacSvcFlag ? pDecInfo->numFbsForDecoding*2 : pDecInfo->numFbsForDecoding) : pDecInfo->numFbsForWTL;
  1179. if (0 <= info->indexFrameDisplay && info->indexFrameDisplay < (int)maxDecIndex)
  1180. info->dispFrame = pDecInfo->frameBufPool[val+info->indexFrameDisplay];
  1181. }
  1182. info->rdPtr = pDecInfo->streamRdPtr;
  1183. info->wrPtr = pDecInfo->streamWrPtr;
  1184. info->frameDisplayFlag = pDecInfo->frameDisplayFlag;
  1185. info->sequenceNo = pDecInfo->initialInfo.sequenceNo;
  1186. if (decodedIndex >= 0 && decodedIndex < MAX_GDI_IDX) {
  1187. pDecInfo->decOutInfo[decodedIndex] = *info;
  1188. }
  1189. if (displayIndex >= 0 && displayIndex < MAX_GDI_IDX) {
  1190. info->numOfTotMBs = info->numOfTotMBs;
  1191. info->numOfErrMBs = info->numOfErrMBs;
  1192. info->numOfTotMBsInDisplay = pDecInfo->decOutInfo[displayIndex].numOfTotMBs;
  1193. info->numOfErrMBsInDisplay = pDecInfo->decOutInfo[displayIndex].numOfErrMBs;
  1194. info->dispFrame.sequenceNo = info->sequenceNo;
  1195. }
  1196. else {
  1197. info->numOfTotMBsInDisplay = 0;
  1198. info->numOfErrMBsInDisplay = 0;
  1199. }
  1200. if (info->sequenceChanged != 0) {
  1201. if (!(pCodecInst->productId == PRODUCT_ID_960 || pCodecInst->productId == PRODUCT_ID_980)) {
  1202. /* Update new sequence information */
  1203. osal_memcpy((void*)&pDecInfo->initialInfo, (void*)&pDecInfo->newSeqInfo, sizeof(DecInitialInfo));
  1204. }
  1205. if ((info->sequenceChanged & SEQ_CHANGE_INTER_RES_CHANGE) != SEQ_CHANGE_INTER_RES_CHANGE) {
  1206. pDecInfo->initialInfo.sequenceNo++;
  1207. }
  1208. }
  1209. SetPendingInst(pCodecInst->coreIdx, 0);
  1210. LeaveLock(pCodecInst->coreIdx);
  1211. return RETCODE_SUCCESS;
  1212. }
  1213. RetCode VPU_DecFrameBufferFlush(DecHandle handle, DecOutputInfo* pRemainings, Uint32* retNum)
  1214. {
  1215. CodecInst* pCodecInst;
  1216. DecInfo* pDecInfo;
  1217. DecOutputInfo* pOut;
  1218. RetCode ret;
  1219. FramebufferIndex retIndex[MAX_GDI_IDX];
  1220. Uint32 retRemainings = 0;
  1221. Int32 i, index, val;
  1222. VpuAttr* pAttr = NULL;
  1223. ret = CheckDecInstanceValidity(handle);
  1224. if (ret != RETCODE_SUCCESS)
  1225. return ret;
  1226. pCodecInst = handle;
  1227. pDecInfo = &pCodecInst->CodecInfo->decInfo;
  1228. EnterLock(pCodecInst->coreIdx);
  1229. if (GetPendingInst(pCodecInst->coreIdx)) {
  1230. LeaveLock(pCodecInst->coreIdx);
  1231. return RETCODE_FRAME_NOT_COMPLETE;
  1232. }
  1233. osal_memset((void*)retIndex, 0xff, sizeof(retIndex));
  1234. pAttr = &g_VpuCoreAttributes[pCodecInst->coreIdx];
  1235. if (pAttr->supportCommandQueue == FALSE) {
  1236. EnterDispFlagLock(pCodecInst->coreIdx);
  1237. val = pDecInfo->frameDisplayFlag;
  1238. val |= pDecInfo->setDisplayIndexes;
  1239. val &= ~(Uint32)(pDecInfo->clearDisplayIndexes);
  1240. VpuWriteReg(pCodecInst->coreIdx, pDecInfo->frameDisplayFlagRegAddr, val);
  1241. pDecInfo->clearDisplayIndexes = 0;
  1242. pDecInfo->setDisplayIndexes = 0;
  1243. LeaveDispFlagLock(pCodecInst->coreIdx);
  1244. }
  1245. if ((ret=ProductVpuDecFlush(pCodecInst, retIndex, MAX_GDI_IDX)) != RETCODE_SUCCESS) {
  1246. LeaveLock(pCodecInst->coreIdx);
  1247. return ret;
  1248. }
  1249. if (pRemainings != NULL) {
  1250. for (i=0; i<MAX_GDI_IDX; i++) {
  1251. index = (pDecInfo->wtlEnable == TRUE) ? retIndex[i].tiledIndex : retIndex[i].linearIndex;
  1252. if (index < 0)
  1253. break;
  1254. pRemainings[i] = pDecInfo->decOutInfo[index];
  1255. pOut = &pRemainings[i];
  1256. pOut->indexFrameDisplay = pOut->indexFrameDecoded;
  1257. pOut->indexFrameDisplayForTiled = pOut->indexFrameDecodedForTiled;
  1258. if (pDecInfo->wtlEnable == TRUE)
  1259. pOut->dispFrame = pDecInfo->frameBufPool[pDecInfo->numFbsForDecoding+retIndex[i].linearIndex];
  1260. else
  1261. pOut->dispFrame = pDecInfo->frameBufPool[index];
  1262. pOut->dispFrame.sequenceNo = pOut->sequenceNo;
  1263. if (pCodecInst->codecMode == W_VP9_DEC || pCodecInst->codecMode == W_AVS2_DEC) {
  1264. Uint32 regVal;
  1265. if ((pDecInfo->scaleWidth == 0) || (pDecInfo->scaleHeight == 0)) {
  1266. regVal = VpuReadReg(pCodecInst->coreIdx, W5_RET_DEC_DISPLAY_SIZE);
  1267. pOut->dispPicWidth = regVal>>16;
  1268. pOut->dispPicHeight = regVal&0xffff;
  1269. }
  1270. else {
  1271. pOut->dispPicWidth = pDecInfo->scaleWidth;
  1272. pOut->dispPicHeight = pDecInfo->scaleHeight;
  1273. }
  1274. }
  1275. else {
  1276. pOut->dispPicWidth = pOut->decPicWidth;
  1277. pOut->dispPicHeight = pOut->decPicHeight;
  1278. }
  1279. if (pDecInfo->rotationEnable)
  1280. {
  1281. switch(pDecInfo->rotationAngle)
  1282. {
  1283. case 90:
  1284. pOut->rcDisplay.left = pDecInfo->decOutInfo[index].rcDecoded.top;
  1285. pOut->rcDisplay.right = pDecInfo->decOutInfo[index].rcDecoded.bottom;
  1286. pOut->rcDisplay.top = pOut->decPicWidth - pDecInfo->decOutInfo[index].rcDecoded.right;
  1287. pOut->rcDisplay.bottom = pOut->decPicWidth - pDecInfo->decOutInfo[index].rcDecoded.left;
  1288. break;
  1289. case 270:
  1290. pOut->rcDisplay.left = pOut->decPicHeight - pDecInfo->decOutInfo[index].rcDecoded.bottom;
  1291. pOut->rcDisplay.right = pOut->decPicHeight - pDecInfo->decOutInfo[index].rcDecoded.top;
  1292. pOut->rcDisplay.top = pDecInfo->decOutInfo[index].rcDecoded.left;
  1293. pOut->rcDisplay.bottom = pDecInfo->decOutInfo[index].rcDecoded.right;
  1294. break;
  1295. case 180:
  1296. pOut->rcDisplay.left = pDecInfo->decOutInfo[index].rcDecoded.left;
  1297. pOut->rcDisplay.right = pDecInfo->decOutInfo[index].rcDecoded.right;
  1298. pOut->rcDisplay.top = pOut->decPicHeight - pDecInfo->decOutInfo[index].rcDecoded.bottom;
  1299. pOut->rcDisplay.bottom = pOut->decPicHeight - pDecInfo->decOutInfo[index].rcDecoded.top;
  1300. break;
  1301. default:
  1302. pOut->rcDisplay.left = pDecInfo->decOutInfo[index].rcDecoded.left;
  1303. pOut->rcDisplay.right = pDecInfo->decOutInfo[index].rcDecoded.right;
  1304. pOut->rcDisplay.top = pDecInfo->decOutInfo[index].rcDecoded.top;
  1305. pOut->rcDisplay.bottom = pDecInfo->decOutInfo[index].rcDecoded.bottom;
  1306. break;
  1307. }
  1308. }
  1309. else
  1310. {
  1311. pOut->rcDisplay.left = pDecInfo->decOutInfo[index].rcDecoded.left;
  1312. pOut->rcDisplay.right = pDecInfo->decOutInfo[index].rcDecoded.right;
  1313. pOut->rcDisplay.top = pDecInfo->decOutInfo[index].rcDecoded.top;
  1314. pOut->rcDisplay.bottom = pDecInfo->decOutInfo[index].rcDecoded.bottom;
  1315. }
  1316. retRemainings++;
  1317. }
  1318. }
  1319. if (retNum) *retNum = retRemainings;
  1320. if (pCodecInst->loggingEnable)
  1321. vdi_log(pCodecInst->coreIdx, DEC_BUF_FLUSH, 0);
  1322. LeaveLock(pCodecInst->coreIdx);
  1323. return ret;
  1324. }
  1325. RetCode VPU_DecSetRdPtr(DecHandle handle, PhysicalAddress addr, int updateWrPtr)
  1326. {
  1327. CodecInst* pCodecInst;
  1328. CodecInst* pPendingInst;
  1329. DecInfo* pDecInfo;
  1330. RetCode ret;
  1331. ret = CheckDecInstanceValidity(handle);
  1332. if (ret != RETCODE_SUCCESS) {
  1333. return ret;
  1334. }
  1335. pCodecInst = (CodecInst*)handle;
  1336. ret = ProductVpuDecCheckCapability(pCodecInst);
  1337. if (ret != RETCODE_SUCCESS) {
  1338. return ret;
  1339. }
  1340. pCodecInst = handle;
  1341. pDecInfo = &pCodecInst->CodecInfo->decInfo;
  1342. pPendingInst = GetPendingInst(pCodecInst->coreIdx);
  1343. if (pCodecInst == pPendingInst) {
  1344. VpuWriteReg(pCodecInst->coreIdx, pDecInfo->streamRdPtrRegAddr, addr);
  1345. }
  1346. else {
  1347. EnterLock(pCodecInst->coreIdx);
  1348. VpuWriteReg(pCodecInst->coreIdx, pDecInfo->streamRdPtrRegAddr, addr);
  1349. LeaveLock(pCodecInst->coreIdx);
  1350. }
  1351. pDecInfo->streamRdPtr = addr;
  1352. pDecInfo->prevFrameEndPos = addr;
  1353. if (updateWrPtr == TRUE) {
  1354. pDecInfo->streamWrPtr = addr;
  1355. }
  1356. pDecInfo->rdPtrValidFlag = 1;
  1357. return RETCODE_SUCCESS;
  1358. }
  1359. RetCode VPU_EncSetWrPtr(EncHandle handle, PhysicalAddress addr, int updateRdPtr)
  1360. {
  1361. CodecInst* pCodecInst;
  1362. CodecInst* pPendingInst;
  1363. EncInfo * pEncInfo;
  1364. RetCode ret;
  1365. ret = CheckEncInstanceValidity(handle);
  1366. if (ret != RETCODE_SUCCESS)
  1367. return ret;
  1368. pCodecInst = (CodecInst*)handle;
  1369. if (pCodecInst->productId == PRODUCT_ID_960 || pCodecInst->productId == PRODUCT_ID_980) {
  1370. return RETCODE_NOT_SUPPORTED_FEATURE;
  1371. }
  1372. pEncInfo = &handle->CodecInfo->encInfo;
  1373. pPendingInst = GetPendingInst(pCodecInst->coreIdx);
  1374. if (pCodecInst == pPendingInst) {
  1375. VpuWriteReg(pCodecInst->coreIdx, pEncInfo->streamWrPtrRegAddr, addr);
  1376. }
  1377. else {
  1378. EnterLock(pCodecInst->coreIdx);
  1379. VpuWriteReg(pCodecInst->coreIdx, pEncInfo->streamWrPtrRegAddr, addr);
  1380. LeaveLock(pCodecInst->coreIdx);
  1381. }
  1382. pEncInfo->streamWrPtr = addr;
  1383. if (updateRdPtr)
  1384. pEncInfo->streamRdPtr = addr;
  1385. return RETCODE_SUCCESS;
  1386. }
  1387. RetCode VPU_DecClrDispFlag(DecHandle handle, int index)
  1388. {
  1389. CodecInst* pCodecInst;
  1390. DecInfo* pDecInfo;
  1391. RetCode ret = RETCODE_SUCCESS;
  1392. Int32 endIndex, SvacSvcFlag;
  1393. VpuAttr* pAttr = NULL;
  1394. BOOL supportCommandQueue;
  1395. ret = CheckDecInstanceValidity(handle);
  1396. if (ret != RETCODE_SUCCESS)
  1397. return ret;
  1398. pCodecInst = handle;
  1399. pDecInfo = &pCodecInst->CodecInfo->decInfo;
  1400. pAttr = &g_VpuCoreAttributes[pCodecInst->coreIdx];
  1401. SvacSvcFlag = (pCodecInst->codecMode == W_SVAC_DEC && pDecInfo->initialInfo.spatialSvcEnable == TRUE);
  1402. endIndex = (pDecInfo->openParam.wtlEnable == TRUE) ? pDecInfo->numFbsForWTL : (SvacSvcFlag == TRUE ? pDecInfo->numFbsForDecoding*2 : pDecInfo->numFbsForDecoding);
  1403. if ((index < 0) || (index > (endIndex - 1))) {
  1404. return RETCODE_INVALID_PARAM;
  1405. }
  1406. supportCommandQueue = (pAttr->supportCommandQueue == TRUE);
  1407. if (supportCommandQueue == TRUE) {
  1408. EnterLock(pCodecInst->coreIdx);
  1409. ret = ProductClrDispFlag(pCodecInst, index);
  1410. LeaveLock(pCodecInst->coreIdx);
  1411. }
  1412. else {
  1413. EnterDispFlagLock(pCodecInst->coreIdx);
  1414. pDecInfo->clearDisplayIndexes |= (1<<index);
  1415. LeaveDispFlagLock(pCodecInst->coreIdx);
  1416. }
  1417. return ret;
  1418. }
  1419. RetCode VPU_DecGiveCommand(DecHandle handle, CodecCommand cmd, void* param)
  1420. {
  1421. CodecInst* pCodecInst;
  1422. DecInfo* pDecInfo;
  1423. RetCode ret;
  1424. ret = CheckDecInstanceValidity(handle);
  1425. if (ret != RETCODE_SUCCESS)
  1426. return ret;
  1427. pCodecInst = handle;
  1428. pDecInfo = &pCodecInst->CodecInfo->decInfo;
  1429. switch (cmd)
  1430. {
  1431. case ENABLE_ROTATION :
  1432. {
  1433. if (pDecInfo->rotatorStride == 0) {
  1434. return RETCODE_ROTATOR_STRIDE_NOT_SET;
  1435. }
  1436. pDecInfo->rotationEnable = 1;
  1437. break;
  1438. }
  1439. case DISABLE_ROTATION :
  1440. {
  1441. pDecInfo->rotationEnable = 0;
  1442. break;
  1443. }
  1444. case ENABLE_MIRRORING :
  1445. {
  1446. if (pDecInfo->rotatorStride == 0) {
  1447. return RETCODE_ROTATOR_STRIDE_NOT_SET;
  1448. }
  1449. pDecInfo->mirrorEnable = 1;
  1450. break;
  1451. }
  1452. case DISABLE_MIRRORING :
  1453. {
  1454. pDecInfo->mirrorEnable = 0;
  1455. break;
  1456. }
  1457. case SET_MIRROR_DIRECTION :
  1458. {
  1459. MirrorDirection mirDir;
  1460. if (param == 0) {
  1461. return RETCODE_INVALID_PARAM;
  1462. }
  1463. mirDir = *(MirrorDirection *)param;
  1464. if ( !(mirDir == MIRDIR_NONE) && !(mirDir==MIRDIR_HOR) && !(mirDir==MIRDIR_VER) && !(mirDir==MIRDIR_HOR_VER)) {
  1465. return RETCODE_INVALID_PARAM;
  1466. }
  1467. pDecInfo->mirrorDirection = mirDir;
  1468. break;
  1469. }
  1470. case SET_ROTATION_ANGLE :
  1471. {
  1472. int angle;
  1473. if (param == 0) {
  1474. return RETCODE_INVALID_PARAM;
  1475. }
  1476. angle = *(int *)param;
  1477. if (angle != 0 && angle != 90 &&
  1478. angle != 180 && angle != 270) {
  1479. return RETCODE_INVALID_PARAM;
  1480. }
  1481. if (pDecInfo->rotatorStride != 0) {
  1482. if (angle == 90 || angle ==270) {
  1483. if (pDecInfo->initialInfo.picHeight > pDecInfo->rotatorStride) {
  1484. return RETCODE_INVALID_PARAM;
  1485. }
  1486. } else {
  1487. if (pDecInfo->initialInfo.picWidth > pDecInfo->rotatorStride) {
  1488. return RETCODE_INVALID_PARAM;
  1489. }
  1490. }
  1491. }
  1492. pDecInfo->rotationAngle = angle;
  1493. break;
  1494. }
  1495. case SET_ROTATOR_OUTPUT :
  1496. {
  1497. FrameBuffer *frame;
  1498. if (param == 0) {
  1499. return RETCODE_INVALID_PARAM;
  1500. }
  1501. frame = (FrameBuffer *)param;
  1502. pDecInfo->rotatorOutput = *frame;
  1503. pDecInfo->rotatorOutputValid = 1;
  1504. break;
  1505. }
  1506. case SET_ROTATOR_STRIDE :
  1507. {
  1508. int stride;
  1509. if (param == 0) {
  1510. return RETCODE_INVALID_PARAM;
  1511. }
  1512. stride = *(int *)param;
  1513. if (stride % 8 != 0 || stride == 0) {
  1514. return RETCODE_INVALID_STRIDE;
  1515. }
  1516. if (pDecInfo->rotationAngle == 90 || pDecInfo->rotationAngle == 270) {
  1517. if (pDecInfo->initialInfo.picHeight > stride) {
  1518. return RETCODE_INVALID_STRIDE;
  1519. }
  1520. } else {
  1521. if (pDecInfo->initialInfo.picWidth > stride) {
  1522. return RETCODE_INVALID_STRIDE;
  1523. }
  1524. }
  1525. pDecInfo->rotatorStride = stride;
  1526. break;
  1527. }
  1528. case DEC_SET_SPS_RBSP:
  1529. {
  1530. if (pCodecInst->codecMode != AVC_DEC) {
  1531. return RETCODE_INVALID_COMMAND;
  1532. }
  1533. if (param == 0) {
  1534. return RETCODE_INVALID_PARAM;
  1535. }
  1536. return SetParaSet(handle, 0, (DecParamSet *)param);
  1537. }
  1538. case DEC_SET_PPS_RBSP:
  1539. {
  1540. if (pCodecInst->codecMode != AVC_DEC) {
  1541. return RETCODE_INVALID_COMMAND;
  1542. }
  1543. if (param == 0) {
  1544. return RETCODE_INVALID_PARAM;
  1545. }
  1546. return SetParaSet(handle, 1, (DecParamSet *)param);
  1547. }
  1548. case ENABLE_DERING :
  1549. {
  1550. if (pDecInfo->rotatorStride == 0) {
  1551. return RETCODE_ROTATOR_STRIDE_NOT_SET;
  1552. }
  1553. pDecInfo->deringEnable = 1;
  1554. break;
  1555. }
  1556. case DISABLE_DERING :
  1557. {
  1558. pDecInfo->deringEnable = 0;
  1559. break;
  1560. }
  1561. case SET_SEC_AXI:
  1562. {
  1563. SecAxiUse secAxiUse;
  1564. if (param == 0) {
  1565. return RETCODE_INVALID_PARAM;
  1566. }
  1567. secAxiUse = *(SecAxiUse *)param;
  1568. if (handle->productId == PRODUCT_ID_512 || handle->productId == PRODUCT_ID_515 ||
  1569. handle->productId == PRODUCT_ID_521 || handle->productId == PRODUCT_ID_511 || handle->productId == PRODUCT_ID_517) {
  1570. pDecInfo->secAxiInfo.u.wave.useIpEnable = secAxiUse.u.wave.useIpEnable;
  1571. pDecInfo->secAxiInfo.u.wave.useLfRowEnable = secAxiUse.u.wave.useLfRowEnable;
  1572. pDecInfo->secAxiInfo.u.wave.useBitEnable = secAxiUse.u.wave.useBitEnable;
  1573. pDecInfo->secAxiInfo.u.wave.useSclEnable = secAxiUse.u.wave.useSclEnable;
  1574. }
  1575. else {
  1576. pDecInfo->secAxiInfo.u.coda9.useBitEnable = secAxiUse.u.coda9.useBitEnable;
  1577. pDecInfo->secAxiInfo.u.coda9.useIpEnable = secAxiUse.u.coda9.useIpEnable;
  1578. pDecInfo->secAxiInfo.u.coda9.useDbkYEnable = secAxiUse.u.coda9.useDbkYEnable;
  1579. pDecInfo->secAxiInfo.u.coda9.useDbkCEnable = secAxiUse.u.coda9.useDbkCEnable;
  1580. pDecInfo->secAxiInfo.u.coda9.useOvlEnable = secAxiUse.u.coda9.useOvlEnable;
  1581. pDecInfo->secAxiInfo.u.coda9.useBtpEnable = secAxiUse.u.coda9.useBtpEnable;
  1582. }
  1583. break;
  1584. }
  1585. case ENABLE_REP_USERDATA:
  1586. {
  1587. if (!pDecInfo->userDataBufAddr) {
  1588. return RETCODE_USERDATA_BUF_NOT_SET;
  1589. }
  1590. if (pDecInfo->userDataBufSize == 0) {
  1591. return RETCODE_USERDATA_BUF_NOT_SET;
  1592. }
  1593. switch (pCodecInst->productId) {
  1594. case PRODUCT_ID_512:
  1595. case PRODUCT_ID_515:
  1596. case PRODUCT_ID_521:
  1597. case PRODUCT_ID_511:
  1598. case PRODUCT_ID_517:
  1599. if (!param)
  1600. return RETCODE_INVALID_PARAM;
  1601. pDecInfo->userDataEnable = *(Uint32*)param;
  1602. break;
  1603. case PRODUCT_ID_960:
  1604. case PRODUCT_ID_980:
  1605. pDecInfo->userDataEnable = TRUE;
  1606. break;
  1607. default:
  1608. VLOG(INFO, "%s(ENABLE_REP_DATA) invalid productId(%d)\n", __FUNCTION__, pCodecInst->productId);
  1609. return RETCODE_INVALID_PARAM;
  1610. }
  1611. break;
  1612. }
  1613. case DISABLE_REP_USERDATA:
  1614. {
  1615. pDecInfo->userDataEnable = 0;
  1616. break;
  1617. }
  1618. case SET_ADDR_REP_USERDATA:
  1619. {
  1620. PhysicalAddress userDataBufAddr;
  1621. if (param == 0) {
  1622. return RETCODE_INVALID_PARAM;
  1623. }
  1624. userDataBufAddr = *(PhysicalAddress *)param;
  1625. if (userDataBufAddr % 8 != 0 || userDataBufAddr == 0) {
  1626. return RETCODE_INVALID_PARAM;
  1627. }
  1628. pDecInfo->userDataBufAddr = userDataBufAddr;
  1629. break;
  1630. }
  1631. case SET_VIRT_ADDR_REP_USERDATA:
  1632. {
  1633. unsigned long userDataVirtAddr;
  1634. if (param == 0) {
  1635. return RETCODE_INVALID_PARAM;
  1636. }
  1637. if (!pDecInfo->userDataBufAddr) {
  1638. return RETCODE_USERDATA_BUF_NOT_SET;
  1639. }
  1640. if (pDecInfo->userDataBufSize == 0) {
  1641. return RETCODE_USERDATA_BUF_NOT_SET;
  1642. }
  1643. userDataVirtAddr = *(unsigned long *)param;
  1644. if (!userDataVirtAddr) {
  1645. return RETCODE_INVALID_PARAM;
  1646. }
  1647. pDecInfo->vbUserData.phys_addr = pDecInfo->userDataBufAddr;
  1648. pDecInfo->vbUserData.size = pDecInfo->userDataBufSize;
  1649. pDecInfo->vbUserData.virt_addr = (unsigned long)userDataVirtAddr;
  1650. if (vdi_attach_dma_memory(pCodecInst->coreIdx, &pDecInfo->vbUserData) != 0) {
  1651. return RETCODE_INSUFFICIENT_RESOURCE;
  1652. }
  1653. break;
  1654. }
  1655. case SET_SIZE_REP_USERDATA:
  1656. {
  1657. PhysicalAddress userDataBufSize;
  1658. if (param == 0) {
  1659. return RETCODE_INVALID_PARAM;
  1660. }
  1661. userDataBufSize = *(PhysicalAddress *)param;
  1662. pDecInfo->userDataBufSize = userDataBufSize;
  1663. break;
  1664. }
  1665. case SET_USERDATA_REPORT_MODE:
  1666. {
  1667. int userDataMode;
  1668. userDataMode = *(int *)param;
  1669. if (userDataMode != 1 && userDataMode != 0) {
  1670. return RETCODE_INVALID_PARAM;
  1671. }
  1672. pDecInfo->userDataReportMode = userDataMode;
  1673. break;
  1674. }
  1675. case SET_CACHE_CONFIG:
  1676. {
  1677. MaverickCacheConfig *mcCacheConfig;
  1678. if (param == 0) {
  1679. return RETCODE_INVALID_PARAM;
  1680. }
  1681. mcCacheConfig = (MaverickCacheConfig *)param;
  1682. pDecInfo->cacheConfig = *mcCacheConfig;
  1683. }
  1684. break;
  1685. case SET_LOW_DELAY_CONFIG:
  1686. {
  1687. LowDelayInfo *lowDelayInfo;
  1688. if (param == 0) {
  1689. return RETCODE_INVALID_PARAM;
  1690. }
  1691. if (pCodecInst->productId != PRODUCT_ID_980) {
  1692. return RETCODE_NOT_SUPPORTED_FEATURE;
  1693. }
  1694. lowDelayInfo = (LowDelayInfo *)param;
  1695. if (lowDelayInfo->lowDelayEn) {
  1696. if ( (pCodecInst->codecMode != AVC_DEC) ||
  1697. pDecInfo->rotationEnable ||
  1698. pDecInfo->mirrorEnable ||
  1699. pDecInfo->tiled2LinearEnable ||
  1700. pDecInfo->deringEnable) {
  1701. return RETCODE_INVALID_PARAM;
  1702. }
  1703. }
  1704. pDecInfo->lowDelayInfo.lowDelayEn = lowDelayInfo->lowDelayEn;
  1705. pDecInfo->lowDelayInfo.numRows = lowDelayInfo->numRows;
  1706. }
  1707. break;
  1708. case DEC_SET_FRAME_DELAY:
  1709. {
  1710. pDecInfo->frameDelay = *(int *)param;
  1711. break;
  1712. }
  1713. case DEC_ENABLE_REORDER:
  1714. {
  1715. if((handle->productId == PRODUCT_ID_980) || (handle->productId == PRODUCT_ID_960) || (handle->productId == PRODUCT_ID_950))
  1716. {
  1717. if (pDecInfo->initialInfoObtained) {
  1718. return RETCODE_WRONG_CALL_SEQUENCE;
  1719. }
  1720. }
  1721. pDecInfo->reorderEnable = 1;
  1722. break;
  1723. }
  1724. case DEC_DISABLE_REORDER:
  1725. {
  1726. if((handle->productId == PRODUCT_ID_980) || (handle->productId == PRODUCT_ID_960) || (handle->productId == PRODUCT_ID_950))
  1727. {
  1728. if (pDecInfo->initialInfoObtained) {
  1729. return RETCODE_WRONG_CALL_SEQUENCE;
  1730. }
  1731. if(pCodecInst->codecMode != AVC_DEC && pCodecInst->codecMode != VC1_DEC && pCodecInst->codecMode != AVS_DEC) {
  1732. return RETCODE_INVALID_COMMAND;
  1733. }
  1734. }
  1735. pDecInfo->reorderEnable = 0;
  1736. break;
  1737. }
  1738. case DEC_SET_AVC_ERROR_CONCEAL_MODE:
  1739. {
  1740. if(pCodecInst->codecMode != AVC_DEC) {
  1741. return RETCODE_INVALID_COMMAND;
  1742. }
  1743. pDecInfo->avcErrorConcealMode = *(int *)param;
  1744. break;
  1745. }
  1746. case DEC_FREE_FRAME_BUFFER:
  1747. {
  1748. int i;
  1749. if (pDecInfo->vbSlice.size)
  1750. vdi_free_dma_memory(pCodecInst->coreIdx, &pDecInfo->vbSlice, DEC_ETC, pCodecInst->instIndex);
  1751. if (pDecInfo->vbFrame.size){
  1752. if (pDecInfo->frameAllocExt == 0)
  1753. vdi_free_dma_memory(pCodecInst->coreIdx, &pDecInfo->vbFrame, DEC_ETC, pCodecInst->instIndex);
  1754. }
  1755. for (i=0 ; i<MAX_REG_FRAME; i++) {
  1756. if (pDecInfo->vbFbcYTbl[i].size)
  1757. vdi_free_dma_memory(pCodecInst->coreIdx, &pDecInfo->vbFbcYTbl[i], DEC_FBCY_TBL, pCodecInst->instIndex);
  1758. if (pDecInfo->vbFbcCTbl[i].size)
  1759. vdi_free_dma_memory(pCodecInst->coreIdx, &pDecInfo->vbFbcCTbl[i], DEC_FBCC_TBL, pCodecInst->instIndex);
  1760. if (pDecInfo->vbMV[i].size)
  1761. vdi_free_dma_memory(pCodecInst->coreIdx, &pDecInfo->vbMV[i], DEC_MV, pCodecInst->instIndex);
  1762. }
  1763. if (pDecInfo->vbPPU.size) {
  1764. if (pDecInfo->ppuAllocExt == 0)
  1765. vdi_free_dma_memory(pCodecInst->coreIdx, &pDecInfo->vbPPU, DEC_ETC, pCodecInst->instIndex);
  1766. }
  1767. if (pDecInfo->wtlEnable) {
  1768. if (pDecInfo->vbWTL.size)
  1769. vdi_free_dma_memory(pCodecInst->coreIdx, &pDecInfo->vbWTL, DEC_FB_LINEAR, pCodecInst->instIndex);
  1770. }
  1771. break;
  1772. }
  1773. case DEC_GET_FRAMEBUF_INFO:
  1774. {
  1775. DecGetFramebufInfo* fbInfo = (DecGetFramebufInfo*)param;
  1776. Uint32 i;
  1777. fbInfo->vbFrame = pDecInfo->vbFrame;
  1778. fbInfo->vbWTL = pDecInfo->vbWTL;
  1779. for (i=0 ; i<MAX_REG_FRAME; i++)
  1780. {
  1781. fbInfo->vbFbcYTbl[i] = pDecInfo->vbFbcYTbl[i];
  1782. fbInfo->vbFbcCTbl[i] = pDecInfo->vbFbcCTbl[i];
  1783. fbInfo->vbMvCol[i] = pDecInfo->vbMV[i];
  1784. }
  1785. for (i=0; i<MAX_GDI_IDX*2; i++) {
  1786. fbInfo->framebufPool[i] = pDecInfo->frameBufPool[i];
  1787. }
  1788. fbInfo->vbTask = pDecInfo->vbTask;
  1789. }
  1790. break;
  1791. case DEC_RESET_FRAMEBUF_INFO:
  1792. {
  1793. int i;
  1794. pDecInfo->vbFrame.base = 0;
  1795. pDecInfo->vbFrame.phys_addr = 0;
  1796. pDecInfo->vbFrame.virt_addr = 0;
  1797. pDecInfo->vbFrame.size = 0;
  1798. pDecInfo->vbWTL.base = 0;
  1799. pDecInfo->vbWTL.phys_addr = 0;
  1800. pDecInfo->vbWTL.virt_addr = 0;
  1801. pDecInfo->vbWTL.size = 0;
  1802. for (i=0 ; i<MAX_REG_FRAME; i++)
  1803. {
  1804. pDecInfo->vbFbcYTbl[i].base = 0;
  1805. pDecInfo->vbFbcYTbl[i].phys_addr = 0;
  1806. pDecInfo->vbFbcYTbl[i].virt_addr = 0;
  1807. pDecInfo->vbFbcYTbl[i].size = 0;
  1808. pDecInfo->vbFbcCTbl[i].base = 0;
  1809. pDecInfo->vbFbcCTbl[i].phys_addr = 0;
  1810. pDecInfo->vbFbcCTbl[i].virt_addr = 0;
  1811. pDecInfo->vbFbcCTbl[i].size = 0;
  1812. pDecInfo->vbMV[i].base = 0;
  1813. pDecInfo->vbMV[i].phys_addr = 0;
  1814. pDecInfo->vbMV[i].virt_addr = 0;
  1815. pDecInfo->vbMV[i].size = 0;
  1816. }
  1817. pDecInfo->frameDisplayFlag = 0;
  1818. pDecInfo->setDisplayIndexes = 0;
  1819. pDecInfo->clearDisplayIndexes = 0;
  1820. break;
  1821. }
  1822. case DEC_GET_QUEUE_STATUS:
  1823. {
  1824. QueueStatusInfo* queueInfo = (QueueStatusInfo*)param;
  1825. queueInfo->instanceQueueCount = pDecInfo->instanceQueueCount;
  1826. queueInfo->reportQueueCount = pDecInfo->reportQueueCount;
  1827. break;
  1828. }
  1829. case ENABLE_DEC_THUMBNAIL_MODE:
  1830. {
  1831. pDecInfo->thumbnailMode = 1;
  1832. break;
  1833. }
  1834. case DEC_GET_SEQ_INFO:
  1835. {
  1836. DecInitialInfo* seqInfo = (DecInitialInfo*)param;
  1837. *seqInfo = pDecInfo->initialInfo;
  1838. break;
  1839. }
  1840. case DEC_GET_FIELD_PIC_TYPE:
  1841. {
  1842. return RETCODE_FAILURE;
  1843. }
  1844. case DEC_GET_DISPLAY_OUTPUT_INFO:
  1845. {
  1846. DecOutputInfo *pDecOutInfo = (DecOutputInfo *)param;
  1847. *pDecOutInfo = pDecInfo->decOutInfo[pDecOutInfo->indexFrameDisplay];
  1848. break;
  1849. }
  1850. case GET_TILEDMAP_CONFIG:
  1851. {
  1852. TiledMapConfig *pMapCfg = (TiledMapConfig *)param;
  1853. if (!pMapCfg) {
  1854. return RETCODE_INVALID_PARAM;
  1855. }
  1856. if (!pDecInfo->stride) {
  1857. return RETCODE_WRONG_CALL_SEQUENCE;
  1858. }
  1859. *pMapCfg = pDecInfo->mapCfg;
  1860. break;
  1861. }
  1862. case SET_DRAM_CONFIG:
  1863. {
  1864. DRAMConfig *cfg = (DRAMConfig *)param;
  1865. if (!cfg) {
  1866. return RETCODE_INVALID_PARAM;
  1867. }
  1868. pDecInfo->dramCfg = *cfg;
  1869. break;
  1870. }
  1871. case GET_DRAM_CONFIG:
  1872. {
  1873. DRAMConfig *cfg = (DRAMConfig *)param;
  1874. if (!cfg) {
  1875. return RETCODE_INVALID_PARAM;
  1876. }
  1877. *cfg = pDecInfo->dramCfg;
  1878. break;
  1879. }
  1880. case GET_LOW_DELAY_OUTPUT:
  1881. {
  1882. DecOutputInfo *lowDelayOutput;
  1883. if (param == 0) {
  1884. return RETCODE_INVALID_PARAM;
  1885. }
  1886. if (!pDecInfo->lowDelayInfo.lowDelayEn || pCodecInst->codecMode != AVC_DEC) {
  1887. return RETCODE_INVALID_COMMAND;
  1888. }
  1889. if (pCodecInst != GetPendingInst(pCodecInst->coreIdx)) {
  1890. return RETCODE_WRONG_CALL_SEQUENCE;
  1891. }
  1892. lowDelayOutput = (DecOutputInfo *)param;
  1893. GetLowDelayOutput(pCodecInst, lowDelayOutput);
  1894. }
  1895. break;
  1896. case ENABLE_LOGGING:
  1897. {
  1898. pCodecInst->loggingEnable = 1;
  1899. }
  1900. break;
  1901. case DISABLE_LOGGING:
  1902. {
  1903. pCodecInst->loggingEnable = 0;
  1904. }
  1905. break;
  1906. case DEC_SET_SEQ_CHANGE_MASK:
  1907. if (PRODUCT_ID_NOT_W_SERIES(pCodecInst->productId))
  1908. return RETCODE_INVALID_PARAM;
  1909. pDecInfo->seqChangeMask = *(int*)param;
  1910. break;
  1911. case DEC_SET_WTL_FRAME_FORMAT:
  1912. pDecInfo->wtlFormat = *(FrameBufferFormat*)param;
  1913. break;
  1914. case DEC_SET_DISPLAY_FLAG:
  1915. {
  1916. Int32 index;
  1917. VpuAttr* pAttr = &g_VpuCoreAttributes[pCodecInst->coreIdx];
  1918. BOOL supportCommandQueue = FALSE;
  1919. if (param == 0) {
  1920. return RETCODE_INVALID_PARAM;
  1921. }
  1922. index = *(Int32 *)param;
  1923. supportCommandQueue = (pAttr->supportCommandQueue == TRUE);
  1924. if (supportCommandQueue == TRUE) {
  1925. EnterLock(pCodecInst->coreIdx);
  1926. ProductSetDispFlag(pCodecInst, index);
  1927. LeaveLock(pCodecInst->coreIdx);
  1928. }
  1929. else {
  1930. EnterDispFlagLock(pCodecInst->coreIdx);
  1931. pDecInfo->setDisplayIndexes |= (1<<index);
  1932. LeaveDispFlagLock(pCodecInst->coreIdx);
  1933. }
  1934. }
  1935. break;
  1936. case DEC_GET_SCALER_INFO:
  1937. {
  1938. ScalerInfo* scalerInfo = (ScalerInfo*)param;
  1939. if (scalerInfo == NULL) {
  1940. return RETCODE_INVALID_PARAM;
  1941. }
  1942. scalerInfo->enScaler = pDecInfo->scalerEnable;
  1943. scalerInfo->scaleWidth = pDecInfo->scaleWidth;
  1944. scalerInfo->scaleHeight = pDecInfo->scaleHeight;
  1945. }
  1946. break;
  1947. case DEC_SET_SCALER_INFO:
  1948. {
  1949. ScalerInfo* scalerInfo = (ScalerInfo*)param;
  1950. if (!pDecInfo->initialInfoObtained) {
  1951. return RETCODE_WRONG_CALL_SEQUENCE;
  1952. }
  1953. if (scalerInfo == NULL) {
  1954. return RETCODE_INVALID_PARAM;
  1955. }
  1956. pDecInfo->scalerEnable = scalerInfo->enScaler;
  1957. if (scalerInfo->enScaler == TRUE) {
  1958. VpuAttr* pAttr = &g_VpuCoreAttributes[pCodecInst->coreIdx];
  1959. Uint32 scalerStep = (pAttr->support2AlignScaler == TRUE) ? 2 : 8;
  1960. // minW = Ceil8(picWidth/8), minH = Ceil8(picHeight/8)
  1961. Uint32 minScaleWidth = VPU_ALIGN8(pDecInfo->initialInfo.picWidth>>3);
  1962. Uint32 minScaleHeight = VPU_ALIGN8(pDecInfo->initialInfo.picHeight>>3);
  1963. if (minScaleWidth == 0) minScaleWidth = 8;
  1964. if (minScaleHeight == 0) minScaleHeight = 8;
  1965. if (scalerInfo->scaleWidth < minScaleWidth || scalerInfo->scaleHeight < minScaleHeight) {
  1966. return RETCODE_INVALID_PARAM;
  1967. }
  1968. if (scalerInfo->scaleWidth > 0 || scalerInfo->scaleHeight > 0) {
  1969. if ((scalerInfo->scaleWidth % scalerStep) || scalerInfo->scaleWidth > (Uint32)(VPU_ALIGN8(pDecInfo->initialInfo.picWidth))) {
  1970. return RETCODE_INVALID_PARAM;
  1971. }
  1972. if ((scalerInfo->scaleHeight % scalerStep) || scalerInfo->scaleHeight > (Uint32)(VPU_ALIGN8(pDecInfo->initialInfo.picHeight))) {
  1973. return RETCODE_INVALID_PARAM;
  1974. }
  1975. pDecInfo->scaleWidth = scalerInfo->scaleWidth;
  1976. pDecInfo->scaleHeight = scalerInfo->scaleHeight;
  1977. pDecInfo->scalerEnable = scalerInfo->enScaler;
  1978. }
  1979. }
  1980. break;
  1981. }
  1982. case DEC_SET_TARGET_TEMPORAL_ID:
  1983. if (param == NULL) {
  1984. return RETCODE_INVALID_PARAM;
  1985. }
  1986. if (pDecInfo->tempIdSelectMode == FALSE)
  1987. pDecInfo->targetSubLayerId = *(Uint32*)param;
  1988. else
  1989. pDecInfo->relTargetLayerId = *(Uint32*)param;
  1990. break;
  1991. case DEC_SET_TEMPORAL_ID_MODE:
  1992. if (param == NULL) {
  1993. return RETCODE_INVALID_PARAM;
  1994. }
  1995. pDecInfo->tempIdSelectMode = *(Uint32*)param;
  1996. break;
  1997. case DEC_SET_BWB_CUR_FRAME_IDX:
  1998. pDecInfo->chBwbFrameIdx = *(Uint32*)param;
  1999. break;
  2000. case DEC_SET_FBC_CUR_FRAME_IDX:
  2001. pDecInfo->chFbcFrameIdx = *(Uint32*)param;
  2002. break;
  2003. case DEC_SET_INTER_RES_INFO_ON:
  2004. pDecInfo->interResChange = 1;
  2005. break;
  2006. case DEC_SET_INTER_RES_INFO_OFF:
  2007. pDecInfo->interResChange = 0;
  2008. break;
  2009. case DEC_FREE_FBC_TABLE_BUFFER:
  2010. {
  2011. Uint32 fbcCurFrameIdx = *(Uint32*)param;
  2012. if(pDecInfo->vbFbcYTbl[fbcCurFrameIdx].size > 0) {
  2013. vdi_free_dma_memory(pCodecInst->coreIdx, &pDecInfo->vbFbcYTbl[fbcCurFrameIdx], DEC_FBCY_TBL, pCodecInst->instIndex);
  2014. pDecInfo->vbFbcYTbl[fbcCurFrameIdx].size = 0;
  2015. }
  2016. if(pDecInfo->vbFbcCTbl[fbcCurFrameIdx].size > 0) {
  2017. vdi_free_dma_memory(pCodecInst->coreIdx, &pDecInfo->vbFbcCTbl[fbcCurFrameIdx], DEC_FBCC_TBL, pCodecInst->instIndex);
  2018. pDecInfo->vbFbcCTbl[fbcCurFrameIdx].size = 0;
  2019. }
  2020. }
  2021. break;
  2022. case DEC_FREE_MV_BUFFER:
  2023. {
  2024. Uint32 fbcCurFrameIdx = *(Uint32*)param;
  2025. if(pDecInfo->vbMV[fbcCurFrameIdx].size > 0) {
  2026. vdi_free_dma_memory(pCodecInst->coreIdx, &pDecInfo->vbMV[fbcCurFrameIdx], DEC_MV, pCodecInst->instIndex);
  2027. pDecInfo->vbMV[fbcCurFrameIdx].size = 0;
  2028. }
  2029. }
  2030. break;
  2031. case DEC_ALLOC_MV_BUFFER:
  2032. {
  2033. Uint32 fbcCurFrameIdx = *(Uint32*)param;
  2034. Uint32 size;
  2035. size = WAVE5_DEC_VP9_MVCOL_BUF_SIZE(pDecInfo->initialInfo.picWidth, pDecInfo->initialInfo.picHeight);
  2036. pDecInfo->vbMV[fbcCurFrameIdx].phys_addr = 0;
  2037. pDecInfo->vbMV[fbcCurFrameIdx].size = ((size+4095)&~4095)+4096; /* 4096 is a margin */
  2038. if (vdi_allocate_dma_memory(pCodecInst->coreIdx, &pDecInfo->vbMV[fbcCurFrameIdx], DEC_MV, pCodecInst->instIndex) < 0)
  2039. return RETCODE_INSUFFICIENT_RESOURCE;
  2040. }
  2041. break;
  2042. case DEC_ALLOC_FBC_Y_TABLE_BUFFER:
  2043. {
  2044. Uint32 fbcCurFrameIdx = *(Uint32*)param;
  2045. Uint32 size;
  2046. size = WAVE5_FBC_LUMA_TABLE_SIZE(VPU_ALIGN64(pDecInfo->initialInfo.picWidth), VPU_ALIGN64(pDecInfo->initialInfo.picHeight));
  2047. size = VPU_ALIGN16(size);
  2048. pDecInfo->vbFbcYTbl[fbcCurFrameIdx].phys_addr = 0;
  2049. pDecInfo->vbFbcYTbl[fbcCurFrameIdx].size = ((size+4095)&~4095)+4096;
  2050. if (vdi_allocate_dma_memory(pCodecInst->coreIdx, &pDecInfo->vbFbcYTbl[fbcCurFrameIdx], DEC_FBCY_TBL, pCodecInst->instIndex) < 0)
  2051. return RETCODE_INSUFFICIENT_RESOURCE;
  2052. }
  2053. break;
  2054. case DEC_ALLOC_FBC_C_TABLE_BUFFER:
  2055. {
  2056. Uint32 fbcCurFrameIdx = *(Uint32*)param;
  2057. Uint32 size;
  2058. size = WAVE5_FBC_CHROMA_TABLE_SIZE(VPU_ALIGN64(pDecInfo->initialInfo.picWidth), VPU_ALIGN64(pDecInfo->initialInfo.picHeight));
  2059. size = VPU_ALIGN16(size);
  2060. pDecInfo->vbFbcCTbl[fbcCurFrameIdx].phys_addr = 0;
  2061. pDecInfo->vbFbcCTbl[fbcCurFrameIdx].size = ((size+4095)&~4095)+4096;
  2062. if (vdi_allocate_dma_memory(pCodecInst->coreIdx, &pDecInfo->vbFbcCTbl[fbcCurFrameIdx], DEC_FBCC_TBL, pCodecInst->instIndex) < 0)
  2063. return RETCODE_INSUFFICIENT_RESOURCE;
  2064. }
  2065. break;
  2066. case GET_BANDWIDTH_REPORT:
  2067. ret = ProductVpuGetBandwidth(pCodecInst, (VPUBWData*)param);
  2068. break;
  2069. case SET_CYCLE_PER_TICK:
  2070. {
  2071. pDecInfo->cyclePerTick = *(Uint32 *)param;
  2072. }
  2073. break;
  2074. case GET_DEBUG_INFORM:
  2075. ret = ProductVpuGetDebugInfo(pCodecInst, (VPUDebugInfo*)param);
  2076. break;
  2077. default:
  2078. return RETCODE_INVALID_COMMAND;
  2079. }
  2080. return ret;
  2081. }
  2082. RetCode VPU_DecAllocateFrameBuffer(DecHandle handle, FrameBufferAllocInfo info, FrameBuffer *frameBuffer)
  2083. {
  2084. CodecInst* pCodecInst;
  2085. DecInfo* pDecInfo;
  2086. RetCode ret;
  2087. Uint32 gdiIndex;
  2088. ret = CheckDecInstanceValidity(handle);
  2089. if (ret != RETCODE_SUCCESS)
  2090. return ret;
  2091. pCodecInst = handle;
  2092. pDecInfo = &pCodecInst->CodecInfo->decInfo;
  2093. if (!frameBuffer) {
  2094. return RETCODE_INVALID_PARAM;
  2095. }
  2096. if (info.type == FB_TYPE_PPU) {
  2097. if (pDecInfo->numFrameBuffers == 0)
  2098. return RETCODE_WRONG_CALL_SEQUENCE;
  2099. if (frameBuffer[0].updateFbInfo == TRUE) {
  2100. pDecInfo->ppuAllocExt = TRUE;
  2101. }
  2102. pDecInfo->ppuAllocExt = frameBuffer[0].updateFbInfo;
  2103. gdiIndex = pDecInfo->numFbsForDecoding;
  2104. ret = ProductVpuAllocateFramebuffer(
  2105. pCodecInst, frameBuffer, (TiledMapType)info.mapType, (Int32)info.num,
  2106. info.stride, info.height, info.format, info.cbcrInterleave, info.nv21, info.endian, &pDecInfo->vbPPU, gdiIndex, FB_TYPE_PPU);
  2107. }
  2108. else if (info.type == FB_TYPE_CODEC) {
  2109. gdiIndex = 0;
  2110. if (frameBuffer[0].updateFbInfo == TRUE) {
  2111. pDecInfo->frameAllocExt = TRUE;
  2112. }
  2113. ret = ProductVpuAllocateFramebuffer(
  2114. pCodecInst, frameBuffer, (TiledMapType)info.mapType, (Int32)info.num,
  2115. info.stride, info.height, info.format, info.cbcrInterleave, info.nv21, info.endian, &pDecInfo->vbFrame, gdiIndex, (FramebufferAllocType)info.type);
  2116. pDecInfo->mapCfg.tiledBaseAddr = pDecInfo->vbFrame.phys_addr;
  2117. }
  2118. return ret;
  2119. }
  2120. RetCode VPU_EncOpen(EncHandle* pHandle, EncOpenParam * pop)
  2121. {
  2122. CodecInst* pCodecInst;
  2123. EncInfo* pEncInfo;
  2124. RetCode ret;
  2125. if ((ret=ProductCheckEncOpenParam(pop)) != RETCODE_SUCCESS)
  2126. return ret;
  2127. EnterLock(pop->coreIdx);
  2128. if (VPU_IsInit(pop->coreIdx) == 0) {
  2129. LeaveLock(pop->coreIdx);
  2130. return RETCODE_NOT_INITIALIZED;
  2131. }
  2132. ret = GetCodecInstance(pop->coreIdx, &pCodecInst);
  2133. if (ret == RETCODE_FAILURE) {
  2134. *pHandle = 0;
  2135. LeaveLock(pop->coreIdx);
  2136. return RETCODE_FAILURE;
  2137. }
  2138. pCodecInst->isDecoder = FALSE;
  2139. *pHandle = pCodecInst;
  2140. pEncInfo = &pCodecInst->CodecInfo->encInfo;
  2141. osal_memset(pEncInfo, 0x00, sizeof(EncInfo));
  2142. pEncInfo->openParam = *pop;
  2143. if ((ret=ProductVpuEncBuildUpOpenParam(pCodecInst, pop)) != RETCODE_SUCCESS) {
  2144. *pHandle = 0;
  2145. }
  2146. LeaveLock(pCodecInst->coreIdx);
  2147. return ret;
  2148. }
  2149. RetCode VPU_EncClose(EncHandle handle)
  2150. {
  2151. CodecInst* pCodecInst;
  2152. EncInfo* pEncInfo;
  2153. RetCode ret;
  2154. ret = CheckEncInstanceValidity(handle);
  2155. if (ret != RETCODE_SUCCESS) {
  2156. return ret;
  2157. }
  2158. pCodecInst = handle;
  2159. pEncInfo = &pCodecInst->CodecInfo->encInfo;
  2160. EnterLock(pCodecInst->coreIdx);
  2161. if (pEncInfo->initialInfoObtained) {
  2162. VpuWriteReg(pCodecInst->coreIdx, pEncInfo->streamWrPtrRegAddr, pEncInfo->streamWrPtr);
  2163. VpuWriteReg(pCodecInst->coreIdx, pEncInfo->streamRdPtrRegAddr, pEncInfo->streamRdPtr);
  2164. if ((ret=ProductVpuEncFiniSeq(pCodecInst)) != RETCODE_SUCCESS) {
  2165. if (pCodecInst->loggingEnable)
  2166. vdi_log(pCodecInst->coreIdx, ENC_SEQ_END, 2);
  2167. if (ret == RETCODE_VPU_STILL_RUNNING) {
  2168. LeaveLock(pCodecInst->coreIdx);
  2169. return ret;
  2170. }
  2171. }
  2172. if (pCodecInst->loggingEnable)
  2173. vdi_log(pCodecInst->coreIdx, ENC_SEQ_END, 0);
  2174. pEncInfo->streamWrPtr = VpuReadReg(pCodecInst->coreIdx, pEncInfo->streamWrPtrRegAddr);
  2175. }
  2176. if (pEncInfo->vbScratch.size) {
  2177. vdi_free_dma_memory(pCodecInst->coreIdx, &pEncInfo->vbScratch, ENC_ETC, pCodecInst->instIndex);
  2178. }
  2179. if (pEncInfo->vbWork.size) {
  2180. vdi_free_dma_memory(pCodecInst->coreIdx, &pEncInfo->vbWork, ENC_WORK, pCodecInst->instIndex);
  2181. }
  2182. if (pEncInfo->vbFrame.size) {
  2183. if (pEncInfo->frameAllocExt == 0)
  2184. vdi_free_dma_memory(pCodecInst->coreIdx, &pEncInfo->vbFrame, ENC_ETC, pCodecInst->instIndex);
  2185. }
  2186. if (pCodecInst->codecMode == W_HEVC_ENC || pCodecInst->codecMode == W_SVAC_ENC || pCodecInst->codecMode == W_AVC_ENC) {
  2187. if (pEncInfo->vbSubSamBuf.size)
  2188. vdi_free_dma_memory(pCodecInst->coreIdx, &pEncInfo->vbSubSamBuf, ENC_SUBSAMBUF, pCodecInst->instIndex);
  2189. if (pEncInfo->vbMV.size)
  2190. vdi_free_dma_memory(pCodecInst->coreIdx, &pEncInfo->vbMV, ENC_MV, pCodecInst->instIndex);
  2191. if (pEncInfo->vbFbcYTbl.size)
  2192. vdi_free_dma_memory(pCodecInst->coreIdx, &pEncInfo->vbFbcYTbl, ENC_FBCY_TBL, pCodecInst->instIndex);
  2193. if (pEncInfo->vbFbcCTbl.size)
  2194. vdi_free_dma_memory(pCodecInst->coreIdx, &pEncInfo->vbFbcCTbl, ENC_FBCC_TBL, pCodecInst->instIndex);
  2195. if (pEncInfo->vbTemp.size)
  2196. vdi_dettach_dma_memory(pCodecInst->coreIdx, &pEncInfo->vbTemp);
  2197. }
  2198. if (pEncInfo->vbPPU.size) {
  2199. if (pEncInfo->ppuAllocExt == 0)
  2200. vdi_free_dma_memory(pCodecInst->coreIdx, &pEncInfo->vbPPU, ENC_ETC, pCodecInst->instIndex);
  2201. }
  2202. if (pEncInfo->vbSubSampFrame.size)
  2203. vdi_free_dma_memory(pCodecInst->coreIdx, &pEncInfo->vbSubSampFrame, ENC_ETC, pCodecInst->instIndex);
  2204. if (pEncInfo->vbMvcSubSampFrame.size)
  2205. vdi_free_dma_memory(pCodecInst->coreIdx, &pEncInfo->vbMvcSubSampFrame, ENC_ETC, pCodecInst->instIndex);
  2206. if (pEncInfo->vbTask.size)
  2207. vdi_free_dma_memory(pCodecInst->coreIdx, &pEncInfo->vbTask, ENC_TASK, pCodecInst->instIndex);
  2208. LeaveLock(pCodecInst->coreIdx);
  2209. FreeCodecInstance(pCodecInst);
  2210. return ret;
  2211. }
  2212. RetCode VPU_EncGetInitialInfo(EncHandle handle, EncInitialInfo * info)
  2213. {
  2214. CodecInst* pCodecInst;
  2215. EncInfo* pEncInfo;
  2216. RetCode ret;
  2217. ret = CheckEncInstanceValidity(handle);
  2218. if (ret != RETCODE_SUCCESS)
  2219. return ret;
  2220. if (info == 0) {
  2221. return RETCODE_INVALID_PARAM;
  2222. }
  2223. pCodecInst = handle;
  2224. pEncInfo = &pCodecInst->CodecInfo->encInfo;
  2225. EnterLock(pCodecInst->coreIdx);
  2226. if (GetPendingInst(pCodecInst->coreIdx)) {
  2227. LeaveLock(pCodecInst->coreIdx);
  2228. return RETCODE_FRAME_NOT_COMPLETE;
  2229. }
  2230. if ((ret=ProductVpuEncSetup(pCodecInst)) != RETCODE_SUCCESS) {
  2231. LeaveLock(pCodecInst->coreIdx);
  2232. return ret;
  2233. }
  2234. if (pCodecInst->codecMode == AVC_ENC && pCodecInst->codecModeAux == AVC_AUX_MVC)
  2235. info->minFrameBufferCount = 3; // reconstructed frame + 2 reference frame
  2236. else if(pCodecInst->codecMode == W_HEVC_ENC || pCodecInst->codecMode == W_SVAC_ENC || pCodecInst->codecMode == W_AVC_ENC) {
  2237. info->minFrameBufferCount = pEncInfo->initialInfo.minFrameBufferCount;
  2238. info->minSrcFrameCount = pEncInfo->initialInfo.minSrcFrameCount;
  2239. }
  2240. else
  2241. info->minFrameBufferCount = 2; // reconstructed frame + reference frame
  2242. pEncInfo->initialInfo = *info;
  2243. pEncInfo->initialInfoObtained = TRUE;
  2244. LeaveLock(pCodecInst->coreIdx);
  2245. return RETCODE_SUCCESS;
  2246. }
  2247. RetCode VPU_EncRegisterFrameBuffer(EncHandle handle, FrameBuffer* bufArray, int num, int stride, int height, TiledMapType mapType)
  2248. {
  2249. CodecInst* pCodecInst;
  2250. EncInfo* pEncInfo;
  2251. Int32 i;
  2252. RetCode ret;
  2253. EncOpenParam* openParam;
  2254. FrameBuffer* fb;
  2255. ret = CheckEncInstanceValidity(handle);
  2256. // FIXME temp
  2257. if (ret != RETCODE_SUCCESS)
  2258. return ret;
  2259. pCodecInst = handle;
  2260. pEncInfo = &pCodecInst->CodecInfo->encInfo;
  2261. openParam = &pEncInfo->openParam;
  2262. if (pEncInfo->stride)
  2263. return RETCODE_CALLED_BEFORE;
  2264. if (!pEncInfo->initialInfoObtained)
  2265. return RETCODE_WRONG_CALL_SEQUENCE;
  2266. if (num < pEncInfo->initialInfo.minFrameBufferCount)
  2267. return RETCODE_INSUFFICIENT_FRAME_BUFFERS;
  2268. if (stride == 0 || (stride % 8 != 0) || stride < 0)
  2269. return RETCODE_INVALID_STRIDE;
  2270. if (height == 0 || height < 0)
  2271. return RETCODE_INVALID_PARAM;
  2272. if ( pEncInfo->productCode == WAVE521C_DUAL_CODE) {
  2273. if (openParam->bitstreamFormat == STD_HEVC) {
  2274. if (stride % 16 != 0)
  2275. return RETCODE_INVALID_STRIDE;
  2276. }
  2277. }
  2278. else {
  2279. if (openParam->bitstreamFormat == STD_HEVC) {
  2280. if (stride % 32 != 0)
  2281. return RETCODE_INVALID_STRIDE;
  2282. }
  2283. }
  2284. EnterLock(pCodecInst->coreIdx);
  2285. if (GetPendingInst(pCodecInst->coreIdx)) {
  2286. LeaveLock(pCodecInst->coreIdx);
  2287. return RETCODE_FRAME_NOT_COMPLETE;
  2288. }
  2289. pEncInfo->numFrameBuffers = num;
  2290. pEncInfo->stride = stride;
  2291. pEncInfo->frameBufferHeight = height;
  2292. pEncInfo->mapType = mapType;
  2293. pEncInfo->mapCfg.productId = pCodecInst->productId;
  2294. if (bufArray) {
  2295. for(i=0; i<num; i++) {
  2296. pEncInfo->frameBufPool[i] = bufArray[i];
  2297. }
  2298. if (openParam->EncStdParam.waveParam.svcEnable == TRUE) {
  2299. for(i=num; i<num*2; i++) {
  2300. pEncInfo->frameBufPool[i] = bufArray[i];
  2301. }
  2302. }
  2303. }
  2304. if (pEncInfo->frameAllocExt == FALSE) {
  2305. fb = pEncInfo->frameBufPool;
  2306. if (bufArray) {
  2307. if (bufArray[0].bufCb == (PhysicalAddress)-1 && bufArray[0].bufCr == (PhysicalAddress)-1) {
  2308. Uint32 size;
  2309. pEncInfo->frameAllocExt = TRUE;
  2310. size = ProductCalculateFrameBufSize(pCodecInst, pCodecInst->productId, stride, height,
  2311. (TiledMapType)mapType, (FrameBufferFormat)openParam->srcFormat,
  2312. (BOOL)openParam->cbcrInterleave, NULL);
  2313. if (mapType == LINEAR_FRAME_MAP) {
  2314. pEncInfo->vbFrame.phys_addr = bufArray[0].bufY;
  2315. pEncInfo->vbFrame.size = size * num;
  2316. }
  2317. }
  2318. }
  2319. ret = ProductVpuAllocateFramebuffer(
  2320. pCodecInst, fb, (TiledMapType)mapType, num, stride, height, (FrameBufferFormat)openParam->srcFormat,
  2321. openParam->cbcrInterleave, FALSE, openParam->frameEndian, &pEncInfo->vbFrame, 0, FB_TYPE_CODEC);
  2322. if (ret != RETCODE_SUCCESS) {
  2323. SetPendingInst(pCodecInst->coreIdx, 0);
  2324. LeaveLock(pCodecInst->coreIdx);
  2325. return ret;
  2326. }
  2327. }
  2328. ret = ProductVpuRegisterFramebuffer(pCodecInst);
  2329. SetPendingInst(pCodecInst->coreIdx, 0);
  2330. LeaveLock(pCodecInst->coreIdx);
  2331. return ret;
  2332. }
  2333. RetCode VPU_EncGetBitstreamBuffer( EncHandle handle,
  2334. PhysicalAddress * prdPrt,
  2335. PhysicalAddress * pwrPtr,
  2336. int * size)
  2337. {
  2338. CodecInst * pCodecInst;
  2339. EncInfo * pEncInfo;
  2340. PhysicalAddress rdPtr;
  2341. PhysicalAddress wrPtr;
  2342. Uint32 room;
  2343. RetCode ret;
  2344. ret = CheckEncInstanceValidity(handle);
  2345. if (ret != RETCODE_SUCCESS)
  2346. return ret;
  2347. if ( prdPrt == 0 || pwrPtr == 0 || size == 0) {
  2348. return RETCODE_INVALID_PARAM;
  2349. }
  2350. pCodecInst = handle;
  2351. pEncInfo = &pCodecInst->CodecInfo->encInfo;
  2352. rdPtr = pEncInfo->streamRdPtr;
  2353. if (GetPendingInst(pCodecInst->coreIdx) == pCodecInst)
  2354. wrPtr = VpuReadReg(pCodecInst->coreIdx, pEncInfo->streamWrPtrRegAddr);
  2355. else {
  2356. if (handle->productId == PRODUCT_ID_521) {
  2357. EnterLock(pCodecInst->coreIdx);
  2358. ProductVpuEncGetRdWrPtr(pCodecInst, &rdPtr, &wrPtr);
  2359. LeaveLock(pCodecInst->coreIdx);
  2360. }
  2361. else
  2362. wrPtr = pEncInfo->streamWrPtr;
  2363. }
  2364. if(pEncInfo->ringBufferEnable == 1 || pEncInfo->lineBufIntEn == 1) {
  2365. if (wrPtr >= rdPtr) {
  2366. room = wrPtr - rdPtr;
  2367. }
  2368. else {
  2369. room = (pEncInfo->streamBufEndAddr - rdPtr) + (wrPtr - pEncInfo->streamBufStartAddr);
  2370. }
  2371. }
  2372. else {
  2373. if(wrPtr >= rdPtr)
  2374. room = wrPtr - rdPtr;
  2375. else
  2376. return RETCODE_INVALID_PARAM;
  2377. }
  2378. *prdPrt = rdPtr;
  2379. *pwrPtr = wrPtr;
  2380. *size = room;
  2381. return RETCODE_SUCCESS;
  2382. }
  2383. RetCode VPU_EncUpdateBitstreamBuffer(
  2384. EncHandle handle,
  2385. int size)
  2386. {
  2387. CodecInst * pCodecInst;
  2388. EncInfo * pEncInfo;
  2389. PhysicalAddress wrPtr;
  2390. PhysicalAddress rdPtr;
  2391. RetCode ret;
  2392. int room = 0;
  2393. ret = CheckEncInstanceValidity(handle);
  2394. if (ret != RETCODE_SUCCESS)
  2395. return ret;
  2396. pCodecInst = handle;
  2397. pEncInfo = &pCodecInst->CodecInfo->encInfo;
  2398. rdPtr = pEncInfo->streamRdPtr;
  2399. if (GetPendingInst(pCodecInst->coreIdx) == pCodecInst)
  2400. wrPtr = VpuReadReg(pCodecInst->coreIdx, pEncInfo->streamWrPtrRegAddr);
  2401. else
  2402. wrPtr = pEncInfo->streamWrPtr;
  2403. if ( rdPtr < wrPtr ) {
  2404. if ( rdPtr + size > wrPtr ) {
  2405. return RETCODE_INVALID_PARAM;
  2406. }
  2407. }
  2408. if (PRODUCT_ID_NOT_W_SERIES(pCodecInst->productId)) {
  2409. //************** for CODA *********************/
  2410. if (pEncInfo->ringBufferEnable == TRUE || pEncInfo->lineBufIntEn == TRUE) {
  2411. rdPtr += size;
  2412. if (rdPtr > pEncInfo->streamBufEndAddr) {
  2413. if (pEncInfo->lineBufIntEn == TRUE) {
  2414. return RETCODE_INVALID_PARAM;
  2415. }
  2416. room = rdPtr - pEncInfo->streamBufEndAddr;
  2417. rdPtr = pEncInfo->streamBufStartAddr;
  2418. rdPtr += room;
  2419. }
  2420. if (rdPtr == pEncInfo->streamBufEndAddr)
  2421. rdPtr = pEncInfo->streamBufStartAddr;
  2422. }
  2423. else {
  2424. rdPtr = pEncInfo->streamBufStartAddr;
  2425. }
  2426. }
  2427. else {
  2428. //************** for WAVE5 *********************/
  2429. if (size > 0) {
  2430. if (pEncInfo->ringBufferEnable == TRUE) {
  2431. rdPtr += size;
  2432. if (pEncInfo->ringBufferWrapEnable == TRUE) {
  2433. //======== [case1]. ring=1 & wrap=1 ===================
  2434. if (rdPtr > pEncInfo->streamBufEndAddr) {
  2435. if (pEncInfo->lineBufIntEn == TRUE) {
  2436. return RETCODE_INVALID_PARAM;
  2437. }
  2438. room = rdPtr - pEncInfo->streamBufEndAddr;
  2439. rdPtr = pEncInfo->streamBufStartAddr;
  2440. rdPtr += room;
  2441. }
  2442. pEncInfo->streamRdPtr = rdPtr;
  2443. EnterLock(pCodecInst->coreIdx);
  2444. ProductVpuEncUpdateBitstreamBuffer(pCodecInst, size);
  2445. LeaveLock(pCodecInst->coreIdx);
  2446. if (rdPtr == pEncInfo->streamBufEndAddr) {
  2447. //set EndAddr to FW and set StartAddr to API
  2448. rdPtr = pEncInfo->streamBufStartAddr; // wrap-around
  2449. }
  2450. }
  2451. else {
  2452. //========= [case2]. ring=1 & wrap=0 ===================
  2453. pEncInfo->streamRdPtr = rdPtr;
  2454. EnterLock(pCodecInst->coreIdx);
  2455. ProductVpuEncUpdateBitstreamBuffer(pCodecInst, size);
  2456. LeaveLock(pCodecInst->coreIdx);
  2457. if (rdPtr == pEncInfo->streamBufEndAddr) {
  2458. //set EndAddr to FW and set StartAddr to API
  2459. rdPtr = pEncInfo->streamBufStartAddr; // start? end? [FIX ME]
  2460. }
  2461. }
  2462. }
  2463. else {
  2464. //========= [case3]. Line buffer mode ===================
  2465. if (VPU_ALIGN16(wrPtr) >= pEncInfo->streamRdPtr + pEncInfo->streamBufSize) { // linebuffer full detected. already host read whole bistream in bitstreamBuffer.
  2466. EnterLock(pCodecInst->coreIdx);
  2467. ProductVpuEncUpdateBitstreamBuffer(pCodecInst, size);
  2468. LeaveLock(pCodecInst->coreIdx);
  2469. }
  2470. }
  2471. }
  2472. else {
  2473. //************ update new CPB buffer addr/size ***************/
  2474. if (size == UPDATE_NEW_BS_BUF) {
  2475. pEncInfo->streamRdPtr = pEncInfo->streamBufStartAddr;
  2476. pEncInfo->streamBufTobeReadStartAddr = pEncInfo->streamBufStartAddr;
  2477. pEncInfo->streamBufTobeReadSize = pEncInfo->streamBufSize;
  2478. pEncInfo->streamBufTobeReadEndAddr = pEncInfo->streamBufStartAddr + pEncInfo->streamBufSize;
  2479. EnterLock(pCodecInst->coreIdx);
  2480. ProductVpuEncUpdateBitstreamBuffer(pCodecInst, size);
  2481. LeaveLock(pCodecInst->coreIdx);
  2482. rdPtr = pEncInfo->streamBufStartAddr;
  2483. }
  2484. }
  2485. }
  2486. pEncInfo->streamRdPtr = rdPtr;
  2487. pEncInfo->streamWrPtr = wrPtr;
  2488. if (GetPendingInst(pCodecInst->coreIdx) == pCodecInst)
  2489. VpuWriteReg(pCodecInst->coreIdx, pEncInfo->streamRdPtrRegAddr, rdPtr);
  2490. if (pEncInfo->ringBufferEnable == FALSE && pEncInfo->lineBufIntEn == TRUE) {
  2491. pEncInfo->streamRdPtr = pEncInfo->streamBufStartAddr;
  2492. }
  2493. return RETCODE_SUCCESS;
  2494. }
  2495. RetCode VPU_EncStartOneFrame(
  2496. EncHandle handle,
  2497. EncParam * param
  2498. )
  2499. {
  2500. CodecInst* pCodecInst;
  2501. EncInfo* pEncInfo;
  2502. RetCode ret;
  2503. VpuAttr* pAttr = NULL;
  2504. vpu_instance_pool_t* vip;
  2505. ret = CheckEncInstanceValidity(handle);
  2506. if (ret != RETCODE_SUCCESS)
  2507. return ret;
  2508. pCodecInst = handle;
  2509. pEncInfo = &pCodecInst->CodecInfo->encInfo;
  2510. vip = (vpu_instance_pool_t *)vdi_get_instance_pool(pCodecInst->coreIdx);
  2511. if (!vip) {
  2512. return RETCODE_INVALID_HANDLE;
  2513. }
  2514. if (pEncInfo->stride == 0) { // This means frame buffers have not been registered.
  2515. return RETCODE_WRONG_CALL_SEQUENCE;
  2516. }
  2517. ret = CheckEncParam(handle, param);
  2518. if (ret != RETCODE_SUCCESS) {
  2519. return ret;
  2520. }
  2521. pAttr = &g_VpuCoreAttributes[pCodecInst->coreIdx];
  2522. EnterLock(pCodecInst->coreIdx);
  2523. pEncInfo->ptsMap[param->srcIdx] = (pEncInfo->openParam.enablePTS == TRUE) ? GetTimestamp(handle) : param->pts;
  2524. if (GetPendingInst(pCodecInst->coreIdx)) {
  2525. LeaveLock(pCodecInst->coreIdx);
  2526. return RETCODE_FRAME_NOT_COMPLETE;
  2527. }
  2528. ret = ProductVpuEncode(pCodecInst, param);
  2529. if (pAttr->supportCommandQueue == TRUE) {
  2530. SetPendingInst(pCodecInst->coreIdx, NULL);
  2531. LeaveLock(pCodecInst->coreIdx);
  2532. }
  2533. else {
  2534. SetPendingInst(pCodecInst->coreIdx, pCodecInst);
  2535. }
  2536. return ret;
  2537. }
  2538. RetCode VPU_EncGetOutputInfo(
  2539. EncHandle handle,
  2540. EncOutputInfo* info
  2541. )
  2542. {
  2543. CodecInst* pCodecInst;
  2544. EncInfo* pEncInfo;
  2545. RetCode ret;
  2546. VpuAttr* pAttr;
  2547. ret = CheckEncInstanceValidity(handle);
  2548. if (ret != RETCODE_SUCCESS) {
  2549. return ret;
  2550. }
  2551. if (info == 0) {
  2552. return RETCODE_INVALID_PARAM;
  2553. }
  2554. pCodecInst = handle;
  2555. pEncInfo = &pCodecInst->CodecInfo->encInfo;
  2556. pAttr = &g_VpuCoreAttributes[pCodecInst->coreIdx];
  2557. if (pAttr->supportCommandQueue == TRUE) {
  2558. EnterLock(pCodecInst->coreIdx);
  2559. }
  2560. else {
  2561. if (pCodecInst != GetPendingInst(pCodecInst->coreIdx)) {
  2562. SetPendingInst(pCodecInst->coreIdx, 0);
  2563. LeaveLock(pCodecInst->coreIdx);
  2564. return RETCODE_WRONG_CALL_SEQUENCE;
  2565. }
  2566. }
  2567. ret = ProductVpuEncGetResult(pCodecInst, info);
  2568. if (ret == RETCODE_SUCCESS) {
  2569. if (info->encSrcIdx >= 0 && info->reconFrameIndex >= 0 )
  2570. info->pts = pEncInfo->ptsMap[info->encSrcIdx];
  2571. }
  2572. else {
  2573. info->pts = 0LL;
  2574. }
  2575. SetPendingInst(pCodecInst->coreIdx, 0);
  2576. LeaveLock(pCodecInst->coreIdx);
  2577. return ret;
  2578. }
  2579. RetCode VPU_EncGiveCommand(
  2580. EncHandle handle,
  2581. CodecCommand cmd,
  2582. void* param
  2583. )
  2584. {
  2585. CodecInst* pCodecInst;
  2586. EncInfo* pEncInfo;
  2587. RetCode ret;
  2588. ret = CheckEncInstanceValidity(handle);
  2589. if (ret != RETCODE_SUCCESS) {
  2590. return ret;
  2591. }
  2592. pCodecInst = handle;
  2593. pEncInfo = &pCodecInst->CodecInfo->encInfo;
  2594. switch (cmd)
  2595. {
  2596. case ENABLE_ROTATION :
  2597. {
  2598. pEncInfo->rotationEnable = 1;
  2599. }
  2600. break;
  2601. case DISABLE_ROTATION :
  2602. {
  2603. pEncInfo->rotationEnable = 0;
  2604. }
  2605. break;
  2606. case ENABLE_MIRRORING :
  2607. {
  2608. pEncInfo->mirrorEnable = 1;
  2609. }
  2610. break;
  2611. case DISABLE_MIRRORING :
  2612. {
  2613. pEncInfo->mirrorEnable = 0;
  2614. }
  2615. break;
  2616. case SET_MIRROR_DIRECTION :
  2617. {
  2618. MirrorDirection mirDir;
  2619. if (param == 0) {
  2620. return RETCODE_INVALID_PARAM;
  2621. }
  2622. mirDir = *(MirrorDirection *)param;
  2623. if ( !(mirDir == MIRDIR_NONE) && !(mirDir==MIRDIR_HOR) && !(mirDir==MIRDIR_VER) && !(mirDir==MIRDIR_HOR_VER)) {
  2624. return RETCODE_INVALID_PARAM;
  2625. }
  2626. pEncInfo->mirrorDirection = mirDir;
  2627. }
  2628. break;
  2629. case SET_ROTATION_ANGLE :
  2630. {
  2631. int angle;
  2632. if (param == 0) {
  2633. return RETCODE_INVALID_PARAM;
  2634. }
  2635. angle = *(int *)param;
  2636. if (angle != 0 && angle != 90 &&
  2637. angle != 180 && angle != 270) {
  2638. return RETCODE_INVALID_PARAM;
  2639. }
  2640. if (pEncInfo->initialInfoObtained && (angle == 90 || angle ==270)) {
  2641. return RETCODE_INVALID_PARAM;
  2642. }
  2643. pEncInfo->rotationAngle = angle;
  2644. }
  2645. break;
  2646. case SET_CACHE_CONFIG:
  2647. {
  2648. MaverickCacheConfig *mcCacheConfig;
  2649. if (param == 0) {
  2650. return RETCODE_INVALID_PARAM;
  2651. }
  2652. mcCacheConfig = (MaverickCacheConfig *)param;
  2653. pEncInfo->cacheConfig = *mcCacheConfig;
  2654. }
  2655. break;
  2656. case ENC_PUT_VIDEO_HEADER:
  2657. {
  2658. EncHeaderParam *encHeaderParam;
  2659. if (param == 0) {
  2660. return RETCODE_INVALID_PARAM;
  2661. }
  2662. encHeaderParam = (EncHeaderParam *)param;
  2663. if (pCodecInst->codecMode == MP4_ENC ) {
  2664. if (!( VOL_HEADER<=encHeaderParam->headerType && encHeaderParam->headerType <= VIS_HEADER)) {
  2665. return RETCODE_INVALID_PARAM;
  2666. }
  2667. }
  2668. else if (pCodecInst->codecMode == AVC_ENC) {
  2669. if (!( SPS_RBSP<=encHeaderParam->headerType && encHeaderParam->headerType <= PPS_RBSP_MVC)) {
  2670. return RETCODE_INVALID_PARAM;
  2671. }
  2672. }
  2673. else if (pCodecInst->codecMode == W_HEVC_ENC || pCodecInst->codecMode == W_SVAC_ENC || pCodecInst->codecMode == W_AVC_ENC) {
  2674. if (!( CODEOPT_ENC_VPS<=encHeaderParam->headerType && encHeaderParam->headerType <= (CODEOPT_ENC_VPS|CODEOPT_ENC_SPS|CODEOPT_ENC_PPS))) {
  2675. return RETCODE_INVALID_PARAM;
  2676. }
  2677. if (pEncInfo->ringBufferEnable == 0 ) {
  2678. if (encHeaderParam->buf % 16 || encHeaderParam->size == 0)
  2679. return RETCODE_INVALID_PARAM;
  2680. }
  2681. if (encHeaderParam->headerType & CODEOPT_ENC_VCL) // ENC_PUT_VIDEO_HEADER encode only non-vcl header.
  2682. return RETCODE_INVALID_PARAM;
  2683. }
  2684. else
  2685. return RETCODE_INVALID_PARAM;
  2686. if (pEncInfo->ringBufferEnable == 0 ) {
  2687. if (encHeaderParam->buf % 8 || encHeaderParam->size == 0) {
  2688. return RETCODE_INVALID_PARAM;
  2689. }
  2690. }
  2691. if (pCodecInst->codecMode == W_HEVC_ENC || pCodecInst->codecMode == W_SVAC_ENC || pCodecInst->codecMode == W_AVC_ENC) {
  2692. if (handle->productId == PRODUCT_ID_521)
  2693. return Wave5VpuEncGetHeader(handle, encHeaderParam);
  2694. else
  2695. return RETCODE_INVALID_PARAM;
  2696. }
  2697. else {
  2698. return GetEncHeader(handle, encHeaderParam);
  2699. }
  2700. }
  2701. case ENC_SET_PARAM:
  2702. {
  2703. if (param == 0) {
  2704. return RETCODE_INVALID_PARAM;
  2705. }
  2706. pEncInfo->openParam = *(EncOpenParam *)param;
  2707. if (pCodecInst->codecMode != AVC_ENC)
  2708. return RETCODE_INVALID_COMMAND;
  2709. ret = EncParaSet(handle, SPS_RBSP);
  2710. if (ret != RETCODE_SUCCESS)
  2711. return ret;
  2712. ret = EncParaSet(handle, PPS_RBSP);
  2713. if (ret != RETCODE_SUCCESS)
  2714. return ret;
  2715. return ret;
  2716. }
  2717. case ENC_SET_GOP_NUMBER:
  2718. {
  2719. int *pGopNumber =(int *)param;
  2720. if (pCodecInst->codecMode != MP4_ENC && pCodecInst->codecMode != AVC_ENC) {
  2721. return RETCODE_INVALID_COMMAND;
  2722. }
  2723. if (*pGopNumber < 0)
  2724. return RETCODE_INVALID_PARAM;
  2725. pEncInfo->openParam.gopSize = *pGopNumber;
  2726. SetGopNumber(handle, (Uint32 *)pGopNumber);
  2727. }
  2728. break;
  2729. case ENC_SET_INTRA_QP:
  2730. {
  2731. int *pIntraQp =(int *)param;
  2732. if (pCodecInst->codecMode != MP4_ENC && pCodecInst->codecMode != AVC_ENC) {
  2733. return RETCODE_INVALID_COMMAND;
  2734. }
  2735. if (pCodecInst->codecMode == MP4_ENC)
  2736. {
  2737. if(*pIntraQp<1 || *pIntraQp>31)
  2738. return RETCODE_INVALID_PARAM;
  2739. }
  2740. if (pCodecInst->codecMode == AVC_ENC)
  2741. {
  2742. if(*pIntraQp<0 || *pIntraQp>51)
  2743. return RETCODE_INVALID_PARAM;
  2744. }
  2745. SetIntraQp(handle, (Uint32 *)pIntraQp);
  2746. }
  2747. break;
  2748. case ENC_SET_BITRATE:
  2749. {
  2750. int *pBitrate = (int *)param;
  2751. if (pCodecInst->codecMode != MP4_ENC && pCodecInst->codecMode != AVC_ENC) {
  2752. return RETCODE_INVALID_COMMAND;
  2753. }
  2754. {
  2755. if (*pBitrate < 0 || *pBitrate> 32767) {
  2756. return RETCODE_INVALID_PARAM;
  2757. }
  2758. }
  2759. SetBitrate(handle, (Uint32 *)pBitrate);
  2760. }
  2761. break;
  2762. case ENC_SET_FRAME_RATE:
  2763. {
  2764. int *pFramerate = (int *)param;
  2765. if (pCodecInst->codecMode != MP4_ENC && pCodecInst->codecMode != AVC_ENC) {
  2766. return RETCODE_INVALID_COMMAND;
  2767. }
  2768. if (*pFramerate <= 0) {
  2769. return RETCODE_INVALID_PARAM;
  2770. }
  2771. SetFramerate(handle, (Uint32 *)pFramerate);
  2772. }
  2773. break;
  2774. case ENC_SET_INTRA_MB_REFRESH_NUMBER:
  2775. {
  2776. int *pIntraRefreshNum =(int *)param;
  2777. SetIntraRefreshNum(handle, (Uint32 *)pIntraRefreshNum);
  2778. }
  2779. break;
  2780. case ENC_SET_SLICE_INFO:
  2781. {
  2782. EncSliceMode *pSliceMode = (EncSliceMode *)param;
  2783. if(pSliceMode->sliceMode<0 || pSliceMode->sliceMode>1)
  2784. {
  2785. return RETCODE_INVALID_PARAM;
  2786. }
  2787. if(pSliceMode->sliceSizeMode<0 || pSliceMode->sliceSizeMode>1)
  2788. {
  2789. return RETCODE_INVALID_PARAM;
  2790. }
  2791. SetSliceMode(handle, (EncSliceMode *)pSliceMode);
  2792. }
  2793. break;
  2794. case ENC_ENABLE_HEC:
  2795. {
  2796. if (pCodecInst->codecMode != MP4_ENC) {
  2797. return RETCODE_INVALID_COMMAND;
  2798. }
  2799. SetHecMode(handle, 1);
  2800. }
  2801. break;
  2802. case ENC_DISABLE_HEC:
  2803. {
  2804. if (pCodecInst->codecMode != MP4_ENC) {
  2805. return RETCODE_INVALID_COMMAND;
  2806. }
  2807. SetHecMode(handle, 0);
  2808. }
  2809. break;
  2810. case SET_SEC_AXI:
  2811. {
  2812. SecAxiUse secAxiUse;
  2813. if (param == 0) {
  2814. return RETCODE_INVALID_PARAM;
  2815. }
  2816. secAxiUse = *(SecAxiUse *)param;
  2817. if (handle->productId == PRODUCT_ID_521) {
  2818. pEncInfo->secAxiInfo.u.wave.useEncRdoEnable = secAxiUse.u.wave.useEncRdoEnable;
  2819. pEncInfo->secAxiInfo.u.wave.useEncLfEnable = secAxiUse.u.wave.useEncLfEnable;
  2820. }
  2821. else { // coda9 or coda7q or ...
  2822. pEncInfo->secAxiInfo.u.coda9.useBitEnable = secAxiUse.u.coda9.useBitEnable;
  2823. pEncInfo->secAxiInfo.u.coda9.useIpEnable = secAxiUse.u.coda9.useIpEnable;
  2824. pEncInfo->secAxiInfo.u.coda9.useDbkYEnable = secAxiUse.u.coda9.useDbkYEnable;
  2825. pEncInfo->secAxiInfo.u.coda9.useDbkCEnable = secAxiUse.u.coda9.useDbkCEnable;
  2826. pEncInfo->secAxiInfo.u.coda9.useOvlEnable = secAxiUse.u.coda9.useOvlEnable;
  2827. pEncInfo->secAxiInfo.u.coda9.useBtpEnable = secAxiUse.u.coda9.useBtpEnable;
  2828. }
  2829. }
  2830. break;
  2831. case GET_TILEDMAP_CONFIG:
  2832. {
  2833. TiledMapConfig *pMapCfg = (TiledMapConfig *)param;
  2834. if (!pMapCfg) {
  2835. return RETCODE_INVALID_PARAM;
  2836. }
  2837. *pMapCfg = pEncInfo->mapCfg;
  2838. break;
  2839. }
  2840. case SET_DRAM_CONFIG:
  2841. {
  2842. DRAMConfig *cfg = (DRAMConfig *)param;
  2843. if (!cfg) {
  2844. return RETCODE_INVALID_PARAM;
  2845. }
  2846. pEncInfo->dramCfg = *cfg;
  2847. break;
  2848. }
  2849. case GET_DRAM_CONFIG:
  2850. {
  2851. DRAMConfig *cfg = (DRAMConfig *)param;
  2852. if (!cfg) {
  2853. return RETCODE_INVALID_PARAM;
  2854. }
  2855. *cfg = pEncInfo->dramCfg;
  2856. break;
  2857. }
  2858. case ENABLE_LOGGING:
  2859. {
  2860. pCodecInst->loggingEnable = 1;
  2861. }
  2862. break;
  2863. case DISABLE_LOGGING:
  2864. {
  2865. pCodecInst->loggingEnable = 0;
  2866. }
  2867. break;
  2868. case ENC_SET_PARA_CHANGE:
  2869. {
  2870. EncChangeParam* option = (EncChangeParam*)param;
  2871. if (handle->productId == PRODUCT_ID_521)
  2872. return Wave5VpuEncParaChange(handle, option);
  2873. else
  2874. return RETCODE_INVALID_PARAM;
  2875. }
  2876. case GET_BANDWIDTH_REPORT :
  2877. return ProductVpuGetBandwidth(pCodecInst, (VPUBWData*)param);
  2878. case ENC_GET_QUEUE_STATUS:
  2879. {
  2880. QueueStatusInfo* queueInfo = (QueueStatusInfo*)param;
  2881. queueInfo->instanceQueueCount = pEncInfo->instanceQueueCount;
  2882. queueInfo->reportQueueCount = pEncInfo->reportQueueCount;
  2883. break;
  2884. }
  2885. case ENC_WRPTR_SEL:
  2886. {
  2887. pEncInfo->encWrPtrSel = *(int *)param;
  2888. }
  2889. break;
  2890. case SET_CYCLE_PER_TICK:
  2891. {
  2892. pEncInfo->cyclePerTick = *(Uint32 *)param;
  2893. }
  2894. break;
  2895. case ENC_GET_SRC_BUF_FLAG:
  2896. return ProductVpuGetSrcBufFlag(pCodecInst, (Uint32*)param);
  2897. case GET_DEBUG_INFORM:
  2898. return ProductVpuGetDebugInfo(pCodecInst, (VPUDebugInfo*)param);
  2899. #ifdef SUPPORT_LOOK_AHEAD_RC
  2900. case ENC_SET_LARC_DATA:
  2901. {
  2902. EncLarcInfo* larcInfo = (EncLarcInfo*)param;
  2903. if (handle->productId == PRODUCT_ID_521)
  2904. return Wave5VpuEncSetLarcData(handle, *larcInfo);
  2905. else
  2906. return RETCODE_INVALID_PARAM;
  2907. }
  2908. break;
  2909. #endif
  2910. default:
  2911. return RETCODE_INVALID_COMMAND;
  2912. }
  2913. return RETCODE_SUCCESS;
  2914. }
  2915. RetCode VPU_EncAllocateFrameBuffer(EncHandle handle, FrameBufferAllocInfo info, FrameBuffer *frameBuffer)
  2916. {
  2917. CodecInst* pCodecInst;
  2918. EncInfo* pEncInfo;
  2919. RetCode ret;
  2920. int gdiIndex;
  2921. ret = CheckEncInstanceValidity(handle);
  2922. if (ret != RETCODE_SUCCESS)
  2923. return ret;
  2924. pCodecInst = handle;
  2925. pEncInfo = &pCodecInst->CodecInfo->encInfo;
  2926. if (!frameBuffer) {
  2927. return RETCODE_INVALID_PARAM;
  2928. }
  2929. if (info.num == 0 || info.num < 0) {
  2930. return RETCODE_INVALID_PARAM;
  2931. }
  2932. if (info.stride == 0 || info.stride < 0) {
  2933. return RETCODE_INVALID_PARAM;
  2934. }
  2935. if (info.height == 0 || info.height < 0) {
  2936. return RETCODE_INVALID_PARAM;
  2937. }
  2938. if (info.type == FB_TYPE_PPU) {
  2939. if (pEncInfo->numFrameBuffers == 0) {
  2940. return RETCODE_WRONG_CALL_SEQUENCE;
  2941. }
  2942. pEncInfo->ppuAllocExt = frameBuffer[0].updateFbInfo;
  2943. gdiIndex = pEncInfo->numFrameBuffers;
  2944. ret = ProductVpuAllocateFramebuffer(pCodecInst, frameBuffer, (TiledMapType)info.mapType, (Int32)info.num,
  2945. info.stride, info.height, info.format, info.cbcrInterleave, info.nv21,
  2946. info.endian, &pEncInfo->vbPPU, gdiIndex, (FramebufferAllocType)info.type);
  2947. }
  2948. else if (info.type == FB_TYPE_CODEC) {
  2949. gdiIndex = 0;
  2950. pEncInfo->frameAllocExt = frameBuffer[0].updateFbInfo;
  2951. ret = ProductVpuAllocateFramebuffer(
  2952. pCodecInst, frameBuffer, (TiledMapType)info.mapType, (Int32)info.num,
  2953. info.stride, info.height, info.format, info.cbcrInterleave, FALSE, info.endian, &pEncInfo->vbFrame, gdiIndex, (FramebufferAllocType)info.type);
  2954. }
  2955. else {
  2956. ret = RETCODE_INVALID_PARAM;
  2957. }
  2958. return ret;
  2959. }
  2960. RetCode VPU_EncIssueSeqInit(EncHandle handle)
  2961. {
  2962. CodecInst* pCodecInst;
  2963. RetCode ret;
  2964. VpuAttr* pAttr;
  2965. ret = CheckEncInstanceValidity(handle);
  2966. if (ret != RETCODE_SUCCESS)
  2967. return ret;
  2968. pCodecInst = handle;
  2969. EnterLock(pCodecInst->coreIdx);
  2970. pAttr = &g_VpuCoreAttributes[pCodecInst->coreIdx];
  2971. if (GetPendingInst(pCodecInst->coreIdx)) {
  2972. LeaveLock(pCodecInst->coreIdx);
  2973. return RETCODE_FRAME_NOT_COMPLETE;
  2974. }
  2975. ret = ProductVpuEncInitSeq(handle);
  2976. if (ret == RETCODE_SUCCESS) {
  2977. SetPendingInst(pCodecInst->coreIdx, pCodecInst);
  2978. }
  2979. if (pAttr->supportCommandQueue == TRUE) {
  2980. SetPendingInst(pCodecInst->coreIdx, NULL);
  2981. LeaveLock(pCodecInst->coreIdx);
  2982. }
  2983. return ret;
  2984. }
  2985. RetCode VPU_EncCompleteSeqInit(EncHandle handle, EncInitialInfo * info)
  2986. {
  2987. CodecInst* pCodecInst;
  2988. EncInfo* pEncInfo;
  2989. RetCode ret;
  2990. VpuAttr* pAttr;
  2991. ret = CheckEncInstanceValidity(handle);
  2992. if (ret != RETCODE_SUCCESS) {
  2993. return ret;
  2994. }
  2995. if (info == 0) {
  2996. return RETCODE_INVALID_PARAM;
  2997. }
  2998. pCodecInst = handle;
  2999. pEncInfo = &pCodecInst->CodecInfo->encInfo;
  3000. pAttr = &g_VpuCoreAttributes[pCodecInst->coreIdx];
  3001. if (pAttr->supportCommandQueue == TRUE) {
  3002. EnterLock(pCodecInst->coreIdx);
  3003. }
  3004. else {
  3005. if (pCodecInst != GetPendingInst(pCodecInst->coreIdx)) {
  3006. SetPendingInst(pCodecInst->coreIdx, 0);
  3007. LeaveLock(pCodecInst->coreIdx);
  3008. return RETCODE_WRONG_CALL_SEQUENCE;
  3009. }
  3010. }
  3011. ret = ProductVpuEncGetSeqInfo(handle, info);
  3012. if (ret == RETCODE_SUCCESS) {
  3013. pEncInfo->initialInfoObtained = 1;
  3014. }
  3015. //info->rdPtr = VpuReadReg(pCodecInst->coreIdx, pEncInfo->streamRdPtrRegAddr);
  3016. //info->wrPtr = VpuReadReg(pCodecInst->coreIdx, pEncInfo->streamWrPtrRegAddr);
  3017. //pEncInfo->prevFrameEndPos = info->rdPtr;
  3018. pEncInfo->initialInfo = *info;
  3019. SetPendingInst(pCodecInst->coreIdx, NULL);
  3020. LeaveLock(pCodecInst->coreIdx);
  3021. return ret;
  3022. }