main_jpg_enc_test.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  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. #include <getopt.h>
  26. #include "jpuapi.h"
  27. #include "regdefine.h"
  28. #include "jpulog.h"
  29. #include "jpulog.h"
  30. #include "jpuapifunc.h"
  31. #include "main_helper.h"
  32. #define NUM_FRAME_BUF MAX_FRAME
  33. #define EXTRA_FRAME_BUFFER_NUM 0
  34. #define ENC_SRC_BUF_NUM 1
  35. #define CFG_DIR "./cfg"
  36. #define YUV_DIR "./yuv"
  37. #define BS_SIZE_ALIGNMENT 4096
  38. #define MIN_BS_SIZE 8192
  39. #define DEFAULT_OUTPUT_PATH "output.jpg"
  40. static void GetSourceYuvAttributes(
  41. JpgEncOpenParam encOP,
  42. YuvAttr* retAttr
  43. )
  44. {
  45. retAttr->bigEndian = TRUE;
  46. retAttr->bpp = encOP.jpg12bit == TRUE ? 12 : 8;
  47. retAttr->chromaInterleaved = encOP.chromaInterleave;
  48. retAttr->packedFormat = encOP.packedFormat;
  49. if (encOP.packedFormat == PACKED_FORMAT_NONE) {
  50. retAttr->format = encOP.sourceFormat;
  51. }
  52. else {
  53. switch (encOP.packedFormat) {
  54. case PACKED_FORMAT_422_YUYV:
  55. case PACKED_FORMAT_422_UYVY:
  56. case PACKED_FORMAT_422_YVYU:
  57. case PACKED_FORMAT_422_VYUY:
  58. retAttr->format = FORMAT_422;
  59. break;
  60. case PACKED_FORMAT_444:
  61. retAttr->format = FORMAT_444;
  62. break;
  63. default:
  64. retAttr->format = FORMAT_MAX;
  65. break;
  66. }
  67. }
  68. retAttr->width = encOP.picWidth;
  69. retAttr->height = encOP.picHeight;
  70. retAttr->lsbJustification = encOP.pixelJustification;
  71. return;
  72. }
  73. static void CalcSliceHeight(JpgEncOpenParam* encOP, Uint32 sliceHeight)
  74. {
  75. Uint32 width = encOP->picWidth;
  76. Uint32 height = encOP->picHeight;
  77. FrameFormat format = encOP->sourceFormat;
  78. if (encOP->rotation == 90 || encOP->rotation == 270) {
  79. width = encOP->picHeight;
  80. height = encOP->picWidth;
  81. if (format == FORMAT_422) format = FORMAT_440;
  82. else if (format == FORMAT_440) format = FORMAT_422;
  83. }
  84. encOP->sliceHeight = (sliceHeight == 0)? height : sliceHeight;
  85. if (encOP->sliceHeight != height) {
  86. if (format == FORMAT_420 || format == FORMAT_422)
  87. encOP->restartInterval = width/16;
  88. else
  89. encOP->restartInterval = width/8;
  90. if (format == FORMAT_420 || format == FORMAT_440)
  91. encOP->restartInterval *= (encOP->sliceHeight/16);
  92. else
  93. encOP->restartInterval *= (encOP->sliceHeight/8);
  94. encOP->sliceInstMode = TRUE;
  95. }
  96. }
  97. static Uint8* DumpES(JpgEncHandle handle, jpu_buffer_t bs, JpgEncOutputInfo* pEncOutput, Uint32* rsize/*OUTPUT*/, EndianMode endian)
  98. {
  99. JpgRet ret = JPG_RET_SUCCESS;
  100. PhysicalAddress paBsBufStart;
  101. PhysicalAddress paBsBufEnd;
  102. PhysicalAddress paBsBufWrPtr;
  103. PhysicalAddress paBsBufRdPtr;
  104. int size = 0;
  105. Uint32 loadSize = 0;
  106. Uint8* data = NULL;
  107. paBsBufStart = bs.phys_addr;
  108. paBsBufEnd = bs.phys_addr + bs.size;
  109. if (pEncOutput) {
  110. paBsBufWrPtr = pEncOutput->streamWrPtr;
  111. paBsBufRdPtr = pEncOutput->streamRdPtr;
  112. size = (Uint32)(paBsBufWrPtr - paBsBufRdPtr);;
  113. }
  114. else {
  115. if (JPG_RET_SUCCESS != (ret=JPU_EncGetBitstreamBuffer(handle, &paBsBufRdPtr, &paBsBufWrPtr, &size))) {
  116. JLOG(ERR, "<%s:%d> JPU_EncGetBitstreamBuffer failed Error code is 0x%x \n", __FUNCTION__, __LINE__, ret);
  117. return NULL;
  118. }
  119. }
  120. loadSize = size;
  121. if (loadSize > 0) {
  122. Uint8* val = 0;
  123. int room = 0;
  124. if (NULL == (val=(Uint8*)malloc(loadSize))) {
  125. JLOG(ERR, "<%s:%d> Failed to allocate memory. size(%d)\n", __FUNCTION__, __LINE__, loadSize);
  126. return NULL;
  127. }
  128. if ((paBsBufRdPtr+size) > paBsBufEnd) {
  129. room = paBsBufEnd - paBsBufRdPtr;
  130. JpuReadMem(paBsBufRdPtr, val, room, endian);
  131. JpuReadMem(paBsBufStart, val+room, (size-room), endian);
  132. }
  133. else {
  134. JpuReadMem(paBsBufRdPtr, val, size, endian);
  135. }
  136. if (pEncOutput && (ENCODE_STATE_FRAME_DONE == pEncOutput->encodeState)) {
  137. loadSize = STREAM_END_SIZE; // after done of one frame. set the current wrPtr to to the base address in the bitstream buffer.
  138. }
  139. ret = JPU_EncUpdateBitstreamBuffer(handle, loadSize);
  140. if (JPG_RET_SUCCESS != ret) {
  141. JLOG(ERR, "<%s:%d> VPU_EncUpdateBitstreamBuffer failed Error code is 0x%x \n", __FUNCTION__, __LINE__, ret);
  142. free(val);
  143. return NULL;
  144. }
  145. data = val;
  146. }
  147. *rsize = size;
  148. return data;
  149. }
  150. #ifdef SUPPORT_MULTI_INSTANCE_TEST
  151. #else
  152. static void Help(
  153. const char* programName
  154. )
  155. {
  156. JLOG(INFO, "------------------------------------------------------------------------------\n");
  157. JLOG(INFO, " CODAJ12 Encoder \n");
  158. JLOG(INFO, "------------------------------------------------------------------------------\n");
  159. JLOG(INFO, "%s [option] cfg_file \n", programName);
  160. JLOG(INFO, "-h help\n");
  161. JLOG(INFO, "--output=FILE output file path\n");
  162. JLOG(INFO, "--cfg-dir=DIR folder that has a huffman table and a quantization table. default: %s\n", CFG_DIR);
  163. JLOG(INFO, "--yuv-dir=DIR folder that has an input source image. default: %s\n", YUV_DIR);
  164. JLOG(INFO, "--yuv=FILE use given yuv file instead of yuv file in cfg file\n");
  165. JLOG(INFO, "--slice-height=height the vertical height of a slice. multiple of 8 alignment. 0 is to set the height of picture\n");
  166. JLOG(INFO, "--enable-slice-intr enable get the interrupt at every slice encoded\n");
  167. JLOG(INFO, "--stream-endian=ENDIAN bitstream endianness. refer to datasheet Chapter 4.\n");
  168. JLOG(INFO, "--frame-endian=ENDIAN pixel endianness of 16bit input source. refer to datasheet Chapter 4.\n");
  169. JLOG(INFO, "--bs-size=SIZE bitstream buffer size in byte\n");
  170. JLOG(INFO, "--quality=PERCENTAGE quality factor(0..100)\n");
  171. JLOG(INFO, "--pixelj=JUSTIFICATION 16bit-pixel justification. 0(default) - msb justified, 1 - lsb justified in little-endianness\n");
  172. JLOG(INFO, "--enable-tiledMode enable tiled mode (default linear mode)\n");
  173. exit(1);
  174. }
  175. #endif /* SUPPORT_MULTI_INSTANCE_TEST */
  176. /* @brief Test jpeg encoder
  177. * @return 0 for success, 1 for failure
  178. */
  179. BOOL TestEncoder(
  180. EncConfigParam* param
  181. )
  182. {
  183. JpgEncHandle handle = { 0 };
  184. JpgEncOpenParam encOP = { 0 };
  185. JpgEncParam encParam = { 0 };
  186. JpgEncOutputInfo outputInfo = { 0 };
  187. JpgEncParamSet encHeaderParam = {0};
  188. jpu_buffer_t vbStream = {0};
  189. FRAME_BUF * pFrame[NUM_FRAME_BUF];
  190. FrameBuffer frameBuf[NUM_FRAME_BUF];
  191. JpgRet ret = JPG_RET_SUCCESS;
  192. Uint32 i = 0, srcFrameIdx = 0, frameIdx = 0;
  193. int srcFrameFormat = 0;
  194. int framebufWidth = 0, framebufHeight = 0;
  195. BOOL suc = FALSE;
  196. int int_reason = 0;
  197. int instIdx = 0;
  198. Uint32 needFrameBufCount;
  199. EncConfigParam encConfig;
  200. BOOL boolVal;
  201. YuvFeeder yuvFeeder = NULL;
  202. YuvAttr sourceAttr;
  203. Uint32 apiVersion;
  204. Uint32 hwRevision;
  205. Uint32 hwProductId;
  206. char yuvPath[MAX_FILE_PATH];
  207. Uint32 bitDepth = 8;
  208. BSWriter writer;
  209. Uint32 esSize;
  210. Uint8* data = NULL;
  211. encConfig = *param;
  212. memset(&pFrame[0], 0x00, sizeof(FRAME_BUF *)*NUM_FRAME_BUF);
  213. memset(&frameBuf[0], 0x00, sizeof(FrameBuffer)*NUM_FRAME_BUF);
  214. memset(&encHeaderParam, 0x00, sizeof(encHeaderParam));
  215. ret = JPU_Init();
  216. if (ret != JPG_RET_SUCCESS && ret != JPG_RET_CALLED_BEFORE) {
  217. JLOG(ERR, "JPU_Init failed Error code is 0x%x \n", ret );
  218. goto ERR_ENC_INIT;
  219. }
  220. JPU_GetVersionInfo(&apiVersion, &hwRevision, &hwProductId);
  221. JLOG(INFO, "JPU Version API_VERSION=0x%x, HW_REVISION=%d, HW_PRODUCT_ID=0x%x\n", apiVersion, hwRevision, hwProductId);
  222. if (hwProductId != PRODUCT_ID_CODAJ12) {
  223. JLOG(ERR, "Error JPU HW_PRODUCT_ID=0x%x is not match with API_VERSION=0x%x\n", hwProductId ,apiVersion);
  224. goto ERR_ENC_INIT;
  225. }
  226. if (strlen(encConfig.cfgFileName) != 0) {
  227. boolVal = GetJpgEncOpenParam(&encOP, &encConfig);
  228. }
  229. else {
  230. boolVal = getJpgEncOpenParamDefault(&encOP, &encConfig);
  231. }
  232. if (boolVal == FALSE) {
  233. suc = FALSE;
  234. goto ERR_ENC_INIT;
  235. }
  236. if (NULL == (writer = BitstreamWriter_Create(encConfig.writerType, &encConfig, encConfig.bitstreamFileName))) {
  237. return FALSE;
  238. }
  239. if ((encConfig.bsSize%BS_SIZE_ALIGNMENT) != 0 || encConfig.bsSize < MIN_BS_SIZE) {
  240. JLOG(ERR, "Invalid size of bitstream buffer\n");
  241. goto ERR_ENC_INIT;
  242. }
  243. vbStream.size = encConfig.bsSize;
  244. if (jdi_allocate_dma_memory(&vbStream) < 0) {
  245. JLOG(ERR, "fail to allocate bitstream buffer\n" );
  246. goto ERR_ENC_INIT;
  247. }
  248. encOP.intrEnableBit = ((1<<INT_JPU_DONE) | (1<<INT_JPU_ERROR) | (1<<INT_JPU_BIT_BUF_FULL));
  249. if (encConfig.sliceInterruptEnable)
  250. encOP.intrEnableBit |= (1<<INT_JPU_SLICE_DONE);
  251. encOP.streamEndian = encConfig.StreamEndian;
  252. encOP.frameEndian = encConfig.FrameEndian;
  253. encOP.bitstreamBuffer = vbStream.phys_addr;
  254. encOP.bitstreamBufferSize = vbStream.size;
  255. encOP.rotation = encConfig.rotation;
  256. encOP.mirror = encConfig.mirror;
  257. if(encOP.packedFormat) {
  258. if (encOP.packedFormat==PACKED_FORMAT_444 && encOP.sourceFormat != FORMAT_444) {
  259. JLOG(ERR, "Invalid operation mode : In case of using packed mode. sourceFormat must be FORMAT_444\n" );
  260. goto ERR_ENC_INIT;
  261. }
  262. }
  263. // srcFrameFormat means that it is original source image format.
  264. srcFrameFormat = encOP.sourceFormat;
  265. framebufWidth = (srcFrameFormat == FORMAT_420 || srcFrameFormat == FORMAT_422) ? JPU_CEIL(16, encOP.picWidth) : JPU_CEIL(8, encOP.picWidth);
  266. framebufHeight = (srcFrameFormat == FORMAT_420 || srcFrameFormat == FORMAT_440) ? JPU_CEIL(16, encOP.picHeight) : JPU_CEIL(8, encOP.picHeight);
  267. CalcSliceHeight(&encOP, encConfig.sliceHeight);
  268. // Open an instance and get initial information for encoding.
  269. if ((ret=JPU_EncOpen(&handle, &encOP)) != JPG_RET_SUCCESS) {
  270. JLOG(ERR, "JPU_EncOpen failed Error code is 0x%x \n", ret);
  271. goto ERR_ENC_INIT;
  272. }
  273. // JPU_EncGiveCommand(handle, ENABLE_LOGGING, NULL);
  274. instIdx = handle->instIndex;
  275. JPU_EncGiveCommand(handle, SET_JPG_USE_STUFFING_BYTE_FF, &encConfig.bEnStuffByte);
  276. if (encConfig.encQualityPercentage > 0) {
  277. JPU_EncGiveCommand(handle, SET_JPG_QUALITY_FACTOR, &encConfig.encQualityPercentage);
  278. }
  279. needFrameBufCount = ENC_SRC_BUF_NUM;
  280. bitDepth = (encOP.jpg12bit == FALSE) ? 8 : 12;
  281. // Initialize frame buffers for encoding and source frame
  282. if (!AllocateFrameBuffer(instIdx, encOP.sourceFormat, encOP.chromaInterleave, encOP.packedFormat, 0, FALSE, framebufWidth, framebufHeight, bitDepth, needFrameBufCount)) {
  283. goto ERR_ENC_OPEN;
  284. }
  285. for( i = 0; i < needFrameBufCount; ++i ) {
  286. pFrame[i] = GetFrameBuffer(instIdx, i);
  287. frameBuf[i].stride = pFrame[i]->strideY;
  288. frameBuf[i].strideC = pFrame[i]->strideC;
  289. frameBuf[i].bufY = pFrame[i]->vbY.phys_addr;
  290. frameBuf[i].bufCb = pFrame[i]->vbCb.phys_addr;
  291. frameBuf[i].bufCr = pFrame[i]->vbCr.phys_addr;
  292. }
  293. JLOG(INFO, "framebuffer stride = %d, width = %d, height = %d\n", frameBuf[0].stride, framebufWidth, framebufHeight);
  294. JLOG(INFO, "framebuffer format = %d, packed format = %d, Interleave = %d\n", srcFrameFormat, encOP.packedFormat, encOP.chromaInterleave);
  295. snprintf(yuvPath, sizeof(yuvPath), "%s/%s", encConfig.strYuvDir, encConfig.yuvFileName);
  296. GetSourceYuvAttributes(encOP, &sourceAttr);
  297. if ((yuvFeeder=YuvFeeder_Create(YUV_FEEDER_MODE_NORMAL, yuvPath, sourceAttr, encOP.frameEndian, NULL)) == NULL) {
  298. goto ERR_ENC_OPEN;
  299. }
  300. outputInfo.encodeState = ENCODE_STATE_NEW_FRAME;
  301. while (TRUE) {
  302. if (outputInfo.encodeState == ENCODE_STATE_NEW_FRAME) { // means new frame start
  303. srcFrameIdx = (frameIdx%ENC_SRC_BUF_NUM);
  304. // Write picture header
  305. if (encConfig.encHeaderMode == ENC_HEADER_MODE_NORMAL) {
  306. encHeaderParam.size = vbStream.size;
  307. encHeaderParam.pParaSet = malloc(STREAM_BUF_SIZE);
  308. encHeaderParam.headerMode = ENC_HEADER_MODE_NORMAL; //Encoder header disable/enable control. Annex:A 1.2.3 item 13
  309. encHeaderParam.quantMode = JPG_TBL_NORMAL; //JPG_TBL_MERGE // Merge quantization table. Annex:A 1.2.3 item 7
  310. encHeaderParam.huffMode = JPG_TBL_NORMAL; // JPG_TBL_MERGE //Merge huffman table. Annex:A 1.2.3 item 6
  311. encHeaderParam.disableAPPMarker = 0; //Remove APPn. Annex:A item 11
  312. encHeaderParam.enableSofStuffing = TRUE; //Remove zero stuffing bits before 0xFFDA. Annex:A item 16.
  313. if (encHeaderParam.headerMode == ENC_HEADER_MODE_NORMAL) {
  314. if (encHeaderParam.pParaSet) {
  315. //make picture header
  316. JPU_EncGiveCommand(handle, ENC_JPG_GET_HEADER, &encHeaderParam); // return exact header size int endHeaderparam.siz;
  317. JLOG(INFO, "JPU_EncGiveCommand[ENC_JPG_GET_HEADER] header size=%d\n", encHeaderParam.size);
  318. BitstreamWriter_Act(writer, encHeaderParam.pParaSet, encHeaderParam.size, TRUE);
  319. free(encHeaderParam.pParaSet);
  320. }
  321. }
  322. }
  323. if (YuvFeeder_Feed(yuvFeeder, &frameBuf[srcFrameIdx]) == FALSE) {
  324. goto ERR_ENC_OPEN;
  325. }
  326. encParam.sourceFrame = &frameBuf[srcFrameIdx];
  327. }
  328. JLOG(INFO,"Start encoding a frame\n");
  329. // Start encoding a frame.
  330. ret = JPU_EncStartOneFrame(handle, &encParam);
  331. if( ret != JPG_RET_SUCCESS ) {
  332. JLOG(ERR, "JPU_EncStartOneFrame failed Error code is 0x%x \n", ret );
  333. goto ERR_ENC_OPEN;
  334. }
  335. while(1) {
  336. JLOG(INFO,"JPU_WaitInterrupt\n");
  337. int_reason = JPU_WaitInterrupt(handle, JPU_INTERRUPT_TIMEOUT_MS);
  338. if (int_reason == -1) {
  339. JLOG(ERR, "Error : inst %d timeout happened\n", instIdx);
  340. JPU_SWReset(handle);
  341. goto ERR_ENC_OPEN;
  342. }
  343. if (int_reason == -2) {
  344. JLOG(ERR, "Interrupt occurred. but this interrupt is not for my instance\n");
  345. goto ERR_ENC_OPEN;
  346. }
  347. if (int_reason & (1<<INT_JPU_DONE) || int_reason & (1<<INT_JPU_SLICE_DONE)) { // Must catch PIC_DONE interrupt before catching EMPTY interrupt
  348. // Do no clear INT_JPU_DONE these will be cleared in JPU_EncGetOutputInfo.
  349. break;
  350. }
  351. if (int_reason & (1<<INT_JPU_BIT_BUF_FULL)) {
  352. JLOG(INFO, "INT_JPU_BIT_BUF_FULL interrupt issued INSTANCE %d \n", instIdx);
  353. if (NULL == (data=DumpES(handle, vbStream, NULL, &esSize, (EndianMode)encOP.streamEndian))) {
  354. goto ERR_ENC_OPEN;
  355. }
  356. if (FALSE == BitstreamWriter_Act(writer, data, esSize, TRUE)) {
  357. goto ERR_ENC_OPEN;
  358. }
  359. free(data), data = NULL;
  360. JPU_ClrStatus(handle, (1<<INT_JPU_BIT_BUF_FULL));
  361. }
  362. }
  363. if ((ret=JPU_EncGetOutputInfo(handle, &outputInfo)) != JPG_RET_SUCCESS) {
  364. JLOG(ERR, "JPU_EncGetOutputInfo failed Error code is 0x%x \n", ret );
  365. goto ERR_ENC_OPEN;
  366. }
  367. data=DumpES(handle, vbStream, &outputInfo, &esSize, (EndianMode)encOP.streamEndian);
  368. if (FALSE == BitstreamWriter_Act(writer, data, esSize, FALSE)) {
  369. goto ERR_ENC_OPEN;
  370. }
  371. free(data), data = NULL;
  372. if (outputInfo.encodeState == ENCODE_STATE_SLICE_DONE) {
  373. JLOG(TRACE, "Enc Slice: %d:%d, rdPtr=0x%x, wrPtr=0x%x, slice height=%d\n", instIdx, frameIdx, outputInfo.streamRdPtr, outputInfo.streamWrPtr, outputInfo.encodedSliceYPos);
  374. }
  375. else {
  376. JLOG(TRACE, "Enc: %d:%d, rdPtr=0x%x, wrPtr=0x%x cycles=%d\n", instIdx, frameIdx, outputInfo.streamRdPtr, outputInfo.streamWrPtr, outputInfo.frameCycle);
  377. frameIdx++;
  378. if (frameIdx > (encConfig.outNum-1)) {
  379. suc = TRUE;
  380. break;
  381. }
  382. }
  383. }
  384. ERR_ENC_OPEN:
  385. if (data) {
  386. free(data);
  387. }
  388. if (int_reason < 0) {
  389. JPU_EncGetOutputInfo( handle, &outputInfo );
  390. }
  391. FreeFrameBuffer(instIdx);
  392. if (JPU_EncClose(handle) == JPG_RET_FRAME_NOT_COMPLETE) {
  393. JPU_EncGetOutputInfo( handle, &outputInfo );
  394. JPU_EncClose(handle);
  395. }
  396. JLOG(INFO, "\nEnc End. instIdx=%d, Tot Frame %d\n" , instIdx, frameIdx);
  397. ERR_ENC_INIT:
  398. jdi_free_dma_memory(&vbStream);
  399. if (yuvFeeder != NULL) {
  400. YuvFeeder_Destroy(yuvFeeder);
  401. }
  402. JPU_DeInit();
  403. return suc;
  404. }
  405. #ifdef SUPPORT_MULTI_INSTANCE_TEST
  406. #else
  407. /*lint -e14 to inhibit multiple main symbol error*/
  408. int main(int argc, char** argv)
  409. {
  410. Int32 ret = 1;
  411. struct option longOpt[] = {
  412. { "yuv", required_argument, NULL, 0 },
  413. { "stream-endian", required_argument, NULL, 0 },
  414. { "frame-endian", required_argument, NULL, 0 },
  415. { "pixelj", required_argument, NULL, 0 },
  416. { "bs-size", required_argument, NULL, 0 },
  417. { "cfg-dir", required_argument, NULL, 0 },
  418. { "yuv-dir", required_argument, NULL, 0 },
  419. { "output", required_argument, NULL, 0 },
  420. { "input", required_argument, NULL, 0 },
  421. { "slice-height", required_argument, NULL, 0 },
  422. { "enable-slice-intr", required_argument, NULL, 0 },
  423. { "quality", required_argument, NULL, 0 },
  424. { "enable-tiledMode", required_argument, NULL, 0 },
  425. { "12bit", no_argument, NULL, 0 },
  426. { "rotation", required_argument, NULL, 0 },
  427. { "mirror", required_argument, NULL, 0 },
  428. { NULL, no_argument, NULL, 0 },
  429. };
  430. const char* shortOpt = "fh";
  431. EncConfigParam config;
  432. Int32 c;
  433. int l;
  434. TestDevConfig devConfig = { ACLK_MIN, CCLK_MIN, TRUE };
  435. char* ext = NULL;
  436. memset((void*)&config, 0x00, sizeof(EncConfigParam));
  437. /* Default configurations */
  438. config.bsSize = STREAM_BUF_SIZE;
  439. strcpy(config.strCfgDir, CFG_DIR);
  440. strcpy(config.strYuvDir, YUV_DIR);
  441. strcpy(config.bitstreamFileName, DEFAULT_OUTPUT_PATH);
  442. while ((c=getopt_long(argc, argv, shortOpt, longOpt, &l)) != -1) {
  443. switch (c) {
  444. case 'h':
  445. break;
  446. case 'f':
  447. devConfig.reset = FALSE;
  448. break;
  449. case 0:
  450. if (strcmp(longOpt[l].name, "aclk") == 0) {
  451. devConfig.aclk = atoi(optarg);
  452. }
  453. else if (strcmp(longOpt[l].name, "cclk") == 0) {
  454. devConfig.cclk = atoi(optarg);
  455. }
  456. else {
  457. if (ParseEncTestLongArgs((void*)&config, longOpt[l].name, optarg) == FALSE) {
  458. Help(argv[0]);
  459. }
  460. }
  461. break;
  462. default:
  463. Help(argv[0]);
  464. break;
  465. }
  466. }
  467. if (CNM_InitTestDev(devConfig) == FALSE) {
  468. JLOG(ERR, "Failed to initialize FPGA\n");
  469. return 1;
  470. }
  471. ext = GetFileExtension(config.bitstreamFileName);
  472. if (strcasecmp("avi", ext) == 0 || strcasecmp("mkv", ext) == 0) {
  473. config.writerType = BSWRITER_CONTAINER;
  474. }
  475. InitLog("ErrorLog.txt");
  476. ret = TestEncoder(&config);
  477. DeInitLog();
  478. return ret==TRUE ? 0 : 1;
  479. }
  480. #endif /* SUPPORT_MULTI_INSTANCE_TEST */