SF_OMX_Mjpeg_decoder.c 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439
  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 <string.h>
  8. #include "SF_OMX_mjpeg_common.h"
  9. #include "SF_OMX_Core.h"
  10. #include <sys/prctl.h>
  11. extern OMX_TICKS gInitTimeStamp;
  12. #define TEMP_DEBUG 1
  13. #define NUM_OF_PORTS 2
  14. static OMX_ERRORTYPE SF_OMX_EmptyThisBuffer(
  15. OMX_IN OMX_HANDLETYPE hComponent,
  16. OMX_IN OMX_BUFFERHEADERTYPE *pBuffer)
  17. {
  18. OMX_ERRORTYPE ret = OMX_ErrorNone;
  19. OMX_BOOL bSendNULL = OMX_FALSE;
  20. OMX_BOOL bSendMessage = OMX_TRUE;
  21. FunctionIn();
  22. if (hComponent == NULL || pBuffer == NULL)
  23. {
  24. ret = OMX_ErrorBadParameter;
  25. goto EXIT;
  26. }
  27. OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
  28. SF_OMX_COMPONENT *pSfOMXComponent = (SF_OMX_COMPONENT *)pOMXComponent->pComponentPrivate;
  29. SF_CODAJ12_IMPLEMEMT *pSfCodaj12Implement = (SF_CODAJ12_IMPLEMEMT *)pSfOMXComponent->componentImpl;
  30. LOG(SF_LOG_DEBUG, "nFilledLen = %d, nFlags = %d, pBuffer = %p\r\n", pBuffer->nFilledLen, pBuffer->nFlags, pBuffer->pBuffer);
  31. if (pBuffer->nFilledLen == 0 || (pBuffer->nFlags & 0x1) == 0x1)
  32. {
  33. bSendNULL = OMX_TRUE;
  34. }
  35. else
  36. {
  37. bSendNULL = OMX_FALSE;
  38. }
  39. if (pBuffer->pBuffer == NULL)
  40. {
  41. bSendMessage = OMX_FALSE;
  42. }
  43. else
  44. {
  45. bSendMessage = OMX_TRUE;
  46. }
  47. Message data;
  48. data.msg_type = 1;
  49. data.msg_flag = 0;
  50. if (bSendMessage)
  51. {
  52. data.pBuffer = pBuffer;
  53. if (msgsnd(pSfCodaj12Implement->sInputMessageQueue, (void *)&data, sizeof(data) - sizeof(data.msg_type), 0) == -1)
  54. {
  55. LOG(SF_LOG_ERR, "msgsnd failed\n");
  56. }
  57. }
  58. if (bSendNULL)
  59. {
  60. data.pBuffer = NULL;
  61. if (msgsnd(pSfCodaj12Implement->sInputMessageQueue, (void *)&data, sizeof(data) - sizeof(data.msg_type), 0) == -1)
  62. {
  63. LOG(SF_LOG_ERR, "msgsnd failed\n");
  64. }
  65. }
  66. EXIT:
  67. FunctionOut();
  68. return ret;
  69. }
  70. #define MAX_INDEX 1
  71. static OMX_ERRORTYPE SF_OMX_FillThisBuffer(
  72. OMX_IN OMX_HANDLETYPE hComponent,
  73. OMX_IN OMX_BUFFERHEADERTYPE *pBuffer)
  74. {
  75. OMX_ERRORTYPE ret = OMX_ErrorNone;
  76. FunctionIn();
  77. if (hComponent == NULL || pBuffer == NULL)
  78. {
  79. ret = OMX_ErrorBadParameter;
  80. goto EXIT;
  81. }
  82. OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
  83. SF_OMX_COMPONENT *pSfOMXComponent = (SF_OMX_COMPONENT *)pOMXComponent->pComponentPrivate;
  84. SF_CODAJ12_IMPLEMEMT *pSfCodaj12Implement = (SF_CODAJ12_IMPLEMEMT *)pSfOMXComponent->componentImpl;
  85. LOG(SF_LOG_DEBUG, "nFilledLen = %d, nFlags = %d, pBuffer = %p\r\n", pBuffer->nFilledLen, pBuffer->nFlags, pBuffer->pBuffer);
  86. // if (pSfCodaj12Implement->functions->Queue_Enqueue(&pSfCodaj12Implement->decodeBufferQueue, (void *)pBuffer->pBuffer) == FALSE)
  87. // {
  88. // return OMX_ErrorInsufficientResources;
  89. // }
  90. Message data;
  91. data.msg_type = 1;
  92. data.msg_flag = 0;
  93. data.pBuffer = pBuffer;
  94. LOG(SF_LOG_DEBUG, "Send to message queue\r\n");
  95. if (msgsnd(pSfCodaj12Implement->sOutputMessageQueue, (void *)&data, sizeof(data) - sizeof(data.msg_type), 0) == -1)
  96. {
  97. LOG(SF_LOG_ERR, "msgsnd failed\n");
  98. }
  99. EXIT:
  100. FunctionOut();
  101. return ret;
  102. }
  103. static OMX_U64 nOutBufIndex = 0;
  104. static OMX_ERRORTYPE SF_OMX_UseBuffer(
  105. OMX_IN OMX_HANDLETYPE hComponent,
  106. OMX_INOUT OMX_BUFFERHEADERTYPE **ppBufferHdr,
  107. OMX_IN OMX_U32 nPortIndex,
  108. OMX_IN OMX_PTR pAppPrivate,
  109. OMX_IN OMX_U32 nSizeBytes,
  110. OMX_IN OMX_U8 *pBuffer)
  111. {
  112. OMX_ERRORTYPE ret = OMX_ErrorNone;
  113. OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
  114. SF_OMX_COMPONENT *pSfOMXComponent = pOMXComponent->pComponentPrivate;
  115. SF_CODAJ12_IMPLEMEMT *pSfCodaj12Implement = pSfOMXComponent->componentImpl;
  116. FunctionIn();
  117. if (hComponent == NULL)
  118. {
  119. ret = OMX_ErrorBadParameter;
  120. goto EXIT;
  121. }
  122. if (AttachOutputBuffer(pSfOMXComponent, pBuffer, nSizeBytes) == OMX_FALSE)
  123. {
  124. LOG(SF_LOG_ERR, "Failed to attach dma buffer\r\n");
  125. return OMX_ErrorInsufficientResources;
  126. }
  127. OMX_BUFFERHEADERTYPE *temp_bufferHeader = (OMX_BUFFERHEADERTYPE *)malloc(sizeof(OMX_BUFFERHEADERTYPE));
  128. if (temp_bufferHeader == NULL)
  129. {
  130. LOG(SF_LOG_ERR, "malloc fail\r\n");
  131. return OMX_ErrorInsufficientResources;
  132. }
  133. memset(temp_bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE));
  134. temp_bufferHeader->nAllocLen = nSizeBytes;
  135. temp_bufferHeader->pAppPrivate = pAppPrivate;
  136. temp_bufferHeader->pBuffer = pBuffer;
  137. *ppBufferHdr = temp_bufferHeader;
  138. if (nPortIndex == 1)
  139. {
  140. temp_bufferHeader->pOutputPortPrivate = (OMX_PTR)nOutBufIndex;
  141. nOutBufIndex ++;
  142. }
  143. LOG(SF_LOG_DEBUG, "pBuffer address = %p, nOutBufIndex = %d\r\n", temp_bufferHeader->pBuffer, (OMX_U64)temp_bufferHeader->pOutputPortPrivate);
  144. pSfCodaj12Implement->allocBufFlag = OMX_FALSE;
  145. EXIT:
  146. FunctionOut();
  147. return ret;
  148. }
  149. static OMX_ERRORTYPE SF_OMX_AllocateBuffer(
  150. OMX_IN OMX_HANDLETYPE hComponent,
  151. OMX_INOUT OMX_BUFFERHEADERTYPE **ppBuffer,
  152. OMX_IN OMX_U32 nPortIndex,
  153. OMX_IN OMX_PTR pAppPrivate,
  154. OMX_IN OMX_U32 nSizeBytes)
  155. {
  156. OMX_ERRORTYPE ret = OMX_ErrorNone;
  157. OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
  158. SF_OMX_COMPONENT *pSfOMXComponent = pOMXComponent->pComponentPrivate;
  159. SF_CODAJ12_IMPLEMEMT *pSfCodaj12Implement = pSfOMXComponent->componentImpl;
  160. FunctionIn();
  161. if (nSizeBytes == 0)
  162. {
  163. LOG(SF_LOG_ERR, "nSizeBytes = %d\r\n", nSizeBytes);
  164. return OMX_ErrorBadParameter;
  165. }
  166. OMX_BUFFERHEADERTYPE *temp_bufferHeader = (OMX_BUFFERHEADERTYPE *)malloc(sizeof(OMX_BUFFERHEADERTYPE));
  167. if (temp_bufferHeader == NULL)
  168. {
  169. LOG(SF_LOG_ERR, "malloc fail\r\n");
  170. return OMX_ErrorInsufficientResources;
  171. }
  172. memset(temp_bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE));
  173. temp_bufferHeader->nAllocLen = nSizeBytes;
  174. temp_bufferHeader->pAppPrivate = pAppPrivate;
  175. if (nPortIndex == 1)
  176. {
  177. temp_bufferHeader->pBuffer = AllocateOutputBuffer(pSfOMXComponent, nSizeBytes);
  178. temp_bufferHeader->pOutputPortPrivate = (OMX_PTR)nOutBufIndex;
  179. nOutBufIndex ++;
  180. pSfCodaj12Implement->allocBufFlag = OMX_TRUE;
  181. // temp_bufferHeader->nFilledLen = nSizeBytes;
  182. }
  183. else if (nPortIndex == 0)
  184. {
  185. jpu_buffer_t *vbStream = &pSfCodaj12Implement->vbStream;
  186. vbStream->size = (nSizeBytes == 0) ? STREAM_BUF_SIZE : nSizeBytes;
  187. vbStream->size = (vbStream->size + 1023) & ~1023; // ceil128(size)
  188. if (pSfCodaj12Implement->functions->jdi_allocate_dma_memory(vbStream) < 0)
  189. {
  190. LOG(SF_LOG_ERR, "fail to allocate bitstream buffer\r\n");
  191. return OMX_ErrorInsufficientResources;
  192. }
  193. temp_bufferHeader->pBuffer = (OMX_U8 *)vbStream->virt_addr;
  194. temp_bufferHeader->pInputPortPrivate = (void *)vbStream->phys_addr;
  195. }
  196. if (temp_bufferHeader->pBuffer == NULL)
  197. {
  198. free(temp_bufferHeader);
  199. LOG(SF_LOG_ERR, "malloc fail\r\n");
  200. return OMX_ErrorInsufficientResources;
  201. }
  202. *ppBuffer = temp_bufferHeader;
  203. LOG(SF_LOG_INFO, "nPortIndex = %d, pBuffer address = %p, nFilledLen = %d, nSizeBytes = %d\r\n",
  204. nPortIndex, temp_bufferHeader->pBuffer, temp_bufferHeader->nFilledLen, nSizeBytes);
  205. FunctionOut();
  206. return ret;
  207. }
  208. static OMX_ERRORTYPE SF_OMX_GetParameter(
  209. OMX_IN OMX_HANDLETYPE hComponent,
  210. OMX_IN OMX_INDEXTYPE nParamIndex,
  211. OMX_INOUT OMX_PTR ComponentParameterStructure)
  212. {
  213. OMX_ERRORTYPE ret = OMX_ErrorNone;
  214. OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
  215. SF_OMX_COMPONENT *pSfOMXComponent = pOMXComponent->pComponentPrivate;
  216. FunctionIn();
  217. if (hComponent == NULL)
  218. {
  219. ret = OMX_ErrorBadParameter;
  220. goto EXIT;
  221. }
  222. if (ComponentParameterStructure == NULL)
  223. {
  224. ret = OMX_ErrorBadParameter;
  225. goto EXIT;
  226. }
  227. LOG(SF_LOG_INFO, "Get parameter on index %X\r\n", nParamIndex);
  228. switch ((OMX_U32)nParamIndex)
  229. {
  230. case OMX_IndexParamImageInit:
  231. case OMX_IndexParamVideoInit:
  232. {
  233. OMX_PORT_PARAM_TYPE *portParam = (OMX_PORT_PARAM_TYPE *)ComponentParameterStructure;
  234. portParam->nPorts = NUM_OF_PORTS;
  235. portParam->nStartPortNumber = OMX_INPUT_PORT_INDEX;
  236. break;
  237. }
  238. case OMX_IndexParamImagePortFormat:
  239. {
  240. OMX_IMAGE_PARAM_PORTFORMATTYPE *portFormat = (OMX_IMAGE_PARAM_PORTFORMATTYPE *)ComponentParameterStructure;
  241. OMX_U32 index = portFormat->nIndex;
  242. switch (index)
  243. {
  244. case OMX_INPUT_PORT_INDEX:
  245. portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused;
  246. portFormat->eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
  247. default:
  248. if (index > 0)
  249. {
  250. ret = OMX_ErrorNoMore;
  251. }
  252. }
  253. break;
  254. }
  255. case OMX_IndexParamPortDefinition:
  256. {
  257. OMX_PARAM_PORTDEFINITIONTYPE *pPortDefinition = (OMX_PARAM_PORTDEFINITIONTYPE *)ComponentParameterStructure;
  258. OMX_U32 portIndex = pPortDefinition->nPortIndex;
  259. OMX_PARAM_PORTDEFINITIONTYPE *pSrcDefinition = &pSfOMXComponent->portDefinition[portIndex];
  260. LOG(SF_LOG_DEBUG, "Get parameter port %X\r\n",portIndex);
  261. LOG_APPEND(SF_LOG_DEBUG, "width = %d, height = %d\r\n", pSrcDefinition->format.video.nFrameWidth, pSrcDefinition->format.video.nFrameHeight);
  262. LOG_APPEND(SF_LOG_DEBUG, "eColorFormat = %d\r\n", pSrcDefinition->format.video.eColorFormat);
  263. LOG_APPEND(SF_LOG_DEBUG, "xFramerate = %d\r\n", pSrcDefinition->format.video.xFramerate);
  264. LOG_APPEND(SF_LOG_DEBUG, "bufferSize = %d\r\n",pSrcDefinition->nBufferSize);
  265. LOG_APPEND(SF_LOG_DEBUG, "Buffer count = %d\r\n", pSrcDefinition->nBufferCountActual);
  266. memcpy(pPortDefinition, pSrcDefinition, pPortDefinition->nSize);
  267. break;
  268. }
  269. case OMX_IndexParamVideoPortFormat:
  270. {
  271. OMX_VIDEO_PARAM_PORTFORMATTYPE *portFormat = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)ComponentParameterStructure;
  272. OMX_U32 index = portFormat->nIndex;
  273. portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused;
  274. portFormat->xFramerate = 30;
  275. LOG(SF_LOG_DEBUG, "Get video format at port %d index %d\r\n",portFormat->nPortIndex, index);
  276. switch (index)
  277. {
  278. case 0:
  279. portFormat->eColorFormat = OMX_COLOR_FormatYUV420Planar;
  280. break;
  281. case 1:
  282. portFormat->eColorFormat = OMX_COLOR_FormatYUV422Planar;
  283. break;
  284. case 2:
  285. portFormat->eColorFormat = OMX_COLOR_FormatYUV444Interleaved;
  286. break;
  287. case 3:
  288. portFormat->eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar; //NV12
  289. break;
  290. case 4:
  291. portFormat->eColorFormat = OMX_COLOR_FormatYVU420SemiPlanar; //NV21
  292. break;
  293. default:
  294. if (index > 0)
  295. {
  296. ret = OMX_ErrorNoMore;
  297. }
  298. }
  299. break;
  300. }
  301. default:
  302. {
  303. ret = OMX_ErrorNotImplemented;
  304. break;
  305. }
  306. }
  307. EXIT:
  308. FunctionOut();
  309. return ret;
  310. }
  311. static OMX_ERRORTYPE SF_OMX_SetParameter(
  312. OMX_IN OMX_HANDLETYPE hComponent,
  313. OMX_IN OMX_INDEXTYPE nIndex,
  314. OMX_IN OMX_PTR ComponentParameterStructure)
  315. {
  316. OMX_ERRORTYPE ret = OMX_ErrorNone;
  317. FunctionIn();
  318. if (hComponent == NULL)
  319. {
  320. ret = OMX_ErrorBadParameter;
  321. goto EXIT;
  322. }
  323. if (ComponentParameterStructure == NULL)
  324. {
  325. ret = OMX_ErrorBadParameter;
  326. goto EXIT;
  327. }
  328. LOG(SF_LOG_INFO, "Set parameter on index %X\r\n", nIndex);
  329. OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
  330. SF_OMX_COMPONENT *pSfOMXComponent = pOMXComponent->pComponentPrivate;
  331. SF_CODAJ12_IMPLEMEMT *pSfMjpegImplement = (SF_CODAJ12_IMPLEMEMT *)pSfOMXComponent->componentImpl;
  332. if (pSfOMXComponent == NULL)
  333. {
  334. ret = OMX_ErrorBadParameter;
  335. goto EXIT;
  336. }
  337. switch ((OMX_U32)nIndex)
  338. {
  339. case OMX_IndexParamPortDefinition:
  340. {
  341. OMX_PARAM_PORTDEFINITIONTYPE *pPortDefinition =
  342. (OMX_PARAM_PORTDEFINITIONTYPE *)ComponentParameterStructure;
  343. OMX_PARAM_PORTDEFINITIONTYPE *pInputPort = &pSfOMXComponent->portDefinition[0];
  344. OMX_PARAM_PORTDEFINITIONTYPE *pOutputPort = &pSfOMXComponent->portDefinition[1];
  345. DecConfigParam *decConfig = pSfMjpegImplement->config;
  346. OMX_U32 portIndex = pPortDefinition->nPortIndex;
  347. OMX_U32 width = pPortDefinition->format.video.nFrameWidth;
  348. OMX_U32 height = pPortDefinition->format.video.nFrameHeight;
  349. LOG(SF_LOG_INFO, "Set parameter on port %d\r\n", pPortDefinition->nPortIndex);
  350. LOG_APPEND(SF_LOG_DEBUG, "width = %d, height = %d\r\n",width, height);
  351. LOG_APPEND(SF_LOG_DEBUG, "eColorFormat = %d\r\n", pPortDefinition->format.video.eColorFormat);
  352. LOG_APPEND(SF_LOG_DEBUG, "xFramerate = %d\r\n", pPortDefinition->format.video.xFramerate);
  353. LOG_APPEND(SF_LOG_DEBUG, "bufferSize = %d\r\n",pPortDefinition->nBufferSize);
  354. LOG_APPEND(SF_LOG_DEBUG, "Buffer count = %d\r\n", pPortDefinition->nBufferCountActual);
  355. if (portIndex == (OMX_U32)OMX_INPUT_PORT_INDEX)
  356. {
  357. memcpy(&pSfOMXComponent->portDefinition[portIndex], pPortDefinition, pPortDefinition->nSize);
  358. pInputPort->format.video.nStride = width;
  359. pInputPort->format.video.nSliceHeight = height;
  360. pInputPort->nBufferSize = width * height * 2;
  361. }
  362. else if (portIndex == (OMX_U32)(OMX_OUTPUT_PORT_INDEX))
  363. {
  364. memcpy(&pSfOMXComponent->portDefinition[portIndex], pPortDefinition, pPortDefinition->nSize);
  365. /*
  366. Some client may set '0' or '1' to output port, in this case use input port parameters
  367. */
  368. if (width <= 1)
  369. {
  370. width = pInputPort->format.video.nFrameWidth;
  371. }
  372. if (height <= 1)
  373. {
  374. height = pInputPort->format.video.nFrameHeight;
  375. }
  376. if (width > 0 && height > 0)
  377. {
  378. int scalew = pInputPort->format.video.nFrameWidth / width;
  379. int scaleh = pInputPort->format.video.nFrameHeight / height;
  380. if (scalew > 8 || scaleh > 8 || scalew < 1 || scaleh < 1)
  381. {
  382. int nInputWidth = pInputPort->format.video.nFrameWidth;
  383. int nInputHeight = pInputPort->format.video.nFrameHeight;
  384. LOG(SF_LOG_WARN, "Scaling should be 1 to 1/8 (down-scaling only)! Use input parameter. "
  385. "OutPut[%d, %d]. Input[%d, %d]\r\n",
  386. width, height, nInputWidth, nInputHeight);
  387. width = nInputWidth;
  388. height = nInputHeight;
  389. }
  390. pOutputPort->format.video.nFrameWidth = width;
  391. pOutputPort->format.video.nFrameHeight = height;
  392. pOutputPort->format.video.nStride = width;
  393. pOutputPort->format.video.nSliceHeight = height;
  394. switch (pOutputPort->format.video.eColorFormat)
  395. {
  396. case OMX_COLOR_FormatYUV420Planar:
  397. decConfig->cbcrInterleave = CBCR_SEPARATED;
  398. decConfig->packedFormat = PACKED_FORMAT_NONE;
  399. pOutputPort->nBufferSize = (width * height * 3) / 2;
  400. break;
  401. case OMX_COLOR_FormatYUV420SemiPlanar: //NV12
  402. decConfig->cbcrInterleave = CBCR_INTERLEAVE;
  403. decConfig->packedFormat = PACKED_FORMAT_NONE;
  404. pOutputPort->nBufferSize = (width * height * 3) / 2;
  405. break;
  406. case OMX_COLOR_FormatYVU420SemiPlanar: //NV21
  407. decConfig->cbcrInterleave = CRCB_INTERLEAVE;
  408. decConfig->packedFormat = PACKED_FORMAT_NONE;
  409. pOutputPort->nBufferSize = (width * height * 3) / 2;
  410. break;
  411. case OMX_COLOR_FormatYUV422Planar:
  412. pOutputPort->nBufferSize = width * height * 2;
  413. break;
  414. case OMX_COLOR_FormatYUV444Interleaved:
  415. pOutputPort->nBufferSize = width * height * 3;
  416. break;
  417. default:
  418. pOutputPort->nBufferSize = width * height * 4;
  419. break;
  420. }
  421. }
  422. }
  423. else
  424. {
  425. ret = OMX_ErrorNoMore;
  426. }
  427. break;
  428. }
  429. case OMX_IndexParamVideoPortFormat:
  430. {
  431. OMX_VIDEO_PARAM_PORTFORMATTYPE *portFormat = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)ComponentParameterStructure;
  432. OMX_U32 nPortIndex = portFormat->nPortIndex;
  433. OMX_PARAM_PORTDEFINITIONTYPE *pPort = &pSfOMXComponent->portDefinition[nPortIndex];
  434. DecConfigParam *decConfig = pSfMjpegImplement->config;
  435. LOG(SF_LOG_DEBUG, "Set video format to port %d color %d\r\n", portFormat->nPortIndex, portFormat->eColorFormat);
  436. switch (portFormat->eColorFormat)
  437. {
  438. case OMX_COLOR_FormatYUV420Planar:
  439. decConfig->cbcrInterleave = CBCR_SEPARATED;
  440. decConfig->packedFormat = PACKED_FORMAT_NONE;
  441. pSfMjpegImplement->frameFormat = FORMAT_420;
  442. pPort->format.video.eColorFormat = portFormat->eColorFormat;
  443. break;
  444. case OMX_COLOR_FormatYUV420SemiPlanar: //NV12
  445. decConfig->cbcrInterleave = CBCR_INTERLEAVE;
  446. decConfig->packedFormat = PACKED_FORMAT_NONE;
  447. pSfMjpegImplement->frameFormat = FORMAT_420;
  448. pPort->format.video.eColorFormat = portFormat->eColorFormat;
  449. break;
  450. case OMX_COLOR_FormatYVU420SemiPlanar: //NV21
  451. decConfig->cbcrInterleave = CRCB_INTERLEAVE;
  452. decConfig->packedFormat = PACKED_FORMAT_NONE;
  453. pSfMjpegImplement->frameFormat = FORMAT_420;
  454. pPort->format.video.eColorFormat = portFormat->eColorFormat;
  455. break;
  456. case OMX_COLOR_FormatYUV422Planar:
  457. pSfMjpegImplement->frameFormat = FORMAT_422;
  458. pPort->format.video.eColorFormat = portFormat->eColorFormat;
  459. break;
  460. case OMX_COLOR_FormatYUV444Interleaved:
  461. pSfMjpegImplement->frameFormat = FORMAT_444;
  462. pPort->format.video.eColorFormat = portFormat->eColorFormat;
  463. break;
  464. default:
  465. ret = OMX_ErrorNotImplemented;
  466. break;
  467. }
  468. }
  469. case OMX_IndexParamVideoInit:
  470. {
  471. OMX_PORT_PARAM_TYPE *portParam = (OMX_PORT_PARAM_TYPE *)ComponentParameterStructure;
  472. portParam->nPorts = 2;
  473. portParam->nStartPortNumber = 0;
  474. break;
  475. }
  476. case OMX_IndexParamImagePortFormat:
  477. break;
  478. default:
  479. break;
  480. }
  481. EXIT:
  482. FunctionOut();
  483. return ret;
  484. }
  485. static OMX_ERRORTYPE SF_OMX_GetConfig(
  486. OMX_HANDLETYPE hComponent,
  487. OMX_INDEXTYPE nIndex,
  488. OMX_PTR pComponentConfigStructure)
  489. {
  490. OMX_ERRORTYPE ret = OMX_ErrorNone;
  491. FunctionIn();
  492. if (hComponent == NULL)
  493. {
  494. ret = OMX_ErrorBadParameter;
  495. goto EXIT;
  496. }
  497. if (pComponentConfigStructure == NULL)
  498. {
  499. ret = OMX_ErrorBadParameter;
  500. goto EXIT;
  501. }
  502. LOG(SF_LOG_INFO, "Get config on index %X\r\n", nIndex);
  503. OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
  504. SF_OMX_COMPONENT *pSfOMXComponent = pOMXComponent->pComponentPrivate;
  505. SF_CODAJ12_IMPLEMEMT *pSfMjpegImplement = (SF_CODAJ12_IMPLEMEMT *)pSfOMXComponent->componentImpl;
  506. switch ((OMX_U32)nIndex)
  507. {
  508. case OMX_IndexConfigCommonOutputCrop:
  509. {
  510. OMX_CONFIG_RECTTYPE *rectParam = (OMX_CONFIG_RECTTYPE *)pComponentConfigStructure;
  511. DecConfigParam *decConfig = pSfMjpegImplement->config;
  512. if(rectParam->nPortIndex == (OMX_U32)(OMX_OUTPUT_PORT_INDEX))
  513. {
  514. rectParam->nLeft = decConfig->roiOffsetX;
  515. rectParam->nTop = decConfig->roiOffsetY;
  516. rectParam->nWidth = decConfig->roiWidth;
  517. rectParam->nHeight = decConfig->roiHeight;
  518. LOG(SF_LOG_INFO, "Get OutputCrop left %d top %d width %d height %d \r\n",
  519. decConfig->roiOffsetX, decConfig->roiOffsetY, decConfig->roiWidth, decConfig->roiHeight);
  520. }
  521. else
  522. {
  523. LOG(SF_LOG_WARN, "Only output port support OutputCrop param\r\n");
  524. ret = OMX_ErrorBadParameter;
  525. }
  526. break;
  527. }
  528. case OMX_IndexConfigCommonRotate:
  529. {
  530. OMX_CONFIG_ROTATIONTYPE *rotatParam = (OMX_CONFIG_ROTATIONTYPE *)pComponentConfigStructure;
  531. DecConfigParam *decConfig = pSfMjpegImplement->config;
  532. if(rotatParam->nPortIndex == (OMX_U32)(OMX_OUTPUT_PORT_INDEX))
  533. {
  534. rotatParam->nRotation = decConfig->rotation;
  535. LOG(SF_LOG_INFO, "Get Rotation %d \r\n", decConfig->rotation);
  536. }
  537. else
  538. {
  539. LOG(SF_LOG_WARN, "Only output port support Rotation config\r\n");
  540. ret = OMX_ErrorBadParameter;
  541. }
  542. break;
  543. }
  544. case OMX_IndexConfigCommonMirror:
  545. {
  546. OMX_CONFIG_MIRRORTYPE *mirrParam = (OMX_CONFIG_MIRRORTYPE *)pComponentConfigStructure;
  547. DecConfigParam *decConfig = pSfMjpegImplement->config;
  548. if(mirrParam->nPortIndex == (OMX_U32)(OMX_OUTPUT_PORT_INDEX))
  549. {
  550. mirrParam->eMirror = decConfig->mirror;
  551. LOG(SF_LOG_INFO, "Get Mirror %d \r\n", decConfig->mirror);
  552. }
  553. else
  554. {
  555. LOG(SF_LOG_WARN, "Only output port support Mirror config\r\n");
  556. ret = OMX_ErrorBadParameter;
  557. }
  558. break;
  559. }
  560. default:
  561. break;
  562. }
  563. EXIT:
  564. FunctionOut();
  565. return ret;
  566. }
  567. static OMX_ERRORTYPE SF_OMX_SetConfig(
  568. OMX_HANDLETYPE hComponent,
  569. OMX_INDEXTYPE nIndex,
  570. OMX_PTR pComponentConfigStructure)
  571. {
  572. OMX_ERRORTYPE ret = OMX_ErrorNone;
  573. FunctionIn();
  574. if (hComponent == NULL)
  575. {
  576. ret = OMX_ErrorBadParameter;
  577. goto EXIT;
  578. }
  579. if (pComponentConfigStructure == NULL)
  580. {
  581. ret = OMX_ErrorBadParameter;
  582. goto EXIT;
  583. }
  584. LOG(SF_LOG_INFO, "Set config on index %X\r\n", nIndex);
  585. OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
  586. SF_OMX_COMPONENT *pSfOMXComponent = pOMXComponent->pComponentPrivate;
  587. SF_CODAJ12_IMPLEMEMT *pSfMjpegImplement = (SF_CODAJ12_IMPLEMEMT *)pSfOMXComponent->componentImpl;
  588. switch ((OMX_U32)nIndex)
  589. {
  590. case OMX_IndexConfigCommonOutputCrop:
  591. {
  592. OMX_CONFIG_RECTTYPE *rectParam = (OMX_CONFIG_RECTTYPE *)pComponentConfigStructure;
  593. DecConfigParam *decConfig = pSfMjpegImplement->config;
  594. if(rectParam->nPortIndex == (OMX_U32)(OMX_OUTPUT_PORT_INDEX))
  595. {
  596. decConfig->roiOffsetX = rectParam->nLeft;
  597. decConfig->roiOffsetY = rectParam->nTop;
  598. decConfig->roiWidth = rectParam->nWidth;
  599. decConfig->roiHeight = rectParam->nHeight;
  600. decConfig->roiEnable = OMX_TRUE;
  601. LOG(SF_LOG_INFO, "Set OutputCrop left %d top %d width %d height %d \r\n",
  602. decConfig->roiOffsetX, decConfig->roiOffsetY, decConfig->roiWidth, decConfig->roiHeight);
  603. }
  604. else
  605. {
  606. LOG(SF_LOG_WARN, "Only support set OutputCrop config to output port\r\n");
  607. ret = OMX_ErrorBadParameter;
  608. }
  609. break;
  610. }
  611. case OMX_IndexConfigCommonRotate:
  612. {
  613. OMX_CONFIG_ROTATIONTYPE *rotatParam = (OMX_CONFIG_ROTATIONTYPE *)pComponentConfigStructure;
  614. DecConfigParam *decConfig = pSfMjpegImplement->config;
  615. if(rotatParam->nPortIndex == (OMX_U32)(OMX_OUTPUT_PORT_INDEX))
  616. {
  617. decConfig->rotation = rotatParam->nRotation;
  618. LOG(SF_LOG_INFO, "Set Rotation %d to output port\r\n", decConfig->rotation);
  619. }
  620. else
  621. {
  622. LOG(SF_LOG_WARN, "Only support set Rotation config to output port\r\n");
  623. ret = OMX_ErrorBadParameter;
  624. }
  625. break;
  626. }
  627. case OMX_IndexConfigCommonMirror:
  628. {
  629. OMX_CONFIG_MIRRORTYPE *mirrParam = (OMX_CONFIG_MIRRORTYPE *)pComponentConfigStructure;
  630. DecConfigParam *decConfig = pSfMjpegImplement->config;
  631. if(mirrParam->nPortIndex == (OMX_U32)(OMX_OUTPUT_PORT_INDEX))
  632. {
  633. decConfig->mirror = mirrParam->eMirror;
  634. LOG(SF_LOG_INFO, "Set Mirror %d \r\n", decConfig->mirror);
  635. }
  636. else
  637. {
  638. LOG(SF_LOG_WARN, "Only output port support Mirror config\r\n");
  639. ret = OMX_ErrorBadParameter;
  640. }
  641. break;
  642. }
  643. default:
  644. break;
  645. }
  646. EXIT:
  647. FunctionOut();
  648. return ret;
  649. }
  650. static OMX_ERRORTYPE InitDecoder(SF_OMX_COMPONENT *pSfOMXComponent)
  651. {
  652. FunctionIn();
  653. SF_CODAJ12_IMPLEMEMT *pSfCodaj12Implement = pSfOMXComponent->componentImpl;
  654. JpgRet ret = JPG_RET_SUCCESS;
  655. DecConfigParam *decConfig = pSfCodaj12Implement->config;
  656. jpu_buffer_t *vbStream = &pSfCodaj12Implement->vbStream;
  657. ret = pSfCodaj12Implement->functions->JPU_Init();
  658. if (ret != JPG_RET_SUCCESS && ret != JPG_RET_CALLED_BEFORE)
  659. {
  660. LOG(SF_LOG_ERR, "JPU_Init failed Error code is 0x%x \r\n", ret);
  661. return ret;
  662. }
  663. decConfig->feedingMode = FEEDING_METHOD_BUFFER;
  664. LOG(SF_LOG_DEBUG, "feedingMode = %d, StreamEndian = %d\r\n", decConfig->feedingMode, decConfig->StreamEndian);
  665. if ((pSfCodaj12Implement->feeder = pSfCodaj12Implement->functions->BitstreamFeeder_Create(decConfig->bitstreamFileName, decConfig->feedingMode, (EndianMode)decConfig->StreamEndian)) == NULL)
  666. {
  667. return OMX_ErrorResourcesLost;
  668. }
  669. FunctionOut();
  670. return OMX_ErrorNone;
  671. pSfCodaj12Implement->functions->FreeFrameBuffer(pSfCodaj12Implement->instIdx);
  672. pSfCodaj12Implement->functions->jdi_free_dma_memory(vbStream);
  673. pSfCodaj12Implement->functions->JPU_DeInit();
  674. FunctionOut();
  675. return OMX_ErrorHardware;
  676. }
  677. static OMX_BOOL FillBufferDone(SF_OMX_COMPONENT *pSfOMXComponent, OMX_BUFFERHEADERTYPE *pBuffer)
  678. {
  679. struct timeval tv;
  680. static OMX_U32 dec_cnt = 0;
  681. OMX_U32 fps = 0;
  682. OMX_U64 diff_time = 0; // ms
  683. static struct timeval tv_old = {0};
  684. FunctionIn();
  685. gettimeofday(&tv, NULL);
  686. if (gInitTimeStamp == 0)
  687. {
  688. gInitTimeStamp = tv.tv_sec * 1000000 + tv.tv_usec;
  689. }
  690. pBuffer->nTimeStamp = tv.tv_sec * 1000000 + tv.tv_usec - gInitTimeStamp;
  691. if (dec_cnt == 0) {
  692. tv_old = tv;
  693. }
  694. if (dec_cnt++ >= 50) {
  695. diff_time = (tv.tv_sec - tv_old.tv_sec) * 1000 + (tv.tv_usec - tv_old.tv_usec) / 1000;
  696. fps = 1000 * (dec_cnt - 1) / diff_time;
  697. dec_cnt = 0;
  698. LOG(SF_LOG_WARN, "Decoding fps: %d \r\n", fps);
  699. }
  700. LOG(SF_LOG_PERF, "OMX finish one buffer, address = %p, size = %d, nTimeStamp = %d, nFlags = %X\r\n",
  701. pBuffer->pBuffer, pBuffer->nFilledLen, pBuffer->nTimeStamp, pBuffer->nFlags);
  702. // Following comment store data loal
  703. // {
  704. // FILE *fb = fopen("./out.bcp", "ab+");
  705. // LOG(SF_LOG_INFO, "%p %d\r\n", pBuffer->pBuffer, pBuffer->nFilledLen);
  706. // fwrite(pBuffer->pBuffer, 1, pBuffer->nFilledLen, fb);
  707. // fclose(fb);
  708. // }
  709. pSfOMXComponent->callbacks->FillBufferDone(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData, pBuffer);
  710. FunctionOut();
  711. return OMX_TRUE;
  712. }
  713. static OMX_BOOL EmptyBufferDone(SF_OMX_COMPONENT *pSfOMXComponent)
  714. {
  715. SF_CODAJ12_IMPLEMEMT *pSfCodaj12Implement = pSfOMXComponent->componentImpl;
  716. OMX_BUFFERHEADERTYPE *pOMXBuffer = NULL;
  717. Message data;
  718. ssize_t ret;
  719. FunctionIn();
  720. LOG(SF_LOG_INFO, "Wait for done used buffer\r\n");
  721. ret = msgrcv(pSfCodaj12Implement->sBufferDoneQueue, (void *)&data, BUFSIZ, 0, IPC_NOWAIT);
  722. if (ret < 0)
  723. {
  724. LOG(SF_LOG_ERR, "msgrcv failed ret = %x\r\n", ret);
  725. return OMX_FALSE;
  726. }
  727. // switch (ret)
  728. // {
  729. // case ENOMSG:
  730. // LOG(SF_LOG_INFO, "msgrcv no message\n");
  731. // return OMX_TRUE;
  732. // default:
  733. // LOG(SF_LOG_ERR, "msgrcv failed ret = %x\r\n", ret);
  734. // return OMX_FALSE;
  735. // }
  736. pOMXBuffer = data.pBuffer;
  737. //TODO: input/output Buffer done
  738. LOG(SF_LOG_DEBUG, "EmptyBufferDone IN\r\n");
  739. pSfOMXComponent->callbacks->EmptyBufferDone(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData, pOMXBuffer);
  740. LOG(SF_LOG_DEBUG, "EmptyBufferDone OUT\r\n");
  741. FunctionOut();
  742. return OMX_TRUE;
  743. }
  744. static OMX_U32 FeedData(SF_OMX_COMPONENT *pSfOMXComponent)
  745. {
  746. FunctionIn();
  747. SF_CODAJ12_IMPLEMEMT *pSfCodaj12Implement = pSfOMXComponent->componentImpl;
  748. BSFeeder feeder = pSfCodaj12Implement->feeder;
  749. JpgDecHandle handle = pSfCodaj12Implement->handle;
  750. jpu_buffer_t *vbStream = &pSfCodaj12Implement->vbStream;
  751. OMX_U32 nFilledLen = 0;
  752. OMX_BUFFERHEADERTYPE *pOMXBuffer = NULL;
  753. Message data;
  754. LOG(SF_LOG_INFO, "Wait for input buffer\r\n");
  755. if (msgrcv(pSfCodaj12Implement->sInputMessageQueue, (void *)&data, BUFSIZ, 0, 0) == -1)
  756. {
  757. LOG(SF_LOG_ERR, "msgrcv failed\n");
  758. return 0;
  759. }
  760. pOMXBuffer = data.pBuffer;
  761. // if (pOMXBuffer == NULL || data.msg_flag == OMX_BUFFERFLAG_EOS)
  762. // {
  763. // return 0;
  764. // }
  765. if (pOMXBuffer != NULL)
  766. {
  767. if (pOMXBuffer->pBuffer != NULL && pOMXBuffer->nFilledLen > 0)
  768. {
  769. nFilledLen = pOMXBuffer->nFilledLen;
  770. LOG(SF_LOG_INFO, "Address = %p, size = %d\r\n", pOMXBuffer->pBuffer, nFilledLen);
  771. pSfCodaj12Implement->functions->BitstreamFeeder_SetData(feeder, pOMXBuffer->pBuffer, nFilledLen);
  772. pSfCodaj12Implement->functions->BitstreamFeeder_Act(feeder, handle, vbStream);
  773. }
  774. LOG(SF_LOG_INFO, "Send %p to sBufferDoneQueue\r\n", pOMXBuffer);
  775. if (msgsnd(pSfCodaj12Implement->sBufferDoneQueue, (void *)&data, sizeof(data) - sizeof(data.msg_type), 0) == -1)
  776. {
  777. LOG(SF_LOG_ERR, "msgsnd failed\n");
  778. return 0;
  779. }
  780. }
  781. // LOG(SF_LOG_DEBUG, "EmptyBufferDone IN\r\n");
  782. // pSfOMXComponent->callbacks->EmptyBufferDone(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData, pOMXBuffer);
  783. // LOG(SF_LOG_DEBUG, "EmptyBufferDone OUT\r\n");
  784. // if (pOMXBuffer->nFlags & 0x1 == 0x1)
  785. // {
  786. // pSfCodaj12Implement->bThreadRunning = OMX_FALSE;
  787. // }
  788. FunctionOut();
  789. return nFilledLen;
  790. }
  791. static OMX_ERRORTYPE WaitForOutputBufferReady(SF_OMX_COMPONENT *pSfOMXComponent,OMX_BUFFERHEADERTYPE **ppOMXBuffer)
  792. {
  793. FunctionIn();
  794. OMX_ERRORTYPE ret = OMX_ErrorNone;
  795. SF_CODAJ12_IMPLEMEMT *pSfCodaj12Implement = pSfOMXComponent->componentImpl;
  796. OMX_BUFFERHEADERTYPE *pOMXBuffer = NULL;
  797. Message data;
  798. LOG(SF_LOG_INFO, "Wait for output buffer\r\n");
  799. if (msgrcv(pSfCodaj12Implement->sOutputMessageQueue, (void *)&data, BUFSIZ, 0, 0) == -1)
  800. {
  801. LOG(SF_LOG_ERR, "msgrcv failed\n");
  802. return OMX_ErrorInsufficientResources;
  803. }
  804. pOMXBuffer = data.pBuffer;
  805. // if (pOMXBuffer == NULL || data.msg_flag == OMX_BUFFERFLAG_EOS)
  806. if (pOMXBuffer == NULL)
  807. {
  808. LOG(SF_LOG_INFO, "Buffer end flag detected! \r\n");
  809. pSfCodaj12Implement->bThreadRunning = OMX_FALSE;
  810. ret = OMX_ErrorNoMore;
  811. }
  812. *ppOMXBuffer = pOMXBuffer;
  813. FunctionOut();
  814. return ret;
  815. }
  816. static void ProcessThread(void *args)
  817. {
  818. SF_OMX_COMPONENT *pSfOMXComponent = (SF_OMX_COMPONENT *)args;
  819. SF_CODAJ12_IMPLEMEMT *pSfCodaj12Implement = pSfOMXComponent->componentImpl;
  820. jpu_buffer_t *vbStream = &pSfCodaj12Implement->vbStream;
  821. JpgDecInitialInfo *initialInfo = &pSfCodaj12Implement->initialInfo;
  822. JpgDecOpenParam *decOP = &pSfCodaj12Implement->decOP;
  823. DecConfigParam *decConfig = pSfCodaj12Implement->config;
  824. JpgDecHandle handle;
  825. Int32 frameIdx = 0;
  826. JpgDecParam decParam = {0};
  827. JpgDecOutputInfo outputInfo = {0};
  828. Int32 int_reason = 0;
  829. Int32 instIdx;
  830. JpgRet ret = JPG_RET_SUCCESS;
  831. FunctionIn();
  832. prctl(PR_SET_NAME, pSfOMXComponent->componentName);
  833. LOG(SF_LOG_INFO, "vbStream phys_addr = %x, size = %d, virt_addr = %x\r\n", vbStream->phys_addr, vbStream->size, vbStream->virt_addr);
  834. decOP->streamEndian = decConfig->StreamEndian;
  835. decOP->frameEndian = decConfig->FrameEndian;
  836. decOP->bitstreamBuffer = vbStream->phys_addr;
  837. decOP->bitstreamBufferSize = vbStream->size;
  838. //set virtual address mapped of physical address
  839. decOP->pBitStream = (BYTE *)vbStream->virt_addr; //lint !e511
  840. decOP->chromaInterleave = decConfig->cbcrInterleave;
  841. decOP->packedFormat = decConfig->packedFormat;
  842. decOP->roiEnable = decConfig->roiEnable;
  843. decOP->roiOffsetX = decConfig->roiOffsetX;
  844. decOP->roiOffsetY = decConfig->roiOffsetY;
  845. decOP->roiWidth = decConfig->roiWidth;
  846. decOP->roiHeight = decConfig->roiHeight;
  847. decOP->rotation = decConfig->rotation;
  848. decOP->mirror = decConfig->mirror;
  849. decOP->pixelJustification = decConfig->pixelJustification;
  850. decOP->outputFormat = pSfCodaj12Implement->frameFormat; //decConfig->subsample;
  851. decOP->intrEnableBit = ((1 << INT_JPU_DONE) | (1 << INT_JPU_ERROR) | (1 << INT_JPU_BIT_BUF_EMPTY));
  852. LOG(SF_LOG_DEBUG, "streamEndian = %x\r\n", decOP->streamEndian);
  853. LOG_APPEND(SF_LOG_DEBUG, "frameEndian = %x\r\n", decOP->frameEndian);
  854. LOG_APPEND(SF_LOG_DEBUG, "bitstreamBuffer = %x\r\n", decOP->bitstreamBuffer);
  855. LOG_APPEND(SF_LOG_DEBUG, "bitstreamBufferSize = %x\r\n", decOP->bitstreamBufferSize);
  856. LOG_APPEND(SF_LOG_DEBUG, "pBitStream = %x\r\n", decOP->pBitStream);
  857. LOG_APPEND(SF_LOG_DEBUG, "chromaInterleave = %x\r\n", decOP->chromaInterleave);
  858. LOG_APPEND(SF_LOG_DEBUG, "packedFormat = %x\r\n", decOP->packedFormat);
  859. LOG_APPEND(SF_LOG_DEBUG, "roiEnable = %x\r\n", decOP->roiEnable);
  860. LOG_APPEND(SF_LOG_DEBUG, "roiOffsetX = %x\r\n", decOP->roiOffsetX);
  861. LOG_APPEND(SF_LOG_DEBUG, "roiOffsetY = %x\r\n", decOP->roiOffsetY);
  862. LOG_APPEND(SF_LOG_DEBUG, "roiWidth = %x\r\n", decOP->roiWidth);
  863. LOG_APPEND(SF_LOG_DEBUG, "roiHeight = %x\r\n", decOP->roiHeight);
  864. LOG_APPEND(SF_LOG_DEBUG, "rotation = %x\r\n", decOP->rotation);
  865. LOG_APPEND(SF_LOG_DEBUG, "mirror = %x\r\n", decOP->mirror);
  866. LOG_APPEND(SF_LOG_DEBUG, "pixelJustification = %x\r\n", decOP->pixelJustification);
  867. LOG_APPEND(SF_LOG_DEBUG, "outputFormat = %x\r\n", decOP->outputFormat);
  868. LOG_APPEND(SF_LOG_DEBUG, "intrEnableBit = %x\r\n", decOP->intrEnableBit);
  869. ret = pSfCodaj12Implement->functions->JPU_DecOpen(&handle, decOP);
  870. if (ret != JPG_RET_SUCCESS)
  871. {
  872. LOG(SF_LOG_ERR, "JPU_DecOpen failed Error code is 0x%x \r\n", ret);
  873. return;
  874. }
  875. pSfCodaj12Implement->handle = handle;
  876. instIdx = pSfCodaj12Implement->instIdx = pSfCodaj12Implement->handle->instIndex;
  877. do
  878. {
  879. OMX_U32 size = FeedData(pSfOMXComponent);
  880. if (size <= 0)
  881. {
  882. LOG(SF_LOG_INFO, "FeedData = %d, end thread\r\n", size);
  883. pSfCodaj12Implement->bThreadRunning = OMX_FALSE;
  884. }
  885. if ((ret = pSfCodaj12Implement->functions->JPU_DecGetInitialInfo(handle, initialInfo)) != JPG_RET_SUCCESS)
  886. {
  887. if (JPG_RET_BIT_EMPTY == ret)
  888. {
  889. LOG(SF_LOG_INFO, "<%s:%d> BITSTREAM EMPTY\n", __FUNCTION__, __LINE__);
  890. continue;
  891. }
  892. else
  893. {
  894. LOG(SF_LOG_ERR, "JPU_DecGetInitialInfo failed Error code is 0x%x, inst=%d \n", ret, instIdx);
  895. return;
  896. }
  897. }
  898. } while (JPG_RET_SUCCESS != ret);
  899. //TODO:Set output info
  900. OMX_PARAM_PORTDEFINITIONTYPE *pPortDefinition = &pSfOMXComponent->portDefinition[OMX_OUTPUT_PORT_INDEX];
  901. LOG(SF_LOG_DEBUG, "picWidth = %d, picHeight = %d\r\n", initialInfo->picWidth, initialInfo->picHeight);
  902. pPortDefinition->format.video.nFrameWidth = initialInfo->picWidth;
  903. pPortDefinition->format.video.nFrameHeight = initialInfo->picHeight;
  904. pPortDefinition->format.video.nStride = initialInfo->picWidth;
  905. pPortDefinition->format.video.nSliceHeight = initialInfo->picHeight;
  906. pPortDefinition->format.video.eCompressionFormat = OMX_IMAGE_CodingUnused;
  907. switch (pSfCodaj12Implement->frameFormat)
  908. {
  909. case FORMAT_400:
  910. case FORMAT_420:
  911. pPortDefinition->nBufferSize = initialInfo->picWidth * initialInfo->picHeight * 3 / 2;
  912. break;
  913. case FORMAT_422:
  914. case FORMAT_440:
  915. pPortDefinition->nBufferSize = initialInfo->picWidth * initialInfo->picHeight * 2;
  916. break;
  917. case FORMAT_444:
  918. case FORMAT_MAX:
  919. pPortDefinition->nBufferSize = initialInfo->picWidth * initialInfo->picHeight * 3;
  920. break;
  921. default:
  922. pPortDefinition->nBufferSize = initialInfo->picWidth * initialInfo->picHeight * 4;
  923. break;
  924. }
  925. LOG(SF_LOG_DEBUG, "Output buffer size = %d\r\n", pPortDefinition->nBufferSize);
  926. if (pPortDefinition->nBufferCountActual < initialInfo->minFrameBufferCount)
  927. {
  928. pPortDefinition->nBufferCountActual = initialInfo->minFrameBufferCount;
  929. }
  930. if (pPortDefinition->nBufferCountMin < initialInfo->minFrameBufferCount)
  931. {
  932. pPortDefinition->nBufferCountMin = initialInfo->minFrameBufferCount;
  933. }
  934. LOG(SF_LOG_DEBUG, "OMX_EventPortSettingsChanged IN\r\n");
  935. pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData, OMX_EventPortSettingsChanged,
  936. 1, OMX_IndexParamPortDefinition, NULL);
  937. LOG(SF_LOG_DEBUG, "OMX_EventPortSettingsChanged OUT\r\n");
  938. LOG(SF_LOG_INFO, "Wait for out buffers ready\r\n");
  939. OMX_U32 nTimeout = 100;
  940. OMX_U32 nBufferNumber = pSfOMXComponent->portDefinition[OMX_OUTPUT_PORT_INDEX].nBufferCountActual;
  941. while (OMX_TRUE)
  942. {
  943. // LOG(SF_LOG_INFO, "GetFrameBufferCount addr = %p\r\n", pSfCodaj12Implement->functions->GetFrameBufferCount);
  944. nBufferNumber = pSfOMXComponent->portDefinition[OMX_OUTPUT_PORT_INDEX].nBufferCountActual;
  945. OMX_U32 number = pSfCodaj12Implement->functions->GetFrameBufferCount(instIdx);
  946. OMX_S32 oldNumber = -1;
  947. if (number < nBufferNumber)
  948. {
  949. if (oldNumber < number)
  950. {
  951. LOG(SF_LOG_INFO, "Wait for output buffer %d/%d\r\n", number, initialInfo->minFrameBufferCount);
  952. oldNumber = number;
  953. }
  954. usleep(50 * 1000);
  955. nTimeout --;
  956. if (nTimeout < 0)
  957. {
  958. LOG(SF_LOG_ERR, "No buffers found on output port\r\n");
  959. LOG(SF_LOG_DEBUG, "OMX_EventBufferFlag IN\r\n");
  960. pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData, OMX_EventBufferFlag,
  961. 1, 1, NULL);
  962. LOG(SF_LOG_DEBUG, "OMX_EventBufferFlag OUT\r\n");
  963. return;
  964. }
  965. }
  966. else
  967. {
  968. break;
  969. }
  970. }
  971. FRAME_BUF *pFrame = pSfCodaj12Implement->frame;
  972. LOG(SF_LOG_INFO, "Update and regist %d FrameBuffers\r\n", nBufferNumber);
  973. LOG(SF_LOG_DEBUG, "%20s%20s%20s%20s\r\n", "virtAddr", "Y", "CB", "CR");
  974. for (int i = 0; i < nBufferNumber; i ++)
  975. {
  976. LOG_APPEND(SF_LOG_DEBUG, "%20lX%20lX%20lX%20lX\r\n", pFrame[i].vbY.virt_addr,
  977. pFrame[i].vbY.phys_addr, pFrame[i].vbCb.phys_addr, pFrame[i].vbCr.phys_addr);
  978. }
  979. // ffmpeg: may register frame buffer append
  980. if (pSfCodaj12Implement->functions->JPU_GetFrameBufPool(pSfCodaj12Implement->handle) == NULL)
  981. {
  982. JpgRet ret = JPG_RET_SUCCESS;
  983. pSfCodaj12Implement->functions->UpdateFrameBuffers(instIdx, nBufferNumber, pFrame);
  984. ret = pSfCodaj12Implement->functions->JPU_DecRegisterFrameBuffer(pSfCodaj12Implement->handle, pSfCodaj12Implement->frameBuf,
  985. nBufferNumber, pSfCodaj12Implement->frameBuf[0].stride);
  986. if (ret != JPG_RET_SUCCESS)
  987. {
  988. LOG(SF_LOG_ERR, "JPU_DecRegisterFrameBuffer fail ret = %d\r\n", ret);
  989. pSfCodaj12Implement->bThreadRunning = OMX_FALSE;
  990. }
  991. }
  992. pSfCodaj12Implement->functions->JPU_DecGiveCommand(handle, SET_JPG_SCALE_HOR, &(decConfig->iHorScaleMode));
  993. pSfCodaj12Implement->functions->JPU_DecGiveCommand(handle, SET_JPG_SCALE_VER, &(decConfig->iVerScaleMode));
  994. /* LOG HEADER */
  995. LOG(SF_LOG_INFO, "I F FB_INDEX FRAME_START ECS_START CONSUME RD_PTR WR_PTR CYCLE\n");
  996. LOG(SF_LOG_INFO, "-------------------------------------------------------------------------------\n");
  997. while (pSfCodaj12Implement->bThreadRunning)
  998. {
  999. OMX_BUFFERHEADERTYPE *pBuffer;
  1000. if (WaitForOutputBufferReady(pSfOMXComponent,&pBuffer) != OMX_ErrorNone)
  1001. {
  1002. continue;
  1003. }
  1004. LOG(SF_LOG_INFO, "pBuffer->pOutputPortPrivate:%d\r\n", (OMX_U64)(pBuffer->pOutputPortPrivate));
  1005. ret = pSfCodaj12Implement->functions->JPU_DecStartOneFrameBySerialNum(handle, &decParam,(OMX_U64)(pBuffer->pOutputPortPrivate));
  1006. if (ret != JPG_RET_SUCCESS && ret != JPG_RET_EOS)
  1007. {
  1008. if (ret == JPG_RET_BIT_EMPTY)
  1009. {
  1010. LOG(SF_LOG_INFO, "BITSTREAM NOT ENOUGH.............\n");
  1011. OMX_U32 size = FeedData(pSfOMXComponent);
  1012. if (size <= 0)
  1013. {
  1014. LOG(SF_LOG_INFO, "FeedData = %d, end thread\r\n", size);
  1015. pSfCodaj12Implement->bThreadRunning = OMX_FALSE;
  1016. }
  1017. continue;
  1018. }
  1019. LOG(SF_LOG_ERR, "JPU_DecStartOneFrameBySerialNum failed Error code is 0x%x \n", ret);
  1020. return;
  1021. }
  1022. if (ret == JPG_RET_EOS)
  1023. {
  1024. pSfCodaj12Implement->functions->JPU_DecGetOutputInfo(handle, &outputInfo);
  1025. break;
  1026. }
  1027. while (1)
  1028. {
  1029. if ((int_reason = pSfCodaj12Implement->functions->JPU_WaitInterrupt(handle, JPU_INTERRUPT_TIMEOUT_MS)) == -1)
  1030. {
  1031. LOG(SF_LOG_ERR, "Error : timeout happened\n");
  1032. pSfCodaj12Implement->functions->JPU_SWReset(handle);
  1033. break;
  1034. }
  1035. if (int_reason & ((1 << INT_JPU_DONE) | (1 << INT_JPU_ERROR) | (1 << INT_JPU_SLICE_DONE)))
  1036. {
  1037. // Do no clear INT_JPU_DONE and INT_JPU_ERROR interrupt. these will be cleared in JPU_DecGetOutputInfo.
  1038. LOG(SF_LOG_INFO, "\tINSTANCE #%d int_reason: %08x\n", handle->instIndex, int_reason);
  1039. break;
  1040. }
  1041. // if (int_reason & (1 << INT_JPU_BIT_BUF_EMPTY))
  1042. // {
  1043. // if (decConfig->feedingMode != FEEDING_METHOD_FRAME_SIZE)
  1044. // {
  1045. // pSfCodaj12Implement->functions->BitstreamFeeder_Act(feeder, handle, &vbStream);
  1046. // }
  1047. // pSfCodaj12Implement->functions->JPU_ClrStatus(handle, (1 << INT_JPU_BIT_BUF_EMPTY));
  1048. // }
  1049. }
  1050. //LOG(SF_LOG_INFO, "\t<->INSTANCE #%d JPU_WaitInterrupt\n", handle->instIndex);
  1051. EmptyBufferDone(pSfOMXComponent);
  1052. if ((ret = pSfCodaj12Implement->functions->JPU_DecGetOutputInfo(handle, &outputInfo)) != JPG_RET_SUCCESS)
  1053. {
  1054. LOG(SF_LOG_ERR, "JPU_DecGetOutputInfo failed Error code is 0x%x \n", ret);
  1055. return;
  1056. }
  1057. switch (pSfCodaj12Implement->frameFormat)
  1058. {
  1059. case FORMAT_420:
  1060. pBuffer->nFilledLen = outputInfo.decPicWidth * outputInfo.decPicHeight * 3 / 2;
  1061. break;
  1062. case FORMAT_422:
  1063. pBuffer->nFilledLen = outputInfo.decPicWidth * outputInfo.decPicHeight * 2;
  1064. break;
  1065. case FORMAT_444:
  1066. pBuffer->nFilledLen = outputInfo.decPicWidth * outputInfo.decPicHeight * 3;
  1067. break;
  1068. default:
  1069. LOG(SF_LOG_ERR, "Unsupported format: %d\r\n", pSfCodaj12Implement->frameFormat);
  1070. break;
  1071. }
  1072. LOG(SF_LOG_DEBUG, "decPicSize = [%d %d], pBuffer = %p\r\n",
  1073. outputInfo.decPicWidth, outputInfo.decPicHeight, pBuffer->pBuffer);
  1074. // AdjustFrame(pBuffer, outputInfo.decPicWidth, outputInfo.decPicHeight, nDestStride, nDestHeight);
  1075. FillBufferDone(pSfOMXComponent, pBuffer);
  1076. // LOG(SF_LOG_DEBUG, "FillBufferDone IN\r\n");
  1077. // Following comment store data loal
  1078. // {
  1079. // FILE *fb = fopen("./out.bcp", "ab+");
  1080. // LOG(SF_LOG_INFO, "%p %d\r\n", pBuffer->pBuffer, pBuffer->nFilledLen);
  1081. // fwrite(pBuffer->pBuffer, 1, pBuffer->nFilledLen, fb);
  1082. // fclose(fb);
  1083. // }
  1084. // pSfOMXComponent->callbacks->FillBufferDone(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData, pBuffer);
  1085. // LOG(SF_LOG_DEBUG, "FillBufferDone OUT\r\n");
  1086. if (outputInfo.numOfErrMBs)
  1087. {
  1088. Int32 errRstIdx, errPosX, errPosY;
  1089. errRstIdx = (outputInfo.numOfErrMBs & 0x0F000000) >> 24;
  1090. errPosX = (outputInfo.numOfErrMBs & 0x00FFF000) >> 12;
  1091. errPosY = (outputInfo.numOfErrMBs & 0x00000FFF);
  1092. LOG(SF_LOG_ERR, "Error restart Idx : %d, MCU x:%d, y:%d, in Frame : %d \n", errRstIdx, errPosX, errPosY, frameIdx);
  1093. }
  1094. // if (pSfCodaj12Implement->bThreadRunning == OMX_FALSE)
  1095. // {
  1096. // break;
  1097. // }
  1098. pSfCodaj12Implement->functions->JPU_DecSetRdPtrEx(handle, vbStream->phys_addr, TRUE);
  1099. OMX_U32 size = FeedData(pSfOMXComponent);
  1100. if (size <= 0)
  1101. {
  1102. LOG(SF_LOG_INFO, "FeedData = %d, end thread\r\n", size);
  1103. pSfCodaj12Implement->bThreadRunning = OMX_FALSE;
  1104. }
  1105. }
  1106. LOG(SF_LOG_DEBUG, "OMX_EventBufferFlag IN\r\n");
  1107. pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData, OMX_EventBufferFlag,
  1108. 1, 1, NULL);
  1109. LOG(SF_LOG_DEBUG, "OMX_EventBufferFlag OUT\r\n");
  1110. CodaJ12FlushBuffer(pSfOMXComponent, OMX_INPUT_PORT_INDEX);
  1111. CodaJ12FlushBuffer(pSfOMXComponent, OMX_OUTPUT_PORT_INDEX);
  1112. pSfCodaj12Implement->currentState = OMX_StateIdle;
  1113. FunctionOut();
  1114. ThreadExit(NULL);
  1115. }
  1116. static OMX_ERRORTYPE SF_OMX_SendCommand(
  1117. OMX_IN OMX_HANDLETYPE hComponent,
  1118. OMX_IN OMX_COMMANDTYPE Cmd,
  1119. OMX_IN OMX_U32 nParam,
  1120. OMX_IN OMX_PTR pCmdData)
  1121. {
  1122. OMX_ERRORTYPE ret = OMX_ErrorNone;
  1123. OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
  1124. SF_OMX_COMPONENT *pSfOMXComponent = pOMXComponent->pComponentPrivate;
  1125. SF_CODAJ12_IMPLEMEMT *pSfCodaj12Implement = pSfOMXComponent->componentImpl;
  1126. FunctionIn();
  1127. if (hComponent == NULL || pSfOMXComponent == NULL)
  1128. {
  1129. ret = OMX_ErrorBadParameter;
  1130. goto EXIT;
  1131. }
  1132. LOG(SF_LOG_INFO, "cmd = %X, nParam = %X\r\n", Cmd, nParam);
  1133. switch (Cmd)
  1134. {
  1135. case OMX_CommandStateSet:
  1136. pSfOMXComponent->nextState = nParam;
  1137. LOG(SF_LOG_INFO, "OMX dest state = %X, current state = %X\r\n", nParam, pSfCodaj12Implement->currentState);
  1138. switch (nParam)
  1139. {
  1140. case OMX_StateLoaded:
  1141. break;
  1142. case OMX_StateIdle:
  1143. switch (pSfCodaj12Implement->currentState)
  1144. {
  1145. case OMX_StateExecuting:
  1146. {
  1147. Message data;
  1148. data.msg_type = 1;
  1149. data.msg_flag = OMX_BUFFERFLAG_EOS;
  1150. data.pBuffer = NULL;
  1151. LOG(SF_LOG_DEBUG, "Send to message queue\r\n");
  1152. if (msgsnd(pSfCodaj12Implement->sOutputMessageQueue, (void *)&data, sizeof(data) - sizeof(data.msg_type), 0) == -1)
  1153. {
  1154. LOG(SF_LOG_ERR, "msgsnd failed\n");
  1155. }
  1156. if (msgsnd(pSfCodaj12Implement->sInputMessageQueue, (void *)&data, sizeof(data) - sizeof(data.msg_type), 0) == -1)
  1157. {
  1158. LOG(SF_LOG_ERR, "msgsnd failed\n");
  1159. }
  1160. pSfCodaj12Implement->currentState = OMX_StateIdle;
  1161. break;
  1162. }
  1163. case OMX_StateIdle:
  1164. break;
  1165. case OMX_StateLoaded:
  1166. // InitDecoder(pSfOMXComponent);
  1167. pSfCodaj12Implement->currentState = OMX_StateIdle;
  1168. break;
  1169. default:
  1170. LOG(SF_LOG_ERR, "Can't go to state %d from %d\r\n",pSfCodaj12Implement->currentState, nParam);
  1171. return OMX_ErrorBadParameter;
  1172. break;
  1173. }
  1174. break;
  1175. case OMX_StateExecuting:
  1176. switch (pSfCodaj12Implement->currentState)
  1177. {
  1178. case OMX_StateIdle:
  1179. pSfCodaj12Implement->bThreadRunning = OMX_TRUE;
  1180. CreateThread(&pSfCodaj12Implement->pProcessThread, ProcessThread, (void *)pSfOMXComponent);
  1181. pSfCodaj12Implement->currentState = OMX_StateExecuting;
  1182. break;
  1183. case OMX_StateExecuting:
  1184. break;
  1185. case OMX_StateLoaded:
  1186. default:
  1187. LOG(SF_LOG_ERR, "Can't go to state %d from %d\r\n",pSfCodaj12Implement->currentState, nParam);
  1188. return OMX_ErrorBadParameter;
  1189. break;
  1190. }
  1191. break;
  1192. default:
  1193. ret = OMX_ErrorIncorrectStateTransition;
  1194. break;
  1195. }
  1196. pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData,
  1197. OMX_EventCmdComplete, OMX_CommandStateSet, nParam, NULL);
  1198. break;
  1199. case OMX_CommandFlush:
  1200. {
  1201. OMX_U32 nPort = nParam;
  1202. CodaJ12FlushBuffer(pSfOMXComponent, nPort);
  1203. pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData,
  1204. OMX_EventCmdComplete, OMX_CommandFlush, nParam, NULL);
  1205. }
  1206. case OMX_CommandPortDisable:
  1207. pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData,
  1208. OMX_EventCmdComplete, OMX_CommandPortDisable, nParam, NULL);
  1209. break;
  1210. case OMX_CommandPortEnable:
  1211. pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData,
  1212. OMX_EventCmdComplete, OMX_CommandPortEnable, nParam, NULL);
  1213. default:
  1214. break;
  1215. }
  1216. //TODO
  1217. EXIT:
  1218. FunctionOut();
  1219. return ret;
  1220. }
  1221. static OMX_ERRORTYPE SF_OMX_GetState(
  1222. OMX_IN OMX_HANDLETYPE hComponent,
  1223. OMX_OUT OMX_STATETYPE *pState)
  1224. {
  1225. OMX_ERRORTYPE ret = OMX_ErrorNone;
  1226. OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
  1227. SF_OMX_COMPONENT *pSfOMXComponent = pOMXComponent->pComponentPrivate;
  1228. SF_CODAJ12_IMPLEMEMT *pSfCodaj12Implement = pSfOMXComponent->componentImpl;
  1229. FunctionIn();
  1230. *pState = pSfCodaj12Implement->currentState;
  1231. FunctionOut();
  1232. return ret;
  1233. }
  1234. static OMX_ERRORTYPE SF_OMX_FreeBuffer(
  1235. OMX_IN OMX_HANDLETYPE hComponent,
  1236. OMX_IN OMX_U32 nPortIndex,
  1237. OMX_IN OMX_BUFFERHEADERTYPE *pBufferHdr)
  1238. {
  1239. OMX_ERRORTYPE ret = OMX_ErrorNone;
  1240. FunctionIn();
  1241. //TODO
  1242. FunctionOut();
  1243. return ret;
  1244. }
  1245. static OMX_ERRORTYPE SF_OMX_ComponentConstructor(SF_OMX_COMPONENT *pSfOMXComponent)
  1246. {
  1247. OMX_ERRORTYPE ret = OMX_ErrorNone;
  1248. SF_CODAJ12_IMPLEMEMT *pSfCodaj12Implement;
  1249. FunctionIn();
  1250. ret = InitMjpegStructorCommon(pSfOMXComponent);
  1251. if (ret != OMX_ErrorNone)
  1252. {
  1253. goto EXIT;
  1254. }
  1255. pSfOMXComponent->pOMXComponent->UseBuffer = &SF_OMX_UseBuffer;
  1256. pSfOMXComponent->pOMXComponent->AllocateBuffer = &SF_OMX_AllocateBuffer;
  1257. pSfOMXComponent->pOMXComponent->EmptyThisBuffer = &SF_OMX_EmptyThisBuffer;
  1258. pSfOMXComponent->pOMXComponent->FillThisBuffer = &SF_OMX_FillThisBuffer;
  1259. pSfOMXComponent->pOMXComponent->FreeBuffer = &SF_OMX_FreeBuffer;
  1260. // pSfOMXComponent->pOMXComponent->ComponentTunnelRequest = &SF_OMX_ComponentTunnelRequest;
  1261. pSfOMXComponent->pOMXComponent->GetParameter = &SF_OMX_GetParameter;
  1262. pSfOMXComponent->pOMXComponent->SetParameter = &SF_OMX_SetParameter;
  1263. pSfOMXComponent->pOMXComponent->GetConfig = &SF_OMX_GetConfig;
  1264. pSfOMXComponent->pOMXComponent->SetConfig = &SF_OMX_SetConfig;
  1265. pSfOMXComponent->pOMXComponent->SendCommand = &SF_OMX_SendCommand;
  1266. pSfOMXComponent->pOMXComponent->GetState = &SF_OMX_GetState;
  1267. // pSfOMXComponent->pOMXComponent->GetExtensionIndex = &SF_OMX_GetExtensionIndex;
  1268. // pSfOMXComponent->pOMXComponent->ComponentRoleEnum = &SF_OMX_ComponentRoleEnum;
  1269. // pSfOMXComponent->pOMXComponent->ComponentDeInit = &SF_OMX_ComponentDeInit;
  1270. pSfCodaj12Implement = pSfOMXComponent->componentImpl;
  1271. pSfCodaj12Implement->currentState = OMX_StateLoaded;
  1272. InitDecoder(pSfOMXComponent);
  1273. EXIT:
  1274. FunctionOut();
  1275. return ret;
  1276. }
  1277. static OMX_ERRORTYPE SF_OMX_ComponentClear(SF_OMX_COMPONENT *pSfOMXComponent)
  1278. {
  1279. OMX_ERRORTYPE ret = OMX_ErrorNone;
  1280. SF_CODAJ12_IMPLEMEMT *pSfCodaj12Implement = pSfOMXComponent->componentImpl;
  1281. jpu_buffer_t *vbStream = &pSfCodaj12Implement->vbStream;
  1282. JpgDecHandle handle = pSfCodaj12Implement->handle;
  1283. FunctionIn();
  1284. if (pSfCodaj12Implement->functions->JPU_DecClose(handle) != JPG_RET_SUCCESS)
  1285. {
  1286. LOG(SF_LOG_ERR, "\nDec End\r\n");
  1287. ret = OMX_ErrorHardware;
  1288. }
  1289. pSfCodaj12Implement->functions->BitstreamFeeder_Destroy(pSfCodaj12Implement->feeder);
  1290. if(pSfCodaj12Implement->allocBufFlag == OMX_TRUE)
  1291. {
  1292. pSfCodaj12Implement->functions->FreeFrameBuffer(pSfCodaj12Implement->instIdx);
  1293. }
  1294. pSfCodaj12Implement->functions->jdi_free_dma_memory(vbStream);
  1295. pSfCodaj12Implement->functions->JPU_DeInit();
  1296. // TODO
  1297. // MjpegClearCommon(hComponent);
  1298. FunctionOut();
  1299. return ret;
  1300. }
  1301. //TODO happer
  1302. SF_OMX_COMPONENT sf_dec_decoder_mjpeg = {
  1303. .componentName = "sf.dec.decoder.mjpeg",
  1304. .libName = "libcodadec.so",
  1305. .pOMXComponent = NULL,
  1306. .SF_OMX_ComponentConstructor = SF_OMX_ComponentConstructor,
  1307. .SF_OMX_ComponentClear = SF_OMX_ComponentClear,
  1308. // .functions = NULL,
  1309. // .bitFormat = STD_HEVC,
  1310. .componentImpl = NULL,
  1311. .fwPath = "/lib/firmware/chagall.bin",
  1312. .componentRule = "video_decoder.mjpeg"};