main_jpg_enc_test.c 21 KB

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