Void Chains_doubleChCapScEncSend(Chains_Ctrl *chainsCfg)
{
    CaptureLink_CreateParams            capturePrm;
    CaptureLink_VipInstParams           *pCaptureInstPrm;
    CaptureLink_OutParams               *pCaptureOutPrm;
    MergeLink_CreateParams              mergePrm;   
    DupLink_CreateParams                dupPrm;
    NsfLink_CreateParams       		 nsfPrm;
    DupLink_CreateParams                dup2Prm;			//for two display
    SwMsLink_CreateParams               swMsPrm[CHAINS_SW_MS_MAX_DISPLAYS];
    DisplayLink_CreateParams            displayPrm[CHAINS_SW_MS_MAX_DISPLAYS];
    IpcLink_CreateParams                ipcOutVpssPrm;
    IpcLink_CreateParams                ipcInVideoPrm;
    EncLink_CreateParams                encPrm;
    IpcBitsOutLinkRTOS_CreateParams     ipcBitsOutVideoPrm;
    IpcBitsInLinkHLOS_CreateParams      ipcBitsInHostPrm;

    UInt32 captureId, vipInstId;
    UInt32 mergeId;
    UInt32 dupId;
    UInt32 nsfId;
    UInt32 dup2Id;
    UInt32 swMsId[CHAINS_SW_MS_MAX_DISPLAYS];
    UInt32 displayId[CHAINS_SW_MS_MAX_DISPLAYS];
    UInt32 ipcOutVpssId;
    UInt32 ipcInVideoId;
    UInt32 encId;
    UInt32 ipcBitsOutVideoId;
    UInt32 ipcBitsInHostId;

    Bool enableOsdAlgLink=1;
    UInt32 enableDisplay = FALSE;
/****************msg between sys and chain*****/
#if 0
	int msgqid = 0;
	msgqid = Msg_Init(MSG_KEY);
#endif
/*************************************/
////////////////////////////OSD///////////////////////////////////
    AlgLink_CreateParams        	    DSPLinkPrm;//guo changed to global
    IpcFramesOutLinkRTOS_CreateParams  ipcFramesOutVpssPrm;
    IpcFramesInLinkHLOS_CreateParams   ipcFramesInDspPrm;
    UInt32 osdId;
    UInt32 ipcFramesOutVpssId, ipcFramesInDspId;	
    UInt8 osdFormat[ALG_LINK_OSD_MAX_CH];

    memset(osdFormat,  SYSTEM_DF_YUV422I_YUYV, ALG_LINK_OSD_MAX_CH);
    if (enableOsdAlgLink) 
    {
        Chains_ipcFramesInit();//This is likely no use.
    }
    CHAINS_INIT_STRUCT(IpcFramesOutLinkRTOS_CreateParams ,ipcFramesOutVpssPrm);
    CHAINS_INIT_STRUCT(IpcFramesInLinkHLOS_CreateParams  ,ipcFramesInDspPrm);
    CHAINS_INIT_STRUCT(AlgLink_CreateParams,DSPLinkPrm);
    ipcFramesOutVpssId  = SYSTEM_VPSS_LINK_ID_IPC_FRAMES_OUT_0;
    ipcFramesInDspId      = SYSTEM_DSP_LINK_ID_IPC_FRAMES_IN_0;
    osdId     = SYSTEM_LINK_ID_ALG_0;
//////////////////guo2014/11/21--added for scd////////////////////////
	//Scd CreateParams is contined in AlgLink_CreateParmas
	NsfLink_CreateParams       		 nsfPrm2;//SCD  only supports YUV420
	SclrLink_CreateParams           sclrPrm;
	AlgLink_CreateParams		scdPrm;
	IpcFramesOutLinkRTOS_CreateParams  ipcFramesOutVpssPrm2;	//outVpss
	IpcFramesInLinkRTOS_CreateParams  ipcFramesInDspPrm2;		//Into Dsp
	IpcBitsOutLinkRTOS_CreateParams   ipcBitsOutDspPrm2;
	IpcBitsInLinkHLOS_CreateParams  ipcBitsInHostPrm2;

	UInt32 nsfId2;
	UInt32 scdId;
	UInt32 sclrId;
	UInt32 ipcFramesOutVpssId2;
	UInt32 ipcFramesInDspId2;
	UInt32 ipcBitsOutDspId2;
	UInt32 ipcBitsInHostId2;
	
	Bool enableScdAlgLink = 1;

	nsfId2 = SYSTEM_LINK_ID_NSF_1;
	scdId = SYSTEM_LINK_ID_ALG_1;
	sclrId = SYSTEM_LINK_ID_SCLR_INST_0;
	ipcFramesOutVpssId2 =  SYSTEM_VPSS_LINK_ID_IPC_FRAMES_OUT_1; 
	ipcFramesInDspId2 = SYSTEM_DSP_LINK_ID_IPC_FRAMES_IN_1;
	ipcBitsOutDspId2 = SYSTEM_DSP_LINK_ID_IPC_BITS_OUT_0;
	ipcBitsInHostId2 = SYSTEM_HOST_LINK_ID_IPC_BITS_IN_1;
	CHAINS_INIT_STRUCT(NsfLink_CreateParams, nsfPrm2);
	CHAINS_INIT_STRUCT(SclrLink_CreateParams,sclrPrm);
	CHAINS_INIT_STRUCT(IpcFramesOutLinkRTOS_CreateParams,ipcFramesOutVpssPrm2);
   	CHAINS_INIT_STRUCT(IpcFramesInLinkHLOS_CreateParams,ipcFramesInDspPrm2);
	CHAINS_INIT_STRUCT(IpcBitsOutLinkRTOS_CreateParams,ipcBitsOutDspPrm2);
	CHAINS_INIT_STRUCT(IpcBitsInLinkHLOS_CreateParams,ipcBitsInHostPrm2);
	CHAINS_INIT_STRUCT(AlgLink_CreateParams,scdPrm);


	Scd_bitsWriteCreate(0,ipcBitsInHostId2);	//Init scd's ipcBitsInHost by:guo8113,this is ok, temporarily disabled!
	
//----------------end scd-----------------------------
    Chains_ipcBitsInit();		

    UInt32 i;
    char   ch;
   
    CHAINS_INIT_STRUCT(CaptureLink_CreateParams,capturePrm);
    for (i=0; i<CHAINS_SW_MS_MAX_DISPLAYS; i++) {
        CHAINS_INIT_STRUCT(SwMsLink_CreateParams,swMsPrm[i]);
        CHAINS_INIT_STRUCT(DisplayLink_CreateParams,displayPrm[i]);
    }
    CHAINS_INIT_STRUCT(IpcLink_CreateParams,ipcOutVpssPrm);
    CHAINS_INIT_STRUCT(IpcLink_CreateParams,ipcInVideoPrm);
    CHAINS_INIT_STRUCT(NsfLink_CreateParams, nsfPrm);
    CHAINS_INIT_STRUCT(EncLink_CreateParams,encPrm);
    CHAINS_INIT_STRUCT(IpcBitsOutLinkRTOS_CreateParams,ipcBitsOutVideoPrm);
    CHAINS_INIT_STRUCT(IpcBitsInLinkHLOS_CreateParams,ipcBitsInHostPrm);

    captureId     = SYSTEM_LINK_ID_CAPTURE;
    mergeId       = SYSTEM_VPSS_LINK_ID_MERGE_0;
    dupId         = SYSTEM_VPSS_LINK_ID_DUP_0;
    nsfId     = SYSTEM_LINK_ID_NSF_0;
    dup2Id        = SYSTEM_VPSS_LINK_ID_DUP_1;
    swMsId[0]     = SYSTEM_LINK_ID_SW_MS_MULTI_INST_0;
    swMsId[1]     = SYSTEM_LINK_ID_SW_MS_MULTI_INST_1;
    displayId[0]  = SYSTEM_LINK_ID_DISPLAY_0;
    displayId[1]  = SYSTEM_LINK_ID_DISPLAY_1;

    encId         = SYSTEM_LINK_ID_VENC_0;
    ipcOutVpssId  = SYSTEM_VPSS_LINK_ID_IPC_OUT_M3_0;
    ipcInVideoId  = 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
    );

    capturePrm.numVipInst               = 2;
    capturePrm.tilerEnable              = FALSE;
    capturePrm.numBufsPerCh             = 16;
    capturePrm.numExtraBufs             = 0;
    capturePrm.maxBlindAreasPerCh       = 0;
    capturePrm.isPalMode                = FALSE;
    capturePrm.enableSdCrop             = FALSE;
    capturePrm.doCropInCapture          = FALSE;

    for(i=0; i<capturePrm.numVipInst; i++)
    {
    	vipInstId = SYSTEM_CAPTURE_INST_VIP0_PORTA + 2*i;
        pCaptureInstPrm                     = &capturePrm.vipInst[i];
        pCaptureInstPrm->vipInstId          = vipInstId%SYSTEM_CAPTURE_INST_MAX;
        pCaptureInstPrm->videoDecoderId     = SYSTEM_DEVICE_VID_DEC_SII9233A_DRV;
        pCaptureInstPrm->inDataFormat       = SYSTEM_DF_YUV422P;
        pCaptureInstPrm->standard           = chainsCfg->displayRes[i];
        pCaptureInstPrm->numOutput          = 2;
        pCaptureInstPrm->numChPerOutput     = 1;
        pCaptureInstPrm->frameCaptureMode   = FALSE;
        pCaptureInstPrm->fieldsMerged       = FALSE;

        pCaptureOutPrm                      = &pCaptureInstPrm->outParams[0];
        pCaptureOutPrm->dataFormat          = SYSTEM_DF_YUV422I_YUYV;//nsf can change 422 to 420,because enc require 420
        pCaptureOutPrm->scEnable            = FALSE;
        pCaptureOutPrm->scOutWidth          = gChains_ctrl.channelConf[i].width;
        pCaptureOutPrm->scOutHeight         = gChains_ctrl.channelConf[i].height;
        pCaptureOutPrm->outQueId            = 0;

        pCaptureOutPrm                      = &pCaptureInstPrm->outParams[1];
        pCaptureOutPrm->dataFormat          = SYSTEM_DF_YUV422I_YUYV;
        pCaptureOutPrm->scEnable            = FALSE;
        pCaptureOutPrm->scOutWidth          = gChains_ctrl.channelConf[2+i].width;
        pCaptureOutPrm->scOutHeight         = gChains_ctrl.channelConf[2+i].height;
        pCaptureOutPrm->outQueId            = 1;
    }
    capturePrm.outQueParams[0].nextLink     = mergeId;
    capturePrm.outQueParams[1].nextLink     = mergeId;

    System_linkCreate(captureId, &capturePrm, sizeof(capturePrm));
    for (i=0; i<gChains_ctrl.channelNum; i++) {
        chainsCfg->displayRes[i] = capturePrm.vipInst[i].standard;
        Vsys_getResSize(chainsCfg->displayRes[i], &chainsCfg->channelConf[i].width, &chainsCfg->channelConf[i].height);
        Vsys_getResRate(chainsCfg->displayRes[i], &chainsCfg->channelConf[i].frameRate);
    }

    mergePrm.numInQue                       = 2;
    mergePrm.inQueParams[0].prevLinkId      = captureId;
    mergePrm.inQueParams[0].prevLinkQueId   = 0;
    mergePrm.inQueParams[1].prevLinkId      = captureId;
    mergePrm.inQueParams[1].prevLinkQueId   = 1;
//guo---------------------------------------------------------
     if (enableOsdAlgLink) 
    {
        mergePrm.outQueParams.nextLink=ipcFramesOutVpssId;  
	 ipcFramesOutVpssPrm.baseCreateParams.inQueParams.prevLinkId = mergeId;
        ipcFramesOutVpssPrm.baseCreateParams.noNotifyMode = FALSE;
        ipcFramesOutVpssPrm.baseCreateParams.notifyNextLink = TRUE;
        ipcFramesOutVpssPrm.baseCreateParams.notifyPrevLink = FALSE;
        ipcFramesOutVpssPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
        ipcFramesOutVpssPrm.baseCreateParams.outQueParams[0].nextLink = dupId;
        ipcFramesOutVpssPrm.baseCreateParams.inputFrameRate = chainsCfg->channelConf[0].frameRate;
        ipcFramesOutVpssPrm.baseCreateParams.outputFrameRate =chainsCfg->channelConf[0].frameRate;// 
        ipcFramesOutVpssPrm.baseCreateParams.processLink = ipcFramesInDspId;
        ipcFramesOutVpssPrm.baseCreateParams.notifyProcessLink = FALSE;
        ipcFramesInDspPrm.baseCreateParams.noNotifyMode = TRUE;
        ipcFramesInDspPrm.baseCreateParams.notifyNextLink = TRUE;
        ipcFramesInDspPrm.baseCreateParams.notifyPrevLink = FALSE;
        ipcFramesInDspPrm.baseCreateParams.inQueParams.prevLinkId = ipcFramesOutVpssId;
        ipcFramesInDspPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
        ipcFramesInDspPrm.baseCreateParams.outQueParams[0].nextLink = osdId;
        ipcFramesInDspPrm.exportOnlyPhyAddr = FALSE;
        ipcFramesInDspPrm.baseCreateParams.inputFrameRate = chainsCfg->channelConf[0].frameRate;
        ipcFramesInDspPrm.baseCreateParams.outputFrameRate = chainsCfg->channelConf[0].frameRate;
        ipcFramesInDspPrm.baseCreateParams.notifyProcessLink = FALSE;
        Chains_ipcFramesInSetCbInfo(&ipcFramesInDspPrm);	//This is likely no use.

	 DSPLinkPrm.inQueParams.prevLinkId=ipcFramesInDspId;
        DSPLinkPrm.inQueParams.prevLinkQueId = 0;
        DSPLinkPrm.enableOSDAlg=TRUE;
	 DSPLinkPrm.enableSCDAlg=FALSE;
//#define LOGOONLY  //this is reserved for original logo only osd ,for case you will test the logo.
#ifdef LOGOONLY

        Chains_OSDConfig(DSPLinkPrm);//origin logo osd is OK
 #else

 	Demo_osdInit(4, osdFormat);
       for(i=0;i< gChains_ctrl.channelNum; i++)
       	{
		       DSPLinkPrm.osdChCreateParams[i].maxWidth = CHAINS_OSD_WIN_MAX_WIDTH;
       			DSPLinkPrm.osdChCreateParams[i].maxHeight = CHAINS_OSD_WIN_MAX_HEIGHT;
			memcpy(&(DSPLinkPrm.osdChCreateParams[i].chDefaultParams),
				&g_osdChParam[i],sizeof(AlgLink_OsdChWinParams));//(dst,src,size)
       	}
 #endif
    }
    else
    {
	 mergePrm.outQueParams.nextLink = dupId;
    }
//------------------------------------------------------------
    mergePrm.notifyNextLink                 = TRUE;
    if (enableOsdAlgLink) 
    {
        dupPrm.inQueParams.prevLinkId    = ipcFramesOutVpssId;
    }
    else 
    {
        dupPrm.inQueParams.prevLinkId       = mergeId;
    }

    dupPrm.inQueParams.prevLinkQueId        = 0;
    dupPrm.numOutQue                        = 2;
//guo scd--------
    if(enableScdAlgLink)
    {
    	dupPrm.numOutQue	=	3;	//dup's third OutQue
	dupPrm.outQueParams[2].nextLink = sclrId;
	

    	sclrPrm.inQueParams.prevLinkId             = dupId;
    	sclrPrm.inQueParams.prevLinkQueId          = 2;
    	sclrPrm.outQueParams.nextLink              = nsfId2;

  	sclrPrm.tilerEnable                        = FALSE;
    	sclrPrm.enableLineSkipSc                   = TRUE;//FALSE;
    	sclrPrm.inputFrameRate                     = 60;
    	sclrPrm.outputFrameRate                    = 60;
    	sclrPrm.scaleMode                          = DEI_SCALE_MODE_ABSOLUTE;
	sclrPrm.outScaleFactor.absoluteResolution.outWidth = 352;
	sclrPrm.outScaleFactor.absoluteResolution.outHeight = 240;


   	nsfPrm2.inQueParams.prevLinkId    = sclrId;
    	nsfPrm2.inQueParams.prevLinkQueId = 0;
    	nsfPrm2.bypassNsf                 = TRUE;
    	nsfPrm2.tilerEnable               = FALSE;
    	nsfPrm2.numOutQue                 = 1;
    	nsfPrm2.outQueParams[0].nextLink  = ipcFramesOutVpssId2;
    	nsfPrm2.inputFrameRate            = 60;
    	nsfPrm2.outputFrameRate           = 60;
    	nsfPrm2.numBufsPerCh              = 8;

      	ipcFramesOutVpssPrm2.baseCreateParams.inQueParams.prevLinkId = nsfId2;
        ipcFramesOutVpssPrm2.baseCreateParams.inQueParams.prevLinkQueId = 0;
        ipcFramesOutVpssPrm2.baseCreateParams.notifyPrevLink = TRUE;

        ipcFramesOutVpssPrm2.baseCreateParams.numOutQue = 1;
        ipcFramesOutVpssPrm2.baseCreateParams.outQueParams[0].nextLink = ipcFramesInDspId2;
        ipcFramesOutVpssPrm2.baseCreateParams.notifyNextLink = TRUE;
	ipcFramesOutVpssPrm2.baseCreateParams.inputFrameRate = 60;
	ipcFramesOutVpssPrm2.baseCreateParams.outputFrameRate = 2;


        ipcFramesInDspPrm2.baseCreateParams.inQueParams.prevLinkId = ipcFramesOutVpssId2;
        ipcFramesInDspPrm2.baseCreateParams.inQueParams.prevLinkQueId = 0;
        ipcFramesInDspPrm2.baseCreateParams.numOutQue   = 1;
        ipcFramesInDspPrm2.baseCreateParams.outQueParams[0].nextLink = scdId;
        ipcFramesInDspPrm2.baseCreateParams.notifyPrevLink = TRUE;
        ipcFramesInDspPrm2.baseCreateParams.notifyNextLink = TRUE;
        ipcFramesInDspPrm2.baseCreateParams.noNotifyMode   = FALSE;


	Int32    numBlksInFrame;
       Int32    numHorzBlks, numVertBlks, chIdx;
       Uint32  x, y, i;
	scdPrm.inQueParams.prevLinkId = ipcFramesInDspId2;
	scdPrm.inQueParams.prevLinkQueId =0;
        scdPrm.enableSCDAlg              = TRUE;
	scdPrm.enableOSDAlg	= FALSE;
        scdPrm.outQueParams[ALG_LINK_SCD_OUT_QUE].nextLink     = ipcBitsOutDspId2;
        scdPrm.scdCreateParams.numBufPerCh            = 3;

        scdPrm.scdCreateParams.maxWidth               = 352;
           scdPrm.scdCreateParams.maxHeight           = 240;//288

        scdPrm.scdCreateParams.maxStride              = 352;
        scdPrm.scdCreateParams.numValidChForSCD       = 4;	//16

        scdPrm.scdCreateParams.numSecs2WaitB4Init     = 3;
        scdPrm.scdCreateParams.numSecs2WaitB4FrmAlert = 1;
        scdPrm.scdCreateParams.inputFrameRate         = 2;
        scdPrm.scdCreateParams.outputFrameRate        = 2;

        scdPrm.scdCreateParams.numSecs2WaitAfterFrmAlert    = 2;
        scdPrm.scdCreateParams.numSecs2Wait2MarkStableFrame = 5;

        scdPrm.scdCreateParams.enableMotionNotify        = FALSE;
        scdPrm.scdCreateParams.enableTamperNotify        = FALSE;

        /* Should be applied on CIF channels whose ch numbers are 4~7 */
        //scdPrm.scdCreateParams.startChNoForSCD = 16;
        // Configure array to monitor scene changes in all frame blocks, i.e., motion detection.
        // Each block is fixed to be 32x10 in size,
        numHorzBlks     = scdPrm.scdCreateParams.maxWidth / 32;
        if(scdPrm.scdCreateParams.maxHeight == 240)
           numVertBlks    = scdPrm.scdCreateParams.maxHeight / 10;
        else   /* For 288 Block height becomes 12 */
           numVertBlks    = scdPrm.scdCreateParams.maxHeight / 12;

        numBlksInFrame  = numHorzBlks * numVertBlks;

        for(chIdx = 0; chIdx < scdPrm.scdCreateParams.numValidChForSCD; chIdx++)
        {
           AlgLink_ScdChParams * chPrm = &scdPrm.scdCreateParams.chDefaultParams[chIdx];

           chPrm->blkNumBlksInFrame  = numBlksInFrame;
           chPrm->chId               = SCDChannelMonitor[chIdx];
           chPrm->mode               = ALG_LINK_SCD_DETECTMODE_MONITOR_BLOCKS_AND_FRAME;
           chPrm->frmIgnoreLightsON  = FALSE;
           chPrm->frmIgnoreLightsOFF = FALSE;
           chPrm->frmSensitivity     = ALG_LINK_SCD_SENSITIVITY_HIGH;//ALG_LINK_SCD_SENSITIVITY_VERYHIGH;
           chPrm->frmEdgeThreshold   = 100;

           i = 0;
           for(y = 0; y < numVertBlks; y++)
           {
             for(x = 0; x < numHorzBlks; x++)
             {
               chPrm->blkConfig[i].sensitivity = ALG_LINK_SCD_SENSITIVITY_MID;
               chPrm->blkConfig[i].monitored     = 1;
               i++;
             }
           }
        }

        ipcBitsOutDspPrm2.baseCreateParams.inQueParams.prevLinkId    = scdId;
        ipcBitsOutDspPrm2.baseCreateParams.inQueParams.prevLinkQueId = 0;
        ipcBitsOutDspPrm2.baseCreateParams.numOutQue                 = 1;
	 ipcBitsOutDspPrm2.baseCreateParams.noNotifyMode	= FALSE;
	  ipcBitsOutDspPrm2.baseCreateParams.notifyNextLink              = TRUE;
        ipcBitsOutDspPrm2.baseCreateParams.outQueParams[0].nextLink  =  ipcBitsInHostId2;
        
        ipcBitsOutDspPrm2.baseCreateParams.notifyNextLink              = TRUE;
        ipcBitsOutDspPrm2.baseCreateParams.noNotifyMode                = FALSE;

        ipcBitsInHostPrm2.baseCreateParams.inQueParams.prevLinkId = ipcBitsOutDspId2;
        ipcBitsInHostPrm2.baseCreateParams.inQueParams.prevLinkQueId = 0;
        ipcBitsInHostPrm2.baseCreateParams.numOutQue                 = 1;
        ipcBitsInHostPrm2.baseCreateParams.outQueParams[0].nextLink   = SYSTEM_LINK_ID_INVALID;
  
	Chains_ipcBitsInitCreateParams_BitsInHLOSVcap(&ipcBitsInHostPrm2);
        ipcBitsInHostPrm2.baseCreateParams.notifyPrevLink         = TRUE;
        ipcBitsInHostPrm2.baseCreateParams.noNotifyMode              = FALSE;		
    }
    else
    {
        scdPrm.outQueParams[ALG_LINK_SCD_OUT_QUE].nextLink     = SYSTEM_LINK_ID_INVALID;//nullId;
    }
	  
    dupPrm.outQueParams[0].nextLink = nsfId;
    dupPrm.outQueParams[1].nextLink = dup2Id;//to display
    dupPrm.notifyNextLink                    = TRUE;


    nsfPrm.inQueParams.prevLinkId    = dupId;
    nsfPrm.inQueParams.prevLinkQueId = 0;
    nsfPrm.bypassNsf                 = FALSE;
    nsfPrm.tilerEnable               = TRUE;
    nsfPrm.numOutQue                 = 1;
    nsfPrm.outQueParams[0].nextLink  = ipcOutVpssId;
    nsfPrm.inputFrameRate            = chainsCfg->channelConf[0].frameRate;
    nsfPrm.outputFrameRate           = chainsCfg->channelConf[0].frameRate;
    nsfPrm.numBufsPerCh              = 8;

    ipcOutVpssPrm.inQueParams.prevLinkId    = nsfId;
    ipcOutVpssPrm.inQueParams.prevLinkQueId = 0;
    ipcOutVpssPrm.numOutQue                 = 1;
    ipcOutVpssPrm.numChPerOutQue[0]         = 1;
    ipcOutVpssPrm.outQueParams[0].nextLink  = ipcInVideoId;
    ipcOutVpssPrm.notifyNextLink            = TRUE;
    ipcOutVpssPrm.notifyPrevLink            = FALSE;
    ipcOutVpssPrm.noNotifyMode              = FALSE;
    ipcOutVpssPrm.numChPerOutQue[0]         = 0;
    ipcOutVpssPrm.equallyDivideChAcrossOutQues = FALSE;

    ipcInVideoPrm.inQueParams.prevLinkId    = ipcOutVpssId;
    ipcInVideoPrm.inQueParams.prevLinkQueId = 0;
    ipcInVideoPrm.numOutQue                 = 1;
    ipcInVideoPrm.numChPerOutQue[0]         = 1;
    ipcInVideoPrm.outQueParams[0].nextLink  = encId;
    ipcInVideoPrm.notifyNextLink            = TRUE;
    ipcInVideoPrm.notifyPrevLink            = FALSE;
    ipcInVideoPrm.noNotifyMode              = FALSE;
    ipcInVideoPrm.numChPerOutQue[0]         = 0;
    ipcInVideoPrm.equallyDivideChAcrossOutQues = FALSE;

    for (i=0; i<gChains_ctrl.channelNum; i++) {
        encPrm.chCreateParams[i].format                             = chainsCfg->channelConf[i].encFormat;
        encPrm.chCreateParams[i].profile                            = chainsCfg->channelConf[i].encProfile;
        encPrm.chCreateParams[i].dataLayout                         = IVIDEO_FIELD_SEPARATED;
        encPrm.chCreateParams[i].fieldMergeEncodeEnable             = FALSE;
        encPrm.chCreateParams[i].enableAnalyticinfo                 = FALSE;
        encPrm.chCreateParams[i].enableWaterMarking                 = FALSE;
        encPrm.chCreateParams[i].encodingPreset                     = XDM_USER_DEFINED;
        encPrm.chCreateParams[i].rateControlPreset                  = IVIDEO_USER_DEFINED;
        encPrm.chCreateParams[i].enableHighSpeed                    = FALSE;
        encPrm.chCreateParams[i].defaultDynamicParams.interFrameInterval  = 1;
        encPrm.chCreateParams[i].defaultDynamicParams.intraFrameInterval  = chainsCfg->channelConf[i].intraFrameInterval;
        encPrm.chCreateParams[i].defaultDynamicParams.inputFrameRate      = chainsCfg->channelConf[i].frameRate;
        encPrm.chCreateParams[i].defaultDynamicParams.targetFrameRate     = chainsCfg->channelConf[i].encFrameRate;
        encPrm.chCreateParams[i].defaultDynamicParams.targetBitRate       = chainsCfg->channelConf[i].bitRate;
        encPrm.chCreateParams[i].defaultDynamicParams.mvAccuracy          = IVIDENC2_MOTIONVECTOR_QUARTERPEL;
        encPrm.chCreateParams[i].defaultDynamicParams.rcAlg               = chainsCfg->channelConf[i].rateCtrl;
        encPrm.chCreateParams[i].defaultDynamicParams.qpMin               = 0;
        encPrm.chCreateParams[i].defaultDynamicParams.qpMax               = 51;
        encPrm.chCreateParams[i].defaultDynamicParams.qpInit              = -1;
        encPrm.chCreateParams[i].defaultDynamicParams.vbrDuration         = 8;
        encPrm.chCreateParams[i].defaultDynamicParams.vbrSensitivity      = 0;
    }
    encPrm.inQueParams.prevLinkId   = ipcInVideoId;
    encPrm.inQueParams.prevLinkQueId= 0;
    encPrm.outQueParams.nextLink    = ipcBitsOutVideoId;
    encPrm.numBufPerCh[0]           = 0;

    ipcBitsOutVideoPrm.baseCreateParams.inQueParams.prevLinkId      = encId;
    ipcBitsOutVideoPrm.baseCreateParams.inQueParams.prevLinkQueId   = 0;
    ipcBitsOutVideoPrm.baseCreateParams.numOutQue                   = 1;
    ipcBitsOutVideoPrm.baseCreateParams.numChPerOutQue[0]           = 1;
    ipcBitsOutVideoPrm.baseCreateParams.outQueParams[0].nextLink    = ipcBitsInHostId;
    ipcBitsOutVideoPrm.baseCreateParams.notifyNextLink              = FALSE;
    ipcBitsOutVideoPrm.baseCreateParams.notifyPrevLink              = FALSE;
    ipcBitsOutVideoPrm.baseCreateParams.noNotifyMode                = TRUE;
    Chains_ipcBitsInitCreateParams_BitsOutRTOS(&ipcBitsOutVideoPrm,FALSE);

    ipcBitsInHostPrm.baseCreateParams.inQueParams.prevLinkId        = ipcBitsOutVideoId;
    ipcBitsInHostPrm.baseCreateParams.inQueParams.prevLinkQueId     = 0;
    ipcBitsInHostPrm.baseCreateParams.numOutQue                     = 1;
    ipcBitsInHostPrm.baseCreateParams.numChPerOutQue[0]             = 1;
    ipcBitsInHostPrm.baseCreateParams.notifyNextLink                = FALSE;
    ipcBitsInHostPrm.baseCreateParams.notifyPrevLink                = FALSE;
    ipcBitsInHostPrm.baseCreateParams.noNotifyMode                  = TRUE;
    Chains_ipcBitsInitCreateParams_BitsInHLOS(&ipcBitsInHostPrm);

    Chains_displayCtrlInit(chainsCfg->displayRes);
    System_linkCreate(mergeId, &mergePrm, sizeof(mergePrm));
   

    dup2Prm.inQueParams.prevLinkId           = dupId;
    dup2Prm.inQueParams.prevLinkQueId        = 1;
    dup2Prm.numOutQue                        = 2;
    dup2Prm.outQueParams[0].nextLink         = swMsId[0];
    dup2Prm.outQueParams[1].nextLink         = swMsId[1];

    dup2Prm.notifyNextLink                   = TRUE;

    for (i=0; i<2; i++) {
		
        swMsPrm[i].numSwMsInst               = 1;
        swMsPrm[i].swMsInstId[0]             = SYSTEM_SW_MS_SC_INST_SC5;
        swMsPrm[i].inQueParams.prevLinkId    = dup2Id;
        swMsPrm[i].inQueParams.prevLinkQueId = i;
        swMsPrm[i].outQueParams.nextLink     = displayId[i];
        swMsPrm[i].lineSkipMode              = FALSE;
        swMsPrm[i].enableLayoutGridDraw      = FALSE;
        swMsPrm[i].layoutPrm.outputFPS       = chainsCfg->channelConf[i].frameRate;
        swMsPrm[i].maxInputQueLen            = SYSTEM_SW_MS_DEFAULT_INPUT_QUE_LEN;
        swMsPrm[i].maxOutRes                 = chainsCfg->displayRes[i];
        swMsPrm[i].numOutBuf                 = 0;
        Chains_swMsSetLayoutParams(i, &swMsPrm[i]);

        displayPrm[i].numInputQueues                = 1;
        displayPrm[i].activeQueue                   = 0;
       displayPrm[i].inQueParams[0].prevLinkId     = swMsId[i];
        displayPrm[i].inQueParams[0].prevLinkQueId  = 0;
        displayPrm[i].displayRes                    = chainsCfg->displayRes[i];
        displayPrm[i].forceFieldSeparatedInputMode  = FALSE;
    }

 	if(enableOsdAlgLink)
    {
        System_linkCreate(ipcFramesOutVpssId     , &ipcFramesOutVpssPrm    , sizeof(ipcFramesOutVpssPrm));
        System_linkCreate(ipcFramesInDspId     , &ipcFramesInDspPrm    , sizeof(ipcFramesInDspPrm));
        System_linkCreate(osdId,&DSPLinkPrm,sizeof(DSPLinkPrm));
    }


    System_linkCreate(dupId, &dupPrm, sizeof(dupPrm));
    System_linkCreate(nsfId , &nsfPrm, sizeof(nsfPrm));
    System_linkCreate(ipcOutVpssId, &ipcOutVpssPrm, sizeof(ipcOutVpssPrm));
    System_linkCreate(ipcInVideoId, &ipcInVideoPrm, sizeof(ipcInVideoPrm));
    System_linkCreate(encId, &encPrm, sizeof(encPrm));
    System_linkCreate(ipcBitsOutVideoId, &ipcBitsOutVideoPrm, sizeof(ipcBitsOutVideoPrm));
    System_linkCreate(ipcBitsInHostId, &ipcBitsInHostPrm, sizeof(ipcBitsInHostPrm));

		//guo
	if(enableScdAlgLink)
	{
		System_linkCreate(sclrId, &sclrPrm    , sizeof(sclrPrm ));
		System_linkCreate(nsfId2,&nsfPrm2,sizeof(nsfPrm2));
		System_linkCreate(ipcFramesOutVpssId2     , &ipcFramesOutVpssPrm2    , sizeof(ipcFramesOutVpssPrm2));
		System_linkCreate(ipcFramesInDspId2     , &ipcFramesInDspPrm2    , sizeof(ipcFramesInDspPrm2));
		System_linkCreate(scdId,&scdPrm,sizeof(scdPrm));
		System_linkCreate(ipcBitsOutDspId2, &ipcBitsOutDspPrm2, sizeof(ipcBitsOutDspPrm2));
   		System_linkCreate(ipcBitsInHostId2, &ipcBitsInHostPrm2, sizeof(ipcBitsInHostPrm2));
	
	}

    System_linkCreate(dup2Id, &dup2Prm, sizeof(dup2Prm));
    for (i=0; i<2; i++) {
       System_linkCreate(swMsId[i], &swMsPrm[i], sizeof(swMsPrm[i]));
       System_linkCreate(displayId[i], &displayPrm[i], sizeof(displayPrm[i]));
    }

    //Chains_memPrintHeapStatus();

   
    System_linkStart(encId);
    for (i=0; i<2; i++) {
          System_linkStart(displayId[i]);
          System_linkStart(swMsId[i]);
    }

  	grpx_init(GRPX_FORMAT_RGB888);
	
     System_linkStart(dup2Id);
     System_linkStart(nsfId);
     System_linkStart(dupId);
//guo scd
	System_linkStart(ipcBitsInHostId2);
	System_linkStart(ipcBitsOutDspId2);
	System_linkStart(scdId);
	System_linkStart(ipcFramesInDspId2);
	System_linkStart(ipcFramesOutVpssId2);
	System_linkStart(nsfId2);
	System_linkStart(sclrId);
//guo OSD
	if(enableOsdAlgLink)
        {
            System_linkStart(osdId);
            System_linkStart(ipcFramesInDspId);
            System_linkStart(ipcFramesOutVpssId);		
        }
	
        System_linkStart(mergeId);
        System_linkStart(captureId);
 	//grpx_fb_draw_demo();

	/***guo********poll thread  ***/
	pthread_t poll_t;
	int res;
	
	PollData poll={
		.encId = encId,
		.swMsId[0]=swMsId[0],
		.swMsId[1]=swMsId[1],
		.swMsPrm[0]=swMsPrm[0],
		.swMsPrm[1]=swMsPrm[1]		
		};
	
	res = pthread_create(&poll_t,NULL,poll_thread,(void*)&poll);
	if(res!=0)
	{
		perror("thread creation failed");
		exit(-1);
	}
	/************end*/

		//Chains_ScdPrint(scdId);//This is only for temp test!!!
//This is for user input args 
	
	Chains_ipcBitsLocSt();	//start RTP (or Local Storage)
    while(1)
    {
      printf("My menu:Input L to storage the video and E to stop\n"
				"Input P for statistic\n");
            ch = Chains_menuRunTime();
            if(ch=='0')
                break;
           
            if(ch=='p')
            {
 				MultiCh_prfLoadPrint(TRUE,TRUE);
				continue;
            }

	   		if(ch == 'd')//draw
	   		{
	   		 grpx_draw_box(500,500,500,500);//在HDMI2上画了出来
	   		 grpx_fb_draw_grid(300,300,200,100,11);
	   		 continue;
			
	   		}
	   		if(ch == 'x')
	   		{
	   		grpx_draw_box_exit(500,500,500,500);
			grpx_fb_draw_grid_exit(300,300,200,100,11);
	 		grpx_exit();
			continue;
	   		}

       
         Bool switchCh = FALSE;
         Bool switchLayout = FALSE;
		if(ch=='L')
		{
			Chains_ipcBitsLocSt();
			continue;
		}
		if(ch=='E')
		{
			Chains_ipcBitsLocStStop();
			continue;
		}
        if(ch=='s')
        {
            switchLayout = TRUE;
            Chains_swMsSwitchLayout(&swMsId, &swMsPrm, switchLayout, switchCh, 2);
			//when you changed layout ,scd is disabled
			gScd_ctrl.enableMotionTracking = 0;
			gScd_ctrl.exitWrThr = 1;
			grpx_exit();
            printf("switch layout\n");
			continue;

         }
		if(ch == 'c')
		{
			gScd_ctrl.enableMotionTracking = 0;
			gScd_ctrl.exitWrThr = 1;
			grpx_exit();
			continue;
		}
         if(ch == '1')
         {
            switchCh = TRUE;
            Chains_swMsSwitchLayout(&swMsId, &swMsPrm, switchLayout, switchCh, 0);
            continue;
         }
		 if(ch == 'o')
		 {
		 		char ch2=Chains_menuSettingOsd();
				if( (ch2 == '0')||(ch2 == '1')||(ch2 == '3'))
				{
					UInt32 winId = ch2-48;
					g_osdChParam[0].chId = 0;
					g_osdChParam[0].winPrm[winId].enableWin = 0;
					System_linkControl(osdId,ALG_LINK_OSD_CMD_SET_CHANNEL_WIN_PRM, 
						&g_osdChParam[0], 
						sizeof(AlgLink_OsdChWinParams),
						TRUE
					);
					continue;
				}
				if(ch2=='x')
				{
					int i=0;
					for(i=0;i<4;i++)
					{
						g_osdChParam[i].chId = i;
						g_osdChParam[i].winPrm[0].enableWin = 0;
						g_osdChParam[i].winPrm[1].enableWin = 0;
						g_osdChParam[i].winPrm[2].enableWin = 0;
						g_osdChParam[i].winPrm[3].enableWin = 0;
						System_linkControl(osdId,ALG_LINK_OSD_CMD_SET_CHANNEL_WIN_PRM, 
						&g_osdChParam[i], 
						sizeof(AlgLink_OsdChWinParams),
						TRUE
						);
					  continue;
					}
				}
				if(ch2=='s')
				{
					int i=0;
					for(i=0;i<4;i++)
					{
						g_osdChParam[i].chId = i;
						g_osdChParam[i].winPrm[0].enableWin = 1;
						g_osdChParam[i].winPrm[1].enableWin = 1;
						g_osdChParam[i].winPrm[2].enableWin = 1;
						g_osdChParam[i].winPrm[3].enableWin = 1;
						System_linkControl(osdId,ALG_LINK_OSD_CMD_SET_CHANNEL_WIN_PRM, 
						&g_osdChParam[i], 
						sizeof(AlgLink_OsdChWinParams),
						TRUE
						);
					  continue;
					}//end for
				}///end if
		 	}///end ch==o
		
      }//end while1


        System_linkStop(captureId);
        System_linkStop(mergeId);
//guo----------------------
	if(enableScdAlgLink)
	{
		Scd_bitsWriteStop();
		System_linkStop(sclrId);
		System_linkStop(nsfId2);	
		System_linkStop(ipcFramesOutVpssId2);
		System_linkStop(ipcFramesInDspId2);
		System_linkStop(scdId);
		System_linkStop(ipcBitsOutDspId2);
		System_linkStop(ipcBitsInHostId2);	
	}
	if(enableOsdAlgLink)
        {
            Chains_ipcFramesStop();
            System_linkStop(ipcFramesOutVpssId);
            System_linkStop(ipcFramesInDspId);
            System_linkStop(osdId);
        }
//-------------------------------
        System_linkStop(dupId);
        System_linkStop(nsfId);
        System_linkStop(dup2Id);
        for (i=0; i<2; i++) {
            System_linkStop(swMsId[i]);
            System_linkStop(displayId[i]);
        }
        System_linkStop(encId);
        Chains_ipcBitsStop();
        System_linkStop(ipcBitsOutVideoId);
        System_linkStop(ipcBitsInHostId);
    

    System_linkDelete(captureId);
    System_linkDelete(mergeId);
//guo-------------
	if(enableScdAlgLink)
	{
		Scd_bitsWriteDelete();
		System_linkDelete(sclrId);
		System_linkDelete(nsfId2);	
		System_linkDelete(ipcFramesOutVpssId2);
		System_linkDelete(ipcFramesInDspId2);
		System_linkDelete(scdId);
		System_linkDelete(ipcBitsOutDspId2);
		System_linkDelete(ipcBitsInHostId2);	
	}
    if(enableOsdAlgLink)
    {
        System_linkDelete(ipcFramesOutVpssId);
        System_linkDelete(ipcFramesInDspId);
        System_linkDelete(osdId);         
    }
//-----------------
    System_linkDelete(dupId);
    System_linkDelete(nsfId);
    System_linkDelete(dup2Id);
    for (i=0; i<2; i++) {
        System_linkDelete(swMsId[i]);
        System_linkDelete(displayId[i]);
    }
    System_linkDelete(ipcOutVpssId);
    System_linkDelete(ipcInVideoId);
    System_linkDelete(encId);
    System_linkDelete(ipcBitsOutVideoId);
    System_linkDelete(ipcBitsInHostId);
    Chains_ipcBitsExit();

    Chains_displayCtrlDeInit();
}
/* This usecase assumes CIF/QCIF <secondary out>, MJPEG are enabled */
Void MultiCh_createProgressive8D1VcapVencVdecVdis()
{
    CaptureLink_CreateParams    capturePrm;
    SclrLink_CreateParams       sclrPrm;
    NsfLink_CreateParams        nsfPrm;
    DeiLink_CreateParams        deiPrm;
    MergeLink_CreateParams      mergePrm[NUM_MERGE_LINK];
    DupLink_CreateParams        dupPrm[NUM_DUP_LINK];
    static SwMsLink_CreateParams       swMsPrm[VDIS_DEV_MAX];
    DisplayLink_CreateParams    displayPrm[VDIS_DEV_MAX];
    IpcLink_CreateParams        ipcOutVpssPrm;
    IpcLink_CreateParams        ipcInVpssPrm;
    IpcLink_CreateParams        ipcOutVideoPrm;
    IpcLink_CreateParams        ipcInVideoPrm;
    EncLink_CreateParams        encPrm;
    DecLink_CreateParams        decPrm;
    IpcBitsOutLinkHLOS_CreateParams   ipcBitsOutHostPrm;
    IpcBitsOutLinkRTOS_CreateParams   ipcBitsOutVideoPrm;
    IpcBitsInLinkHLOS_CreateParams    ipcBitsInHostPrm[2];

    IpcBitsInLinkRTOS_CreateParams    ipcBitsInVideoPrm;
    CaptureLink_VipInstParams         *pCaptureInstPrm;
    CaptureLink_OutParams             *pCaptureOutPrm;
    IpcFramesInLinkRTOS_CreateParams  ipcFramesInDspPrm;
    IpcFramesOutLinkRTOS_CreateParams ipcFramesOutVpssPrm;
    AlgLink_CreateParams              dspAlgPrm;

    System_LinkInfo                   bitsProducerLinkInfo;
    UInt32 mergeId[NUM_MERGE_LINK];
    UInt32 dupId[NUM_DUP_LINK];
    UInt32 ipcOutVpssId, ipcInVpssId;
    UInt32 ipcOutVideoId, ipcInVideoId;

    VCAP_VIDDEC_PARAMS_S vidDecVideoModeArgs[NUM_CAPTURE_DEVICES];

    IpcBitsOutLinkRTOS_CreateParams   ipcBitsOutDspPrm;
    UInt32 ipcBitsOutDSPId;

    UInt32 vipInstId;
    UInt32 i, j;
    Bool   enableOsdAlgLink = gVsysModuleContext.vsysConfig.enableOsd;
    Bool   enableScdAlgLink = gVsysModuleContext.vsysConfig.enableScd;

    MULTICH_INIT_STRUCT(IpcLink_CreateParams,ipcOutVpssPrm);
    MULTICH_INIT_STRUCT(IpcLink_CreateParams,ipcInVpssPrm);
    MULTICH_INIT_STRUCT(IpcLink_CreateParams,ipcOutVideoPrm);
    MULTICH_INIT_STRUCT(IpcLink_CreateParams,ipcInVideoPrm);
    MULTICH_INIT_STRUCT(IpcBitsOutLinkHLOS_CreateParams,ipcBitsOutHostPrm);
    MULTICH_INIT_STRUCT(IpcBitsOutLinkRTOS_CreateParams,ipcBitsOutVideoPrm);
    MULTICH_INIT_STRUCT(IpcBitsOutLinkRTOS_CreateParams,ipcBitsOutDspPrm);

    MULTICH_INIT_STRUCT(IpcBitsInLinkHLOS_CreateParams,ipcBitsInHostPrm[0]);
    MULTICH_INIT_STRUCT(IpcBitsInLinkHLOS_CreateParams,ipcBitsInHostPrm[1]);
    MULTICH_INIT_STRUCT(IpcBitsInLinkRTOS_CreateParams,ipcBitsInVideoPrm);
    MULTICH_INIT_STRUCT(DecLink_CreateParams, decPrm);
    MULTICH_INIT_STRUCT(IpcFramesInLinkRTOS_CreateParams,ipcFramesInDspPrm);
    MULTICH_INIT_STRUCT(IpcFramesOutLinkRTOS_CreateParams,ipcFramesOutVpssPrm);
    MULTICH_INIT_STRUCT(EncLink_CreateParams, encPrm);
    MULTICH_INIT_STRUCT(AlgLink_CreateParams, dspAlgPrm);

    for (i = 0; i < VDIS_DEV_MAX;i++)
    {
        MULTICH_INIT_STRUCT(DisplayLink_CreateParams,
                            displayPrm[i]);
        MULTICH_INIT_STRUCT(SwMsLink_CreateParams ,swMsPrm[i]);
    }
    MULTICH_INIT_STRUCT(SclrLink_CreateParams, sclrPrm);
    MULTICH_INIT_STRUCT(NsfLink_CreateParams,  nsfPrm);
    MULTICH_INIT_STRUCT(DeiLink_CreateParams,  deiPrm);

    printf("\n********* Entered usecase 8CH <814x> Enc/Dec OSD %s SCD %s \n\n",
            enableOsdAlgLink == TRUE ? "Enabled" : "Disabled",
            enableScdAlgLink == TRUE ? "Enabled" : "Disabled"
            );

    MultiCh_detectBoard();

    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
    );
#if (TILER_ENABLE == FALSE)
    {
        /* Disable tiler allocator for this usecase
         * for that tiler memory can be reused for
         * non-tiled allocation
         */
        SystemTiler_disableAllocator();
    }
#endif


    vipInstId = 0;

    gVcapModuleContext.captureId    = SYSTEM_LINK_ID_CAPTURE;

    if(enableOsdAlgLink || enableScdAlgLink)
    {
        dspAlgPrm.enableOSDAlg = TRUE;

        gVcapModuleContext.dspAlgId[0] = SYSTEM_LINK_ID_ALG_0  ;
        gVcapModuleContext.ipcFramesOutVpssId[0] = SYSTEM_VPSS_LINK_ID_IPC_FRAMES_OUT_0;
        gVcapModuleContext.ipcFramesInDspId[0] = SYSTEM_DSP_LINK_ID_IPC_FRAMES_IN_0;
        if(enableScdAlgLink)
        {
          ipcBitsOutDSPId = SYSTEM_DSP_LINK_ID_IPC_BITS_OUT_0;
          gVcapModuleContext.ipcBitsInHLOSId = SYSTEM_HOST_LINK_ID_IPC_BITS_IN_0;
        }
    }

    gVcapModuleContext.sclrId[0]       = SYSTEM_LINK_ID_SCLR_INST_0;
    gVcapModuleContext.nsfId[0]        = SYSTEM_LINK_ID_NSF_0;
    gVcapModuleContext.deiId[0]     = SYSTEM_LINK_ID_DEI_0;
    gVencModuleContext.encId        = SYSTEM_LINK_ID_VENC_0;
    gVdecModuleContext.decId        = SYSTEM_LINK_ID_VDEC_0;

    gVdisModuleContext.swMsId[0]      = SYSTEM_LINK_ID_SW_MS_MULTI_INST_0;
    gVdisModuleContext.swMsId[1]      = SYSTEM_LINK_ID_SW_MS_MULTI_INST_1;

    swMsPrm[0].numSwMsInst = 1;
    swMsPrm[1].numSwMsInst = 1;

    #if defined(TI_814X_BUILD) || defined(TI_8107_BUILD)
    /* use AUX scaler (SC2), since SC1 is used for DEI */
    swMsPrm[0].swMsInstId[0] = SYSTEM_SW_MS_SC_INST_DEI_SC_NO_DEI;
    #else
    /* use MAIN scaler (SC1), since SC2 is used for DEI */
    swMsPrm[0].swMsInstId[0] = SYSTEM_SW_MS_SC_INST_DEIHQ_SC_NO_DEI;
    #endif

    swMsPrm[1].swMsInstId[0] = SYSTEM_SW_MS_SC_INST_SC5;

    gVdisModuleContext.displayId[0] = SYSTEM_LINK_ID_DISPLAY_0; /* ON AND OFF CHIP HDMI */
    gVdisModuleContext.displayId[1] = SYSTEM_LINK_ID_DISPLAY_2; /* SDTV */

    mergeId[LIVE_DECODE_MERGE_LINK_IDX]     = SYSTEM_VPSS_LINK_ID_MERGE_0;
    mergeId[D1_CIF_MERGE_LINK_IDX]          = SYSTEM_VPSS_LINK_ID_MERGE_1;

    dupId[CAP_DUP_LINK_IDX]             = SYSTEM_VPSS_LINK_ID_DUP_0;
    dupId[LIVE_DECODE_DUP_LINK_IDX]     = SYSTEM_VPSS_LINK_ID_DUP_1;

    ipcOutVpssId = SYSTEM_VPSS_LINK_ID_IPC_OUT_M3_0;
    ipcInVideoId = SYSTEM_VIDEO_LINK_ID_IPC_IN_M3_0;
    ipcOutVideoId= SYSTEM_VIDEO_LINK_ID_IPC_OUT_M3_0;
    ipcInVpssId  = SYSTEM_VPSS_LINK_ID_IPC_IN_M3_0;

    gVencModuleContext.ipcBitsOutRTOSId  = SYSTEM_VIDEO_LINK_ID_IPC_BITS_OUT_0;
    if(enableScdAlgLink)
       gVencModuleContext.ipcBitsInHLOSId   = SYSTEM_HOST_LINK_ID_IPC_BITS_IN_1;
    else
       gVencModuleContext.ipcBitsInHLOSId   = SYSTEM_HOST_LINK_ID_IPC_BITS_IN_0;

    gVdecModuleContext.ipcBitsOutHLOSId  = SYSTEM_HOST_LINK_ID_IPC_BITS_OUT_0;
    gVdecModuleContext.ipcBitsInRTOSId  = SYSTEM_VIDEO_LINK_ID_IPC_BITS_IN_0;

    CaptureLink_CreateParams_Init(&capturePrm);
    capturePrm.outQueParams[0].nextLink   = dupId[CAP_DUP_LINK_IDX];

    capturePrm.numVipInst                 = 2;
    capturePrm.tilerEnable                = FALSE;
    capturePrm.numBufsPerCh               = NUM_CAPTURE_BUFFERS;
    capturePrm.maxBlindAreasPerCh         = 4;

    pCaptureInstPrm                     = &capturePrm.vipInst[0];
    pCaptureInstPrm->vipInstId          = (SYSTEM_CAPTURE_INST_VIP0_PORTA+
                                          vipInstId)%SYSTEM_CAPTURE_INST_MAX;
    pCaptureInstPrm->videoDecoderId     = SYSTEM_DEVICE_VID_DEC_TVP5158_DRV;
    pCaptureInstPrm->inDataFormat       = SYSTEM_DF_YUV422P;
    pCaptureInstPrm->standard           = SYSTEM_STD_MUX_4CH_D1;
    pCaptureInstPrm->numOutput          = 1;

    pCaptureOutPrm                      = &pCaptureInstPrm->outParams[0];
    pCaptureOutPrm->dataFormat          = SYSTEM_DF_YUV422I_YUYV;
    pCaptureOutPrm->scEnable            = FALSE;
    pCaptureOutPrm->scOutWidth          = 0;
    pCaptureOutPrm->scOutHeight         = 0;
    pCaptureOutPrm->outQueId            = 0;

    pCaptureInstPrm                     = &capturePrm.vipInst[1];
    pCaptureInstPrm->vipInstId          = SYSTEM_CAPTURE_INST_VIP0_PORTB;
    pCaptureInstPrm->videoDecoderId     = SYSTEM_DEVICE_VID_DEC_TVP5158_DRV;
    pCaptureInstPrm->inDataFormat       = SYSTEM_DF_YUV422P;
    pCaptureInstPrm->standard           = SYSTEM_STD_MUX_4CH_D1;
    pCaptureInstPrm->numOutput          = 1;

    pCaptureOutPrm                      = &pCaptureInstPrm->outParams[0];
    pCaptureOutPrm->dataFormat          = SYSTEM_DF_YUV422I_YUYV;
    pCaptureOutPrm->scEnable            = FALSE;
    pCaptureOutPrm->scOutWidth          = 0;
    pCaptureOutPrm->scOutHeight         = 0;
    pCaptureOutPrm->outQueId            = 0;

    for(i = 0; i < NUM_CAPTURE_DEVICES; i++)
    {
        vidDecVideoModeArgs[i].videoIfMode        = DEVICE_CAPT_VIDEO_IF_MODE_8BIT;
        vidDecVideoModeArgs[i].videoDataFormat    = SYSTEM_DF_YUV422P;
        vidDecVideoModeArgs[i].standard           = SYSTEM_STD_MUX_4CH_D1;
        vidDecVideoModeArgs[i].videoCaptureMode   =
                    DEVICE_CAPT_VIDEO_CAPTURE_MODE_MULTI_CH_PIXEL_MUX_EMBEDDED_SYNC;
        vidDecVideoModeArgs[i].videoSystem        =
                                      DEVICE_VIDEO_DECODER_VIDEO_SYSTEM_AUTO_DETECT;
        vidDecVideoModeArgs[i].videoCropEnable    = FALSE;
        vidDecVideoModeArgs[i].videoAutoDetectTimeout = -1;
    }

    Vcap_configVideoDecoder(vidDecVideoModeArgs, NUM_CAPTURE_DEVICES);

    dupPrm[CAP_DUP_LINK_IDX].inQueParams.prevLinkId    = gVcapModuleContext.captureId;
    dupPrm[CAP_DUP_LINK_IDX].inQueParams.prevLinkQueId = 0;
    dupPrm[CAP_DUP_LINK_IDX].notifyNextLink            = TRUE;
    dupPrm[CAP_DUP_LINK_IDX].numOutQue                 = 2;
    dupPrm[CAP_DUP_LINK_IDX].outQueParams[0].nextLink  = gVcapModuleContext.deiId[0];
    dupPrm[CAP_DUP_LINK_IDX].outQueParams[1].nextLink  = gVcapModuleContext.sclrId[0];

    deiPrm.inQueParams.prevLinkId = dupId[CAP_DUP_LINK_IDX];
    deiPrm.inQueParams.prevLinkQueId  = 0;

    /* Set Output Scaling at DEI based on ratio */
    deiPrm.outScaleFactor[DEI_LINK_OUT_QUE_DEI_SC][0].scaleMode = DEI_SCALE_MODE_RATIO;
    deiPrm.outScaleFactor[DEI_LINK_OUT_QUE_DEI_SC][0].ratio.widthRatio.numerator = 1;
    deiPrm.outScaleFactor[DEI_LINK_OUT_QUE_DEI_SC][0].ratio.widthRatio.denominator = 1;
    deiPrm.outScaleFactor[DEI_LINK_OUT_QUE_DEI_SC][0].ratio.heightRatio.numerator = 1;
    deiPrm.outScaleFactor[DEI_LINK_OUT_QUE_DEI_SC][0].ratio.heightRatio.denominator = 1;
    for (i=1; i < DEI_LINK_MAX_CH; i++)
        deiPrm.outScaleFactor[DEI_LINK_OUT_QUE_DEI_SC][i] = deiPrm.outScaleFactor[DEI_LINK_OUT_QUE_DEI_SC][0];

    deiPrm.outScaleFactor[DEI_LINK_OUT_QUE_VIP_SC][0].scaleMode = DEI_SCALE_MODE_RATIO;
    deiPrm.outScaleFactor[DEI_LINK_OUT_QUE_VIP_SC][0].ratio.heightRatio.numerator = 1;
    deiPrm.outScaleFactor[DEI_LINK_OUT_QUE_VIP_SC][0].ratio.heightRatio.denominator = 1;
    deiPrm.outScaleFactor[DEI_LINK_OUT_QUE_VIP_SC][0].ratio.widthRatio.numerator = 1;
    deiPrm.outScaleFactor[DEI_LINK_OUT_QUE_VIP_SC][0].ratio.widthRatio.denominator = 1;
    for (i=1; i < DEI_LINK_MAX_CH; i++)
        deiPrm.outScaleFactor[DEI_LINK_OUT_QUE_VIP_SC][i] = deiPrm.outScaleFactor[DEI_LINK_OUT_QUE_VIP_SC][0];

    deiPrm.outScaleFactor[DEI_LINK_OUT_QUE_VIP_SC_SECONDARY_OUT][0].scaleMode = DEI_SCALE_MODE_RATIO;
    deiPrm.outScaleFactor[DEI_LINK_OUT_QUE_VIP_SC_SECONDARY_OUT][0].ratio.heightRatio.numerator = 1;
    deiPrm.outScaleFactor[DEI_LINK_OUT_QUE_VIP_SC_SECONDARY_OUT][0].ratio.heightRatio.denominator = 1;
    deiPrm.outScaleFactor[DEI_LINK_OUT_QUE_VIP_SC_SECONDARY_OUT][0].ratio.widthRatio.numerator = 1;
    deiPrm.outScaleFactor[DEI_LINK_OUT_QUE_VIP_SC_SECONDARY_OUT][0].ratio.widthRatio.denominator = 1;
    for (i=1; i < DEI_LINK_MAX_CH; i++)
        deiPrm.outScaleFactor[DEI_LINK_OUT_QUE_VIP_SC_SECONDARY_OUT][i] = deiPrm.outScaleFactor[DEI_LINK_OUT_QUE_VIP_SC_SECONDARY_OUT][0];

    deiPrm.enableOut[DEI_LINK_OUT_QUE_DEI_SC]                        = TRUE;
    deiPrm.enableOut[DEI_LINK_OUT_QUE_VIP_SC]                        = TRUE;
    deiPrm.enableOut[DEI_LINK_OUT_QUE_VIP_SC_SECONDARY_OUT]          = TRUE;

    deiPrm.outputFrameRate[DEI_LINK_OUT_QUE_VIP_SC_SECONDARY_OUT]    = 1;

    deiPrm.outQueParams[DEI_LINK_OUT_QUE_DEI_SC].nextLink                   = mergeId[LIVE_DECODE_MERGE_LINK_IDX];
    deiPrm.outQueParams[DEI_LINK_OUT_QUE_VIP_SC].nextLink                   = mergeId[D1_CIF_MERGE_LINK_IDX];
    deiPrm.outQueParams[DEI_LINK_OUT_QUE_VIP_SC_SECONDARY_OUT].nextLink     = mergeId[D1_CIF_MERGE_LINK_IDX];

    deiPrm.tilerEnable[DEI_LINK_OUT_QUE_VIP_SC]          = TILER_ENABLE;
    deiPrm.comprEnable                                   = FALSE;
    deiPrm.setVipScYuv422Format                          = FALSE;

    sclrPrm.enableLineSkipSc = FALSE;
    sclrPrm.inputFrameRate   = 30;
    sclrPrm.outputFrameRate  = 30;
    sclrPrm.inQueParams.prevLinkId    = dupId[CAP_DUP_LINK_IDX];
    sclrPrm.inQueParams.prevLinkQueId = 1;
    sclrPrm.outQueParams.nextLink     = gVcapModuleContext.nsfId[0];
    sclrPrm.scaleMode = DEI_SCALE_MODE_RATIO;
    sclrPrm.outScaleFactor.ratio.heightRatio.numerator   = 1;
    sclrPrm.outScaleFactor.ratio.heightRatio.denominator = 2;
    sclrPrm.outScaleFactor.ratio.widthRatio.numerator    = 1;
    sclrPrm.outScaleFactor.ratio.widthRatio.denominator  = 4;
    sclrPrm.tilerEnable = FALSE;

    nsfPrm.bypassNsf                        = TRUE;
    nsfPrm.tilerEnable                      = FALSE;
    nsfPrm.inQueParams.prevLinkId           = gVcapModuleContext.sclrId[0];
    nsfPrm.inQueParams.prevLinkQueId        = 0;
    nsfPrm.numOutQue                        = 1;
    nsfPrm.outQueParams[0].nextLink         = mergeId[D1_CIF_MERGE_LINK_IDX];
    nsfPrm.numBufsPerCh                     = NUM_NSF_BUFFERS;
    nsfPrm.inputFrameRate  = 30;
    nsfPrm.outputFrameRate = 30;

    /* Merge Q0 - D1 <from VIP-SC>, Q1 - CIF <from VIP-SC_SECONDARY>, Q2 -D1 for MJPEG <from DEI-SC>  */
    mergePrm[D1_CIF_MERGE_LINK_IDX].inQueParams[0].prevLinkId       = gVcapModuleContext.deiId[0];
    mergePrm[D1_CIF_MERGE_LINK_IDX].inQueParams[0].prevLinkQueId    = DEI_LINK_OUT_QUE_VIP_SC;
    mergePrm[D1_CIF_MERGE_LINK_IDX].inQueParams[1].prevLinkId       = gVcapModuleContext.nsfId[0];
    mergePrm[D1_CIF_MERGE_LINK_IDX].inQueParams[1].prevLinkQueId    = 0;
    mergePrm[D1_CIF_MERGE_LINK_IDX].inQueParams[2].prevLinkId       = gVcapModuleContext.deiId[0];
    mergePrm[D1_CIF_MERGE_LINK_IDX].inQueParams[2].prevLinkQueId    = DEI_LINK_OUT_QUE_VIP_SC_SECONDARY_OUT;
    mergePrm[D1_CIF_MERGE_LINK_IDX].notifyNextLink                  = TRUE;
    mergePrm[D1_CIF_MERGE_LINK_IDX].numInQue = 3;

    if (enableOsdAlgLink || enableScdAlgLink)
    {
        mergePrm[D1_CIF_MERGE_LINK_IDX].outQueParams.nextLink  = gVcapModuleContext.ipcFramesOutVpssId[0];
        ipcOutVpssPrm.inQueParams.prevLinkId                   = gVcapModuleContext.ipcFramesOutVpssId[0];

        /* Redirect to DSP for OSD / SCD */
        ipcFramesOutVpssPrm .baseCreateParams.inQueParams.prevLinkId   = mergeId[D1_CIF_MERGE_LINK_IDX];
        ipcFramesOutVpssPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
        ipcFramesOutVpssPrm.baseCreateParams.outQueParams[0].nextLink  = ipcOutVpssId;
        ipcFramesOutVpssPrm.baseCreateParams.processLink               = gVcapModuleContext.ipcFramesInDspId[0];
        ipcFramesOutVpssPrm.baseCreateParams.notifyPrevLink            = TRUE;
        ipcFramesOutVpssPrm.baseCreateParams.notifyNextLink            = TRUE;
        ipcFramesOutVpssPrm.baseCreateParams.notifyProcessLink         = TRUE;
        ipcFramesOutVpssPrm.baseCreateParams.noNotifyMode              = FALSE;
        ipcFramesOutVpssPrm.baseCreateParams.numOutQue                 = 1;

        ipcFramesInDspPrm.baseCreateParams.inQueParams.prevLinkId      = gVcapModuleContext.ipcFramesOutVpssId[0];
        ipcFramesInDspPrm.baseCreateParams.inQueParams.prevLinkQueId   = 0;
        ipcFramesInDspPrm.baseCreateParams.outQueParams[0].nextLink    = gVcapModuleContext.dspAlgId[0];
        ipcFramesInDspPrm.baseCreateParams.notifyPrevLink              = TRUE;
        ipcFramesInDspPrm.baseCreateParams.notifyNextLink              = TRUE;
        ipcFramesInDspPrm.baseCreateParams.noNotifyMode                = FALSE;
        ipcFramesInDspPrm.baseCreateParams.numOutQue                   = 1;

        dspAlgPrm.inQueParams.prevLinkId = gVcapModuleContext.ipcFramesInDspId[0];
        dspAlgPrm.inQueParams.prevLinkQueId = 0;
    }
    else
    {
        mergePrm[D1_CIF_MERGE_LINK_IDX].outQueParams.nextLink  = ipcOutVpssId;
        ipcOutVpssPrm.inQueParams.prevLinkId                   = mergeId[D1_CIF_MERGE_LINK_IDX];
    }

    ipcOutVpssPrm.inQueParams.prevLinkQueId    = 0;
    ipcOutVpssPrm.numOutQue = 1;
    ipcOutVpssPrm.outQueParams[0].nextLink     = ipcInVideoId;
    ipcOutVpssPrm.notifyNextLink               = TRUE;
    ipcOutVpssPrm.notifyPrevLink               = TRUE;
    ipcOutVpssPrm.noNotifyMode                 = FALSE;

    ipcInVideoPrm.inQueParams.prevLinkId       = ipcOutVpssId;
    ipcInVideoPrm.inQueParams.prevLinkQueId    = 0;
    ipcInVideoPrm.numOutQue                    = 1;
    ipcInVideoPrm.outQueParams[0].nextLink     = gVencModuleContext.encId;
    ipcInVideoPrm.notifyNextLink               = TRUE;
    ipcInVideoPrm.notifyPrevLink               = TRUE;
    ipcInVideoPrm.noNotifyMode                 = FALSE;

    encPrm.numBufPerCh[0] = NUM_ENCODE_D1_BUFFERS;
    encPrm.numBufPerCh[1] = NUM_ENCODE_CIF_BUFFERS;

    {
        EncLink_ChCreateParams *pLinkChPrm;
        EncLink_ChDynamicParams *pLinkDynPrm;
        VENC_CHN_DYNAMIC_PARAM_S *pDynPrm;
        VENC_CHN_PARAMS_S *pChPrm;

        /* Primary Stream Params - D1 */
        for (i=0; i<gVencModuleContext.vencConfig.numPrimaryChn; i++)
        {
            pLinkChPrm  = &encPrm.chCreateParams[i];
            pLinkDynPrm = &pLinkChPrm->defaultDynamicParams;

            pChPrm      = &gVencModuleContext.vencConfig.encChannelParams[i];
            pDynPrm     = &pChPrm->dynamicParam;

            pLinkChPrm->format                  = IVIDEO_H264HP;
            pLinkChPrm->profile                 = gVencModuleContext.vencConfig.h264Profile[i];
            pLinkChPrm->dataLayout              = IVIDEO_FIELD_SEPARATED;
            pLinkChPrm->fieldMergeEncodeEnable  = FALSE;
            pLinkChPrm->enableAnalyticinfo      = pChPrm->enableAnalyticinfo;
            pLinkChPrm->enableWaterMarking      = pChPrm->enableWaterMarking;
            pLinkChPrm->maxBitRate              = pChPrm->maxBitRate;
            pLinkChPrm->encodingPreset          = pChPrm->encodingPreset;
            pLinkChPrm->rateControlPreset       = pChPrm->rcType;
            pLinkChPrm->enableSVCExtensionFlag  = pChPrm->enableSVCExtensionFlag;
            pLinkChPrm->numTemporalLayer        = pChPrm->numTemporalLayer;

            pLinkDynPrm->intraFrameInterval     = pDynPrm->intraFrameInterval;
            pLinkDynPrm->targetBitRate          = pDynPrm->targetBitRate;
            pLinkDynPrm->interFrameInterval     = 1;
            pLinkDynPrm->mvAccuracy             = IVIDENC2_MOTIONVECTOR_QUARTERPEL;
            pLinkDynPrm->inputFrameRate         = pDynPrm->inputFrameRate;
            pLinkDynPrm->rcAlg                  = pDynPrm->rcAlg;
            pLinkDynPrm->qpMin                  = pDynPrm->qpMin;
            pLinkDynPrm->qpMax                  = pDynPrm->qpMax;
            pLinkDynPrm->qpInit                 = pDynPrm->qpInit;
            pLinkDynPrm->vbrDuration            = pDynPrm->vbrDuration;
            pLinkDynPrm->vbrSensitivity         = pDynPrm->vbrSensitivity;
        }

        if (gVsysModuleContext.vsysConfig.enableSecondaryOut == TRUE)
        {
            /* Secondary Out <CIF> Params */
            for (i=gVencModuleContext.vencConfig.numPrimaryChn, j=VENC_PRIMARY_CHANNELS;
                  i<(gVencModuleContext.vencConfig.numPrimaryChn
                           + gVencModuleContext.vencConfig.numSecondaryChn);
                    i++, j++)
            {
                pLinkChPrm  = &encPrm.chCreateParams[i];
                pLinkDynPrm = &pLinkChPrm->defaultDynamicParams;

                pChPrm      = &gVencModuleContext.vencConfig.encChannelParams[j];
                pDynPrm     = &pChPrm->dynamicParam;

                pLinkChPrm->format                  = IVIDEO_H264HP;
                pLinkChPrm->profile                 = gVencModuleContext.vencConfig.h264Profile[i];
                pLinkChPrm->dataLayout              = IVIDEO_FIELD_SEPARATED;
                pLinkChPrm->fieldMergeEncodeEnable  = FALSE;
                pLinkChPrm->enableAnalyticinfo      = pChPrm->enableAnalyticinfo;
                pLinkChPrm->enableWaterMarking      = pChPrm->enableWaterMarking;
                pLinkChPrm->maxBitRate              = pChPrm->maxBitRate;
                pLinkChPrm->encodingPreset          = pChPrm->encodingPreset;
                pLinkChPrm->rateControlPreset       = pChPrm->rcType;
                pLinkChPrm->enableSVCExtensionFlag  = pChPrm->enableSVCExtensionFlag;
                pLinkChPrm->numTemporalLayer        = pChPrm->numTemporalLayer;

                pLinkDynPrm->intraFrameInterval     = pDynPrm->intraFrameInterval;
                pLinkDynPrm->targetBitRate          = pDynPrm->targetBitRate;
                pLinkDynPrm->interFrameInterval     = 1;
                pLinkDynPrm->mvAccuracy             = IVIDENC2_MOTIONVECTOR_QUARTERPEL;
                pLinkDynPrm->inputFrameRate         = pDynPrm->inputFrameRate;
                pLinkDynPrm->rcAlg                  = pDynPrm->rcAlg;
                pLinkDynPrm->qpMin                  = pDynPrm->qpMin;
                pLinkDynPrm->qpMax                  = pDynPrm->qpMax;
                pLinkDynPrm->qpInit                 = pDynPrm->qpInit;
                pLinkDynPrm->vbrDuration            = pDynPrm->vbrDuration;
                pLinkDynPrm->vbrSensitivity         = pDynPrm->vbrSensitivity;
            }
        }

        /* MJPEG  Params */
        if (gVsysModuleContext.vsysConfig.enableMjpegEnc == TRUE)
        {
            for (i=gVencModuleContext.vencConfig.numPrimaryChn + gVencModuleContext.vencConfig.numSecondaryChn;
                      i<(VENC_CHN_MAX); i++)
            {
                pLinkChPrm  = &encPrm.chCreateParams[i];
                pLinkDynPrm = &pLinkChPrm->defaultDynamicParams;

                pChPrm      = &gVencModuleContext.vencConfig.encChannelParams[i];
                pDynPrm     = &pChPrm->dynamicParam;

                pLinkChPrm->format                 = IVIDEO_MJPEG;
                pLinkChPrm->profile                = 0;
                pLinkChPrm->dataLayout             = IVIDEO_FIELD_SEPARATED;
                pLinkChPrm->fieldMergeEncodeEnable = FALSE;
                pLinkChPrm->enableAnalyticinfo     = 0;
                pLinkChPrm->enableWaterMarking     = 0;
                pLinkChPrm->maxBitRate             = 0;
                pLinkChPrm->encodingPreset         = 0;
                pLinkChPrm->rateControlPreset      = 0;
                pLinkChPrm->enableSVCExtensionFlag = 0;
                pLinkChPrm->numTemporalLayer       = 0;

                pLinkDynPrm->intraFrameInterval    = 0;
                pLinkDynPrm->targetBitRate         = 100*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    = ipcInVideoId;
        encPrm.inQueParams.prevLinkQueId = 0;
        encPrm.outQueParams.nextLink     = gVencModuleContext.ipcBitsOutRTOSId;
    }

    ipcBitsOutVideoPrm.baseCreateParams.inQueParams.prevLinkId = gVencModuleContext.encId;
    ipcBitsOutVideoPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
    ipcBitsOutVideoPrm.baseCreateParams.numOutQue                 = 1;
    ipcBitsOutVideoPrm.baseCreateParams.outQueParams[0].nextLink = gVencModuleContext.ipcBitsInHLOSId;
    MultiCh_ipcBitsInitCreateParams_BitsOutRTOS(&ipcBitsOutVideoPrm,
                                               TRUE);

    ipcBitsInHostPrm[0].baseCreateParams.inQueParams.prevLinkId = gVencModuleContext.ipcBitsOutRTOSId;
    ipcBitsInHostPrm[0].baseCreateParams.inQueParams.prevLinkQueId = 0;
    MultiCh_ipcBitsInitCreateParams_BitsInHLOS(&ipcBitsInHostPrm[0]);

    if(enableOsdAlgLink)
    {
        int chId;

        for(chId = 0; chId < ALG_LINK_OSD_MAX_CH; chId++)
        {
            AlgLink_OsdChWinParams * chWinPrm = &dspAlgPrm.osdChCreateParams[chId].chDefaultParams;

            /* set osd window max width and height */
            dspAlgPrm.osdChCreateParams[chId].maxWidth  = EXAMPLE_OSD_WIN_MAX_WIDTH;
            dspAlgPrm.osdChCreateParams[chId].maxHeight = EXAMPLE_OSD_WIN_MAX_HEIGHT;

            chWinPrm->chId = chId;
            chWinPrm->numWindows = 0;
        }
    }

    if (enableScdAlgLink)
    {
        Int32   numBlksInFrame;
        Int32   numHorzBlks, numVertBlks, chId;
        Uint32  x, y, i;
        //AlgLink_ScdblkChngConfig  blkConfig[ALG_LINK_SCD_MAX_BLOCKS_IN_FRAME];

        dspAlgPrm.enableSCDAlg              = TRUE;
        dspAlgPrm.outQueParams[ALG_LINK_SCD_OUT_QUE].nextLink     = ipcBitsOutDSPId;

        dspAlgPrm.scdCreateParams.maxWidth = 176;
        dspAlgPrm.scdCreateParams.maxHeight = 144;
        dspAlgPrm.scdCreateParams.maxStride = 176;
        dspAlgPrm.scdCreateParams.numValidChForSCD = 8;
        dspAlgPrm.scdCreateParams.numSecs2WaitB4Init    = 3;
        dspAlgPrm.scdCreateParams.numSecs2WaitB4FrmAlert= 1;
        dspAlgPrm.scdCreateParams.inputFrameRate         = 30;
        dspAlgPrm.scdCreateParams.outputFrameRate        = 5;
        dspAlgPrm.scdCreateParams.numSecs2WaitAfterFrmAlert = 2;

        dspAlgPrm.scdCreateParams.enableMotionNotify     = FALSE;
        dspAlgPrm.scdCreateParams.enableTamperNotify     = FALSE;


        // Configure array to monitor scene changes in all frame blocks, i.e., motion detection.
            // Each block is fixed to be 32x10 in size,
        numHorzBlks     = ((dspAlgPrm.scdCreateParams.maxWidth + 0x1F ) & (~0x1F)) / 32;
        if (dspAlgPrm.scdCreateParams.maxHeight == 120)
            numVertBlks     = dspAlgPrm.scdCreateParams.maxHeight / 10;
        else
            numVertBlks     = dspAlgPrm.scdCreateParams.maxHeight / 12;
        numBlksInFrame  = numHorzBlks * numVertBlks;

        for(chId = 0; chId < dspAlgPrm.scdCreateParams.numValidChForSCD; chId++)
        {
            AlgLink_ScdChParams * chPrm = &dspAlgPrm.scdCreateParams.chDefaultParams[chId];

            chPrm->blkNumBlksInFrame  = numBlksInFrame;
            chPrm->chId               = SCDChannelMonitor[chId];
            chPrm->mode               = ALG_LINK_SCD_DETECTMODE_MONITOR_BLOCKS_AND_FRAME;
            chPrm->frmIgnoreLightsON  = FALSE;
            chPrm->frmIgnoreLightsOFF = FALSE;
            chPrm->frmSensitivity     = ALG_LINK_SCD_SENSITIVITY_MID;
                chPrm->frmEdgeThreshold   = 100;

           i = 0;
           for(y = 0; y < numVertBlks; y++)
           {
             for(x = 0; x < numHorzBlks; x++)
             {
               chPrm->blkConfig[i].sensitivity = ALG_LINK_SCD_SENSITIVITY_MID;
               chPrm->blkConfig[i].monitored     = 0;
               i++;
             }
           }
        }

        ipcBitsOutDspPrm.baseCreateParams.inQueParams.prevLinkId    = gVcapModuleContext.dspAlgId[0];
        ipcBitsOutDspPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
        ipcBitsOutDspPrm.baseCreateParams.numOutQue                 = 1;
        ipcBitsOutDspPrm.baseCreateParams.outQueParams[0].nextLink  = gVcapModuleContext.ipcBitsInHLOSId;
        MultiCh_ipcBitsInitCreateParams_BitsOutRTOS(&ipcBitsOutDspPrm,
                                                   TRUE);
        ipcBitsOutDspPrm.baseCreateParams.notifyNextLink              = TRUE;
        ipcBitsOutDspPrm.baseCreateParams.noNotifyMode                = FALSE;

        ipcBitsInHostPrm[1].baseCreateParams.inQueParams.prevLinkId = ipcBitsOutDSPId;
        ipcBitsInHostPrm[1].baseCreateParams.inQueParams.prevLinkQueId = 0;
        MultiCh_ipcBitsInitCreateParams_BitsInHLOSVcap(&ipcBitsInHostPrm[1]);
        ipcBitsInHostPrm[1].baseCreateParams.notifyPrevLink         = TRUE;
        ipcBitsInHostPrm[1].baseCreateParams.noNotifyMode           = FALSE;

    }
    else
    {
        dspAlgPrm.outQueParams[ALG_LINK_SCD_OUT_QUE].nextLink     = SYSTEM_LINK_ID_INVALID;
    }

#ifndef SYSTEM_USE_VIDEO_DECODER
    capturePrm.isPalMode = Vcap_isPalMode();
#endif
    System_linkCreate (gVcapModuleContext.captureId, &capturePrm, sizeof(capturePrm));
    System_linkCreate(dupId[CAP_DUP_LINK_IDX], &dupPrm[CAP_DUP_LINK_IDX], sizeof(dupPrm[CAP_DUP_LINK_IDX]));
    System_linkCreate(gVcapModuleContext.sclrId[0], &sclrPrm, sizeof(sclrPrm));
    System_linkCreate(gVcapModuleContext.nsfId[0] , &nsfPrm, sizeof(nsfPrm));
    System_linkCreate(gVcapModuleContext.deiId[0], &deiPrm, sizeof(deiPrm));
    System_linkCreate(mergeId[D1_CIF_MERGE_LINK_IDX], &mergePrm[D1_CIF_MERGE_LINK_IDX], sizeof(mergePrm[D1_CIF_MERGE_LINK_IDX]));

    if(enableOsdAlgLink || enableScdAlgLink)
    {
        System_linkCreate(gVcapModuleContext.ipcFramesOutVpssId[0], &ipcFramesOutVpssPrm, sizeof(ipcFramesOutVpssPrm));
        System_linkCreate(gVcapModuleContext.ipcFramesInDspId[0], &ipcFramesInDspPrm, sizeof(ipcFramesInDspPrm));
        System_linkCreate(gVcapModuleContext.dspAlgId[0] , &dspAlgPrm, sizeof(dspAlgPrm));
        if(enableScdAlgLink)
        {
          System_linkCreate(ipcBitsOutDSPId, &ipcBitsOutDspPrm, sizeof(ipcBitsOutDspPrm));
          System_linkCreate(gVcapModuleContext.ipcBitsInHLOSId, &ipcBitsInHostPrm[1], sizeof(ipcBitsInHostPrm[1]));
        }
    }
    System_linkCreate(ipcOutVpssId , &ipcOutVpssPrm , sizeof(ipcOutVpssPrm) );
    System_linkCreate(ipcInVideoId , &ipcInVideoPrm , sizeof(ipcInVideoPrm) );

    System_linkCreate(gVencModuleContext.encId, &encPrm, sizeof(encPrm));

    System_linkCreate(gVencModuleContext.ipcBitsOutRTOSId, &ipcBitsOutVideoPrm, sizeof(ipcBitsOutVideoPrm));
    System_linkCreate(gVencModuleContext.ipcBitsInHLOSId, &ipcBitsInHostPrm[0], sizeof(ipcBitsInHostPrm[0]));

    System_linkGetInfo(gVencModuleContext.ipcBitsInHLOSId,&bitsProducerLinkInfo);
    OSA_assert(bitsProducerLinkInfo.numQue == 1);
    ipcBitsOutHostPrm.baseCreateParams.outQueParams[0].nextLink = gVdecModuleContext.ipcBitsInRTOSId;

    printf ("\n\n========bitsProducerLinkInfo============\n");
    printf ("numQ %d, numCh %d\n",
                    bitsProducerLinkInfo.numQue,
                    bitsProducerLinkInfo.queInfo[0].numCh);
    {
        int i;
        for (i=0; i<bitsProducerLinkInfo.queInfo[0].numCh; i++)
        {
            printf ("Ch [%d] Width %d, Height %d\n",
                i,
                bitsProducerLinkInfo.queInfo[0].chInfo[i].width,
                bitsProducerLinkInfo.queInfo[0].chInfo[i].height
                );
        }
    }
    printf ("\n====================\n\n");

    if (bitsProducerLinkInfo.queInfo[0].numCh > gVencModuleContext.vencConfig.numPrimaryChn)
        bitsProducerLinkInfo.queInfo[0].numCh = gVencModuleContext.vencConfig.numPrimaryChn;

    printf ("Reducing bitsProducerLinkInfo.numCh to %d\n", bitsProducerLinkInfo.queInfo[0].numCh);

    MultiCh_ipcBitsInitCreateParams_BitsOutHLOS(&ipcBitsOutHostPrm,
                                               &bitsProducerLinkInfo.queInfo[0]);
    ipcBitsOutHostPrm.numBufPerCh[0]  = NUM_IPC_OUT_BUFFERS;
    if(gVdecModuleContext.vdecConfig.forceUseDecChannelParams)
    {
        /* use channel info provided by user instead of from encoder */
        UInt32 chId;
        System_LinkChInfo *pChInfo;

        ipcBitsOutHostPrm.inQueInfo.numCh = gVdecModuleContext.vdecConfig.numChn;

        for(chId=0; chId<ipcBitsOutHostPrm.inQueInfo.numCh; chId++)
        {
            pChInfo = &ipcBitsOutHostPrm.inQueInfo.chInfo[chId];

            /* Not Used - Start */
            pChInfo->bufType        = 0;
            pChInfo->codingformat   = 0;
            pChInfo->dataFormat     = 0;
            pChInfo->memType        = 0;
            pChInfo->startX         = 0;
            pChInfo->startY         = 0;
            pChInfo->pitch[0]       = 0;
            pChInfo->pitch[1]       = 0;
            pChInfo->pitch[2]       = 0;
            /* Not Used - End */

            pChInfo->width          = gVdecModuleContext.vdecConfig.decChannelParams[chId].maxVideoWidth;
            pChInfo->height         = gVdecModuleContext.vdecConfig.decChannelParams[chId].maxVideoHeight;
            pChInfo->scanFormat     = SYSTEM_SF_PROGRESSIVE;
        }
    }
    ipcBitsInVideoPrm.baseCreateParams.inQueParams.prevLinkId       = gVdecModuleContext.ipcBitsOutHLOSId;
    ipcBitsInVideoPrm.baseCreateParams.inQueParams.prevLinkQueId    = 0;
    ipcBitsInVideoPrm.baseCreateParams.numOutQue                    = 1;
    ipcBitsInVideoPrm.baseCreateParams.outQueParams[0].nextLink     = gVdecModuleContext.decId;
    MultiCh_ipcBitsInitCreateParams_BitsInRTOS(&ipcBitsInVideoPrm, TRUE);

    for (i=0; i<gVdecModuleContext.vdecConfig.numChn; i++) {
        decPrm.chCreateParams[i].format                 = IVIDEO_H264HP;
        decPrm.chCreateParams[i].profile                = IH264VDEC_PROFILE_ANY;
        decPrm.chCreateParams[i].fieldMergeDecodeEnable = FALSE;
        decPrm.chCreateParams[i].targetMaxWidth         = ipcBitsOutHostPrm.inQueInfo.chInfo[i].width;
        decPrm.chCreateParams[i].targetMaxHeight        = ipcBitsOutHostPrm.inQueInfo.chInfo[i].height;
        decPrm.chCreateParams[i].defaultDynamicParams.targetFrameRate = gVdecModuleContext.vdecConfig.decChannelParams[i].dynamicParam.frameRate;
        decPrm.chCreateParams[i].defaultDynamicParams.targetBitRate   = gVdecModuleContext.vdecConfig.decChannelParams[i].dynamicParam.targetBitRate;
        decPrm.chCreateParams[i].numBufPerCh = NUM_DECODE_BUFFERS;
    }
    decPrm.inQueParams.prevLinkId    = gVdecModuleContext.ipcBitsInRTOSId;
    decPrm.inQueParams.prevLinkQueId = 0;
    decPrm.outQueParams.nextLink  = ipcOutVideoId;
    decPrm.tilerEnable = TILER_ENABLE;

    ipcOutVideoPrm.inQueParams.prevLinkId    = gVdecModuleContext.decId;
    ipcOutVideoPrm.inQueParams.prevLinkQueId = 0;
    ipcOutVideoPrm.numOutQue                 = 1;
    ipcOutVideoPrm.outQueParams[0].nextLink  = ipcInVpssId;
    ipcOutVideoPrm.notifyNextLink            = TRUE;
    ipcOutVideoPrm.notifyPrevLink            = TRUE;
    ipcOutVideoPrm.noNotifyMode              = FALSE;

    ipcInVpssPrm.inQueParams.prevLinkId    = ipcOutVideoId;
    ipcInVpssPrm.inQueParams.prevLinkQueId = 0;
    ipcInVpssPrm.numOutQue                 = 1;
    ipcInVpssPrm.outQueParams[0].nextLink  = mergeId[LIVE_DECODE_MERGE_LINK_IDX];
    ipcInVpssPrm.notifyNextLink            = TRUE;
    ipcInVpssPrm.notifyPrevLink            = TRUE;
    ipcInVpssPrm.noNotifyMode              = FALSE;

    mergePrm[LIVE_DECODE_MERGE_LINK_IDX].numInQue                     = 2;
    mergePrm[LIVE_DECODE_MERGE_LINK_IDX].inQueParams[0].prevLinkId    = gVcapModuleContext.deiId[0];
    mergePrm[LIVE_DECODE_MERGE_LINK_IDX].inQueParams[0].prevLinkQueId = DEI_LINK_OUT_QUE_DEI_SC;
    mergePrm[LIVE_DECODE_MERGE_LINK_IDX].inQueParams[1].prevLinkId    = ipcInVpssId;
    mergePrm[LIVE_DECODE_MERGE_LINK_IDX].inQueParams[1].prevLinkQueId = 0;
    mergePrm[LIVE_DECODE_MERGE_LINK_IDX].outQueParams.nextLink        = dupId[LIVE_DECODE_DUP_LINK_IDX];
    mergePrm[LIVE_DECODE_MERGE_LINK_IDX].notifyNextLink               = TRUE;

    dupPrm[LIVE_DECODE_DUP_LINK_IDX].inQueParams.prevLinkId         = mergeId[LIVE_DECODE_MERGE_LINK_IDX];
    dupPrm[LIVE_DECODE_DUP_LINK_IDX].inQueParams.prevLinkQueId      = 0;
    dupPrm[LIVE_DECODE_DUP_LINK_IDX].numOutQue                      = 2;
    dupPrm[LIVE_DECODE_DUP_LINK_IDX].outQueParams[0].nextLink       = gVdisModuleContext.swMsId[0];
    dupPrm[LIVE_DECODE_DUP_LINK_IDX].outQueParams[1].nextLink       = gVdisModuleContext.swMsId[1];
    dupPrm[LIVE_DECODE_DUP_LINK_IDX].notifyNextLink                 = TRUE;

    for(i=0; i<2; i++)
    {
        swMsPrm[i].inQueParams.prevLinkId    = dupId[LIVE_DECODE_DUP_LINK_IDX];
        swMsPrm[i].inQueParams.prevLinkQueId = i;
        swMsPrm[i].outQueParams.nextLink     = gVdisModuleContext.displayId[i];
        swMsPrm[i].maxInputQueLen            = 4; // KC: changed to 4 to make the display smooth
        swMsPrm[i].maxOutRes                 = VSYS_STD_1080P_60;
        swMsPrm[i].initOutRes                = gVdisModuleContext.vdisConfig.deviceParams[i].resolution;
        swMsPrm[0].numOutBuf                 = 5;
        swMsPrm[1].numOutBuf                 = 8;
        if (i == 1)
		{
            swMsPrm[i].maxOutRes  = VSYS_STD_PAL;
            swMsPrm[i].initOutRes = gVdisModuleContext.vdisConfig.deviceParams[VDIS_DEV_SD].resolution;
		}

#ifdef  SYSTEM_USE_TILER
        swMsPrm[i].lineSkipMode = FALSE;    // Double pitch not possible in tiler mode; so Line skip not possible
#else
        swMsPrm[i].lineSkipMode = TRUE; // Set to TRUE for Enable low cost scaling
#endif
        swMsPrm[i].enableLayoutGridDraw = gVdisModuleContext.vdisConfig.enableLayoutGridDraw;

        MultiCh_swMsGetDefaultLayoutPrm(VDIS_DEV_HDMI, &swMsPrm[0], TRUE);
        MultiCh_swMsGetDefaultLayoutPrm(VDIS_DEV_SD, &swMsPrm[1], TRUE);

        displayPrm[i].inQueParams[0].prevLinkId    = gVdisModuleContext.swMsId[i];
        displayPrm[i].inQueParams[0].prevLinkQueId = 0;
        displayPrm[i].displayRes                = swMsPrm[i].initOutRes;
        if (i == 1)
        {
            displayPrm[i].displayRes            = gVdisModuleContext.vdisConfig.deviceParams[VDIS_DEV_SD].resolution;
            displayPrm[i].forceFieldSeparatedInputMode = TRUE;
        }
    }

    System_linkCreate(gVdecModuleContext.ipcBitsOutHLOSId,&ipcBitsOutHostPrm,sizeof(ipcBitsOutHostPrm));
    System_linkCreate(gVdecModuleContext.ipcBitsInRTOSId,&ipcBitsInVideoPrm,sizeof(ipcBitsInVideoPrm));
    System_linkCreate(gVdecModuleContext.decId, &decPrm, sizeof(decPrm));

    System_linkCreate(ipcOutVideoId, &ipcOutVideoPrm, sizeof(ipcOutVideoPrm));
    System_linkCreate(ipcInVpssId  , &ipcInVpssPrm  , sizeof(ipcInVpssPrm)  );
    System_linkCreate(mergeId[LIVE_DECODE_MERGE_LINK_IDX], &mergePrm[LIVE_DECODE_MERGE_LINK_IDX], sizeof(mergePrm[LIVE_DECODE_MERGE_LINK_IDX]));
    System_linkCreate(dupId[LIVE_DECODE_DUP_LINK_IDX], &dupPrm[LIVE_DECODE_DUP_LINK_IDX], sizeof(dupPrm[LIVE_DECODE_DUP_LINK_IDX]));

    for(i=0; i<2; i++)
        System_linkCreate(gVdisModuleContext.swMsId[i]  , &swMsPrm[i], sizeof(swMsPrm[i]));

    for(i=0; i<2; i++)  /* Both tied VENCs HDMI and DVO2 are handled by single link instance */
        System_linkCreate(gVdisModuleContext.displayId[i], &displayPrm[i], sizeof(displayPrm[i]));

    {
        MergeLink_InLinkChInfo inChInfo;

        MergeLink_InLinkChInfo_Init(&inChInfo);
        inChInfo.inLinkID = ipcInVpssId;
        System_linkControl(mergeId[LIVE_DECODE_MERGE_LINK_IDX],
                           MERGE_LINK_CMD_GET_INPUT_LINK_CHINFO,
                           &inChInfo,
                           sizeof(inChInfo),
                           TRUE);
        OSA_assert(inChInfo.numCh == gVdecModuleContext.vdecConfig.numChn);
        MultiCh_setDec2DispMap(VDIS_DEV_HDMI,gVdecModuleContext.vdecConfig.numChn,0,inChInfo.startChNum);
        MultiCh_setDec2DispMap(VDIS_DEV_SD,gVdecModuleContext.vdecConfig.numChn,0,inChInfo.startChNum);
   }

}
Exemple #3
0
Void MultiCh_createVcapVdis()
{
    CaptureLink_CreateParams    capturePrm;
    NsfLink_CreateParams        nsfPrm;
    DeiLink_CreateParams        deiPrm[2];
    NullSrcLink_CreateParams    nullSrcPrm;
    MergeLink_CreateParams      mergePrm;
    DupLink_CreateParams        dupPrm;
    static SwMsLink_CreateParams       swMsPrm[VDIS_DEV_MAX];
    DisplayLink_CreateParams    displayPrm[VDIS_DEV_MAX];

    CaptureLink_VipInstParams *pCaptureInstPrm;
    CaptureLink_OutParams     *pCaptureOutPrm;

    VCAP_VIDDEC_PARAMS_S vidDecVideoModeArgs[NUM_CAPTURE_DEVICES];

    UInt32 grpxId[VDIS_DEV_MAX];
    UInt32 nullId;
    UInt32 mergeId, dupId;
    UInt32 deiOutQue;

    UInt32 vipInstId;
    UInt32 i;
    UInt32 numSubChains;
    Bool enableSdtv;

    for (i = 0; i < VDIS_DEV_MAX; i++)
    {
        MULTICH_INIT_STRUCT(DisplayLink_CreateParams,displayPrm[i]);
        MULTICH_INIT_STRUCT(SwMsLink_CreateParams ,swMsPrm[i]);
    }

    MultiCh_detectBoard();

    System_linkControl(
        SYSTEM_LINK_ID_M3VPSS,
        SYSTEM_M3VPSS_CMD_RESET_VIDEO_DEVICES,
        NULL,
        0,
        TRUE
        );

    gVcapModuleContext.captureId    = SYSTEM_LINK_ID_CAPTURE;
    gVcapModuleContext.nsfId[0]     = SYSTEM_LINK_ID_NSF_0;
    gVcapModuleContext.deiId[0]     = SYSTEM_LINK_ID_DEI_HQ_0;
    gVcapModuleContext.deiId[1]     = SYSTEM_LINK_ID_DEI_0;
    gVcapModuleContext.nullSrcId    = SYSTEM_VPSS_LINK_ID_NULL_SRC_0;
    mergeId                         = SYSTEM_VPSS_LINK_ID_MERGE_0;
    dupId                           = SYSTEM_VPSS_LINK_ID_DUP_0;

    gVdisModuleContext.swMsId[0]      = SYSTEM_LINK_ID_SW_MS_MULTI_INST_0;
    gVdisModuleContext.swMsId[1]      = SYSTEM_LINK_ID_SW_MS_MULTI_INST_1;

    swMsPrm[0].numSwMsInst   = 1;
    swMsPrm[1].numSwMsInst   = 1;
    swMsPrm[0].swMsInstId[0] = SYSTEM_SW_MS_SC_INST_SC5;
    swMsPrm[1].swMsInstId[0] = SYSTEM_SW_MS_SC_INST_SC5;

    gVdisModuleContext.displayId[0] = SYSTEM_LINK_ID_DISPLAY_0; // ON CHIP HDMI
    gVdisModuleContext.displayId[1] = SYSTEM_LINK_ID_DISPLAY_1; // OFF CHIP HDMI
    gVdisModuleContext.displayId[2] = SYSTEM_LINK_ID_DISPLAY_2; // OFF CHIP HDMI
    grpxId[0]                       = SYSTEM_LINK_ID_GRPX_0;
    grpxId[1]                       = SYSTEM_LINK_ID_GRPX_1;
#if 0    /* Enabling graphics only for ON CHIP HDMI an OFF CHIP HDMI*/
    grpxId[2]                       = SYSTEM_LINK_ID_GRPX_2;
#endif
    nullId                          = SYSTEM_VPSS_LINK_ID_NULL_0;

    numSubChains             = 2;
    deiOutQue                = DEI_LINK_OUT_QUE_VIP_SC;
    enableSdtv               = FALSE;

    CaptureLink_CreateParams_Init(&capturePrm);

    capturePrm.numVipInst    = 2 * numSubChains;
    capturePrm.outQueParams[0].nextLink = gVcapModuleContext.nsfId[0];

    capturePrm.tilerEnable              = FALSE;
    capturePrm.enableSdCrop             = FALSE;

    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     = SYSTEM_DEVICE_VID_DEC_TVP5158_DRV;
        pCaptureInstPrm->inDataFormat       = SYSTEM_DF_YUV422P;
        pCaptureInstPrm->standard           = SYSTEM_STD_MUX_4CH_D1;
        pCaptureInstPrm->numOutput          = 1;

        pCaptureOutPrm                      = &pCaptureInstPrm->outParams[0];
        pCaptureOutPrm->dataFormat          = SYSTEM_DF_YUV422I_YUYV;
        pCaptureOutPrm->scEnable            = FALSE;
        pCaptureOutPrm->scOutWidth          = 0;
        pCaptureOutPrm->scOutHeight         = 0;
        pCaptureOutPrm->outQueId            = 0;
    }

    for(i = 0; i < NUM_CAPTURE_DEVICES; i++)
    {
        vidDecVideoModeArgs[i].videoIfMode        = DEVICE_CAPT_VIDEO_IF_MODE_8BIT;
        vidDecVideoModeArgs[i].videoDataFormat    = SYSTEM_DF_YUV422P;
        vidDecVideoModeArgs[i].standard           = SYSTEM_STD_MUX_4CH_D1;
        vidDecVideoModeArgs[i].videoCaptureMode   =
                    DEVICE_CAPT_VIDEO_CAPTURE_MODE_MULTI_CH_PIXEL_MUX_EMBEDDED_SYNC;
        vidDecVideoModeArgs[i].videoSystem        =
                                      DEVICE_VIDEO_DECODER_VIDEO_SYSTEM_AUTO_DETECT;
        vidDecVideoModeArgs[i].videoCropEnable    = FALSE;
        vidDecVideoModeArgs[i].videoAutoDetectTimeout = -1;
    }

    Vcap_configVideoDecoder(vidDecVideoModeArgs, NUM_CAPTURE_DEVICES);

    NsfLink_CreateParams_Init(&nsfPrm);
    nsfPrm.bypassNsf                 = FALSE;
    nsfPrm.tilerEnable               = FALSE;
    nsfPrm.inQueParams.prevLinkId    = gVcapModuleContext.captureId;
    nsfPrm.inQueParams.prevLinkQueId = 0;
    nsfPrm.numOutQue                 = numSubChains;
    nsfPrm.outQueParams[0].nextLink  = gVcapModuleContext.deiId[0];
    nsfPrm.outQueParams[1].nextLink  = gVcapModuleContext.deiId[1];

    nullSrcPrm.outQueParams.nextLink      = mergeId;
    nullSrcPrm.timerPeriod                = 33;
    nullSrcPrm.inputInfo.numCh            = 16;
    for(i=0; i<nullSrcPrm.inputInfo.numCh; i++)
    {
        System_LinkChInfo *pChInfo;

        pChInfo = &nullSrcPrm.inputInfo.chInfo[i];

        pChInfo->dataFormat = SYSTEM_DF_YUV420SP_UV;
        pChInfo->memType    = SYSTEM_MT_NONTILEDMEM;
        pChInfo->startX     = 48;
        pChInfo->startY     = 32;
        pChInfo->width      = 720;
        pChInfo->height     = 576;
        pChInfo->pitch[0]   = SystemUtils_align(pChInfo->width+pChInfo->startX, SYSTEM_BUFFER_ALIGNMENT);
        pChInfo->pitch[1]   = pChInfo->pitch[0];
        pChInfo->pitch[2]   = 0;
        pChInfo->scanFormat = SYSTEM_SF_PROGRESSIVE;
    }

    for(i=0; i<numSubChains; i++)
    {
        Int32 chId;

        DeiLink_CreateParams_Init(&deiPrm[i]);

        deiPrm[i].inQueParams.prevLinkId                        = gVcapModuleContext.nsfId[0];
        deiPrm[i].inQueParams.prevLinkQueId                     = i;
        deiPrm[i].outQueParams[deiOutQue].nextLink              = mergeId;
        deiPrm[i].outQueParams[deiOutQue^1].nextLink            = nullId;
        deiPrm[i].enableOut[deiOutQue]                          = TRUE;
        deiPrm[i].enableOut[deiOutQue^1]                        = FALSE;
        deiPrm[i].tilerEnable[DEI_LINK_OUT_QUE_VIP_SC]          = FALSE;

        deiPrm[i].comprEnable                                   = FALSE;
        deiPrm[i].setVipScYuv422Format                          = FALSE;

        /* DEI Path Scalar ratio is 1:2, D1 => CIF */
        deiPrm[i].outScaleFactor[DEI_LINK_OUT_QUE_DEI_SC][0].scaleMode = DEI_SCALE_MODE_RATIO;
        deiPrm[i].outScaleFactor[DEI_LINK_OUT_QUE_DEI_SC][0].ratio.widthRatio.numerator    = 1;
        deiPrm[i].outScaleFactor[DEI_LINK_OUT_QUE_DEI_SC][0].ratio.widthRatio.denominator  = 2;
        deiPrm[i].outScaleFactor[DEI_LINK_OUT_QUE_DEI_SC][0].ratio.heightRatio.numerator   = 1;
        deiPrm[i].outScaleFactor[DEI_LINK_OUT_QUE_DEI_SC][0].ratio.heightRatio.denominator         = 2;
        for (chId=1; chId < DEI_LINK_MAX_CH; chId++)
            deiPrm[i].outScaleFactor[DEI_LINK_OUT_QUE_DEI_SC][chId] = deiPrm[i].outScaleFactor[DEI_LINK_OUT_QUE_DEI_SC][0];

        /* VIP Scalar ratio is 1:1 */
        deiPrm[i].outScaleFactor[DEI_LINK_OUT_QUE_VIP_SC][0].scaleMode = DEI_SCALE_MODE_RATIO;
        deiPrm[i].outScaleFactor[DEI_LINK_OUT_QUE_VIP_SC][0].ratio.widthRatio.numerator    = 1;
        deiPrm[i].outScaleFactor[DEI_LINK_OUT_QUE_VIP_SC][0].ratio.widthRatio.denominator  = 1;
        deiPrm[i].outScaleFactor[DEI_LINK_OUT_QUE_VIP_SC][0].ratio.heightRatio.numerator   = 1;
        deiPrm[i].outScaleFactor[DEI_LINK_OUT_QUE_VIP_SC][0].ratio.heightRatio.denominator     = 1;
        for (chId=1; chId < DEI_LINK_MAX_CH; chId++)
            deiPrm[i].outScaleFactor[DEI_LINK_OUT_QUE_VIP_SC][chId] = deiPrm[i].outScaleFactor[DEI_LINK_OUT_QUE_VIP_SC][0];

        mergePrm.numInQue                     = numSubChains;
        mergePrm.inQueParams[i].prevLinkId    = gVcapModuleContext.deiId[i];
        mergePrm.inQueParams[i].prevLinkQueId = deiOutQue;
        mergePrm.outQueParams.nextLink        = dupId;
        mergePrm.notifyNextLink               = TRUE;

        dupPrm.inQueParams.prevLinkId         = mergeId;
        dupPrm.inQueParams.prevLinkQueId      = 0;
        dupPrm.numOutQue                      = numSubChains;
        dupPrm.outQueParams[i].nextLink       = gVdisModuleContext.swMsId[i];
        dupPrm.notifyNextLink                 = TRUE;
    }

    mergePrm.numInQue                     = 3;
    mergePrm.inQueParams[i].prevLinkId    = gVcapModuleContext.nullSrcId;
    mergePrm.inQueParams[i].prevLinkQueId = 0;

    for(i=0; i<numSubChains; i++)
    {
        swMsPrm[i].inQueParams.prevLinkId    = dupId;
        swMsPrm[i].inQueParams.prevLinkQueId = i;
        swMsPrm[i].outQueParams.nextLink     = gVdisModuleContext.displayId[i];
        swMsPrm[i].maxInputQueLen            = SYSTEM_SW_MS_DEFAULT_INPUT_QUE_LEN;
        swMsPrm[i].maxOutRes                 = VSYS_STD_1080P_60;
        swMsPrm[i].initOutRes                = gVdisModuleContext.vdisConfig.deviceParams[i].resolution;
        swMsPrm[i].lineSkipMode = TRUE;

        swMsPrm[i].enableLayoutGridDraw = gVdisModuleContext.vdisConfig.enableLayoutGridDraw;

        MultiCh_swMsGetDefaultLayoutPrm(0, &swMsPrm[i], FALSE); /* Since only live preview is there, show it on both displays */

        displayPrm[i].inQueParams[0].prevLinkId    = gVdisModuleContext.swMsId[i];
        displayPrm[i].inQueParams[0].prevLinkQueId = 0;
        displayPrm[i].displayRes                = swMsPrm[i].initOutRes;
    }

    if(enableSdtv)
    {
        dupPrm.numOutQue                      = 3;
        dupPrm.outQueParams[2].nextLink       = gVdisModuleContext.displayId[2];
    }

    displayPrm[2].numInputQueues = 1;
    displayPrm[2].activeQueue    = 0;
    displayPrm[2].inQueParams[0].prevLinkId    = dupId;
    displayPrm[2].inQueParams[0].prevLinkQueId = 2;
    displayPrm[2].displayRes = gVdisModuleContext.vdisConfig.deviceParams[VDIS_DEV_SD].resolution;


#ifndef SYSTEM_USE_VIDEO_DECODER
    capturePrm.isPalMode = Vcap_isPalMode();
#endif

    System_linkCreate (gVcapModuleContext.captureId, &capturePrm, sizeof(capturePrm));
    System_linkCreate(gVcapModuleContext.nsfId[0] , &nsfPrm, sizeof(nsfPrm));

    for(i=0; i<numSubChains; i++)
        System_linkCreate(gVcapModuleContext.deiId[i]  , &deiPrm[i], sizeof(deiPrm[i]));

    System_linkCreate(gVcapModuleContext.nullSrcId , &nullSrcPrm, sizeof(nullSrcPrm));
    System_linkCreate(mergeId   , &mergePrm  , sizeof(mergePrm));
    System_linkCreate(dupId     , &dupPrm    , sizeof(dupPrm));

    for(i=0; i<numSubChains; i++)
        System_linkCreate(gVdisModuleContext.swMsId[i]  , &swMsPrm[i], sizeof(swMsPrm[i]));

    for(i=0; i<numSubChains; i++)
        System_linkCreate(gVdisModuleContext.displayId[i], &displayPrm[i], sizeof(displayPrm[i]));

    if(enableSdtv)
    {
        System_linkCreate(gVdisModuleContext.displayId[2], &displayPrm[2], sizeof(displayPrm[2]));
    }

    MultiCh_memPrintHeapStatus();

}
Exemple #4
0
Int32 Vdec_create(System_LinkInQueParams *vdecOutQue, UInt32 vdecNextLinkId, Bool tilerEnable, UInt32 numFramesPerCh)
{
    IpcBitsOutLinkHLOS_CreateParams   ipcBitsOutHostPrm;
    IpcBitsInLinkRTOS_CreateParams    ipcBitsInVideoPrm;
    DecLink_CreateParams              decPrm;
    IpcLink_CreateParams              ipcOutVideoPrm;
    IpcLink_CreateParams              ipcInVpssPrm;

    Int32 i;

    MULTICH_INIT_STRUCT(IpcLink_CreateParams,ipcInVpssPrm);
    MULTICH_INIT_STRUCT(IpcLink_CreateParams,ipcOutVideoPrm);
    MULTICH_INIT_STRUCT(IpcBitsOutLinkHLOS_CreateParams,ipcBitsOutHostPrm);
    MULTICH_INIT_STRUCT(IpcBitsInLinkRTOS_CreateParams,ipcBitsInVideoPrm);
    MULTICH_INIT_STRUCT(DecLink_CreateParams, decPrm);

    gVdecModuleContext.ipcBitsOutHLOSId = SYSTEM_HOST_LINK_ID_IPC_BITS_OUT_0;
    gVdecModuleContext.ipcBitsInRTOSId  = SYSTEM_VIDEO_LINK_ID_IPC_BITS_IN_0;
    gVdecModuleContext.decId            = SYSTEM_LINK_ID_VDEC_0;
    gVdecModuleContext.ipcM3OutId       = SYSTEM_VIDEO_LINK_ID_IPC_OUT_M3_0;
    gVdecModuleContext.ipcM3InId        = SYSTEM_VPSS_LINK_ID_IPC_IN_M3_0;

    ipcBitsOutHostPrm.baseCreateParams.outQueParams[0].nextLink = gVdecModuleContext.ipcBitsInRTOSId;
    ipcBitsOutHostPrm.baseCreateParams.notifyNextLink       = TRUE;
    ipcBitsOutHostPrm.baseCreateParams.notifyPrevLink       = FALSE;
    ipcBitsOutHostPrm.baseCreateParams.noNotifyMode         = FALSE;
    ipcBitsOutHostPrm.baseCreateParams.numOutQue            = 1;
    ipcBitsOutHostPrm.inQueInfo.numCh                       = gVdecModuleContext.vdecConfig.numChn;

    for (i=0; i<ipcBitsOutHostPrm.inQueInfo.numCh; i++)
    {
        ipcBitsOutHostPrm.inQueInfo.chInfo[i].width =
            gVdecModuleContext.vdecConfig.decChannelParams[i].maxVideoWidth;

        ipcBitsOutHostPrm.inQueInfo.chInfo[i].height =
            gVdecModuleContext.vdecConfig.decChannelParams[i].maxVideoHeight;

        ipcBitsOutHostPrm.inQueInfo.chInfo[i].scanFormat =
            SYSTEM_SF_PROGRESSIVE;

        ipcBitsOutHostPrm.inQueInfo.chInfo[i].bufType        = 0; // NOT USED
        ipcBitsOutHostPrm.inQueInfo.chInfo[i].codingformat   = 0; // NOT USED
        ipcBitsOutHostPrm.inQueInfo.chInfo[i].dataFormat     = 0; // NOT USED
        ipcBitsOutHostPrm.inQueInfo.chInfo[i].memType        = 0; // NOT USED
        ipcBitsOutHostPrm.inQueInfo.chInfo[i].startX         = 0; // NOT USED
        ipcBitsOutHostPrm.inQueInfo.chInfo[i].startY         = 0; // NOT USED
        ipcBitsOutHostPrm.inQueInfo.chInfo[i].pitch[0]       = 0; // NOT USED
        ipcBitsOutHostPrm.inQueInfo.chInfo[i].pitch[1]       = 0; // NOT USED
        ipcBitsOutHostPrm.inQueInfo.chInfo[i].pitch[2]       = 0; // NOT USED
    }

    ipcBitsInVideoPrm.baseCreateParams.inQueParams.prevLinkId    = gVdecModuleContext.ipcBitsOutHLOSId;
    ipcBitsInVideoPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
    ipcBitsInVideoPrm.baseCreateParams.outQueParams[0].nextLink  = gVdecModuleContext.decId;
    ipcBitsInVideoPrm.baseCreateParams.noNotifyMode              = FALSE;
    ipcBitsInVideoPrm.baseCreateParams.notifyNextLink            = TRUE;
    ipcBitsInVideoPrm.baseCreateParams.notifyPrevLink            = FALSE;
    ipcBitsInVideoPrm.baseCreateParams.numOutQue                 = 1;

    decPrm.numBufPerPool[0] = numFramesPerCh;
    for (i=0; i<ipcBitsOutHostPrm.inQueInfo.numCh; i++)
    {
        decPrm.chCreateParams[i].format                 = IVIDEO_H264HP;
        decPrm.chCreateParams[i].profile                = IH264VDEC_PROFILE_ANY;
        decPrm.chCreateParams[i].fieldMergeDecodeEnable = FALSE;

        decPrm.chCreateParams[i].targetMaxWidth  =
            ipcBitsOutHostPrm.inQueInfo.chInfo[i].width;

        decPrm.chCreateParams[i].targetMaxHeight =
            ipcBitsOutHostPrm.inQueInfo.chInfo[i].height;

        decPrm.chCreateParams[i].defaultDynamicParams.targetFrameRate =
            gVdecModuleContext.vdecConfig.decChannelParams[i].dynamicParam.frameRate;

        decPrm.chCreateParams[i].defaultDynamicParams.targetBitRate =
            gVdecModuleContext.vdecConfig.decChannelParams[i].dynamicParam.targetBitRate;
    }

    decPrm.inQueParams.prevLinkId       = gVdecModuleContext.ipcBitsInRTOSId;
    decPrm.inQueParams.prevLinkQueId    = 0;
    decPrm.outQueParams.nextLink        = gVdecModuleContext.ipcM3OutId;
    decPrm.tilerEnable                  = tilerEnable;

    ipcOutVideoPrm.inQueParams.prevLinkId    = gVdecModuleContext.decId;
    ipcOutVideoPrm.inQueParams.prevLinkQueId = 0;
    ipcOutVideoPrm.outQueParams[0].nextLink  = gVdecModuleContext.ipcM3InId;
    ipcOutVideoPrm.notifyNextLink            = TRUE;
    ipcOutVideoPrm.notifyPrevLink            = TRUE;
    ipcOutVideoPrm.numOutQue                 = 1;

    ipcInVpssPrm.inQueParams.prevLinkId    = gVdecModuleContext.ipcM3OutId;
    ipcInVpssPrm.inQueParams.prevLinkQueId = 0;
    ipcInVpssPrm.outQueParams[0].nextLink  = vdecNextLinkId;
    ipcInVpssPrm.notifyNextLink            = TRUE;
    ipcInVpssPrm.notifyPrevLink            = TRUE;
    ipcInVpssPrm.numOutQue                 = 1;

    vdecOutQue->prevLinkId = gVdecModuleContext.ipcM3InId;
    vdecOutQue->prevLinkQueId = 0;

    System_linkCreate(gVdecModuleContext.ipcBitsOutHLOSId, &ipcBitsOutHostPrm, sizeof(ipcBitsOutHostPrm));
    System_linkCreate(gVdecModuleContext.ipcBitsInRTOSId , &ipcBitsInVideoPrm, sizeof(ipcBitsInVideoPrm));
    System_linkCreate(gVdecModuleContext.decId           , &decPrm           , sizeof(decPrm)           );
    System_linkCreate(gVdecModuleContext.ipcM3OutId      , &ipcOutVideoPrm   , sizeof(ipcOutVideoPrm)   );
    System_linkCreate(gVdecModuleContext.ipcM3InId       , &ipcInVpssPrm     , sizeof(ipcInVpssPrm)     );

    return 0;
}
Void Chains_singleChDucatiSystem(Chains_Ctrl *chainsCfg)
{
    CaptureLink_CreateParams    capturePrm;
    CaptureLink_VipInstParams   *pCaptureInstPrm;
    CaptureLink_OutParams       *pCaptureOutPrm;
    NsfLink_CreateParams        nsfPrm;
    SwMsLink_CreateParams       swMsPrm;
    DisplayLink_CreateParams    displayPrm;
    EncLink_CreateParams        encPrm;
    DecLink_CreateParams        decPrm;
    IpcLink_CreateParams        ipcOutVpssPrm;
    IpcLink_CreateParams        ipcInVpssPrm;
    IpcLink_CreateParams        ipcOutVideoPrm;
    IpcLink_CreateParams        ipcInVideoPrm;
    IpcBitsOutLinkHLOS_CreateParams   ipcBitsOutHostPrm;
    IpcBitsOutLinkRTOS_CreateParams   ipcBitsOutVideoPrm;
    IpcBitsInLinkHLOS_CreateParams    ipcBitsInHostPrm;
    IpcBitsInLinkRTOS_CreateParams    ipcBitsInVideoPrm;

    System_LinkInfo bitsProducerLinkInfo;

    UInt32 captureId, displayId;
    UInt32 nsfId, swMsId;
    UInt32 vipInstId;
    UInt32 encId, decId;
    UInt32 ipcOutVpssId, ipcInVpssId;
    UInt32 ipcOutVideoId, ipcInVideoId;
    UInt32 ipcBitsOutVideoId, ipcBitsInHostId;
    UInt32 ipcBitsInVideoId, ipcBitsOutHostId;

    UInt32 i;
    char   ch;

    Chains_ipcBitsInit();

    CHAINS_INIT_STRUCT(CaptureLink_CreateParams, capturePrm);
    CHAINS_INIT_STRUCT(NsfLink_CreateParams, nsfPrm);
    CHAINS_INIT_STRUCT(SwMsLink_CreateParams, swMsPrm);
    CHAINS_INIT_STRUCT(DisplayLink_CreateParams,displayPrm);
    CHAINS_INIT_STRUCT(IpcLink_CreateParams,ipcOutVpssPrm);
    CHAINS_INIT_STRUCT(IpcLink_CreateParams,ipcInVpssPrm);
    CHAINS_INIT_STRUCT(IpcLink_CreateParams,ipcOutVideoPrm);
    CHAINS_INIT_STRUCT(IpcLink_CreateParams,ipcInVideoPrm);
    CHAINS_INIT_STRUCT(IpcBitsOutLinkRTOS_CreateParams,ipcBitsOutVideoPrm);
    CHAINS_INIT_STRUCT(IpcBitsInLinkHLOS_CreateParams,ipcBitsInHostPrm);
    CHAINS_INIT_STRUCT(IpcBitsOutLinkHLOS_CreateParams,ipcBitsOutHostPrm);
    CHAINS_INIT_STRUCT(IpcBitsInLinkRTOS_CreateParams,ipcBitsInVideoPrm);
    CHAINS_INIT_STRUCT(EncLink_CreateParams, encPrm);
    CHAINS_INIT_STRUCT(DecLink_CreateParams, decPrm);

    captureId = SYSTEM_LINK_ID_CAPTURE;
    nsfId     = SYSTEM_LINK_ID_NSF_0;
    swMsId    = SYSTEM_LINK_ID_SW_MS_MULTI_INST_0;
    displayId = SYSTEM_LINK_ID_DISPLAY_1;

    encId        = SYSTEM_LINK_ID_VENC_0;
    decId        = SYSTEM_LINK_ID_VDEC_0;

    ipcOutVpssId = SYSTEM_VPSS_LINK_ID_IPC_OUT_M3_0;
    ipcInVideoId = SYSTEM_VIDEO_LINK_ID_IPC_IN_M3_0;
    ipcOutVideoId= SYSTEM_VIDEO_LINK_ID_IPC_OUT_M3_0;
    ipcInVpssId  = SYSTEM_VPSS_LINK_ID_IPC_IN_M3_0;

    ipcBitsOutVideoId = SYSTEM_VIDEO_LINK_ID_IPC_BITS_OUT_0;
    ipcBitsInHostId   = SYSTEM_HOST_LINK_ID_IPC_BITS_IN_0;
    ipcBitsOutHostId  = SYSTEM_HOST_LINK_ID_IPC_BITS_OUT_0;
    ipcBitsInVideoId  = SYSTEM_VIDEO_LINK_ID_IPC_BITS_IN_0;

    System_linkControl(
        SYSTEM_LINK_ID_M3VIDEO,
        SYSTEM_COMMON_CMD_SET_CH2IVAHD_MAP_TBL,
        &systemVid_encDecIvaChMapTbl,
        sizeof(SystemVideo_Ivahd2ChMap_Tbl),
        TRUE
    );

    capturePrm.numVipInst               = 1;
    capturePrm.tilerEnable              = FALSE;
    capturePrm.numBufsPerCh             = CAPTURE_LINK_NUM_BUFS_PER_CH_DEFAULT;
    capturePrm.numExtraBufs             = 8;
    capturePrm.maxBlindAreasPerCh       = 0;
    capturePrm.isPalMode                = FALSE;
    capturePrm.enableSdCrop             = FALSE;
    capturePrm.doCropInCapture          = FALSE;

    for(vipInstId=0; vipInstId<capturePrm.numVipInst; vipInstId++)
    {
        pCaptureInstPrm                     = &capturePrm.vipInst[vipInstId];
        pCaptureInstPrm->vipInstId          = (SYSTEM_CAPTURE_INST_VIP0_PORTA+vipInstId*2)%SYSTEM_CAPTURE_INST_MAX;
        pCaptureInstPrm->videoDecoderId     = SYSTEM_DEVICE_VID_DEC_SII9233A_DRV;
        pCaptureInstPrm->inDataFormat       = SYSTEM_DF_YUV422P;
        pCaptureInstPrm->standard           = chainsCfg->displayRes[0];
        pCaptureInstPrm->numOutput          = 1;
        pCaptureInstPrm->numChPerOutput     = 1;
        pCaptureInstPrm->frameCaptureMode   = FALSE;
        pCaptureInstPrm->fieldsMerged       = FALSE;
        if (Chains_IsInterlaced(chainsCfg->displayRes[0])) {
            pCaptureInstPrm->frameCaptureMode = TRUE;
            pCaptureInstPrm->fieldsMerged   = TRUE;
        }

        pCaptureOutPrm                      = &pCaptureInstPrm->outParams[0];
        pCaptureOutPrm->dataFormat          = SYSTEM_DF_YUV422I_YUYV;
        pCaptureOutPrm->scEnable            = FALSE;
        pCaptureOutPrm->scOutWidth          = chainsCfg->channelConf[0].width;
        pCaptureOutPrm->scOutHeight         = chainsCfg->channelConf[0].height;
        pCaptureOutPrm->outQueId            = 0;
    }
    capturePrm.outQueParams[0].nextLink = nsfId;

    System_linkCreate(captureId, &capturePrm, sizeof(capturePrm));
    chainsCfg->displayRes[0] = capturePrm.vipInst[0].standard;
    Vsys_getResSize(chainsCfg->displayRes[0], &chainsCfg->channelConf[0].width, &chainsCfg->channelConf[0].height);
    Vsys_getResRate(chainsCfg->displayRes[0], &chainsCfg->channelConf[0].frameRate);

    nsfPrm.inQueParams.prevLinkId    = captureId;
    nsfPrm.inQueParams.prevLinkQueId = 0;
    nsfPrm.bypassNsf                 = FALSE;
    nsfPrm.tilerEnable               = TRUE;
    nsfPrm.numOutQue                 = 1;
    nsfPrm.outQueParams[0].nextLink  = ipcOutVpssId;
    nsfPrm.inputFrameRate            = chainsCfg->channelConf[0].frameRate;
    nsfPrm.outputFrameRate           = chainsCfg->channelConf[0].frameRate;
    nsfPrm.numBufsPerCh              = 8;

    ipcOutVpssPrm.inQueParams.prevLinkId    = nsfId;
    ipcOutVpssPrm.inQueParams.prevLinkQueId = 0;
    ipcOutVpssPrm.numOutQue                 = 1;
    ipcOutVpssPrm.numChPerOutQue[0]         = 1;
    ipcOutVpssPrm.outQueParams[0].nextLink  = ipcInVideoId;
    ipcOutVpssPrm.notifyNextLink            = TRUE;
    ipcOutVpssPrm.notifyPrevLink            = FALSE;
    ipcOutVpssPrm.noNotifyMode              = FALSE;
    ipcOutVpssPrm.inputFrameRate            = chainsCfg->channelConf[0].frameRate;
    ipcOutVpssPrm.outputFrameRate           = chainsCfg->channelConf[0].frameRate;
    ipcOutVpssPrm.equallyDivideChAcrossOutQues = FALSE;
    ipcOutVpssPrm.numChPerOutQue[0]         = 0;

    ipcInVideoPrm.inQueParams.prevLinkId    = ipcOutVpssId;
    ipcInVideoPrm.inQueParams.prevLinkQueId = 0;
    ipcInVideoPrm.numOutQue                 = 1;
    ipcInVideoPrm.numChPerOutQue[0]         = 1;
    ipcInVideoPrm.outQueParams[0].nextLink  = encId;
    ipcInVideoPrm.notifyNextLink            = TRUE;
    ipcInVideoPrm.notifyPrevLink            = FALSE;
    ipcInVideoPrm.noNotifyMode              = FALSE;
    ipcInVideoPrm.inputFrameRate            = chainsCfg->channelConf[0].frameRate;
    ipcInVideoPrm.outputFrameRate           = chainsCfg->channelConf[0].frameRate;
    ipcInVideoPrm.equallyDivideChAcrossOutQues = FALSE;
    ipcInVideoPrm.numChPerOutQue[0]         = 0;

    for (i=0; i<1; i++) {
        encPrm.chCreateParams[i].format                             = chainsCfg->channelConf[i].encFormat;
        encPrm.chCreateParams[i].profile                            = chainsCfg->channelConf[i].encProfile;
        encPrm.chCreateParams[i].dataLayout                         = IVIDEO_FIELD_SEPARATED;
        encPrm.chCreateParams[i].fieldMergeEncodeEnable             = FALSE;
        encPrm.chCreateParams[i].enableAnalyticinfo                 = FALSE;
        encPrm.chCreateParams[i].enableWaterMarking                 = FALSE;
        encPrm.chCreateParams[i].maxBitRate                         = -1;
        encPrm.chCreateParams[i].encodingPreset                     = XDM_USER_DEFINED;
                                                                      //XDM_DEFAULT;
        encPrm.chCreateParams[i].rateControlPreset                  = IVIDEO_USER_DEFINED;
                                                                      //IVIDEO_STORAGE;
                                                                      //IVIDEO_LOW_DELAY;
        encPrm.chCreateParams[i].enableHighSpeed                    = FALSE;
        encPrm.chCreateParams[i].numTemporalLayer                   = 0;
        encPrm.chCreateParams[i].enableSVCExtensionFlag             = FALSE;

        encPrm.chCreateParams[i].defaultDynamicParams.intraFrameInterval = chainsCfg->channelConf[i].intraFrameInterval;
        encPrm.chCreateParams[i].defaultDynamicParams.interFrameInterval = 1;
        encPrm.chCreateParams[i].defaultDynamicParams.inputFrameRate     = chainsCfg->channelConf[i].frameRate;
        encPrm.chCreateParams[i].defaultDynamicParams.targetFrameRate    = chainsCfg->channelConf[i].encFrameRate;
        encPrm.chCreateParams[i].defaultDynamicParams.targetBitRate      = chainsCfg->channelConf[i].bitRate;
        encPrm.chCreateParams[i].defaultDynamicParams.mvAccuracy         = IVIDENC2_MOTIONVECTOR_QUARTERPEL;
        encPrm.chCreateParams[i].defaultDynamicParams.rcAlg              = chainsCfg->channelConf[i].rateCtrl;
        encPrm.chCreateParams[i].defaultDynamicParams.qpMin              = 0;
        encPrm.chCreateParams[i].defaultDynamicParams.qpMax              = 51;
        encPrm.chCreateParams[i].defaultDynamicParams.qpInit             = -1;
        encPrm.chCreateParams[i].defaultDynamicParams.vbrDuration        = 8;
        encPrm.chCreateParams[i].defaultDynamicParams.vbrSensitivity     = 0;
    }
    encPrm.inQueParams.prevLinkId   = ipcInVideoId;
    encPrm.inQueParams.prevLinkQueId= 0;
    encPrm.outQueParams.nextLink    = ipcBitsOutVideoId;
    encPrm.numBufPerCh[0]           = 8;

    ipcBitsOutVideoPrm.baseCreateParams.inQueParams.prevLinkId      = encId;
    ipcBitsOutVideoPrm.baseCreateParams.inQueParams.prevLinkQueId   = 0;
    ipcBitsOutVideoPrm.baseCreateParams.numOutQue                   = 1;
    ipcBitsOutVideoPrm.baseCreateParams.numChPerOutQue[0]           = 1;
    ipcBitsOutVideoPrm.baseCreateParams.outQueParams[0].nextLink    = ipcBitsInHostId;
    ipcBitsOutVideoPrm.baseCreateParams.inputFrameRate              = chainsCfg->channelConf[0].encFrameRate;
    ipcBitsOutVideoPrm.baseCreateParams.outputFrameRate             = chainsCfg->channelConf[0].encFrameRate;
    Chains_ipcBitsInitCreateParams_BitsOutRTOS(&ipcBitsOutVideoPrm,
                                               FALSE);

    ipcBitsInHostPrm.baseCreateParams.inQueParams.prevLinkId        = ipcBitsOutVideoId;
    ipcBitsInHostPrm.baseCreateParams.inQueParams.prevLinkQueId     = 0;
    ipcBitsInHostPrm.baseCreateParams.numOutQue                     = 1;
    ipcBitsInHostPrm.baseCreateParams.numChPerOutQue[0]             = 1;
    ipcBitsInHostPrm.baseCreateParams.inputFrameRate                = chainsCfg->channelConf[0].encFrameRate;
    ipcBitsInHostPrm.baseCreateParams.outputFrameRate               = chainsCfg->channelConf[0].encFrameRate;
    Chains_ipcBitsInitCreateParams_BitsInHLOS(&ipcBitsInHostPrm);

    Chains_displayCtrlInit(chainsCfg->displayRes);

    System_linkCreate(nsfId , &nsfPrm, sizeof(nsfPrm));
    System_linkCreate(ipcOutVpssId , &ipcOutVpssPrm , sizeof(ipcOutVpssPrm) );
    System_linkCreate(ipcInVideoId , &ipcInVideoPrm , sizeof(ipcInVideoPrm) );
    System_linkCreate(encId, &encPrm, sizeof(encPrm));
    System_linkCreate(ipcBitsOutVideoId, &ipcBitsOutVideoPrm, sizeof(ipcBitsOutVideoPrm));
    System_linkCreate(ipcBitsInHostId, &ipcBitsInHostPrm, sizeof(ipcBitsInHostPrm));

    System_linkGetInfo(ipcBitsInHostId,&bitsProducerLinkInfo);
    OSA_assert(bitsProducerLinkInfo.numQue = 1);

    System_LinkQueInfo queInfo;
    queInfo.numCh                       = 1;
    queInfo.chInfo[0].bufType           = SYSTEM_BUF_TYPE_VIDBITSTREAM;
    queInfo.chInfo[0].codingformat      = chainsCfg->channelConf[0].encFormat;
    queInfo.chInfo[0].memType           = SYSTEM_MT_TILEDMEM;
    queInfo.chInfo[0].width             = chainsCfg->channelConf[0].width;
    queInfo.chInfo[0].height            = chainsCfg->channelConf[0].height;
    queInfo.chInfo[0].scanFormat        = SYSTEM_SF_PROGRESSIVE;

    ipcBitsOutHostPrm.baseCreateParams.numOutQue                    = 1;
    ipcBitsOutHostPrm.baseCreateParams.numChPerOutQue[0]            = 1;
    ipcBitsOutHostPrm.baseCreateParams.outQueParams[0].nextLink     = ipcBitsInVideoId;
    ipcBitsOutHostPrm.bufPoolPerCh                                  = FALSE;
    ipcBitsOutHostPrm.numBufPerCh[0]                                = 0;
    //Chains_ipcBitsInitCreateParams_BitsOutHLOS(&ipcBitsOutHostPrm, &bitsProducerLinkInfo.queInfo[0]);
    Chains_ipcBitsInitCreateParams_BitsOutHLOS(&ipcBitsOutHostPrm, &queInfo);

    ipcBitsInVideoPrm.baseCreateParams.inQueParams.prevLinkId       = ipcBitsOutHostId;
    ipcBitsInVideoPrm.baseCreateParams.inQueParams.prevLinkQueId    = 0;
    ipcBitsInVideoPrm.baseCreateParams.numOutQue                    = 1;
    ipcBitsInVideoPrm.baseCreateParams.outQueParams[0].nextLink     = decId;
    Chains_ipcBitsInitCreateParams_BitsInRTOS(&ipcBitsInVideoPrm, TRUE);

    for (i=0; i<1; i++) {
        decPrm.chCreateParams[i].format                               = chainsCfg->channelConf[i].encFormat;
        decPrm.chCreateParams[i].profile                              = IH264VDEC_PROFILE_ANY;
        decPrm.chCreateParams[i].targetMaxWidth                       = chainsCfg->channelConf[i].width;
        decPrm.chCreateParams[i].targetMaxHeight                      = chainsCfg->channelConf[i].height;
        decPrm.chCreateParams[i].displayDelay                         = IVIDDEC3_DECODE_ORDER;
        decPrm.chCreateParams[i].fieldMergeDecodeEnable               = FALSE;
        decPrm.chCreateParams[i].numBufPerCh                          = 16;
        decPrm.chCreateParams[i].dpbBufSizeInFrames                   = //DEC_LINK_DPB_SIZE_IN_FRAMES_DEFAULT;
                                                                        IH264VDEC_DPB_NUMFRAMES_AUTO;
        decPrm.chCreateParams[i].algCreateStatus                      = DEC_LINK_ALG_CREATE_STATUS_CREATE;
        decPrm.chCreateParams[i].defaultDynamicParams.targetFrameRate = chainsCfg->channelConf[i].encFrameRate;
        decPrm.chCreateParams[i].defaultDynamicParams.targetBitRate   = chainsCfg->channelConf[i].bitRate;
    }
    decPrm.inQueParams.prevLinkId    = ipcBitsInVideoId;
    decPrm.inQueParams.prevLinkQueId = 0;
    decPrm.outQueParams.nextLink     = ipcOutVideoId;
    decPrm.tilerEnable               = TRUE;

    ipcOutVideoPrm.inQueParams.prevLinkId    = decId;
    ipcOutVideoPrm.inQueParams.prevLinkQueId = 0;
    ipcOutVideoPrm.numOutQue                 = 1;
    ipcOutVideoPrm.outQueParams[0].nextLink  = ipcInVpssId;
    ipcOutVideoPrm.notifyNextLink            = TRUE;
    ipcOutVideoPrm.notifyPrevLink            = FALSE;
    ipcOutVideoPrm.noNotifyMode              = FALSE;

    ipcInVpssPrm.inQueParams.prevLinkId    = ipcOutVideoId;
    ipcInVpssPrm.inQueParams.prevLinkQueId = 0;
    ipcInVpssPrm.numOutQue                 = 1;
    ipcInVpssPrm.outQueParams[0].nextLink  = swMsId;
    ipcInVpssPrm.notifyNextLink            = TRUE;
    ipcInVpssPrm.notifyPrevLink            = FALSE;
    ipcInVpssPrm.noNotifyMode              = FALSE;

    swMsPrm.numSwMsInst               = 1;
    swMsPrm.swMsInstId[0]             = SYSTEM_SW_MS_SC_INST_SC5;
    swMsPrm.inQueParams.prevLinkId    = ipcInVpssId;
    swMsPrm.inQueParams.prevLinkQueId = 0;
    swMsPrm.outQueParams.nextLink     = displayId;
    swMsPrm.layoutPrm.outputFPS       = chainsCfg->channelConf[0].frameRate;
    swMsPrm.maxOutRes                 = chainsCfg->displayRes[0];
    swMsPrm.lineSkipMode              = FALSE;
    swMsPrm.enableLayoutGridDraw      = FALSE;
    swMsPrm.maxInputQueLen            = SYSTEM_SW_MS_DEFAULT_INPUT_QUE_LEN;
    swMsPrm.numOutBuf                 = 0;

    Chains_swMsGenerateLayoutParams(0, 2, &swMsPrm);

    displayPrm.inQueParams[0].prevLinkId    = swMsId;
    displayPrm.inQueParams[0].prevLinkQueId = 0;
    displayPrm.displayRes                   = chainsCfg->displayRes[0];

    System_linkCreate(ipcBitsOutHostId,&ipcBitsOutHostPrm,sizeof(ipcBitsOutHostPrm));
    System_linkCreate(ipcBitsInVideoId,&ipcBitsInVideoPrm,sizeof(ipcBitsInVideoPrm));
    System_linkCreate(decId, &decPrm, sizeof(decPrm));
    System_linkCreate(ipcOutVideoId, &ipcOutVideoPrm, sizeof(ipcOutVideoPrm));
    System_linkCreate(ipcInVpssId  , &ipcInVpssPrm  , sizeof(ipcInVpssPrm)  );
    System_linkCreate(swMsId, &swMsPrm, sizeof(swMsPrm));
    System_linkCreate(displayId, &displayPrm, sizeof(displayPrm));

    Chains_memPrintHeapStatus();

    {
        System_linkStart(displayId);
        System_linkStart(swMsId);
        System_linkStart(decId);
        System_linkStart(ipcBitsInVideoId);
        System_linkStart(ipcBitsOutHostId);
        System_linkStart(ipcBitsInHostId);
        System_linkStart(ipcBitsOutVideoId);
        System_linkStart(encId);
        System_linkStart(nsfId);
        System_linkStart(captureId);

        while(1)
        {
            ch = Chains_menuRunTime();
            if(ch=='0')
                break;
            if(ch=='v')
                System_linkControl(captureId, CAPTURE_LINK_CMD_FORCE_RESET, NULL, 0, TRUE);
            if(ch=='p')
                System_linkControl(captureId, CAPTURE_LINK_CMD_PRINT_ADV_STATISTICS, NULL, 0, TRUE);
        }

        System_linkStop(captureId);
        System_linkStop(nsfId);
        System_linkStop(encId);
        Chains_ipcBitsStop();
        System_linkStop(ipcBitsInVideoId);
        System_linkStop(ipcBitsOutHostId);
        System_linkStop(ipcBitsInHostId);
        System_linkStop(ipcBitsOutVideoId);
        System_linkStop(decId);
        System_linkStop(swMsId);
        System_linkStop(displayId);
    }

    System_linkDelete(captureId);
    System_linkDelete(nsfId);
    System_linkDelete(ipcOutVpssId);
    System_linkDelete(ipcInVideoId);
    System_linkDelete(encId);
    System_linkDelete(ipcBitsOutVideoId);
    System_linkDelete(ipcBitsInHostId);
    System_linkDelete(ipcBitsOutHostId);
    System_linkDelete(ipcBitsInVideoId);
    System_linkDelete(decId);
    System_linkDelete(ipcOutVideoId);
    System_linkDelete(ipcInVpssId);
    System_linkDelete(swMsId);
    System_linkDelete(displayId);

    Chains_displayCtrlDeInit();
    Chains_ipcBitsExit();
}
Void MultiCh_createVdecVdis()
{
    IpcBitsOutLinkHLOS_CreateParams   ipcBitsOutHostPrm;
    IpcBitsInLinkRTOS_CreateParams    ipcBitsInVideoPrm;
    DecLink_CreateParams        decPrm;
    IpcLink_CreateParams        ipcOutVideoPrm;
    IpcLink_CreateParams        ipcInVpssPrm;
    DupLink_CreateParams        dupPrm;
    static SwMsLink_CreateParams       swMsPrm[VDIS_DEV_MAX];
    DisplayLink_CreateParams    displayPrm[VDIS_DEV_MAX];
    IpcFramesOutLinkHLOS_CreateParams  ipcFramesOutHostPrm;
    IpcFramesInLinkRTOS_CreateParams   ipcFramesInVpssFromHostPrm;
    MergeLink_CreateParams             mergePrm;

    UInt32 i;
    UInt32 enableGrpx;
    Bool tilerEnable;
    Bool enableVideoFrameExport;

    System_init();
#if AVSYNC_COMP_ENABLE
    if (gVsysModuleContext.vsysConfig.enableAVsync == TRUE)
    {
        printf("AVSYNC_Init start\n");

        AVSYNC_Init();  // avsync init for linux / A8 side

        printf("AVSYNC_Init done\n");
    }
#endif


    MULTICH_INIT_STRUCT(IpcLink_CreateParams,ipcInVpssPrm);
    MULTICH_INIT_STRUCT(IpcLink_CreateParams,ipcOutVideoPrm);
    MULTICH_INIT_STRUCT(IpcBitsOutLinkHLOS_CreateParams,ipcBitsOutHostPrm);
    MULTICH_INIT_STRUCT(IpcBitsInLinkRTOS_CreateParams,ipcBitsInVideoPrm);
    MULTICH_INIT_STRUCT(DecLink_CreateParams, decPrm);
    MULTICH_INIT_STRUCT(IpcFramesOutLinkHLOS_CreateParams ,ipcFramesOutHostPrm);
    MULTICH_INIT_STRUCT(IpcFramesInLinkRTOS_CreateParams  ,ipcFramesInVpssFromHostPrm);
    for (i = 0; i < VDIS_DEV_MAX;i++)
    {
        MULTICH_INIT_STRUCT(DisplayLink_CreateParams,displayPrm[i]);
        MULTICH_INIT_STRUCT(SwMsLink_CreateParams ,swMsPrm[i]);
    }
    MultiCh_detectBoard();

    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
    );
#ifdef TI_814X_BUILD
    tilerEnable  = FALSE;
    enableGrpx   = FALSE;
#else
    tilerEnable  = FALSE;
    enableGrpx   = TRUE;
#endif

#if (tilerEnable == FALSE)
    {
        /* Disable tiler allocator for this usecase
         * for that tiler memory can be reused for
         * non-tiled allocation
         */
        SystemTiler_disableAllocator();
    }
#endif

    enableVideoFrameExport = FALSE;

    gVdecModuleContext.ipcBitsOutHLOSId = SYSTEM_HOST_LINK_ID_IPC_BITS_OUT_0;
    gVdecModuleContext.ipcBitsInRTOSId  = SYSTEM_VIDEO_LINK_ID_IPC_BITS_IN_0;
    gVdecModuleContext.decId            = SYSTEM_LINK_ID_VDEC_0;

    gMultiCh_VdecVdisObj.ipcOutVideoId  = SYSTEM_VIDEO_LINK_ID_IPC_OUT_M3_0;
    gMultiCh_VdecVdisObj.ipcInVpssId    = SYSTEM_VPSS_LINK_ID_IPC_IN_M3_0;
    gMultiCh_VdecVdisObj.dupId          = SYSTEM_VPSS_LINK_ID_DUP_0;


    gVdisModuleContext.swMsId[0]        = SYSTEM_LINK_ID_SW_MS_MULTI_INST_0;
    gVdisModuleContext.swMsId[1]        = SYSTEM_LINK_ID_SW_MS_MULTI_INST_1;

    gVdisModuleContext.displayId[0]     = SYSTEM_LINK_ID_DISPLAY_0; // ON AND OFF CHIP HDMI
#ifdef TI_814X_BUILD
    gVdisModuleContext.displayId[1]     = SYSTEM_LINK_ID_DISPLAY_2; // SDTV
#else
    gVdisModuleContext.displayId[1]     = SYSTEM_LINK_ID_DISPLAY_1; // OFF CHIP HDMI
#endif


    if (enableVideoFrameExport)
    {
        gMultiCh_VdecVdisObj.mergeId                 = SYSTEM_VPSS_LINK_ID_MERGE_0;
        gVdisModuleContext.ipcFramesOutHostId        = SYSTEM_HOST_LINK_ID_IPC_FRAMES_OUT_0;
        gVdisModuleContext.ipcFramesInVpssFromHostId = SYSTEM_VPSS_LINK_ID_IPC_FRAMES_IN_0;
    }

    if(enableGrpx)
    {
        // GRPX is enabled in Vdis_start() based on the link ID set here
        gVdisModuleContext.grpxId[0]    = SYSTEM_LINK_ID_GRPX_0;
#ifdef TI_814X_BUILD
        gVdisModuleContext.grpxId[1]    = SYSTEM_LINK_ID_INVALID;
#else
        gVdisModuleContext.grpxId[1]    = SYSTEM_LINK_ID_GRPX_1;
#endif
    }

    MultiCh_displayCtrlInit(&gVdisModuleContext.vdisConfig);


    ipcBitsOutHostPrm.baseCreateParams.outQueParams[0].nextLink= gVdecModuleContext.ipcBitsInRTOSId;
    ipcBitsOutHostPrm.baseCreateParams.notifyNextLink       = FALSE;
    ipcBitsOutHostPrm.baseCreateParams.notifyPrevLink       = FALSE;
    ipcBitsOutHostPrm.baseCreateParams.noNotifyMode         = TRUE;
    ipcBitsOutHostPrm.baseCreateParams.numOutQue            = 1;
    ipcBitsOutHostPrm.inQueInfo.numCh                       = gVdecModuleContext.vdecConfig.numChn;

    for (i=0; i<ipcBitsOutHostPrm.inQueInfo.numCh; i++)
    {
        ipcBitsOutHostPrm.inQueInfo.chInfo[i].width =
            gVdecModuleContext.vdecConfig.decChannelParams[i].maxVideoWidth;

        ipcBitsOutHostPrm.inQueInfo.chInfo[i].height =
            gVdecModuleContext.vdecConfig.decChannelParams[i].maxVideoHeight;

        ipcBitsOutHostPrm.inQueInfo.chInfo[i].scanFormat =
            SYSTEM_SF_PROGRESSIVE;

        ipcBitsOutHostPrm.inQueInfo.chInfo[i].bufType        = 0; // NOT USED
        ipcBitsOutHostPrm.inQueInfo.chInfo[i].codingformat   = 0; // NOT USED
        ipcBitsOutHostPrm.inQueInfo.chInfo[i].dataFormat     = 0; // NOT USED
        ipcBitsOutHostPrm.inQueInfo.chInfo[i].memType        = 0; // NOT USED
        ipcBitsOutHostPrm.inQueInfo.chInfo[i].startX         = 0; // NOT USED
        ipcBitsOutHostPrm.inQueInfo.chInfo[i].startY         = 0; // NOT USED
        ipcBitsOutHostPrm.inQueInfo.chInfo[i].pitch[0]       = 0; // NOT USED
        ipcBitsOutHostPrm.inQueInfo.chInfo[i].pitch[1]       = 0; // NOT USED
        ipcBitsOutHostPrm.inQueInfo.chInfo[i].pitch[2]       = 0; // NOT USED
    }

    ipcBitsInVideoPrm.baseCreateParams.inQueParams.prevLinkId    = gVdecModuleContext.ipcBitsOutHLOSId;
    ipcBitsInVideoPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
    ipcBitsInVideoPrm.baseCreateParams.outQueParams[0].nextLink  = gVdecModuleContext.decId;
    ipcBitsInVideoPrm.baseCreateParams.noNotifyMode              = TRUE;
    ipcBitsInVideoPrm.baseCreateParams.notifyNextLink            = TRUE;
    ipcBitsInVideoPrm.baseCreateParams.notifyPrevLink            = FALSE;
    ipcBitsInVideoPrm.baseCreateParams.numOutQue                 = 1;

    decPrm.numBufPerPool[0] = MAX_DEC_OUT_FRAMES_PER_CH;
    for (i=0; i<ipcBitsOutHostPrm.inQueInfo.numCh; i++)
    {
        if(gVdecModuleContext.vdecConfig.decChannelParams[i].isCodec == VDEC_CHN_H264)
            decPrm.chCreateParams[i].format                 = IVIDEO_H264HP;
        else if(gVdecModuleContext.vdecConfig.decChannelParams[i].isCodec == VDEC_CHN_MPEG4)
            decPrm.chCreateParams[i].format                 = IVIDEO_MPEG4ASP;
        else if(gVdecModuleContext.vdecConfig.decChannelParams[i].isCodec == VDEC_CHN_MJPEG)
            decPrm.chCreateParams[i].format                 = IVIDEO_MJPEG;

        decPrm.chCreateParams[i].numBufPerCh 
                         = gVdecModuleContext.vdecConfig.decChannelParams[i].numBufPerCh;
        decPrm.chCreateParams[i].profile                = IH264VDEC_PROFILE_ANY;
        decPrm.chCreateParams[i].displayDelay
                         = gVdecModuleContext.vdecConfig.decChannelParams[i].displayDelay;
        decPrm.chCreateParams[i].dpbBufSizeInFrames = IH264VDEC_DPB_NUMFRAMES_AUTO;
        decPrm.chCreateParams[i].fieldMergeDecodeEnable = FALSE;

        decPrm.chCreateParams[i].targetMaxWidth  =
            ipcBitsOutHostPrm.inQueInfo.chInfo[i].width;

        decPrm.chCreateParams[i].targetMaxHeight =
            ipcBitsOutHostPrm.inQueInfo.chInfo[i].height;

        decPrm.chCreateParams[i].defaultDynamicParams.targetFrameRate =
            gVdecModuleContext.vdecConfig.decChannelParams[i].dynamicParam.frameRate;

        decPrm.chCreateParams[i].defaultDynamicParams.targetBitRate =
            gVdecModuleContext.vdecConfig.decChannelParams[i].dynamicParam.targetBitRate;
    }

    decPrm.inQueParams.prevLinkId       = gVdecModuleContext.ipcBitsInRTOSId;
    decPrm.inQueParams.prevLinkQueId    = 0;
    decPrm.outQueParams.nextLink        = gMultiCh_VdecVdisObj.ipcOutVideoId;
    decPrm.tilerEnable                  = tilerEnable;

    ipcOutVideoPrm.inQueParams.prevLinkId    = gVdecModuleContext.decId;
    ipcOutVideoPrm.inQueParams.prevLinkQueId = 0;
    ipcOutVideoPrm.outQueParams[0].nextLink     = gMultiCh_VdecVdisObj.ipcInVpssId;
    ipcOutVideoPrm.notifyNextLink            = TRUE;
    ipcOutVideoPrm.notifyPrevLink            = TRUE;
    ipcOutVideoPrm.numOutQue                 = 1;

    ipcInVpssPrm.inQueParams.prevLinkId    = gMultiCh_VdecVdisObj.ipcOutVideoId;
    ipcInVpssPrm.inQueParams.prevLinkQueId = 0;
    ipcInVpssPrm.notifyNextLink            = TRUE;
    ipcInVpssPrm.notifyPrevLink            = TRUE;
    ipcInVpssPrm.numOutQue                 = 1;

    if (enableVideoFrameExport)
    {
        ipcFramesOutHostPrm.baseCreateParams.noNotifyMode = TRUE;
        ipcFramesOutHostPrm.baseCreateParams.notifyNextLink = FALSE;
        ipcFramesOutHostPrm.baseCreateParams.notifyPrevLink = FALSE;
        ipcFramesOutHostPrm.baseCreateParams.inQueParams.prevLinkId = SYSTEM_LINK_ID_INVALID;
        ipcFramesOutHostPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
        ipcFramesOutHostPrm.baseCreateParams.numOutQue = 1;
        ipcFramesOutHostPrm.baseCreateParams.outQueParams[0].nextLink = gVdisModuleContext.ipcFramesInVpssFromHostId;
        MultiCh_setIpcFramesOutInQueInfo(&ipcFramesOutHostPrm.inQueInfo);

        ipcFramesInVpssFromHostPrm.baseCreateParams.noNotifyMode = TRUE;
        ipcFramesInVpssFromHostPrm.baseCreateParams.notifyNextLink = TRUE;
        ipcFramesInVpssFromHostPrm.baseCreateParams.notifyPrevLink = FALSE;
        ipcFramesInVpssFromHostPrm.baseCreateParams.inQueParams.prevLinkId = gVdisModuleContext.ipcFramesOutHostId;
        ipcFramesInVpssFromHostPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
        ipcFramesInVpssFromHostPrm.baseCreateParams.numOutQue = 1;
        ipcFramesInVpssFromHostPrm.baseCreateParams.outQueParams[0].nextLink = gMultiCh_VdecVdisObj.mergeId;

        
        ipcInVpssPrm.outQueParams[0].nextLink     = gMultiCh_VdecVdisObj.mergeId;
        
        mergePrm.numInQue                     = 2;
        mergePrm.inQueParams[0].prevLinkId    = gMultiCh_VdecVdisObj.ipcInVpssId;
        mergePrm.inQueParams[0].prevLinkQueId = 0;
        mergePrm.inQueParams[1].prevLinkId    = gVdisModuleContext.ipcFramesInVpssFromHostId;
        mergePrm.inQueParams[1].prevLinkQueId = 0;
        mergePrm.outQueParams.nextLink        = gMultiCh_VdecVdisObj.dupId;
        mergePrm.notifyNextLink               = TRUE;
        dupPrm.inQueParams.prevLinkId         = gMultiCh_VdecVdisObj.mergeId;
    }
    else
    {
        dupPrm.inQueParams.prevLinkId         = gMultiCh_VdecVdisObj.ipcInVpssId;
        ipcInVpssPrm.outQueParams[0].nextLink     = gMultiCh_VdecVdisObj.dupId;

    }
    dupPrm.inQueParams.prevLinkQueId      = 0;
    dupPrm.numOutQue                      = gVsysModuleContext.vsysConfig.numDisplays;
    dupPrm.outQueParams[0].nextLink       = gVdisModuleContext.swMsId[0];
    dupPrm.outQueParams[1].nextLink       = gVdisModuleContext.swMsId[1];
    dupPrm.notifyNextLink                 = TRUE;
#ifdef TI_814X_BUILD
    swMsPrm[0].numSwMsInst = 2;
    swMsPrm[0].swMsInstId[0]        = SYSTEM_SW_MS_SC_INST_VIP1_SC;
    swMsPrm[0].swMsInstId[1]        = SYSTEM_SW_MS_SC_INST_SC5;


    swMsPrm[0].swMsInstStartWin[0]  = 0;
    swMsPrm[0].swMsInstStartWin[1]  = 10;
#else
    swMsPrm[0].swMsInstId[0]        = SYSTEM_SW_MS_SC_INST_VIP1_SC;
    swMsPrm[0].swMsInstId[1]        = SYSTEM_SW_MS_SC_INST_DEI_SC_NO_DEI;

    swMsPrm[1].swMsInstId[0]        = SYSTEM_SW_MS_SC_INST_SC5;
    swMsPrm[1].swMsInstId[1]        = SYSTEM_SW_MS_SC_INST_DEIHQ_SC_NO_DEI;

    swMsPrm[0].numSwMsInst          = 2;

    swMsPrm[0].swMsInstStartWin[0]  = 0;
    swMsPrm[0].swMsInstStartWin[1]  = 16;

    swMsPrm[1].numSwMsInst          = swMsPrm[0].numSwMsInst;
    swMsPrm[1].swMsInstStartWin[0]  = swMsPrm[0].swMsInstStartWin[0];
    swMsPrm[1].swMsInstStartWin[1]  = swMsPrm[0].swMsInstStartWin[1];
#endif
    for(i=0; i<gVsysModuleContext.vsysConfig.numDisplays; i++)
    {
        swMsPrm[i].inQueParams.prevLinkId     = gMultiCh_VdecVdisObj.dupId;
        swMsPrm[i].inQueParams.prevLinkQueId  = i;
        swMsPrm[i].outQueParams.nextLink      = gVdisModuleContext.displayId[i];

        /* Disable inQue drop at SwMs as input may arrive very fast in VDEC->VDIS use case */
        swMsPrm[i].maxInputQueLen             = SYSTEM_SW_MS_INVALID_INPUT_QUE_LEN;
        if (i == 0)
            swMsPrm[i].maxOutRes              = gVdisModuleContext.vdisConfig.deviceParams[VDIS_DEV_HDMI].resolution;
        else if (i == 1)
#ifdef TI_814X_BUILD
            swMsPrm[i].maxOutRes              = VSYS_STD_PAL;
#else
            swMsPrm[i].maxOutRes              = gVdisModuleContext.vdisConfig.deviceParams[VDIS_DEV_DVO2].resolution;
#endif
        /* low cost line skip mode of scaling can be used, when tiler is off */
        if(tilerEnable)
            swMsPrm[i].lineSkipMode           = FALSE;
        else
            swMsPrm[i].lineSkipMode           = TRUE;

        swMsPrm[i].enableLayoutGridDraw = gVdisModuleContext.vdisConfig.enableLayoutGridDraw;

        MultiCh_swMsGetDefaultLayoutPrm(i, &swMsPrm[i], FALSE);    /* both from 0-16 chnl */

        displayPrm[i].inQueParams[0].prevLinkId    = gVdisModuleContext.swMsId[i];
        displayPrm[i].inQueParams[0].prevLinkQueId = 0;
        displayPrm[i].displayRes                = swMsPrm[i].maxOutRes;
        if (i == 1)
#ifdef TI_814X_BUILD
                        displayPrm[i].displayRes            = gVdisModuleContext.vdisConfig.deviceParams[VDIS_DEV_SD].resolution;
#else
                        displayPrm[i].displayRes            = gVdisModuleContext.vdisConfig.deviceParams[VDIS_DEV_DVO2].resolution;
#endif
    }

    System_linkCreate(gVdecModuleContext.ipcBitsOutHLOSId,&ipcBitsOutHostPrm,sizeof(ipcBitsOutHostPrm));
    System_linkCreate(gVdecModuleContext.ipcBitsInRTOSId,&ipcBitsInVideoPrm,sizeof(ipcBitsInVideoPrm));
    System_linkCreate(gVdecModuleContext.decId, &decPrm, sizeof(decPrm));

    System_linkCreate(gMultiCh_VdecVdisObj.ipcOutVideoId, &ipcOutVideoPrm, sizeof(ipcOutVideoPrm));
    System_linkCreate(gMultiCh_VdecVdisObj.ipcInVpssId  , &ipcInVpssPrm, sizeof(ipcInVpssPrm));

    if (enableVideoFrameExport)
    {
        System_linkCreate(gVdisModuleContext.ipcFramesOutHostId     , &ipcFramesOutHostPrm    , sizeof(ipcFramesOutHostPrm));
        System_linkCreate(gVdisModuleContext.ipcFramesInVpssFromHostId     , &ipcFramesInVpssFromHostPrm    , sizeof(ipcFramesInVpssFromHostPrm));
        System_linkCreate(gMultiCh_VdecVdisObj.mergeId,&mergePrm,sizeof(mergePrm));
    }
    System_linkCreate(gMultiCh_VdecVdisObj.dupId     , &dupPrm    , sizeof(dupPrm));

    for(i=0; i<gVsysModuleContext.vsysConfig.numDisplays; i++)
        System_linkCreate(gVdisModuleContext.swMsId[i]  , &swMsPrm[i], sizeof(swMsPrm[i]));

    for(i=0; i<gVsysModuleContext.vsysConfig.numDisplays; i++)
        System_linkCreate(gVdisModuleContext.displayId[i], &displayPrm[i], sizeof(displayPrm[i]));

    MultiCh_memPrintHeapStatus();
    gMultiCh_VdecVdisObj.enableVideoFrameExport = enableVideoFrameExport;
}
Void MultiCh_create_8CifProgressiveVcapVencVdecVdis()
{
    CaptureLink_CreateParams    capturePrm;
    NsfLink_CreateParams        nsfPrm;
    DeiLink_CreateParams        deiPrm[1];
    DupLink_CreateParams        dup1Prm;
    MergeLink_CreateParams      merge1Prm;
    static SwMsLink_CreateParams       swMsPrm[2];
    DisplayLink_CreateParams    displayPrm[3];
    IpcLink_CreateParams        ipcOutVpssPrm;
    IpcLink_CreateParams        ipcInVpssPrm;
    IpcLink_CreateParams        ipcOutVideoPrm;
    IpcLink_CreateParams        ipcInVideoPrm;
    EncLink_CreateParams        encPrm;
    DecLink_CreateParams        decPrm;
    IpcBitsOutLinkHLOS_CreateParams   ipcBitsOutHostPrm;
    IpcBitsOutLinkRTOS_CreateParams   ipcBitsOutVideoPrm;
    IpcBitsInLinkHLOS_CreateParams    ipcBitsInHostPrm;
    IpcBitsInLinkRTOS_CreateParams    ipcBitsInVideoPrm;
    System_LinkInfo bitsProducerLinkInfo;

    VCAP_VIDDEC_PARAMS_S vidDecVideoModeArgs[NUM_CAPTURE_DEVICES];

    CaptureLink_VipInstParams *pCaptureInstPrm;
    CaptureLink_OutParams     *pCaptureOutPrm;
    UInt32 dup1Id,merge1Id,nullId;
    UInt32 ipcOutVpssId, ipcInVpssId;
    UInt32 ipcOutVideoId, ipcInVideoId;

    UInt32 vipInstId;
    UInt32 i;
    UInt32 numSubChains;

    printf("\nDB_DEBUG:%s %s() %d\n",__FILE__,__FUNCTION__,__LINE__);
    System_init();

    printf("\nDB_DEBUG:%s %s() %d\n",__FILE__,__FUNCTION__,__LINE__);
    MULTICH_INIT_STRUCT(IpcLink_CreateParams,ipcOutVpssPrm);
    MULTICH_INIT_STRUCT(IpcLink_CreateParams,ipcInVpssPrm);
    MULTICH_INIT_STRUCT(IpcLink_CreateParams,ipcOutVideoPrm);
    MULTICH_INIT_STRUCT(IpcLink_CreateParams,ipcInVideoPrm);
    MULTICH_INIT_STRUCT(IpcBitsOutLinkHLOS_CreateParams,ipcBitsOutHostPrm);
    MULTICH_INIT_STRUCT(IpcBitsOutLinkRTOS_CreateParams,ipcBitsOutVideoPrm);
    MULTICH_INIT_STRUCT(IpcBitsInLinkHLOS_CreateParams,ipcBitsInHostPrm);
    MULTICH_INIT_STRUCT(IpcBitsInLinkRTOS_CreateParams,ipcBitsInVideoPrm);
    MULTICH_INIT_STRUCT(DecLink_CreateParams, decPrm);
    MULTICH_INIT_STRUCT(EncLink_CreateParams, encPrm);
    MULTICH_INIT_STRUCT(SwMsLink_CreateParams ,swMsPrm[0]);
    MULTICH_INIT_STRUCT(SwMsLink_CreateParams ,swMsPrm[1]);

    for (i = 0; i < 3; i++)
    {
        MULTICH_INIT_STRUCT(DisplayLink_CreateParams ,displayPrm[i]);
    }
    printf("\n********* Entered usecase 8CH <814x> Enc/Dec \n\n");

    printf("\nDB_DEBUG:%s %s() %d\n",__FILE__,__FUNCTION__,__LINE__);
    MultiCh_detectBoard();
    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
    );

    printf("\nDB_DEBUG:%s %s() %d\n",__FILE__,__FUNCTION__,__LINE__);
    gVcapModuleContext.captureId    = SYSTEM_LINK_ID_CAPTURE;
    gVcapModuleContext.nsfId[0]     = SYSTEM_LINK_ID_NSF_0;
    gVcapModuleContext.deiId[0]     = SYSTEM_LINK_ID_DEI_0;
    gVencModuleContext.encId        = SYSTEM_LINK_ID_VENC_0;
    gVdecModuleContext.decId        = SYSTEM_LINK_ID_VDEC_0;

    gVdisModuleContext.swMsId[0]      = SYSTEM_LINK_ID_SW_MS_MULTI_INST_0;
    gVdisModuleContext.swMsId[1]      = SYSTEM_LINK_ID_SW_MS_MULTI_INST_1;
    swMsPrm[0].numSwMsInst = 1;
    swMsPrm[1].numSwMsInst = 1;
    swMsPrm[0].swMsInstId[0] = SYSTEM_SW_MS_SC_INST_SC5;
    swMsPrm[1].swMsInstId[0] = SYSTEM_SW_MS_SC_INST_SC5;

    gVdisModuleContext.displayId[0] = SYSTEM_LINK_ID_DISPLAY_0; // ON CHIP HDMI
    gVdisModuleContext.displayId[1] = SYSTEM_LINK_ID_DISPLAY_1; // OFF CHIP HDMI
    gVdisModuleContext.displayId[2] = SYSTEM_LINK_ID_DISPLAY_2; // OFF CHIP HDMI
    merge1Id      = SYSTEM_VPSS_LINK_ID_MERGE_0;
    dup1Id      = SYSTEM_VPSS_LINK_ID_DUP_0;
    nullId      = SYSTEM_VPSS_LINK_ID_NULL_0;


    ipcOutVpssId = SYSTEM_VPSS_LINK_ID_IPC_OUT_M3_0;
    ipcInVideoId = SYSTEM_VIDEO_LINK_ID_IPC_IN_M3_0;
    ipcOutVideoId= SYSTEM_VIDEO_LINK_ID_IPC_OUT_M3_0;
    ipcInVpssId  = SYSTEM_VPSS_LINK_ID_IPC_IN_M3_0;

    gVencModuleContext.ipcBitsOutRTOSId     = SYSTEM_VIDEO_LINK_ID_IPC_BITS_OUT_0;
    gVencModuleContext.ipcBitsInHLOSId       = SYSTEM_HOST_LINK_ID_IPC_BITS_IN_0;
    gVdecModuleContext.ipcBitsOutHLOSId     = SYSTEM_HOST_LINK_ID_IPC_BITS_OUT_0;
    gVdecModuleContext.ipcBitsInRTOSId       = SYSTEM_VIDEO_LINK_ID_IPC_BITS_IN_0;


    capturePrm.numVipInst    = 2;       // 8 channel
    capturePrm.outQueParams[0].nextLink = gVcapModuleContext.deiId[0];      // DEI support both 420SP & 422I
    capturePrm.tilerEnable              = FALSE;

    for(vipInstId=0; vipInstId<capturePrm.numVipInst; vipInstId++)
    {
        pCaptureInstPrm                     = &capturePrm.vipInst[vipInstId];
        pCaptureInstPrm->vipInstId          = (SYSTEM_CAPTURE_INST_VIP1_PORTB-
                                              vipInstId)%SYSTEM_CAPTURE_INST_MAX;//(SYSTEM_CAPTURE_INST_VIP0_PORTA+
                                              //vipInstId)%SYSTEM_CAPTURE_INST_MAX;
        pCaptureInstPrm->videoDecoderId     = SYSTEM_DEVICE_VID_DEC_TVP5158_DRV;
        pCaptureInstPrm->inDataFormat       = SYSTEM_DF_YUV422P;
        pCaptureInstPrm->standard           = SYSTEM_STD_MUX_4CH_HALF_D1;
        pCaptureInstPrm->numOutput          = 1;

        pCaptureOutPrm                      = &pCaptureInstPrm->outParams[0];
        pCaptureOutPrm->dataFormat          = SYSTEM_DF_YUV422I_YUYV;
        pCaptureOutPrm->scEnable            = FALSE;
        pCaptureOutPrm->scOutWidth          = 0;
        pCaptureOutPrm->scOutHeight         = 0;
        pCaptureOutPrm->outQueId            = 0;
    }

    for(i = 0; i < NUM_CAPTURE_DEVICES; i++)
    {
        vidDecVideoModeArgs[i].videoIfMode        = DEVICE_CAPT_VIDEO_IF_MODE_8BIT;
        vidDecVideoModeArgs[i].videoDataFormat    = SYSTEM_DF_YUV422P;
        vidDecVideoModeArgs[i].standard           = SYSTEM_STD_MUX_4CH_D1;
        vidDecVideoModeArgs[i].videoCaptureMode   =
                    DEVICE_CAPT_VIDEO_CAPTURE_MODE_MULTI_CH_PIXEL_MUX_EMBEDDED_SYNC;
        vidDecVideoModeArgs[i].videoSystem        =
                                      DEVICE_VIDEO_DECODER_VIDEO_SYSTEM_AUTO_DETECT;
        vidDecVideoModeArgs[i].videoCropEnable    = FALSE;
        vidDecVideoModeArgs[i].videoAutoDetectTimeout = -1;
    }

    Vcap_configVideoDecoder(vidDecVideoModeArgs, NUM_CAPTURE_DEVICES);


    {
    DeiLink_CreateParams_Init(&deiPrm[0]);
        deiPrm[0].inQueParams.prevLinkId                        = gVcapModuleContext.captureId;
        deiPrm[0].inQueParams.prevLinkQueId                     = 0;
        deiPrm[0].outQueParams[DEI_LINK_OUT_QUE_VIP_SC].nextLink  = merge1Id;
        deiPrm[0].outQueParams[DEI_LINK_OUT_QUE_DEI_SC].nextLink  = gVcapModuleContext.nsfId[0];
        deiPrm[0].enableOut[DEI_LINK_OUT_QUE_VIP_SC]              = TRUE;
        deiPrm[0].enableOut[DEI_LINK_OUT_QUE_DEI_SC]              = TRUE;
        deiPrm[0].tilerEnable                                   = TRUE;
        deiPrm[0].comprEnable                                   = FALSE;
        deiPrm[0].setVipScYuv422Format                          = FALSE;

#ifdef      DEI_SCALING_BASED_ON_RATIO
        /* Set Output Scaling at DEI to ratio based */
        deiPrm[0].scaleMode = DEI_SCALE_MODE_RATIO;

        /* DEI Path Scalar ratio is 1:2, D1 => CIF */
        deiPrm[0].outScaleFactor[DEI_LINK_OUT_QUE_DEI_SC].ratio.widthRatio.numerator    = 1;
        deiPrm[0].outScaleFactor[DEI_LINK_OUT_QUE_DEI_SC].ratio.widthRatio.denominator  = 2;

        deiPrm[0].outScaleFactor[DEI_LINK_OUT_QUE_DEI_SC].ratio.heightRatio.numerator   = 1;
        deiPrm[0].outScaleFactor[DEI_LINK_OUT_QUE_DEI_SC].ratio.heightRatio.denominator         = 2;

        /* VIP Scalar ratio is 1:1 */
        deiPrm[0].outScaleFactor[DEI_LINK_OUT_QUE_VIP_SC].ratio.widthRatio.numerator    = 1;
        deiPrm[0].outScaleFactor[DEI_LINK_OUT_QUE_VIP_SC].ratio.widthRatio.denominator  = 1;

        deiPrm[0].outScaleFactor[DEI_LINK_OUT_QUE_VIP_SC].ratio.heightRatio.numerator   = 1;
        deiPrm[0].outScaleFactor[DEI_LINK_OUT_QUE_VIP_SC].ratio.heightRatio.denominator         = 1;
#else
        /* Set Output Scaling at DEI to ratio based */
        deiPrm[0].scaleMode = DEI_SCALE_MODE_ABSOLUTE;

        /* DEI Path Scalar <for primary out> is set to D1 */
        deiPrm[0].outScaleFactor[DEI_LINK_OUT_QUE_DEI_SC].absoluteResolution.outWidth   = 352;
        deiPrm[0].outScaleFactor[DEI_LINK_OUT_QUE_DEI_SC].absoluteResolution.outHeight  = 288;

        /* DEI Path Scalar <for secondary out> is set to CIF */
        deiPrm[0].outScaleFactor[DEI_LINK_OUT_QUE_VIP_SC].absoluteResolution.outWidth   = 720;
        deiPrm[0].outScaleFactor[DEI_LINK_OUT_QUE_VIP_SC].absoluteResolution.outHeight  = 480;
#endif
    }

    NsfLink_CreateParams_Init(&nsfPrm);
    nsfPrm.bypassNsf                 = TRUE;
    nsfPrm.tilerEnable               = FALSE;
    nsfPrm.inQueParams.prevLinkId    = gVcapModuleContext.deiId[0];
    nsfPrm.inQueParams.prevLinkQueId = DEI_LINK_OUT_QUE_DEI_SC;
    nsfPrm.numOutQue                 = 1;
    nsfPrm.outQueParams[0].nextLink  = ipcOutVpssId;

    ipcOutVpssPrm.inQueParams.prevLinkId    = gVcapModuleContext.nsfId[0];
    ipcOutVpssPrm.inQueParams.prevLinkQueId = 0;
    ipcOutVpssPrm.outQueParams[0].nextLink     = ipcInVideoId;
    ipcOutVpssPrm.notifyNextLink            = FALSE;
    ipcOutVpssPrm.notifyPrevLink            = TRUE;
    ipcOutVpssPrm.noNotifyMode              = TRUE;

    ipcInVideoPrm.inQueParams.prevLinkId    = ipcOutVpssId;
    ipcInVideoPrm.inQueParams.prevLinkQueId = 0;
    ipcInVideoPrm.outQueParams[0].nextLink     = gVencModuleContext.encId;
    ipcInVideoPrm.notifyNextLink            = TRUE;
    ipcInVideoPrm.notifyPrevLink            = FALSE;
    ipcInVideoPrm.noNotifyMode              = TRUE;

    encPrm.numBufPerCh[0] = 4; //CIF
    {
        EncLink_ChCreateParams *pLinkChPrm;
        EncLink_ChDynamicParams *pLinkDynPrm;
        VENC_CHN_DYNAMIC_PARAM_S *pDynPrm;
        VENC_CHN_PARAMS_S *pChPrm;

        /* Primary Stream Params - D1 */
        for (i=0; i<8; i++)
        {
            pLinkChPrm  = &encPrm.chCreateParams[i];
            pLinkDynPrm = &pLinkChPrm->defaultDynamicParams;

            pChPrm      = &gVencModuleContext.vencConfig.encChannelParams[i];
            pDynPrm     = &pChPrm->dynamicParam;

            pLinkChPrm->format                  = IVIDEO_H264HP;
            pLinkChPrm->profile                 = gVencModuleContext.vencConfig.h264Profile[i];
            pLinkChPrm->dataLayout              = IVIDEO_FIELD_SEPARATED;
            pLinkChPrm->fieldMergeEncodeEnable  = FALSE;
            pLinkChPrm->enableAnalyticinfo      = pChPrm->enableAnalyticinfo;
            pLinkChPrm->maxBitRate              = pChPrm->maxBitRate;
            pLinkChPrm->encodingPreset          = pChPrm->encodingPreset;
            pLinkChPrm->rateControlPreset       = pChPrm->rcType;

            pLinkDynPrm->intraFrameInterval     = pDynPrm->intraFrameInterval;
            pLinkDynPrm->targetBitRate          = pDynPrm->targetBitRate;
            pLinkDynPrm->interFrameInterval     = 1;
            pLinkDynPrm->mvAccuracy             = IVIDENC2_MOTIONVECTOR_QUARTERPEL;
            pLinkDynPrm->inputFrameRate         = pDynPrm->inputFrameRate;
            pLinkDynPrm->rcAlg                  = pDynPrm->rcAlg;
            pLinkDynPrm->qpMin                  = pDynPrm->qpMin;
            pLinkDynPrm->qpMax                  = pDynPrm->qpMax;
            pLinkDynPrm->qpInit                 = pDynPrm->qpInit;
            pLinkDynPrm->vbrDuration            = pDynPrm->vbrDuration;
            pLinkDynPrm->vbrSensitivity         = pDynPrm->vbrSensitivity;
        }

        encPrm.inQueParams.prevLinkId    = ipcInVideoId;
        encPrm.inQueParams.prevLinkQueId = 0;
        encPrm.outQueParams.nextLink     = gVencModuleContext.ipcBitsOutRTOSId;
    }


    ipcBitsOutVideoPrm.baseCreateParams.inQueParams.prevLinkId = gVencModuleContext.encId;
    ipcBitsOutVideoPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
    ipcBitsOutVideoPrm.baseCreateParams.outQueParams[0].nextLink = gVencModuleContext.ipcBitsInHLOSId;
    MultiCh_ipcBitsInitCreateParams_BitsOutRTOS(&ipcBitsOutVideoPrm,
                                               TRUE);

    ipcBitsInHostPrm.baseCreateParams.inQueParams.prevLinkId = gVencModuleContext.ipcBitsOutRTOSId;
    ipcBitsInHostPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
    MultiCh_ipcBitsInitCreateParams_BitsInHLOS(&ipcBitsInHostPrm);

    MultiCh_displayCtrlInit(&gVdisModuleContext.vdisConfig);

#ifndef SYSTEM_USE_VIDEO_DECODER
    capturePrm.isPalMode = Vcap_isPalMode();
#endif
    System_linkCreate (gVcapModuleContext.captureId, &capturePrm, sizeof(capturePrm));
    System_linkCreate(gVcapModuleContext.deiId[0]  , &deiPrm[0], sizeof(deiPrm[0]));
    System_linkCreate(gVcapModuleContext.nsfId[0] , &nsfPrm, sizeof(nsfPrm));
    System_linkCreate(ipcOutVpssId , &ipcOutVpssPrm , sizeof(ipcOutVpssPrm) );
    System_linkCreate(ipcInVideoId , &ipcInVideoPrm , sizeof(ipcInVideoPrm) );

    System_linkCreate(gVencModuleContext.encId, &encPrm, sizeof(encPrm));

    System_linkCreate(gVencModuleContext.ipcBitsOutRTOSId, &ipcBitsOutVideoPrm, sizeof(ipcBitsOutVideoPrm));
    System_linkCreate(gVencModuleContext.ipcBitsInHLOSId, &ipcBitsInHostPrm, sizeof(ipcBitsInHostPrm));


    System_linkGetInfo(gVencModuleContext.ipcBitsInHLOSId,&bitsProducerLinkInfo);
    OSA_assert(bitsProducerLinkInfo.numQue = 1);
    ipcBitsOutHostPrm.baseCreateParams.outQueParams[0].nextLink = gVdecModuleContext.ipcBitsInRTOSId;
    printf ("\n\n========bitsProducerLinkInfo============\n");
    printf ("numQ %d, numCh %d\n",
                    bitsProducerLinkInfo.numQue,
                    bitsProducerLinkInfo.queInfo[0].numCh);
    {
        int i;
        for (i=0; i<bitsProducerLinkInfo.queInfo[0].numCh; i++)
        {
            printf ("Ch [%d] Width %d, Height %d\n",
                i,
                bitsProducerLinkInfo.queInfo[0].chInfo[i].width,
                bitsProducerLinkInfo.queInfo[0].chInfo[i].height
                );
        }
    }
    printf ("\n====================\n\n");

    printf ("Reducing bitsProducerLinkInfo.numCh to 8\n");
    bitsProducerLinkInfo.queInfo[0].numCh = 8;

    MultiCh_ipcBitsInitCreateParams_BitsOutHLOS(&ipcBitsOutHostPrm,
                                               &bitsProducerLinkInfo.queInfo[0]);
    if(gVdecModuleContext.vdecConfig.forceUseDecChannelParams)
    {
        /* use channel info provided by user instead of from encoder */
        UInt32 chId;
        System_LinkChInfo *pChInfo;

        ipcBitsOutHostPrm.inQueInfo.numCh = gVdecModuleContext.vdecConfig.numChn;

        for(chId=0; chId<ipcBitsOutHostPrm.inQueInfo.numCh; chId++)
        {
            pChInfo = &ipcBitsOutHostPrm.inQueInfo.chInfo[chId];

            pChInfo->bufType        = 0; // NOT USED
            pChInfo->codingformat   = 0; // NOT USED
            pChInfo->dataFormat     = 0; // NOT USED
            pChInfo->memType        = 0; // NOT USED
            pChInfo->startX         = 0; // NOT USED
            pChInfo->startY         = 0; // NOT USED
            pChInfo->width          = gVdecModuleContext.vdecConfig.decChannelParams[chId].maxVideoWidth;
            pChInfo->height         = gVdecModuleContext.vdecConfig.decChannelParams[chId].maxVideoHeight;
            pChInfo->pitch[0]       = 0; // NOT USED
            pChInfo->pitch[1]       = 0; // NOT USED
            pChInfo->pitch[2]       = 0; // NOT USED
            pChInfo->scanFormat     = SYSTEM_SF_PROGRESSIVE;
        }
    }
    ipcBitsInVideoPrm.baseCreateParams.inQueParams.prevLinkId = gVdecModuleContext.ipcBitsOutHLOSId;
    ipcBitsInVideoPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
    ipcBitsInVideoPrm.baseCreateParams.outQueParams[0].nextLink = gVdecModuleContext.decId;
    MultiCh_ipcBitsInitCreateParams_BitsInRTOS(&ipcBitsInVideoPrm,
                                              TRUE);
    for (i=0; i<8; i++) {
        decPrm.chCreateParams[i].format          = IVIDEO_H264HP;
        decPrm.chCreateParams[i].profile         = IH264VDEC_PROFILE_ANY;
        decPrm.chCreateParams[i].fieldMergeDecodeEnable = FALSE;
        decPrm.chCreateParams[i].targetMaxWidth  =
            gVdecModuleContext.vdecConfig.decChannelParams[i].maxVideoWidth;
        decPrm.chCreateParams[i].targetMaxHeight =
            gVdecModuleContext.vdecConfig.decChannelParams[i].maxVideoHeight;
        decPrm.chCreateParams[i].defaultDynamicParams.targetFrameRate =
            gVdecModuleContext.vdecConfig.decChannelParams[i].dynamicParam.frameRate;
        decPrm.chCreateParams[i].defaultDynamicParams.targetBitRate =
            gVdecModuleContext.vdecConfig.decChannelParams[i].dynamicParam.targetBitRate;
    }
    decPrm.inQueParams.prevLinkId = gVdecModuleContext.ipcBitsInRTOSId;
    decPrm.inQueParams.prevLinkQueId = 0;
    decPrm.outQueParams.nextLink     = ipcOutVideoId;
    decPrm.tilerEnable = TRUE;

    ipcOutVideoPrm.inQueParams.prevLinkId    = gVdecModuleContext.decId;
    ipcOutVideoPrm.inQueParams.prevLinkQueId = 0;
    ipcOutVideoPrm.outQueParams[0].nextLink     = ipcInVpssId;
    ipcOutVideoPrm.notifyNextLink            = FALSE;
    ipcOutVideoPrm.notifyPrevLink            = TRUE;
    ipcOutVideoPrm.noNotifyMode              = TRUE;

    ipcInVpssPrm.inQueParams.prevLinkId    = ipcOutVideoId;
    ipcInVpssPrm.inQueParams.prevLinkQueId = 0;
    ipcInVpssPrm.outQueParams[0].nextLink     = merge1Id;
    ipcInVpssPrm.notifyNextLink            = TRUE;
    ipcInVpssPrm.notifyPrevLink            = FALSE;
    ipcInVpssPrm.noNotifyMode              = TRUE;

    merge1Prm.numInQue                     = 2;
    merge1Prm.inQueParams[0].prevLinkId    = gVcapModuleContext.deiId[0];
    merge1Prm.inQueParams[0].prevLinkQueId = DEI_LINK_OUT_QUE_VIP_SC;
    merge1Prm.inQueParams[1].prevLinkId    = ipcInVpssId;
    merge1Prm.inQueParams[1].prevLinkQueId = 0;
    merge1Prm.outQueParams.nextLink        = dup1Id;
    merge1Prm.notifyNextLink               = TRUE;

    dup1Prm.inQueParams.prevLinkId         = merge1Id;;
    dup1Prm.inQueParams.prevLinkQueId      = 0;
    dup1Prm.numOutQue                      = 2;
    dup1Prm.outQueParams[0].nextLink       = gVdisModuleContext.swMsId[0];
    dup1Prm.outQueParams[1].nextLink       = gVdisModuleContext.swMsId[1];
    dup1Prm.notifyNextLink                 = TRUE;

//  swMsPrm[0].inQueParams.prevLinkId    = dup1Id;
//  swMsPrm[0].inQueParams.prevLinkQueId = 0;   //DEI_LINK_OUT_QUE_VIP_SC;
//  swMsPrm[1].inQueParams.prevLinkId    = dup1Id;
//  swMsPrm[1].inQueParams.prevLinkQueId = 1;

    numSubChains = 2;
    for(i=0; i<numSubChains; i++)
    {
        swMsPrm[i].inQueParams.prevLinkId    = dup1Id;
        swMsPrm[i].inQueParams.prevLinkQueId = i;
        swMsPrm[i].outQueParams.nextLink     = gVdisModuleContext.displayId[i];
        swMsPrm[i].maxOutRes                 = gVdisModuleContext.vdisConfig.deviceParams[i].resolution;
        swMsPrm[i].lineSkipMode = FALSE;

        swMsPrm[i].enableLayoutGridDraw = gVdisModuleContext.vdisConfig.enableLayoutGridDraw;

        MultiCh_swMsGetDefaultLayoutPrm(i, &swMsPrm[i], FALSE);

        displayPrm[i].inQueParams[0].prevLinkId    = gVdisModuleContext.swMsId[i];
        displayPrm[i].inQueParams[0].prevLinkQueId = 0;
        displayPrm[i].displayRes                = swMsPrm[i].maxOutRes;
    }
    displayPrm[2].inQueParams[0].prevLinkId    = dup1Id;
    displayPrm[2].inQueParams[0].prevLinkQueId = 1;
    displayPrm[2].displayRes            = gVdisModuleContext.vdisConfig.deviceParams[VDIS_DEV_SD].resolution;


    System_linkCreate(gVdecModuleContext.ipcBitsOutHLOSId,&ipcBitsOutHostPrm,sizeof(ipcBitsOutHostPrm));
    System_linkCreate(gVdecModuleContext.ipcBitsInRTOSId,&ipcBitsInVideoPrm,sizeof(ipcBitsInVideoPrm));
    System_linkCreate(gVdecModuleContext.decId, &decPrm, sizeof(decPrm));
    System_linkCreate(ipcOutVideoId, &ipcOutVideoPrm, sizeof(ipcOutVideoPrm));
    System_linkCreate(ipcInVpssId  , &ipcInVpssPrm  , sizeof(ipcInVpssPrm)  );
    System_linkCreate(merge1Id   , &merge1Prm  , sizeof(merge1Prm));
    System_linkCreate(dup1Id     , &dup1Prm    , sizeof(dup1Prm));
    for(i=0; i<2; i++)
        System_linkCreate(gVdisModuleContext.swMsId[i]  , &swMsPrm[i], sizeof(swMsPrm[i]));
    for(i=0; i<3; i++)
        System_linkCreate(gVdisModuleContext.displayId[i], &displayPrm[i], sizeof(displayPrm[i]));

//    MultiCh_memPrintHeapStatus();
    //Utils_encdecHdvicpPrfInit();
}