📄 pindevice.cpp
字号:
default :
DEBUGMSG(ZONE_IOCTL|ZONE_ERROR, (_T("PIN_IOControl(%08x): Incorrect State\r\n"), this));
dwError = ERROR_INVALID_PARAMETER;
}
break;
default:
DEBUGMSG(ZONE_IOCTL|ZONE_ERROR, (_T("PIN_IOControl(%08x): Invalid Request\r\n"), this));
break;
}
return dwError;
}
/********************************************************************
*
* FUNCTION: PinHandleConnDataFormatSubReqs
*
* DESCRIPTION: get or set the current data format for the pin
*
* PARAMETERS: ULONG ulReqFlags,
* PCS_DATAFORMAT_VIDEOINFOHEADER pCsDataFormatVidInfoHdr,
* PDWORD pdwBytesTransferred
*
* RETURNS: Returns ERROR_SUCCESS if the operation completes successfully;
* otherwise, returns a Microsoft Win32 error code.
*
********************************************************************/
DWORD CPinDevice::PinHandleConnDataFormatSubReqs(
ULONG ulReqFlags,
PCS_DATAFORMAT_VIDEOINFOHEADER pCsDataFormatVidInfoHdr,
PDWORD pdwBytesTransferred
)
{
DWORD dwError = ERROR_INVALID_PARAMETER ;
//PCSSTATE pCsState = NULL; //More investigation needed for stopping pin.
PCS_DATARANGE_VIDEO pCsDataRangeVideoMatched = NULL;
ULONG ulNewFrameSize;
// We must have called IOCTL_STREAM_INSTANTIATE before setting format
if (-1 == m_ulPinId)
{
return dwError;
}
switch(ulReqFlags)
{
case CSPROPERTY_TYPE_SET:
// We don't allow to change STILL Pin's data format
if (m_ulPinId == STILL)
{
DEBUGMSG(ZONE_IOCTL|ZONE_ERROR, (_T("PIN_IOControl(%08x): Can not change STILL Pin's dataformat.\r\n"), this));
return dwError;
}
if (m_CsState != CSSTATE_STOP)
{
DEBUGMSG(ZONE_IOCTL|ZONE_ERROR, (_T("PIN_IOControl(%08x): Can not set data format when running. Stop pin first.\r\n"), this));
return dwError;
}
if (true == m_pCamAdapter->AdapterCompareFormat(m_ulPinId, reinterpret_cast<PCS_DATARANGE_VIDEO>(pCsDataFormatVidInfoHdr), &pCsDataRangeVideoMatched, false))
{
// We found our format
memcpy(&m_CsDataRangeVideo, pCsDataRangeVideoMatched, sizeof(CS_DATARANGE_VIDEO));
memcpy(&m_CsDataRangeVideo, &pCsDataFormatVidInfoHdr->DataFormat, sizeof(CSDATARANGE));
memcpy(&m_CsDataRangeVideo.VideoInfoHeader, &pCsDataFormatVidInfoHdr->VideoInfoHeader, sizeof(CS_VIDEOINFOHEADER));
m_RtAveTimePerFrame = m_CsDataRangeVideo.VideoInfoHeader.AvgTimePerFrame;
*pdwBytesTransferred = sizeof ( CS_DATARANGE_VIDEO );
// Assure that we will reconfigure IPU before starting.
m_pCamAdapter->CameraMarkAsModified(m_ulPinId);
ulNewFrameSize = CS__DIBSIZE(m_CsDataRangeVideo.VideoInfoHeader.bmiHeader); // by bytes
// If new data format changes the frame size, the camera driver buffers
// must be reallocated.
if (ulNewFrameSize != m_ulFrameSize)
{
m_bBuffersAllocated = false;
}
DEBUGMSG(ZONE_IOCTL|ZONE_ERROR, (_T("PIN_IOControl(%08x): Modified CSDataRangeVideo for Pin %x. New width: %x, New height: %x\r\n"),
this, m_ulPinId, m_CsDataRangeVideo.VideoInfoHeader.bmiHeader.biWidth, m_CsDataRangeVideo.VideoInfoHeader.bmiHeader.biHeight));
if (m_pCamAdapter->m_StillPinInherited == m_ulPinId)
{
memcpy(&m_pCamAdapter->m_StrmInstances[STILL].pPinDev->m_CsDataRangeVideo, &m_CsDataRangeVideo, sizeof(CS_DATARANGE_VIDEO));
memcpy(&m_pCamAdapter->m_StrmInstances[STILL].pPinDev->m_CsDataRangeVideo.DataRange, &m_CsDataRangeVideo.DataRange, sizeof(CSDATARANGE));
memcpy(&m_pCamAdapter->m_StrmInstances[STILL].pPinDev->m_CsDataRangeVideo.VideoInfoHeader, &m_CsDataRangeVideo.VideoInfoHeader, sizeof(CS_VIDEOINFOHEADER));
m_pCamAdapter->m_StrmInstances[STILL].pPinDev->m_RtAveTimePerFrame = m_RtAveTimePerFrame;
}
dwError = ERROR_SUCCESS;
}
else
{
DEBUGMSG(ZONE_IOCTL|ZONE_ERROR, (_T("PIN_IOControl(%08x): Failed Adapter format compare. Did not change settings.\r\n"), this));
}
break;
case CSPROPERTY_TYPE_GET:
memcpy(&pCsDataFormatVidInfoHdr, &m_CsDataRangeVideo.DataRange, sizeof(CSDATARANGE));
memcpy(&pCsDataFormatVidInfoHdr->VideoInfoHeader, &m_CsDataRangeVideo.VideoInfoHeader, sizeof(CS_VIDEOINFOHEADER));
*pdwBytesTransferred = sizeof (CS_DATARANGE_VIDEO);
dwError = ERROR_SUCCESS;
break;
default:
DEBUGMSG(ZONE_IOCTL|ZONE_ERROR, (_T("PIN_IOControl(%08x): Invalid Request\r\n"), this));
}
return dwError;
}
/********************************************************************
*
* FUNCTION: PinHandleReadStreamRequests
*
* DESCRIPTION: //??
*
* 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::PinHandleReadStreamRequests(
PUCHAR pInBuf,
DWORD InBufLen,
PUCHAR pOutBuf,
DWORD OutBufLen,
PDWORD pdwBytesTransferred
)
{
DEBUGMSG( ZONE_IOCTL, (_T("PIN_IOControl(%08x): PinHandleReadStreamRequests\r\n"), this));
DWORD dwError = ERROR_SUCCESS;
ULONG ulBuffSize = sizeof(CSSTREAM_HEADER) + sizeof(CS_FRAME_INFO);
ULONG ulBuffNum = InBufLen / ulBuffSize;
PCS_STREAM_DESCRIPTOR pCsStreamDesc = reinterpret_cast<PCS_STREAM_DESCRIPTOR>(pInBuf);
do
{
if (false == AddFreeBuf(false, pCsStreamDesc))
{
dwError = ERROR_INVALID_PARAMETER;
}
pCsStreamDesc += 1;
} while (--ulBuffNum);
if (false == m_fClientInitialized && CSSTATE_PAUSE == m_CsState)
{
m_fClientInitialized = true;
}
return dwError ;
}
//-----------------------------------------------------------------------------
//
// Function: PinSetDirectDisplayMode
//
// This function sets the direct display mode for the camera device.
//
// Parameters:
// bDirectDisplayMode
// [in] Boolean value used to set the direct display mode.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
DWORD CPinDevice::PinSetDirectDisplayMode(BOOL bDirectDisplayMode)
{
DWORD retVal = ERROR_SUCCESS;
if (m_ulPinId == PREVIEW)
{
m_pCamAdapter->CameraSetDirectDisplay(bDirectDisplayMode);
}
else
{
DEBUGMSG(ZONE_ERROR, (_T("PIN_IOControl(%08x): Cannot set Direct Display mode for non-Preview pin.\r\n"), this));
retVal = ERROR_INVALID_CATEGORY;
}
return retVal;
}
//-----------------------------------------------------------------------------
//
// Function: PinSetDirectCaptureMode
//
// This function sets the direct capture mode for the camera device.
//
// Parameters:
// bDirectCaptureMode
// [in] Boolean value used to set the direct capture mode.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
DWORD CPinDevice::PinSetDirectCaptureMode(BOOL bDirectCaptureMode)
{
DWORD retVal = ERROR_SUCCESS;
if (m_ulPinId == CAPTURE)
{
m_pCamAdapter->CameraSetDirectCapture(bDirectCaptureMode);
}
else
{
DEBUGMSG(ZONE_ERROR, (_T("PIN_IOControl(%08x): Cannot set Direct Capture mode for non-Capture pin.\r\n"), this));
retVal = ERROR_INVALID_CATEGORY;
}
return retVal;
}
/********************************************************************
*
* FUNCTION: AddFreeBuf
*
* DESCRIPTION: The driver keeps two empty-buffer lists, i.e., m_pHeadBufferOri and
* m_pHeadBuffer. m_pHeadBufferOri is filled up when the driver allocates
* the buffers, while m_pHeadBuffer is used when the pin is in run state
* and it wants to fill up a sample. AddFreeBuf() is called with fDriverAllocating=true
* at the time the driver is allocation and it called with fDriverAllocating=false
* when the driver handles READ_STREAM calls. At the driver unloading time,
* the driver would only try to delete m_pHeadBufferOri
*
* PARAMETERS: bool fDriverAllocating,
* PCS_STREAM_DESCRIPTOR pCsStreamDesc
*
* RETURNS: true if success, otherwise false.
*
********************************************************************/
bool CPinDevice::AddFreeBuf(
bool fDriverAllocating,
PCS_STREAM_DESCRIPTOR pCsStreamDesc
)
{
DEBUGMSG(ZONE_IOCTL, (_T("+AddFreeBuf\r\n")));
PCS_VIDEOINFOHEADER pCsVideoInfoHdr = reinterpret_cast<PCS_VIDEOINFOHEADER>(&m_CsDataRangeVideo.VideoInfoHeader);
UINT biHeight = pCsVideoInfoHdr->bmiHeader.biHeight;
UINT biWidthBytes = CS_DIBWIDTHBYTES (pCsVideoInfoHdr->bmiHeader);
UINT LinesToCopy = abs(biHeight);
EnterCriticalSection(&m_csStreamBuffer);
PSTREAM_BUFFERNODE pStreamBuffer = reinterpret_cast<PSTREAM_BUFFERNODE>(RemoteLocalAlloc(LPTR, sizeof(STREAM_BUFFERNODE)));
if (NULL == pStreamBuffer)
{
DEBUGMSG(ZONE_IOCTL|ZONE_ERROR, (_T("PIN_IOControl(%08x): AddFreeBuf OOM\r\n"), this));
LeaveCriticalSection(&m_csStreamBuffer);
return false;
}
memset(pStreamBuffer, 0x0, sizeof (STREAM_BUFFERNODE));
if (true == fDriverAllocating)
{
DEBUGMSG(ZONE_IOCTL, (_T("PIN_IOControl(%08x): fDriverAllocating = true\r\n"), this));
pStreamBuffer->pCsStreamDesc = pCsStreamDesc;
pStreamBuffer->pCsStreamDesc->CsStreamHeader.Data =(PUCHAR)MapCallerPtr( pStreamBuffer->pCsStreamDesc->CsStreamHeader.Data, LinesToCopy*biWidthBytes);
pStreamBuffer->pNext = m_pHeadBufferOri;
m_pHeadBufferOri = pStreamBuffer;
}
else
{
DEBUGMSG(ZONE_IOCTL, (_T("AddFreeBuf(%08x): fDriverAllocating = false\r\n"), this));
PCS_STREAM_DESCRIPTOR pCsStrmDescLocal = reinterpret_cast<PCS_STREAM_DESCRIPTOR>(RemoteLocalAlloc(LPTR, sizeof(CS_STREAM_DESCRIPTOR)));
if (NULL == pCsStrmDescLocal)
{
DEBUGMSG(ZONE_IOCTL|ZONE_ERROR, (_T("AddFreeBuf(%08x): AddFreeBuf OOM Stream Descriptor\r\n"), this));
LeaveCriticalSection(&m_csStreamBuffer);
return false;
}
memcpy(pCsStrmDescLocal, pCsStreamDesc, sizeof(CS_STREAM_DESCRIPTOR));
pStreamBuffer->pCsStreamDesc = pCsStrmDescLocal;
pStreamBuffer->pCsStreamDesc->CsStreamHeader.Data = (PUCHAR)MapCallerPtr(pStreamBuffer->pCsStreamDesc->CsStreamHeader.Data, LinesToCopy*biWidthBytes);
pStreamBuffer->pNext = m_pHeadBuffer;
m_pHeadBuffer = pStreamBuffer;
}
LeaveCriticalSection(&m_csStreamBuffer);
DEBUGMSG(ZONE_IOCTL, (_T("-AddFreeBuf: LeaveCriticalSection\r\n")));
return true;
}
/********************************************************************
*
* FUNCTION: RemoveBufferFromList
*
* DESCRIPTION: Handle Pin IO request
*
* PARAMETERS: None
*
* RETURNS: None
********************************************************************/
bool CPinDevice::RemoveBufferFromList(PCS_STREAM_DESCRIPTOR *ppCsStreamDesc)
{
DEBUGMSG(ZONE_IOCTL, (_T("PIN_IOControl(%08x): +RemoveBufferFromList\r\n"), this));
PSTREAM_BUFFERNODE pStrmBuf = NULL;
EnterCriticalSection(&m_csStreamBuffer);
if (NULL == m_pHeadBuffer)
{
pStrmBuf = NULL;
LeaveCriticalSection(&m_csStreamBuffer);
DEBUGMSG(ZONE_IOCTL, (_T("PIN_IOControl(%08x): +RemoveBufferFromList: m_pHeadBuffer is empty.\r\n"), this));
return false;
}
pStrmBuf = m_pHeadBuffer;
m_pHeadBuffer = m_pHeadBuffer->pNext;
*ppCsStreamDesc = pStrmBuf->pCsStreamDesc;
RemoteLocalFree(pStrmBuf);
LeaveCriticalSection(&m_csStreamBuffer);
DEBUGMSG(ZONE_IOCTL, (_T("PIN_IOControl(%08x): -RemoveBufferFromList\r\n"), this));
return true;
}
bool
CPinDevice::DeleteBufferList()
{
DWORD ReferencePin;
DEBUGMSG(ZONE_IOCTL, (_T("+DeleteBufferList\r\n")));
EnterCriticalSection(&m_csStreamBuffer);
while (NULL != m_pHeadBufferOri)
{
PSTREAM_BUFFERNODE pStrmBuf = m_pHeadBufferOri;
if (false == m_fClientAllocateBuffers)
{
RemoteLocalFree(m_pHeadBufferOri->pCsStreamDesc->CsStreamHeader.Data);
RemoteLocalFree(m_pHeadBufferOri->pCsStreamDesc);
}
m_pHeadBufferOri = m_pHeadBufferOri->pNext;
RemoteLocalFree(pStrmBuf);
}
LeaveCriticalSection(&m_csStreamBuffer);
// Call down to Prp to deallocate buffer list
switch (m_ulPinId)
{
case PREVIEW:
if (!m_pCamAdapter->m_pPrp->PrpDeleteVfBuffers())
{
return false;
}
break;
case CAPTURE:
if (!m_pCamAdapter->m_pPrp->PrpDeleteEncBuffers())
{
return false;
}
break;
case STILL:
ReferencePin = m_pCamAdapter->m_StillPinInherited;
if (ReferencePin == PREVIEW)
{
if (!m_pCamAdapter->m_pPrp->PrpDeleteVfBuffers())
{
return false;
}
}
else if (ReferencePin == CAPTURE)
{
if (!m_pCamAdapter->m_pPrp->PrpDeleteEncBuffers())
{
return false;
}
}
break;
default:
DEBUGMSG(ZONE_ERROR,(_T("DeleteBufferList: Invalid pin id.\r\n"))) ;
return false;
}
DEBUGMSG(ZONE_IOCTL, (_T("-DeleteBufferList\r\n")));
return true;
}
/*********************************************************************
END OF FILE
*********************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -