📄 cameradevice.cpp
字号:
m_DevProps[ENUM_EXPOSURE].ulCurrentValue = ExposureDefault;
m_DevProps[ENUM_EXPOSURE].ulDefaultValue = ExposureDefault;
m_DevProps[ENUM_EXPOSURE].pRangeNStep = &ExposureRangeAndStep[0];
m_DevProps[ENUM_EXPOSURE].ulFlags = CSPROPERTY_CAMERACONTROL_FLAGS_AUTO;
m_DevProps[ENUM_EXPOSURE].ulCapabilities = CSPROPERTY_CAMERACONTROL_FLAGS_MANUAL|CSPROPERTY_CAMERACONTROL_FLAGS_AUTO;
m_DevProps[ENUM_EXPOSURE].fSetSupported = VideoProcAmpProperties[ENUM_EXPOSURE-NUM_VIDEOPROCAMP_ITEMS].SetSupported;
m_DevProps[ENUM_EXPOSURE].fGetSupported = VideoProcAmpProperties[ENUM_EXPOSURE-NUM_VIDEOPROCAMP_ITEMS].GetSupported;
m_DevProps[ENUM_EXPOSURE].pCsPropValues = &ExposureValues;
m_DevProps[ENUM_FOCUS].ulCurrentValue = FocusDefault;
m_DevProps[ENUM_FOCUS].ulDefaultValue = FocusDefault;
m_DevProps[ENUM_FOCUS].pRangeNStep = &FocusRangeAndStep[0];
m_DevProps[ENUM_FOCUS].ulFlags = CSPROPERTY_CAMERACONTROL_FLAGS_MANUAL;
m_DevProps[ENUM_FOCUS].ulCapabilities = CSPROPERTY_CAMERACONTROL_FLAGS_MANUAL;
m_DevProps[ENUM_FOCUS].fSetSupported = VideoProcAmpProperties[ENUM_FOCUS-NUM_VIDEOPROCAMP_ITEMS].SetSupported;
m_DevProps[ENUM_FOCUS].fGetSupported = VideoProcAmpProperties[ENUM_FOCUS-NUM_VIDEOPROCAMP_ITEMS].GetSupported;
m_DevProps[ENUM_FOCUS].pCsPropValues = &FocusValues;
m_DevProps[ENUM_FLASH].ulCurrentValue = FlashDefault;
m_DevProps[ENUM_FLASH].ulDefaultValue = FlashDefault;
m_DevProps[ENUM_FLASH].pRangeNStep = &FlashRangeAndStep[0];
m_DevProps[ENUM_FLASH].ulFlags = CSPROPERTY_CAMERACONTROL_FLAGS_AUTO;
m_DevProps[ENUM_FLASH].ulCapabilities = CSPROPERTY_CAMERACONTROL_FLAGS_MANUAL |CSPROPERTY_CAMERACONTROL_FLAGS_AUTO;
m_DevProps[ENUM_FLASH].fSetSupported = VideoProcAmpProperties[ENUM_FLASH-NUM_VIDEOPROCAMP_ITEMS].SetSupported;
m_DevProps[ENUM_FLASH].fGetSupported = VideoProcAmpProperties[ENUM_FLASH-NUM_VIDEOPROCAMP_ITEMS].GetSupported;
m_DevProps[ENUM_FLASH].pCsPropValues = &FlashValues;
// Video Format initialization
m_PinVideoFormat[PREVIEW].categoryGUID = PINNAME_VIDEO_PREVIEW;
m_PinVideoFormat[PREVIEW].ulAvailFormats = 7;
m_PinVideoFormat[PREVIEW].pCsDataRangeVideo[0] = &DCAM_StreamMode_RGB565_QCIF;
m_PinVideoFormat[PREVIEW].pCsDataRangeVideo[1] = &DCAM_StreamMode_RGB565_QQCIF;
m_PinVideoFormat[PREVIEW].pCsDataRangeVideo[2] = &DCAM_StreamMode_RGB565_QQVGA;
m_PinVideoFormat[PREVIEW].pCsDataRangeVideo[3] = &DCAM_StreamMode_RGB565_QVGA;
m_PinVideoFormat[PREVIEW].pCsDataRangeVideo[4] = &DCAM_StreamMode_RGB565_CIF;
m_PinVideoFormat[PREVIEW].pCsDataRangeVideo[5] = &DCAM_StreamMode_RGB565_VGA;
m_PinVideoFormat[PREVIEW].pCsDataRangeVideo[6] = &DCAM_StreamMode_RGB565_QQQVGA;
m_PinVideoFormat[CAPTURE].categoryGUID = PINNAME_VIDEO_CAPTURE;
m_PinVideoFormat[CAPTURE].ulAvailFormats = 6;
// TODO: Switch back
m_PinVideoFormat[CAPTURE].pCsDataRangeVideo[0] = &DCAM_StreamMode_YV12_QQCIF;
m_PinVideoFormat[CAPTURE].pCsDataRangeVideo[1] = &DCAM_StreamMode_YV12_QQVGA;
m_PinVideoFormat[CAPTURE].pCsDataRangeVideo[2] = &DCAM_StreamMode_YV12_QCIF;
// m_PinVideoFormat[CAPTURE].pCsDataRangeVideo[3] = &DCAM_StreamMode_RGB565_QVGA;
m_PinVideoFormat[CAPTURE].pCsDataRangeVideo[3] = &DCAM_StreamMode_YV12_QVGA;
m_PinVideoFormat[CAPTURE].pCsDataRangeVideo[4] = &DCAM_StreamMode_YV12_CIF;
m_PinVideoFormat[CAPTURE].pCsDataRangeVideo[5] = &DCAM_StreamMode_YV12_VGA;
/* MX27 only support the above 6 format.
m_PinVideoFormat[CAPTURE].pCsDataRangeVideo[6] = &DCAM_StreamMode_RGB565_QCIF;
m_PinVideoFormat[CAPTURE].pCsDataRangeVideo[7] = &DCAM_StreamMode_RGB565_QVGA;
m_PinVideoFormat[CAPTURE].pCsDataRangeVideo[8] = &DCAM_StreamMode_RGB565_CIF;
m_PinVideoFormat[CAPTURE].pCsDataRangeVideo[9] = &DCAM_StreamMode_RGB565_VGA;
*/
m_PinVideoFormat[STILL].categoryGUID = PINNAME_VIDEO_STILL;
m_PinVideoFormat[STILL].ulAvailFormats = 6;
m_PinVideoFormat[STILL].pCsDataRangeVideo[0] = &DCAM_StreamMode_RGB565_QQCIF;
m_PinVideoFormat[STILL].pCsDataRangeVideo[1] = &DCAM_StreamMode_RGB565_QQVGA;
m_PinVideoFormat[STILL].pCsDataRangeVideo[2] = &DCAM_StreamMode_RGB565_QCIF;
m_PinVideoFormat[STILL].pCsDataRangeVideo[3] = &DCAM_StreamMode_RGB565_QVGA;
m_PinVideoFormat[STILL].pCsDataRangeVideo[4] = &DCAM_StreamMode_RGB565_QCIF;
m_PinVideoFormat[STILL].pCsDataRangeVideo[5] = &DCAM_StreamMode_RGB565_VGA;
// Video Control Caps
// TODO : Set the following caps to 0 for this null DD.
m_PinVideoCaps[PREVIEW].ulVideoControlCaps = DefaultVideoControlCaps[PREVIEW];
m_PinVideoCaps[CAPTURE].ulVideoControlCaps = DefaultVideoControlCaps[CAPTURE];
m_PinVideoCaps[STILL].ulVideoControlCaps = DefaultVideoControlCaps[STILL];
if (!CameraInit())
{
return FALSE;
}
CAM_FUNCTION_EXIT();
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: CameraInit
//
// This function initializes the Camera Sensor Interface and
// Preprocessor (Image Converter) modules.
//
// Parameters:
// None.
//
// Returns:
// TRUE if success
// FALSE if failure
//
//-----------------------------------------------------------------------------
BOOL CCameraDevice::CameraInit()
{
CAM_FUNCTION_ENTRY();
// Create (and initialize) preprocessor class object
if(m_pPrp == NULL)
{
m_pPrp = new PrpClass;
}
else
{
DEBUGMSG(ZONE_ERROR, (TEXT("%s: Failed creating PrpClass object!\r\n"), __WFUNCTION__));
}
// Create (and initialize) CSI class object
if(m_pCsi == NULL)
{
m_pCsi = new CsiClass;
}
else
{
DEBUGMSG(ZONE_ERROR, (TEXT("%s: Failed creating CsiClass object!\r\n"), __WFUNCTION__));
}
// As part of initialization, turn power on (set to D0).
// SetCameraPower(D0); we don't need to do this. We power up the device when we are tring to open it.
CAM_FUNCTION_EXIT();
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: CameraDeinit
//
// This function deinitializes the Camera Sensor Interface and
// Image Converter modules.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
void CCameraDevice::CameraDeinit()
{
CAM_FUNCTION_ENTRY();
// TODO: Remember that the Preprocessor may still be in use,
// even if Camera is closed. When we create a preprocessor driver,
// there must be a mechanism for determining between these two
// drivers whether the IC is still in use.
delete(m_pPrp);
delete(m_pCsi);
CAM_FUNCTION_EXIT();
}
//-----------------------------------------------------------------------------
//
// Function: CameraConfig
//
// This function configures the camera sensor and preprocessing module.
//
// Parameters:
// iEncPin
// [in] Specifies whether data format for STILL pin or
// CAPTURE pin should be used to configure the encoding path.
//
// iBufNum
// [in] Number of buffers to allocate for Pre-processing
//
// Returns:
// TRUE if success
// FALSE if failure
//
//-----------------------------------------------------------------------------
BOOL CCameraDevice::CameraConfig(UINT32 iEncPin, UINT32 iBufNum)
{
ULONG PinID;
static BOOL displayInitialized = FALSE;
CAM_FUNCTION_ENTRY();
// If no changes to the camera settings have been made
// since the last configuration, we do not need to
// go through configuration steps, so we bail out.
if (m_bCameraConfig)
{
return TRUE;
}
// Quit if any non-STILL pins are in the RUN state.
if (iEncPin != STILL)
{
for (PinID = 0; PinID <= (MAX_SUPPORTED_PINS - 1); PinID++)
{
if(m_StrmInstances[PinID].pPinDev != NULL && m_StrmInstances[PinID].pPinDev->m_CsState == CSSTATE_RUN)
{
DEBUGMSG(ZONE_ERROR, (TEXT("%s: Pins are running. Stop all Pin before config camera!\r\n"), __WFUNCTION__));
return FALSE;
}
}
}
if ((m_StrmInstances[PREVIEW].pPinDev == NULL) && (m_StrmInstances[CAPTURE].pPinDev == NULL))
{
DEBUGMSG(ZONE_ERROR, (TEXT("%s: No Pins are active! Aborting camera configuration.\r\n"), __WFUNCTION__));
return FALSE;
}
// Perform one-time configuration tasks
if (m_SensorConfigured == FALSE)
{
if (!CameraSensorConfig())
{
return FALSE;
}
m_SensorConfigured = TRUE;
}
//----------------------------------------------------
// Configure viewfinding path if Preview pin is used
// and configuration is needed.
//----------------------------------------------------
if (m_bCameraConfig == FALSE)
{
if (!CameraPrpConfig(iBufNum))
{
return FALSE;
}
// Camera has been configured
m_bCameraConfig = TRUE;
}
CAM_FUNCTION_EXIT();
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: CameraSensorConfig
//
// This function configures the camera sensor.
//
// Parameters:
// None.
//
// Returns:
// TRUE if success
// FALSE if failure
//
//-----------------------------------------------------------------------------
BOOL CCameraDevice::CameraSensorConfig()
{
csiSensorOutputFormat sensorOutputFormat;
csiSensorOutputResolution sensorOutputResolution;
DWORD sensorFormat,sensorResolution;
CAM_FUNCTION_ENTRY();
//----------------------------------------------------
// Configure camera sensor and CSI
//----------------------------------------------------
BSPGetSensorFormat(&sensorFormat);
BSPGetSensorResolution(&sensorResolution);
sensorOutputFormat = (csiSensorOutputFormat) sensorFormat;
sensorOutputResolution = (csiSensorOutputResolution) sensorResolution;
if (!m_pCsi->CsiConfigureSensor(sensorOutputFormat, sensorOutputResolution))
{
DEBUGMSG(ZONE_ERROR, (TEXT("%s: Sensor configuration failed. Aborting remaining configuration steps.\r\n"), __WFUNCTION__));
return FALSE;
}
//----------------------------------------------------
// Set up preprocessor input parameters common
// to both encoding and viewfinding tasks
//----------------------------------------------------
if (sensorOutputFormat == csiSensorOutputFormat_RGB)
{
m_inFormat = prpInputFormat_RGB16; // Interlaced RGB888
}
else if ((sensorOutputFormat == csiSensorOutputFormat_YUV422) ||
(sensorOutputFormat == csiSensorOutputFormat_YUV422))
{
m_inFormat = prpInputFormat_UYVY422; // Interlaced YUV444
}
else
{
//m_inFormat = prpInputFormat_Generic; // Bayer data
DEBUGMSG(ZONE_ERROR, (TEXT("%s: Sensor configuration failed. Don't Support the sensor output format.\r\n"), __WFUNCTION__));
return FALSE;
}
// m_inFormat = prpInputFormat_RGB; // Use this if we are
// are using CSI test pattern.
// Set up Preproc input width and height configuration
// parameters from the output resolution.
switch (sensorOutputResolution)
{
case csiSensorOutputResolution_SXGA:
m_inFrameSize.width = 1280;
m_inFrameSize.height = 960;
break;
case csiSensorOutputResolution_VGA:
m_inFrameSize.width = 640;
m_inFrameSize.height = 480;
break;
case csiSensorOutputResolution_QVGA:
m_inFrameSize.width = 320;
m_inFrameSize.height = 240;
break;
case csiSensorOutputResolution_CIF:
m_inFrameSize.width = 352;
m_inFrameSize.height = 288;
break;
case csiSensorOutputResolution_QCIF:
m_inFrameSize.width = 176;
m_inFrameSize.height = 144;
break;
case csiSensorOutputResolution_QQVGA:
m_inFrameSize.width = 160;
m_inFrameSize.height = 120;
break;
case csiSensorOutputResolution_PAL:
m_inFrameSize.width = 720;
m_inFrameSize.height = 288;
break;
case csiSensorOutputResolution_NTSC:
m_inFrameSize.width = 720;
m_inFrameSize.height = 244;
break;
default:
break;
}
CAM_FUNCTION_EXIT();
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: CameraPrpConfig
//
// This function configures the camera sensor and preprocessing module.
//
// Parameters:
// iBufNum
// [in] Number of buffers to allocate for Pre-processing
//
// Returns:
// TRUE if success
// FALSE if failure
//
//-----------------------------------------------------------------------------
BOOL CCameraDevice::CameraPrpConfig(UINT32 iBufNum)
{
DWORD Format;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -