📄 camerapdd.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
//
/******************************************************************************
** Copyright 2000-2003 Intel Corporation All Rights Reserved.
**
** Portions of the source code contained or described herein and all documents
** related to such source code (Material) are owned by Intel Corporation
** or its suppliers or licensors and is licensed by Microsoft Corporation for distribution.
** Title to the Material remains with Intel Corporation or its suppliers and licensors.
** Use of the Materials is subject to the terms of the Microsoft license agreement which accompanied the Materials.
** No other 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
** Some portion of the Materials may be copyrighted by Microsoft Corporation.
**
********************************************************************************/
#include <windows.h>
#include <pm.h>
#include <types.h>
#include <string.h>
#include <stdio.h>
#include <tchar.h>
#include <ceddk.h>
#include <bulverde.h>
#include <mainstoneii.h>
#include <xllp_i2c.h>
#include "Cs.h"
#include "Csmedia.h"
#include "CameraPDDProps.h"
#include "dstruct.h"
#include "dbgsettings.h"
#include <camera.h>
#include "CameraDriver.h"
#include "SensorFormats.h"
#include "SensorProperties.h"
#include "PinDriver.h"
extern "C" {
#include "bulverde_camera.h"
}
#include "cameraPdd.h"
#include "wchar.h"
#include "pdd_intf.h"
extern "C" {
#include "ADCM2650.h"
}
#define WIDTHBYTES(bits) ((DWORD)(((bits)+31) & (~31)) / 8)
void CameraVideoFrameCallback(DWORD dwContext);
void CameraStillFrameCallback(DWORD dwContext);
PDDFUNCTBL FuncTbl = {
sizeof(PDDFUNCTBL),
PDD_Init,
PDD_DeInit,
PDD_GetAdapterInfo,
PDD_HandleVidProcAmpChanges,
PDD_HandleCamControlChanges,
PDD_HandleVideoControlCapsChanges,
PDD_SetPowerState,
PDD_HandleAdapterCustomProperties,
PDD_InitSensorMode,
PDD_DeInitSensorMode,
PDD_SetSensorState,
PDD_TakeStillPicture,
PDD_GetSensorModeInfo,
PDD_SetSensorModeFormat,
PDD_AllocateBuffer,
PDD_DeAllocateBuffer,
PDD_RegisterClientBuffer,
PDD_UnRegisterClientBuffer,
PDD_FillBuffer,
PDD_HandleModeCustomProperties
};
const POWER_CAPABILITIES s_PowerCaps =
{
// DeviceDx: Supported power states
DX_MASK(D0 )| DX_MASK(D2) | DX_MASK(D3) | DX_MASK(D4),
0, // WakeFromDx:
0, // InrushDx: No inrush of power
{ // Power: Maximum milliwatts in each state
0x00000001, // D0 = 0
0x00000001, // D1 = 0
0x00000001, // D2 = 0
0x00000001, // D3 = 0
0x00000001 // D4 = 0 (off)
},
{ // Latency
0x00000000, // D0 = 0
0x00000000, // D1 = 0
0x00000000, // D2 = 0
0x00000000, // D3 = 0
0x00000000 // D4 = 0
},
0, // Flags: None
};
CCameraPdd::CCameraPdd()
{
m_ulCTypes = 2;
m_hContext = NULL;
m_pModeVideoFormat = NULL;
m_pModeVideoCaps = NULL;
m_ppModeContext = NULL;
m_ulCurrentFrame = 0;
m_bCameraHWRunning = FALSE;
m_bStillInProgress = FALSE;
m_PowerState = D0;
memset( &m_CsState, 0x0, sizeof(m_CsState));
memset( &m_CsPrevState, 0x0, sizeof(m_CsPrevState));
memset( &m_SensorModeInfo, 0x0, sizeof(m_SensorModeInfo));
memset( &m_SensorProps, 0x0, sizeof(m_SensorProps));
memset( &PowerCaps, 0x0, sizeof(PowerCaps));
memset( &m_CurrentFormat, 0x0, sizeof(m_CurrentFormat));
}
CCameraPdd::~CCameraPdd()
{
if( NULL != m_pModeVideoCaps )
{
delete [] m_pModeVideoCaps;
m_pModeVideoCaps = NULL;
}
if( NULL != m_pModeVideoFormat )
{
delete [] m_pModeVideoFormat;
m_pModeVideoFormat = NULL;
}
if( NULL != m_ppModeContext )
{
delete [] m_ppModeContext;
m_ppModeContext = NULL;
}
}
DWORD CCameraPdd::PDDInit( PVOID MDDContext, PPDDFUNCTBL pPDDFuncTbl )
{
DWORD hr = ERROR_SUCCESS;
if(!MDDContext)
{
DEBUGMSG( ZONE_ERROR, ( _T("PddInit:FAILED NULL MDD context\r\n") ) );
hr = ERROR_INVALID_PARAMETER;
goto ErrorExit;
}
// Save the MDD context for future use...
m_hContext = (HANDLE)MDDContext;
// Call CameraInit()
// It initializes Bulverde registers, create events and interrupt thread,
// and initialize sensor with default parameter.
if (!CameraInit(MDDContext))
{
DEBUGMSG( ZONE_ERROR, ( _T("PddInit:FAILED to Initialize camera\r\n") ) );
CameraDeinit();
goto ErrorExit;
}
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;
// We support only 2 PIN driver. Preview and Still.
m_ulCTypes = 2; // Default number of Sensor Modes is 2
// Return the function table if you have sufficient memory.
if( pPDDFuncTbl->dwSize > sizeof( PDDFUNCTBL ) )
{
DEBUGMSG( ZONE_ERROR, ( _T("PddInit:Out of Memory\r\n") ) );
hr = ERROR_INSUFFICIENT_BUFFER;
goto ErrorExit;
}
memcpy( pPDDFuncTbl, &FuncTbl, sizeof( PDDFUNCTBL ) );
memset( m_SensorProps, 0x0, sizeof(m_SensorProps) );
memcpy( &PowerCaps, &s_PowerCaps, sizeof( POWER_CAPABILITIES ) );
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Set all VideoProcAmp and CameraControl properties.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//VideoProcAmp
m_SensorProps[ENUM_BRIGHTNESS].ulCurrentValue = BrightnessDefault;
m_SensorProps[ENUM_BRIGHTNESS].ulDefaultValue = BrightnessDefault;
m_SensorProps[ENUM_BRIGHTNESS].pRangeNStep = &BrightnessRangeAndStep[0];
m_SensorProps[ENUM_BRIGHTNESS].ulFlags = CSPROPERTY_VIDEOPROCAMP_FLAGS_MANUAL;
m_SensorProps[ENUM_BRIGHTNESS].ulCapabilities = CSPROPERTY_VIDEOPROCAMP_FLAGS_MANUAL|CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_SensorProps[ENUM_BRIGHTNESS].fSetSupported = VideoProcAmpProperties[ENUM_BRIGHTNESS].SetSupported;
m_SensorProps[ENUM_BRIGHTNESS].fGetSupported = VideoProcAmpProperties[ENUM_BRIGHTNESS].GetSupported;
m_SensorProps[ENUM_BRIGHTNESS].pCsPropValues = &BrightnessValues;
m_SensorProps[ENUM_CONTRAST].ulCurrentValue = ContrastDefault;
m_SensorProps[ENUM_CONTRAST].ulDefaultValue = ContrastDefault;
m_SensorProps[ENUM_CONTRAST].pRangeNStep = &ContrastRangeAndStep[0];
m_SensorProps[ENUM_CONTRAST].ulFlags = CSPROPERTY_VIDEOPROCAMP_FLAGS_MANUAL;
m_SensorProps[ENUM_CONTRAST].ulCapabilities = CSPROPERTY_VIDEOPROCAMP_FLAGS_MANUAL|CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_SensorProps[ENUM_CONTRAST].fSetSupported = VideoProcAmpProperties[ENUM_CONTRAST].SetSupported;
m_SensorProps[ENUM_CONTRAST].fGetSupported = VideoProcAmpProperties[ENUM_CONTRAST].GetSupported;
m_SensorProps[ENUM_CONTRAST].pCsPropValues = &ContrastValues;
m_SensorProps[ENUM_HUE].ulCurrentValue = HueDefault;
m_SensorProps[ENUM_HUE].ulDefaultValue = HueDefault;
m_SensorProps[ENUM_HUE].pRangeNStep = &HueRangeAndStep[0];
m_SensorProps[ENUM_HUE].ulFlags = CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_SensorProps[ENUM_HUE].ulCapabilities = CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_SensorProps[ENUM_HUE].fSetSupported = VideoProcAmpProperties[ENUM_HUE].SetSupported;
m_SensorProps[ENUM_HUE].fGetSupported = VideoProcAmpProperties[ENUM_HUE].GetSupported;
m_SensorProps[ENUM_HUE].pCsPropValues = &HueValues;
m_SensorProps[ENUM_SATURATION].ulCurrentValue = SaturationDefault;
m_SensorProps[ENUM_SATURATION].ulDefaultValue = SaturationDefault;
m_SensorProps[ENUM_SATURATION].pRangeNStep = &SaturationRangeAndStep[0];
m_SensorProps[ENUM_SATURATION].ulFlags = CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_SensorProps[ENUM_SATURATION].ulCapabilities = CSPROPERTY_VIDEOPROCAMP_FLAGS_MANUAL|CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_SensorProps[ENUM_SATURATION].fSetSupported = VideoProcAmpProperties[ENUM_SATURATION].SetSupported;
m_SensorProps[ENUM_SATURATION].fGetSupported = VideoProcAmpProperties[ENUM_SATURATION].GetSupported;
m_SensorProps[ENUM_SATURATION].pCsPropValues = &SaturationValues;
m_SensorProps[ENUM_SHARPNESS].ulCurrentValue = SharpnessDefault;
m_SensorProps[ENUM_SHARPNESS].ulDefaultValue = SharpnessDefault;
m_SensorProps[ENUM_SHARPNESS].pRangeNStep = &SharpnessRangeAndStep[0];
m_SensorProps[ENUM_SHARPNESS].ulFlags = CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_SensorProps[ENUM_SHARPNESS].ulCapabilities = CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_SensorProps[ENUM_SHARPNESS].fSetSupported = VideoProcAmpProperties[ENUM_SHARPNESS].SetSupported;
m_SensorProps[ENUM_SHARPNESS].fGetSupported = VideoProcAmpProperties[ENUM_SHARPNESS].GetSupported;
m_SensorProps[ENUM_SHARPNESS].pCsPropValues = &SharpnessValues;
m_SensorProps[ENUM_GAMMA].ulCurrentValue = GammaDefault;
m_SensorProps[ENUM_GAMMA].ulDefaultValue = GammaDefault;
m_SensorProps[ENUM_GAMMA].pRangeNStep = &GammaRangeAndStep[0];
m_SensorProps[ENUM_GAMMA].ulFlags = CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_SensorProps[ENUM_GAMMA].ulCapabilities = CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_SensorProps[ENUM_GAMMA].fSetSupported = VideoProcAmpProperties[ENUM_GAMMA].SetSupported;
m_SensorProps[ENUM_GAMMA].fGetSupported = VideoProcAmpProperties[ENUM_GAMMA].GetSupported;
m_SensorProps[ENUM_GAMMA].pCsPropValues = &GammaValues;
m_SensorProps[ENUM_COLORENABLE].ulCurrentValue = ColorEnableDefault;
m_SensorProps[ENUM_COLORENABLE].ulDefaultValue = ColorEnableDefault;
m_SensorProps[ENUM_COLORENABLE].pRangeNStep = &ColorEnableRangeAndStep[0];
m_SensorProps[ENUM_COLORENABLE].ulFlags = CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_SensorProps[ENUM_COLORENABLE].ulCapabilities = CSPROPERTY_VIDEOPROCAMP_FLAGS_MANUAL|CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_SensorProps[ENUM_COLORENABLE].fSetSupported = VideoProcAmpProperties[ENUM_COLORENABLE].SetSupported;
m_SensorProps[ENUM_COLORENABLE].fGetSupported = VideoProcAmpProperties[ENUM_COLORENABLE].GetSupported;
m_SensorProps[ENUM_COLORENABLE].pCsPropValues = &ColorEnableValues;
m_SensorProps[ENUM_WHITEBALANCE].ulCurrentValue = WhiteBalanceDefault;
m_SensorProps[ENUM_WHITEBALANCE].ulDefaultValue = WhiteBalanceDefault;
m_SensorProps[ENUM_WHITEBALANCE].pRangeNStep = &WhiteBalanceRangeAndStep[0];
m_SensorProps[ENUM_WHITEBALANCE].ulFlags = CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_SensorProps[ENUM_WHITEBALANCE].ulCapabilities = CSPROPERTY_VIDEOPROCAMP_FLAGS_MANUAL|CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_SensorProps[ENUM_WHITEBALANCE].fSetSupported = VideoProcAmpProperties[ENUM_WHITEBALANCE].SetSupported;
m_SensorProps[ENUM_WHITEBALANCE].fGetSupported = VideoProcAmpProperties[ENUM_WHITEBALANCE].GetSupported;
m_SensorProps[ENUM_WHITEBALANCE].pCsPropValues = &WhiteBalanceValues;
m_SensorProps[ENUM_BACKLIGHT_COMPENSATION].ulCurrentValue = BackLightCompensationDefault;
m_SensorProps[ENUM_BACKLIGHT_COMPENSATION].ulDefaultValue = BackLightCompensationDefault;
m_SensorProps[ENUM_BACKLIGHT_COMPENSATION].pRangeNStep = &BackLightCompensationRangeAndStep[0];
m_SensorProps[ENUM_BACKLIGHT_COMPENSATION].ulFlags = CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_SensorProps[ENUM_BACKLIGHT_COMPENSATION].ulCapabilities = CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_SensorProps[ENUM_BACKLIGHT_COMPENSATION].fSetSupported = VideoProcAmpProperties[ENUM_BACKLIGHT_COMPENSATION].SetSupported;
m_SensorProps[ENUM_BACKLIGHT_COMPENSATION].fGetSupported = VideoProcAmpProperties[ENUM_BACKLIGHT_COMPENSATION].GetSupported;
m_SensorProps[ENUM_BACKLIGHT_COMPENSATION].pCsPropValues = &BackLightCompensationValues;
m_SensorProps[ENUM_GAIN].ulCurrentValue = GainDefault;
m_SensorProps[ENUM_GAIN].ulDefaultValue = GainDefault;
m_SensorProps[ENUM_GAIN].pRangeNStep = &GainRangeAndStep[0];
m_SensorProps[ENUM_GAIN].ulFlags = CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_SensorProps[ENUM_GAIN].ulCapabilities = CSPROPERTY_VIDEOPROCAMP_FLAGS_AUTO;
m_SensorProps[ENUM_GAIN].fSetSupported = VideoProcAmpProperties[ENUM_GAIN].SetSupported;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -