SF_OMX_Wave420L_encoder.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2022 StarFive Technology Co., Ltd.
  4. */
  5. #ifndef SF_OMX_WAVE4_ENC
  6. #define SF_OMX_WAVE4_ENC
  7. #include "OMX_Component.h"
  8. #include "OMX_Video.h"
  9. #include "OMX_Index.h"
  10. #include "OMX_IndexExt.h"
  11. #include "SF_OMX_Core.h"
  12. #include <sys/queue.h>
  13. #include <sys/ipc.h>
  14. #include <sys/msg.h>
  15. #include <pthread.h>
  16. #include <errno.h>
  17. #include "sf_queue.h"
  18. #include "sf_thread.h"
  19. #include "sf_semaphore.h"
  20. #include "wave420l/sample/helper/main_helper.h"
  21. #include "wave420l/vpuapi/vpuapi.h"
  22. #define INIT_SET_SIZE_VERSION(_struct_, _structType_) \
  23. do \
  24. { \
  25. memset((_struct_), 0, sizeof(_structType_)); \
  26. (_struct_)->nSize = sizeof(_structType_); \
  27. (_struct_)->nVersion.s.nVersionMajor = 1; \
  28. (_struct_)->nVersion.s.nVersionMinor = 18; \
  29. (_struct_)->nVersion.s.nRevision = 1; \
  30. (_struct_)->nVersion.s.nStep = 0; \
  31. } while (0)
  32. #define NUM_OF_PORTS 2
  33. #define DEFAULT_FRAME_WIDTH 1920
  34. #define DEFAULT_FRAME_HEIGHT 1080
  35. #define DEFAULT_MJPEG_INPUT_BUFFER_SIZE (DEFAULT_FRAME_WIDTH * DEFAULT_FRAME_HEIGHT * 3)
  36. #define DEFAULT_MJPEG_OUTPUT_BUFFER_SIZE (DEFAULT_FRAME_WIDTH * DEFAULT_FRAME_HEIGHT * 3)
  37. #define DEFAULT_FRAMERATE 30
  38. #define DEFAULT_GOP 30
  39. #define DEFAULT_FRAME_FORMAT FORMAT_420
  40. #define WAVE_DEFAULT_INPUT_BUF_NUMBER 8
  41. #define WAVE_DEFAULT_OUTPUT_BUF_NUMBER 8
  42. #define DEFAULT_BS_BUFF 1
  43. typedef struct _SF_W420L_FUNCTIONS
  44. {
  45. Int32 (*VPU_GetProductId)(Int32 coreIdx);
  46. RetCode (*VPU_GetVersionInfo)(Uint32 coreIdx, Uint32 *versionInfo, Uint32 *revision, Uint32 *productId);
  47. RetCode (*VPU_InitWithBitcode)(Uint32 coreIdx, const Uint16* code, Uint32 size);
  48. RetCode (*VPU_DeInit)(Uint32 coreIdx);
  49. Int32 (*GetEncOpenParam)(EncOpenParam *pEncOP, TestEncConfig *pEncConfig, ENC_CFG *pEncCfg);
  50. Int32 (*GetEncOpenParamDefault)(EncOpenParam *pEncOP, TestEncConfig *pEncConfig);
  51. RetCode (*VPU_EncOpen)(EncHandle* pHandle, EncOpenParam * pop);
  52. RetCode (*VPU_EncClose)(EncHandle handle);
  53. Int32 (*VPU_GetFrameBufSize)(Int32 coreIdx, Int32 stride, Int32 height, Int32 mapType, Int32 format, Int32 interleave, DRAMConfig *pDramCfg);
  54. RetCode (*VPU_EncRegisterFrameBuffer)(EncHandle handle, FrameBuffer* bufArray, Int32 num, Int32 stride, Int32 height, Int32 mapType);
  55. RetCode (*VPU_EncAllocateFrameBuffer)(EncHandle handle, FrameBufferAllocInfo info, FrameBuffer *frameBuffer);
  56. RetCode (*VPU_EncGiveCommand)(EncHandle handle, CodecCommand cmd, void* param);
  57. RetCode (*VPU_EncGetInitialInfo)(EncHandle handle, EncInitialInfo * info);
  58. RetCode (*VPU_SWReset)(Uint32 coreIdx, SWResetMode resetMode, void *pendingInst);
  59. RetCode (*VPU_EncStartOneFrame)(EncHandle handle, EncParam * param);
  60. Int32 (*VPU_WaitInterrupt)(Uint32 coreIdx, Int32 timeout);
  61. void (*VPU_ClearInterrupt)(Uint32 coreIdx);
  62. RetCode (*VPU_EncGetOutputInfo)(EncHandle handle, EncOutputInfo* info);
  63. int (*vdi_allocate_dma_memory)(unsigned long core_idx, vpu_buffer_t *vb);
  64. void (*vdi_free_dma_memory)(unsigned long core_idx, vpu_buffer_t *vb);
  65. YuvFeeder (*YuvFeeder_Create)(Uint32 type, const char* srcFilePath, YuvInfo yuvInfo);
  66. BOOL (*YuvFeeder_Feed)(YuvFeeder feeder, Uint32 coreIdx, FrameBuffer* fb, size_t picWidth, size_t picHeight, void* arg);
  67. BOOL (*YuvFeeder_Destroy)(YuvFeeder feeder);
  68. BitstreamReader (*BufferStreamReader_Create)(Uint32 type, EndianMode endian, EncHandle* handle);
  69. BOOL (*BufferStreamReader_Act)(BitstreamReader reader, PhysicalAddress bitstreamBuffer, Uint32 bitstreamBufferSize, Uint32 streamReadSize, Uint8* pBuffer,Comparator comparator);
  70. BOOL (*BufferStreamReader_Destroy)(BitstreamReader reader);
  71. Comparator (*Comparator_Create)(Uint32 type, char* goldenPath, ...);
  72. BOOL (*Comparator_Destroy)(Comparator comp);
  73. BOOL (*Comparator_CheckEOF)(Comparator comp);
  74. void (*DisplayEncodedInformation)(EncHandle handle, CodStd codec, Uint32 frameNo, EncOutputInfo* encodedInfo, ...);
  75. void (*PrintVpuVersionInfo)(Uint32 core_idx);
  76. Int32 (*CalcStride)(Uint32 width, Uint32 height, FrameBufferFormat format, BOOL cbcrInterleave, TiledMapType mapType, BOOL isVP9);
  77. Int32 (*GetPackedFormat) (Int32 srcBitDepth, Int32 packedType, Int32 p10bits,Int32 msb);
  78. Int32 (*LoadFirmware)(Int32 productId, Uint8** retFirmware, Uint32* retSizeInWord, const char* path);
  79. void (*SetMaxLogLevel)(int level);
  80. RetCode (*EnterLock)(Uint32 coreIdx);
  81. RetCode (*LeaveLock)(Uint32 coreIdx);
  82. void (*PrintVpuStatus)(Uint32 coreIdx, Uint32 productId);
  83. }SF_W420L_FUNCTIONS;
  84. typedef struct Message
  85. {
  86. long msg_type;
  87. OMX_U32 msg_flag;
  88. OMX_BUFFERHEADERTYPE *pBuffer;
  89. } Message;
  90. typedef struct SF_OMX_CMD
  91. {
  92. OMX_COMMANDTYPE Cmd;
  93. OMX_U32 nParam;
  94. OMX_PTR pCmdData;
  95. }SF_OMX_CMD;
  96. enum port_index
  97. {
  98. OMX_INPUT_PORT_INDEX = 0,
  99. OMX_OUTPUT_PORT_INDEX = 1,
  100. OMX_PORT_MAX = 2,
  101. };
  102. typedef struct _SF_WAVE420L_IMPLEMEMT
  103. {
  104. EncHandle handle;
  105. SF_W420L_FUNCTIONS *functions;
  106. BSFeeder feeder;
  107. vpu_buffer_t vbSourceFrameBuf[ENC_SRC_BUF_NUM];
  108. vpu_buffer_t vbReconFrameBuf[MAX_REG_FRAME];
  109. vpu_buffer_t vbStream[MAX_REG_FRAME];
  110. FrameBuffer fbSrc[ENC_SRC_BUF_NUM];
  111. FrameBuffer fbRecon[MAX_REG_FRAME];
  112. Int32 regFrameBufCount;
  113. Int32 bsBufferCount;
  114. EncOpenParam encOP;
  115. TestEncConfig encConfig;
  116. EncInitialInfo initialInfo;
  117. EncOutputInfo outputInfo;
  118. Int32 instIdx;
  119. Int32 coreIdx;
  120. Uint32 tmpFramerate;
  121. Uint64 tmpCounter;
  122. SF_Queue *EmptyQueue;
  123. SF_Queue *FillQueue;
  124. SF_Queue *CmdQueue;
  125. SF_Queue *pauseQ;
  126. OMX_HANDLETYPE pauseSemaphore;
  127. OMX_VIDEO_PARAM_HEVCTYPE HEVCComponent[2];
  128. THREAD_HANDLE_TYPE *pProcessThread;
  129. THREAD_HANDLE_TYPE *pCmdThread;
  130. OMX_BOOL bThreadRunning;
  131. OMX_BOOL bCmdRunning;
  132. OMX_BOOL bPause;
  133. OMX_STATETYPE currentState;
  134. } SF_WAVE420L_IMPLEMEMT;
  135. /* Warper functions marco */
  136. #define Warp_VPU_GetProductId(Implement, coreIdx) \
  137. Implement->functions->VPU_GetProductId(coreIdx)
  138. #define Warp_VPU_GetVersionInfo(Implement, coreIdx, pVersionInfo, pRevision, pProductId) \
  139. Implement->functions->VPU_GetVersionInfo(coreIdx, pVersionInfo, pRevision, pProductId)
  140. #define Warp_VPU_InitWithBitcode(Implement, coreIdx, pCode, size) \
  141. Implement->functions->VPU_InitWithBitcode(coreIdx, pCode, size)
  142. #define Warp_VPU_DeInit(Implement, coreIdx) \
  143. Implement->functions->VPU_DeInit(coreIdx)
  144. #define Warp_GetEncOpenParam(Implement, pEncOP, pEncConfig, pEncCfg) \
  145. Implement->functions->GetEncOpenParam(pEncOP, pEncConfig, pEncCfg)
  146. #define Warp_GetEncOpenParamDefault(Implement, pEncOP, pEncConfig) \
  147. Implement->functions->GetEncOpenParamDefault(pEncOP, pEncConfig)
  148. #define Warp_VPU_EncOpen(Implement, pHandle, pop) \
  149. Implement->functions->VPU_EncOpen(pHandle, pop)
  150. #define Warp_VPU_EncClose(Implement, handle) \
  151. Implement->functions->VPU_EncClose(handle)
  152. #define Warp_VPU_GetFrameBufSize(Implement, coreIdx, stride, height, mapType, format, interleave, pDramCfg) \
  153. Implement->functions->VPU_GetFrameBufSize(coreIdx, stride, height, mapType, format, interleave, pDramCfg)
  154. #define Warp_VPU_EncRegisterFrameBuffer(Implement, handle, bufArray, num, stride, height, mapType)\
  155. Implement->functions->VPU_EncRegisterFrameBuffer(handle, bufArray, num, stride, height, mapType)
  156. #define Warp_VPU_EncAllocateFrameBuffer(Implement, handle, info, pframeBuffer) \
  157. Implement->functions->VPU_EncAllocateFrameBuffer(handle, info, pframeBuffer)
  158. #define Warp_VPU_EncGiveCommand(Implement, handle, cmd, param) \
  159. Implement->functions->VPU_EncGiveCommand(handle, cmd, param)
  160. #define Warp_VPU_EncGetInitialInfo(Implement, handle, pInfo) \
  161. Implement->functions->VPU_EncGetInitialInfo(handle, pInfo)
  162. #define Warp_VPU_SWReset(Implement, coreIdx, resetMode, pendingInst) \
  163. Implement->functions->VPU_SWReset(coreIdx, resetMode, pendingInst)
  164. #define Warp_VPU_EncStartOneFrame(Implement, handle, param) \
  165. Implement->functions->VPU_EncStartOneFrame(handle, param)
  166. #define Warp_VPU_WaitInterrupt(Implement, coreIdx, timeout) \
  167. Implement->functions->VPU_WaitInterrupt(coreIdx, timeout)
  168. #define Warp_VPU_ClearInterrupt(Implement, coreIdx) \
  169. Implement->functions->VPU_ClearInterrupt(coreIdx)
  170. #define Warp_VPU_EncGetOutputInfo(Implement, handle, info) \
  171. Implement->functions->VPU_EncGetOutputInfo(handle, info)
  172. #define Warp_vdi_allocate_dma_memory(Implement, core_idx, vb) \
  173. Implement->functions->vdi_allocate_dma_memory(core_idx, vb)
  174. #define Warp_vdi_free_dma_memory(Implement, core_idx, vb) \
  175. Implement->functions->vdi_free_dma_memory(core_idx, vb)
  176. #define Warp_YuvFeeder_Create(Implement, type, srcFilePath, yuvInfo) \
  177. Implement->functions->YuvFeeder_Create(type, srcFilePath, yuvInfo)
  178. #define Warp_YuvFeeder_Feed(Implement, feeder, coreIdx, fb, picWidth, picHeight, arg) \
  179. Implement->functions->YuvFeeder_Feed(feeder, coreIdx, fb, picWidth, picHeight, arg)
  180. #define Warp_YuvFeeder_Destroy(Implement, feeder) \
  181. Implement->functions->YuvFeeder_Destroy(feeder)
  182. #define Warp_BufferStreamReader_Create(Implement, type, endian, handle) \
  183. Implement->functions->BufferStreamReader_Create(type, endian, handle)
  184. #define Warp_BufferStreamReader_Act(Implement, reader, bitstreamBuffer, bitstreamBufferSize, streamReadSize, pBuffer, comparator) \
  185. Implement->functions->BufferStreamReader_Act(reader, bitstreamBuffer, bitstreamBufferSize, streamReadSize, pBuffer, comparator)
  186. #define Warp_BufferStreamReader_Destroy(Implement, reader) \
  187. Implement->functions->BufferStreamReader_Destroy(reader)
  188. #define Warp_Comparator_Create(Implement, type, goldenPath, ...) \
  189. Implement->functions->Comparator_Create(type, goldenPath, __VA_ARGS__)
  190. #define Warp_Comparator_Destroy(Implement, comp) \
  191. Implement->functions->Comparator_Destroy(comp)
  192. #define Warp_Comparator_CheckEOF(Implement, comp) \
  193. Implement->functions->Comparator_CheckEOF(comp)
  194. #define Warp_DisplayEncodedInformation(Implement, handle, codec, frameNo, encodedInfo, ...) \
  195. Implement->functions->DisplayEncodedInformation(handle, codec, frameNo, encodedInfo, __VA_ARGS__)
  196. #define Warp_PrintVpuVersionInfo(Implement, core_idx) \
  197. Implement->functions->PrintVpuVersionInfo(core_idx)
  198. #define Warp_CalcStride(Implement, width, height, format, cbcrInterleave, mapType, isVP9) \
  199. Implement->functions->CalcStride(width, height, format, cbcrInterleave, mapType, isVP9)
  200. #define Warp_LoadFirmware(Implement, productId, retFirmware, retSizeInWord, path) \
  201. Implement->functions->LoadFirmware(productId, retFirmware, retSizeInWord, path)
  202. #define Warp_SetMaxLogLevel(Implement, level) \
  203. Implement->functions->SetMaxLogLevel(level)
  204. #define Warp_EnterLock(Implement, coreIdx) \
  205. Implement->functions->EnterLock(coreIdx)
  206. #define Warp_LeaveLock(Implement, coreIdx) \
  207. Implement->functions->LeaveLock(coreIdx)
  208. #define Warp_PrintVpuStatus(Implement, coreIdx, productId) \
  209. Implement->functions->PrintVpuStatus(coreIdx, productId)
  210. #endif //SF_OMX_WAVE4_ENC