📄 pindevice.cpp
字号:
}
if (FALSE == m_bDirectMode)
{
//For normal mode, we free the buffer automatically.or we should free it manually.
m_pCamAdapter->m_pPrp->PrpPutEncBufIdle(&prpBuffData);
}
}
break;
default:
DEBUGMSG(ZONE_ERROR,(_T("BufferFill: Invalid pin id.\r\n"))) ;
return -1;
}
// If we got a buffer from Prp, exit loop and continue.
// If there was no buffer returned, loop again and wait for one.
if ((prpBuffData.pPhysAddr != NULL) && (prpBuffData.pVirtAddr != NULL))
{
break;
}
DEBUGMSG(ZONE_FUNCTION, (TEXT("+BufferFill: pbySrcBuffer NULL! Waiting again...\r\n")));
}
pbyDstBuffer = reinterpret_cast<PUINT8>(pImage);
if (FALSE == m_bDirectMode)
{
// Here, copy the whole frame buffer memory to application.
pbySrcBuffer = (PUINT8) prpBuffData.pVirtAddr;
memcpy(pbyDstBuffer, pbySrcBuffer, BufferSize);
retVal = BufferSize;
}
else
{
// Here, only return the physics addres for other drivers' further processing
memcpy(pbyDstBuffer, &prpBuffData, sizeof(prpBuffData));
retVal = sizeof(prpBuffData);
}
DEBUGMSG(ZONE_FUNCTION, (TEXT("+BufferFill:buffer filled success!\r\n")));
DEBUGMSG(ZONE_FUNCTION, (TEXT("-BufferFill\r\n")));
return retVal;
}
//------------------------------------------------------------------------------
//
// FUNCTION: PauseStream
//
// DESCRIPTION: Pause stream. if not creat timer, creat it.
//
// PARAMETERS: None
//
// RETURNS: Returns ERROR_SUCCESS if the operation completes successfully;
// otherwise, returns a Microsoft Win32 error code.
//
//------------------------------------------------------------------------------
DWORD CPinDevice ::PauseStream( )
{
if( m_CsState == CSSTATE_STOP )
{
// Let's allocate our resources
if( m_pStreamDescriptorList == NULL )
{
m_pStreamDescriptorList = (PCS_STREAM_DESCRIPTOR_SHADOW) LocalAlloc( LMEM_ZEROINIT, sizeof( CS_STREAM_DESCRIPTOR_SHADOW ) * m_ulMaxNumOfBuffers );
m_dwBufferCount = 0;//Move the line from the following.
if( NULL == m_pStreamDescriptorList )
return ERROR_OUTOFMEMORY;
}
}
if ( FALSE == m_fClientInitialized )
{
// By this time the buffers must be allocated
m_fClientInitialized = CreateTimer() ;
}
if( m_fClientInitialized )
{
m_CsState = CSSTATE_PAUSE ;
}
if( m_fClientInitialized == FALSE )
{
return ERROR_INTERNAL_ERROR;
}
return ERROR_SUCCESS ;
}
//------------------------------------------------------------------------------
//
// FUNCTION: PinHandleConnectionRequests
//
// 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 :: PinHandleConnectionRequests(
PCSPROPERTY pCsProp,
PUCHAR pOutBuf, // Unsafe, use with caution
DWORD OutBufLen,
PDWORD pdwBytesTransferred // Unsafe, use with caution
)
{
DEBUGMSG(ZONE_IOCTL, (_T("PIN_IOControl(%08x): PinHandleConnectionRequests\r\n"), this));
DWORD dwError = ERROR_INVALID_PARAMETER;
PCSALLOCATOR_FRAMING pCsAllocatorFraming = NULL;
PCS_DATAFORMAT_VIDEOINFOHEADER pCsDataFormatVidInfoHdr = NULL;
PCS_DATAFORMAT_VIDEOINFOHEADER pCsDataFormatVidInfoHdrCopy = NULL;
if ( NULL == pCsProp )
{
return dwError;
}
__try
{
*pdwBytesTransferred = 0 ;
}
__except( EXCEPTION_EXECUTE_HANDLER )
{
return ERROR_INVALID_PARAMETER;
}
// we support PROPSETID_Pin, so just return success
if ( CSPROPERTY_TYPE_SETSUPPORT == pCsProp->Flags )
{
return ERROR_SUCCESS;
}
switch ( pCsProp->Id )
{
case CSPROPERTY_CONNECTION_STATE:
dwError = PinHandleConnStateSubReqs(pCsProp->Flags, pOutBuf, OutBufLen, pdwBytesTransferred);
break;
case CSPROPERTY_CONNECTION_DATAFORMAT:
pCsDataFormatVidInfoHdr = (PCS_DATAFORMAT_VIDEOINFOHEADER) pOutBuf;
DWORD dwStructSize;
if(( OutBufLen < sizeof( PCS_DATAFORMAT_VIDEOINFOHEADER )) || ( pOutBuf == NULL ))
{
return dwError;
}
// The DeviceIOControl function is already taking care of calling MapCallerPointer.
// The video info header can be modified by the caller while it's being accessed in the subroutine.
// The Subroutine needs to make a copy of the video info header before accessing it.
__try
{
dwStructSize = sizeof( CS_DATAFORMAT_VIDEOINFOHEADER ) + pCsDataFormatVidInfoHdr->VideoInfoHeader.bmiHeader.biSize - sizeof( CS_BITMAPINFOHEADER );
pCsDataFormatVidInfoHdrCopy = (PCS_DATAFORMAT_VIDEOINFOHEADER) LocalAlloc( LMEM_ZEROINIT, dwStructSize );
if( pCsDataFormatVidInfoHdrCopy == NULL )
{
return ERROR_INVALID_PARAMETER; // TODO: change it into out of memory
}
if( BSPCameraMemCpy( pCsDataFormatVidInfoHdrCopy, pCsDataFormatVidInfoHdr, dwStructSize ))
{
dwError = PinHandleConnDataFormatSubReqs( pCsProp->Flags, pCsDataFormatVidInfoHdrCopy, pdwBytesTransferred ) ;
}
if (pCsProp->Flags == CSPROPERTY_TYPE_GET)
{
BSPCameraMemCpy( pCsDataFormatVidInfoHdr, pCsDataFormatVidInfoHdrCopy, dwStructSize );
}
}
__except( EXCEPTION_EXECUTE_HANDLER )
{
}
LocalFree( pCsDataFormatVidInfoHdrCopy );
break;
case CSPROPERTY_CONNECTION_ALLOCATORFRAMING:
switch ( pCsProp->Flags )
{
case CSPROPERTY_TYPE_GET:
case CSPROPERTY_TYPE_BASICSUPPORT:
CSALLOCATOR_FRAMING csAllocatorFraming;
if(( OutBufLen < sizeof( CSALLOCATOR_FRAMING )) || ( pOutBuf == NULL ))
{
dwError = ERROR_MORE_DATA;
break;
}
{
csAllocatorFraming.RequirementsFlags = GetCurrentMemoryModel();
csAllocatorFraming.PoolType = PagedPool;
//TODO : put PIN_GUID specific decision about number of max. frames
csAllocatorFraming.Frames = m_ulMaxNumOfBuffers;
csAllocatorFraming.FrameSize = m_CsDataRangeVideo.VideoInfoHeader.bmiHeader.biSizeImage;
csAllocatorFraming.FileAlignment = FILE_BYTE_ALIGNMENT;
csAllocatorFraming.Reserved = 0;
}
__try
{
memcpy( pOutBuf, &csAllocatorFraming, sizeof( CSALLOCATOR_FRAMING ));
*pdwBytesTransferred = sizeof( CSALLOCATOR_FRAMING );
}
__except( EXCEPTION_EXECUTE_HANDLER )
{
dwError = ERROR_INVALID_PARAMETER;
break;
}
dwError = ERROR_SUCCESS;
break ;
case CSPROPERTY_TYPE_SET:
if( OutBufLen < sizeof( CSALLOCATOR_FRAMING ))
{
dwError = ERROR_INVALID_PARAMETER;
break;
}
pCsAllocatorFraming = (PCSALLOCATOR_FRAMING) pOutBuf;
if(( m_CsState != CSSTATE_STOP ) || ( GetCurrentMemoryModel() != pCsAllocatorFraming->RequirementsFlags ))
{
dwError = ERROR_INVALID_PARAMETER;
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: PinHandleBufferRequest
//
// DESCRIPTION: Handle the buffer control commands to the driver
//
// PARAMETERS: DWORD dwCommand,
// PUCHAR pOutBuf,
// DWORD OutBufLen,
//
// RETURNS: Returns ERROR_SUCCESS if the operation completes successfully;
// otherwise, returns a Microsoft Win32 error code.
//
//------------------------------------------------------------------------------
DWORD
CPinDevice::PinHandleBufferRequest(
CSBUFFER_INFO csBufferInfo,
PUCHAR pOutBuf,
DWORD OutBufLen,
DWORD *pdwBytesTransferred
)
{
DWORD dwError = ERROR_INVALID_PARAMETER;
DWORD dwCommand = csBufferInfo.dwCommand;
PCS_STREAM_DESCRIPTOR pCsDescriptor = (PCS_STREAM_DESCRIPTOR) csBufferInfo.pStreamDescriptor;
if ( pdwBytesTransferred )
{
*pdwBytesTransferred = 0;
}
// The pOutBuf argument has already been probed with MapCallerPointer, and the upper layer
// has already checked for the size of the buffer to be at least sizeof( CS_STREAM_DESCRIPTOR )
switch( dwCommand )
{
case CS_ALLOCATE:
// Let's allocate our resources
if( m_pStreamDescriptorList == NULL )
{
m_pStreamDescriptorList = (PCS_STREAM_DESCRIPTOR_SHADOW) LocalAlloc( LMEM_ZEROINIT, sizeof( CS_STREAM_DESCRIPTOR_SHADOW ) * m_ulMaxNumOfBuffers );
if( NULL == m_pStreamDescriptorList )
return ERROR_OUTOFMEMORY;
}
dwError = AllocateBuffer( csBufferInfo.pStreamDescriptor, pOutBuf, OutBufLen, pdwBytesTransferred );
break;
case CS_ENQUEUE:
dwError = EnqueueDescriptor( csBufferInfo.pStreamDescriptor );
break;
case CS_DEALLOCATE:
dwError = DeallocateBuffer( csBufferInfo.pStreamDescriptor );
default:
break;
}
return dwError;
}
//------------------------------------------------------------------------------
//
// 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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -