main_w4_enc_test.c 40 KB

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