📄 pindevice.cpp
字号:
//-----------------------------------------------------------------------------
//
// Copyright (C) 2003-2004, MOTOROLA, INC. All Rights Reserved
// THIS SOURCE CODE IS CONFIDENTIAL AND PROPRIETARY AND MAY NOT
// BE USED OR DISTRIBUTED WITHOUT THE WRITTEN PERMISSION OF
// MOTOROLA, INC.
//
//------------------------------------------------------------------------------
//
// Copyright (C) 2004-2006, Freescale Semiconductor, Inc. All Rights Reserved.
// THIS SOURCE CODE, AND ITS USE AND DISTRIBUTION, IS SUBJECT TO THE TERMS
// AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT
//
//------------------------------------------------------------------------------
//
// File: Pindevice.cpp
//
// PinDevice Class Implementation
//
//------------------------------------------------------------------------------
#define PININTERFACE
#include <windows.h>
#include <ceddk.h>
#include <Msgqueue.h>
#include <pwinbase.h>
#include <camera.h>
#include "csp.h"
#include "prp.h"
#include "PrpClass.h"
#include "cameradbg.h"
#include "PinDriver.h"
//------------------------------------------------------------------------------
// External Functions
extern BOOL BSPCameraMemCpy(LPVOID pDst, LPCVOID pSrc, DWORD cbSize);
//------------------------------------------------------------------------------
// External Variables
//------------------------------------------------------------------------------
// Defines
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
// Global Variables
//------------------------------------------------------------------------------
// Local Variables
//------------------------------------------------------------------------------
// Local Functions
//------------------------------------------------------------------------------
//
// FUNCTION: BufferFill
//
// DESCRIPTION: a wrap function for PinBufferFill
//
// PARAMETERS: PUCHAR pImage,
// PCS_VIDEOINFOHEADER pCsVideoInfoHdr,
// IMAGECOMMAND Command,
// bool FlipHorizontal,
// LPVOID lpParam
//
// RETURNS: Data used
//
//------------------------------------------------------------------------------
UINT BufferFill( PUCHAR pImage, PCS_VIDEOINFOHEADER pCsVideoInfoHdr, IMAGECOMMAND Command, bool FlipHorizontal, LPVOID lpParam )
{
PPINDEVICE pPinDev = reinterpret_cast<PPINDEVICE>(lpParam);
ULONG ulDataUsed = pPinDev->PinBufferFill(pImage, pCsVideoInfoHdr, Command, FlipHorizontal, NULL);
return ulDataUsed;
}
//------------------------------------------------------------------------------
//
// FUNCTION: CPinDevice
//
// DESCRIPTION: CPinDevice constructor
//
// PARAMETERS: None
//
// RETURNS: None
//
//------------------------------------------------------------------------------
CPinDevice :: CPinDevice(void)
{
// m_dwMemoryModel = CSPROPERTY_BUFFER_CLIENT_LIMITED;
m_dwMemoryModel = CSPROPERTY_BUFFER_DRIVER;
m_fClientAllocateBuffers = FALSE;
m_fClientInitialized = FALSE;
m_fDiscontinuity = TRUE;
m_fPrpChannelEnabled = FALSE;
m_bStillPinActive = FALSE;
m_ulPinId = -1; // Invalid Pin Id
m_ulMaxNumOfBuffers = BUFFER_COUNT;
m_ulCurrNumOfBuffers = 0;
m_ulFrameSize = 0;
m_RtAveTimePerFrame = 0;
m_ulFramesDropped = 0;
m_ulPictureNumber = 0;
m_hMsgQ = NULL;
m_hTimerDll = NULL;
m_TimerIdentifier = NULL;
m_CsState = CSSTATE_STOP;
m_pfnTimeSetEvent = NULL;
m_pfnTimeKillEvent = NULL;
m_msStart = 0xFFFFFFFF;
m_msLastPT = 0;
m_pfnBufferFill = NULL;
m_pStreamDescriptorList = NULL;
m_dwBufferCount = 0;
m_hPrPBuffFilled = NULL;
m_BufferFilled = 0;
m_bDirectMode = FALSE;
m_pHeap = NULL;
InitializeCriticalSection( &m_csStreamBuffer );
}
//------------------------------------------------------------------------------
//
// FUNCTION: ~CPinDevice
//
// DESCRIPTION: CPinDevice destructor
//
// PARAMETERS: None
//
// RETURNS: None
//
//------------------------------------------------------------------------------
CPinDevice :: ~CPinDevice(void)
{
ResetBufferList( );
// Allow camera to release unneeded resources for the pin
m_pCamAdapter->CameraClosePin(m_ulPinId);
//DeleteDriverBuffers();
if ( NULL != m_TimerIdentifier && NULL != m_pfnTimeKillEvent )
{
m_pfnTimeKillEvent( m_TimerIdentifier );
m_TimerIdentifier = NULL;
}
if ( NULL != m_hMsgQ )
{
CloseMsgQueue( m_hMsgQ );
}
if ( NULL != m_hTimerDll )
{
FreeLibrary( m_hTimerDll );
}
if (m_hPrPBuffFilled != NULL)
CloseHandle(m_hPrPBuffFilled);
if ( NULL != m_pStreamDescriptorList )
{
LocalFree( m_pStreamDescriptorList );
m_pStreamDescriptorList = NULL;
}
if ( NULL != m_pHeap )
{
HeapDestroy(m_pHeap);
m_pHeap = NULL;
}
m_CsState = CSSTATE_STOP;
DeleteCriticalSection( &m_csStreamBuffer );
CloseSubDevice( );
}
//------------------------------------------------------------------------------
//
// FUNCTION: InitializeSubDevice
//
// DESCRIPTION: Bind caller CamDevice to this PinDevice
//
// PARAMETERS: PCAMERADEVICE pCamDevice
//
// RETURNS: TRUE if successfully, otherwise return FALSE
//
//------------------------------------------------------------------------------
BOOL CPinDevice :: InitializeSubDevice( PCAMERADEVICE pCamDevice )
{
TCHAR *tszLibraryName = NULL;
TCHAR *tszFunctionName = NULL;
DWORD dwDataSize = 0;
DWORD dwDataType = 0;
HKEY hkeyFillLibrary = NULL;
// if we can open the key
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
TEXT("Drivers\\Capture\\Camera"),
0, // Reseved. Must == 0.
0, // Must == 0.
&hkeyFillLibrary) == ERROR_SUCCESS)
{
// and the value we're looking for is available
if (RegQueryValueEx(hkeyFillLibrary,
TEXT("LibraryName"),
NULL, // Reserved. Must == NULL.
&dwDataType, // Do not need type info.
NULL,
&dwDataSize) == ERROR_SUCCESS)
{
// and it's type is correct
if(dwDataType == REG_SZ && dwDataSize > 0)
{
tszLibraryName = (TCHAR *) new BYTE[dwDataSize];
// and we can allocate a buffer for it
if(tszLibraryName)
{
// and we can fill it
if(RegQueryValueEx(hkeyFillLibrary,
TEXT("LibraryName"),
NULL, // Reserved. Must == NULL.
&dwDataType, // Do not need type info.
(LPBYTE) tszLibraryName,
&dwDataSize) == ERROR_SUCCESS)
{
// and we the other value we need is available
if (RegQueryValueEx(hkeyFillLibrary,
TEXT("FunctionName"),
NULL, // Reserved. Must == NULL.
&dwDataType, // Do not need type info.
NULL,
&dwDataSize) == ERROR_SUCCESS)
{
// and it's the right type
if(dwDataType == REG_SZ && dwDataSize > 0)
{
tszFunctionName = (TCHAR *) new BYTE[dwDataSize];
// and we can allocate a buffer for it
if(tszFunctionName)
{
// and we can fill the buffer
if(RegQueryValueEx(hkeyFillLibrary,
TEXT("FunctionName"),
NULL, // Reserved. Must == NULL.
&dwDataType, // Do not need type info.
(LPBYTE) tszFunctionName,
&dwDataSize) == ERROR_SUCCESS)
{
// then try to load the library we were given and retrieve the pointer.
if(m_hInstBuffer = LoadLibrary(tszLibraryName))
m_pfnBufferFill = (PFNBUFFERFILL) GetProcAddress(m_hInstBuffer, tszFunctionName);
}
delete[] tszFunctionName;
}
}
}
}
delete[] tszLibraryName;
}
}
}
RegCloseKey(hkeyFillLibrary);
}
// if a user specified function doesn't exist, then use the default.
if(!m_pfnBufferFill)
m_pfnBufferFill = &BufferFill;
m_pCamAdapter = pCamDevice ;
if (NULL == m_pCamAdapter)
return FALSE;
// Let's retrieve the pin model from the registry. If none is provided,
// the default model will be APPLICATION_LIMITED
ReadMemoryModelFromRegistry();
return TRUE ;
}
//------------------------------------------------------------------------------
//
// FUNCTION: CloseSubDevice
//
// DESCRIPTION: Bind caller CamDevice to this PinDevice
//
// PARAMETERS: None
//
// RETURNS: TRUE if successfully, otherwise return FALSE
//
//------------------------------------------------------------------------------
BOOL CPinDevice :: CloseSubDevice()
{
m_pCamAdapter->DecrCInstances( m_ulPinId ) ;
// free the library if it was loaded.
if(m_hInstBuffer)
{
FreeLibrary(m_hInstBuffer);
m_hInstBuffer = 0;
}
// and if we were using the filler function from the library, invalidate it.
if(m_pfnBufferFill != &BufferFill)
m_pfnBufferFill = NULL;
if (( STILL == m_ulPinId ) || ( m_ulPinId == m_pCamAdapter->m_StillPinInherited ))
m_pCamAdapter->m_StillPinInherited = STILL;
return TRUE ;
}
//------------------------------------------------------------------------------
//
// FUNCTION: PictureNumber
//
// DESCRIPTION: Query the information of picture number
//
// PARAMETERS: None
//
// RETURNS: Picture number
//
//------------------------------------------------------------------------------
ULONG CPinDevice :: PictureNumber( ) const
{
return m_ulPictureNumber;
}
//------------------------------------------------------------------------------
//
// FUNCTION: FramesDropped
//
// DESCRIPTION: Query the information of dropped frame number
//
// PARAMETERS: None
//
// RETURNS: Dropped frame number
//
//------------------------------------------------------------------------------
ULONG CPinDevice :: FramesDropped( ) const
{
return m_ulFramesDropped;
}
//------------------------------------------------------------------------------
//
// FUNCTION: FrameSize
//
// DESCRIPTION: Query the information of the size for each frame
//
// PARAMETERS: None
//
// RETURNS: The size for each frame
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -