📄 dsound.c
字号:
/* The sleep above should have allowed the timer process to expire
* but try to grab the lock just in case. Can't hold lock because
* IDirectSoundBufferImpl_Destroy also grabs the lock */
RtlAcquireResourceShared(&(device->buffer_list_lock), TRUE);
RtlReleaseResource(&(device->buffer_list_lock));
/* It is allowed to release this object even when buffers are playing */
if (device->buffers) {
WARN("%d secondary buffers not released\n", device->nrofbuffers);
for( i=0;i<device->nrofbuffers;i++)
IDirectSoundBufferImpl_Destroy(device->buffers[i]);
}
if (device->primary) {
WARN("primary buffer not released\n");
IDirectSoundBuffer8_Release((LPDIRECTSOUNDBUFFER8)device->primary);
}
hr = DSOUND_PrimaryDestroy(device);
if (hr != DS_OK)
WARN("DSOUND_PrimaryDestroy failed\n");
if (device->driver)
IDsDriver_Close(device->driver);
if (device->drvdesc.dwFlags & DSDDESC_DOMMSYSTEMOPEN)
waveOutClose(device->hwo);
if (device->driver)
IDsDriver_Release(device->driver);
DSOUND_renderer[device->drvdesc.dnDevNode] = NULL;
HeapFree(GetProcessHeap(),0,device->tmp_buffer);
HeapFree(GetProcessHeap(),0,device->buffer);
RtlDeleteResource(&device->buffer_list_lock);
device->mixlock.DebugInfo->Spare[0] = 0;
DeleteCriticalSection(&device->mixlock);
HeapFree(GetProcessHeap(),0,device);
TRACE("(%p) released\n", device);
}
return device->ref;
}
HRESULT WINAPI IDirectSoundImpl_Create(
LPDIRECTSOUND8 * ppDS)
{
IDirectSoundImpl* pDS;
TRACE("(%p)\n",ppDS);
/* Allocate memory */
pDS = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirectSoundImpl));
if (pDS == NULL) {
WARN("out of memory\n");
*ppDS = NULL;
return DSERR_OUTOFMEMORY;
}
pDS->lpVtbl = &IDirectSoundImpl_Vtbl;
pDS->ref = 0;
pDS->device = NULL;
*ppDS = (LPDIRECTSOUND8)pDS;
return DS_OK;
}
/*******************************************************************************
* IDirectSound_IUnknown
*/
static HRESULT WINAPI IDirectSound_IUnknown_QueryInterface(
LPUNKNOWN iface,
REFIID riid,
LPVOID * ppobj)
{
IDirectSound_IUnknown *This = (IDirectSound_IUnknown *)iface;
TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
return DSOUND_QueryInterface(This->pds, riid, ppobj);
}
static ULONG WINAPI IDirectSound_IUnknown_AddRef(
LPUNKNOWN iface)
{
IDirectSound_IUnknown *This = (IDirectSound_IUnknown *)iface;
ULONG ref = InterlockedIncrement(&(This->ref));
TRACE("(%p) ref was %ld\n", This, ref - 1);
return ref;
}
static ULONG WINAPI IDirectSound_IUnknown_Release(
LPUNKNOWN iface)
{
IDirectSound_IUnknown *This = (IDirectSound_IUnknown *)iface;
ULONG ref = InterlockedDecrement(&(This->ref));
TRACE("(%p) ref was %ld\n", This, ref + 1);
if (!ref) {
IDirectSoundImpl_Release(This->pds);
HeapFree(GetProcessHeap(), 0, This);
TRACE("(%p) released\n", This);
}
return ref;
}
static const IUnknownVtbl DirectSound_Unknown_Vtbl =
{
IDirectSound_IUnknown_QueryInterface,
IDirectSound_IUnknown_AddRef,
IDirectSound_IUnknown_Release
};
HRESULT WINAPI IDirectSound_IUnknown_Create(
LPDIRECTSOUND8 pds,
LPUNKNOWN * ppunk)
{
IDirectSound_IUnknown * pdsunk;
TRACE("(%p,%p)\n",pds,ppunk);
if (ppunk == NULL) {
ERR("invalid parameter: ppunk == NULL\n");
return DSERR_INVALIDPARAM;
}
if (pds == NULL) {
ERR("invalid parameter: pds == NULL\n");
*ppunk = NULL;
return DSERR_INVALIDPARAM;
}
pdsunk = HeapAlloc(GetProcessHeap(),0,sizeof(*pdsunk));
if (pdsunk == NULL) {
WARN("out of memory\n");
*ppunk = NULL;
return DSERR_OUTOFMEMORY;
}
pdsunk->lpVtbl = &DirectSound_Unknown_Vtbl;
pdsunk->ref = 0;
pdsunk->pds = pds;
IDirectSoundImpl_AddRef(pds);
*ppunk = (LPUNKNOWN)pdsunk;
return DS_OK;
}
/*******************************************************************************
* IDirectSound_IDirectSound
*/
static HRESULT WINAPI IDirectSound_IDirectSound_QueryInterface(
LPDIRECTSOUND iface,
REFIID riid,
LPVOID * ppobj)
{
IDirectSound_IDirectSound *This = (IDirectSound_IDirectSound *)iface;
TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
return DSOUND_QueryInterface(This->pds, riid, ppobj);
}
static ULONG WINAPI IDirectSound_IDirectSound_AddRef(
LPDIRECTSOUND iface)
{
IDirectSound_IDirectSound *This = (IDirectSound_IDirectSound *)iface;
ULONG ref = InterlockedIncrement(&(This->ref));
TRACE("(%p) ref was %ld\n", This, ref - 1);
return ref;
}
static ULONG WINAPI IDirectSound_IDirectSound_Release(
LPDIRECTSOUND iface)
{
IDirectSound_IDirectSound *This = (IDirectSound_IDirectSound *)iface;
ULONG ref = InterlockedDecrement(&(This->ref));
TRACE("(%p) ref was %ld\n", This, ref + 1);
if (!ref) {
IDirectSoundImpl_Release(This->pds);
HeapFree(GetProcessHeap(), 0, This);
TRACE("(%p) released\n", This);
}
return ref;
}
static HRESULT WINAPI IDirectSound_IDirectSound_CreateSoundBuffer(
LPDIRECTSOUND iface,
LPCDSBUFFERDESC dsbd,
LPLPDIRECTSOUNDBUFFER ppdsb,
LPUNKNOWN lpunk)
{
IDirectSound_IDirectSound *This = (IDirectSound_IDirectSound *)iface;
TRACE("(%p,%p,%p,%p)\n",This,dsbd,ppdsb,lpunk);
return DSOUND_CreateSoundBuffer(This->pds,dsbd,ppdsb,lpunk,FALSE);
}
static HRESULT WINAPI IDirectSound_IDirectSound_GetCaps(
LPDIRECTSOUND iface,
LPDSCAPS lpDSCaps)
{
IDirectSound_IDirectSound *This = (IDirectSound_IDirectSound *)iface;
TRACE("(%p,%p)\n",This,lpDSCaps);
return IDirectSoundImpl_GetCaps(This->pds, lpDSCaps);
}
static HRESULT WINAPI IDirectSound_IDirectSound_DuplicateSoundBuffer(
LPDIRECTSOUND iface,
LPDIRECTSOUNDBUFFER psb,
LPLPDIRECTSOUNDBUFFER ppdsb)
{
IDirectSound_IDirectSound *This = (IDirectSound_IDirectSound *)iface;
TRACE("(%p,%p,%p)\n",This,psb,ppdsb);
return IDirectSoundImpl_DuplicateSoundBuffer(This->pds,psb,ppdsb);
}
static HRESULT WINAPI IDirectSound_IDirectSound_SetCooperativeLevel(
LPDIRECTSOUND iface,
HWND hwnd,
DWORD level)
{
IDirectSound_IDirectSound *This = (IDirectSound_IDirectSound *)iface;
TRACE("(%p,%p,%s)\n",This,hwnd,dumpCooperativeLevel(level));
return IDirectSoundImpl_SetCooperativeLevel(This->pds,hwnd,level);
}
static HRESULT WINAPI IDirectSound_IDirectSound_Compact(
LPDIRECTSOUND iface)
{
IDirectSound_IDirectSound *This = (IDirectSound_IDirectSound *)iface;
TRACE("(%p)\n", This);
return IDirectSoundImpl_Compact(This->pds);
}
static HRESULT WINAPI IDirectSound_IDirectSound_GetSpeakerConfig(
LPDIRECTSOUND iface,
LPDWORD lpdwSpeakerConfig)
{
IDirectSound_IDirectSound *This = (IDirectSound_IDirectSound *)iface;
TRACE("(%p, %p)\n", This, lpdwSpeakerConfig);
return IDirectSoundImpl_GetSpeakerConfig(This->pds,lpdwSpeakerConfig);
}
static HRESULT WINAPI IDirectSound_IDirectSound_SetSpeakerConfig(
LPDIRECTSOUND iface,
DWORD config)
{
IDirectSound_IDirectSound *This = (IDirectSound_IDirectSound *)iface;
TRACE("(%p,0x%08lx)\n",This,config);
return IDirectSoundImpl_SetSpeakerConfig(This->pds,config);
}
static HRESULT WINAPI IDirectSound_IDirectSound_Initialize(
LPDIRECTSOUND iface,
LPCGUID lpcGuid)
{
IDirectSound_IDirectSound *This = (IDirectSound_IDirectSound *)iface;
TRACE("(%p, %s)\n", This, debugstr_guid(lpcGuid));
return IDirectSoundImpl_Initialize(This->pds,lpcGuid);
}
static const IDirectSoundVtbl DirectSound_DirectSound_Vtbl =
{
IDirectSound_IDirectSound_QueryInterface,
IDirectSound_IDirectSound_AddRef,
IDirectSound_IDirectSound_Release,
IDirectSound_IDirectSound_CreateSoundBuffer,
IDirectSound_IDirectSound_GetCaps,
IDirectSound_IDirectSound_DuplicateSoundBuffer,
IDirectSound_IDirectSound_SetCooperativeLevel,
IDirectSound_IDirectSound_Compact,
IDirectSound_IDirectSound_GetSpeakerConfig,
IDirectSound_IDirectSound_SetSpeakerConfig,
IDirectSound_IDirectSound_Initialize
};
HRESULT WINAPI IDirectSound_IDirectSound_Create(
LPDIRECTSOUND8 pds,
LPDIRECTSOUND * ppds)
{
IDirectSound_IDirectSound * pdsds;
TRACE("(%p,%p)\n",pds,ppds);
if (ppds == NULL) {
ERR("invalid parameter: ppds == NULL\n");
return DSERR_INVALIDPARAM;
}
if (pds == NULL) {
ERR("invalid parameter: pds == NULL\n");
*ppds = NULL;
return DSERR_INVALIDPARAM;
}
pdsds = HeapAlloc(GetProcessHeap(),0,sizeof(*pdsds));
if (pdsds == NULL) {
WARN("out of memory\n");
*ppds = NULL;
return DSERR_OUTOFMEMORY;
}
pdsds->lpVtbl = &DirectSound_DirectSound_Vtbl;
pdsds->ref = 0;
pdsds->pds = pds;
IDirectSoundImpl_AddRef(pds);
*ppds = (LPDIRECTSOUND)pdsds;
return DS_OK;
}
/*******************************************************************************
* IDirectSound8_IUnknown
*/
static HRESULT WINAPI IDirectSound8_IUnknown_QueryInterface(
LPUNKNOWN iface,
REFIID riid,
LPVOID * ppobj)
{
IDirectSound_IUnknown *This = (IDirectSound_IUnknown *)iface;
TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
return DSOUND_QueryInterface8(This->pds, riid, ppobj);
}
static ULONG WINAPI IDirectSound8_IUnknown_AddRef(
LPUNKNOWN iface)
{
IDirectSound_IUnknown *This = (IDirectSound_IUnknown *)iface;
ULONG ref = InterlockedIncrement(&(This->ref));
TRACE("(%p) ref was %ld\n", This, ref - 1);
return ref;
}
static ULONG WINAPI IDirectSound8_IUnknown_Release(
LPUNKNOWN iface)
{
IDirectSound_IUnknown *This = (IDirectSound_IUnknown *)iface;
ULONG ref = InterlockedDecrement(&(This->ref));
TRACE("(%p) ref was %ld\n", This, ref + 1);
if (!ref) {
IDirectSoundImpl_Release(This->pds);
HeapFree(GetProcessHeap(), 0, This);
TRACE("(%p) released\n", This);
}
return ref;
}
static const IUnknownVtbl DirectSound8_Unknown_Vtbl =
{
IDirectSound8_IUnknown_QueryInterface,
IDirectSound8_IUnknown_AddRef,
IDirectSound8_IUnknown_Release
};
HRESULT WINAPI IDirectSound8_IUnknown_Create(
LPDIRECTSOUND8 pds,
LPUNKNOWN * ppunk)
{
IDirectSound8_IUnknown * pdsunk;
TRACE("(%p,%p)\n",pds,ppunk);
if (ppunk == NULL) {
ERR("invalid parameter: ppunk == NULL\n");
return DSERR_INVALIDPARAM;
}
if (pds == NULL) {
ERR("invalid parameter: pds == NULL\n");
*ppunk = NULL;
return DSERR_INVALIDPARAM;
}
pdsunk = HeapAlloc(GetProcessHeap(),0,sizeof(*pdsunk));
if (pdsunk == NULL) {
WARN("out of memory\n");
*ppunk = NULL;
return DSERR_OUTOFMEMORY;
}
pdsunk->lpVtbl = &DirectSound8_Unknown_Vtbl;
pdsunk->ref = 0;
pdsunk->pds = pds;
IDirectSoundImpl_AddRef(pds);
*ppunk = (LPUNKNOWN)pdsunk;
return DS_OK;
}
/*******************************************************************************
* IDirectSound8_IDirectSound
*/
static HRESULT WINAPI IDirectSound8_IDirectSound_QueryInterface(
LPDIRECTSOUND iface,
REFIID riid,
LPVOID * ppobj)
{
IDirectSound8_IDirectSound *This = (IDirectSound8_IDirectSound *)iface;
TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
return DSOUND_QueryInterface8(This->pds, riid, ppobj);
}
static ULONG WINAPI IDirectSound8_IDirectSound_AddRef(
LPDIRECTSOUND iface)
{
IDirectSound8_IDirectSound *This = (IDirectSound8_IDirectSound *)iface;
ULONG ref = InterlockedIncrement(&(This->ref));
TRACE("(%p) ref was %ld\n", This, ref - 1);
return ref;
}
static ULONG WINAPI IDirectSound8_IDirectSound_Release(
LPDIRECTSOUND iface)
{
IDirectSound8_IDirectSound *This = (IDirectSound8_IDirectSound *)iface;
ULONG ref = InterlockedDecrement(&(This->ref));
TRACE("(%p) ref was %ld\n", This, ref + 1);
if (!ref) {
IDirectSoundImpl_Release(This->pds);
HeapFree(GetProcessHeap(), 0, This);
TRACE("(%p) released\n", This);
}
return ref;
}
static HRESULT WINAPI IDirectSound8_IDirectSound_CreateSoundBuffer(
LPDIRECTSOUND iface,
LPCDSBUFFERDESC dsbd,
LPLPDIRECTSOUNDBUFFER ppdsb,
LPUNKNOWN lpunk)
{
IDirectSound8_IDirectSound *This = (IDirectSound8_IDirectSound *)iface;
TRACE("(%p,%p,%p,%p)\n",This,dsbd,ppdsb,lpunk);
return DSOUND_CreateSoundBuffer(This->pds,dsbd,ppdsb,lpunk,TRUE);
}
static HRESULT WINAPI IDirectSound8_IDirectSound_GetCaps(
LPDIRECTSOUND iface,
LPDSCAPS lpDSCaps)
{
IDirectSound8_IDirectSound *This = (IDirectSound8_IDirectSound *)iface;
TRACE("(%p,%p)\n",This,lpDSCaps);
return IDirectSoundImpl_GetCaps(This->pds, lpDSCaps);
}
static HRESULT WINAPI IDirectSound8_IDirectSound_DuplicateSoundBuffer(
LPDIRECTSOUND iface,
LPDIRECTSOUNDBUFFER psb,
LPLPDIRECTSOUNDBUFFER ppdsb)
{
IDirectSound8_IDirectSound *This = (IDirectSound8_IDirectSound *)iface;
TRACE("(%p,%p,%p)\n",This,psb,ppdsb);
return IDirectSoundImpl_DuplicateSoundBuffer(This->pds,psb,ppdsb);
}
static HRESULT WINAPI IDirectSound8_IDirectSound_SetCooperativeLevel(
LPDIRECTSOUND iface,
HWND hwnd,
DWORD level)
{
IDirectSound8_IDirectSound *This = (IDirectSound8_IDirectSound *)iface;
TRACE("(%p,%p,%s)\n",This,hwnd,dumpCooperativeLevel(level));
return IDirectSoundImpl_SetCooperativeLevel(This->pds,hwnd,level);
}
static HRESULT WINAPI IDirectSound8_IDirectSound_Compact(
LPDIRECTSOUND iface)
{
IDirectSound8_IDirectSound *This = (IDirectSound8_IDirectSound *)iface;
TRACE("(%p)\n", This);
return IDirectSoundImpl_Compact(This->pds);
}
static HRESULT WINAPI IDirectSound8_IDirectSound_GetSpeakerConfig(
LPDIRECTSOUND iface,
LPDWORD lpdwSpeakerConfig)
{
IDirectSound8_IDirectSound *This = (IDirectSound8_IDirectSound *)iface;
TRACE("(%p, %p)\n", This, lpdwSpeakerConfig);
return IDirectSoundImpl_GetSpeakerConfig(This->pds,lpdwSpeakerConfig);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -