PIN 和 CAM 关系应该是并列的,但是必须要先有CAM 然后才有PIN
可以看看他们的Init函数:
在Cam_Init中
CAM_Init(
VOID * pContext
)
{
CAMERADEVICE * pCamDev = NULL;
DEBUGMSG(ZONE_INIT, (_T("CAM_Init: context %s\n"), pContext));
pCamDev = new CAMERADEVICE;
//这里新建了一个CAMERADEVICE的类。然后这个函数返回这个类的指针
………………
}
在Pin_Init中
DWORD
PIN_Init(
LPCTSTR Context,
LPVOID lpvBusContext
)
{
DEBUGMSG( ZONE_INIT, ( _T("PIN_Init: context %s\n"), Context ) );
PPININITHANDLE pPinInitDev = NULL;
pPinInitDev = new PININITHANDLE;
//这个结构体就是一个CAMERADEVICE的指针
//typedef struct CPinInitHandle
//{
// PCAMERADEVICE pCamDevice;
//} PININITHANDLE, * PPININITHANDLE;
//如果CAMERADEVICE不存在,PIN_INIT就会失败
if ( NULL != pPinInitDev )
{
pPinInitDev->pCamDevice = reinterpret_cast ( lpvBusContext );
if ( NULL == pPinInitDev->pCamDevice )
{
SetLastError( ERROR_INVALID_HANDLE );
SAFEDELETE( pPinInitDev );
DEBUGMSG( ZONE_INIT|ZONE_ERROR, ( _T("PIN_Init: Initialization Failed") ) );
}
}
else
{
SetLastError( ERROR_OUTOFMEMORY );
}
…………
}
在Pin_Open的时候,把这个CameraDevice的指针给了他的一个成员:
DWORD
PIN_Open(
DWORD Context,
DWORD Access,
DWORD ShareMode
)
{
…………
if ( false == pPinDevice->InitializeSubDevice( pPinInit->pCamDevice ) )
//InitializeSubDevice这个函数就是一个简单的set函数,给成员函数赋值
{
SAFEDELETE( pPinDevice );
DEBUGMSG( ZONE_INIT|ZONE_ERROR, ( _T("PIN_Init: Initialization Failed") ) );
}
……………………
}
在处理IOContro的时候:
在处理Pin驱动上面的IOCTL_CS_PROPERTY的时候会调用下面的一个函数
DWORD
CPinDevice::PinHandleCustomRequests(
PUCHAR pInBuf, // Warning: This is an unsafe buffer, access with care
DWORD InBufLen,
PUCHAR pOutBuf, // Warning: This is an unsafe buffer, access with care
DWORD OutBufLen,
PDWORD pdwBytesTransferred // Warning: This is an unsafe buffer, access with care
)
{
return m_pCamAdapter->PDDHandlePinCustomProperties( m_ulPinId, pInBuf, InBufLen, pOutBuf, OutBufLen, pdwBytesTransferred );
//这里这个m_pCamAdapter成员 其实就是PCAMERADEVICE,上面在Pin Open的时候已经赋值
}
EXTERN_C
BOOL
CAM_IOControl(
DWORD dwContext,
DWORD Ioctl,
UCHAR * pInBufUnmapped,
DWORD InBufLen,
UCHAR * pOutBufUnmapped,
DWORD OutBufLen,
DWORD * pdwBytesTransferred
)
{
………………
case IOCTL_CS_PROPERTY:
{
DEBUGMSG( ZONE_IOCTL, ( _T("CAM_IOControl(%08x): IOCTL_CS_PROPERTY\r\n"), dwContext ) );
__try
{
dwErr = pCamDevice->AdapterHandleCustomRequests( pInBuf,InBufLen, pOutBuf, OutBufLen, pdwBytesTransferred );
………………
}
两个驱动都可以访问同一个PCAMERADEVICE的指针。但是对于Pin的驱动来说,他自己还有一个PinDevice。
|