SF_OMX_Mjpeg_decoder.c 52 KB

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