123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- // SPDX-License-Identifier: GPL-2.0
- /*
- * Copyright (C) 2021 StarFive Technology Co., Ltd.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdlib.h>
- #include "SF_OMX_Core.h"
- static int gInitialized = 0;
- OMX_TICKS gInitTimeStamp = 0;
- int gDebugLevel = SF_LOG_ERR;
- extern SF_OMX_COMPONENT sf_dec_decoder_h265;
- extern SF_OMX_COMPONENT sf_dec_decoder_h264;
- extern SF_OMX_COMPONENT sf_enc_encoder_h265;
- extern SF_OMX_COMPONENT sf_enc_encoder_h264;
- extern SF_OMX_COMPONENT sf_dec_decoder_mjpeg;
- SF_OMX_COMPONENT *sf_omx_component_list[] = {
- &sf_dec_decoder_h265,
- &sf_dec_decoder_h264,
- &sf_enc_encoder_h265,
- &sf_enc_encoder_h264,
- &sf_dec_decoder_mjpeg,
- NULL,
- };
- #define SF_OMX_COMPONENT_NUM ((sizeof(sf_omx_component_list) / sizeof(SF_OMX_COMPONENT *)) - 1)
- int GetNumberOfComponent()
- {
- return sizeof(sf_omx_component_list) / sizeof(SF_OMX_COMPONENT *);
- }
- OMX_ERRORTYPE SF_OMX_ComponentLoad(SF_OMX_COMPONENT *sf_component)
- {
- OMX_ERRORTYPE ret = OMX_ErrorNone;
- FunctionIn();
- sf_component->SF_OMX_ComponentConstructor(sf_component);
- FunctionOut();
- return ret;
- }
- OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_Init(void)
- {
- OMX_ERRORTYPE ret = OMX_ErrorNone;
- char *debugLevel = NULL;
- FunctionIn();
- if (gInitialized == 0)
- {
- gInitialized = 1;
- }
- debugLevel = getenv("OMX_DEBUG");
- if (debugLevel != NULL)
- {
- gDebugLevel = atoi(debugLevel);
- }
- FunctionOut();
- return ret;
- }
- OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_Deinit(void)
- {
- OMX_ERRORTYPE ret = OMX_ErrorNone;
- FunctionIn();
- FunctionOut();
- return ret;
- }
- OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_ComponentNameEnum(
- OMX_OUT OMX_STRING cComponentName,
- OMX_IN OMX_U32 nNameLength,
- OMX_IN OMX_U32 nIndex)
- {
- OMX_ERRORTYPE ret = OMX_ErrorNone;
- FunctionIn();
- if (nIndex >= SF_OMX_COMPONENT_NUM)
- {
- ret = OMX_ErrorNoMore;
- goto EXIT;
- }
- snprintf(cComponentName, nNameLength, "%s", sf_omx_component_list[nIndex]->componentName);
- EXIT:
- FunctionOut();
- return ret;
- }
- OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_GetHandle(
- OMX_OUT OMX_HANDLETYPE *pHandle,
- OMX_IN OMX_STRING cComponentName,
- OMX_IN OMX_PTR pAppData,
- OMX_IN OMX_CALLBACKTYPE *pCallBacks)
- {
- OMX_ERRORTYPE ret = OMX_ErrorNone;
- unsigned int i = 0;
- SF_OMX_COMPONENT *pSf_omx_component = NULL;
- FunctionIn();
- if (gInitialized != 1)
- {
- ret = OMX_ErrorNotReady;
- goto EXIT;
- }
- if ((pHandle == NULL) || (cComponentName == NULL))
- {
- ret = OMX_ErrorBadParameter;
- goto EXIT;
- }
- for (i = 0; i < SF_OMX_COMPONENT_NUM; i++)
- {
- pSf_omx_component = sf_omx_component_list[i];
- if (pSf_omx_component == NULL)
- {
- ret = OMX_ErrorBadParameter;
- goto EXIT;
- }
- if (strcmp(cComponentName, pSf_omx_component->componentName) == 0)
- {
- ret = pSf_omx_component->SF_OMX_ComponentConstructor(pSf_omx_component);
- if (ret != OMX_ErrorNone)
- {
- goto EXIT;
- }
- *pHandle = pSf_omx_component->pOMXComponent;
- pSf_omx_component->callbacks = pCallBacks;
- pSf_omx_component->pAppData = pAppData;
- break;
- }
- }
- EXIT:
- FunctionOut();
- return ret;
- }
- OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_FreeHandle(OMX_IN OMX_HANDLETYPE hComponent)
- {
- OMX_ERRORTYPE ret = OMX_ErrorNone;
- OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent;
- SF_OMX_COMPONENT *pSfOMXComponent = (SF_OMX_COMPONENT *)pOMXComponent->pComponentPrivate;
- FunctionIn();
- ret = pSfOMXComponent->SF_OMX_ComponentClear(pSfOMXComponent);
- FunctionOut();
- return ret;
- }
- OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_SetupTunnel(
- OMX_IN OMX_HANDLETYPE hOutput,
- OMX_IN OMX_U32 nPortOutput,
- OMX_IN OMX_HANDLETYPE hInput,
- OMX_IN OMX_U32 nPortInput)
- {
- OMX_ERRORTYPE ret = OMX_ErrorNone;
- // OMX_COMPONENTTYPE *pOMXComponent_hOutput = (OMX_COMPONENTTYPE *)hOutput;
- // OMX_COMPONENTTYPE *pOMXComponent_hInput = (OMX_COMPONENTTYPE *)hInput;
- FunctionIn();
- ret = OMX_ErrorNotImplemented;
- FunctionOut();
- return ret;
- }
- OMX_API OMX_ERRORTYPE OMX_GetContentPipe(
- OMX_OUT OMX_HANDLETYPE *hPipe,
- OMX_IN OMX_STRING szURI)
- {
- OMX_ERRORTYPE ret = OMX_ErrorNone;
- FunctionIn();
- FunctionOut();
- return ret;
- }
- OMX_API OMX_ERRORTYPE OMX_GetComponentsOfRole(
- OMX_IN OMX_STRING role,
- OMX_INOUT OMX_U32 *pNumComps,
- OMX_INOUT OMX_U8 **compNames)
- {
- OMX_ERRORTYPE ret = OMX_ErrorNone;
- FunctionIn();
- LOG(SF_LOG_INFO, "Role = %s\r\n", role);
- *pNumComps = 0;
- for (int i = 0; i < SF_OMX_COMPONENT_NUM; i ++)
- {
- if (sf_omx_component_list[i] == NULL)
- {
- break;
- }
- if (strcmp(sf_omx_component_list[i]->componentRule, role) == 0)
- {
- if (compNames != NULL) {
- strcpy((OMX_STRING)compNames[*pNumComps], sf_omx_component_list[i]->componentName);
- }
- *pNumComps = (*pNumComps + 1);
- LOG(SF_LOG_INFO,"Get component %s, Role = %s\r\n", sf_omx_component_list[i]->componentName, sf_omx_component_list[i]->componentRule)
- }
- }
- FunctionOut();
- return ret;
- }
- OMX_API OMX_ERRORTYPE OMX_GetRolesOfComponent(
- OMX_IN OMX_STRING compName,
- OMX_INOUT OMX_U32 *pNumRoles,
- OMX_OUT OMX_U8 **roles)
- {
- OMX_ERRORTYPE ret = OMX_ErrorNone;
- FunctionIn();
- FunctionOut();
- return ret;
- }
- void SF_LogMsgAppend(int level, const char *format, ...)
- {
- va_list ptr;
- if (level > gDebugLevel)
- {
- return;
- }
-
- printf("%66s\t", " ");
- va_start(ptr, format);
- vprintf(format, ptr);
- va_end(ptr);
- }
- void SF_LogMsg(int level, const char *function, int line, const char *format, ...)
- {
- char *prefix = "";
- va_list ptr;
- struct timeval tv;
- if (level > gDebugLevel)
- {
- return;
- }
- switch (level)
- {
- case SF_LOG_ERR:
- prefix = "[ERROR]";
- break;
- case SF_LOG_WARN:
- prefix = "[WARN ]";
- break;
- case SF_LOG_PERF:
- prefix = "[PERF ]";
- break;
- case SF_LOG_INFO:
- prefix = "[INFO ]";
- break;
- case SF_LOG_DEBUG:
- prefix = "[DEBUG]";
- break;
- default:
- break;
- }
- gettimeofday(&tv, NULL);
- printf("[%06ld:%06ld]%10s%32s%10d\t", tv.tv_sec, tv.tv_usec, prefix, function, line);
- va_start(ptr, format);
- vprintf(format, ptr);
- va_end(ptr);
- }
|