SF_OMX_Core.h 7.8 KB

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