📄 cameradevice.cpp.svn-base
字号:
/**************************************************************************
** INTEL CONFIDENTIAL
** Copyright 2000-2004 Intel Corporation. All Rights Reserved.
**
** The source code contained or described herein and all documents
** related to the source code (Material) are owned by Intel Corporation
** or its suppliers or licensors. Title to the Material remains with
** Intel Corporation or its suppliers and licensors. The Material contains
** trade secrets and proprietary and confidential information of Intel
** or its suppliers and licensors. The Material is protected by worldwide
** copyright and trade secret laws and treaty provisions. No part of the
** Material may be used, copied, reproduced, modified, published, uploaded,
** posted, transmitted, distributed, or disclosed in any way without Intel抯
** prior express written permission.
** No license under any patent, copyright, trade secret or other intellectual
** property right is granted to or conferred upon you by disclosure or
** delivery of the Materials, either expressly, by implication, inducement,
** estoppel or otherwise. Any license under such intellectual property rights
** must be express and approved by Intel in writing.
********************************************************************************/
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
#include <windows.h>
#include "CameraDriver.h"
#include "camera.h"
#include "PinDriver.h"
#define EXTERN_PROP_VALUES
#include "adapterprops.h"
extern "C"
{
extern PVOID VirtualAllocCopyPhysical(unsigned size,char *str,PVOID pPhysicalAddress);
}
BOOL
ConvertStringToGuid(
LPCTSTR GuidString,
GUID * Guid
)
{
// ConvertStringToGuid
// this routine converts a string into a GUID and returns TRUE if the
// conversion was successful.
// Local variables.
UINT Data4[8];
int Count;
BOOL Ok = FALSE;
LPWSTR GuidFormat = L"{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}";
DEBUGCHK(Guid != NULL && GuidString != NULL);
__try
{
if (_stscanf(GuidString, GuidFormat, &Guid->Data1,
&Guid->Data2, &Guid->Data3, &Data4[0], &Data4[1], &Data4[2], &Data4[3],
&Data4[4], &Data4[5], &Data4[6], &Data4[7]) == 11)
{
for (Count = 0; Count < (sizeof(Data4) / sizeof(Data4[0])); Count++)
{
Guid->Data4[Count] = (UCHAR) Data4[Count];
}
}
Ok = TRUE;
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
return Ok;
}
CCameraDevice::CCameraDevice( )
{
m_hStream = NULL;
m_hCallerProcess = NULL;
InitializeCriticalSection( &m_csDevice );
m_ulCTypes = 0;
memset( m_StrmInstances, 0x0, sizeof ( STREAM_INSTANCES ) * MAX_SUPPORTED_PINS );
memset( m_DevProps, 0x0, sizeof ( DEV_PROPERTY ) * NUM_PROPERTY_ITEMS );
m_vpBoardLevelRegister = NULL;
memset( m_CameraHWVideoBuffers, 0x0, sizeof ( CAMERA_DMA_BUFFER_INFO ) * MAX_HW_FRAMES );
memset( &m_CameraHWStillBuffer, 0x0, sizeof ( CAMERA_DMA_BUFFER_INFO ) );
m_ulCurrentFrame = 0;
m_hCameraShutdownComplete = NULL;
m_bCameraHWRunning = false;
m_bNewFrameReady = false;
}
CCameraDevice::~CCameraDevice( )
{
DeleteCriticalSection( &m_csDevice );
if ( NULL != m_hStream )
{
DeactivateDevice( m_hStream );
}
if (!DeAllocateHWBuffers(VIDEO_CAPTURE_BUFFER) || !DeAllocateHWBuffers(STILL_CAPTURE_BUFFER))
{
DEBUGMSG( ZONE_INIT|ZONE_ERROR, ( _T("CAM_DeInit: DeAllocateHWBuffers() failed\r\n") ) );
}
// Shutdown camera sensor h/w
CameraShutdown();
CloseHandle(m_hCameraShutdownComplete);
}
bool
CCameraDevice::Initialize(
PVOID context
)
{
// Mainstone II specific memory allocation
m_vpBoardLevelRegister=(volatile MAINSTONEII_BLR_REGS *)VirtualAllocCopyPhysical(sizeof(MAINSTONEII_BLR_REGS),"CAM_Init : v_pBoardLevelRegister",(PVOID)MAINSTONEII_BASE_REG_PA_FPGA);
if (!m_vpBoardLevelRegister)
{
return false;
}
// Initialize Intel PXA27x camera interface h/w
if (!CameraInit())
{
DEBUGMSG( ZONE_INIT|ZONE_ERROR, ( _T("CAM_Init: CameraInit() failed\r\n") ) );
return false;
}
// Camera sensor specific information (Agilent ADCM2650)
XllpCAMERA.sensor_type = XLLP_CAMERA_TYPE_ADCM_2650;
pFunctions.init = CameraFuncADCM2650Init;
pFunctions.deinit = CameraFuncADCM2650DeInit;
pFunctions.set_capture_format = CameraFuncADCM2650SetCaptureFormat;
pFunctions.start_capture = CameraFuncADCM2650StartCapture;
pFunctions.stop_capture = CameraFuncADCM2650StopCapture;
// os mapped register address
XllpCAMERA.board_reg_base = reinterpret_cast<unsigned int>(m_vpBoardLevelRegister);
// capture image info
XllpCAMERA.capture_width = DEFAULT_VIDEO_WIDTH;
XllpCAMERA.capture_height = DEFAULT_VIDEO_HEIGHT;
XllpCAMERA.Video_capture_width = DEFAULT_VIDEO_WIDTH;
XllpCAMERA.Video_capture_height = DEFAULT_VIDEO_HEIGHT;
XllpCAMERA.Video_capture_width = DEFAULT_VIDEO_WIDTH;
XllpCAMERA.Video_capture_height = DEFAULT_VIDEO_HEIGHT;
XllpCAMERA.Still_capture_width = DEFAULT_STILL_WIDTH;
XllpCAMERA.Still_capture_height = DEFAULT_STILL_HEIGHT;
XllpCAMERA.sensor_flip_mode = XLLP_CAMERA_VIDEO_FLIP_HORIZONTAL | XLLP_CAMERA_STILL_FLIP_HORIZONTAL;
XllpCAMERA.capture_input_format = DEFAULT_CAMERA_INPUT_FORMAT;
XllpCAMERA.capture_output_format = DEFAULT_CAMERA_OUTPUT_FORMAT;
if (!CameraInitSensor())
{
DEBUGMSG( ZONE_INIT|ZONE_ERROR, ( _T("CAM_Init: CameraInitSensor() failed\r\n") ) );
return false;
}
if (!AllocateHWBuffers(VIDEO_CAPTURE_BUFFER) || !AllocateHWBuffers(STILL_CAPTURE_BUFFER))
{
DEBUGMSG( ZONE_INIT|ZONE_ERROR, ( _T("CAM_Init: AllocateHWBuffers() failed\r\n") ) );
return false;
}
dwCameraDriverContext = reinterpret_cast<DWORD>( this );
// This callback function is used to signal the application that the video frame is now available.
pfnCameraHandleVideoFrame = CameraVideoFrameCallback;
// This callback function is used to signal the application that the still image is now available.
pfnCameraHandleStillFrame = CameraStillFrameCallback;
// This event is used to signal the application that the driver has completed the shutdown sequence.
m_hCameraShutdownComplete = CreateEvent(NULL, FALSE, FALSE, CAMERA_SHUTDOWN_COMPLETE);
m_hStream = ActivateDeviceEx( PIN_REG_PATH, NULL, 0, reinterpret_cast<LPVOID>( this ) );
if ( NULL == m_hStream )
{
DEBUGMSG( ZONE_INIT|ZONE_ERROR, ( _T("CAM_Init: ActivateDevice on Pin failed\r\n") ) );
return false;
}
m_ulCTypes = 3;
//VideoProcAmp
m_DevProps[ENUM_BRIGHTNESS].ulCurrentValue = BrightnessDefault;
m_DevProps[ENUM_BRIGHTNESS].ulDefaultValue = BrightnessDefault;
m_DevProps[ENUM_BRIGHTNESS].pRangeNStep = &BrightnessRangeAndStep[0];
m_DevProps[ENUM_BRIGHTNESS].ulFlags = CSPROPERTY_VIDEOPROCAMP_FLAGS_MANUAL;
m_DevProps[ENUM_BRIGHTNESS].ulCapabilities = CSPROPERTY_VIDEOPROCAMP_FLAGS_MANUAL|CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_DevProps[ENUM_BRIGHTNESS].fSetSupported = VideoProcAmpProperties[ENUM_BRIGHTNESS].SetSupported;
m_DevProps[ENUM_BRIGHTNESS].fGetSupported = VideoProcAmpProperties[ENUM_BRIGHTNESS].GetSupported;
m_DevProps[ENUM_BRIGHTNESS].pCsPropValues = &BrightnessValues;
m_DevProps[ENUM_CONTRAST].ulCurrentValue = ContrastDefault;
m_DevProps[ENUM_CONTRAST].ulDefaultValue = ContrastDefault;
m_DevProps[ENUM_CONTRAST].pRangeNStep = &ContrastRangeAndStep[0];
m_DevProps[ENUM_CONTRAST].ulFlags = CSPROPERTY_VIDEOPROCAMP_FLAGS_MANUAL;
m_DevProps[ENUM_CONTRAST].ulCapabilities = CSPROPERTY_VIDEOPROCAMP_FLAGS_MANUAL|CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_DevProps[ENUM_CONTRAST].fSetSupported = VideoProcAmpProperties[ENUM_CONTRAST].SetSupported;
m_DevProps[ENUM_CONTRAST].fGetSupported = VideoProcAmpProperties[ENUM_CONTRAST].GetSupported;
m_DevProps[ENUM_CONTRAST].pCsPropValues = &ContrastValues;
m_DevProps[ENUM_HUE].ulCurrentValue = HueDefault;
m_DevProps[ENUM_HUE].ulDefaultValue = HueDefault;
m_DevProps[ENUM_HUE].pRangeNStep = &HueRangeAndStep[0];
m_DevProps[ENUM_HUE].ulFlags = CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_DevProps[ENUM_HUE].ulCapabilities = CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_DevProps[ENUM_HUE].fSetSupported = VideoProcAmpProperties[ENUM_HUE].SetSupported;
m_DevProps[ENUM_HUE].fGetSupported = VideoProcAmpProperties[ENUM_HUE].GetSupported;
m_DevProps[ENUM_HUE].pCsPropValues = &HueValues;
m_DevProps[ENUM_SATURATION].ulCurrentValue = SaturationDefault;
m_DevProps[ENUM_SATURATION].ulDefaultValue = SaturationDefault;
m_DevProps[ENUM_SATURATION].pRangeNStep = &SaturationRangeAndStep[0];
m_DevProps[ENUM_SATURATION].ulFlags = CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_DevProps[ENUM_SATURATION].ulCapabilities = CSPROPERTY_VIDEOPROCAMP_FLAGS_MANUAL|CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_DevProps[ENUM_SATURATION].fSetSupported = VideoProcAmpProperties[ENUM_SATURATION].SetSupported;
m_DevProps[ENUM_SATURATION].fGetSupported = VideoProcAmpProperties[ENUM_SATURATION].GetSupported;
m_DevProps[ENUM_SATURATION].pCsPropValues = &SaturationValues;
m_DevProps[ENUM_SHARPNESS].ulCurrentValue = SharpnessDefault;
m_DevProps[ENUM_SHARPNESS].ulDefaultValue = SharpnessDefault;
m_DevProps[ENUM_SHARPNESS].pRangeNStep = &SharpnessRangeAndStep[0];
m_DevProps[ENUM_SHARPNESS].ulFlags = CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_DevProps[ENUM_SHARPNESS].ulCapabilities = CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_DevProps[ENUM_SHARPNESS].fSetSupported = VideoProcAmpProperties[ENUM_SHARPNESS].SetSupported;
m_DevProps[ENUM_SHARPNESS].fGetSupported = VideoProcAmpProperties[ENUM_SHARPNESS].GetSupported;
m_DevProps[ENUM_SHARPNESS].pCsPropValues = &SharpnessValues;
m_DevProps[ENUM_GAMMA].ulCurrentValue = GammaDefault;
m_DevProps[ENUM_GAMMA].ulDefaultValue = GammaDefault;
m_DevProps[ENUM_GAMMA].pRangeNStep = &GammaRangeAndStep[0];
m_DevProps[ENUM_GAMMA].ulFlags = CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_DevProps[ENUM_GAMMA].ulCapabilities = CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_DevProps[ENUM_GAMMA].fSetSupported = VideoProcAmpProperties[ENUM_GAMMA].SetSupported;
m_DevProps[ENUM_GAMMA].fGetSupported = VideoProcAmpProperties[ENUM_GAMMA].GetSupported;
m_DevProps[ENUM_GAMMA].pCsPropValues = &GammaValues;
m_DevProps[ENUM_COLORENABLE].ulCurrentValue = ColorEnableDefault;
m_DevProps[ENUM_COLORENABLE].ulDefaultValue = ColorEnableDefault;
m_DevProps[ENUM_COLORENABLE].pRangeNStep = &ColorEnableRangeAndStep[0];
m_DevProps[ENUM_COLORENABLE].ulFlags = CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_DevProps[ENUM_COLORENABLE].ulCapabilities = CSPROPERTY_VIDEOPROCAMP_FLAGS_MANUAL|CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_DevProps[ENUM_COLORENABLE].fSetSupported = VideoProcAmpProperties[ENUM_COLORENABLE].SetSupported;
m_DevProps[ENUM_COLORENABLE].fGetSupported = VideoProcAmpProperties[ENUM_COLORENABLE].GetSupported;
m_DevProps[ENUM_COLORENABLE].pCsPropValues = &ColorEnableValues;
m_DevProps[ENUM_WHITEBALANCE].ulCurrentValue = WhiteBalanceDefault;
m_DevProps[ENUM_WHITEBALANCE].ulDefaultValue = WhiteBalanceDefault;
m_DevProps[ENUM_WHITEBALANCE].pRangeNStep = &WhiteBalanceRangeAndStep[0];
m_DevProps[ENUM_WHITEBALANCE].ulFlags = CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_DevProps[ENUM_WHITEBALANCE].ulCapabilities = CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_DevProps[ENUM_WHITEBALANCE].fSetSupported = VideoProcAmpProperties[ENUM_WHITEBALANCE].SetSupported;
m_DevProps[ENUM_WHITEBALANCE].fGetSupported = VideoProcAmpProperties[ENUM_WHITEBALANCE].GetSupported;
m_DevProps[ENUM_WHITEBALANCE].pCsPropValues = &WhiteBalanceValues;
m_DevProps[ENUM_BACKLIGHT_COMPENSATION].ulCurrentValue = BackLightCompensationDefault;
m_DevProps[ENUM_BACKLIGHT_COMPENSATION].ulDefaultValue = BackLightCompensationDefault;
m_DevProps[ENUM_BACKLIGHT_COMPENSATION].pRangeNStep = &BackLightCompensationRangeAndStep[0];
m_DevProps[ENUM_BACKLIGHT_COMPENSATION].ulFlags = CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_DevProps[ENUM_BACKLIGHT_COMPENSATION].ulCapabilities = CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_DevProps[ENUM_BACKLIGHT_COMPENSATION].fSetSupported = VideoProcAmpProperties[ENUM_BACKLIGHT_COMPENSATION].SetSupported;
m_DevProps[ENUM_BACKLIGHT_COMPENSATION].fGetSupported = VideoProcAmpProperties[ENUM_BACKLIGHT_COMPENSATION].GetSupported;
m_DevProps[ENUM_BACKLIGHT_COMPENSATION].pCsPropValues = &BackLightCompensationValues;
m_DevProps[ENUM_GAIN].ulCurrentValue = GainDefault;
m_DevProps[ENUM_GAIN].ulDefaultValue = GainDefault;
m_DevProps[ENUM_GAIN].pRangeNStep = &GainRangeAndStep[0];
m_DevProps[ENUM_GAIN].ulFlags = CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_DevProps[ENUM_GAIN].ulCapabilities = CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_DevProps[ENUM_GAIN].fSetSupported = VideoProcAmpProperties[ENUM_GAIN].SetSupported;
m_DevProps[ENUM_GAIN].fGetSupported = VideoProcAmpProperties[ENUM_GAIN].GetSupported;
m_DevProps[ENUM_GAIN].pCsPropValues = &GainValues;
//CameraControl
m_DevProps[ENUM_PAN].ulCurrentValue = PanDefault;
m_DevProps[ENUM_PAN].ulDefaultValue = PanDefault;
m_DevProps[ENUM_PAN].pRangeNStep = &PanRangeAndStep[0];
m_DevProps[ENUM_PAN].ulFlags = CSPROPERTY_CAMERACONTROL_FLAGS_AUTO;
m_DevProps[ENUM_PAN].ulCapabilities = CSPROPERTY_CAMERACONTROL_FLAGS_MANUAL|CSPROPERTY_CAMERACONTROL_FLAGS_AUTO;
m_DevProps[ENUM_PAN].fSetSupported = VideoProcAmpProperties[ENUM_PAN-NUM_VIDEOPROCAMP_ITEMS].SetSupported;
m_DevProps[ENUM_PAN].fGetSupported = VideoProcAmpProperties[ENUM_PAN-NUM_VIDEOPROCAMP_ITEMS].GetSupported;
m_DevProps[ENUM_PAN].pCsPropValues = &PanValues;
m_DevProps[ENUM_TILT].ulCurrentValue = TiltDefault;
m_DevProps[ENUM_TILT].ulDefaultValue = TiltDefault;
m_DevProps[ENUM_TILT].pRangeNStep = &TiltRangeAndStep[0];
m_DevProps[ENUM_TILT].ulFlags = CSPROPERTY_CAMERACONTROL_FLAGS_AUTO;
m_DevProps[ENUM_TILT].ulCapabilities = CSPROPERTY_CAMERACONTROL_FLAGS_MANUAL|CSPROPERTY_CAMERACONTROL_FLAGS_AUTO;
m_DevProps[ENUM_TILT].fSetSupported = VideoProcAmpProperties[ENUM_TILT-NUM_VIDEOPROCAMP_ITEMS].SetSupported;
m_DevProps[ENUM_TILT].fGetSupported = VideoProcAmpProperties[ENUM_TILT-NUM_VIDEOPROCAMP_ITEMS].GetSupported;
m_DevProps[ENUM_TILT].pCsPropValues = &TiltValues;
m_DevProps[ENUM_ROLL].ulCurrentValue = RollDefault;
m_DevProps[ENUM_ROLL].ulDefaultValue = RollDefault;
m_DevProps[ENUM_ROLL].pRangeNStep = &RollRangeAndStep[0];
m_DevProps[ENUM_ROLL].ulFlags = CSPROPERTY_CAMERACONTROL_FLAGS_AUTO;
m_DevProps[ENUM_ROLL].ulCapabilities = CSPROPERTY_CAMERACONTROL_FLAGS_MANUAL|CSPROPERTY_CAMERACONTROL_FLAGS_AUTO;
m_DevProps[ENUM_ROLL].fSetSupported = VideoProcAmpProperties[ENUM_ROLL-NUM_VIDEOPROCAMP_ITEMS].SetSupported;
m_DevProps[ENUM_ROLL].fGetSupported = VideoProcAmpProperties[ENUM_ROLL-NUM_VIDEOPROCAMP_ITEMS].GetSupported;
m_DevProps[ENUM_ROLL].pCsPropValues = &RollValues;
m_DevProps[ENUM_ZOOM].ulCurrentValue = ZoomDefault;
m_DevProps[ENUM_ZOOM].ulDefaultValue = ZoomDefault;
m_DevProps[ENUM_ZOOM].pRangeNStep = &ZoomRangeAndStep[0];
m_DevProps[ENUM_ZOOM].ulFlags = CSPROPERTY_CAMERACONTROL_FLAGS_AUTO;
m_DevProps[ENUM_ZOOM].ulCapabilities = CSPROPERTY_CAMERACONTROL_FLAGS_MANUAL|CSPROPERTY_CAMERACONTROL_FLAGS_AUTO;
m_DevProps[ENUM_ZOOM].fSetSupported = VideoProcAmpProperties[ENUM_ZOOM-NUM_VIDEOPROCAMP_ITEMS].SetSupported;
m_DevProps[ENUM_ZOOM].fGetSupported = VideoProcAmpProperties[ENUM_ZOOM-NUM_VIDEOPROCAMP_ITEMS].GetSupported;
m_DevProps[ENUM_ZOOM].pCsPropValues = &ZoomValues;
m_DevProps[ENUM_IRIS].ulCurrentValue = IrisDefault;
m_DevProps[ENUM_IRIS].ulDefaultValue = IrisDefault;
m_DevProps[ENUM_IRIS].pRangeNStep = &IrisRangeAndStep[0];
m_DevProps[ENUM_IRIS].ulFlags = CSPROPERTY_CAMERACONTROL_FLAGS_AUTO;
m_DevProps[ENUM_IRIS].ulCapabilities = CSPROPERTY_CAMERACONTROL_FLAGS_MANUAL|CSPROPERTY_CAMERACONTROL_FLAGS_AUTO;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -