dsound: Rename some functions, make some functions global, and move

some code around.
This commit is contained in:
Robert Reif 2006-01-14 17:06:52 +01:00 committed by Alexandre Julliard
parent 2d82fc42f0
commit 52e384f9fb
3 changed files with 131 additions and 109 deletions

View File

@ -364,7 +364,7 @@ static ULONG WINAPI IDirectSoundBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface)
TRACE("(%p) ref was %ld\n", This, ref + 1); TRACE("(%p) ref was %ld\n", This, ref + 1);
if (!ref) { if (!ref) {
DSOUND_RemoveBuffer(This->device, This); DirectSoundDevice_RemoveBuffer(This->device, This);
This->lock.DebugInfo->Spare[0] = 0; This->lock.DebugInfo->Spare[0] = 0;
DeleteCriticalSection(&(This->lock)); DeleteCriticalSection(&(This->lock));
@ -1158,7 +1158,7 @@ HRESULT IDirectSoundBufferImpl_Create(
/* register buffer if not primary */ /* register buffer if not primary */
if (!(dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER)) { if (!(dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER)) {
err = DSOUND_AddBuffer(device, dsb); err = DirectSoundDevice_AddBuffer(device, dsb);
if (err != DS_OK) { if (err != DS_OK) {
HeapFree(GetProcessHeap(),0,dsb->buffer->memory); HeapFree(GetProcessHeap(),0,dsb->buffer->memory);
HeapFree(GetProcessHeap(),0,dsb->buffer); HeapFree(GetProcessHeap(),0,dsb->buffer);
@ -1212,6 +1212,104 @@ HRESULT IDirectSoundBufferImpl_Destroy(
return S_OK; return S_OK;
} }
HRESULT IDirectSoundBufferImpl_Duplicate(
DirectSoundDevice *device,
IDirectSoundBufferImpl **ppdsb,
IDirectSoundBufferImpl *pdsb)
{
IDirectSoundBufferImpl *dsb;
HRESULT hres = DS_OK;
int size;
TRACE("(%p,%p,%p)\n", device, pdsb, pdsb);
dsb = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*dsb));
if (dsb == NULL) {
WARN("out of memory\n");
*ppdsb = NULL;
return DSERR_OUTOFMEMORY;
}
CopyMemory(dsb, pdsb, sizeof(IDirectSoundBufferImpl));
if (pdsb->hwbuf) {
TRACE("duplicating hardware buffer\n");
hres = IDsDriver_DuplicateSoundBuffer(device->driver, pdsb->hwbuf,
(LPVOID *)&dsb->hwbuf);
if (hres != DS_OK) {
TRACE("IDsDriver_DuplicateSoundBuffer failed, falling back to "
"software buffer\n");
dsb->hwbuf = NULL;
/* allocate buffer */
if (device->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) {
dsb->buffer = HeapAlloc(GetProcessHeap(),0,sizeof(*(dsb->buffer)));
if (dsb->buffer == NULL) {
WARN("out of memory\n");
HeapFree(GetProcessHeap(),0,dsb);
*ppdsb = NULL;
return DSERR_OUTOFMEMORY;
}
dsb->buffer->memory = HeapAlloc(GetProcessHeap(),0,dsb->buflen);
if (dsb->buffer->memory == NULL) {
WARN("out of memory\n");
HeapFree(GetProcessHeap(),0,dsb->buffer);
HeapFree(GetProcessHeap(),0,dsb);
*ppdsb = NULL;
return DSERR_OUTOFMEMORY;
}
dsb->buffer->ref = 1;
/* FIXME: copy buffer ? */
}
}
} else {
dsb->hwbuf = NULL;
dsb->buffer->ref++;
}
dsb->ref = 0;
dsb->state = STATE_STOPPED;
dsb->playpos = 0;
dsb->buf_mixpos = 0;
dsb->device = device;
dsb->ds3db = NULL;
dsb->iks = NULL; /* FIXME? */
dsb->secondary = NULL;
/* variable sized struct so calculate size based on format */
size = sizeof(WAVEFORMATEX) + pdsb->pwfx->cbSize;
dsb->pwfx = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,size);
if (dsb->pwfx == NULL) {
WARN("out of memory\n");
HeapFree(GetProcessHeap(),0,dsb->buffer);
HeapFree(GetProcessHeap(),0,dsb);
*ppdsb = NULL;
return DSERR_OUTOFMEMORY;
}
CopyMemory(dsb->pwfx, pdsb->pwfx, size);
InitializeCriticalSection(&(dsb->lock));
dsb->lock.DebugInfo->Spare[0] = (DWORD_PTR)"DSOUNDBUFFER_lock";
/* register buffer */
hres = DirectSoundDevice_AddBuffer(device, dsb);
if (hres != DS_OK) {
dsb->lock.DebugInfo->Spare[0] = 0;
DeleteCriticalSection(&(dsb->lock));
HeapFree(GetProcessHeap(),0,dsb->buffer);
HeapFree(GetProcessHeap(),0,dsb->pwfx);
HeapFree(GetProcessHeap(),0,dsb);
*ppdsb = 0;
}
*ppdsb = dsb;
return hres;
}
/******************************************************************************* /*******************************************************************************
* SecondaryBuffer * SecondaryBuffer
*/ */

View File

@ -45,10 +45,6 @@ static ULONG WINAPI IDirectSound8_IUnknown_AddRef(LPUNKNOWN iface);
static ULONG WINAPI IDirectSound8_IDirectSound_AddRef(LPDIRECTSOUND iface); static ULONG WINAPI IDirectSound8_IDirectSound_AddRef(LPDIRECTSOUND iface);
static ULONG WINAPI IDirectSound8_IDirectSound8_AddRef(LPDIRECTSOUND8 iface); static ULONG WINAPI IDirectSound8_IDirectSound8_AddRef(LPDIRECTSOUND8 iface);
static HRESULT DirectSoundDevice_Create(DirectSoundDevice ** ppDevice);
static ULONG DirectSoundDevice_AddRef(DirectSoundDevice * device);
static ULONG DirectSoundDevice_Release(DirectSoundDevice * device);
static const char * dumpCooperativeLevel(DWORD level) static const char * dumpCooperativeLevel(DWORD level)
{ {
static char unknown[32]; static char unknown[32];
@ -440,10 +436,8 @@ static HRESULT WINAPI IDirectSoundImpl_DuplicateSoundBuffer(
LPDIRECTSOUNDBUFFER psb, LPDIRECTSOUNDBUFFER psb,
LPLPDIRECTSOUNDBUFFER ppdsb) LPLPDIRECTSOUNDBUFFER ppdsb)
{ {
IDirectSoundBufferImpl* pdsb;
IDirectSoundBufferImpl* dsb; IDirectSoundBufferImpl* dsb;
HRESULT hres = DS_OK; HRESULT hres = DS_OK;
int size;
IDirectSoundImpl *This = (IDirectSoundImpl *)iface; IDirectSoundImpl *This = (IDirectSoundImpl *)iface;
TRACE("(%p,%p,%p)\n",This,psb,ppdsb); TRACE("(%p,%p,%p)\n",This,psb,ppdsb);
@ -475,90 +469,11 @@ static HRESULT WINAPI IDirectSoundImpl_DuplicateSoundBuffer(
return DSERR_INVALIDCALL; return DSERR_INVALIDCALL;
} }
pdsb = ((SecondaryBufferImpl *)psb)->dsb; /* duplicate the actual buffer implementation */
hres = IDirectSoundBufferImpl_Duplicate(This->device, &dsb,
((SecondaryBufferImpl *)psb)->dsb);
dsb = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*dsb)); if (hres == DS_OK) {
if (dsb == NULL) {
WARN("out of memory\n");
*ppdsb = NULL;
return DSERR_OUTOFMEMORY;
}
CopyMemory(dsb, pdsb, sizeof(IDirectSoundBufferImpl));
if (pdsb->hwbuf) {
TRACE("duplicating hardware buffer\n");
hres = IDsDriver_DuplicateSoundBuffer(This->device->driver, pdsb->hwbuf, (LPVOID *)&dsb->hwbuf);
if (hres != DS_OK) {
TRACE("IDsDriver_DuplicateSoundBuffer failed, falling back to software buffer\n");
dsb->hwbuf = NULL;
/* allocate buffer */
if (This->device->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) {
dsb->buffer = HeapAlloc(GetProcessHeap(),0,sizeof(*(dsb->buffer)));
if (dsb->buffer == NULL) {
WARN("out of memory\n");
HeapFree(GetProcessHeap(),0,dsb);
*ppdsb = NULL;
return DSERR_OUTOFMEMORY;
}
dsb->buffer->memory = HeapAlloc(GetProcessHeap(),0,dsb->buflen);
if (dsb->buffer->memory == NULL) {
WARN("out of memory\n");
HeapFree(GetProcessHeap(),0,dsb->buffer);
HeapFree(GetProcessHeap(),0,dsb);
*ppdsb = NULL;
return DSERR_OUTOFMEMORY;
}
dsb->buffer->ref = 1;
/* FIXME: copy buffer ? */
}
}
} else {
dsb->hwbuf = NULL;
dsb->buffer->ref++;
}
dsb->ref = 0;
dsb->state = STATE_STOPPED;
dsb->playpos = 0;
dsb->buf_mixpos = 0;
dsb->device = This->device;
dsb->ds3db = NULL;
dsb->iks = NULL; /* FIXME? */
dsb->secondary = NULL;
/* variable sized struct so calculate size based on format */
size = sizeof(WAVEFORMATEX) + pdsb->pwfx->cbSize;
dsb->pwfx = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,size);
if (dsb->pwfx == NULL) {
WARN("out of memory\n");
HeapFree(GetProcessHeap(),0,dsb->buffer);
HeapFree(GetProcessHeap(),0,dsb);
*ppdsb = NULL;
return DSERR_OUTOFMEMORY;
}
CopyMemory(dsb->pwfx, pdsb->pwfx, size);
InitializeCriticalSection(&(dsb->lock));
dsb->lock.DebugInfo->Spare[0] = (DWORD_PTR)"DSOUNDBUFFER_lock";
/* register buffer */
hres = DSOUND_AddBuffer(This->device, dsb);
if (hres != DS_OK) {
IDirectSoundBuffer8_Release(psb);
dsb->lock.DebugInfo->Spare[0] = 0;
DeleteCriticalSection(&(dsb->lock));
HeapFree(GetProcessHeap(),0,dsb->buffer);
HeapFree(GetProcessHeap(),0,dsb->pwfx);
HeapFree(GetProcessHeap(),0,dsb);
*ppdsb = 0;
} else {
hres = SecondaryBufferImpl_Create(dsb, (SecondaryBufferImpl**)ppdsb); hres = SecondaryBufferImpl_Create(dsb, (SecondaryBufferImpl**)ppdsb);
if (*ppdsb) { if (*ppdsb) {
dsb->secondary = (SecondaryBufferImpl*)*ppdsb; dsb->secondary = (SecondaryBufferImpl*)*ppdsb;
@ -867,7 +782,7 @@ static const IDirectSound8Vtbl IDirectSoundImpl_Vtbl =
IDirectSoundImpl_VerifyCertification IDirectSoundImpl_VerifyCertification
}; };
static HRESULT DirectSoundDevice_Create(DirectSoundDevice ** ppDevice) HRESULT DirectSoundDevice_Create(DirectSoundDevice ** ppDevice)
{ {
DirectSoundDevice * device; DirectSoundDevice * device;
TRACE("(%p)\n", ppDevice); TRACE("(%p)\n", ppDevice);
@ -947,14 +862,14 @@ static HRESULT DirectSoundDevice_Create(DirectSoundDevice ** ppDevice)
return DS_OK; return DS_OK;
} }
static ULONG DirectSoundDevice_AddRef(DirectSoundDevice * device) ULONG DirectSoundDevice_AddRef(DirectSoundDevice * device)
{ {
ULONG ref = InterlockedIncrement(&(device->ref)); ULONG ref = InterlockedIncrement(&(device->ref));
TRACE("(%p) ref was %ld\n", device, ref - 1); TRACE("(%p) ref was %ld\n", device, ref - 1);
return ref; return ref;
} }
static ULONG DirectSoundDevice_Release(DirectSoundDevice * device) ULONG DirectSoundDevice_Release(DirectSoundDevice * device)
{ {
HRESULT hr; HRESULT hr;
ULONG ref = InterlockedDecrement(&(device->ref)); ULONG ref = InterlockedDecrement(&(device->ref));
@ -1848,7 +1763,7 @@ HRESULT WINAPI DirectSoundCreate8(
* Add secondary buffer to buffer list. * Add secondary buffer to buffer list.
* Gets exclusive access to buffer for writing. * Gets exclusive access to buffer for writing.
*/ */
HRESULT DSOUND_AddBuffer( HRESULT DirectSoundDevice_AddBuffer(
DirectSoundDevice * device, DirectSoundDevice * device,
IDirectSoundBufferImpl * pDSB) IDirectSoundBufferImpl * pDSB)
{ {
@ -1883,7 +1798,7 @@ HRESULT DSOUND_AddBuffer(
* Remove secondary buffer from buffer list. * Remove secondary buffer from buffer list.
* Gets exclusive access to buffer for writing. * Gets exclusive access to buffer for writing.
*/ */
HRESULT DSOUND_RemoveBuffer( HRESULT DirectSoundDevice_RemoveBuffer(
DirectSoundDevice * device, DirectSoundDevice * device,
IDirectSoundBufferImpl * pDSB) IDirectSoundBufferImpl * pDSB)
{ {

View File

@ -81,6 +81,12 @@ struct IDirectSoundImpl
LPDIRECTSOUND8 pDS8; LPDIRECTSOUND8 pDS8;
}; };
HRESULT IDirectSoundImpl_Create(
LPDIRECTSOUND8 * ppds);
/*****************************************************************************
* IDirectSoundDevice implementation structure
*/
struct DirectSoundDevice struct DirectSoundDevice
{ {
LONG ref; LONG ref;
@ -122,16 +128,15 @@ typedef struct BufferMemory
LPBYTE memory; LPBYTE memory;
} BufferMemory; } BufferMemory;
HRESULT IDirectSoundImpl_Create( HRESULT DirectSoundDevice_Create(DirectSoundDevice ** ppDevice);
LPDIRECTSOUND8 * ppds); ULONG DirectSoundDevice_AddRef(DirectSoundDevice * device);
ULONG DirectSoundDevice_Release(DirectSoundDevice * device);
HRESULT DSOUND_Create( HRESULT DirectSoundDevice_AddBuffer(
LPDIRECTSOUND *ppDS, DirectSoundDevice *device,
IUnknown *pUnkOuter); IDirectSoundBufferImpl * pDSB);
HRESULT DirectSoundDevice_RemoveBuffer(
HRESULT DSOUND_Create8( DirectSoundDevice *device,
LPDIRECTSOUND8 *ppDS, IDirectSoundBufferImpl * pDSB);
IUnknown *pUnkOuter);
/***************************************************************************** /*****************************************************************************
* IDirectSound COM components * IDirectSound COM components
@ -240,6 +245,10 @@ HRESULT IDirectSoundBufferImpl_Create(
LPCDSBUFFERDESC dsbd); LPCDSBUFFERDESC dsbd);
HRESULT IDirectSoundBufferImpl_Destroy( HRESULT IDirectSoundBufferImpl_Destroy(
IDirectSoundBufferImpl *pdsb); IDirectSoundBufferImpl *pdsb);
HRESULT IDirectSoundBufferImpl_Duplicate(
DirectSoundDevice *device,
IDirectSoundBufferImpl **ppdsb,
IDirectSoundBufferImpl *pdsb);
/***************************************************************************** /*****************************************************************************
* SecondaryBuffer implementation structure * SecondaryBuffer implementation structure
@ -488,8 +497,8 @@ void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb);
/* dsound.c */ /* dsound.c */
HRESULT DSOUND_AddBuffer(DirectSoundDevice *device, IDirectSoundBufferImpl * pDSB); HRESULT DSOUND_Create(LPDIRECTSOUND *ppDS, IUnknown *pUnkOuter);
HRESULT DSOUND_RemoveBuffer(DirectSoundDevice *device, IDirectSoundBufferImpl * pDSB); HRESULT DSOUND_Create8(LPDIRECTSOUND8 *ppDS, IUnknown *pUnkOuter);
/* primary.c */ /* primary.c */