1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266 |
- // SPDX-License-Identifier: GPL-2.0
- /*
- * Copyright (C) 2021 StarFive Technology Co., Ltd.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include "SF_OMX_video_common.h"
- #include "SF_OMX_Core.h"
- #define DEC_StopThread OMX_CommandMax
- typedef struct DEC_CMD
- {
- OMX_COMMANDTYPE Cmd;
- OMX_U32 nParam;
- OMX_PTR pCmdData;
- }DEC_CMD;
- static char* Event2Str(unsigned long event)
- {
- char *event_str = NULL;
- switch (event)
- {
- case COMPONENT_EVENT_DEC_OPEN:
- event_str = "COMPONENT_EVENT_DEC_OPEN";
- break;
- case COMPONENT_EVENT_DEC_ISSUE_SEQ:
- event_str = "COMPONENT_EVENT_DEC_ISSUE_SEQ";
- break;
- case COMPONENT_EVENT_DEC_COMPLETE_SEQ:
- event_str = "COMPONENT_EVENT_DEC_COMPLETE_SEQ";
- break;
- case COMPONENT_EVENT_DEC_REGISTER_FB:
- event_str = "COMPONENT_EVENT_DEC_REGISTER_FB";
- break;
- case COMPONENT_EVENT_DEC_READY_ONE_FRAME:
- event_str = "COMPONENT_EVENT_DEC_READY_ONE_FRAME";
- break;
- case COMPONENT_EVENT_DEC_START_ONE_FRAME:
- event_str = "COMPONENT_EVENT_DEC_START_ONE_FRAME";
- break;
- case COMPONENT_EVENT_DEC_INTERRUPT:
- event_str = "COMPONENT_EVENT_DEC_INTERRUPT";
- break;
- case COMPONENT_EVENT_DEC_GET_OUTPUT_INFO:
- event_str = "COMPONENT_EVENT_DEC_GET_OUTPUT_INFO";
- break;
- case COMPONENT_EVENT_DEC_DECODED_ALL:
- event_str = "COMPONENT_EVENT_DEC_DECODED_ALL";
- break;
- case COMPONENT_EVENT_DEC_CLOSE:
- event_str = "COMPONENT_EVENT_DEC_CLOSE";
- break;
- case COMPONENT_EVENT_DEC_RESET_DONE:
- event_str = "COMPONENT_EVENT_DEC_RESET_DONE";
- break;
- case COMPONENT_EVENT_DEC_EMPTY_BUFFER_DONE:
- event_str = "COMPONENT_EVENT_DEC_EMPTY_BUFFER_DONE";
- break;
- case COMPONENT_EVENT_DEC_FILL_BUFFER_DONE:
- event_str = "COMPONENT_EVENT_DEC_FILL_BUFFER_DONE";
- break;
- case COMPONENT_EVENT_DEC_ALL:
- event_str = "COMPONENT_EVENT_DEC_ALL";
- break;
- }
- return event_str;
- }
- static void OnEventArrived(Component com, unsigned long event, void *data, void *context)
- {
- PortContainerExternal *pPortContainerExternal = (PortContainerExternal *)data;
- OMX_BUFFERHEADERTYPE *pOMXBuffer;
- OMX_BUFFERHEADERTYPE **ppBuffer;
- OMX_BUFFERHEADERTYPE *pBuffer;
- SF_OMX_BUF_INFO *pBufInfo;
- OMX_U32 fps = 0;
- OMX_U64 diff_time = 0; // ms
- FunctionIn();
- SF_OMX_COMPONENT *pSfOMXComponent = (SF_OMX_COMPONENT*)context;
- SF_WAVE5_IMPLEMEMT *pSfVideoImplement = (SF_WAVE5_IMPLEMEMT *)pSfOMXComponent->componentImpl;
- char *event_str = Event2Str(event);
- LOG(SF_LOG_INFO, "event=%lX %s\r\n", event, event_str);
- switch (event)
- {
- case COMPONENT_EVENT_DEC_EMPTY_BUFFER_DONE:
- if (pSfOMXComponent->bPortFlushing[0])
- {
- LOG(SF_LOG_INFO, "flushing,break\r\n");
- break;
- }
- pOMXBuffer = (OMX_BUFFERHEADERTYPE *)pPortContainerExternal->pAppPrivate;
- if (pOMXBuffer == NULL)
- {
- LOG(SF_LOG_WARN, "Could not find omx buffer by address\r\n");
- return;
- }
- ppBuffer = SF_Queue_Peek(pSfVideoImplement->inPortQ);
- if (ppBuffer)
- pBuffer = *ppBuffer;
- if (pBuffer == pOMXBuffer)
- {
- LOG(SF_LOG_INFO, "get buffer %p\r\n", pOMXBuffer);
- SF_Queue_Dequeue(pSfVideoImplement->inPortQ);
- }
- else
- {
- LOG(SF_LOG_INFO, "buffer %p gone, break.\r\n", pOMXBuffer);
- break;
- }
- LOG(SF_LOG_INFO, "Empty done h %p b %p\r\n", pOMXBuffer, pOMXBuffer->pBuffer);
- if (pSfOMXComponent->markType[0].hMarkTargetComponent != NULL)
- {
- LOG(SF_LOG_INFO, "set Component mark %p\r\n", pSfOMXComponent->markType[0].hMarkTargetComponent);
- pOMXBuffer->hMarkTargetComponent = pSfOMXComponent->markType[0].hMarkTargetComponent;
- pOMXBuffer->pMarkData = pSfOMXComponent->markType[0].pMarkData;
- pSfOMXComponent->markType[0].hMarkTargetComponent = NULL;
- pSfOMXComponent->markType[0].pMarkData = NULL;
- }
- if (pOMXBuffer->hMarkTargetComponent != NULL)
- {
- if (pOMXBuffer->hMarkTargetComponent == pSfOMXComponent->pOMXComponent)
- {
- LOG(SF_LOG_INFO, "Component mark hit\r\n");
- pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent,
- pSfOMXComponent->pAppData,
- OMX_EventMark,
- 0, 0, pOMXBuffer->pMarkData);
- } else {
- LOG(SF_LOG_INFO, "Component propagate mark from input port\r\n");
- pSfOMXComponent->propagateMarkType.hMarkTargetComponent = pOMXBuffer->hMarkTargetComponent;
- pSfOMXComponent->propagateMarkType.pMarkData = pOMXBuffer->pMarkData;
- }
- }
- if (pSfOMXComponent->state == OMX_StatePause)
- {
- LOG(SF_LOG_INFO, "tmp store buf when pause\r\n");
- SF_Queue_Enqueue(pSfVideoImplement->inPauseQ, &pOMXBuffer);
- }
- else{
- pSfOMXComponent->callbacks->EmptyBufferDone(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData, pOMXBuffer);
- }
- break;
- case COMPONENT_EVENT_DEC_FILL_BUFFER_DONE:
- {
- struct timeval tv;
- if (pSfOMXComponent->bPortFlushing[1] && !pSfOMXComponent->memory_optimization)
- {
- LOG(SF_LOG_INFO, "flushing,break\r\n");
- break;
- }
- pOMXBuffer = (OMX_BUFFERHEADERTYPE *)pPortContainerExternal->pAppPrivate;
- if (pOMXBuffer == NULL)
- {
- LOG(SF_LOG_WARN, "Could not find omx buffer by address\r\n");
- return;
- }
- if (!pSfOMXComponent->memory_optimization){
- ppBuffer = SF_Queue_Peek(pSfVideoImplement->outPortQ);
- if (ppBuffer)
- pBuffer = *ppBuffer;
- if (pBuffer == pOMXBuffer)
- {
- LOG(SF_LOG_INFO, "get buffer %p\r\n", pOMXBuffer);
- SF_Queue_Dequeue(pSfVideoImplement->outPortQ);
- }
- else
- {
- LOG(SF_LOG_INFO, "buffer %p gone, break.\r\n", pOMXBuffer);
- break;
- }
- }
- gettimeofday(&tv, NULL);
- if (pSfVideoImplement->initTimeStamp == 0)
- {
- pSfVideoImplement->initTimeStamp = tv.tv_sec * 1000000 + tv.tv_usec;
- }
- pOMXBuffer->nFilledLen = pPortContainerExternal->nFilledLen;
- pOMXBuffer->nTimeStamp = tv.tv_sec * 1000000 + tv.tv_usec - pSfVideoImplement->initTimeStamp;
- pBufInfo = pOMXBuffer->pOutputPortPrivate;
- // Following is to print the decoding fps
- if (pSfVideoImplement->fpsCnt == 0) {
- pSfVideoImplement->fpsStarTime = tv;
- }
- if (pSfVideoImplement->fpsCnt++ >= 50) {
- diff_time = (tv.tv_sec - pSfVideoImplement->fpsStarTime.tv_sec) * 1000 + (tv.tv_usec - pSfVideoImplement->fpsStarTime.tv_usec) / 1000;
- fps = 1000 * (pSfVideoImplement->fpsCnt - 1) / diff_time;
- pSfVideoImplement->fpsCnt = 0;
- LOG(SF_LOG_WARN, "Decoding fps: %d \r\n", fps);
- }
- if (pPortContainerExternal->nFlags & 0x1)
- pOMXBuffer->nFlags |= OMX_BUFFERFLAG_EOS;
- LOG(SF_LOG_PERF, "OMX finish one buffer, address = %p, size = %d, nTimeStamp = %d, nFlags = %X\r\n",
- pOMXBuffer->pBuffer, pOMXBuffer->nFilledLen, pOMXBuffer->nTimeStamp, pOMXBuffer->nFlags);
- LOG(SF_LOG_INFO, "indexFrameDisplay = %d, OMXBuferFlag = %d, OMXBufferAddr = %p\r\n",
- pPortContainerExternal->index, pBufInfo->index, pOMXBuffer->pBuffer);
- ComponentImpl *pRendererComponent = (ComponentImpl *)pSfVideoImplement->hSFComponentRender;
- LOG(SF_LOG_PERF, "output queue count=%d/%d\r\n", pSfVideoImplement->functions->Queue_Get_Cnt(pRendererComponent->sinkPort.inputQ),
- pSfOMXComponent->portDefinition[1].nBufferCountActual);
- if (pSfOMXComponent->propagateMarkType.hMarkTargetComponent != NULL) {
- LOG(SF_LOG_INFO, "Component propagate mark to output port\r\n");
- pOMXBuffer->hMarkTargetComponent = pSfOMXComponent->propagateMarkType.hMarkTargetComponent;
- pOMXBuffer->pMarkData = pSfOMXComponent->propagateMarkType.pMarkData;
- pSfOMXComponent->propagateMarkType.hMarkTargetComponent = NULL;
- pSfOMXComponent->propagateMarkType.pMarkData = NULL;
- }
- if (pSfOMXComponent->state == OMX_StatePause)
- {
- LOG(SF_LOG_INFO, "tmp store buf when pause\r\n");
- SF_Queue_Enqueue(pSfVideoImplement->outPauseQ, &pOMXBuffer);
- }
- else{
- #if 0
- SF_OMX_BUF_INFO *pBufInfo = pOMXBuffer->pOutputPortPrivate;
- FILE *fb = fopen("./out.yuv", "ab+");
- LOG(SF_LOG_INFO, "%p %d %p\r\n", pOMXBuffer->pBuffer, pOMXBuffer->nFilledLen, pBufInfo->remap_vaddr);
- fwrite(pOMXBuffer->pBuffer, 1, pOMXBuffer->nFilledLen, fb);
- fclose(fb);
- }
- #endif
- if (pOMXBuffer->nFlags & OMX_BUFFERFLAG_EOS)
- {
- pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData, OMX_EventBufferFlag,
- 1, pOMXBuffer->nFlags, NULL);
- }
- pSfOMXComponent->callbacks->FillBufferDone(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData, pOMXBuffer);
- }
- }
- break;
- case COMPONENT_EVENT_DEC_REGISTER_FB:
- {
- /*The width and height vpu return will align to 16, eg: 1080 will be 1088. so check scale value at first.*/
- TestDecConfig *testConfig = (TestDecConfig *)pSfVideoImplement->testConfig;
- DecHandle decHandle = NULL;
- DecInitialInfo* pInfo;
- pSfVideoImplement->functions->ComponentGetParameter(NULL, com, GET_PARAM_DEC_HANDLE, &decHandle);
- pInfo = &decHandle->CodecInfo->decInfo.initialInfo;
- if(testConfig->scaleDownWidth > 0 || testConfig->scaleDownHeight > 0)
- {
- pSfOMXComponent->portDefinition[1].format.video.nFrameWidth = testConfig->scaleDownWidth;
- pSfOMXComponent->portDefinition[1].format.video.nFrameHeight = testConfig->scaleDownHeight;
- pSfOMXComponent->portDefinition[1].format.video.nStride = OMX_ALIGN32(testConfig->scaleDownWidth);
- pSfOMXComponent->portDefinition[1].format.video.nSliceHeight = testConfig->scaleDownHeight;
- }
- else
- {
- pSfOMXComponent->portDefinition[1].format.video.nFrameWidth = pInfo->picCropRect.right;
- pSfOMXComponent->portDefinition[1].format.video.nFrameHeight = pInfo->picCropRect.bottom;
- pSfOMXComponent->portDefinition[1].format.video.nStride = OMX_ALIGN32(pInfo->picWidth);
- pSfOMXComponent->portDefinition[1].format.video.nSliceHeight = pInfo->picHeight;
- }
- LOG(SF_LOG_INFO, "Get Output width = %d, height = %d\r\n", pSfOMXComponent->portDefinition[1].format.video.nFrameWidth,
- pSfOMXComponent->portDefinition[1].format.video.nFrameHeight);
- ComponentImpl *pRendererComponent = (ComponentImpl *)pSfVideoImplement->hSFComponentRender;
- pSfOMXComponent->portDefinition[1].nBufferCountActual = pSfVideoImplement->functions->GetRenderTotalBufferNumber(pRendererComponent);
- pSfOMXComponent->portDefinition[1].nBufferCountMin = pSfOMXComponent->portDefinition[1].nBufferCountActual;
- /*Caculate buffer size by eColorFormat*/
- switch (pSfOMXComponent->portDefinition[1].format.video.eColorFormat)
- {
- case OMX_COLOR_FormatYUV420Planar:
- case OMX_COLOR_FormatYUV420SemiPlanar:
- case OMX_COLOR_FormatYVU420SemiPlanar:
- pSfOMXComponent->portDefinition[1].nBufferSize = (pSfOMXComponent->portDefinition[1].format.video.nStride
- * pSfOMXComponent->portDefinition[1].format.video.nSliceHeight * 3) / 2;
- break;
- default:
- pSfOMXComponent->portDefinition[1].nBufferSize = pSfOMXComponent->portDefinition[1].format.video.nStride
- * pSfOMXComponent->portDefinition[1].format.video.nSliceHeight * 2;
- break;
- }
- pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData, OMX_EventPortSettingsChanged,
- 1, OMX_IndexParamPortDefinition, NULL);
- }
- break;
- case COMPONENT_EVENT_DEC_INSUFFIC_RESOURCE:
- {
- LOG(SF_LOG_ERR, "Lack of memory for decoder buffer, process stop!\r\n");
- pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData, OMX_EventError,
- OMX_ErrorInsufficientResources, 0, NULL);
- ComponentImpl *pSFComponentDecoder = (ComponentImpl *)pSfVideoImplement->hSFComponentExecoder;
- ComponentImpl *pSFComponentFeeder = (ComponentImpl *)pSfVideoImplement->hSFComponentFeeder;
- ComponentImpl *pSFComponentRender = (ComponentImpl *)pSfVideoImplement->hSFComponentRender;
- void *ThreadRet = NULL;
- DEC_CMD cmd;
- cmd.Cmd = DEC_StopThread;
- SF_Queue_Enqueue(pSfVideoImplement->CmdQueue, &cmd);
- pthread_cancel(pSfVideoImplement->pCmdThread->pthread);
- pthread_join(pSfVideoImplement->pCmdThread->pthread, &ThreadRet);
- LOG(SF_LOG_INFO, "Cmd thread end %ld\r\n", (Uint64)ThreadRet);
- if (!pSfOMXComponent->memory_optimization)
- {
- LOG(SF_LOG_INFO,"feeder src q cnt %d\r\n",
- pSfVideoImplement->functions->Queue_Get_Cnt(((ComponentImpl *)(pSfVideoImplement->hSFComponentFeeder))->srcPort.inputQ));
- pSfVideoImplement->functions->ComponentStop(pSFComponentRender);
- pSfVideoImplement->functions->ComponentStop(pSFComponentDecoder);
- pSfVideoImplement->functions->ComponentStop(pSFComponentFeeder);
- FlushBuffer(pSfOMXComponent, 0);
- FlushBuffer(pSfOMXComponent, 1);
- pSfVideoImplement->functions->ComponentWait(pSFComponentRender);
- pSfVideoImplement->functions->ComponentWait(pSFComponentDecoder);
- pSfVideoImplement->functions->ComponentWait(pSFComponentFeeder);
- pSFComponentRender->terminate = OMX_TRUE;
- pSFComponentDecoder->terminate = OMX_TRUE;
- pSFComponentFeeder->terminate = OMX_TRUE;
- }
- else
- {
- pSFComponentDecoder->pause = OMX_TRUE;
- pSFComponentFeeder->pause = OMX_TRUE;
- pSFComponentRender->pause = OMX_TRUE;
- FlushBuffer(pSfOMXComponent, 0);
- FlushBuffer(pSfOMXComponent, 1);
- }
- pSfOMXComponent->state = OMX_StateInvalid;
- LOG(SF_LOG_ERR, "Component into invalid state!\r\n");
- pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData, OMX_EventError,
- OMX_ErrorInvalidState, 0, NULL);
- }
- break;
- case COMPONENT_EVENT_TERMINATED:
- break;
- case COMPONENT_EVENT_DEC_DECODED_ALL:
- LOG(SF_LOG_DEBUG,"renderer meet end\r\n");
- default:
- break;
- }
- FunctionOut();
- }
- static OMX_ERRORTYPE SF_OMX_EmptyThisBuffer(
- OMX_IN OMX_HANDLETYPE hComponent,
- OMX_IN OMX_BUFFERHEADERTYPE *pBuffer)
- {
- OMX_ERRORTYPE ret = OMX_ErrorNone;
- FunctionIn();
- if (hComponent == NULL || pBuffer == NULL)
- {
- ret = OMX_ErrorBadParameter;
- goto EXIT;
- }
- OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
- SF_OMX_COMPONENT *pSfOMXComponent = pOMXComponent->pComponentPrivate;
- SF_WAVE5_IMPLEMEMT *pSfVideoImplement = (SF_WAVE5_IMPLEMEMT *)pSfOMXComponent->componentImpl;
- ComponentImpl *pFeederComponent = (ComponentImpl *)pSfVideoImplement->hSFComponentFeeder;
- LOG(SF_LOG_DEBUG, "bufheader %p nFilledLen = %d, nFlags = %d, pBuffer = %p\r\n", pBuffer, pBuffer->nFilledLen, pBuffer->nFlags, pBuffer->pBuffer);
- if (!pSfOMXComponent->portDefinition[0].bEnabled)
- {
- LOG(SF_LOG_INFO, "feed buffer when input port stop\r\n");
- return OMX_ErrorIncorrectStateOperation;
- }
- if (pBuffer->nInputPortIndex != 0)
- {
- LOG(SF_LOG_INFO, "Incorrect nInputPortIndex %d\r\n", pBuffer->nInputPortIndex);
- return OMX_ErrorBadPortIndex;
- }
- PortContainerExternal *pPortContainerExternal = malloc(sizeof(PortContainerExternal));
- if (pPortContainerExternal == NULL)
- {
- LOG(SF_LOG_ERR, "malloc fail\r\n");
- return OMX_ErrorInsufficientResources;
- }
- memset(pPortContainerExternal, 0, sizeof(PortContainerExternal));
- pPortContainerExternal->pBuffer = pBuffer->pBuffer;
- pPortContainerExternal->nFilledLen = pBuffer->nFilledLen;
- pPortContainerExternal->nFlags = pBuffer->nFlags;
- pPortContainerExternal->pAppPrivate = (void*)pBuffer;
- SF_Queue_Enqueue(pSfVideoImplement->inPortQ, &pBuffer);
- if (pSfVideoImplement->functions->Queue_Enqueue(pFeederComponent->srcPort.inputQ, (void *)pPortContainerExternal) != OMX_TRUE)
- {
- LOG(SF_LOG_ERR, "%p:%p FAIL\r\n", pFeederComponent->srcPort.inputQ, pPortContainerExternal);
- free(pPortContainerExternal);
- return OMX_ErrorInsufficientResources;
- }
- LOG(SF_LOG_PERF, "input queue count=%d/%d\r\n", pSfVideoImplement->functions->Queue_Get_Cnt(pFeederComponent->srcPort.inputQ),
- pSfOMXComponent->portDefinition[0].nBufferCountActual);
- //LOG(SF_LOG_INFO, "input buffer address = %p, size = %d, flag = %x\r\n", pBuffer->pBuffer, pBuffer->nFilledLen, pBuffer->nFlags);
- if (pBuffer->nFlags & OMX_BUFFERFLAG_EOS)
- {
- pSfVideoImplement->rev_eos = OMX_TRUE;
- }
- free(pPortContainerExternal);
- pFeederComponent->pause = OMX_FALSE;
- EXIT:
- FunctionOut();
- return ret;
- }
- static OMX_ERRORTYPE SF_OMX_FillThisBuffer(
- OMX_IN OMX_HANDLETYPE hComponent,
- OMX_IN OMX_BUFFERHEADERTYPE *pBuffer)
- {
- OMX_ERRORTYPE ret = OMX_ErrorNone;
- FunctionIn();
- if (hComponent == NULL || pBuffer == NULL)
- {
- ret = OMX_ErrorBadParameter;
- goto EXIT;
- }
- OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
- SF_OMX_COMPONENT *pSfOMXComponent = (SF_OMX_COMPONENT *)pOMXComponent->pComponentPrivate;
- SF_WAVE5_IMPLEMEMT *pSfVideoImplement = (SF_WAVE5_IMPLEMEMT *)pSfOMXComponent->componentImpl;
- SF_OMX_BUF_INFO *pBufInfo = (SF_OMX_BUF_INFO *)pBuffer->pOutputPortPrivate;
- ComponentImpl *pRendererComponent = (ComponentImpl *)pSfVideoImplement->hSFComponentRender;
- LOG(SF_LOG_DEBUG, "bufheader %p nFilledLen = %d, nFlags = %d, pBuffer = %p\r\n", pBuffer, pBuffer->nFilledLen, pBuffer->nFlags, pBuffer->pBuffer);
- if (!pSfOMXComponent->portDefinition[1].bEnabled)
- {
- LOG(SF_LOG_INFO, "feed buffer when output port stop\r\n");
- return OMX_ErrorIncorrectStateOperation;
- }
- if (pBuffer->nOutputPortIndex != 1)
- {
- LOG(SF_LOG_INFO, "Incorrect nOutputPortIndex %d\r\n", pBuffer->nOutputPortIndex);
- return OMX_ErrorBadPortIndex;
- }
- PortContainerExternal *pPortContainerExternal = malloc(sizeof(PortContainerExternal));
- if (pPortContainerExternal == NULL)
- {
- LOG(SF_LOG_ERR, "malloc fail\r\n");
- return OMX_ErrorInsufficientResources;
- }
- memset(pPortContainerExternal, 0, sizeof(PortContainerExternal));
- pPortContainerExternal->pBuffer = pBuffer->pBuffer;
- pPortContainerExternal->nFilledLen = pBuffer->nAllocLen;
- pPortContainerExternal->pAppPrivate = (void*)pBuffer;
- if (pSfVideoImplement->initTimeStamp != 0 && pSfOMXComponent->memory_optimization)
- {
- int clear = pSfVideoImplement->frame_array[pSfVideoImplement->frame_array_index];
- pSfVideoImplement->functions->Render_DecClrDispFlag(pRendererComponent->context, clear);
- pSfVideoImplement->frame_array[pSfVideoImplement->frame_array_index] = pBufInfo->index;
- LOG(SF_LOG_INFO, "store display flag: %d, clear display flag: %d\r\n",
- pSfVideoImplement->frame_array[pSfVideoImplement->frame_array_index], clear);
- pSfVideoImplement->frame_array_index ++;
- }
- if (pSfVideoImplement->frame_array_index == MAX_INDEX) pSfVideoImplement->frame_array_index = 0;
- if (!pSfOMXComponent->memory_optimization)
- SF_Queue_Enqueue(pSfVideoImplement->outPortQ, &pBuffer);
- if (pSfVideoImplement->functions->Queue_Enqueue(pRendererComponent->sinkPort.inputQ, (void *)pPortContainerExternal) == FALSE)
- {
- LOG(SF_LOG_ERR, "%p:%p FAIL\r\n", pRendererComponent->sinkPort.inputQ, pPortContainerExternal);
- free(pPortContainerExternal);
- return OMX_ErrorInsufficientResources;
- }
- LOG(SF_LOG_PERF, "output queue count=%d/%d\r\n", pSfVideoImplement->functions->Queue_Get_Cnt(pRendererComponent->sinkPort.inputQ),
- pSfOMXComponent->portDefinition[1].nBufferCountActual);
- free(pPortContainerExternal);
- pRendererComponent->pause = OMX_FALSE;
- EXIT:
- FunctionOut();
- return ret;
- }
- static OMX_ERRORTYPE SF_OMX_UseBuffer(
- OMX_IN OMX_HANDLETYPE hComponent,
- OMX_INOUT OMX_BUFFERHEADERTYPE **ppBufferHdr,
- OMX_IN OMX_U32 nPortIndex,
- OMX_IN OMX_PTR pAppPrivate,
- OMX_IN OMX_U32 nSizeBytes,
- OMX_IN OMX_U8 *pBuffer)
- {
- OMX_ERRORTYPE ret = OMX_ErrorNone;
- OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
- SF_OMX_COMPONENT *pSfOMXComponent = pOMXComponent->pComponentPrivate;
- SF_WAVE5_IMPLEMEMT *pSfVideoImplement = (SF_WAVE5_IMPLEMEMT *)pSfOMXComponent->componentImpl;
- ComponentImpl *pComponentRender = (ComponentImpl *)pSfVideoImplement->hSFComponentRender;
- OMX_U32 i;
- FunctionIn();
- if (hComponent == NULL)
- {
- ret = OMX_ErrorBadParameter;
- goto EXIT;
- }
- OMX_BUFFERHEADERTYPE *temp_bufferHeader = (OMX_BUFFERHEADERTYPE *)malloc(sizeof(OMX_BUFFERHEADERTYPE));
- if (temp_bufferHeader == NULL)
- {
- LOG(SF_LOG_ERR, "malloc fail\r\n");
- return OMX_ErrorInsufficientResources;
- }
- memset(temp_bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE));
- SF_OMX_BUF_INFO *pBufInfo = (SF_OMX_BUF_INFO *)malloc(sizeof(SF_OMX_BUF_INFO));
- if (pBufInfo == NULL)
- {
- LOG(SF_LOG_ERR, "malloc fail\r\n");
- free(temp_bufferHeader);
- return OMX_ErrorInsufficientResources;
- }
- temp_bufferHeader->nAllocLen = nSizeBytes;
- temp_bufferHeader->pAppPrivate = pAppPrivate;
- temp_bufferHeader->pBuffer = pBuffer;
- temp_bufferHeader->nSize = sizeof(OMX_BUFFERHEADERTYPE);
- memcpy(&(temp_bufferHeader->nVersion), &(pSfOMXComponent->componentVersion), sizeof(OMX_VERSIONTYPE));
- *ppBufferHdr = temp_bufferHeader;
- if (nPortIndex == 1)
- {
- for (i = 0; i < MAX_BUFF_NUM; i++)
- {
- if (!pSfOMXComponent->pBufferArray[1][i])
- {
- if ((!pComponentRender) || (!pSfOMXComponent->memory_optimization)
- || (pSfVideoImplement->functions->AttachDMABuffer(pComponentRender, (Uint64)pBuffer, nSizeBytes) == FALSE))
- {
- LOG(SF_LOG_INFO, "Failed to attach dma buffer, no memory optimization\r\n");
- pSfOMXComponent->memory_optimization = OMX_FALSE;
- }
- pBufInfo->type = SF_BUFFER_DMA_EXTERNAL;
- pBufInfo->index = i;
- temp_bufferHeader->pOutputPortPrivate = (OMX_PTR)pBufInfo;
- temp_bufferHeader->nOutputPortIndex = 1;
- pSfOMXComponent->pBufferArray[1][i] = temp_bufferHeader;
- pSfOMXComponent->assignedBufferNum[1] ++;
- if (pSfOMXComponent->assignedBufferNum[1] == pSfOMXComponent->portDefinition[1].nBufferCountActual)
- {
- pSfOMXComponent->portDefinition[1].bPopulated = OMX_TRUE;
- SF_SemaphorePost(pSfOMXComponent->portSemaphore[1]);
- }
- break;
- }
- }
- if (i == MAX_BUFF_NUM){
- LOG(SF_LOG_ERR, "buffer array full\r\n");
- free(temp_bufferHeader);
- free(pBufInfo);
- ret = OMX_ErrorInsufficientResources;
- }
- }
- else if (nPortIndex == 0)
- {
- for (i = 0; i < MAX_BUFF_NUM; i++)
- {
- if (!pSfOMXComponent->pBufferArray[0][i])
- {
- pBufInfo->type = SF_BUFFER_DMA_EXTERNAL;
- pBufInfo->index = i;
- temp_bufferHeader->pInputPortPrivate = (OMX_PTR)pBufInfo;
- temp_bufferHeader->nInputPortIndex = 0;
- pSfOMXComponent->pBufferArray[0][i] = temp_bufferHeader;
- pSfOMXComponent->assignedBufferNum[0] ++;
- if (pSfOMXComponent->assignedBufferNum[0] == pSfOMXComponent->portDefinition[0].nBufferCountActual)
- {
- pSfOMXComponent->portDefinition[0].bPopulated = OMX_TRUE;
- SF_SemaphorePost(pSfOMXComponent->portSemaphore[0]);
- }
- break;
- }
- }
- if (i == MAX_BUFF_NUM){
- LOG(SF_LOG_ERR, "buffer array full\r\n");
- free(temp_bufferHeader);
- free(pBufInfo);
- ret = OMX_ErrorInsufficientResources;
- }
- }
- LOG(SF_LOG_INFO, "header %p pBuffer address = %p on port %d\r\n", temp_bufferHeader, temp_bufferHeader->pBuffer, nPortIndex);
- EXIT:
- FunctionOut();
- return ret;
- }
- static OMX_ERRORTYPE SF_OMX_AllocateBuffer(
- OMX_IN OMX_HANDLETYPE hComponent,
- OMX_INOUT OMX_BUFFERHEADERTYPE **ppBuffer,
- OMX_IN OMX_U32 nPortIndex,
- OMX_IN OMX_PTR pAppPrivate,
- OMX_IN OMX_U32 nSizeBytes)
- {
- OMX_ERRORTYPE ret = OMX_ErrorNone;
- OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
- SF_OMX_COMPONENT *pSfOMXComponent = pOMXComponent->pComponentPrivate;
- SF_WAVE5_IMPLEMEMT *pSfVideoImplement = (SF_WAVE5_IMPLEMEMT *)pSfOMXComponent->componentImpl;
- ComponentImpl *pComponentRender = (ComponentImpl *)pSfVideoImplement->hSFComponentRender;
- OMX_U32 i;
- FunctionIn();
- if (nSizeBytes == 0)
- {
- LOG(SF_LOG_WARN, "nSizeBytes = %d, use default buffer size\r\n", nSizeBytes);
- nSizeBytes = DEFAULT_VIDEO_OUTPUT_BUFFER_SIZE;
- }
- OMX_BUFFERHEADERTYPE *temp_bufferHeader = (OMX_BUFFERHEADERTYPE *)malloc(sizeof(OMX_BUFFERHEADERTYPE));
- if (temp_bufferHeader == NULL)
- {
- LOG(SF_LOG_ERR, "malloc fail\r\n");
- return OMX_ErrorInsufficientResources;
- }
- memset(temp_bufferHeader, 0, sizeof(OMX_BUFFERHEADERTYPE));
- SF_OMX_BUF_INFO *pBufInfo = (SF_OMX_BUF_INFO *)malloc(sizeof(SF_OMX_BUF_INFO));
- if (pBufInfo == NULL)
- {
- LOG(SF_LOG_ERR, "malloc fail\r\n");
- free(temp_bufferHeader);
- return OMX_ErrorInsufficientResources;
- }
- temp_bufferHeader->nAllocLen = nSizeBytes;
- temp_bufferHeader->pAppPrivate = pAppPrivate;
- temp_bufferHeader->nSize = sizeof(OMX_BUFFERHEADERTYPE);
- memcpy(&(temp_bufferHeader->nVersion), &(pSfOMXComponent->componentVersion), sizeof(OMX_VERSIONTYPE));
- if (nPortIndex == 1)
- {
- for (i = 0; i < MAX_BUFF_NUM; i++)
- {
- if (!pSfOMXComponent->pBufferArray[1][i])
- {
- // Alloc DMA memory first
- if (pSfOMXComponent->memory_optimization)
- {
- OMX_U32 nLinearBufferSize, nFrameWidth, nFrameHeight;
- nFrameWidth = pSfOMXComponent->portDefinition[1].format.video.nStride;
- nFrameHeight = pSfOMXComponent->portDefinition[1].format.video.nSliceHeight;
- nLinearBufferSize = nFrameWidth * nFrameHeight * 3 / 2;
- nLinearBufferSize = (nLinearBufferSize > nSizeBytes)? nLinearBufferSize : nSizeBytes;
- temp_bufferHeader->pBuffer = pSfVideoImplement->functions->AllocateFrameBuffer2(pComponentRender, nLinearBufferSize);
- }
- // DMA Memory alloc fail, goto normal alloc
- if (temp_bufferHeader->pBuffer == NULL)
- {
- pSfOMXComponent->memory_optimization = OMX_FALSE;
- temp_bufferHeader->pBuffer = malloc(nSizeBytes);
- memset(temp_bufferHeader->pBuffer, 0, nSizeBytes);
- pBufInfo->type = SF_BUFFER_NOMAL;
- LOG(SF_LOG_PERF, "Use normal buffer\r\n");
- }
- else
- {
- pBufInfo->type = SF_BUFFER_DMA;
- LOG(SF_LOG_PERF, "Use DMA buffer\r\n");
- }
- pBufInfo->index = i;
- temp_bufferHeader->pOutputPortPrivate = (OMX_PTR)pBufInfo;
- temp_bufferHeader->nOutputPortIndex = 1;
- pSfOMXComponent->pBufferArray[1][i] = temp_bufferHeader;
- pSfOMXComponent->assignedBufferNum[1] ++;
- if (pSfOMXComponent->assignedBufferNum[1] == pSfOMXComponent->portDefinition[1].nBufferCountActual)
- {
- pSfOMXComponent->portDefinition[1].bPopulated = OMX_TRUE;
- SF_SemaphorePost(pSfOMXComponent->portSemaphore[1]);
- }
- break;
- }
- }
- if (i == MAX_BUFF_NUM){
- LOG(SF_LOG_ERR, "buffer array full\r\n");
- temp_bufferHeader->pBuffer = NULL;
- }
- }
- else if (nPortIndex == 0)
- {
- for (i = 0; i < MAX_BUFF_NUM; i++)
- {
- if (!pSfOMXComponent->pBufferArray[0][i])
- {
- temp_bufferHeader->pBuffer = malloc(nSizeBytes);
- memset(temp_bufferHeader->pBuffer, 0, nSizeBytes);
- pBufInfo->type = SF_BUFFER_NOMAL;
- pBufInfo->index = i;
- temp_bufferHeader->pInputPortPrivate = (OMX_PTR)pBufInfo;
- temp_bufferHeader->nInputPortIndex = 0;
- pSfOMXComponent->pBufferArray[0][i] = temp_bufferHeader;
- pSfOMXComponent->assignedBufferNum[0] ++;
- if (pSfOMXComponent->assignedBufferNum[0] == pSfOMXComponent->portDefinition[0].nBufferCountActual)
- {
- pSfOMXComponent->portDefinition[0].bPopulated = OMX_TRUE;
- SF_SemaphorePost(pSfOMXComponent->portSemaphore[0]);
- }
- break;
- }
- }
- if (i == MAX_BUFF_NUM){
- LOG(SF_LOG_ERR, "buffer array full\r\n");
- temp_bufferHeader->pBuffer = NULL;
- }
- }
- if (temp_bufferHeader->pBuffer == NULL)
- {
- free(temp_bufferHeader);
- free(pBufInfo);
- LOG(SF_LOG_ERR, "malloc fail\r\n");
- return OMX_ErrorInsufficientResources;
- }
- *ppBuffer = temp_bufferHeader;
- LOG(SF_LOG_INFO, "header %p pBuffer address = %p on port %d\r\n", temp_bufferHeader, temp_bufferHeader->pBuffer, nPortIndex);
- FunctionOut();
- return ret;
- }
- static OMX_ERRORTYPE SF_OMX_GetParameter(
- OMX_IN OMX_HANDLETYPE hComponent,
- OMX_IN OMX_INDEXTYPE nParamIndex,
- OMX_INOUT OMX_PTR ComponentParameterStructure)
- {
- OMX_ERRORTYPE ret = OMX_ErrorNone;
- OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
- SF_OMX_COMPONENT *pSfOMXComponent = pOMXComponent->pComponentPrivate;
- SF_WAVE5_IMPLEMEMT *pSfVideoImplement = (SF_WAVE5_IMPLEMEMT *)pSfOMXComponent->componentImpl;
- FunctionIn();
- LOG(SF_LOG_INFO, "Get parameter on index %X\r\n", nParamIndex);
- if (hComponent == NULL || ComponentParameterStructure == NULL)
- {
- ret = OMX_ErrorBadParameter;
- goto EXIT;
- }
- switch ((OMX_U32)nParamIndex)
- {
- case OMX_IndexParamVideoInit:
- {
- OMX_PORT_PARAM_TYPE *portParam = (OMX_PORT_PARAM_TYPE *)ComponentParameterStructure;
- portParam->nPorts = 2;
- portParam->nStartPortNumber = 0;
- }
- break;
- case OMX_IndexParamAudioInit:
- case OMX_IndexParamImageInit:
- case OMX_IndexParamOtherInit:
- {
- OMX_PORT_PARAM_TYPE *portParam = (OMX_PORT_PARAM_TYPE *)ComponentParameterStructure;
- portParam->nPorts = 0;
- portParam->nStartPortNumber = 0;
- }
- break;
- case OMX_IndexParamVideoPortFormat:
- {
- OMX_VIDEO_PARAM_PORTFORMATTYPE *portFormat = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)ComponentParameterStructure;
- OMX_U32 index = portFormat->nIndex;
- if (portFormat->nPortIndex == 0)
- {
- if (index > 0)
- {
- ret = OMX_ErrorNoMore;
- break;
- }
- portFormat->eCompressionFormat = pSfOMXComponent->portDefinition[0].format.video.eCompressionFormat;
- portFormat->eColorFormat = pSfOMXComponent->portDefinition[0].format.video.eColorFormat;
- portFormat->xFramerate = pSfOMXComponent->portDefinition[0].format.video.xFramerate;
- }
- else if (portFormat->nPortIndex == 1)
- {
- switch (index)
- {
- case 0:
- portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused;
- portFormat->eColorFormat = OMX_COLOR_FormatYUV420Planar;
- portFormat->xFramerate = pSfOMXComponent->portDefinition[1].format.video.xFramerate;
- break;
- case 1:
- portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused;
- portFormat->eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
- portFormat->xFramerate = pSfOMXComponent->portDefinition[1].format.video.xFramerate;
- break;
- case 2:
- portFormat->eCompressionFormat = OMX_VIDEO_CodingUnused;
- portFormat->eColorFormat = OMX_COLOR_FormatYVU420SemiPlanar;
- portFormat->xFramerate = pSfOMXComponent->portDefinition[1].format.video.xFramerate;
- break;
- default:
- if (index > 0)
- {
- ret = OMX_ErrorNoMore;
- }
- break;
- }
- }
- else
- {
- ret = OMX_ErrorBadPortIndex;
- }
- }
- break;
- case OMX_IndexParamVideoBitrate:
- break;
- case OMX_IndexParamVideoQuantization:
- break;
- case OMX_IndexParamPortDefinition:{
- OMX_PARAM_PORTDEFINITIONTYPE *pPortDefinition = (OMX_PARAM_PORTDEFINITIONTYPE *)ComponentParameterStructure;
- OMX_U32 portIndex = pPortDefinition->nPortIndex;
- OMX_PARAM_PORTDEFINITIONTYPE *pSrcDefinition;
- if (portIndex < 2)
- {
- pSrcDefinition = &pSfOMXComponent->portDefinition[portIndex];
- LOG(SF_LOG_INFO, "Get parameter width = %d, height = %d from port %X\r\n",
- pSrcDefinition->format.video.nFrameWidth, pSrcDefinition->format.video.nFrameHeight, portIndex);
- memcpy(pPortDefinition, pSrcDefinition, pPortDefinition->nSize);
- }
- else
- {
- LOG(SF_LOG_INFO,"Bad port index %d\r\n",portIndex);
- ret = OMX_ErrorBadPortIndex;
- }
- }
- break;
- case OMX_IndexParamVideoIntraRefresh:
- break;
- case OMX_IndexParamStandardComponentRole:
- {
- OMX_PARAM_COMPONENTROLETYPE *pComponentRole = (OMX_PARAM_COMPONENTROLETYPE *)ComponentParameterStructure;
- strcpy((OMX_STRING)(pComponentRole->cRole), pSfOMXComponent->componentRule);
- }
- break;
- case OMX_IndexParamVideoAvc:
- {
- OMX_VIDEO_PARAM_AVCTYPE *sFormatAvc = (OMX_VIDEO_PARAM_AVCTYPE *)ComponentParameterStructure;
- sFormatAvc->eProfile = OMX_VIDEO_AVCProfileBaseline;
- sFormatAvc->eLevel = OMX_VIDEO_AVCLevel1;
- }
- break;
- case OMX_IndexParamVideoHevc:
- break;
- case OMX_IndexParamVideoProfileLevelQuerySupported:
- ret = OMX_ErrorNoMore;
- break;
- case OMX_IndexParamCompBufferSupplier:
- {
- OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplier = (OMX_PARAM_BUFFERSUPPLIERTYPE *)ComponentParameterStructure;
- OMX_U32 portIndex = bufferSupplier->nPortIndex;
- if (portIndex >= 2)
- ret = OMX_ErrorBadPortIndex;
- }
- break;
- case OMX_IndexParamVideoProfileLevelCurrent:
- {
- OMX_VIDEO_PARAM_PROFILELEVELTYPE *pSrcProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)ComponentParameterStructure;
- OMX_U32 portIndex = pSrcProfileLevel->nPortIndex;
- OMX_VIDEO_PARAM_AVCTYPE *pAVCComponent = NULL;
- if (portIndex >= 2)
- ret = OMX_ErrorBadPortIndex;
- pAVCComponent = &pSfVideoImplement->AVCComponent[portIndex];
- pSrcProfileLevel->eProfile = pAVCComponent->eProfile;
- pSrcProfileLevel->eLevel = pAVCComponent->eLevel;
- }
- break;
- default:
- ret = OMX_ErrorUnsupportedIndex;
- break;
- }
- EXIT:
- FunctionOut();
- return ret;
- }
- static OMX_ERRORTYPE SF_OMX_SetParameter(
- OMX_IN OMX_HANDLETYPE hComponent,
- OMX_IN OMX_INDEXTYPE nIndex,
- OMX_IN OMX_PTR ComponentParameterStructure)
- {
- OMX_ERRORTYPE ret = OMX_ErrorNone;
- FunctionIn();
- if (hComponent == NULL || ComponentParameterStructure == NULL)
- {
- ret = OMX_ErrorBadParameter;
- goto EXIT;
- }
- OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
- SF_OMX_COMPONENT *pSfOMXComponent = pOMXComponent->pComponentPrivate;
- SF_WAVE5_IMPLEMEMT *pSfVideoImplement = (SF_WAVE5_IMPLEMEMT *)pSfOMXComponent->componentImpl;
- if (pSfOMXComponent == NULL)
- {
- ret = OMX_ErrorBadParameter;
- goto EXIT;
- }
- TestDecConfig *testConfig = pSfVideoImplement->testConfig;
- LOG(SF_LOG_INFO, "Set parameter on index %X\r\n", nIndex);
- switch ((OMX_U32)nIndex)
- {
- case OMX_IndexParamVideoPortFormat:
- {
- OMX_VIDEO_PARAM_PORTFORMATTYPE *portFormat = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)ComponentParameterStructure;
- OMX_U32 nPortIndex = portFormat->nPortIndex;
- TestDecConfig *pTestDecConfig = (TestDecConfig *)pSfVideoImplement->testConfig;
- OMX_PARAM_PORTDEFINITIONTYPE *pPort = &pSfOMXComponent->portDefinition[nPortIndex];
- LOG(SF_LOG_DEBUG, "Set video format to port %d color %d\r\n", portFormat->nPortIndex, portFormat->eColorFormat);
- if (nPortIndex == 0)
- {
- if (portFormat->eColorFormat != pPort->format.video.eColorFormat ||
- portFormat->eCompressionFormat != pPort->format.video.eCompressionFormat)
- {
- return OMX_ErrorBadParameter;
- }
- }
- else if (nPortIndex == 1)
- {
- if (portFormat->eCompressionFormat != pPort->format.video.eCompressionFormat)
- {
- return OMX_ErrorBadParameter;
- }
- switch (portFormat->eColorFormat)
- {
- case OMX_COLOR_FormatYUV420Planar: //I420
- pTestDecConfig->cbcrInterleave = FALSE;
- pTestDecConfig->nv21 = FALSE;
- pPort->format.video.eColorFormat = portFormat->eColorFormat;
- break;
- case OMX_COLOR_FormatYUV420SemiPlanar: //NV12
- pTestDecConfig->cbcrInterleave = TRUE;
- pTestDecConfig->nv21 = FALSE;
- pPort->format.video.eColorFormat = portFormat->eColorFormat;
- break;
- case OMX_COLOR_FormatYVU420SemiPlanar: //NV21
- pTestDecConfig->cbcrInterleave = TRUE;
- pTestDecConfig->nv21 = TRUE;
- pPort->format.video.eColorFormat = portFormat->eColorFormat;
- break;
- default:
- LOG(SF_LOG_ERR, "Error to set parameter: %d, only nv12 nv21 i420 supported\r\n", portFormat->eColorFormat);
- return OMX_ErrorBadParameter;
- break;
- }
- }
- else
- {
- return OMX_ErrorBadPortIndex;
- }
- break;
- }
- case OMX_IndexParamVideoBitrate:
- break;
- case OMX_IndexParamVideoQuantization:
- break;
- break;
- case OMX_IndexParamPortDefinition:
- {
- OMX_PARAM_PORTDEFINITIONTYPE *pPortDefinition = (OMX_PARAM_PORTDEFINITIONTYPE *)ComponentParameterStructure;
- OMX_PARAM_PORTDEFINITIONTYPE *pInputPort = &pSfOMXComponent->portDefinition[0];
- OMX_PARAM_PORTDEFINITIONTYPE *pOutputPort = &pSfOMXComponent->portDefinition[1];
- TestDecConfig *pTestDecConfig = (TestDecConfig *)pSfVideoImplement->testConfig;
- OMX_U32 portIndex = pPortDefinition->nPortIndex;
- OMX_U32 width = pPortDefinition->format.video.nFrameWidth;
- OMX_U32 height = pPortDefinition->format.video.nFrameHeight;
- LOG(SF_LOG_INFO, "Set width = %d, height = %d on port %d\r\n", width, height, pPortDefinition->nPortIndex);
- if (portIndex == 0)
- {
- if (pPortDefinition->nBufferCountActual != pInputPort->nBufferCountActual)
- {
- LOG(SF_LOG_INFO, "Set input buffer count = %d\r\n", pPortDefinition->nBufferCountActual);
- ComponentImpl *pFeederComponent = (ComponentImpl *)pSfVideoImplement->hSFComponentFeeder;
- if (pFeederComponent)
- {
- pSfVideoImplement->functions->ComponentPortDestroy(&pFeederComponent->srcPort);
- pSfVideoImplement->functions->ComponentPortCreate(&pFeederComponent->srcPort, pSfVideoImplement->hSFComponentFeeder,
- pPortDefinition->nBufferCountActual, sizeof(PortContainerExternal));
- }
- }
- memcpy(&pSfOMXComponent->portDefinition[portIndex], pPortDefinition, pPortDefinition->nSize);
- pInputPort->format.video.nStride = width;
- pInputPort->format.video.nSliceHeight = height;
- pInputPort->nBufferSize = width * height / 2;
- pOutputPort->format.video.nFrameWidth = width;
- pOutputPort->format.video.nFrameHeight = height;
- pOutputPort->format.video.nStride = OMX_ALIGN32(width);
- if (pSfOMXComponent->portDefinition[0].format.video.eCompressionFormat == OMX_VIDEO_CodingAVC)
- pOutputPort->format.video.nSliceHeight = OMX_ALIGN16(height);
- else
- pOutputPort->format.video.nSliceHeight = height;
- pTestDecConfig->scaleDownWidth = 0;
- pTestDecConfig->scaleDownHeight = 0;
- if (width && height)
- pOutputPort->nBufferSize = (pOutputPort->format.video.nStride * pOutputPort->format.video.nSliceHeight * 3) / 2;
- LOG(SF_LOG_INFO, "Set resol = %d x %d, stride %d x %d\r\n", width, height, pOutputPort->format.video.nStride, pOutputPort->format.video.nSliceHeight);
- }
- else if (portIndex == 1)
- {
- if (pPortDefinition->nBufferCountActual != pOutputPort->nBufferCountActual)
- {
- LOG(SF_LOG_INFO, "Set output buffer count = %d\r\n", pPortDefinition->nBufferCountActual);
- ComponentImpl *pRenderComponent = (ComponentImpl *)pSfVideoImplement->hSFComponentRender;
- if (pRenderComponent)
- {
- pSfVideoImplement->functions->SetRenderTotalBufferNumber(pRenderComponent, pPortDefinition->nBufferCountActual);
- pSfVideoImplement->functions->ComponentPortDestroy(&pRenderComponent->sinkPort);
- pSfVideoImplement->functions->ComponentPortCreate(&pRenderComponent->sinkPort, pSfVideoImplement->hSFComponentRender,
- pPortDefinition->nBufferCountActual, sizeof(PortContainerExternal));
- }
- }
- memcpy(&pSfOMXComponent->portDefinition[portIndex], pPortDefinition, pPortDefinition->nSize);
- /*
- Some client may set '0' or '1' to output port, in this case use input port parameters
- */
- if (width <= 1)
- {
- width = pInputPort->format.video.nFrameWidth;
- }
- if (height <= 1)
- {
- height = pInputPort->format.video.nFrameHeight;
- }
- if (width > 0 && height > 0)
- {
- int scalew = pInputPort->format.video.nFrameWidth / width;
- int scaleh = pInputPort->format.video.nFrameHeight / height;
- if (scalew > 8 || scaleh > 8 || scalew < 1 || scaleh < 1)
- {
- int nInputWidth = pInputPort->format.video.nFrameWidth;
- int nInputHeight = pInputPort->format.video.nFrameHeight;
- LOG(SF_LOG_WARN, "Scaling should be 1 to 1/8 (down-scaling only)! Use input parameter. "
- "OutPut[%d, %d]. Input[%d, %d]\r\n", width, height, nInputWidth, nInputHeight);
- width = nInputWidth;
- height = nInputHeight;
- }
- }
- pOutputPort->format.video.nFrameWidth = width;
- pOutputPort->format.video.nFrameHeight = height;
- pOutputPort->format.video.nStride = OMX_ALIGN32(width);
- if (pSfOMXComponent->portDefinition[0].format.video.eCompressionFormat == OMX_VIDEO_CodingAVC)
- pOutputPort->format.video.nSliceHeight = OMX_ALIGN16(height);
- else
- pOutputPort->format.video.nSliceHeight = height;
- LOG(SF_LOG_INFO, "Set resol = %d x %d, stride %d x %d\r\n", width, height, pOutputPort->format.video.nStride, pOutputPort->format.video.nSliceHeight);
- if(width != pInputPort->format.video.nFrameWidth || height != pInputPort->format.video.nFrameHeight)
- {
- pTestDecConfig->scaleDownWidth = OMX_ALIGN2(width);
- pTestDecConfig->scaleDownHeight = OMX_ALIGN2(height);
- pOutputPort->format.video.nStride = OMX_ALIGN32(testConfig->scaleDownWidth);
- pOutputPort->format.video.nSliceHeight = testConfig->scaleDownHeight;
- LOG(SF_LOG_INFO, "Set scale = %d, %d\r\n", pTestDecConfig->scaleDownWidth , pTestDecConfig->scaleDownHeight);
- }
- /*
- if cbcrInterleave is FALSE and nv21 is FALSE, the default dec format is I420
- if cbcrInterleave is TRUE and nv21 is FALSE, then the dec format is NV12
- if cbcrInterleave is TRUE and nv21 is TRUE, then the dec format is NV21
- */
- LOG(SF_LOG_INFO, "Set format = %d\r\n", pOutputPort->format.video.eColorFormat);
- switch (pOutputPort->format.video.eColorFormat)
- {
- case OMX_COLOR_FormatYUV420Planar: //I420
- pTestDecConfig->cbcrInterleave = FALSE;
- pTestDecConfig->nv21 = FALSE;
- if (width && height)
- pOutputPort->nBufferSize = (pOutputPort->format.video.nStride * pOutputPort->format.video.nSliceHeight * 3) / 2;
- break;
- case OMX_COLOR_FormatYUV420SemiPlanar: //NV12
- pTestDecConfig->cbcrInterleave = TRUE;
- pTestDecConfig->nv21 = FALSE;
- if (width && height)
- pOutputPort->nBufferSize = (pOutputPort->format.video.nStride * pOutputPort->format.video.nSliceHeight * 3) / 2;
- break;
- case OMX_COLOR_FormatYVU420SemiPlanar: //NV21
- pTestDecConfig->cbcrInterleave = TRUE;
- pTestDecConfig->nv21 = TRUE;
- if (width && height)
- pOutputPort->nBufferSize = (pOutputPort->format.video.nStride * pOutputPort->format.video.nSliceHeight * 3) / 2;
- break;
- default:
- LOG(SF_LOG_ERR, "Error to set parameter: %d, only nv12 nv21 i420 supported\r\n",
- pOutputPort->format.video.eColorFormat);
- return OMX_ErrorBadParameter;
- break;
- }
- }
- else
- {
- LOG(SF_LOG_INFO,"Bad port index %d\r\n",portIndex);
- ret = OMX_ErrorBadPortIndex;
- }
- }
- break;
- case OMX_IndexParamVideoIntraRefresh:
- break;
- case OMX_IndexParamStandardComponentRole:
- {
- if ((pSfOMXComponent->state != OMX_StateLoaded) &&
- (pSfOMXComponent->state != OMX_StateWaitForResources)) {
- ret = OMX_ErrorIncorrectStateOperation;
- }
- }
- break;
- case OMX_IndexParamVideoAvc:
- testConfig->bitFormat = 0;
- break;
- case OMX_IndexParamVideoHevc:
- testConfig->bitFormat = 12;
- break;
- case OMX_IndexParamCompBufferSupplier:
- {
- OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplier = (OMX_PARAM_BUFFERSUPPLIERTYPE *)ComponentParameterStructure;
- OMX_U32 portIndex = bufferSupplier->nPortIndex;
- if (portIndex >= 2)
- ret = OMX_ErrorBadPortIndex;
- }
- break;
- case OMX_IndexParamVideoProfileLevelCurrent:
- {
- OMX_VIDEO_PARAM_PROFILELEVELTYPE *pSrcProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)ComponentParameterStructure;
- OMX_U32 portIndex = pSrcProfileLevel->nPortIndex;
- OMX_VIDEO_PARAM_AVCTYPE *pAVCComponent = NULL;
- if (portIndex >= 2)
- ret = OMX_ErrorBadPortIndex;
- pAVCComponent = &pSfVideoImplement->AVCComponent[portIndex];
- pAVCComponent->eProfile = pSrcProfileLevel->eProfile;
- pAVCComponent->eLevel = pSrcProfileLevel->eLevel;
- }
- break;
- default:
- ret = OMX_ErrorUnsupportedIndex;
- break;
- }
- EXIT:
- FunctionOut();
- return ret;
- }
- static OMX_ERRORTYPE SF_OMX_GetConfig(
- OMX_HANDLETYPE hComponent,
- OMX_INDEXTYPE nIndex,
- OMX_PTR pComponentConfigStructure)
- {
- OMX_ERRORTYPE ret = OMX_ErrorNone;
- FunctionIn();
- if (hComponent == NULL)
- {
- ret = OMX_ErrorBadParameter;
- goto EXIT;
- }
- switch (nIndex)
- {
- case OMX_IndexConfigVideoAVCIntraPeriod:
- break;
- case OMX_IndexConfigVideoBitrate:
- break;
- case OMX_IndexConfigVideoFramerate:
- break;
- default:
- break;
- }
- EXIT:
- FunctionOut();
- return ret;
- }
- static OMX_ERRORTYPE SF_OMX_SetConfig(
- OMX_HANDLETYPE hComponent,
- OMX_INDEXTYPE nIndex,
- OMX_PTR pComponentConfigStructure)
- {
- OMX_ERRORTYPE ret = OMX_ErrorNone;
- FunctionIn();
- if (hComponent == NULL)
- {
- ret = OMX_ErrorBadParameter;
- goto EXIT;
- }
- switch ((OMX_U32)nIndex)
- {
- case OMX_IndexConfigVideoAVCIntraPeriod:
- break;
- case OMX_IndexConfigVideoBitrate:
- break;
- case OMX_IndexConfigVideoFramerate:
- break;
- case OMX_IndexConfigVideoIntraVOPRefresh:
- break;
- default:
- break;
- }
- EXIT:
- FunctionOut();
- return ret;
- }
- static OMX_ERRORTYPE SF_OMX_ComponentTunnelRequest(
- OMX_IN OMX_HANDLETYPE hComp,
- OMX_IN OMX_U32 nPort,
- OMX_IN OMX_HANDLETYPE hTunneledComp,
- OMX_IN OMX_U32 nTunneledPort,
- OMX_INOUT OMX_TUNNELSETUPTYPE *pTunnelSetup)
- {
- OMX_ERRORTYPE ret = OMX_ErrorNone;
- (void) hComp;
- (void) nPort;
- (void) hTunneledComp;
- (void) nTunneledPort;
- (void) pTunnelSetup;
- ret = OMX_ErrorTunnelingUnsupported;
- goto EXIT;
- EXIT:
- return ret;
- }
- static OMX_ERRORTYPE InitDecoder(SF_OMX_COMPONENT *pSfOMXComponent)
- {
- TestDecConfig *testConfig = NULL;
- CNMComponentConfig *config = NULL;
- Uint32 sizeInWord;
- char *fwPath = NULL;
- SF_WAVE5_IMPLEMEMT *pSfVideoImplement = (SF_WAVE5_IMPLEMEMT *)pSfOMXComponent->componentImpl;
- OMX_PARAM_PORTDEFINITIONTYPE *pInputPort = &pSfOMXComponent->portDefinition[0];
- if (pSfVideoImplement->hSFComponentExecoder != NULL)
- {
- return OMX_ErrorNone;
- }
- FunctionIn();
- testConfig = (TestDecConfig *)pSfVideoImplement->testConfig;
- testConfig->productId = (ProductId)pSfVideoImplement->functions->VPU_GetProductId(testConfig->coreIdx);
- if (CheckDecTestConfig(testConfig) == FALSE)
- {
- LOG(SF_LOG_ERR, "fail to CheckTestConfig()\n");
- return OMX_ErrorBadParameter;
- }
- switch (testConfig->productId)
- {
- case PRODUCT_ID_521:
- fwPath = pSfOMXComponent->fwPath;
- break;
- case PRODUCT_ID_511:
- fwPath = pSfOMXComponent->fwPath;
- break;
- case PRODUCT_ID_517:
- fwPath = CORE_7_BIT_CODE_FILE_PATH;
- break;
- default:
- LOG(SF_LOG_ERR, "Unknown product id: %d, whether kernel module loaded?\n", testConfig->productId);
- return OMX_ErrorBadParameter;
- }
- LOG(SF_LOG_INFO, "FW PATH = %s\n", fwPath);
- if (pSfVideoImplement->functions->LoadFirmware(testConfig->productId, (Uint8 **)&(pSfVideoImplement->pusBitCode), &sizeInWord, fwPath) < 0)
- {
- LOG(SF_LOG_ERR, "Failed to load firmware: %s\n", fwPath);
- return OMX_ErrorInsufficientResources;
- }
- config = pSfVideoImplement->config;
- memcpy(&(config->testDecConfig), testConfig, sizeof(TestDecConfig));
- config->bitcode = (Uint8 *)pSfVideoImplement->pusBitCode;
- config->sizeOfBitcode = sizeInWord;
- if (pInputPort->format.video.nFrameWidth && pInputPort->format.video.nFrameHeight)
- config->testDecConfig.bsSize = (pInputPort->format.video.nFrameWidth * pInputPort->format.video.nFrameHeight / 2);
- if (pSfOMXComponent->memory_optimization)
- {
- config->MemoryOptimization = TRUE;
- }
- if (pSfVideoImplement->functions->SetUpDecoderOpenParam(&config->decOpenParam, &config->testDecConfig) != RETCODE_SUCCESS)
- {
- LOG(SF_LOG_ERR, "SetupDecoderOpenParam error\n");
- return OMX_ErrorBadParameter;
- }
- LOG(SF_LOG_DEBUG, "cbcrInterleave = %d, nv21 = %d\r\n", testConfig->cbcrInterleave, testConfig->nv21);
- pSfVideoImplement->hSFComponentExecoder = pSfVideoImplement->functions->ComponentCreate("wave_decoder", config);
- pSfVideoImplement->hSFComponentFeeder = pSfVideoImplement->functions->ComponentCreate("feeder", config);
- pSfVideoImplement->hSFComponentRender = pSfVideoImplement->functions->ComponentCreate("renderer", config);
- ComponentImpl *pFeederComponent = (ComponentImpl *)pSfVideoImplement->hSFComponentFeeder;
- pSfVideoImplement->functions->ComponentPortCreate(&pFeederComponent->srcPort, pSfVideoImplement->hSFComponentFeeder,
- pSfOMXComponent->portDefinition[0].nBufferCountActual, sizeof(PortContainerExternal));
- ComponentImpl *pRenderComponent = (ComponentImpl *)pSfVideoImplement->hSFComponentRender;
- pSfVideoImplement->functions->ComponentPortDestroy(&pRenderComponent->sinkPort);
- pSfVideoImplement->functions->ComponentPortCreate(&pRenderComponent->sinkPort, pSfVideoImplement->hSFComponentRender,
- MAX_GDI_IDX, sizeof(PortContainerExternal));
- if (pSfVideoImplement->functions->SetupDecListenerContext(pSfVideoImplement->lsnCtx, config, NULL) == TRUE)
- {
- pSfVideoImplement->functions->ComponentRegisterListener(pSfVideoImplement->hSFComponentExecoder,
- COMPONENT_EVENT_DEC_ALL, pSfVideoImplement->functions->DecoderListener, (void *)pSfVideoImplement->lsnCtx);
- pSfVideoImplement->functions->ComponentRegisterListener(pSfVideoImplement->hSFComponentExecoder,
- COMPONENT_EVENT_DEC_INSUFFIC_RESOURCE, OnEventArrived, (void *)pSfOMXComponent);
- pSfVideoImplement->functions->ComponentRegisterListener(pSfVideoImplement->hSFComponentRender,
- COMPONENT_EVENT_DEC_DECODED_ALL, OnEventArrived, (void *)pSfOMXComponent);
- pSfVideoImplement->functions->ComponentRegisterListener(pSfVideoImplement->hSFComponentFeeder,
- COMPONENT_EVENT_DEC_ALL, OnEventArrived, (void *)pSfOMXComponent);
- pSfVideoImplement->functions->ComponentRegisterListener(pSfVideoImplement->hSFComponentRender,
- COMPONENT_EVENT_DEC_ALL, OnEventArrived, (void *)pSfOMXComponent);
- }
- else
- {
- LOG(SF_LOG_ERR, "ComponentRegisterListener fail\r\n");
- return OMX_ErrorBadParameter;
- }
- pSfVideoImplement->functions->ComponentSetupTunnel(pSfVideoImplement->hSFComponentFeeder, pSfVideoImplement->hSFComponentExecoder);
- pSfVideoImplement->functions->ComponentSetupTunnel(pSfVideoImplement->hSFComponentExecoder, pSfVideoImplement->hSFComponentRender);
- FunctionOut();
- return OMX_ErrorNone;
- }
- static OMX_ERRORTYPE SF_OMX_SendCommand(
- OMX_IN OMX_HANDLETYPE hComponent,
- OMX_IN OMX_COMMANDTYPE Cmd,
- OMX_IN OMX_U32 nParam,
- OMX_IN OMX_PTR pCmdData)
- {
- OMX_ERRORTYPE ret = OMX_ErrorNone;
- OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
- SF_OMX_COMPONENT *pSfOMXComponent = pOMXComponent->pComponentPrivate;
- SF_WAVE5_IMPLEMEMT *pSfVideoImplement = (SF_WAVE5_IMPLEMEMT *)pSfOMXComponent->componentImpl;
- OMX_STATETYPE comCurrentState;
- DEC_CMD cmd;
- //BOOL done = 0;
- FunctionIn();
- if (hComponent == NULL || pSfOMXComponent == NULL)
- {
- ret = OMX_ErrorBadParameter;
- goto EXIT;
- }
- LOG(SF_LOG_INFO, "cmd = %X, nParam = %X\r\n", Cmd, nParam);
- comCurrentState = pSfOMXComponent->state;
- if (comCurrentState == OMX_StateInvalid) {
- return OMX_ErrorInvalidState;
- }
- switch (Cmd)
- {
- case OMX_CommandStateSet:
- {
- if ((nParam == OMX_StateLoaded) &&
- (pSfOMXComponent->state == OMX_StateIdle))
- {
- pSfOMXComponent->traningState = OMX_TransStateIdleToLoaded;
- }
- else if ((nParam == OMX_StateIdle) &&
- (pSfOMXComponent->state == OMX_StateLoaded))
- {
- pSfOMXComponent->traningState = OMX_TransStateLoadedToIdle;
- }
- }
- break;
- case OMX_CommandFlush:
- {
- if (nParam >= 2 && nParam != OMX_ALL)
- return OMX_ErrorBadPortIndex;
- }
- break;
- case OMX_CommandMarkBuffer:
- {
- if (nParam >= 2)
- return OMX_ErrorBadPortIndex;
- if ((pSfOMXComponent->state != OMX_StateExecuting) &&
- (pSfOMXComponent->state != OMX_StatePause))
- return OMX_ErrorIncorrectStateOperation;
- }
- break;
- case OMX_CommandPortDisable:
- {
- if (nParam >= 2 && nParam != OMX_ALL)
- return OMX_ErrorBadPortIndex;
- if (nParam == OMX_ALL)
- {
- for (int i = 0; i < 2; i++)
- {
- if(pSfOMXComponent->portDefinition[i].bEnabled == OMX_FALSE)
- return OMX_ErrorIncorrectStateOperation;
- }
- for (int i = 0; i < 2; i++)
- {
- pSfOMXComponent->portDefinition[i].bEnabled = OMX_FALSE;
- }
- }
- else
- {
- if (pSfOMXComponent->portDefinition[nParam].bEnabled == OMX_FALSE)
- return OMX_ErrorIncorrectStateOperation;
- pSfOMXComponent->portDefinition[nParam].bEnabled = OMX_FALSE;
- }
- }
- break;
- case OMX_CommandPortEnable:
- {
- if (nParam >= 2 && nParam != OMX_ALL)
- return OMX_ErrorBadPortIndex;
- if (nParam == OMX_ALL)
- {
- for (int i = 0; i < 2; i++)
- {
- if(pSfOMXComponent->portDefinition[i].bEnabled == OMX_TRUE)
- return OMX_ErrorIncorrectStateOperation;
- }
- for (int i = 0; i < 2; i++)
- {
- pSfOMXComponent->portDefinition[i].bEnabled = OMX_TRUE;
- }
- }
- else
- {
- if (pSfOMXComponent->portDefinition[nParam].bEnabled == OMX_TRUE)
- return OMX_ErrorIncorrectStateOperation;
- pSfOMXComponent->portDefinition[nParam].bEnabled = OMX_TRUE;
- }
- }
- break;
- default:
- break;
- }
- cmd.Cmd = Cmd;
- cmd.nParam = nParam;
- cmd.pCmdData = pCmdData;
- ret = SF_Queue_Enqueue(pSfVideoImplement->CmdQueue, &cmd);
- EXIT:
- FunctionOut();
- return ret;
- }
- static OMX_ERRORTYPE SF_OMX_GetState(
- OMX_IN OMX_HANDLETYPE hComponent,
- OMX_OUT OMX_STATETYPE *pState)
- {
- OMX_ERRORTYPE ret = OMX_ErrorNone;
- OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
- SF_OMX_COMPONENT *pSfOMXComponent = pOMXComponent->pComponentPrivate;
- FunctionIn();
- *pState = pSfOMXComponent->state;
- FunctionOut();
- return ret;
- }
- static OMX_ERRORTYPE SF_OMX_FreeBuffer(
- OMX_IN OMX_HANDLETYPE hComponent,
- OMX_IN OMX_U32 nPortIndex,
- OMX_IN OMX_BUFFERHEADERTYPE *pBufferHdr)
- {
- OMX_ERRORTYPE ret = OMX_ErrorNone;
- OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
- SF_OMX_COMPONENT *pSfOMXComponent = pOMXComponent->pComponentPrivate;
- SF_OMX_BUF_INFO *pBufInfo;
- FunctionIn();
- if(pBufferHdr == NULL)
- return OMX_ErrorBadParameter;
- if(nPortIndex == 0)
- pBufInfo = pBufferHdr->pInputPortPrivate;
- else if(nPortIndex == 1)
- pBufInfo = pBufferHdr->pOutputPortPrivate;
- LOG(SF_LOG_INFO, "free header %p pBuffer address = %p on port %d\r\n",
- pBufferHdr, pBufferHdr->pBuffer, nPortIndex);
- if ((pSfOMXComponent->traningState != OMX_TransStateIdleToLoaded) &&
- (pSfOMXComponent->portDefinition[nPortIndex].bEnabled))
- {
- LOG(SF_LOG_INFO, "port Unpopulated\r\n");
- pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData,
- OMX_EventError, OMX_ErrorPortUnpopulated, nPortIndex, NULL);
- }
- if(pBufInfo->type == SF_BUFFER_NOMAL)
- {
- if(pBufferHdr->pBuffer)
- free(pBufferHdr->pBuffer);
- }
- else if(pBufInfo->type == SF_BUFFER_DMA)
- {
- SF_WAVE5_IMPLEMEMT *pSfVideoImplement = (SF_WAVE5_IMPLEMEMT *)pSfOMXComponent->componentImpl;
- ComponentImpl *pComponentRender = (ComponentImpl *)pSfVideoImplement->hSFComponentRender;
- pSfVideoImplement->functions->FreeFrameBuffer2(pComponentRender, pBufferHdr->pBuffer);
- }
- pSfOMXComponent->pBufferArray[nPortIndex][pBufInfo->index] = NULL;
- pSfOMXComponent->assignedBufferNum[nPortIndex]--;
- LOG(SF_LOG_INFO, "remain %d buff port %d assgin\r\n",pSfOMXComponent->assignedBufferNum[nPortIndex], nPortIndex);
- free(pBufferHdr);
- free(pBufInfo);
- if (ret == OMX_ErrorNone) {
- if (pSfOMXComponent->assignedBufferNum[nPortIndex] == 0) {
- LOG(SF_LOG_INFO, "unloadedResource signal set\r\n");
- SF_SemaphorePost(pSfOMXComponent->portUnloadSemaphore[nPortIndex]);
- pSfOMXComponent->portDefinition[nPortIndex].bPopulated = OMX_FALSE;
- }
- }
- FunctionOut();
- return ret;
- }
- static void FlushInputQ(SF_OMX_COMPONENT *pSfOMXComponent, SF_Queue *pQueue)
- {
- OMX_BUFFERHEADERTYPE *pOMXBuffer = NULL;
- OMX_BUFFERHEADERTYPE **ppBuffer = NULL;
- ppBuffer = SF_Queue_Dequeue(pQueue);
- while (ppBuffer)
- {
- pOMXBuffer = *ppBuffer;
- LOG(SF_LOG_PERF, "OMX empty one buffer, address = %p, size = %d, nTimeStamp = %d, nFlags = %X\r\n",
- pOMXBuffer->pBuffer, pOMXBuffer->nFilledLen, pOMXBuffer->nTimeStamp, pOMXBuffer->nFlags);
- pSfOMXComponent->callbacks->EmptyBufferDone(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData, pOMXBuffer);
- ppBuffer = SF_Queue_Dequeue(pQueue);
- }
- }
- static void FlushOutputQ(SF_OMX_COMPONENT *pSfOMXComponent, SF_Queue *pQueue)
- {
- OMX_BUFFERHEADERTYPE *pOMXBuffer = NULL;
- OMX_BUFFERHEADERTYPE **ppBuffer = NULL;
- ppBuffer = SF_Queue_Dequeue(pQueue);
- while (ppBuffer)
- {
- pOMXBuffer = *ppBuffer;
- LOG(SF_LOG_PERF, "OMX finish one buffer, address = %p, size = %d, nTimeStamp = %d, nFlags = %X\r\n",
- pOMXBuffer->pBuffer, pOMXBuffer->nFilledLen, pOMXBuffer->nTimeStamp, pOMXBuffer->nFlags);
- pSfOMXComponent->callbacks->FillBufferDone(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData, pOMXBuffer);
- ppBuffer = SF_Queue_Dequeue(pQueue);
- }
- }
- static void CmdThread(void *args)
- {
- OMX_ERRORTYPE ret = OMX_ErrorNone;
- SF_OMX_COMPONENT *pSfOMXComponent = (SF_OMX_COMPONENT *)args;
- SF_WAVE5_IMPLEMEMT *pSfVideoImplement = (SF_WAVE5_IMPLEMEMT *)pSfOMXComponent->componentImpl;
- OMX_STATETYPE comCurrentState;
- ComponentImpl *pSFComponentDecoder = NULL;
- ComponentImpl *pSFComponentFeeder = NULL;
- ComponentImpl *pSFComponentRender = NULL;
- ComponentState componentState;
- DEC_CMD *pCmd;
- OMX_U32 i = 0, cnt = 0;
- while(1){
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
- pCmd = (DEC_CMD*)SF_Queue_Dequeue_Block(pSfVideoImplement->CmdQueue);
- pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
- pthread_testcancel();
- pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
- if(!pCmd)
- continue;
- if(pCmd->Cmd == DEC_StopThread)
- break;
- switch (pCmd->Cmd)
- {
- case OMX_CommandStateSet:
- LOG(SF_LOG_INFO, "OMX dest state = %X\r\n", pCmd->nParam);
- //GetStateCommon(hComponent, &comCurrentState);
- comCurrentState = pSfOMXComponent->state;
- if (comCurrentState == pCmd->nParam)
- {
- LOG(SF_LOG_DEBUG, "same state %d\r\n", pCmd->nParam);
- pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData,
- OMX_EventError, OMX_ErrorSameState, pCmd->nParam, NULL);
- break;
- }
- ret = OMX_ErrorNone;
- switch (pCmd->nParam)
- {
- case OMX_StateInvalid:
- switch (comCurrentState)
- {
- case OMX_StateExecuting:
- pSfVideoImplement->functions->ComponentStop(pSfVideoImplement->hSFComponentFeeder);
- pSfVideoImplement->functions->ComponentStop(pSfVideoImplement->hSFComponentExecoder);
- pSfVideoImplement->functions->ComponentStop(pSfVideoImplement->hSFComponentRender);
- case OMX_StateIdle:
- case OMX_StatePause:
- case OMX_StateLoaded:
- case OMX_StateWaitForResources:
- default:
- pSfOMXComponent->state = OMX_StateInvalid;
- break;
- }
- ret = OMX_ErrorInvalidState;
- break;
- case OMX_StateLoaded:
- switch (comCurrentState)
- {
- case OMX_StateWaitForResources:
- break;
- case OMX_StateIdle:
- for (i = 0; i < 2; i++)
- {
- if (pSfOMXComponent->portDefinition[i].bEnabled){
- LOG(SF_LOG_INFO,"unload SemaphoreWait \r\n");
- SF_SemaphoreWait(pSfOMXComponent->portUnloadSemaphore[i]);
- LOG(SF_LOG_INFO,"unload SemaphoreWait out\r\n");
- }
- }
- break;
- default:
- ret = OMX_ErrorIncorrectStateTransition;
- break;
- }
- break;
- case OMX_StateIdle:
- if (comCurrentState == OMX_StatePause)
- {
- comCurrentState = pSfOMXComponent->stateBeforePause;
- }
- switch (comCurrentState)
- {
- case OMX_StateLoaded:
- ret = InitDecoder(pSfOMXComponent);
- if (ret != OMX_ErrorNone)
- {
- break;
- }
- pSFComponentDecoder = (ComponentImpl *)pSfVideoImplement->hSFComponentExecoder;
- pSFComponentFeeder = (ComponentImpl *)pSfVideoImplement->hSFComponentFeeder;
- pSFComponentRender = (ComponentImpl *)pSfVideoImplement->hSFComponentRender;
- pSFComponentFeeder->pause = OMX_FALSE;
- pSFComponentDecoder->pause = OMX_FALSE;
- pSFComponentRender->pause = OMX_FALSE;
- for (i = 0; i < 2; i++)
- {
- if (pSfOMXComponent->portDefinition[i].bEnabled){
- LOG(SF_LOG_INFO,"SemaphoreWait \r\n");
- SF_SemaphoreWait(pSfOMXComponent->portSemaphore[i]);
- LOG(SF_LOG_INFO,"SemaphoreWait out\r\n");
- }
- }
- pSfVideoImplement->rev_eos =OMX_FALSE;
- break;
- case OMX_StateExecuting:
- pSFComponentDecoder = (ComponentImpl *)pSfVideoImplement->hSFComponentExecoder;
- pSFComponentFeeder = (ComponentImpl *)pSfVideoImplement->hSFComponentFeeder;
- pSFComponentRender = (ComponentImpl *)pSfVideoImplement->hSFComponentRender;
- if (!pSfOMXComponent->memory_optimization)
- {
- LOG(SF_LOG_INFO,"feeder src q cnt %d\r\n",
- pSfVideoImplement->functions->Queue_Get_Cnt(((ComponentImpl *)(pSfVideoImplement->hSFComponentFeeder))->srcPort.inputQ));
- pSfVideoImplement->functions->ComponentStop(pSFComponentRender);
- pSfVideoImplement->functions->ComponentStop(pSFComponentDecoder);
- pSfVideoImplement->functions->ComponentStop(pSFComponentFeeder);
- FlushBuffer(pSfOMXComponent, 0);
- FlushInputQ(pSfOMXComponent, pSfVideoImplement->inPortQ);
- FlushBuffer(pSfOMXComponent, 1);
- FlushOutputQ(pSfOMXComponent, pSfVideoImplement->outPortQ);
- pSfVideoImplement->functions->ComponentWait(pSFComponentRender);
- pSfVideoImplement->functions->ComponentWait(pSFComponentDecoder);
- pSfVideoImplement->functions->ComponentWait(pSFComponentFeeder);
- pSFComponentRender->terminate = OMX_TRUE;
- pSFComponentDecoder->terminate = OMX_TRUE;
- pSFComponentFeeder->terminate = OMX_TRUE;
- pSfVideoImplement->functions->ComponentRelease(pSFComponentFeeder);
- pSfVideoImplement->functions->ComponentRelease(pSFComponentDecoder);
- pSfVideoImplement->functions->ComponentRelease(pSFComponentRender);
- pSfVideoImplement->functions->ComponentDestroy(pSFComponentFeeder, NULL);
- pSfVideoImplement->functions->ComponentDestroy(pSFComponentDecoder, NULL);
- pSfVideoImplement->functions->ComponentDestroy(pSFComponentRender, NULL);
- pSfVideoImplement->hSFComponentExecoder = NULL;
- pSfVideoImplement->hSFComponentFeeder = NULL;
- pSfVideoImplement->hSFComponentRender = NULL;
- }
- else
- {
- pSFComponentDecoder->pause = OMX_TRUE;
- pSFComponentFeeder->pause = OMX_TRUE;
- pSFComponentRender->pause = OMX_TRUE;
- FlushBuffer(pSfOMXComponent, 0);
- FlushBuffer(pSfOMXComponent, 1);
- }
- pSfVideoImplement->rev_eos =OMX_FALSE;
- break;
- case OMX_StateIdle:
- pSFComponentFeeder->pause = OMX_FALSE;
- pSFComponentDecoder->pause = OMX_FALSE;
- pSFComponentRender->pause = OMX_FALSE;
- break;
- default:
- ret = OMX_ErrorIncorrectStateTransition;
- break;
- }
- break;
- case OMX_StateWaitForResources:
- switch (comCurrentState)
- {
- case OMX_StateLoaded:
- break;
- default:
- ret = OMX_ErrorIncorrectStateTransition;
- break;
- }
- break;
- case OMX_StateExecuting:
- if (comCurrentState == OMX_StatePause)
- {
- comCurrentState = pSfOMXComponent->stateBeforePause;
- }
- switch (comCurrentState)
- {
- case OMX_StateIdle:
- ret = InitDecoder(pSfOMXComponent);
- if (ret != OMX_ErrorNone)
- {
- break;
- }
- pSFComponentDecoder = (ComponentImpl *)pSfVideoImplement->hSFComponentExecoder;
- pSFComponentFeeder = (ComponentImpl *)pSfVideoImplement->hSFComponentFeeder;
- pSFComponentRender = (ComponentImpl *)pSfVideoImplement->hSFComponentRender;
- if (pSFComponentDecoder->thread == NULL)
- {
- LOG(SF_LOG_INFO, "execute component %s\r\n", pSFComponentDecoder->name);
- componentState = pSfVideoImplement->functions->ComponentExecute(pSFComponentDecoder);
- LOG(SF_LOG_INFO, "ret = %d\r\n", componentState);
- }
- if (pSFComponentFeeder->thread == NULL)
- {
- LOG(SF_LOG_INFO, "execute component %s\r\n", pSFComponentFeeder->name);
- componentState = pSfVideoImplement->functions->ComponentExecute(pSFComponentFeeder);
- LOG(SF_LOG_INFO, "ret = %d\r\n", componentState);
- }
- if (pSFComponentRender->thread == NULL)
- {
- LOG(SF_LOG_INFO, "execute component %s\r\n", pSFComponentRender->name);
- componentState = pSfVideoImplement->functions->ComponentExecute(pSFComponentRender);
- LOG(SF_LOG_INFO, "ret = %d\r\n", componentState);
- }
- pSFComponentFeeder->pause = OMX_FALSE;
- pSFComponentDecoder->pause = OMX_FALSE;
- pSFComponentRender->pause = OMX_FALSE;
- break;
- case OMX_StateExecuting:
- pSFComponentFeeder->pause = OMX_FALSE;
- pSFComponentDecoder->pause = OMX_FALSE;
- pSFComponentRender->pause = OMX_FALSE;
- break;
- default:
- ret = OMX_ErrorIncorrectStateTransition;
- break;
- }
- break;
- case OMX_StatePause:
- switch (comCurrentState)
- {
- case OMX_StateIdle:
- case OMX_StateExecuting:
- pSFComponentFeeder->pause = OMX_TRUE;
- pSFComponentDecoder->pause = OMX_TRUE;
- pSFComponentRender->pause = OMX_TRUE;
- pSfOMXComponent->stateBeforePause = comCurrentState;
- break;
- default:
- ret = OMX_ErrorIncorrectStateTransition;
- break;
- }
- break;
- default:
- ret = OMX_ErrorIncorrectStateTransition;
- break;
- }
- if (ret == OMX_ErrorNone)
- {
- pSfOMXComponent->state = pCmd->nParam;
- pSfOMXComponent->traningState = OMX_TransStateInvalid;
- pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData,
- OMX_EventCmdComplete, OMX_CommandStateSet, pCmd->nParam, NULL);
- LOG(SF_LOG_DEBUG, "complete cmd StateSet %d\r\n", pCmd->nParam);
- if (pSfOMXComponent->state == OMX_StateExecuting)
- {
- FlushOutputQ(pSfOMXComponent, pSfVideoImplement->outPauseQ);
- FlushInputQ(pSfOMXComponent, pSfVideoImplement->inPauseQ);
- }
- }
- else
- {
- pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData,
- OMX_EventError, ret, 0, NULL);
- LOG(SF_LOG_DEBUG, "Can't go to state %d from %d, ret %X \r\n",pSfOMXComponent->state, pCmd->nParam, ret);
- }
- break;
- case OMX_CommandFlush:
- {
- LOG(SF_LOG_INFO, "flush port %d\r\n", pCmd->nParam);
- OMX_U32 nPort = pCmd->nParam;
- cnt = (pCmd->nParam == OMX_ALL) ? 2 : 1;
- for (i = 0; i < cnt; i++) {
- if (pCmd->nParam == OMX_ALL)
- nPort = i;
- else
- nPort = pCmd->nParam;
- if (nPort == 0)
- {
- pSfOMXComponent->bPortFlushing[0] = OMX_TRUE;
- FlushBuffer(pSfOMXComponent, nPort);
- if (pSfOMXComponent->state == OMX_StatePause)
- {
- FlushInputQ(pSfOMXComponent, pSfVideoImplement->inPauseQ);
- }
- FlushInputQ(pSfOMXComponent, pSfVideoImplement->inPortQ);
- pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData,
- OMX_EventCmdComplete, OMX_CommandFlush, nPort, NULL);
- pSfOMXComponent->bPortFlushing[0] = OMX_FALSE;
- }
- else
- {
- pSfOMXComponent->bPortFlushing[1] = OMX_TRUE;
- FlushBuffer(pSfOMXComponent, nPort);
- if (pSfOMXComponent->state == OMX_StatePause)
- {
- FlushOutputQ(pSfOMXComponent, pSfVideoImplement->outPauseQ);
- }
- if (!pSfOMXComponent->memory_optimization){
- FlushOutputQ(pSfOMXComponent, pSfVideoImplement->outPortQ);
- }
- pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData,
- OMX_EventCmdComplete, OMX_CommandFlush, nPort, NULL);
- pSfOMXComponent->bPortFlushing[1] = OMX_FALSE;
- }
- }
- }
- break;
- case OMX_CommandPortDisable:
- {
- LOG(SF_LOG_INFO, "disable port %d\r\n", pCmd->nParam);
- OMX_U32 nPort;
- cnt = (pCmd->nParam == OMX_ALL) ? 2 : 1;
- for (i = 0; i < cnt; i++) {
- if (pCmd->nParam == OMX_ALL)
- nPort = i;
- else
- nPort = pCmd->nParam;
- FlushBuffer(pSfOMXComponent, nPort);
- if (nPort == 0)
- FlushInputQ(pSfOMXComponent, pSfVideoImplement->inPortQ);
- else if (nPort == 1)
- FlushOutputQ(pSfOMXComponent, pSfVideoImplement->outPortQ);
- }
- for (i = 0; i < cnt; i++) {
- if (pCmd->nParam == OMX_ALL)
- nPort = i;
- else
- nPort = pCmd->nParam;
- if (pSfOMXComponent->state != OMX_StateLoaded)
- SF_SemaphoreWait(pSfOMXComponent->portUnloadSemaphore[nPort]);
- pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData,
- OMX_EventCmdComplete, OMX_CommandPortDisable, nPort, NULL);
- }
- }
- break;
- case OMX_CommandPortEnable:
- {
- LOG(SF_LOG_INFO, "enable port %d\r\n", pCmd->nParam);
- OMX_U32 nPort;
- cnt = (pCmd->nParam == OMX_ALL) ? 2 : 1;
- for (i = 0; i < cnt; i++) {
- if (pCmd->nParam == OMX_ALL)
- nPort = i;
- else
- nPort = pCmd->nParam;
- if ((pSfOMXComponent->state != OMX_StateLoaded) &&
- (pSfOMXComponent->state != OMX_StateWaitForResources))
- SF_SemaphoreWait(pSfOMXComponent->portSemaphore[nPort]);
- pSfOMXComponent->callbacks->EventHandler(pSfOMXComponent->pOMXComponent, pSfOMXComponent->pAppData,
- OMX_EventCmdComplete, OMX_CommandPortEnable, nPort, NULL);
- }
- }
- break;
- case OMX_CommandMarkBuffer:
- {
- LOG(SF_LOG_INFO, "set mark %d\r\n", pCmd->nParam);
- OMX_U32 nPort;
- nPort = pCmd->nParam;
- pSfOMXComponent->markType[nPort].hMarkTargetComponent =
- ((OMX_MARKTYPE *)pCmd->pCmdData)->hMarkTargetComponent;
- pSfOMXComponent->markType[nPort].pMarkData =
- ((OMX_MARKTYPE *)pCmd->pCmdData)->pMarkData;
- }
- break;
- default:
- break;
- }
- }
- pthread_exit(NULL);
- }
- static OMX_ERRORTYPE SF_OMX_GetComponentVersion(
- OMX_IN OMX_HANDLETYPE hComponent,
- OMX_OUT OMX_STRING pComponentName,
- OMX_OUT OMX_VERSIONTYPE *pComponentVersion,
- OMX_OUT OMX_VERSIONTYPE *pSpecVersion,
- OMX_OUT OMX_UUIDTYPE *pComponentUUID)
- {
- OMX_ERRORTYPE ret = OMX_ErrorNone;
- OMX_COMPONENTTYPE *pOMXComponent = NULL;
- SF_OMX_COMPONENT *pSfOMXComponent = NULL;
- OMX_U32 compUUID[4];
- FunctionIn();
- /* check parameters */
- if (hComponent == NULL ||
- pComponentName == NULL || pComponentVersion == NULL ||
- pSpecVersion == NULL || pComponentUUID == NULL) {
- ret = OMX_ErrorBadParameter;
- goto EXIT;
- }
- pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
- if (pOMXComponent->pComponentPrivate == NULL) {
- ret = OMX_ErrorBadParameter;
- goto EXIT;
- }
- pSfOMXComponent = (SF_OMX_COMPONENT *)pOMXComponent->pComponentPrivate;
- if (pSfOMXComponent->state == OMX_StateInvalid) {
- ret = OMX_ErrorInvalidState;
- goto EXIT;
- }
- strcpy(pComponentName, pSfOMXComponent->componentName);
- memcpy(pComponentVersion, &(pSfOMXComponent->componentVersion), sizeof(OMX_VERSIONTYPE));
- memcpy(pSpecVersion, &(pSfOMXComponent->specVersion), sizeof(OMX_VERSIONTYPE));
- /* Fill UUID with handle address, PID and UID.
- * This should guarantee uiniqness */
- compUUID[0] = (OMX_U32)getpid();
- compUUID[1] = (OMX_U32)getpid();
- compUUID[2] = (OMX_U32)getpid();
- compUUID[3] = (OMX_U32)getpid();
- //compUUID[1] = getpid();
- //compUUID[2] = getuid();
- memcpy(*pComponentUUID, compUUID, 4 * sizeof(*compUUID));
- ret = OMX_ErrorNone;
- EXIT:
- FunctionOut();
- return ret;
- }
- static OMX_ERRORTYPE SF_OMX_UseEGLImage(
- OMX_IN OMX_HANDLETYPE hComponent,
- OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
- OMX_IN OMX_U32 nPortIndex,
- OMX_IN OMX_PTR pAppPrivate,
- OMX_IN void* eglImage)
- {
- return OMX_ErrorNotImplemented;
- }
- static OMX_U32 nInstance = 0;
- static OMX_ERRORTYPE SF_OMX_ComponentConstructor(SF_OMX_COMPONENT *pSfOMXComponent)
- {
- OMX_ERRORTYPE ret = OMX_ErrorNone;
- FunctionIn();
- if (nInstance >= 4)
- {
- ret = OMX_ErrorInsufficientResources;
- goto EXIT;
- }
- nInstance++;
- ret = InitComponentStructorCommon(pSfOMXComponent);
- if (ret != OMX_ErrorNone)
- {
- nInstance--;
- goto EXIT;
- }
- SF_WAVE5_IMPLEMEMT *pSfVideoImplement = (SF_WAVE5_IMPLEMEMT *)pSfOMXComponent->componentImpl;
- TestDecConfig *pTestDecConfig = (TestDecConfig *)pSfVideoImplement->testConfig;
- pTestDecConfig->feedingMode = FEEDING_METHOD_BUFFER;
- pTestDecConfig->bitstreamMode = BS_MODE_PIC_END;
- pTestDecConfig->bitFormat = pSfVideoImplement->bitFormat;
- /*
- if cbcrInterleave is FALSE and nv21 is FALSE, the default dec format is I420
- if cbcrInterleave is TRUE and nv21 is FALSE, then the dec format is NV12
- if cbcrInterleave is TRUE and nv21 is TRUE, then the dec format is NV21
- */
- pTestDecConfig->cbcrInterleave = TRUE;
- pTestDecConfig->nv21 = FALSE;
- pSfOMXComponent->pOMXComponent->UseBuffer = &SF_OMX_UseBuffer;
- pSfOMXComponent->pOMXComponent->AllocateBuffer = &SF_OMX_AllocateBuffer;
- pSfOMXComponent->pOMXComponent->EmptyThisBuffer = &SF_OMX_EmptyThisBuffer;
- pSfOMXComponent->pOMXComponent->FillThisBuffer = &SF_OMX_FillThisBuffer;
- pSfOMXComponent->pOMXComponent->FreeBuffer = &SF_OMX_FreeBuffer;
- pSfOMXComponent->pOMXComponent->ComponentTunnelRequest = &SF_OMX_ComponentTunnelRequest;
- pSfOMXComponent->pOMXComponent->GetParameter = &SF_OMX_GetParameter;
- pSfOMXComponent->pOMXComponent->SetParameter = &SF_OMX_SetParameter;
- pSfOMXComponent->pOMXComponent->GetConfig = &SF_OMX_GetConfig;
- pSfOMXComponent->pOMXComponent->SetConfig = &SF_OMX_SetConfig;
- pSfOMXComponent->pOMXComponent->SendCommand = &SF_OMX_SendCommand;
- pSfOMXComponent->pOMXComponent->GetState = &SF_OMX_GetState;
- pSfOMXComponent->pOMXComponent->GetComponentVersion = &SF_OMX_GetComponentVersion;
- pSfOMXComponent->pOMXComponent->UseEGLImage = &SF_OMX_UseEGLImage;
- // pSfOMXComponent->pOMXComponent->GetExtensionIndex = &SF_OMX_GetExtensionIndex;
- // pSfOMXComponent->pOMXComponent->ComponentRoleEnum = &SF_OMX_ComponentRoleEnum;
- // pSfOMXComponent->pOMXComponent->ComponentDeInit = &SF_OMX_ComponentDeInit;
- for (int i = 0; i < MAX_INDEX; i++)
- {
- pSfVideoImplement->frame_array[i] = -1;
- }
- pSfVideoImplement->frame_array_index = 0;
- pSfVideoImplement->fpsCnt = 0;
- pSfVideoImplement->initTimeStamp = 0;
- pSfVideoImplement->CmdQueue = SF_Queue_Create(20, sizeof(DEC_CMD));
- if (NULL == pSfVideoImplement->CmdQueue)
- {
- LOG(SF_LOG_ERR, "create CmdQueue error");
- nInstance--;
- return OMX_ErrorInsufficientResources;
- }
- pSfVideoImplement->inPauseQ = SF_Queue_Create(20, sizeof(OMX_BUFFERHEADERTYPE*));
- if (NULL == pSfVideoImplement->inPauseQ)
- {
- LOG(SF_LOG_ERR, "create inPauseQ error");
- nInstance--;
- return OMX_ErrorInsufficientResources;
- }
- pSfVideoImplement->outPauseQ = SF_Queue_Create(20, sizeof(OMX_BUFFERHEADERTYPE*));
- if (NULL == pSfVideoImplement->outPauseQ)
- {
- LOG(SF_LOG_ERR, "create outPauseQ error");
- nInstance--;
- return OMX_ErrorInsufficientResources;
- }
- pSfVideoImplement->inPortQ = SF_Queue_Create(20, sizeof(OMX_BUFFERHEADERTYPE*));
- if (NULL == pSfVideoImplement->inPortQ)
- {
- LOG(SF_LOG_ERR, "create inPortQ error");
- nInstance--;
- return OMX_ErrorInsufficientResources;
- }
- pSfVideoImplement->outPortQ = SF_Queue_Create(20, sizeof(OMX_BUFFERHEADERTYPE*));
- if (NULL == pSfVideoImplement->outPortQ)
- {
- LOG(SF_LOG_ERR, "create outPortQ error");
- nInstance--;
- return OMX_ErrorInsufficientResources;
- }
- CreateThread(&pSfVideoImplement->pCmdThread, CmdThread, (void *)pSfOMXComponent);
- pSfVideoImplement->bCmdRunning = OMX_TRUE;
- EXIT:
- FunctionOut();
- return ret;
- }
- static OMX_ERRORTYPE SF_OMX_ComponentClear(SF_OMX_COMPONENT *pSfOMXComponent)
- {
- OMX_ERRORTYPE ret = OMX_ErrorNone;
- DEC_CMD cmd;
- void *ThreadRet = NULL;
- SF_WAVE5_IMPLEMEMT *pSfVideoImplement = (SF_WAVE5_IMPLEMEMT *)pSfOMXComponent->componentImpl;
- ComponentImpl *pSFComponentDecoder = (ComponentImpl *)pSfVideoImplement->hSFComponentExecoder;
- ComponentImpl *pSFComponentFeeder = (ComponentImpl *)pSfVideoImplement->hSFComponentFeeder;
- ComponentImpl *pSFComponentRender = (ComponentImpl *)pSfVideoImplement->hSFComponentRender;
- FunctionIn();
- if (pSFComponentFeeder)
- {
- pSFComponentFeeder->terminate = OMX_TRUE;
- pSfVideoImplement->functions->ComponentWait(pSfVideoImplement->hSFComponentFeeder);
- }
- if (pSFComponentDecoder)
- {
- pSFComponentDecoder->terminate = OMX_TRUE;
- pSfVideoImplement->functions->ComponentWait(pSfVideoImplement->hSFComponentExecoder);
- }
- if (pSFComponentRender)
- {
- pSFComponentRender->terminate = OMX_TRUE;
- pSfVideoImplement->functions->ComponentWait(pSfVideoImplement->hSFComponentRender);
- }
- pSfVideoImplement->bCmdRunning = 0;
- /* enqueue DEC_StopThread mean cmd thread cycle end */
- cmd.Cmd = DEC_StopThread;
- SF_Queue_Enqueue(pSfVideoImplement->CmdQueue, &cmd);
- pthread_join(pSfVideoImplement->pCmdThread->pthread, &ThreadRet);
- LOG(SF_LOG_INFO, "Cmd thread end %ld\r\n", (Uint64)ThreadRet);
- SF_Queue_Destroy(pSfVideoImplement->CmdQueue);
- SF_Queue_Destroy(pSfVideoImplement->outPauseQ);
- SF_Queue_Destroy(pSfVideoImplement->inPauseQ);
- SF_Queue_Destroy(pSfVideoImplement->inPortQ);
- SF_Queue_Destroy(pSfVideoImplement->outPortQ);
- free(pSfVideoImplement->pusBitCode);
- pSfVideoImplement->functions->ClearDecListenerContext(pSfVideoImplement->lsnCtx);
- ComponentClearCommon(pSfOMXComponent);
- nInstance--;
- FunctionOut();
- return ret;
- }
- SF_OMX_COMPONENT sf_dec_decoder_h265 = {
- .componentName = "OMX.sf.video_decoder.hevc",
- .libName = "libsfdec.so",
- .pOMXComponent = NULL,
- .SF_OMX_ComponentConstructor = SF_OMX_ComponentConstructor,
- .SF_OMX_ComponentClear = SF_OMX_ComponentClear,
- // .functions = NULL,
- // .bitFormat = STD_HEVC,
- .componentImpl = NULL,
- .fwPath = "/lib/firmware/chagall.bin",
- .componentRule = "video_decoder.hevc"};
- SF_OMX_COMPONENT sf_dec_decoder_h264 = {
- .componentName = "OMX.sf.video_decoder.avc",
- .libName = "libsfdec.so",
- .pOMXComponent = NULL,
- .SF_OMX_ComponentConstructor = SF_OMX_ComponentConstructor,
- .SF_OMX_ComponentClear = SF_OMX_ComponentClear,
- // .functions = NULL,
- // .bitFormat = STD_AVC,
- .componentImpl = NULL,
- .fwPath = "/lib/firmware/chagall.bin",
- .componentRule = "video_decoder.avc"};
|