📄 pindevice.cpp
字号:
*pdwBytesTransferred = sizeof(CSALLOCATOR_FRAMING);
if(NULL == (pCsAllocatorFraming = reinterpret_cast<PCSALLOCATOR_FRAMING>(m_pCamAdapter->ValidateBuffer(pOutBuf, OutBufLen, sizeof(CSALLOCATOR_FRAMING), &dwError))))
{
dwError = ERROR_MORE_DATA;
break;
}
if (m_ulMaxNumOfBuffers > m_pCamAdapter->m_pPrp->PrpGetMaxBuffers())
{
// Number of buffers requested is greater than the maximum
// number that can be supported. Return with error.
DEBUGMSG(ZONE_IOCTL|ZONE_ERROR, (_T("PIN_IOControl(%08x): CSPROPERTY_CONNECTION_ALLOCATORFRAMING buffers requested exceeds max limit\r\n"), this)) ;
break;
}
m_ulMaxNumOfBuffers = pCsAllocatorFraming->Frames ;
dwError = ERROR_SUCCESS;
break ;
default :
DEBUGMSG(ZONE_IOCTL|ZONE_ERROR, (_T("PIN_IOControl(%08x): CSPROPERTY_CONNECTION_ALLOCATORFRAMING Invalid Request\r\n"), this)) ;
}
break ;
case CSPROPERTY_CONNECTION_PROPOSEDATAFORMAT :
// I don't want to support dynamic format changes for this test driver
break ;
default :
DEBUGMSG(ZONE_IOCTL|ZONE_ERROR, (_T("PIN_IOControl(%08x): Invalid Request\r\n"), this)) ;
}
return dwError ;
}
/********************************************************************
*
* FUNCTION: PinHandleAllocateBuffers
*
* DESCRIPTION: //Examine or set the state of a connection on a pin
*
* PARAMETERS: PUCHAR pInBuf,
* DWORD InBufLen,
* PUCHAR pOutBuf,
* DWORD OutBufLen,
* PDWORD pdwBytesTransferred
*
* RETURNS: Returns ERROR_SUCCESS if the operation completes successfully;
* otherwise, returns a Microsoft Win32 error code.
*
********************************************************************/
DWORD CPinDevice::PinHandleAllocateBuffers(
PUCHAR pInBuf,
DWORD InBufLen,
PUCHAR pOutBuf,
DWORD OutBufLen,
PDWORD pdwBytesTransferred
)
{
DEBUGMSG(ZONE_IOCTL, (_T("PIN_IOControl(%08x): PinHandleAllocateBuffers\r\n"), this ) );
DWORD dwError = ERROR_INVALID_PARAMETER;
PCSSTREAM_ALLOCATOR pCsStreamAllocIn = reinterpret_cast<PCSSTREAM_ALLOCATOR>( m_pCamAdapter->ValidateBuffer(pInBuf, InBufLen, sizeof(CSSTREAM_ALLOCATOR), &dwError));
PCSSTREAM_ALLOCATOR pCsStreamAllocOut = reinterpret_cast<PCSSTREAM_ALLOCATOR>( m_pCamAdapter->ValidateBuffer(pOutBuf, OutBufLen, sizeof(CSSTREAM_ALLOCATOR), &dwError));
//UNREFERENCED_PARAMETER(pInBuf);
//UNREFERENCED_PARAMETER(InBufLen);
if (NULL == pCsStreamAllocIn)
{
return dwError;
}
*pdwBytesTransferred = sizeof(CSSTREAM_ALLOCATOR);
if (NULL == pCsStreamAllocOut)
{
return ERROR_MORE_DATA;
}
DEBUGMSG(ZONE_IOCTL, (_T("PIN_IOControl(%08x): Driver is allocating buffers \r\n"), this));
// This is the place where the driver will allocate buffer and initializes the headers.
if (m_ulMaxNumOfBuffers > pCsStreamAllocIn->DesiredCount)
{
m_ulMaxNumOfBuffers = pCsStreamAllocIn->DesiredCount;
}
if (true == m_fClientAllocateBuffers)
{
DEBUGMSG(ZONE_IOCTL, (_T("PIN_IOControl(%08x): If client is the allocator then we should not call CS_ALLOCATE_BUFFERS \r\n"), this));
return dwError;
}
if (false == AllocateBuffers())
{
DEBUGMSG(ZONE_IOCTL|ZONE_ERROR, (_T("PIN_IOControl(%08x): Could not allocate buffers.\r\n"), this));
return dwError;
}
// if DesiredCount is greater than the Maximum number of buffers that the driver can allocate then set the DesiredCount memeber to reflect
// the MAX no. of buffers the driver can allocate.
pCsStreamAllocOut->DesiredCount = m_ulMaxNumOfBuffers;
pCsStreamAllocOut->ActualCount = m_ulCurrNumOfBuffers;
pCsStreamAllocOut->pBuffers = reinterpret_cast<LPVOID>( m_pHeadBufferOri);
dwError = ERROR_SUCCESS;
return dwError;
}
/********************************************************************
*
* FUNCTION: PinHandleStreamRequests
*
* DESCRIPTION: Query if the pin allocates stream buffers or can provide an allocator
*
* PARAMETERS: PUCHAR pInBuf,
* DWORD InBufLen,
* PUCHAR pOutBuf,
* DWORD OutBufLen,
* PDWORD pdwBytesTransferred
*
* RETURNS: Returns ERROR_SUCCESS if the operation completes successfully;
* otherwise, returns a Microsoft Win32 error code.
*
********************************************************************/
DWORD CPinDevice::PinHandleStreamRequests(
PUCHAR pInBuf,
DWORD InBufLen,
PUCHAR pOutBuf,
DWORD OutBufLen,
PDWORD pdwBytesTransferred
)
{
DEBUGMSG(ZONE_IOCTL, (_T("PIN_IOControl(%08x): PinHandleStreamRequests\r\n"), this));
DWORD dwError = ERROR_INVALID_PARAMETER;
PCSPROPERTY pCsProp = reinterpret_cast<PCSPROPERTY>(m_pCamAdapter->ValidateBuffer(pInBuf, InBufLen, sizeof(CSPROPERTY), &dwError));
if(NULL == pCsProp)
{
return dwError;
}
*pdwBytesTransferred = 0;
// we support this property set, so just return success
if (CSPROPERTY_TYPE_SETSUPPORT == pCsProp->Flags)
{
return ERROR_SUCCESS;
}
switch (pCsProp->Flags)
{
case CSPROPERTY_TYPE_GET:
*pdwBytesTransferred = sizeof (bool);
if (NULL == m_pCamAdapter->ValidateBuffer(pOutBuf, OutBufLen, sizeof(HANDLE), &dwError))
{
dwError = ERROR_MORE_DATA;
break;
}
*(reinterpret_cast<bool *>(pOutBuf)) = m_fClientAllocateBuffers;
dwError = ERROR_SUCCESS;
break;
case CSPROPERTY_TYPE_SET:
if (NULL == m_pCamAdapter->ValidateBuffer(pOutBuf, OutBufLen, sizeof(HANDLE ), &dwError))
{
dwError = ERROR_MORE_DATA;
break;
}
m_fClientAllocateBuffers = *(reinterpret_cast<bool *>(pOutBuf));
dwError = ERROR_SUCCESS;
break;
case CSPROPERTY_TYPE_DEFAULTVALUES:
*pdwBytesTransferred = sizeof(bool);
if (NULL == m_pCamAdapter->ValidateBuffer(pOutBuf, OutBufLen, sizeof(HANDLE), &dwError))
{
dwError = ERROR_MORE_DATA;
break;
}
*(reinterpret_cast<bool *>(pOutBuf)) = false; // driver can allocate buffers
dwError = ERROR_SUCCESS;
break;
default:
DEBUGMSG(ZONE_IOCTL|ZONE_ERROR, (_T("PIN_IOControl(%08x): Incorrect Request\r\n"), this));
break;
}
return dwError;
}
/********************************************************************
*
* FUNCTION: PinHandleVPConfigRequests
*
* DESCRIPTION: Not support
*
* PARAMETERS: PUCHAR pInBuf,
* DWORD InBufLen,
* PUCHAR pOutBuf,
* DWORD OutBufLen,
* PDWORD pdwBytesTransferred
*
* RETURNS: Returns ERROR_NOT_SUPPORTED.
*
********************************************************************/
DWORD CPinDevice::PinHandleVPConfigRequests(
PUCHAR pInBuf,
DWORD InBufLen,
PUCHAR pOutBuf,
DWORD OutBufLen,
PDWORD pdwBytesTransferred
)
{
return ERROR_NOT_SUPPORTED;
}
/********************************************************************
*
* FUNCTION: PinHandleConnStateSubReqs
*
* DESCRIPTION: sets the current run state of the pin
*
* PARAMETERS: ULONG ulReqFlags,
* PUCHAR pOutBuf,
* DWORD OutBufLen,
* PDWORD pdwBytesTransferred
*
* RETURNS: Returns ERROR_SUCCESS if the operation completes successfully;
* otherwise, returns a Microsoft Win32 error code.
*
********************************************************************/
DWORD CPinDevice::PinHandleConnStateSubReqs(
ULONG ulReqFlags,
PUCHAR pOutBuf,
DWORD OutBufLen,
PDWORD pdwBytesTransferred
)
{
DEBUGMSG(ZONE_IOCTL, (_T("PIN_IOControl(%08x): PinHandleConnStateSubReqs\r\n"), this));
DWORD dwError = ERROR_INVALID_PARAMETER;
PCSSTATE pCsState = NULL;
switch(ulReqFlags)
{
case CSPROPERTY_TYPE_GET:
*pdwBytesTransferred = sizeof(CSSTATE);
pCsState = reinterpret_cast<PCSSTATE>(m_pCamAdapter->ValidateBuffer(pOutBuf, OutBufLen, sizeof(CSSTATE), &dwError));
if (NULL == pCsState)
{
dwError = ERROR_MORE_DATA;
break;
}
*(pCsState) = m_CsState;
dwError = ERROR_SUCCESS;
break;
case CSPROPERTY_TYPE_SET:
pCsState = reinterpret_cast<PCSSTATE>(m_pCamAdapter->ValidateBuffer(pOutBuf, OutBufLen, sizeof(CSSTATE), &dwError));
if (NULL == pCsState)
{
dwError = ERROR_MORE_DATA;
break;
}
switch (*pCsState)
{
case CSSTATE_STOP:
DEBUGMSG(ZONE_IOCTL, (_T("PIN_IOControl(%08x): Set CSSTATE_STOP\r\n"), this));
// We can get to the CSSTATE_STOP state from any other state.
if (CSSTATE_STOP == m_CsState)
{
DEBUGMSG(ZONE_IOCTL, (_T("PIN_IOControl(%08x): State to set = CSSTATE_STOP but we are already Stopped.\r\n"), this));
dwError = ERROR_SUCCESS;
break;
}
m_CsState = CSSTATE_STOP;
// Kill the timer to conserve resources
if (NULL != m_TimerIdentifier)
{
ASSERT(m_pfnTimeKillEvent);
m_pfnTimeKillEvent(m_TimerIdentifier);
m_TimerIdentifier = NULL;
}
if ((m_ulPinId == PREVIEW))
{
if (false == m_pCamAdapter->m_pPrp->PrpStopVfChannel())
{
break;
}
}
else if ((m_ulPinId == CAPTURE))
{
if (false == m_pCamAdapter->m_pPrp->PrpStopEncChannel())
{
break;
}
}
dwError = ERROR_SUCCESS;
break;
case CSSTATE_PAUSE:
DEBUGMSG(ZONE_IOCTL, (_T("PIN_IOControl(%08x): Set CSSTATE_PAUSE\r\n"), this));
if (CSSTATE_PAUSE == m_CsState)
{
DEBUGMSG(ZONE_IOCTL, (_T("PIN_IOControl(%08x): State to set = CSSTATE_PAUSE but we are already Paused.\r\n"), this));
dwError = ERROR_SUCCESS;
break;
}
if (false == m_pCamAdapter->CameraConfig())
{
DEBUGMSG(ZONE_IOCTL, (_T("PIN_IOControl(%08x): Config camera failed!\r\n"), this));
break;
}
if (m_ulPinId == PREVIEW)
{
if (!m_pCamAdapter->m_pPrp->PrpPauseViewfinding())
{
DEBUGMSG(ZONE_IOCTL, (_T("PIN_IOControl(%08x): Failed disabling viewfinding in display!\r\n"), this));
break;
}
}
if (false == PauseStream())
{
break;
}
dwError = ERROR_SUCCESS;
break;
case CSSTATE_RUN:
DEBUGMSG(ZONE_IOCTL, (_T("PIN_IOControl(%08x): Set CSSTATE_RUN\r\n"), this));
// We only allow Still Pin to goto Run state through PROPSETID_VIDCAP_VIDEOCONTROL
if (STILL == m_ulPinId)
{
break;
}
//TODO : not sure if we should completely block transitioning from STOP->RUN state.
if (CSSTATE_STOP == m_CsState)
{
DEBUGMSG(ZONE_IOCTL, (_T("PIN_IOControl(%08x): CSSTATE_STOP to CSSTATE_RUN is not a supported transition .\r\n"), this));
dwError = ERROR_INVALID_STATE;
break;
}
m_CsState = CSSTATE_RUN;
m_ulPictureNumber = 0;
if (!m_bBuffersAllocated)
{
DEBUGMSG(ZONE_IOCTL, (_T("PIN_IOControl(%08x): Cannot move to CSSTATE_RUN without allocating buffers (or reallocate if image size modified).\r\n"), this));
dwError = ERROR_INVALID_STATE;
break;
}
if (m_ulPinId == PREVIEW)
{
if (false == m_pCamAdapter->m_pPrp->PrpStartVfChannel())
{
break;
}
}
else if (m_ulPinId == CAPTURE)
{
if (false == m_pCamAdapter->m_pPrp->PrpStartEncChannel())
{
break;
}
}
dwError = ERROR_SUCCESS;
if (NULL == m_TimerIdentifier)
{
dwError = (CreateTimer() ? ERROR_SUCCESS : ERROR_NOT_READY);
}
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -