dscapturedriver.cpp
来自「WinCE 3.0 BSP, 包含Inter SA1110, Intel_815」· C++ 代码 · 共 364 行
CPP
364 行
//////////////////////////////////////////////////////////////////////////////
/*****************************************************************************
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Copyright (c) 1995-2000 Microsoft Corporation
Module Name:
DsCaptureDriver.cpp
Abstract:
Implementation file for the DsCaptureDriver class.
Revision History:
coscor 7/5/2000 created
*****************************************************************************/
//////////////////////////////////////////////////////////////////////////////
#include "includes.h"
#include "DsCaptureDriver.h"
#include "DsCaptureDriverBuffer.h"
DsCaptureDriver::DsCaptureDriver(HRESULT &hr):
m_ulRefCount(1),
m_bOpened(false),
m_pCX5530 (NULL)
{
FUNCMSG("DsCaptureDriver::DsCaptureDriver");
InitializeCriticalSection( &m_csSoundBuffer );
hr = DS_OK;
// Do initialization stuff that needs to be done whenever the driver is
// Open'ed or Close'd in those methods (below).
}
DsCaptureDriver::~DsCaptureDriver()
{
FUNCMSG("DsCaptureDriver::~DsCaptureDriver");
if(m_bOpened)
Close();
DeleteCriticalSection( &m_csSoundBuffer );
}
//////////////////////////////////////////////////////////////////////////////
/*****************************************************************************
*****************************************************************************/
//////////////////////////////////////////////////////////////////////////////
STDMETHODIMP DsCaptureDriver::QueryInterface (
REFIID pIid,
LPVOID *ppNew )
{
FUNCMSG("DsCaptureDriver::QueryInterface");
DEBUGCHK(ppNew != NULL);
#ifdef PARAMETER_VALIDATION
if( ! ppNew )
{
ERRMSG("DsCaptureDriver::QueryInterface -- ppNew is NULL");
return DSERR_INVALIDPARAM;
}
#endif
if( IsEqualIID(IID_IUnknown, pIid)
|| IsEqualIID( IID_IDsCaptureDriver, pIid)
)
{
InterlockedIncrement( (LPLONG) &m_ulRefCount );
*ppNew = (IDsCaptureDriver *) this;
return NO_ERROR;
}
*ppNew = NULL;
return DSERR_NOINTERFACE;
}
//////////////////////////////////////////////////////////////////////////////
/*****************************************************************************
*****************************************************************************/
//////////////////////////////////////////////////////////////////////////////
STDMETHODIMP_(ULONG) DsCaptureDriver::AddRef(void)
{
DEBUGMSG(ZONE_REFCOUNT,(TEXT("DsCaptureDriver::AddRef previous=%ld\r\n"), m_ulRefCount));
return InterlockedIncrement( (LPLONG) &m_ulRefCount );
}
//////////////////////////////////////////////////////////////////////////////
/*****************************************************************************
*****************************************************************************/
//////////////////////////////////////////////////////////////////////////////
STDMETHODIMP_(ULONG) DsCaptureDriver::Release(void)
{
DEBUGMSG(ZONE_REFCOUNT,(TEXT("DsCaptureDriver::Release previous=%ld\r\n"), m_ulRefCount));
ULONG ulRefs = InterlockedDecrement( (LPLONG) &m_ulRefCount );
if( ulRefs == 0 )
{
DEBUGMSG(ZONE_REFCOUNT,(TEXT("DsCaptureDriver::Release final on 0x%08x\n"), this ));
delete this;
}
return ulRefs;
}
//////////////////////////////////////////////////////////////////////////////
/*****************************************************************************
*****************************************************************************/
//////////////////////////////////////////////////////////////////////////////
STDMETHODIMP DsCaptureDriver::Open(void)
{
FUNCMSG("DsCaptureDriver::Open");
//
// Driver dll has already been loaded and this is the first call to open
//
CriticalSectionAcquisition csa(&m_csSoundBuffer);
//return if already opened
if(m_bOpened)
return DS_OK;
m_pCX5530 = CCX5530Audio::GetCX5530AudioObject();
if(! m_pCX5530)
return DSERR_GENERIC;
// m_pCX5530->SetCaptureDriver(this, TRUE);
m_bOpened = true;
return DS_OK;
}
//////////////////////////////////////////////////////////////////////////////
/*****************************************************************************
*****************************************************************************/
//////////////////////////////////////////////////////////////////////////////
STDMETHODIMP DsCaptureDriver::Close(void)
{
FUNCMSG("DsCaptureDriver::Close");
CriticalSectionAcquisition csa(&m_csSoundBuffer);
// m_pCX5530->SetCaptureDriver(this, FALSE);
m_bOpened = false;
return DS_OK;
}
//////////////////////////////////////////////////////////////////////////////
/*****************************************************************************
*****************************************************************************/
//////////////////////////////////////////////////////////////////////////////
STDMETHODIMP DsCaptureDriver::CreateCaptureBuffer(
LPWAVEFORMATEX lpWaveFormatEx,
DWORD dwFlags,
DWORD dwCardAddress,
LPDWORD pdwcbBufferSize,
LPBYTE *ppbBuffer, // not actually used
LPVOID *ppvObj
)
{
FUNCMSG("+DsCaptureDriver::CreateCaptureBuffer");
CriticalSectionAcquisition csa(&m_csSoundBuffer);
HRESULT hr;
if(!m_bOpened)
return DSERR_GENERIC;
if( ! lpWaveFormatEx )
{
ERRMSG("DsCaptureDriver::CreateSoundBuffer -- lpWaveFormatEx is NULL");
return DSERR_INVALIDPARAM;
}
if (!m_pCX5530->IsFormatSupported(lpWaveFormatEx))
{
ERRMSG3("DsCaptureDriver::CreateSoundBuffer Unsupported format: %d Hz, %d bits, %s", lpWaveFormatEx->nSamplesPerSec, lpWaveFormatEx->wBitsPerSample, ( lpWaveFormatEx->nChannels == 1)?TEXT("MONO"):TEXT("STEREO"));
return DSERR_UNSUPPORTED;
}
if( ! ppvObj )
{
ERRMSG("DsCaptureDriver::CreateSoundBuffer -- ppvObj is NULL");
return DSERR_INVALIDPARAM;
}
if( ! pdwcbBufferSize)
{
ERRMSG("DsCaptureDriver::CreateSoundBuffer -- pdwcbBufferSize is NULL");
return DSERR_INVALIDPARAM;
}
// ask hardware obj to give us a buffer object
DsCaptureDriverBuffer *pCaptureBuffer = NULL;
hr = m_pCX5530->CreateCaptureBuffer(pdwcbBufferSize, &pCaptureBuffer);
if (FAILED(hr))
{
return hr;
}
if(dwCardAddress)
ERRMSG("DsCaptureDriver::CreateSoundBuffer -- WARNING dwCardAddress Not supported");
// Set format (we checked above that it's valid)
hr = pCaptureBuffer->SetFormat(lpWaveFormatEx);
// Now call on the object we've created and retrieve the
// IDsCaptureDriverBuffer interface.
hr = pCaptureBuffer->QueryInterface( IID_IDsCaptureDriverBuffer, ppvObj );
// Need to make sure RefCount on the object is correct -- whether we
// succeeded above or failed, it is 1 higher than it should be.
// If we succeeded above, it is now 2, not 1 and if we failed it is 1 not 0.
// This is because both constructor and QueryInterface increased RefCount.
pCaptureBuffer->Release();
if( FAILED(hr) || ! *ppvObj )
{
ERRMSG("DsCaptureDriver::CreateCaptureBuffer -- QueryInterface failed");
if( *ppvObj )
{
((IUnknown *) *ppvObj)->Release();
*ppvObj = NULL;
}
pCaptureBuffer->Release();
*pdwcbBufferSize = 0;
hr = CLASS_E_CLASSNOTAVAILABLE;
}
FUNCMSG1("-DsCaptureDriver::CreateCaptureBuffer: %s", FAILED(hr)?TEXT("FAIL"):TEXT("SUCCESS"));
return hr;
}
//////////////////////////////////////////////////////////////////////////////
/*****************************************************************************
*****************************************************************************/
//////////////////////////////////////////////////////////////////////////////
STDMETHODIMP DsCaptureDriver::GetCaps(PDSCDRIVERCAPS pDSCDriverCaps )
{
RETMSG("DsCaptureDriver::GetCaps");
// Fill out the DSDRIVERCAPS structure with the appropriate information.
if(! pDSCDriverCaps)
return DSERR_GENERIC; //invalid param
pDSCDriverCaps->dwFlags = 0;
pDSCDriverCaps->dwChannels = 2;
pDSCDriverCaps->dwFormats = WAVE_FORMAT_4S16| // stereo, 16 bit 44.1 khz
WAVE_FORMAT_2S16| // stereo, 16 bit 22.05 khz
WAVE_FORMAT_1S16; // stereo, 16 bit 11.025 khz
return DS_OK;
}
//////////////////////////////////////////////////////////////////////////////
/*****************************************************************************
*****************************************************************************/
//////////////////////////////////////////////////////////////////////////////
STDMETHODIMP DsCaptureDriver::GetDriverDesc(PDSDRIVERDESC pDSDriverDesc )
{
FUNCMSG("DsCaptureDriver::GetDriverDesc");
HRESULT hr = DS_OK;
// Fill out the DSDRIVERDESC structure with the appropriate information.
if(! pDSDriverDesc)
return DSERR_GENERIC; //invalid param
pDSDriverDesc->dwFlags = DSDDESC_DONTNEEDPRIMARYLOCK | DSDDESC_DONTNEEDSECONDARYLOCK;
strcpy(pDSDriverDesc->szDesc, "Windows CE CX5530 DirectSound Capture Driver");
strcpy(pDSDriverDesc->szDrvname,"IDSCX5530.DLL");
pDSDriverDesc->dnDevNode = 0;
pDSDriverDesc->wVxdId = 0;
pDSDriverDesc->wReserved = 0;
pDSDriverDesc->ulDeviceNum = 0;
pDSDriverDesc->dwHeapType = DSDHEAP_NOHEAP;
pDSDriverDesc->pvDirectDrawHeap = 0;
pDSDriverDesc->dwMemStartAddress = 0;
pDSDriverDesc->dwMemEndAddress = 0;
pDSDriverDesc->dwMemAllocExtra = 0;
pDSDriverDesc->pvReserved1 = 0;
pDSDriverDesc->pvReserved2 = 0;
return hr;
}
/*
VOID DsCaptureDriver::ProcessInterrupt()
{
UCHAR intsrc = m_pCX5530->GetInterruptSource();
//
// ACK the ISR.
//
//
// Route interrupt processing to appropriate buffer object
//
m_pCX5530->AckDMAInterrupt( ES1371_INT_ADC );
if(m_pCaptureBuffer)
m_pCaptureBuffer->ProcessInterrupt();
return;
}
*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?