main_helper.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /*
  2. * Copyright (c) 2018, Chips&Media
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  18. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #ifndef JPUHELPER_H_INCLUDED
  26. #define JPUHELPER_H_INCLUDED
  27. #ifdef USE_FEEDING_METHOD_BUFFER
  28. #include "codaj12/jpuapi/jpuapi.h"
  29. #include "codaj12/sample/helper/jpulog.h"
  30. #include "codaj12/sample/helper/cnm_fpga.h"
  31. #include "codaj12/sample/helper/yuv_feeder.h"
  32. #else
  33. #include "jpulog.h"
  34. #include "jpuapi.h"
  35. #include "cnm_fpga.h"
  36. #include "yuv_feeder.h"
  37. #endif
  38. #define MAX_FILE_PATH 256
  39. typedef struct {
  40. Uint32 Format;
  41. Uint32 Index;
  42. jpu_buffer_t vbY;
  43. jpu_buffer_t vbCb;
  44. jpu_buffer_t vbCr;
  45. Uint32 strideY;
  46. Uint32 strideC;
  47. } FRAME_BUF;
  48. typedef struct {
  49. FRAME_BUF frameBuf[MAX_FRAME];
  50. jpu_buffer_t vb_base;
  51. int instIndex;
  52. int last_num;
  53. int last_addr;
  54. } fb_context;
  55. typedef enum {
  56. FEEDING_METHOD_FIXED_SIZE,
  57. FEEDING_METHOD_FRAME_SIZE, /*!<< use FFMPEG demuxer */
  58. #ifdef USE_FEEDING_METHOD_BUFFER
  59. FEEDING_METHOD_BUFFER,
  60. #endif
  61. FEEDING_METHOD_MAX
  62. } FeedingMethod;
  63. typedef enum {
  64. BSWRITER_ES,
  65. BSWRITER_CONTAINER,
  66. BSWRITER_MAX
  67. } BSWriterType;
  68. typedef struct
  69. {
  70. char yuvFileName[MAX_FILE_PATH];
  71. char bitstreamFileName[MAX_FILE_PATH];
  72. char huffFileName[MAX_FILE_PATH];
  73. char qMatFileName[MAX_FILE_PATH];
  74. char cfgFileName[MAX_FILE_PATH];
  75. Uint32 picWidth;
  76. Uint32 picHeight;
  77. Uint32 mjpgChromaFormat;
  78. Uint32 mjpgFramerate;
  79. Uint32 outNum;
  80. Uint32 StreamEndian;
  81. Uint32 FrameEndian;
  82. FrameFormat sourceSubsample;
  83. CbCrInterLeave chromaInterleave;
  84. PackedFormat packedFormat;
  85. Uint32 bEnStuffByte;
  86. Uint32 encHeaderMode;
  87. char strCfgDir[MAX_FILE_PATH];
  88. char strYuvDir[MAX_FILE_PATH];
  89. Uint32 bsSize;
  90. Uint32 encQualityPercentage;
  91. Uint32 tiledModeEnable;
  92. Uint32 sliceHeight;
  93. Uint32 sliceInterruptEnable;
  94. BOOL extendedSequential;
  95. Uint32 pixelJustification;
  96. Uint32 rotation;
  97. JpgMirrorDirection mirror;
  98. BSWriterType writerType;
  99. } EncConfigParam;
  100. typedef struct
  101. {
  102. char yuvFileName[MAX_FILE_PATH];
  103. char bitstreamFileName[MAX_FILE_PATH];
  104. Uint32 outNum;
  105. Uint32 checkeos;
  106. Uint32 StreamEndian;
  107. Uint32 FrameEndian;
  108. Uint32 iHorScaleMode;
  109. Uint32 iVerScaleMode;
  110. //ROI
  111. Uint32 roiEnable;
  112. Uint32 roiWidth;
  113. Uint32 roiHeight;
  114. Uint32 roiOffsetX;
  115. Uint32 roiOffsetY;
  116. Uint32 roiWidthInMcu;
  117. Uint32 roiHeightInMcu;
  118. Uint32 roiOffsetXInMcu;
  119. Uint32 roiOffsetYInMcu;
  120. Uint32 rotation;
  121. JpgMirrorDirection mirror;
  122. FrameFormat subsample;
  123. PackedFormat packedFormat;
  124. CbCrInterLeave cbcrInterleave;
  125. Uint32 bsSize;
  126. Uint32 pixelJustification;
  127. FeedingMethod feedingMode;
  128. } DecConfigParam;
  129. typedef struct {
  130. char SrcFileName[256];
  131. Uint32 NumFrame;
  132. Uint32 PicX;
  133. Uint32 PicY;
  134. Uint32 FrameRate;
  135. // MJPEG ONLY
  136. char HuffTabName[256];
  137. char QMatTabName[256];
  138. Uint32 VersionID;
  139. Uint32 FrmFormat;
  140. FrameFormat SrcFormat;
  141. Uint32 RstIntval;
  142. Uint32 ThumbEnable;
  143. Uint32 ThumbSizeX;
  144. Uint32 ThumbSizeY;
  145. Uint32 prec;
  146. Uint32 QMatPrec0;
  147. Uint32 QMatPrec1;
  148. } ENC_CFG;
  149. typedef struct {
  150. Uint32 sourceFormat;
  151. Uint32 restartInterval;
  152. BYTE huffBits[4][256];
  153. BYTE huffVal[4][256];
  154. short qMatTab[4][64];
  155. BOOL lumaQ12bit;
  156. BOOL chromaQ12bit;
  157. BOOL extendedSequence; /* 12bit JPEG */
  158. } EncMjpgParam;
  159. typedef enum {
  160. JPU_ENCODER,
  161. JPU_DECODER,
  162. JPU_NONE,
  163. } JPUComponentType;
  164. typedef struct {
  165. Uint32 numInstances;
  166. JPUComponentType type[MAX_NUM_INSTANCE];
  167. union {
  168. DecConfigParam decConfig;
  169. EncConfigParam encConfig;
  170. } u[MAX_NUM_INSTANCE];
  171. TestDevConfig devConfig;
  172. } TestMultiConfig;
  173. typedef enum { YUV444, YUV422, YUV420, NV12, NV21, YUV400, YUYV, YVYU, UYVY, VYUY, YYY, RGB_PLANAR, RGB32, RGB24, RGB16 } yuv2rgb_color_format;
  174. #if defined (__cplusplus)
  175. extern "C"{
  176. #endif
  177. extern BOOL TestDecoder(DecConfigParam *param);
  178. extern BOOL TestEncoder(EncConfigParam *param);
  179. extern int jpgGetHuffTable(char *huffFileName, EncMjpgParam *param, int prec);
  180. extern int jpgGetQMatrix(char *qMatFileName, EncMjpgParam *param);
  181. extern int getJpgEncOpenParamDefault(JpgEncOpenParam *pEncOP, EncConfigParam *pEncConfig);
  182. extern BOOL GetJpgEncOpenParam(JpgEncOpenParam *pEncOP, EncConfigParam *pEncConfig);
  183. extern int parseJpgCfgFile(ENC_CFG *pEncCfg, char *FileName);
  184. extern JpgRet ReadJpgBsBufHelper(JpgEncHandle handle,
  185. FILE *bsFp,
  186. JpgEncOpenParam *pEncOP,
  187. JpgEncOutputInfo *pEncOutput);
  188. extern int LoadYuvImageHelperFormat_V20( int prec, FILE *yuvFp,
  189. Uint8 *pYuv,
  190. PhysicalAddress addrY,
  191. PhysicalAddress addrCb,
  192. PhysicalAddress addrCr,
  193. int picWidth,
  194. int picHeight,
  195. int stride,
  196. int interleave,
  197. int format,
  198. int endian,
  199. int packed,
  200. Uint32 justification);
  201. extern int SaveYuvImageHelperFormat_V20(
  202. FILE* yuvFp,
  203. Uint8* pYuv,
  204. FrameBuffer* fb,
  205. CbCrInterLeave interLeave,
  206. PackedFormat packed,
  207. Uint32 picWidth,
  208. Uint32 picHeight,
  209. Uint32 bitDepth,
  210. BOOL tiled2Linear
  211. );
  212. extern int GetFrameBufSize(int framebufFormat, int picWidth, int picHeight);
  213. extern void GetMcuUnitSize(int format, int *mcuWidth, int *mcuHeight);
  214. //DPBBufSize may not same with FrameBufSize due to format convert rounding
  215. extern int GetDPBBufSize(int framebufFormat, int picWidth, int picHeight, int picWidth_C, int interleave);
  216. extern BOOL ParseDecTestLongArgs(void* config, const char* argName, char* value);
  217. extern BOOL ParseEncTestLongArgs(void* config, const char* argName, char* value);
  218. extern BOOL ParseMultiLongOptions(TestMultiConfig* config, const char* argName, char* value);
  219. extern BOOL AllocateFrameBuffer(Uint32 instIdx, FrameFormat subsample, CbCrInterLeave cbcrIntlv, PackedFormat packed,
  220. Uint32 rotation, BOOL scalerOn, Uint32 width, Uint32 height, Uint32 bitDepth, Uint32 num);
  221. extern void FreeFrameBuffer(int instIdx);
  222. extern FRAME_BUF *GetFrameBuffer(int instIdx, int index);
  223. extern int GetFrameBufBase(int instIdx);
  224. extern int GetFrameBufAllocSize(int instIdx);
  225. extern FRAME_BUF* FindFrameBuffer(int instIdx, PhysicalAddress addrY);
  226. /* --------------------------------------------------------------------------
  227. * BS feeder
  228. -------------------------------------------------------------------------- */
  229. typedef struct {
  230. void* data;
  231. Uint32 size;
  232. BOOL eos; //!<< End of stream
  233. } BSChunk;
  234. typedef void* BSFeeder;
  235. extern BSFeeder BitstreamFeeder_Create(const char* path, FeedingMethod method, EndianMode endian);
  236. extern Uint32 BitstreamFeeder_Act(BSFeeder feeder, JpgDecHandle handle, jpu_buffer_t* bsBuffer);
  237. extern BOOL BitstreamFeeder_Destroy(BSFeeder feeder);
  238. extern BOOL BitstreamFeeder_IsEos(BSFeeder feeder);
  239. /* --------------------------------------------------------------------------
  240. * BS writer
  241. -------------------------------------------------------------------------- */
  242. typedef void* BSWriter;
  243. typedef struct BitstreamWriterImpl {
  244. void* context;
  245. BOOL (*Create)(struct BitstreamWriterImpl* impl, EncConfigParam* config, const char* path);
  246. Uint32 (*Act)(struct BitstreamWriterImpl* impl, Uint8* es, Uint32 size);
  247. BOOL (*Destroy)(struct BitstreamWriterImpl* impl);
  248. } BitstreamWriterImpl;
  249. extern BSWriter BitstreamWriter_Create(BSWriterType type, EncConfigParam* config, const char* path);
  250. extern BOOL BitstreamWriter_Act(BSWriter writer, Uint8* es, Uint32 size, BOOL delayedWrite);
  251. extern void BitstreamWriter_Destroy(BSWriter writer);
  252. /* --------------------------------------------------------------------------
  253. * String
  254. -------------------------------------------------------------------------- */
  255. extern char* GetFileExtension(const char* filename);
  256. #if defined (__cplusplus)
  257. }
  258. #endif
  259. #endif /* JPUHELPER_H_INCLUDED */