123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665 |
- /*
- * Copyright (c) 2019, Chips&Media
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- #include <string.h>
- #include "component.h"
- typedef enum {
- SRC_FB_TYPE_YUV,
- SRC_FB_TYPE_CFRAME
- } SRC_FB_TYPE;
- typedef enum {
- YUV_FEEDER_STATE_WAIT,
- YUV_FEEDER_STATE_FEEDING
- } YuvFeederState;
- typedef struct {
- EncHandle handle;
- char inputPath[MAX_FILE_PATH];
- EncOpenParam encOpenParam;
- Int32 rotAngle;
- Int32 mirDir;
- Int32 frameOutNum;
- Int32 yuvMode;
- FrameBufferAllocInfo srcFbAllocInfo;
- FrameBufferAllocInfo reconFbAllocInfo;
- BOOL fbAllocated;
- ParamEncNeedFrameBufferNum fbCount;
- FrameBuffer pFbRecon[MAX_REG_FRAME];
- vpu_buffer_t pFbReconMem[MAX_REG_FRAME];
- FrameBuffer pFbSrc[ENC_SRC_BUF_NUM];
- vpu_buffer_t pFbSrcMem[ENC_SRC_BUF_NUM];
- FrameBuffer pFbOffsetTbl[ENC_SRC_BUF_NUM];
- vpu_buffer_t pFbOffsetTblMem[ENC_SRC_BUF_NUM];
- YuvFeeder yuvFeeder;
- BOOL last;
- YuvFeederState state;
- BOOL stateDoing;
- Int32 feedingNum;
- TiledMapConfig mapConfig;
- Int32 productID;
- BOOL MemoryOptimization;
- int totalBufferNumber;
- int currentBufferNumber;
- } YuvFeederContext;
- static void InitYuvFeederContext(YuvFeederContext* ctx, CNMComponentConfig* componentParam)
- {
- osal_memset((void*)ctx, 0, sizeof(YuvFeederContext));
- strcpy(ctx->inputPath, componentParam->testEncConfig.yuvFileName);
- ctx->fbAllocated = FALSE;
- ctx->encOpenParam = componentParam->encOpenParam;
- ctx->yuvMode = componentParam->testEncConfig.yuv_mode;
- ctx->fbCount.reconFbNum = 0;
- ctx->fbCount.srcFbNum = 0;
- ctx->frameOutNum = componentParam->testEncConfig.outNum;
- ctx->rotAngle = componentParam->testEncConfig.rotAngle;
- ctx->mirDir = componentParam->testEncConfig.mirDir;
- osal_memset(&ctx->srcFbAllocInfo, 0x00, sizeof(FrameBufferAllocInfo));
- osal_memset(&ctx->reconFbAllocInfo, 0x00, sizeof(FrameBufferAllocInfo));
- osal_memset((void*)ctx->pFbRecon, 0x00, sizeof(ctx->pFbRecon));
- osal_memset((void*)ctx->pFbReconMem, 0x00, sizeof(ctx->pFbReconMem));
- osal_memset((void*)ctx->pFbSrc, 0x00, sizeof(ctx->pFbSrc));
- osal_memset((void*)ctx->pFbSrcMem, 0x00, sizeof(ctx->pFbSrcMem));
- osal_memset((void*)ctx->pFbOffsetTbl, 0x00, sizeof(ctx->pFbOffsetTbl));
- osal_memset((void*)ctx->pFbOffsetTblMem, 0x00, sizeof(ctx->pFbOffsetTblMem));
- }
- static CNMComponentParamRet GetParameterYuvFeeder(ComponentImpl* from, ComponentImpl* com, GetParameterCMD commandType, void* data)
- {
- YuvFeederContext* ctx = (YuvFeederContext*)com->context;
- BOOL result = TRUE;
- ParamEncFrameBuffer* allocFb = NULL;
- switch(commandType) {
- case GET_PARAM_YUVFEEDER_FRAME_BUF:
- if (ctx->fbAllocated == FALSE || ctx->currentBufferNumber < ctx->totalBufferNumber) return CNM_COMPONENT_PARAM_NOT_READY;
- allocFb = (ParamEncFrameBuffer*)data;
- allocFb->reconFb = ctx->pFbRecon;
- allocFb->srcFb = ctx->pFbSrc;
- allocFb->reconFbAllocInfo = ctx->reconFbAllocInfo;
- allocFb->srcFbAllocInfo = ctx->srcFbAllocInfo;
- break;
- default:
- return CNM_COMPONENT_PARAM_NOT_FOUND;
- }
- return (result == TRUE) ? CNM_COMPONENT_PARAM_SUCCESS : CNM_COMPONENT_PARAM_FAILURE;
- }
- static CNMComponentParamRet SetParameterYuvFeeder(ComponentImpl* from, ComponentImpl* com, SetParameterCMD commandType, void* data)
- {
- BOOL result = TRUE;
- switch(commandType) {
- default:
- VLOG(ERR, "Unknown SetParameterCMD Type : %d\n", commandType);
- result = FALSE;
- break;
- }
- return (result == TRUE) ? CNM_COMPONENT_PARAM_SUCCESS : CNM_COMPONENT_PARAM_FAILURE;
- }
- BOOL GetAllocInfo(ComponentImpl* com, Uint32 size)
- {
- YuvFeederContext* ctx = (YuvFeederContext*)com->context;
- EncOpenParam encOpenParam = ctx->encOpenParam;
- FrameBufferAllocInfo fbAllocInfo;
- Uint32 fbWidth = 0;
- Uint32 fbHeight = 0;
- Uint32 fbStride = 0;
- SRC_FB_TYPE srcFbType = SRC_FB_TYPE_YUV;
- TiledMapType mapType;
- osal_memset(&fbAllocInfo, 0x00, sizeof(FrameBufferAllocInfo));
- //Buffers for source frames
- if (PRODUCT_ID_W_SERIES(ctx->productID)) {
- fbWidth = VPU_ALIGN8(encOpenParam.picWidth);
- fbHeight = VPU_ALIGN8(encOpenParam.picHeight);
- fbAllocInfo.endian = encOpenParam.sourceEndian;
- } else {
- //CODA
- fbWidth = VPU_ALIGN16(encOpenParam.picWidth);
- fbHeight = VPU_ALIGN16(encOpenParam.picHeight);
- fbAllocInfo.endian = encOpenParam.frameEndian;
- }
- if (SRC_FB_TYPE_YUV == srcFbType) {
- mapType = LINEAR_FRAME_MAP;
- }
- fbStride = CalcStride(fbWidth, fbHeight, (FrameBufferFormat)encOpenParam.srcFormat, encOpenParam.cbcrInterleave, mapType, FALSE);
- fbAllocInfo.format = (FrameBufferFormat)encOpenParam.srcFormat;
- fbAllocInfo.cbcrInterleave = encOpenParam.cbcrInterleave;
- fbAllocInfo.mapType = mapType;
- fbAllocInfo.stride = fbStride;
- fbAllocInfo.height = fbHeight;
- fbAllocInfo.size = size;
- fbAllocInfo.type = FB_TYPE_PPU;
- fbAllocInfo.num = ctx->fbCount.srcFbNum;
- fbAllocInfo.nv21 = encOpenParam.nv21;
- if (PRODUCT_ID_NOT_W_SERIES(ctx->productID)) {
- fbAllocInfo.lumaBitDepth = 8;
- fbAllocInfo.chromaBitDepth = 8;
- }
- ctx->srcFbAllocInfo = fbAllocInfo;
- return TRUE;
- }
- void SetFeederTotalBufferNumber(ComponentImpl* com, Uint32 number)
- {
- YuvFeederContext* ctx = (YuvFeederContext*)com->context;
- ctx->totalBufferNumber = number;
- }
- BOOL AttachDMABuffer(ComponentImpl* com, void *pBuffer, Uint32 size)
- {
- YuvFeederContext* ctx = (YuvFeederContext*)com->context;
- EncOpenParam encOpenParam = ctx->encOpenParam;
- int i = 0;
- GetAllocInfo(com, size);
- for (i = 0;i < ENC_SRC_BUF_NUM; i ++){
- if (ctx->pFbSrcMem[i].phys_addr == 0)
- {
- VLOG(INFO, "Found empty frame at index %d\r\n", i);
- break;
- }
- }
- if (i == MAX_REG_FRAME)
- {
- VLOG(ERR, "Could not found empty frame at index\r\n");
- return FALSE;
- }
- if (FALSE == AttachFBMemory(encOpenParam.coreIdx, &ctx->pFbSrcMem[i], &ctx->pFbSrc[i], pBuffer, size)) {
- VLOG(ERR, "failed to attach source buffers\n");
- return FALSE;
- }
- ctx->pFbSrcMem[i].virt_addr = (unsigned long)pBuffer;
- ctx->currentBufferNumber ++;
- return TRUE;
- }
- void* AllocateFrameBuffer2(ComponentImpl* com, Uint32 size)
- {
- YuvFeederContext* ctx = (YuvFeederContext*)com->context;
- EncOpenParam encOpenParam = ctx->encOpenParam;
- Uint32 fbWidth = 0;
- Uint32 fbHeight = 0;
- Uint32 fbStride = 0;
- Uint32 fbSize = 0;
- SRC_FB_TYPE srcFbType = SRC_FB_TYPE_YUV;
- DRAMConfig dramConfig;
- DRAMConfig* pDramConfig = NULL;
- TiledMapType mapType;
- FrameBufferAllocInfo fbAllocInfo;
- int i = 0;
- if (ctx->handle == NULL) {
- ctx->MemoryOptimization = FALSE;
- return NULL;
- }
- osal_memset(&fbAllocInfo, 0x00, sizeof(FrameBufferAllocInfo));
- osal_memset(&dramConfig, 0x00, sizeof(DRAMConfig));
- //Buffers for source frames
- if (PRODUCT_ID_W_SERIES(ctx->productID)) {
- fbWidth = VPU_ALIGN8(encOpenParam.picWidth);
- fbHeight = VPU_ALIGN8(encOpenParam.picHeight);
- fbAllocInfo.endian = encOpenParam.sourceEndian;
- } else {
- //CODA
- fbWidth = VPU_ALIGN16(encOpenParam.picWidth);
- fbHeight = VPU_ALIGN16(encOpenParam.picHeight);
- fbAllocInfo.endian = encOpenParam.frameEndian;
- VPU_EncGiveCommand(ctx->handle, GET_DRAM_CONFIG, &dramConfig);
- pDramConfig = &dramConfig;
- }
- if (fbWidth % 32 > 0)
- {
- ctx->MemoryOptimization = FALSE;
- return NULL;
- }
- if (SRC_FB_TYPE_YUV == srcFbType) {
- mapType = LINEAR_FRAME_MAP;
- }
- fbStride = CalcStride(fbWidth, fbHeight, (FrameBufferFormat)encOpenParam.srcFormat, encOpenParam.cbcrInterleave, mapType, FALSE);
- fbSize = VPU_GetFrameBufSize(ctx->handle, encOpenParam.coreIdx, fbStride, fbHeight, mapType, (FrameBufferFormat)encOpenParam.srcFormat, encOpenParam.cbcrInterleave, pDramConfig);
- VLOG(INFO, "fbSize = %d\r\n", fbSize);
- fbAllocInfo.format = (FrameBufferFormat)encOpenParam.srcFormat;
- fbAllocInfo.cbcrInterleave = encOpenParam.cbcrInterleave;
- fbAllocInfo.mapType = mapType;
- fbAllocInfo.stride = fbStride;
- fbAllocInfo.height = fbHeight;
- fbAllocInfo.size = fbSize == 0? size : fbSize;
- fbAllocInfo.type = FB_TYPE_PPU;
- fbAllocInfo.num = ctx->fbCount.srcFbNum;
- fbAllocInfo.nv21 = encOpenParam.nv21;
- if (PRODUCT_ID_NOT_W_SERIES(ctx->productID)) {
- fbAllocInfo.lumaBitDepth = 8;
- fbAllocInfo.chromaBitDepth = 8;
- }
- for (i = 0;i < ENC_SRC_BUF_NUM; i ++){
- if (ctx->pFbSrcMem[i].phys_addr == 0)
- {
- VLOG(INFO, "Found empty frame at index %d\r\n", i);
- break;
- }
- }
- if (i == MAX_REG_FRAME)
- {
- VLOG(ERR, "Could not found empty frame at index\r\n");
- return NULL;
- }
- if (FALSE == AllocFBMemory(encOpenParam.coreIdx, &ctx->pFbSrcMem[i], &ctx->pFbSrc[i], fbAllocInfo.size, 1, ENC_SRC, ctx->handle->instIndex)) {
- VLOG(ERR, "failed to allocate source buffers\n");
- return NULL;
- }
- ctx->srcFbAllocInfo = fbAllocInfo;
- ctx->currentBufferNumber ++;
- return (void *)ctx->pFbSrcMem[i].virt_addr;
- }
- static BOOL AllocateFrameBuffer(ComponentImpl* com) {
- YuvFeederContext* ctx = (YuvFeederContext*)com->context;
- EncOpenParam encOpenParam = ctx->encOpenParam;
- Uint32 fbWidth = 0;
- Uint32 fbHeight = 0;
- Uint32 fbStride = 0;
- Uint32 fbSize = 0;
- SRC_FB_TYPE srcFbType = SRC_FB_TYPE_YUV;
- DRAMConfig dramConfig;
- DRAMConfig* pDramConfig = NULL;
- TiledMapType mapType;
- FrameBufferAllocInfo fbAllocInfo;
- osal_memset(&fbAllocInfo, 0x00, sizeof(FrameBufferAllocInfo));
- osal_memset(&dramConfig, 0x00, sizeof(DRAMConfig));
- //Buffers for source frames
- if (PRODUCT_ID_W_SERIES(ctx->productID)) {
- fbWidth = VPU_ALIGN8(encOpenParam.picWidth);
- fbHeight = VPU_ALIGN8(encOpenParam.picHeight);
- fbAllocInfo.endian = encOpenParam.sourceEndian;
- } else {
- //CODA
- fbWidth = VPU_ALIGN16(encOpenParam.picWidth);
- fbHeight = VPU_ALIGN16(encOpenParam.picHeight);
- fbAllocInfo.endian = encOpenParam.frameEndian;
- VPU_EncGiveCommand(ctx->handle, GET_DRAM_CONFIG, &dramConfig);
- pDramConfig = &dramConfig;
- }
- VLOG(INFO, "fbWidth = %d fbHeight = %d MemoryOptimization = %d\r\n", fbWidth, fbHeight, ctx->MemoryOptimization);
- if (fbWidth % 32 > 0)
- {
- ctx->MemoryOptimization = FALSE;
- }
- else if (ctx->MemoryOptimization)
- {
- goto alloc_fbc;
- }
- VLOG(INFO, "Alloc FrameBuffers\r\n");
- if (SRC_FB_TYPE_YUV == srcFbType) {
- mapType = LINEAR_FRAME_MAP;
- }
- fbStride = CalcStride(fbWidth, fbHeight, (FrameBufferFormat)encOpenParam.srcFormat, encOpenParam.cbcrInterleave, mapType, FALSE);
- fbSize = VPU_GetFrameBufSize(ctx->handle, encOpenParam.coreIdx, fbStride, fbHeight, mapType, (FrameBufferFormat)encOpenParam.srcFormat, encOpenParam.cbcrInterleave, pDramConfig);
- fbAllocInfo.format = (FrameBufferFormat)encOpenParam.srcFormat;
- fbAllocInfo.cbcrInterleave = encOpenParam.cbcrInterleave;
- fbAllocInfo.mapType = mapType;
- fbAllocInfo.stride = fbStride;
- fbAllocInfo.height = fbHeight;
- fbAllocInfo.size = fbSize;
- fbAllocInfo.type = FB_TYPE_PPU;
- fbAllocInfo.num = ctx->fbCount.srcFbNum;
- fbAllocInfo.nv21 = encOpenParam.nv21;
- if (PRODUCT_ID_NOT_W_SERIES(ctx->productID)) {
- fbAllocInfo.lumaBitDepth = 8;
- fbAllocInfo.chromaBitDepth = 8;
- }
- if (FALSE == AllocFBMemory(encOpenParam.coreIdx, ctx->pFbSrcMem, ctx->pFbSrc, fbSize, ctx->fbCount.srcFbNum, ENC_SRC, ctx->handle->instIndex)) {
- VLOG(ERR, "failed to allocate source buffers\n");
- return FALSE;
- }
- ctx->srcFbAllocInfo = fbAllocInfo;
- ctx->currentBufferNumber = ctx->fbCount.srcFbNum;
- alloc_fbc:
- //Buffers for reconstructed frames
- osal_memset(&fbAllocInfo, 0x00, sizeof(FrameBufferAllocInfo));
- if (PRODUCT_ID_W_SERIES(ctx->productID)) {
- pDramConfig = NULL;
- if (ctx->encOpenParam.bitstreamFormat == STD_AVC) {
- fbWidth = VPU_ALIGN16(encOpenParam.picWidth);
- fbHeight = VPU_ALIGN16(encOpenParam.picHeight);
- } else {
- fbWidth = VPU_ALIGN8(encOpenParam.picWidth);
- fbHeight = VPU_ALIGN8(encOpenParam.picHeight);
- }
- if ((ctx->rotAngle != 0 || ctx->mirDir != 0) && !(ctx->rotAngle == 180 && ctx->mirDir == MIRDIR_HOR_VER)) {
- fbWidth = VPU_ALIGN32(encOpenParam.picWidth);
- fbHeight = VPU_ALIGN32(encOpenParam.picHeight);
- }
- //TODO if --> else if
- if (ctx->rotAngle == 90 || ctx->rotAngle == 270) {
- fbWidth = VPU_ALIGN32(encOpenParam.picHeight);
- fbHeight = VPU_ALIGN32(encOpenParam.picWidth);
- }
- if (WAVE521C_DUAL_CODE == (VPU_HANDLE_TO_ENCINFO(ctx->handle)->productCode)) {
- mapType = encOpenParam.EncStdParam.waveParam.internalBitDepth==8?COMPRESSED_FRAME_MAP_DUAL_CORE_8BIT:COMPRESSED_FRAME_MAP_DUAL_CORE_10BIT;
- } else {
- mapType = COMPRESSED_FRAME_MAP;
- }
- } else {
- //CODA
- pDramConfig = &dramConfig;
- fbWidth = encOpenParam.picWidth;
- fbHeight = encOpenParam.picHeight;
- if (90 == ctx->rotAngle || 270 == ctx->rotAngle) {
- fbWidth = encOpenParam.picHeight;
- fbHeight = encOpenParam.picWidth;
- }
- fbWidth = VPU_ALIGN16(fbWidth);
- fbHeight = VPU_ALIGN32(fbHeight);
- mapType = mapType;
- }
- fbStride = CalcStride(fbWidth, fbHeight, (FrameBufferFormat)encOpenParam.outputFormat, encOpenParam.cbcrInterleave, mapType, FALSE);
- fbSize = VPU_GetFrameBufSize(ctx->handle, encOpenParam.coreIdx, fbStride, fbHeight, mapType, (FrameBufferFormat)encOpenParam.outputFormat, encOpenParam.cbcrInterleave, pDramConfig);
- if (FALSE == AllocFBMemory(encOpenParam.coreIdx, ctx->pFbReconMem, ctx->pFbRecon, fbSize, ctx->fbCount.reconFbNum, ENC_FBC, ctx->handle->instIndex)) {
- VLOG(ERR, "failed to allocate recon buffers\n");
- return FALSE;
- }
- fbAllocInfo.stride = fbStride;
- fbAllocInfo.height = fbHeight;
- fbAllocInfo.type = FB_TYPE_CODEC;
- fbAllocInfo.num = ctx->fbCount.reconFbNum;
- ctx->reconFbAllocInfo = fbAllocInfo;
- return TRUE;
- }
- static BOOL PrepareYuvFeeder(ComponentImpl* com, BOOL* done)
- {
- CNMComponentParamRet ret;
- YuvFeederContext* ctx = (YuvFeederContext*)com->context;
- EncOpenParam* encOpenParam = &ctx->encOpenParam;
- BOOL success;
- Uint32 i;
- YuvFeeder yuvFeeder = NULL;
- YuvInfo yuvFeederInfo;
- *done = FALSE;
- // wait signal GET_PARAM_ENC_FRAME_BUF_NUM
- ret = ComponentGetParameter(com, com->sinkPort.connectedComponent, GET_PARAM_ENC_FRAME_BUF_NUM, &ctx->fbCount);
- if (ComponentParamReturnTest(ret, &success) == FALSE) {
- return success;
- }
- ret = ComponentGetParameter(com, com->sinkPort.connectedComponent, GET_PARAM_ENC_HANDLE, &ctx->handle);
- if (ComponentParamReturnTest(ret, &success) == FALSE) {
- return success;
- }
- if (FALSE == AllocateFrameBuffer(com)) {
- VLOG(ERR, "AllocateFramBuffer() error\n");
- return FALSE;
- }
- osal_memset(&yuvFeederInfo, 0x00, sizeof(YuvInfo));
- yuvFeederInfo.cbcrInterleave = encOpenParam->cbcrInterleave;
- yuvFeederInfo.nv21 = encOpenParam->nv21;
- yuvFeederInfo.packedFormat = encOpenParam->packedFormat;
- yuvFeederInfo.srcFormat = encOpenParam->srcFormat;
- yuvFeederInfo.srcPlanar = TRUE;
- yuvFeederInfo.srcStride = ctx->srcFbAllocInfo.stride;
- yuvFeederInfo.srcHeight = VPU_CEIL(encOpenParam->picHeight, 8);
- yuvFeeder = YuvFeeder_Create(ctx->yuvMode, ctx->inputPath, yuvFeederInfo);
- if (yuvFeeder == NULL) {
- VLOG(ERR, "YuvFeeder_Create Error\n");
- return FALSE;
- }
- ((AbstractYuvFeeder*)yuvFeeder)->impl->handle = ctx->handle;
- ctx->yuvFeeder = yuvFeeder;
- // Fill data into the input queue of the sink port.
- // The empty input queue of the sink port occurs a hangup problem in this example.
- while (Queue_Dequeue(com->sinkPort.inputQ) != NULL);
- for (i = 0; i < com->sinkPort.inputQ->size; i++) {
- PortContainerYuv defaultData;
- osal_memset(&defaultData, 0x00, sizeof(PortContainerYuv));
- defaultData.srcFbIndex = -1;
- if (i<ctx->fbCount.srcFbNum) {
- defaultData.srcFbIndex = i;
- Queue_Enqueue(com->sinkPort.inputQ, (void*)&defaultData);
- }
- }
- if (PRODUCT_ID_NOT_W_SERIES(ctx->productID)) {
- VPU_EncGiveCommand(ctx->handle, GET_TILEDMAP_CONFIG, &(ctx->mapConfig));
- }
- ctx->fbAllocated = TRUE;
- *done = TRUE;
- return TRUE;
- }
- static BOOL ExecuteYuvFeeder(ComponentImpl* com, PortContainer* in, PortContainer* out)
- {
- YuvFeederContext* ctx = (YuvFeederContext*)com->context;
- EncOpenParam* encOpenParam = &ctx->encOpenParam;
- int ret = 0;
- PortContainerYuv* sinkData = (PortContainerYuv*)out;
- void* extraFeedingInfo = NULL;
- #ifdef USE_FEEDING_METHOD_BUFFER
- extern void yuvBufferFeeder_SetData(YuvFeederImpl* impl, Uint8* address, Uint32 size);
- PortContainerExternal *input = NULL;
- input = (PortContainerExternal *)ComponentPortPeekData(&com->srcPort);
- if (input == NULL) {
- return TRUE;
- }
- AbstractYuvFeeder* absFeeder = (AbstractYuvFeeder*)ctx->yuvFeeder;
- yuvBufferFeeder_SetData(absFeeder->impl, (Uint8 *)input->pBuffer, input->nFilledLen);
- #endif
- out->reuse = FALSE;
- if (ctx->state == YUV_FEEDER_STATE_WAIT) {
- CNMComponentParamRet ParamRet;
- BOOL success, done = FALSE;
- out->reuse = TRUE;
- ParamRet = ComponentGetParameter(com, com->sinkPort.connectedComponent, GET_PARAM_ENC_FRAME_BUF_REGISTERED, &done);
- if (ComponentParamReturnTest(ParamRet, &success) == FALSE) {
- return success;
- }
- if (done == FALSE) return TRUE;
- ctx->state = YUV_FEEDER_STATE_FEEDING;
- out->reuse = FALSE;
- }
- if ( ctx->last ) {
- sinkData->last = TRUE;
- return TRUE;
- }
- sinkData->fb = ctx->pFbSrc[sinkData->srcFbIndex];
- if (PRODUCT_ID_NOT_W_SERIES(ctx->productID)) {
- extraFeedingInfo = &(ctx->mapConfig);
- }
- #ifdef USE_FEEDING_METHOD_BUFFER
- if ((input->nFlags & 0x1) == 0x1)
- {
- ctx->last = sinkData->last = TRUE;
- // return TRUE;
- }
- #else
- ctx->feedingNum++;
- if (ctx->feedingNum > ctx->frameOutNum && ctx->frameOutNum != -1) {
- ctx->last = sinkData->last = TRUE;
- return TRUE;
- }
- #endif
- if (ctx->MemoryOptimization)
- {
- Uint32 nBufferIndex = input->nBufferIndex;
- Uint32 totalCount = Queue_Get_Cnt(com->sinkPort.inputQ);
- Uint32 i = 0;
- ret = TRUE;
- for(i = 0; i < totalCount; i ++) {
- VLOG(INFO, "Input index = %d, Output index = %d\n", nBufferIndex, sinkData->srcFbIndex);
- if (nBufferIndex == sinkData->srcFbIndex) {
- break;
- }
- void *tmp = ComponentPortGetData(&com->sinkPort);
- Queue_Enqueue(com->sinkPort.inputQ, (void *)tmp);
- sinkData = (PortContainerYuv*)ComponentPortPeekData(&com->sinkPort);
- }
- if (i == totalCount)
- {
- VLOG(ERR, "Could not find match index!\n");
- ret = FALSE;
- }
- } else {
- VLOG(INFO, "Normal Feed\r\n");
- ret = YuvFeeder_Feed(ctx->yuvFeeder, encOpenParam->coreIdx, &sinkData->fb, encOpenParam->picWidth, encOpenParam->picHeight, sinkData->srcFbIndex, extraFeedingInfo);
- }
- if (ret == FALSE) {
- ctx->last = sinkData->last = TRUE;
- }
- #ifdef USE_FEEDING_METHOD_BUFFER
- if (input != NULL) {
- ComponentPortGetData(&com->srcPort);
- ComponentNotifyListeners(com, COMPONENT_EVENT_ENC_EMPTY_BUFFER_DONE, (void *)input);
- }
- if ((input->nFlags & 0x1) == 0x1)
- {
- while ((input = (PortContainerExternal*)ComponentPortGetData(&com->srcPort)) != NULL)
- {
- input->nFlags = 0x1;
- input->nFilledLen = 0;
- ComponentNotifyListeners(com, COMPONENT_EVENT_ENC_EMPTY_BUFFER_DONE, (void *)input);
- }
- }
- #endif
- return TRUE;
- }
- static void ReleaseYuvFeeder(ComponentImpl* com)
- {
- YuvFeederContext* ctx = (YuvFeederContext*)com->context;
- Uint32 i = 0;
- for (i = 0; i < ctx->fbCount.reconFbNum*2; i++) {
- if (ctx->pFbReconMem[i].size)
- vdi_free_dma_memory(ctx->encOpenParam.coreIdx, &ctx->pFbReconMem[i], ENC_FBC, ctx->handle->instIndex);
- }
- for (i = 0; i < ctx->fbCount.srcFbNum; i++) {
- if (ctx->pFbSrcMem[i].size)
- vdi_free_dma_memory(ctx->encOpenParam.coreIdx, &ctx->pFbSrcMem[i], ENC_SRC, ctx->handle->instIndex);
- if (ctx->pFbOffsetTblMem[i].size)
- vdi_free_dma_memory(ctx->encOpenParam.coreIdx, &ctx->pFbOffsetTblMem[i], ENC_FBCY_TBL, ctx->handle->instIndex);
- }
- }
- static BOOL DestroyYuvFeeder(ComponentImpl* com)
- {
- YuvFeederContext* ctx = (YuvFeederContext*)com->context;
- if (ctx->yuvFeeder) YuvFeeder_Destroy(ctx->yuvFeeder);
- osal_free(ctx);
- return TRUE;
- }
- static Component CreateYuvFeeder(ComponentImpl* com, CNMComponentConfig* componentParam)
- {
- YuvFeederContext* ctx;
- com->context = osal_malloc(sizeof(YuvFeederContext));
- ctx = (YuvFeederContext*)com->context;
- InitYuvFeederContext(ctx, componentParam);
- if ( ctx->encOpenParam.sourceBufCount > com->numSinkPortQueue )
- com->numSinkPortQueue = ctx->encOpenParam.sourceBufCount;//set requested sourceBufCount
- ctx->productID = componentParam->testEncConfig.productId;
- ctx->MemoryOptimization = TRUE;
- ctx->totalBufferNumber = 5;
- ctx->currentBufferNumber = 0;
- return (Component)com;
- }
- ComponentImpl yuvFeederComponentImpl = {
- "yuvfeeder",
- NULL,
- {0,},
- {0,},
- sizeof(PortContainerYuv),
- ENC_SRC_BUF_NUM, /* minimum feeder's numSinkPortQueue(relates to source buffer count)*/
- CreateYuvFeeder,
- GetParameterYuvFeeder,
- SetParameterYuvFeeder,
- PrepareYuvFeeder,
- ExecuteYuvFeeder,
- ReleaseYuvFeeder,
- DestroyYuvFeeder
- };
|