component_enc_feeder.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  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 (fbWidth % 32 > 0)
  149. {
  150. ctx->MemoryOptimization = FALSE;
  151. return NULL;
  152. }
  153. if (SRC_FB_TYPE_YUV == srcFbType) {
  154. mapType = LINEAR_FRAME_MAP;
  155. }
  156. fbStride = CalcStride(fbWidth, fbHeight, (FrameBufferFormat)encOpenParam.srcFormat, encOpenParam.cbcrInterleave, mapType, FALSE);
  157. fbSize = VPU_GetFrameBufSize(ctx->handle, encOpenParam.coreIdx, fbStride, fbHeight, mapType, (FrameBufferFormat)encOpenParam.srcFormat, encOpenParam.cbcrInterleave, pDramConfig);
  158. VLOG(INFO, "fbSize = %d\r\n", fbSize);
  159. fbAllocInfo.format = (FrameBufferFormat)encOpenParam.srcFormat;
  160. fbAllocInfo.cbcrInterleave = encOpenParam.cbcrInterleave;
  161. fbAllocInfo.mapType = mapType;
  162. fbAllocInfo.stride = fbStride;
  163. fbAllocInfo.height = fbHeight;
  164. fbAllocInfo.size = fbSize == 0? size : fbSize;
  165. fbAllocInfo.type = FB_TYPE_PPU;
  166. fbAllocInfo.num = ctx->fbCount.srcFbNum;
  167. fbAllocInfo.nv21 = encOpenParam.nv21;
  168. if (PRODUCT_ID_NOT_W_SERIES(ctx->productID)) {
  169. fbAllocInfo.lumaBitDepth = 8;
  170. fbAllocInfo.chromaBitDepth = 8;
  171. }
  172. for (i = 0;i < ENC_SRC_BUF_NUM; i ++){
  173. if (ctx->pFbSrcMem[i].phys_addr == 0)
  174. {
  175. VLOG(INFO, "Found empty frame at index %d\r\n", i);
  176. break;
  177. }
  178. }
  179. if (i == MAX_REG_FRAME)
  180. {
  181. VLOG(ERR, "Could not found empty frame at index\r\n");
  182. return NULL;
  183. }
  184. if (FALSE == AllocFBMemory(encOpenParam.coreIdx, &ctx->pFbSrcMem[i], &ctx->pFbSrc[i], fbAllocInfo.size, 1, ENC_SRC, ctx->handle->instIndex)) {
  185. VLOG(ERR, "failed to allocate source buffers\n");
  186. return NULL;
  187. }
  188. ctx->srcFbAllocInfo = fbAllocInfo;
  189. ctx->currentBufferNumber ++;
  190. return (void *)ctx->pFbSrcMem[i].virt_addr;
  191. }
  192. static BOOL AllocateFrameBuffer(ComponentImpl* com) {
  193. YuvFeederContext* ctx = (YuvFeederContext*)com->context;
  194. EncOpenParam encOpenParam = ctx->encOpenParam;
  195. Uint32 fbWidth = 0;
  196. Uint32 fbHeight = 0;
  197. Uint32 fbStride = 0;
  198. Uint32 fbSize = 0;
  199. SRC_FB_TYPE srcFbType = SRC_FB_TYPE_YUV;
  200. DRAMConfig dramConfig;
  201. DRAMConfig* pDramConfig = NULL;
  202. TiledMapType mapType;
  203. FrameBufferAllocInfo fbAllocInfo;
  204. osal_memset(&fbAllocInfo, 0x00, sizeof(FrameBufferAllocInfo));
  205. osal_memset(&dramConfig, 0x00, sizeof(DRAMConfig));
  206. //Buffers for source frames
  207. if (PRODUCT_ID_W_SERIES(ctx->productID)) {
  208. fbWidth = VPU_ALIGN8(encOpenParam.picWidth);
  209. fbHeight = VPU_ALIGN8(encOpenParam.picHeight);
  210. fbAllocInfo.endian = encOpenParam.sourceEndian;
  211. } else {
  212. //CODA
  213. fbWidth = VPU_ALIGN16(encOpenParam.picWidth);
  214. fbHeight = VPU_ALIGN16(encOpenParam.picHeight);
  215. fbAllocInfo.endian = encOpenParam.frameEndian;
  216. VPU_EncGiveCommand(ctx->handle, GET_DRAM_CONFIG, &dramConfig);
  217. pDramConfig = &dramConfig;
  218. }
  219. VLOG(INFO, "fbWidth = %d fbHeight = %d MemoryOptimization = %d\r\n", fbWidth, fbHeight, ctx->MemoryOptimization);
  220. if (fbWidth % 32 > 0)
  221. {
  222. ctx->MemoryOptimization = FALSE;
  223. }
  224. else if (ctx->MemoryOptimization)
  225. {
  226. goto alloc_fbc;
  227. }
  228. VLOG(INFO, "Alloc FrameBuffers\r\n");
  229. if (SRC_FB_TYPE_YUV == srcFbType) {
  230. mapType = LINEAR_FRAME_MAP;
  231. }
  232. fbStride = CalcStride(fbWidth, fbHeight, (FrameBufferFormat)encOpenParam.srcFormat, encOpenParam.cbcrInterleave, mapType, FALSE);
  233. fbSize = VPU_GetFrameBufSize(ctx->handle, encOpenParam.coreIdx, fbStride, fbHeight, mapType, (FrameBufferFormat)encOpenParam.srcFormat, encOpenParam.cbcrInterleave, pDramConfig);
  234. fbAllocInfo.format = (FrameBufferFormat)encOpenParam.srcFormat;
  235. fbAllocInfo.cbcrInterleave = encOpenParam.cbcrInterleave;
  236. fbAllocInfo.mapType = mapType;
  237. fbAllocInfo.stride = fbStride;
  238. fbAllocInfo.height = fbHeight;
  239. fbAllocInfo.size = fbSize;
  240. fbAllocInfo.type = FB_TYPE_PPU;
  241. fbAllocInfo.num = ctx->fbCount.srcFbNum;
  242. fbAllocInfo.nv21 = encOpenParam.nv21;
  243. if (PRODUCT_ID_NOT_W_SERIES(ctx->productID)) {
  244. fbAllocInfo.lumaBitDepth = 8;
  245. fbAllocInfo.chromaBitDepth = 8;
  246. }
  247. if (FALSE == AllocFBMemory(encOpenParam.coreIdx, ctx->pFbSrcMem, ctx->pFbSrc, fbSize, ctx->fbCount.srcFbNum, ENC_SRC, ctx->handle->instIndex)) {
  248. VLOG(ERR, "failed to allocate source buffers\n");
  249. return FALSE;
  250. }
  251. ctx->srcFbAllocInfo = fbAllocInfo;
  252. ctx->currentBufferNumber = ctx->fbCount.srcFbNum;
  253. alloc_fbc:
  254. //Buffers for reconstructed frames
  255. osal_memset(&fbAllocInfo, 0x00, sizeof(FrameBufferAllocInfo));
  256. if (PRODUCT_ID_W_SERIES(ctx->productID)) {
  257. pDramConfig = NULL;
  258. if (ctx->encOpenParam.bitstreamFormat == STD_AVC) {
  259. fbWidth = VPU_ALIGN16(encOpenParam.picWidth);
  260. fbHeight = VPU_ALIGN16(encOpenParam.picHeight);
  261. } else {
  262. fbWidth = VPU_ALIGN8(encOpenParam.picWidth);
  263. fbHeight = VPU_ALIGN8(encOpenParam.picHeight);
  264. }
  265. if ((ctx->rotAngle != 0 || ctx->mirDir != 0) && !(ctx->rotAngle == 180 && ctx->mirDir == MIRDIR_HOR_VER)) {
  266. fbWidth = VPU_ALIGN32(encOpenParam.picWidth);
  267. fbHeight = VPU_ALIGN32(encOpenParam.picHeight);
  268. }
  269. //TODO if --> else if
  270. if (ctx->rotAngle == 90 || ctx->rotAngle == 270) {
  271. fbWidth = VPU_ALIGN32(encOpenParam.picHeight);
  272. fbHeight = VPU_ALIGN32(encOpenParam.picWidth);
  273. }
  274. if (WAVE521C_DUAL_CODE == (VPU_HANDLE_TO_ENCINFO(ctx->handle)->productCode)) {
  275. mapType = encOpenParam.EncStdParam.waveParam.internalBitDepth==8?COMPRESSED_FRAME_MAP_DUAL_CORE_8BIT:COMPRESSED_FRAME_MAP_DUAL_CORE_10BIT;
  276. } else {
  277. mapType = COMPRESSED_FRAME_MAP;
  278. }
  279. } else {
  280. //CODA
  281. pDramConfig = &dramConfig;
  282. fbWidth = encOpenParam.picWidth;
  283. fbHeight = encOpenParam.picHeight;
  284. if (90 == ctx->rotAngle || 270 == ctx->rotAngle) {
  285. fbWidth = encOpenParam.picHeight;
  286. fbHeight = encOpenParam.picWidth;
  287. }
  288. fbWidth = VPU_ALIGN16(fbWidth);
  289. fbHeight = VPU_ALIGN32(fbHeight);
  290. mapType = mapType;
  291. }
  292. fbStride = CalcStride(fbWidth, fbHeight, (FrameBufferFormat)encOpenParam.outputFormat, encOpenParam.cbcrInterleave, mapType, FALSE);
  293. fbSize = VPU_GetFrameBufSize(ctx->handle, encOpenParam.coreIdx, fbStride, fbHeight, mapType, (FrameBufferFormat)encOpenParam.outputFormat, encOpenParam.cbcrInterleave, pDramConfig);
  294. if (FALSE == AllocFBMemory(encOpenParam.coreIdx, ctx->pFbReconMem, ctx->pFbRecon, fbSize, ctx->fbCount.reconFbNum, ENC_FBC, ctx->handle->instIndex)) {
  295. VLOG(ERR, "failed to allocate recon buffers\n");
  296. return FALSE;
  297. }
  298. fbAllocInfo.stride = fbStride;
  299. fbAllocInfo.height = fbHeight;
  300. fbAllocInfo.type = FB_TYPE_CODEC;
  301. fbAllocInfo.num = ctx->fbCount.reconFbNum;
  302. ctx->reconFbAllocInfo = fbAllocInfo;
  303. return TRUE;
  304. }
  305. static BOOL PrepareYuvFeeder(ComponentImpl* com, BOOL* done)
  306. {
  307. CNMComponentParamRet ret;
  308. YuvFeederContext* ctx = (YuvFeederContext*)com->context;
  309. EncOpenParam* encOpenParam = &ctx->encOpenParam;
  310. BOOL success;
  311. Uint32 i;
  312. YuvFeeder yuvFeeder = NULL;
  313. YuvInfo yuvFeederInfo;
  314. *done = FALSE;
  315. // wait signal GET_PARAM_ENC_FRAME_BUF_NUM
  316. ret = ComponentGetParameter(com, com->sinkPort.connectedComponent, GET_PARAM_ENC_FRAME_BUF_NUM, &ctx->fbCount);
  317. if (ComponentParamReturnTest(ret, &success) == FALSE) {
  318. return success;
  319. }
  320. ret = ComponentGetParameter(com, com->sinkPort.connectedComponent, GET_PARAM_ENC_HANDLE, &ctx->handle);
  321. if (ComponentParamReturnTest(ret, &success) == FALSE) {
  322. return success;
  323. }
  324. if (FALSE == AllocateFrameBuffer(com)) {
  325. VLOG(ERR, "AllocateFramBuffer() error\n");
  326. return FALSE;
  327. }
  328. osal_memset(&yuvFeederInfo, 0x00, sizeof(YuvInfo));
  329. yuvFeederInfo.cbcrInterleave = encOpenParam->cbcrInterleave;
  330. yuvFeederInfo.nv21 = encOpenParam->nv21;
  331. yuvFeederInfo.packedFormat = encOpenParam->packedFormat;
  332. yuvFeederInfo.srcFormat = encOpenParam->srcFormat;
  333. yuvFeederInfo.srcPlanar = TRUE;
  334. yuvFeederInfo.srcStride = ctx->srcFbAllocInfo.stride;
  335. yuvFeederInfo.srcHeight = VPU_CEIL(encOpenParam->picHeight, 8);
  336. yuvFeeder = YuvFeeder_Create(ctx->yuvMode, ctx->inputPath, yuvFeederInfo);
  337. if (yuvFeeder == NULL) {
  338. VLOG(ERR, "YuvFeeder_Create Error\n");
  339. return FALSE;
  340. }
  341. ((AbstractYuvFeeder*)yuvFeeder)->impl->handle = ctx->handle;
  342. ctx->yuvFeeder = yuvFeeder;
  343. // Fill data into the input queue of the sink port.
  344. // The empty input queue of the sink port occurs a hangup problem in this example.
  345. while (Queue_Dequeue(com->sinkPort.inputQ) != NULL);
  346. for (i = 0; i < com->sinkPort.inputQ->size; i++) {
  347. PortContainerYuv defaultData;
  348. osal_memset(&defaultData, 0x00, sizeof(PortContainerYuv));
  349. defaultData.srcFbIndex = -1;
  350. if (i<ctx->fbCount.srcFbNum) {
  351. defaultData.srcFbIndex = i;
  352. Queue_Enqueue(com->sinkPort.inputQ, (void*)&defaultData);
  353. }
  354. }
  355. if (PRODUCT_ID_NOT_W_SERIES(ctx->productID)) {
  356. VPU_EncGiveCommand(ctx->handle, GET_TILEDMAP_CONFIG, &(ctx->mapConfig));
  357. }
  358. ctx->fbAllocated = TRUE;
  359. *done = TRUE;
  360. return TRUE;
  361. }
  362. static BOOL ExecuteYuvFeeder(ComponentImpl* com, PortContainer* in, PortContainer* out)
  363. {
  364. YuvFeederContext* ctx = (YuvFeederContext*)com->context;
  365. EncOpenParam* encOpenParam = &ctx->encOpenParam;
  366. int ret = 0;
  367. PortContainerYuv* sinkData = (PortContainerYuv*)out;
  368. void* extraFeedingInfo = NULL;
  369. #ifdef USE_FEEDING_METHOD_BUFFER
  370. extern void yuvBufferFeeder_SetData(YuvFeederImpl* impl, Uint8* address, Uint32 size);
  371. PortContainerExternal *input = NULL;
  372. input = (PortContainerExternal *)ComponentPortPeekData(&com->srcPort);
  373. if (input == NULL) {
  374. return TRUE;
  375. }
  376. AbstractYuvFeeder* absFeeder = (AbstractYuvFeeder*)ctx->yuvFeeder;
  377. yuvBufferFeeder_SetData(absFeeder->impl, (Uint8 *)input->pBuffer, input->nFilledLen);
  378. #endif
  379. out->reuse = FALSE;
  380. if (ctx->state == YUV_FEEDER_STATE_WAIT) {
  381. CNMComponentParamRet ParamRet;
  382. BOOL success, done = FALSE;
  383. out->reuse = TRUE;
  384. ParamRet = ComponentGetParameter(com, com->sinkPort.connectedComponent, GET_PARAM_ENC_FRAME_BUF_REGISTERED, &done);
  385. if (ComponentParamReturnTest(ParamRet, &success) == FALSE) {
  386. return success;
  387. }
  388. if (done == FALSE) return TRUE;
  389. ctx->state = YUV_FEEDER_STATE_FEEDING;
  390. out->reuse = FALSE;
  391. }
  392. if ( ctx->last ) {
  393. sinkData->last = TRUE;
  394. return TRUE;
  395. }
  396. sinkData->fb = ctx->pFbSrc[sinkData->srcFbIndex];
  397. if (PRODUCT_ID_NOT_W_SERIES(ctx->productID)) {
  398. extraFeedingInfo = &(ctx->mapConfig);
  399. }
  400. #ifdef USE_FEEDING_METHOD_BUFFER
  401. if ((input->nFlags & 0x1) == 0x1)
  402. {
  403. ctx->last = sinkData->last = TRUE;
  404. // return TRUE;
  405. }
  406. #else
  407. ctx->feedingNum++;
  408. if (ctx->feedingNum > ctx->frameOutNum && ctx->frameOutNum != -1) {
  409. ctx->last = sinkData->last = TRUE;
  410. return TRUE;
  411. }
  412. #endif
  413. if (ctx->MemoryOptimization)
  414. {
  415. Uint32 nBufferIndex = input->nBufferIndex;
  416. Uint32 totalCount = Queue_Get_Cnt(com->sinkPort.inputQ);
  417. Uint32 i = 0;
  418. ret = TRUE;
  419. for(i = 0; i < totalCount; i ++) {
  420. VLOG(INFO, "Input index = %d, Output index = %d\n", nBufferIndex, sinkData->srcFbIndex);
  421. if (nBufferIndex == sinkData->srcFbIndex) {
  422. break;
  423. }
  424. void *tmp = ComponentPortGetData(&com->sinkPort);
  425. Queue_Enqueue(com->sinkPort.inputQ, (void *)tmp);
  426. sinkData = (PortContainerYuv*)ComponentPortPeekData(&com->sinkPort);
  427. }
  428. if (i == totalCount)
  429. {
  430. VLOG(ERR, "Could not find match index!\n");
  431. ret = FALSE;
  432. }
  433. } else {
  434. VLOG(INFO, "Normal Feed\r\n");
  435. ret = YuvFeeder_Feed(ctx->yuvFeeder, encOpenParam->coreIdx, &sinkData->fb, encOpenParam->picWidth, encOpenParam->picHeight, sinkData->srcFbIndex, extraFeedingInfo);
  436. }
  437. if (ret == FALSE) {
  438. ctx->last = sinkData->last = TRUE;
  439. }
  440. #ifdef USE_FEEDING_METHOD_BUFFER
  441. if (input != NULL) {
  442. ComponentPortGetData(&com->srcPort);
  443. ComponentNotifyListeners(com, COMPONENT_EVENT_ENC_EMPTY_BUFFER_DONE, (void *)input);
  444. }
  445. if ((input->nFlags & 0x1) == 0x1)
  446. {
  447. while ((input = (PortContainerExternal*)ComponentPortGetData(&com->srcPort)) != NULL)
  448. {
  449. input->nFlags = 0x1;
  450. input->nFilledLen = 0;
  451. ComponentNotifyListeners(com, COMPONENT_EVENT_ENC_EMPTY_BUFFER_DONE, (void *)input);
  452. }
  453. }
  454. #endif
  455. return TRUE;
  456. }
  457. static void ReleaseYuvFeeder(ComponentImpl* com)
  458. {
  459. YuvFeederContext* ctx = (YuvFeederContext*)com->context;
  460. Uint32 i = 0;
  461. for (i = 0; i < ctx->fbCount.reconFbNum*2; i++) {
  462. if (ctx->pFbReconMem[i].size)
  463. vdi_free_dma_memory(ctx->encOpenParam.coreIdx, &ctx->pFbReconMem[i], ENC_FBC, ctx->handle->instIndex);
  464. }
  465. for (i = 0; i < ctx->fbCount.srcFbNum; i++) {
  466. if (ctx->pFbSrcMem[i].size)
  467. vdi_free_dma_memory(ctx->encOpenParam.coreIdx, &ctx->pFbSrcMem[i], ENC_SRC, ctx->handle->instIndex);
  468. if (ctx->pFbOffsetTblMem[i].size)
  469. vdi_free_dma_memory(ctx->encOpenParam.coreIdx, &ctx->pFbOffsetTblMem[i], ENC_FBCY_TBL, ctx->handle->instIndex);
  470. }
  471. }
  472. static BOOL DestroyYuvFeeder(ComponentImpl* com)
  473. {
  474. YuvFeederContext* ctx = (YuvFeederContext*)com->context;
  475. if (ctx->yuvFeeder) YuvFeeder_Destroy(ctx->yuvFeeder);
  476. osal_free(ctx);
  477. return TRUE;
  478. }
  479. static Component CreateYuvFeeder(ComponentImpl* com, CNMComponentConfig* componentParam)
  480. {
  481. YuvFeederContext* ctx;
  482. com->context = osal_malloc(sizeof(YuvFeederContext));
  483. ctx = (YuvFeederContext*)com->context;
  484. InitYuvFeederContext(ctx, componentParam);
  485. if ( ctx->encOpenParam.sourceBufCount > com->numSinkPortQueue )
  486. com->numSinkPortQueue = ctx->encOpenParam.sourceBufCount;//set requested sourceBufCount
  487. ctx->productID = componentParam->testEncConfig.productId;
  488. ctx->MemoryOptimization = TRUE;
  489. ctx->totalBufferNumber = 5;
  490. ctx->currentBufferNumber = 0;
  491. return (Component)com;
  492. }
  493. ComponentImpl yuvFeederComponentImpl = {
  494. "yuvfeeder",
  495. NULL,
  496. {0,},
  497. {0,},
  498. sizeof(PortContainerYuv),
  499. ENC_SRC_BUF_NUM, /* minimum feeder's numSinkPortQueue(relates to source buffer count)*/
  500. CreateYuvFeeder,
  501. GetParameterYuvFeeder,
  502. SetParameterYuvFeeder,
  503. PrepareYuvFeeder,
  504. ExecuteYuvFeeder,
  505. ReleaseYuvFeeder,
  506. DestroyYuvFeeder
  507. };