📄 cameradriver.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.
//
/*++
Module Name:
CameraDriver.cpp
Abstract:
Intel PXA27x Mainstone II Direct Show camera driver
Notes:
Revision History:
--*/
#include <windows.h>
#include <devload.h>
#include <nkintr.h>
#define CAMINTERFACE
#include "CameraDriver.h"
EXTERN_C
DWORD
CAM_Init(
VOID * pContext
)
{
CAMERADEVICE * pCamDev = NULL;
DEBUGMSG(ZONE_INIT, (_T("CAM_Init: context %s\n"), pContext));
if( OEM_CERTIFY_TRUST != CeGetCallerTrust() )
{
SetLastError(ERROR_ACCESS_DENIED);
}
else
{
pCamDev = new CAMERADEVICE;
if ( NULL != pCamDev )
{
// NOTE: real drivers would need to validate pContext before dereferencing the pointer
if ( false == pCamDev->Initialize( pContext ) )
{
SetLastError( ERROR_INVALID_HANDLE );
SAFEDELETE( pCamDev );
DEBUGMSG( ZONE_INIT|ZONE_ERROR, ( _T("CAM_Init: Initialization Failed") ) );
}
}
else
{
SetLastError( ERROR_OUTOFMEMORY );
}
}
DEBUGMSG( ZONE_INIT, ( _T("CAM_Init: returning 0x%08x\r\n"), reinterpret_cast<DWORD>( pCamDev ) ) );
return reinterpret_cast<DWORD>( pCamDev );
}
EXTERN_C
BOOL
CAM_Deinit(
DWORD dwContext
)
{
DEBUGMSG( ZONE_INIT, ( _T("CAM_Deinit\r\n") ) );
CAMERADEVICE * pCamDevice = reinterpret_cast<CAMERADEVICE *>( dwContext );
SAFEDELETE( pCamDevice );
return TRUE;
}
EXTERN_C
BOOL
CAM_IOControl(
DWORD dwContext,
DWORD Ioctl,
UCHAR * pInBufUnmapped,
DWORD InBufLen,
UCHAR * pOutBufUnmapped,
DWORD OutBufLen,
DWORD * pdwBytesTransferred
)
{
DEBUGMSG( ZONE_FUNCTION, ( _T("CAM_IOControl(%08x): IOCTL:0x%x, InBuf:0x%x, InBufLen:%d, OutBuf:0x%x, OutBufLen:0x%x)\r\n"), dwContext, Ioctl, pInBufUnmapped, InBufLen, pOutBufUnmapped, OutBufLen ) );
UCHAR * pInBuf = NULL;
UCHAR * pOutBuf = NULL;
DWORD dwErr = ERROR_INVALID_PARAMETER;
BOOL bRc = FALSE;
if ( ( NULL == pInBufUnmapped )
|| ( InBufLen < sizeof ( CSPROPERTY ) )
|| ( NULL == pdwBytesTransferred ) )
{
SetLastError( dwErr );
return bRc;
}
pInBuf = (UCHAR*) MapCallerPtr( pInBufUnmapped, InBufLen );
if(( pInBuf == NULL ) && ( pInBufUnmapped != NULL ))
{
DEBUGMSG( ZONE_IOCTL|ZONE_ERROR, ( _T("CAM_IOControl(%08x): CAM_IOControl. MapCallerPtr failed for incoming buffer.\r\n"), dwContext ) );
return dwErr;
}
pOutBuf = (UCHAR*) MapCallerPtr( pOutBufUnmapped, OutBufLen );
if (( NULL == pOutBuf ) && ( pOutBufUnmapped != NULL ))
{
DEBUGMSG( ZONE_IOCTL|ZONE_ERROR, ( _T("CAM_IOControl(%08x): CAM_IOControl. MapCallerPtr failed for incoming buffer.\r\n"), dwContext ) );
return dwErr;
}
if ( NULL == MapCallerPtr( pdwBytesTransferred, sizeof ( DWORD ) ) )
{
DEBUGMSG( ZONE_IOCTL|ZONE_ERROR, ( _T("CAM_IOControl(%08x): CAM_IOControl. MapCallerPtr failed for dwBytesTransferred.\r\n"), dwContext ) );
return dwErr;
}
CAMERAOPENHANDLE * pCamOpenHandle = reinterpret_cast<CAMERAOPENHANDLE *>( dwContext );
CAMERADEVICE * pCamDevice = pCamOpenHandle->pCamDevice;
CSPROPERTY * pCsProp = reinterpret_cast<CSPROPERTY *>( MapCallerPtr( pInBuf, sizeof ( CSPROPERTY ) ) );
if ( NULL == pCsProp )
{
DEBUGMSG( ZONE_IOCTL|ZONE_ERROR, (_T("CAM_IOControl(%08x): MapCallerPtr failed for input buffer.\r\n"), dwContext ) );
return dwErr;
}
switch ( Ioctl )
{
case IOCTL_CS_PROPERTY:
{
DEBUGMSG( ZONE_IOCTL, ( _T("CAM_IOControl(%08x): IOCTL_CS_PROPERTY\r\n"), dwContext ) );
__try
{
if ( TRUE == IsEqualGUID( pCsProp->Set, CSPROPSETID_Pin ) )
{
dwErr = pCamDevice->AdapterHandlePinRequests( pInBuf, InBufLen, pOutBuf, OutBufLen, pdwBytesTransferred );
}
else if ( TRUE == IsEqualGUID( pCsProp->Set, CSPROPSETID_VERSION ) )
{
dwErr = pCamDevice->AdapterHandleVersion( pOutBuf, OutBufLen, pdwBytesTransferred );
}
else if ( TRUE == IsEqualGUID( pCsProp->Set, PROPSETID_VIDCAP_VIDEOPROCAMP ) )
{
dwErr = pCamDevice->AdapterHandleVidProcAmpRequests( pInBuf,InBufLen, pOutBuf, OutBufLen, pdwBytesTransferred );
}
else if ( TRUE == IsEqualGUID( pCsProp->Set, PROPSETID_VIDCAP_CAMERACONTROL ) )
{
dwErr = pCamDevice->AdapterHandleCamControlRequests( pInBuf,InBufLen, pOutBuf, OutBufLen, pdwBytesTransferred );
}
else if ( TRUE == IsEqualGUID( pCsProp->Set, PROPSETID_VIDCAP_VIDEOCOMPRESSION ) )
{
dwErr = pCamDevice->AdapterHandleCompressionRequests( pInBuf,InBufLen, pOutBuf, OutBufLen, pdwBytesTransferred );
}
else if ( TRUE == IsEqualGUID( pCsProp->Set, PROPSETID_VIDCAP_VIDEOCONTROL ) )
{
dwErr = pCamDevice->AdapterHandleVideoControlRequests( pInBuf,InBufLen, pOutBuf, OutBufLen, pdwBytesTransferred );
}
else if ( TRUE == IsEqualGUID( pCsProp->Set, PROPSETID_VIDCAP_DROPPEDFRAMES) )
{
dwErr = pCamDevice->AdapterHandleDroppedFramesRequests( pInBuf,InBufLen, pOutBuf, OutBufLen, pdwBytesTransferred );
}
else
{
DEBUGMSG( ZONE_IOCTL, ( _T("CAM_IOControl(%08x): Unsupported PropertySet Request%u\r\n"), dwContext, pCsProp->Set ) );
dwErr = ERROR_NOT_SUPPORTED;
}
}
__except ( EXCEPTION_EXECUTE_HANDLER )
{
DEBUGMSG( ZONE_IOCTL, ( _T("CAM_IOControl(%08x):Exception in IOCTL_CS_PROPERTY"), dwContext ) );
}
break;
}
default:
{
DEBUGMSG( ZONE_IOCTL, (_T("CAM_IOControl(%08x): Unsupported IOCTL code %u\r\n"), dwContext, Ioctl ) );
dwErr = ERROR_NOT_SUPPORTED;
break;
}
}
// pass back appropriate response codes
SetLastError( dwErr );
return ( ( dwErr == ERROR_SUCCESS ) ? TRUE : FALSE );
}
EXTERN_C
DWORD
CAM_Open(
DWORD Context,
DWORD Access,
DWORD ShareMode
)
{
DEBUGMSG( ZONE_FUNCTION, ( _T("CAM_Open(%x, 0x%x, 0x%x)\r\n"), Context, Access, ShareMode ) );
UNREFERENCED_PARAMETER( ShareMode );
UNREFERENCED_PARAMETER( Access );
// TODO : HANDLE ShareMode and Access parameters
CAMERADEVICE * pCamDevice = reinterpret_cast<CAMERADEVICE *>( Context );
CAMERAOPENHANDLE * pCamOpenHandle = NULL;
HANDLE hCurrentProc = NULL;
hCurrentProc = GetCallerProcess();
ASSERT( pCamDevice != NULL );
if ( pCamDevice->BindApplicationProc( hCurrentProc ) )
{
pCamOpenHandle = new CAMERAOPENHANDLE;
if ( NULL == pCamOpenHandle )
{
DEBUGMSG( ZONE_FUNCTION, ( _T("CAM_Open(%x): Not enought memory to create open handle\r\n"), Context ) );
}
else
{
pCamOpenHandle->pCamDevice = pCamDevice;
}
}
else
{
SetLastError( ERROR_ALREADY_INITIALIZED );
}
return reinterpret_cast<DWORD>( pCamOpenHandle );
}
EXTERN_C
BOOL
CAM_Close(
DWORD Context
)
{
DEBUGMSG( ZONE_FUNCTION, ( _T("CAM_Close(%x)\r\n"), Context ) );
PCAMERAOPENHANDLE pCamOpenHandle = reinterpret_cast<PCAMERAOPENHANDLE>( Context );
pCamOpenHandle->pCamDevice->UnBindApplicationProc( );
SAFEDELETE( pCamOpenHandle ) ;
return TRUE;
}
BOOL
__stdcall
DllMain(
HANDLE hDllHandle,
DWORD dwReason,
VOID * lpReserved
)
{
BOOL bRc = TRUE;
UNREFERENCED_PARAMETER( lpReserved );
switch ( dwReason )
{
case DLL_PROCESS_ATTACH:
{
DEBUGREGISTER( reinterpret_cast<HMODULE>( hDllHandle ) );
DEBUGMSG( ZONE_INIT, ( _T("*** DLL_PROCESS_ATTACH - Current Process: 0x%x, ID: 0x%x ***\r\n"), GetCurrentProcess(), GetCurrentProcessId() ) );
DisableThreadLibraryCalls( reinterpret_cast<HMODULE>( hDllHandle ) );
break;
}
case DLL_PROCESS_DETACH:
{
DEBUGMSG( ZONE_INIT, ( _T("*** DLL_PROCESS_DETACH - Current Process: 0x%x, ID: 0x%x ***\r\n"), GetCurrentProcess(), GetCurrentProcessId() ) );
break;
}
case DLL_THREAD_DETACH:
{
break;
}
case DLL_THREAD_ATTACH:
{
break;
}
default:
{
break;
}
}
return bRc;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -