This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

DM8148 building the right pipeline for encoder

Other Parts Discussed in Thread: TVP5158

Dear Experts,

I have  a MIstral DM8148 and I want to utilize the existing demo Decode->Display (demo_vdec_vdis.c) to use the encoder also, for this purpose I want to disconnect one of the DUP element connections which goes to display and send it to the encoder and then write the encoded stream to the file.

But seems that I misunderstanding the concept of buffers and data flow between components, I will appreciate any help, to be more specific can any body draw me a flow from DUP to Encoder to Save Stream, which include buffer and link types.

Thanks in advance.

Ilia.

Below is code part example of what I tried to do, but it not working.

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

dupPrm.numOutQue = 2;//here we send one to display - one to encoder//gVsysModuleContext.vsysConfig.numDisplays;
dupPrm.outQueParams[0].nextLink = gVdisModuleContext.swMsId[0];
dupPrm.outQueParams[1].nextLink = gMultiCh_VdecVdisObj.ipcOutVpssId;//gVdisModuleContext.swMsId[1];
dupPrm.notifyNextLink = TRUE;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ipcOutVpssPrm.inQueParams.prevLinkId = gMultiCh_VdecVdisObj.dupId;
ipcOutVpssPrm.inQueParams.prevLinkQueId = 1;
ipcOutVpssPrm.numOutQue = 1;
ipcOutVpssPrm.outQueParams[0].nextLink = gMultiCh_VdecVdisObj.ipcInVideoId;
ipcOutVpssPrm.notifyNextLink = FALSE;
ipcOutVpssPrm.notifyPrevLink = TRUE;
ipcOutVpssPrm.noNotifyMode = TRUE;

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

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.baseCreateParams.inQueParams.prevLinkId = gVencModuleContext.ipcBitsOutRTOSId;
ipcBitsInHostPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
ipcBitsInHostPrm.baseCreateParams.numOutQue = 1;
ipcBitsInHostPrm.baseCreateParams.outQueParams[0].nextLink = SYSTEM_LINK_ID_INVALID;
MultiCh_ipcBitsInitCreateParams_BitsInHLOS(&ipcBitsInHostPrm);

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

//EncLink_CreateParams_Init(&encPrm);

encPrm.numBufPerCh[0] = 6;

/* 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 = VCODEC_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;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

  • Hello,

    What is the software release that you are using here DVRRDK or IPNC?

    BR

    Margarita

  • Hello Margarita,

    I'm using Ti DVRRDK 4.01.

    P.S. The error which I get for the code above is :
    [m3video] 26233: Assertion @ Line: 1406 in links_m3video/iva_enc/encLink_common.c: pPrm->inQueParams.prevLinkQueId < pObj->inTskInfo.numQue : failed !!!

    Also all the use cases for 8148 use SD capture with some TVP5158 board which I don't have, No HD case from component input, this is strange.

    Best.
    Ilia.
  • Hello,

    For DVRRDK support you could contact your local FAE or try to search in the e2e for similar issue.

    BR
    Margarita
  • Dear Experts,

    My problem still exist and I will appreciate any help with this issue!

    BR.
    Ilia.
  • Some additional info:

    I'm using the Decode-Display demo, 

    the error I keep receiving is :  [m3video]  24563: Assertion @ Line: 82 in links_common/system/system_linkApi.c: procId < SYSTEM_PROC_MAX : failed !!!

    The Encoder pipeline is :

    Dup -> SYSTEM_VPSS_LINK_ID_IPC_FRAMES_OUT_0 - > SYSTEM_VIDEO_LINK_ID_IPC_FRAMES_IN_0 ->
    Encoder -> SYSTEM_VIDEO_LINK_ID_IPC_BITS_OUT_0 -> SYSTEM_HOST_LINK_ID_IPC_BITS_IN_0

    Can anyone help with this?

    Source code attached.

    Thanks.

    Ilia.

    =========
    
    
     Main Menu
    
    
     =========
    
    
    
    
    
     1: 4CH VCAP + VENC + VDEC + VDIS  - Progressive SD Encode + Decode
    
    
     2: 8CH <D1+CIF> VCAP + VENC + VDEC + VDIS  - Progressive SD Encode + Decode
    
    
     3: 16CH RT VCAP + VENC + VDEC + VDIS  - Progressive SD Encode + Decode
    
    
     4: 16CH NRT <D1+CIF> VCAP + VENC + VDEC + VDIS  - Progressive SD Encode + Decode
    
    
     5:               VDEC + VDIS  - SD/HD Decode ONLY ilia
    
    
     6:               YUV FILE VENC  - SD/HD Decode ONLY ilia
    
    
    
    
    
    
    
     e: Exit
    
    
    
    
    
     Enter Choice:
    
     Sample ini files available in ./demo_ini folder.
    
     Enter the .ini filename with full path : /opt/dvr_rdk/ti814x/demo_ini/704x576_01_1CH.ini
    
    
    
     *** a new param codec is needed for ini, if you not sure about this
    
     *** please reference demo_ini/704x576_02_32CH.ini
    
     *** H264:  codec = h264
    
     *** MPEG4: codec = mpeg4
    
     *** MJPEG: codec = mjpeg
    
     *** MPEG2: codec = mpeg2
    
     *** Four new params numbuf ,displaydelay,tilerEnable,fieldPicture has been added for ini, if not defaults are set
    
    
    
     *** Generate header files ***
    
    
    
     This will take very long time if the file is large.
    
     - For first time you MUST select YES.
    
     - If you already have the header file on disk, you can select NO.
    
    
    
     Do you want to generate header ? (YES - y, NO - n) : n
    
    
    
    
    
     0: Opening file [/data/Samplesdump4.h264] of 1280 x 720  Codec: h264...
    
     0: WARNING: Either the displaydelay was not set or Default value was set as 0
    
    gVdecVdis_config.numChannels : 1 gVdecVdis_config.chBufSize[0] : 921600
    
     File open ... DONE !!!
    
    
    
    
    
    
     [host] MCFW_IPCFRAMES:VdecVdis_ipcFramesSendFxn:Entered...--------------- CHANNEL DETAILS-------------
    
    Dec Channels => 1
    
    Enc Channels => Primary 1, Secondary 0
    
    Disp Channels => 1
    
    -------------------------------------------
    
     0: SYSTEM: System Common Init in progress !!!
    
     0: SYSTEM: IPC init in progress !!!
    
     12: SYSTEM: CPU [DSP] syslink proc ID is [0] !!!
    
     12: SYSTEM: CPU [VIDEO-M3] syslink proc ID is [1] !!!
    
     12: SYSTEM: CPU [VPSS-M3] syslink proc ID is [2] !!!
    
     12: SYSTEM: CPU [HOST] syslink proc ID is [3] !!!
    
     12: SYSTEM: Creating MsgQ Heap [IPC_MSGQ_MSG_HEAP_3] ...
    
     15: SYSTEM: Creating MsgQ [HOST_MSGQ] ...
    
     17: SYSTEM: Creating MsgQ [HOST_ACK_MSGQ] ...
    
     18: SYSTEM: Opening MsgQ [DSP_MSGQ] ...
    
     19: SYSTEM: Opening MsgQ [VIDEO-M3_MSGQ] ...
    
     19: SYSTEM: Opening MsgQ [VPSS-M3_MSGQ] ...
    
     20: SYSTEM: Notify register to [DSP] line 0, event 15 ...
    
     21: SYSTEM: Notify register to [VIDEO-M3] line 0, event 15 ...
    
     22: SYSTEM: Notify register to [VPSS-M3] line 0, event 15 ...
    
     22: SYSTEM: IPC init DONE !!!
    
     23: SYSTEM: Creating ListMP [HOST_IPC_OUT_24] in region 0 ...
    
     25: SYSTEM: Creating ListMP [HOST_IPC_IN_24] in region 0 ...
    
     27: SYSTEM: ListElem Shared Addr = 0x41783680
    
     28: SYSTEM: Creating ListMP [HOST_IPC_OUT_25] in region 0 ...
    
     30: SYSTEM: Creating ListMP [HOST_IPC_IN_25] in region 0 ...
    
     32: SYSTEM: ListElem Shared Addr = 0x417ba480
    
     33: SYSTEM: Creating ListMP [HOST_IPC_OUT_19] in region 0 ...
    
     35: SYSTEM: Creating ListMP [HOST_IPC_IN_19] in region 0 ...
    
     37: SYSTEM: ListElem Shared Addr = 0x417f1280
    
     38: SYSTEM: Creating ListMP [HOST_IPC_OUT_20] in region 0 ...
    
     40: SYSTEM: Creating ListMP [HOST_IPC_IN_20] in region 0 ...
    
     41: SYSTEM: ListElem Shared Addr = 0x41834580
    
     42: SYSTEM: Creating ListMP [HOST_IPC_OUT_21] in region 0 ...
    
     44: SYSTEM: Creating ListMP [HOST_IPC_IN_21] in region 0 ...
    
     46: SYSTEM: ListElem Shared Addr = 0x41877880
    
     68: SYSTEM: System Common Init Done !!!
    
    ch[0], h264
    
     [host] HDMI Ctrl :Initializing
    
    [HOST]
    
    ThreadName:Vdis_hdmiControlThread_0,ThreadID:748
    
     [host] HDMI Ctrl :Initialized
    
     [host] HDMI Ctrl :Sink Connected
    
     [FBDEV]
    
     [FBDEV] FB: Starting !!!
    
     [FBDEV] FB: Opened device [/dev/fb0] (fd=23) !!!
    
     [FBDEV]
    
     [FBDEV] Fix Screen Info
    
     [FBDEV] ---------------
    
     [FBDEV] Line Length - 1600
    
     [FBDEV] Physical Address = 84c00000
    
     [FBDEV] Buffer Length = 2097152
    
     [FBDEV]
    
     [FBDEV]
    
     [FBDEV] Var Screen Info
    
     [FBDEV] ---------------
    
     [FBDEV] Xres - 800
    
     [FBDEV] Yres - 600
    
     [FBDEV] Xres Virtual - 800
    
     [FBDEV] Yres Virtual - 600
    
     [FBDEV] Bits Per Pixel - 16
    
     [FBDEV] Pixel Clk - 6734
    
     [FBDEV] Rotation - 0
    
     [FBDEV]
    
     [FBDEV]
    
     [FBDEV] Reg Params Info
    
     [FBDEV] ---------------
    
     [FBDEV] region 0, postion 0 x 0, prioirty 1
    
     [FBDEV] first 1, last 1
    
     [FBDEV] sc en 0, sten en 0
    
     [FBDEV] tran en 0, type 0, key 0
    
     [FBDEV] blend 0, alpha 0
    
     [FBDEV] bb en 0, alpha 0
    
     [FBDEV]
    
     [FBDEV]
    
     [FBDEV] ### BUF SIZE = 960000 Bytes !!!
    
     [FBDEV]
    
     [FBDEV] FB: Opened device [/dev/fb2] (fd2=24) !!!
    
     [FBDEV]
    
     [FBDEV] Fix Screen Info
    
     [FBDEV] ---------------
    
     [FBDEV] Line Length - 1440
    
     [FBDEV] Physical Address = 84e00000
    
     [FBDEV] Buffer Length = 1048576
    
     [FBDEV]
    
     [FBDEV]
    
     [FBDEV] Var Screen Info
    
     [FBDEV] ---------------
    
     [FBDEV] Xres - 720
    
     [FBDEV] Yres - 480
    
     [FBDEV] Xres Virtual - 720
    
     [FBDEV] Yres Virtual - 480
    
     [FBDEV] Bits Per Pixel - 16
    
     [FBDEV] Pixel Clk - 18518
    
     [FBDEV] Rotation - 0
    
     [FBDEV]
    
     [FBDEV]
    
     [FBDEV] Reg Params Info
    
     [FBDEV] ---------------
    
     [FBDEV] region 0, postion 0 x 0, prioirty 1
    
     [FBDEV] first 1, last 1
    
     [FBDEV] sc en 0, sten en 0
    
     [FBDEV] tran en 0, type 0, key 0
    
     [FBDEV] blend 0, alpha 0
    
     [FBDEV] bb en 0, alpha 0
    
     [FBDEV]
    
     [FBDEV]
    
     [FBDEV] ### BUF SIZE = 691200 Bytes !!!
    
     [FBDEV]
    
     [FBDEV]
    
     [FBDEV] Fix Screen Info
    
     [FBDEV] ---------------
    
     [FBDEV] Line Length - 1600
    
     [FBDEV] Physical Address = 84c00000
    
     [FBDEV] Buffer Length = 2097152
    
     [FBDEV]
    
     [FBDEV]
    
     [FBDEV] Var Screen Info
    
     [FBDEV] ---------------
    
     [FBDEV] Xres - 800
    
     [FBDEV] Yres - 600
    
     [FBDEV] Xres Virtual - 800
    
     [FBDEV] Yres Virtual - 600
    
     [FBDEV] Bits Per Pixel - 16
    
     [FBDEV] Pixel Clk - 6734
    
     [FBDEV] Rotation - 0
    
     [FBDEV]
    
     [FBDEV]
    
     [FBDEV] Reg Params Info
    
     [FBDEV] ---------------
    
     [FBDEV] region 0, postion 0 x 0, prioirty 1
    
     [FBDEV] first 1, last 1
    
     [FBDEV] sc en 0, sten en 0
    
     [FBDEV] tran en 0, type 0, key 0
    
     [FBDEV] blend 0, alpha 0
    
     [FBDEV] bb en 0, alpha 0
    
     [FBDEV]
    
     [FBDEV]
    
     [FBDEV] ### BUF SIZE = 960000 Bytes !!!
    
     [FBDEV]
    
     [FBDEV]
    
     [FBDEV] Fix Screen Info
    
     [FBDEV] ---------------
    
     [FBDEV] Line Length - 1440
    
     [FBDEV] Physical Address = 84e00000
    
     [FBDEV] Buffer Length = 1048576
    
     [FBDEV]
    
     [FBDEV]
    
     [FBDEV] Var Screen Info
    
     [FBDEV] ---------------
    
     [FBDEV] Xres - 720
    
     [FBDEV] Yres - 480
    
     [FBDEV] Xres Virtual - 720
    
     [FBDEV] Yres Virtual - 480
    
     [FBDEV] Bits Per Pixel - 16
    
     [FBDEV] Pixel Clk - 18518
    
     [FBDEV] Rotation - 0
    
     [FBDEV]
    
     [FBDEV]
    
     [FBDEV] Reg Params Info
    
     [FBDEV] ---------------
    
     [FBDEV] region 0, postion 0 x 0, prioirty 1
    
     [FBDEV] first 1, last 1
    
     [FBDEV] sc en 0, sten en 0
    
     [FBDEV] tran en 0, type 0, key 0
    
     [FBDEV] blend 0, alpha 0
    
     [FBDEV] bb en 0, alpha 0
    
     [FBDEV]
    
     [FBDEV]
    
     [FBDEV] ### BUF SIZE = 691200 Bytes !!!
    
     [FBDEV]
    
     [FBDEV] grpx_fb_draw ...
    
     [FBDEV] grpx_fb_draw ... Done !!!
    
     [FBDEV] grpx_fb_draw ...
    
     [FBDEV] grpx_fb_draw ... Done !!!
    
     [FBDEV] FB: Start DONE !!!
    
     [FBDEV]
    
    
    
     Enable file write (YES - y / NO - n) :
    
     File write DISABLED !!!
    
    
    
     301: MCFW  : CPU Revision [ES2.1] !!!
    
    
    
    
    
     [host] XAXAXAXAXAXAXAXAXAX
    
    [HOST]
    
    ThreadName:IpcBitsOutLink_tskMain_30000018,ThreadID:740
    
    
    
    
     [host]  308: IPC_BITS_OUT   : Create in progress !!!
    
    
    
    
     [host] IPC_BITSOUT:BitBuffer Alloc.ChID:0,Size:0x465000
    
    
     [host]
    
    
    ******* RingBuf 0 created ********
    
    
    
    
     [host] IPCBITSOUTLINK:Translated Addr Virt:0x41cc6080 To Phy:0x88000080
    
    
     [host]
    
    ###Bit buff of size from the SR # 1 : 4608000 / bufsize 921600, maxQueueDepth 50
    
    
    
    
     [host] ###Bit buff BasePtr: 41CC6080 / PhyAddr 88000080
    
    
    
    
     [host]  310: IPC_BITS_OUT   : Create Done !!!
    
    [HOST]
    
    ThreadName:IpcBitsOutLink_periodicTaskFxn_30000018,ThreadID:750
    
     [m3video]  24422: IPC_BITS_IN   : Create in progress !!!
    
     [m3video]  24422: SYSTEM: Opening ListMP [HOST_IPC_OUT_24] ...
    
     [m3video]  24423: SYSTEM: Opening ListMP [HOST_IPC_IN_24] ...
    
     [m3video]  24424: SYSTEM: Opening MsgQ [HOST_MSGQ] ...
    
     [m3video]  24427: IPC_BITS_IN   : Create Done !!!
    
     [m3video]  24427: DECODE: Create in progress ... !!!
    
     [m3video] DECLINK_H264:HEAPID:0        USED:4264
    
     [m3video] DECLINK_H264:HEAPID:3        USED:4915200
    
     [m3video]  24529: DECODE: Creating CH0 of 1280 x 720 [PROGRESSIVE] [NON-TILED  ],target bitrate = 2000 Kbps ...
    
     [m3vpss ]  24537: IPC_IN_M3   : Create in progress !!!
    
     [m3video]  24531: DECODE: All CH Create ... DONE !!!
    
     [m3vpss ]  24537: SYSTEM: Opening ListMP [VIDEO-M3_IPC_OUT_0] ...
    
     [m3vpss ]  24538: SYSTEM: Opening ListMP [VIDEO-M3_IPC_IN_0] ...
    
     [m3video] DECLINK:HEAPID:0     USED:4304
    
     [m3vpss ]  24539: SYSTEM: Opening MsgQ [VIDEO-M3_MSGQ] ...
    
     [m3video] DECLINK:HEAPID:3     USED:15255552
    
     [m3vpss ]  24541: IPC_IN_M3   : Create Done !!!
    
     [m3video]  24535: DECODE: Create ... DONE !!!
    
     [m3vpss ]  24542: MP_SCLR: Create in progress !!!
    
     [m3video]  24535: IPC_OUT_M3   : Create in progress !!!
    
     [m3vpss ]  24544: MP_SCLR: Configured to use scalar instance 3 !!!
    
     [m3video]  24536: IPC_OUT_M3   : Create Done !!!
    
     [m3vpss ]  24546: MP_SCLR: Create Done !!!
    
     [m3video]  24556: IPC_FRAMES_IN   : Create in progress !!!
    
     [m3vpss ]  24551: DUP:  0: Format: PROGRESSIVE, 1280 x 720
    
     [m3video]  24557: SYSTEM: Opening ListMP [VPSS-M3_IPC_OUT_19] ...
    
     [m3vpss ]  24553: DUP   : Create Done !!!
    
     [m3video]  24557: SYSTEM: Opening ListMP [VPSS-M3_IPC_IN_19] ...
    
     [m3vpss ]  24553: IPC_FRAMES_OUT   : Create in progress !!!
    
     [m3vpss ]  24556: IPC_FRAMES_OUT   : Create Done !!!
    
     [m3video] IPC_FRAMES_IN:HEAPID:0       USED:304
    
     [m3video]  24562: IPC_FRAMES_IN   : Create Done !!!
    
     [m3video]  24562: ENCODE: Create in progress ... !!!
    
     [m3video]  24563: Assertion @ Line: 82 in links_common/system/system_linkApi.c: procId < SYSTEM_PROC_MAX : failed !!!
    
    
    /*==============================================================================
     * @file:       demo_vdec_vdis.c
     *
     * @brief:      Video capture mcfw function definition.
     *
     * @vers:       0.5.0.0 2011-06
     *
     *==============================================================================
     *
     * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
     *
     *  Redistribution and use in source and binary forms, with or without
     *  modification, are permitted provided that the following conditions
     *  are met:
     *
     *    Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     *    Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the
     *    distribution.
     *
     *    Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     */
    #include <sys/time.h>
    #include <demo_vdec_vdis.h>
    
    VdecVenc_Ctrl gVdecVenc_ctrl;
    /**
        \brief Encode Sub-system initialization parameters
    */
    /*
    typedef struct {
    
        VENC_CHN_PARAMS_S encChannelParams[VENC_CHN_MAX];
        //< Channel Specific Parameters 
    
        VENC_CHN_H264_Profile_E h264Profile[VENC_CHN_MAX];
        //< Codec profile 
    
        UInt32 numPrimaryChn;
        //< Number of encoder primary channels <D1> 
    
        UInt32 numSecondaryChn;
        //< Number of encoder secondary channels <CIF> 
    
        UInt32 numTertiaryChn;
        //< Number of encoder tertiary channels <QCIF> 
    
    } VENC_PARAMS_S; 
    */
    #define VDEC_VDIS_ENABLE_IPCFRAMESOUT                 (FALSE)
    #define VDEC_VDIS_ENABLE_ENCODE		                 (TRUE)
    static Int64 get_current_time_to_msec(void)
    {
        struct timeval tv;
        gettimeofday(&tv, NULL);
    
        return ((Int64)tv.tv_sec*1000 + tv.tv_usec/1000);
    }
    
    Void VdecVdis_start()
    {
        VSYS_PARAMS_S vsysParams;
        VDEC_PARAMS_S vdecParams;
        VDIS_PARAMS_S vdisParams;
    	VENC_PARAMS_S vencParams;
        VDIS_MOSAIC_S sVdMosaicParam;
    
        UInt32 i,status;
        Bool forceLowCostScale = FALSE;
        UInt32 startChID;
        UInt64 wallTimeBase;
    
        VdecVdis_bitsRdInit();
    
        #ifdef VDEC_VDIS_ENABLE_IPCFRAMESOUT
        VdecVdis_ipcFramesCreate();
        #endif
    
        gDemo_info.maxVcapChannels = 0;
        gDemo_info.maxVdisChannels = gVdecVdis_config.fileNum;
    #ifdef VDEC_VDIS_ENABLE_ENCODE
        gDemo_info.maxVencChannels = gVdecVdis_config.fileNum;
    #else
    	gDemo_info.maxVencChannels = 0;
    #endif
        gDemo_info.maxVdecChannels = gVdecVdis_config.fileNum;
    
        vdecParams.numChn = gVdecVdis_config.fileNum;
    #ifdef VDEC_VDIS_ENABLE_ENCODE
    	vencParams.numPrimaryChn = gVdecVdis_config.fileNum;
    #else
    	vencParams.numPrimaryChn = 0;
    #endif
        vdisParams.numChannels = gVdecVdis_config.fileNum;
    
        Vsys_params_init(&vsysParams);
        vsysParams.systemUseCase = VSYS_USECASE_MULTICHN_VDEC_VDIS;
        vsysParams.enableCapture = FALSE;
        vsysParams.enableNsf     = FALSE;
    	#ifdef VDEC_VDIS_ENABLE_ENCODE 
        vsysParams.enableEncode  = TRUE;
    #else
    	vsysParams.enableEncode  = FALSE;
    #endif
        vsysParams.enableDecode  = TRUE;
    #ifdef VDEC_VDIS_ENABLE_ENCODE
        vsysParams.enableNullSrc = TRUE;//FALSE;
    #else
    	 vsysParams.enableNullSrc = FALSE;
    #endif
        vsysParams.enableAVsync  = TRUE;
        vsysParams.numDeis       = 0;
    #if defined(TI_814X_BUILD) || defined(TI_8107_BUILD)
    #ifdef VDEC_VDIS_ENABLE_ENCODE
        vsysParams.numSwMs       = 1;
        vsysParams.numDisplays   = 1;
    #else
    	vsysParams.numSwMs       = 2;
        vsysParams.numDisplays   = 2;
    #endif
    #else
        vsysParams.numSwMs       = 2;
        vsysParams.numDisplays   = 2;
    #endif
    	
    #ifdef VDEC_VDIS_ENABLE_ENCODE
        vencParams.numSecondaryChn = 0;//16;
    #endif
    
        printf ("--------------- CHANNEL DETAILS-------------\n");
        printf ("Dec Channels => %d\n", vdecParams.numChn);
    	printf ("Enc Channels => Primary %d, Secondary %d\n", vencParams.numPrimaryChn, vencParams.numSecondaryChn);
        printf ("Disp Channels => %d\n", vdisParams.numChannels);
        printf ("-------------------------------------------\n");
    
        /* Override the context here as needed */
        Vsys_init(&vsysParams);	
        Vdec_params_init(&vdecParams);
    #ifdef VDEC_VDIS_ENABLE_ENCODE
    	Venc_params_init(&vencParams);
    #endif
        /* Override the context here as needed */
    
        vdecParams.numChn = gVdecVdis_config.fileNum;
        vdecParams.forceUseDecChannelParams = TRUE;
    #ifdef VDEC_VDIS_ENABLE_ENCODE
    	vencParams.numPrimaryChn = gVdecVdis_config.fileNum;//16;
        vencParams.numSecondaryChn = 0;//16;
    #endif
        OSA_assert( vdecParams.numChn <= VDEC_CHN_MAX );
    
        for (i=0; i < vdecParams.numChn; i++) {
    
            vdecParams.decChannelParams[i].dynamicParam.frameRate = 30; // NOT USED
            vdecParams.decChannelParams[i].dynamicParam.targetBitRate = 2 * 1000 * 1000; // NOT USED
            if (gVdecVdis_config.fileInfo[i].width != 0 && gVdecVdis_config.fileInfo[i].height != 0)
            {
                vdecParams.decChannelParams[i].maxVideoWidth = gVdecVdis_config.fileInfo[i].width;
                vdecParams.decChannelParams[i].maxVideoHeight = gVdecVdis_config.fileInfo[i].height;
    #ifdef VDEC_VDIS_ENABLE_ENCODE
    			vencParams.encChannelParams[i].videoWidth = gVdecVdis_config.fileInfo[i].width;
    			vencParams.encChannelParams[i].videoHeight = gVdecVdis_config.fileInfo[i].height;
    #endif
            }
            else
            {
                printf(" ERROR: Invalid Decoder width x height !!!\n");
                OSA_assert(0);
            }
    
            /*If the codec type is missing, by default choose h264*/
            if(strlen(gVdecVdis_config.fileInfo[i].codec) == 0)
                strcpy(gVdecVdis_config.fileInfo[i].codec,"h264");
    
            if(strcmp(gVdecVdis_config.fileInfo[i].codec,"h264") == 0)
            {
                vdecParams.decChannelParams[i].isCodec = VDEC_CHN_H264;
                printf("ch[%d], h264\n",i);
            }
            else if(strcmp(gVdecVdis_config.fileInfo[i].codec,"mpeg4") == 0)
            {
                vdecParams.decChannelParams[i].isCodec = VDEC_CHN_MPEG4;
                vdecParams.decChannelParams[i].dynamicParam.frameRate = 30;
                vdecParams.decChannelParams[i].dynamicParam.targetBitRate = 2 * 1000 * 1000;
    
                printf("ch[%d], mpeg4\n",i);
            }
            else if(strcmp(gVdecVdis_config.fileInfo[i].codec,"mjpeg") == 0)
            {
                vdecParams.decChannelParams[i].isCodec = VDEC_CHN_MJPEG;
                vdecParams.decChannelParams[i].dynamicParam.frameRate = 1;
                vdecParams.decChannelParams[i].dynamicParam.targetBitRate = 2 * 1000 * 1000;
                printf("ch[%d], jpeg\n",i);
    
            }
    
            else if(strcmp(gVdecVdis_config.fileInfo[i].codec,"mpeg2") == 0)
            {
                vdecParams.decChannelParams[i].isCodec = VDEC_CHN_MPEG2;
                vdecParams.decChannelParams[i].dynamicParam.frameRate = 30;
                vdecParams.decChannelParams[i].dynamicParam.targetBitRate = 4 * 1000 * 1000;
                printf("ch[%d], MPEG2\n",i);
    
            }
    
            vdecParams.decChannelParams[i].displayDelay = gVdecVdis_config.fileInfo[i].displaydelay;
            vdecParams.decChannelParams[i].numBufPerCh = gVdecVdis_config.fileInfo[i].numbuf;
            vdecParams.decChannelParams[i].tilerEnable  = gVdecVdis_config.fileInfo[i].tilerEnable;
            vdecParams.decChannelParams[i].fieldPicture = gVdecVdis_config.fileInfo[i].fieldPicture;
    
        }
    #ifdef VDEC_VDIS_ENABLE_ENCODE	
        Venc_init(&vencParams);
    #endif
        Vdec_init(&vdecParams);	
        Vdis_params_init(&vdisParams);
        /* Override the context here as needed */
        vdisParams.numChannels = gVdecVdis_config.fileNum;
    
        vdisParams.deviceParams[VDIS_DEV_HDMI].resolution   = DEMO_HD_DISPLAY_DEFAULT_STD;
        /* Since HDCOMP and DVO2 are tied together they must have same resolution */
        vdisParams.deviceParams[VDIS_DEV_HDCOMP].resolution = DEMO_HD_DISPLAY_DEFAULT_STD;
        vdisParams.deviceParams[VDIS_DEV_DVO2].resolution   =
                               vdisParams.deviceParams[VDIS_DEV_HDMI].resolution;
        vdisParams.deviceParams[VDIS_DEV_SD].resolution     = VSYS_STD_NTSC;
    
        Vdis_tiedVencInit(VDIS_DEV_HDCOMP, VDIS_DEV_DVO2, &vdisParams);
    
    
    
    #if defined(TI_814X_BUILD) || defined(TI_8107_BUILD)
        /* set for 2 displays */
        i = 0;
        Demo_swMsGenerateLayout(VDIS_DEV_HDMI, 0, vdecParams.numChn,
                              DEMO_LAYOUT_MODE_4CH,
                              &vdisParams.mosaicParams[VDIS_DEV_HDMI], forceLowCostScale, gDemo_info.Type,
                              Vdis_getSwMsLayoutResolution(VDIS_DEV_HDMI));
        vdisParams.mosaicParams[VDIS_DEV_HDMI].userSetDefaultSWMLayout = TRUE;
    
        if(vdecParams.numChn < 16)
            startChID = 0;
        else
            startChID = 16;
        i = 1;
        Demo_swMsGenerateLayout(VDIS_DEV_SD, startChID, vdecParams.numChn,
                              DEMO_LAYOUT_MODE_4CH,
                              &vdisParams.mosaicParams[VDIS_DEV_SD], forceLowCostScale, gDemo_info.Type,
                              Vdis_getSwMsLayoutResolution(VDIS_DEV_SD));
        vdisParams.mosaicParams[VDIS_DEV_SD].userSetDefaultSWMLayout = TRUE;
    #else
        /* set for 3 displays */
        i = 0;
        Demo_swMsGenerateLayout(VDIS_DEV_HDMI, 0, vdecParams.numChn,
                              DEMO_LAYOUT_MODE_4CH_4CH,
                              &vdisParams.mosaicParams[i], forceLowCostScale,
                              gDemo_info.Type,
                              Vdis_getSwMsLayoutResolution(VDIS_DEV_HDMI));
        vdisParams.mosaicParams[i].userSetDefaultSWMLayout = TRUE;
    
    
        if(vdecParams.numChn < 16)
            startChID = 0;
        else
            startChID = 16;
        i = 1;
        Demo_swMsGenerateLayout(VDIS_DEV_HDCOMP, startChID, vdecParams.numChn,
                              DEMO_LAYOUT_MODE_4CH_4CH,
                              &vdisParams.mosaicParams[i], forceLowCostScale,
                              gDemo_info.Type,
                              Vdis_getSwMsLayoutResolution(VDIS_DEV_HDCOMP));
        vdisParams.mosaicParams[i].userSetDefaultSWMLayout = TRUE;
    
    #endif
        vdisParams.enableConfigExtVideoEncoder = FALSE;//ilia	
        Vdis_init(&vdisParams);
    
        wallTimeBase = get_current_time_to_msec();
        wallTimeBase = 0;
        Vdis_setWallTimeBase(wallTimeBase);
    
        /* Configure display */
        Vsys_configureDisplay();
    
    #if USE_FBDEV
        grpx_init(GRPX_FORMAT_RGB565);
    #endif
    
    #ifdef VDEC_VDIS_ENABLE_ENCODE
    	/* Init the application specific module which will handle bitstream exchange */
        VdecVenc_bitsWriteCreate();
    #endif
        /* Create Link instances and connects compoent blocks */
        Vsys_create();
    
        /* This is done to re-map ch to window mappping when no. of chan are <16 */
        if(vdecParams.numChn < 16)
        {
            status = Vdis_getMosaicParams(1,&sVdMosaicParam);
            status = Vdis_setMosaicParams(1, &sVdMosaicParam);
        }
    
        /* Start components in reverse order */
        Vdis_start();
    #ifdef VDEC_VDIS_ENABLE_ENCODE
        Venc_start();
    #endif
        Vdec_start();
    	
    
        #ifdef VDEC_VDIS_ENABLE_IPCFRAMESOUT
        VdecVdis_ipcFramesStart();
        #endif
    
        VdecVdis_bitsRdStart();
    }
    
    Void VdecVdis_stop()
    {
        VdecVdis_bitsRdStop();
    
        #ifdef VDEC_VDIS_ENABLE_IPCFRAMESOUT
        VdecVdis_ipcFramesStop();
        #endif
    
        /* Stop components */
        Vdec_stop();
        Vdis_stop();
    #ifdef VDEC_VDIS_ENABLE_ENCODE
        Venc_stop();
    #endif
    #if USE_FBDEV
        grpx_exit();
    #endif
    
        Vsys_delete();
    
        /* De-configure display */
        Vsys_deConfigureDisplay();
    
    
        /* De-initialize components */
    	Venc_exit();
        Vdec_exit();
        Vdis_exit();
        Vsys_exit();
    
        VdecVdis_bitsRdExit();
    
    #ifdef VDEC_VDIS_ENABLE_ENCODE
    	VdecVenc_bitsWriteDelete();
    #endif
    
        #ifdef VDEC_VDIS_ENABLE_IPCFRAMESOUT
        VdecVdis_ipcFramesDelete();
        #endif
    
    }
    
    
    /*******************************************************************************
     *                                                                             *
     * Copyright (c) 2009 Texas Instruments Incorporated - http://www.ti.com/      *
     *                        ALL RIGHTS RESERVED                                  *
     *                                                                             *
     ******************************************************************************/
    /*  ========================= TI_816X_BUILD case ==============================
                              |
                            IPC_BITS_OUT_A8 (BitStream)
                              |
                            IPC_BITS_IN (Video)
                              |
                            DEC (YUV420SP)
                              |
                            IPC_OUT (Video)
                              |
                            IPC_IN (Vpss)
                              |   (32 D1 + 10 720P + 6 1080P)
                            MP_SCLR (Vpss)
                              |
                             DUP
                   (48CH)    | |    (48CH)
             +---------------+ +-------------+
             |                               |
             |                               |
          SW Mosaic                       SW Mosaic
         (SC5 SC1 YUV422I)                (SC4 SC2 YUV422I)
            |  |                             |  |
            |  |                             |  |
           (DDR)(422I)                      (DDR)(422I)
              |                               |
      GRPX0   |                      GRPX1    |
         |    |                          |    |
         On-Chip HDMI                    Off-Chip HDMI
           1080p60                        1080p60
    */
    
    /* ========================= TI_814X_BUILD case ==============================
                              |
                            IPC_BITS_OUT_A8 (BitStream)
                              |
                            IPC_BITS_IN (Video)
                              |
                            DEC (YUV420SP)
                              |
                            IPC_OUT (Video)
                              |
                            IPC_IN (Vpss)
                              |   (16 channels)
                            MP_SCLR (Vpss)
                              |
                             DUP
                   (16CH)    | |    (16CH)
             +---------------+ +-------------+
             |                               |
             |                               |
          SW Mosaic                       SW Mosaic
         (SC5 YUV422I)                (SC5 YUV422I)
            |  |                             |  |
            |  |                             |  |
           (DDR)(422I)                      (DDR)(422I)
              |                               |
      GRPX0   |----Tied---|                   |
         |    |           |                   |
         On-Chip HDMI  Off-Chip HDMI         SDTV
           1080p60       1080p60
    */
    
    #include "mcfw/src_linux/mcfw_api/usecases/multich_common.h"
    #include "mcfw/src_linux/mcfw_api/usecases/multich_ipcbits.h"
    #include "mcfw/interfaces/link_api/system_tiler.h"
    #include "mcfw/interfaces/link_api/avsync_hlos.h"
    
    /* =============================================================================
     * Externs
     * =============================================================================
     */
    
    
    /* =============================================================================
     * Use case code
     * =============================================================================
     */
    
    
    
    #define MAX_DEC_OUT_FRAMES_PER_CH                           (5)
    #define MULTICH_VDEC_VDIS_IPCFRAMEEXPORT_NUM_CHANNELS       (16)
    #define MULTICH_VDEC_VDIS_IPCFRAMEEXPORT_FRAME_WIDTH        (1280)//(720)
    #define MULTICH_VDEC_VDIS_IPCFRAMEEXPORT_FRAME_HEIGHT       (720)//(480)
    #define MULTICH_NUM_SWMS_MAX_BUFFERS                        (7)
    
    #define     MAX_BUFFERING_QUEUE_LEN_PER_CH           (50)
    
    #define     BIT_BUF_LENGTH_LIMIT_FACTOR_CIF           (10)
    #define     BIT_BUF_LENGTH_LIMIT_FACTOR_SD            (6)
    #define     BIT_BUF_LENGTH_LIMIT_FACTOR_HD            (5)
    #define     BIT_BUF_LENGTH_LIMIT_FACTOR_720P          (4)
    #define     BIT_BUF_LENGTH_LIMIT_FACTOR_HMP           (4)
    
    
    #if defined(TI_814X_BUILD) || defined(TI_8107_BUILD)
    static SystemVideo_Ivahd2ChMap_Tbl systemVid_encDecIvaChMapTbl =
    {
        .isPopulated = 1,
        .ivaMap[0] =
        {
            .EncNumCh  = 1,
            .EncChList = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    
            .DecNumCh  = 16,
            .DecChList = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
        },
    };
    #define NUM_STATIC_CHANNELS   (6)
    #else
    /*
    Max channels per IVA-HD MUST be < 16,
    i.e total number of channels for decode can be 48.
    
    Example CH allocation for SD+HD,
    
    32CH SD    :  0 to 31
     6CH 1080P : 32 to 38
    10CH 720P  : 39 to 48
    
    */
    static SystemVideo_Ivahd2ChMap_Tbl systemVid_encDecIvaChMapTbl =
    {
        .isPopulated = 1,
        .ivaMap[0] =
        {
            .EncNumCh  = 0,
            .EncChList = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 , 0, 0},
    
            .DecNumCh  = 17,
            .DecChList = {   0,  3,  6,  9, 12, 15, 18, 21,
                            24, 27, 30, 33, 36, 39, 42, 45,
                            48
                         },
        },
        .ivaMap[1] =
        {
            .EncNumCh  = 0,
            .EncChList = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 , 0, 0},
    
            .DecNumCh  = 17,
            .DecChList = {   1,  4,  7, 10, 13, 16, 19, 22,
                            25, 28, 31, 34, 37, 40, 43, 46,
                            49
                         },
        },
        .ivaMap[2] =
        {
            .EncNumCh  = 0,
            .EncChList = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 , 0, 0},
    
            .DecNumCh  = 16,
            .DecChList = {   2,  5,  8, 11, 14, 17, 20, 23,
                            26, 29, 32, 35, 38, 41, 44, 47
                         },
        },
    };
    #define NUM_STATIC_CHANNELS   (8)
    #endif
    
    typedef struct {
    
        UInt32 dupId;
        UInt32 ipcOutVideoId;
        UInt32 ipcInVpssId;
    	UInt32 ipcOutVpssId;
    	//UInt32	_ipcOutVpssId = 0;
    	//UInt32 _ipcInVideoId = 0;
        UInt32 mergeId;
        Bool   enableVideoFrameExport;
        AvsyncLink_LinkSynchConfigParams   avsyncCfg[VDIS_DEV_MAX];
        UInt32 mpSclrId;
    	UInt32 ipcInVideoId;
    
    } MultiCh_VdecVdisObj;
    
    MultiCh_VdecVdisObj gMultiCh_VdecVdisObj;
    FILE	*_fout = NULL;
    
    static Void MultiCh_setIpcFramesOutInQueInfo(System_LinkQueInfo *inQueInfo)
    {
        Int i;
    
        inQueInfo->numCh = MULTICH_VDEC_VDIS_IPCFRAMEEXPORT_NUM_CHANNELS;
        for (i = 0; i < inQueInfo->numCh; i++)
        {
            inQueInfo->chInfo[i].bufType = SYSTEM_BUF_TYPE_VIDFRAME;
            inQueInfo->chInfo[i].dataFormat = SYSTEM_DF_YUV422I_YUYV;
            inQueInfo->chInfo[i].memType    = SYSTEM_MT_NONTILEDMEM;
            inQueInfo->chInfo[i].scanFormat = SYSTEM_SF_PROGRESSIVE;
            inQueInfo->chInfo[i].startX     = 0;
            inQueInfo->chInfo[i].startY     = 0;
            inQueInfo->chInfo[i].width      =
                       MULTICH_VDEC_VDIS_IPCFRAMEEXPORT_FRAME_WIDTH;
            inQueInfo->chInfo[i].height     =
                       MULTICH_VDEC_VDIS_IPCFRAMEEXPORT_FRAME_HEIGHT;
            inQueInfo->chInfo[i].pitch[0]   =
                       MULTICH_VDEC_VDIS_IPCFRAMEEXPORT_FRAME_WIDTH * 2;
            inQueInfo->chInfo[i].pitch[1]   = 0;
            inQueInfo->chInfo[i].pitch[2]   = 0;
        }
    }
    
    static
    Void mulich_vdec_vdis_set_avsync_vidque_prm(Avsync_SynchConfigParams *queCfg,
                                                Int chnum,
                                                UInt32 avsStartChNum,
                                                UInt32 avsEndChNum,
                                                VDIS_DEV vdDevId)
    {
        queCfg->chNum = chnum;
        queCfg->audioPresent = FALSE;
        if ((queCfg->chNum >= avsStartChNum)
            &&
            (queCfg->chNum <= avsEndChNum)
            &&
            (gVsysModuleContext.vsysConfig.enableAVsync))
        {
            queCfg->avsyncEnable = TRUE;
        }
        else
        {
            queCfg->avsyncEnable = FALSE;
        }
    
        queCfg->clkAdjustPolicy.refClkType = AVSYNC_REFCLKADJUST_NONE;
        queCfg->clkAdjustPolicy.clkAdjustLead = AVSYNC_VIDEO_TIMEBASESHIFT_MAX_LEAD_MS;
        queCfg->clkAdjustPolicy.clkAdjustLag  = AVSYNC_VIDEO_TIMEBASESHIFT_MAX_LAG_MS;
        queCfg->vidSynchPolicy.maxReplayLead  = AVSYNC_VIDEO_FUTURE_FRAME_DROP_THRESHOLD_MS;
        queCfg->vidSynchPolicy.playMaxLag  = 180;
        queCfg->vidSynchPolicy.playMaxLead = 0;
        queCfg->vidSynchPolicy.doMarginScaling = FALSE;
        queCfg->playTimerStartTimeout = 0;
        queCfg->playStartMode = AVSYNC_PLAYBACK_START_MODE_WAITSYNCH;
        queCfg->ptsInitMode   = AVSYNC_PTS_INIT_MODE_APP;
    }
    Void capture_encode_bitsWriteCbFxn(Ptr pPrm)
    {
        Bitstream_BufList bitsBuf;
        Bitstream_Buf *pBuf;
        Int32 frameId;
        Int32 status;
        unsigned long writeDataSize;
    #if ENABLE_TIME_BUFFER   || ENABLE_LOG_BUFFER 
        static unsigned long countImage = 0;
    #endif    
        /* Get buffer list from the IPC Link*/
        bitsBuf.numBufs = 0;
    	//printf(" Before IpcBitsInLink_getFullVideoBitStreamBufs\n");
        status = IpcBitsInLink_getFullVideoBitStreamBufs(gVencModuleContext.ipcBitsInHLOSId, &bitsBuf);
    	//printf(" After IpcBitsInLink_getFullVideoBitStreamBufs\n");
        if( (status == 0 ) && (bitsBuf.numBufs) && (_fout != NULL) )
        {
            for(frameId = 0; frameId < bitsBuf.numBufs ; frameId++ )
            {
                pBuf = bitsBuf.bufs[frameId];
                if( pBuf->fillLength > 0 )
                {
                    writeDataSize = fwrite(pBuf->addr, sizeof(char),pBuf->fillLength, _fout);
    		//printf("pBuf->temporalId   %d\n",pBuf->temporalId);
                    if( writeDataSize != pBuf->fillLength)
                    {
                        //fclose(_fout);
                        //_fout = NULL;
                        printf(" Error write : Closing file\n");
                    }
    #if ENABLE_TIME_BUFFER
                    printf("******************************\n");
                    printf("countImage %lu:%lu\n",countImage++,(unsigned long)bitsBuf.numBufs);
                    printf("timeStamp %lu\n",(unsigned long)pBuf->timeStamp);
                    printf("encodeTimeStamp %lu\n",(unsigned long)pBuf->encodeTimeStamp);
                    printf("isKeyFrame %lu\n",(unsigned long)pBuf->isKeyFrame);
    #endif                
    #if ENABLE_LOG_BUFFER
    		if((countImage++ %100)==0)
    		{
                    printf("******************************\n");
                    printf("countImage %lu\n",countImage);
                    printf("codingType %d\n",pBuf->codingType);
                    printf("channelNum %d\n",pBuf->channelNum);
                    printf("%d:%d\n",pBuf->frameWidth,pBuf->frameHeight);
                    printf("timeStamp %lu\n",(unsigned long)pBuf->timeStamp);
                    printf("capture timestamp up %lu\n",(unsigned long)pBuf->upperTimeStamp);
                    printf("capture timestamp low %lu\n",(unsigned long)pBuf->lowerTimeStamp);
                    printf("encodeTimeStamp %lu\n",(unsigned long)pBuf->encodeTimeStamp);
                    printf("isKeyFrame %lu\n",(unsigned long)pBuf->isKeyFrame);
                    printf("doNotDisplay %d\n",pBuf->doNotDisplay);
                    printf("seqId %d\n",pBuf->seqId);
                    printf("inputFileChanged %d\n",pBuf->inputFileChanged);
                    printf("flushFrame %d\n",pBuf->flushFrame);
                    printf("allocPoolID %d\n",pBuf->allocPoolID);
                    printf("temporalId %d\n",pBuf->temporalId);
                    printf("numTemporalLayerSetInCodec %d\n",pBuf->numTemporalLayerSetInCodec);
                    printf("bufSize %lu\n",(unsigned long)pBuf->bufSize);
                    printf("fillLength %lu\n",(unsigned long)pBuf->fillLength);
                    printf("startOffset %lu\n",(unsigned long)pBuf->startOffset);
                    printf("mvDataOffset %lu\n",(unsigned long)pBuf->mvDataOffset);
                    printf("mvDataFilledSize %lu\n",(unsigned long)pBuf->mvDataFilledSize);
                    printf("phyAddr 0x%08lX\n",(unsigned long)pBuf->phyAddr);
    		}
    #endif
                }
    
            }
        }
        /* Release buffer list back to the IPC Link*/
        /* On relese tout le temps même si pas de données dispo */
        IpcBitsInLink_putEmptyVideoBitStreamBufs(gVencModuleContext.ipcBitsInHLOSId, &bitsBuf);
        
    }
    void capture_encode_ipcBitsInitCreateParams_BitsInHLOS(IpcBitsInLinkHLOS_CreateParams *cp)
    {
    	VENC_CALLBACK_S *callback;
        Ptr cbCtx;
    	Venc_getCallbackInfo(&callback, &cbCtx);
        //ipcBitsInHostPrm.cbFxn = callback->newDataAvailableCb;
        //ipcBitsInHostPrm.cbCtx = cbCtx;
        cp->baseCreateParams.noNotifyMode = FALSE; //FALSE;
        cp->cbFxn = capture_encode_bitsWriteCbFxn;
        cp->cbCtx = cbCtx;//NULL;
        cp->baseCreateParams.notifyNextLink = FALSE;
        /* Previous link of bitsInHLOS is bitsOutRTOS. So, notifyPrevLink
         * should be set to false if bitsInHLOS is to operate in
         * NO_NOTIFY_MODE
         */
        cp->baseCreateParams.notifyPrevLink = TRUE;//TRUE;
    }
    static
    Void mulich_vdec_vdis_set_avsync_prm(AvsyncLink_LinkSynchConfigParams *avsyncPrm,
                                         UInt32 swMsIdx,
                                         VDIS_DEV vdDevId)
    {
        Int i;
        Int32 status;
    
        Vdis_getAvsyncConfig(vdDevId,avsyncPrm);
        avsyncPrm->displayLinkID        = Vdis_getDisplayId(vdDevId);
        avsyncPrm->videoSynchLinkID = gVdisModuleContext.swMsId[swMsIdx];
        avsyncPrm->numCh            = gVdecModuleContext.vdecConfig.numChn;
        avsyncPrm->syncMasterChnum =  AVSYNC_INVALID_CHNUM;
        for (i = 0; i < avsyncPrm->numCh;i++)
        {
            mulich_vdec_vdis_set_avsync_vidque_prm(&avsyncPrm->queCfg[i],
                                                   i,
                                                   0,
                                                   (0 + gVdecModuleContext.vdecConfig.numChn),
                                                   vdDevId);
        }
        if (0 == swMsIdx)
        {
            Vdis_setAvsyncConfig(VDIS_DEV_HDMI,avsyncPrm);
        }
        else
        {
            Vdis_setAvsyncConfig(VDIS_DEV_SD,avsyncPrm);
        }
    
        status = Avsync_configSyncConfigInfo(avsyncPrm);
        OSA_assert(status == 0);
    }
    
    Void MultiCh_createVdecVdis()
    {
        IpcBitsOutLinkHLOS_CreateParams   ipcBitsOutHostPrm;//bitstream A8 out
    	IpcBitsInLinkHLOS_CreateParams    ipcBitsInHostPrm;//bitstream A8 in 1
        IpcBitsInLinkRTOS_CreateParams    ipcBitsInVideoPrm;//bitstream M3 in	
        IpcBitsOutLinkRTOS_CreateParams   ipcBitsOutVideoPrm;//bitstream M3 out  1     
    
        DecLink_CreateParams        decPrm;
        IpcLink_CreateParams        ipcOutVideoPrm;
        IpcLink_CreateParams        ipcInVpssPrm;
    	IpcLink_CreateParams        ipcOutVpssPrm;//1
    	IpcLink_CreateParams        ipcInVideoPrm;//1
    
        DupLink_CreateParams        dupPrm;//we will send one side to display and other one to video encoding
        static SwMsLink_CreateParams       swMsPrm[VDIS_DEV_MAX];
        DisplayLink_CreateParams    displayPrm[VDIS_DEV_MAX];
        IpcFramesOutLinkHLOS_CreateParams  ipcFramesOutHostPrm;
        IpcFramesInLinkRTOS_CreateParams   ipcFramesInVpssFromHostPrm;
    
        MergeLink_CreateParams             mergePrm;
        MpSclrLink_CreateParams            mpSclrPrm;
    	EncLink_CreateParams            encPrm;	
        
    
        UInt32 i;
        UInt32 enableGrpx;
        Bool tilerEnable;
        Bool enableVideoFrameExport;
    	Bool enableVideoEncode;
    
    	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(IpcBitsInLinkRTOS_CreateParams,ipcBitsInVideoPrm);
    
    	 MULTICH_INIT_STRUCT(IpcBitsInLinkHLOS_CreateParams,ipcBitsInHostPrm);
         MULTICH_INIT_STRUCT(IpcBitsOutLinkRTOS_CreateParams,ipcBitsOutVideoPrm);
    
        MULTICH_INIT_STRUCT(DecLink_CreateParams, decPrm);
    	MULTICH_INIT_STRUCT(EncLink_CreateParams, encPrm);
        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_INIT_STRUCT(MpSclrLink_CreateParams, mpSclrPrm);
    
        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 defined(TI_814X_BUILD) || defined(TI_8107_BUILD)
        enableGrpx   = FALSE;
    #else
        enableGrpx   = TRUE;
    #endif
    
        tilerEnable  = FALSE;
    
        if (tilerEnable == FALSE)
        {
            /* Disable tiler allocator for this usecase
             * for that tiler memory can be reused for
             * non-tiled allocation
             */
            SystemTiler_disableAllocator();
        }
        else
        {
            SystemTiler_BucketGeometry_t bucketRes;
    
            bucketRes.bucketWidth  = SYSTEM_TILER_ALLOCATOR_BUCKET_WIDTH_DEFAULT;
            bucketRes.bucketHeight = SYSTEM_TILER_ALLOCATOR_BUCKET_HEIGHT_DEFAULT;
            bucketRes.minResolution = SYSTEM_TILER_RESOLUTION_CIF;
            bucketRes.setSingleBucketGeometry = FALSE;
            SystemTiler_setBucketGeometry(&bucketRes);
        }
    	_fout = NULL;
        if( (_fout = fopen("/data/test2.264","wb")) == NULL )
        {
            printf("error open write file //data//test2.264 \n");		
            return ;
        }
        enableVideoFrameExport = FALSE;//FALSE;
    	enableVideoEncode = TRUE;
    
        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;
    
    	gVencModuleContext.encId			= SYSTEM_LINK_ID_VENC_0;
    	gVencModuleContext.ipcBitsInHLOSId   = SYSTEM_HOST_LINK_ID_IPC_BITS_IN_0;
        gVencModuleContext.ipcBitsOutRTOSId = SYSTEM_VIDEO_LINK_ID_IPC_BITS_OUT_0;
    
    	gMultiCh_VdecVdisObj.ipcOutVpssId =		SYSTEM_VPSS_LINK_ID_IPC_FRAMES_OUT_0 ;//SYSTEM_VPSS_LINK_ID_IPC_OUT_M3_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;
        gMultiCh_VdecVdisObj.mpSclrId       = SYSTEM_LINK_ID_MP_SCLR_INST_0;
        gVdisModuleContext.mpSclrId         = SYSTEM_LINK_ID_MP_SCLR_INST_0;
        gVdisModuleContext.swMsId[0]        = SYSTEM_LINK_ID_SW_MS_MULTI_INST_0;
    	gMultiCh_VdecVdisObj.ipcInVideoId   = SYSTEM_VIDEO_LINK_ID_IPC_FRAMES_IN_0;//SYSTEM_VIDEO_LINK_ID_IPC_IN_M3_0;
        gVdisModuleContext.displayId[0]     = SYSTEM_LINK_ID_DISPLAY_0; // ON AND OFF CHIP HDMI
    
        if (gVsysModuleContext.vsysConfig.numDisplays > 1)
        {
            gVdisModuleContext.swMsId[1]        = SYSTEM_LINK_ID_SW_MS_MULTI_INST_1;
    #if defined(TI_814X_BUILD) || defined(TI_8107_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;
    #if defined(TI_814X_BUILD) || defined(TI_8107_BUILD)
            gVdisModuleContext.grpxId[1]    = SYSTEM_LINK_ID_INVALID;
    #else
            gVdisModuleContext.grpxId[1]    = SYSTEM_LINK_ID_GRPX_1;
    #endif
        }
    
        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
    
            ipcBitsOutHostPrm.maxQueueDepth[i] = MAX_BUFFERING_QUEUE_LEN_PER_CH;
            ipcBitsOutHostPrm.chMaxReqBufSize[i] = 
                    (ipcBitsOutHostPrm.inQueInfo.chInfo[i].width * ipcBitsOutHostPrm.inQueInfo.chInfo[i].height); 
            ipcBitsOutHostPrm.totalBitStreamBufferSize [i] = 
                    (ipcBitsOutHostPrm.chMaxReqBufSize[i] * BIT_BUF_LENGTH_LIMIT_FACTOR_HD);
    
        }
    
        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;
    
        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;
            else if(gVdecModuleContext.vdecConfig.decChannelParams[i].isCodec == VDEC_CHN_MPEG2)
                decPrm.chCreateParams[i].format                 = IVIDEO_MPEG2HP;
    
            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;
            if (gVdecModuleContext.vdecConfig.decChannelParams[i].fieldPicture)
            {
                OSA_printf("MULTICH_VDEC_VDIS:INFO ChId[%d] configured for field picture\n",i);
                decPrm.chCreateParams[i].processCallLevel   = VDEC_FIELDLEVELPROCESSCALL;
            }
            else
            {
                decPrm.chCreateParams[i].processCallLevel   = VDEC_FRAMELEVELPROCESSCALL;
            }
            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;
            if (FALSE == tilerEnable)
            {
            	decPrm.chCreateParams[i].tilerEnable = FALSE;
            }
            else
            {
            	decPrm.chCreateParams[i].tilerEnable = gVdecModuleContext.vdecConfig.decChannelParams[i].tilerEnable;
            }
            decPrm.chCreateParams[i].enableWaterMarking = 
                gVdecModuleContext.vdecConfig.decChannelParams[i].enableWaterMarking;
        }
    
        decPrm.inQueParams.prevLinkId       = gVdecModuleContext.ipcBitsInRTOSId;
        decPrm.inQueParams.prevLinkQueId    = 0;
        decPrm.outQueParams.nextLink        = gMultiCh_VdecVdisObj.ipcOutVideoId;
    	if(enableVideoEncode)
    	{
    	encPrm.inQueParams.prevLinkId   = gMultiCh_VdecVdisObj.ipcInVideoId;
        encPrm.inQueParams.prevLinkQueId= 0;
        encPrm.outQueParams.nextLink    = gVencModuleContext.ipcBitsOutRTOSId;
    	}
        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;
    		if(enableVideoEncode)
    		{
            ipcFramesInVpssFromHostPrm.baseCreateParams.outQueParams[0].nextLink = gMultiCh_VdecVdisObj.ipcOutVpssId;
    		mpSclrPrm.inQueParams.prevLinkId        = gMultiCh_VdecVdisObj.ipcInVpssId;
            ipcInVpssPrm.outQueParams[0].nextLink   = gMultiCh_VdecVdisObj.mpSclrId;
    		}
    		else
    		{
    		 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.mpSclrId;
            mergePrm.notifyNextLink               = TRUE;
            mpSclrPrm.inQueParams.prevLinkId      = gMultiCh_VdecVdisObj.mergeId;
    		}
        }
        else
        {
            mpSclrPrm.inQueParams.prevLinkId        = gMultiCh_VdecVdisObj.ipcInVpssId;
            ipcInVpssPrm.outQueParams[0].nextLink   = gMultiCh_VdecVdisObj.mpSclrId;
    
        }
    #if defined(TI_814X_BUILD) || defined(TI_8107_BUILD)
        mpSclrPrm.pathId = MP_SCLR_LINK_SEC0_SC3_VIP0;
    #else
        mpSclrPrm.pathId = MP_SCLR_LINK_SEC1_SC4_VIP1;
    #endif
    OSA_printf("XAXAXAXAXAXAXAXAXAX\n");
        mpSclrPrm.numCh = 4;
        mpSclrPrm.enableLineSkip = FALSE;
    
        mpSclrPrm.outQueParams.nextLink       = gMultiCh_VdecVdisObj.dupId;
        dupPrm.inQueParams.prevLinkId         = gMultiCh_VdecVdisObj.mpSclrId;
    
        dupPrm.inQueParams.prevLinkQueId      = 0;
        dupPrm.numOutQue                      = 2;//here we send one to display - one to encoder//gVsysModuleContext.vsysConfig.numDisplays;
        dupPrm.outQueParams[0].nextLink       = gVdisModuleContext.swMsId[0];
    	if(enableVideoEncode)
    	{
    		if (enableVideoFrameExport)
    			dupPrm.outQueParams[1].nextLink       = gVdisModuleContext.swMsId[1];
    		else
    			dupPrm.outQueParams[1].nextLink       = gMultiCh_VdecVdisObj.ipcOutVpssId;
    	}
    	else
        dupPrm.outQueParams[1].nextLink       = gVdisModuleContext.swMsId[1];
        dupPrm.notifyNextLink                 = TRUE;
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    	if(enableVideoEncode)
    	{
    if (enableVideoFrameExport)
    {
    	 ipcOutVpssPrm.inQueParams.prevLinkId    = gVdisModuleContext.ipcFramesInVpssFromHostId;//gMultiCh_VdecVdisObj.dupId;
    	 ipcOutVpssPrm.inQueParams.prevLinkQueId = 0;
    	}
    else
    {
    	ipcOutVpssPrm.inQueParams.prevLinkId    = gMultiCh_VdecVdisObj.dupId;
    	ipcOutVpssPrm.inQueParams.prevLinkQueId = 1;
    }
    
        ipcOutVpssPrm.inQueParams.prevLinkQueId = 0;
    	ipcOutVpssPrm.numOutQue                 = 1;
        ipcOutVpssPrm.outQueParams[0].nextLink     = gMultiCh_VdecVdisObj.ipcInVideoId;
        ipcOutVpssPrm.notifyNextLink            = TRUE;//FALSE;
        ipcOutVpssPrm.notifyPrevLink            = TRUE;
        ipcOutVpssPrm.noNotifyMode              = FALSE;//TRUE;
    	
    	 ipcInVideoPrm.inQueParams.prevLinkId    = gMultiCh_VdecVdisObj.ipcOutVpssId;
        ipcInVideoPrm.inQueParams.prevLinkQueId = 0;
        ipcInVideoPrm.numOutQue                 = 1;
        ipcInVideoPrm.outQueParams[0].nextLink     = gVencModuleContext.encId;
        ipcInVideoPrm.notifyNextLink            = TRUE;
        ipcInVideoPrm.notifyPrevLink            = TRUE;//FALSE;
        ipcInVideoPrm.noNotifyMode              = FALSE;//TRUE;
    
        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.baseCreateParams.inQueParams.prevLinkId    = gVencModuleContext.ipcBitsOutRTOSId;
        ipcBitsInHostPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
        ipcBitsInHostPrm.baseCreateParams.numOutQue                 = 1;
        ipcBitsInHostPrm.baseCreateParams.outQueParams[0].nextLink   = SYSTEM_LINK_ID_INVALID;
    	capture_encode_ipcBitsInitCreateParams_BitsInHLOS(&ipcBitsInHostPrm);
       // MultiCh_ipcBitsInitCreateParams_BitsInHLOS(&ipcBitsInHostPrm);
    
    	EncLink_ChCreateParams *pLinkChPrm;
            EncLink_ChDynamicParams *pLinkDynPrm;
            VENC_CHN_DYNAMIC_PARAM_S *pDynPrm;
            VENC_CHN_PARAMS_S *pChPrm;
    
        EncLink_CreateParams_Init(&encPrm);
    
            encPrm.numBufPerCh[0] = 6;        
    
            /* 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              = VCODEC_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;
    			/*Note:Specific for h264 Encoder: Enabling this flag adds svc extension
              headers to the stream, not all decoders are generally able to play back such a stream. */
        /* Needs to be enabled to IH264_SVC_EXTENSION_FLAG_ENABLE for the
              svc extension headers to be present in the stream*/
       // pLinkChPrm->enableSVCExtensionFlag =VENC_IH264_SVC_EXTENSION_FLAG_ENABLE;
    
        /** Note: For the encoder to give out frames with SVC-T properties,
                 number of layers needs to be increased as per requirement.
                 A flag enableLayerWrite needs to be set if for any channel the Layer is increased to beyond 1.
                 This check has also been done for Channel 0, just before VcapVencVdecVdis_ipcBitsInit call.
    
                 For example for Channel 0 it has been set to LAYERS_4,
                 file stream dump will generate four(Base + 3) files with differing frame-rates**/
        /** WARNING: SVC-T cannot be used if B Frame is enabled */
       // pLinkChPrm->numTemporalLayer = VENC_TEMPORAL_LAYERS_2;
    
            } 
    	}//if(enableVideoEncode)
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    #if defined(TI_814X_BUILD) || defined(TI_8107_BUILD)
    
        swMsPrm[0].numSwMsInst = 1;
        swMsPrm[0].swMsInstId[0]        = SYSTEM_SW_MS_SC_INST_DEIHQ_SC_NO_DEI;
    
        swMsPrm[0].swMsInstStartWin[0]  = 0;
        swMsPrm[0].swMsInstStartWin[1]  = 10;
    
        swMsPrm[1].numSwMsInst = 1;
        swMsPrm[1].swMsInstId[0]        = SYSTEM_SW_MS_SC_INST_DEI_SC_NO_DEI;
    
        swMsPrm[1].swMsInstStartWin[0]  = 0;
        swMsPrm[1].swMsInstStartWin[1]  = 10;
    
        swMsPrm[0].enableProcessTieWithDisplay = TRUE;
        swMsPrm[1].enableProcessTieWithDisplay = FALSE;
    
        /* We do not require dual output, this free up SC3 scalar */
        swMsPrm[0].includeVipScInDrvPath = FALSE;
        swMsPrm[1].includeVipScInDrvPath = FALSE;
    #else
        swMsPrm[0].swMsInstId[0]        = SYSTEM_SW_MS_SC_INST_DEI_SC_NO_DEI;
        swMsPrm[0].swMsInstId[1]        = SYSTEM_SW_MS_SC_INST_VIP1_SC;
    
        swMsPrm[1].swMsInstId[0]        = SYSTEM_SW_MS_SC_INST_DEIHQ_SC_NO_DEI;
        swMsPrm[1].swMsInstId[1]        = SYSTEM_SW_MS_SC_INST_VIP0_SC;
    
        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];
    
        swMsPrm[0].enableProcessTieWithDisplay = TRUE;
        swMsPrm[1].enableProcessTieWithDisplay = TRUE;
    
    #endif
        for(i=0; i<gVsysModuleContext.vsysConfig.numDisplays; i++)
        {
            VDIS_DEV vdDevId = VDIS_DEV_HDMI;
    
            swMsPrm[i].inQueParams.prevLinkId     = gMultiCh_VdecVdisObj.dupId;
            swMsPrm[i].inQueParams.prevLinkQueId  = i;
            swMsPrm[i].outQueParams.nextLink      = gVdisModuleContext.displayId[i];
            swMsPrm[i].numOutBuf                 = MULTICH_NUM_SWMS_MAX_BUFFERS;
    
            /* 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)
            {
                vdDevId = VDIS_DEV_HDMI;
                swMsPrm[i].maxOutRes              = VSYS_STD_1080P_60;
                swMsPrm[i].initOutRes             = gVdisModuleContext.vdisConfig.deviceParams[VDIS_DEV_HDMI].resolution;
            }
            else if (i == 1)
            {
    #if defined(TI_814X_BUILD) || defined(TI_8107_BUILD)
                vdDevId = VDIS_DEV_SD;
                swMsPrm[i].maxOutRes              = VSYS_STD_PAL;
                swMsPrm[i].outQueParams.nextLink  = SYSTEM_LINK_ID_DISPLAY_2;
                swMsPrm[i].initOutRes             = gVdisModuleContext.vdisConfig.deviceParams[VDIS_DEV_SD].resolution;
    
    #else
                vdDevId = VDIS_DEV_DVO2;
                swMsPrm[i].maxOutRes              = VSYS_STD_1080P_60;
                swMsPrm[i].initOutRes             = 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(vdDevId, &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].initOutRes;
            if (i == 1)
    #if defined(TI_814X_BUILD) || defined(TI_8107_BUILD)
                            displayPrm[i].displayRes            = gVdisModuleContext.vdisConfig.deviceParams[VDIS_DEV_SD].resolution;
    #else
                            displayPrm[i].displayRes            = gVdisModuleContext.vdisConfig.deviceParams[VDIS_DEV_DVO2].resolution;
    #endif
            mulich_vdec_vdis_set_avsync_prm(&gMultiCh_VdecVdisObj.avsyncCfg[i],i,vdDevId);
        }
    
        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(enableVideoEncode)
    	//System_linkCreate(gMultiCh_VdecVdisObj.ipcInVideoId , &ipcInVideoPrm , sizeof(ipcInVideoPrm) );
    
        
    	
    
        if (enableVideoFrameExport)
        {
            System_linkCreate(gVdisModuleContext.ipcFramesOutHostId     , &ipcFramesOutHostPrm    , sizeof(ipcFramesOutHostPrm));
            System_linkCreate(gVdisModuleContext.ipcFramesInVpssFromHostId     , &ipcFramesInVpssFromHostPrm    , sizeof(ipcFramesInVpssFromHostPrm));
    		if(!enableVideoEncode)
            System_linkCreate(gMultiCh_VdecVdisObj.mergeId,&mergePrm,sizeof(mergePrm));
        }
    
        System_linkCreate(gMultiCh_VdecVdisObj.mpSclrId, &mpSclrPrm, sizeof(mpSclrPrm));
        System_linkCreate(gMultiCh_VdecVdisObj.dupId     , &dupPrm    , sizeof(dupPrm));
    
    	
    
       
    	if(enableVideoEncode)
    	{
    	System_linkCreate(gMultiCh_VdecVdisObj.ipcOutVpssId , &ipcOutVpssPrm , sizeof(ipcOutVpssPrm) ); 
    	System_linkCreate(gMultiCh_VdecVdisObj.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));
    	}
    	 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;
        {
            MultiCh_setDec2DispMap(VDIS_DEV_HDMI,gVdecModuleContext.vdecConfig.numChn,0,0);
            #if defined(TI_814X_BUILD) || defined(TI_8107_BUILD)
            MultiCh_setDec2DispMap(VDIS_DEV_SD,gVdecModuleContext.vdecConfig.numChn,0,0);
            #else
            MultiCh_setDec2DispMap(VDIS_DEV_HDCOMP,gVdecModuleContext.vdecConfig.numChn,0,0);
            #endif
       }
    
    }
    
    Void MultiCh_deleteVdecVdis()
    {
        Bool tilerEnable;
    
        tilerEnable  = FALSE;
    
        if( _fout != NULL )
            fclose(_fout);
    
        /* delete can be done in any order */
        Vdec_delete();
        Vdis_delete();
    
        if (gMultiCh_VdecVdisObj.enableVideoFrameExport)
        {
            System_linkDelete(gMultiCh_VdecVdisObj.mergeId);
        }
    
        System_linkDelete(gMultiCh_VdecVdisObj.mpSclrId);
        System_linkDelete(gMultiCh_VdecVdisObj.dupId);
        System_linkDelete(gMultiCh_VdecVdisObj.ipcOutVideoId );
        System_linkDelete(gMultiCh_VdecVdisObj.ipcInVpssId );
    
        /* Print the HWI, SWI and all tasks load */
        /* Reset the accumulated timer ticks */
        MultiCh_prfLoadCalcEnable(FALSE, TRUE, FALSE);
    
    
        if (tilerEnable == FALSE)
        {
            /* Disable tiler allocator for this usecase
             * for that tiler memory can be reused for
             * non-tiled allocation
             */
            SystemTiler_enableAllocator();
        }
        else
        {
            SystemTiler_BucketGeometry_t bucketRes;
    
            bucketRes.minResolution = SYSTEM_TILER_RESOLUTION_CIF;
            bucketRes.setSingleBucketGeometry = TRUE;
            SystemTiler_setBucketGeometry(&bucketRes);
        }
    
    }