main_jpg_dec_test.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  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 <stdlib.h>
  27. #include <string.h>
  28. #include <getopt.h>
  29. #include <strings.h>
  30. #include "jpuapi.h"
  31. #include "regdefine.h"
  32. #include "jpulog.h"
  33. #include "jpuapifunc.h"
  34. #include "main_helper.h"
  35. #define NUM_FRAME_BUF MAX_FRAME
  36. #define MAX_ROT_BUF_NUM 1
  37. #ifdef SUPPORT_MULTI_INSTANCE_TEST
  38. #else
  39. static void Help(
  40. const char* programName
  41. )
  42. {
  43. JLOG(INFO, "------------------------------------------------------------------------------\n");
  44. JLOG(INFO, " CODAJ12 Decoder\n");
  45. JLOG(INFO, "------------------------------------------------------------------------------\n");
  46. JLOG(INFO, "%s [options] --input=jpg_file_path\n", programName);
  47. JLOG(INFO, "-h help\n");
  48. JLOG(INFO, "--input=FILE jpeg filepath\n");
  49. JLOG(INFO, "--output=FILE output file path\n");
  50. JLOG(INFO, "--stream-endian=ENDIAN bitstream endianness. refer to datasheet Chapter 4.\n");
  51. JLOG(INFO, "--frame-endian=ENDIAN pixel endianness of 16bit input source. refer to datasheet Chapter 4.\n");
  52. JLOG(INFO, "--pixelj=JUSTIFICATION 16bit-pixel justification. 0(default) - msb justified, 1 - lsb justified in little-endianness\n");
  53. JLOG(INFO, "--bs-size=SIZE bitstream buffer size in byte\n");
  54. JLOG(INFO, "--roi=x,y,w,h ROI region\n");
  55. JLOG(INFO, "--subsample conversion sub-sample(ignore case): NONE, 420, 422, 444\n");
  56. JLOG(INFO, "--ordering conversion ordering(ingore-case): NONE, NV12, NV21, YUYV, YVYU, UYVY, VYUY, AYUV\n");
  57. JLOG(INFO, " NONE - planar format\n");
  58. JLOG(INFO, " NV12, NV21 - semi-planar format for all the subsamples.\n");
  59. JLOG(INFO, " If subsample isn't defined or is none, the sub-sample depends on jpeg information\n");
  60. JLOG(INFO, " The subsample 440 can be converted to the semi-planar format. It means that the encoded sub-sample should be 440.\n");
  61. JLOG(INFO, " YUVV..VYUY - packed format. subsample be ignored.\n");
  62. JLOG(INFO, " AYUV - packed format. subsample be ignored.\n");
  63. JLOG(INFO, "--rotation 0, 90, 180, 270\n");
  64. JLOG(INFO, "--mirror 0(none), 1(V), 2(H), 3(VH)\n");
  65. JLOG(INFO, "--scaleH Horizontal downscale: 0(none), 1(1/2), 2(1/4), 3(1/8)\n");
  66. JLOG(INFO, "--scaleV Vertical downscale : 0(none), 1(1/2), 2(1/4), 3(1/8)\n");
  67. exit(1);
  68. }
  69. #endif /* SUPPORT_MULTI_INSTANCE_TEST */
  70. BOOL TestDecoder(
  71. DecConfigParam *param
  72. )
  73. {
  74. JpgDecHandle handle = {0};
  75. JpgDecOpenParam decOP = {0};
  76. JpgDecInitialInfo initialInfo = {0};
  77. JpgDecOutputInfo outputInfo = {0};
  78. JpgDecParam decParam = {0};
  79. JpgRet ret = JPG_RET_SUCCESS;
  80. FrameBuffer frameBuf[NUM_FRAME_BUF];
  81. jpu_buffer_t vbStream = {0};
  82. FRAME_BUF* pFrame[NUM_FRAME_BUF];
  83. Uint32 framebufWidth=0, framebufHeight=0, framebufStride = 0;
  84. Int32 i = 0, frameIdx = 0, saveIdx =0, totalNumofErrMbs = 0;
  85. BOOL suc = FALSE;
  86. Uint8* pYuv = NULL;
  87. FILE* fpYuv = NULL;
  88. Int32 needFrameBufCount = 0;
  89. Int32 int_reason = 0;
  90. Int32 instIdx = 0;
  91. Uint32 outbufSize=0;
  92. DecConfigParam decConfig;
  93. Uint32 decodingWidth, decodingHeight;
  94. Uint32 displayWidth, displayHeight;
  95. FrameFormat subsample;
  96. Uint32 bitDepth = 0;
  97. Uint32 temp;
  98. BOOL scalerOn = FALSE;
  99. BSFeeder feeder;
  100. memcpy(&decConfig, param, sizeof(DecConfigParam));
  101. memset(pFrame, 0x00, sizeof(pFrame));
  102. memset(frameBuf, 0x00, sizeof(frameBuf));
  103. ret = JPU_Init();
  104. if (ret != JPG_RET_SUCCESS && ret != JPG_RET_CALLED_BEFORE) {
  105. suc = 0;
  106. JLOG(ERR, "JPU_Init failed Error code is 0x%x \n", ret );
  107. goto ERR_DEC_INIT;
  108. }
  109. if ((feeder=BitstreamFeeder_Create(decConfig.bitstreamFileName, decConfig.feedingMode, (EndianMode)decConfig.StreamEndian)) == NULL) {
  110. goto ERR_DEC_INIT;
  111. }
  112. if (strlen(decConfig.yuvFileName)) {
  113. if ((fpYuv=fopen(decConfig.yuvFileName, "wb")) == NULL) {
  114. JLOG(ERR, "Can't open %s \n", decConfig.yuvFileName );
  115. goto ERR_DEC_INIT;
  116. }
  117. }
  118. // Open an instance and get initial information for decoding.
  119. vbStream.size = (decConfig.bsSize == 0) ? STREAM_BUF_SIZE : decConfig.bsSize;
  120. vbStream.size = (vbStream.size + 1023) & ~1023; // ceil128(size)
  121. if (jdi_allocate_dma_memory(&vbStream) < 0) {
  122. JLOG(ERR, "fail to allocate bitstream buffer\n" );
  123. goto ERR_DEC_INIT;
  124. }
  125. decOP.streamEndian = decConfig.StreamEndian;
  126. decOP.frameEndian = decConfig.FrameEndian;
  127. decOP.bitstreamBuffer = vbStream.phys_addr;
  128. decOP.bitstreamBufferSize = vbStream.size;
  129. //set virtual address mapped of physical address
  130. decOP.pBitStream = (BYTE *)vbStream.virt_addr; //lint !e511
  131. decOP.chromaInterleave = decConfig.cbcrInterleave;
  132. decOP.packedFormat = decConfig.packedFormat;
  133. decOP.roiEnable = decConfig.roiEnable;
  134. decOP.roiOffsetX = decConfig.roiOffsetX;
  135. decOP.roiOffsetY = decConfig.roiOffsetY;
  136. decOP.roiWidth = decConfig.roiWidth;
  137. decOP.roiHeight = decConfig.roiHeight;
  138. decOP.rotation = decConfig.rotation;
  139. decOP.mirror = decConfig.mirror;
  140. decOP.pixelJustification = decConfig.pixelJustification;
  141. decOP.outputFormat = decConfig.subsample;
  142. decOP.intrEnableBit = ((1<<INT_JPU_DONE) | (1<<INT_JPU_ERROR) | (1<<INT_JPU_BIT_BUF_EMPTY));
  143. ret = JPU_DecOpen(&handle, &decOP);
  144. if( ret != JPG_RET_SUCCESS ) {
  145. JLOG(ERR, "JPU_DecOpen failed Error code is 0x%x \n", ret );
  146. goto ERR_DEC_INIT;
  147. }
  148. instIdx = handle->instIndex;
  149. //JPU_DecGiveCommand(handle, ENABLE_LOGGING, NULL);
  150. do {
  151. /* Fill jpeg data in the bitstream buffer */
  152. BitstreamFeeder_Act(feeder, handle, &vbStream);
  153. if ((ret=JPU_DecGetInitialInfo(handle, &initialInfo)) != JPG_RET_SUCCESS) {
  154. if (JPG_RET_BIT_EMPTY == ret) {
  155. JLOG(INFO, "<%s:%d> BITSTREAM EMPTY\n", __FUNCTION__, __LINE__);
  156. continue;
  157. }
  158. else {
  159. JLOG(ERR, "JPU_DecGetInitialInfo failed Error code is 0x%x, inst=%d \n", ret, instIdx);
  160. goto ERR_DEC_OPEN;
  161. }
  162. }
  163. } while (JPG_RET_SUCCESS != ret);
  164. if (initialInfo.sourceFormat == FORMAT_420 || initialInfo.sourceFormat == FORMAT_422)
  165. framebufWidth = JPU_CEIL(16, initialInfo.picWidth);
  166. else
  167. framebufWidth = JPU_CEIL(8, initialInfo.picWidth);
  168. if (initialInfo.sourceFormat == FORMAT_420 || initialInfo.sourceFormat == FORMAT_440)
  169. framebufHeight = JPU_CEIL(16, initialInfo.picHeight);
  170. else
  171. framebufHeight = JPU_CEIL(8, initialInfo.picHeight);
  172. decodingWidth = framebufWidth >> decConfig.iHorScaleMode;
  173. decodingHeight = framebufHeight >> decConfig.iVerScaleMode;
  174. if (decOP.packedFormat != PACKED_FORMAT_NONE && decOP.packedFormat != PACKED_FORMAT_444) {
  175. // When packed format, scale-down resolution should be multiple of 2.
  176. decodingWidth = JPU_CEIL(2, decodingWidth);
  177. }
  178. subsample = (decConfig.subsample == FORMAT_MAX) ? initialInfo.sourceFormat : decConfig.subsample;
  179. temp = decodingWidth;
  180. decodingWidth = (decConfig.rotation == 90 || decConfig.rotation == 270) ? decodingHeight : decodingWidth;
  181. decodingHeight = (decConfig.rotation == 90 || decConfig.rotation == 270) ? temp : decodingHeight;
  182. if(decConfig.roiEnable == TRUE) {
  183. decodingWidth = framebufWidth = initialInfo.roiFrameWidth ;
  184. decodingHeight = framebufHeight = initialInfo.roiFrameHeight;
  185. }
  186. if (0 != decConfig.iHorScaleMode || 0 != decConfig.iVerScaleMode) {
  187. displayWidth = JPU_FLOOR(2, (framebufWidth >> decConfig.iHorScaleMode));
  188. displayHeight = JPU_FLOOR(2, (framebufHeight >> decConfig.iVerScaleMode));
  189. }
  190. else {
  191. displayWidth = decodingWidth;
  192. displayHeight = decodingHeight;
  193. }
  194. JLOG(INFO, "decodingWidth: %d, decodingHeight: %d\n", decodingWidth, decodingHeight);
  195. // Check restrictions
  196. if (decOP.rotation != 0 || decOP.mirror != MIRDIR_NONE) {
  197. if (decOP.outputFormat != FORMAT_MAX && decOP.outputFormat != initialInfo.sourceFormat) {
  198. JLOG(ERR, "The rotator cannot work with the format converter together.\n");
  199. goto ERR_DEC_OPEN;
  200. }
  201. }
  202. JLOG(INFO, "<INSTANCE %d>\n", instIdx);
  203. JLOG(INFO, "SOURCE PICTURE SIZE : W(%d) H(%d)\n", initialInfo.picWidth, initialInfo.picHeight);
  204. JLOG(INFO, "DECODED PICTURE SIZE: W(%d) H(%d)\n", displayWidth, displayHeight);
  205. JLOG(INFO, "SUBSAMPLE : %d\n", subsample);
  206. //Allocate frame buffer
  207. needFrameBufCount = initialInfo.minFrameBufferCount;
  208. bitDepth = initialInfo.bitDepth;
  209. scalerOn = (BOOL)(decConfig.iHorScaleMode || decConfig.iVerScaleMode);
  210. if (AllocateFrameBuffer(instIdx, subsample, decOP.chromaInterleave, decOP.packedFormat, decConfig.rotation, scalerOn, decodingWidth, decodingHeight, bitDepth, needFrameBufCount) == FALSE) {
  211. JLOG(ERR, "Failed to AllocateFrameBuffer()\n");
  212. goto ERR_DEC_OPEN;
  213. }
  214. for( i = 0; i < needFrameBufCount; ++i ) {
  215. pFrame[i] = GetFrameBuffer(instIdx, i);
  216. frameBuf[i].bufY = pFrame[i]->vbY.phys_addr;
  217. frameBuf[i].bufCb = pFrame[i]->vbCb.phys_addr;
  218. if (decOP.chromaInterleave == CBCR_SEPARATED)
  219. frameBuf[i].bufCr = pFrame[i]->vbCr.phys_addr;
  220. frameBuf[i].stride = pFrame[i]->strideY;
  221. frameBuf[i].strideC = pFrame[i]->strideC;
  222. frameBuf[i].endian = decOP.frameEndian;
  223. frameBuf[i].format = (FrameFormat)pFrame[i]->Format;
  224. }
  225. framebufStride = frameBuf[0].stride;
  226. outbufSize = decodingWidth * decodingHeight * 3 * (bitDepth+7)/8;
  227. if ((pYuv=malloc(outbufSize)) == NULL) {
  228. JLOG(ERR, "Fail to allocation memory for display buffer\n");
  229. goto ERR_DEC_OPEN;
  230. }
  231. // Register frame buffers requested by the decoder.
  232. if ((ret=JPU_DecRegisterFrameBuffer(handle, frameBuf, needFrameBufCount, framebufStride)) != JPG_RET_SUCCESS) {
  233. JLOG(ERR, "JPU_DecRegisterFrameBuffer failed Error code is 0x%x \n", ret );
  234. goto ERR_DEC_OPEN;
  235. }
  236. JPU_DecGiveCommand(handle, SET_JPG_SCALE_HOR, &(decConfig.iHorScaleMode));
  237. JPU_DecGiveCommand(handle, SET_JPG_SCALE_VER, &(decConfig.iVerScaleMode));
  238. /* LOG HEADER */
  239. JLOG(INFO, "I F FB_INDEX FRAME_START ECS_START CONSUME RD_PTR WR_PTR CYCLE\n");
  240. JLOG(INFO, "-------------------------------------------------------------------------------\n");
  241. while(1) {
  242. // Start decoding a frame.
  243. ret = JPU_DecStartOneFrame(handle, &decParam);
  244. if (ret != JPG_RET_SUCCESS && ret != JPG_RET_EOS) {
  245. if (ret == JPG_RET_BIT_EMPTY) {
  246. JLOG(INFO, "BITSTREAM NOT ENOUGH.............\n");
  247. BitstreamFeeder_Act(feeder, handle, &vbStream);
  248. continue;
  249. }
  250. JLOG(ERR, "JPU_DecStartOneFrame failed Error code is 0x%x \n", ret );
  251. goto ERR_DEC_OPEN;
  252. }
  253. if (ret == JPG_RET_EOS) {
  254. JPU_DecGetOutputInfo(handle, &outputInfo);
  255. suc = TRUE;
  256. break;
  257. }
  258. //JLOG(INFO, "\t<+>INSTANCE #%d JPU_WaitInterrupt\n", handle->instIndex);
  259. while(1) {
  260. if ((int_reason=JPU_WaitInterrupt(handle, JPU_INTERRUPT_TIMEOUT_MS)) == -1) {
  261. JLOG(ERR, "Error : timeout happened\n");
  262. JPU_SWReset(handle);
  263. break;
  264. }
  265. if (int_reason & ((1<<INT_JPU_DONE) | (1<<INT_JPU_ERROR) | (1<<INT_JPU_SLICE_DONE))) {
  266. // Do no clear INT_JPU_DONE and INT_JPU_ERROR interrupt. these will be cleared in JPU_DecGetOutputInfo.
  267. JLOG(INFO, "\tINSTANCE #%d int_reason: %08x\n", handle->instIndex, int_reason);
  268. break;
  269. }
  270. if (int_reason & (1<<INT_JPU_BIT_BUF_EMPTY)) {
  271. if (decConfig.feedingMode != FEEDING_METHOD_FRAME_SIZE) {
  272. BitstreamFeeder_Act(feeder, handle, &vbStream);
  273. }
  274. JPU_ClrStatus(handle, (1<<INT_JPU_BIT_BUF_EMPTY));
  275. }
  276. }
  277. //JLOG(INFO, "\t<->INSTANCE #%d JPU_WaitInterrupt\n", handle->instIndex);
  278. if ((ret=JPU_DecGetOutputInfo(handle, &outputInfo)) != JPG_RET_SUCCESS) {
  279. JLOG(ERR, "JPU_DecGetOutputInfo failed Error code is 0x%x \n", ret );
  280. goto ERR_DEC_OPEN;
  281. }
  282. if (outputInfo.decodingSuccess == 0)
  283. JLOG(ERR, "JPU_DecGetOutputInfo decode fail framdIdx %d \n", frameIdx);
  284. JLOG(INFO, "%02d %04d %8d %8x %8x %10d %8x %8x %10d\n",
  285. instIdx, frameIdx, outputInfo.indexFrameDisplay, outputInfo.bytePosFrameStart, outputInfo.ecsPtr, outputInfo.consumedByte,
  286. outputInfo.rdPtr, outputInfo.wrPtr, outputInfo.frameCycle);
  287. if (outputInfo.indexFrameDisplay == -1)
  288. break;
  289. saveIdx = outputInfo.indexFrameDisplay;
  290. if (!SaveYuvImageHelperFormat_V20(fpYuv, pYuv, &frameBuf[saveIdx], decOP.chromaInterleave, decOP.packedFormat, displayWidth, displayHeight, bitDepth, FALSE)) {
  291. goto ERR_DEC_OPEN;
  292. }
  293. if (outputInfo.numOfErrMBs) {
  294. Int32 errRstIdx, errPosX, errPosY;
  295. errRstIdx = (outputInfo.numOfErrMBs & 0x0F000000) >> 24;
  296. errPosX = (outputInfo.numOfErrMBs & 0x00FFF000) >> 12;
  297. errPosY = (outputInfo.numOfErrMBs & 0x00000FFF);
  298. JLOG(ERR, "Error restart Idx : %d, MCU x:%d, y:%d, in Frame : %d \n", errRstIdx, errPosX, errPosY, frameIdx);
  299. }
  300. frameIdx++;
  301. if (decConfig.outNum && (frameIdx == decConfig.outNum)) {
  302. suc = TRUE;
  303. break;
  304. }
  305. if (decConfig.feedingMode == FEEDING_METHOD_FRAME_SIZE) {
  306. JPU_DecSetRdPtrEx(handle, vbStream.phys_addr, TRUE);
  307. BitstreamFeeder_Act(feeder, handle, &vbStream);
  308. }
  309. }
  310. if (totalNumofErrMbs) {
  311. suc = 0;
  312. JLOG(ERR, "Total Num of Error MBs : %d\n", totalNumofErrMbs);
  313. }
  314. ERR_DEC_OPEN:
  315. // Now that we are done with decoding, close the open instance.
  316. ret = JPU_DecClose(handle);
  317. if (ret != JPG_RET_SUCCESS)
  318. suc = 0;
  319. JLOG(INFO, "\nDec End. Tot Frame %d\n", frameIdx);
  320. BitstreamFeeder_Destroy(feeder);
  321. ERR_DEC_INIT:
  322. FreeFrameBuffer(instIdx);
  323. jdi_free_dma_memory(&vbStream);
  324. if (pYuv)
  325. free(pYuv);
  326. if (fpYuv)
  327. fclose(fpYuv);
  328. JPU_DeInit();
  329. return suc;
  330. }
  331. #ifdef SUPPORT_MULTI_INSTANCE_TEST
  332. #else
  333. /*line -e14 to inhibit multiple main symbol error*/
  334. int main(int argc, char** argv)
  335. {
  336. Int32 ret = 1;
  337. struct option longOpt[] = {
  338. { "stream-endian", required_argument, NULL, 0 },
  339. { "frame-endian", required_argument, NULL, 0 },
  340. { "output", required_argument, NULL, 0 },
  341. { "input", required_argument, NULL, 0 },
  342. { "pixelj", required_argument, NULL, 0 },
  343. { "bs-size", required_argument, NULL, 0 },
  344. { "roi", required_argument, NULL, 0 },
  345. { "subsample", required_argument, NULL, 0 },
  346. { "ordering", required_argument, NULL, 0 },
  347. { "rotation", required_argument, NULL, 0 },
  348. { "mirror", required_argument, NULL, 0 },
  349. { "scaleH", required_argument, NULL, 0 },
  350. { "scaleV", required_argument, NULL, 0 },
  351. { NULL, no_argument, NULL, 0 },
  352. };
  353. Int32 c;
  354. int l;
  355. const char* shortOpt = "fh";
  356. DecConfigParam config;
  357. TestDevConfig devConfig = { ACLK_MIN, CCLK_MIN, TRUE };
  358. char* ext = NULL;
  359. memset((void*)&config, 0x00, sizeof(DecConfigParam));
  360. config.subsample = FORMAT_MAX;
  361. while ((c=getopt_long(argc, argv, shortOpt, longOpt, &l)) != -1) {
  362. switch (c) {
  363. case 'h':
  364. Help(argv[0]);
  365. break;
  366. case 'f':
  367. devConfig.reset = FALSE;
  368. break;
  369. case 0:
  370. if (strcmp(longOpt[l].name, "aclk") == 0) {
  371. devConfig.aclk=atoi(optarg);
  372. if (devConfig.aclk < ACLK_MIN || devConfig.aclk > ACLK_MAX) {
  373. JLOG(ERR, "Invalid ACLK(%d) valid range(%d ~ %d)\n", devConfig.aclk, ACLK_MIN, ACLK_MAX);
  374. Help(argv[0]);
  375. }
  376. }
  377. else if (strcmp(longOpt[l].name, "cclk") == 0) {
  378. devConfig.cclk=atoi(optarg);
  379. if (devConfig.cclk < CCLK_MIN || devConfig.cclk > CCLK_MAX) {
  380. JLOG(ERR, "Invalid CCLK(%d) valid range(%d ~ %d)\n", devConfig.cclk, CCLK_MIN, CCLK_MAX);
  381. Help(argv[0]);
  382. }
  383. }
  384. else {
  385. if (ParseDecTestLongArgs((void*)&config, longOpt[l].name, optarg) == FALSE) {
  386. Help(argv[0]);
  387. }
  388. }
  389. break;
  390. default:
  391. Help(argv[0]);
  392. break;
  393. }
  394. }
  395. if (CNM_InitTestDev(devConfig) == FALSE) {
  396. JLOG(ERR, "Failed to initialize FPGA\n");
  397. return 1;
  398. }
  399. #ifndef SUPPORT_FFMPEG
  400. config.feedingMode = FEEDING_METHOD_FIXED_SIZE;
  401. #endif
  402. /* CHECK PARAMETERS */
  403. if ((config.iHorScaleMode || config.iVerScaleMode) && config.roiEnable) {
  404. JLOG(ERR, "Invalid operation mode : ROI cannot work with the scaler\n");
  405. return 1;
  406. }
  407. if(config.packedFormat && config.roiEnable) {
  408. JLOG(ERR, "Invalid operation mode : ROI cannot work with the packed format conversion\n");
  409. return 1;
  410. }
  411. if (config.roiEnable && (config.rotation || config.mirror)) {
  412. JLOG(ERR, "Invalid operation mode : ROI cannot work with the PPU.\n");
  413. }
  414. ext = GetFileExtension(config.bitstreamFileName);
  415. if (strcasecmp("avi", ext) == 0 || strcasecmp("mkv", ext) == 0) {
  416. config.feedingMode = FEEDING_METHOD_FRAME_SIZE;
  417. }
  418. InitLog("ErrorLog.txt");
  419. ret = TestDecoder(&config);
  420. DeInitLog();
  421. return ret == TRUE ? 0 : 1;
  422. }
  423. #endif /* SUPPORT_MULTI_INSTANCE_TEST */