SF_OMX_Mjpeg_decoder.c 105 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2021 StarFive Technology Co., Ltd.
  4. */
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <unistd.h>
  8. #include <string.h>
  9. #include <sys/types.h>
  10. #include <unistd.h>
  11. #include "SF_OMX_mjpeg_common.h"
  12. #include "SF_OMX_Core.h"
  13. #include <sys/prctl.h>
  14. extern OMX_TICKS gInitTimeStamp;
  15. #define TEMP_DEBUG 1
  16. #define NUM_OF_PORTS 2
  17. #define DEC_StopThread OMX_CommandMax
  18. typedef struct DEC_CMD
  19. {
  20. OMX_COMMANDTYPE Cmd;
  21. OMX_U32 nParam;
  22. OMX_PTR pCmdData;
  23. }DEC_CMD;
  24. static OMX_ERRORTYPE SF_OMX_EmptyThisBuffer(
  25. OMX_IN OMX_HANDLETYPE hComponent,
  26. OMX_IN OMX_BUFFERHEADERTYPE *pBuffer)
  27. {
  28. OMX_ERRORTYPE ret = OMX_ErrorNone;
  29. FunctionIn();
  30. if (hComponent == NULL || pBuffer == NULL)
  31. {
  32. ret = OMX_ErrorBadParameter;
  33. goto EXIT;
  34. }
  35. OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
  36. SF_OMX_COMPONENT *pSfOMXComponent = (SF_OMX_COMPONENT *)pOMXComponent->pComponentPrivate;
  37. SF_CODAJ12_IMPLEMEMT *pSfCodaj12Implement = (SF_CODAJ12_IMPLEMEMT *)pSfOMXComponent->componentImpl;
  38. LOG(SF_LOG_DEBUG, "nFilledLen = %d, nFlags = %d, header = %p, pBuffer = %p\r\n", pBuffer->nFilledLen, pBuffer->nFlags, pBuffer, pBuffer->pBuffer);
  39. if (!pSfOMXComponent->portDefinition[OMX_INPUT_PORT_INDEX].bEnabled)
  40. {
  41. LOG(SF_LOG_INFO, "feed buffer when input port stop\r\n");
  42. return OMX_ErrorIncorrectStateOperation;
  43. }
  44. if (pBuffer->nInputPortIndex != OMX_INPUT_PORT_INDEX)
  45. {
  46. LOG(SF_LOG_INFO, "Incorrect nInputPortIndex %d\r\n", pBuffer->nInputPortIndex);
  47. return OMX_ErrorBadPortIndex;
  48. }
  49. Message data;
  50. data.msg_type = 1;
  51. data.msg_flag = 0;
  52. data.pBuffer = pBuffer;
  53. pSfOMXComponent->handlingBufferNum[OMX_INPUT_PORT_INDEX]++;
  54. if (msgsnd(pSfCodaj12Implement->sInputMessageQueue, (void *)&data, sizeof(data) - sizeof(data.msg_type), 0) == -1)
  55. {
  56. LOG(SF_LOG_ERR, "msgsnd failed\n");
  57. }
  58. EXIT:
  59. FunctionOut();
  60. return ret;
  61. }
  62. static OMX_ERRORTYPE SF_OMX_FillThisBuffer(
  63. OMX_IN OMX_HANDLETYPE hComponent,
  64. OMX_IN OMX_BUFFERHEADERTYPE *pBuffer)
  65. {
  66. OMX_ERRORTYPE ret = OMX_ErrorNone;
  67. FunctionIn();
  68. if (hComponent == NULL || pBuffer == NULL)
  69. {
  70. ret = OMX_ErrorBadParameter;
  71. goto EXIT;
  72. }
  73. OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
  74. SF_OMX_COMPONENT *pSfOMXComponent = (SF_OMX_COMPONENT *)pOMXComponent->pComponentPrivate;
  75. SF_CODAJ12_IMPLEMEMT *pSfCodaj12Implement = (SF_CODAJ12_IMPLEMEMT *)pSfOMXComponent->componentImpl;
  76. LOG(SF_LOG_DEBUG, "nFilledLen = %d, nFlags = %d, header = %p, pBuffer = %p\r\n", pBuffer->nFilledLen, pBuffer->nFlags, pBuffer, pBuffer->pBuffer);
  77. if (!pSfOMXComponent->portDefinition[OMX_OUTPUT_PORT_INDEX].bEnabled)
  78. {
  79. LOG(SF_LOG_INFO, "feed buffer when output port stop\r\n");
  80. return OMX_ErrorIncorrectStateOperation;
  81. }
  82. if (pBuffer->nOutputPortIndex != OMX_OUTPUT_PORT_INDEX)
  83. {
  84. LOG(SF_LOG_INFO, "Incorrect nOutputPortIndex %d\r\n", pBuffer->nOutputPortIndex);
  85. return OMX_ErrorBadPortIndex;
  86. }
  87. Message data;
  88. data.msg_type = 1;
  89. data.msg_flag = 0;
  90. data.pBuffer = pBuffer;
  91. pSfOMXComponent->handlingBufferNum[OMX_OUTPUT_PORT_INDEX]++;
  92. LOG(SF_LOG_DEBUG, "Send to message queue\r\n");
  93. if (msgsnd(pSfCodaj12Implement->sOutputMessageQueue, (void *)&data, sizeof(data) - sizeof(data.msg_type), 0) == -1)
  94. {
  95. LOG(SF_LOG_ERR, "msgsnd failed\n");
  96. }
  97. EXIT:
  98. FunctionOut();
  99. return ret;
  100. }
  101. static OMX_ERRORTYPE SF_OMX_UseBuffer(
  102. OMX_IN OMX_HANDLETYPE hComponent,
  103. OMX_INOUT OMX_BUFFERHEADERTYPE **ppBufferHdr,
  104. OMX_IN OMX_U32 nPortIndex,
  105. OMX_IN OMX_PTR pAppPrivate,
  106. OMX_IN OMX_U32 nSizeBytes,
  107. OMX_IN OMX_U8 *pBuffer)
  108. {
  109. OMX_ERRORTYPE ret = OMX_ErrorNone;
  110. OMX_BUFFERHEADERTYPE *temp_bufferHeader;
  111. SF_OMX_BUF_INFO *pBufInfo;
  112. OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
  113. SF_OMX_COMPONENT *pSfOMXComponent = pOMXComponent->pComponentPrivate;
  114. OMX_U32 i;
  115. FunctionIn();
  116. temp_bufferHeader = (OMX_BUFFERHEADERTYPE *)malloc(sizeof(OMX_BUFFERHEADERTYPE));
  117. if (temp_bufferHeader == NULL)
  118. {
  119. LOG(SF_LOG_ERR, "malloc fail\r\n");
  120. return OMX_ErrorInsufficientResources;
  121. }
  122. pBufInfo = (SF_OMX_BUF_INFO *)malloc(sizeof(SF_OMX_BUF_INFO));
  123. if (pBufInfo == NULL)
  124. {
  125. LOG(SF_LOG_ERR, "malloc fail\r\n");
  126. free(temp_bufferHeader);
  127. return OMX_ErrorInsufficientResources;
  128. }
  129. memset(temp_bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE));
  130. temp_bufferHeader->nAllocLen = nSizeBytes;
  131. temp_bufferHeader->pAppPrivate = pAppPrivate;
  132. temp_bufferHeader->pBuffer = pBuffer;
  133. temp_bufferHeader->nSize = sizeof(OMX_BUFFERHEADERTYPE);
  134. memcpy(&(temp_bufferHeader->nVersion), &(pSfOMXComponent->componentVersion), sizeof(OMX_VERSIONTYPE));
  135. if(nPortIndex == OMX_INPUT_PORT_INDEX)
  136. {
  137. for (i = 0; i < MAX_BUFF_NUM; i++)
  138. {
  139. if (!pSfOMXComponent->pBufferArray[OMX_INPUT_PORT_INDEX][i])
  140. {
  141. pBufInfo->type = SF_BUFFER_NOMAL_EXTERNAL;
  142. pBufInfo->index = i;
  143. temp_bufferHeader->pInputPortPrivate = (OMX_PTR)pBufInfo;
  144. temp_bufferHeader->nInputPortIndex = OMX_INPUT_PORT_INDEX;
  145. pSfOMXComponent->pBufferArray[OMX_INPUT_PORT_INDEX][i] = temp_bufferHeader;
  146. pSfOMXComponent->assignedBufferNum[OMX_INPUT_PORT_INDEX] ++;
  147. if (pSfOMXComponent->assignedBufferNum[OMX_INPUT_PORT_INDEX] ==
  148. pSfOMXComponent->portDefinition[OMX_INPUT_PORT_INDEX].nBufferCountActual)
  149. {
  150. pSfOMXComponent->portDefinition[OMX_INPUT_PORT_INDEX].bPopulated = OMX_TRUE;
  151. SF_SemaphorePost(pSfOMXComponent->portSemaphore[OMX_INPUT_PORT_INDEX]);
  152. }
  153. break;
  154. }
  155. }
  156. if (i == MAX_BUFF_NUM){
  157. LOG(SF_LOG_ERR, "buffer array full\r\n");
  158. free(temp_bufferHeader);
  159. free(pBufInfo);
  160. ret = OMX_ErrorInsufficientResources;
  161. }
  162. }
  163. else if(nPortIndex == OMX_OUTPUT_PORT_INDEX)
  164. {
  165. for (i = 0; i < MAX_BUFF_NUM; i++)
  166. {
  167. if (!pSfOMXComponent->pBufferArray[OMX_OUTPUT_PORT_INDEX][i])
  168. {
  169. if (pSfOMXComponent->memory_optimization)
  170. {
  171. if (AttachOutputBuffer(pSfOMXComponent, pBuffer, nSizeBytes) == OMX_FALSE)
  172. {
  173. LOG(SF_LOG_INFO, "Failed to attach dma buffer, no memory optimization\r\n");
  174. pSfOMXComponent->memory_optimization = OMX_FALSE;
  175. }
  176. }
  177. pBufInfo->type = SF_BUFFER_NOMAL_EXTERNAL;
  178. pBufInfo->index = i;
  179. temp_bufferHeader->pOutputPortPrivate = (OMX_PTR)pBufInfo;
  180. temp_bufferHeader->nOutputPortIndex = OMX_OUTPUT_PORT_INDEX;
  181. pSfOMXComponent->pBufferArray[OMX_OUTPUT_PORT_INDEX][i] = temp_bufferHeader;
  182. pSfOMXComponent->assignedBufferNum[OMX_OUTPUT_PORT_INDEX] ++;
  183. if (pSfOMXComponent->assignedBufferNum[OMX_OUTPUT_PORT_INDEX] ==
  184. pSfOMXComponent->portDefinition[OMX_OUTPUT_PORT_INDEX].nBufferCountActual)
  185. {
  186. pSfOMXComponent->portDefinition[OMX_OUTPUT_PORT_INDEX].bPopulated = OMX_TRUE;
  187. SF_SemaphorePost(pSfOMXComponent->portSemaphore[OMX_OUTPUT_PORT_INDEX]);
  188. }
  189. break;
  190. }
  191. }
  192. if (i == MAX_BUFF_NUM){
  193. LOG(SF_LOG_ERR, "buffer array full\r\n");
  194. free(temp_bufferHeader);
  195. free(pBufInfo);
  196. ret = OMX_ErrorInsufficientResources;
  197. }
  198. }
  199. *ppBufferHdr = temp_bufferHeader;
  200. FunctionOut();
  201. return ret;
  202. }
  203. static OMX_ERRORTYPE SF_OMX_AllocateBuffer(
  204. OMX_IN OMX_HANDLETYPE hComponent,
  205. OMX_INOUT OMX_BUFFERHEADERTYPE **ppBuffer,
  206. OMX_IN OMX_U32 nPortIndex,
  207. OMX_IN OMX_PTR pAppPrivate,
  208. OMX_IN OMX_U32 nSizeBytes)
  209. {
  210. OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
  211. SF_OMX_COMPONENT *pSfOMXComponent = pOMXComponent->pComponentPrivate;
  212. OMX_ERRORTYPE ret = OMX_ErrorNone;
  213. OMX_BUFFERHEADERTYPE *temp_bufferHeader;
  214. SF_OMX_BUF_INFO *pBufInfo;
  215. OMX_U32 i;
  216. FunctionIn();
  217. if (nSizeBytes == 0)
  218. {
  219. LOG(SF_LOG_ERR, "nSizeBytes = %d\r\n", nSizeBytes);
  220. return OMX_ErrorBadParameter;
  221. }
  222. temp_bufferHeader = (OMX_BUFFERHEADERTYPE *)malloc(sizeof(OMX_BUFFERHEADERTYPE));
  223. if (temp_bufferHeader == NULL)
  224. {
  225. LOG(SF_LOG_ERR, "malloc fail\r\n");
  226. return OMX_ErrorInsufficientResources;
  227. }
  228. memset(temp_bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE));
  229. pBufInfo = (SF_OMX_BUF_INFO *)malloc(sizeof(SF_OMX_BUF_INFO));
  230. if (pBufInfo == NULL)
  231. {
  232. LOG(SF_LOG_ERR, "malloc fail\r\n");
  233. free(temp_bufferHeader);
  234. return OMX_ErrorInsufficientResources;
  235. }
  236. temp_bufferHeader->nAllocLen = nSizeBytes;
  237. temp_bufferHeader->pAppPrivate = pAppPrivate;
  238. temp_bufferHeader->nSize = sizeof(OMX_BUFFERHEADERTYPE);
  239. memcpy(&(temp_bufferHeader->nVersion), &(pSfOMXComponent->componentVersion), sizeof(OMX_VERSIONTYPE));
  240. if (nPortIndex == OMX_OUTPUT_PORT_INDEX)
  241. {
  242. for (i = 0; i < MAX_BUFF_NUM; i++)
  243. {
  244. if (!pSfOMXComponent->pBufferArray[OMX_OUTPUT_PORT_INDEX][i])
  245. {
  246. if (pSfOMXComponent->memory_optimization)
  247. {
  248. temp_bufferHeader->pBuffer = AllocateOutputBuffer(pSfOMXComponent, i, nSizeBytes);
  249. }
  250. if (temp_bufferHeader->pBuffer == NULL)
  251. {
  252. temp_bufferHeader->pBuffer = malloc(nSizeBytes);
  253. memset(temp_bufferHeader->pBuffer, 0, nSizeBytes);
  254. pBufInfo->type = SF_BUFFER_NOMAL;
  255. LOG(SF_LOG_PERF, "Use normal buffer\r\n");
  256. }
  257. else
  258. {
  259. pBufInfo->type = SF_BUFFER_DMA;
  260. LOG(SF_LOG_PERF, "Use DMA buffer\r\n");
  261. }
  262. temp_bufferHeader->nOutputPortIndex = OMX_OUTPUT_PORT_INDEX;
  263. pBufInfo->index = i;
  264. temp_bufferHeader->pOutputPortPrivate = (void*)pBufInfo;
  265. pSfOMXComponent->pBufferArray[OMX_OUTPUT_PORT_INDEX][i] = temp_bufferHeader;
  266. pSfOMXComponent->assignedBufferNum[OMX_OUTPUT_PORT_INDEX]++;
  267. if (pSfOMXComponent->assignedBufferNum[OMX_OUTPUT_PORT_INDEX] ==
  268. pSfOMXComponent->portDefinition[OMX_OUTPUT_PORT_INDEX].nBufferCountActual)
  269. {
  270. pSfOMXComponent->portDefinition[OMX_OUTPUT_PORT_INDEX].bPopulated = OMX_TRUE;
  271. SF_SemaphorePost(pSfOMXComponent->portSemaphore[OMX_OUTPUT_PORT_INDEX]);
  272. }
  273. break;
  274. }
  275. }
  276. if (i == MAX_BUFF_NUM){
  277. LOG(SF_LOG_ERR, "buffer array full\r\n");
  278. temp_bufferHeader->pBuffer = NULL;
  279. }
  280. }
  281. else if (nPortIndex == OMX_INPUT_PORT_INDEX)
  282. {
  283. for (i = 0; i < MAX_BUFF_NUM; i++)
  284. {
  285. if (!pSfOMXComponent->pBufferArray[OMX_INPUT_PORT_INDEX][i])
  286. {
  287. temp_bufferHeader->pBuffer = malloc(nSizeBytes);
  288. memset(temp_bufferHeader->pBuffer, 0, nSizeBytes);
  289. temp_bufferHeader->nInputPortIndex = OMX_INPUT_PORT_INDEX;
  290. pBufInfo->type = SF_BUFFER_NOMAL;
  291. pBufInfo->index = i;
  292. temp_bufferHeader->pInputPortPrivate = (void*)pBufInfo;
  293. LOG(SF_LOG_PERF, "alloc normal intput buffer %d \r\n", i);
  294. pSfOMXComponent->pBufferArray[OMX_INPUT_PORT_INDEX][i] = temp_bufferHeader;
  295. pSfOMXComponent->assignedBufferNum[OMX_INPUT_PORT_INDEX]++;
  296. if (pSfOMXComponent->assignedBufferNum[OMX_INPUT_PORT_INDEX] ==
  297. pSfOMXComponent->portDefinition[OMX_INPUT_PORT_INDEX].nBufferCountActual)
  298. {
  299. pSfOMXComponent->portDefinition[OMX_INPUT_PORT_INDEX].bPopulated = OMX_TRUE;
  300. SF_SemaphorePost(pSfOMXComponent->portSemaphore[OMX_INPUT_PORT_INDEX]);
  301. }
  302. break;
  303. }
  304. }
  305. if (i == MAX_BUFF_NUM){
  306. LOG(SF_LOG_ERR, "buffer array full\r\n");
  307. temp_bufferHeader->pBuffer = NULL;
  308. }
  309. }
  310. if (temp_bufferHeader->pBuffer == NULL)
  311. {
  312. free(pBufInfo);
  313. free(temp_bufferHeader);
  314. LOG(SF_LOG_ERR, "malloc fail\r\n");
  315. return OMX_ErrorInsufficientResources;
  316. }
  317. *ppBuffer = temp_bufferHeader;
  318. LOG(SF_LOG_INFO, "nPortIndex = %d, buffheader %p Buffer address = %p, nFilledLen = %d, nSizeBytes = %d\r\n",
  319. nPortIndex, temp_bufferHeader, temp_bufferHeader->pBuffer, temp_bufferHeader->nFilledLen, nSizeBytes);
  320. FunctionOut();
  321. return ret;
  322. }
  323. static OMX_ERRORTYPE SF_OMX_GetParameter(
  324. OMX_IN OMX_HANDLETYPE hComponent,
  325. OMX_IN OMX_INDEXTYPE nParamIndex,
  326. OMX_INOUT OMX_PTR ComponentParameterStructure)
  327. {
  328. OMX_ERRORTYPE ret = OMX_ErrorNone;
  329. OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
  330. SF_OMX_COMPONENT *pSfOMXComponent = pOMXComponent->pComponentPrivate;
  331. OMX_PARAM_PORTDEFINITIONTYPE *pOutputPort = &pSfOMXComponent->portDefinition[OMX_OUTPUT_PORT_INDEX];
  332. FunctionIn();
  333. if (hComponent == NULL || ComponentParameterStructure == NULL)
  334. {
  335. ret = OMX_ErrorBadParameter;
  336. goto EXIT;
  337. }
  338. LOG(SF_LOG_INFO, "Get parameter on index %X\r\n", nParamIndex);
  339. switch ((OMX_U32)nParamIndex)
  340. {
  341. case OMX_IndexParamVideoInit:
  342. {
  343. OMX_PORT_PARAM_TYPE *portParam = (OMX_PORT_PARAM_TYPE *)ComponentParameterStructure;
  344. portParam->nPorts = OMX_PORT_MAX;
  345. portParam->nStartPortNumber = OMX_INPUT_PORT_INDEX;
  346. break;
  347. }
  348. case OMX_IndexParamAudioInit:
  349. case OMX_IndexParamImageInit:
  350. case OMX_IndexParamOtherInit:
  351. {
  352. OMX_PORT_PARAM_TYPE *portParam = (OMX_PORT_PARAM_TYPE *)ComponentParameterStructure;
  353. portParam->nPorts = 0;
  354. portParam->nStartPortNumber = 0;
  355. break;
  356. }
  357. case OMX_IndexParamVideoPortFormat:
  358. {
  359. OMX_VIDEO_PARAM_PORTFORMATTYPE *portFormat = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)ComponentParameterStructure;
  360. OMX_U32 index = portFormat->nIndex;
  361. OMX_PARAM_PORTDEFINITIONTYPE *pPortDefinition;
  362. LOG(SF_LOG_DEBUG, "Get video format at port %d index %d\r\n",portFormat->nPortIndex, index);
  363. if (portFormat->nPortIndex >= OMX_PORT_MAX)
  364. {
  365. ret = OMX_ErrorBadPortIndex;
  366. break;
  367. }
  368. if (portFormat->nPortIndex == OMX_INPUT_PORT_INDEX)
  369. {
  370. if (index >= INPUT_PORT_SUPPORTFORMAT_NUM_MAX)
  371. {
  372. ret = OMX_ErrorNoMore;
  373. break;
  374. }
  375. pPortDefinition = &pSfOMXComponent->portDefinition[OMX_INPUT_PORT_INDEX];
  376. portFormat->eCompressionFormat = pPortDefinition->format.video.eCompressionFormat;
  377. portFormat->eColorFormat = pPortDefinition->format.video.eColorFormat;
  378. portFormat->xFramerate = pPortDefinition->format.video.xFramerate;
  379. }
  380. else if (portFormat->nPortIndex == OMX_OUTPUT_PORT_INDEX)
  381. {
  382. pPortDefinition = &pSfOMXComponent->portDefinition[OMX_OUTPUT_PORT_INDEX];
  383. switch (index)
  384. {
  385. case 0:
  386. portFormat->eColorFormat = OMX_COLOR_FormatYUV420Planar;
  387. break;
  388. case 1:
  389. portFormat->eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
  390. break;
  391. case 2:
  392. portFormat->eColorFormat = OMX_COLOR_FormatYVU420SemiPlanar;
  393. break;
  394. case 3:
  395. portFormat->eColorFormat = OMX_COLOR_FormatYUV422Planar;
  396. break;
  397. case 4:
  398. portFormat->eColorFormat = OMX_COLOR_FormatYUV422SemiPlanar;
  399. break;
  400. case 5:
  401. portFormat->eColorFormat = OMX_COLOR_FormatYVU422SemiPlanar;
  402. break;
  403. case 6:
  404. portFormat->eColorFormat = OMX_COLOR_FormatYCbYCr;
  405. break;
  406. case 7:
  407. portFormat->eColorFormat = OMX_COLOR_FormatYCrYCb;
  408. break;
  409. case 8:
  410. portFormat->eColorFormat = OMX_COLOR_FormatCbYCrY;
  411. break;
  412. case 9:
  413. portFormat->eColorFormat = OMX_COLOR_FormatCrYCbY;
  414. break;
  415. case 10:
  416. portFormat->eColorFormat = OMX_COLOR_FormatYUV444Planar;
  417. break;
  418. case 11:
  419. portFormat->eColorFormat = OMX_COLOR_FormatYUV444Interleaved;
  420. break;
  421. default:
  422. ret = OMX_ErrorNoMore;
  423. }
  424. if (ret == OMX_ErrorNone)
  425. {
  426. portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused;
  427. portFormat->xFramerate = pPortDefinition->format.video.xFramerate;
  428. }
  429. }
  430. break;
  431. }
  432. case OMX_IndexParamVideoBitrate:
  433. {
  434. OMX_VIDEO_PARAM_BITRATETYPE *videoRateControl = (OMX_VIDEO_PARAM_BITRATETYPE *)ComponentParameterStructure;
  435. OMX_U32 portIndex = videoRateControl->nPortIndex;
  436. if ((portIndex != OMX_OUTPUT_PORT_INDEX)) {
  437. ret = OMX_ErrorBadPortIndex;
  438. goto EXIT;
  439. }
  440. else
  441. {
  442. videoRateControl->nTargetBitrate = pOutputPort->format.video.nBitrate;
  443. }
  444. LOG(SF_LOG_INFO, "Get nTargetBitrate = %u on port %d\r\n",videoRateControl->nTargetBitrate, videoRateControl->nPortIndex);
  445. break;
  446. }
  447. case OMX_IndexParamVideoQuantization:
  448. break;
  449. case OMX_IndexParamPortDefinition:
  450. {
  451. OMX_PARAM_PORTDEFINITIONTYPE *pPortDefinition = (OMX_PARAM_PORTDEFINITIONTYPE *)ComponentParameterStructure;
  452. OMX_U32 portIndex = pPortDefinition->nPortIndex;
  453. OMX_PARAM_PORTDEFINITIONTYPE *pSrcDefinition;
  454. if (portIndex < OMX_PORT_MAX)
  455. {
  456. pSrcDefinition = &pSfOMXComponent->portDefinition[portIndex];
  457. LOG(SF_LOG_DEBUG, "Get parameter port %X\r\n",portIndex);
  458. LOG_APPEND(SF_LOG_DEBUG, "width = %d, height = %d\r\n", pSrcDefinition->format.video.nFrameWidth, pSrcDefinition->format.video.nFrameHeight);
  459. LOG_APPEND(SF_LOG_DEBUG, "eColorFormat = %d\r\n", pSrcDefinition->format.video.eColorFormat);
  460. LOG_APPEND(SF_LOG_DEBUG, "xFramerate = %d\r\n", pSrcDefinition->format.video.xFramerate);
  461. LOG_APPEND(SF_LOG_DEBUG, "bufferSize = %d\r\n",pSrcDefinition->nBufferSize);
  462. LOG_APPEND(SF_LOG_DEBUG, "Buffer count = %d\r\n", pSrcDefinition->nBufferCountActual);
  463. memcpy(pPortDefinition, pSrcDefinition, pPortDefinition->nSize);
  464. }
  465. else
  466. {
  467. LOG(SF_LOG_INFO,"Bad port index %d\r\n",portIndex);
  468. ret = OMX_ErrorBadPortIndex;
  469. }
  470. break;
  471. }
  472. case OMX_IndexParamVideoIntraRefresh:
  473. break;
  474. case OMX_IndexParamStandardComponentRole:
  475. {
  476. OMX_PARAM_COMPONENTROLETYPE *pComponentRole = (OMX_PARAM_COMPONENTROLETYPE *)ComponentParameterStructure;
  477. strcpy((OMX_STRING)(pComponentRole->cRole), pSfOMXComponent->componentRule);
  478. break;
  479. }
  480. case OMX_IndexParamCompBufferSupplier:
  481. {
  482. OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplier = (OMX_PARAM_BUFFERSUPPLIERTYPE *)ComponentParameterStructure;
  483. OMX_U32 portIndex = bufferSupplier->nPortIndex;
  484. if (portIndex >= OMX_PORT_MAX)
  485. ret = OMX_ErrorBadPortIndex;
  486. break;
  487. }
  488. case OMX_IndexParamImagePortFormat:
  489. {
  490. OMX_IMAGE_PARAM_PORTFORMATTYPE *portFormat = (OMX_IMAGE_PARAM_PORTFORMATTYPE *)ComponentParameterStructure;
  491. OMX_U32 index = portFormat->nIndex;
  492. if (index < OMX_PORT_MAX)
  493. {
  494. portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused;
  495. portFormat->eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
  496. }
  497. else
  498. {
  499. LOG(SF_LOG_INFO,"Bad port index %d\r\n",index);
  500. ret = OMX_ErrorBadPortIndex;
  501. }
  502. break;
  503. }
  504. default:
  505. {
  506. ret = OMX_ErrorUnsupportedIndex;
  507. break;
  508. }
  509. }
  510. EXIT:
  511. FunctionOut();
  512. return ret;
  513. }
  514. static OMX_ERRORTYPE SF_OMX_SetParameter(
  515. OMX_IN OMX_HANDLETYPE hComponent,
  516. OMX_IN OMX_INDEXTYPE nIndex,
  517. OMX_IN OMX_PTR ComponentParameterStructure)
  518. {
  519. OMX_ERRORTYPE ret = OMX_ErrorNone;
  520. FunctionIn();
  521. if (hComponent == NULL)
  522. {
  523. ret = OMX_ErrorBadParameter;
  524. goto EXIT;
  525. }
  526. if (ComponentParameterStructure == NULL)
  527. {
  528. ret = OMX_ErrorBadParameter;
  529. goto EXIT;
  530. }
  531. LOG(SF_LOG_INFO, "Set parameter on index %X\r\n", nIndex);
  532. OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
  533. SF_OMX_COMPONENT *pSfOMXComponent = pOMXComponent->pComponentPrivate;
  534. SF_CODAJ12_IMPLEMEMT *pSfMjpegImplement = (SF_CODAJ12_IMPLEMEMT *)pSfOMXComponent->componentImpl;
  535. if (pSfOMXComponent == NULL)
  536. {
  537. ret = OMX_ErrorBadParameter;
  538. goto EXIT;
  539. }
  540. switch ((OMX_U32)nIndex)
  541. {
  542. case OMX_IndexParamPortDefinition:
  543. {
  544. OMX_PARAM_PORTDEFINITIONTYPE *pPortDefinition =
  545. (OMX_PARAM_PORTDEFINITIONTYPE *)ComponentParameterStructure;
  546. OMX_PARAM_PORTDEFINITIONTYPE *pInputPort = &pSfOMXComponent->portDefinition[0];
  547. OMX_PARAM_PORTDEFINITIONTYPE *pOutputPort = &pSfOMXComponent->portDefinition[1];
  548. DecConfigParam *decConfig = pSfMjpegImplement->config;
  549. OMX_U32 portIndex = pPortDefinition->nPortIndex;
  550. OMX_U32 width = pPortDefinition->format.video.nFrameWidth;
  551. OMX_U32 height = pPortDefinition->format.video.nFrameHeight;
  552. LOG(SF_LOG_INFO, "Set parameter on port %d\r\n", pPortDefinition->nPortIndex);
  553. LOG_APPEND(SF_LOG_DEBUG, "width = %d, height = %d\r\n",width, height);
  554. LOG_APPEND(SF_LOG_DEBUG, "eColorFormat = %d\r\n", pPortDefinition->format.video.eColorFormat);
  555. LOG_APPEND(SF_LOG_DEBUG, "xFramerate = %d\r\n", pPortDefinition->format.video.xFramerate);
  556. LOG_APPEND(SF_LOG_DEBUG, "bufferSize = %d\r\n",pPortDefinition->nBufferSize);
  557. LOG_APPEND(SF_LOG_DEBUG, "Buffer count = %d\r\n", pPortDefinition->nBufferCountActual);
  558. if (portIndex == (OMX_U32)OMX_INPUT_PORT_INDEX)
  559. {
  560. memcpy(&pSfOMXComponent->portDefinition[portIndex], pPortDefinition, pPortDefinition->nSize);
  561. pInputPort->format.video.nStride = width;
  562. pInputPort->format.video.nSliceHeight = height;
  563. pInputPort->nBufferSize = width * height * 2;
  564. }
  565. else if (portIndex == (OMX_U32)(OMX_OUTPUT_PORT_INDEX))
  566. {
  567. memcpy(&pSfOMXComponent->portDefinition[portIndex], pPortDefinition, pPortDefinition->nSize);
  568. /*
  569. Some client may set '0' or '1' to output port, in this case use input port parameters
  570. */
  571. if (width <= 1)
  572. {
  573. width = pInputPort->format.video.nFrameWidth;
  574. }
  575. if (height <= 1)
  576. {
  577. height = pInputPort->format.video.nFrameHeight;
  578. }
  579. if (width > 0 && height > 0)
  580. {
  581. int scalew = pInputPort->format.video.nFrameWidth / width;
  582. int scaleh = pInputPort->format.video.nFrameHeight / height;
  583. if (scalew > 8 || scaleh > 8 || scalew < 1 || scaleh < 1)
  584. {
  585. int nInputWidth = pInputPort->format.video.nFrameWidth;
  586. int nInputHeight = pInputPort->format.video.nFrameHeight;
  587. LOG(SF_LOG_WARN, "Scaling should be 1 to 1/8 (down-scaling only)! Use input parameter. "
  588. "OutPut[%d, %d]. Input[%d, %d]\r\n",
  589. width, height, nInputWidth, nInputHeight);
  590. width = nInputWidth;
  591. height = nInputHeight;
  592. }
  593. pOutputPort->format.video.nFrameWidth = width;
  594. pOutputPort->format.video.nFrameHeight = height;
  595. pOutputPort->format.video.nStride = width;
  596. pOutputPort->format.video.nSliceHeight = height;
  597. switch (pOutputPort->format.video.eColorFormat)
  598. {
  599. case OMX_COLOR_FormatYUV420Planar:
  600. decConfig->cbcrInterleave = CBCR_SEPARATED;
  601. decConfig->packedFormat = PACKED_FORMAT_NONE;
  602. pSfMjpegImplement->frameFormat = FORMAT_420;
  603. pOutputPort->nBufferSize = (width * height * 3) / 2;
  604. break;
  605. case OMX_COLOR_FormatYUV420SemiPlanar: //NV12
  606. decConfig->cbcrInterleave = CBCR_INTERLEAVE;
  607. decConfig->packedFormat = PACKED_FORMAT_NONE;
  608. pSfMjpegImplement->frameFormat = FORMAT_420;
  609. pOutputPort->nBufferSize = (width * height * 3) / 2;
  610. break;
  611. case OMX_COLOR_FormatYVU420SemiPlanar: //NV21
  612. decConfig->cbcrInterleave = CRCB_INTERLEAVE;
  613. decConfig->packedFormat = PACKED_FORMAT_NONE;
  614. pSfMjpegImplement->frameFormat = FORMAT_420;
  615. pOutputPort->nBufferSize = (width * height * 3) / 2;
  616. break;
  617. case OMX_COLOR_FormatYUV422Planar:
  618. decConfig->cbcrInterleave = CBCR_SEPARATED;
  619. decConfig->packedFormat = PACKED_FORMAT_NONE;
  620. pSfMjpegImplement->frameFormat = FORMAT_422;
  621. pOutputPort->nBufferSize = width * height * 2;
  622. break;
  623. case OMX_COLOR_FormatYUV422SemiPlanar: //NV16
  624. decConfig->cbcrInterleave = CBCR_INTERLEAVE;
  625. decConfig->packedFormat = PACKED_FORMAT_NONE;
  626. pSfMjpegImplement->frameFormat = FORMAT_422;
  627. pOutputPort->nBufferSize = width * height * 2;
  628. break;
  629. case OMX_COLOR_FormatYVU422SemiPlanar: //NV61
  630. decConfig->cbcrInterleave = CRCB_INTERLEAVE;
  631. decConfig->packedFormat = PACKED_FORMAT_NONE;
  632. pSfMjpegImplement->frameFormat = FORMAT_422;
  633. pOutputPort->nBufferSize = width * height * 2;
  634. break;
  635. case OMX_COLOR_FormatYCbYCr: //YUYV
  636. decConfig->cbcrInterleave = CBCR_SEPARATED;
  637. decConfig->packedFormat = PACKED_FORMAT_422_YUYV;
  638. pSfMjpegImplement->frameFormat = FORMAT_422;
  639. pOutputPort->nBufferSize = width * height * 2;
  640. break;
  641. case OMX_COLOR_FormatYCrYCb: //YVYU
  642. decConfig->cbcrInterleave = CBCR_SEPARATED;
  643. decConfig->packedFormat = PACKED_FORMAT_422_YVYU;
  644. pSfMjpegImplement->frameFormat = FORMAT_422;
  645. pOutputPort->nBufferSize = width * height * 2;
  646. break;
  647. case OMX_COLOR_FormatCbYCrY: //UYVY
  648. decConfig->cbcrInterleave = CBCR_SEPARATED;
  649. decConfig->packedFormat = PACKED_FORMAT_422_UYVY;
  650. pSfMjpegImplement->frameFormat = FORMAT_422;
  651. pOutputPort->nBufferSize = width * height * 2;
  652. break;
  653. case OMX_COLOR_FormatCrYCbY: //VYUY
  654. decConfig->cbcrInterleave = CBCR_SEPARATED;
  655. decConfig->packedFormat = PACKED_FORMAT_422_VYUY;
  656. pSfMjpegImplement->frameFormat = FORMAT_422;
  657. pOutputPort->nBufferSize = width * height * 2;
  658. break;
  659. case OMX_COLOR_FormatYUV444Planar: //I444
  660. decConfig->cbcrInterleave = CBCR_SEPARATED;
  661. decConfig->packedFormat = PACKED_FORMAT_NONE;
  662. pSfMjpegImplement->frameFormat = FORMAT_444;
  663. pOutputPort->nBufferSize = width * height * 3;
  664. break;
  665. case OMX_COLOR_FormatYUV444Interleaved: //YUV444PACKED
  666. decConfig->cbcrInterleave = CBCR_SEPARATED;
  667. decConfig->packedFormat = PACKED_FORMAT_444;
  668. pSfMjpegImplement->frameFormat = FORMAT_444;
  669. pOutputPort->nBufferSize = width * height * 3;
  670. break;
  671. default:
  672. pOutputPort->nBufferSize = width * height * 4;
  673. break;
  674. }
  675. }
  676. }
  677. else
  678. {
  679. LOG(SF_LOG_INFO,"Bad port index %d\r\n",portIndex);
  680. ret = OMX_ErrorBadPortIndex;
  681. }
  682. break;
  683. }
  684. case OMX_IndexParamVideoPortFormat:
  685. {
  686. OMX_VIDEO_PARAM_PORTFORMATTYPE *portFormat = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)ComponentParameterStructure;
  687. OMX_PARAM_PORTDEFINITIONTYPE *pPort;
  688. DecConfigParam *decConfig = pSfMjpegImplement->config;
  689. LOG(SF_LOG_DEBUG, "Set video format to port %d color %d\r\n", portFormat->nPortIndex, portFormat->eColorFormat);
  690. if (portFormat->nPortIndex >= OMX_PORT_MAX)
  691. {
  692. ret = OMX_ErrorBadPortIndex;
  693. break;
  694. }
  695. if (portFormat->nPortIndex == OMX_INPUT_PORT_INDEX)
  696. {
  697. pPort = &pSfOMXComponent->portDefinition[OMX_INPUT_PORT_INDEX];
  698. pPort->format.video.xFramerate = portFormat->xFramerate;
  699. }
  700. else if (portFormat->nPortIndex == OMX_OUTPUT_PORT_INDEX)
  701. {
  702. pPort = &pSfOMXComponent->portDefinition[OMX_OUTPUT_PORT_INDEX];
  703. switch (portFormat->eColorFormat)
  704. {
  705. case OMX_COLOR_FormatYUV420Planar:
  706. decConfig->cbcrInterleave = CBCR_SEPARATED;
  707. decConfig->packedFormat = PACKED_FORMAT_NONE;
  708. pSfMjpegImplement->frameFormat = FORMAT_420;
  709. break;
  710. case OMX_COLOR_FormatYUV420SemiPlanar: //NV12
  711. decConfig->cbcrInterleave = CBCR_INTERLEAVE;
  712. decConfig->packedFormat = PACKED_FORMAT_NONE;
  713. pSfMjpegImplement->frameFormat = FORMAT_420;
  714. break;
  715. case OMX_COLOR_FormatYVU420SemiPlanar: //NV21
  716. decConfig->cbcrInterleave = CRCB_INTERLEAVE;
  717. decConfig->packedFormat = PACKED_FORMAT_NONE;
  718. pSfMjpegImplement->frameFormat = FORMAT_420;
  719. break;
  720. case OMX_COLOR_FormatYUV422Planar:
  721. decConfig->cbcrInterleave = CBCR_SEPARATED;
  722. decConfig->packedFormat = PACKED_FORMAT_NONE;
  723. pSfMjpegImplement->frameFormat = FORMAT_422;
  724. break;
  725. case OMX_COLOR_FormatYUV422SemiPlanar: //NV16
  726. decConfig->cbcrInterleave = CBCR_INTERLEAVE;
  727. decConfig->packedFormat = PACKED_FORMAT_NONE;
  728. pSfMjpegImplement->frameFormat = FORMAT_422;
  729. break;
  730. case OMX_COLOR_FormatYVU422SemiPlanar: //NV61
  731. decConfig->cbcrInterleave = CRCB_INTERLEAVE;
  732. decConfig->packedFormat = PACKED_FORMAT_NONE;
  733. pSfMjpegImplement->frameFormat = FORMAT_422;
  734. break;
  735. case OMX_COLOR_FormatYCbYCr: //YUYV
  736. decConfig->cbcrInterleave = CBCR_SEPARATED;
  737. decConfig->packedFormat = PACKED_FORMAT_422_YUYV;
  738. pSfMjpegImplement->frameFormat = FORMAT_422;
  739. break;
  740. case OMX_COLOR_FormatYCrYCb: //YVYU
  741. decConfig->cbcrInterleave = CBCR_SEPARATED;
  742. decConfig->packedFormat = PACKED_FORMAT_422_YVYU;
  743. pSfMjpegImplement->frameFormat = FORMAT_422;
  744. break;
  745. case OMX_COLOR_FormatCbYCrY: //UYVY
  746. decConfig->cbcrInterleave = CBCR_SEPARATED;
  747. decConfig->packedFormat = PACKED_FORMAT_422_UYVY;
  748. pSfMjpegImplement->frameFormat = FORMAT_422;
  749. break;
  750. case OMX_COLOR_FormatCrYCbY: //VYUY
  751. decConfig->cbcrInterleave = CBCR_SEPARATED;
  752. decConfig->packedFormat = PACKED_FORMAT_422_VYUY;
  753. pSfMjpegImplement->frameFormat = FORMAT_422;
  754. break;
  755. case OMX_COLOR_FormatYUV444Planar: //I444
  756. decConfig->cbcrInterleave = CBCR_SEPARATED;
  757. decConfig->packedFormat = PACKED_FORMAT_NONE;
  758. pSfMjpegImplement->frameFormat = FORMAT_444;
  759. break;
  760. case OMX_COLOR_FormatYUV444Interleaved: //YUV444PACKED
  761. decConfig->cbcrInterleave = CBCR_SEPARATED;
  762. decConfig->packedFormat = PACKED_FORMAT_444;
  763. pSfMjpegImplement->frameFormat = FORMAT_444;
  764. break;
  765. default:
  766. ret = OMX_ErrorNotImplemented;
  767. break;
  768. }
  769. if(ret == OMX_ErrorNone)
  770. {
  771. pPort->format.video.eColorFormat = portFormat->eColorFormat;
  772. pPort->format.video.xFramerate = portFormat->xFramerate;
  773. }
  774. }
  775. break;
  776. }
  777. case OMX_IndexParamVideoInit:
  778. {
  779. OMX_PORT_PARAM_TYPE *portParam = (OMX_PORT_PARAM_TYPE *)ComponentParameterStructure;
  780. portParam->nPorts = 2;
  781. portParam->nStartPortNumber = 0;
  782. break;
  783. }
  784. case OMX_IndexParamImagePortFormat:
  785. break;
  786. case OMX_IndexParamStandardComponentRole:
  787. {
  788. if ((pSfOMXComponent->state != OMX_StateLoaded) &&
  789. (pSfOMXComponent->state != OMX_StateWaitForResources)) {
  790. ret = OMX_ErrorIncorrectStateOperation;
  791. }
  792. break;
  793. }
  794. case OMX_IndexParamCompBufferSupplier:
  795. {
  796. OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplier = (OMX_PARAM_BUFFERSUPPLIERTYPE *)ComponentParameterStructure;
  797. OMX_U32 portIndex = bufferSupplier->nPortIndex;
  798. if (portIndex >= OMX_PORT_MAX)
  799. ret = OMX_ErrorBadPortIndex;
  800. break;
  801. }
  802. default:
  803. ret = OMX_ErrorUnsupportedIndex;
  804. break;
  805. }
  806. EXIT:
  807. FunctionOut();
  808. return ret;
  809. }
  810. static OMX_ERRORTYPE SF_OMX_GetConfig(
  811. OMX_HANDLETYPE hComponent,
  812. OMX_INDEXTYPE nIndex,
  813. OMX_PTR pComponentConfigStructure)
  814. {
  815. OMX_ERRORTYPE ret = OMX_ErrorNone;
  816. FunctionIn();
  817. if (hComponent == NULL)
  818. {
  819. ret = OMX_ErrorBadParameter;
  820. goto EXIT;
  821. }
  822. if (pComponentConfigStructure == NULL)
  823. {
  824. ret = OMX_ErrorBadParameter;
  825. goto EXIT;
  826. }
  827. LOG(SF_LOG_INFO, "Get config on index %X\r\n", nIndex);
  828. OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
  829. SF_OMX_COMPONENT *pSfOMXComponent = pOMXComponent->pComponentPrivate;
  830. SF_CODAJ12_IMPLEMEMT *pSfMjpegImplement = (SF_CODAJ12_IMPLEMEMT *)pSfOMXComponent->componentImpl;
  831. switch ((OMX_U32)nIndex)
  832. {
  833. case OMX_IndexConfigCommonOutputCrop:
  834. {
  835. OMX_CONFIG_RECTTYPE *rectParam = (OMX_CONFIG_RECTTYPE *)pComponentConfigStructure;
  836. DecConfigParam *decConfig = pSfMjpegImplement->config;
  837. if(rectParam->nPortIndex == (OMX_U32)(OMX_OUTPUT_PORT_INDEX))
  838. {
  839. rectParam->nLeft = decConfig->roiOffsetX;
  840. rectParam->nTop = decConfig->roiOffsetY;
  841. rectParam->nWidth = decConfig->roiWidth;
  842. rectParam->nHeight = decConfig->roiHeight;
  843. LOG(SF_LOG_INFO, "Get OutputCrop left %d top %d width %d height %d \r\n",
  844. decConfig->roiOffsetX, decConfig->roiOffsetY, decConfig->roiWidth, decConfig->roiHeight);
  845. }
  846. else
  847. {
  848. LOG(SF_LOG_WARN, "Only output port support OutputCrop param\r\n");
  849. ret = OMX_ErrorBadParameter;
  850. }
  851. break;
  852. }
  853. case OMX_IndexConfigCommonRotate:
  854. {
  855. OMX_CONFIG_ROTATIONTYPE *rotatParam = (OMX_CONFIG_ROTATIONTYPE *)pComponentConfigStructure;
  856. DecConfigParam *decConfig = pSfMjpegImplement->config;
  857. if(rotatParam->nPortIndex == (OMX_U32)(OMX_OUTPUT_PORT_INDEX))
  858. {
  859. rotatParam->nRotation = decConfig->rotation;
  860. LOG(SF_LOG_INFO, "Get Rotation %d \r\n", decConfig->rotation);
  861. }
  862. else
  863. {
  864. LOG(SF_LOG_WARN, "Only output port support Rotation config\r\n");
  865. ret = OMX_ErrorBadParameter;
  866. }
  867. break;
  868. }
  869. case OMX_IndexConfigCommonMirror:
  870. {
  871. OMX_CONFIG_MIRRORTYPE *mirrParam = (OMX_CONFIG_MIRRORTYPE *)pComponentConfigStructure;
  872. DecConfigParam *decConfig = pSfMjpegImplement->config;
  873. if(mirrParam->nPortIndex == (OMX_U32)(OMX_OUTPUT_PORT_INDEX))
  874. {
  875. mirrParam->eMirror = decConfig->mirror;
  876. LOG(SF_LOG_INFO, "Get Mirror %d \r\n", decConfig->mirror);
  877. }
  878. else
  879. {
  880. LOG(SF_LOG_WARN, "Only output port support Mirror config\r\n");
  881. ret = OMX_ErrorBadParameter;
  882. }
  883. break;
  884. }
  885. case OMX_IndexConfigCommonScale:
  886. {
  887. OMX_CONFIG_SCALEFACTORTYPE *scaleParam = (OMX_CONFIG_SCALEFACTORTYPE *)pComponentConfigStructure;
  888. DecConfigParam *decConfig = pSfMjpegImplement->config;
  889. if(scaleParam->nPortIndex == (OMX_U32)(OMX_OUTPUT_PORT_INDEX))
  890. {
  891. /* In Q16 format */
  892. scaleParam->xWidth = (1 << 16) >> decConfig->iHorScaleMode;
  893. scaleParam->xHeight = (1 << 16) >> decConfig->iVerScaleMode;
  894. LOG(SF_LOG_INFO, "Get scale %d(Q16),%d(Q16) \r\n", scaleParam->xWidth, scaleParam->xHeight);
  895. }
  896. else
  897. {
  898. LOG(SF_LOG_WARN, "Only output port support Scale config\r\n");
  899. ret = OMX_ErrorBadParameter;
  900. }
  901. break;
  902. }
  903. default:
  904. break;
  905. }
  906. EXIT:
  907. FunctionOut();
  908. return ret;
  909. }
  910. static OMX_ERRORTYPE SF_OMX_SetConfig(
  911. OMX_HANDLETYPE hComponent,
  912. OMX_INDEXTYPE nIndex,
  913. OMX_PTR pComponentConfigStructure)
  914. {
  915. OMX_ERRORTYPE ret = OMX_ErrorNone;
  916. FunctionIn();
  917. if (hComponent == NULL)
  918. {
  919. ret = OMX_ErrorBadParameter;
  920. goto EXIT;
  921. }
  922. if (pComponentConfigStructure == NULL)
  923. {
  924. ret = OMX_ErrorBadParameter;
  925. goto EXIT;
  926. }
  927. LOG(SF_LOG_INFO, "Set config on index %X\r\n", nIndex);
  928. OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
  929. SF_OMX_COMPONENT *pSfOMXComponent = pOMXComponent->pComponentPrivate;
  930. SF_CODAJ12_IMPLEMEMT *pSfMjpegImplement = (SF_CODAJ12_IMPLEMEMT *)pSfOMXComponent->componentImpl;
  931. switch ((OMX_U32)nIndex)
  932. {
  933. case OMX_IndexConfigCommonOutputCrop:
  934. {
  935. OMX_CONFIG_RECTTYPE *rectParam = (OMX_CONFIG_RECTTYPE *)pComponentConfigStructure;
  936. DecConfigParam *decConfig = pSfMjpegImplement->config;
  937. if(rectParam->nPortIndex == (OMX_U32)(OMX_OUTPUT_PORT_INDEX))
  938. {
  939. decConfig->roiOffsetX = rectParam->nLeft;
  940. decConfig->roiOffsetY = rectParam->nTop;
  941. decConfig->roiWidth = rectParam->nWidth;
  942. decConfig->roiHeight = rectParam->nHeight;
  943. decConfig->roiEnable = OMX_TRUE;
  944. LOG(SF_LOG_INFO, "Set OutputCrop left %d top %d width %d height %d \r\n",
  945. decConfig->roiOffsetX, decConfig->roiOffsetY, decConfig->roiWidth, decConfig->roiHeight);
  946. }
  947. else
  948. {
  949. LOG(SF_LOG_WARN, "Only support set OutputCrop config to output port\r\n");
  950. ret = OMX_ErrorBadParameter;
  951. }
  952. break;
  953. }
  954. case OMX_IndexConfigCommonRotate:
  955. {
  956. OMX_CONFIG_ROTATIONTYPE *rotatParam = (OMX_CONFIG_ROTATIONTYPE *)pComponentConfigStructure;
  957. DecConfigParam *decConfig = pSfMjpegImplement->config;
  958. if(rotatParam->nPortIndex == (OMX_U32)(OMX_OUTPUT_PORT_INDEX))
  959. {
  960. decConfig->rotation = rotatParam->nRotation;
  961. LOG(SF_LOG_INFO, "Set Rotation %d to output port\r\n", decConfig->rotation);
  962. }
  963. else
  964. {
  965. LOG(SF_LOG_WARN, "Only support set Rotation config to output port\r\n");
  966. ret = OMX_ErrorBadParameter;
  967. }
  968. break;
  969. }
  970. case OMX_IndexConfigCommonMirror:
  971. {
  972. OMX_CONFIG_MIRRORTYPE *mirrParam = (OMX_CONFIG_MIRRORTYPE *)pComponentConfigStructure;
  973. DecConfigParam *decConfig = pSfMjpegImplement->config;
  974. if(mirrParam->nPortIndex == (OMX_U32)(OMX_OUTPUT_PORT_INDEX))
  975. {
  976. decConfig->mirror = mirrParam->eMirror;
  977. LOG(SF_LOG_INFO, "Set Mirror %d \r\n", decConfig->mirror);
  978. }
  979. else
  980. {
  981. LOG(SF_LOG_WARN, "Only output port support Mirror config\r\n");
  982. ret = OMX_ErrorBadParameter;
  983. }
  984. break;
  985. }
  986. case OMX_IndexConfigCommonScale:
  987. {
  988. OMX_CONFIG_SCALEFACTORTYPE *scaleParam = (OMX_CONFIG_SCALEFACTORTYPE *)pComponentConfigStructure;
  989. DecConfigParam *decConfig = pSfMjpegImplement->config;
  990. OMX_U32 x;
  991. if(scaleParam->nPortIndex == (OMX_U32)(OMX_OUTPUT_PORT_INDEX))
  992. {
  993. /* In Q16 format */
  994. x = (1 << 16) / (scaleParam->xWidth);
  995. if(x >= 8)
  996. decConfig->iHorScaleMode = 3;
  997. else if(x >= 4)
  998. decConfig->iHorScaleMode = 2;
  999. else if(x >= 2)
  1000. decConfig->iHorScaleMode = 1;
  1001. else
  1002. decConfig->iHorScaleMode = 0;
  1003. x = (1 << 16) / (scaleParam->xHeight);
  1004. if(x >= 8)
  1005. decConfig->iVerScaleMode = 3;
  1006. else if(x >= 4)
  1007. decConfig->iVerScaleMode = 2;
  1008. else if(x >= 2)
  1009. decConfig->iVerScaleMode = 1;
  1010. else
  1011. decConfig->iVerScaleMode = 0;
  1012. LOG(SF_LOG_INFO, "Set scale H 1/%d, V 1/%d \r\n", 1 << decConfig->iHorScaleMode, 1 << scaleParam->xHeight);
  1013. }
  1014. else
  1015. {
  1016. LOG(SF_LOG_WARN, "Only output port support Scale config\r\n");
  1017. ret = OMX_ErrorBadParameter;
  1018. }
  1019. break;
  1020. }
  1021. default:
  1022. break;
  1023. }
  1024. EXIT:
  1025. FunctionOut();
  1026. return ret;
  1027. }
  1028. static OMX_ERRORTYPE InitDecoder(SF_OMX_COMPONENT *pSfOMXComponent)
  1029. {
  1030. FunctionIn();
  1031. SF_CODAJ12_IMPLEMEMT *pSfCodaj12Implement = pSfOMXComponent->componentImpl;
  1032. JpgRet ret = JPG_RET_SUCCESS;
  1033. DecConfigParam *decConfig = pSfCodaj12Implement->config;
  1034. ret = pSfCodaj12Implement->functions->JPU_Init();
  1035. if (ret != JPG_RET_SUCCESS && ret != JPG_RET_CALLED_BEFORE)
  1036. {
  1037. LOG(SF_LOG_ERR, "JPU_Init failed Error code is 0x%x \r\n", ret);
  1038. return ret;
  1039. }
  1040. decConfig->feedingMode = FEEDING_METHOD_BUFFER;
  1041. LOG(SF_LOG_DEBUG, "feedingMode = %d, StreamEndian = %d\r\n", decConfig->feedingMode, decConfig->StreamEndian);
  1042. if ((pSfCodaj12Implement->feeder = pSfCodaj12Implement->functions->BitstreamFeeder_Create(decConfig->bitstreamFileName, decConfig->feedingMode, (EndianMode)decConfig->StreamEndian)) == NULL)
  1043. {
  1044. return OMX_ErrorResourcesLost;
  1045. }
  1046. FunctionOut();
  1047. return OMX_ErrorNone;
  1048. }
  1049. static OMX_BOOL FillBufferDone(SF_OMX_COMPONENT *pSfOMXComponent, OMX_BUFFERHEADERTYPE *pBuffer)
  1050. {
  1051. SF_CODAJ12_IMPLEMEMT *pSfCodaj12Implement = pSfOMXComponent->componentImpl;
  1052. struct timeval tv;
  1053. static OMX_U32 dec_cnt = 0;
  1054. OMX_U32 fps = 0;
  1055. OMX_U64 diff_time = 0; // ms
  1056. static struct timeval tv_old = {0};
  1057. FunctionIn();
  1058. gettimeofday(&tv, NULL);
  1059. if (gInitTimeStamp == 0)
  1060. {
  1061. gInitTimeStamp = tv.tv_sec * 1000000 + tv.tv_usec;
  1062. }
  1063. pBuffer->nTimeStamp = tv.tv_sec * 1000000 + tv.tv_usec - gInitTimeStamp;
  1064. if (dec_cnt == 0) {
  1065. tv_old = tv;
  1066. }
  1067. if (dec_cnt++ >= 50) {
  1068. diff_time = (tv.tv_sec - tv_old.tv_sec) * 1000 + (tv.tv_usec - tv_old.tv_usec) / 1000;
  1069. fps = 1000 * (dec_cnt - 1) / diff_time;
  1070. dec_cnt = 0;
  1071. LOG(SF_LOG_WARN, "Decoding fps: %d \r\n", fps);
  1072. }
  1073. LOG(SF_LOG_PERF, "OMX finish one buffer, header = %p, address = %p, size = %d, nTimeStamp = %d, nFlags = %X\r\n",
  1074. pBuffer, pBuffer->pBuffer, pBuffer->nFilledLen, pBuffer->nTimeStamp, pBuffer->nFlags);
  1075. // Following comment store data loal
  1076. // {
  1077. // FILE *fb = fopen("./out.bcp", "ab+");
  1078. // LOG(SF_LOG_INFO, "%p %d\r\n", pBuffer->pBuffer, pBuffer->nFilledLen);
  1079. // fwrite(pBuffer->pBuffer, 1, pBuffer->nFilledLen, fb);
  1080. // fclose(fb);
  1081. // }
  1082. if (pSfOMXComponent->propagateMarkType.hMarkTargetComponent != NULL) {
  1083. LOG(SF_LOG_INFO, "Component propagate mark to output port\r\n");
  1084. pBuffer->hMarkTargetComponent = pSfOMXComponent->propagateMarkType.hMarkTargetComponent;
  1085. pBuffer->pMarkData = pSfOMXComponent->propagateMarkType.pMarkData;
  1086. pSfOMXComponent->propagateMarkType.hMarkTargetComponent = NULL;
  1087. pSfOMXComponent->propagateMarkType.pMarkData = NULL;
  1088. }
  1089. if (pSfOMXComponent->state == OMX_StatePause && !pSfOMXComponent->bPortFlushing[OMX_OUTPUT_PORT_INDEX])
  1090. {
  1091. LOG(SF_LOG_INFO, "tmp store buf when pause\r\n");
  1092. SF_Queue_Enqueue(pSfCodaj12Implement->outPauseQ, &pBuffer);
  1093. }
  1094. else{
  1095. if (pBuffer->nFlags & OMX_BUFFERFLAG_EOS)
  1096. {
  1097. pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData, OMX_EventBufferFlag,
  1098. OMX_OUTPUT_PORT_INDEX, pBuffer->nFlags, NULL);
  1099. }
  1100. pSfOMXComponent->callbacks->FillBufferDone(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData, pBuffer);
  1101. pSfOMXComponent->handlingBufferNum[OMX_OUTPUT_PORT_INDEX]--;
  1102. if((pSfOMXComponent->handlingBufferNum[OMX_OUTPUT_PORT_INDEX] == 0) && pSfOMXComponent->bPortFlushing[OMX_OUTPUT_PORT_INDEX])
  1103. {
  1104. LOG(SF_LOG_INFO, "return all out buff\r\n");
  1105. SF_SemaphorePost(pSfOMXComponent->portFlushSemaphore[OMX_OUTPUT_PORT_INDEX]);
  1106. }
  1107. }
  1108. FunctionOut();
  1109. return OMX_TRUE;
  1110. }
  1111. static OMX_BOOL EmptyBufferDone(SF_OMX_COMPONENT *pSfOMXComponent)
  1112. {
  1113. SF_CODAJ12_IMPLEMEMT *pSfCodaj12Implement = pSfOMXComponent->componentImpl;
  1114. OMX_BUFFERHEADERTYPE *pOMXBuffer = NULL;
  1115. Message data;
  1116. ssize_t ret;
  1117. FunctionIn();
  1118. LOG(SF_LOG_INFO, "Wait for done used buffer\r\n");
  1119. ret = msgrcv(pSfCodaj12Implement->sBufferDoneQueue, (void *)&data, BUFSIZ, 0, IPC_NOWAIT);
  1120. if (ret < 0)
  1121. {
  1122. LOG(SF_LOG_INFO, "msgrcv failed ret = %x\r\n", ret);
  1123. return OMX_FALSE;
  1124. }
  1125. // switch (ret)
  1126. // {
  1127. // case ENOMSG:
  1128. // LOG(SF_LOG_INFO, "msgrcv no message\n");
  1129. // return OMX_TRUE;
  1130. // default:
  1131. // LOG(SF_LOG_ERR, "msgrcv failed ret = %x\r\n", ret);
  1132. // return OMX_FALSE;
  1133. // }
  1134. pOMXBuffer = data.pBuffer;
  1135. if (pSfOMXComponent->markType[OMX_INPUT_PORT_INDEX].hMarkTargetComponent != NULL)
  1136. {
  1137. LOG(SF_LOG_INFO, "set Component mark %p\r\n", pSfOMXComponent->markType[OMX_INPUT_PORT_INDEX].hMarkTargetComponent);
  1138. pOMXBuffer->hMarkTargetComponent = pSfOMXComponent->markType[OMX_INPUT_PORT_INDEX].hMarkTargetComponent;
  1139. pOMXBuffer->pMarkData = pSfOMXComponent->markType[OMX_INPUT_PORT_INDEX].pMarkData;
  1140. pSfOMXComponent->markType[OMX_INPUT_PORT_INDEX].hMarkTargetComponent = NULL;
  1141. pSfOMXComponent->markType[OMX_INPUT_PORT_INDEX].pMarkData = NULL;
  1142. }
  1143. if (pOMXBuffer->hMarkTargetComponent != NULL)
  1144. {
  1145. if (pOMXBuffer->hMarkTargetComponent == pSfOMXComponent->pOMXComponent)
  1146. {
  1147. LOG(SF_LOG_INFO, "Component mark hit\r\n");
  1148. pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent,
  1149. pSfOMXComponent->pAppData,
  1150. OMX_EventMark,
  1151. 0, 0, pOMXBuffer->pMarkData);
  1152. } else {
  1153. LOG(SF_LOG_INFO, "Component propagate mark from input port\r\n");
  1154. pSfOMXComponent->propagateMarkType.hMarkTargetComponent = pOMXBuffer->hMarkTargetComponent;
  1155. pSfOMXComponent->propagateMarkType.pMarkData = pOMXBuffer->pMarkData;
  1156. }
  1157. }
  1158. //TODO: input/output Buffer done
  1159. if (pSfOMXComponent->state == OMX_StatePause && !pSfOMXComponent->bPortFlushing[OMX_INPUT_PORT_INDEX])
  1160. {
  1161. LOG(SF_LOG_INFO, "tmp store buf when pause\r\n");
  1162. SF_Queue_Enqueue(pSfCodaj12Implement->inPauseQ, &pOMXBuffer);
  1163. }else{
  1164. LOG(SF_LOG_DEBUG, "Finish inpu buffer header %p pBuffer %p\r\n",pOMXBuffer, pOMXBuffer->pBuffer);
  1165. pSfOMXComponent->callbacks->EmptyBufferDone(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData, pOMXBuffer);
  1166. pSfOMXComponent->handlingBufferNum[OMX_INPUT_PORT_INDEX]--;
  1167. if((pSfOMXComponent->handlingBufferNum[OMX_INPUT_PORT_INDEX] == 0) && pSfOMXComponent->bPortFlushing[OMX_INPUT_PORT_INDEX])
  1168. {
  1169. LOG(SF_LOG_INFO, "return all in buff\r\n");
  1170. SF_SemaphorePost(pSfOMXComponent->portFlushSemaphore[OMX_INPUT_PORT_INDEX]);
  1171. }
  1172. }
  1173. FunctionOut();
  1174. return OMX_TRUE;
  1175. }
  1176. static OMX_S32 FeedData(SF_OMX_COMPONENT *pSfOMXComponent)
  1177. {
  1178. FunctionIn();
  1179. SF_CODAJ12_IMPLEMEMT *pSfCodaj12Implement = pSfOMXComponent->componentImpl;
  1180. BSFeeder feeder = pSfCodaj12Implement->feeder;
  1181. JpgDecHandle handle = pSfCodaj12Implement->handle;
  1182. jpu_buffer_t *vbStream = &pSfCodaj12Implement->vbStream;
  1183. OMX_U32 nFilledLen = 0;
  1184. OMX_BUFFERHEADERTYPE *pOMXBuffer = NULL;
  1185. Message data;
  1186. LOG(SF_LOG_INFO, "Wait for input buffer\r\n");
  1187. if (msgrcv(pSfCodaj12Implement->sInputMessageQueue, (void *)&data, BUFSIZ, 0, 0) == -1)
  1188. {
  1189. LOG(SF_LOG_ERR, "msgrcv failed\n");
  1190. return 0;
  1191. }
  1192. pOMXBuffer = data.pBuffer;
  1193. LOG(SF_LOG_DEBUG, "get buffer %p\n", pOMXBuffer);
  1194. if (!pOMXBuffer)
  1195. {
  1196. return -1;
  1197. }
  1198. if(!pOMXBuffer->nFilledLen){
  1199. LOG(SF_LOG_DEBUG, "end of stream,end\n");
  1200. msgsnd(pSfCodaj12Implement->sBufferDoneQueue, (void *)&data, sizeof(data) - sizeof(data.msg_type), 0);
  1201. return 0;
  1202. }
  1203. else if(pOMXBuffer->nFlags == OMX_BUFFERFLAG_EOS)
  1204. {
  1205. LOG(SF_LOG_DEBUG, "end of stream,end\n");
  1206. pSfCodaj12Implement->gotEos = OMX_TRUE;
  1207. }
  1208. if (pOMXBuffer->pBuffer != NULL && pOMXBuffer->nFilledLen > 0)
  1209. {
  1210. nFilledLen = pOMXBuffer->nFilledLen;
  1211. LOG(SF_LOG_INFO, "Address = %p, size = %d\r\n", pOMXBuffer->pBuffer, nFilledLen);
  1212. pSfCodaj12Implement->functions->BitstreamFeeder_SetData(feeder, pOMXBuffer->pBuffer, nFilledLen);
  1213. pSfCodaj12Implement->functions->BitstreamFeeder_Act(feeder, handle, vbStream);
  1214. }
  1215. LOG(SF_LOG_INFO, "Send %p to sBufferDoneQueue\r\n", pOMXBuffer);
  1216. if (msgsnd(pSfCodaj12Implement->sBufferDoneQueue, (void *)&data, sizeof(data) - sizeof(data.msg_type), 0) == -1)
  1217. {
  1218. LOG(SF_LOG_ERR, "msgsnd failed\n");
  1219. return 0;
  1220. }
  1221. // LOG(SF_LOG_DEBUG, "EmptyBufferDone IN\r\n");
  1222. // pSfOMXComponent->callbacks->EmptyBufferDone(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData, pOMXBuffer);
  1223. // LOG(SF_LOG_DEBUG, "EmptyBufferDone OUT\r\n");
  1224. // if (pOMXBuffer->nFlags & 0x1 == 0x1)
  1225. // {
  1226. // pSfCodaj12Implement->bThreadRunning = OMX_FALSE;
  1227. // }
  1228. FunctionOut();
  1229. return nFilledLen;
  1230. }
  1231. static OMX_ERRORTYPE WaitForOutputBufferReady(SF_OMX_COMPONENT *pSfOMXComponent,OMX_BUFFERHEADERTYPE **ppOMXBuffer)
  1232. {
  1233. FunctionIn();
  1234. OMX_ERRORTYPE ret = OMX_ErrorNone;
  1235. SF_CODAJ12_IMPLEMEMT *pSfCodaj12Implement = pSfOMXComponent->componentImpl;
  1236. OMX_BUFFERHEADERTYPE *pOMXBuffer = NULL;
  1237. Message data;
  1238. LOG(SF_LOG_INFO, "Wait for output buffer\r\n");
  1239. if (msgrcv(pSfCodaj12Implement->sOutputMessageQueue, (void *)&data, BUFSIZ, 0, 0) == -1)
  1240. {
  1241. LOG(SF_LOG_ERR, "msgrcv failed\n");
  1242. return OMX_ErrorInsufficientResources;
  1243. }
  1244. pOMXBuffer = data.pBuffer;
  1245. LOG(SF_LOG_INFO, "get buffer header %p\r\n",pOMXBuffer);
  1246. if (pOMXBuffer == NULL)
  1247. {
  1248. LOG(SF_LOG_INFO, "Buffer end flag detected! \r\n");
  1249. pSfCodaj12Implement->bThreadRunning = OMX_FALSE;
  1250. ret = OMX_ErrorNoMore;
  1251. }
  1252. *ppOMXBuffer = pOMXBuffer;
  1253. FunctionOut();
  1254. return ret;
  1255. }
  1256. static void ProcessThread(void *args)
  1257. {
  1258. SF_OMX_COMPONENT *pSfOMXComponent = (SF_OMX_COMPONENT *)args;
  1259. SF_CODAJ12_IMPLEMEMT *pSfCodaj12Implement = pSfOMXComponent->componentImpl;
  1260. FrameBuffer *pFrameBuf = pSfCodaj12Implement->frameBuf;
  1261. jpu_buffer_t *vbStream = &pSfCodaj12Implement->vbStream;
  1262. JpgDecInitialInfo *initialInfo = &pSfCodaj12Implement->initialInfo;
  1263. JpgDecOpenParam *decOP = &pSfCodaj12Implement->decOP;
  1264. DecConfigParam *decConfig = pSfCodaj12Implement->config;
  1265. OMX_BUFFERHEADERTYPE *pBuffer = NULL;
  1266. JpgDecHandle handle;
  1267. Int32 frameIdx = 0;
  1268. JpgDecParam decParam = {0};
  1269. JpgDecOutputInfo outputInfo = {0};
  1270. Uint32 framebufWidth = 0, framebufHeight = 0, framebufStride = 0;
  1271. Uint32 decodingWidth, decodingHeight;
  1272. Uint32 displayWidth, displayHeight;
  1273. Int32 int_reason = 0;
  1274. Uint32 bitDepth = 0;
  1275. Int32 size = 0;
  1276. Int32 instIdx;
  1277. Uint32 temp;
  1278. BOOL scalerOn = FALSE;
  1279. JpgRet ret = JPG_RET_SUCCESS;
  1280. CbCrInterLeave chromaInterleave;
  1281. PackedFormat packedFormat;
  1282. FrameFormat subsample;
  1283. FunctionIn();
  1284. prctl(PR_SET_NAME, pSfOMXComponent->componentName);
  1285. OMX_U32 nSizeBytes = pSfOMXComponent->portDefinition[0].nBufferSize;
  1286. if (!vbStream->phys_addr)
  1287. {
  1288. vbStream->size = (nSizeBytes == 0) ? STREAM_BUF_SIZE : nSizeBytes;
  1289. vbStream->size = (vbStream->size + 1023) & ~1023; // ceil128(size)
  1290. if (pSfCodaj12Implement->functions->jdi_allocate_dma_memory(vbStream) < 0)
  1291. {
  1292. LOG(SF_LOG_ERR, "fail to allocate bitstream buffer\r\n");
  1293. goto thread_end;
  1294. }
  1295. }
  1296. LOG(SF_LOG_INFO, "vbStream phys_addr = %x, size = %d, virt_addr = %x\r\n", vbStream->phys_addr, vbStream->size, vbStream->virt_addr);
  1297. decOP->streamEndian = decConfig->StreamEndian;
  1298. decOP->frameEndian = decConfig->FrameEndian;
  1299. decOP->bitstreamBuffer = vbStream->phys_addr;
  1300. decOP->bitstreamBufferSize = vbStream->size;
  1301. //set virtual address mapped of physical address
  1302. decOP->pBitStream = (BYTE *)vbStream->virt_addr; //lint !e511
  1303. decOP->chromaInterleave = decConfig->cbcrInterleave;
  1304. decOP->packedFormat = decConfig->packedFormat;
  1305. decOP->roiEnable = decConfig->roiEnable;
  1306. decOP->roiOffsetX = decConfig->roiOffsetX;
  1307. decOP->roiOffsetY = decConfig->roiOffsetY;
  1308. decOP->roiWidth = decConfig->roiWidth;
  1309. decOP->roiHeight = decConfig->roiHeight;
  1310. decOP->rotation = decConfig->rotation;
  1311. decOP->mirror = decConfig->mirror;
  1312. decOP->pixelJustification = decConfig->pixelJustification;
  1313. if (decConfig->packedFormat ||
  1314. (pSfCodaj12Implement->frameFormat == FORMAT_422 && (decConfig->rotation == 90 || decConfig->rotation == 270)))
  1315. {
  1316. decOP->outputFormat = FORMAT_MAX;
  1317. }
  1318. else
  1319. {
  1320. decOP->outputFormat = pSfCodaj12Implement->frameFormat;
  1321. }
  1322. decOP->intrEnableBit = ((1 << INT_JPU_DONE) | (1 << INT_JPU_ERROR) | (1 << INT_JPU_BIT_BUF_EMPTY));
  1323. LOG(SF_LOG_DEBUG, "streamEndian = %x\r\n", decOP->streamEndian);
  1324. LOG_APPEND(SF_LOG_DEBUG, "frameEndian = %x\r\n", decOP->frameEndian);
  1325. LOG_APPEND(SF_LOG_DEBUG, "bitstreamBuffer = %x\r\n", decOP->bitstreamBuffer);
  1326. LOG_APPEND(SF_LOG_DEBUG, "bitstreamBufferSize = %x\r\n", decOP->bitstreamBufferSize);
  1327. LOG_APPEND(SF_LOG_DEBUG, "pBitStream = %x\r\n", decOP->pBitStream);
  1328. LOG_APPEND(SF_LOG_DEBUG, "chromaInterleave = %x\r\n", decOP->chromaInterleave);
  1329. LOG_APPEND(SF_LOG_DEBUG, "packedFormat = %x\r\n", decOP->packedFormat);
  1330. LOG_APPEND(SF_LOG_DEBUG, "roiEnable = %x\r\n", decOP->roiEnable);
  1331. LOG_APPEND(SF_LOG_DEBUG, "roiOffsetX = %x\r\n", decOP->roiOffsetX);
  1332. LOG_APPEND(SF_LOG_DEBUG, "roiOffsetY = %x\r\n", decOP->roiOffsetY);
  1333. LOG_APPEND(SF_LOG_DEBUG, "roiWidth = %x\r\n", decOP->roiWidth);
  1334. LOG_APPEND(SF_LOG_DEBUG, "roiHeight = %x\r\n", decOP->roiHeight);
  1335. LOG_APPEND(SF_LOG_DEBUG, "rotation = %x\r\n", decOP->rotation);
  1336. LOG_APPEND(SF_LOG_DEBUG, "mirror = %x\r\n", decOP->mirror);
  1337. LOG_APPEND(SF_LOG_DEBUG, "pixelJustification = %x\r\n", decOP->pixelJustification);
  1338. LOG_APPEND(SF_LOG_DEBUG, "outputFormat = %x\r\n", decOP->outputFormat);
  1339. LOG_APPEND(SF_LOG_DEBUG, "intrEnableBit = %x\r\n", decOP->intrEnableBit);
  1340. ret = pSfCodaj12Implement->functions->JPU_DecOpen(&handle, decOP);
  1341. if (ret != JPG_RET_SUCCESS)
  1342. {
  1343. LOG(SF_LOG_ERR, "JPU_DecOpen failed Error code is 0x%x \r\n", ret);
  1344. return;
  1345. }
  1346. pSfCodaj12Implement->handle = handle;
  1347. instIdx = pSfCodaj12Implement->instIdx = pSfCodaj12Implement->handle->instIndex;
  1348. do
  1349. {
  1350. size = FeedData(pSfOMXComponent);
  1351. if (size == 0)
  1352. {
  1353. LOG(SF_LOG_INFO, "FeedData = %d, end thread\r\n", size);
  1354. WaitForOutputBufferReady(pSfOMXComponent,&pBuffer);
  1355. pBuffer->nFilledLen = 0;
  1356. pBuffer->nFlags = OMX_BUFFERFLAG_EOS;
  1357. FillBufferDone(pSfOMXComponent, pBuffer);
  1358. pBuffer = NULL;
  1359. pSfCodaj12Implement->bThreadRunning = OMX_FALSE;
  1360. goto thread_end;
  1361. }
  1362. else if (size < 0)
  1363. {
  1364. LOG(SF_LOG_INFO, "get null buf, end thread\r\n");
  1365. pSfCodaj12Implement->bThreadRunning = OMX_FALSE;
  1366. goto thread_end;
  1367. }
  1368. if ((ret = pSfCodaj12Implement->functions->JPU_DecGetInitialInfo(handle, initialInfo)) != JPG_RET_SUCCESS)
  1369. {
  1370. if (JPG_RET_BIT_EMPTY == ret)
  1371. {
  1372. LOG(SF_LOG_INFO, "<%s:%d> BITSTREAM EMPTY\n", __FUNCTION__, __LINE__);
  1373. continue;
  1374. }
  1375. else
  1376. {
  1377. LOG(SF_LOG_ERR, "JPU_DecGetInitialInfo failed Error code is 0x%x, inst=%d \n", ret, instIdx);
  1378. return;
  1379. }
  1380. }
  1381. } while (JPG_RET_SUCCESS != ret);
  1382. if (initialInfo->sourceFormat == FORMAT_420 || initialInfo->sourceFormat == FORMAT_422)
  1383. framebufWidth = JPU_CEIL(16, initialInfo->picWidth);
  1384. else
  1385. framebufWidth = JPU_CEIL(8, initialInfo->picWidth);
  1386. if (initialInfo->sourceFormat == FORMAT_420 || initialInfo->sourceFormat == FORMAT_440)
  1387. framebufHeight = JPU_CEIL(16, initialInfo->picHeight);
  1388. else
  1389. framebufHeight = JPU_CEIL(8, initialInfo->picHeight);
  1390. LOG(SF_LOG_DEBUG, "framebufWidth: %d, framebufHeight: %d\r\n", framebufWidth, framebufHeight);
  1391. decodingWidth = framebufWidth >> decConfig->iHorScaleMode;
  1392. decodingHeight = framebufHeight >> decConfig->iVerScaleMode;
  1393. if (decOP->packedFormat != PACKED_FORMAT_NONE && decOP->packedFormat != PACKED_FORMAT_444)
  1394. {
  1395. // When packed format, scale-down resolution should be multiple of 2.
  1396. decodingWidth = JPU_CEIL(2, decodingWidth);
  1397. }
  1398. if (decConfig->packedFormat)
  1399. {
  1400. subsample = initialInfo->sourceFormat;
  1401. }
  1402. else
  1403. {
  1404. subsample = pSfCodaj12Implement->frameFormat;
  1405. }
  1406. temp = decodingWidth;
  1407. decodingWidth = (decConfig->rotation == 90 || decConfig->rotation == 270) ? decodingHeight : decodingWidth;
  1408. decodingHeight = (decConfig->rotation == 90 || decConfig->rotation == 270) ? temp : decodingHeight;
  1409. if (decConfig->roiEnable == TRUE)
  1410. {
  1411. decodingWidth = framebufWidth = initialInfo->roiFrameWidth;
  1412. decodingHeight = framebufHeight = initialInfo->roiFrameHeight;
  1413. }
  1414. LOG(SF_LOG_DEBUG, "decodingWidth: %d, decodingHeight: %d\n", decodingWidth, decodingHeight);
  1415. if (decConfig->iHorScaleMode)
  1416. {
  1417. displayWidth = JPU_FLOOR(2, (framebufWidth >> decConfig->iHorScaleMode));
  1418. }
  1419. else if (decConfig->roiEnable == TRUE)
  1420. {
  1421. displayWidth = initialInfo->roiFrameWidth;
  1422. }
  1423. else
  1424. {
  1425. displayWidth = initialInfo->picWidth;
  1426. }
  1427. if (decConfig->iVerScaleMode)
  1428. {
  1429. displayHeight = JPU_FLOOR(2, (framebufHeight >> decConfig->iVerScaleMode));
  1430. }
  1431. else if (decConfig->roiEnable == TRUE)
  1432. {
  1433. displayHeight = initialInfo->roiFrameHeight;
  1434. }
  1435. else
  1436. {
  1437. displayHeight = initialInfo->picHeight;
  1438. }
  1439. temp = displayWidth;
  1440. displayWidth = (decConfig->rotation == 90 || decConfig->rotation == 270) ? displayHeight : displayWidth;
  1441. displayHeight = (decConfig->rotation == 90 || decConfig->rotation == 270) ? temp : displayHeight;
  1442. LOG(SF_LOG_DEBUG, "displayWidth: %d, displayHeight: %d\n", displayWidth, displayHeight);
  1443. if (decOP->rotation != 0 || decOP->mirror != MIRDIR_NONE)
  1444. {
  1445. if (decOP->outputFormat != FORMAT_MAX && decOP->outputFormat != initialInfo->sourceFormat)
  1446. {
  1447. LOG(SF_LOG_ERR, "The rotator cannot work with the format converter together.\n");
  1448. goto thread_end;
  1449. }
  1450. }
  1451. if (!pSfOMXComponent->memory_optimization)
  1452. {
  1453. bitDepth = initialInfo->bitDepth;
  1454. scalerOn = (BOOL)(decConfig->iHorScaleMode || decConfig->iVerScaleMode);
  1455. // may be handle == NULL on ffmpeg case
  1456. if (bitDepth == 0)
  1457. {
  1458. bitDepth = 8;
  1459. }
  1460. chromaInterleave = decOP->chromaInterleave;
  1461. packedFormat = decOP->packedFormat;
  1462. LOG(SF_LOG_DEBUG, "AllocateFrameBuffer\r\n");
  1463. LOG_APPEND(SF_LOG_DEBUG, "instIdx = %d subsample = %d chromaInterleave = %d packedFormat = %d rotation = %d\r\n",
  1464. instIdx, subsample, chromaInterleave, packedFormat, decConfig->rotation);
  1465. LOG_APPEND(SF_LOG_DEBUG, "scalerOn = %d decodingWidth = %d decodingHeight = %d bitDepth = %d\r\n",
  1466. scalerOn, decodingWidth, decodingHeight, bitDepth);
  1467. if (pSfCodaj12Implement->functions->AllocateFrameBuffer(instIdx, subsample, chromaInterleave, packedFormat, decConfig->rotation,
  1468. scalerOn, decodingWidth, decodingHeight, bitDepth, initialInfo->minFrameBufferCount) == FALSE) {
  1469. LOG(SF_LOG_ERR, "Failed to AllocateFrameBuffer()\n");
  1470. goto thread_end;
  1471. }
  1472. pSfCodaj12Implement->allocBufFlag = OMX_TRUE;
  1473. for( int i = 0; i < initialInfo->minFrameBufferCount; ++i ) {
  1474. FRAME_BUF *pFrame = pSfCodaj12Implement->functions->GetFrameBuffer(instIdx, i);
  1475. pFrameBuf[i].bufY = pFrame->vbY.phys_addr;
  1476. pFrameBuf[i].bufCb = pFrame->vbCb.phys_addr;
  1477. if (decOP->chromaInterleave == CBCR_SEPARATED)
  1478. pFrameBuf[i].bufCr = pFrame->vbCr.phys_addr;
  1479. pFrameBuf[i].stride = pFrame->strideY;
  1480. pFrameBuf[i].strideC = pFrame->strideC;
  1481. pFrameBuf[i].endian = decOP->frameEndian;
  1482. pFrameBuf[i].format = (FrameFormat)pFrame->Format;
  1483. }
  1484. framebufStride = pFrameBuf[0].stride;
  1485. if ((ret = pSfCodaj12Implement->functions->JPU_DecRegisterFrameBuffer
  1486. (handle, pFrameBuf, initialInfo->minFrameBufferCount, framebufStride)) != JPG_RET_SUCCESS) {
  1487. LOG(SF_LOG_ERR, "JPU_DecRegisterFrameBuffer failed Error code is 0x%x \n", ret );
  1488. goto thread_end;
  1489. }
  1490. }
  1491. //TODO:Set output info
  1492. OMX_PARAM_PORTDEFINITIONTYPE *pPortDefinition = &pSfOMXComponent->portDefinition[OMX_OUTPUT_PORT_INDEX];
  1493. LOG(SF_LOG_DEBUG, "picWidth = %d, picHeight = %d, output Width = %d, output Height = %d\r\n", initialInfo->picWidth, initialInfo->picHeight,displayWidth, displayHeight);
  1494. pPortDefinition->format.video.nFrameWidth = displayWidth;
  1495. pPortDefinition->format.video.nFrameHeight = displayHeight;
  1496. pPortDefinition->format.video.nStride = displayWidth;
  1497. pPortDefinition->format.video.nSliceHeight = displayHeight;
  1498. pPortDefinition->format.video.eCompressionFormat = OMX_IMAGE_CodingUnused;
  1499. switch (pSfCodaj12Implement->frameFormat)
  1500. {
  1501. case FORMAT_400:
  1502. case FORMAT_420:
  1503. pPortDefinition->nBufferSize = initialInfo->picWidth * initialInfo->picHeight * 3 / 2;
  1504. break;
  1505. case FORMAT_422:
  1506. case FORMAT_440:
  1507. pPortDefinition->nBufferSize = initialInfo->picWidth * initialInfo->picHeight * 2;
  1508. break;
  1509. case FORMAT_444:
  1510. case FORMAT_MAX:
  1511. pPortDefinition->nBufferSize = initialInfo->picWidth * initialInfo->picHeight * 3;
  1512. break;
  1513. default:
  1514. pPortDefinition->nBufferSize = initialInfo->picWidth * initialInfo->picHeight * 4;
  1515. break;
  1516. }
  1517. LOG(SF_LOG_DEBUG, "Output buffer size = %d\r\n", pPortDefinition->nBufferSize);
  1518. if (pPortDefinition->nBufferCountActual < initialInfo->minFrameBufferCount)
  1519. {
  1520. pPortDefinition->nBufferCountActual = initialInfo->minFrameBufferCount;
  1521. }
  1522. if (pPortDefinition->nBufferCountMin < initialInfo->minFrameBufferCount)
  1523. {
  1524. pPortDefinition->nBufferCountMin = initialInfo->minFrameBufferCount;
  1525. }
  1526. LOG(SF_LOG_DEBUG, "OMX_EventPortSettingsChanged IN\r\n");
  1527. pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData, OMX_EventPortSettingsChanged,
  1528. 1, OMX_IndexParamPortDefinition, NULL);
  1529. LOG(SF_LOG_DEBUG, "OMX_EventPortSettingsChanged OUT\r\n");
  1530. LOG(SF_LOG_INFO, "Wait for out buffers ready\r\n");
  1531. OMX_U32 nBufferNumber = pSfOMXComponent->portDefinition[OMX_OUTPUT_PORT_INDEX].nBufferCountActual;
  1532. if (pSfOMXComponent->memory_optimization)
  1533. {
  1534. OMX_U32 nTimeout = 100;
  1535. while (OMX_TRUE)
  1536. {
  1537. // LOG(SF_LOG_INFO, "GetFrameBufferCount addr = %p\r\n", pSfCodaj12Implement->functions->GetFrameBufferCount);
  1538. nBufferNumber = pSfOMXComponent->portDefinition[OMX_OUTPUT_PORT_INDEX].nBufferCountActual;
  1539. OMX_U32 number = pSfCodaj12Implement->functions->GetFrameBufferCount(instIdx);
  1540. OMX_S32 oldNumber = -1;
  1541. if (number < nBufferNumber)
  1542. {
  1543. if (oldNumber < number)
  1544. {
  1545. LOG(SF_LOG_INFO, "Wait for output buffer %d/%d\r\n", number, initialInfo->minFrameBufferCount);
  1546. oldNumber = number;
  1547. }
  1548. usleep(50 * 1000);
  1549. nTimeout --;
  1550. if (nTimeout < 0)
  1551. {
  1552. LOG(SF_LOG_ERR, "No buffers found on output port\r\n");
  1553. LOG(SF_LOG_DEBUG, "OMX_EventBufferFlag IN\r\n");
  1554. pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData, OMX_EventBufferFlag,
  1555. 1, 1, NULL);
  1556. LOG(SF_LOG_DEBUG, "OMX_EventBufferFlag OUT\r\n");
  1557. return;
  1558. }
  1559. }
  1560. else
  1561. {
  1562. break;
  1563. }
  1564. }
  1565. }
  1566. FRAME_BUF *pFrame = pSfCodaj12Implement->frame;
  1567. LOG(SF_LOG_INFO, "Update and regist %d FrameBuffers\r\n", nBufferNumber);
  1568. LOG(SF_LOG_DEBUG, "%20s%20s%20s%20s\r\n", "virtAddr", "Y", "CB", "CR");
  1569. for (int i = 0; i < nBufferNumber; i ++)
  1570. {
  1571. LOG_APPEND(SF_LOG_DEBUG, "%20lX%20lX%20lX%20lX\r\n", pFrame[i].vbY.virt_addr,
  1572. pFrame[i].vbY.phys_addr, pFrame[i].vbCb.phys_addr, pFrame[i].vbCr.phys_addr);
  1573. }
  1574. if (pSfOMXComponent->memory_optimization)
  1575. {
  1576. if (pSfCodaj12Implement->functions->JPU_GetFrameBufPool(pSfCodaj12Implement->handle) == NULL)
  1577. {
  1578. JpgRet ret = JPG_RET_SUCCESS;
  1579. pSfCodaj12Implement->functions->UpdateFrameBuffers(instIdx, nBufferNumber, pFrame);
  1580. ret = pSfCodaj12Implement->functions->JPU_DecRegisterFrameBuffer(pSfCodaj12Implement->handle, pSfCodaj12Implement->frameBuf,
  1581. nBufferNumber, pSfCodaj12Implement->frameBuf[0].stride);
  1582. if (ret != JPG_RET_SUCCESS)
  1583. {
  1584. LOG(SF_LOG_ERR, "JPU_DecRegisterFrameBuffer fail ret = %d\r\n", ret);
  1585. pSfCodaj12Implement->bThreadRunning = OMX_FALSE;
  1586. }
  1587. }
  1588. }
  1589. pSfCodaj12Implement->functions->JPU_DecGiveCommand(handle, SET_JPG_SCALE_HOR, &(decConfig->iHorScaleMode));
  1590. pSfCodaj12Implement->functions->JPU_DecGiveCommand(handle, SET_JPG_SCALE_VER, &(decConfig->iVerScaleMode));
  1591. /* LOG HEADER */
  1592. LOG(SF_LOG_INFO, "I F FB_INDEX FRAME_START ECS_START CONSUME RD_PTR WR_PTR CYCLE\n");
  1593. LOG(SF_LOG_INFO, "-------------------------------------------------------------------------------\n");
  1594. while (pSfCodaj12Implement->bThreadRunning)
  1595. {
  1596. if (WaitForOutputBufferReady(pSfOMXComponent,&pBuffer) != OMX_ErrorNone)
  1597. {
  1598. continue;
  1599. }
  1600. LOG(SF_LOG_INFO, "pBuffer index:%d\r\n", ((SF_OMX_BUF_INFO*)(pBuffer->pOutputPortPrivate))->index);
  1601. refill:
  1602. if (pSfOMXComponent->memory_optimization)
  1603. {
  1604. ret = pSfCodaj12Implement->functions->JPU_DecStartOneFrameBySerialNum(handle, &decParam,
  1605. (OMX_U64)(((SF_OMX_BUF_INFO*)(pBuffer->pOutputPortPrivate))->index));
  1606. }
  1607. else
  1608. {
  1609. ret = pSfCodaj12Implement->functions->JPU_DecStartOneFrame(handle, &decParam);
  1610. }
  1611. if (ret != JPG_RET_SUCCESS && ret != JPG_RET_EOS)
  1612. {
  1613. if (ret == JPG_RET_BIT_EMPTY)
  1614. {
  1615. LOG(SF_LOG_INFO, "BITSTREAM NOT ENOUGH.............\n");
  1616. EmptyBufferDone(pSfOMXComponent);
  1617. size = FeedData(pSfOMXComponent);
  1618. if (size == 0)
  1619. {
  1620. LOG(SF_LOG_INFO, "FeedData = %d, end thread\r\n", size);
  1621. pBuffer->nFilledLen = 0;
  1622. pBuffer->nFlags |= OMX_BUFFERFLAG_EOS;
  1623. FillBufferDone(pSfOMXComponent, pBuffer);
  1624. pBuffer = NULL;
  1625. pSfCodaj12Implement->bThreadRunning = OMX_FALSE;
  1626. break;
  1627. }
  1628. else if (size < 0)
  1629. {
  1630. LOG(SF_LOG_INFO, "get null buf, end thread\r\n");
  1631. pSfCodaj12Implement->bThreadRunning = OMX_FALSE;
  1632. goto thread_end;
  1633. }
  1634. goto refill;
  1635. }
  1636. LOG(SF_LOG_ERR, "JPU_DecStartOneFrameBySerialNum failed Error code is 0x%x \n", ret);
  1637. return;
  1638. }
  1639. if (ret == JPG_RET_EOS)
  1640. {
  1641. pSfCodaj12Implement->functions->JPU_DecGetOutputInfo(handle, &outputInfo);
  1642. break;
  1643. }
  1644. LOG(SF_LOG_INFO, "wait process frame \n");
  1645. while (1)
  1646. {
  1647. if ((int_reason = pSfCodaj12Implement->functions->JPU_WaitInterrupt(handle, JPU_INTERRUPT_TIMEOUT_MS)) == -1)
  1648. {
  1649. LOG(SF_LOG_ERR, "Error : timeout happened\n");
  1650. pSfCodaj12Implement->functions->JPU_SWReset(handle);
  1651. break;
  1652. }
  1653. if (int_reason & ((1 << INT_JPU_DONE) | (1 << INT_JPU_ERROR) | (1 << INT_JPU_SLICE_DONE)))
  1654. {
  1655. // Do no clear INT_JPU_DONE and INT_JPU_ERROR interrupt. these will be cleared in JPU_DecGetOutputInfo.
  1656. LOG(SF_LOG_INFO, "\tINSTANCE #%d int_reason: %08x\n", handle->instIndex, int_reason);
  1657. break;
  1658. }
  1659. // if (int_reason & (1 << INT_JPU_BIT_BUF_EMPTY))
  1660. // {
  1661. // if (decConfig->feedingMode != FEEDING_METHOD_FRAME_SIZE)
  1662. // {
  1663. // pSfCodaj12Implement->functions->BitstreamFeeder_Act(feeder, handle, &vbStream);
  1664. // }
  1665. // pSfCodaj12Implement->functions->JPU_ClrStatus(handle, (1 << INT_JPU_BIT_BUF_EMPTY));
  1666. // }
  1667. }
  1668. LOG(SF_LOG_INFO, "process frame done\n");
  1669. EmptyBufferDone(pSfOMXComponent);
  1670. if ((ret = pSfCodaj12Implement->functions->JPU_DecGetOutputInfo(handle, &outputInfo)) != JPG_RET_SUCCESS)
  1671. {
  1672. LOG(SF_LOG_ERR, "JPU_DecGetOutputInfo failed Error code is 0x%x \n", ret);
  1673. break;
  1674. }
  1675. if (outputInfo.indexFrameDisplay == -1)
  1676. {
  1677. LOG(SF_LOG_ERR, "indexFrameDisplay -1\r\n");
  1678. goto thread_end;;
  1679. }
  1680. if (pSfOMXComponent->memory_optimization)
  1681. {
  1682. pBuffer->nFilledLen = pSfCodaj12Implement->functions->SaveYuvImageHelperDma
  1683. (pBuffer->pBuffer, &pSfCodaj12Implement->frameBuf[(OMX_U64)(((SF_OMX_BUF_INFO*)(pBuffer->pOutputPortPrivate))->index)],
  1684. decOP->chromaInterleave, decOP->packedFormat, displayWidth, displayHeight, initialInfo->bitDepth);
  1685. }
  1686. else{
  1687. pBuffer->nFilledLen = pSfCodaj12Implement->functions->SaveYuvImageHelper
  1688. (pBuffer->pBuffer, &pFrameBuf[outputInfo.indexFrameDisplay],
  1689. decOP->chromaInterleave, decOP->packedFormat, displayWidth, displayHeight, bitDepth);
  1690. }
  1691. if (!pBuffer->nFilledLen)
  1692. {
  1693. LOG(SF_LOG_ERR, "fill out buffer err -1\r\n");
  1694. goto thread_end;
  1695. }
  1696. LOG(SF_LOG_DEBUG, "decPicSize = [%d %d], PicSize = [%d %d], pBuffer = %p, fillen %d\r\n",
  1697. outputInfo.decPicWidth, outputInfo.decPicHeight, initialInfo->picWidth,
  1698. initialInfo->picHeight, pBuffer->pBuffer, pBuffer->nFilledLen);
  1699. // AdjustFrame(pBuffer, outputInfo.decPicWidth, outputInfo.decPicHeight, nDestStride, nDestHeight);
  1700. if (pSfCodaj12Implement->gotEos)
  1701. {
  1702. pSfCodaj12Implement->gotEos = OMX_FALSE;
  1703. pBuffer->nFlags |= OMX_BUFFERFLAG_EOS;
  1704. }
  1705. FillBufferDone(pSfOMXComponent, pBuffer);
  1706. pBuffer = NULL;
  1707. if(pSfCodaj12Implement->bPause){
  1708. LOG(SF_LOG_DEBUG,"in pause\n");
  1709. SF_SemaphoreWait(pSfCodaj12Implement->pauseOutSemaphore);
  1710. LOG(SF_LOG_DEBUG,"out pause\n");
  1711. }
  1712. // LOG(SF_LOG_DEBUG, "FillBufferDone IN\r\n");
  1713. // Following comment store data loal
  1714. // {
  1715. // FILE *fb = fopen("./out.bcp", "ab+");
  1716. // LOG(SF_LOG_INFO, "%p %d\r\n", pBuffer->pBuffer, pBuffer->nFilledLen);
  1717. // fwrite(pBuffer->pBuffer, 1, pBuffer->nFilledLen, fb);
  1718. // fclose(fb);
  1719. // }
  1720. // pSfOMXComponent->callbacks->FillBufferDone(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData, pBuffer);
  1721. // LOG(SF_LOG_DEBUG, "FillBufferDone OUT\r\n");
  1722. if (outputInfo.numOfErrMBs)
  1723. {
  1724. Int32 errRstIdx, errPosX, errPosY;
  1725. errRstIdx = (outputInfo.numOfErrMBs & 0x0F000000) >> 24;
  1726. errPosX = (outputInfo.numOfErrMBs & 0x00FFF000) >> 12;
  1727. errPosY = (outputInfo.numOfErrMBs & 0x00000FFF);
  1728. LOG(SF_LOG_ERR, "Error restart Idx : %d, MCU x:%d, y:%d, in Frame : %d \n", errRstIdx, errPosX, errPosY, frameIdx);
  1729. }
  1730. // if (pSfCodaj12Implement->bThreadRunning == OMX_FALSE)
  1731. // {
  1732. // break;
  1733. // }
  1734. pSfCodaj12Implement->functions->JPU_DecSetRdPtrEx(handle, vbStream->phys_addr, TRUE);
  1735. size = 0;
  1736. while (!size)
  1737. {
  1738. size = FeedData(pSfOMXComponent);
  1739. if (size == 0)
  1740. {
  1741. LOG(SF_LOG_INFO, "FeedData = %d, end thread\r\n", size);
  1742. WaitForOutputBufferReady(pSfOMXComponent,&pBuffer);
  1743. pBuffer->nFilledLen = 0;
  1744. pBuffer->nFlags = OMX_BUFFERFLAG_EOS;
  1745. EmptyBufferDone(pSfOMXComponent);
  1746. FillBufferDone(pSfOMXComponent, pBuffer);
  1747. pBuffer = NULL;
  1748. }
  1749. else if (size < 0)
  1750. {
  1751. LOG(SF_LOG_INFO, "get null buf, end thread\r\n");
  1752. pSfCodaj12Implement->bThreadRunning = OMX_FALSE;
  1753. goto thread_end;
  1754. }
  1755. }
  1756. }
  1757. thread_end:
  1758. LOG(SF_LOG_DEBUG, "decoder thread end\r\n");
  1759. if (pBuffer)
  1760. {
  1761. pBuffer->nFilledLen = 0;
  1762. pBuffer->nFlags = OMX_BUFFERFLAG_EOS;
  1763. FillBufferDone(pSfOMXComponent, pBuffer);
  1764. }
  1765. CodaJ12FlushBuffer(pSfOMXComponent, OMX_INPUT_PORT_INDEX);
  1766. CodaJ12FlushBuffer(pSfOMXComponent, OMX_OUTPUT_PORT_INDEX);
  1767. pSfCodaj12Implement->currentState = OMX_StateIdle;
  1768. pSfCodaj12Implement->functions->JPU_DecClose(handle);
  1769. FunctionOut();
  1770. ThreadExit(NULL);
  1771. }
  1772. static OMX_ERRORTYPE SF_OMX_SendCommand(
  1773. OMX_IN OMX_HANDLETYPE hComponent,
  1774. OMX_IN OMX_COMMANDTYPE Cmd,
  1775. OMX_IN OMX_U32 nParam,
  1776. OMX_IN OMX_PTR pCmdData)
  1777. {
  1778. OMX_ERRORTYPE ret = OMX_ErrorNone;
  1779. OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
  1780. SF_OMX_COMPONENT *pSfOMXComponent = pOMXComponent->pComponentPrivate;
  1781. SF_CODAJ12_IMPLEMEMT *pSfCodaj12Implement = pSfOMXComponent->componentImpl;
  1782. OMX_STATETYPE comCurrentState;
  1783. DEC_CMD cmd;
  1784. //BOOL done = 0;
  1785. FunctionIn();
  1786. if (hComponent == NULL || pSfOMXComponent == NULL)
  1787. {
  1788. ret = OMX_ErrorBadParameter;
  1789. goto EXIT;
  1790. }
  1791. LOG(SF_LOG_INFO, "cmd = %X, nParam = %X\r\n", Cmd, nParam);
  1792. comCurrentState = pSfOMXComponent->state;
  1793. if (comCurrentState == OMX_StateInvalid) {
  1794. return OMX_ErrorInvalidState;
  1795. }
  1796. switch (Cmd)
  1797. {
  1798. case OMX_CommandStateSet:
  1799. {
  1800. if ((nParam == OMX_StateLoaded) &&
  1801. (pSfOMXComponent->state == OMX_StateIdle))
  1802. {
  1803. pSfOMXComponent->traningState = OMX_TransStateIdleToLoaded;
  1804. }
  1805. else if ((nParam == OMX_StateIdle) &&
  1806. (pSfOMXComponent->state == OMX_StateLoaded))
  1807. {
  1808. pSfOMXComponent->traningState = OMX_TransStateLoadedToIdle;
  1809. }
  1810. }
  1811. break;
  1812. case OMX_CommandFlush:
  1813. {
  1814. if (nParam >= 2 && nParam != OMX_ALL)
  1815. return OMX_ErrorBadPortIndex;
  1816. }
  1817. break;
  1818. case OMX_CommandMarkBuffer:
  1819. {
  1820. if (nParam >= 2)
  1821. return OMX_ErrorBadPortIndex;
  1822. if ((pSfOMXComponent->state != OMX_StateExecuting) &&
  1823. (pSfOMXComponent->state != OMX_StatePause))
  1824. return OMX_ErrorIncorrectStateOperation;
  1825. }
  1826. break;
  1827. case OMX_CommandPortDisable:
  1828. {
  1829. if (nParam >= 2 && nParam != OMX_ALL)
  1830. return OMX_ErrorBadPortIndex;
  1831. if (nParam == OMX_ALL)
  1832. {
  1833. for (int i = 0; i < 2; i++)
  1834. {
  1835. if(pSfOMXComponent->portDefinition[i].bEnabled == OMX_FALSE)
  1836. return OMX_ErrorIncorrectStateOperation;
  1837. }
  1838. for (int i = 0; i < 2; i++)
  1839. {
  1840. pSfOMXComponent->portDefinition[i].bEnabled = OMX_FALSE;
  1841. }
  1842. }
  1843. else
  1844. {
  1845. if (pSfOMXComponent->portDefinition[nParam].bEnabled == OMX_FALSE)
  1846. return OMX_ErrorIncorrectStateOperation;
  1847. pSfOMXComponent->portDefinition[nParam].bEnabled = OMX_FALSE;
  1848. }
  1849. }
  1850. break;
  1851. case OMX_CommandPortEnable:
  1852. {
  1853. if (nParam >= 2 && nParam != OMX_ALL)
  1854. return OMX_ErrorBadPortIndex;
  1855. if (nParam == OMX_ALL)
  1856. {
  1857. for (int i = 0; i < 2; i++)
  1858. {
  1859. if(pSfOMXComponent->portDefinition[i].bEnabled == OMX_TRUE)
  1860. return OMX_ErrorIncorrectStateOperation;
  1861. }
  1862. for (int i = 0; i < 2; i++)
  1863. {
  1864. pSfOMXComponent->portDefinition[i].bEnabled = OMX_TRUE;
  1865. }
  1866. }
  1867. else
  1868. {
  1869. if (pSfOMXComponent->portDefinition[nParam].bEnabled == OMX_TRUE)
  1870. return OMX_ErrorIncorrectStateOperation;
  1871. pSfOMXComponent->portDefinition[nParam].bEnabled = OMX_TRUE;
  1872. }
  1873. }
  1874. break;
  1875. default:
  1876. break;
  1877. }
  1878. cmd.Cmd = Cmd;
  1879. cmd.nParam = nParam;
  1880. cmd.pCmdData = pCmdData;
  1881. ret = SF_Queue_Enqueue(pSfCodaj12Implement->CmdQueue, &cmd);
  1882. EXIT:
  1883. FunctionOut();
  1884. return ret;
  1885. }
  1886. static OMX_ERRORTYPE SF_OMX_GetState(
  1887. OMX_IN OMX_HANDLETYPE hComponent,
  1888. OMX_OUT OMX_STATETYPE *pState)
  1889. {
  1890. OMX_ERRORTYPE ret = OMX_ErrorNone;
  1891. OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
  1892. SF_OMX_COMPONENT *pSfOMXComponent = pOMXComponent->pComponentPrivate;
  1893. FunctionIn();
  1894. *pState = pSfOMXComponent->state;
  1895. FunctionOut();
  1896. return ret;
  1897. }
  1898. static OMX_ERRORTYPE SF_OMX_FreeBuffer(
  1899. OMX_IN OMX_HANDLETYPE hComponent,
  1900. OMX_IN OMX_U32 nPortIndex,
  1901. OMX_IN OMX_BUFFERHEADERTYPE *pBufferHdr)
  1902. {
  1903. SF_OMX_BUF_INFO *pBufInfo;
  1904. OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
  1905. SF_OMX_COMPONENT *pSfOMXComponent = pOMXComponent->pComponentPrivate;
  1906. FunctionIn();
  1907. if(pBufferHdr == NULL)
  1908. return OMX_ErrorBadParameter;
  1909. if(nPortIndex >= OMX_PORT_MAX)
  1910. return OMX_ErrorBadParameter;
  1911. if(nPortIndex == OMX_INPUT_PORT_INDEX)
  1912. pBufInfo = pBufferHdr->pInputPortPrivate;
  1913. else if(nPortIndex == OMX_OUTPUT_PORT_INDEX)
  1914. pBufInfo = pBufferHdr->pOutputPortPrivate;
  1915. LOG(SF_LOG_INFO, "free header %p pBuffer address = %p on port %d\r\n",
  1916. pBufferHdr, pBufferHdr->pBuffer, nPortIndex);
  1917. if ((pSfOMXComponent->traningState != OMX_TransStateIdleToLoaded) &&
  1918. (pSfOMXComponent->portDefinition[nPortIndex].bEnabled))
  1919. {
  1920. LOG(SF_LOG_INFO, "port Unpopulated\r\n");
  1921. pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData,
  1922. OMX_EventError, OMX_ErrorPortUnpopulated, nPortIndex, NULL);
  1923. }
  1924. if(pBufInfo->type == SF_BUFFER_NOMAL)
  1925. {
  1926. if(pBufferHdr->pBuffer)
  1927. free(pBufferHdr->pBuffer);
  1928. }
  1929. else if (pBufInfo->type == SF_BUFFER_DMA)
  1930. {
  1931. SF_CODAJ12_IMPLEMEMT *pSfCodaj12Implement = pSfOMXComponent->componentImpl;
  1932. pSfCodaj12Implement->functions->FreeOneFrameBuffer(pSfCodaj12Implement->instIdx, pBufInfo->index);
  1933. }
  1934. pSfOMXComponent->pBufferArray[nPortIndex][pBufInfo->index] = NULL;
  1935. pSfOMXComponent->assignedBufferNum[nPortIndex]--;
  1936. LOG(SF_LOG_INFO, "remain %d buff port %d assgin\r\n",pSfOMXComponent->assignedBufferNum[nPortIndex], nPortIndex);
  1937. free(pBufferHdr);
  1938. free(pBufInfo);
  1939. if (pSfOMXComponent->assignedBufferNum[nPortIndex] == 0) {
  1940. LOG(SF_LOG_INFO, "unloadedResource signal set\r\n");
  1941. SF_SemaphorePost(pSfOMXComponent->portUnloadSemaphore[nPortIndex]);
  1942. pSfOMXComponent->portDefinition[nPortIndex].bPopulated = OMX_FALSE;
  1943. }
  1944. FunctionOut();
  1945. return OMX_ErrorNone;
  1946. }
  1947. static void CmdThread(void *args)
  1948. {
  1949. SF_OMX_COMPONENT *pSfOMXComponent = (SF_OMX_COMPONENT *)args;
  1950. SF_CODAJ12_IMPLEMEMT *pSfCodaj12Implement = pSfOMXComponent->componentImpl;
  1951. OMX_BUFFERHEADERTYPE *pOMXBuffer = NULL;
  1952. OMX_BUFFERHEADERTYPE **ppBuffer = NULL;
  1953. OMX_ERRORTYPE ret = OMX_ErrorNone;
  1954. OMX_STATETYPE comCurrentState;
  1955. OMX_U32 i = 0, cnt = 0;
  1956. DEC_CMD *pCmd;
  1957. Message data;
  1958. void *ThreadRet;
  1959. while(1){
  1960. pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
  1961. pCmd = (DEC_CMD*)SF_Queue_Dequeue_Block(pSfCodaj12Implement->CmdQueue);
  1962. pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
  1963. pthread_testcancel();
  1964. pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
  1965. if(pCmd->Cmd == DEC_StopThread)
  1966. break;
  1967. switch (pCmd->Cmd)
  1968. {
  1969. case OMX_CommandStateSet:
  1970. LOG(SF_LOG_INFO, "OMX dest state = %X\r\n", pCmd->nParam);
  1971. comCurrentState = pSfOMXComponent->state;
  1972. if (comCurrentState == pCmd->nParam)
  1973. {
  1974. LOG(SF_LOG_DEBUG, "same state %d\r\n", pCmd->nParam);
  1975. pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData,
  1976. OMX_EventError, OMX_ErrorSameState, pCmd->nParam, NULL);
  1977. break;
  1978. }
  1979. ret = OMX_ErrorNone;
  1980. switch (pCmd->nParam)
  1981. {
  1982. case OMX_StateInvalid:
  1983. switch (comCurrentState)
  1984. {
  1985. case OMX_StateExecuting:
  1986. // enqueue null mean encoder thread cycle end
  1987. pSfCodaj12Implement->bThreadRunning = 0;
  1988. data.msg_type = 1;
  1989. data.msg_flag = OMX_BUFFERFLAG_EOS;
  1990. data.pBuffer = NULL;
  1991. LOG(SF_LOG_DEBUG, "Send to message queue\r\n");
  1992. if (msgsnd(pSfCodaj12Implement->sOutputMessageQueue, (void *)&data, sizeof(data) - sizeof(data.msg_type), 0) == -1)
  1993. {
  1994. LOG(SF_LOG_ERR, "msgsnd failed\n");
  1995. }
  1996. if (msgsnd(pSfCodaj12Implement->sInputMessageQueue, (void *)&data, sizeof(data) - sizeof(data.msg_type), 0) == -1)
  1997. {
  1998. LOG(SF_LOG_ERR, "msgsnd failed\n");
  1999. }
  2000. pthread_join(pSfCodaj12Implement->pProcessThread->pthread, &ThreadRet);
  2001. case OMX_StateIdle:
  2002. case OMX_StatePause:
  2003. case OMX_StateLoaded:
  2004. case OMX_StateWaitForResources:
  2005. default:
  2006. pSfOMXComponent->state = OMX_StateInvalid;
  2007. break;
  2008. }
  2009. ret = OMX_ErrorInvalidState;
  2010. break;
  2011. case OMX_StateLoaded:
  2012. switch (comCurrentState)
  2013. {
  2014. case OMX_StateWaitForResources:
  2015. break;
  2016. case OMX_StateIdle:
  2017. for (i = 0; i < 2; i++)
  2018. {
  2019. if (pSfOMXComponent->portDefinition[i].bEnabled){
  2020. LOG(SF_LOG_INFO,"unload SemaphoreWait \r\n");
  2021. SF_SemaphoreWait(pSfOMXComponent->portUnloadSemaphore[i]);
  2022. LOG(SF_LOG_INFO,"unload SemaphoreWait out\r\n");
  2023. }
  2024. }
  2025. if (pSfCodaj12Implement->feeder){
  2026. pSfCodaj12Implement->functions->BitstreamFeeder_Destroy(pSfCodaj12Implement->feeder);
  2027. pSfCodaj12Implement->feeder = NULL;
  2028. }
  2029. if(pSfCodaj12Implement->allocBufFlag == OMX_TRUE)
  2030. {
  2031. pSfCodaj12Implement->functions->FreeFrameBuffer(pSfCodaj12Implement->instIdx);
  2032. pSfCodaj12Implement->allocBufFlag = OMX_FALSE;
  2033. }
  2034. if (pSfCodaj12Implement->vbStream.phys_addr)
  2035. pSfCodaj12Implement->functions->jdi_free_dma_memory(&pSfCodaj12Implement->vbStream);
  2036. pSfCodaj12Implement->functions->JPU_DeInit();
  2037. break;
  2038. default:
  2039. ret = OMX_ErrorIncorrectStateTransition;
  2040. break;
  2041. }
  2042. break;
  2043. case OMX_StateIdle:
  2044. if (comCurrentState == OMX_StatePause)
  2045. {
  2046. comCurrentState = pSfOMXComponent->stateBeforePause;
  2047. }
  2048. switch (comCurrentState)
  2049. {
  2050. case OMX_StateLoaded:
  2051. ret = InitDecoder(pSfOMXComponent);
  2052. if (ret != OMX_ErrorNone)
  2053. {
  2054. break;
  2055. }
  2056. for (i = 0; i < 2; i++)
  2057. {
  2058. if (pSfOMXComponent->portDefinition[i].bEnabled){
  2059. LOG(SF_LOG_INFO,"SemaphoreWait \r\n");
  2060. SF_SemaphoreWait(pSfOMXComponent->portSemaphore[i]);
  2061. LOG(SF_LOG_INFO,"SemaphoreWait out\r\n");
  2062. }
  2063. }
  2064. break;
  2065. case OMX_StateExecuting:
  2066. pSfCodaj12Implement->bThreadRunning = 0;
  2067. data.msg_type = 1;
  2068. data.msg_flag = OMX_BUFFERFLAG_EOS;
  2069. data.pBuffer = NULL;
  2070. LOG(SF_LOG_DEBUG, "Send to message queue\r\n");
  2071. if (msgsnd(pSfCodaj12Implement->sOutputMessageQueue, (void *)&data, sizeof(data) - sizeof(data.msg_type), 0) == -1)
  2072. {
  2073. LOG(SF_LOG_ERR, "msgsnd failed\n");
  2074. }
  2075. if (msgsnd(pSfCodaj12Implement->sInputMessageQueue, (void *)&data, sizeof(data) - sizeof(data.msg_type), 0) == -1)
  2076. {
  2077. LOG(SF_LOG_ERR, "msgsnd failed\n");
  2078. }
  2079. pthread_join(pSfCodaj12Implement->pProcessThread->pthread, &ThreadRet);
  2080. LOG(SF_LOG_INFO, "Encoder thread end %ld\r\n", (Uint64)ThreadRet);
  2081. CodaJ12FlushBuffer(pSfOMXComponent,OMX_INPUT_PORT_INDEX);
  2082. CodaJ12FlushBuffer(pSfOMXComponent,OMX_OUTPUT_PORT_INDEX);
  2083. break;
  2084. case OMX_StateIdle:
  2085. pSfCodaj12Implement->bPause = OMX_FALSE;
  2086. break;
  2087. default:
  2088. ret = OMX_ErrorIncorrectStateTransition;
  2089. break;
  2090. }
  2091. break;
  2092. case OMX_StateWaitForResources:
  2093. switch (comCurrentState)
  2094. {
  2095. case OMX_StateLoaded:
  2096. break;
  2097. default:
  2098. ret = OMX_ErrorIncorrectStateTransition;
  2099. break;
  2100. }
  2101. break;
  2102. case OMX_StateExecuting:
  2103. if (comCurrentState == OMX_StatePause)
  2104. {
  2105. comCurrentState = pSfOMXComponent->stateBeforePause;
  2106. }
  2107. switch (comCurrentState)
  2108. {
  2109. case OMX_StateIdle:
  2110. pSfCodaj12Implement->bThreadRunning = OMX_TRUE;
  2111. pSfCodaj12Implement->bPause =OMX_FALSE;
  2112. CreateThread(&pSfCodaj12Implement->pProcessThread, ProcessThread, (void *)pSfOMXComponent);
  2113. break;
  2114. case OMX_StateExecuting:
  2115. pSfCodaj12Implement->bPause = OMX_FALSE;
  2116. SF_SemaphorePost(pSfCodaj12Implement->pauseOutSemaphore);
  2117. break;
  2118. default:
  2119. ret = OMX_ErrorIncorrectStateTransition;
  2120. break;
  2121. }
  2122. break;
  2123. case OMX_StatePause:
  2124. switch (comCurrentState)
  2125. {
  2126. case OMX_StateIdle:
  2127. case OMX_StateExecuting:
  2128. pSfCodaj12Implement->bPause = OMX_TRUE;
  2129. pSfOMXComponent->stateBeforePause = comCurrentState;
  2130. break;
  2131. default:
  2132. ret = OMX_ErrorIncorrectStateTransition;
  2133. break;
  2134. }
  2135. break;
  2136. default:
  2137. ret = OMX_ErrorIncorrectStateTransition;
  2138. break;
  2139. }
  2140. if (ret == OMX_ErrorNone)
  2141. {
  2142. pSfOMXComponent->state = pCmd->nParam;
  2143. pSfOMXComponent->traningState = OMX_TransStateInvalid;
  2144. pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData,
  2145. OMX_EventCmdComplete, OMX_CommandStateSet, pCmd->nParam, NULL);
  2146. LOG(SF_LOG_DEBUG, "complete cmd StateSet %d\r\n", pCmd->nParam);
  2147. if (pSfOMXComponent->state == OMX_StateExecuting)
  2148. {
  2149. ppBuffer = SF_Queue_Dequeue(pSfCodaj12Implement->outPauseQ);
  2150. while (ppBuffer)
  2151. {
  2152. pOMXBuffer = *ppBuffer;
  2153. pSfOMXComponent->callbacks->FillBufferDone(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData, pOMXBuffer);
  2154. pSfOMXComponent->handlingBufferNum[1]--;
  2155. ppBuffer = SF_Queue_Dequeue(pSfCodaj12Implement->outPauseQ);
  2156. }
  2157. ppBuffer = SF_Queue_Dequeue(pSfCodaj12Implement->inPauseQ);
  2158. while (ppBuffer)
  2159. {
  2160. pOMXBuffer = *ppBuffer;
  2161. pSfOMXComponent->callbacks->EmptyBufferDone(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData, pOMXBuffer);
  2162. pSfOMXComponent->handlingBufferNum[0]--;
  2163. ppBuffer = SF_Queue_Dequeue(pSfCodaj12Implement->inPauseQ);
  2164. }
  2165. }
  2166. }
  2167. else
  2168. {
  2169. pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData,
  2170. OMX_EventError, ret, 0, NULL);
  2171. LOG(SF_LOG_DEBUG, "Can't go to state %d from %d, ret %X \r\n",pCmd->nParam, pSfOMXComponent->state, ret);
  2172. }
  2173. break;
  2174. case OMX_CommandFlush:
  2175. {
  2176. LOG(SF_LOG_INFO, "flush port %d\r\n", pCmd->nParam);
  2177. OMX_U32 nPort = pCmd->nParam;
  2178. cnt = (pCmd->nParam == OMX_ALL) ? 2 : 1;
  2179. for (i = 0; i < cnt; i++) {
  2180. if (pCmd->nParam == OMX_ALL)
  2181. nPort = i;
  2182. else
  2183. nPort = pCmd->nParam;
  2184. if (nPort == 0)
  2185. {
  2186. pSfOMXComponent->bPortFlushing[0] = OMX_TRUE;
  2187. CodaJ12FlushBuffer(pSfOMXComponent, nPort);
  2188. if (pSfOMXComponent->state == OMX_StatePause)
  2189. {
  2190. ppBuffer = SF_Queue_Dequeue(pSfCodaj12Implement->inPauseQ);
  2191. while (ppBuffer)
  2192. {
  2193. pOMXBuffer = *ppBuffer;
  2194. pSfOMXComponent->callbacks->EmptyBufferDone(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData, pOMXBuffer);
  2195. pSfOMXComponent->handlingBufferNum[0]--;
  2196. if((pSfOMXComponent->handlingBufferNum[0] == 0) && pSfOMXComponent->bPortFlushing[0])
  2197. {
  2198. LOG(SF_LOG_INFO, "return all input buff\r\n");
  2199. SF_SemaphorePost(pSfOMXComponent->portFlushSemaphore[0]);
  2200. }
  2201. ppBuffer = SF_Queue_Dequeue(pSfCodaj12Implement->inPauseQ);
  2202. }
  2203. }
  2204. if(pSfOMXComponent->handlingBufferNum[0] > 0)
  2205. SF_SemaphoreWait(pSfOMXComponent->portFlushSemaphore[0]);
  2206. pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData,
  2207. OMX_EventCmdComplete, OMX_CommandFlush, nPort, NULL);
  2208. pSfOMXComponent->bPortFlushing[0] = OMX_FALSE;
  2209. }
  2210. else
  2211. {
  2212. pSfOMXComponent->bPortFlushing[1] = OMX_TRUE;
  2213. CodaJ12FlushBuffer(pSfOMXComponent, nPort);
  2214. if (pSfOMXComponent->state == OMX_StatePause)
  2215. {
  2216. ppBuffer = SF_Queue_Dequeue(pSfCodaj12Implement->outPauseQ);
  2217. while (ppBuffer)
  2218. {
  2219. pOMXBuffer = *ppBuffer;
  2220. pSfOMXComponent->callbacks->FillBufferDone(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData, pOMXBuffer);
  2221. pSfOMXComponent->handlingBufferNum[1]--;
  2222. if((pSfOMXComponent->handlingBufferNum[1] == 0) && pSfOMXComponent->bPortFlushing[1])
  2223. {
  2224. LOG(SF_LOG_INFO, "return all out buff\r\n");
  2225. SF_SemaphorePost(pSfOMXComponent->portFlushSemaphore[1]);
  2226. }
  2227. ppBuffer = SF_Queue_Dequeue(pSfCodaj12Implement->outPauseQ);
  2228. }
  2229. }
  2230. if(pSfOMXComponent->handlingBufferNum[1] > 0)
  2231. SF_SemaphoreWait(pSfOMXComponent->portFlushSemaphore[1]);
  2232. pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData,
  2233. OMX_EventCmdComplete, OMX_CommandFlush, nPort, NULL);
  2234. pSfOMXComponent->bPortFlushing[1] = OMX_FALSE;
  2235. }
  2236. }
  2237. }
  2238. break;
  2239. case OMX_CommandPortDisable:
  2240. {
  2241. LOG(SF_LOG_INFO, "disable port %d\r\n", pCmd->nParam);
  2242. OMX_U32 nPort;
  2243. cnt = (pCmd->nParam == OMX_ALL) ? 2 : 1;
  2244. for (i = 0; i < cnt; i++) {
  2245. if (pCmd->nParam == OMX_ALL)
  2246. nPort = i;
  2247. else
  2248. nPort = pCmd->nParam;
  2249. CodaJ12FlushBuffer(pSfOMXComponent, nPort);
  2250. }
  2251. for (i = 0; i < cnt; i++) {
  2252. if (pCmd->nParam == OMX_ALL)
  2253. nPort = i;
  2254. else
  2255. nPort = pCmd->nParam;
  2256. if (pSfOMXComponent->state != OMX_StateLoaded)
  2257. SF_SemaphoreWait(pSfOMXComponent->portUnloadSemaphore[nPort]);
  2258. pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData,
  2259. OMX_EventCmdComplete, OMX_CommandPortDisable, nPort, NULL);
  2260. }
  2261. }
  2262. break;
  2263. case OMX_CommandPortEnable:
  2264. {
  2265. LOG(SF_LOG_INFO, "enable port %d\r\n", pCmd->nParam);
  2266. OMX_U32 nPort;
  2267. cnt = (pCmd->nParam == OMX_ALL) ? 2 : 1;
  2268. for (i = 0; i < cnt; i++) {
  2269. if (pCmd->nParam == OMX_ALL)
  2270. nPort = i;
  2271. else
  2272. nPort = pCmd->nParam;
  2273. if ((pSfOMXComponent->state != OMX_StateLoaded) &&
  2274. (pSfOMXComponent->state != OMX_StateWaitForResources))
  2275. SF_SemaphoreWait(pSfOMXComponent->portSemaphore[nPort]);
  2276. pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData,
  2277. OMX_EventCmdComplete, OMX_CommandPortEnable, nPort, NULL);
  2278. }
  2279. }
  2280. break;
  2281. case OMX_CommandMarkBuffer:
  2282. {
  2283. LOG(SF_LOG_INFO, "set mark %d\r\n", pCmd->nParam);
  2284. OMX_U32 nPort;
  2285. nPort = pCmd->nParam;
  2286. pSfOMXComponent->markType[nPort].hMarkTargetComponent =
  2287. ((OMX_MARKTYPE *)pCmd->pCmdData)->hMarkTargetComponent;
  2288. pSfOMXComponent->markType[nPort].pMarkData =
  2289. ((OMX_MARKTYPE *)pCmd->pCmdData)->pMarkData;
  2290. }
  2291. break;
  2292. default:
  2293. break;
  2294. }
  2295. }
  2296. pthread_exit(NULL);
  2297. }
  2298. static OMX_ERRORTYPE SF_OMX_GetComponentVersion(
  2299. OMX_IN OMX_HANDLETYPE hComponent,
  2300. OMX_OUT OMX_STRING pComponentName,
  2301. OMX_OUT OMX_VERSIONTYPE *pComponentVersion,
  2302. OMX_OUT OMX_VERSIONTYPE *pSpecVersion,
  2303. OMX_OUT OMX_UUIDTYPE *pComponentUUID)
  2304. {
  2305. OMX_ERRORTYPE ret = OMX_ErrorNone;
  2306. OMX_COMPONENTTYPE *pOMXComponent = NULL;
  2307. SF_OMX_COMPONENT *pSfOMXComponent = NULL;
  2308. OMX_U32 compUUID[4];
  2309. FunctionIn();
  2310. /* check parameters */
  2311. if (hComponent == NULL ||
  2312. pComponentName == NULL || pComponentVersion == NULL ||
  2313. pSpecVersion == NULL || pComponentUUID == NULL) {
  2314. ret = OMX_ErrorBadParameter;
  2315. goto EXIT;
  2316. }
  2317. pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
  2318. if (pOMXComponent->pComponentPrivate == NULL) {
  2319. ret = OMX_ErrorBadParameter;
  2320. goto EXIT;
  2321. }
  2322. pSfOMXComponent = (SF_OMX_COMPONENT *)pOMXComponent->pComponentPrivate;
  2323. if (pSfOMXComponent->state == OMX_StateInvalid) {
  2324. ret = OMX_ErrorInvalidState;
  2325. goto EXIT;
  2326. }
  2327. strcpy(pComponentName, pSfOMXComponent->componentName);
  2328. memcpy(pComponentVersion, &(pSfOMXComponent->componentVersion), sizeof(OMX_VERSIONTYPE));
  2329. memcpy(pSpecVersion, &(pSfOMXComponent->specVersion), sizeof(OMX_VERSIONTYPE));
  2330. /* Fill UUID with handle address, PID and UID.
  2331. * This should guarantee uiniqness */
  2332. compUUID[0] = (OMX_U32)getpid();
  2333. compUUID[1] = (OMX_U32)getpid();
  2334. compUUID[2] = (OMX_U32)getpid();
  2335. compUUID[3] = (OMX_U32)getpid();
  2336. //compUUID[1] = getpid();
  2337. //compUUID[2] = getuid();
  2338. memcpy(*pComponentUUID, compUUID, 4 * sizeof(*compUUID));
  2339. ret = OMX_ErrorNone;
  2340. EXIT:
  2341. FunctionOut();
  2342. return ret;
  2343. }
  2344. static OMX_ERRORTYPE SF_OMX_ComponentTunnelRequest(
  2345. OMX_IN OMX_HANDLETYPE hComp,
  2346. OMX_IN OMX_U32 nPort,
  2347. OMX_IN OMX_HANDLETYPE hTunneledComp,
  2348. OMX_IN OMX_U32 nTunneledPort,
  2349. OMX_INOUT OMX_TUNNELSETUPTYPE *pTunnelSetup)
  2350. {
  2351. OMX_ERRORTYPE ret = OMX_ErrorNone;
  2352. (void) hComp;
  2353. (void) nPort;
  2354. (void) hTunneledComp;
  2355. (void) nTunneledPort;
  2356. (void) pTunnelSetup;
  2357. ret = OMX_ErrorTunnelingUnsupported;
  2358. goto EXIT;
  2359. EXIT:
  2360. return ret;
  2361. }
  2362. static OMX_ERRORTYPE SF_OMX_UseEGLImage(
  2363. OMX_IN OMX_HANDLETYPE hComponent,
  2364. OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
  2365. OMX_IN OMX_U32 nPortIndex,
  2366. OMX_IN OMX_PTR pAppPrivate,
  2367. OMX_IN void* eglImage)
  2368. {
  2369. return OMX_ErrorNotImplemented;
  2370. }
  2371. static OMX_U32 nInstance = 0;
  2372. static OMX_ERRORTYPE SF_OMX_ComponentConstructor(SF_OMX_COMPONENT *pSfOMXComponent)
  2373. {
  2374. OMX_ERRORTYPE ret = OMX_ErrorNone;
  2375. SF_CODAJ12_IMPLEMEMT *pSfCodaj12Implement;
  2376. FunctionIn();
  2377. if (nInstance >= 1)
  2378. {
  2379. ret = OMX_ErrorInsufficientResources;
  2380. goto EXIT;
  2381. }
  2382. nInstance++;
  2383. ret = InitMjpegStructorCommon(pSfOMXComponent);
  2384. if (ret != OMX_ErrorNone)
  2385. {
  2386. nInstance--;
  2387. goto EXIT;
  2388. }
  2389. pSfOMXComponent->pOMXComponent->UseBuffer = &SF_OMX_UseBuffer;
  2390. pSfOMXComponent->pOMXComponent->AllocateBuffer = &SF_OMX_AllocateBuffer;
  2391. pSfOMXComponent->pOMXComponent->EmptyThisBuffer = &SF_OMX_EmptyThisBuffer;
  2392. pSfOMXComponent->pOMXComponent->FillThisBuffer = &SF_OMX_FillThisBuffer;
  2393. pSfOMXComponent->pOMXComponent->FreeBuffer = &SF_OMX_FreeBuffer;
  2394. pSfOMXComponent->pOMXComponent->ComponentTunnelRequest = &SF_OMX_ComponentTunnelRequest;
  2395. pSfOMXComponent->pOMXComponent->GetParameter = &SF_OMX_GetParameter;
  2396. pSfOMXComponent->pOMXComponent->SetParameter = &SF_OMX_SetParameter;
  2397. pSfOMXComponent->pOMXComponent->GetConfig = &SF_OMX_GetConfig;
  2398. pSfOMXComponent->pOMXComponent->SetConfig = &SF_OMX_SetConfig;
  2399. pSfOMXComponent->pOMXComponent->SendCommand = &SF_OMX_SendCommand;
  2400. pSfOMXComponent->pOMXComponent->GetState = &SF_OMX_GetState;
  2401. pSfOMXComponent->pOMXComponent->GetComponentVersion = &SF_OMX_GetComponentVersion;
  2402. pSfOMXComponent->pOMXComponent->UseEGLImage = &SF_OMX_UseEGLImage;
  2403. // pSfOMXComponent->pOMXComponent->GetExtensionIndex = &SF_OMX_GetExtensionIndex;
  2404. // pSfOMXComponent->pOMXComponent->ComponentRoleEnum = &SF_OMX_ComponentRoleEnum;
  2405. // pSfOMXComponent->pOMXComponent->ComponentDeInit = &SF_OMX_ComponentDeInit;
  2406. pSfCodaj12Implement = pSfOMXComponent->componentImpl;
  2407. pSfCodaj12Implement->currentState = OMX_StateLoaded;
  2408. pSfCodaj12Implement->CmdQueue = SF_Queue_Create(20, sizeof(DEC_CMD));
  2409. if (NULL == pSfCodaj12Implement->CmdQueue)
  2410. {
  2411. LOG(SF_LOG_ERR, "create CmdQueue error");
  2412. nInstance--;
  2413. return OMX_ErrorInsufficientResources;
  2414. }
  2415. pSfCodaj12Implement->outPauseQ = SF_Queue_Create(20, sizeof(OMX_BUFFERHEADERTYPE*));
  2416. if (NULL == pSfCodaj12Implement->outPauseQ)
  2417. {
  2418. LOG(SF_LOG_ERR, "create outPauseQ error");
  2419. nInstance--;
  2420. return OMX_ErrorInsufficientResources;
  2421. }
  2422. pSfCodaj12Implement->inPauseQ = SF_Queue_Create(20, sizeof(OMX_BUFFERHEADERTYPE*));
  2423. if (NULL == pSfCodaj12Implement->inPauseQ)
  2424. {
  2425. LOG(SF_LOG_ERR, "create inPauseQ error");
  2426. nInstance--;
  2427. return OMX_ErrorInsufficientResources;
  2428. }
  2429. CreateThread(&pSfCodaj12Implement->pCmdThread, CmdThread, (void *)pSfOMXComponent);
  2430. pSfCodaj12Implement->bCmdRunning = OMX_TRUE;
  2431. //InitDecoder(pSfOMXComponent);
  2432. EXIT:
  2433. FunctionOut();
  2434. return ret;
  2435. }
  2436. static OMX_ERRORTYPE SF_OMX_ComponentClear(SF_OMX_COMPONENT *pSfOMXComponent)
  2437. {
  2438. OMX_ERRORTYPE ret = OMX_ErrorNone;
  2439. SF_CODAJ12_IMPLEMEMT *pSfCodaj12Implement = pSfOMXComponent->componentImpl;
  2440. jpu_buffer_t *vbStream = &pSfCodaj12Implement->vbStream;
  2441. DEC_CMD cmd;
  2442. void *ThreadRet = NULL;
  2443. FunctionIn();
  2444. if (pSfCodaj12Implement->feeder){
  2445. pSfCodaj12Implement->functions->BitstreamFeeder_Destroy(pSfCodaj12Implement->feeder);
  2446. pSfCodaj12Implement->feeder = NULL;
  2447. }
  2448. if(pSfCodaj12Implement->allocBufFlag == OMX_TRUE)
  2449. {
  2450. pSfCodaj12Implement->functions->FreeFrameBuffer(pSfCodaj12Implement->instIdx);
  2451. pSfCodaj12Implement->allocBufFlag = OMX_FALSE;
  2452. }
  2453. if (vbStream->phys_addr)
  2454. pSfCodaj12Implement->functions->jdi_free_dma_memory(vbStream);
  2455. cmd.Cmd = DEC_StopThread;
  2456. SF_Queue_Enqueue(pSfCodaj12Implement->CmdQueue, &cmd);
  2457. pthread_cancel(pSfCodaj12Implement->pCmdThread->pthread);
  2458. pthread_join(pSfCodaj12Implement->pCmdThread->pthread, &ThreadRet);
  2459. LOG(SF_LOG_INFO, "Cmd thread end %ld\r\n", (Uint64)ThreadRet);
  2460. SF_Queue_Destroy(pSfCodaj12Implement->CmdQueue);
  2461. SF_Queue_Destroy(pSfCodaj12Implement->inPauseQ);
  2462. SF_Queue_Destroy(pSfCodaj12Implement->outPauseQ);
  2463. // TODO
  2464. // MjpegClearCommon(hComponent);
  2465. nInstance--;
  2466. FunctionOut();
  2467. return ret;
  2468. }
  2469. //TODO happer
  2470. SF_OMX_COMPONENT sf_dec_decoder_mjpeg = {
  2471. .componentName = "OMX.sf.video_decoder.mjpeg",
  2472. .libName = "libcodadec.so",
  2473. .pOMXComponent = NULL,
  2474. .SF_OMX_ComponentConstructor = SF_OMX_ComponentConstructor,
  2475. .SF_OMX_ComponentClear = SF_OMX_ComponentClear,
  2476. // .functions = NULL,
  2477. // .bitFormat = STD_HEVC,
  2478. .componentImpl = NULL,
  2479. .fwPath = "/lib/firmware/chagall.bin",
  2480. .componentRule = "video_decoder.mjpeg"};