📄 cameradevice.cpp
字号:
if (NULL == (lpMapped = MapCallerPtr(lpBuff, ulActualBufLen)))
{
DEBUGMSG(ZONE_IOCTL|ZONE_ERROR, (_T("IOControl(%08x): MapCallerPtr failed for buffer.\r\n"), this));
*dwError = ERROR_INVALID_USER_BUFFER;
return NULL;
}
return lpMapped;
}
//-----------------------------------------------------------------------------
//
// Function: AdapterHandlePinRequests
//
// Query for information on each pin factory that it supports.
//
// Parameters:
// pInBuf
// [in] Input buffer.
//
// InBufLen
// [in] Input buffer length.
//
// pOutBuf
// [in] Output buffer.
//
// OutBufLen
// [in] Output buffer length.
//
// pdwBytesTransferred
// [in] Bytes transferred.
//
// Returns:
// Returns ERROR_SUCCESS if the operation completes successfully;
// Otherwise, returns a Microsoft Win32 error code.
//
//-----------------------------------------------------------------------------
DWORD CCameraDevice::AdapterHandlePinRequests(
PUCHAR pInBuf,
DWORD InBufLen,
PUCHAR pOutBuf,
DWORD OutBufLen,
PDWORD pdwBytesTransferred
)
{
DEBUGMSG(ZONE_IOCTL, (_T("CAM_IOControl(%08x): HandlePinRequests\r\n"), this));
DWORD dwError = ERROR_INVALID_PARAMETER;
PCSP_PIN pCsPin = NULL;
PCS_DATARANGE_VIDEO pCsDataRangeVideo = NULL;
PCSMULTIPLE_ITEM pCsMultipleItem = NULL;
PCSPROPERTY pCsProp = (PCSPROPERTY)pInBuf;
PCS_DATAFORMAT_VIDEOINFOHEADER pCsDataFormatVih = NULL;
PCSPIN_CINSTANCES pCsPinCinstances = NULL;
*pdwBytesTransferred = 0;
// we support PROPSETID_Pin, so just return success
if (CSPROPERTY_TYPE_SETSUPPORT == pCsProp->Flags)
{
return ERROR_SUCCESS;
}
// we are here so the request is not SETSUPPORT and after this only GET requests will be entertained since
// PROPSETID_Pin contains READ-ONLY properties
if (CSPROPERTY_TYPE_GET != pCsProp->Flags)
{
return dwError;
}
switch(pCsProp->Id)
{
case CSPROPERTY_PIN_CTYPES: //how many pin types this camera device supports
{
DEBUGMSG(ZONE_IOCTL, (_T("CAM_IOControl(%08x): CSPROPERTY_PIN_CTYPES\r\n"), this));
*pdwBytesTransferred = sizeof(ULONG);
if (NULL == ValidateBuffer(pOutBuf, OutBufLen, sizeof (ULONG), &dwError))
{
dwError = ERROR_MORE_DATA;
break;
}
EnterCriticalSection(&m_csDevice);
memcpy(pOutBuf, &m_ulCTypes, sizeof (ULONG));
LeaveCriticalSection(&m_csDevice);
dwError = ERROR_SUCCESS;
break;
}
case CSPROPERTY_PIN_CINSTANCES: //The current number of pins this pin factory has instantiated, as well as the maximum number of pins this pin factory can instantiate, per camera device
{
DEBUGMSG(ZONE_IOCTL, (_T("CAM_IOControl(%08x): CSPROPERTY_PIN_CINSTANCES\r\n"), this));
if (NULL == (pCsPin = reinterpret_cast<PCSP_PIN>(ValidateBuffer(pInBuf, InBufLen, sizeof (CSP_PIN), &dwError))))
break;
if (false == IsValidPin(pCsPin->PinId))
{
DEBUGMSG(ZONE_IOCTL, (_T("CAM_IOControl(%08x): Invalid PinId\r\n"), this));
break;
}
*pdwBytesTransferred = sizeof(CSPIN_CINSTANCES);
if (NULL == (pCsPinCinstances = reinterpret_cast<PCSPIN_CINSTANCES>(ValidateBuffer(pOutBuf, OutBufLen, sizeof(CSPIN_CINSTANCES), &dwError))))
{
dwError = ERROR_MORE_DATA;
break;
}
pCsPinCinstances->PossibleCount = 1;
pCsPinCinstances->CurrentCount = m_StrmInstances[pCsPin->PinId].ulCInstances;
dwError = ERROR_SUCCESS;
break;
}
case CSPROPERTY_PIN_DATARANGES: //Get the data ranges supported by pins instantiated by the pin factory
{
DEBUGMSG(ZONE_IOCTL, (_T("CAM_IOControl(%08x): CSPROPERTY_PIN_DATARANGES\r\n"), this));
if(NULL == (pCsPin = reinterpret_cast<PCSP_PIN>(ValidateBuffer(pInBuf, InBufLen, sizeof (CSP_PIN), &dwError))))
break;
if (false == IsValidPin(pCsPin->PinId))
{
DEBUGMSG(ZONE_IOCTL, (_T("CAM_IOControl(%08x): Invalid PinId\r\n"), this));
break;
}
*pdwBytesTransferred = sizeof(CSMULTIPLE_ITEM) + (m_PinVideoFormat[pCsPin->PinId].ulAvailFormats * sizeof (CS_DATARANGE_VIDEO));
if (NULL == (pCsMultipleItem = reinterpret_cast<PCSMULTIPLE_ITEM>(ValidateBuffer(pOutBuf, OutBufLen, *pdwBytesTransferred, &dwError))))
{
dwError = ERROR_MORE_DATA;
break;
}
pCsMultipleItem->Count = m_PinVideoFormat[pCsPin->PinId].ulAvailFormats;
pCsMultipleItem->Size = *pdwBytesTransferred;
pCsDataRangeVideo = NULL;
pCsDataRangeVideo = reinterpret_cast<PCS_DATARANGE_VIDEO>(pCsMultipleItem + 1);
for (int iCount = 0; iCount < static_cast<int>( m_PinVideoFormat[pCsPin->PinId].ulAvailFormats); iCount++)
{
memcpy(pCsDataRangeVideo, m_PinVideoFormat[pCsPin->PinId].pCsDataRangeVideo[iCount], sizeof (CS_DATARANGE_VIDEO));
pCsDataRangeVideo = reinterpret_cast<PCS_DATARANGE_VIDEO>(pCsDataRangeVideo + 1);
}
dwError = ERROR_SUCCESS;
break;
}
case CSPROPERTY_PIN_DATAINTERSECTION: //find a data format supported by pins instantiated by the pin factory
{
DEBUGMSG(ZONE_IOCTL, (_T("CAM_IOControl(%08x): CSPROPERTY_PIN_DATAINTERSECTION\r\n"), this));
if (NULL == (pCsPin = reinterpret_cast<PCSP_PIN>(ValidateBuffer(pInBuf, InBufLen, sizeof (CSP_PIN), &dwError))))
{
break;
}
if (false == IsValidPin(pCsPin->PinId))
{
DEBUGMSG(ZONE_IOCTL, (_T("CAM_IOControl(%08x): Invalid PinId\r\n"), this));
break;
}
pCsMultipleItem = NULL;
pCsMultipleItem = reinterpret_cast<PCSMULTIPLE_ITEM>(pCsPin + 1);
if (NULL == ValidateBuffer(pInBuf, InBufLen, (sizeof(CSP_PIN) + (pCsMultipleItem->Count * pCsMultipleItem->Size)), &dwError))
{
break;
}
*pdwBytesTransferred = sizeof(CS_DATAFORMAT_VIDEOINFOHEADER);
if(NULL == (pCsDataFormatVih = reinterpret_cast<PCS_DATAFORMAT_VIDEOINFOHEADER>(ValidateBuffer(pOutBuf, OutBufLen, *pdwBytesTransferred, &dwError))))
{
dwError = ERROR_MORE_DATA;
break;
}
pCsDataRangeVideo = NULL;
pCsDataRangeVideo = reinterpret_cast<PCS_DATARANGE_VIDEO>(pCsMultipleItem + 1);
for (int iCount = 0 ; iCount < (int)pCsMultipleItem->Count ; iCount++)
{
// First check whether the GUIDs match or not. This driver also tests other high level attributes of KS_DATARANGE_VIDEO
if (true == AdapterCompareFormat(pCsPin->PinId, pCsDataRangeVideo, NULL, true))
{
// We found our format
memcpy(&pCsDataFormatVih->DataFormat,&pCsDataRangeVideo->DataRange, sizeof(CSDATAFORMAT));
memcpy(&pCsDataFormatVih->VideoInfoHeader,&pCsDataRangeVideo->VideoInfoHeader, sizeof(CS_VIDEOINFOHEADER));
dwError = ERROR_SUCCESS;
break;
}
pCsDataRangeVideo = reinterpret_cast<PCS_DATARANGE_VIDEO>(pCsDataRangeVideo + 1);
}
break;
}
case CSPROPERTY_PIN_CATEGORY: //retrieve the category of a pin factory
{
DEBUGMSG(ZONE_IOCTL, (_T("CAM_IOControl(%08x): CSPROPERTY_PIN_CATEGORY\r\n"), this));
if (NULL == (pCsPin = reinterpret_cast<PCSP_PIN>(ValidateBuffer(pInBuf, InBufLen, sizeof (CSP_PIN), &dwError))))
{
break;
}
if (false == IsValidPin(pCsPin->PinId))
{
DEBUGMSG(ZONE_IOCTL, (_T("CAM_IOControl(%08x): Invalid PinId\r\n"), this));
break;
}
*pdwBytesTransferred = sizeof(GUID);
if (NULL == ValidateBuffer(pOutBuf, OutBufLen, *pdwBytesTransferred, &dwError))
{
dwError = ERROR_MORE_DATA;
break;
}
memcpy(pOutBuf, &m_PinVideoFormat[pCsPin->PinId].categoryGUID, sizeof(GUID));
dwError = ERROR_SUCCESS;
break;
}
case CSPROPERTY_PIN_NAME:
{
DEBUGMSG(ZONE_IOCTL, (_T("CAM_IOControl(%08x): Property CSPROPERTY_PIN_NAME\r\n"), this));
if (NULL == (pCsPin = reinterpret_cast<PCSP_PIN>(ValidateBuffer(pInBuf, InBufLen, sizeof(CSP_PIN), &dwError))))
{
break;
}
if (false == IsValidPin(pCsPin->PinId))
{
DEBUGMSG(ZONE_IOCTL, (_T("CAM_IOControl(%08x): Invalid PinId\r\n"), this));
break;
}
*pdwBytesTransferred = (wcslen(g_wszPinNames[pCsPin->PinId]) + 1) * sizeof(g_wszPinNames[0][0]);
if (NULL == ValidateBuffer(pOutBuf, OutBufLen, *pdwBytesTransferred, &dwError))
{
dwError = ERROR_MORE_DATA;
break;
}
memcpy( pOutBuf, g_wszPinNames[pCsPin->PinId], *pdwBytesTransferred);
dwError = ERROR_SUCCESS;
break;
}
case CSPROPERTY_PIN_DEVICENAME:
{
DEBUGMSG(ZONE_IOCTL, (_T("CAM_IOControl(%08x): Property CSPROPERTY_PIN_NAME\r\n"), this));
if (NULL == (pCsPin = reinterpret_cast<PCSP_PIN>(ValidateBuffer(pInBuf, InBufLen, sizeof(CSP_PIN), &dwError))))
{
break;
}
if (false == IsValidPin(pCsPin->PinId))
{
DEBUGMSG(ZONE_IOCTL, (_T("CAM_IOControl(%08x): Invalid PinId\r\n"), this));
break;
}
*pdwBytesTransferred = (wcslen(g_wszPinDeviceNames[pCsPin->PinId]) + 1) * sizeof( g_wszPinDeviceNames[0][0]);
if (NULL == ValidateBuffer(pOutBuf, OutBufLen, *pdwBytesTransferred, &dwError))
{
dwError = ERROR_MORE_DATA;
break;
}
memcpy(pOutBuf, g_wszPinDeviceNames[pCsPin->PinId], *pdwBytesTransferred);
dwError = ERROR_SUCCESS;
break;
}
default:
{
DEBUGMSG(ZONE_IOCTL, (_T("CAM_IOControl(%08x): Invalid Property\r\n"), this));
break;
}
}
return dwError;
}
//-----------------------------------------------------------------------------
//
// Function: AdapterHandleVidProcAmpRequests
//
// Adjusts image color attributes in either analog or digital domains.
//
// Parameters:
// pInBuf
// [in] Input buffer.
//
// InBufLen
// [in] Input buffer length.
//
// pOutBuf
// [in] Output buffer.
//
// OutBufLen
// [in] Output buffer length.
//
// pdwBytesTransferred
// [in] Bytes transferred.
//
// Returns:
// Returns ERROR_SUCCESS if the operation completes successfully;
// Otherwise, returns ERROR_INVALID_PARAMETER.
//
//-----------------------------------------------------------------------------
DWORD CCameraDevice::AdapterHandleVidProcAmpRequests(
PUCHAR pInBuf,
DWORD InBufLen,
PUCHAR pOutBuf,
DWORD OutBufLen,
PDWORD pdwBytesTransferred
)
{
DEBUGMSG(ZONE_IOCTL, (_T("CAM_IOControl(%08x): HandleVidProcAmpRequests\r\n"), this));
DWORD dwError = ERROR_INVALID_PARAMETER;
LONG lValue = 0;
PCSPROPERTY pCsProp = NULL;
PDEV_PROPERTY pDevProp = NULL;
PCSPROPERTY_VIDEOPROCAMP_S pCsPropVidProcAmpOutput = NULL;
PCSPROPERTY_VIDEOPROCAMP_S pCsPropVidProcAmpInput = NULL;
PCSPROPERTY_DESCRIPTION pCsPropDesc = NULL;
PCSPROPERTY_VALUES pCsPropValues = NULL;
pCsProp = reinterpret_cast<PCSPROPERTY>(ValidateBuffer(pInBuf, InBufLen, sizeof(CSPROPERTY), &dwError));
if (NULL == pCsProp)
{
return dwError;
}
*pdwBytesTransferred = 0;
// we support PROPSETID_Pin, so just return success
if (CSPROPERTY_TYPE_SETSUPPORT == pCsProp->Flags)
{
return ERROR_SUCCESS;
}
// we do not support any PROCAMP properties now
DEBUGMSG(ZONE_IOCTL, (_T("CAM_IOControl(%08x): Invalid Property\r\n"), this));
return dwError;
}
//-----------------------------------------------------------------------------
//
// Function: AdapterHandleCamControlRequests
//
// Controls camera devices.
//
// Parameters:
// pInBuf
// [in] Input buffer.
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -