//----------------------------------------------------------------------------- // COPYRIGHT (C) 2020 CHIPS&MEDIA INC. ALL RIGHTS RESERVED // // This file is distributed under BSD 3 clause and LGPL2.1 (dual license) // SPDX License Identifier: BSD-3-Clause // SPDX License Identifier: LGPL-2.1-only // // The entire notice above must be reproduced on all authorized copies. // // Description : //----------------------------------------------------------------------------- #include #include #include #include #include #include "vpuapifunc.h" #include "wave5_regdefine.h" #include "vpuerror.h" #include "main_helper.h" #include "misc/debug.h" #include "cnm_app.h" #include "encoder_listener.h" #include "decoder_listener.h" #include "nc_utils.h" #include #include #if defined(PLATFORM_NON_OS) || defined (PLATFORM_LINUX) #include #endif #if defined(PLATFORM_LINUX) || defined(PLATFORM_QNX) || defined(PLATFORM_NON_OS) #include #include #endif #define MAX_CODE_BUF_SIZE (512*1024) #define MQ_NAME_DATA_TO_ENCODE "/data_to_encode" #define MQ_NAME_DATA_TO_DECODE "/data_to_decode" #ifdef PLATFORM_WIN32 #pragma warning(disable : 4996) //!<< disable waring C4996: The POSIX name for this item is deprecated. #endif #define MAX_MQ_SIZE_DEC (10) #define MAX_MQ_SIZE_ENC (10) static int32 auto_free_data_for_decode = 0; static int32 auto_free_data_for_encode = 0; pthread_mutex_t encoded_lock = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t decoded_lock = PTHREAD_MUTEX_INITIALIZER; static struct CNMComponentConfig enc_config; static struct CNMComponentConfig dec_config; const char* EncPicTypeStringH264[] = { "IDR/I", "P", }; const char* EncPicTypeStringMPEG4[] = { "I", "P", }; void SetDefaultDecTestConfig(TestDecConfig* testConfig) { osal_memset(testConfig, 0, sizeof(TestDecConfig)); testConfig->bitstreamMode = BS_MODE_INTERRUPT; testConfig->feedingMode = FEEDING_METHOD_FIXED_SIZE; testConfig->streamEndian = VPU_STREAM_ENDIAN; testConfig->frameEndian = VPU_FRAME_ENDIAN; testConfig->cbcrInterleave = TRUE; testConfig->nv21 = FALSE; testConfig->renderType = RENDER_DEVICE_NULL; testConfig->mapType = COMPRESSED_FRAME_MAP; testConfig->enableWTL = TRUE; testConfig->wtlMode = FF_FRAME; testConfig->wtlFormat = FORMAT_420; //!<< 8 bit YUV // testConfig->wtlFormat = FORMAT_422; //!<< 8 bit YUV testConfig->wave.av1Format = 0; testConfig->fps = 30; } void Coda9SetDefaultDecTestConfig(TestDecConfig* testConfig) { osal_memset(testConfig, 0, sizeof(TestDecConfig)); testConfig->bitstreamMode = BS_MODE_INTERRUPT; testConfig->feedingMode = FEEDING_METHOD_FIXED_SIZE; testConfig->streamEndian = VPU_STREAM_ENDIAN; testConfig->frameEndian = VPU_FRAME_ENDIAN; testConfig->cbcrInterleave = FALSE; testConfig->nv21 = FALSE; testConfig->bitFormat = STD_AVC; testConfig->renderType = RENDER_DEVICE_NULL; testConfig->mapType = LINEAR_FRAME_MAP; testConfig->wtlMode = FF_NONE; testConfig->enableWTL = FALSE; testConfig->wtlFormat = FORMAT_420; //!<< 8 bit YUV testConfig->fps = 30; testConfig->coda9.frameCacheBypass = 0; testConfig->coda9.frameCacheBurst = 0; testConfig->coda9.frameCacheMerge = 3; testConfig->coda9.frameCacheWayShape = 15; testConfig->coda9.rotate = 0; testConfig->coda9.mirror = 0; testConfig->coda9.enableTiled2Linear = FALSE; testConfig->coda9.tiled2LinearMode = FF_NONE; testConfig->coda9.enableDering = FALSE; testConfig->coda9.enableBWB = TRUE; } Uint32 randomSeed; static BOOL initializedRandom; Uint32 GetRandom( Uint32 start, Uint32 end ) { Uint32 range = end-start+1; if (randomSeed == 0) { randomSeed = (Uint32)time(NULL); VLOG(INFO, "======= RANDOM SEED: %08x ======\n", randomSeed); } if (initializedRandom == FALSE) { srand(randomSeed); initializedRandom = TRUE; } if (range == 0) { VLOG(ERR, "%s:%d RANGE IS 0\n", __FUNCTION__, __LINE__); return 0; } else { return ((rand()%range) + start); } } Int32 LoadFirmware( Int32 productId, Uint8** retFirmware, Uint32* retSizeInWord, const char* path ) { Int32 nread; Uint32 totalRead, allocSize, readSize = WAVE5_MAX_CODE_BUF_SIZE; Uint8* firmware = NULL; osal_file_t fp; if ((fp=osal_fopen(path, "rb")) == NULL) { VLOG(ERR, "Failed to open %s\n", path); return -1; } totalRead = 0; if (PRODUCT_ID_W_SERIES(productId)) { firmware = (Uint8*)osal_malloc(readSize); allocSize = readSize; nread = 0; while (TRUE) { if (allocSize < (totalRead+readSize)) { allocSize += 2*nread; firmware = (Uint8*)realloc(firmware, allocSize); } nread = (Int32)osal_fread((void*)&firmware[totalRead], 1, readSize, fp);//lint !e613 totalRead += nread; if (nread < (Int32)readSize) break; } *retSizeInWord = (totalRead+1)/2; } else { Uint16* pusBitCode; pusBitCode = (Uint16 *)osal_malloc(MAX_CODE_BUF_SIZE); firmware = (Uint8*)pusBitCode; if (pusBitCode) { Uint32 code; while (!osal_feof((FILE*)fp) || totalRead < (MAX_CODE_BUF_SIZE/2)) { code = -1; if (fscanf((FILE*)fp, "%x", &code) <= 0) { /* matching failure or EOF */ break; } pusBitCode[totalRead++] = (Uint16)code; } } *retSizeInWord = totalRead; } osal_fclose(fp); *retFirmware = firmware; return 0; } void PrintVpuVersionInfo( Uint32 core_idx ) { Uint32 version; Uint32 revision; Uint32 productId; VPU_GetVersionInfo(core_idx, &version, &revision, &productId); VLOG(INFO, "VPU coreNum : [%d]\n", core_idx); VLOG(INFO, "Firmware : CustomerCode: %04x | version : %d.%d.%d rev.%d\n", (Uint32)(version>>16), (Uint32)((version>>(12))&0x0f), (Uint32)((version>>(8))&0x0f), (Uint32)((version)&0xff), revision); VLOG(INFO, "Hardware : %04x\n", productId); VLOG(INFO, "API : %d.%d.%d\n\n", API_VERSION_MAJOR, API_VERSION_MINOR, API_VERSION_PATCH); } BOOL OpenDisplayBufferFile(CodStd codec, char *outputPath, VpuRect rcDisplay, TiledMapType mapType, FILE *fp[]) { char strFile[MAX_FILE_PATH]; int width; int height; width = rcDisplay.right - rcDisplay.left; height = rcDisplay.bottom - rcDisplay.top; if (mapType == LINEAR_FRAME_MAP) { if ((fp[0]=(FILE*)osal_fopen(outputPath, "wb")) == NULL) { VLOG(ERR, "%s:%d failed to open %s\n", __FUNCTION__, __LINE__, outputPath); goto ERR_OPEN_DISP_BUFFER_FILE; } } else { width = (codec == STD_HEVC || codec == STD_AVS2) ? VPU_ALIGN16(width) : VPU_ALIGN64(width); height = (codec == STD_HEVC || codec == STD_AVS2) ? VPU_ALIGN16(height) : VPU_ALIGN64(height); sprintf(strFile, "%s_%dx%d_fbc_data_y.bin", outputPath, width, height); if ((fp[0]=(FILE*)osal_fopen(strFile, "wb")) == NULL) { VLOG(ERR, "%s:%d failed to open %s\n", __FUNCTION__, __LINE__, strFile); goto ERR_OPEN_DISP_BUFFER_FILE; } sprintf(strFile, "%s_%dx%d_fbc_data_c.bin", outputPath, width, height); if ((fp[1]=(FILE*)osal_fopen(strFile, "wb")) == NULL) { VLOG(ERR, "%s:%d failed to open %s\n", __FUNCTION__, __LINE__, strFile); goto ERR_OPEN_DISP_BUFFER_FILE; } sprintf(strFile, "%s_%dx%d_fbc_table_y.bin", outputPath, width, height); if ((fp[2]=(FILE*)osal_fopen(strFile, "wb")) == NULL) { VLOG(ERR, "%s:%d failed to open %s\n", __FUNCTION__, __LINE__, strFile); goto ERR_OPEN_DISP_BUFFER_FILE; } sprintf(strFile, "%s_%dx%d_fbc_table_c.bin", outputPath, width, height); if ((fp[3]=(FILE*)osal_fopen(strFile, "wb")) == NULL) { VLOG(ERR, "%s:%d failed to open %s\n", __FUNCTION__, __LINE__, strFile); goto ERR_OPEN_DISP_BUFFER_FILE; } } return TRUE; ERR_OPEN_DISP_BUFFER_FILE: CloseDisplayBufferFile(fp); return FALSE; } void CloseDisplayBufferFile(FILE *fp[]) { int i; for (i=0; i < OUTPUT_FP_NUMBER; i++) { if (fp[i] != NULL) { osal_fclose(fp[i]); fp[i] = NULL; } } } Int32 CalculateAuxBufferSize(AUX_BUF_TYPE type, CodStd codStd, Int32 width, Int32 height) { Int32 size = 0; switch (type) { case AUX_BUF_TYPE_MVCOL: if (codStd == STD_AVC || codStd == STD_VC1 || codStd == STD_MPEG4 || codStd == STD_H263 || codStd == STD_RV || codStd == STD_AVS) { size = VPU_ALIGN32(width)*VPU_ALIGN32(height); size = (size * 3) / 2; size = (size + 4) / 5; size = ((size + 7) / 8) * 8; } else if (codStd == STD_HEVC) { size = WAVE5_DEC_HEVC_MVCOL_BUF_SIZE(width, height); } else if (codStd == STD_VP9) { size = WAVE5_DEC_VP9_MVCOL_BUF_SIZE(width, height); } else if (codStd == STD_AVS2) { size = WAVE5_DEC_AVS2_MVCOL_BUF_SIZE(width, height); } else if (codStd == STD_AV1) { size = WAVE5_DEC_AV1_MVCOL_BUF_SIZE(width, height); } else { size = 0; } break; case AUX_BUF_TYPE_FBC_Y_OFFSET: size = WAVE5_FBC_LUMA_TABLE_SIZE(width, height); break; case AUX_BUF_TYPE_FBC_C_OFFSET: size = WAVE5_FBC_CHROMA_TABLE_SIZE(width, height); break; } return size; } RetCode GetFBCOffsetTableSize(CodStd codStd, int width, int height, int* ysize, int* csize) { if (ysize == NULL || csize == NULL) return RETCODE_INVALID_PARAM; *ysize = CalculateAuxBufferSize(AUX_BUF_TYPE_FBC_Y_OFFSET, codStd, width, height); *csize = CalculateAuxBufferSize(AUX_BUF_TYPE_FBC_C_OFFSET, codStd, width, height); return RETCODE_SUCCESS; } RetCode GetPVRICRealSize(CodStd codStd __attribute__((unused)), TiledMapType mapType, FrameBufferFormat format, Uint32 width, Uint32 height, int* ysize, int* csize, Uint32* offset_luma, Uint32* offset_chroma, Uint32 frameWidth, Uint32 frameHeight) { Uint32 total_tile_num, hdr_size, data_size; Uint32 frame_total_tile_num, frame_hdr_size; if (ysize == NULL || csize == NULL) return RETCODE_INVALID_PARAM; switch (format) { case FORMAT_420: total_tile_num = (VPU_ALIGN64(width) >> 6) *(VPU_ALIGN4(height) >> 2);//width frame_total_tile_num = (VPU_ALIGN64(frameWidth) >> 6) *(VPU_ALIGN4(frameHeight) >> 2);//width break; default: /* 10bit */ total_tile_num = (width+47)/48 * (VPU_ALIGN4(height) >> 2); frame_total_tile_num = (frameWidth+47)/48 * (VPU_ALIGN4(frameHeight) >> 2); break; } hdr_size = VPU_ALIGN256(total_tile_num); frame_hdr_size = VPU_ALIGN256(frame_total_tile_num); if (frame_hdr_size >= hdr_size) { *offset_luma = frame_hdr_size - hdr_size; } if( mapType == PVRIC_COMPRESSED_FRAME_LOSSLESS_MAP ) { data_size = (total_tile_num*256); // byte } else { data_size = (total_tile_num*128); // byte } *ysize = (hdr_size + data_size); VLOG(INFO, "<%s> Input WidthxHeight : %dx%d \t luma h=%d(%x), d=%d(%x)\n", __FUNCTION__, width, height, hdr_size, hdr_size, data_size, data_size); switch (format) { case FORMAT_420: total_tile_num = (VPU_ALIGN64(width) >> 6) *(VPU_ALIGN4((height+1)/2) >> 2); frame_total_tile_num = (VPU_ALIGN64(frameWidth) >> 6) *(VPU_ALIGN4((frameHeight+1)/2) >> 2); break; default: /* 10bit */ total_tile_num = (width+47)/48 * (VPU_ALIGN4((height+1)/2) >> 2); frame_total_tile_num = (frameWidth+47)/48 * (VPU_ALIGN4((frameHeight+1)/2) >> 2); break; } hdr_size = VPU_ALIGN256(total_tile_num); frame_hdr_size = VPU_ALIGN256(frame_total_tile_num); if (frame_hdr_size >= hdr_size) { *offset_chroma = frame_hdr_size - hdr_size; } if( mapType == PVRIC_COMPRESSED_FRAME_LOSSLESS_MAP ) { data_size = (total_tile_num*256); // byte } else { data_size = (total_tile_num*128); // byte } *csize = (hdr_size + data_size); VLOG(INFO, "<%s> chroma h=%d(%x), d=%d(%x)\n", __FUNCTION__, hdr_size, hdr_size, data_size, data_size); return RETCODE_SUCCESS; } void ProcessVc1MultiResolution( Uint8* image, Int32 width, Int32 height, BOOL horz_half, BOOL vert_half ) { Int32 disX, disY; Int32 x, y; if (horz_half == 0 && vert_half == 0) { return; } disX = horz_half ? ((width+31)&~31)/2 : width; disY = vert_half ? ((height+31)&~31)/2 : height; for (y=0; y= disX || y >= disY) image[x+y*width] = 0; } } /* Cb */ image += width * height; width /= 2; height /= 2; disX /= 2; disY /= 2; for (y=0; y= disX || y >= disY) image[x+y*width] = 0; } } /* Cr */ image += width * height; for (y=0; y= disX || y >= disY) image[x+y*width] = 0; } } } static callback_t decoded_done_callback_ftnptr = NULL; static callback_t2 last_frame_decoded_callback_ftnptr = NULL; void nc_register_decode_callback(callback_t cb) { if (cb) { decoded_done_callback_ftnptr = cb; } else { printf("[%s:%d] ... Fail to register decoding callback function \n",__FUNCTION__,__LINE__); } } void call_decode_done_callback(Uint8* val, Uint32 size) { if (decoded_done_callback_ftnptr) { decoded_done_callback_ftnptr(val, size); } else { printf("[%s:%d] ... decoding callback function is NULL\n",__FUNCTION__,__LINE__); } } void nc_register_last_frame_decoded_callback(callback_t2 cb) { if (cb) { last_frame_decoded_callback_ftnptr = cb; } else { printf("[%s:%d] ... Fail to register last frame decoded callback function \n",__FUNCTION__,__LINE__); } } void call_last_frame_decoded_callback() { if (last_frame_decoded_callback_ftnptr) { last_frame_decoded_callback_ftnptr(); } else { printf("[%s:%d] ... last frame decoded callback function is NULL\n",__FUNCTION__,__LINE__); } } void SaveDisplayBufferToFile(DecHandle handle, CodStd codStd, RendererOutInfo* rendererOutInfo, FrameBuffer dispFrame, VpuRect rcDisplay, FILE *fp[]) { Uint32 width; Uint32 height; Uint32 bpp; DecGetFramebufInfo fbInfo; CodecInst * pCodecInst; pCodecInst = handle; if (dispFrame.myIndex < 0) return; if (dispFrame.mapType != COMPRESSED_FRAME_MAP) { size_t sizeYuv; Uint8* pYuv; pYuv = GetYUVFromFrameBuffer(handle, &dispFrame, rcDisplay, &width, &height, &bpp, &sizeYuv); if (STD_VC1 == codStd) { ProcessVc1MultiResolution(pYuv, rendererOutInfo->pOutInfo->decPicWidth, rendererOutInfo->pOutInfo->decPicHeight, rendererOutInfo->scaleX, rendererOutInfo->scaleY); } call_decode_done_callback(pYuv, (Uint32)sizeYuv); osal_free(pYuv); } else { Uint32 lumaTblSize; Uint32 chromaTblSize; Uint32 lSize; Uint32 cSize; Uint32 addr; Uint32 endian; Uint8* buf; Uint32 coreIdx = VPU_HANDLE_CORE_INDEX(handle); Uint32 productId = VPU_HANDLE_PRODUCT_ID(handle); Uint32 cFrameStride; VPU_DecGiveCommand(handle, DEC_GET_FRAMEBUF_INFO, (void*)&fbInfo); width = rcDisplay.right - rcDisplay.left; width = (codStd == STD_HEVC || codStd == STD_AVS2) ? VPU_ALIGN16(width) : VPU_ALIGN64(width); height = rcDisplay.bottom - rcDisplay.top; height = (codStd == STD_HEVC || codStd == STD_AVS2) ? VPU_ALIGN16(height) : VPU_ALIGN64(height); cFrameStride = CalcStride(width, height, dispFrame.format, dispFrame.cbcrInterleave, dispFrame.mapType, (codStd == STD_VP9)); lSize = CalcLumaSize(pCodecInst, productId, cFrameStride, height, dispFrame.format, dispFrame.cbcrInterleave, dispFrame.mapType, NULL); cSize = CalcChromaSize(pCodecInst, productId, cFrameStride, height, dispFrame.format, dispFrame.cbcrInterleave, dispFrame.mapType, NULL) * 2; // Invert the endian because the pixel order register doesn't affect the FBC data. endian = (~(Uint32)dispFrame.endian & 0xf) | 0x10; /* Dump Y compressed data */ if ((buf=(Uint8*)osal_malloc(lSize)) != NULL) { vdi_read_memory(coreIdx, dispFrame.bufY, buf, lSize, endian); osal_fwrite((void *)buf, sizeof(Uint8), lSize, fp[0]); osal_fflush(fp[0]); osal_free(buf); } else { VLOG(ERR, "%s:%d Failed to save the luma compressed data!!\n", __FUNCTION__, __LINE__); } /* Dump C compressed data */ if ((buf=(Uint8*)osal_malloc(cSize)) != NULL) { vdi_read_memory(coreIdx, dispFrame.bufCb, buf, cSize, endian); osal_fwrite((void *)buf, sizeof(Uint8), cSize, fp[1]); osal_fflush(fp[1]); osal_free(buf); } else { VLOG(ERR, "%s:%d Failed to save the chroma compressed data!!\n", __FUNCTION__, __LINE__); } /* Dump Y Offset table */ GetFBCOffsetTableSize(codStd, (int)width, (int)height, (int*)&lumaTblSize, (int*)&chromaTblSize); addr = fbInfo.vbFbcYTbl[dispFrame.myIndex].phys_addr; if ((buf=(Uint8*)osal_malloc(lumaTblSize)) != NULL) { vdi_read_memory(coreIdx, addr, buf, lumaTblSize, endian); osal_fwrite((void *)buf, sizeof(Uint8), lumaTblSize, fp[2]); osal_fflush(fp[2]); osal_free(buf); } else { VLOG(ERR, "%s:%d Failed to save the offset table of luma!\n", __FUNCTION__, __LINE__); } /* Dump C Offset table */ addr = fbInfo.vbFbcCTbl[dispFrame.myIndex].phys_addr; if ((buf=(Uint8*)osal_malloc(chromaTblSize)) != NULL) { vdi_read_memory(coreIdx, addr, buf, chromaTblSize, endian); osal_fwrite((void *)buf, sizeof(Uint8), chromaTblSize, fp[3]); osal_fflush(fp[3]); osal_free(buf); } else { VLOG(ERR, "%s:%d Failed to save the offset table of chroma!\n", __FUNCTION__, __LINE__); } } } void PrintDecSeqWarningMessages( Uint32 productId, DecInitialInfo* seqInfo ) { if (PRODUCT_ID_W_SERIES(productId)) { if (seqInfo->seqInitErrReason&0x00000001) VLOG(WARN, "sps_max_sub_layer_minus1 shall be 0 to 6\n"); if (seqInfo->seqInitErrReason&0x00000002) VLOG(WARN, "general_reserved_zero_44bits shall be 0.\n"); if (seqInfo->seqInitErrReason&0x00000004) VLOG(WARN, "reserved_zero_2bits shall be 0\n"); if (seqInfo->seqInitErrReason&0x00000008) VLOG(WARN, "sub_layer_reserved_zero_44bits shall be 0"); if (seqInfo->seqInitErrReason&0x00000010) VLOG(WARN, "general_level_idc shall have one of level of Table A.1\n"); if (seqInfo->seqInitErrReason&0x00000020) VLOG(WARN, "sps_max_dec_pic_buffering[i] <= MaxDpbSize\n"); if (seqInfo->seqInitErrReason&0x00000040) VLOG(WARN, "trailing bits shall be 1000... pattern, 7.3.2.1\n"); if (seqInfo->seqInitErrReason&0x00100000) VLOG(WARN, "Not supported or undefined profile: %d\n", seqInfo->profile); if (seqInfo->seqInitErrReason&0x00200000) VLOG(WARN, "Spec over level(%d)\n", seqInfo->level); } } void DisplayDecodedInformationForHevc( DecHandle handle, Uint32 frameNo, BOOL performance, DecOutputInfo* decodedInfo ) { Int32 logLevel; QueueStatusInfo queueStatus; PhysicalAddress frameSize = 0, frameStAddr = 0, frameEdAddr = 0; VPU_DecGiveCommand(handle, DEC_GET_QUEUE_STATUS, &queueStatus); if (decodedInfo == NULL) { if ( performance == TRUE ) { VLOG(INFO, " | FRAME | HOST | SEEK_S SEEK_E SEEK | PARSE_S PARSE_E PARSE | DEC_S DEC_E DEC |\n"); VLOG(INFO, "I NO T POC NAL DECO DISP DISPFLAG RD_PTR WR_PTR FRM_START FRM_END FRM_SIZE WxH SEQ TEMP | CYCLE | TICK | TICK TICK CYCLE | TICK TICK CYCLE | TICK TICK CYCLE | RQ IQ VCore\n"); VLOG(INFO, "-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n"); } else { VLOG(INFO, "I NO T POC NAL DECO DISP DISPFLAG RD_PTR WR_PTR FRM_START FRM_END FRM_SIZE WxH SEQ TEMP CYCLE ( Seek, Parse, Dec) RQ IQ VCore\n"); VLOG(INFO, "---------------------------------------------------------------------------------------------------------------------------------------------------------------------\n"); } } else { logLevel = (decodedInfo->decodingSuccess&0x01) == 0 ? WARN : INFO; frameStAddr = decodedInfo->bytePosFrameStart; frameEdAddr = decodedInfo->bytePosFrameEnd; frameSize = (frameEdAddr > frameStAddr) ? (frameEdAddr - frameStAddr) : (frameStAddr - frameEdAddr); // Print informations if ( performance == TRUE ) { VLOG(logLevel, "%02d %5d %d %4d(%4d) %3d %2d(%2d) %2d(%2d) %08x %08x %08x %08x %08x %8d %4dx%-4d %4d %4d %8d %8d (%6d,%6d,%8d) (%6d,%6d,%8d) (%6d,%6d,%8d) %d %d %d\n", handle->instIndex, frameNo, decodedInfo->picType, decodedInfo->decodedPOC, decodedInfo->displayPOC, decodedInfo->nalType, decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled, decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled, decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr, decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, frameSize, decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo, decodedInfo->temporalId, decodedInfo->frameCycle, decodedInfo->decHostCmdTick, decodedInfo->decSeekStartTick, decodedInfo->decSeekEndTick, decodedInfo->seekCycle, decodedInfo->decParseStartTick, decodedInfo->decParseEndTick, decodedInfo->parseCycle, decodedInfo->decDecodeStartTick, decodedInfo->decDecodeEndTick, decodedInfo->DecodedCycle, queueStatus.reportQueueCount, queueStatus.instanceQueueCount, 0 ); } else { VLOG(logLevel, "%02d %5d %d %4d(%4d) %3d %2d(%2d) %2d(%2d) %08x %08x %08x %08x %08x %8d %4dx%-4d %4d %4d %8d(%8d,%8d,%8d) %d %d %d\n", handle->instIndex, frameNo, decodedInfo->picType, decodedInfo->decodedPOC, decodedInfo->displayPOC, decodedInfo->nalType, decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled, decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled, decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr, decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, frameSize, decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo, decodedInfo->temporalId, decodedInfo->frameCycle, decodedInfo->seekCycle, decodedInfo->parseCycle, decodedInfo->DecodedCycle, queueStatus.reportQueueCount, queueStatus.instanceQueueCount, 0 ); } if (logLevel == ERR) { VLOG(ERR, "\t>>ERROR REASON: 0x%08x(0x%08x)\n", decodedInfo->errorReason, decodedInfo->errorReasonExt); } if (decodedInfo->numOfErrMBs) { VLOG(WARN, "\t>> ErrorBlock: %d\n", decodedInfo->numOfErrMBs); } } } void DisplayDecodedInformationForAVS2( DecHandle handle, Uint32 frameNo, BOOL performance, DecOutputInfo* decodedInfo ) { Int32 logLevel; QueueStatusInfo queueStatus; PhysicalAddress frameSize = 0, frameStAddr = 0, frameEdAddr = 0; VPU_DecGiveCommand(handle, DEC_GET_QUEUE_STATUS, &queueStatus); if (decodedInfo == NULL) { if ( performance == TRUE ) { VLOG(INFO, " | FRAME | HOST | SEEK_S SEEK_E SEEK | PARSE_S PARSE_E PARSE | DEC_S DEC_E DEC |\n"); VLOG(INFO, "I NO T POC NAL DECO DISP DISPFLAG RD_PTR WR_PTR FRM_START FRM_END FRM_SIZE WxH SEQ TEMP | CYCLE | TICK | TICK TICK CYCLE | TICK TICK CYCLE | TICK TICK CYCLE | RQ IQ\n"); } else { VLOG(INFO, "I NO T POC NAL DECO DISP DISPFLAG RD_PTR WR_PTR FRM_START FRM_END FRM_SIZE WxH SEQ TEMP CYCLE (Seek, Parse, Dec) RQ IQ\n"); } VLOG(INFO, "------------------------------------------------------------------------------------------------------------\n"); } else { logLevel = (decodedInfo->decodingSuccess&0x01) == 0 ? ERR : TRACE; frameStAddr = decodedInfo->bytePosFrameStart; frameEdAddr = decodedInfo->bytePosFrameEnd; frameSize = (frameEdAddr > frameStAddr) ? (frameEdAddr - frameStAddr) : (frameStAddr - frameEdAddr); // Print informations if (performance == TRUE) { VLOG(logLevel, "%02d %5d %d %4d(%4d) %3d %2d(%2d) %2d(%2d) %08x %08x %08x %08x %08x %8d %4dx%-4d %4d %4d %8d %8d (%6d,%6d,%8d) (%6d,%6d,%8d) (%6d,%6d,%8d) %d %d %d\n", handle->instIndex, frameNo, decodedInfo->picType, decodedInfo->avs2Info.decodedPOI, decodedInfo->avs2Info.displayPOI, decodedInfo->nalType, decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled, decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled, decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr, decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, frameSize, decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo, decodedInfo->temporalId, decodedInfo->frameCycle, decodedInfo->decHostCmdTick, decodedInfo->decSeekStartTick, decodedInfo->decSeekEndTick, decodedInfo->seekCycle, decodedInfo->decParseStartTick, decodedInfo->decParseEndTick, decodedInfo->parseCycle, decodedInfo->decDecodeStartTick, decodedInfo->decDecodeEndTick, decodedInfo->DecodedCycle, queueStatus.reportQueueCount, queueStatus.instanceQueueCount, 0 ); } else { VLOG(logLevel, "%02d %5d %d %4d(%4d) %3d %2d(%2d) %2d(%2d) %08x %08x %08x %08x %08x %8d %4dx%-4d %4d %4d %8d(%8d,%8d,%8d) %d %d %d\n", handle->instIndex, frameNo, decodedInfo->picType, decodedInfo->avs2Info.decodedPOI, decodedInfo->avs2Info.displayPOI, decodedInfo->nalType, decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled, decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled, decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr, decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, frameSize, decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo, decodedInfo->temporalId, decodedInfo->frameCycle, decodedInfo->seekCycle, decodedInfo->parseCycle, decodedInfo->DecodedCycle, queueStatus.reportQueueCount, queueStatus.instanceQueueCount, 0 ); } if (logLevel == ERR) { VLOG(ERR, "\t>>ERROR REASON: 0x%08x(0x%08x)\n", decodedInfo->errorReason, decodedInfo->errorReasonExt); } if (decodedInfo->numOfErrMBs) { VLOG(WARN, "\t>> ErrorBlock: %d\n", decodedInfo->numOfErrMBs); } } } void DisplayDecodedInformationForVP9( DecHandle handle, Uint32 frameNo, BOOL performance, DecOutputInfo* decodedInfo) { Int32 logLevel; QueueStatusInfo queueStatus; PhysicalAddress frameSize = 0, frameStAddr = 0, frameEdAddr = 0; VPU_DecGiveCommand(handle, DEC_GET_QUEUE_STATUS, &queueStatus); if (decodedInfo == NULL) { // Print header if ( performance == TRUE ) { VLOG(INFO, " | FRAME | HOST | SEEK_S SEEK_E SEEK | PARSE_S PARSE_E PARSE | DEC_S DEC_E DEC |\n"); VLOG(INFO, "I NO T DECO DISP DISPFLAG RD_PTR WR_PTR FRM_START FRM_END FRM_SIZE WxH SEQ | CYCLE | TICK | TICK TICK CYCLE | TICK TICK CYCLE | TICK TICK CYCLE | RQ IQ\n"); } else { VLOG(INFO, "I NO T DECO DISP DISPFLAG RD_PTR WR_PTR FRM_START FRM_END FRM_SIZE WxH SEQ CYCLE (Seek, Parse, Dec) RQ IQ\n"); } VLOG(INFO, "--------------------------------------------------------------------------------------------\n"); } else { logLevel = (decodedInfo->decodingSuccess&0x01) == 0 ? ERR : TRACE; frameStAddr = decodedInfo->bytePosFrameStart; frameEdAddr = decodedInfo->bytePosFrameEnd; frameSize = (frameEdAddr > frameStAddr) ? (frameEdAddr - frameStAddr) : (frameStAddr - frameEdAddr); // Print informations if (performance == TRUE) { VLOG(logLevel, "%02d %5d %d %2d(%2d) %2d(%2d) %08x %08x %08x %08x %08x %8d %4dx%-4d %4d %8d %8d (%6d,%6d,%8d) (%6d,%6d,%8d) (%6d,%6d,%8d) %d %d %d\n", handle->instIndex, frameNo, decodedInfo->picType, decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled, decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled, decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr, decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, frameSize, decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo, decodedInfo->frameCycle, decodedInfo->decHostCmdTick, decodedInfo->decSeekStartTick, decodedInfo->decSeekEndTick, decodedInfo->seekCycle, decodedInfo->decParseStartTick, decodedInfo->decParseEndTick, decodedInfo->parseCycle, decodedInfo->decDecodeStartTick, decodedInfo->decDecodeEndTick, decodedInfo->DecodedCycle, queueStatus.reportQueueCount, queueStatus.instanceQueueCount, 0 ); } else { VLOG(logLevel, "%02d %5d %d %2d(%2d) %2d(%2d) %08x %08x %08x %08x %08x %8d %4dx%-4d %4d %8d (%8d,%8d,%8d) %d %d %d\n", handle->instIndex, frameNo, decodedInfo->picType, decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled, decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled, decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr, decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, frameSize, decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo, decodedInfo->frameCycle, decodedInfo->seekCycle, decodedInfo->parseCycle, decodedInfo->DecodedCycle, queueStatus.reportQueueCount, queueStatus.instanceQueueCount, 0 ); } if (logLevel == ERR) { VLOG(ERR, "\t>>ERROR REASON: 0x%08x(0x%08x)\n", decodedInfo->errorReason, decodedInfo->errorReasonExt); } if (decodedInfo->numOfErrMBs) { VLOG(WARN, "\t>> ErrorBlock: %d\n", decodedInfo->numOfErrMBs); } } } void DisplayDecodedInformationForAVC( DecHandle handle, Uint32 frameNo, BOOL performance, DecOutputInfo* decodedInfo) { Int32 logLevel; QueueStatusInfo queueStatus; PhysicalAddress frameSize = 0, frameStAddr = 0, frameEdAddr = 0; VPU_DecGiveCommand(handle, DEC_GET_QUEUE_STATUS, &queueStatus); if (decodedInfo == NULL) { // Print header if ( performance == TRUE ) { VLOG(INFO, " | FRAME | HOST | SEEK_S SEEK_E SEEK | PARSE_S PARSE_E PARSE | DEC_S DEC_E DEC |\n"); VLOG(INFO, "I NO T POC NAL DECO DISP DISPFLAG RD_PTR WR_PTR FRM_START FRM_END FRM_SIZE WxH SEQ TEMP | CYCLE | TICK | TICK TICK CYCLE | TICK TICK CYCLE | TICK TICK CYCLE | RQ IQ VCore\n"); } else { VLOG(INFO, "I NO T POC NAL DECO DISP DISPFLAG RD_PTR WR_PTR FRM_START FRM_END FRM_SIZE WxH SEQ TEMP CYCLE ( Seek, Parse, Dec) RQ IQ VCore\n"); } VLOG(INFO, "-----------------------------------------------------------------------------------------------------------------------------------------------\n"); } else { logLevel = (decodedInfo->decodingSuccess&0x01) == 0 ? ERR : INFO; frameStAddr = decodedInfo->bytePosFrameStart; frameEdAddr = decodedInfo->bytePosFrameEnd; frameSize = (frameEdAddr > frameStAddr) ? (frameEdAddr - frameStAddr) : (frameStAddr - frameEdAddr); // Print informations if (performance == TRUE) { VLOG(logLevel, "%02d %5d %d %4d(%4d) %3d %2d(%2d) %2d(%2d) %08x %08x %08x %08x %08x %8d %4dx%-4d %4d %4d %8d %8d (%6d,%6d,%8d) (%6d,%6d,%8d) (%6d,%6d,%8d) %d %d %d\n", handle->instIndex, frameNo, decodedInfo->picType, decodedInfo->decodedPOC, decodedInfo->displayPOC, decodedInfo->nalType, decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled, decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled, decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr, decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, frameSize, decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo, decodedInfo->temporalId, decodedInfo->frameCycle, decodedInfo->decHostCmdTick, decodedInfo->decSeekStartTick, decodedInfo->decSeekEndTick, decodedInfo->seekCycle, decodedInfo->decParseStartTick, decodedInfo->decParseEndTick, decodedInfo->parseCycle, decodedInfo->decDecodeStartTick, decodedInfo->decDecodeEndTick, decodedInfo->DecodedCycle, queueStatus.reportQueueCount, queueStatus.instanceQueueCount, 0 ); } else { VLOG(logLevel, "%02d %5d %d %4d(%4d) %3d %2d(%2d) %2d(%2d) %08x %08x %08x %08x %08x %8d %4dx%-4d %4d %4d %8d(%8d,%8d,%8d) %d %d %d\n", handle->instIndex, frameNo, decodedInfo->picType, decodedInfo->decodedPOC, decodedInfo->displayPOC, decodedInfo->nalType, decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled, decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled, decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr, decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, frameSize, decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo, decodedInfo->temporalId, decodedInfo->frameCycle, decodedInfo->seekCycle, decodedInfo->parseCycle, decodedInfo->DecodedCycle, queueStatus.reportQueueCount, queueStatus.instanceQueueCount, 0 ); } if (logLevel == ERR) { VLOG(ERR, "\t>>ERROR REASON: 0x%08x(0x%08x)\n", decodedInfo->errorReason, decodedInfo->errorReasonExt); } if (decodedInfo->numOfErrMBs) { VLOG(WARN, "\t>> ErrorBlock: %d\n", decodedInfo->numOfErrMBs); } } } void DisplayDecodedInformationForAV1( DecHandle handle, Uint32 frameNo, BOOL performance, DecOutputInfo* decodedInfo) { Int32 logLevel; QueueStatusInfo queueStatus; PhysicalAddress frameSize = 0, frameStAddr = 0, frameEdAddr = 0; VPU_DecGiveCommand(handle, DEC_GET_QUEUE_STATUS, &queueStatus); if (decodedInfo == NULL) { // Print header if ( performance == TRUE ) { VLOG(INFO, " | FRAME | HOST | SEEK_S SEEK_E SEEK | PARSE_S PARSE_E PARSE | DEC_S DEC_E DEC |\n"); VLOG(INFO, "I NO T DECO DISP DISPFLAG RD_PTR WR_PTR FRM_START FRM_END FRM_SIZE WxH SEQ | CYCLE | TICK | TICK TICK CYCLE | TICK TICK CYCLE | TICK TICK CYCLE | RQ IQ\n"); } else { VLOG(INFO, "I NO T DECO DISP DISPFLAG RD_PTR WR_PTR FRM_START FRM_END FRM_SIZE WxH SEQ CYCLE (Seek, Parse, Dec) RQ IQ\n"); } VLOG(INFO, "--------------------------------------------------------------------------------------------\n"); } else { logLevel = (decodedInfo->decodingSuccess&0x01) == 0 ? ERR : TRACE; frameStAddr = decodedInfo->bytePosFrameStart; frameEdAddr = decodedInfo->bytePosFrameEnd; frameSize = (frameEdAddr > frameStAddr) ? (frameEdAddr - frameStAddr) : (frameStAddr - frameEdAddr); // Print informations if (performance == TRUE) { VLOG(logLevel, "%02d %5d %d %2d(%2d) %2d(%2d) %08x %08x %08x %08x %08x %8d %4dx%-4d %4d %8d %8d (%6d,%6d,%8d) (%6d,%6d,%8d) (%6d,%6d,%8d) %d %d %d\n", handle->instIndex, frameNo, decodedInfo->picType, decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled, decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled, decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr, decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, frameSize, decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo, decodedInfo->frameCycle, decodedInfo->decHostCmdTick, decodedInfo->decSeekStartTick, decodedInfo->decSeekEndTick, decodedInfo->seekCycle, decodedInfo->decParseStartTick, decodedInfo->decParseEndTick, decodedInfo->parseCycle, decodedInfo->decDecodeStartTick, decodedInfo->decDecodeEndTick, decodedInfo->DecodedCycle, queueStatus.reportQueueCount, queueStatus.instanceQueueCount, 0 ); } else { VLOG(logLevel, "%02d %5d %d %2d(%2d) %2d(%2d) %08x %08x %08x %08x %08x %8d %4dx%-4d %4d %8d (%8d,%8d,%8d) %d %d %d\n", handle->instIndex, frameNo, decodedInfo->picType, decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled, decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled, decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr, decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, frameSize, decodedInfo->dispPicWidth, decodedInfo->dispPicHeight, decodedInfo->sequenceNo, decodedInfo->frameCycle, decodedInfo->seekCycle, decodedInfo->parseCycle, decodedInfo->DecodedCycle, queueStatus.reportQueueCount, queueStatus.instanceQueueCount, 0 ); } if (logLevel == ERR) { VLOG(ERR, "\t>>ERROR REASON: 0x%08x(0x%08x)\n", decodedInfo->errorReason, decodedInfo->errorReasonExt); } if (decodedInfo->numOfErrMBs) { VLOG(WARN, "\t>> ErrorBlock: %d\n", decodedInfo->numOfErrMBs); } } } void DisplayDecodedInformationCommon( DecHandle handle, Uint32 frameNo, DecOutputInfo* decodedInfo) { Int32 logLevel; PhysicalAddress frameSize = 0, frameStAddr = 0, frameEdAddr = 0; if (decodedInfo == NULL) { // Print header VLOG(TRACE, "I NO T DECO DISP DISPFLAG RD_PTR WR_PTR FRM_START FRM_END FRM_SIZE WxH \n"); VLOG(TRACE, "---------------------------------------------------------------------------\n"); } else { VpuRect rc = decodedInfo->rcDisplay; Uint32 width = rc.right - rc.left; Uint32 height = rc.bottom - rc.top; logLevel = (decodedInfo->decodingSuccess&0x01) == 0 ? WARN : INFO; frameStAddr = decodedInfo->bytePosFrameStart; frameEdAddr = decodedInfo->bytePosFrameEnd; frameSize = (frameEdAddr > frameStAddr) ? (frameEdAddr - frameStAddr) : (frameStAddr - frameEdAddr); // Print informations VLOG(logLevel, "%02d %5d %d %2d(%2d) %2d(%2d) %08x %08x %08x %08x %08x %8d %dx%d\n", handle->instIndex, frameNo, decodedInfo->picType, decodedInfo->indexFrameDecoded, decodedInfo->indexFrameDecodedForTiled, decodedInfo->indexFrameDisplay, decodedInfo->indexFrameDisplayForTiled, decodedInfo->frameDisplayFlag,decodedInfo->rdPtr, decodedInfo->wrPtr, decodedInfo->bytePosFrameStart, decodedInfo->bytePosFrameEnd, frameSize, width, height); if (logLevel == ERR) { VLOG(ERR, "\t>>ERROR REASON: 0x%08x(0x%08x)\n", decodedInfo->errorReason, decodedInfo->errorReasonExt); } if (decodedInfo->numOfErrMBs) { VLOG(WARN, "\t>> ErrorBlock: %d\n", decodedInfo->numOfErrMBs); } } } /** * \brief Print out decoded information such like RD_PTR, WR_PTR, PIC_TYPE, .. * \param decodedInfo If this parameter is not NULL then print out decoded informations * otherwise print out header. */ void DisplayDecodedInformation( DecHandle handle __attribute__((unused)), CodStd codec, Uint32 frameNo __attribute__((unused)), DecOutputInfo* decodedInfo, ... ) { int performance = FALSE; va_list ap; va_start(ap, decodedInfo); performance = va_arg(ap, Uint32); va_end(ap); switch (codec) { case STD_HEVC: DisplayDecodedInformationForHevc(handle, frameNo, performance, decodedInfo); break; case STD_VP9: DisplayDecodedInformationForVP9(handle, frameNo, performance, decodedInfo); break; case STD_AVS2: DisplayDecodedInformationForAVS2(handle, frameNo, performance, decodedInfo); break; case STD_AVC: DisplayDecodedInformationForAVC(handle, frameNo, performance, decodedInfo); break; case STD_AV1: DisplayDecodedInformationForAV1(handle, frameNo, performance, decodedInfo); break; default: DisplayDecodedInformationCommon(handle, frameNo, decodedInfo); break; } return; } void SetDefaultEncTestConfig(TestEncConfig* testConfig) { osal_memset(testConfig, 0, sizeof(TestEncConfig)); testConfig->frame_endian = VPU_FRAME_ENDIAN; testConfig->stream_endian = VPU_STREAM_ENDIAN; testConfig->source_endian = VPU_SOURCE_ENDIAN; testConfig->mapType = COMPRESSED_FRAME_MAP; testConfig->lineBufIntEn = TRUE; #ifdef SUPPORT_SOURCE_RELEASE_INTERRUPT testConfig->srcReleaseIntEnable = FALSE; #endif testConfig->ringBufferEnable = FALSE; testConfig->ringBufferWrapEnable = FALSE; testConfig->coreIdx = 0; testConfig->cbcrInterleave = TRUE; testConfig->nv21 = FALSE; } void Coda9SetDefaultEncTestConfig(TestEncConfig* encConfig) { osal_memset(encConfig, 0, sizeof(TestEncConfig)); encConfig->stdMode = STD_AVC; encConfig->frame_endian = VPU_FRAME_ENDIAN; encConfig->stream_endian = VPU_STREAM_ENDIAN; encConfig->source_endian = VPU_SOURCE_ENDIAN; encConfig->mapType = LINEAR_FRAME_MAP; encConfig->ringBufferEnable = FALSE; encConfig->yuv_mode = SOURCE_YUV; } static void Wave5DisplayEncodedInformation( EncHandle handle, CodStd codec __attribute__((unused)), Uint32 frameNo __attribute__((unused)), EncOutputInfo* encodedInfo, Int32 srcEndFlag, Int32 srcFrameIdx, Int32 performance ) { QueueStatusInfo queueStatus; VPU_EncGiveCommand(handle, ENC_GET_QUEUE_STATUS, &queueStatus); if (encodedInfo == NULL) { if (performance == TRUE ) { printf("----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n"); printf(" USEDSRC | FRAME | HOST | PREP_S PREP_E PREP | PROCE_S PROCE_E PROCE | ENC_S ENC_E ENC |\n"); printf("I NO T RECON RD_PTR WR_PTR BYTES SRCIDX IDX IDC Vcore | CYCLE | TICK | TICK TICK CYCLE | TICK TICK CYCLE | TICK TICK CYCLE | RQ IQ\n"); printf("----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n"); } else { printf("---------------------------------------------------------------------------------------------------------------------------\n"); printf(" USEDSRC | CYCLE\n"); printf("I NO T RECON RD_PTR WR_PTR BYTES SRCIDX IDX IDC Vcore | FRAME PREPARING PROCESSING ENCODING | RQ IQ\n"); printf("---------------------------------------------------------------------------------------------------------------------------\n"); } } else { if (performance == TRUE) { printf("%02d %5d %5d %5d %08x %08x %8x %2d %2d %08x %2d %8u %8u (%8u,%8u,%8u) (%8u,%8u,%8u) (%8u,%8u,%8u) %d %d\n", handle->instIndex, encodedInfo->encPicCnt, encodedInfo->picType, encodedInfo->reconFrameIndex, encodedInfo->rdPtr, encodedInfo->wrPtr, encodedInfo->bitstreamSize, (srcEndFlag == 1 ? -1 : srcFrameIdx), encodedInfo->encSrcIdx, encodedInfo->releaseSrcFlag, 0, encodedInfo->frameCycle, encodedInfo->encHostCmdTick, encodedInfo->encPrepareStartTick, encodedInfo->encPrepareEndTick, encodedInfo->prepareCycle, encodedInfo->encProcessingStartTick, encodedInfo->encProcessingEndTick, encodedInfo->processing, encodedInfo->encEncodeStartTick, encodedInfo->encEncodeEndTick, encodedInfo->EncodedCycle, queueStatus.reportQueueCount, queueStatus.instanceQueueCount); } else { printf("%02d %5d %5d %5d %08x %08x %8x %2d %2d %04x %d %8d %8d %8d %8d %d %d\n", handle->instIndex, encodedInfo->encPicCnt, encodedInfo->picType, encodedInfo->reconFrameIndex, encodedInfo->rdPtr, encodedInfo->wrPtr, encodedInfo->bitstreamSize, (srcEndFlag == 1 ? -1 : srcFrameIdx), encodedInfo->encSrcIdx, encodedInfo->releaseSrcFlag, 0, encodedInfo->frameCycle, encodedInfo->prepareCycle, encodedInfo->processing, encodedInfo->EncodedCycle, queueStatus.reportQueueCount, queueStatus.instanceQueueCount); } } } static void Coda9DisplayEncodedInformation( DecHandle handle, CodStd codec, Uint32 frameNo, EncOutputInfo* encodedInfo ) { if (encodedInfo == NULL) { // Print header VLOG(INFO, "I NO T RECON RD_PTR WR_PTR \n"); VLOG(INFO, "-------------------------------------\n"); } else { char** picTypeArray = (char**)(codec==STD_AVC ? EncPicTypeStringH264 : EncPicTypeStringMPEG4); const char* strPicType; if (encodedInfo->picType > 2) strPicType = "?"; else strPicType = picTypeArray[encodedInfo->picType]; // Print informations VLOG(INFO, "%02d %5d %5s %5d %08x %08x\n", handle->instIndex, frameNo, strPicType, encodedInfo->reconFrameIndex, encodedInfo->rdPtr, encodedInfo->wrPtr); } } /*lint -esym(438, ap) */ void DisplayEncodedInformation( EncHandle handle, CodStd codec, Uint32 frameNo __attribute__((unused)), EncOutputInfo* encodedInfo, ... ) { int srcEndFlag; int srcFrameIdx; int performance = FALSE; va_list ap; switch (codec) { case STD_HEVC: va_start(ap, encodedInfo); srcEndFlag = va_arg(ap, Uint32); srcFrameIdx = va_arg(ap, Uint32); performance = va_arg(ap, Uint32); va_end(ap); Wave5DisplayEncodedInformation(handle, codec, frameNo, encodedInfo, srcEndFlag , srcFrameIdx, performance); break; case STD_AVC: if(handle->productId == PRODUCT_ID_521) { va_start(ap, encodedInfo); srcEndFlag = va_arg(ap, Uint32); srcFrameIdx = va_arg(ap, Uint32); performance = va_arg(ap, Uint32); va_end(ap); Wave5DisplayEncodedInformation(handle, codec, frameNo, encodedInfo, srcEndFlag , srcFrameIdx, performance); } else Coda9DisplayEncodedInformation(handle, codec, frameNo, encodedInfo); break; default: Coda9DisplayEncodedInformation(handle, codec, frameNo, encodedInfo); break; } return; } /*lint +esym(438, ap) */ void replace_character(char* str, char c, char r) { int i=0; int len; len = (Int32)strlen(str); for(i=0; icoreIdx; Uint32 idx; for (idx=0; idxinstIndex); } } BOOL AllocateDecFrameBuffer( DecHandle decHandle, TestDecConfig* config, Uint32 nonLinearFbCnt, Uint32 linearFbCount, FrameBuffer* retFbArray, vpu_buffer_t* retFbAddrs, Uint32* retStride ) { Uint32 framebufSize; Uint32 totalFbCount, linearFbStartIdx = 0; Uint32 coreIndex; Uint32 idx; FrameBufferFormat format = config->wtlFormat; DecInitialInfo seqInfo; FrameBufferAllocInfo fbAllocInfo; RetCode ret; vpu_buffer_t* pvb; size_t framebufStride; size_t framebufHeight; Uint32 productId; DRAMConfig* pDramCfg = NULL; DRAMConfig dramCfg; const DecInfo* pDecInfo = VPU_HANDLE_TO_DECINFO(decHandle); memset(&dramCfg, 0, sizeof(DRAMConfig)); coreIndex = VPU_HANDLE_CORE_INDEX(decHandle); productId = VPU_HANDLE_PRODUCT_ID(decHandle); VPU_DecGiveCommand(decHandle, DEC_GET_SEQ_INFO, (void*)&seqInfo); if (pDecInfo->productCode == WAVE521C_DUAL_CODE) { if ( seqInfo.lumaBitdepth == 8 && seqInfo.chromaBitdepth == 8) { config->mapType = COMPRESSED_FRAME_MAP_DUAL_CORE_8BIT; } else { config->mapType = COMPRESSED_FRAME_MAP_DUAL_CORE_10BIT; } } totalFbCount = nonLinearFbCnt + linearFbCount; if (PRODUCT_ID_W_SERIES(productId)) { linearFbStartIdx = nonLinearFbCnt; } else { //CODA series if (0 == nonLinearFbCnt) { nonLinearFbCnt = linearFbCount; linearFbCount = 0; } else { linearFbStartIdx = nonLinearFbCnt; } } if (PRODUCT_ID_W_SERIES(productId)) { format = (seqInfo.lumaBitdepth > 8 || seqInfo.chromaBitdepth > 8) ? FORMAT_420_P10_16BIT_LSB : FORMAT_420; } else { //CODA series pDramCfg = &dramCfg; ret = VPU_DecGiveCommand(decHandle, GET_DRAM_CONFIG, pDramCfg); if (RETCODE_SUCCESS != ret) { VLOG(ERR, "%s:%d VPU_DecGiveCommand[GET_DRAM_CONFIG] failed Error code is 0x%x \n", __FUNCTION__, __LINE__, ret ); return FALSE; } } if (config->bitFormat == STD_VP9) { framebufStride = CalcStride(VPU_ALIGN64((Uint32)seqInfo.picWidth), seqInfo.picHeight, format, config->cbcrInterleave, config->mapType, TRUE); framebufHeight = VPU_ALIGN64((Uint32)seqInfo.picHeight); framebufSize = VPU_GetFrameBufSize(decHandle, decHandle->coreIdx, (Int32)framebufStride, (Int32)framebufHeight, config->mapType, format, config->cbcrInterleave, NULL); *retStride = (Uint32)framebufStride; } else if (config->bitFormat == STD_AVS2) { framebufStride = CalcStride(seqInfo.picWidth, seqInfo.picHeight, format, config->cbcrInterleave, config->mapType, FALSE); framebufHeight = VPU_ALIGN8(seqInfo.picHeight); framebufSize = VPU_GetFrameBufSize(decHandle, decHandle->coreIdx, (Int32)framebufStride, (Int32)framebufHeight, config->mapType, format, config->cbcrInterleave, pDramCfg); *retStride = (Uint32)framebufStride; } else if (config->bitFormat == STD_AV1){ framebufStride = CalcStride(VPU_ALIGN64((Uint32)seqInfo.picWidth), seqInfo.picHeight, format, config->cbcrInterleave, config->mapType, TRUE); framebufHeight = VPU_ALIGN64((Uint32)seqInfo.picHeight); framebufSize = VPU_GetFrameBufSize(decHandle, decHandle->coreIdx, (Int32)framebufStride, (Int32)framebufHeight, config->mapType, format, config->cbcrInterleave, NULL); *retStride = (Uint32)framebufStride; } else { *retStride = VPU_ALIGN32(seqInfo.picWidth); framebufStride = CalcStride(seqInfo.picWidth, seqInfo.picHeight, format, config->cbcrInterleave, config->mapType, FALSE); framebufHeight = VPU_ALIGN32(seqInfo.picHeight); framebufSize = VPU_GetFrameBufSize(decHandle, decHandle->coreIdx, (Int32)framebufStride, (Int32)framebufHeight, config->mapType, format, config->cbcrInterleave, pDramCfg); } osal_memset((void*)&fbAllocInfo, 0x00, sizeof(fbAllocInfo)); osal_memset((void*)retFbArray, 0x00, (Int32)sizeof(FrameBuffer)*totalFbCount); fbAllocInfo.format = format; fbAllocInfo.cbcrInterleave = config->cbcrInterleave; fbAllocInfo.mapType = config->mapType; fbAllocInfo.stride = (Int32)framebufStride; fbAllocInfo.height = (Int32)framebufHeight; fbAllocInfo.size = framebufSize; fbAllocInfo.lumaBitDepth = seqInfo.lumaBitdepth; fbAllocInfo.chromaBitDepth = seqInfo.chromaBitdepth; fbAllocInfo.num = nonLinearFbCnt; fbAllocInfo.endian = PRODUCT_ID_NOT_W_SERIES(productId) ? config->frameEndian : VDI_128BIT_LITTLE_ENDIAN ; // FBC endian is not fixed. fbAllocInfo.type = FB_TYPE_CODEC; osal_memset((void*)retFbAddrs, 0x00, (Int32)sizeof(vpu_buffer_t)*totalFbCount); // APIDPRINT("ALLOC MEM - FBC data\n"); for (idx=0; idxsize = framebufSize; if (vdi_allocate_dma_memory(coreIndex, pvb, DEC_FBC, decHandle->instIndex) < 0) { VLOG(ERR, "%s:%d fail to allocate frame buffer\n", __FUNCTION__, __LINE__); ReleaseVideoMemory(decHandle, retFbAddrs, totalFbCount); return FALSE; } retFbArray[idx].bufY = pvb->phys_addr; retFbArray[idx].bufCb = (PhysicalAddress)-1; retFbArray[idx].bufCr = (PhysicalAddress)-1; retFbArray[idx].updateFbInfo = TRUE; retFbArray[idx].size = framebufSize; retFbArray[idx].width = seqInfo.picWidth; } if (nonLinearFbCnt != 0) { if ((ret=VPU_DecAllocateFrameBuffer(decHandle, fbAllocInfo, retFbArray)) != RETCODE_SUCCESS) { VLOG(ERR, "%s:%d failed to VPU_DecAllocateFrameBuffer(), ret(%d)\n", __FUNCTION__, __LINE__, ret); ReleaseVideoMemory(decHandle, retFbAddrs, totalFbCount); return FALSE; } } if (config->enableWTL == TRUE || linearFbCount != 0) { size_t linearStride; size_t picWidth; size_t picHeight; size_t fbHeight; TiledMapType mapType = LINEAR_FRAME_MAP; FrameBufferFormat outFormat = config->wtlFormat; picWidth = seqInfo.picWidth; picHeight = seqInfo.picHeight; fbHeight = picHeight; if (PRODUCT_ID_960 == productId || PRODUCT_ID_980 == productId) { //wtl frame buffer mapType = (FF_FRAME == config->wtlMode) ? LINEAR_FRAME_MAP : LINEAR_FIELD_MAP; } if (config->bitFormat == STD_VP9) { fbHeight = VPU_ALIGN64(picHeight); } else if (config->bitFormat == STD_AVS2) { fbHeight = VPU_ALIGN8(picHeight); } else if (productId == PRODUCT_ID_960 || productId == PRODUCT_ID_980) { fbHeight = VPU_ALIGN32(picHeight); } else if (config->bitFormat == STD_AV1) { fbHeight = VPU_ALIGN8(picHeight); } if (config->scaleDownWidth > 0 || config->scaleDownHeight > 0) { ScalerInfo sclInfo; VPU_DecGiveCommand(decHandle, DEC_GET_SCALER_INFO, (void*)&sclInfo); if (sclInfo.enScaler == TRUE) { picWidth = sclInfo.scaleWidth; picHeight = sclInfo.scaleHeight; if (config->bitFormat == STD_VP9) { fbHeight = VPU_ALIGN64((Uint32)picHeight); } else { fbHeight = VPU_CEIL(picHeight, 2); } } } if (config->bitFormat == STD_VP9) { linearStride = CalcStride(VPU_ALIGN64((Uint32)picWidth), (Uint32)picHeight, outFormat, config->cbcrInterleave, (TiledMapType)mapType, TRUE); } else if (config->bitFormat == STD_AV1) { linearStride = CalcStride(VPU_ALIGN16((Uint32)picWidth), (Uint32)picHeight, outFormat, config->cbcrInterleave, (TiledMapType)mapType, TRUE); } else { linearStride = CalcStride((Uint32)picWidth, (Uint32)picHeight, outFormat, config->cbcrInterleave, (TiledMapType)mapType, FALSE); } framebufSize = VPU_GetFrameBufSize(decHandle, coreIndex, (Uint32)linearStride, (Uint32)fbHeight, (TiledMapType)mapType, outFormat, config->cbcrInterleave, pDramCfg); for (idx=linearFbStartIdx; idxsize = framebufSize; if (vdi_allocate_dma_memory(coreIndex, pvb, DEC_FB_LINEAR, decHandle->instIndex) < 0) { VLOG(ERR, "%s:%d fail to allocate frame buffer\n", __FUNCTION__, __LINE__); ReleaseVideoMemory(decHandle, retFbAddrs, totalFbCount); return FALSE; } retFbArray[idx].bufY = pvb->phys_addr; retFbArray[idx].bufCb = (PhysicalAddress)-1; retFbArray[idx].bufCr = (PhysicalAddress)-1; retFbArray[idx].updateFbInfo = TRUE; retFbArray[idx].size = framebufSize; retFbArray[idx].width = (Int32)picWidth; } fbAllocInfo.nv21 = config->nv21; fbAllocInfo.format = outFormat; fbAllocInfo.num = linearFbCount; fbAllocInfo.mapType = (TiledMapType)mapType; fbAllocInfo.stride = (Int32)linearStride; fbAllocInfo.height = (Int32)fbHeight; ret = VPU_DecAllocateFrameBuffer(decHandle, fbAllocInfo, &retFbArray[linearFbStartIdx]); if (ret != RETCODE_SUCCESS) { VLOG(ERR, "%s:%d failed to VPU_DecAllocateFrameBuffer() ret:%d\n", __FUNCTION__, __LINE__, ret); ReleaseVideoMemory(decHandle, retFbAddrs, totalFbCount); return FALSE; } } return TRUE; } BOOL AllocFBMemory(Uint32 coreIdx, vpu_buffer_t *pFbMem, FrameBuffer* pFb,Uint32 memSize, Uint32 memNum, Int32 memTypes, Int32 instIndex) { Uint32 i =0; for (i = 0; i < memNum; i++) { pFbMem[i].size = memSize; if (vdi_allocate_dma_memory(coreIdx, &pFbMem[i], memTypes, instIndex) < 0) { VLOG(ERR, "fail to allocate src buffer\n"); return FALSE; } pFb[i].bufY = pFbMem[i].phys_addr; pFb[i].bufCb = (PhysicalAddress) - 1; pFb[i].bufCr = (PhysicalAddress) - 1; pFb[i].size = memSize; pFb[i].updateFbInfo = TRUE; } return TRUE; } BOOL Coda9AllocateDecPPUFrameBuffer( BOOL* pEnablePPU, DecHandle decHandle, TestDecConfig* config, FrameBuffer* retFbArray, vpu_buffer_t* retFbAddrs, Queue* ppuQ ) { Uint32 stridePpu = 0; Uint32 sizePPUFb = 0; Uint32 rotate = config->coda9.rotate; Uint32 rotateWidth = 0; Uint32 rotateHeight = 0; Uint32 coreIndex = 0; const Uint32 ppuFbCount = 2; // #define PPU_FB_COUNT 2 Uint32 idx = 0; DecInitialInfo seqInfo; BOOL enablePPU = FALSE; vpu_buffer_t* pvb = NULL; FrameBufferAllocInfo fbAllocInfo; DRAMConfig* pDramCfg = NULL; DRAMConfig dramCfg; memset(&dramCfg, 0, sizeof(DRAMConfig)); osal_memset((void*)&fbAllocInfo, 0x00, sizeof(fbAllocInfo)); osal_memset((void*)retFbArray, 0x00, sizeof(FrameBuffer)*ppuFbCount); enablePPU = (BOOL)(config->coda9.rotate > 0 || config->coda9.mirror > 0 || config->coda9.enableTiled2Linear == TRUE || config->coda9.enableDering == TRUE); if(pEnablePPU) { *pEnablePPU = enablePPU; } if(!enablePPU) { VLOG(INFO, "<%s> No need PPU Buffers.\n", __FUNCTION__); return TRUE; } else { VLOG(INFO, "<%s> PPU Buffer : %d\n", __FUNCTION__, ppuFbCount); } pDramCfg = &dramCfg; VPU_DecGiveCommand(decHandle, GET_DRAM_CONFIG, pDramCfg); coreIndex = VPU_HANDLE_CORE_INDEX(decHandle); VPU_DecGiveCommand(decHandle, DEC_GET_SEQ_INFO, (void*)&seqInfo); rotateWidth = seqInfo.picWidth; rotateHeight = seqInfo.picHeight; if (rotate == 90 || rotate == 270) { rotateWidth = seqInfo.picHeight; rotateHeight = seqInfo.picWidth; } rotateWidth = VPU_ALIGN32(rotateWidth); rotateHeight = VPU_ALIGN32(rotateHeight); stridePpu = CalcStride(rotateWidth, rotateHeight, FORMAT_420, config->cbcrInterleave, LINEAR_FRAME_MAP, FALSE); sizePPUFb = VPU_GetFrameBufSize(decHandle, coreIndex, stridePpu, rotateHeight, LINEAR_FRAME_MAP, FORMAT_420, config->cbcrInterleave, pDramCfg); for (idx=0; idxsize = sizePPUFb; if (vdi_allocate_dma_memory(coreIndex, pvb, DEC_ETC, decHandle->instIndex) < 0) { VLOG(ERR, "%s:%d fail to allocate frame buffer\n", __FUNCTION__, __LINE__); return FALSE; } retFbArray[idx].bufY = pvb->phys_addr; retFbArray[idx].bufCb = (PhysicalAddress)-1; retFbArray[idx].bufCr = (PhysicalAddress)-1; retFbArray[idx].updateFbInfo = TRUE; retFbArray[idx].size = sizePPUFb; } fbAllocInfo.mapType = LINEAR_FRAME_MAP; fbAllocInfo.cbcrInterleave = config->cbcrInterleave; fbAllocInfo.format = FORMAT_420; fbAllocInfo.stride = stridePpu; fbAllocInfo.height = rotateHeight; fbAllocInfo.endian = config->frameEndian; fbAllocInfo.lumaBitDepth = 8; fbAllocInfo.chromaBitDepth = 8; fbAllocInfo.num = ppuFbCount; fbAllocInfo.type = FB_TYPE_PPU; fbAllocInfo.size = sizePPUFb; if (RETCODE_SUCCESS != VPU_DecAllocateFrameBuffer(decHandle, fbAllocInfo, retFbArray)) { VLOG(ERR, "%s:%d failed to VPU_DecAllocateFrameBuffer() ret:%d\n", __FUNCTION__, __LINE__); return FALSE; } // Note: Please keep the below call sequence. VPU_DecGiveCommand(decHandle, SET_ROTATION_ANGLE, (void*)&(config->coda9.rotate)); VPU_DecGiveCommand(decHandle, SET_MIRROR_DIRECTION, (void*)&(config->coda9.mirror)); VPU_DecGiveCommand(decHandle, SET_ROTATOR_STRIDE, (void*)&stridePpu); for (idx=0; idxbitstreamFormat = config->bitFormat; param->coreIdx = config->coreIdx; param->bitstreamMode = config->bitstreamMode; param->wtlEnable = config->enableWTL; param->wtlMode = config->wtlMode; param->cbcrInterleave = config->cbcrInterleave; param->nv21 = config->nv21; param->streamEndian = config->streamEndian; param->frameEndian = config->frameEndian; if (PRODUCT_ID_W_SERIES(config->productId)) { //WAVE param->errorConcealMode = config->errConcealMode; param->errorConcealUnit = config->errConcealUnit; param->av1Format = config->wave.av1Format; } else { //CODA param->avcExtension = config->coda9.enableMvc; param->bwbEnable = config->coda9.enableBWB; param->mp4Class = config->coda9.mp4class; param->tiled2LinearEnable = config->coda9.enableTiled2Linear; param->tiled2LinearMode = config->coda9.tiled2LinearMode; param->mp4DeblkEnable = config->coda9.enableDeblock; } } return ret; } #if defined(_WIN32) || defined(__MSDOS__) #define DOS_FILESYSTEM #define IS_DIR_SEPARATOR(__c) ((__c == '/') || (__c == '\\')) #else /* UNIX style */ #define IS_DIR_SEPARATOR(__c) (__c == '/') #endif char* GetDirname( const char* path ) { int length; int i; char* upper_dir; if (path == NULL) return NULL; length = (Int32)strlen(path); for (i=length-1; i>=0; i--) { if (IS_DIR_SEPARATOR(path[i])) break; } if (i<0) { upper_dir = strdup("."); } else { upper_dir = strdup(path); upper_dir[i] = 0; } return upper_dir; } char* GetBasename( const char* pathname ) { const char* base = NULL; const char* p = pathname; if (p == NULL) { return NULL; } #if defined(DOS_FILESYSTEM) if (isalpha((int)p[0]) && p[1] == ':') { p += 2; } #endif for (base=p; *p; p++) {//lint !e443 if (IS_DIR_SEPARATOR(*p)) { base = p+1; } } return (char*)base; } char* GetFileExtension( const char* filename ) { Int32 len; Int32 i; len = (Int32)strlen(filename); for (i=len-1; i>=0; i--) { if (filename[i] == '.') { return (char*)&filename[i+1]; } } return NULL; } void byte_swap(unsigned char* data, int len) { Uint8 temp; Int32 i; for (i=0; ibitstreamFormat = config->stdMode; if (GetEncOpenParam(param, config, encCfg, get_param) == FALSE) { VLOG(ERR, "[ERROR] Failed to parse CFG file(GetEncOpenParam)\n"); return FALSE; } if (0 == param->streamBufCount) { param->streamBufCount = ENC_STREAM_BUF_COUNT; } if (0 == param->streamBufSize) { param->streamBufSize = ENC_STREAM_BUF_SIZE; } if (param->srcBitDepth == 8) { if ( config->i422 == TRUE ) { config->srcFormat = FORMAT_422; } else { config->srcFormat = FORMAT_420; } } else if (param->srcBitDepth == 10) { if (config->srcFormat == FORMAT_420) { config->srcFormat = FORMAT_420_P10_16BIT_MSB; //set srcFormat in ParseArgumentAndSetTestConfig function return FALSE; } else if (config->srcFormat == FORMAT_422) { config->srcFormat = FORMAT_422_P10_16BIT_MSB; //set srcFormat in ParseArgumentAndSetTestConfig function return FALSE; } } if (config->optYuvPath[0] != 0) strcpy(config->yuvFileName, config->optYuvPath); if (config->packedFormat >= PACKED_YUYV) { int p10bits = 0; FrameBufferFormat packedFormat; if (config->srcFormat == FORMAT_420_P10_16BIT_MSB || config->srcFormat == FORMAT_420_P10_16BIT_LSB ) p10bits = 16; if (config->srcFormat == FORMAT_420_P10_32BIT_MSB || config->srcFormat == FORMAT_420_P10_32BIT_LSB ) p10bits = 32; packedFormat = GetPackedFormat(param->srcBitDepth, config->packedFormat, p10bits, 1); if (packedFormat == -1) { VLOG(ERR, "[ERROR] Failed to GetPackedFormat\n"); return FALSE; } param->srcFormat = packedFormat; param->nv21 = 0; param->cbcrInterleave = 0; } else { param->srcFormat = config->srcFormat; param->nv21 = config->nv21; } param->packedFormat = config->packedFormat; param->cbcrInterleave = config->cbcrInterleave; param->frameEndian = config->frame_endian; param->streamEndian = config->stream_endian; param->sourceEndian = config->source_endian; param->lineBufIntEn = config->lineBufIntEn; param->coreIdx = config->coreIdx; param->cbcrOrder = CBCR_ORDER_NORMAL; param->EncStdParam.waveParam.useLongTerm = (config->useAsLongtermPeriod > 0 && config->refLongtermPeriod > 0) ? 1 : 0; if (PRODUCT_ID_W_SERIES(config->productId)) { #ifdef SUPPORT_SOURCE_RELEASE_INTERRUPT param->srcReleaseIntEnable = config->srcReleaseIntEnable; #endif param->ringBufferEnable = config->ringBufferEnable; param->ringBufferWrapEnable = config->ringBufferWrapEnable; if (config->ringBufferEnable == TRUE) { param->streamBufCount = 1; param->lineBufIntEn = FALSE; } } param->subFrameSyncEnable = config->subFrameSyncEn; param->subFrameSyncMode = config->subFrameSyncMode;// default mode = register based for Ref.SW if(PRODUCT_ID_NOT_W_SERIES(config->productId)) { param->bwbEnable = TRUE; param->linear2TiledEnable = config->coda9.enableLinear2Tiled; param->linear2TiledMode = config->coda9.linear2TiledMode; param->ringBufferEnable = config->ringBufferEnable; if (TRUE == config->ringBufferEnable) { param->streamBufCount = 1; } #ifdef SUPPORT_NEW_SCHEDULER param->ringBufferWrapEnable = config->ringBufferWrapEnable; #endif } return TRUE; } void GenRegionToMap( VpuRect *region, /**< The size of the ROI region for H.265 (start X/Y in CTU, end X/Y int CTU) */ int *roiQp, int num, Uint32 mapWidth, Uint32 mapHeight, Uint8 *roiCtuMap) { Int32 roi_id, blk_addr; Uint32 roi_map_size = mapWidth * mapHeight; //init roi map for (blk_addr=0; blk_addr<(Int32)roi_map_size; blk_addr++) roiCtuMap[blk_addr] = 0; //set roi map. roi_entry[i] has higher priority than roi_entry[i+1] for (roi_id=(Int32)num-1; roi_id>=0; roi_id--) { Uint32 x, y; VpuRect *roi = region + roi_id; for (y=roi->top; y<=roi->bottom; y++) { for (x=roi->left; x<=roi->right; x++) { roiCtuMap[y*mapWidth + x] = (Uint8)(*(roiQp + roi_id)); } } } } void GenRegionToQpMap( VpuRect *region, /**< The size of the ROI region for H.265 (start X/Y in CTU, end X/Y int CTU) */ int *roiQp, int num, int initQp, Uint32 mapWidth, Uint32 mapHeight, Uint8 *roiCtuMap) { Int32 roi_id, blk_addr; Uint32 roi_map_size = mapWidth * mapHeight; //init roi map for (blk_addr=0; blk_addr<(Int32)roi_map_size; blk_addr++) roiCtuMap[blk_addr] = (Uint8)initQp; //set roi map. roi_entry[i] has higher priority than roi_entry[i+1] for (roi_id=(Int32)num-1; roi_id>=0; roi_id--) { Uint32 x, y; VpuRect *roi = region + roi_id; for (y=roi->top; y<=roi->bottom; y++) { for (x=roi->left; x<=roi->right; x++) { roiCtuMap[y*mapWidth + x] = (Uint8)(*(roiQp + roi_id)); } } } } Int32 writeVuiRbsp(int coreIdx, TestEncConfig *encConfig, EncOpenParam *encOP, vpu_buffer_t *vbVuiRbsp) { if (encOP->encodeVuiRbsp == TRUE) { vbVuiRbsp->size = VUI_HRD_RBSP_BUF_SIZE; if (vdi_allocate_dma_memory(coreIdx, vbVuiRbsp, ENC_ETC, 0) < 0) {//I don't know instIndex before Calling VpuEncOpen VLOG(ERR, "fail to allocate VUI rbsp buffer\n" ); return FALSE; } encOP->vuiRbspDataAddr = vbVuiRbsp->phys_addr; if (encConfig->vui_rbsp_file_name) { Uint8 *pVuiRbspBuf; Int32 rbspSizeInByte = (encOP->vuiRbspDataSize+7)>>3; ChangePathStyle(encConfig->vui_rbsp_file_name); if ((encConfig->vui_rbsp_fp = (FILE*)osal_fopen(encConfig->vui_rbsp_file_name, "r")) == NULL) { VLOG(ERR, "fail to open VUI rbsp Data file, %s\n", encConfig->vui_rbsp_file_name); return FALSE; } if (rbspSizeInByte > (Int32)VUI_HRD_RBSP_BUF_SIZE) VLOG(ERR, "VUI Rbsp size is bigger than buffer size\n"); pVuiRbspBuf = (Uint8*)osal_malloc(VUI_HRD_RBSP_BUF_SIZE); osal_memset(pVuiRbspBuf, 0, VUI_HRD_RBSP_BUF_SIZE); osal_fread(pVuiRbspBuf, 1, rbspSizeInByte, encConfig->vui_rbsp_fp); vdi_write_memory(coreIdx, encOP->vuiRbspDataAddr, pVuiRbspBuf, rbspSizeInByte, encOP->streamEndian); osal_free(pVuiRbspBuf); } } return TRUE; } Int32 writeHrdRbsp(int coreIdx, TestEncConfig *encConfig, EncOpenParam *encOP, vpu_buffer_t *vbHrdRbsp) { if (encOP->encodeHrdRbspInVPS) { vbHrdRbsp->size = VUI_HRD_RBSP_BUF_SIZE; if (vdi_allocate_dma_memory(coreIdx, vbHrdRbsp, ENC_ETC, 0) < 0) {//I don't know instIndex before Calling VpuEncOpen VLOG(ERR, "fail to allocate HRD rbsp buffer\n" ); return FALSE; } encOP->hrdRbspDataAddr = vbHrdRbsp->phys_addr; if (encConfig->hrd_rbsp_file_name) { Uint8 *pHrdRbspBuf; Int32 rbspSizeInByte = (encOP->hrdRbspDataSize+7)>>3; ChangePathStyle(encConfig->hrd_rbsp_file_name); if ((encConfig->hrd_rbsp_fp = (FILE*)osal_fopen(encConfig->hrd_rbsp_file_name, "r")) == NULL) { VLOG(ERR, "fail to open HRD rbsp Data file, %s\n", encConfig->hrd_rbsp_file_name); return FALSE; } if (rbspSizeInByte > (Int32)VUI_HRD_RBSP_BUF_SIZE) VLOG(ERR, "HRD Rbsp size is bigger than buffer size\n"); pHrdRbspBuf = (Uint8*)osal_malloc(VUI_HRD_RBSP_BUF_SIZE); osal_memset(pHrdRbspBuf, 0, VUI_HRD_RBSP_BUF_SIZE); osal_fread(pHrdRbspBuf, 1, rbspSizeInByte, encConfig->hrd_rbsp_fp); vdi_write_memory(coreIdx, encOP->hrdRbspDataAddr, pHrdRbspBuf, rbspSizeInByte, encOP->streamEndian); osal_free(pHrdRbspBuf); } } return TRUE; } int openRoiMapFile(TestEncConfig *encConfig) { if (encConfig->roi_enable) { if (encConfig->roi_file_name) { ChangePathStyle(encConfig->roi_file_name); if ((encConfig->roi_file = (FILE*)osal_fopen(encConfig->roi_file_name, "r")) == NULL) { VLOG(ERR, "fail to open ROI file, %s\n", encConfig->roi_file_name); return FALSE; } } } return TRUE; } int allocateRoiMapBuf(EncHandle handle, TestEncConfig encConfig, vpu_buffer_t *vbRoi, int srcFbNum, int ctuNum) { int i; Int32 coreIdx = handle->coreIdx; if (encConfig.roi_enable) { //number of roi buffer should be the same as source buffer num. for (i = 0; i < srcFbNum ; i++) { vbRoi[i].size = ctuNum; if (vdi_allocate_dma_memory(coreIdx, &vbRoi[i], ENC_ETC, handle->instIndex) < 0) { VLOG(ERR, "fail to allocate ROI buffer\n" ); return FALSE; } } } return TRUE; } // Define tokens for parsing scaling list file const char* MatrixType[SCALING_LIST_SIZE_NUM][SL_NUM_MATRIX] = { {"INTRA4X4_LUMA", "INTRA4X4_CHROMAU", "INTRA4X4_CHROMAV", "INTER4X4_LUMA", "INTER4X4_CHROMAU", "INTER4X4_CHROMAV"}, {"INTRA8X8_LUMA", "INTRA8X8_CHROMAU", "INTRA8X8_CHROMAV", "INTER8X8_LUMA", "INTER8X8_CHROMAU", "INTER8X8_CHROMAV"}, {"INTRA16X16_LUMA", "INTRA16X16_CHROMAU", "INTRA16X16_CHROMAV", "INTER16X16_LUMA", "INTER16X16_CHROMAU", "INTER16X16_CHROMAV"}, {"INTRA32X32_LUMA", "INTRA32X32_CHROMAU_FROM16x16_CHROMAU", "INTRA32X32_CHROMAV_FROM16x16_CHROMAV","INTER32X32_LUMA", "INTER32X32_CHROMAU_FROM16x16_CHROMAU", "INTER32X32_CHROMAV_FROM16x16_CHROMAV"} }; const char* MatrixType_DC[SCALING_LIST_SIZE_NUM - 2][SL_NUM_MATRIX] = { {"INTRA16X16_LUMA_DC", "INTRA16X16_CHROMAU_DC", "INTRA16X16_CHROMAV_DC", "INTER16X16_LUMA_DC", "INTER16X16_CHROMAU_DC", "INTER16X16_CHROMAV_DC"}, {"INTRA32X32_LUMA_DC", "INTRA32X32_CHROMAU_DC_FROM16x16_CHROMAU", "INTRA32X32_CHROMAV_DC_FROM16x16_CHROMAV", "INTER32X32_LUMA_DC","INTER32X32_CHROMAU_DC_FROM16x16_CHROMAU","INTER32X32_CHROMAV_DC_FROM16x16_CHROMAV"}, }; static Uint8* get_sl_addr(UserScalingList* sl, Uint32 size_id, Uint32 mat_id) { Uint8* addr = NULL; switch(size_id) { case SCALING_LIST_4x4: addr = sl->s4[mat_id]; break; case SCALING_LIST_8x8: addr = sl->s8[mat_id]; break; case SCALING_LIST_16x16: addr = sl->s16[mat_id]; break; case SCALING_LIST_32x32: addr = sl->s32[mat_id]; break; } return addr; } int parse_user_scaling_list(UserScalingList* sl, FILE* fp_sl, CodStd stdMode) { #define LINE_SIZE (1024) const Uint32 scaling_list_size[SCALING_LIST_SIZE_NUM] = {16, 64, 64, 64}; char line[LINE_SIZE]; Uint32 i; Uint32 size_id, mat_id, data, num_coef = 0; Uint8* src = NULL; Uint8* ref = NULL; char* ret; const char* type_str; Uint32 maxScalingListSizeNum; if (fp_sl == NULL) return 0; // for HEVC : 4x4, 8x8, 16x16, 32x32 // for AVC : 4x4, 8x8 maxScalingListSizeNum = (stdMode == STD_HEVC) ? SCALING_LIST_SIZE_NUM : SCALING_LIST_SIZE_NUM-2; for(size_id = 0; size_id < maxScalingListSizeNum; size_id++) { num_coef = scaling_list_size[size_id];//lint !e644 // for intra_y, intra_cb, intra_cr, inter_y, inter_cb, inter_cr for(mat_id = 0; mat_id < SL_NUM_MATRIX; mat_id++) { src = get_sl_addr(sl, size_id, mat_id); // for AVC : ignore scaling list of chroma8x8 if((stdMode == STD_AVC) && (size_id == SCALING_LIST_8x8 && (mat_id % 3))) continue; // for HEVC : derive scaling list of chroma32x32 from chroma16x16 if((stdMode == STD_HEVC) && (size_id == SCALING_LIST_32x32 && (mat_id % 3))) { ref = get_sl_addr(sl, size_id - 1, mat_id); for(i = 0; i < num_coef; i++) src[i] = ref[i]; continue; } fseek(fp_sl,0,0); type_str = MatrixType[size_id][mat_id]; do { ret = fgets(line, LINE_SIZE, fp_sl); if((ret == NULL) || (strstr(line, type_str) == NULL && feof(fp_sl))) { VLOG(ERR,"Error: can't read a scaling list matrix(%s)\n", type_str); return 0; } } while (strstr(line, type_str) == NULL); // get all coeff for(i = 0; i < num_coef; i++) { if(fscanf(fp_sl, "%u,", &data) != 1) { VLOG(ERR,"Error: can't read a scaling list matrix(%s)\n", type_str); return 0; } if (stdMode == STD_AVC && data < 4) { VLOG(ERR,"Error: invald value in scaling list matrix(%s %d)\n", type_str, data); return 0; } src[i] = (Uint8)data; } // get DC coeff for 16, 32 if(size_id > SCALING_LIST_8x8) { fseek(fp_sl,0,0); type_str = MatrixType_DC[size_id - 2][mat_id]; do { ret = fgets(line, LINE_SIZE, fp_sl); if((ret == NULL) || (strstr(line, type_str) == NULL && feof(fp_sl))) { VLOG(ERR,"Error: can't read a scaling list matrix(%s)\n", type_str); return 0; } } while (strstr(line, type_str) == NULL); if(fscanf(fp_sl, "%u,", &data) != 1) { VLOG(ERR,"Error: can't read a scaling list matrix(%s)\n", type_str); return 0; } if (stdMode == STD_AVC && data < 4) { VLOG(ERR,"Error: invald value in scaling list matrix(%s %d)\n", type_str, data); return 0; } if(size_id == SCALING_LIST_16x16) sl->s16dc[mat_id] = (Uint8)data; else // SCALING_LIST_32x32 sl->s32dc[mat_id/3] = (Uint8)data; } } // for matrix id } // for size id return 1; } int parse_custom_lambda(Uint32 buf[NUM_CUSTOM_LAMBDA], FILE* fp) { int i, j = 0; char lineStr[256] = {0, }; for(i = 0; i < 52; i++) { if( NULL == fgets(lineStr, 256, fp) ) { VLOG(ERR,"Error: can't read custom_lambda\n"); return 0; } else { sscanf(lineStr, "%u\n", &buf[j++]); } } for(i = 0; i < 52; i++) { if( NULL == fgets(lineStr, 256, fp) ) { VLOG(ERR,"Error: can't read custom_lambda\n"); return 0; } else sscanf(lineStr, "%u\n", &buf[j++]); } return 1; } #if defined(PLATFORM_NON_OS) || defined (PLATFORM_LINUX) struct option* ConvertOptions( struct OptionExt* cnmOpt, Uint32 nItems ) { struct option* opt; Uint32 i; opt = (struct option*)osal_malloc((Int32)(sizeof(struct option) * nItems)); if (opt == NULL) { return NULL; } for (i=0; idisplay_primaries_x[i], i, mastering->display_primaries_y[i]); } VLOG(INFO, " WHITE_POINT_X: %10d WHITE_POINT_Y: %10d\n", mastering->white_point_x, mastering->white_point_y); VLOG(INFO, " MIN_LUMINANCE: %10d MAX_LUMINANCE: %10d\n", mastering->min_display_mastering_luminance, mastering->max_display_mastering_luminance); } if(idx == H265_USERDATA_FLAG_VUI) { h265_vui_param_t* vui; vui = (h265_vui_param_t*)(pBase + pEntry[H265_USERDATA_FLAG_VUI].offset); VLOG(INFO, " VUI SAR(%d, %d)\n", vui->sar_width, vui->sar_height); VLOG(INFO, " VIDEO FORMAT(%d)\n", vui->video_format); VLOG(INFO, " COLOUR PRIMARIES(%d)\n", vui->colour_primaries); VLOG(INFO, "log2_max_mv_length_horizontal: %d\n", vui->log2_max_mv_length_horizontal); VLOG(INFO, "log2_max_mv_length_vertical : %d\n", vui->log2_max_mv_length_vertical); VLOG(INFO, "video_full_range_flag : %d\n", vui->video_full_range_flag); VLOG(INFO, "transfer_characteristics : %d\n", vui->transfer_characteristics); VLOG(INFO, "matrix_coeffs : %d\n", vui->matrix_coefficients); } if (idx == H265_USERDATA_FLAG_CHROMA_RESAMPLING_FILTER_HINT) { h265_chroma_resampling_filter_hint_t* c_resampleing_filter_hint; Uint32 i,j; c_resampleing_filter_hint = (h265_chroma_resampling_filter_hint_t*)(pBase + pEntry[H265_USERDATA_FLAG_CHROMA_RESAMPLING_FILTER_HINT].offset); VLOG(INFO, " CHROMA_RESAMPLING_FILTER_HINT\n"); VLOG(INFO, " VER_CHROMA_FILTER_IDC: %10d HOR_CHROMA_FILTER_IDC: %10d\n", c_resampleing_filter_hint->ver_chroma_filter_idc, c_resampleing_filter_hint->hor_chroma_filter_idc); VLOG(INFO, " VER_FILTERING_FIELD_PROCESSING_FLAG: %d \n", c_resampleing_filter_hint->ver_filtering_field_processing_flag); if (c_resampleing_filter_hint->ver_chroma_filter_idc == 1 || c_resampleing_filter_hint->hor_chroma_filter_idc == 1) { VLOG(INFO, " TARGET_FORMAT_IDC: %d \n", c_resampleing_filter_hint->target_format_idc); if (c_resampleing_filter_hint->ver_chroma_filter_idc == 1) { VLOG(INFO, " NUM_VERTICAL_FILTERS: %d \n", c_resampleing_filter_hint->num_vertical_filters); for (i=0; inum_vertical_filters; i++) { VLOG(INFO, " VER_TAP_LENGTH_M1[%d]: %d \n", i, c_resampleing_filter_hint->ver_tap_length_minus1[i]); for (j=0; jver_tap_length_minus1[i]; j++) { VLOG(INFO, " VER_FILTER_COEFF[%d][%d]: %d \n", i, j, c_resampleing_filter_hint->ver_filter_coeff[i][j]); } } } if (c_resampleing_filter_hint->hor_chroma_filter_idc == 1) { VLOG(INFO, " NUM_HORIZONTAL_FILTERS: %d \n", c_resampleing_filter_hint->num_horizontal_filters); for (i=0; inum_horizontal_filters; i++) { VLOG(INFO, " HOR_TAP_LENGTH_M1[%d]: %d \n", i, c_resampleing_filter_hint->hor_tap_length_minus1[i]); for (j=0; jhor_tap_length_minus1[i]; j++) { VLOG(INFO, " HOR_FILTER_COEFF[%d][%d]: %d \n", i, j, c_resampleing_filter_hint->hor_filter_coeff[i][j]); } } } } } if (idx == H265_USERDATA_FLAG_KNEE_FUNCTION_INFO) { h265_knee_function_info_t* knee_function; knee_function = (h265_knee_function_info_t*)(pBase + pEntry[H265_USERDATA_FLAG_KNEE_FUNCTION_INFO].offset); VLOG(INFO, " FLAG_KNEE_FUNCTION_INFO\n"); VLOG(INFO, " KNEE_FUNCTION_ID: %10d\n", knee_function->knee_function_id); VLOG(INFO, " KNEE_FUNCTION_CANCEL_FLAG: %d\n", knee_function->knee_function_cancel_flag); if (!knee_function->knee_function_cancel_flag) { int i; VLOG(INFO, " KNEE_FUNCTION_PERSISTENCE_FLAG: %10d\n", knee_function->knee_function_persistence_flag); VLOG(INFO, " INPUT_D_RANGE: %d\n", knee_function->input_d_range); VLOG(INFO, " INPUT_DISP_LUMINANCE: %d\n", knee_function->input_disp_luminance); VLOG(INFO, " OUTPUT_D_RANGE: %d\n", knee_function->output_d_range); VLOG(INFO, " OUTPUT_DISP_LUMINANCE: %d\n", knee_function->output_disp_luminance); VLOG(INFO, " NUM_KNEE_POINTS_M1: %d\n", knee_function->num_knee_points_minus1); for (i=0; (Uint32)inum_knee_points_minus1; i++) { VLOG(INFO, " INPUT_KNEE_POINT: %10d OUTPUT_KNEE_POINT: %10d\n", knee_function->input_knee_point[i], knee_function->output_knee_point[i]); } } } if (idx == H265_USERDATA_FLAG_ITU_T_T35_PRE) { char* itu_t_t35 = (char*)(pBase + pEntry[H265_USERDATA_FLAG_ITU_T_T35_PRE].offset); Uint32 i; VLOG(INFO, "ITU_T_T35_PRE = %d bytes, offset = %d\n",pEntry[H265_USERDATA_FLAG_ITU_T_T35_PRE].size, pEntry[H265_USERDATA_FLAG_ITU_T_T35_PRE].offset); for(i=0; isize; //pEntry[H265_USERDATA_FLAG_ITU_T_T35_PRE_2].offset = pEntry_prev->offset; } if (idx == H265_USERDATA_FLAG_COLOUR_REMAPPING_INFO) { int c, i; h265_colour_remapping_info_t* colour_remapping; colour_remapping = (h265_colour_remapping_info_t*)(pBase + pEntry[H265_USERDATA_FLAG_COLOUR_REMAPPING_INFO].offset); VLOG(INFO, " COLOUR_REMAPPING_INFO\n"); VLOG(INFO, " COLOUR_REMAP_ID: %10d\n", colour_remapping->colour_remap_id); VLOG(INFO, " COLOUR_REMAP_CANCEL_FLAG: %d\n", colour_remapping->colour_remap_cancel_flag); if (!colour_remapping->colour_remap_cancel_flag) { VLOG(INFO, " COLOUR_REMAP_PERSISTENCE_FLAG: %d\n", colour_remapping->colour_remap_persistence_flag); VLOG(INFO, " COLOUR_REMAP_VIDEO_SIGNAL_INFO_PRESENT_FLAG: %d\n", colour_remapping->colour_remap_video_signal_info_present_flag); if (colour_remapping->colour_remap_video_signal_info_present_flag) { VLOG(INFO, " COLOUR_REMAP_FULL_RANGE_FLAG: %d\n", colour_remapping->colour_remap_full_range_flag); VLOG(INFO, " COLOUR_REMAP_PRIMARIES: %d\n", colour_remapping->colour_remap_primaries); VLOG(INFO, " COLOUR_REMAP_TRANSFER_FUNCTION: %d\n", colour_remapping->colour_remap_transfer_function); VLOG(INFO, " COLOUR_REMAP_MATRIX_COEFFICIENTS: %d\n", colour_remapping->colour_remap_matrix_coefficients); } VLOG(INFO, " COLOUR_REMAP_INPUT_BIT_DEPTH: %d\n", colour_remapping->colour_remap_input_bit_depth); VLOG(INFO, " COLOUR_REMAP_OUTPUT_BIT_DEPTH: %d\n", colour_remapping->colour_remap_output_bit_depth); for( c = 0; c < H265_MAX_LUT_NUM_VAL; c++ ) { VLOG(INFO, " PRE_LUT_NUM_VAL_MINUS1[%d]: %d\n", c, colour_remapping->pre_lut_num_val_minus1[c]); if(colour_remapping->pre_lut_num_val_minus1[c] > 0) { for( i = 0; i <= colour_remapping->pre_lut_num_val_minus1[c]; i++ ) { VLOG(INFO, " PRE_LUT_CODED_VALUE[%d][%d]: %d\n", c, i, colour_remapping->pre_lut_coded_value[c][i]); VLOG(INFO, " PRE_LUT_TARGET_VALUE[%d][%d]: %d\n", c, i, colour_remapping->pre_lut_target_value[c][i]); } } } VLOG(INFO, " COLOUR_REMAP_MATRIX_PRESENT_FLAG: %d\n", colour_remapping->colour_remap_matrix_present_flag); if(colour_remapping->colour_remap_matrix_present_flag) { VLOG(INFO, " LOG2_MATRIX_DENOM: %d\n", colour_remapping->log2_matrix_denom); for( c = 0; c < H265_MAX_COLOUR_REMAP_COEFFS; c++ ) for( i = 0; i < H265_MAX_COLOUR_REMAP_COEFFS; i++ ) VLOG(INFO, " LOG2_MATRIX_DENOM[%d][%d]: %d\n", c, i, colour_remapping->colour_remap_coeffs[c][i]); } for( c = 0; c < H265_MAX_LUT_NUM_VAL; c++ ) { VLOG(INFO, " POST_LUT_NUM_VAL_MINUS1[%d]: %d\n", c, colour_remapping->post_lut_num_val_minus1[c]); if(colour_remapping->post_lut_num_val_minus1[c] > 0) { for( i = 0; i <= colour_remapping->post_lut_num_val_minus1[c]; i++) { VLOG(INFO, " POST_LUT_CODED_VALUE[%d][%d]: %d\n", c, i, colour_remapping->post_lut_coded_value[c][i]); VLOG(INFO, " POST_LUT_TARGET_VALUE[%d][%d]: %d\n", c, i, colour_remapping->post_lut_target_value[c][i]); } } } } } if (idx == H265_USERDATA_FLAG_TONE_MAPPING_INFO) { h265_tone_mapping_info_t* tone_mapping; tone_mapping = (h265_tone_mapping_info_t*)(pBase + pEntry[H265_USERDATA_FLAG_TONE_MAPPING_INFO].offset); VLOG(INFO, " FLAG_TONE_MAPPING_INFO\n"); VLOG(INFO, " TONE_MAP_ID: %10d\n", tone_mapping->tone_map_id); VLOG(INFO, " TONE_MAP_CANCEL_FLAG: %d\n", tone_mapping->tone_map_cancel_flag); if (!tone_mapping->tone_map_cancel_flag) { Uint32 i; VLOG(INFO, " TONE_MAP_PERSISTENCE_FLAG: %10d\n", tone_mapping->tone_map_persistence_flag); VLOG(INFO, " CODED_DATA_BIT_DEPTH : %d\n", tone_mapping->coded_data_bit_depth); VLOG(INFO, " TARGET_BIT_DEPTH : %d\n", tone_mapping->target_bit_depth); VLOG(INFO, " TONE_MAP_MODEL_ID : %d\n", tone_mapping->tone_map_model_id); VLOG(INFO, " MIN_VALUE : %d\n", tone_mapping->min_value); VLOG(INFO, " MAX_VALUE : %d\n", tone_mapping->max_value); VLOG(INFO, " SIGMOID_MIDPOINT : %d\n", tone_mapping->sigmoid_midpoint); VLOG(INFO, " SIGMOID_MIDPOINT : %d\n", tone_mapping->sigmoid_width); for (i=0; i<(Uint32)(1<target_bit_depth); i++) { VLOG(INFO, " START_OF_CODED_INTERVAL[%d] : %d\n", i, tone_mapping->start_of_coded_interval[i]); // [1 << target_bit_depth] // 10bits } VLOG(INFO, " NUM_PIVOTS : %d\n", tone_mapping->num_pivots); // [(1 << coded_data_bit_depth)?1][(1 << target_bit_depth)-1] // 10bits for (i=0; inum_pivots; i++) { VLOG(INFO, " CODED_PIVOT_VALUE[%d] : %d, TARGET_PIVOT_VALUE[%d] : %d\n", i, tone_mapping->coded_pivot_value[i] , i, tone_mapping->target_pivot_value[i]); } VLOG(INFO, " CAMERA_ISO_SPEED_IDC : %d\n", tone_mapping->camera_iso_speed_idc); VLOG(INFO, " CAMERA_ISO_SPEED_VALUE : %d\n", tone_mapping->camera_iso_speed_value); VLOG(INFO, " EXPOSURE_INDEX_IDC : %d\n", tone_mapping->exposure_index_idc); VLOG(INFO, " EXPOSURE_INDEX_VALUE : %d\n", tone_mapping->exposure_index_value); VLOG(INFO, " EXPOSURE_INDEX_COMPESATION_VALUE_SIGN_FLAG : %d\n", tone_mapping->exposure_compensation_value_sign_flag); VLOG(INFO, " EXPOSURE_INDEX_COMPESATION_VALUE_NUMERATOR : %d\n", tone_mapping->exposure_compensation_value_numerator); VLOG(INFO, " EXPOSURE_INDEX_COMPESATION_VALUE_DENOM_IDC : %d\n", tone_mapping->exposure_compensation_value_denom_idc); VLOG(INFO, " REF_SCREEN_LUMINANCE_WHITE : %d\n", tone_mapping->ref_screen_luminance_white); VLOG(INFO, " EXTENDED_RANGE_WHITE_LEVEL : %d\n", tone_mapping->extended_range_white_level); VLOG(INFO, " NOMINAL_BLACK_LEVEL_CODE_VALUE : %d\n", tone_mapping->nominal_black_level_code_value); VLOG(INFO, " NOMINAL_WHITE_LEVEL_CODE_VALUE : %d\n", tone_mapping->nominal_white_level_code_value); VLOG(INFO, " EXTENDED_WHITE_LEVEL_CODE_VALUE : %d\n", tone_mapping->extended_white_level_code_value); } VLOG(INFO, "\n"); } if (idx == H265_USERDATA_FLAG_CONTENT_LIGHT_LEVEL_INFO) { h265_content_light_level_info_t* content_light_level; content_light_level = (h265_content_light_level_info_t*)(pBase + pEntry[H265_USERDATA_FLAG_CONTENT_LIGHT_LEVEL_INFO].offset); VLOG(INFO, " CONTNET_LIGHT_INFO\n"); VLOG(INFO, " MAX_CONTENT_LIGHT_LEVEL : %d\n", content_light_level->max_content_light_level); VLOG(INFO, " MAX_PIC_AVERAGE_LIGHT_LEVEL : %d\n", content_light_level->max_pic_average_light_level); VLOG(INFO, "\n"); } if (idx == H265_USERDATA_FLAG_FILM_GRAIN_CHARACTERISTICS_INFO) { h265_film_grain_characteristics_t* film_grain_characteristics; int i,j,c; film_grain_characteristics = (h265_film_grain_characteristics_t*)(pBase + pEntry[H265_USERDATA_FLAG_FILM_GRAIN_CHARACTERISTICS_INFO].offset); VLOG(INFO, " FILM_GRAIN_CHARACTERISTICS_INFO\n"); VLOG(INFO, " FILM_GRAIN_CHARACTERISTICS_CANCEL_FLAG: %d\n", film_grain_characteristics->film_grain_characteristics_cancel_flag); if (!film_grain_characteristics->film_grain_characteristics_cancel_flag) { VLOG(INFO, " FILM_GRAIN_MODEL_ID: %10d\n", film_grain_characteristics->film_grain_model_id); VLOG(INFO, " SEPARATE_COLOUR_DESCRIPTION_PRESENT_FLAG: %d\n", film_grain_characteristics->separate_colour_description_present_flag); if (film_grain_characteristics->separate_colour_description_present_flag) { VLOG(INFO, " FILM_GRAIN_BIT_DEPTH_LUMA_MINUS8: %d\n", film_grain_characteristics->film_grain_bit_depth_luma_minus8); VLOG(INFO, " FILM_GRAIN_BIT_DEPTH_CHROMA_MINUS8: %d\n", film_grain_characteristics->film_grain_bit_depth_chroma_minus8); VLOG(INFO, " FILM_GRAIN_FULL_RANGE_FLAG: %d\n", film_grain_characteristics->film_grain_full_range_flag); VLOG(INFO, " FILM_GRAIN_COLOUR_PRIMARIES: %d\n", film_grain_characteristics->film_grain_colour_primaries); VLOG(INFO, " FILM_GRAIN_TRANSFER_CHARACTERISTICS: %d\n", film_grain_characteristics->film_grain_transfer_characteristics); VLOG(INFO, " FILM_GRAIN_MATRIX_COEFF: %d\n", film_grain_characteristics->film_grain_matrix_coeffs); } } VLOG(INFO, " BLENDING_MODE_ID: %d\n", film_grain_characteristics->blending_mode_id); VLOG(INFO, " LOG2_SCALE_FACTOR: %d\n", film_grain_characteristics->log2_scale_factor); for(c=0; c < H265_MAX_NUM_FILM_GRAIN_COMPONENT; c++ ) { VLOG(INFO, " COMP_MODEL_PRESENT_FLAG[%d]: %d\n", c, film_grain_characteristics->comp_model_present_flag[c]); } for(c=0; c < H265_MAX_NUM_FILM_GRAIN_COMPONENT; c++ ) { if(film_grain_characteristics->comp_model_present_flag[c]) { VLOG(INFO, " NUM_INTENSITY_INTERVALS_MINUS1[%d]: %d\n", c, film_grain_characteristics->num_intensity_intervals_minus1[c]); VLOG(INFO, " NUM_MODEL_VALUES_MINUS1[%d]: %d\n", c, film_grain_characteristics->num_model_values_minus1[c]); for(i=0; (Uint32)i <= film_grain_characteristics->num_intensity_intervals_minus1[c]; i++) { VLOG(INFO, " INTENSITY_INTERVAL_LOWER_BOUND[%d][%d]: %d\n", c, i, film_grain_characteristics->intensity_interval_lower_bound[c][i]); VLOG(INFO, " INTENSITY_INTERVAL_UPPER_BOUND[%d][%d]: %d\n", c, i, film_grain_characteristics->intensity_interval_upper_bound[c][i]); for(j=0; (Uint32)j <= film_grain_characteristics->num_model_values_minus1[c]; j++) { VLOG(INFO, " COMP_MODEL_VALUE[%d][%d][%d]: %d\n", c, i, j, film_grain_characteristics->comp_model_value[c][i][j]); } } } } VLOG(INFO, " FILM_GRAIN_CHARACTERISTICS_PERSISTENCE_FLAG: %d\n", film_grain_characteristics->film_grain_characteristics_persistence_flag); VLOG(INFO, "\n"); } } } VLOG(INFO, "===========================================\n"); } void SetMapData(int coreIdx, TestEncConfig encConfig, EncOpenParam encOP, EncParam *encParam, int srcFrameWidth, int srcFrameHeight, unsigned long addrCustomMap) { int productId = VPU_GetProductId(coreIdx); if (productId == PRODUCT_ID_521 && encOP.bitstreamFormat == STD_AVC) { Uint8 roiMapBuf[MAX_MB_NUM] = {0,}; Uint8 modeMapBuf[MAX_MB_NUM] = {0,}; AvcEncCustomMap customMapBuf[MAX_MB_NUM]; // custom map 1 MB data = 8bits int MbWidth = VPU_ALIGN16(encOP.picWidth) >> 4; int MbHeight = VPU_ALIGN16(encOP.picHeight) >> 4; int h, w, mbAddr; osal_memset(&customMapBuf[0], 0x00, MAX_MB_NUM); if (encParam->customMapOpt.customRoiMapEnable == 1) { int sumQp = 0; int bufSize = MbWidth*MbHeight; if ( (int)(osal_fread(&roiMapBuf[0], 1, bufSize, encConfig.roi_file)) != bufSize) { osal_fseek(encConfig.roi_file, 0, SEEK_SET); osal_fread(&roiMapBuf[0], 1, bufSize, encConfig.roi_file); } for (h = 0; h < MbHeight; h++) { for (w = 0; w < MbWidth; w++) { mbAddr = w + h*MbWidth; customMapBuf[mbAddr].field.mb_qp = MAX(MIN(roiMapBuf[mbAddr], 51), 0) & 0x3F; sumQp += customMapBuf[mbAddr].field.mb_qp; } } encParam->customMapOpt.roiAvgQp = (sumQp + (bufSize>>1)) / bufSize; // round off. } if (encParam->customMapOpt.customModeMapEnable == 1) { int bufSize = MbWidth*MbHeight; if ((int)(osal_fread(&modeMapBuf[0], 1, bufSize, encConfig.mode_map_file)) != bufSize) { osal_fseek(encConfig.mode_map_file, 0, SEEK_SET); osal_fread(&modeMapBuf[0], 1, bufSize, encConfig.mode_map_file); } for (h = 0; h < MbHeight; h++) { for (w = 0; w < MbWidth; w++) { mbAddr = w + h*MbWidth; customMapBuf[mbAddr].field.mb_force_mode = modeMapBuf[mbAddr] & 0x3; } } } encParam->customMapOpt.addrCustomMap = (PhysicalAddress)addrCustomMap; vdi_write_memory(coreIdx, encParam->customMapOpt.addrCustomMap, (unsigned char*)customMapBuf, MAX_MB_NUM, VDI_LITTLE_ENDIAN); } else { // for HEVC custom map. Uint8 roiMapBuf[MAX_SUB_CTU_NUM] = {0,}; Uint8 lambdaMapBuf[MAX_SUB_CTU_NUM] = {0,}; Uint8 modeMapBuf[MAX_CTU_NUM] = {0,}; EncCustomMap customMapBuf[MAX_CTU_NUM]; // custom map 1 CTU data = 64bits int ctuMapWidthCnt = VPU_ALIGN64(encOP.picWidth) >> 6; int ctuMapHeightCnt = VPU_ALIGN64(encOP.picHeight) >> 6; int ctuMapStride = VPU_ALIGN64(encOP.picWidth) >> 6; int subCtuMapStride = VPU_ALIGN64(encOP.picWidth) >> 5; int i, sumQp = 0;; int h, w, ctuPos, initQp; Uint8* src; VpuRect region[MAX_ROI_NUMBER]; /**< The size of the ROI region for H.265 (start X/Y in CTU, end X/Y int CTU) */ int roiQp[MAX_ROI_NUMBER]; /**< An importance level for the given ROI region for H.265. The higher an ROI level is, the more important the region is with a lower QP. */ osal_memset(&customMapBuf[0], 0x00, MAX_CTU_NUM * 8); if (encParam->customMapOpt.customRoiMapEnable == 1) { int bufSize = (VPU_ALIGN64(encOP.picWidth) >> 5) * (VPU_ALIGN64(encOP.picHeight) >> 5); if (productId == PRODUCT_ID_521) { if ((int)osal_fread(&roiMapBuf[0], 1, bufSize, encConfig.roi_file) != bufSize) { osal_fseek(encConfig.roi_file, 0, SEEK_SET); osal_fread(&roiMapBuf[0], 1, bufSize, encConfig.roi_file); } } else { int roiNum = 0; // sample code to convert ROI coordinate to ROI map. osal_memset(®ion[0], 0, sizeof(VpuRect)*MAX_ROI_NUMBER); osal_memset(&roiQp[0], 0, sizeof(int)*MAX_ROI_NUMBER); if (encConfig.roi_file_name[0]) { char lineStr[256] = {0,}; int val; fgets(lineStr, 256, encConfig.roi_file); sscanf(lineStr, "%d\n", &val); if (val != 0xFFFF) VLOG(ERR, "can't find the picture delimiter \n"); fgets(lineStr, 256, encConfig.roi_file); sscanf(lineStr, "%d\n", &val); // picture index fgets(lineStr, 256, encConfig.roi_file); sscanf(lineStr, "%d\n", &roiNum); // number of roi regions for (i = 0; i < roiNum; i++) { fgets(lineStr, 256, encConfig.roi_file); if (parseRoiCtuModeParam(lineStr, ®ion[i], &roiQp[i], srcFrameWidth, srcFrameHeight) == 0) { VLOG(ERR, "CFG file error : %s value is not available. \n", encConfig.roi_file_name); } } } encParam->customMapOpt.customRoiMapEnable = (roiNum != 0) ? encParam->customMapOpt.customRoiMapEnable : 0; if (encParam->customMapOpt.customRoiMapEnable) { initQp = encConfig.roi_avg_qp; GenRegionToQpMap(®ion[0], &roiQp[0], roiNum, initQp, subCtuMapStride, VPU_ALIGN64(encOP.picHeight) >> 5, &roiMapBuf[0]); } } for (h = 0; h < ctuMapHeightCnt; h++) { src = &roiMapBuf[subCtuMapStride * h * 2]; for (w = 0; w < ctuMapWidthCnt; w++, src += 2) { ctuPos = (h * ctuMapStride + w); // store in the order of sub-ctu. customMapBuf[ctuPos].field.sub_ctu_qp_0 = MAX(MIN(*src, 51), 0) & 0x3F; customMapBuf[ctuPos].field.sub_ctu_qp_1 = MAX(MIN(*(src + 1), 51), 0) & 0x3F; customMapBuf[ctuPos].field.sub_ctu_qp_2 = MAX(MIN(*(src + subCtuMapStride), 51), 0) & 0x3F; customMapBuf[ctuPos].field.sub_ctu_qp_3 = MAX(MIN(*(src + subCtuMapStride + 1), 51), 0) & 0x3F; sumQp += (customMapBuf[ctuPos].field.sub_ctu_qp_0 + customMapBuf[ctuPos].field.sub_ctu_qp_1 + customMapBuf[ctuPos].field.sub_ctu_qp_2 + customMapBuf[ctuPos].field.sub_ctu_qp_3); } } if (productId == PRODUCT_ID_521) encParam->customMapOpt.roiAvgQp = (sumQp + (bufSize>>1)) / bufSize; // round off. } if (encParam->customMapOpt.customLambdaMapEnable == 1) { int bufSize = (VPU_ALIGN64(encOP.picWidth) >> 5) * (VPU_ALIGN64(encOP.picHeight) >> 5); if ((int)osal_fread(&lambdaMapBuf[0], 1, bufSize, encConfig.lambda_map_file) != bufSize) { osal_fseek(encConfig.lambda_map_file, 0, SEEK_SET); osal_fread(&lambdaMapBuf[0], 1, bufSize, encConfig.lambda_map_file); } for (h = 0; h < ctuMapHeightCnt; h++) { src = &lambdaMapBuf[subCtuMapStride * 2 * h]; for (w = 0; w < ctuMapWidthCnt; w++, src += 2) { ctuPos = (h * ctuMapStride + w); // store in the order of sub-ctu. customMapBuf[ctuPos].field.lambda_sad_0 = *src; customMapBuf[ctuPos].field.lambda_sad_1 = *(src + 1); customMapBuf[ctuPos].field.lambda_sad_2 = *(src + subCtuMapStride); customMapBuf[ctuPos].field.lambda_sad_3 = *(src + subCtuMapStride + 1); } } } if ((encParam->customMapOpt.customModeMapEnable == 1) || (encParam->customMapOpt.customCoefDropEnable == 1)) { int bufSize = (VPU_ALIGN64(encOP.picWidth) >> 6) * (VPU_ALIGN64(encOP.picHeight) >> 6); if ((int)osal_fread(&modeMapBuf[0], 1, bufSize, encConfig.mode_map_file) != bufSize) { osal_fseek(encConfig.mode_map_file, 0, SEEK_SET); osal_fread(&modeMapBuf[0], 1, bufSize, encConfig.mode_map_file); } for (h = 0; h < ctuMapHeightCnt; h++) { src = &modeMapBuf[ctuMapStride * h]; for (w = 0; w < ctuMapWidthCnt; w++, src++) { ctuPos = (h * ctuMapStride + w); customMapBuf[ctuPos].field.ctu_force_mode = (*src) & 0x3; customMapBuf[ctuPos].field.ctu_coeff_drop = ((*src) >> 2) & 0x1; } } } encParam->customMapOpt.addrCustomMap = (PhysicalAddress)addrCustomMap; vdi_write_memory(coreIdx, encParam->customMapOpt.addrCustomMap, (unsigned char*)customMapBuf, MAX_CTU_NUM * 8, VDI_LITTLE_ENDIAN); } } RetCode SetChangeParam(EncHandle handle, TestEncConfig encConfig, EncOpenParam encOP __attribute__((unused)), Int32 changedCount) { int i; RetCode ret; ENC_CFG ParaChagCfg; EncChangeParam changeParam; osal_memset(&ParaChagCfg, 0x00, sizeof(ENC_CFG)); osal_memset(&changeParam, 0x00, sizeof(EncChangeParam)); parseWaveChangeParamCfgFile(&ParaChagCfg, encConfig.changeParam[changedCount].cfgName); changeParam.enable_option = encConfig.changeParam[changedCount].enableOption; if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_PPS) { changeParam.constIntraPredFlag = ParaChagCfg.waveCfg.constIntraPredFlag; changeParam.lfCrossSliceBoundaryEnable = ParaChagCfg.waveCfg.lfCrossSliceBoundaryEnable; changeParam.weightPredEnable = ParaChagCfg.waveCfg.weightPredEnable; changeParam.disableDeblk = ParaChagCfg.waveCfg.disableDeblk; changeParam.betaOffsetDiv2 = ParaChagCfg.waveCfg.betaOffsetDiv2; changeParam.tcOffsetDiv2 = ParaChagCfg.waveCfg.tcOffsetDiv2; changeParam.chromaCbQpOffset = ParaChagCfg.waveCfg.chromaCbQpOffset; changeParam.chromaCrQpOffset = ParaChagCfg.waveCfg.chromaCrQpOffset; if (encConfig.stdMode == STD_AVC) { changeParam.transform8x8Enable = ParaChagCfg.waveCfg.transform8x8; changeParam.entropyCodingMode = ParaChagCfg.waveCfg.entropyCodingMode; } } if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_INDEPEND_SLICE) { changeParam.independSliceMode = ParaChagCfg.waveCfg.independSliceMode; changeParam.independSliceModeArg = ParaChagCfg.waveCfg.independSliceModeArg; if (encConfig.stdMode == STD_AVC) { changeParam.avcSliceMode = ParaChagCfg.waveCfg.avcSliceMode; changeParam.avcSliceArg = ParaChagCfg.waveCfg.avcSliceArg; } } if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_DEPEND_SLICE) { changeParam.dependSliceMode = ParaChagCfg.waveCfg.dependSliceMode; changeParam.dependSliceModeArg = ParaChagCfg.waveCfg.dependSliceModeArg; } if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_RDO) { changeParam.coefClearDisable = ParaChagCfg.waveCfg.coefClearDisable; changeParam.intraNxNEnable = ParaChagCfg.waveCfg.intraNxNEnable; changeParam.maxNumMerge = ParaChagCfg.waveCfg.maxNumMerge; changeParam.customLambdaEnable = ParaChagCfg.waveCfg.customLambdaEnable; changeParam.customMDEnable = ParaChagCfg.waveCfg.customMDEnable; if (encConfig.stdMode == STD_AVC) { changeParam.rdoSkip = ParaChagCfg.waveCfg.rdoSkip; changeParam.lambdaScalingEnable = ParaChagCfg.waveCfg.lambdaScalingEnable; } } if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_RC_FRAME_RATE) { changeParam.frameRate = ParaChagCfg.waveCfg.frameRate; } if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_RC_TARGET_RATE) { changeParam.bitRate = ParaChagCfg.RcBitRate; } if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_RC) { changeParam.hvsQPEnable = ParaChagCfg.waveCfg.hvsQPEnable; changeParam.hvsQpScale = ParaChagCfg.waveCfg.hvsQpScale; changeParam.vbvBufferSize = ParaChagCfg.VbvBufferSize; } if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_RC_MIN_MAX_QP) { changeParam.minQpI = ParaChagCfg.waveCfg.minQp; changeParam.maxQpI = ParaChagCfg.waveCfg.maxQp; changeParam.hvsMaxDeltaQp = ParaChagCfg.waveCfg.maxDeltaQp; } if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_RC_INTER_MIN_MAX_QP) { changeParam.minQpP = ParaChagCfg.waveCfg.minQp; changeParam.minQpB = ParaChagCfg.waveCfg.minQp; changeParam.maxQpP = ParaChagCfg.waveCfg.maxQp; changeParam.maxQpB = ParaChagCfg.waveCfg.maxQp; } if (changeParam.enable_option & ENC_SET_CHANGE_PARAM_RC_BIT_RATIO_LAYER) { for (i=0 ; i NULL point exception\n", __FUNCTION__, __LINE__); return FALSE; } coreIdx = VPU_HANDLE_CORE_INDEX(handle); if (0 == streamBufStartAddr || 0 == streamBufEndAddr) { VLOG(ERR, "<%s:%d> Wrong Address, start or end Addr\n", __FUNCTION__, __LINE__); return FALSE; } else if (0 == rdAddr || 0 == wrAddr) { VLOG(ERR, "<%s:%d> Wrong Address, read or write Addr\n", __FUNCTION__, __LINE__); return FALSE; } if (TRUE == ringbufferEnabled) { if ((rdAddr + streamSize) > streamBufEndAddr) { //wrap around on ringbuffer room = streamBufEndAddr - rdAddr; vdi_read_memory(coreIdx, rdAddr, pBuffer, room, endian); vdi_read_memory(coreIdx, streamBufStartAddr, pBuffer + room, (streamSize-room), endian); } else { vdi_read_memory(coreIdx, rdAddr, pBuffer, streamSize, endian); } } else { //Line buffer vdi_read_memory(coreIdx, rdAddr, pBuffer, streamSize, endian); } return TRUE; } typedef struct CommandLineArgument{ int argc; char **argv; }CommandLineArgument; CODEC_ERR_STATE nc_init_encoder(ENCParameter *get_param) { const char* fwPath = NULL; TestEncConfig testConfig; Uint32 sizeInWord; Uint16* pusBitCode; mq_unlink(MQ_NAME_DATA_TO_ENCODE); osal_memset(&enc_config, 0x00, sizeof(CNMComponentConfig)); SetDefaultEncTestConfig(&testConfig); testConfig.stdMode = (CodStd)get_param->enc_codec_type; testConfig.productId = (ProductId)VPU_GetProductId(testConfig.coreIdx); if(testConfig.productId == PRODUCT_ID_521) { fwPath = getenv("VIDEO_CODEC_FIRMWARE_FILE"); nc_trim((char*)fwPath); if(fwPath == NULL || fwPath[0] == '\0') { fwPath = CORE_6_BIT_CODE_FILE_PATH; } } else { VLOG(ERR, "Unknown product id: %d\n", testConfig.productId); return ERR_ENC_INVALID_PRODUCT_ID; } if (LoadFirmware(testConfig.productId, (Uint8**)&pusBitCode, &sizeInWord, fwPath) < 0) { VLOG(ERR, "Failed to load firmware: %s\n", fwPath); return ERR_ENC_LOAD_FIRMWARE; } enc_config.testEncConfig = testConfig; enc_config.bitcode = (Uint8*)pusBitCode; enc_config.sizeOfBitcode = sizeInWord; enc_config.testEncConfig.subFrameSyncMode = REGISTER_BASE_SUB_FRAME_SYNC; if (SetupEncoderOpenParam(&enc_config.encOpenParam, &enc_config.testEncConfig, NULL, get_param) == FALSE) { VLOG(ERR, "SetupEncoderOpenParam error\n"); return ERR_ENC_INVALID_PARAM; } return CODEC_SUCCESS; } CODEC_ERR_STATE nc_start_encoder(void) { int ret; CNMTask task; Component yuvFeeder; Component encoder; Component reader; EncListenerContext lsnCtx; CNMAppInit(); task = CNMTaskCreate(); yuvFeeder = ComponentCreate("yuvfeeder", &enc_config); encoder = ComponentCreate("wave_encoder", &enc_config); reader = ComponentCreate("reader", &enc_config); CNMTaskAdd(task, yuvFeeder); CNMTaskAdd(task, encoder); CNMTaskAdd(task, reader); CNMAppAdd(task); if ((ret=SetupEncListenerContext(&lsnCtx, &enc_config)) == TRUE) { ComponentRegisterListener(encoder, COMPONENT_EVENT_ENC_ALL, EncoderListener, (void*)&lsnCtx); if(!CNMAppRun()) { VLOG(ERR, "Fail to create encoder pipeline\n"); return ERR_ENC_CREATE_PIPELINE; } } else { CNMAppStop(); VLOG(ERR, "Fail to create event listner\n"); return ERR_ENC_CREATE_EVENT_LISTNER; } osal_free(enc_config.bitcode); ClearEncListenerContext(&lsnCtx); return CODEC_SUCCESS; } CODEC_ERR_STATE nc_send_buf_to_encode(Uint8 *ptr_video_buf, int32 auto_free) { CODEC_ERR_STATE ret = CODEC_SUCCESS; struct mq_attr attr; attr.mq_maxmsg = MAX_MQ_SIZE_ENC; attr.mq_msgsize = sizeof(Uint8*); int oflag = O_WRONLY | O_CREAT; auto_free_data_for_encode = auto_free; mqd_t mfd = mq_open(MQ_NAME_DATA_TO_ENCODE, oflag, 0666, &attr); if (mfd == -1) { perror("mq open error"); return ERR_ENC_FAIL_TO_OPEN; } if ((mq_send(mfd, (const char *)&ptr_video_buf, attr.mq_msgsize, 1)) == -1) { ret = ERR_ENC_SEND_BUF; printf("errno of mq_send = %d\n", errno); } mq_close(mfd); return ret; } CODEC_ERR_STATE nc_receive_buf_to_encode(Uint8 **out_video_buf, int32 *auto_free) { CODEC_ERR_STATE ret = CODEC_SUCCESS; struct mq_attr attr; attr.mq_maxmsg = MAX_MQ_SIZE_ENC; attr.mq_msgsize = sizeof(Uint8 *); int oflag = O_RDONLY | O_CREAT; mqd_t mfd = mq_open(MQ_NAME_DATA_TO_ENCODE, oflag, 0666, &attr); if (mfd == -1) { perror("mq open error"); return ERR_ENC_FAIL_TO_OPEN; } *auto_free = auto_free_data_for_encode; if (((int)mq_receive(mfd, (char*)out_video_buf, attr.mq_msgsize, NULL)) == -1) { ret = ERR_ENC_RECEIVE_BUF; printf("errno of mq_receive = %d\n", errno); } mq_close(mfd); return ret; } void nc_stop_encoder(void) { CNMAppStop(); } static BOOL CheckDecConfig(TestDecConfig testConfig) { BOOL isValidParameters = TRUE; /* Check parameters */ if (testConfig.skipMode < 0 || testConfig.skipMode == 3 || testConfig.skipMode > 4) { VLOG(ERR, "Invalid skip mode: %d\n", testConfig.skipMode); isValidParameters = FALSE; } if ((FORMAT_422 < testConfig.wtlFormat && testConfig.wtlFormat <= FORMAT_400) || testConfig.wtlFormat < FORMAT_420 || testConfig.wtlFormat >= FORMAT_MAX) { VLOG(ERR, "Invalid WTL format(%d)\n", testConfig.wtlFormat); isValidParameters = FALSE; } if (isValidParameters == TRUE && (testConfig.scaleDownWidth > 0 || testConfig.scaleDownHeight > 0)) { } if (testConfig.renderType < RENDER_DEVICE_NULL || testConfig.renderType >= RENDER_DEVICE_MAX) { VLOG(ERR, "unknown render device type(%d)\n", testConfig.renderType); isValidParameters = FALSE; } if (testConfig.thumbnailMode == TRUE && testConfig.skipMode != 0) { VLOG(ERR, "Turn off thumbnail mode or skip mode\n"); isValidParameters = FALSE; } if (STD_AVC == testConfig.bitFormat || STD_AV1 == testConfig.bitFormat) { isValidParameters = (testConfig.secondaryAXI&0x04) ? FALSE : TRUE; if (!isValidParameters) { VLOG(ERR, "AVC/AV1 do not support tBPU secondary AXI. \n"); } } return isValidParameters; } CODEC_ERR_STATE nc_init_decoder(DECParameter *get_param) { const char* fwPath = NULL; TestDecConfig testConfig; Uint32 sizeInWord; Uint16* pusBitCode; BOOL ret; mq_unlink(MQ_NAME_DATA_TO_DECODE); osal_memset(&dec_config, 0x00, sizeof(CNMComponentConfig)); SetDefaultDecTestConfig(&testConfig); testConfig.bitFormat = (CodStd)get_param->dec_codec_type; testConfig.fps = get_param->dec_framerate; if (CheckDecConfig(testConfig) == FALSE) { VLOG(ERR, "fail to CheckDecConfig()\n"); return ERR_DEC_INVALID_PARAM; } testConfig.productId = (ProductId)VPU_GetProductId(testConfig.coreIdx); if(testConfig.productId == PRODUCT_ID_521) { fwPath = getenv("VIDEO_CODEC_FIRMWARE_FILE"); nc_trim((char*)fwPath); if(fwPath == NULL || fwPath[0] == '\0') { fwPath = CORE_6_BIT_CODE_FILE_PATH; } } else { VLOG(ERR, "Unknown product id: %d\n", testConfig.productId); return ERR_DEC_INVALID_PRODUCT_ID; } if (LoadFirmware(testConfig.productId, (Uint8**)&pusBitCode, &sizeInWord, fwPath) < 0) { VLOG(ERR, "Failed to load firmware: %s\n", fwPath); return ERR_DEC_LOAD_FIRMWARE; } dec_config.testDecConfig = testConfig; dec_config.bitcode = (Uint8*)pusBitCode; dec_config.sizeOfBitcode = sizeInWord; printf("\n==================================================\n"); printf(" DEC CONFIGURATION\n"); printf("\n dec_framerate : %d\n", testConfig.fps ); printf("==================================================\n"); if (RETCODE_SUCCESS != (ret=SetUpDecoderOpenParam(&(dec_config.decOpenParam), &(dec_config.testDecConfig)))) { VLOG(ERR, "SetUpDecoderOpenParam failed Error code is 0x%x \n", ret); return ERR_DEC_INVALID_PARAM; } return CODEC_SUCCESS; } CODEC_ERR_STATE nc_start_decoder(void) { CNMTask task; Component feeder; Component decoder; Component renderer; BOOL ret; DecListenerContext lsnCtx; CNMAppInit(); task = CNMTaskCreate(); feeder = ComponentCreate("feeder", &dec_config); decoder = ComponentCreate("wave_decoder", &dec_config); renderer = ComponentCreate("renderer", &dec_config); CNMTaskAdd(task, feeder); CNMTaskAdd(task, decoder); CNMTaskAdd(task, renderer); CNMAppAdd(task); if ((ret=SetupDecListenerContext(&lsnCtx, &dec_config, renderer)) == TRUE) { ComponentRegisterListener(decoder, COMPONENT_EVENT_DEC_ALL, DecoderListener, (void*)&lsnCtx); if(!CNMAppRun()) { VLOG(ERR, "Fail to create decoder pipeline\n"); return ERR_DEC_CREATE_PIPELINE; } } else { CNMAppStop(); VLOG(ERR, "Fail to create event listner\n"); return ERR_DEC_CREATE_EVENT_LISTNER; } osal_free(dec_config.bitcode); ClearDecListenerContext(&lsnCtx); return CODEC_SUCCESS; } void nc_stop_decoder(void) { CNMAppStop(); } void nc_display_libncvcodec_info(void) { printf("\n================================================== \n"); printf(" Nextchip Video CODEC library info \n\n"); printf(" Build Date : %s %s \n", APP_BUILD_DATE, APP_BUILD_TIME); printf(" Library Version : ver.%02d.%02d.%02d \n", APP_VER_MAJOR, APP_VER_MINOR1, APP_VER_MINOR2); printf(" Git Hash : %s \n", GIT_HEAD_HASH); printf("================================================== \n"); } CODEC_ERR_STATE nc_send_buf_to_decode(Uint8 *ptr_video_buf, Uint32 size, Int32 end_of_file, Int32 auto_free) { DECODED_DATA *get_decode_data; CODEC_ERR_STATE ret = CODEC_SUCCESS; struct mq_attr attr; attr.mq_maxmsg = MAX_MQ_SIZE_DEC; attr.mq_msgsize = sizeof(DECODED_DATA*); int oflag = O_WRONLY | O_CREAT; auto_free_data_for_decode = auto_free; get_decode_data = (DECODED_DATA*)malloc(sizeof(DECODED_DATA)); get_decode_data->ptr_decoded_buf = ptr_video_buf; get_decode_data->size = size; get_decode_data->end_of_file = end_of_file; mqd_t mfd = mq_open(MQ_NAME_DATA_TO_DECODE, oflag, 0666, &attr); if (mfd == -1) { perror("mq open error"); return ERR_DEC_FAIL_TO_OPEN; } if ((mq_send(mfd, (const char *)&get_decode_data, attr.mq_msgsize, 1)) == -1) { ret = ERR_DEC_SEND_BUF; printf("############# errno of mq_send = %d\n", errno); } mq_close(mfd); return ret; } CODEC_ERR_STATE nc_receive_buf_to_decode(DECODED_DATA **out_video_buf, int32 *auto_free) { CODEC_ERR_STATE ret = CODEC_SUCCESS; struct mq_attr attr; attr.mq_maxmsg = MAX_MQ_SIZE_DEC; attr.mq_msgsize = sizeof(DECODED_DATA *); int oflag = O_RDONLY | O_CREAT; mqd_t mfd = mq_open(MQ_NAME_DATA_TO_DECODE, oflag, 0666, &attr); if (mfd == -1) { perror("mq open error"); return ERR_DEC_FAIL_TO_OPEN; } *auto_free = auto_free_data_for_decode; if (((int)mq_receive(mfd, (char*)out_video_buf, attr.mq_msgsize, NULL)) == -1) { ret = ERR_DEC_RECEIVE_BUF; printf("errno of mq_receive = %d\n", errno); } mq_close(mfd); return ret; } void nc_lock_encoding_done(void) { pthread_mutex_lock(&encoded_lock); } void nc_unlock_encoding_done(void) { pthread_mutex_unlock(&encoded_lock); }