SF_OMX_Core.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2021 StarFive Technology Co., Ltd.
  4. */
  5. #ifndef OMX__CORE
  6. #define OMX__CORE
  7. #include <semaphore.h>
  8. #include "OMX_Types.h"
  9. #include "OMX_Core.h"
  10. #include "OMX_Component.h"
  11. #include "component.h"
  12. #include "encoder_listener.h"
  13. #include "decoder_listener.h"
  14. #include <sys/time.h>
  15. #include <stdarg.h>
  16. #include <dlfcn.h>
  17. #include <string.h>
  18. #define ENABLE_DEBUG
  19. #ifdef ENABLE_DEBUG
  20. enum
  21. {
  22. SF_LOG_ERR = 0,
  23. SF_LOG_WARN,
  24. SF_LOG_PERF,
  25. SF_LOG_INFO,
  26. SF_LOG_DEBUG,
  27. SF_LOG_ALL,
  28. };
  29. void SF_LogMsg(int level, const char *function, int line, const char *format, ...);
  30. #define LOG(level, ...) SF_LogMsg(level, __FUNCTION__, __LINE__, __VA_ARGS__);
  31. #define FunctionIn() SF_LogMsg(SF_LOG_DEBUG, __FUNCTION__, __LINE__, "FUN IN\r\n");
  32. #define FunctionOut() SF_LogMsg(SF_LOG_DEBUG, __FUNCTION__, __LINE__, "FUN OUT\r\n");
  33. #else
  34. #define FunctionIn()
  35. #define FunctionOut()
  36. #endif
  37. typedef struct _SF_COMPONENT_FUNCTIONS
  38. {
  39. Component (*ComponentCreate)(const char *componentName, CNMComponentConfig *componentParam);
  40. BOOL(*ComponentSetupTunnel)(Component fromComponent, Component toComponent);
  41. ComponentState (*ComponentExecute)(Component component);
  42. Int32 (*ComponentWait)(Component component);
  43. void (*ComponentStop)(Component component);
  44. void (*ComponentRelease)(Component component);
  45. BOOL(*ComponentChangeState)(Component component, Uint32 state);
  46. BOOL(*ComponentDestroy)(Component component, BOOL *ret);
  47. CNMComponentParamRet (*ComponentGetParameter)(Component from, Component to, GetParameterCMD commandType, void *data);
  48. CNMComponentParamRet (*ComponentSetParameter)(Component from, Component to, SetParameterCMD commandType, void *data);
  49. void (*ComponentNotifyListeners)(Component component, Uint64 event, void *data);
  50. BOOL(*ComponentRegisterListener)(Component component, Uint64 events, ComponentListenerFunc func, void *context);
  51. void (*ComponentPortCreate)(Port *port, Component owner, Uint32 depth, Uint32 size);
  52. void (*ComponentPortSetData)(Port *port, PortContainer *portData);
  53. PortContainer *(*ComponentPortPeekData)(Port *port);
  54. PortContainer *(*ComponentPortGetData)(Port *port);
  55. void *(*WaitBeforeComponentPortGetData)(Port *port);
  56. void (*ComponentPortWaitReadyStatus)(Port *port);
  57. void (*ComponentPortDestroy)(Port *port);
  58. BOOL(*ComponentPortHasInputData)(Port *port);
  59. Uint32 (*ComponentPortGetSize)(Port *port);
  60. void (*ComponentPortFlush)(Component component);
  61. ComponentState (*ComponentGetState)(Component component);
  62. BOOL(*ComponentParamReturnTest)(CNMComponentParamRet ret, BOOL *retry);
  63. // Listener
  64. BOOL(*SetupDecListenerContext)(DecListenerContext *ctx, CNMComponentConfig *config, Component renderer);
  65. BOOL(*SetupEncListenerContext)(EncListenerContext *ctx, CNMComponentConfig *config);
  66. void (*ClearDecListenerContext)(DecListenerContext *ctx);
  67. void (*HandleDecCompleteSeqEvent)(Component com, CNMComListenerDecCompleteSeq *param, DecListenerContext *ctx);
  68. void (*HandleDecRegisterFbEvent)(Component com, CNMComListenerDecRegisterFb *param, DecListenerContext *ctx);
  69. void (*HandleDecGetOutputEvent)(Component com, CNMComListenerDecDone *param, DecListenerContext *ctx);
  70. void (*HandleDecCloseEvent)(Component com, CNMComListenerDecClose *param, DecListenerContext *ctx);
  71. void (*ClearEncListenerContext)(EncListenerContext *ctx);
  72. void (*HandleEncFullEvent)(Component com, CNMComListenerEncFull *param, EncListenerContext *ctx);
  73. void (*HandleEncGetOutputEvent)(Component com, CNMComListenerEncDone *param, EncListenerContext *ctx);
  74. void (*HandleEncCompleteSeqEvent)(Component com, CNMComListenerEncCompleteSeq *param, EncListenerContext *ctx);
  75. void (*HandleEncGetEncCloseEvent)(Component com, CNMComListenerEncClose *param, EncListenerContext *ctx);
  76. void (*EncoderListener)(Component com, Uint64 event, void *data, void *context);
  77. void (*DecoderListener)(Component com, Uint64 event, void *data, void *context);
  78. // Helper
  79. void (*SetDefaultEncTestConfig)(TestEncConfig *testConfig);
  80. void (*SetDefaultDecTestConfig)(TestDecConfig *testConfig);
  81. Int32 (*LoadFirmware)(Int32 productId, Uint8 **retFirmware, Uint32 *retSizeInWord, const char *path);
  82. BOOL(*SetupEncoderOpenParam)(EncOpenParam *param, TestEncConfig *config, ENC_CFG *encCfg);
  83. RetCode (*SetUpDecoderOpenParam)(DecOpenParam *param, TestDecConfig *config);
  84. // VPU
  85. int (*VPU_GetProductId)(int coreIdx);
  86. BOOL(*Queue_Enqueue)(Queue *queue, void *data);
  87. Uint32 (*Queue_Get_Cnt)(Queue *queue);
  88. // VPU Log
  89. int (*InitLog)(void);
  90. void (*DeInitLog)(void);
  91. void (*SetMaxLogLevel)(int level);
  92. int (*GetMaxLogLevel)(void);
  93. } SF_COMPONENT_FUNCTIONS;
  94. typedef struct _SF_OMX_COMPONENT
  95. {
  96. OMX_STRING componentName;
  97. OMX_STRING libName;
  98. OMX_COMPONENTTYPE *pOMXComponent;
  99. OMX_ERRORTYPE (*SF_OMX_ComponentConstructor)(struct _SF_OMX_COMPONENT *hComponent);
  100. OMX_ERRORTYPE (*SF_OMX_ComponentClear)(struct _SF_OMX_COMPONENT *hComponent);
  101. SF_COMPONENT_FUNCTIONS *functions;
  102. Component *hSFComponentExecoder;
  103. Component *hSFComponentFeeder;
  104. Component *hSFComponentRender;
  105. void *testConfig;
  106. CNMComponentConfig *config;
  107. void *lsnCtx;
  108. OMX_PTR soHandle;
  109. Uint16 *pusBitCode;
  110. OMX_CALLBACKTYPE *callbacks;
  111. OMX_PTR pAppData;
  112. OMX_PARAM_PORTDEFINITIONTYPE portDefinition[2];
  113. OMX_BUFFERHEADERTYPE *pBufferArray[64];
  114. sem_t *inputSemaphore;
  115. CodStd bitFormat;
  116. OMX_STRING fwPath;
  117. } SF_OMX_COMPONENT;
  118. #define PRINT_STUCT(a, b) \
  119. do \
  120. { \
  121. printf("size = %d\r\n", sizeof(b)); \
  122. for (int i = 0; i < sizeof(b); i += sizeof(void *)) \
  123. { \
  124. for (int j = 0; j < sizeof(void *); j++) \
  125. { \
  126. printf("%02X ", *((char *)a + i + j)); \
  127. } \
  128. for (int j = 0; j < sizeof(void *); j++) \
  129. { \
  130. printf("%c", *((char *)a + i + j)); \
  131. } \
  132. printf("\r\n"); \
  133. } \
  134. } while (0)
  135. #ifdef __cplusplus
  136. extern "C"
  137. {
  138. #endif
  139. void sf_get_component_functions(SF_COMPONENT_FUNCTIONS *funcs, OMX_PTR *sohandle);
  140. SF_OMX_COMPONENT *GetSFOMXComponrntByComponent(Component *pComponent);
  141. OMX_BUFFERHEADERTYPE *GetOMXBufferByAddr(SF_OMX_COMPONENT *pSfOMXComponent, OMX_U8 *pAddr);
  142. OMX_ERRORTYPE StoreOMXBuffer(SF_OMX_COMPONENT *pSfOMXComponent, OMX_BUFFERHEADERTYPE *pBuffer);
  143. OMX_ERRORTYPE ClearOMXBuffer(SF_OMX_COMPONENT *pSfOMXComponent, OMX_BUFFERHEADERTYPE *pBuffer);
  144. OMX_U32 GetOMXBufferCount(SF_OMX_COMPONENT *pSfOMXComponent);
  145. #ifdef __cplusplus
  146. }
  147. #endif
  148. #endif