Пример #1
0
MBOOL
HdrHal::init(void *pInitInData)
{
	HDR_LOGD("- E. mUsers: %d.", mUsers);
	HDR_PIPE_INIT_INFO* prHdrPipeInitInfo = (HDR_PIPE_INIT_INFO*)pInitInData;
	HDR_LOGV("ImgW/H: (%d, %d). FinalGainDiff[0/1]: (%d, %d). OutputFrameNum: %d. TargetTone: %d.", prHdrPipeInitInfo->u4ImgW, prHdrPipeInitInfo->u4ImgH, prHdrPipeInitInfo->u4FinalGainDiff0, prHdrPipeInitInfo->u4FinalGainDiff1, prHdrPipeInitInfo->u4OutputFrameNum, prHdrPipeInitInfo->u4TargetTone);
	HDR_LOGV("pSourceImgBufAddr[0/1/2]: (%p, %p, %p).", prHdrPipeInitInfo->pSourceImgBufAddr[0], prHdrPipeInitInfo->pSourceImgBufAddr[1], prHdrPipeInitInfo->pSourceImgBufAddr[2]);

    MBOOL   ret = MFALSE;
	MINT32	err = 0;	// 0: No error. other value: error.

	Mutex::Autolock lock(mLock);

	if (mUsers > 0)
	{
		HDR_LOGD("%d has created.", mUsers);
		android_atomic_inc(&mUsers);

		HDR_LOGD("- X. ret: %d.", MTRUE);
		return MTRUE;
	}

	// Create HdrDrv instance.
    m_pHdrDrv = MTKHdr::createInstance();
	if (!m_pHdrDrv)
	{
		HDR_LOGD("MTKHdr::createInstance() fail.");
		goto create_fail_exit;
	}

	// Allocate working buffer needed by Drv (HdrDrv and MavDrv).

	// Init HdrDrv object.
    //     Fill init data.
    HDR_SET_ENV_INFO_STRUCT rHdrInitInfo;

	rHdrInitInfo.image_num		= prHdrPipeInitInfo->u4OutputFrameNum;
	GS_u4OutputFrameNum			= prHdrPipeInitInfo->u4OutputFrameNum;	// Record u4OutputFrameNum for HDR Pipe to use.
	rHdrInitInfo.ev_gain1		= (MUINT16)prHdrPipeInitInfo->u4FinalGainDiff0;
	rHdrInitInfo.ev_gain2		= 1024; 	// Fix at 1024.
	rHdrInitInfo.ev_gain3		= (MUINT16)prHdrPipeInitInfo->u4FinalGainDiff1;
	rHdrInitInfo.target_tone	= prHdrPipeInitInfo->u4TargetTone;
	rHdrInitInfo.image_width	= prHdrPipeInitInfo->u4ImgW;
    rHdrInitInfo.image_height	= prHdrPipeInitInfo->u4ImgH;

    if(CustomHdrUseIspGamma())
    {
        HDR_LOGD("Use ISP Gamma");
        rHdrInitInfo.pIsp_gamma = prHdrPipeInitInfo->pIsp_gamma;
    }
    else
    {
        HDR_LOGD("Use Fixed Gamma");
        rHdrInitInfo.pIsp_gamma = NULL;
    }
	
    rHdrInitInfo.hdr_tuning_data.BRatio	= CustomHdrBRatioGet();

    for (MUINT32 i = 0; i < 11; i++)
    {
		rHdrInitInfo.hdr_tuning_data.Gain[i]	= CustomHdrGainArrayGet(i);
    }

    rHdrInitInfo.hdr_tuning_data.BottomFRatio	= CustomHdrBottomFRatioGet();
    rHdrInitInfo.hdr_tuning_data.TopFRatio		= CustomHdrTopFRatioGet();
    rHdrInitInfo.hdr_tuning_data.BottomFBound	= CustomHdrBottomFBoundGet();
    rHdrInitInfo.hdr_tuning_data.TopFBound		= CustomHdrTopFBoundGet();

    rHdrInitInfo.hdr_tuning_data.ThHigh         = CustomHdrThHighGet();
    rHdrInitInfo.hdr_tuning_data.ThLow          = CustomHdrThLowGet();

    rHdrInitInfo.hdr_tuning_data.TargetLevelSub = CustomHdrTargetLevelSubGet();
    rHdrInitInfo.hdr_tuning_data.CoreNumber     = CustomHdrCoreNumberGet();
    rHdrInitInfo.hdr_tuning_data.HdrSpeed       = HDR_PROCESS_NORMAL;	//Never use HDR_PROCESS_FAST

    rHdrInitInfo.HdrSrcInfo     = (prHdrPipeInitInfo->u4SensorType == NSCam::SENSOR_TYPE_YUV)
                                    ? HDR_INFO_SRC_YUV
                                    : HDR_INFO_SRC_RAW;

	HDR_LOGD("rHdrInitInfo:: ImgW/H: (%d, %d). FinalGainDiff[0/1]: (%d, %d). OutputFrameNum: %d. TargetTone: %d. RawSensor: %d."
			, rHdrInitInfo.image_width
			, rHdrInitInfo.image_height
			, rHdrInitInfo.ev_gain1
			, rHdrInitInfo.ev_gain3
			, rHdrInitInfo.image_num
			, rHdrInitInfo.target_tone
			, rHdrInitInfo.HdrSrcInfo);

	//HDR_LOGV("rHdrInitInfo:: pSourceImgBufAddr[0/1/2]: (0x%08X, 0x%08X, 0x%08X).", rHdrInitInfo.image_addr[0], rHdrInitInfo.image_addr[1], rHdrInitInfo.image_addr[2]);
	HDR_LOGV("rHdrInitInfo:: BRatio: %d. BottomFRatio: %f. TopFRatio: %f. BottomFBound:	%d. TopFBound: %d.",
		rHdrInitInfo.hdr_tuning_data.BRatio,
		rHdrInitInfo.hdr_tuning_data.BottomFRatio,
		rHdrInitInfo.hdr_tuning_data.TopFRatio,
		rHdrInitInfo.hdr_tuning_data.BottomFBound,
		rHdrInitInfo.hdr_tuning_data.TopFBound
	);
	HDR_LOGV("rHdrInitInfo:: ThHigh: %d. ThLow: %d. TargetLevelSub: %d.",
		rHdrInitInfo.hdr_tuning_data.ThHigh,
		rHdrInitInfo.hdr_tuning_data.ThLow,
		rHdrInitInfo.hdr_tuning_data.TargetLevelSub
	);
    for (MUINT32 i = 0; i < 11; i++)
		HDR_LOGV("rHdrInitInfo:: u4Gain[%d]: %d.", i, rHdrInitInfo.hdr_tuning_data.Gain[i]);

    //     Call HdrDrv init.
    err = m_pHdrDrv->HdrInit(&rHdrInitInfo, 0);
	if (err)	// if ret != 0 means error happened.
	{
		HDR_LOGD("m_pHdrDrv->HdrInit() fail, err=%d", err);
		goto create_fail_exit;
	}

	if(1) {
		//	set HDR default pthread attribute to avoid RT throttling
	    pthread_attr_t attr = {0, NULL, 1024 * 1024, 4096, SCHED_OTHER, ANDROID_PRIORITY_FOREGROUND+1};
		m_pHdrDrv->HdrFeatureCtrl(HDR_FEATURE_SET_PTHREAD_ATTR, &attr, NULL);
	}

#if EARLY_MAV_INIT
	// Create MavDrv instance.
	m_pMavDrv = MTKMav::createInstance(DRV_MAV_OBJ_SWHDR);
	if (!m_pMavDrv)
	{
		HDR_LOGD("MTKMav::createInstance() fail.");
		goto create_fail_exit;
	}

	// Init MavDrv object.
    //     Fill init data.
	MavInitInfo rMavInitInfo;
	rMavInitInfo.WorkingBuffAddr = (MUINT32)global_buffer_rectify;	// FIXME: Allocate working buffer for MAV.
    rMavInitInfo.pTuningInfo = NULL;
    //     Call MavDrv init.
	err = m_pMavDrv->MavInit(&rMavInitInfo, 0);
	if (err)	// if ret != 0 means error happened.
	{
		HDR_LOGD("m_pMavDrv->MavInit() fail. err: %d.", err);
		goto create_fail_exit;
	}
#endif	// EARLY_MAV_INIT

	android_atomic_inc(&mUsers);

	ret = MTRUE;
	HDR_LOGD("- X. ret: %d.", ret);
	return ret;

create_fail_exit:

	// HdrDrv Init failed, destroy HdrDrv instance.
	if (m_pHdrDrv)
	{
		m_pHdrDrv->destroyInstance();
		m_pHdrDrv = NULL;
	}

#if EARLY_MAV_INIT
	// MavDrv Init failed, destroy MavDrv instance.
	if (m_pMavDrv)
	{
		m_pMavDrv->MavReset();
		m_pMavDrv->destroyInstance();
		m_pMavDrv = NULL;
	}
#endif	// EARLY_MAV_INIT

	HDR_LOGD("- X. ret: %d.", ret);
	return ret;	// 0: No error. other value: error.

}
MBOOL
HdrHal::init(void *pInitInData)
{
	HDR_LOGD("- E. mUsers: %d.", mUsers);
	HDR_PIPE_INIT_INFO* prHdrPipeInitInfo = (HDR_PIPE_INIT_INFO*)pInitInData;
	HDR_LOGV("ImgW/H: (%d, %d). FinalGainDiff[0/1]: (%d, %d). OutputFrameNum: %d. TargetTone: %d.", prHdrPipeInitInfo->u4ImgW, prHdrPipeInitInfo->u4ImgH, prHdrPipeInitInfo->u4FinalGainDiff0, prHdrPipeInitInfo->u4FinalGainDiff1, prHdrPipeInitInfo->u4OutputFrameNum, prHdrPipeInitInfo->u4TargetTone);
	HDR_LOGV("pSourceImgBufAddr[0/1/2]: (0x%08X, 0x%08X, 0x%08X).", prHdrPipeInitInfo->pSourceImgBufAddr[0], prHdrPipeInitInfo->pSourceImgBufAddr[1], prHdrPipeInitInfo->pSourceImgBufAddr[2]);

    MBOOL   ret = MFALSE;
	MINT32	err = 0;	// 0: No error. other value: error.

	Mutex::Autolock lock(mLock);

	if (mUsers > 0)
	{
		HDR_LOGD("%d has created.", mUsers);
		android_atomic_inc(&mUsers);

		HDR_LOGD("- X. ret: %d.", MTRUE);
		return MTRUE;
	}

	// Create HdrDrv instance.
    m_pHdrDrv = MTKHdr::createInstance();
	if (!m_pHdrDrv)
	{
		HDR_LOGD("MTKHdr::createInstance() fail.");
		goto create_fail_exit;
	}

	// Allocate working buffer needed by Drv (HdrDrv and MavDrv).

	// Init HdrDrv object.
    //     Fill init data.
    HDR_SET_ENV_INFO_STRUCT rHdrInitInfo;

	rHdrInitInfo.image_num		= prHdrPipeInitInfo->u4OutputFrameNum;
	GS_u4OutputFrameNum			= prHdrPipeInitInfo->u4OutputFrameNum;	// Record u4OutputFrameNum for HDR Pipe to use.
	rHdrInitInfo.ev_gain1		= (MUINT16)prHdrPipeInitInfo->u4FinalGainDiff0;
	rHdrInitInfo.ev_gain2		= 1024; 	// Fix at 1024.
	rHdrInitInfo.ev_gain3		= (MUINT16)prHdrPipeInitInfo->u4FinalGainDiff1;
	rHdrInitInfo.target_tone	= prHdrPipeInitInfo->u4TargetTone;
	rHdrInitInfo.image_width	= prHdrPipeInitInfo->u4ImgW;
    rHdrInitInfo.image_height	= prHdrPipeInitInfo->u4ImgH;
	rHdrInitInfo.image_addr[0]	= prHdrPipeInitInfo->pSourceImgBufAddr[0];
	rHdrInitInfo.image_addr[1]	= prHdrPipeInitInfo->pSourceImgBufAddr[1];
	rHdrInitInfo.image_addr[2]	= prHdrPipeInitInfo->pSourceImgBufAddr[2];

    rHdrInitInfo.hdr_tuning_data.BlurRatio	= CustomHdrBlurRatioGet();

    for (MUINT32 i = 0; i < 11; i++)
    {
		rHdrInitInfo.hdr_tuning_data.Gain[i]	= CustomHdrGainArrayGet(i);
    }
 
    rHdrInitInfo.hdr_tuning_data.BottomFlareRatio	= CustomHdrBottomFlareRatioGet();
    rHdrInitInfo.hdr_tuning_data.TopFlareRatio		= CustomHdrTopFlareRatioGet();
    rHdrInitInfo.hdr_tuning_data.BottomFlareBound	= CustomHdrBottomFlareBoundGet();
    rHdrInitInfo.hdr_tuning_data.TopFlareBound		= CustomHdrTopFlareBoundGet();

    rHdrInitInfo.hdr_tuning_data.ThHigh				= CustomHdrThHighGet();
    rHdrInitInfo.hdr_tuning_data.ThLow				= CustomHdrThLowGet();
    
    rHdrInitInfo.hdr_tuning_data.TargetLevelSub		= CustomHdrTargetLevelSubGet();
    rHdrInitInfo.hdr_tuning_data.CoreNumber		    = CustomHdrCoreNumberGet();

	HDR_LOGV("rHdrInitInfo:: ImgW/H: (%d, %d). FinalGainDiff[0/1]: (%d, %d). OutputFrameNum: %d. TargetTone: %d.", rHdrInitInfo.image_width, rHdrInitInfo.image_height, rHdrInitInfo.ev_gain1, rHdrInitInfo.ev_gain3, rHdrInitInfo.image_num, rHdrInitInfo.target_tone);
	HDR_LOGV("rHdrInitInfo:: pSourceImgBufAddr[0/1/2]: (0x%08X, 0x%08X, 0x%08X).", rHdrInitInfo.image_addr[0], rHdrInitInfo.image_addr[1], rHdrInitInfo.image_addr[2]);
	HDR_LOGV("rHdrInitInfo:: BlurRatio: %d. BottomFlareRatio: %f. TopFlareRatio: %f. BottomFlareBound:	%d. TopFlareBound: %d.",
		rHdrInitInfo.hdr_tuning_data.BlurRatio,
		rHdrInitInfo.hdr_tuning_data.BottomFlareRatio,
		rHdrInitInfo.hdr_tuning_data.TopFlareRatio,
		rHdrInitInfo.hdr_tuning_data.BottomFlareBound,
		rHdrInitInfo.hdr_tuning_data.TopFlareBound
	);
	HDR_LOGD("rHdrInitInfo:: ThHigh: %d. ThLow: %d. TargetLevelSub: %d. CoreNumber: %d.",
		rHdrInitInfo.hdr_tuning_data.ThHigh,
		rHdrInitInfo.hdr_tuning_data.ThLow,
		rHdrInitInfo.hdr_tuning_data.TargetLevelSub,
		rHdrInitInfo.hdr_tuning_data.CoreNumber
	);
    for (MUINT32 i = 0; i < 11; i++)
		HDR_LOGV("rHdrInitInfo:: u4Gain[%d]: %d.", i, rHdrInitInfo.hdr_tuning_data.Gain[i]);

    //     Call HdrDrv init.
    err = m_pHdrDrv->HdrInit(&rHdrInitInfo, 0);
	if (err)	// if ret != 0 means error happened.
	{
		HDR_LOGD("m_pHdrDrv->HdrInit() fail.");
		goto create_fail_exit;
	}

#if EARLY_MAV_INIT
	// Create MavDrv instance.
	m_pMavDrv = MTKMav::createInstance(DRV_MAV_OBJ_SWHDR);
	if (!m_pMavDrv)
	{
		HDR_LOGD("MTKMav::createInstance() fail.");
		goto create_fail_exit;
	}

	// Init MavDrv object.
    //     Fill init data.
	MavInitInfo rMavInitInfo;
	rMavInitInfo.WorkingBuffAddr = (MUINT32)global_buffer_rectify;	// FIXME: Allocate working buffer for MAV.
    rMavInitInfo.pTuningInfo = NULL;
    //     Call MavDrv init.
	err = m_pMavDrv->MavInit(&rMavInitInfo, 0);
	if (err)	// if ret != 0 means error happened.
	{
		HDR_LOGD("m_pMavDrv->MavInit() fail. err: %d.", err);
		goto create_fail_exit;
	}
#endif	// EARLY_MAV_INIT

	android_atomic_inc(&mUsers);

	ret = MTRUE;
	HDR_LOGD("- X. ret: %d.", ret);
	return ret;

create_fail_exit:

	// HdrDrv Init failed, destroy HdrDrv instance.
	if (m_pHdrDrv)
	{
		m_pHdrDrv->destroyInstance();
		m_pHdrDrv = NULL;
	}

#if EARLY_MAV_INIT
	// MavDrv Init failed, destroy MavDrv instance.
	if (m_pMavDrv)
	{
		m_pMavDrv->destroyInstance();
		m_pMavDrv = NULL;
	}
#endif	// EARLY_MAV_INIT

	HDR_LOGD("- X. ret: %d.", ret);
	return ret;	// 0: No error. other value: error.

}