SF_OMX_video_common.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2021 StarFive Technology Co., Ltd.
  4. */
  5. #ifndef SF_OMX_VIDEO_COMMON
  6. #define SF_OMX_VIDEO_COMMON
  7. #include "OMX_Component.h"
  8. #include "OMX_Video.h"
  9. #include "OMX_VideoExt.h"
  10. #include "OMX_Index.h"
  11. #include "OMX_IndexExt.h"
  12. #include "SF_OMX_Core.h"
  13. #include "sf_queue.h"
  14. #include "sf_thread.h"
  15. #include "sf_semaphore.h"
  16. #include "wave511/sample_v2/component/component.h"
  17. #include "wave511/sample_v2/component_encoder/encoder_listener.h"
  18. #include "wave511/sample_v2/component_decoder/decoder_listener.h"
  19. #define INIT_SET_SIZE_VERSION(_struct_, _structType_) \
  20. do \
  21. { \
  22. memset((_struct_), 0, sizeof(_structType_)); \
  23. (_struct_)->nSize = sizeof(_structType_); \
  24. (_struct_)->nVersion.s.nVersionMajor = 1; \
  25. (_struct_)->nVersion.s.nVersionMinor = 18; \
  26. (_struct_)->nVersion.s.nRevision = 1; \
  27. (_struct_)->nVersion.s.nStep = 0; \
  28. } while (0)
  29. #define DEFAULT_FRAME_WIDTH 3840
  30. #define DEFAULT_FRAME_HEIGHT 2160
  31. #define DEFAULT_VIDEO_INPUT_BUFFER_SIZE (DEFAULT_FRAME_WIDTH * DEFAULT_FRAME_HEIGHT) / 2
  32. #define DEFAULT_VIDEO_OUTPUT_BUFFER_SIZE (DEFAULT_FRAME_WIDTH * DEFAULT_FRAME_HEIGHT * 3) / 2
  33. #define MAX_INDEX 1
  34. typedef struct _SF_COMPONENT_FUNCTIONS
  35. {
  36. Component (*ComponentCreate)(const char *componentName, CNMComponentConfig *componentParam);
  37. BOOL(*ComponentSetupTunnel)(Component fromComponent, Component toComponent);
  38. ComponentState (*ComponentExecute)(Component component);
  39. Int32 (*ComponentWait)(Component component);
  40. void (*ComponentStop)(Component component);
  41. void (*ComponentRelease)(Component component);
  42. BOOL(*ComponentChangeState)(Component component, Uint32 state);
  43. BOOL(*ComponentDestroy)(Component component, BOOL *ret);
  44. CNMComponentParamRet (*ComponentGetParameter)(Component from, Component to, GetParameterCMD commandType, void *data);
  45. CNMComponentParamRet (*ComponentSetParameter)(Component from, Component to, SetParameterCMD commandType, void *data);
  46. void (*ComponentNotifyListeners)(Component component, Uint64 event, void *data);
  47. BOOL(*ComponentRegisterListener)(Component component, Uint64 events, ComponentListenerFunc func, void *context);
  48. void (*ComponentPortCreate)(Port *port, Component owner, Uint32 depth, Uint32 size);
  49. void (*ComponentPortSetData)(Port *port, PortContainer *portData);
  50. PortContainer *(*ComponentPortPeekData)(Port *port);
  51. PortContainer *(*ComponentPortGetData)(Port *port);
  52. void *(*WaitBeforeComponentPortGetData)(Port *port);
  53. void (*ComponentPortWaitReadyStatus)(Port *port);
  54. void (*ComponentPortDestroy)(Port *port);
  55. BOOL(*ComponentPortHasInputData)(Port *port);
  56. Uint32 (*ComponentPortGetSize)(Port *port);
  57. void (*ComponentPortFlush)(Component component);
  58. ComponentState (*ComponentGetState)(Component component);
  59. BOOL(*ComponentParamReturnTest)(CNMComponentParamRet ret, BOOL *retry);
  60. // Listener
  61. BOOL(*SetupDecListenerContext)(DecListenerContext *ctx, CNMComponentConfig *config, Component renderer);
  62. BOOL(*SetupEncListenerContext)(EncListenerContext *ctx, CNMComponentConfig *config);
  63. void (*ClearDecListenerContext)(DecListenerContext *ctx);
  64. void (*HandleDecCompleteSeqEvent)(Component com, CNMComListenerDecCompleteSeq *param, DecListenerContext *ctx);
  65. void (*HandleDecRegisterFbEvent)(Component com, CNMComListenerDecRegisterFb *param, DecListenerContext *ctx);
  66. void (*HandleDecGetOutputEvent)(Component com, CNMComListenerDecDone *param, DecListenerContext *ctx);
  67. void (*HandleDecCloseEvent)(Component com, CNMComListenerDecClose *param, DecListenerContext *ctx);
  68. void (*ClearEncListenerContext)(EncListenerContext *ctx);
  69. void (*HandleEncFullEvent)(Component com, CNMComListenerEncFull *param, EncListenerContext *ctx);
  70. void (*HandleEncGetOutputEvent)(Component com, CNMComListenerEncDone *param, EncListenerContext *ctx);
  71. void (*HandleEncCompleteSeqEvent)(Component com, CNMComListenerEncCompleteSeq *param, EncListenerContext *ctx);
  72. void (*HandleEncGetEncCloseEvent)(Component com, CNMComListenerEncClose *param, EncListenerContext *ctx);
  73. void (*EncoderListener)(Component com, Uint64 event, void *data, void *context);
  74. void (*DecoderListener)(Component com, Uint64 event, void *data, void *context);
  75. // Helper
  76. void (*SetDefaultEncTestConfig)(TestEncConfig *testConfig);
  77. void (*SetDefaultDecTestConfig)(TestDecConfig *testConfig);
  78. Int32 (*LoadFirmware)(Int32 productId, Uint8 **retFirmware, Uint32 *retSizeInWord, const char *path);
  79. BOOL(*SetupEncoderOpenParam)(EncOpenParam *param, TestEncConfig *config, ENC_CFG *encCfg);
  80. RetCode (*SetUpDecoderOpenParam)(DecOpenParam *param, TestDecConfig *config);
  81. // VPU
  82. int (*VPU_GetProductId)(int coreIdx);
  83. BOOL(*Queue_Enqueue)(Queue *queue, void *data);
  84. Uint32 (*Queue_Get_Cnt)(Queue *queue);
  85. RetCode (*VPU_DecClrDispFlag)(DecHandle handle, int index);
  86. RetCode (*VPU_DecGetFrameBuffer)(DecHandle handle, int frameIdx, FrameBuffer* frameBuf);
  87. void (*Render_DecClrDispFlag)(void *context, int index);
  88. // VPU Log
  89. int (*InitLog)(void);
  90. void (*DeInitLog)(void);
  91. void (*SetMaxLogLevel)(int level);
  92. int (*GetMaxLogLevel)(void);
  93. // FrameBuffer
  94. void* (*AllocateFrameBuffer2)(ComponentImpl* com, Uint32 size);
  95. BOOL (*AttachDMABuffer)(ComponentImpl* com, Uint64 virtAddress, Uint32 size);
  96. void (*SetRenderTotalBufferNumber)(ComponentImpl* com, Uint32 number);
  97. void (*SetFeederTotalBufferNumber)(ComponentImpl* com, Uint32 number);
  98. void (*WaitForExecoderReady)(ComponentImpl *com);
  99. } SF_COMPONENT_FUNCTIONS;
  100. typedef struct _SF_WAVE5_IMPLEMEMT
  101. {
  102. SF_COMPONENT_FUNCTIONS *functions;
  103. Component *hSFComponentExecoder;
  104. Component *hSFComponentFeeder;
  105. Component *hSFComponentRender;
  106. void *testConfig;
  107. CNMComponentConfig *config;
  108. void *lsnCtx;
  109. Uint16 *pusBitCode;
  110. CodStd bitFormat;
  111. OMX_BOOL rev_eos;
  112. SF_Queue *CmdQueue;
  113. SF_Queue *pauseQ;
  114. THREAD_HANDLE_TYPE *pCmdThread;
  115. OMX_BOOL bCmdRunning;
  116. OMX_U64 frame_array[MAX_INDEX];
  117. OMX_U32 frame_array_index;
  118. OMX_VIDEO_PARAM_AVCTYPE AVCComponent[2];
  119. OMX_VIDEO_PARAM_HEVCTYPE HEVCComponent[2];
  120. }SF_WAVE5_IMPLEMEMT;
  121. #ifdef __cplusplus
  122. extern "C"
  123. {
  124. #endif
  125. BOOL CheckEncTestConfig(TestEncConfig *testConfig);
  126. BOOL CheckDecTestConfig(TestDecConfig *testConfig);
  127. OMX_ERRORTYPE GetStateCommon(OMX_IN OMX_HANDLETYPE hComponent, OMX_OUT OMX_STATETYPE *pState);
  128. OMX_ERRORTYPE InitComponentStructorCommon(SF_OMX_COMPONENT *hComponent);
  129. OMX_ERRORTYPE ComponentClearCommon(SF_OMX_COMPONENT *hComponent);
  130. OMX_ERRORTYPE FlushBuffer(SF_OMX_COMPONENT *pSfOMXComponent, OMX_U32 nPort);
  131. SF_OMX_COMPONENT *GetSFOMXComponrntByComponent(Component *pComponent);
  132. #ifdef __cplusplus
  133. }
  134. #endif
  135. #endif