Dear Experts!
Can you please explain the link flow or provide some source code example for feeding the encoder from host with yuv frames.
Really appreciate any help here, because I'm stuck with NullSrc and it gives me some garbage frames, don't know how to go from there.
BR.
Ilia.
#include <stdio.h> #include <signal.h> #include <string.h> #include <stdlib.h> #include <getopt.h> #include <time.h> #include <stdint.h> #include <unistd.h> #include <demos/link_api_demos/common/chains.h> #include <../../interfaces/link_api/system.h> #include <../../interfaces/link_api/captureLink.h> #include <../../interfaces/link_api/nsfLink.h> #include <../../interfaces/link_api/nullLink.h> #include <../../interfaces/link_api/dupLink.h> #include <../../interfaces/link_api/ipcLink.h> #include <../../interfaces/link_api/systemLink_m3vpss.h> #include <../../interfaces/link_api/systemLink_m3video.h> #include <../../interfaces/link_api/encLink.h> #include <../../interfaces/link_api/system_tiler.h> #include "ti_vdis_common_def.h" #include "ti_vdec_common_def.h" #include "ti_vsys.h" #include "ti_vcap.h" #include "ti_venc.h" #include "ti_vdec.h" #include "ti_vdis.h" #include "ti_vdis_timings.h" #include "ti_audio.h" /** definition de debug */ #define ENABLE_NSF 0 #define ENABLE_LOG_BUFFER 0 #define MAX_INPUT_STR_SIZE (128) #define ENABLE_TIME_BUFFER 0 #define ENABLE_LOG_GLOBAL 0 #define IPC_FRAMERATE 1.0 /*****************************/ UInt32 _captureId = SYSTEM_LINK_ID_CAPTURE; UInt32 _srcId = SYSTEM_VPSS_LINK_ID_NULL_SRC_0; UInt32 _encId = SYSTEM_LINK_ID_VENC_0; UInt32 _ipcBitsOutVpssId = SYSTEM_VPSS_LINK_ID_IPC_OUT_M3_0; UInt32 _ipcBitsInVideoId = SYSTEM_VIDEO_LINK_ID_IPC_IN_M3_0; UInt32 _ipcBitsOutVideoId = SYSTEM_VIDEO_LINK_ID_IPC_BITS_OUT_0; UInt32 _ipcBitsInHostId = SYSTEM_HOST_LINK_ID_IPC_BITS_IN_0; FILE *_fout = NULL; #define MAX_PATH_SIZE 255 #define NUM_CAPTURE_DEVICES (1) #define SRC_NUM_CH 1 typedef struct { UInt32 res0; UInt32 num_layers; UInt32 width[NUM_CAPTURE_DEVICES]; UInt32 height[NUM_CAPTURE_DEVICES]; UInt32 framerate[NUM_CAPTURE_DEVICES]; UInt32 bitrate; VCODEC_TYPE_E codec; UInt32 gopsize[NUM_CAPTURE_DEVICES]; char *Pt_file; }Config_struct; /*IVA HD MAP Table*/ static SystemVideo_Ivahd2ChMap_Tbl _systemVid_encDecIvaChMapTbl = { .isPopulated = 1, .ivaMap[0] = { .EncNumCh = 1, .EncChList = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0 , 0, 0}, .DecNumCh = 0, .DecChList = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, }, .ivaMap[1] = { .EncNumCh = 1, .EncChList = {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, .DecNumCh = 0, .DecChList = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, }, .ivaMap[2] = { .EncNumCh = 1, .EncChList = {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, .DecNumCh = 0, .DecChList = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, }, }; int run = 1; void sighandler(int signum) { if (signum == SIGINT) { printf("Signal interrupt received\n"); run = 0; } } Void capture_encode_bitsWriteCbFxn(Ptr pPrm) { Bitstream_BufList bitsBuf; Bitstream_Buf *pBuf; Int32 frameId; Int32 status; unsigned long writeDataSize; #if ENABLE_TIME_BUFFER || ENABLE_LOG_BUFFER static unsigned long countImage = 0; #endif /* Get buffer list from the IPC Link*/ bitsBuf.numBufs = 0; //printf(" Before IpcBitsInLink_getFullVideoBitStreamBufs\n"); status = IpcBitsInLink_getFullVideoBitStreamBufs(_ipcBitsInHostId, &bitsBuf); //printf(" After IpcBitsInLink_getFullVideoBitStreamBufs\n"); if( (status == 0 ) && (bitsBuf.numBufs) && (_fout != NULL) ) { for(frameId = 0; frameId < bitsBuf.numBufs ; frameId++ ) { pBuf = bitsBuf.bufs[frameId]; if( pBuf->fillLength > 0 ) { writeDataSize = fwrite(pBuf->addr, sizeof(char),pBuf->fillLength, _fout); //printf("pBuf->temporalId %d\n",pBuf->temporalId); if( writeDataSize != pBuf->fillLength) { //fclose(_fout); //_fout = NULL; printf(" Error write : Closing file\n"); } #if ENABLE_TIME_BUFFER printf("******************************\n"); printf("countImage %lu:%lu\n",countImage++,(unsigned long)bitsBuf.numBufs); printf("timeStamp %lu\n",(unsigned long)pBuf->timeStamp); printf("encodeTimeStamp %lu\n",(unsigned long)pBuf->encodeTimeStamp); printf("isKeyFrame %lu\n",(unsigned long)pBuf->isKeyFrame); #endif #if ENABLE_LOG_BUFFER if((countImage++ %100)==0) { printf("******************************\n"); printf("countImage %lu\n",countImage); printf("codingType %d\n",pBuf->codingType); printf("channelNum %d\n",pBuf->channelNum); printf("%d:%d\n",pBuf->frameWidth,pBuf->frameHeight); printf("timeStamp %lu\n",(unsigned long)pBuf->timeStamp); printf("capture timestamp up %lu\n",(unsigned long)pBuf->upperTimeStamp); printf("capture timestamp low %lu\n",(unsigned long)pBuf->lowerTimeStamp); printf("encodeTimeStamp %lu\n",(unsigned long)pBuf->encodeTimeStamp); printf("isKeyFrame %lu\n",(unsigned long)pBuf->isKeyFrame); printf("doNotDisplay %d\n",pBuf->doNotDisplay); printf("seqId %d\n",pBuf->seqId); printf("inputFileChanged %d\n",pBuf->inputFileChanged); printf("flushFrame %d\n",pBuf->flushFrame); printf("allocPoolID %d\n",pBuf->allocPoolID); printf("temporalId %d\n",pBuf->temporalId); printf("numTemporalLayerSetInCodec %d\n",pBuf->numTemporalLayerSetInCodec); printf("bufSize %lu\n",(unsigned long)pBuf->bufSize); printf("fillLength %lu\n",(unsigned long)pBuf->fillLength); printf("startOffset %lu\n",(unsigned long)pBuf->startOffset); printf("mvDataOffset %lu\n",(unsigned long)pBuf->mvDataOffset); printf("mvDataFilledSize %lu\n",(unsigned long)pBuf->mvDataFilledSize); printf("phyAddr 0x%08lX\n",(unsigned long)pBuf->phyAddr); } #endif } } } /* Release buffer list back to the IPC Link*/ /* On relese tout le temps même si pas de données dispo */ IpcBitsInLink_putEmptyVideoBitStreamBufs(_ipcBitsInHostId, &bitsBuf); } void capture_encode_ipcBitsInitCreateParams_BitsInHLOS(IpcBitsInLinkHLOS_CreateParams *cp) { cp->baseCreateParams.noNotifyMode = FALSE; //FALSE; cp->cbFxn = capture_encode_bitsWriteCbFxn; cp->cbCtx = NULL; cp->baseCreateParams.notifyNextLink = FALSE; /* Previous link of bitsInHLOS is bitsOutRTOS. So, notifyPrevLink * should be set to false if bitsInHLOS is to operate in * NO_NOTIFY_MODE */ cp->baseCreateParams.notifyPrevLink = TRUE;//TRUE; } void capture_encode_ipcBitsInitCreateParams_BitsOutRTOS(IpcBitsOutLinkRTOS_CreateParams *cp, Bool notifyPrevLink) { /* Next link of bitsOutRTOS is bitsInHLOS. So, notifyPrevLink * should be set to false if bitsInHLOS is to operate in * NO_NOTIFY_MODE */ cp->baseCreateParams.noNotifyMode = FALSE; //FALSE; cp->baseCreateParams.notifyNextLink = TRUE;//TRUE; cp->baseCreateParams.notifyPrevLink = notifyPrevLink; } int capture_encode_dynamique_parameters(Config_struct *Pt_Conf) { CaptureLink_SetResolution vcapSetRes = {0}; EncLink_ChFpsParams params; Int32 status = ERROR_NONE; /* On force la résolution */ vcapSetRes.queId = 0; vcapSetRes.chId = 0; vcapSetRes.width = SystemUtils_align(Pt_Conf->width[0],16); vcapSetRes.height = SystemUtils_align(Pt_Conf->height[0], 1); status = System_linkControl(_captureId,CAPTURE_LINK_CMD_SET_RESOLUTION, &(vcapSetRes),sizeof(vcapSetRes), TRUE ); #if 1 /* configuration de la frequence image */ params.chId = 0; /* New fps vaule in fps x 1000 formate */ params.targetFps = Pt_Conf->framerate[0] *1000; /* Corresponding bitrate value */ params.targetBitRate = Pt_Conf->bitrate*1000; //System_linkControl(_encId, ENC_LINK_CMD_SET_CODEC_INPUT_FPS, // ¶ms, sizeof(params), TRUE); System_linkControl(_encId, ENC_LINK_CMD_SET_CODEC_FPS, ¶ms, sizeof(params), TRUE); #endif return 0; } void capture_encode_start(Config_struct *Pt_Conf) { NullSrcLink_CreateParams srcPrm;//L //CaptureLink_CreateParams capturePrm;//L IpcLink_CreateParams ipcOutVpssPrm; IpcLink_CreateParams ipcInVideoPrm; EncLink_CreateParams encPrm; IpcBitsOutLinkRTOS_CreateParams ipcBitsOutVideoPrm; IpcBitsInLinkHLOS_CreateParams ipcBitsInHostPrm; // System_LinkInfo framesProducerLinkInfo; // CaptureLink_VipInstParams *pCaptureInstPrm = NULL;//L // CaptureLink_OutParams *pCaptureOutPrm = NULL;//L //VCAP_VIDDEC_PARAMS_S vidDecVideoModeArgs[NUM_CAPTURE_DEVICES]; Bool isProgressive=TRUE; UInt32 i/*,vipInstId //L*//*, status*/; //Bool switchCh; //Bool switchLayout; //char ch; printf("NME : capture_encode_start\n"); //UInt32 _captureId = SYSTEM_LINK_ID_CAPTURE;//L _encId = SYSTEM_LINK_ID_VENC_0; _ipcBitsOutVpssId = SYSTEM_VPSS_LINK_ID_IPC_OUT_M3_0; _ipcBitsInVideoId = SYSTEM_VIDEO_LINK_ID_IPC_IN_M3_0; _ipcBitsOutVideoId = SYSTEM_VIDEO_LINK_ID_IPC_BITS_OUT_0; _ipcBitsInHostId = SYSTEM_HOST_LINK_ID_IPC_BITS_IN_0; System_linkControl( SYSTEM_LINK_ID_M3VPSS, SYSTEM_M3VPSS_CMD_RESET_VIDEO_DEVICES, NULL, 0, TRUE ); System_linkControl( SYSTEM_LINK_ID_M3VIDEO, SYSTEM_COMMON_CMD_SET_CH2IVAHD_MAP_TBL, &_systemVid_encDecIvaChMapTbl, sizeof(SystemVideo_Ivahd2ChMap_Tbl), TRUE ); //Chains_ipcBitsInit(); //CHAINS_INIT_STRUCT(CaptureLink_CreateParams, capturePrm);//L CHAINS_INIT_STRUCT(IpcLink_CreateParams, ipcOutVpssPrm); CHAINS_INIT_STRUCT(IpcLink_CreateParams, ipcInVideoPrm); CHAINS_INIT_STRUCT(EncLink_CreateParams, encPrm); CHAINS_INIT_STRUCT(IpcBitsOutLinkRTOS_CreateParams, ipcBitsOutVideoPrm); CHAINS_INIT_STRUCT(IpcBitsInLinkHLOS_CreateParams, ipcBitsInHostPrm); //CaptureLink_CreateParams_Init(&capturePrm);//L ///capturePrm.numVipInst = 1; /* on utilise qu'un seul VIP inst *///L // capturePrm.outQueParams[0].nextLink = _ipcBitsOutVpssId;//L /*//L capturePrm.tilerEnable = FALSE; capturePrm.enableSdCrop = FALSE; capturePrm.isPalMode = FALSE; capturePrm.numBufsPerCh = 8; capturePrm.numExtraBufs = 0; capturePrm.maxBlindAreasPerCh = 0; capturePrm.doCropInCapture = FALSE; printf("NME : init pCaptureInstPrm\n"); for(vipInstId=0; vipInstId< capturePrm.numVipInst ; vipInstId++) { pCaptureInstPrm = &capturePrm.vipInst[vipInstId]; pCaptureInstPrm->vipInstId = (SYSTEM_CAPTURE_INST_VIP0_PORTA+vipInstId) % SYSTEM_CAPTURE_INST_MAX; pCaptureInstPrm->videoDecoderId = 0;//SYSTEM_DEVICE_VID_DEC_TVP5158_DRV; pCaptureInstPrm->inDataFormat = SYSTEM_DF_YUV422P; pCaptureInstPrm->standard = Pt_Conf->res0; pCaptureInstPrm->numOutput = 1; pCaptureInstPrm->numChPerOutput = 1; pCaptureOutPrm = &pCaptureInstPrm->outParams[0]; pCaptureOutPrm->dataFormat = SYSTEM_DF_YUV420SP_UV; //pCaptureOutPrm->dataFormat = SYSTEM_DF_YUV422I_UYVY; //pCaptureOutPrm->dataFormat = SYSTEM_DF_YUV422P; pCaptureOutPrm->scEnable = TRUE; pCaptureOutPrm->scOutWidth = Pt_Conf->width[vipInstId]; pCaptureOutPrm->scOutHeight = Pt_Conf->height[vipInstId]; pCaptureOutPrm->outQueId = 0; switch(pCaptureInstPrm->standard) { case VSYS_STD_NTSC: case VSYS_STD_PAL: case VSYS_STD_480I: case VSYS_STD_576I: case VSYS_STD_CIF: case VSYS_STD_HALF_D1: case VSYS_STD_D1: pCaptureInstPrm->inDataFormat = SYSTEM_DF_YUV422I_UYVY; pCaptureInstPrm->videoIfMode = SYSTEM_CAPT_VIDEO_IF_MODE_8BIT; pCaptureInstPrm->inScanFormat = SYSTEM_SF_INTERLACED; pCaptureInstPrm->videoCaptureMode = SYSTEM_CAPT_VIDEO_CAPTURE_MODE_SINGLE_CH_NON_MUX_EMBEDDED_SYNC; break; case VSYS_STD_1080I_60: case VSYS_STD_1080I_50: pCaptureInstPrm->inDataFormat = SYSTEM_DF_YUV422I_UYVY; pCaptureInstPrm->videoIfMode = SYSTEM_CAPT_VIDEO_IF_MODE_16BIT; pCaptureInstPrm->inScanFormat = SYSTEM_SF_INTERLACED; pCaptureInstPrm->videoCaptureMode = SYSTEM_CAPT_VIDEO_CAPTURE_MODE_SINGLE_CH_NON_MUX_EMBEDDED_SYNC; break; case VSYS_STD_480P: case VSYS_STD_576P: pCaptureInstPrm->inDataFormat = SYSTEM_DF_YUV422SP_UV; pCaptureInstPrm->videoIfMode = SYSTEM_CAPT_VIDEO_IF_MODE_8BIT; pCaptureInstPrm->inScanFormat = SYSTEM_SF_PROGRESSIVE; pCaptureInstPrm->videoCaptureMode = SYSTEM_CAPT_VIDEO_CAPTURE_MODE_SINGLE_CH_NON_MUX_EMBEDDED_SYNC; break; case VSYS_STD_720P_60: case VSYS_STD_720P_50: case VSYS_STD_1080P_60: case VSYS_STD_1080P_50: case VSYS_STD_1080P_24: case VSYS_STD_1080P_30: pCaptureInstPrm->inDataFormat = SYSTEM_DF_YUV422P; pCaptureInstPrm->videoIfMode = SYSTEM_CAPT_VIDEO_IF_MODE_16BIT; pCaptureInstPrm->inScanFormat = SYSTEM_SF_PROGRESSIVE; pCaptureInstPrm->videoCaptureMode = SYSTEM_CAPT_VIDEO_CAPTURE_MODE_SINGLE_CH_NON_MUX_EMBEDDED_SYNC; break; default: pCaptureInstPrm->standard = VSYS_STD_720P_50; pCaptureInstPrm->inDataFormat = SYSTEM_DF_YUV422SP_UV; pCaptureInstPrm->videoIfMode = SYSTEM_CAPT_VIDEO_IF_MODE_16BIT; pCaptureInstPrm->inScanFormat = SYSTEM_SF_PROGRESSIVE; break; } }*///L //L srcPrm.outQueParams.nextLink = _ipcBitsOutVpssId; if (isProgressive){ srcPrm.timerPeriod = 30; }else { srcPrm.timerPeriod = 15; } srcPrm.inputInfo.numCh = SRC_NUM_CH; for(i=0; i<srcPrm.inputInfo.numCh; i++) { System_LinkChInfo *pChInfo; pChInfo = &srcPrm.inputInfo.chInfo[i]; pChInfo->dataFormat = SYSTEM_DF_YUV420SP_UV; pChInfo->memType = SYSTEM_MT_TILEDMEM; pChInfo->width = Pt_Conf->width[0]; if (isProgressive){ pChInfo->height = Pt_Conf->height[0]; pChInfo->scanFormat = SYSTEM_SF_PROGRESSIVE; } else{ pChInfo->height = 480/2; pChInfo->scanFormat = SYSTEM_SF_INTERLACED; } pChInfo->pitch[0] = SystemUtils_align(pChInfo->width+pChInfo->startX, SYSTEM_BUFFER_ALIGNMENT); pChInfo->pitch[1] = pChInfo->pitch[0]; pChInfo->pitch[2] = 0; } //L ipcOutVpssPrm.inQueParams.prevLinkId = _srcId;//_captureId;//L ipcOutVpssPrm.inQueParams.prevLinkQueId = 1;//0;//L ipcOutVpssPrm.numOutQue = 1; ipcOutVpssPrm.notifyNextLink = TRUE; ipcOutVpssPrm.notifyPrevLink = TRUE; ipcOutVpssPrm.noNotifyMode = FALSE; ipcOutVpssPrm.inputFrameRate = (UInt32)((double)Pt_Conf->framerate[0] / (double)IPC_FRAMERATE); ipcOutVpssPrm.outputFrameRate = (UInt32)((double)Pt_Conf->framerate[0] / (double)IPC_FRAMERATE); ipcOutVpssPrm.outQueParams[0].nextLink = _ipcBitsInVideoId; ipcOutVpssPrm.numChPerOutQue[0] = 1; /** * ipcBitsOutVpss to ipcBitsInVideo **/ printf("NME : ipcBitsOutVpss to ipcBitsInVideo\n"); ipcInVideoPrm.inQueParams.prevLinkId = _ipcBitsOutVpssId; ipcInVideoPrm.inQueParams.prevLinkQueId = 0; ipcInVideoPrm.numOutQue = 1; ipcInVideoPrm.notifyNextLink = TRUE; ipcInVideoPrm.notifyPrevLink = TRUE; ipcInVideoPrm.noNotifyMode = FALSE; //FALSE; ipcInVideoPrm.inputFrameRate = (UInt32)((double)Pt_Conf->framerate[0] / (double)IPC_FRAMERATE); ipcInVideoPrm.outputFrameRate = (UInt32)((double)Pt_Conf->framerate[0] / (double)IPC_FRAMERATE); ipcInVideoPrm.outQueParams[0].nextLink = _encId; ipcInVideoPrm.numChPerOutQue[0] = 1; /** * ipcBitsInVideo to Encoder **/ printf("NME : ipcBitsInVideo to Encoder\n"); /* configuartion du module de compression, ici qu'un seul */ for( i = 0 ; i < 1 ; i++ ) { EncLink_ChCreateParams *pLinkChPrm; EncLink_ChDynamicParams *pLinkDynPrm; if( Pt_Conf->codec == VCODEC_TYPE_H264 ) { encPrm.numBufPerCh[i] = 6; pLinkChPrm = &encPrm.chCreateParams[i]; pLinkDynPrm = &pLinkChPrm->defaultDynamicParams; pLinkChPrm->format = IVIDEO_H264HP; pLinkChPrm->profile = IH264_HIGH_PROFILE; pLinkChPrm->enableAnalyticinfo = 0; pLinkChPrm->enableWaterMarking = 0; pLinkChPrm->maxBitRate = Pt_Conf->bitrate * 1000 ; pLinkChPrm->encodingPreset = XDM_USER_DEFINED;//VENC_XDM_HIGH_SPEED_MED_QUALITY; /////////////////////// /*Note:Specific for h264 Encoder: Enabling this flag adds svc extension headers to the stream, not all decoders are generally able to play back such a stream. */ /* Needs to be enabled to IH264_SVC_EXTENSION_FLAG_ENABLE for the svc extension headers to be present in the stream*/ pLinkChPrm->enableSVCExtensionFlag =VENC_IH264_SVC_EXTENSION_FLAG_DISABLE; if(Pt_Conf->num_layers > 1) pLinkChPrm->enableSVCExtensionFlag =VENC_IH264_SVC_EXTENSION_FLAG_ENABLE; /** Note: For the encoder to give out frames with SVC-T properties, number of layers needs to be increased as per requirement. A flag enableLayerWrite needs to be set if for any channel the Layer is increased to beyond 1. This check has also been done for Channel 0, just before VcapVencVdecVdis_ipcBitsInit call. For example for Channel 0 it has been set to LAYERS_4, file stream dump will generate four(Base + 3) files with differing frame-rates**/ /** WARNING: SVC-T cannot be used if B Frame is enabled */ pLinkChPrm->numTemporalLayer = Pt_Conf->num_layers; printf("NME : Number SVC layers %d\n",Pt_Conf->num_layers); /** VENC_XDM_DEFAULT = 0, VENC_XDM_HIGH_QUALITY = 1, VENC_XDM_HIGH_SPEED = 2, VENC_XDM_USER_DEFINED = 3, VENC_XDM_HIGH_SPEED_MED_QUALITY = 4, VENC_XDM_MED_SPEED_MED_QUALITY = 5, VENC_XDM_MED_SPEED_HIGH_QUALITY = 6, */ pLinkChPrm->rateControlPreset = VENC_RATE_CTRL_VBR;//VENC_RATE_CTRL_VBR; //IVIDEO_STORAGE /** VENC_RATE_CTRL_VBR = 0, VENC_RATE_CTRL_CBR = 1,*/ pLinkChPrm->enableHighSpeed = 0; /* enable only if encodingPreset is set to VENC_XDM_USER_DEFINED*/ pLinkChPrm->overrideInputScanFormat = FALSE; pLinkChPrm->fieldPicEncode = FALSE; pLinkDynPrm->intraFrameInterval = Pt_Conf->gopsize[0]; pLinkDynPrm->targetBitRate = Pt_Conf->bitrate * 1000 ; pLinkDynPrm->interFrameInterval = 1; pLinkDynPrm->mvAccuracy = IVIDENC2_MOTIONVECTOR_QUARTERPEL; pLinkDynPrm->rcAlg = 0;//VENC_RATE_CTRL_VBR; pLinkDynPrm->qpMin = 10; pLinkDynPrm->qpMax = 40; pLinkDynPrm->qpInit = 20; pLinkDynPrm->vbrDuration = 8; pLinkDynPrm->vbrSensitivity = 0; pLinkDynPrm->inputFrameRate = (UInt32)(Pt_Conf->framerate[i] / (double)IPC_FRAMERATE); /* switch(Pt_Conf->res0) { case VSYS_STD_NTSC: case VSYS_STD_PAL: case VSYS_STD_480I: case VSYS_STD_576I: case VSYS_STD_CIF: case VSYS_STD_HALF_D1: case VSYS_STD_D1: case VSYS_STD_1080I_60: case VSYS_STD_1080I_50: pLinkChPrm->fieldMergeEncodeEnable = TRUE; pLinkChPrm->dataLayout = IVIDEO_FIELD_INTERLEAVED; //IVIDEO_INTERLACED; break; case VSYS_STD_480P: case VSYS_STD_576P: case VSYS_STD_720P_60: case VSYS_STD_720P_50: case VSYS_STD_1080P_60: case VSYS_STD_1080P_50: case VSYS_STD_1080P_24: case VSYS_STD_1080P_30: default: pLinkChPrm->fieldMergeEncodeEnable = FALSE; pLinkChPrm->dataLayout = VCODEC_FIELD_SEPARATED; //IVIDEO_PROGRESSIVE; break; }*/ } /* else if ( Pt_Conf->codec == VCODEC_TYPE_MJPEG ) { pLinkChPrm->format = IVIDEO_MJPEG; pLinkChPrm->profile = 0; pLinkChPrm->dataLayout = VCODEC_FIELD_SEPARATED; pLinkChPrm->fieldMergeEncodeEnable = FALSE; pLinkChPrm->enableAnalyticinfo = 0; pLinkChPrm->maxBitRate = Pt_Conf->bitrate * 1000 ; pLinkChPrm->encodingPreset = 0; pLinkChPrm->rateControlPreset = 0; pLinkDynPrm->intraFrameInterval = 0; pLinkDynPrm->targetBitRate = Pt_Conf->bitrate * 1000 ; pLinkDynPrm->interFrameInterval = 0; pLinkDynPrm->mvAccuracy = 0; pLinkDynPrm->inputFrameRate = 1;//pDynPrm->inputFrameRate; pLinkDynPrm->qpMin = 0; pLinkDynPrm->qpMax = 0; pLinkDynPrm->qpInit = -1; pLinkDynPrm->vbrDuration = 0; pLinkDynPrm->vbrSensitivity = 0; }*/ } encPrm.inQueParams.prevLinkId = _ipcBitsInVideoId; encPrm.inQueParams.prevLinkQueId= 0; encPrm.outQueParams.nextLink = _ipcBitsOutVideoId; //encPrm.numBufPerCh[0] = 6; /** * Encoder to ipcBitsOutVideo **/ printf("NME : Encoder to ipcBitsOutVideo\n"); ipcBitsOutVideoPrm.baseCreateParams.inQueParams.prevLinkId = _encId; ipcBitsOutVideoPrm.baseCreateParams.inQueParams.prevLinkQueId = 0; ipcBitsOutVideoPrm.baseCreateParams.numOutQue = 1; ipcBitsOutVideoPrm.baseCreateParams.inputFrameRate = (UInt32)((double)Pt_Conf->framerate[0] / (double)IPC_FRAMERATE); ipcBitsOutVideoPrm.baseCreateParams.outputFrameRate = (UInt32)((double)Pt_Conf->framerate[0] / (double)IPC_FRAMERATE); ipcBitsOutVideoPrm.baseCreateParams.outQueParams[0].nextLink = _ipcBitsInHostId; ipcBitsOutVideoPrm.baseCreateParams.numChPerOutQue[0] = 1; capture_encode_ipcBitsInitCreateParams_BitsOutRTOS(&ipcBitsOutVideoPrm, TRUE); ipcBitsInHostPrm.baseCreateParams.inQueParams.prevLinkId = _ipcBitsOutVideoId; ipcBitsInHostPrm.baseCreateParams.inQueParams.prevLinkQueId = 0; ipcBitsInHostPrm.baseCreateParams.numOutQue = 1; ipcBitsInHostPrm.baseCreateParams.inputFrameRate = (UInt32)((double)Pt_Conf->framerate[0] / (double)IPC_FRAMERATE); ipcBitsInHostPrm.baseCreateParams.outputFrameRate = (UInt32)((double)Pt_Conf->framerate[0] / (double)IPC_FRAMERATE); ipcBitsInHostPrm.baseCreateParams.outQueParams[0].nextLink = SYSTEM_LINK_ID_INVALID; ipcBitsInHostPrm.baseCreateParams.numChPerOutQue[0] = 0; capture_encode_ipcBitsInitCreateParams_BitsInHLOS(&ipcBitsInHostPrm); printf("NME : System_linkCreate _captureId\n"); System_linkCreate(_srcId, &srcPrm, sizeof(srcPrm)); //System_linkCreate(_captureId, &capturePrm, sizeof(capturePrm));//L //System_linkControl(_captureId, CAPTURE_LINK_CMD_CONFIGURE_VIP_DECODERS, NULL, 0, TRUE); printf("NME : System_linkCreate _ipcBitsOutVpssId\n"); System_linkCreate(_ipcBitsOutVpssId, &ipcOutVpssPrm, sizeof(ipcOutVpssPrm)); printf("NME : System_linkCreate _ipcBitsInVideoId\n"); System_linkCreate(_ipcBitsInVideoId, &ipcInVideoPrm, sizeof(ipcInVideoPrm)); printf("NME : System_linkCreate _encId\n"); System_linkCreate(_encId, &encPrm, sizeof(encPrm)); printf("NME : System_linkCreate _ipcBitsOutVideoId\n"); System_linkCreate(_ipcBitsOutVideoId, &ipcBitsOutVideoPrm, sizeof(ipcBitsOutVideoPrm)); printf("NME : System_linkCreate _ipcBitsInHostId\n"); System_linkCreate(_ipcBitsInHostId, &ipcBitsInHostPrm, sizeof(ipcBitsInHostPrm)); printf("NME : System_linkStart _ipcBitsInHostId\n"); System_linkStart(_ipcBitsInHostId); printf("NME : System_linkStart _ipcBitsOutVideoId\n"); System_linkStart(_ipcBitsOutVideoId); printf("NME : System_linkStart _encId\n"); System_linkStart(_encId); printf("NME : System_linkStart _ipcBitsInVideoId\n"); System_linkStart(_ipcBitsInVideoId); printf("NME : System_linkStart _ipcBitsOutVpssId\n"); System_linkStart(_ipcBitsOutVpssId); printf("NME : System_linkStart _captureId\n"); //System_linkStart(_captureId);//L System_linkStart(_srcId); } void capture_encode_stop() { printf("NME : capture_encode_stop\n"); //System_linkStop(_captureId);//L System_linkStop(_ipcBitsOutVpssId); System_linkStop(_ipcBitsInVideoId); System_linkStop(_encId); System_linkStop(_ipcBitsOutVideoId); System_linkStop(_ipcBitsInHostId); //System_linkDelete(_captureId);//L System_linkDelete(_ipcBitsOutVpssId); System_linkDelete(_ipcBitsInVideoId); System_linkDelete(_encId); System_linkDelete(_ipcBitsOutVideoId); System_linkDelete(_ipcBitsInHostId); } Int32 capture_encode_printDetailedStatistics() { //System_linkControl(_captureId, CAPTURE_LINK_CMD_PRINT_ADV_STATISTICS, NULL, 0, TRUE);//L //System_linkControl(_captureId, CAPTURE_LINK_CMD_PRINT_BUFFER_STATISTICS, NULL, 0, TRUE);//L System_linkControl(_encId, ENC_LINK_CMD_PRINT_IVAHD_STATISTICS, NULL, 0, TRUE); System_linkControl(_encId, ENC_LINK_CMD_PRINT_STATISTICS, NULL, 0, TRUE); System_linkControl(_encId, ENC_LINK_CMD_PRINT_BUFFER_STATISTICS, NULL, 0, TRUE); return 0; } /* typedef enum { VSYS_STD_NTSC = 0u, //< 720x480 30FPS interlaced NTSC standard. VSYS_STD_PAL = 1u, //< 720x576 30FPS interlaced PAL standard. VSYS_STD_480I = 2u, //< 720x480 30FPS interlaced SD standard. VSYS_STD_576I = 3u, //< 720x576 30FPS interlaced SD standard. VSYS_STD_CIF = 4u, //< Interlaced, 360x120 per field NTSC, 360x144 per field PAL. VSYS_STD_HALF_D1 = 5u, //< Interlaced, 360x240 per field NTSC, 360x288 per field PAL. VSYS_STD_D1 = 6u, //< Interlaced, 720x240 per field NTSC, 720x288 per field PAL. VSYS_STD_480P = 7u, //< 720x480 60FPS progressive ED standard. VSYS_STD_576P = 8u, //< 720x576 60FPS progressive ED standard. VSYS_STD_720P_60 = 9u, //< 1280x720 60FPS progressive HD standard. VSYS_STD_720P_50 = 10u, //< 1280x720 50FPS progressive HD standard. VSYS_STD_1080I_60 = 11u, //< 1920x1080 30FPS interlaced HD standard. VSYS_STD_1080I_50 = 12u, //< 1920x1080 50FPS interlaced HD standard. VSYS_STD_1080P_60 = 13u, //< 1920x1080 60FPS progressive HD standard. VSYS_STD_1080P_50 = 14u, //< 1920x1080 50FPS progressive HD standard. VSYS_STD_1080P_24 = 15u, //< 1920x1080 24FPS progressive HD standard. VSYS_STD_1080P_30 = 16u, //< 1920x1080 30FPS progressive HD standard. */ void Usage(void) { /* Print message with program arguments */ fprintf(stderr, "usage: parseargs [-file <filename>] [-w <width>] [-h <height>] [-f <framerate>] [-b <bitrate>] [-g <gop>] [-s <videostd>] [-l <num svc layers(1-4)>] [-h264]\n"); fprintf(stderr, "\ VSYS_STD_NTSC = 0, 720x480 30FPS interlaced NTSC standard\ VSYS_STD_PAL = 1, 720x576 30FPS interlaced PAL standard\ VSYS_STD_480I = 2, 720x480 30FPS interlaced SD standard\ VSYS_STD_576I = 3, 720x576 30FPS interlaced SD standard\ VSYS_STD_CIF = 4, Interlaced, 360x120 per field NTSC, 360x144 per field PAL\ VSYS_STD_HALF_D1 = 5, Interlaced, 360x240 per field NTSC, 360x288 per field PAL\ VSYS_STD_D1 = 6, Interlaced, 720x240 per field NTSC, 720x288 per field PAL\ VSYS_STD_480P = 7, 720x480 60FPS progressive ED standard\ VSYS_STD_576P = 8, 720x576 60FPS progressive ED standard\ VSYS_STD_720P_60 = 9, 1280x720 60FPS progressive HD standard\ VSYS_STD_720P_50 = 10, 1280x720 50FPS progressive HD standard\ VSYS_STD_1080I_60 = 11, 1920x1080 30FPS interlaced HD standard\ VSYS_STD_1080I_50 = 12, 1920x1080 50FPS interlaced HD standard\ VSYS_STD_1080P_60 = 13, 1920x1080 60FPS progressive HD standard\ VSYS_STD_1080P_50 = 14, 1920x1080 50FPS progressive HD standard\ VSYS_STD_1080P_24 = 15, 1920x1080 24FPS progressive HD standard\ VSYS_STD_1080P_30 = 16,1920x1080 50FPS progressive HD standard\n" ); fprintf(stderr, "e or q - exit\n"); } int ParseArguments(int argc, char **argv, Config_struct *Conf) { /* Skip over program name */ argc--; argv++; memset(Conf,0,sizeof(Config_struct)); Conf->codec = VCODEC_TYPE_H264; Conf->num_layers = 1;//by default we don't use SVC /* typedef struct { UInt32 res0; UInt32 width[NUM_CAPTURE_DEVICES]; UInt32 height[NUM_CAPTURE_DEVICES]; UInt32 framerate[NUM_CAPTURE_DEVICES]; UInt32 bitrate; VCODEC_TYPE_E codec; UInt32 gopsize[NUM_CAPTURE_DEVICES]; char Pt_file[256]; }Config_struct; */ /* Loop through command line words */ while (argc > 0) { if (!strcmp(*argv, "-file")) { argv++; argc--; Conf->Pt_file = *argv; } else if (!strcmp(*argv, "-w")) { argv++; argc--; Conf->width[0] = atoi(*argv); } else if (!strcmp(*argv, "-h")) { argv++; argc--; Conf->height[0] = atoi(*argv); } else if (!strcmp(*argv, "-f")) { argv++; argc--; Conf->framerate[0] = atoi(*argv); } else if (!strcmp(*argv, "-b")) { argv++; argc--; Conf->bitrate = atoi(*argv); } else if (!strcmp(*argv, "-g")) { argv++; argc--; Conf->gopsize[0] = atoi(*argv); } else if (!strcmp(*argv, "-s")) { argv++; argc--; Conf->res0 = atoi(*argv); } else if (!strcmp(*argv, "-l")) { argv++; argc--; Conf->num_layers = atoi(*argv); } else if (!strcmp(*argv, "-h264")) { Conf->codec = VCODEC_TYPE_H264; } else { fprintf(stderr, "Unrecognized recognized command line argument: %s\n", *argv); Usage(); return 0; } argv++; argc--; } if(Conf->width[0] == 0 || Conf->height[0] == 0 || Conf->Pt_file == NULL || Conf->gopsize[0] == 0 || Conf->framerate[0] == 0) { Usage(); return 0; } /* Return success */ return 1; } char Demo_getChar() { char buffer[MAX_INPUT_STR_SIZE]; fflush(stdin); fgets(buffer, MAX_INPUT_STR_SIZE, stdin); return(buffer[0]); } int main( int argc, char *argv[] ) { Config_struct Conf; char ch; struct sigaction sigintAction; //int count = 0; sigintAction.sa_handler = sighandler; sigemptyset(& (sigintAction.sa_mask)); if (sigaction(SIGINT, &sigintAction, NULL) != 0) { fprintf(stderr, "Erreur SIGINT\n\r"); exit(1); } printf("NME : System_init\n"); System_init(); //SystemTiler_disableAllocator(); if(ParseArguments(argc, argv, &Conf) == 0) { printf("error parsing arguments \n"); return -1; } _fout = NULL; if( (_fout = fopen(Conf.Pt_file,"wb")) == NULL ) { printf("error open write file %s\n",Conf.Pt_file); Usage(); return -1; } capture_encode_start(&Conf); sleep(2); printf("NME : run\n"); capture_encode_printDetailedStatistics(); //printf("NME : Change dynamics parameters\n"); //capture_encode_dynamique_parameters(&Conf); while( run ) { ch = Demo_getChar(); switch(ch) { case 'e': case 'q': run = FALSE; capture_encode_printDetailedStatistics(); break; } usleep(200); /* count++; if( count >= 10000) { printf("NME : capture_encode_printDetailedStatistics\n"); //capture_encode_printDetailedStatistics(); count = 0; }*/ } capture_encode_stop(); if( _fout != NULL ) fclose(_fout); printf("NME : System_deInit\n"); /*System De-Initialization. A8 (Linux) side link de-init calls. e..g IPC De-Init calls*/ System_deInit(); return 0; }