// SPDX-License-Identifier: LGPL-2.1 OR BSD-3-Clause //------------------------------------------------------------------------------ // File: main.c // // Copyright (c) 2006, Chips & Media. All rights reserved. //------------------------------------------------------------------------------ #include #include #include "main_helper.h" #include "vpuapi.h" #define STREAM_READ_SIZE (512 * 16) #define STREAM_READ_ALL_SIZE (0) #define STREAM_BUF_MIN_SIZE (0x18000) #define STREAM_BUF_SIZE 0xB00000 // max bitstream size (11MB) #define MAX_CTU_NUM 0x4000 // CTU num for max resolution = 8192x8192/(64x64) #define WAVE4_ENC_REPORT_SIZE 144 #ifdef ANDROID #define CHECK_CORE_INDEX(COREINDEX) if (COREINDEX > (MAX_NUM_VPU_CORE-1) ) { break; } #else #define CHECK_CORE_INDEX(COREINDEX) if (COREINDEX > (MAX_NUM_VPU_CORE-1) ) { fprintf(stderr, "Invalid Core Index\n"); break; } #endif #define NUM_OF_BS_BUF 1 static Uint32 sizeInWord; static Uint16* pusBitCode; static char optYuvPath[256]; static void help(struct OptionExt *opt, const char *programName ) { int i; VLOG(INFO, "------------------------------------------------------------------------------\n"); VLOG(INFO, "%s(API v%d.%d.%d)\n", programName, API_VERSION_MAJOR, API_VERSION_MINOR, API_VERSION_PATCH); VLOG(INFO, "\tAll rights reserved by Chips&Media(C)\n"); VLOG(INFO, "\tSample program controlling the Chips&Media VPU\n"); VLOG(INFO, "------------------------------------------------------------------------------\n"); VLOG(INFO, "%s [option]\n", programName); VLOG(INFO, "-h help\n"); VLOG(INFO, "-n [num] output frame number\n"); VLOG(INFO, "-v print version information\n"); VLOG(INFO, "-c compare with golden bitstream\n"); for (i = 0;i < MAX_GETOPT_OPTIONS;i++) { if (opt[i].name == NULL) break; VLOG(INFO, "%s", opt[i].help); } } extern char *optarg; /* argument associated with option */ int TestEncoder(TestEncConfig *param) { EncHandle handle; EncOpenParam encOP; EncParam encParam; EncInitialInfo initialInfo; EncOutputInfo outputInfo; SecAxiUse secAxiUse; vpu_buffer_t vbStream[NUM_OF_BS_BUF]; Uint32 bsBufferCount = 1; Uint32 bsQueueIndex = 1; vpu_buffer_t vbReport; vpu_buffer_t vbReconFrameBuf[MAX_REG_FRAME]; vpu_buffer_t vbSourceFrameBuf[MAX_REG_FRAME]; int FrameBufSize; FrameBuffer fbSrc[ENC_SRC_BUF_NUM]; FrameBufferAllocInfo fbAllocInfo; int ret = RETCODE_SUCCESS; EncHeaderParam encHeaderParam; int srcFrameIdx = 0, frameIdx = 0; int srcFrameWidth, srcFrameHeight, srcFrameStride; int framebufStride = 0, framebufWidth = 0, framebufHeight = 0, mapType; int suc = 0; int regFrameBufCount = 0; int int_reason = 0, i; int timeoutCount = 0; int instIdx, coreIdx; MirrorDirection mirrorDirection; TestEncConfig encConfig; Int32 productId; Comparator comparatorBitStream = NULL; BitstreamReader bsReader = NULL; FrameBuffer fbRecon[MAX_REG_FRAME]; vpu_buffer_t vbRoi[MAX_REG_FRAME]; vpu_buffer_t vbCtuQp[MAX_REG_FRAME]; Uint8 ctuQpMapBuf[MAX_CTU_NUM]; // for encode host rbsp header vpu_buffer_t vbPrefixSeiNal[MAX_REG_FRAME]; vpu_buffer_t vbSuffixSeiNal[MAX_REG_FRAME]; vpu_buffer_t vbHrdRbsp; vpu_buffer_t vbVuiRbsp; #ifdef TEST_ENCODE_CUSTOM_HEADER vpu_buffer_t vbSeiNal[MAX_REG_FRAME]; vpu_buffer_t vbCustomHeader; #endif Uint8 roiMapBuf[MAX_CTU_NUM]; void* yuvFeeder = NULL; FrameBufferFormat srcFrameFormat; YuvInfo yuvFeederInfo; Uint32 interruptTimeout = VPU_ENC_TIMEOUT; #ifdef TEST_ENCODE_CUSTOM_HEADER hrd_t hrd; #endif osal_memcpy(&encConfig, param, sizeof(TestEncConfig)); osal_memset(&yuvFeederInfo, 0x00, sizeof(YuvInfo)); osal_memset(&fbSrc[0], 0x00, sizeof(fbSrc)); osal_memset(&fbRecon[0], 0x00, sizeof(fbRecon)); osal_memset(vbReconFrameBuf, 0x00, sizeof(vbReconFrameBuf)); osal_memset(vbSourceFrameBuf, 0x00, sizeof(vbSourceFrameBuf)); osal_memset(&encOP, 0x00, sizeof(EncOpenParam)); osal_memset(&encParam, 0x00, sizeof(EncParam)); osal_memset(&initialInfo, 0x00, sizeof(EncInitialInfo)); osal_memset(&outputInfo, 0x00, sizeof(EncOutputInfo)); osal_memset(&secAxiUse, 0x00, sizeof(SecAxiUse)); osal_memset(vbStream, 0x00, sizeof(vbStream)); osal_memset(&vbReport, 0x00, sizeof(vpu_buffer_t)); osal_memset(&encHeaderParam, 0x00, sizeof(EncHeaderParam)); osal_memset(vbRoi, 0x00, sizeof(vbRoi)); osal_memset(vbCtuQp, 0x00, sizeof(vbCtuQp)); osal_memset(vbPrefixSeiNal, 0x00, sizeof(vbPrefixSeiNal)); osal_memset(vbSuffixSeiNal, 0x00, sizeof(vbSuffixSeiNal)); osal_memset(&vbVuiRbsp, 0x00, sizeof(vpu_buffer_t)); osal_memset(&vbHrdRbsp, 0x00, sizeof(vpu_buffer_t)); #ifdef TEST_ENCODE_CUSTOM_HEADER osal_memset(vbSeiNal, 0x00, sizeof(vbSeiNal)); osal_memset(&vbCustomHeader, 0x00, sizeof(vpu_buffer_t)); #endif instIdx = encConfig.instNum; coreIdx = encConfig.coreIdx; productId = VPU_GetProductId(coreIdx); ret = VPU_InitWithBitcode(coreIdx, pusBitCode, sizeInWord); if (ret != RETCODE_CALLED_BEFORE && ret != RETCODE_SUCCESS) { VLOG(ERR, "Failed to boot up VPU(coreIdx: %d, productId: %d)\n", coreIdx, productId); goto ERR_ENC_INIT; } PrintVpuVersionInfo(coreIdx); encOP.bitstreamFormat = encConfig.stdMode; mapType = (encConfig.mapType & 0x0f); if (strlen(encConfig.cfgFileName) != 0) { ret = GetEncOpenParam(&encOP, &encConfig, NULL); } else { ret = GetEncOpenParamDefault(&encOP, &encConfig); } if (ret == 0) goto ERR_ENC_INIT; srcFrameWidth = ((encOP.picWidth+7)&~7); // width = 8-aligned (CU unit) srcFrameHeight = ((encOP.picHeight+7)&~7); // height = 8-aligned (CU unit) srcFrameStride = ((encOP.picWidth+31)&~31); // stride should be a 32-aligned. /* Set user's options */ if (optYuvPath[0] != 0) strcpy(encConfig.yuvFileName, optYuvPath); if (strlen(encConfig.cfgFileName) != 0) { if (encOP.srcBitDepth == 8) { encConfig.srcFormat = FORMAT_420; } else if (encOP.srcBitDepth == 10) { encConfig.srcFormat = FORMAT_420_P10_16BIT_LSB; if (encConfig.yuv_mode == YUV_MODE_YUV_LOADER) { VLOG(INFO, "Need to check YUV style.\n"); encConfig.srcFormat = FORMAT_420_P10_16BIT_MSB; } if (encConfig.srcFormat3p4b == 1) { encConfig.srcFormat = FORMAT_420_P10_32BIT_MSB; } if (encConfig.srcFormat3p4b == 2) { encConfig.srcFormat = FORMAT_420_P10_32BIT_LSB; } } } if (encConfig.packedFormat >= 1) encConfig.srcFormat = FORMAT_422; if (encConfig.srcFormat == FORMAT_422 && encConfig.packedFormat >= PACKED_YUYV) { int p10bits = encConfig.srcFormat3p4b == 0 ? 16 : 32; int packedFormat = GetPackedFormat(encOP.srcBitDepth, encConfig.packedFormat, p10bits, 1); if (packedFormat == -1) { VLOG(ERR, "fail to GetPackedFormat\n" ); goto ERR_ENC_INIT; } encOP.srcFormat = packedFormat; srcFrameFormat = (FrameBufferFormat)packedFormat; encOP.nv21 = 0; encOP.cbcrInterleave = 0; } else { encOP.srcFormat = encConfig.srcFormat; srcFrameFormat = (FrameBufferFormat)encConfig.srcFormat; encOP.nv21 = encConfig.nv21; } encOP.packedFormat = encConfig.packedFormat; framebufWidth = (encOP.picWidth +7)&~7; framebufHeight = (encOP.picHeight +7)&~7; if ((encConfig.rotAngle != 0 || encConfig.mirDir != 0) && !(encConfig.rotAngle== 180 && encConfig.mirDir == MIRDIR_HOR_VER)) { framebufWidth = (encOP.picWidth +31)&~31; framebufHeight = (encOP.picHeight +31)&~31; } if (encConfig.rotAngle == 90 || encConfig.rotAngle == 270) { framebufWidth = (encOP.picHeight +31)&~31; framebufHeight = (encOP.picWidth +31)&~31; } bsBufferCount = NUM_OF_BS_BUF; for (i=0; i 0 && encConfig.refLongtermPeriod > 0) ? 1 : 0; // host can set useLongTerm to 1 or 0 directly. if (writeVuiRbsp(coreIdx, &encConfig, &encOP, &vbVuiRbsp) == FALSE) goto ERR_ENC_INIT; if (writeHrdRbsp(coreIdx, &encConfig, &encOP, &vbHrdRbsp) == FALSE) goto ERR_ENC_INIT; #ifdef TEST_ENCODE_CUSTOM_HEADER if (writeCustomHeader(coreIdx, &encOP, &vbCustomHeader, &hrd) == FALSE) goto ERR_ENC_INIT; #endif // Open an instance and get initial information for encoding. ret = VPU_EncOpen(&handle, &encOP); if (ret != RETCODE_SUCCESS) { VLOG(ERR, "VPU_EncOpen failed Error code is 0x%x \n", ret ); goto ERR_ENC_INIT; } //VPU_EncGiveCommand(handle, ENABLE_LOGGING, 0); if (encConfig.rotAngle != 0 || encConfig.mirDir != 0) { VPU_EncGiveCommand(handle, ENABLE_ROTATION, 0); VPU_EncGiveCommand(handle, ENABLE_MIRRORING, 0); VPU_EncGiveCommand(handle, SET_ROTATION_ANGLE, &encConfig.rotAngle); mirrorDirection = (MirrorDirection)encConfig.mirDir; VPU_EncGiveCommand(handle, SET_MIRROR_DIRECTION, &mirrorDirection); } ret = VPU_EncGetInitialInfo(handle, &initialInfo); if (ret != RETCODE_SUCCESS) { VLOG(ERR, "VPU_EncGetInitialInfo failed Error code is 0x%x \n", ret ); goto ERR_ENC_OPEN; } VLOG(INFO, "* Enc InitialInfo =>\n instance #%d, \n minframeBuffercount: %u\n minSrcBufferCount: %d\n", instIdx, initialInfo.minFrameBufferCount, initialInfo.minSrcFrameCount); VLOG(INFO, " picWidth: %u\n picHeight: %u\n ",encOP.picWidth, encOP.picHeight); if (encConfig.compare_type & (1<sourceLBurstEn = 0;///??? } if( encOP.ringBufferEnable == FALSE) { bsQueueIndex = (bsQueueIndex+1)%bsBufferCount; encParam.picStreamBufferAddr = vbStream[bsQueueIndex].phys_addr; // can set the newly allocated buffer. encParam.picStreamBufferSize = encOP.bitstreamBufferSize; } if ( (encConfig.seiDataEnc.prefixSeiNalEnable || encConfig.seiDataEnc.suffixSeiNalEnable) && encParam.srcEndFlag != 1) { { Uint8 *pUserBuf; pUserBuf = (Uint8*)osal_malloc(SEI_NAL_DATA_BUF_SIZE); osal_memset(pUserBuf, 0, SEI_NAL_DATA_BUF_SIZE); osal_fread(pUserBuf, 1, encConfig.seiDataEnc.prefixSeiDataSize, encConfig.prefix_sei_nal_fp); vdi_write_memory(coreIdx, vbPrefixSeiNal[srcFrameIdx].phys_addr, pUserBuf, encConfig.seiDataEnc.prefixSeiDataSize, encOP.streamEndian); osal_free(pUserBuf); } { Uint8 *pUserBuf; pUserBuf = (Uint8*)osal_malloc(SEI_NAL_DATA_BUF_SIZE); osal_memset(pUserBuf, 0, SEI_NAL_DATA_BUF_SIZE); osal_fread(pUserBuf, 1, encConfig.seiDataEnc.suffixSeiDataSize, encConfig.suffix_sei_nal_fp); vdi_write_memory(coreIdx, vbSuffixSeiNal[srcFrameIdx].phys_addr, pUserBuf, encConfig.seiDataEnc.suffixSeiDataSize, encOP.streamEndian); osal_free(pUserBuf); } encConfig.seiDataEnc.prefixSeiNalAddr = vbPrefixSeiNal[srcFrameIdx].phys_addr; encConfig.seiDataEnc.suffixSeiNalAddr = vbSuffixSeiNal[srcFrameIdx].phys_addr; VPU_EncGiveCommand(handle, ENC_SET_SEI_NAL_DATA, &encConfig.seiDataEnc); } osal_memset(&encParam.ctuOptParam, 0, sizeof(HevcCtuOptParam)); setRoiMap(coreIdx, &encConfig, encOP, vbRoi[srcFrameIdx].phys_addr, &roiMapBuf[0], srcFrameWidth, srcFrameHeight, &encParam, MAX_CTU_NUM); setCtuQpMap(coreIdx, &encConfig, encOP, vbCtuQp[srcFrameIdx].phys_addr, &ctuQpMapBuf[0], srcFrameWidth, srcFrameHeight, &encParam, MAX_CTU_NUM); #ifdef TEST_ENCODE_CUSTOM_HEADER if (writeSeiNalData(handle, encOP.streamEndian, vbSeiNal[srcFrameIdx].phys_addr, &hrd) == FALSE) { goto ERR_ENC_OPEN; } #endif if (encConfig.useAsLongtermPeriod > 0 && encConfig.refLongtermPeriod > 0) { encParam.useCurSrcAsLongtermPic = (frameIdx % encConfig.useAsLongtermPeriod) == 0 ? 1 : 0; encParam.useLongtermRef = (frameIdx % encConfig.refLongtermPeriod) == 0 ? 1 : 0; } // Start encoding a frame. frameIdx++; ret = VPU_EncStartOneFrame(handle, &encParam); if(ret != RETCODE_SUCCESS) { VLOG(ERR, "VPU_EncStartOneFrame failed Error code is 0x%x \n", ret ); LeaveLock(coreIdx); goto ERR_ENC_OPEN; } timeoutCount = 0; while (TRUE) { int_reason = VPU_WaitInterrupt(coreIdx, VPU_WAIT_TIME_OUT); if (int_reason == -1) { if (interruptTimeout > 0 && timeoutCount*VPU_WAIT_TIME_OUT > interruptTimeout) { VLOG(ERR, "Error : encoder timeout happened\n"); PrintVpuStatus(coreIdx, productId); VPU_SWReset(coreIdx, SW_RESET_SAFETY, handle); break; } int_reason = 0; timeoutCount++; } if (encOP.ringBufferEnable == TRUE) { if (!BitstreamReader_Act(bsReader, encOP.bitstreamBuffer, encOP.bitstreamBufferSize, STREAM_READ_SIZE, comparatorBitStream)) { PrintVpuStatus(coreIdx, productId); break; } } if (int_reason & (1<= 0) { VLOG(ERR, "ERROR!!! bitstreamsize = 0 \n"); } if (encOP.lineBufIntEn == 0) { if (outputInfo.wrPtr < outputInfo.rdPtr) { VLOG(ERR, "wrptr < rdptr\n"); goto ERR_ENC_OPEN; } } if ( outputInfo.bitstreamSize ) { EnterLock(coreIdx); ret = BitstreamReader_Act(bsReader, outputInfo.bitstreamBuffer, encOP.bitstreamBufferSize, outputInfo.bitstreamSize, comparatorBitStream); LeaveLock(coreIdx); if (ret == FALSE) { goto ERR_ENC_OPEN; } } } if (outputInfo.reconFrameIndex == -1) // end of encoding { break; } #ifdef ENC_RECON_FRAME_DISPLAY SimpleRenderer_Act(); #endif if (frameIdx > (encConfig.outNum-1)) encParam.srcEndFlag = 1; } if( encOP.ringBufferEnable == 1 ) { EnterLock(coreIdx); ret = BitstreamReader_Act(bsReader, encOP.bitstreamBuffer, encOP.bitstreamBufferSize, 0, comparatorBitStream); LeaveLock(coreIdx); if (ret == FALSE) { EnterLock(coreIdx); PrintVpuStatus(coreIdx, productId); LeaveLock(coreIdx); goto ERR_ENC_OPEN; } } if (param->outNum == 0) { if (comparatorBitStream) { if (Comparator_CheckEOF(comparatorBitStream) == FALSE) { VLOG(ERR, "MISMATCH BitStream data size. There is still data to compare.\n"); goto ERR_ENC_OPEN; } } } suc = 1; ERR_ENC_OPEN: // Now that we are done with encoding, close the open instance. for (i = 0; i < regFrameBufCount; i++) { if (vbReconFrameBuf[i].size > 0) { vdi_free_dma_memory(coreIdx, &vbReconFrameBuf[i]); } } for (i = 0; i < fbAllocInfo.num; i++) { if (vbSourceFrameBuf[i].size > 0) { vdi_free_dma_memory(coreIdx, &vbSourceFrameBuf[i]); } if (vbRoi[i].size) { vdi_free_dma_memory(coreIdx, &vbRoi[i]); } if (vbCtuQp[i].size) { vdi_free_dma_memory(coreIdx, &vbCtuQp[i]); } if (vbPrefixSeiNal[i].size) vdi_free_dma_memory(coreIdx, &vbPrefixSeiNal[i]); if (vbSuffixSeiNal[i].size) vdi_free_dma_memory(coreIdx, &vbSuffixSeiNal[i]); #ifdef TEST_ENCODE_CUSTOM_HEADER if (vbSeiNal[i].size) vdi_free_dma_memory(coreIdx, &vbSeiNal[i]); #endif } if (vbHrdRbsp.size) vdi_free_dma_memory(coreIdx, &vbHrdRbsp); if (vbVuiRbsp.size) vdi_free_dma_memory(coreIdx, &vbVuiRbsp); #ifdef TEST_ENCODE_CUSTOM_HEADER if (vbCustomHeader.size) vdi_free_dma_memory(coreIdx, &vbCustomHeader); #endif if (encConfig.prefix_sei_nal_fp) osal_fclose(encConfig.prefix_sei_nal_fp); if (encConfig.suffix_sei_nal_fp) osal_fclose(encConfig.suffix_sei_nal_fp); if (encConfig.vui_rbsp_fp) osal_fclose(encConfig.vui_rbsp_fp); if (encConfig.hrd_rbsp_fp) osal_fclose(encConfig.hrd_rbsp_fp); if (encConfig.roi_file) osal_fclose(encConfig.roi_file); VPU_EncClose(handle); VLOG(INFO, "\ninst %d Enc End. Tot Frame %d\n" , instIdx, outputInfo.encPicCnt); ERR_ENC_INIT: for (i=0; i< bsBufferCount ; i++) { if (vbStream[i].size) vdi_free_dma_memory(coreIdx, &vbStream[i]); } if (vbReport.size) vdi_free_dma_memory(coreIdx, &vbReport); if (comparatorBitStream != NULL) { Comparator_Destroy(comparatorBitStream); osal_free(comparatorBitStream); } BitstreamReader_Destroy(bsReader); if (yuvFeeder != NULL) { YuvFeeder_Destroy(yuvFeeder); osal_free(yuvFeeder); } VPU_DeInit(coreIdx); return suc; } int main(int argc, char **argv) { Uint32 productId; BOOL showVersion = FALSE; BOOL debugMode = FALSE; int opt, index, ret = 0, i; TestEncConfig encConfig; struct option options[MAX_GETOPT_OPTIONS]; struct OptionExt options_help[] = { {"output", 1, NULL, 0, "--output bitstream path\n"}, {"input", 1, NULL, 0, "--input YUV file path. The value of InputFile in a cfg is replaced to this value.\n"}, {"codec", 1, NULL, 0, "--codec codec index, HEVC: 12\n"}, {"cfgFileName", 1, NULL, 0, "--cfgFileName cfg file path\n"}, {"coreIdx", 1, NULL, 0, "--coreIdx core index: default 0\n"}, {"picWidth", 1, NULL, 0, "--picWidth source width\n"}, {"picHeight", 1, NULL, 0, "--picHeight source height\n"}, {"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"}, {"enable-ringBuffer", 0, NULL, 0, "--enable-ringBuffer enable stream ring buffer mode\n"}, {"enable-lineBufInt", 0, NULL, 0, "--enable-lineBufInt enable linebuffer interrupt\n"}, {"mapType", 1, NULL, 0, "--mapType mapType\n"}, {"loop-count", 1, NULL, 0, "--loop-count integer number. loop test, default 0\n"}, {"enable-cbcrInterleave", 0, NULL, 0, "--enable-cbcrInterleave enable cbcr interleave\n"}, {"nv21", 1, NULL, 0, "--nv21 enable NV21(must set enable-cbcrInterleave)\n"}, {"packedFormat", 1, NULL, 0, "--packedFormat 1:YUYV, 2:YVYU, 3:UYVY, 4:VYUY\n"}, {"rotAngle", 1, NULL, 0, "--rotAngle rotation angle(0,90,180,270), Not supported on WAVE420L\n"}, {"mirDir", 1, NULL, 0, "--mirDir 1:Vertical, 2: Horizontal, 3:Vert-Horz, Not supported on WAVE420L\n"}, /* 20 */ {"secondary-axi", 1, NULL, 0, "--secondary-axi 0~7: bit mask values, Please refer programmer's guide or datasheet\n" " 1:IMD(not supported on WAVE420L), 2: RDO, 4: LF\n"}, {"frame-endian", 1, NULL, 0, "--frame-endian 16~31, default 31(LE) Please refer programmer's guide or datasheet\n"}, {"stream-endian", 1, NULL, 0, "--stream-endian 16~31, default 31(LE) Please refer programmer's guide or datasheet\n"}, {"source-endian", 1, NULL, 0, "--source-endian 16~31, default 31(LE) Please refer programmer's guide or datasheet\n"}, {"ref_stream_path", 1, NULL, 0, "--ref_stream_path golden data which is compared with encoded stream when -c option\n"}, {"srcFormat3p4b", 1, NULL, 0, "--srcFormat3p4b [WAVE420]This option MUST BE enabled when format of source yuv is 3pixel 4byte format\n"}, {NULL, 0, NULL, 0}, }; char* optString = "rbhvn:"; char* fwPath = NULL; InitLog(); //default setting. osal_memset(&encConfig, 0, sizeof(encConfig)); encConfig.stdMode = STD_HEVC; encConfig.frame_endian = VPU_FRAME_ENDIAN; encConfig.stream_endian = VPU_STREAM_ENDIAN; encConfig.source_endian = VPU_SOURCE_ENDIAN; encConfig.mapType = COMPRESSED_FRAME_MAP; for (i = 0; i < MAX_GETOPT_OPTIONS;i++) { if (options_help[i].name == NULL) break; osal_memcpy(&options[i], &options_help[i], sizeof(struct option)); } while ((opt=getopt_long(argc, argv, optString, options, &index)) != -1) { switch (opt) { case 'n': encConfig.outNum = atoi(optarg); break; case 'c': encConfig.compare_type |= (1 << MODE_COMP_ENCODED); VLOG(ERR,"Stream compare Enable\n"); break; case 'h': help(options_help, argv[0]); return 0; break; case 'v': showVersion = TRUE; break; case 0: if (!strcmp(options[index].name, "output")) { osal_memcpy(encConfig.bitstreamFileName, optarg, strlen(optarg)); ChangePathStyle(encConfig.bitstreamFileName); } else if (!strcmp(options[index].name, "input")) { strcpy(optYuvPath, optarg); ChangePathStyle(optYuvPath); } else if (!strcmp(options[index].name, "codec")) { encConfig.stdMode = (CodStd)atoi(optarg); } else if (!strcmp(options[index].name, "cfgFileName")) { osal_memcpy(encConfig.cfgFileName, optarg, strlen(optarg)); } else if (!strcmp(options[index].name, "coreIdx")) { encConfig.coreIdx = atoi(optarg); } else if (!strcmp(options[index].name, "picWidth")) { encConfig.picWidth = atoi(optarg); } else if (!strcmp(options[index].name, "picHeight")) { encConfig.picHeight = atoi(optarg); } else if (!strcmp(options[index].name, "kbps")) { encConfig.kbps = atoi(optarg); } else if (!strcmp(options[index].name, "enable-ringBuffer")) { encConfig.ringBufferEnable = TRUE; } else if (!strcmp(options[index].name, "enable-lineBufInt")) { encConfig.lineBufIntEn = TRUE; } else if (!strcmp(options[index].name, "loop-count")) { encConfig.loopCount = atoi(optarg); } else if (!strcmp(options[index].name, "enable-cbcrInterleave")) { encConfig.cbcrInterleave = 1; } else if (!strcmp(options[index].name, "nv21")) { encConfig.nv21 = atoi(optarg); } else if (!strcmp(options[index].name, "packedFormat")) { encConfig.packedFormat = atoi(optarg); } else if (!strcmp(options[index].name, "rotAngle")) { encConfig.rotAngle = atoi(optarg); } else if (!strcmp(options[index].name, "mirDir")) { encConfig.mirDir = atoi(optarg); } else if (!strcmp(options[index].name, "secondary-axi")) { encConfig.secondary_axi = atoi(optarg); } else if (!strcmp(options[index].name, "frame-endian")) { encConfig.frame_endian = atoi(optarg); } else if (!strcmp(options[index].name, "stream-endian")) { encConfig.stream_endian = atoi(optarg); } else if (!strcmp(options[index].name, "source-endian")) { encConfig.source_endian = atoi(optarg); } else if (!strcmp(options[index].name, "ref_stream_path")) { osal_memcpy(encConfig.ref_stream_path, optarg, strlen(optarg)); ChangePathStyle(encConfig.ref_stream_path); } else if (!strcmp(options[index].name, "srcFormat3p4b")) { encConfig.srcFormat3p4b = atoi(optarg); } else { VLOG(ERR, "not exist param = %s\n", options[index].name); help(options_help, argv[0]); return 1; } break; default: help(options_help, argv[0]); return 1; } } productId = VPU_GetProductId(encConfig.coreIdx); if (checkParamRestriction(productId, &encConfig) == FALSE) return 1; switch (productId) { case PRODUCT_ID_420: fwPath = CORE_0_BIT_CODE_FILE_PATH; break; case PRODUCT_ID_420L: fwPath = CORE_5_BIT_CODE_FILE_PATH; break; case PRODUCT_ID_520: fwPath = CORE_9_BIT_CODE_FILE_PATH; break; default: VLOG(ERR, "Unknown product id: %d\n", productId); return 1; } VLOG(INFO, "FW PATH = %s\n", fwPath); if (LoadFirmware(productId, (Uint8**)&pusBitCode, &sizeInWord, fwPath) < 0) { VLOG(ERR, "%s:%d Failed to load firmware: %s\n", __FUNCTION__, __LINE__, fwPath); return 1; } if (showVersion == TRUE || debugMode == TRUE) { Uint32 ver, rev; ret = VPU_InitWithBitcode(encConfig.coreIdx, (const Uint16*)pusBitCode, sizeInWord); if (ret != RETCODE_CALLED_BEFORE && ret != RETCODE_SUCCESS) { VLOG(ERR, "Failed to boot up VPU(coreIdx: %d, productId: %d)\n", __FUNCTION__, __LINE__, encConfig.coreIdx, productId); osal_free(pusBitCode); return 1; } VPU_GetVersionInfo(encConfig.coreIdx, &ver, &rev, &productId); printf("VERSION=%d\n", ver); printf("REVISION=%d\n", rev); printf("PRODUCT_ID=%d\n", productId); if (showVersion == TRUE) { osal_free(pusBitCode); VPU_DeInit(encConfig.coreIdx); return 0; } } osal_init_keyboard(); InitializeDebugEnv(productId, encConfig.testEnvOptions); ret = TestEncoder(&encConfig); ReleaseDebugEnv(); if (debugMode == TRUE) { VPU_DeInit(encConfig.coreIdx); } osal_close_keyboard(); osal_free(pusBitCode); return ret == 1 ? 0 : 1; }