component_enc_feeder.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. /*
  2. * Copyright (c) 2019, Chips&Media
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  18. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include <string.h>
  26. #include "component.h"
  27. typedef enum {
  28. SRC_FB_TYPE_YUV,
  29. SRC_FB_TYPE_CFRAME
  30. } SRC_FB_TYPE;
  31. typedef enum {
  32. YUV_FEEDER_STATE_WAIT,
  33. YUV_FEEDER_STATE_FEEDING
  34. } YuvFeederState;
  35. typedef struct {
  36. EncHandle handle;
  37. char inputPath[MAX_FILE_PATH];
  38. EncOpenParam encOpenParam;
  39. Int32 rotAngle;
  40. Int32 mirDir;
  41. Int32 frameOutNum;
  42. Int32 yuvMode;
  43. FrameBufferAllocInfo srcFbAllocInfo;
  44. FrameBufferAllocInfo reconFbAllocInfo;
  45. BOOL fbAllocated;
  46. ParamEncNeedFrameBufferNum fbCount;
  47. FrameBuffer pFbRecon[MAX_REG_FRAME];
  48. vpu_buffer_t pFbReconMem[MAX_REG_FRAME];
  49. FrameBuffer pFbSrc[ENC_SRC_BUF_NUM];
  50. vpu_buffer_t pFbSrcMem[ENC_SRC_BUF_NUM];
  51. FrameBuffer pFbOffsetTbl[ENC_SRC_BUF_NUM];
  52. vpu_buffer_t pFbOffsetTblMem[ENC_SRC_BUF_NUM];
  53. YuvFeeder yuvFeeder;
  54. BOOL last;
  55. YuvFeederState state;
  56. BOOL stateDoing;
  57. Int32 feedingNum;
  58. TiledMapConfig mapConfig;
  59. Int32 productID;
  60. BOOL MemoryOptimization;
  61. int totalBufferNumber;
  62. int currentBufferNumber;
  63. } YuvFeederContext;
  64. static void InitYuvFeederContext(YuvFeederContext* ctx, CNMComponentConfig* componentParam)
  65. {
  66. osal_memset((void*)ctx, 0, sizeof(YuvFeederContext));
  67. strcpy(ctx->inputPath, componentParam->testEncConfig.yuvFileName);
  68. ctx->fbAllocated = FALSE;
  69. ctx->encOpenParam = componentParam->encOpenParam;
  70. ctx->yuvMode = componentParam->testEncConfig.yuv_mode;
  71. ctx->fbCount.reconFbNum = 0;
  72. ctx->fbCount.srcFbNum = 0;
  73. ctx->frameOutNum = componentParam->testEncConfig.outNum;
  74. ctx->rotAngle = componentParam->testEncConfig.rotAngle;
  75. ctx->mirDir = componentParam->testEncConfig.mirDir;
  76. osal_memset(&ctx->srcFbAllocInfo, 0x00, sizeof(FrameBufferAllocInfo));
  77. osal_memset(&ctx->reconFbAllocInfo, 0x00, sizeof(FrameBufferAllocInfo));
  78. osal_memset((void*)ctx->pFbRecon, 0x00, sizeof(ctx->pFbRecon));
  79. osal_memset((void*)ctx->pFbReconMem, 0x00, sizeof(ctx->pFbReconMem));
  80. osal_memset((void*)ctx->pFbSrc, 0x00, sizeof(ctx->pFbSrc));
  81. osal_memset((void*)ctx->pFbSrcMem, 0x00, sizeof(ctx->pFbSrcMem));
  82. osal_memset((void*)ctx->pFbOffsetTbl, 0x00, sizeof(ctx->pFbOffsetTbl));
  83. osal_memset((void*)ctx->pFbOffsetTblMem, 0x00, sizeof(ctx->pFbOffsetTblMem));
  84. }
  85. static CNMComponentParamRet GetParameterYuvFeeder(ComponentImpl* from, ComponentImpl* com, GetParameterCMD commandType, void* data)
  86. {
  87. YuvFeederContext* ctx = (YuvFeederContext*)com->context;
  88. BOOL result = TRUE;
  89. ParamEncFrameBuffer* allocFb = NULL;
  90. switch(commandType) {
  91. case GET_PARAM_YUVFEEDER_FRAME_BUF:
  92. if (ctx->fbAllocated == FALSE || ctx->currentBufferNumber < ctx->totalBufferNumber) return CNM_COMPONENT_PARAM_NOT_READY;
  93. allocFb = (ParamEncFrameBuffer*)data;
  94. allocFb->reconFb = ctx->pFbRecon;
  95. allocFb->srcFb = ctx->pFbSrc;
  96. allocFb->reconFbAllocInfo = ctx->reconFbAllocInfo;
  97. allocFb->srcFbAllocInfo = ctx->srcFbAllocInfo;
  98. break;
  99. default:
  100. return CNM_COMPONENT_PARAM_NOT_FOUND;
  101. }
  102. return (result == TRUE) ? CNM_COMPONENT_PARAM_SUCCESS : CNM_COMPONENT_PARAM_FAILURE;
  103. }
  104. static CNMComponentParamRet SetParameterYuvFeeder(ComponentImpl* from, ComponentImpl* com, SetParameterCMD commandType, void* data)
  105. {
  106. BOOL result = TRUE;
  107. switch(commandType) {
  108. default:
  109. VLOG(ERR, "Unknown SetParameterCMD Type : %d\n", commandType);
  110. result = FALSE;
  111. break;
  112. }
  113. return (result == TRUE) ? CNM_COMPONENT_PARAM_SUCCESS : CNM_COMPONENT_PARAM_FAILURE;
  114. }
  115. void* AllocateFrameBuffer2(ComponentImpl* com, Uint32 size)
  116. {
  117. YuvFeederContext* ctx = (YuvFeederContext*)com->context;
  118. EncOpenParam encOpenParam = ctx->encOpenParam;
  119. Uint32 fbWidth = 0;
  120. Uint32 fbHeight = 0;
  121. Uint32 fbStride = 0;
  122. // Uint32 fbSize = 0;
  123. SRC_FB_TYPE srcFbType = SRC_FB_TYPE_YUV;
  124. // DRAMConfig dramConfig;
  125. // DRAMConfig* pDramConfig = NULL;
  126. TiledMapType mapType;
  127. FrameBufferAllocInfo fbAllocInfo;
  128. int i = 0;
  129. if (ctx->handle == NULL) {
  130. ctx->MemoryOptimization = FALSE;
  131. return NULL;
  132. }
  133. osal_memset(&fbAllocInfo, 0x00, sizeof(FrameBufferAllocInfo));
  134. // osal_memset(&dramConfig, 0x00, sizeof(DRAMConfig));
  135. //Buffers for source frames
  136. if (PRODUCT_ID_W_SERIES(ctx->productID)) {
  137. fbWidth = VPU_ALIGN8(encOpenParam.picWidth);
  138. fbHeight = VPU_ALIGN8(encOpenParam.picHeight);
  139. fbAllocInfo.endian = encOpenParam.sourceEndian;
  140. } else {
  141. //CODA
  142. fbWidth = VPU_ALIGN16(encOpenParam.picWidth);
  143. fbHeight = VPU_ALIGN16(encOpenParam.picHeight);
  144. fbAllocInfo.endian = encOpenParam.frameEndian;
  145. // VPU_EncGiveCommand(ctx->handle, GET_DRAM_CONFIG, &dramConfig);
  146. // pDramConfig = &dramConfig;
  147. }
  148. if (SRC_FB_TYPE_YUV == srcFbType) {
  149. mapType = LINEAR_FRAME_MAP;
  150. }
  151. fbStride = CalcStride(fbWidth, fbHeight, (FrameBufferFormat)encOpenParam.srcFormat, encOpenParam.cbcrInterleave, mapType, FALSE);
  152. // fbSize = VPU_GetFrameBufSize(ctx->handle, encOpenParam.coreIdx, fbStride, fbHeight, mapType, (FrameBufferFormat)encOpenParam.srcFormat, encOpenParam.cbcrInterleave, pDramConfig);
  153. fbAllocInfo.format = (FrameBufferFormat)encOpenParam.srcFormat;
  154. fbAllocInfo.cbcrInterleave = encOpenParam.cbcrInterleave;
  155. fbAllocInfo.mapType = mapType;
  156. fbAllocInfo.stride = fbStride;
  157. fbAllocInfo.height = fbHeight;
  158. fbAllocInfo.size = size;
  159. fbAllocInfo.type = FB_TYPE_PPU;
  160. fbAllocInfo.num = ctx->fbCount.srcFbNum;
  161. fbAllocInfo.nv21 = encOpenParam.nv21;
  162. if (PRODUCT_ID_NOT_W_SERIES(ctx->productID)) {
  163. fbAllocInfo.lumaBitDepth = 8;
  164. fbAllocInfo.chromaBitDepth = 8;
  165. }
  166. for (i = 0;i < ENC_SRC_BUF_NUM; i ++){
  167. if (ctx->pFbSrcMem[i].phys_addr == 0)
  168. {
  169. VLOG(INFO, "Found empty frame at index %d\r\n", i);
  170. break;
  171. }
  172. }
  173. if (i == MAX_REG_FRAME)
  174. {
  175. VLOG(ERR, "Could not found empty frame at index\r\n");
  176. return NULL;
  177. }
  178. if (FALSE == AllocFBMemory(encOpenParam.coreIdx, &ctx->pFbSrcMem[i], &ctx->pFbSrc[i], size, 1, ENC_SRC, ctx->handle->instIndex)) {
  179. VLOG(ERR, "failed to allocate source buffers\n");
  180. return NULL;
  181. }
  182. ctx->srcFbAllocInfo = fbAllocInfo;
  183. ctx->currentBufferNumber ++;
  184. return (void *)ctx->pFbSrcMem[i].virt_addr;
  185. }
  186. static BOOL AllocateFrameBuffer(ComponentImpl* com) {
  187. YuvFeederContext* ctx = (YuvFeederContext*)com->context;
  188. EncOpenParam encOpenParam = ctx->encOpenParam;
  189. Uint32 fbWidth = 0;
  190. Uint32 fbHeight = 0;
  191. Uint32 fbStride = 0;
  192. Uint32 fbSize = 0;
  193. SRC_FB_TYPE srcFbType = SRC_FB_TYPE_YUV;
  194. DRAMConfig dramConfig;
  195. DRAMConfig* pDramConfig = NULL;
  196. TiledMapType mapType;
  197. FrameBufferAllocInfo fbAllocInfo;
  198. osal_memset(&fbAllocInfo, 0x00, sizeof(FrameBufferAllocInfo));
  199. osal_memset(&dramConfig, 0x00, sizeof(DRAMConfig));
  200. if (ctx->MemoryOptimization) {
  201. goto alloc_fbc;
  202. }
  203. //Buffers for source frames
  204. if (PRODUCT_ID_W_SERIES(ctx->productID)) {
  205. fbWidth = VPU_ALIGN8(encOpenParam.picWidth);
  206. fbHeight = VPU_ALIGN8(encOpenParam.picHeight);
  207. fbAllocInfo.endian = encOpenParam.sourceEndian;
  208. } else {
  209. //CODA
  210. fbWidth = VPU_ALIGN16(encOpenParam.picWidth);
  211. fbHeight = VPU_ALIGN16(encOpenParam.picHeight);
  212. fbAllocInfo.endian = encOpenParam.frameEndian;
  213. VPU_EncGiveCommand(ctx->handle, GET_DRAM_CONFIG, &dramConfig);
  214. pDramConfig = &dramConfig;
  215. }
  216. if (SRC_FB_TYPE_YUV == srcFbType) {
  217. mapType = LINEAR_FRAME_MAP;
  218. }
  219. fbStride = CalcStride(fbWidth, fbHeight, (FrameBufferFormat)encOpenParam.srcFormat, encOpenParam.cbcrInterleave, mapType, FALSE);
  220. fbSize = VPU_GetFrameBufSize(ctx->handle, encOpenParam.coreIdx, fbStride, fbHeight, mapType, (FrameBufferFormat)encOpenParam.srcFormat, encOpenParam.cbcrInterleave, pDramConfig);
  221. fbAllocInfo.format = (FrameBufferFormat)encOpenParam.srcFormat;
  222. fbAllocInfo.cbcrInterleave = encOpenParam.cbcrInterleave;
  223. fbAllocInfo.mapType = mapType;
  224. fbAllocInfo.stride = fbStride;
  225. fbAllocInfo.height = fbHeight;
  226. fbAllocInfo.size = fbSize;
  227. fbAllocInfo.type = FB_TYPE_PPU;
  228. fbAllocInfo.num = ctx->fbCount.srcFbNum;
  229. fbAllocInfo.nv21 = encOpenParam.nv21;
  230. if (PRODUCT_ID_NOT_W_SERIES(ctx->productID)) {
  231. fbAllocInfo.lumaBitDepth = 8;
  232. fbAllocInfo.chromaBitDepth = 8;
  233. }
  234. if (FALSE == AllocFBMemory(encOpenParam.coreIdx, ctx->pFbSrcMem, ctx->pFbSrc, fbSize, ctx->fbCount.srcFbNum, ENC_SRC, ctx->handle->instIndex)) {
  235. VLOG(ERR, "failed to allocate source buffers\n");
  236. return FALSE;
  237. }
  238. ctx->srcFbAllocInfo = fbAllocInfo;
  239. alloc_fbc:
  240. //Buffers for reconstructed frames
  241. osal_memset(&fbAllocInfo, 0x00, sizeof(FrameBufferAllocInfo));
  242. if (PRODUCT_ID_W_SERIES(ctx->productID)) {
  243. pDramConfig = NULL;
  244. if (ctx->encOpenParam.bitstreamFormat == STD_AVC) {
  245. fbWidth = VPU_ALIGN16(encOpenParam.picWidth);
  246. fbHeight = VPU_ALIGN16(encOpenParam.picHeight);
  247. } else {
  248. fbWidth = VPU_ALIGN8(encOpenParam.picWidth);
  249. fbHeight = VPU_ALIGN8(encOpenParam.picHeight);
  250. }
  251. if ((ctx->rotAngle != 0 || ctx->mirDir != 0) && !(ctx->rotAngle == 180 && ctx->mirDir == MIRDIR_HOR_VER)) {
  252. fbWidth = VPU_ALIGN32(encOpenParam.picWidth);
  253. fbHeight = VPU_ALIGN32(encOpenParam.picHeight);
  254. }
  255. //TODO if --> else if
  256. if (ctx->rotAngle == 90 || ctx->rotAngle == 270) {
  257. fbWidth = VPU_ALIGN32(encOpenParam.picHeight);
  258. fbHeight = VPU_ALIGN32(encOpenParam.picWidth);
  259. }
  260. if (WAVE521C_DUAL_CODE == (VPU_HANDLE_TO_ENCINFO(ctx->handle)->productCode)) {
  261. mapType = encOpenParam.EncStdParam.waveParam.internalBitDepth==8?COMPRESSED_FRAME_MAP_DUAL_CORE_8BIT:COMPRESSED_FRAME_MAP_DUAL_CORE_10BIT;
  262. } else {
  263. mapType = COMPRESSED_FRAME_MAP;
  264. }
  265. } else {
  266. //CODA
  267. pDramConfig = &dramConfig;
  268. fbWidth = encOpenParam.picWidth;
  269. fbHeight = encOpenParam.picHeight;
  270. if (90 == ctx->rotAngle || 270 == ctx->rotAngle) {
  271. fbWidth = encOpenParam.picHeight;
  272. fbHeight = encOpenParam.picWidth;
  273. }
  274. fbWidth = VPU_ALIGN16(fbWidth);
  275. fbHeight = VPU_ALIGN32(fbHeight);
  276. mapType = mapType;
  277. }
  278. fbStride = CalcStride(fbWidth, fbHeight, (FrameBufferFormat)encOpenParam.outputFormat, encOpenParam.cbcrInterleave, mapType, FALSE);
  279. fbSize = VPU_GetFrameBufSize(ctx->handle, encOpenParam.coreIdx, fbStride, fbHeight, mapType, (FrameBufferFormat)encOpenParam.outputFormat, encOpenParam.cbcrInterleave, pDramConfig);
  280. if (FALSE == AllocFBMemory(encOpenParam.coreIdx, ctx->pFbReconMem, ctx->pFbRecon, fbSize, ctx->fbCount.reconFbNum, ENC_FBC, ctx->handle->instIndex)) {
  281. VLOG(ERR, "failed to allocate recon buffers\n");
  282. return FALSE;
  283. }
  284. fbAllocInfo.stride = fbStride;
  285. fbAllocInfo.height = fbHeight;
  286. fbAllocInfo.type = FB_TYPE_CODEC;
  287. fbAllocInfo.num = ctx->fbCount.reconFbNum;
  288. ctx->reconFbAllocInfo = fbAllocInfo;
  289. return TRUE;
  290. }
  291. static BOOL PrepareYuvFeeder(ComponentImpl* com, BOOL* done)
  292. {
  293. CNMComponentParamRet ret;
  294. YuvFeederContext* ctx = (YuvFeederContext*)com->context;
  295. EncOpenParam* encOpenParam = &ctx->encOpenParam;
  296. BOOL success;
  297. Uint32 i;
  298. YuvFeeder yuvFeeder = NULL;
  299. YuvInfo yuvFeederInfo;
  300. *done = FALSE;
  301. // wait signal GET_PARAM_ENC_FRAME_BUF_NUM
  302. ret = ComponentGetParameter(com, com->sinkPort.connectedComponent, GET_PARAM_ENC_FRAME_BUF_NUM, &ctx->fbCount);
  303. if (ComponentParamReturnTest(ret, &success) == FALSE) {
  304. return success;
  305. }
  306. ret = ComponentGetParameter(com, com->sinkPort.connectedComponent, GET_PARAM_ENC_HANDLE, &ctx->handle);
  307. if (ComponentParamReturnTest(ret, &success) == FALSE) {
  308. return success;
  309. }
  310. if (FALSE == AllocateFrameBuffer(com)) {
  311. VLOG(ERR, "AllocateFramBuffer() error\n");
  312. return FALSE;
  313. }
  314. osal_memset(&yuvFeederInfo, 0x00, sizeof(YuvInfo));
  315. yuvFeederInfo.cbcrInterleave = encOpenParam->cbcrInterleave;
  316. yuvFeederInfo.nv21 = encOpenParam->nv21;
  317. yuvFeederInfo.packedFormat = encOpenParam->packedFormat;
  318. yuvFeederInfo.srcFormat = encOpenParam->srcFormat;
  319. yuvFeederInfo.srcPlanar = TRUE;
  320. yuvFeederInfo.srcStride = ctx->srcFbAllocInfo.stride;
  321. yuvFeederInfo.srcHeight = VPU_CEIL(encOpenParam->picHeight, 8);
  322. yuvFeeder = YuvFeeder_Create(ctx->yuvMode, ctx->inputPath, yuvFeederInfo);
  323. if (yuvFeeder == NULL) {
  324. VLOG(ERR, "YuvFeeder_Create Error\n");
  325. return FALSE;
  326. }
  327. ((AbstractYuvFeeder*)yuvFeeder)->impl->handle = ctx->handle;
  328. ctx->yuvFeeder = yuvFeeder;
  329. // Fill data into the input queue of the sink port.
  330. // The empty input queue of the sink port occurs a hangup problem in this example.
  331. while (Queue_Dequeue(com->sinkPort.inputQ) != NULL);
  332. for (i = 0; i < com->sinkPort.inputQ->size; i++) {
  333. PortContainerYuv defaultData;
  334. osal_memset(&defaultData, 0x00, sizeof(PortContainerYuv));
  335. defaultData.srcFbIndex = -1;
  336. if (i<ctx->fbCount.srcFbNum) {
  337. defaultData.srcFbIndex = i;
  338. Queue_Enqueue(com->sinkPort.inputQ, (void*)&defaultData);
  339. }
  340. }
  341. if (PRODUCT_ID_NOT_W_SERIES(ctx->productID)) {
  342. VPU_EncGiveCommand(ctx->handle, GET_TILEDMAP_CONFIG, &(ctx->mapConfig));
  343. }
  344. ctx->fbAllocated = TRUE;
  345. *done = TRUE;
  346. return TRUE;
  347. }
  348. static BOOL ExecuteYuvFeeder(ComponentImpl* com, PortContainer* in, PortContainer* out)
  349. {
  350. YuvFeederContext* ctx = (YuvFeederContext*)com->context;
  351. EncOpenParam* encOpenParam = &ctx->encOpenParam;
  352. int ret = 0;
  353. PortContainerYuv* sinkData = (PortContainerYuv*)out;
  354. void* extraFeedingInfo = NULL;
  355. #ifdef USE_FEEDING_METHOD_BUFFER
  356. extern void yuvBufferFeeder_SetData(YuvFeederImpl* impl, Uint8* address, Uint32 size);
  357. PortContainerExternal *input = NULL;
  358. input = (PortContainerExternal *)ComponentPortPeekData(&com->srcPort);
  359. if (input == NULL) {
  360. return TRUE;
  361. }
  362. AbstractYuvFeeder* absFeeder = (AbstractYuvFeeder*)ctx->yuvFeeder;
  363. yuvBufferFeeder_SetData(absFeeder->impl, (Uint8 *)input->pBuffer, input->nFilledLen);
  364. #endif
  365. out->reuse = FALSE;
  366. if (ctx->state == YUV_FEEDER_STATE_WAIT) {
  367. CNMComponentParamRet ParamRet;
  368. BOOL success, done = FALSE;
  369. out->reuse = TRUE;
  370. ParamRet = ComponentGetParameter(com, com->sinkPort.connectedComponent, GET_PARAM_ENC_FRAME_BUF_REGISTERED, &done);
  371. if (ComponentParamReturnTest(ParamRet, &success) == FALSE) {
  372. return success;
  373. }
  374. if (done == FALSE) return TRUE;
  375. ctx->state = YUV_FEEDER_STATE_FEEDING;
  376. out->reuse = FALSE;
  377. }
  378. if ( ctx->last ) {
  379. sinkData->last = TRUE;
  380. return TRUE;
  381. }
  382. sinkData->fb = ctx->pFbSrc[sinkData->srcFbIndex];
  383. if (PRODUCT_ID_NOT_W_SERIES(ctx->productID)) {
  384. extraFeedingInfo = &(ctx->mapConfig);
  385. }
  386. #ifdef USE_FEEDING_METHOD_BUFFER
  387. if ((input->nFlags & 0x1) == 0x1)
  388. {
  389. ctx->last = sinkData->last = TRUE;
  390. // return TRUE;
  391. }
  392. #else
  393. ctx->feedingNum++;
  394. if (ctx->feedingNum > ctx->frameOutNum && ctx->frameOutNum != -1) {
  395. ctx->last = sinkData->last = TRUE;
  396. return TRUE;
  397. }
  398. #endif
  399. if (ctx->MemoryOptimization)
  400. {
  401. Uint32 nBufferIndex = input->nBufferIndex;
  402. Uint32 totalCount = Queue_Get_Cnt(com->sinkPort.inputQ);
  403. Uint32 i = 0;
  404. ret = TRUE;
  405. for(i = 0; i < totalCount; i ++) {
  406. VLOG(INFO, "Input index = %d, Output index = %d\n", nBufferIndex, sinkData->srcFbIndex);
  407. if (nBufferIndex == sinkData->srcFbIndex) {
  408. break;
  409. }
  410. void *tmp = ComponentPortGetData(&com->sinkPort);
  411. Queue_Enqueue(com->sinkPort.inputQ, (void *)tmp);
  412. sinkData = (PortContainerYuv*)ComponentPortPeekData(&com->sinkPort);
  413. }
  414. if (i == totalCount)
  415. {
  416. VLOG(ERR, "Could not find match index!\n");
  417. ret = FALSE;
  418. }
  419. } else {
  420. ret = YuvFeeder_Feed(ctx->yuvFeeder, encOpenParam->coreIdx, &sinkData->fb, encOpenParam->picWidth, encOpenParam->picHeight, sinkData->srcFbIndex, extraFeedingInfo);
  421. }
  422. if (ret == FALSE) {
  423. ctx->last = sinkData->last = TRUE;
  424. }
  425. #ifdef USE_FEEDING_METHOD_BUFFER
  426. if (input != NULL) {
  427. ComponentPortGetData(&com->srcPort);
  428. ComponentNotifyListeners(com, COMPONENT_EVENT_ENC_EMPTY_BUFFER_DONE, (void *)input);
  429. }
  430. if ((input->nFlags & 0x1) == 0x1)
  431. {
  432. while ((input = (PortContainerExternal*)ComponentPortGetData(&com->srcPort)) != NULL)
  433. {
  434. input->nFlags = 0x1;
  435. input->nFilledLen = 0;
  436. ComponentNotifyListeners(com, COMPONENT_EVENT_ENC_EMPTY_BUFFER_DONE, (void *)input);
  437. }
  438. }
  439. #endif
  440. return TRUE;
  441. }
  442. static void ReleaseYuvFeeder(ComponentImpl* com)
  443. {
  444. YuvFeederContext* ctx = (YuvFeederContext*)com->context;
  445. Uint32 i = 0;
  446. for (i = 0; i < ctx->fbCount.reconFbNum*2; i++) {
  447. if (ctx->pFbReconMem[i].size)
  448. vdi_free_dma_memory(ctx->encOpenParam.coreIdx, &ctx->pFbReconMem[i], ENC_FBC, ctx->handle->instIndex);
  449. }
  450. for (i = 0; i < ctx->fbCount.srcFbNum; i++) {
  451. if (ctx->pFbSrcMem[i].size)
  452. vdi_free_dma_memory(ctx->encOpenParam.coreIdx, &ctx->pFbSrcMem[i], ENC_SRC, ctx->handle->instIndex);
  453. if (ctx->pFbOffsetTblMem[i].size)
  454. vdi_free_dma_memory(ctx->encOpenParam.coreIdx, &ctx->pFbOffsetTblMem[i], ENC_FBCY_TBL, ctx->handle->instIndex);
  455. }
  456. }
  457. static BOOL DestroyYuvFeeder(ComponentImpl* com)
  458. {
  459. YuvFeederContext* ctx = (YuvFeederContext*)com->context;
  460. if (ctx->yuvFeeder) YuvFeeder_Destroy(ctx->yuvFeeder);
  461. osal_free(ctx);
  462. return TRUE;
  463. }
  464. static Component CreateYuvFeeder(ComponentImpl* com, CNMComponentConfig* componentParam)
  465. {
  466. YuvFeederContext* ctx;
  467. com->context = osal_malloc(sizeof(YuvFeederContext));
  468. ctx = (YuvFeederContext*)com->context;
  469. InitYuvFeederContext(ctx, componentParam);
  470. if ( ctx->encOpenParam.sourceBufCount > com->numSinkPortQueue )
  471. com->numSinkPortQueue = ctx->encOpenParam.sourceBufCount;//set requested sourceBufCount
  472. ctx->productID = componentParam->testEncConfig.productId;
  473. ctx->MemoryOptimization = TRUE;
  474. ctx->totalBufferNumber = 5;
  475. ctx->currentBufferNumber = 0;
  476. return (Component)com;
  477. }
  478. ComponentImpl yuvFeederComponentImpl = {
  479. "yuvfeeder",
  480. NULL,
  481. {0,},
  482. {0,},
  483. sizeof(PortContainerYuv),
  484. ENC_SRC_BUF_NUM, /* minimum feeder's numSinkPortQueue(relates to source buffer count)*/
  485. CreateYuvFeeder,
  486. GetParameterYuvFeeder,
  487. SetParameterYuvFeeder,
  488. PrepareYuvFeeder,
  489. ExecuteYuvFeeder,
  490. ReleaseYuvFeeder,
  491. DestroyYuvFeeder
  492. };