main_w4_enc_test.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953
  1. // SPDX-License-Identifier: LGPL-2.1 OR BSD-3-Clause
  2. //------------------------------------------------------------------------------
  3. // File: main.c
  4. //
  5. // Copyright (c) 2006, Chips & Media. All rights reserved.
  6. //------------------------------------------------------------------------------
  7. #include <string.h>
  8. #include <getopt.h>
  9. #include "main_helper.h"
  10. #include "vpuapi.h"
  11. #define STREAM_READ_SIZE (512 * 16)
  12. #define STREAM_READ_ALL_SIZE (0)
  13. #define STREAM_BUF_MIN_SIZE (0x18000)
  14. #define STREAM_BUF_SIZE 0xB00000 // max bitstream size (11MB)
  15. #define MAX_CTU_NUM 0x4000 // CTU num for max resolution = 8192x8192/(64x64)
  16. #define WAVE4_ENC_REPORT_SIZE 144
  17. #ifdef ANDROID
  18. #define CHECK_CORE_INDEX(COREINDEX) if (COREINDEX > (MAX_NUM_VPU_CORE-1) ) { break; }
  19. #else
  20. #define CHECK_CORE_INDEX(COREINDEX) if (COREINDEX > (MAX_NUM_VPU_CORE-1) ) { fprintf(stderr, "Invalid Core Index\n"); break; }
  21. #endif
  22. #define NUM_OF_BS_BUF 1
  23. static Uint32 sizeInWord;
  24. static Uint16* pusBitCode;
  25. static char optYuvPath[256];
  26. static void
  27. help(struct OptionExt *opt, const char *programName )
  28. {
  29. int i;
  30. VLOG(INFO, "------------------------------------------------------------------------------\n");
  31. VLOG(INFO, "%s(API v%d.%d.%d)\n", programName, API_VERSION_MAJOR, API_VERSION_MINOR, API_VERSION_PATCH);
  32. VLOG(INFO, "\tAll rights reserved by Chips&Media(C)\n");
  33. VLOG(INFO, "\tSample program controlling the Chips&Media VPU\n");
  34. VLOG(INFO, "------------------------------------------------------------------------------\n");
  35. VLOG(INFO, "%s [option]\n", programName);
  36. VLOG(INFO, "-h help\n");
  37. VLOG(INFO, "-n [num] output frame number\n");
  38. VLOG(INFO, "-v print version information\n");
  39. VLOG(INFO, "-c compare with golden bitstream\n");
  40. for (i = 0;i < MAX_GETOPT_OPTIONS;i++)
  41. {
  42. if (opt[i].name == NULL)
  43. break;
  44. VLOG(INFO, "%s", opt[i].help);
  45. }
  46. }
  47. extern char *optarg; /* argument associated with option */
  48. int TestEncoder(TestEncConfig *param)
  49. {
  50. EncHandle handle;
  51. EncOpenParam encOP;
  52. EncParam encParam;
  53. EncInitialInfo initialInfo;
  54. EncOutputInfo outputInfo;
  55. SecAxiUse secAxiUse;
  56. vpu_buffer_t vbStream[NUM_OF_BS_BUF];
  57. Uint32 bsBufferCount = 1;
  58. Uint32 bsQueueIndex = 1;
  59. vpu_buffer_t vbReport;
  60. vpu_buffer_t vbReconFrameBuf[MAX_REG_FRAME];
  61. vpu_buffer_t vbSourceFrameBuf[MAX_REG_FRAME];
  62. int FrameBufSize;
  63. FrameBuffer fbSrc[ENC_SRC_BUF_NUM];
  64. FrameBufferAllocInfo fbAllocInfo;
  65. int ret = RETCODE_SUCCESS;
  66. EncHeaderParam encHeaderParam;
  67. int srcFrameIdx = 0, frameIdx = 0;
  68. int srcFrameWidth, srcFrameHeight, srcFrameStride;
  69. int framebufStride = 0, framebufWidth = 0, framebufHeight = 0, mapType;
  70. int suc = 0;
  71. int regFrameBufCount = 0;
  72. int int_reason = 0, i;
  73. int timeoutCount = 0;
  74. int instIdx, coreIdx;
  75. MirrorDirection mirrorDirection;
  76. TestEncConfig encConfig;
  77. Int32 productId;
  78. Comparator comparatorBitStream = NULL;
  79. BitstreamReader bsReader = NULL;
  80. FrameBuffer fbRecon[MAX_REG_FRAME];
  81. vpu_buffer_t vbRoi[MAX_REG_FRAME];
  82. vpu_buffer_t vbCtuQp[MAX_REG_FRAME];
  83. Uint8 ctuQpMapBuf[MAX_CTU_NUM];
  84. // for encode host rbsp header
  85. vpu_buffer_t vbPrefixSeiNal[MAX_REG_FRAME];
  86. vpu_buffer_t vbSuffixSeiNal[MAX_REG_FRAME];
  87. vpu_buffer_t vbHrdRbsp;
  88. vpu_buffer_t vbVuiRbsp;
  89. #ifdef TEST_ENCODE_CUSTOM_HEADER
  90. vpu_buffer_t vbSeiNal[MAX_REG_FRAME];
  91. vpu_buffer_t vbCustomHeader;
  92. #endif
  93. Uint8 roiMapBuf[MAX_CTU_NUM];
  94. void* yuvFeeder = NULL;
  95. FrameBufferFormat srcFrameFormat;
  96. YuvInfo yuvFeederInfo;
  97. Uint32 interruptTimeout = VPU_ENC_TIMEOUT;
  98. #ifdef TEST_ENCODE_CUSTOM_HEADER
  99. hrd_t hrd;
  100. #endif
  101. osal_memcpy(&encConfig, param, sizeof(TestEncConfig));
  102. osal_memset(&yuvFeederInfo, 0x00, sizeof(YuvInfo));
  103. osal_memset(&fbSrc[0], 0x00, sizeof(fbSrc));
  104. osal_memset(&fbRecon[0], 0x00, sizeof(fbRecon));
  105. osal_memset(vbReconFrameBuf, 0x00, sizeof(vbReconFrameBuf));
  106. osal_memset(vbSourceFrameBuf, 0x00, sizeof(vbSourceFrameBuf));
  107. osal_memset(&encOP, 0x00, sizeof(EncOpenParam));
  108. osal_memset(&encParam, 0x00, sizeof(EncParam));
  109. osal_memset(&initialInfo, 0x00, sizeof(EncInitialInfo));
  110. osal_memset(&outputInfo, 0x00, sizeof(EncOutputInfo));
  111. osal_memset(&secAxiUse, 0x00, sizeof(SecAxiUse));
  112. osal_memset(vbStream, 0x00, sizeof(vbStream));
  113. osal_memset(&vbReport, 0x00, sizeof(vpu_buffer_t));
  114. osal_memset(&encHeaderParam, 0x00, sizeof(EncHeaderParam));
  115. osal_memset(vbRoi, 0x00, sizeof(vbRoi));
  116. osal_memset(vbCtuQp, 0x00, sizeof(vbCtuQp));
  117. osal_memset(vbPrefixSeiNal, 0x00, sizeof(vbPrefixSeiNal));
  118. osal_memset(vbSuffixSeiNal, 0x00, sizeof(vbSuffixSeiNal));
  119. osal_memset(&vbVuiRbsp, 0x00, sizeof(vpu_buffer_t));
  120. osal_memset(&vbHrdRbsp, 0x00, sizeof(vpu_buffer_t));
  121. #ifdef TEST_ENCODE_CUSTOM_HEADER
  122. osal_memset(vbSeiNal, 0x00, sizeof(vbSeiNal));
  123. osal_memset(&vbCustomHeader, 0x00, sizeof(vpu_buffer_t));
  124. #endif
  125. instIdx = encConfig.instNum;
  126. coreIdx = encConfig.coreIdx;
  127. productId = VPU_GetProductId(coreIdx);
  128. ret = VPU_InitWithBitcode(coreIdx, pusBitCode, sizeInWord);
  129. if (ret != RETCODE_CALLED_BEFORE && ret != RETCODE_SUCCESS)
  130. {
  131. VLOG(ERR, "Failed to boot up VPU(coreIdx: %d, productId: %d)\n", coreIdx, productId);
  132. goto ERR_ENC_INIT;
  133. }
  134. PrintVpuVersionInfo(coreIdx);
  135. encOP.bitstreamFormat = encConfig.stdMode;
  136. mapType = (encConfig.mapType & 0x0f);
  137. if (strlen(encConfig.cfgFileName) != 0) {
  138. ret = GetEncOpenParam(&encOP, &encConfig, NULL);
  139. }
  140. else {
  141. ret = GetEncOpenParamDefault(&encOP, &encConfig);
  142. }
  143. if (ret == 0)
  144. goto ERR_ENC_INIT;
  145. srcFrameWidth = ((encOP.picWidth+7)&~7); // width = 8-aligned (CU unit)
  146. srcFrameHeight = ((encOP.picHeight+7)&~7); // height = 8-aligned (CU unit)
  147. srcFrameStride = ((encOP.picWidth+31)&~31); // stride should be a 32-aligned.
  148. /* Set user's options */
  149. if (optYuvPath[0] != 0)
  150. strcpy(encConfig.yuvFileName, optYuvPath);
  151. if (strlen(encConfig.cfgFileName) != 0) {
  152. if (encOP.srcBitDepth == 8) {
  153. encConfig.srcFormat = FORMAT_420;
  154. }
  155. else if (encOP.srcBitDepth == 10) {
  156. encConfig.srcFormat = FORMAT_420_P10_16BIT_LSB;
  157. if (encConfig.yuv_mode == YUV_MODE_YUV_LOADER) {
  158. VLOG(INFO, "Need to check YUV style.\n");
  159. encConfig.srcFormat = FORMAT_420_P10_16BIT_MSB;
  160. }
  161. if (encConfig.srcFormat3p4b == 1) {
  162. encConfig.srcFormat = FORMAT_420_P10_32BIT_MSB;
  163. }
  164. if (encConfig.srcFormat3p4b == 2) {
  165. encConfig.srcFormat = FORMAT_420_P10_32BIT_LSB;
  166. }
  167. }
  168. }
  169. if (encConfig.packedFormat >= 1)
  170. encConfig.srcFormat = FORMAT_422;
  171. if (encConfig.srcFormat == FORMAT_422 && encConfig.packedFormat >= PACKED_YUYV) {
  172. int p10bits = encConfig.srcFormat3p4b == 0 ? 16 : 32;
  173. int packedFormat = GetPackedFormat(encOP.srcBitDepth, encConfig.packedFormat, p10bits, 1);
  174. if (packedFormat == -1) {
  175. VLOG(ERR, "fail to GetPackedFormat\n" );
  176. goto ERR_ENC_INIT;
  177. }
  178. encOP.srcFormat = packedFormat;
  179. srcFrameFormat = (FrameBufferFormat)packedFormat;
  180. encOP.nv21 = 0;
  181. encOP.cbcrInterleave = 0;
  182. }
  183. else {
  184. encOP.srcFormat = encConfig.srcFormat;
  185. srcFrameFormat = (FrameBufferFormat)encConfig.srcFormat;
  186. encOP.nv21 = encConfig.nv21;
  187. }
  188. encOP.packedFormat = encConfig.packedFormat;
  189. framebufWidth = (encOP.picWidth +7)&~7;
  190. framebufHeight = (encOP.picHeight +7)&~7;
  191. if ((encConfig.rotAngle != 0 || encConfig.mirDir != 0) && !(encConfig.rotAngle== 180 && encConfig.mirDir == MIRDIR_HOR_VER)) {
  192. framebufWidth = (encOP.picWidth +31)&~31;
  193. framebufHeight = (encOP.picHeight +31)&~31;
  194. }
  195. if (encConfig.rotAngle == 90 || encConfig.rotAngle == 270) {
  196. framebufWidth = (encOP.picHeight +31)&~31;
  197. framebufHeight = (encOP.picWidth +31)&~31;
  198. }
  199. bsBufferCount = NUM_OF_BS_BUF;
  200. for (i=0; i<bsBufferCount; i++ ) {
  201. vbStream[i].size = STREAM_BUF_SIZE;
  202. if (vdi_allocate_dma_memory(coreIdx, &vbStream[i]) < 0) {
  203. VLOG(ERR, "fail to allocate bitstream buffer\n" );
  204. goto ERR_ENC_INIT;
  205. }
  206. VLOG(ERR, "STREAM_BUF=0x%x STREAM_BUF_SIZE=%d(0x%x)\n",vbStream[i].phys_addr, vbStream[i].size, vbStream[i].size);
  207. }
  208. encOP.bitstreamBuffer = vbStream[0].phys_addr;
  209. encOP.bitstreamBufferSize = vbStream[0].size;//* bsBufferCount;//
  210. // -- HW Constraint --
  211. // Required size = actual size of bitstream buffer + 32KBytes
  212. // Minimum size of bitstream : 96KBytes
  213. // Margin : 32KBytes
  214. // Please refer to 3.2.4.4 Encoder Stream Handling in WAVE420 programmer's guide.
  215. if (encConfig.ringBufferEnable)
  216. encOP.bitstreamBufferSize -= 0x8000;
  217. encOP.ringBufferEnable = encConfig.ringBufferEnable;
  218. encOP.cbcrInterleave = encConfig.cbcrInterleave;
  219. encOP.frameEndian = encConfig.frame_endian;
  220. encOP.streamEndian = encConfig.stream_endian;
  221. encOP.sourceEndian = encConfig.source_endian;
  222. encOP.lineBufIntEn = encConfig.lineBufIntEn;
  223. encOP.coreIdx = coreIdx;
  224. encOP.cbcrOrder = CBCR_ORDER_NORMAL;
  225. encOP.EncStdParam.hevcParam.useLongTerm = (encConfig.useAsLongtermPeriod > 0 && encConfig.refLongtermPeriod > 0) ? 1 : 0; // host can set useLongTerm to 1 or 0 directly.
  226. if (writeVuiRbsp(coreIdx, &encConfig, &encOP, &vbVuiRbsp) == FALSE)
  227. goto ERR_ENC_INIT;
  228. if (writeHrdRbsp(coreIdx, &encConfig, &encOP, &vbHrdRbsp) == FALSE)
  229. goto ERR_ENC_INIT;
  230. #ifdef TEST_ENCODE_CUSTOM_HEADER
  231. if (writeCustomHeader(coreIdx, &encOP, &vbCustomHeader, &hrd) == FALSE)
  232. goto ERR_ENC_INIT;
  233. #endif
  234. // Open an instance and get initial information for encoding.
  235. ret = VPU_EncOpen(&handle, &encOP);
  236. if (ret != RETCODE_SUCCESS) {
  237. VLOG(ERR, "VPU_EncOpen failed Error code is 0x%x \n", ret );
  238. goto ERR_ENC_INIT;
  239. }
  240. //VPU_EncGiveCommand(handle, ENABLE_LOGGING, 0);
  241. if (encConfig.rotAngle != 0 || encConfig.mirDir != 0) {
  242. VPU_EncGiveCommand(handle, ENABLE_ROTATION, 0);
  243. VPU_EncGiveCommand(handle, ENABLE_MIRRORING, 0);
  244. VPU_EncGiveCommand(handle, SET_ROTATION_ANGLE, &encConfig.rotAngle);
  245. mirrorDirection = (MirrorDirection)encConfig.mirDir;
  246. VPU_EncGiveCommand(handle, SET_MIRROR_DIRECTION, &mirrorDirection);
  247. }
  248. ret = VPU_EncGetInitialInfo(handle, &initialInfo);
  249. if (ret != RETCODE_SUCCESS) {
  250. VLOG(ERR, "VPU_EncGetInitialInfo failed Error code is 0x%x \n", ret );
  251. goto ERR_ENC_OPEN;
  252. }
  253. VLOG(INFO, "* Enc InitialInfo =>\n instance #%d, \n minframeBuffercount: %u\n minSrcBufferCount: %d\n", instIdx, initialInfo.minFrameBufferCount, initialInfo.minSrcFrameCount);
  254. VLOG(INFO, " picWidth: %u\n picHeight: %u\n ",encOP.picWidth, encOP.picHeight);
  255. if (encConfig.compare_type & (1<<MODE_COMP_ENCODED)) {
  256. comparatorBitStream = Comparator_Create(STREAM_COMPARE, encConfig.ref_stream_path, encConfig.cfgFileName);
  257. if (comparatorBitStream == NULL) {
  258. goto ERR_ENC_OPEN;
  259. }
  260. }
  261. secAxiUse.u.wave4.useEncImdEnable = (encConfig.secondary_axi & 0x1)?TRUE:FALSE; //USE_IMD_INTERNAL_BUF
  262. secAxiUse.u.wave4.useEncRdoEnable = (encConfig.secondary_axi & 0x2)?TRUE:FALSE; //USE_RDO_INTERNAL_BUF
  263. secAxiUse.u.wave4.useEncLfEnable = (encConfig.secondary_axi & 0x4)?TRUE:FALSE; //USE_LF_INTERNAL_BUF
  264. VPU_EncGiveCommand(handle, SET_SEC_AXI, &secAxiUse);
  265. /* Allocate framebuffers for recon. */
  266. framebufStride = CalcStride(framebufWidth, framebufHeight, (FrameBufferFormat)encOP.srcFormat, encOP.cbcrInterleave, (TiledMapType)mapType, FALSE);
  267. FrameBufSize = VPU_GetFrameBufSize(coreIdx, framebufStride, framebufHeight, (TiledMapType)mapType, encOP.srcFormat, encOP.cbcrInterleave, NULL);
  268. regFrameBufCount = initialInfo.minFrameBufferCount;
  269. for (i = 0; i < regFrameBufCount; i++) {
  270. vbReconFrameBuf[i].size = FrameBufSize;
  271. if (vdi_allocate_dma_memory(coreIdx, &vbReconFrameBuf[i]) < 0) {
  272. VLOG(ERR, "fail to allocate recon buffer\n" );
  273. goto ERR_ENC_OPEN;
  274. }
  275. fbRecon[i].bufY = vbReconFrameBuf[i].phys_addr;
  276. fbRecon[i].bufCb = (PhysicalAddress)-1;
  277. fbRecon[i].bufCr = (PhysicalAddress)-1;
  278. fbRecon[i].size = FrameBufSize;
  279. fbRecon[i].updateFbInfo = TRUE;
  280. }
  281. ret = VPU_EncRegisterFrameBuffer(handle, fbRecon, regFrameBufCount, framebufStride, framebufHeight, mapType);
  282. if( ret != RETCODE_SUCCESS ) {
  283. VLOG(ERR, "VPU_EncRegisterFrameBuffer failed Error code is 0x%x \n", ret );
  284. goto ERR_ENC_OPEN;
  285. }
  286. fbAllocInfo.mapType = LINEAR_FRAME_MAP;
  287. srcFrameStride = CalcStride(srcFrameWidth, srcFrameHeight, (FrameBufferFormat)srcFrameFormat, encOP.cbcrInterleave, (TiledMapType)fbAllocInfo.mapType, FALSE);
  288. FrameBufSize = VPU_GetFrameBufSize(coreIdx, srcFrameStride, srcFrameHeight, (TiledMapType)fbAllocInfo.mapType, srcFrameFormat, encOP.cbcrInterleave, NULL);
  289. fbAllocInfo.format = (FrameBufferFormat)srcFrameFormat;
  290. fbAllocInfo.cbcrInterleave = encOP.cbcrInterleave;
  291. fbAllocInfo.stride = srcFrameStride;
  292. fbAllocInfo.height = srcFrameHeight;
  293. fbAllocInfo.endian = encOP.sourceEndian;
  294. fbAllocInfo.type = FB_TYPE_PPU;
  295. fbAllocInfo.num = initialInfo.minSrcFrameCount + EXTRA_SRC_BUFFER_NUM;
  296. fbAllocInfo.nv21 = encOP.nv21;
  297. VLOG(INFO, "Allocated source framebuffers : %d, size : %d\n", fbAllocInfo.num, FrameBufSize);
  298. for (i = 0; i < fbAllocInfo.num; i++) {
  299. vbSourceFrameBuf[i].size = FrameBufSize;
  300. if (vdi_allocate_dma_memory(coreIdx, &vbSourceFrameBuf[i]) < 0)
  301. {
  302. VLOG(ERR, "fail to allocate frame buffer\n" );
  303. goto ERR_ENC_OPEN;
  304. }
  305. fbSrc[i].bufY = vbSourceFrameBuf[i].phys_addr;
  306. fbSrc[i].bufCb = (PhysicalAddress)-1;
  307. fbSrc[i].bufCr = (PhysicalAddress)-1;
  308. fbSrc[i].size = FrameBufSize;
  309. fbSrc[i].updateFbInfo = TRUE;
  310. }
  311. ret = VPU_EncAllocateFrameBuffer(handle, fbAllocInfo, fbSrc);
  312. if (ret != RETCODE_SUCCESS) {
  313. VLOG(ERR, "VPU_EncAllocateFrameBuffer fail to allocate source frame buffer is 0x%x \n", ret );
  314. goto ERR_ENC_OPEN;
  315. }
  316. if (openRoiMapFile(&encConfig) == FALSE) {
  317. goto ERR_ENC_OPEN;
  318. }
  319. if (allocateRoiMapBuf(coreIdx, encConfig, &vbRoi[0], fbAllocInfo.num, MAX_CTU_NUM) == FALSE) {
  320. goto ERR_ENC_OPEN;
  321. }
  322. if (openCtuQpMapFile(&encConfig) == FALSE) {
  323. goto ERR_ENC_OPEN;
  324. }
  325. if ( allocateCtuQpMapBuf(coreIdx, encConfig, &vbCtuQp[0], fbAllocInfo.num, MAX_CTU_NUM) == FALSE) {
  326. goto ERR_ENC_OPEN;
  327. }
  328. // allocate User data buffer amount of source buffer num
  329. if (encConfig.seiDataEnc.prefixSeiNalEnable) {
  330. if (encConfig.prefix_sei_nal_file_name[0]) {
  331. ChangePathStyle(encConfig.prefix_sei_nal_file_name);
  332. if ((encConfig.prefix_sei_nal_fp = osal_fopen(encConfig.prefix_sei_nal_file_name, "r")) == NULL) {
  333. VLOG(ERR, "fail to open Prefix SEI NAL Data file, %s\n", encConfig.prefix_sei_nal_file_name);
  334. goto ERR_ENC_OPEN;
  335. }
  336. }
  337. for (i = 0; i < fbAllocInfo.num ; i++) { // the number of roi buffer should be the same as source buffer num.
  338. vbPrefixSeiNal[i].size = SEI_NAL_DATA_BUF_SIZE;
  339. if (vdi_allocate_dma_memory(coreIdx, &vbPrefixSeiNal[i]) < 0) {
  340. VLOG(ERR, "fail to allocate ROI buffer\n" );
  341. goto ERR_ENC_OPEN;
  342. }
  343. }
  344. }
  345. if (encConfig.seiDataEnc.suffixSeiNalEnable) {
  346. if (encConfig.suffix_sei_nal_file_name[0]) {
  347. ChangePathStyle(encConfig.suffix_sei_nal_file_name);
  348. if ((encConfig.suffix_sei_nal_fp = osal_fopen(encConfig.suffix_sei_nal_file_name, "r")) == NULL) {
  349. VLOG(ERR, "fail to open Prefix SEI NAL Data file, %s\n", encConfig.suffix_sei_nal_file_name);
  350. goto ERR_ENC_OPEN;
  351. }
  352. }
  353. for (i = 0; i < fbAllocInfo.num ; i++) { // the number of roi buffer should be the same as source buffer num.
  354. vbSuffixSeiNal[i].size = SEI_NAL_DATA_BUF_SIZE;
  355. if (vdi_allocate_dma_memory(coreIdx, &vbSuffixSeiNal[i]) < 0) {
  356. VLOG(ERR, "fail to allocate ROI buffer\n" );
  357. goto ERR_ENC_OPEN;
  358. }
  359. }
  360. }
  361. #ifdef TEST_ENCODE_CUSTOM_HEADER
  362. if (allocateSeiNalDataBuf(coreIdx, &vbSeiNal[0], fbAllocInfo.num) == FALSE) {
  363. goto ERR_ENC_OPEN;
  364. }
  365. #endif
  366. encParam.skipPicture = 0;
  367. encParam.quantParam = encConfig.picQpY;
  368. encParam.skipPicture = 0;
  369. encParam.forcePicQpEnable = 0;
  370. encParam.forcePicQpI = 0;
  371. encParam.forcePicQpP = 0;
  372. encParam.forcePicQpB = 0;
  373. encParam.forcePicTypeEnable = 0;
  374. encParam.forcePicType = 0;
  375. encParam.codeOption.implicitHeaderEncode = 1; // FW will encode header data implicitly when changing the header syntaxes
  376. encParam.codeOption.encodeAUD = encConfig.encAUD;
  377. encParam.codeOption.encodeEOS = 0;
  378. if (encOP.ringBufferEnable == TRUE) {
  379. VPU_EncSetWrPtr(handle, encOP.bitstreamBuffer, 1);
  380. }
  381. else {
  382. encHeaderParam.buf = encOP.bitstreamBuffer;
  383. encHeaderParam.size = encOP.bitstreamBufferSize;
  384. }
  385. encHeaderParam.headerType = CODEOPT_ENC_VPS | CODEOPT_ENC_SPS | CODEOPT_ENC_PPS;
  386. ret = VPU_EncGiveCommand(handle, ENC_PUT_VIDEO_HEADER, &encHeaderParam);
  387. if (ret != RETCODE_SUCCESS) {
  388. VLOG(ERR, "VPU_EncGiveCommand ( ENC_PUT_VIDEO_HEADER ) for VPS/SPS/PPS failed Error Reason code : 0x%x \n", ret);
  389. goto ERR_ENC_OPEN;
  390. }
  391. if (encHeaderParam.size == 0) {
  392. VLOG(ERR, "encHeaderParam.size=0\n");
  393. goto ERR_ENC_OPEN;
  394. }
  395. #ifdef SUPPORT_DONT_READ_STREAM
  396. #else
  397. bsReader = BitstreamReader_Create(encOP.ringBufferEnable, encConfig.bitstreamFileName, (EndianMode)encOP.streamEndian, &handle);
  398. #endif
  399. EnterLock(coreIdx);
  400. ret = BitstreamReader_Act(bsReader, encHeaderParam.buf, encOP.bitstreamBufferSize, encHeaderParam.size, comparatorBitStream);
  401. LeaveLock(coreIdx);
  402. if (ret == FALSE) {
  403. goto ERR_ENC_OPEN;
  404. }
  405. yuvFeederInfo.cbcrInterleave = encConfig.cbcrInterleave;
  406. yuvFeederInfo.nv21 = encConfig.nv21;
  407. yuvFeederInfo.packedFormat = encConfig.packedFormat;
  408. yuvFeederInfo.srcFormat = encOP.srcFormat;
  409. yuvFeederInfo.srcPlanar = TRUE;
  410. yuvFeederInfo.srcStride = srcFrameStride;
  411. yuvFeederInfo.srcHeight = srcFrameHeight;
  412. yuvFeeder = YuvFeeder_Create(encConfig.yuv_mode, encConfig.yuvFileName, yuvFeederInfo);
  413. if ( yuvFeeder == NULL ) {
  414. VLOG(INFO, "YuvFeeder_Create error");
  415. goto ERR_ENC_OPEN;
  416. }
  417. VLOG(INFO, "Enc Start : Press any key to stop.\n");
  418. if (encOP.ringBufferEnable == TRUE) {
  419. VPU_EncSetWrPtr(handle, encOP.bitstreamBuffer, 1); // this function shows that HOST can set wrPtr to start position of encoded output in ringbuffer enable mode
  420. }
  421. DisplayEncodedInformation(handle, STD_HEVC, 0, NULL, 0, 0);
  422. while( 1 ) {
  423. if (osal_kbhit()) {
  424. break;
  425. }
  426. srcFrameIdx = (frameIdx%fbAllocInfo.num);
  427. encParam.srcIdx = srcFrameIdx;
  428. ret = YuvFeeder_Feed(yuvFeeder, coreIdx, &fbSrc[srcFrameIdx], encOP.picWidth, encOP.picHeight, NULL);
  429. if ( ret == 0 ) {
  430. encParam.srcEndFlag = 1; // when there is no more source image to be encoded, srcEndFlag should be set 1. because of encoding delay for WAVE420
  431. }
  432. if ( encParam.srcEndFlag != 1) {
  433. fbSrc[srcFrameIdx].srcBufState = SRC_BUFFER_USE_ENCODE;
  434. encParam.sourceFrame = &fbSrc[srcFrameIdx];
  435. encParam.sourceFrame->sourceLBurstEn = 0;///???
  436. }
  437. if( encOP.ringBufferEnable == FALSE) {
  438. bsQueueIndex = (bsQueueIndex+1)%bsBufferCount;
  439. encParam.picStreamBufferAddr = vbStream[bsQueueIndex].phys_addr; // can set the newly allocated buffer.
  440. encParam.picStreamBufferSize = encOP.bitstreamBufferSize;
  441. }
  442. if ( (encConfig.seiDataEnc.prefixSeiNalEnable || encConfig.seiDataEnc.suffixSeiNalEnable) && encParam.srcEndFlag != 1) {
  443. {
  444. Uint8 *pUserBuf;
  445. pUserBuf = (Uint8*)osal_malloc(SEI_NAL_DATA_BUF_SIZE);
  446. osal_memset(pUserBuf, 0, SEI_NAL_DATA_BUF_SIZE);
  447. osal_fread(pUserBuf, 1, encConfig.seiDataEnc.prefixSeiDataSize, encConfig.prefix_sei_nal_fp);
  448. vdi_write_memory(coreIdx, vbPrefixSeiNal[srcFrameIdx].phys_addr, pUserBuf, encConfig.seiDataEnc.prefixSeiDataSize, encOP.streamEndian);
  449. osal_free(pUserBuf);
  450. }
  451. {
  452. Uint8 *pUserBuf;
  453. pUserBuf = (Uint8*)osal_malloc(SEI_NAL_DATA_BUF_SIZE);
  454. osal_memset(pUserBuf, 0, SEI_NAL_DATA_BUF_SIZE);
  455. osal_fread(pUserBuf, 1, encConfig.seiDataEnc.suffixSeiDataSize, encConfig.suffix_sei_nal_fp);
  456. vdi_write_memory(coreIdx, vbSuffixSeiNal[srcFrameIdx].phys_addr, pUserBuf, encConfig.seiDataEnc.suffixSeiDataSize, encOP.streamEndian);
  457. osal_free(pUserBuf);
  458. }
  459. encConfig.seiDataEnc.prefixSeiNalAddr = vbPrefixSeiNal[srcFrameIdx].phys_addr;
  460. encConfig.seiDataEnc.suffixSeiNalAddr = vbSuffixSeiNal[srcFrameIdx].phys_addr;
  461. VPU_EncGiveCommand(handle, ENC_SET_SEI_NAL_DATA, &encConfig.seiDataEnc);
  462. }
  463. osal_memset(&encParam.ctuOptParam, 0, sizeof(HevcCtuOptParam));
  464. setRoiMap(coreIdx, &encConfig, encOP, vbRoi[srcFrameIdx].phys_addr, &roiMapBuf[0], srcFrameWidth, srcFrameHeight, &encParam, MAX_CTU_NUM);
  465. setCtuQpMap(coreIdx, &encConfig, encOP, vbCtuQp[srcFrameIdx].phys_addr, &ctuQpMapBuf[0], srcFrameWidth, srcFrameHeight, &encParam, MAX_CTU_NUM);
  466. #ifdef TEST_ENCODE_CUSTOM_HEADER
  467. if (writeSeiNalData(handle, encOP.streamEndian, vbSeiNal[srcFrameIdx].phys_addr, &hrd) == FALSE) {
  468. goto ERR_ENC_OPEN;
  469. }
  470. #endif
  471. if (encConfig.useAsLongtermPeriod > 0 && encConfig.refLongtermPeriod > 0) {
  472. encParam.useCurSrcAsLongtermPic = (frameIdx % encConfig.useAsLongtermPeriod) == 0 ? 1 : 0;
  473. encParam.useLongtermRef = (frameIdx % encConfig.refLongtermPeriod) == 0 ? 1 : 0;
  474. }
  475. // Start encoding a frame.
  476. frameIdx++;
  477. ret = VPU_EncStartOneFrame(handle, &encParam);
  478. if(ret != RETCODE_SUCCESS) {
  479. VLOG(ERR, "VPU_EncStartOneFrame failed Error code is 0x%x \n", ret );
  480. LeaveLock(coreIdx);
  481. goto ERR_ENC_OPEN;
  482. }
  483. timeoutCount = 0;
  484. while (TRUE) {
  485. int_reason = VPU_WaitInterrupt(coreIdx, VPU_WAIT_TIME_OUT);
  486. if (int_reason == -1) {
  487. if (interruptTimeout > 0 && timeoutCount*VPU_WAIT_TIME_OUT > interruptTimeout) {
  488. VLOG(ERR, "Error : encoder timeout happened\n");
  489. PrintVpuStatus(coreIdx, productId);
  490. VPU_SWReset(coreIdx, SW_RESET_SAFETY, handle);
  491. break;
  492. }
  493. int_reason = 0;
  494. timeoutCount++;
  495. }
  496. if (encOP.ringBufferEnable == TRUE) {
  497. if (!BitstreamReader_Act(bsReader, encOP.bitstreamBuffer, encOP.bitstreamBufferSize, STREAM_READ_SIZE, comparatorBitStream)) {
  498. PrintVpuStatus(coreIdx, productId);
  499. break;
  500. }
  501. }
  502. if (int_reason & (1<<INT_BIT_BIT_BUF_FULL)) {
  503. VLOG(WARN,"INT_BIT_BIT_BUF_FULL \n");
  504. BitstreamReader_Act(bsReader, encOP.bitstreamBuffer, encOP.bitstreamBufferSize, STREAM_READ_ALL_SIZE, comparatorBitStream);
  505. }
  506. if (int_reason) {
  507. VPU_ClearInterrupt(coreIdx);
  508. if (int_reason & (1<<INT_WAVE_ENC_PIC)) {
  509. break;
  510. }
  511. }
  512. }
  513. ret = VPU_EncGetOutputInfo(handle, &outputInfo);
  514. if (ret != RETCODE_SUCCESS) {
  515. VLOG(ERR, "VPU_EncGetOutputInfo failed Error code is 0x%x \n", ret );
  516. if (ret == RETCODE_STREAM_BUF_FULL) {
  517. VLOG(ERR, "RETCODE_STREAM_BUF_FULL\n");
  518. continue;
  519. }
  520. else if ( ret == RETCODE_MEMORY_ACCESS_VIOLATION || ret == RETCODE_CP0_EXCEPTION || ret == RETCODE_ACCESS_VIOLATION_HW)
  521. {
  522. EnterLock(coreIdx);
  523. PrintMemoryAccessViolationReason(coreIdx, (void*)&outputInfo);
  524. PrintVpuStatus(coreIdx, productId);
  525. VPU_SWReset(coreIdx, SW_RESET_SAFETY, handle);
  526. LeaveLock(coreIdx);
  527. } else {
  528. EnterLock(coreIdx);
  529. PrintVpuStatus(coreIdx, productId);
  530. VPU_SWReset(coreIdx, SW_RESET_SAFETY, handle);
  531. LeaveLock(coreIdx);
  532. }
  533. goto ERR_ENC_OPEN;
  534. }
  535. DisplayEncodedInformation(handle, STD_HEVC, 0, &outputInfo, encParam.srcEndFlag , srcFrameIdx);
  536. if (encOP.ringBufferEnable == 0) {
  537. if (outputInfo.bitstreamWrapAround == 1) {
  538. VLOG(WARN, "Warnning!! BitStream buffer wrap arounded. prepare more large buffer \n", ret );
  539. }
  540. if (outputInfo.bitstreamSize == 0 && outputInfo.reconFrameIndex >= 0) {
  541. VLOG(ERR, "ERROR!!! bitstreamsize = 0 \n");
  542. }
  543. if (encOP.lineBufIntEn == 0) {
  544. if (outputInfo.wrPtr < outputInfo.rdPtr)
  545. {
  546. VLOG(ERR, "wrptr < rdptr\n");
  547. goto ERR_ENC_OPEN;
  548. }
  549. }
  550. if ( outputInfo.bitstreamSize ) {
  551. EnterLock(coreIdx);
  552. ret = BitstreamReader_Act(bsReader, outputInfo.bitstreamBuffer, encOP.bitstreamBufferSize, outputInfo.bitstreamSize, comparatorBitStream);
  553. LeaveLock(coreIdx);
  554. if (ret == FALSE) {
  555. goto ERR_ENC_OPEN;
  556. }
  557. }
  558. }
  559. if (outputInfo.reconFrameIndex == -1) // end of encoding
  560. {
  561. break;
  562. }
  563. #ifdef ENC_RECON_FRAME_DISPLAY
  564. SimpleRenderer_Act();
  565. #endif
  566. if (frameIdx > (encConfig.outNum-1))
  567. encParam.srcEndFlag = 1;
  568. }
  569. if( encOP.ringBufferEnable == 1 ) {
  570. EnterLock(coreIdx);
  571. ret = BitstreamReader_Act(bsReader, encOP.bitstreamBuffer, encOP.bitstreamBufferSize, 0, comparatorBitStream);
  572. LeaveLock(coreIdx);
  573. if (ret == FALSE) {
  574. EnterLock(coreIdx);
  575. PrintVpuStatus(coreIdx, productId);
  576. LeaveLock(coreIdx);
  577. goto ERR_ENC_OPEN;
  578. }
  579. }
  580. if (param->outNum == 0) {
  581. if (comparatorBitStream) {
  582. if (Comparator_CheckEOF(comparatorBitStream) == FALSE) {
  583. VLOG(ERR, "MISMATCH BitStream data size. There is still data to compare.\n");
  584. goto ERR_ENC_OPEN;
  585. }
  586. }
  587. }
  588. suc = 1;
  589. ERR_ENC_OPEN:
  590. // Now that we are done with encoding, close the open instance.
  591. for (i = 0; i < regFrameBufCount; i++) {
  592. if (vbReconFrameBuf[i].size > 0) {
  593. vdi_free_dma_memory(coreIdx, &vbReconFrameBuf[i]);
  594. }
  595. }
  596. for (i = 0; i < fbAllocInfo.num; i++) {
  597. if (vbSourceFrameBuf[i].size > 0) {
  598. vdi_free_dma_memory(coreIdx, &vbSourceFrameBuf[i]);
  599. }
  600. if (vbRoi[i].size) {
  601. vdi_free_dma_memory(coreIdx, &vbRoi[i]);
  602. }
  603. if (vbCtuQp[i].size) {
  604. vdi_free_dma_memory(coreIdx, &vbCtuQp[i]);
  605. }
  606. if (vbPrefixSeiNal[i].size)
  607. vdi_free_dma_memory(coreIdx, &vbPrefixSeiNal[i]);
  608. if (vbSuffixSeiNal[i].size)
  609. vdi_free_dma_memory(coreIdx, &vbSuffixSeiNal[i]);
  610. #ifdef TEST_ENCODE_CUSTOM_HEADER
  611. if (vbSeiNal[i].size)
  612. vdi_free_dma_memory(coreIdx, &vbSeiNal[i]);
  613. #endif
  614. }
  615. if (vbHrdRbsp.size)
  616. vdi_free_dma_memory(coreIdx, &vbHrdRbsp);
  617. if (vbVuiRbsp.size)
  618. vdi_free_dma_memory(coreIdx, &vbVuiRbsp);
  619. #ifdef TEST_ENCODE_CUSTOM_HEADER
  620. if (vbCustomHeader.size)
  621. vdi_free_dma_memory(coreIdx, &vbCustomHeader);
  622. #endif
  623. if (encConfig.prefix_sei_nal_fp)
  624. osal_fclose(encConfig.prefix_sei_nal_fp);
  625. if (encConfig.suffix_sei_nal_fp)
  626. osal_fclose(encConfig.suffix_sei_nal_fp);
  627. if (encConfig.vui_rbsp_fp)
  628. osal_fclose(encConfig.vui_rbsp_fp);
  629. if (encConfig.hrd_rbsp_fp)
  630. osal_fclose(encConfig.hrd_rbsp_fp);
  631. if (encConfig.roi_file)
  632. osal_fclose(encConfig.roi_file);
  633. VPU_EncClose(handle);
  634. VLOG(INFO, "\ninst %d Enc End. Tot Frame %d\n" , instIdx, outputInfo.encPicCnt);
  635. ERR_ENC_INIT:
  636. for (i=0; i< bsBufferCount ; i++) {
  637. if (vbStream[i].size)
  638. vdi_free_dma_memory(coreIdx, &vbStream[i]);
  639. }
  640. if (vbReport.size)
  641. vdi_free_dma_memory(coreIdx, &vbReport);
  642. if (comparatorBitStream != NULL) {
  643. Comparator_Destroy(comparatorBitStream);
  644. osal_free(comparatorBitStream);
  645. }
  646. BitstreamReader_Destroy(bsReader);
  647. if (yuvFeeder != NULL) {
  648. YuvFeeder_Destroy(yuvFeeder);
  649. osal_free(yuvFeeder);
  650. }
  651. VPU_DeInit(coreIdx);
  652. return suc;
  653. }
  654. int main(int argc, char **argv)
  655. {
  656. Uint32 productId;
  657. BOOL showVersion = FALSE;
  658. BOOL debugMode = FALSE;
  659. int opt, index, ret = 0, i;
  660. TestEncConfig encConfig;
  661. struct option options[MAX_GETOPT_OPTIONS];
  662. struct OptionExt options_help[] = {
  663. {"output", 1, NULL, 0, "--output bitstream path\n"},
  664. {"input", 1, NULL, 0, "--input YUV file path. The value of InputFile in a cfg is replaced to this value.\n"},
  665. {"codec", 1, NULL, 0, "--codec codec index, HEVC: 12\n"},
  666. {"cfgFileName", 1, NULL, 0, "--cfgFileName cfg file path\n"},
  667. {"coreIdx", 1, NULL, 0, "--coreIdx core index: default 0\n"},
  668. {"picWidth", 1, NULL, 0, "--picWidth source width\n"},
  669. {"picHeight", 1, NULL, 0, "--picHeight source height\n"},
  670. {"kbps", 1, NULL, 0, "--kbps RC bitrate in kbps. In case of without cfg file, if this option has value then RC will be enabled\n"},
  671. {"enable-ringBuffer", 0, NULL, 0, "--enable-ringBuffer enable stream ring buffer mode\n"},
  672. {"enable-lineBufInt", 0, NULL, 0, "--enable-lineBufInt enable linebuffer interrupt\n"},
  673. {"mapType", 1, NULL, 0, "--mapType mapType\n"},
  674. {"loop-count", 1, NULL, 0, "--loop-count integer number. loop test, default 0\n"},
  675. {"enable-cbcrInterleave", 0, NULL, 0, "--enable-cbcrInterleave enable cbcr interleave\n"},
  676. {"nv21", 1, NULL, 0, "--nv21 enable NV21(must set enable-cbcrInterleave)\n"},
  677. {"packedFormat", 1, NULL, 0, "--packedFormat 1:YUYV, 2:YVYU, 3:UYVY, 4:VYUY\n"},
  678. {"rotAngle", 1, NULL, 0, "--rotAngle rotation angle(0,90,180,270), Not supported on WAVE420L\n"},
  679. {"mirDir", 1, NULL, 0, "--mirDir 1:Vertical, 2: Horizontal, 3:Vert-Horz, Not supported on WAVE420L\n"}, /* 20 */
  680. {"secondary-axi", 1, NULL, 0, "--secondary-axi 0~7: bit mask values, Please refer programmer's guide or datasheet\n"
  681. " 1:IMD(not supported on WAVE420L), 2: RDO, 4: LF\n"},
  682. {"frame-endian", 1, NULL, 0, "--frame-endian 16~31, default 31(LE) Please refer programmer's guide or datasheet\n"},
  683. {"stream-endian", 1, NULL, 0, "--stream-endian 16~31, default 31(LE) Please refer programmer's guide or datasheet\n"},
  684. {"source-endian", 1, NULL, 0, "--source-endian 16~31, default 31(LE) Please refer programmer's guide or datasheet\n"},
  685. {"ref_stream_path", 1, NULL, 0, "--ref_stream_path golden data which is compared with encoded stream when -c option\n"},
  686. {"srcFormat3p4b", 1, NULL, 0, "--srcFormat3p4b [WAVE420]This option MUST BE enabled when format of source yuv is 3pixel 4byte format\n"},
  687. {NULL, 0, NULL, 0},
  688. };
  689. char* optString = "rbhvn:";
  690. char* fwPath = NULL;
  691. InitLog();
  692. //default setting.
  693. osal_memset(&encConfig, 0, sizeof(encConfig));
  694. encConfig.stdMode = STD_HEVC;
  695. encConfig.frame_endian = VPU_FRAME_ENDIAN;
  696. encConfig.stream_endian = VPU_STREAM_ENDIAN;
  697. encConfig.source_endian = VPU_SOURCE_ENDIAN;
  698. encConfig.mapType = COMPRESSED_FRAME_MAP;
  699. for (i = 0; i < MAX_GETOPT_OPTIONS;i++) {
  700. if (options_help[i].name == NULL)
  701. break;
  702. osal_memcpy(&options[i], &options_help[i], sizeof(struct option));
  703. }
  704. while ((opt=getopt_long(argc, argv, optString, options, &index)) != -1) {
  705. switch (opt) {
  706. case 'n':
  707. encConfig.outNum = atoi(optarg);
  708. break;
  709. case 'c':
  710. encConfig.compare_type |= (1 << MODE_COMP_ENCODED);
  711. VLOG(ERR,"Stream compare Enable\n");
  712. break;
  713. case 'h':
  714. help(options_help, argv[0]);
  715. return 0;
  716. break;
  717. case 'v':
  718. showVersion = TRUE;
  719. break;
  720. case 0:
  721. if (!strcmp(options[index].name, "output")) {
  722. osal_memcpy(encConfig.bitstreamFileName, optarg, strlen(optarg));
  723. ChangePathStyle(encConfig.bitstreamFileName);
  724. } else if (!strcmp(options[index].name, "input")) {
  725. strcpy(optYuvPath, optarg);
  726. ChangePathStyle(optYuvPath);
  727. } else if (!strcmp(options[index].name, "codec")) {
  728. encConfig.stdMode = (CodStd)atoi(optarg);
  729. } else if (!strcmp(options[index].name, "cfgFileName")) {
  730. osal_memcpy(encConfig.cfgFileName, optarg, strlen(optarg));
  731. } else if (!strcmp(options[index].name, "coreIdx")) {
  732. encConfig.coreIdx = atoi(optarg);
  733. } else if (!strcmp(options[index].name, "picWidth")) {
  734. encConfig.picWidth = atoi(optarg);
  735. } else if (!strcmp(options[index].name, "picHeight")) {
  736. encConfig.picHeight = atoi(optarg);
  737. } else if (!strcmp(options[index].name, "kbps")) {
  738. encConfig.kbps = atoi(optarg);
  739. } else if (!strcmp(options[index].name, "enable-ringBuffer")) {
  740. encConfig.ringBufferEnable = TRUE;
  741. } else if (!strcmp(options[index].name, "enable-lineBufInt")) {
  742. encConfig.lineBufIntEn = TRUE;
  743. } else if (!strcmp(options[index].name, "loop-count")) {
  744. encConfig.loopCount = atoi(optarg);
  745. } else if (!strcmp(options[index].name, "enable-cbcrInterleave")) {
  746. encConfig.cbcrInterleave = 1;
  747. } else if (!strcmp(options[index].name, "nv21")) {
  748. encConfig.nv21 = atoi(optarg);
  749. } else if (!strcmp(options[index].name, "packedFormat")) {
  750. encConfig.packedFormat = atoi(optarg);
  751. } else if (!strcmp(options[index].name, "rotAngle")) {
  752. encConfig.rotAngle = atoi(optarg);
  753. } else if (!strcmp(options[index].name, "mirDir")) {
  754. encConfig.mirDir = atoi(optarg);
  755. } else if (!strcmp(options[index].name, "secondary-axi")) {
  756. encConfig.secondary_axi = atoi(optarg);
  757. } else if (!strcmp(options[index].name, "frame-endian")) {
  758. encConfig.frame_endian = atoi(optarg);
  759. } else if (!strcmp(options[index].name, "stream-endian")) {
  760. encConfig.stream_endian = atoi(optarg);
  761. } else if (!strcmp(options[index].name, "source-endian")) {
  762. encConfig.source_endian = atoi(optarg);
  763. } else if (!strcmp(options[index].name, "ref_stream_path")) {
  764. osal_memcpy(encConfig.ref_stream_path, optarg, strlen(optarg));
  765. ChangePathStyle(encConfig.ref_stream_path);
  766. } else if (!strcmp(options[index].name, "srcFormat3p4b")) {
  767. encConfig.srcFormat3p4b = atoi(optarg);
  768. } else {
  769. VLOG(ERR, "not exist param = %s\n", options[index].name);
  770. help(options_help, argv[0]);
  771. return 1;
  772. }
  773. break;
  774. default:
  775. help(options_help, argv[0]);
  776. return 1;
  777. }
  778. }
  779. productId = VPU_GetProductId(encConfig.coreIdx);
  780. if (checkParamRestriction(productId, &encConfig) == FALSE)
  781. return 1;
  782. switch (productId) {
  783. case PRODUCT_ID_420: fwPath = CORE_0_BIT_CODE_FILE_PATH; break;
  784. case PRODUCT_ID_420L: fwPath = CORE_5_BIT_CODE_FILE_PATH; break;
  785. case PRODUCT_ID_520: fwPath = CORE_9_BIT_CODE_FILE_PATH; break;
  786. default:
  787. VLOG(ERR, "Unknown product id: %d\n", productId);
  788. return 1;
  789. }
  790. VLOG(INFO, "FW PATH = %s\n", fwPath);
  791. if (LoadFirmware(productId, (Uint8**)&pusBitCode, &sizeInWord, fwPath) < 0) {
  792. VLOG(ERR, "%s:%d Failed to load firmware: %s\n", __FUNCTION__, __LINE__, fwPath);
  793. return 1;
  794. }
  795. if (showVersion == TRUE || debugMode == TRUE) {
  796. Uint32 ver, rev;
  797. ret = VPU_InitWithBitcode(encConfig.coreIdx, (const Uint16*)pusBitCode, sizeInWord);
  798. if (ret != RETCODE_CALLED_BEFORE && ret != RETCODE_SUCCESS) {
  799. VLOG(ERR, "Failed to boot up VPU(coreIdx: %d, productId: %d)\n",
  800. __FUNCTION__, __LINE__, encConfig.coreIdx, productId);
  801. osal_free(pusBitCode);
  802. return 1;
  803. }
  804. VPU_GetVersionInfo(encConfig.coreIdx, &ver, &rev, &productId);
  805. printf("VERSION=%d\n", ver);
  806. printf("REVISION=%d\n", rev);
  807. printf("PRODUCT_ID=%d\n", productId);
  808. if (showVersion == TRUE) {
  809. osal_free(pusBitCode);
  810. VPU_DeInit(encConfig.coreIdx);
  811. return 0;
  812. }
  813. }
  814. osal_init_keyboard();
  815. InitializeDebugEnv(productId, encConfig.testEnvOptions);
  816. ret = TestEncoder(&encConfig);
  817. ReleaseDebugEnv();
  818. if (debugMode == TRUE) {
  819. VPU_DeInit(encConfig.coreIdx);
  820. }
  821. osal_close_keyboard();
  822. osal_free(pusBitCode);
  823. return ret == 1 ? 0 : 1;
  824. }