vpuapi.c 114 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567
  1. //SPDX-License-Identifier: LGPL-2.1 OR BSD-3-Clause
  2. /*
  3. * Copyright (c) 2019, Chips&Media
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  16. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  19. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  22. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include "vpuapifunc.h"
  27. #include "product.h"
  28. #include "wave/wave5_regdefine.h"
  29. #include "wave/wave5.h"
  30. #include "misc/debug.h"
  31. #define W5_RET_DEC_DISPLAY_SIZE (W5_REG_BASE + 0x01D8) // [FIX ME] delete ? or not?
  32. #define INVALID_CORE_INDEX_RETURN_ERROR(_coreIdx) \
  33. if (_coreIdx >= MAX_NUM_VPU_CORE) \
  34. return -1;
  35. static const Uint16* s_pusBitCode[MAX_NUM_VPU_CORE] = {NULL,};
  36. static int s_bitCodeSize[MAX_NUM_VPU_CORE] = {0,};
  37. Uint32 __VPU_BUSY_TIMEOUT = VPU_BUSY_CHECK_TIMEOUT;
  38. static RetCode CheckDecInstanceValidity(CodecInst* pCodecInst)
  39. {
  40. RetCode ret;
  41. if (pCodecInst == NULL)
  42. return RETCODE_INVALID_HANDLE;
  43. ret = CheckInstanceValidity(pCodecInst);
  44. if (ret != RETCODE_SUCCESS) {
  45. return RETCODE_INVALID_HANDLE;
  46. }
  47. if (!pCodecInst->inUse) {
  48. return RETCODE_INVALID_HANDLE;
  49. }
  50. return ProductVpuDecCheckCapability(pCodecInst);
  51. }
  52. Int32 VPU_IsInit(Uint32 coreIdx)
  53. {
  54. Int32 pc;
  55. INVALID_CORE_INDEX_RETURN_ERROR(coreIdx);
  56. pc = ProductVpuIsInit(coreIdx);
  57. return pc;
  58. }
  59. Int32 VPU_WaitInterrupt(Uint32 coreIdx, int timeout)
  60. {
  61. Int32 ret;
  62. CodecInst* instance;
  63. INVALID_CORE_INDEX_RETURN_ERROR(coreIdx);
  64. if ((instance=GetPendingInst(coreIdx)) != NULL) {
  65. ret = ProductVpuWaitInterrupt(instance, timeout);
  66. }
  67. else {
  68. ret = -1;
  69. }
  70. return ret;
  71. }
  72. Int32 VPU_WaitInterruptEx(VpuHandle handle, int timeout)
  73. {
  74. Int32 ret;
  75. CodecInst *pCodecInst;
  76. pCodecInst = handle;
  77. INVALID_CORE_INDEX_RETURN_ERROR(pCodecInst->coreIdx);
  78. ret = ProductVpuWaitInterrupt(pCodecInst, timeout);
  79. return ret;
  80. }
  81. void VPU_ClearInterrupt(Uint32 coreIdx)
  82. {
  83. /* clear all interrupt flags */
  84. ProductVpuClearInterrupt(coreIdx, 0xffff);
  85. }
  86. void VPU_ClearInterruptEx(VpuHandle handle, Int32 intrFlag)
  87. {
  88. CodecInst *pCodecInst;
  89. pCodecInst = handle;
  90. ProductVpuClearInterrupt(pCodecInst->coreIdx, intrFlag);
  91. }
  92. int VPU_GetFrameBufSize(VpuHandle handle, int coreIdx, int stride, int height, int mapType, int format, int interleave, DRAMConfig *pDramCfg)
  93. {
  94. int productId;
  95. CodecInst *pCodecInst;
  96. pCodecInst = handle;
  97. UNREFERENCED_PARAMETER(interleave); /*!<< for backward compatiblity */
  98. if (coreIdx < 0 || coreIdx >= MAX_NUM_VPU_CORE)
  99. return -1;
  100. productId = ProductVpuGetId(coreIdx);
  101. return ProductCalculateFrameBufSize(pCodecInst, productId, stride, height, (TiledMapType)mapType, (FrameBufferFormat)format, (BOOL)interleave, pDramCfg);
  102. }
  103. int VPU_GetProductId(int coreIdx)
  104. {
  105. Int32 productId;
  106. INVALID_CORE_INDEX_RETURN_ERROR(coreIdx);
  107. if ((productId=ProductVpuGetId(coreIdx)) != PRODUCT_ID_NONE) {
  108. return productId;
  109. }
  110. if (vdi_init(coreIdx) < 0)
  111. return -1;
  112. EnterLock(coreIdx);
  113. if (ProductVpuScan(coreIdx) == FALSE)
  114. productId = -1;
  115. else
  116. productId = ProductVpuGetId(coreIdx);
  117. LeaveLock((coreIdx));
  118. vdi_release(coreIdx);
  119. return productId;
  120. }
  121. int VPU_GetOpenInstanceNum(Uint32 coreIdx)
  122. {
  123. INVALID_CORE_INDEX_RETURN_ERROR(coreIdx);
  124. return vdi_get_instance_num(coreIdx);
  125. }
  126. static RetCode InitializeVPU(Uint32 coreIdx, const Uint16* code, Uint32 size)
  127. {
  128. RetCode ret;
  129. if (vdi_init(coreIdx) < 0)
  130. return RETCODE_FAILURE;
  131. EnterLock(coreIdx);
  132. if (vdi_get_instance_num(coreIdx) > 0) {
  133. if (ProductVpuScan(coreIdx) == 0) {
  134. LeaveLock(coreIdx);
  135. return RETCODE_NOT_FOUND_VPU_DEVICE;
  136. }
  137. }
  138. /* force to reset vpu, so that the vpu in a clean state */
  139. if (VPU_IsInit(coreIdx) != 0) {
  140. ProductVpuReInit(coreIdx, (void *)code, size);
  141. LeaveLock(coreIdx);
  142. return RETCODE_CALLED_BEFORE;
  143. }
  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. }