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.

A8 send frames to m3video can not work correct?

/** ==================================================================
 *  @file   ti_vcam.c
 *
 *  @path    ipnc_mcfw/mcfw/src_linux/mcfw_api/
 *
 *  @desc   This  File contains.
 * ===================================================================
 *  Copyright (c) Texas Instruments Inc 2011, 2012
 *
 *  Use of this software is controlled by the terms and conditions found
 *  in the license agreement under which this software has been supplied
 * ===================================================================*/

#include "ti_vsys_priv.h"
#include "ti_vcam_priv.h"

/* =============================================================================
 * Globals
 * ============================================================================= */

VCAM_MODULE_CONTEXT_S gVcamModuleContext;

/* =============================================================================
 * Vcam module APIs
 * ============================================================================= */

/* ===================================================================
 *  @func     Vcam_params_init
 *
 *  @desc     Function does the following
 *
 *  @modif    This function modifies the following structures
 *
 *  @inputs   This function takes the following inputs
 *            <argument name>
 *            Description of usage
 *            <argument name>
 *            Description of usage
 *
 *  @outputs  <argument name>
 *            Description of usage
 *
 *  @return   Return value of this function if any
 *  ==================================================================
 */
Void Vcam_params_init(VCAM_PARAMS_S * pContext)
{
    UInt16 devId, chnId, strmId;

    for (devId = 0; devId < VCAM_DEV_MAX; devId++)
    {
        pContext->deviceParams[devId].portEnable = FALSE;
        pContext->deviceParams[devId].portMode = VCAM_MODE_YUV420;
        pContext->deviceParams[devId].dataFormat =
            VCAM_MULTICHN_OPTION_SINGLE_CHN;
        pContext->deviceParams[devId].signalType = VS_AUTO_DETECT;
    }
    for (chnId = 0; chnId < VCAM_CHN_MAX; chnId++)
    {
        for (strmId = 0; strmId < VCAM_STRM_MAX; strmId++)
        {
            pContext->channelParams[chnId].strmEnable[strmId] = FALSE;
            pContext->channelParams[chnId].strmFormat[strmId] = VF_YUV422I_UYVY;
            pContext->channelParams[chnId].strmResolution[strmId].start_X = 0;
            pContext->channelParams[chnId].strmResolution[strmId].start_Y = 0;
            pContext->channelParams[chnId].strmResolution[strmId].width = 0;
            pContext->channelParams[chnId].strmResolution[strmId].height = 0;
        }
        pContext->channelParams[chnId].deviceId = 0;
        pContext->channelParams[chnId].dynamicParams.contrast = 0;
        pContext->channelParams[chnId].dynamicParams.saturation = 0;
        pContext->channelParams[chnId].dynamicParams.brightness = 0;
        pContext->channelParams[chnId].dynamicParams.hue = 0;
    }
}

/* ===================================================================
 *  @func     Vcam_init
 *
 *  @desc     Function does the following
 *
 *  @modif    This function modifies the following structures
 *
 *  @inputs   This function takes the following inputs
 *            <argument name>
 *            Description of usage
 *            <argument name>
 *            Description of usage
 *
 *  @outputs  <argument name>
 *            Description of usage
 *
 *  @return   Return value of this function if any
 *  ==================================================================
 */
Int32 Vcam_init(VCAM_PARAMS_S * pContext)
{
    UInt16 devId, chnId, strmId, deiId;

    /* Mark all links related to camera as invalid by default, they will be
     * setup with valid IDs later */
    gVcamModuleContext.cameraId           = SYSTEM_LINK_ID_INVALID;
    gVcamModuleContext.osdId              = SYSTEM_LINK_ID_INVALID;
    gVcamModuleContext.nsfId              = SYSTEM_LINK_ID_INVALID;
	gVcamModuleContext.vnfId              = SYSTEM_LINK_ID_INVALID;
    gVcamModuleContext.nullSrcId          = SYSTEM_LINK_ID_INVALID;
    gVcamModuleContext.ipcFramesOutVpssId = SYSTEM_LINK_ID_INVALID;
    gVcamModuleContext.ipcFramesInDspId   = SYSTEM_LINK_ID_INVALID;
    gVcamModuleContext.glbceId            = SYSTEM_LINK_ID_INVALID;
    gVcamModuleContext.ipcFramesOutHostId            = SYSTEM_LINK_ID_INVALID;

    for (deiId = 0; deiId < MAX_DEI_LINK; deiId++)
    {
        gVcamModuleContext.deiId[deiId] = SYSTEM_LINK_ID_INVALID;
    }
    gVcamModuleContext.ipcFramesOutVpssToHostId = SYSTEM_LINK_ID_INVALID;
    gVcamModuleContext.ipcFramesInHostId = SYSTEM_LINK_ID_INVALID;

    /* initialize counters */
    gVcamModuleContext.numDevices = 0;
    gVcamModuleContext.numChannels = 0;

    if (pContext == NULL)
    {
        Vcam_params_init(&gVcamModuleContext.vcamConfig);
    }
    else
    {
        for (devId = 0; devId < VCAM_DEV_MAX; devId++)
        {
            if (pContext->deviceParams[devId].portEnable)
            {
                gVcamModuleContext.numDevices++;
            }
        }

        for (chnId = 0; chnId < VCAM_CHN_MAX; chnId++)
        {
            for (strmId = 0; strmId < VCAM_STRM_MAX; strmId++)
            {
                if (pContext->channelParams[chnId].strmEnable[strmId])
                {
                    gVcamModuleContext.numChannels++;
                }
            }
        }

        memcpy(&gVcamModuleContext.vcamConfig, pContext, sizeof(VCAM_PARAMS_S));
    }
    return 0;
}

/* ===================================================================
 *  @func     Vcam_exit
 *
 *  @desc     Function does the following
 *
 *  @modif    This function modifies the following structures
 *
 *  @inputs   This function takes the following inputs
 *            <argument name>
 *            Description of usage
 *            <argument name>
 *            Description of usage
 *
 *  @outputs  <argument name>
 *            Description of usage
 *
 *  @return   Return value of this function if any
 *  ==================================================================
 */
Void Vcam_exit()
{
    /* Empty for now */
}

/* ===================================================================
 *  @func     Vcam_start
 *
 *  @desc     Function does the following
 *
 *  @modif    This function modifies the following structures
 *
 *  @inputs   This function takes the following inputs
 *            <argument name>
 *            Description of usage
 *            <argument name>
 *            Description of usage
 *
 *  @outputs  <argument name>
 *            Description of usage
 *
 *  @return   Return value of this function if any
 *  ==================================================================
 */
Int32 Vcam_start()
{
    UInt32 deiId;

    /* start can happen in any order, except its recommended to start camera
     * Link the last */
    if (gVcamModuleContext.ipcFramesOutVpssToHostId != SYSTEM_LINK_ID_INVALID)
    {
        System_linkStart(gVcamModuleContext.ipcFramesOutVpssToHostId);
    }
	

    if (gVcamModuleContext.ipcFramesInHostId != SYSTEM_LINK_ID_INVALID)
    {
        System_linkStart(gVcamModuleContext.ipcFramesInHostId);
    }
//	if( gVcamModuleContext.ipcFramesOutHostId!=SYSTEM_LINK_ID_INVALID)
//		System_linkStart(gVcamModuleContext.ipcFramesOutHostId);

    /* start can happen in any order, except its recommended to start camera
     * Link the last */
    if (gVcamModuleContext.nsfId != SYSTEM_LINK_ID_INVALID)
    {
        System_linkStart(gVcamModuleContext.nsfId);
    }

    /* start can happen in any order, except its recommended to start camera
     * Link the last */
    if (gVcamModuleContext.vnfId != SYSTEM_LINK_ID_INVALID)
    {
        System_linkStart(gVcamModuleContext.nsfId);
        System_linkStart(gVcamModuleContext.vnfId);
    }

    /* start can happen in any order, except its recommended to start camera
     * Link the last */
    if (gVcamModuleContext.osdId != SYSTEM_LINK_ID_INVALID)
    {
        if (gVcamModuleContext.ipcFramesOutVpssId != SYSTEM_LINK_ID_INVALID)
        {
			System_linkStart(gVcamModuleContext.nsfId);
            System_linkStart(gVcamModuleContext.ipcFramesOutVpssId);
        }
        if (gVcamModuleContext.ipcFramesInDspId != SYSTEM_LINK_ID_INVALID)
        {
			System_linkStart(gVcamModuleContext.nsfId);
            System_linkStart(gVcamModuleContext.ipcFramesInDspId);
        }
        System_linkStart(gVcamModuleContext.osdId);
    }

    for (deiId = 0; deiId < MAX_DEI_LINK; deiId++)
    {
        if (gVcamModuleContext.deiId[deiId] != SYSTEM_LINK_ID_INVALID)
        {
			System_linkStart(gVcamModuleContext.nsfId);
            System_linkStart(gVcamModuleContext.deiId[deiId]);
        }
    }
    if (gVcamModuleContext.nullSrcId != SYSTEM_LINK_ID_INVALID)
    {
        System_linkStart(gVcamModuleContext.nullSrcId);
    }

    /* Start taking CPU load just before starting of camera link */
    MultiCh_prfLoadCalcEnable(TRUE, FALSE, FALSE);

    if (gVcamModuleContext.cameraId != SYSTEM_LINK_ID_INVALID)
    {
        System_linkStart(gVcamModuleContext.cameraId);
    }
/*
	VCAM_CHN_DYNAMIC_PARAM_S params = { 0 };
	 memset(&params, 0, sizeof(params));
	 Venc_setInputFrameRate(0, 25);
	 params.frameRate = 25;
	 Venc_setDynamicParam(0, 0, &params, VENC_FRAMERATE);
	 Venc_setDynamicParam(1, 0, &params, VENC_FRAMERATE);
*/								


#if defined(CAPTURE_DISPLAY_MODE) || defined(ENC_A8_DEC_USE_CASE)
    
	
	
	VCAM_CHN_DYNAMIC_PARAM_S params = { 0 };
    params.brightness = 128;
    Vcam_setDynamicParamChn(0, &params, VCAM_BRIGHTNESS);
    params.contrast = 128;
    Vcam_setDynamicParamChn(0, &params, VCAM_CONTRAST);
    params.saturation = 128;
    Vcam_setDynamicParamChn(0, &params, VCAM_SATURATION);
    params.sharpness = 128;
    Vcam_setDynamicParamChn(0, &params, VCAM_SHARPNESS);
#endif

    return 0;
}

/* ===================================================================
 *  @func     Vcam_stop
 *
 *  @desc     Function does the following
 *
 *  @modif    This function modifies the following structures
 *
 *  @inputs   This function takes the following inputs
 *            <argument name>
 *            Description of usage
 *            <argument name>
 *            Description of usage
 *
 *  @outputs  <argument name>
 *            Description of usage
 *
 *  @return   Return value of this function if any
 *  ==================================================================
 */
Int32 Vcam_stop()
{
    UInt32 deiId;

    /* stop needs to be in the reseverse order of create */

    if (gVcamModuleContext.cameraId != SYSTEM_LINK_ID_INVALID)
    {
        System_linkStop(gVcamModuleContext.cameraId);
    }

    if (gVcamModuleContext.nullSrcId != SYSTEM_LINK_ID_INVALID)
    {
        System_linkStop(gVcamModuleContext.nullSrcId);
    }

    if (gVcamModuleContext.nsfId != SYSTEM_LINK_ID_INVALID)
    {
        System_linkStop(gVcamModuleContext.nsfId);
    }

    if (gVcamModuleContext.vnfId != SYSTEM_LINK_ID_INVALID)
    {
        System_linkStop(gVcamModuleContext.vnfId);
    }

    if (gVcamModuleContext.ipcFramesOutVpssId != SYSTEM_LINK_ID_INVALID)
    {
        System_linkStop(gVcamModuleContext.ipcFramesOutVpssId);
    }

    if (gVcamModuleContext.ipcFramesInDspId != SYSTEM_LINK_ID_INVALID)
    {
        System_linkStop(gVcamModuleContext.ipcFramesInDspId);
    }

    if (gVcamModuleContext.osdId != SYSTEM_LINK_ID_INVALID)
    {
        System_linkStop(gVcamModuleContext.osdId);
    }

    for (deiId = 0; deiId < gVsysModuleContext.vsysConfig.numDeis; deiId++)
    {
        if (gVcamModuleContext.deiId[deiId] != SYSTEM_LINK_ID_INVALID)
        {
            System_linkStop(gVcamModuleContext.deiId[deiId]);
        }
    }

    if (gVcamModuleContext.ipcFramesOutVpssToHostId != SYSTEM_LINK_ID_INVALID)
    {
        System_linkStop(gVcamModuleContext.ipcFramesOutVpssToHostId);
    }

    if (gVcamModuleContext.ipcFramesInHostId != SYSTEM_LINK_ID_INVALID)
    {
        System_linkStop(gVcamModuleContext.ipcFramesInHostId);
    }

    return 0;
}

/* ===================================================================
 *  @func     Vcam_setParamDevice
 *
 *  @desc     Function does the following
 *
 *  @modif    This function modifies the following structures
 *
 *  @inputs   This function takes the following inputs
 *            <argument name>
 *            Description of usage
 *            <argument name>
 *            Description of usage
 *
 *  @outputs  <argument name>
 *            Description of usage
 *
 *  @return   Return value of this function if any
 *  ==================================================================
 */
Int32 Vcam_setParamDevice(VCAM_DEV vcDevId, VCAM_DEV_PARAM_S * psvcDevParam,
                          VCAM_PARAMS_E paramId)
{
    memcpy(&gVcamModuleContext.vcamConfig.deviceParams[vcDevId], psvcDevParam,
           sizeof(VCAM_DEV_PARAM_S));
    return 0;
}

/* ===================================================================
 *  @func     Vcam_getParamDevice
 *
 *  @desc     Function does the following
 *
 *  @modif    This function modifies the following structures
 *
 *  @inputs   This function takes the following inputs
 *            <argument name>
 *            Description of usage
 *            <argument name>
 *            Description of usage
 *
 *  @outputs  <argument name>
 *            Description of usage
 *
 *  @return   Return value of this function if any
 *  ==================================================================
 */
Int32 Vcam_getParamDevice(VCAM_DEV vcDevId, VCAM_DEV_PARAM_S * psvcDevParam,
                          VCAM_PARAMS_E paramId)
{
    memcpy(psvcDevParam, &gVcamModuleContext.vcamConfig.deviceParams[vcDevId],
           sizeof(VCAM_DEV_PARAM_S));
    return 0;
}

/* ===================================================================
 *  @func     Vcam_enableDevice
 *
 *  @desc     Function does the following
 *
 *  @modif    This function modifies the following structures
 *
 *  @inputs   This function takes the following inputs
 *            <argument name>
 *            Description of usage
 *            <argument name>
 *            Description of usage
 *
 *  @outputs  <argument name>
 *            Description of usage
 *
 *  @return   Return value of this function if any
 *  ==================================================================
 */
Int32 Vcam_enableDevice(VCAM_DEV vcDevId)
{
    return 0;
}

/* ===================================================================
 *  @func     Vcam_disableDevice
 *
 *  @desc     Function does the following
 *
 *  @modif    This function modifies the following structures
 *
 *  @inputs   This function takes the following inputs
 *            <argument name>
 *            Description of usage
 *            <argument name>
 *            Description of usage
 *
 *  @outputs  <argument name>
 *            Description of usage
 *
 *  @return   Return value of this function if any
 *  ==================================================================
 */
Int32 Vcam_disableDevice(VCAM_DEV vcDevId)
{
    return 0;
}

/* ===================================================================
 *  @func     Vcam_setParamChn
 *
 *  @desc     Function does the following
 *
 *  @modif    This function modifies the following structures
 *
 *  @inputs   This function takes the following inputs
 *            <argument name>
 *            Description of usage
 *            <argument name>
 *            Description of usage
 *
 *  @outputs  <argument name>
 *            Description of usage
 *
 *  @return   Return value of this function if any
 *  ==================================================================
 */
Int32 Vcam_setParamChn(VCAM_CHN vcChnId, VCAM_CHN_PARAM_S * psCamChnParam,
                       VCAM_PARAMS_E paramId)
{
    memcpy(&gVcamModuleContext.vcamConfig.channelParams[vcChnId], psCamChnParam,
           sizeof(VCAM_CHN_PARAM_S));
    return 0;
}

/* ===================================================================
 *  @func     Vcam_getParamChn
 *
 *  @desc     Function does the following
 *
 *  @modif    This function modifies the following structures
 *
 *  @inputs   This function takes the following inputs
 *            <argument name>
 *            Description of usage
 *            <argument name>
 *            Description of usage
 *
 *  @outputs  <argument name>
 *            Description of usage
 *
 *  @return   Return value of this function if any
 *  ==================================================================
 */
Int32 Vcam_getParamChn(VCAM_CHN vcChnId, VCAM_CHN_PARAM_S * psCamChnParam,
                       VCAM_PARAMS_E paramId)
{
    memcpy(psCamChnParam, &gVcamModuleContext.vcamConfig.channelParams[vcChnId],
           sizeof(VCAM_CHN_PARAM_S));
    return 0;
}

/* ===================================================================
 *  @func     Vcam_setDynamicParamChn
 *
 *  @desc     Function does the following
 *
 *  @modif    This function modifies the following structures
 *
 *  @inputs   This function takes the following inputs
 *            <argument name>
 *            Description of usage
 *            <argument name>
 *            Description of usage
 *
 *  @outputs  <argument name>
 *            Description of usage
 *
 *  @return   Return value of this function if any
 *  ==================================================================
 */
Int32 Vcam_setDynamicParamChn(VCAM_CHN vcChnId,
                              VCAM_CHN_DYNAMIC_PARAM_S * psCamChnDynaParam,
                              VCAM_PARAMS_E paramId)
{
    Int32 status = ERROR_NONE;

    if (gVcamModuleContext.cameraId == SYSTEM_LINK_ID_INVALID)
        return ERROR_FAIL;

    switch (paramId)
    {
        case VCAM_FORMAT:
            break;

        case VCAM_GLBCE:
			if (gVcamModuleContext.glbceId != SYSTEM_LINK_ID_INVALID)
             status = System_linkControl(gVcamModuleContext.glbceId, 
                                         GLBCE_LINK_CMD_SET_DYNAMIC_PARAMS,
                                         &(psCamChnDynaParam->enableGlbce),
                                         sizeof(psCamChnDynaParam->enableGlbce),
                                         TRUE);

            break;

        case VCAM_RESOLUTION:
		{
			CameraLink_SetDynParams params;
		    params.chId = vcChnId;
            params.InputWidth = psCamChnDynaParam->InputWidth;
			params.InputHeight = psCamChnDynaParam->InputHeight;
			status = System_linkControl(gVcamModuleContext.cameraId,
							CAMERA_LINK_CMD_CHANGE_RESOLUTION,
							&(params), sizeof(params), TRUE);
            break;
		}	
        case VCAM_DCCBUFADDR:
        {
            CameraLink_DccParams params;
            params.dccBufAddr = psCamChnDynaParam->dccBufAddr;
            params.dccSize = psCamChnDynaParam->dccSize;
            status = System_linkControl(gVcamModuleContext.cameraId,
                                        CAMERA_LINK_CMD_DCC_BUFFER,
                                        &(params), sizeof(params), TRUE);
            break;
        }
        case VCAM_AEWB_VENDOR:
            status = System_linkControl(gVcamModuleContext.cameraId,
                                        CAMERA_LINK_CMD_AEWB_VENDOR,
                                        &(psCamChnDynaParam->aewbVendor),
                                        sizeof(psCamChnDynaParam->aewbVendor),
                                        TRUE);
            break;

        case VCAM_MIRROR_MODE:
            status = System_linkControl(gVcamModuleContext.cameraId,
                                        CAMERA_LINK_CMD_MIRROR_MODE,
                                        &(psCamChnDynaParam->mirrorMode),
                                        sizeof(psCamChnDynaParam->mirrorMode),
                                        TRUE);
            break;
        case VCAM_AEWB_MODE:
            status = System_linkControl(gVcamModuleContext.cameraId,
                                        CAMERA_LINK_CMD_AEWB_MODE,
                                        &(psCamChnDynaParam->aewbMode),
                                        sizeof(psCamChnDynaParam->aewbMode),
                                        TRUE);
            break;
        case VCAM_AEWB_PRIORITY:
            status = System_linkControl(gVcamModuleContext.cameraId,
                                        CAMERA_LINK_CMD_AEWB_PRIORITY,
                                        &(psCamChnDynaParam->aewbPriority),
                                        sizeof(psCamChnDynaParam->aewbPriority),
                                        TRUE);
            break;
        case VCAM_IRIS:
            status = System_linkControl(gVcamModuleContext.cameraId,
                                        CAMERA_LINK_CMD_IRIS,
                                        &(psCamChnDynaParam->IRIS),
                                        sizeof(psCamChnDynaParam->IRIS), TRUE);
            break;
        case VCAM_FRAMECTRL:
            status = System_linkControl(gVcamModuleContext.cameraId,
                                        CAMERA_LINK_CMD_FRAMECTRL,
                                        &(psCamChnDynaParam->frameCtrl),
                                        sizeof(psCamChnDynaParam->frameCtrl),
                                        TRUE);
            break;
        case VCAM_CONTRAST:
            status = System_linkControl(gVcamModuleContext.cameraId,
                                        CAMERA_LINK_CMD_CHANGE_CONTRAST,
                                        &(psCamChnDynaParam->contrast),
                                        sizeof(psCamChnDynaParam->contrast),
                                        TRUE);
            break;
        case VCAM_SATURATION:
            status = System_linkControl(gVcamModuleContext.cameraId,
                                        CAMERA_LINK_CMD_CHANGE_SATURATION,
                                        &(psCamChnDynaParam->saturation),
                                        sizeof(psCamChnDynaParam->saturation),
                                        TRUE);
            break;
        case VCAM_BRIGHTNESS:
            status = System_linkControl(gVcamModuleContext.cameraId,
                                        CAMERA_LINK_CMD_CHANGE_BRIGHTNESS,
                                        &(psCamChnDynaParam->brightness),
                                        sizeof(psCamChnDynaParam->brightness),
                                        TRUE);
            break;
        case VCAM_SHARPNESS:
            status = System_linkControl(gVcamModuleContext.cameraId,
                                        CAMERA_LINK_CMD_CHANGE_SHARPNESS,
                                        &(psCamChnDynaParam->sharpness),
                                        sizeof(psCamChnDynaParam->sharpness),
                                        TRUE);
            break;
        case VCAM_BLC:
            status = System_linkControl(gVcamModuleContext.cameraId,
                                        CAMERA_LINK_CMD_CHANGE_BLC,
                                        &(psCamChnDynaParam->blc),
                                        sizeof(psCamChnDynaParam->blc), TRUE);
            break;
        case VCAM_AWBMODE:
            status = System_linkControl(gVcamModuleContext.cameraId,
                                        CAMERA_LINK_CMD_CHANGE_AWBMODE,
                                        &(psCamChnDynaParam->awbMode),
                                        sizeof(psCamChnDynaParam->awbMode),
                                        TRUE);
            break;
        case VCAM_FRAMERATE:
        {
            CameraLink_FpsParams params;

            params.StreamId = vcChnId;
            params.targetFps = psCamChnDynaParam->frameRate;
            status = System_linkControl(gVcamModuleContext.cameraId,
                                        CAMERA_LINK_CMD_CHANGE_FRAMERATE,
                                        &(params), sizeof(params), TRUE);
            break;
        }
        case VCAM_AEMODE:
            status = System_linkControl(gVcamModuleContext.cameraId,
                                        CAMERA_LINK_CMD_CHANGE_AEMODE,
                                        &(psCamChnDynaParam->AEMode),
                                        sizeof(psCamChnDynaParam->AEMode),
                                        TRUE);
            break;
        case VCAM_ENV_50_60HZ:
            status = System_linkControl(gVcamModuleContext.cameraId,
                                        CAMERA_LINK_CMD_CHANGE_ENV_50_60HZ,
                                        &(psCamChnDynaParam->env50_60hz),
                                        sizeof(psCamChnDynaParam->env50_60hz),
                                        TRUE);
            break;
        case VCAM_BINNING_SKIP:
            status = System_linkControl(gVcamModuleContext.cameraId,
                                        CAMERA_LINK_CMD_CHANGE_BINNING,
                                        &(psCamChnDynaParam->binningMode),
                                        sizeof(psCamChnDynaParam->binningMode),
                                        TRUE);
            break;

        case VCAM_HUE:
            status = System_linkControl(gVcamModuleContext.cameraId,
                                        CAMERA_LINK_CMD_CHANGE_HUE,
                                        &(psCamChnDynaParam->hue),
                                        sizeof(psCamChnDynaParam->hue), TRUE);
            break;
        case VCAM_LDC:
            if (gVcamModuleContext.vnfId != SYSTEM_LINK_ID_INVALID)
                status = System_linkControl(gVcamModuleContext.vnfId,
                                            VNF_LINK_CMD_ENABLE_LDC,
                                            &(psCamChnDynaParam->enableLDC),
                                            sizeof(psCamChnDynaParam->
                                                   enableLDC), TRUE);
            break;
        case VCAM_TNF:
            if (gVcamModuleContext.vnfId != SYSTEM_LINK_ID_INVALID)
                status = System_linkControl(gVcamModuleContext.vnfId,
                                            VNF_LINK_CMD_ENABLE_TNF,
                                            &(psCamChnDynaParam->enableTNF),
                                            sizeof(psCamChnDynaParam->
                                                   enableTNF), TRUE);
            if (gVcamModuleContext.nsfId != SYSTEM_LINK_ID_INVALID)
                status = System_linkControl(gVcamModuleContext.nsfId,
                                            NSF_LINK_CMD_ENABLE_TNF,
                                            &(psCamChnDynaParam->enableTNF),
                                            sizeof(psCamChnDynaParam->
                                                   enableTNF), TRUE);
            break;
        case VCAM_SNF:
            if (gVcamModuleContext.vnfId != SYSTEM_LINK_ID_INVALID)
                status = System_linkControl(gVcamModuleContext.vnfId,
                                            VNF_LINK_CMD_ENABLE_SNF,
                                            &(psCamChnDynaParam->enableSNF),
                                            sizeof(psCamChnDynaParam->
                                                   enableSNF), TRUE);
            if (gVcamModuleContext.nsfId != SYSTEM_LINK_ID_INVALID)
                status = System_linkControl(gVcamModuleContext.nsfId,
                                            NSF_LINK_CMD_ENABLE_SNF,
                                            &(psCamChnDynaParam->enableSNF),
                                            sizeof(psCamChnDynaParam->
                                                   enableTNF), TRUE);
            break;

        case VCAM_NF_STRENGTH:
            if (gVcamModuleContext.vnfId != SYSTEM_LINK_ID_INVALID)
                status = System_linkControl(gVcamModuleContext.vnfId,
                                            VNF_LINK_CMD_VNF_STRENGTH,
                                            &(psCamChnDynaParam->nfStrength),
                                            sizeof(psCamChnDynaParam->
                                                   nfStrength), TRUE);
            if (gVcamModuleContext.nsfId != SYSTEM_LINK_ID_INVALID)
                status = System_linkControl(gVcamModuleContext.nsfId,
                                            NSF_LINK_CMD_NSF_STRENGTH,
                                            &(psCamChnDynaParam->nfStrength),
                                            sizeof(psCamChnDynaParam->
                                                   nfStrength), TRUE);
            break;

        case VCAM_PORTMODE:
            break;
        case VCAM_SIGNALTYPE:
            break;
		case VCAM_SD_FORMAT:
			status = System_linkControl(gVcamModuleContext.cameraId,
										CAMERA_LINK_CMD_SET_FORMAT,
										&(psCamChnDynaParam->sdFormat),
										sizeof(psCamChnDynaParam->
											   sdFormat), TRUE);
			break;
        case VCAM_ALL:
            status = System_linkControl(gVcamModuleContext.cameraId,
                                        CAMERA_LINK_CMD_CHANGE_CONTRAST,
                                        &(psCamChnDynaParam->contrast),
                                        sizeof(psCamChnDynaParam->contrast),
                                        TRUE);
            if (status >= 0)
            {
                status = System_linkControl(gVcamModuleContext.cameraId,
                                            CAMERA_LINK_CMD_CHANGE_SATURATION,
                                            &(psCamChnDynaParam->saturation),
                                            sizeof(psCamChnDynaParam->
                                                   saturation), TRUE);
            }
            if (status >= 0)
            {
                status = System_linkControl(gVcamModuleContext.cameraId,
                                            CAMERA_LINK_CMD_CHANGE_BRIGHTNESS,
                                            &(psCamChnDynaParam->brightness),
                                            sizeof(psCamChnDynaParam->
                                                   brightness), TRUE);
            }
            if (status >= 0)
            {
                status = System_linkControl(gVcamModuleContext.cameraId,
                                            CAMERA_LINK_CMD_CHANGE_HUE,
                                            &(psCamChnDynaParam->hue),
                                            sizeof(psCamChnDynaParam->hue),
                                            TRUE);
            }
            break;

    }

    return status;
}

/**
 * \brief:
 *      Set camera frame rate. This is an additional control in camera side itself; is really useful for secondary stream <CIF>.
 *      Stream 0 is D1 & Stream 1 is CIF.
 * \input:
 *      vcChnId             -- camera Channel id
 *      vStrmId             -- Stream Id
 *      frameRate          -- Frame Rate
 * \output:
 *      NA
 * \return
*       TI_MEDIA_SUCCESS    --  while success
*       ERROR_CODE          --  refer for err defination
*/
/* ===================================================================
 *  @func     Vcam_setFrameRate
 *
 *  @desc     Function does the following
 *
 *  @modif    This function modifies the following structures
 *
 *  @inputs   This function takes the following inputs
 *            <argument name>
 *            Description of usage
 *            <argument name>
 *            Description of usage
 *
 *  @outputs  <argument name>
 *            Description of usage
 *
 *  @return   Return value of this function if any
 *  ==================================================================
 */
Int32 Vcam_setFrameRate(VCAM_CHN vcChnId, VCAM_STRM vStrmId, Int32 frameRate)
{
    DeiLink_ChFpsParams params;

    Int32 status = ERROR_NONE;

    params.chId = vcChnId;
    params.streamId = vStrmId;

    params.inputFrameRate = (1000 * frameRate);
    status =
        System_linkControl(gVcamModuleContext.deiId[0],
                           DEI_LINK_CMD_SET_FRAME_RATE, &params, sizeof(params),
                           TRUE);
#if !defined(TI_814X_BUILD) && !defined(TI_8107_BUILD)
    status =
        System_linkControl(gVcamModuleContext.deiId[1],
                           DEI_LINK_CMD_SET_FRAME_RATE, &params, sizeof(params),
                           TRUE);
#endif
    return status;
}

/**
 * \brief:
 *      Get camera frame rate. Not available now
 * \input:
 *      vcChnId             -- camera Channel id
 *      vStrmId             -- Stream Id
 *      frameRate          -- Frame Rate
 * \output:
 *      NA
 * \return
*       TI_MEDIA_SUCCESS    --  while success
*       ERROR_CODE          --  refer for err defination
*/
/* ===================================================================
 *  @func     Vcam_getFrameRate
 *
 *  @desc     Function does the following
 *
 *  @modif    This function modifies the following structures
 *
 *  @inputs   This function takes the following inputs
 *            <argument name>
 *            Description of usage
 *            <argument name>
 *            Description of usage
 *
 *  @outputs  <argument name>
 *            Description of usage
 *
 *  @return   Return value of this function if any
 *  ==================================================================
 */
Int32 Vcam_getFrameRate(VCAM_CHN vcChnId, VCAM_STRM vStrmId)
{
    return 0;
}

/**
 * \brief:
 *      Get camera Channel dynamic parameters
 * \input:
 *      vcChnId             -- camera Channel id
 *      psCamChnDynaParam   -- Device dynamic parameter structure
 * \output:
 *      NA
 * \return
*       TI_MEDIA_SUCCESS    --  while success
*       ERROR_CODE          --  refer for err defination
*/
/* ===================================================================
 *  @func     Vcam_getDynamicParamChn
 *
 *  @desc     Function does the following
 *
 *  @modif    This function modifies the following structures
 *
 *  @inputs   This function takes the following inputs
 *            <argument name>
 *            Description of usage
 *            <argument name>
 *            Description of usage
 *
 *  @outputs  <argument name>
 *            Description of usage
 *
 *  @return   Return value of this function if any
 *  ==================================================================
 */
Int32 Vcam_getDynamicParamChn(VCAM_CHN vcChnId,
                              VCAM_CHN_DYNAMIC_PARAM_S * psCamChnParam,
                              VCAM_PARAMS_E paramId)
{
    return 0;
}

/* ===================================================================
 *  @func     Vcam_enableDisableChn
 *
 *  @desc     Function does the following
 *
 *  @modif    This function modifies the following structures
 *
 *  @inputs   This function takes the following inputs
 *            <argument name>
 *            Description of usage
 *            <argument name>
 *            Description of usage
 *
 *  @outputs  <argument name>
 *            Description of usage
 *
 *  @return   Return value of this function if any
 *  ==================================================================
 */
Int32 Vcam_enableDisableChn(VCAM_CHN vcChnId, VCAM_STRM vcStrmId,
                            Bool enableChn)
{
    char *onOffName[] = { "ON ", "OFF" };
    Int32 status = ERROR_FAIL;

    DeiLink_ChannelInfo channelInfo;

    UInt32 cmdId, deiId;

    channelInfo.channelId = vcChnId % NUM_CH_PER_DEI;
    channelInfo.streamId = vcStrmId;
    channelInfo.enable = enableChn;

    deiId = vcChnId / NUM_CH_PER_DEI;

    if (enableChn)
        cmdId = DEI_LINK_CMD_ENABLE_CHANNEL;
    else
        cmdId = DEI_LINK_CMD_DISABLE_CHANNEL;

    OSA_printf(" VCAM: CH%d STRM%d = [%s]\n", vcChnId, vcChnId,
           onOffName[enableChn]);

    if (deiId < MAX_DEI_LINK)
    {
        if (gVcamModuleContext.deiId[deiId] != SYSTEM_LINK_ID_INVALID)
        {
            status = System_linkControl(gVcamModuleContext.deiId[deiId],
                                        cmdId,
                                        &(channelInfo),
                                        sizeof(DeiLink_ChannelInfo), TRUE);
        }
    }

    return status;

}

/* ===================================================================
 *  @func     Vcam_enableChn
 *
 *  @desc     Function does the following
 *
 *  @modif    This function modifies the following structures
 *
 *  @inputs   This function takes the following inputs
 *            <argument name>
 *            Description of usage
 *            <argument name>
 *            Description of usage
 *
 *  @outputs  <argument name>
 *            Description of usage
 *
 *  @return   Return value of this function if any
 *  ==================================================================
 */
Int32 Vcam_enableChn(VCAM_CHN vcChnId, VCAM_STRM vcStrmId)
{
    return Vcam_enableDisableChn(vcChnId, vcStrmId, TRUE);
}

/* ===================================================================
 *  @func     Vcam_disableChn
 *
 *  @desc     Function does the following
 *
 *  @modif    This function modifies the following structures
 *
 *  @inputs   This function takes the following inputs
 *            <argument name>
 *            Description of usage
 *            <argument name>
 *            Description of usage
 *
 *  @outputs  <argument name>
 *            Description of usage
 *
 *  @return   Return value of this function if any
 *  ==================================================================
 */
Int32 Vcam_disableChn(VCAM_CHN vcChnId, VCAM_STRM vcStrmId)
{
    return Vcam_enableDisableChn(vcChnId, vcStrmId, FALSE);
}

/* ===================================================================
 *  @func     Vcam_getChnBufferBlocking
 *
 *  @desc     Function does the following
 *
 *  @modif    This function modifies the following structures
 *
 *  @inputs   This function takes the following inputs
 *            <argument name>
 *            Description of usage
 *            <argument name>
 *            Description of usage
 *
 *  @outputs  <argument name>
 *            Description of usage
 *
 *  @return   Return value of this function if any
 *  ==================================================================
 */
Int32 Vcam_getChnBufferBlocking(VCAM_CHN vcChnId, UInt8 * pChnBuffer, UInt32 uiTimeoutMs)   // consider
                                                                                            // later
{
    return 0;
}

/* ===================================================================
 *  @func     Vcam_getChnBufferNonBlocking
 *
 *  @desc     Function does the following
 *
 *  @modif    This function modifies the following structures
 *
 *  @inputs   This function takes the following inputs
 *            <argument name>
 *            Description of usage
 *            <argument name>
 *            Description of usage
 *
 *  @outputs  <argument name>
 *            Description of usage
 *
 *  @return   Return value of this function if any
 *  ==================================================================
 */
Int32 Vcam_getChnBufferNonBlocking(VCAM_CHN vcChnId, UInt8 * pChnBuffer)    // consider
                                                                            // later
{
    return 0;
}

/* ===================================================================
 *  @func     Vcam_releaseChnBuffer
 *
 *  @desc     Function does the following
 *
 *  @modif    This function modifies the following structures
 *
 *  @inputs   This function takes the following inputs
 *            <argument name>
 *            Description of usage
 *            <argument name>
 *            Description of usage
 *
 *  @outputs  <argument name>
 *            Description of usage
 *
 *  @return   Return value of this function if any
 *  ==================================================================
 */
Int32 Vcam_releaseChnBuffer(VCAM_CHN vcChnId, UInt8 * pChnBuffer)   // consider
                                                                    // later
{
    return 0;
}

/* ===================================================================
 *  @func     Vcam_delete
 *
 *  @desc     Function does the following
 *
 *  @modif    This function modifies the following structures
 *
 *  @inputs   This function takes the following inputs
 *            <argument name>
 *            Description of usage
 *            <argument name>
 *            Description of usage
 *
 *  @outputs  <argument name>
 *            Description of usage
 *
 *  @return   Return value of this function if any
 *  ==================================================================
 */
Int32 Vcam_delete()
{
    UInt32 i;

    /* delete can be done in any order */

    if (gVcamModuleContext.cameraId != SYSTEM_LINK_ID_INVALID)
        System_linkDelete(gVcamModuleContext.cameraId);
    if (gVcamModuleContext.ipcFramesOutVpssId != SYSTEM_LINK_ID_INVALID)
    {
        System_linkDelete(gVcamModuleContext.ipcFramesOutVpssId);
    }

    if (gVcamModuleContext.ipcFramesInDspId != SYSTEM_LINK_ID_INVALID)
    {
        System_linkDelete(gVcamModuleContext.ipcFramesInDspId);
    }

    if (gVcamModuleContext.osdId != SYSTEM_LINK_ID_INVALID)
    {
        System_linkDelete(gVcamModuleContext.osdId);
    }

    for (i = 0; i < MAX_DEI_LINK; i++)
    {
        if (gVcamModuleContext.deiId[i] != SYSTEM_LINK_ID_INVALID)
            System_linkDelete(gVcamModuleContext.deiId[i]);
    }

    if (gVcamModuleContext.nsfId != SYSTEM_LINK_ID_INVALID)
        System_linkDelete(gVcamModuleContext.nsfId);
    if (gVcamModuleContext.vnfId != SYSTEM_LINK_ID_INVALID)
        System_linkDelete(gVcamModuleContext.vnfId);

    if (gVcamModuleContext.ipcFramesOutVpssToHostId != SYSTEM_LINK_ID_INVALID)
    {
        System_linkDelete(gVcamModuleContext.ipcFramesOutVpssToHostId);
    }

    if (gVcamModuleContext.ipcFramesInHostId != SYSTEM_LINK_ID_INVALID)
    {
        System_linkDelete(gVcamModuleContext.ipcFramesInHostId);
    }

    return 0;
}

static Void Vcam_copyVidFrameInfoLink2McFw(VIDEO_FRAMEBUF_S *dstBuf,
                                           VIDFrame_Buf    *srcBuf)
{
    Int i,j;
    OSA_assert(VIDEO_MAX_FIELDS == VIDFRAME_MAX_FIELDS);
    OSA_assert(VIDEO_MAX_PLANES == VIDFRAME_MAX_PLANES);

    for (i = 0; i < VIDEO_MAX_FIELDS; i++)
    {
        for (j = 0; j < VIDEO_MAX_PLANES; j++)
        {
            dstBuf->addr[i][j] = srcBuf->addr[i][j];
            dstBuf->phyAddr[i][j] = srcBuf->phyAddr[i][j];
        }
    }
    dstBuf->channelNum  = srcBuf->channelNum;
    dstBuf->fid         = srcBuf->fid;
    dstBuf->frameWidth  = srcBuf->frameWidth;
    dstBuf->frameHeight = srcBuf->frameHeight;
    dstBuf->linkPrivate = srcBuf->linkPrivate;
    dstBuf->timeStamp   = srcBuf->timeStamp;
    dstBuf->framePitch[0] = srcBuf->framePitch[0];
    dstBuf->framePitch[1] = srcBuf->framePitch[1];
}

static Void Vcam_copyVidFrameInfoMcFw2Link(VIDFrame_Buf *dstBuf,
                                           VIDEO_FRAMEBUF_S    *srcBuf)
{
    Int i,j;
    OSA_assert(VIDEO_MAX_FIELDS == VIDFRAME_MAX_FIELDS);
    OSA_assert(VIDEO_MAX_PLANES == VIDFRAME_MAX_PLANES);

    for (i = 0; i < VIDEO_MAX_FIELDS; i++)
    {
        for (j = 0; j < VIDEO_MAX_PLANES; j++)
        {
            dstBuf->addr[i][j] = srcBuf->addr[i][j];
            dstBuf->phyAddr[i][j] = srcBuf->phyAddr[i][j];
        }
    }
    dstBuf->channelNum  = srcBuf->channelNum;
    dstBuf->fid         = srcBuf->fid;
    dstBuf->frameWidth  = srcBuf->frameWidth;
    dstBuf->frameHeight = srcBuf->frameHeight;
    dstBuf->linkPrivate = srcBuf->linkPrivate;
    dstBuf->timeStamp   = srcBuf->timeStamp;
    dstBuf->framePitch[0] = srcBuf->framePitch[0];
    dstBuf->framePitch[1] = srcBuf->framePitch[1];
}

/**
    \brief Send filled video gBuffers to framework for display

    User calls this API to put full video frames for display

    \param pFrameBufList    [OUT]  List of video frames to be displayed

    \return ERROR_NONE on success
*/
Int32 Vcam_putFullVideoFrames(VIDEO_FRAMEBUF_LIST_S *pFrameBufList)
{
    VIDEO_FRAMEBUF_S *pSrcBuf;
    VIDFrame_Buf     *pDstBuf;
    VIDFrame_BufList  vidBufList;
    UInt32 i;
    Int status = 0;
    
	if (gVcamModuleContext.ipcFramesOutHostId == SYSTEM_LINK_ID_INVALID)
		return 0;

    //VDIS_TRACE_FXN_ENTRY("Num bufs put:%d",pFrameBufList->numFrames);
    vidBufList.numFrames = pFrameBufList->numFrames;
    for (i = 0; i < vidBufList.numFrames; i++)
    {
        pSrcBuf = &pFrameBufList->frames[i];
        pDstBuf = &vidBufList.frames[i];
        Vcam_copyVidFrameInfoMcFw2Link(pDstBuf,pSrcBuf);
    }
    if (vidBufList.numFrames)
    {
        status =
        IpcFramesOutLink_putFullVideoFrames(gVcamModuleContext.ipcFramesOutHostId,
                                            &vidBufList);
    }
    OSA_printf("VIDFrame release :%d  status:%d\n",vidBufList.numFrames, status);
    return 0;
}


/**
    \brief :w
	Give displayed video frames back to the application

    Buffers that are were previously put by Vdis_putFullVideoFrames can be
    freed back to the framework by invoking this API.

    \param pFrameBufList [IN]   List of video frames

    \return ERROR_NONE on success
*/
Int32 Vcam_getEmptyVideoFrames(VIDEO_FRAMEBUF_LIST_S *pFrameBufList, UInt32 timeout)
{
    VIDFrame_BufList  vidBufList;
    VIDFrame_Buf     *pInBuf;
    VIDEO_FRAMEBUF_S *pOutBuf;
    UInt32 i;

	if (gVcamModuleContext.ipcFramesOutHostId== SYSTEM_LINK_ID_INVALID)
		return 0;

    //VDIS_TRACE_FXN_ENTRY();
    pFrameBufList->numFrames = 0;
    vidBufList.numFrames = 0;
    IpcFramesOutLink_getEmptyVideoFrames(gVcamModuleContext.ipcFramesOutHostId,
                                         &vidBufList);

    pFrameBufList->numFrames = vidBufList.numFrames;
    for (i = 0; i < vidBufList.numFrames; i++)
    {
        pOutBuf = &pFrameBufList->frames[i];
        pInBuf = &vidBufList.frames[i];

        Vcam_copyVidFrameInfoLink2McFw(pOutBuf,pInBuf);
    }

    OSA_printf("NumFrames Received:%d\n",pFrameBufList->numFrames);
    return 0;
}
/**
    \brief Request filled video buffers from framework

    User calls this API to get full video frames from the framework.
    After getting the video frames, user will
    - consume the video frames
    - and then call Vcam_putEmptyVideoFrames() to free the video frames back to the framework

    \param pFrameBufList    [OUT]  List of video frames returned by the framework
    \param timeout          [IN]   TIMEOUT_WAIT_FOREVER or TIMEOUT_NO_WAIT or timeout in msecs

    \return ERROR_NONE on success
*/
Int32 Vcam_getFullVideoFrames(VIDEO_FRAMEBUF_LIST_S *pFrameBufList, UInt32 timeout)
{
    VIDFrame_BufList  vidBufList;
    VIDFrame_Buf     *pInBuf;
    VIDEO_FRAMEBUF_S *pOutBuf;
    UInt32 i;

    pFrameBufList->numFrames = 0;
    vidBufList.numFrames = 0;
    IpcFramesInLink_getFullVideoFrames(gVcamModuleContext.ipcFramesInHostId,
                                       &vidBufList);

    pFrameBufList->numFrames = vidBufList.numFrames;
    for (i = 0; i < vidBufList.numFrames; i++)
    {
        pOutBuf = &pFrameBufList->frames[i];
        pInBuf = &vidBufList.frames[i];

        Vcam_copyVidFrameInfoLink2McFw(pOutBuf,pInBuf);
    }

    return 0;
}
/**
    \brief Give consumed video frames back to the application to be freed

    Buffers that are were previously got from Vcam_getFullVideoFrames can be
    freed back to the framework by invoking this API.

    \param pFrameBufList [IN]   List of video frames

    \return ERROR_NONE on success
*/
Int32 Vcam_putEmptyVideoFrames(VIDEO_FRAMEBUF_LIST_S *pFrameBufList)
{
    VIDEO_FRAMEBUF_S *pSrcBuf;
    VIDFrame_Buf     *pDstBuf;
    VIDFrame_BufList  vidBufList;
    UInt32 i;
    Int status = 0;

    vidBufList.numFrames = pFrameBufList->numFrames;
    for (i = 0; i < vidBufList.numFrames; i++)
    {
        pSrcBuf = &pFrameBufList->frames[i];
        pDstBuf = &vidBufList.frames[i];
        Vcam_copyVidFrameInfoMcFw2Link(pDstBuf,pSrcBuf);
    }
    if (vidBufList.numFrames)
    {
        status =
        IpcFramesInLink_putEmptyVideoFrames(gVcamModuleContext.ipcFramesInHostId,
                                            &vidBufList);
    }
    return 0;
}

/**
 * \brief:
 *              register call back which will post the message
 * \input:
 *              callback                -- callback function
 * \output:
 *              NA
 * \return
*               TI_MEDIA_SUCCESS        --      while success
*               ERROR_CODE                      --      refer for err defination
*/
Int32 Vcam_registerCallback(VCAM_CALLBACK_S * callback, Ptr arg)
{
    gVcamModuleContext.callbackFxn = *callback;
    gVcamModuleContext.callbackArg = arg;

    return 0;
}

/**
 * \brief:
 *              MCFW layer call back which will invoke the app registered callback
 * \input:
 *              callback                -- callback function
 * \output:
 *              NA
 * \return
*               TI_MEDIA_SUCCESS        --      while success
*               ERROR_CODE                      --      refer for err defination
*/
Void Vcam_ipcFramesInCbFxn(Ptr cbCtx)
{
    OSA_assert(cbCtx == &gVcamModuleContext);

    if (gVcamModuleContext.callbackFxn.newDataAvailableCb)
    {
        gVcamModuleContext.callbackFxn.newDataAvailableCb(gVcamModuleContext.callbackArg);
    }
}

#include "mcfw/src_linux/mcfw_api/usecases/multich_common.h"
#include "mcfw/src_linux/mcfw_api/usecases/multich_ipcbits.h"
#include "demos/mcfw_api_demos/multich_usecase/ti_mcfw_ipnc_main.h"


/* =============================================================================
 * Externs
 * ============================================================================= */

/* Merge Link for camera streams */
//#define NUM_DUP_LINK           (3)
#define NUM_MERGE_LINK              (1)
#define CAM_STREAM_MERGE_IDX        (0)
//#define HDMIDIS_DUP_IDX        (0)
/* =============================================================================
 * Use case code
 * ============================================================================= */
static SystemVideo_Ivahd2ChMap_Tbl systemVid_encDecIvaChMapTbl = {
    .isPopulated = 1,
    .ivaMap[0] = {
                  .EncNumCh = 2,
                  .EncChList = {0, 1},
                  .DecNumCh = 2,
                  .DecChList = {0, 1},
                  },

};



static Void SetIpcFramesOutInQueInfo(System_LinkQueInfo *inQueInfo)
{
    Int i;

    inQueInfo->numCh =2;// gVencModuleContext.vencConfig.numPrimaryChn;
    for (i = 0; i < inQueInfo->numCh; i++)
    {
        inQueInfo->chInfo[i].bufType = SYSTEM_BUF_TYPE_VIDFRAME;
        inQueInfo->chInfo[i].dataFormat = SYSTEM_DF_YUV420SP_UV;
        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      = 1920;
        inQueInfo->chInfo[i].height     = 1080;
        inQueInfo->chInfo[i].pitch[0]   = 1920;
        inQueInfo->chInfo[i].pitch[1]   = 0;
        inQueInfo->chInfo[i].pitch[2]   = 0;
    }
}

Void multich_create_uw_fullftr()
{
	Int32 i;
	// VPSS ---->A8
	//A8--->c674
    System_LinkInfo framesProducerLinkInfo;
	//A8--->VIDEO
    CameraLink_CreateParams cameraPrm;
    UInt32 mergeId[NUM_MERGE_LINK];
    MergeLink_CreateParams mergePrm[NUM_MERGE_LINK];
	//VPSS ---->A8
	IpcFramesOutLinkRTOS_CreateParams ipcFramesOutVpssToHostPrm;
	IpcFramesInLinkHLOS_CreateParams ipcFramesInHostPrm;
    //A8--->M3Video
	UInt32 ipcInVideoFrameId;
	
	IpcFramesOutLinkHLOS_CreateParams  ipcFramesOutHostPrm;
    IpcFramesInLinkRTOS_CreateParams   ipcFramesInVideoFromHostPrm;
    
	EncLink_CreateParams encPrm;
    //M3Video --->A8
	IpcBitsOutLinkRTOS_CreateParams ipcBitsOutVideoToHostPrm;
    IpcBitsInLinkHLOS_CreateParams ipcBitsInHostPrm;

    CameraLink_VipInstParams *pCameraInstPrm;
    CameraLink_OutParams *pCameraOutPrm;

	/* IPC struct init */
	MULTICH_INIT_STRUCT(IpcFramesOutLinkRTOS_CreateParams, ipcFramesOutVpssToHostPrm);
	MULTICH_INIT_STRUCT(IpcFramesInLinkHLOS_CreateParams, ipcFramesInHostPrm);
	MULTICH_INIT_STRUCT(IpcFramesOutLinkHLOS_CreateParams, ipcFramesOutHostPrm);
	MULTICH_INIT_STRUCT(IpcFramesInLinkRTOS_CreateParams,  ipcFramesInVideoFromHostPrm);

	MULTICH_INIT_STRUCT(IpcBitsOutLinkRTOS_CreateParams, ipcBitsOutVideoToHostPrm);
	MULTICH_INIT_STRUCT(IpcBitsInLinkHLOS_CreateParams, ipcBitsInHostPrm);

    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);

	gVcamModuleContext.cameraId = SYSTEM_LINK_ID_CAMERA;
    mergeId[CAM_STREAM_MERGE_IDX] = SYSTEM_VPSS_LINK_ID_MERGE_0;
	gVcamModuleContext.ipcFramesOutVpssToHostId  = SYSTEM_VPSS_LINK_ID_IPC_FRAMES_OUT_0;
	gVcamModuleContext.ipcFramesInHostId = SYSTEM_HOST_LINK_ID_IPC_FRAMES_IN_0;
	
    ipcInVideoFrameId = SYSTEM_VIDEO_LINK_ID_IPC_FRAMES_IN_0;//SYSTEM_VIDEO_LINK_ID_IPC_IN_M3_0;
	gVcamModuleContext.ipcFramesOutHostId = SYSTEM_HOST_LINK_ID_IPC_FRAMES_OUT_0; 
	
	gVencModuleContext.encId = SYSTEM_LINK_ID_VENC_0;

	gVencModuleContext.ipcBitsOutRTOSId = SYSTEM_VIDEO_LINK_ID_IPC_BITS_OUT_0;
    gVencModuleContext.ipcBitsInHLOSId = SYSTEM_HOST_LINK_ID_IPC_BITS_IN_0;

	/* Camera Link params */
	CameraLink_CreateParams_Init(&cameraPrm);
	cameraPrm.captureMode = CAMERA_LINK_CAPMODE_ISIF;
	cameraPrm.outQueParams[0].nextLink  = mergeId[CAM_STREAM_MERGE_IDX];
	cameraPrm.outQueParams[1].nextLink  = mergeId[CAM_STREAM_MERGE_IDX];

	/* This is for TVP5158 Audio Channels - Change it to 16 if there are 16
	 * audio channels connected in cascade */
	cameraPrm.numAudioChannels = 0;
	cameraPrm.numVipInst = 1;

	cameraPrm.tilerEnable = FALSE;
	cameraPrm.vsEnable = FALSE;

	pCameraInstPrm = &cameraPrm.vipInst[0];
	pCameraInstPrm->vipInstId = SYSTEM_CAMERA_INST_VP_CSI2;
	pCameraInstPrm->videoDecoderId = MultiCh_getSensorId(gUI_mcfw_config.sensorId);
	pCameraInstPrm->inDataFormat = SYSTEM_DF_YUV420SP_UV;
	pCameraInstPrm->sensorOutWidth  = 1920;
	pCameraInstPrm->sensorOutHeight = 1080;
	pCameraInstPrm->standard = SYSTEM_STD_1080P_24;//SYSTEM_STD_1080P_30;
	pCameraInstPrm->numOutput = 2;

	/* First stream */
	pCameraOutPrm = &pCameraInstPrm->outParams[0];
	pCameraOutPrm->dataFormat = SYSTEM_DF_YUV420SP_UV;
	pCameraOutPrm->scEnable = FALSE;
	pCameraOutPrm->scOutWidth = 1920;
	pCameraOutPrm->scOutHeight = 1080;
	pCameraOutPrm->outQueId = 0;

	/* second stream */
	pCameraOutPrm = &pCameraInstPrm->outParams[1];
	pCameraOutPrm->dataFormat = SYSTEM_DF_YUV420SP_UV;
	pCameraOutPrm->scEnable = FALSE;
	pCameraOutPrm->scOutWidth = 1920;//720;
	pCameraOutPrm->scOutHeight = 1080;//480;
	pCameraOutPrm->outQueId = 1;

	/* 2A config*/
	cameraPrm.t2aConfig.n2A_vendor = gUI_mcfw_config.n2A_vendor;
	cameraPrm.t2aConfig.n2A_mode = gUI_mcfw_config.n2A_mode;

    mergePrm[CAM_STREAM_MERGE_IDX].numInQue = 2;
    mergePrm[CAM_STREAM_MERGE_IDX].inQueParams[0].prevLinkId = gVcamModuleContext.cameraId;
    mergePrm[CAM_STREAM_MERGE_IDX].inQueParams[0].prevLinkQueId = 0;
    mergePrm[CAM_STREAM_MERGE_IDX].inQueParams[1].prevLinkId = gVcamModuleContext.cameraId;
    mergePrm[CAM_STREAM_MERGE_IDX].inQueParams[1].prevLinkQueId = 1;
    mergePrm[CAM_STREAM_MERGE_IDX].outQueParams.nextLink = gVcamModuleContext.ipcFramesOutVpssToHostId;
    mergePrm[CAM_STREAM_MERGE_IDX].notifyNextLink = TRUE;

	//set Frames out vpss to host link info
	ipcFramesOutVpssToHostPrm.baseCreateParams.noNotifyMode = TRUE;
	ipcFramesOutVpssToHostPrm.baseCreateParams.notifyNextLink = FALSE;
	ipcFramesOutVpssToHostPrm.baseCreateParams.notifyPrevLink = FALSE;
	ipcFramesOutVpssToHostPrm.baseCreateParams.inQueParams.prevLinkId =  mergeId[CAM_STREAM_MERGE_IDX];
	ipcFramesOutVpssToHostPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
	ipcFramesOutVpssToHostPrm.baseCreateParams.outQueParams[0].nextLink = gVcamModuleContext.ipcFramesInHostId;
	ipcFramesOutVpssToHostPrm.baseCreateParams.numOutQue=1;
	ipcFramesOutVpssToHostPrm.baseCreateParams.notifyProcessLink=FALSE;

	ipcFramesInHostPrm.baseCreateParams.noNotifyMode = TRUE;
	ipcFramesInHostPrm.baseCreateParams.notifyNextLink = FALSE;
	ipcFramesInHostPrm.baseCreateParams.notifyPrevLink = FALSE;//TRUE;
	ipcFramesInHostPrm.baseCreateParams.inQueParams.prevLinkId = gVcamModuleContext.ipcFramesOutVpssToHostId;
	ipcFramesInHostPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
	ipcFramesInHostPrm.baseCreateParams.outQueParams[0].nextLink = SYSTEM_LINK_ID_INVALID;;
	ipcFramesInHostPrm.baseCreateParams.numOutQue = 1;
	ipcFramesInHostPrm.exportOnlyPhyAddr = TRUE;
	
	ipcFramesInHostPrm.cbCtx = &gVcamModuleContext;
	ipcFramesInHostPrm.cbFxn = Vcam_ipcFramesInCbFxn;

	//A8 Frames to M3Video set
	ipcFramesOutHostPrm.baseCreateParams.noNotifyMode = TRUE;
	ipcFramesOutHostPrm.baseCreateParams.notifyNextLink = FALSE;//TRUE;
	ipcFramesOutHostPrm.baseCreateParams.notifyPrevLink = FALSE;
	ipcFramesOutHostPrm.baseCreateParams.numOutQue = 1;
	ipcFramesOutHostPrm.baseCreateParams.inQueParams.prevLinkId = SYSTEM_LINK_ID_INVALID;
	ipcFramesOutHostPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
	ipcFramesOutHostPrm.baseCreateParams.outQueParams[0].nextLink = ipcInVideoFrameId;
	SetIpcFramesOutInQueInfo(&ipcFramesOutHostPrm.inQueInfo);
	
	ipcFramesInVideoFromHostPrm.baseCreateParams.noNotifyMode = TRUE;
	ipcFramesInVideoFromHostPrm.baseCreateParams.notifyNextLink = FALSE;
	ipcFramesInVideoFromHostPrm.baseCreateParams.notifyPrevLink = FALSE;
	ipcFramesInVideoFromHostPrm.baseCreateParams.numOutQue = 1;
	ipcFramesInVideoFromHostPrm.baseCreateParams.inQueParams.prevLinkId = gVcamModuleContext.ipcFramesOutHostId;
	ipcFramesInVideoFromHostPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
	ipcFramesInVideoFromHostPrm.baseCreateParams.outQueParams[0].nextLink = gVencModuleContext.encId;
	
	// init encode params
    /* Video Encoder Link params */
	MULTICH_INIT_STRUCT(EncLink_CreateParams, encPrm);
	{
	    encPrm.numBufPerCh[0] = 4; //D1
	    encPrm.numBufPerCh[1] = 4; //CIF]]
	
		EncLink_ChCreateParams *pLinkChPrm;
        EncLink_ChDynamicParams *pLinkDynPrm;
        VENC_CHN_DYNAMIC_PARAM_S *pDynPrm;
        VENC_CHN_PARAMS_S *pChPrm;

		for (i = 0; i < VENC_PRIMARY_CHANNELS; i++)
		{
			pLinkChPrm  = &encPrm.chCreateParams[i];
			pLinkDynPrm = &pLinkChPrm->defaultDynamicParams;

			pChPrm      = &gVencModuleContext.vencConfig.encChannelParams[i];
			pDynPrm     = &pChPrm->dynamicParam;
	//		if( i==1)
				pLinkChPrm->format = IVIDEO_H264HP;
	//		else
	//			pLinkChPrm->format = IVIDEO_MJPEG;

			pLinkChPrm->profile                 = gVencModuleContext.vencConfig.h264Profile[i];
			pLinkChPrm->dataLayout              = IVIDEO_PROGRESSIVE;
			pLinkChPrm->fieldMergeEncodeEnable  = FALSE;
			pLinkChPrm->enableAnalyticinfo      = pChPrm->enableAnalyticinfo;
			pLinkChPrm->maxBitRate              = pChPrm->maxBitRate;
			pLinkChPrm->encodingPreset          = pChPrm->encodingPreset;
			pLinkChPrm->rateControlPreset       = IVIDEO_USER_DEFINED; //pChPrm->rcType;
			pLinkChPrm->enableHighSpeed         = FALSE;
			pLinkChPrm->enableWaterMarking      = pChPrm->enableWaterMarking;
			pLinkChPrm->StreamPreset            = gUI_mcfw_config.StreamPreset[i];

			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.numBufPerCh[i] = 4;
//			gVencModuleContext.encFormat[i] = pLinkChPrm->format;
		}
	}

    /* Video Encoder Framerate */
    encPrm.chCreateParams[0].defaultDynamicParams.inputFrameRate = 25;
    encPrm.chCreateParams[1].defaultDynamicParams.inputFrameRate = 25;
	encPrm.vsEnable = gUI_mcfw_config.vsEnable;
	encPrm.isVaUseCase = 0;
/*	
    for (i = VENC_PRIMARY_CHANNELS; i < (VENC_CHN_MAX - 1); i++)
    {
        encPrm.chCreateParams[i].format = IVIDEO_MJPEG;
        encPrm.chCreateParams[i].profile = 0;
        encPrm.chCreateParams[i].dataLayout = IVIDEO_PROGRESSIVE;
        encPrm.chCreateParams[i].fieldMergeEncodeEnable = FALSE;
        encPrm.chCreateParams[i].defaultDynamicParams.intraFrameInterval = 0;
        encPrm.chCreateParams[i].encodingPreset = 0;
        encPrm.chCreateParams[i].enableAnalyticinfo = 0;
        encPrm.chCreateParams[i].enableWaterMarking = 0;
        encPrm.chCreateParams[i].defaultDynamicParams.inputFrameRate = 25;
        encPrm.chCreateParams[i].rateControlPreset = 0;
        encPrm.chCreateParams[i].defaultDynamicParams.targetBitRate = 100 * 1000;
        encPrm.chCreateParams[i].defaultDynamicParams.interFrameInterval = 0;
        encPrm.chCreateParams[i].defaultDynamicParams.mvAccuracy = 0;
    }
*/
	encPrm.inQueParams.prevLinkId = ipcInVideoFrameId;
    encPrm.inQueParams.prevLinkQueId = 0;
    encPrm.outQueParams.nextLink = gVencModuleContext.ipcBitsOutRTOSId;

	/* IPC Bits Out VIDEO Link params */
	ipcBitsOutVideoToHostPrm.baseCreateParams.noNotifyMode = TRUE;//FALSE;
	ipcBitsOutVideoToHostPrm.baseCreateParams.notifyNextLink = FALSE;
	ipcBitsOutVideoToHostPrm.baseCreateParams.notifyPrevLink = FALSE;
    ipcBitsOutVideoToHostPrm.baseCreateParams.inQueParams.prevLinkId = gVencModuleContext.encId;
    ipcBitsOutVideoToHostPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
    ipcBitsOutVideoToHostPrm.baseCreateParams.numOutQue = 1;
    ipcBitsOutVideoToHostPrm.baseCreateParams.outQueParams[0].nextLink = gVencModuleContext.ipcBitsInHLOSId;
    MultiCh_ipcBitsInitCreateParams_BitsOutRTOS(&ipcBitsOutVideoToHostPrm, TRUE);

    /* IPC Bits In HOST Link params */
	ipcBitsInHostPrm.baseCreateParams.noNotifyMode = TRUE;//FALSE;
	ipcBitsInHostPrm.baseCreateParams.notifyNextLink = FALSE;
	ipcBitsInHostPrm.baseCreateParams.notifyPrevLink = FALSE;//TRUE;
    ipcBitsInHostPrm.baseCreateParams.inQueParams.prevLinkId = gVencModuleContext.ipcBitsOutRTOSId;
    ipcBitsInHostPrm.baseCreateParams.inQueParams.prevLinkQueId = 0;
    MultiCh_ipcBitsInitCreateParams_BitsInHLOS(&ipcBitsInHostPrm);

    /* Links Creation */
    /* Camera Link */
    System_linkCreate(gVcamModuleContext.cameraId, &cameraPrm, sizeof(cameraPrm));
    System_linkControl(gVcamModuleContext.cameraId, CAMERA_LINK_CMD_DETECT_VIDEO, NULL, 0, TRUE);
    /* Merge Link */
    System_linkCreate(mergeId[CAM_STREAM_MERGE_IDX], &mergePrm[CAM_STREAM_MERGE_IDX], sizeof(mergePrm[CAM_STREAM_MERGE_IDX]));
	
	//out yuv 420 1080P to A8
	System_linkCreate(gVcamModuleContext.ipcFramesOutVpssToHostId, &ipcFramesOutVpssToHostPrm, sizeof(ipcFramesOutVpssToHostPrm));
	System_linkCreate(gVcamModuleContext.ipcFramesInHostId, &ipcFramesInHostPrm, sizeof(ipcFramesInHostPrm));

	System_linkGetInfo(gVcamModuleContext.ipcFramesInHostId,&framesProducerLinkInfo);
	OSA_assert(framesProducerLinkInfo.numQue == 1);
	ipcFramesOutHostPrm.inQueInfo = framesProducerLinkInfo.queInfo[0];
	//A8 out yuv420 to M3Video
	System_linkCreate(gVcamModuleContext.ipcFramesOutHostId, &ipcFramesOutHostPrm, sizeof(ipcFramesOutHostPrm));
	System_linkCreate(ipcInVideoFrameId, &ipcFramesInVideoFromHostPrm, sizeof(ipcFramesInVideoFromHostPrm));

	// Video Encoder Link
    System_linkCreate(gVencModuleContext.encId, &encPrm, sizeof(encPrm));

	//M3Video to A8
	System_linkCreate(gVencModuleContext.ipcBitsOutRTOSId, &ipcBitsOutVideoToHostPrm, sizeof(ipcBitsOutVideoToHostPrm));
	System_linkCreate(gVencModuleContext.ipcBitsInHLOSId, &ipcBitsInHostPrm, sizeof(ipcBitsInHostPrm));

	//start Links
    System_linkStart(gVencModuleContext.ipcBitsInHLOSId);
    System_linkStart(gVencModuleContext.ipcBitsOutRTOSId);
    System_linkStart(gVencModuleContext.encId);

    System_linkStart(ipcInVideoFrameId);

    System_linkStart(gVcamModuleContext.ipcFramesOutHostId);
    System_linkStart(gVcamModuleContext.ipcFramesInHostId);
    System_linkStart(gVcamModuleContext.ipcFramesOutVpssToHostId);
       
	System_linkStart(mergeId[CAM_STREAM_MERGE_IDX]);
	System_linkStart(gVcamModuleContext.cameraId);

}

Void multich_delete_uw_fullftr()
{
    UInt32 mergeId[NUM_MERGE_LINK];

    /* display link */
	System_linkDelete(gVcamModuleContext.ipcFramesInHostId);
	System_linkDelete(gVcamModuleContext.ipcFramesOutVpssToHostId);

    /* Merge Link */
    System_linkDelete(mergeId[CAM_STREAM_MERGE_IDX]);

    /* Camera Link */
    System_linkDelete(gVcamModuleContext.cameraId);

    /* Print the HWI, SWI and all tasks load */
    /* Reset the accumulated timer ticks */
    MultiCh_prfLoadCalcEnable(FALSE, TRUE, FALSE);

    OSA_printf("USECASE TEARDOWN DONE\n");
}
/*******************************************************************************
 *                                                                             *
 * Copyright (c) 2011 Texas Instruments Incorporated - http://www.ti.com/      *
 *                        ALL RIGHTS RESERVED                                  *
 *                                                                             *
 ******************************************************************************/

/**
    \file ti_mcfw_ipcframes.c
    \brief
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <ctype.h>
#include <assert.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <osa_que.h>
#include <osa_mutex.h>
#include <osa_thr.h>
#include <osa_sem.h>
#include "ti_mcfw_ipcframes.h"
#include "mcfw/interfaces/ti_vcam.h"
#include "mcfw/interfaces/ti_vdis.h"

#ifdef CUSTOM_SD_DEMO
#include <osa_dma.h>

App_IpcFramesMMapCtrl gMMapCtrl;
#define FILE_WRITE_STOPPED  (0)
#define FILE_WRITE_RUNNING  (1)
#endif

#define MCFW_IPC_FRAMES_NONOTIFYMODE_FRAMESIN                          (TRUE)
#define MCFW_IPC_FRAMES_NONOTIFYMODE_FRAMESOUT                         (TRUE)

#define MCFW_IPCFRAMES_SENDRECVFXN_TSK_PRI                             (2)
#define MCFW_IPCFRAMES_SENDRECVFXN_TSK_STACK_SIZE                      (0) /* 0 means system default will be used */
#define MCFW_IPCFRAMES_SENDRECVFXN_PERIOD_MS                           (16)


#define MCFW_IPCFRAMES_INFO_PRINT_INTERVAL                             (8192)

#define MCFW_IPCFRAMES_MAX_PENDING_RECV_SEM_COUNT                      (10)
#define MCFW_IPC_FRAMES_TRACE_ENABLE_FXN_ENTRY_EXIT                    (1)
#define MCFW_IPC_FRAMES_TRACE_INFO_PRINT_INTERVAL                      (8192)


#if MCFW_IPC_FRAMES_TRACE_ENABLE_FXN_ENTRY_EXIT
#define MCFW_IPC_FRAMES_TRACE_FXN(str,...)         do {                           \
                                                     static Int printInterval = 0;\
                                                     if ((printInterval % MCFW_IPC_FRAMES_TRACE_INFO_PRINT_INTERVAL) == 0) \
                                                     {                                                          \
                                                         OSA_printf("MCFW_IPCFRAMES:%s function:%s",str,__func__);     \
                                                         OSA_printf(__VA_ARGS__);                               \
                                                     }                                                          \
                                                     printInterval++;                                           \
                                                   } while (0)
#define MCFW_IPC_FRAMES_TRACE_FXN_ENTRY(...)                  MCFW_IPC_FRAMES_TRACE_FXN("Entered",__VA_ARGS__)
#define MCFW_IPC_FRAMES_TRACE_FXN_EXIT(...)                   MCFW_IPC_FRAMES_TRACE_FXN("Leaving",__VA_ARGS__)
#else
#define MCFW_IPC_FRAMES_TRACE_FXN_ENTRY(...)
#define MCFW_IPC_FRAMES_TRACE_FXN_EXIT(...)
#endif


//extern Int32 Vsys_allocBuf(UInt32 srRegId, UInt32 bufSize, UInt32 bufAlign, Vsys_AllocBufInfo *bufInfo);
/*
static void  App_ipcFramesPrintFrameInfo(VIDEO_FRAMEBUF_S *buf)
{
    OSA_printf("MCFW_IPCFRAMES:VIDFRAME_INFO:"
               "chNum:%d\t"
               "fid:%d\t"
               "frameWidth:%d\t"
               "frameHeight:%d\t"
               "timeStamp:%d\t"
               "virtAddr[0][0]:%p\t"
               "phyAddr[0][0]:%p",
                buf->channelNum,
                buf->fid,
                buf->frameWidth,
                buf->frameHeight,
                buf->timeStamp,
                buf->addr[0][0],
                buf->phyAddr[0][0]);

}
*/

static void  App_ipcFramesPrintFullFrameListInfo(VIDEO_FRAMEBUF_LIST_S *bufList,
                                                char *listName)
{
 //   static Int printStatsInterval = 0;
//    if ((printStatsInterval % MCFW_IPCFRAMES_INFO_PRINT_INTERVAL) == 0)
    {
        Int i;

        OSA_printf("MCFW_IPCFRAMES:VIDFRAMELIST_INFO:%s\t"
                   "numFullFrames:%d",
                   listName,
                   bufList->numFrames);
        for (i = 0; i < bufList->numFrames; i++)
      {
//         App_ipcFramesPrintFrameInfo(&bufList->frames[i]);
  }
    }
   // printStatsInterval++;
}

static void mymemcpy( VIDEO_FRAMEBUF_LIST_S* psrc, Vsys_AllocBufInfo bufinfo, VIDEO_FRAMEBUF_LIST_S *pdst )
{
	Int32 i;
	UInt32 addrphy; 
	UInt32 addrvir;
	addrphy  = (UInt32)bufinfo.physAddr;
	addrvir = (UInt32)bufinfo.virtAddr;
	
	pdst->numFrames = psrc->numFrames;
	for( i=0; i<pdst->numFrames; i++ )
	{
		//change to dma cpy,
		addrphy  = (UInt32)bufinfo.physAddr+i*1920*1080*3/2;
		addrvir = (UInt32)bufinfo.virtAddr+i*1920*1080*3/2;

		pdst->frames[i].addr[0][0] = (Ptr)addrvir;//cirBufpsrc->frames[i].addr[0][0];
		pdst->frames[i].phyAddr[0][0] = (Ptr)addrphy;//psrc->frames[i].phyAddr[0][0];
		pdst->frames[i].addr[0][1] = (Ptr)(addrvir+1920*1080);//psrc->frames[i].addr[0][1];
		pdst->frames[i].phyAddr[0][1] =(Ptr)(addrphy+1920*1080);//psrc->frames[i].phyAddr[0][1];
		
		pdst->frames[i].channelNum = psrc->frames[i].channelNum;
		pdst->frames[i].timeStamp = psrc->frames[i].timeStamp;
		pdst->frames[i].fid = psrc->frames[i].fid;
		pdst->frames[i].frameWidth = psrc->frames[i].frameWidth;
		pdst->frames[i].frameHeight = psrc->frames[i].frameHeight;
		memcpy( pdst->frames[i].framePitch, psrc->frames[i].framePitch, 4*VIDEO_MAX_PLANES );
//		pdst->frames[i].linkPrivate = psrc->frames[i].linkPrivate;
	}
}
static Void * App_ipcFramesSendRecvFxn(Void * prm)
{
     App_IpcFramesCtrlThrObj *thrObj = ( App_IpcFramesCtrlThrObj *) prm;
    VIDEO_FRAMEBUF_LIST_S bufList;
    VIDEO_FRAMEBUF_LIST_S bufputList;
    Int status;
	Vsys_AllocBufInfo bufinfo;

	Vsys_allocBuf( VSYS_SR1_SHAREMEM, 2*1920*1080*3/2, 128, &bufinfo);

    OSA_semWait(&thrObj->framesInNotifySem,OSA_TIMEOUT_FOREVER);
    while (FALSE == thrObj->exitFramesInOutThread)
    {
        status =  Vcam_getFullVideoFrames(&bufList, TIMEOUT_WAIT_FOREVER);
        OSA_assert(0 == status);

        if (bufList.numFrames)
        {
			App_ipcFramesPrintFullFrameListInfo(&bufList, "ddddddddddddd");
			mymemcpy( &bufList, bufinfo, &bufputList  );
			status = Vcam_putFullVideoFrames(&bufList);
      		OSA_assert(0 == status);
        }

		bufputList.numFrames = 0;
		Vcam_getEmptyVideoFrames( &bufputList, 0 );
		if(bufputList.numFrames)
		{
			status = Vcam_putEmptyVideoFrames(&bufputList);
      		OSA_assert(0 == status);
		}
        OSA_waitMsecs(MCFW_IPCFRAMES_SENDRECVFXN_PERIOD_MS);
    }

    /*while (FALSE == thrObj->exitFramesInOutThread)
    {
        status =  Vcam_getFullVideoFrames(&bufList, TIMEOUT_WAIT_FOREVER);
        OSA_assert(0 == status);

        if (bufList.numFrames)
        {
//TODO:put yuv420 ---->m3video
			App_ipcFramesPrintFullFrameListInfo(&bufList, "ddddddddddddd");
			//Vcam_getEmptyVideoFrames(&bufputList, 0);
			mymemcpy( &bufList, bufinfo, &bufputList  );
			//Vcam_putFullVideoFrames(&bufputList);
//			Vcam_getFullVideoFrames( &bufputList, 0 );
			Vcam_putFullVideoFrames(&bufList);

//put MPout
//			status = Vcam_putEmptyVideoFrames(&bufList);
//			status = Vcam_putEmptyVideoFrames(&bufputList);
			OSA_assert(0 == status);
        }
		bufputList.numFrames = 0;
		Vcam_getEmptyVideoFrames( &bufputList, 0 );
		if(bufputList.numFrames)
		{
			status = Vcam_putEmptyVideoFrames(&bufputList);
		}


        OSA_waitMsecs(MCFW_IPCFRAMES_SENDRECVFXN_PERIOD_MS);
    }
	*/
    OSA_printf("MCFW_IPCFRAMES:%s:Leaving...",__func__);
    return NULL;
}


static Void  App_ipcFramesInitThrObj( App_IpcFramesCtrlThrObj *thrObj)
{

    OSA_semCreate(&thrObj->framesInNotifySem,
                  MCFW_IPCFRAMES_MAX_PENDING_RECV_SEM_COUNT,0);
    thrObj->exitFramesInOutThread = FALSE;
    OSA_thrCreate(&thrObj->thrHandleFramesInOut,
                   App_ipcFramesSendRecvFxn,
                  MCFW_IPCFRAMES_SENDRECVFXN_TSK_PRI,
                  MCFW_IPCFRAMES_SENDRECVFXN_TSK_STACK_SIZE,
                  thrObj);

}

static Void  App_ipcFramesDeInitThrObj( App_IpcFramesCtrlThrObj *thrObj)
{
    thrObj->exitFramesInOutThread = TRUE;
    OSA_thrDelete(&thrObj->thrHandleFramesInOut);
    OSA_semDelete(&thrObj->framesInNotifySem);
}


static
Void  App_ipcFramesInCbFxn (Ptr cbCtx)
{
     App_IpcFramesCtrl *ipcFramesCtrl;
    static Int printInterval;

    OSA_assert(cbCtx = &gApp_ipcFramesCtrl.ipcFrames);
    ipcFramesCtrl = cbCtx;
    OSA_semSignal(&ipcFramesCtrl->thrObj.framesInNotifySem);
    //if ((printInterval % MCFW_IPCFRAMES_INFO_PRINT_INTERVAL) == 0)
    {
//        OSA_printf("MCFW_IPCFRAMES: Callback function:%s",__func__);
    }
    printInterval++;
}


Void  App_ipcFramesInSetCbInfo ()
{
    VCAM_CALLBACK_S VcamCallback;

    VcamCallback.newDataAvailableCb =  App_ipcFramesInCbFxn;

    Vcam_registerCallback(&VcamCallback, &gApp_ipcFramesCtrl.ipcFrames);
}

Int32  App_ipcFramesCreate(int demoId)
{

#ifdef CUSTOM_SD_DEMO
    if(demoId == 1)
    {
         App_ipcFramesFileWriteCreate();
    }
    else
    {
        gApp_ipcFramesCtrl.fileFrameWriteChn    = 0;
        gApp_ipcFramesCtrl.fileFrameWriteEnable = FALSE;

    }
#endif
     App_ipcFramesInitThrObj(&gApp_ipcFramesCtrl.ipcFrames.thrObj);
    return OSA_SOK;
}

Void  App_ipcFramesStop(void)
{
    gApp_ipcFramesCtrl.ipcFrames.thrObj.exitFramesInOutThread = TRUE;
}

Int32  App_ipcFramesDelete()
{
    OSA_printf("Entered:%s...",__func__);
    App_ipcFramesDeInitThrObj(&gApp_ipcFramesCtrl.ipcFrames.thrObj);
    OSA_printf("Leaving:%s...",__func__);
    return OSA_SOK;
}

#ifdef CUSTOM_SD_DEMO

Void App_ipcFramesFileWriteCreate()
{
    OSA_printf("\nEnable RAW Frame Write\n\n");
    gApp_ipcFramesCtrl.fileFrameWriteChn = 0;

    gApp_ipcFramesCtrl.fileFrameWriteEnable = Demo_getFileWriteEnable();

    if(gApp_ipcFramesCtrl.fileFrameWriteEnable)
    {
        char path[256];

        Demo_getFileWritePath(path, "/dev/shm");

        gApp_ipcFramesCtrl.fileFrameWriteChn = Demo_getChId("FRAME File Write", gDemo_info.maxVcamChannels);

        sprintf(gApp_ipcFramesCtrl.fileFrameWriteName, "%s/VID_CH%02d.yuv", path, gApp_ipcFramesCtrl.fileFrameWriteChn);
    }
}

Void App_ipcFramesFileOpen()
{
    gApp_ipcFramesCtrl.fp = NULL;

    gApp_ipcFramesCtrl.fileFrameWriteState = FILE_WRITE_STOPPED;
    if(gApp_ipcFramesCtrl.fileFrameWriteEnable)
    {
        gApp_ipcFramesCtrl.fp = fopen(gApp_ipcFramesCtrl.fileFrameWriteName, "wb");
        if(gApp_ipcFramesCtrl.fp!=NULL)
        {
            gApp_ipcFramesCtrl.fileFrameWriteState = FILE_WRITE_RUNNING;
            OSA_printf(" Opened file [%s] for writing CH%d\n", gApp_ipcFramesCtrl.fileFrameWriteName, gApp_ipcFramesCtrl.fileFrameWriteChn);
        }
        else
        {
            OSA_printf(" ERROR: File open [%s] for writing CH%d FAILED !!!!\n", gApp_ipcFramesCtrl.fileFrameWriteName, gApp_ipcFramesCtrl.fileFrameWriteChn);
        }
    }
}
Void App_ipcFrameFileWrite(VIDEO_FRAMEBUF_LIST_S *pFrameBufList)
{
    UInt32 writeDataSize;
    VIDEO_FRAMEBUF_S *pBuf;
    App_IpcFramesChInfo *pChInfo;
    UInt32 frameSize = 0, frameId;

    for(frameId=0; frameId<pFrameBufList->numFrames; frameId++)
    {
        pBuf = &pFrameBufList->frames[frameId];
        if(pBuf->channelNum<VENC_CHN_MAX)
        {

            pChInfo = &gApp_ipcFramesCtrl.chFrameInfo[pBuf->channelNum];

            frameSize = (pBuf->frameWidth * pBuf->frameHeight) << 1;

            pChInfo->totalDataSize += frameSize;

            pChInfo->numFrames++;

            if(pBuf->frameWidth > pChInfo->maxWidth)
                pChInfo->maxWidth = pBuf->frameWidth;

            if(pBuf->frameHeight > pChInfo->maxHeight)
                pChInfo->maxHeight = pBuf->frameHeight;

        }
        if(gApp_ipcFramesCtrl.fileFrameWriteEnable)
        {
            if(pBuf->channelNum== gApp_ipcFramesCtrl.fileFrameWriteChn && gApp_ipcFramesCtrl.fileFrameWriteState == FILE_WRITE_RUNNING)
            {
                UInt32 pMemVirtAddr;
                pMemVirtAddr = 0;
                App_mMap((UInt32)(pBuf->phyAddr[0][0]), frameSize, &pMemVirtAddr);

                writeDataSize = fwrite((Ptr) pMemVirtAddr, 1, frameSize, gApp_ipcFramesCtrl.fp);
                if(writeDataSize!=frameSize)
                {
                    gApp_ipcFramesCtrl.fileFrameWriteState = FILE_WRITE_STOPPED;
                    fclose(gApp_ipcFramesCtrl.fp);
                    OSA_printf(" Closing file [%s] for CH%d\n", gApp_ipcFramesCtrl.fileFrameWriteName, gApp_ipcFramesCtrl.fileFrameWriteChn);
                }
                App_unmapMem();
            }
        }
    }
}
Int32 App_mMap(UInt32 physAddr, Uint32 memSize , UInt32 *pMemVirtAddr)
{
    gMMapCtrl.memDevFd = open("/dev/mem",O_RDWR|O_SYNC);

    if(gMMapCtrl.memDevFd < 0)
    {
      OSA_printf(" ERROR: /dev/mem open failed !!!\n");
      return -1;
    }


    gMMapCtrl.memOffset   = physAddr & MMAP_MEM_PAGEALIGN;

    gMMapCtrl.mmapMemAddr = physAddr - gMMapCtrl.memOffset;

    gMMapCtrl.mmapMemSize = memSize + gMMapCtrl.memOffset;

    gMMapCtrl.pMemVirtAddr = mmap(
           (void	*)gMMapCtrl.mmapMemAddr,
           gMMapCtrl.mmapMemSize,
           PROT_READ|PROT_WRITE|PROT_EXEC,MAP_SHARED,
           gMMapCtrl.memDevFd,
           gMMapCtrl.mmapMemAddr
           );

   if (gMMapCtrl.pMemVirtAddr==NULL)
   {
     OSA_printf(" ERROR: mmap() failed !!!\n");
     return -1;
   }
    *pMemVirtAddr = (UInt32)((UInt32)gMMapCtrl.pMemVirtAddr + gMMapCtrl.memOffset);

    return 0;
}

Int32 App_unmapMem()
{
    if(gMMapCtrl.pMemVirtAddr)
      munmap((void*)gMMapCtrl.pMemVirtAddr, gMMapCtrl.mmapMemSize);

    if(gMMapCtrl.memDevFd >= 0)
      close(gMMapCtrl.memDevFd);

    return 0;
}

#endif

m3Vpss----->A8------->m3Video----------------->A8

i define SYSTEM_VIDEO_LINK_ID_IPC_FRAMES_IN_0

#define SYSTEM_VIDEO_LINK_ID_IPC_FRAMES_IN_0  VIDEO_LINK(SYSTEM_LINK_ID_IPC_FRAMES_IN_0)
#define SYSTEM_VIDEO_LINK_ID_IPC_FRAMES_IN_1  VIDEO_LINK(SYSTEM_LINK_ID_IPC_FRAMES_IN_1)

#define SYSTEM_VIDEO_LINK_ID_IPC_FRAMES_OUT_0  VIDEO_LINK(SYSTEM_LINK_ID_IPC_FRAMES_OUT_0)
#define SYSTEM_VIDEO_LINK_ID_IPC_FRAMES_OUT_1  VIDEO_LINK(SYSTEM_LINK_ID_IPC_FRAMES_OUT_1)
#define SYSTEM_VIDEO_LINK_ID_IPC_FRAMES_OUT_2  VIDEO_LINK(SYSTEM_LINK_ID_IPC_FRAMES_OUT_2)

1 if i use ipcInVideoFrameId = SYSTEM_VIDEO_LINK_ID_IPC_IN_M3_0;
question is m3Video Can not get frames from A8, but A8 have send out the frames;

2 if i use ipcInVideoFrameId =SYSTEM_VIDEO_LINK_ID_IPC_FRAMES_IN_0;

[M3video] Assertion Line 1129 in links_m3video/iva_enc/encLink_common.c: status== FVID2_OK: failed !!!

why?