SF_OMX_mjpeg_common.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2021 StarFive Technology Co., Ltd.
  4. */
  5. #ifndef SF_OMX_MJPEG_COMMON
  6. #define SF_OMX_MJPEG_COMMON
  7. #include "OMX_Component.h"
  8. #include "OMX_Image.h"
  9. #include "OMX_Index.h"
  10. #include "OMX_IndexExt.h"
  11. #include "SF_OMX_Core.h"
  12. #include "sf_queue.h"
  13. #include "sf_thread.h"
  14. #include "sf_semaphore.h"
  15. #include "codaj12/jpuapi/jpuapi.h"
  16. #include "codaj12/jpuapi/jpuapifunc.h"
  17. #include "codaj12/sample/main_helper.h"
  18. #include <sys/queue.h>
  19. #include <sys/ipc.h>
  20. #include <sys/msg.h>
  21. #include <pthread.h>
  22. #include <errno.h>
  23. #define INIT_SET_SIZE_VERSION(_struct_, _structType_) \
  24. do \
  25. { \
  26. memset((_struct_), 0, sizeof(_structType_)); \
  27. (_struct_)->nSize = sizeof(_structType_); \
  28. (_struct_)->nVersion.s.nVersionMajor = 1; \
  29. (_struct_)->nVersion.s.nVersionMinor = 18; \
  30. (_struct_)->nVersion.s.nRevision = 1; \
  31. (_struct_)->nVersion.s.nStep = 0; \
  32. } while (0)
  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 NUM_FRAME_BUF MAX_FRAME
  38. #define DEFAULT_FRAME_FORMAT FORMAT_420
  39. #define CODAJ12_OUTPUT_BUF_NUMBER 4
  40. #define CODAJ12_INPUT_BUF_NUMBER 1
  41. #define INPUT_PORT_SUPPORTFORMAT_NUM_MAX 1
  42. #define MCA_MAX_INDEX 1
  43. typedef struct _SF_CODAJ12_FUNCTIONS
  44. {
  45. JpgRet (*JPU_Init)(void);
  46. JpgRet (*JPU_DecOpen)(JpgDecHandle *pHandle, JpgDecOpenParam *pop);
  47. JpgRet (*JPU_DecGetInitialInfo)(JpgDecHandle handle, JpgDecInitialInfo *info);
  48. JpgRet (*JPU_DecRegisterFrameBuffer2)(JpgDecHandle handle, FrameBuffer *bufArray, int stride);
  49. JpgRet (*JPU_DecRegisterFrameBuffer)(JpgDecHandle handle, FrameBuffer * bufArray, int num, int stride);
  50. JpgRet (*JPU_DecGiveCommand)(JpgDecHandle handle, JpgCommand cmd, void *param);
  51. JpgRet (*JPU_DecStartOneFrameBySerialNum)(JpgDecHandle handle, JpgDecParam *param,int bufferIndex);
  52. JpgRet (*JPU_DecStartOneFrame)(JpgDecHandle handle, JpgDecParam *param);
  53. JpgRet (*JPU_DecGetOutputInfo)(JpgDecHandle handle, JpgDecOutputInfo *info);
  54. JpgRet (*JPU_SWReset)(JpgHandle handle);
  55. JpgRet (*JPU_DecSetRdPtrEx)(JpgDecHandle handle, PhysicalAddress addr, BOOL updateWrPtr);
  56. JpgRet (*JPU_DecClose)(JpgDecHandle handle);
  57. Int32 (*JPU_WaitInterrupt)(JpgHandle handle, int timeout);
  58. FrameBuffer *(*JPU_GetFrameBufPool)(JpgDecHandle handle);
  59. void (*JPU_ClrStatus)(JpgHandle handle, Uint32 val);
  60. void (*JPU_DeInit)(void);
  61. void (*BSFeederBuffer_SetData)(void *feeder, char *address, Uint32 size);
  62. Uint32 (*BitstreamFeeder_SetData)(BSFeeder feeder, void *data, Uint32 size);
  63. BSFeeder (*BitstreamFeeder_Create)(const char *path, FeedingMethod method, EndianMode endian);
  64. Uint32 (*BitstreamFeeder_Act)(BSFeeder feeder, JpgDecHandle handle, jpu_buffer_t *bsBuffer);
  65. BOOL(*BitstreamFeeder_Destroy)
  66. (BSFeeder feeder);
  67. int (*jdi_allocate_dma_memory)(jpu_buffer_t *vb);
  68. void (*jdi_free_dma_memory)(jpu_buffer_t *vb);
  69. void *(*AllocateOneFrameBuffer)
  70. // (Uint32 instIdx, Uint32 size, Uint32 *bufferIndex);
  71. (Uint32 instIdx, FrameFormat subsample, CbCrInterLeave cbcrIntlv,
  72. PackedFormat packed, Uint32 rotation, BOOL scalerOn, Uint32 width, Uint32 height, Uint32 bitDepth, Uint32 *bufferIndex);
  73. int (*SaveYuvImageHelper)(Uint8* pYuv, FrameBuffer* fb, CbCrInterLeave interLeave, PackedFormat packed,
  74. Uint32 picWidth, Uint32 picHeight, Uint32 bitDepth);
  75. int (*SaveYuvImageHelperDma)(Uint8* pYuv, FrameBuffer* fb, CbCrInterLeave interLeave, PackedFormat packed,
  76. Uint32 picWidth, Uint32 picHeight, Uint32 bitDepth);
  77. int (*FreeOneFrameBuffer)(Uint32 instIdx, void* virt_addr);
  78. void (*FreeFrameBuffer)(int instIdx);
  79. FRAME_BUF *(*GetFrameBuffer)(int instIdx, int idx);
  80. Uint32 (*GetFrameBufferCount)(int instIdx);
  81. BOOL (*AttachOneFrameBuffer)(Uint32 instIdx, FrameFormat subsample, CbCrInterLeave cbcrIntlv, PackedFormat packed,
  82. Uint32 rotation, BOOL scalerOn, Uint32 width, Uint32 height, Uint32 bitDepth,
  83. void *virtAddress, Uint32 size, Uint32 *bufferIndex);
  84. BOOL (*AllocateFrameBuffer)(Uint32 instIdx, FrameFormat subsample, CbCrInterLeave cbcrIntlv, PackedFormat packed,
  85. Uint32 rotation, BOOL scalerOn, Uint32 width, Uint32 height, Uint32 bitDepth, Uint32 num);
  86. BOOL (*UpdateFrameBuffers)(Uint32 instIdx, Uint32 num, FRAME_BUF *frameBuf);
  87. // JPU Log
  88. void (*SetMaxLogLevel)(int level);
  89. } SF_CODAJ12_FUNCTIONS;
  90. typedef struct Message
  91. {
  92. long msg_type;
  93. OMX_U32 msg_flag;
  94. OMX_BUFFERHEADERTYPE *pBuffer;
  95. } Message;
  96. typedef struct _SF_CODAJ12_IMPLEMEMT
  97. {
  98. DecConfigParam *config;
  99. SF_CODAJ12_FUNCTIONS *functions;
  100. BSFeeder feeder;
  101. jpu_buffer_t vbStream;
  102. JpgDecOpenParam decOP;
  103. JpgDecHandle handle;
  104. JpgDecInitialInfo initialInfo;
  105. Int32 instIdx;
  106. FrameBuffer frameBuf[NUM_FRAME_BUF];
  107. FRAME_BUF frame[NUM_FRAME_BUF];
  108. OMX_S32 sInputMessageQueue;
  109. OMX_S32 sOutputMessageQueue;
  110. OMX_S32 sBufferDoneQueue;
  111. THREAD_HANDLE_TYPE *pProcessThread;
  112. OMX_BOOL bThreadRunning;
  113. OMX_STATETYPE currentState;
  114. FrameFormat frameFormat;
  115. OMX_BOOL allocBufFlag;
  116. OMX_BOOL gotEos;
  117. SF_Queue *CmdQueue;
  118. SF_Queue *inPauseQ;
  119. SF_Queue *outPauseQ;
  120. OMX_HANDLETYPE pauseOutSemaphore;
  121. THREAD_HANDLE_TYPE *pCmdThread;
  122. OMX_BOOL bCmdRunning;
  123. OMX_BOOL bPause;
  124. } SF_CODAJ12_IMPLEMEMT;
  125. enum port_index
  126. {
  127. OMX_INPUT_PORT_INDEX = 0,
  128. OMX_OUTPUT_PORT_INDEX = 1,
  129. OMX_PORT_MAX = 2,
  130. };
  131. #ifdef __cplusplus
  132. extern "C"
  133. {
  134. #endif
  135. OMX_ERRORTYPE GetStateMjpegCommon(OMX_IN OMX_HANDLETYPE hComponent, OMX_OUT OMX_STATETYPE *pState);
  136. OMX_ERRORTYPE InitMjpegStructorCommon(SF_OMX_COMPONENT *hComponent);
  137. OMX_BOOL AttachOutputBuffer(SF_OMX_COMPONENT *pSfOMXComponent, OMX_U8* pBuffer, OMX_U32 nSizeBytes);
  138. OMX_U8* AllocateOutputBuffer(SF_OMX_COMPONENT *pSfOMXComponent, OMX_U32 nSizeBytes);
  139. void ThreadExit(void *value_ptr);
  140. void CodaJ12FlushBuffer(SF_OMX_COMPONENT *pSfOMXComponent, OMX_U32 nPortNumber);
  141. #ifdef __cplusplus
  142. }
  143. #endif
  144. #endif