- make parameter checking and error notification consistent

- propagate driver and local function errors where needed
- fix error returns where pointer is given for returned data
- add 3d listener to primary buffer when needed
- copy 3d part of buffer when duplicated
- fix bug when primary buffer is reopened with smaller buffer
- loosen requirements on caps data size check
- set caps for emulated mode based on actual driver caps
This commit is contained in:
Robert Reif 2003-05-22 03:39:13 +00:00 committed by Alexandre Julliard
parent a4d733ae5a
commit a4ed8e7740
7 changed files with 800 additions and 260 deletions

View File

@ -106,8 +106,8 @@ static HRESULT WINAPI IDirectSoundNotifyImpl_SetNotificationPositions(
ICOM_THIS(IDirectSoundNotifyImpl,iface);
TRACE("(%p,0x%08lx,%p)\n",This,howmuch,notify);
if (!notify) {
WARN("invalid parameter\n");
if (notify == NULL) {
WARN("invalid parameter: notify == NULL\n");
return DSERR_INVALIDPARAM;
}
@ -119,13 +119,20 @@ static HRESULT WINAPI IDirectSoundNotifyImpl_SetNotificationPositions(
}
if (This->hwnotify) {
return IDsDriverNotify_SetNotificationPositions(This->hwnotify, howmuch, notify);
}
else {
HRESULT hres;
hres = IDsDriverNotify_SetNotificationPositions(This->hwnotify, howmuch, notify);
if (hres != DS_OK)
WARN("IDsDriverNotify_SetNotificationPositions failed\n");
return hres;
} else {
/* Make an internal copy of the caller-supplied array.
* Replace the existing copy if one is already present. */
This->notifies = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
This->notifies, howmuch * sizeof(DSBPOSITIONNOTIFY));
if (This->notifies == NULL) {
WARN("out of memory\n");
return DSERR_OUTOFMEMORY;
}
memcpy(This->notifies, notify, howmuch * sizeof(DSBPOSITIONNOTIFY));
This->nrofnotifies = howmuch;
}
@ -153,6 +160,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_SetFormat(
TRACE("(%p,%p)\n",This,wfex);
/* This method is not available on secondary buffers */
WARN("invalid call\n");
return DSERR_INVALIDCALL;
}
@ -164,11 +172,15 @@ static HRESULT WINAPI IDirectSoundBufferImpl_SetVolume(
TRACE("(%p,%ld)\n",This,vol);
if (!(This->dsbd.dwFlags & DSBCAPS_CTRLVOLUME))
if (!(This->dsbd.dwFlags & DSBCAPS_CTRLVOLUME)) {
WARN("control unavailable: This->dsbd.dwFlags = 0x%08lx\n", This->dsbd.dwFlags);
return DSERR_CONTROLUNAVAIL;
}
if ((vol > DSBVOLUME_MAX) || (vol < DSBVOLUME_MIN))
if ((vol > DSBVOLUME_MAX) || (vol < DSBVOLUME_MIN)) {
WARN("invalid parameter: vol = %ld\n", vol);
return DSERR_INVALIDPARAM;
}
/* **** */
EnterCriticalSection(&(This->lock));
@ -179,14 +191,18 @@ static HRESULT WINAPI IDirectSoundBufferImpl_SetVolume(
} else {
oldVol = This->volpan.lVolume;
This->volpan.lVolume = vol;
if (vol != oldVol) DSOUND_RecalcVolPan(&(This->volpan));
if (vol != oldVol)
DSOUND_RecalcVolPan(&(This->volpan));
}
if (vol != oldVol) {
if (This->hwbuf) {
IDsDriverBuffer_SetVolumePan(This->hwbuf, &(This->volpan));
}
else DSOUND_ForceRemix(This);
HRESULT hres;
hres = IDsDriverBuffer_SetVolumePan(This->hwbuf, &(This->volpan));
if (hres != DS_OK)
WARN("IDsDriverBuffer_SetVolumePan failed\n");
} else
DSOUND_ForceRemix(This);
}
LeaveCriticalSection(&(This->lock));
@ -201,8 +217,10 @@ static HRESULT WINAPI IDirectSoundBufferImpl_GetVolume(
ICOM_THIS(IDirectSoundBufferImpl,iface);
TRACE("(%p,%p)\n",This,vol);
if (vol == NULL)
if (vol == NULL) {
WARN("invalid parameter: vol == NULL\n");
return DSERR_INVALIDPARAM;
}
if (This->dsbd.dwFlags & DSBCAPS_CTRL3D)
*vol = This->ds3db->lVolume;
@ -219,14 +237,18 @@ static HRESULT WINAPI IDirectSoundBufferImpl_SetFrequency(
TRACE("(%p,%ld)\n",This,freq);
if (!(This->dsbd.dwFlags & DSBCAPS_CTRLFREQUENCY))
if (!(This->dsbd.dwFlags & DSBCAPS_CTRLFREQUENCY)) {
WARN("control unavailable\n");
return DSERR_CONTROLUNAVAIL;
}
if (freq == DSBFREQUENCY_ORIGINAL)
freq = This->wfx.nSamplesPerSec;
if ((freq < DSBFREQUENCY_MIN) || (freq > DSBFREQUENCY_MAX))
if ((freq < DSBFREQUENCY_MIN) || (freq > DSBFREQUENCY_MAX)) {
WARN("invalid parameter: freq = %ld\n", freq);
return DSERR_INVALIDPARAM;
}
/* **** */
EnterCriticalSection(&(This->lock));
@ -237,7 +259,8 @@ static HRESULT WINAPI IDirectSoundBufferImpl_SetFrequency(
This->freqAdjust = (freq << DSOUND_FREQSHIFT) / This->dsound->wfx.nSamplesPerSec;
This->nAvgBytesPerSec = freq * This->wfx.nBlockAlign;
DSOUND_RecalcFormat(This);
if (!This->hwbuf) DSOUND_ForceRemix(This);
if (!This->hwbuf)
DSOUND_ForceRemix(This);
}
LeaveCriticalSection(&(This->lock));
@ -249,10 +272,9 @@ static HRESULT WINAPI IDirectSoundBufferImpl_SetFrequency(
static HRESULT WINAPI IDirectSoundBufferImpl_Play(
LPDIRECTSOUNDBUFFER8 iface,DWORD reserved1,DWORD reserved2,DWORD flags
) {
HRESULT hres = DS_OK;
ICOM_THIS(IDirectSoundBufferImpl,iface);
TRACE("(%p,%08lx,%08lx,%08lx)\n",
This,reserved1,reserved2,flags
);
TRACE("(%p,%08lx,%08lx,%08lx)\n",This,reserved1,reserved2,flags);
/* **** */
EnterCriticalSection(&(This->lock));
@ -265,18 +287,22 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Play(
} else if (This->state == STATE_STOPPING)
This->state = STATE_PLAYING;
if (This->hwbuf) {
IDsDriverBuffer_Play(This->hwbuf, 0, 0, This->playflags);
This->state = STATE_PLAYING;
hres = IDsDriverBuffer_Play(This->hwbuf, 0, 0, This->playflags);
if (hres != DS_OK)
WARN("IDsDriverBuffer_Play failed\n");
else
This->state = STATE_PLAYING;
}
LeaveCriticalSection(&(This->lock));
/* **** */
return DS_OK;
return hres;
}
static HRESULT WINAPI IDirectSoundBufferImpl_Stop(LPDIRECTSOUNDBUFFER8 iface)
{
HRESULT hres = DS_OK;
ICOM_THIS(IDirectSoundBufferImpl,iface);
TRACE("(%p)\n",This);
@ -288,15 +314,18 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Stop(LPDIRECTSOUNDBUFFER8 iface)
else if (This->state == STATE_STARTING)
This->state = STATE_STOPPED;
if (This->hwbuf) {
IDsDriverBuffer_Stop(This->hwbuf);
This->state = STATE_STOPPED;
hres = IDsDriverBuffer_Stop(This->hwbuf);
if (hres != DS_OK)
WARN("IDsDriverBuffer_Stop failed\n");
else
This->state = STATE_STOPPED;
}
DSOUND_CheckEvent(This, 0);
LeaveCriticalSection(&(This->lock));
/* **** */
return DS_OK;
return hres;
}
static DWORD WINAPI IDirectSoundBufferImpl_AddRef(LPDIRECTSOUNDBUFFER8 iface) {
@ -345,8 +374,11 @@ static DWORD WINAPI IDirectSoundBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface) {
else if (!This->parent)
HeapFree(GetProcessHeap(),0,This->buffer);
if (This->ds3db) {
DeleteCriticalSection(&This->ds3db->lock);
HeapFree(GetProcessHeap(), 0, This->ds3db);
IDirectSound3DBuffer_Release((LPDIRECTSOUND3DBUFFER)This->ds3db);
}
if (This->dsound->listener) {
if (IDirectSound3DListener_Release((LPDIRECTSOUND3DLISTENER)This->dsound->listener) == 0)
This->dsound->listener = 0;
}
if (This->iks) {
HeapFree(GetProcessHeap(), 0, This->iks);
@ -418,8 +450,10 @@ static HRESULT WINAPI IDirectSoundBufferImpl_GetCurrentPosition(
TRACE("(%p,%p,%p)\n",This,playpos,writepos);
if (This->hwbuf) {
hres=IDsDriverBuffer_GetPosition(This->hwbuf,playpos,writepos);
if (hres)
if (hres != DS_OK) {
WARN("IDsDriverBuffer_GetPosition failed\n");
return hres;
}
}
else {
if (playpos && (This->state != STATE_PLAYING)) {
@ -430,7 +464,8 @@ static HRESULT WINAPI IDirectSoundBufferImpl_GetCurrentPosition(
DWORD pplay, pwrite, lplay, splay, pstate;
/* let's get this exact; first, recursively call GetPosition on the primary */
EnterCriticalSection(&(This->dsound->mixlock));
DSOUND_PrimaryGetPosition(This->dsound, &pplay, &pwrite);
if (DSOUND_PrimaryGetPosition(This->dsound, &pplay, &pwrite) != DS_OK)
WARN("DSOUND_PrimaryGetPosition failed\n");
/* detect HEL mode underrun */
pstate = This->dsound->state;
if (!(This->dsound->hwbuf || This->dsound->pwqueue)) {
@ -481,8 +516,10 @@ static HRESULT WINAPI IDirectSoundBufferImpl_GetStatus(
ICOM_THIS(IDirectSoundBufferImpl,iface);
TRACE("(%p,%p), thread is %04lx\n",This,status,GetCurrentThreadId());
if (status == NULL)
if (status == NULL) {
WARN("invalid parameter: status = NULL\n");
return DSERR_INVALIDPARAM;
}
*status = 0;
if ((This->state == STATE_STARTING) || (This->state == STATE_PLAYING)) {
@ -508,11 +545,14 @@ static HRESULT WINAPI IDirectSoundBufferImpl_GetFormat(
memcpy(lpwf,&(This->wfx),wfsize);
if (wfwritten)
*wfwritten = wfsize;
} else
} else {
if (wfwritten)
*wfwritten = sizeof(This->wfx);
else
else {
WARN("invalid parameter: wfwritten == NULL\n");
return DSERR_INVALIDPARAM;
}
}
return DS_OK;
}
@ -520,6 +560,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_GetFormat(
static HRESULT WINAPI IDirectSoundBufferImpl_Lock(
LPDIRECTSOUNDBUFFER8 iface,DWORD writecursor,DWORD writebytes,LPVOID lplpaudioptr1,LPDWORD audiobytes1,LPVOID lplpaudioptr2,LPDWORD audiobytes2,DWORD flags
) {
HRESULT hres = DS_OK;
ICOM_THIS(IDirectSoundBufferImpl,iface);
TRACE("(%p,%ld,%ld,%p,%p,%p,%p,0x%08lx) at %ld\n",
@ -537,7 +578,11 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Lock(
if (flags & DSBLOCK_FROMWRITECURSOR) {
DWORD writepos;
/* GetCurrentPosition does too much magic to duplicate here */
IDirectSoundBufferImpl_GetCurrentPosition(iface, NULL, &writepos);
hres = IDirectSoundBufferImpl_GetCurrentPosition(iface, NULL, &writepos);
if (hres != DS_OK) {
WARN("IDirectSoundBufferImpl_GetCurrentPosition failed\n");
return hres;
}
writecursor += writepos;
}
while (writecursor >= This->buflen)
@ -564,13 +609,17 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Lock(
This->probably_valid_to = writecursor;
if (!(This->dsound->drvdesc.dwFlags & DSDDESC_DONTNEEDSECONDARYLOCK) && This->hwbuf) {
IDsDriverBuffer_Lock(This->hwbuf,
hres = IDsDriverBuffer_Lock(This->hwbuf,
lplpaudioptr1, audiobytes1,
lplpaudioptr2, audiobytes2,
writecursor, writebytes,
0);
}
else {
if (hres != DS_OK) {
WARN("IDsDriverBuffer_Lock failed\n");
LeaveCriticalSection(&(This->lock));
return hres;
}
} else {
BOOL remix = FALSE;
if (writecursor+writebytes <= This->buflen) {
*(LPBYTE*)lplpaudioptr1 = This->buffer+writecursor;
@ -618,6 +667,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Lock(
static HRESULT WINAPI IDirectSoundBufferImpl_SetCurrentPosition(
LPDIRECTSOUNDBUFFER8 iface,DWORD newpos
) {
HRESULT hres = DS_OK;
ICOM_THIS(IDirectSoundBufferImpl,iface);
TRACE("(%p,%ld)\n",This,newpos);
@ -627,30 +677,38 @@ static HRESULT WINAPI IDirectSoundBufferImpl_SetCurrentPosition(
while (newpos >= This->buflen)
newpos -= This->buflen;
This->buf_mixpos = newpos;
if (This->hwbuf)
IDsDriverBuffer_SetPosition(This->hwbuf, This->buf_mixpos);
if (This->hwbuf) {
hres = IDsDriverBuffer_SetPosition(This->hwbuf, This->buf_mixpos);
if (hres != DS_OK)
WARN("IDsDriverBuffer_SetPosition failed\n");
}
LeaveCriticalSection(&(This->lock));
/* **** */
return DS_OK;
return hres;
}
static HRESULT WINAPI IDirectSoundBufferImpl_SetPan(
LPDIRECTSOUNDBUFFER8 iface,LONG pan
) {
HRESULT hres = DS_OK;
ICOM_THIS(IDirectSoundBufferImpl,iface);
LONG oldPan;
TRACE("(%p,%ld)\n",This,pan);
if ((pan > DSBPAN_RIGHT) || (pan < DSBPAN_LEFT))
if ((pan > DSBPAN_RIGHT) || (pan < DSBPAN_LEFT)) {
WARN("invalid parameter: pan = %ld\n", pan);
return DSERR_INVALIDPARAM;
}
/* You cannot use both pan and 3D controls */
if (!(This->dsbd.dwFlags & DSBCAPS_CTRLPAN) ||
(This->dsbd.dwFlags & DSBCAPS_CTRL3D))
(This->dsbd.dwFlags & DSBCAPS_CTRL3D)) {
WARN("control unavailable\n");
return DSERR_CONTROLUNAVAIL;
}
/* **** */
EnterCriticalSection(&(This->lock));
@ -662,15 +720,17 @@ static HRESULT WINAPI IDirectSoundBufferImpl_SetPan(
DSOUND_RecalcVolPan(&(This->volpan));
if (This->hwbuf) {
IDsDriverBuffer_SetVolumePan(This->hwbuf, &(This->volpan));
}
else DSOUND_ForceRemix(This);
hres = IDsDriverBuffer_SetVolumePan(This->hwbuf, &(This->volpan));
if (hres != DS_OK)
WARN("IDsDriverBuffer_SetVolumePan failed\n");
} else
DSOUND_ForceRemix(This);
}
LeaveCriticalSection(&(This->lock));
/* **** */
return DS_OK;
return hres;
}
static HRESULT WINAPI IDirectSoundBufferImpl_GetPan(
@ -679,8 +739,10 @@ static HRESULT WINAPI IDirectSoundBufferImpl_GetPan(
ICOM_THIS(IDirectSoundBufferImpl,iface);
TRACE("(%p,%p)\n",This,pan);
if (pan == NULL)
if (pan == NULL) {
WARN("invalid parameter: pan = NULL\n");
return DSERR_INVALIDPARAM;
}
*pan = This->volpan.lPan;
@ -704,7 +766,12 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Unlock(
#endif
if (!(This->dsound->drvdesc.dwFlags & DSDDESC_DONTNEEDSECONDARYLOCK) && This->hwbuf) {
IDsDriverBuffer_Unlock(This->hwbuf, p1, x1, p2, x2);
HRESULT hres;
hres = IDsDriverBuffer_Unlock(This->hwbuf, p1, x1, p2, x2);
if (hres != DS_OK) {
WARN("IDsDriverBuffer_Unlock failed\n");
return hres;
}
}
if (p2) probably_valid_to = (((LPBYTE)p2)-This->buffer) + x2;
@ -735,8 +802,10 @@ static HRESULT WINAPI IDirectSoundBufferImpl_GetFrequency(
ICOM_THIS(IDirectSoundBufferImpl,iface);
TRACE("(%p,%p)\n",This,freq);
if (freq == NULL)
if (freq == NULL) {
WARN("invalid parameter: freq = NULL\n");
return DSERR_INVALIDPARAM;
}
*freq = This->freq;
TRACE("-> %ld\n", *freq);
@ -755,6 +824,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_SetFX(
if (pdwResultCodes)
for (u=0; u<dwEffectsCount; u++) pdwResultCodes[u] = DSFXR_UNKNOWN;
WARN("control unavailable\n");
return DSERR_CONTROLUNAVAIL;
}
@ -769,6 +839,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_AcquireResources(
if (pdwResultCodes)
for (u=0; u<dwEffectsCount; u++) pdwResultCodes[u] = DSFXR_UNKNOWN;
WARN("control unavailable\n");
return DSERR_CONTROLUNAVAIL;
}
@ -779,6 +850,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_GetObjectInPath(
FIXME("(%p,%s,%lu,%s,%p): stub\n",This,debugstr_guid(rguidObject),dwIndex,debugstr_guid(rguidInterface),ppObject);
WARN("control unavailable\n");
return DSERR_CONTROLUNAVAIL;
}
@ -788,6 +860,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Initialize(
ICOM_THIS(IDirectSoundBufferImpl,iface);
FIXME("(%p,%p,%p):stub\n",This,dsound,dbsd);
DPRINTF("Re-Init!!!\n");
WARN("already initialized\n");
return DSERR_ALREADYINITIALIZED;
}
@ -797,8 +870,15 @@ static HRESULT WINAPI IDirectSoundBufferImpl_GetCaps(
ICOM_THIS(IDirectSoundBufferImpl,iface);
TRACE("(%p)->(%p)\n",This,caps);
if (caps == NULL || caps->dwSize!=sizeof(*caps))
if (caps == NULL) {
WARN("invalid parameter: caps == NULL\n");
return DSERR_INVALIDPARAM;
}
if (caps->dwSize < sizeof(*caps)) {
WARN("invalid parameter: caps->dwSize = %ld < %d\n",caps->dwSize, sizeof(*caps));
return DSERR_INVALIDPARAM;
}
caps->dwFlags = This->dsbd.dwFlags;
if (This->hwbuf) caps->dwFlags |= DSBCAPS_LOCHARDWARE;
@ -839,6 +919,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_QueryInterface(
return S_OK;
}
*ppobj = NULL;
WARN("IID_IDirectSoundNotify\n");
return E_FAIL;
}
@ -851,6 +932,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_QueryInterface(
return S_OK;
}
*ppobj = NULL;
WARN("IID_IDirectSound3DBuffer\n");
return E_FAIL;
}
@ -869,6 +951,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_QueryInterface(
return S_OK;
}
*ppobj = NULL;
WARN("IID_IKsPropertySet\n");
return E_FAIL;
}
@ -926,11 +1009,18 @@ HRESULT WINAPI SecondaryBuffer_Create(
int use_hw;
if (dsbd->dwBufferBytes < DSBSIZE_MIN || dsbd->dwBufferBytes > DSBSIZE_MAX) {
ERR("invalid sound buffer size %ld\n", dsbd->dwBufferBytes);
ERR("invalid parameter: dsbd->dwBufferBytes = %ld\n", dsbd->dwBufferBytes);
*pdsb = NULL;
return DSERR_INVALIDPARAM; /* FIXME: which error? */
}
dsb = (IDirectSoundBufferImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*dsb));
if (dsb == 0) {
WARN("out of memory\n");
*pdsb = NULL;
return DSERR_OUTOFMEMORY;
}
dsb->ref = 1;
dsb->dsound = This;
dsb->parent = NULL;
@ -960,24 +1050,29 @@ HRESULT WINAPI SecondaryBuffer_Create(
/* Allocate system memory if applicable */
if ((This->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) || !use_hw) {
dsb->buffer = (LPBYTE)HeapAlloc(GetProcessHeap(),0,dsb->buflen);
if (dsb->buffer == NULL)
err = DSERR_OUTOFMEMORY;
if (dsb->buffer == NULL) {
WARN("out of memory\n");
HeapFree(GetProcessHeap(),0,dsb);
*pdsb = NULL;
return DSERR_OUTOFMEMORY;
}
}
/* Allocate the hardware buffer */
if (use_hw && (err == DS_OK)) {
if (use_hw) {
err = IDsDriver_CreateSoundBuffer(This->driver,wfex,dsbd->dwFlags,0,
&(dsb->buflen),&(dsb->buffer),
(LPVOID*)&(dsb->hwbuf));
if (err != DS_OK) {
WARN("IDsDriver_CreateSoundBuffer failed\n");
if (dsb->buffer)
HeapFree(GetProcessHeap(),0,dsb->buffer);
HeapFree(GetProcessHeap(),0,dsb);
*pdsb = NULL;
return err;
}
}
if (err != DS_OK) {
if (dsb->buffer)
HeapFree(GetProcessHeap(),0,dsb->buffer);
HeapFree(GetProcessHeap(),0,dsb);
dsb = NULL;
return err;
}
/* calculate fragment size and write lead */
DSOUND_RecalcFormat(dsb);
@ -993,9 +1088,16 @@ HRESULT WINAPI SecondaryBuffer_Create(
dsbd->lpwfxFormat->nBlockAlign;
if (dsbd->dwFlags & DSBCAPS_CTRL3D) {
IDirectSound3DBufferImpl_Create(dsb, &dsb->ds3db);
}
else
err = IDirectSound3DBufferImpl_Create(dsb, &dsb->ds3db);
if (err != DS_OK) {
WARN("IDirectSound3DBufferImpl_Create failed\n");
if (dsb->buffer)
HeapFree(GetProcessHeap(),0,dsb->buffer);
HeapFree(GetProcessHeap(),0,dsb);
dsb = NULL;
return err;
}
} else
DSOUND_RecalcVolPan(&(dsb->volpan));
InitializeCriticalSection(&(dsb->lock));
@ -1011,19 +1113,17 @@ HRESULT WINAPI SecondaryBuffer_Create(
TRACE("buffer count is now %d\n", This->nrofbuffers);
} else {
ERR("out of memory for buffer list! Current buffer count is %d\n", This->nrofbuffers);
err = DSERR_OUTOFMEMORY;
if (dsb->buffer)
HeapFree(GetProcessHeap(),0,dsb->buffer);
DeleteCriticalSection(&(dsb->lock));
RtlReleaseResource(&(This->lock));
HeapFree(GetProcessHeap(),0,dsb);
dsb = NULL;
return DSERR_OUTOFMEMORY;
}
}
RtlReleaseResource(&(This->lock));
IDirectSound8_AddRef((LPDIRECTSOUND8)This);
if (err != DS_OK) {
/* oops... */
IDirectSoundBuffer8_Release((LPDIRECTSOUNDBUFFER8)dsb);
*pdsb = NULL;
return err;
}
*pdsb = dsb;
return S_OK;
}

View File

@ -128,11 +128,9 @@ DirectSoundCaptureCreate8(
HEAP_ZERO_MEMORY, sizeof(IDirectSoundCaptureImpl));
if (*ippDSC == NULL) {
TRACE("couldn't allocate memory\n");
WARN("out of memory\n");
return DSERR_OUTOFMEMORY;
}
else
{
} else {
ICOM_THIS(IDirectSoundCaptureImpl, *ippDSC);
This->ref = 1;
@ -143,10 +141,15 @@ DirectSoundCaptureCreate8(
This->lpVtbl = &dscvt;
dsound_capture = This;
if (GetDeviceID(lpcGUID, &This->guid) == DS_OK)
return IDirectSoundCaptureImpl_Initialize( (LPDIRECTSOUNDCAPTURE)This, &This->guid);
if (GetDeviceID(lpcGUID, &This->guid) == DS_OK) {
HRESULT hres;
hres = IDirectSoundCaptureImpl_Initialize( (LPDIRECTSOUNDCAPTURE)This, &This->guid);
if (hres != DS_OK)
WARN("IDirectSoundCaptureImpl_Initialize failed\n");
return hres;
}
}
WARN("invalid GUID\n");
WARN("invalid GUID: %s\n", debugstr_guid(lpcGUID));
return DSERR_INVALIDPARAM;
}
@ -350,9 +353,15 @@ IDirectSoundCaptureImpl_QueryInterface(
ICOM_THIS(IDirectSoundCaptureImpl,iface);
TRACE( "(%p,%s,%p)\n", This, debugstr_guid(riid), ppobj );
if (This->driver)
return IDsCaptureDriver_QueryInterface(This->driver, riid, ppobj);
if (This->driver) {
HRESULT hres;
hres = IDsCaptureDriver_QueryInterface(This->driver, riid, ppobj);
if (hres != DS_OK)
WARN("IDsCaptureDriver_QueryInterface failed\n");
return hres;
}
WARN("unsupported riid: %s\n", debugstr_guid(riid));
return E_FAIL;
}
@ -420,21 +429,38 @@ IDirectSoundCaptureImpl_CreateCaptureBuffer(
TRACE( "(%p,%p,%p,%p)\n",This,lpcDSCBufferDesc,lplpDSCaptureBuffer,pUnk );
if ( (This == NULL) || (lpcDSCBufferDesc== NULL) ||
(lplpDSCaptureBuffer == NULL) || pUnk ) {
WARN("invalid parameters\n");
if (This == NULL) {
WARN("invalid parameter: This == NULL\n");
return DSERR_INVALIDPARAM;
}
if (lpcDSCBufferDesc == NULL) {
WARN("invalid parameter: lpcDSCBufferDesc == NULL)\n");
return DSERR_INVALIDPARAM;
}
if (lplpDSCaptureBuffer == NULL) {
WARN("invalid parameter: lplpDSCaptureBuffer == NULL\n");
return DSERR_INVALIDPARAM;
}
if (pUnk != NULL) {
WARN("invalid parameter: pUnk != NULL\n");
return DSERR_INVALIDPARAM;
}
/* FIXME: We can only have one buffer so what do we do here? */
if (This->capture_buffer) {
WARN("already has buffer\n");
WARN("lnvalid parameter: already has buffer\n");
return DSERR_INVALIDPARAM; /* DSERR_GENERIC ? */
}
hr = DSOUND_CreateDirectSoundCaptureBuffer( This, lpcDSCBufferDesc,
(LPVOID*)lplpDSCaptureBuffer );
if (hr != DS_OK)
WARN("DSOUND_CreateDirectSoundCaptureBuffer failed\n");
return hr;
}
@ -446,8 +472,14 @@ IDirectSoundCaptureImpl_GetCaps(
ICOM_THIS(IDirectSoundCaptureImpl,iface);
TRACE("(%p,%p)\n",This,lpDSCCaps);
if ( (lpDSCCaps== NULL) || (lpDSCCaps->dwSize != sizeof(*lpDSCCaps)) ) {
WARN("invalid parameters\n");
if (lpDSCCaps== NULL) {
WARN("invalid parameter: lpDSCCaps== NULL\n");
return DSERR_INVALIDPARAM;
}
if (lpDSCCaps->dwSize < sizeof(*lpDSCCaps)) {
WARN("invalid parameter: lpDSCCaps->dwSize = %ld < %d\n",
lpDSCCaps->dwSize, sizeof(*lpDSCCaps));
return DSERR_INVALIDPARAM;
}
@ -477,7 +509,7 @@ IDirectSoundCaptureImpl_Initialize(
TRACE("(%p)\n", This);
if (!This) {
WARN("invalid parameter\n");
WARN("invalid parameter: This == NULL\n");
return DSERR_INVALIDPARAM;
}
@ -600,8 +632,18 @@ DSOUND_CreateDirectSoundCaptureBuffer(
LPWAVEFORMATEX wfex;
TRACE( "(%p,%p)\n", lpcDSCBufferDesc, ppobj );
if ( (ipDSC == NULL) || (lpcDSCBufferDesc == NULL) || (ppobj == NULL) ) {
WARN("invalid parameters\n");
if (ipDSC == NULL) {
WARN("invalid parameter: ipDSC == NULL\n");
return DSERR_INVALIDPARAM;
}
if (lpcDSCBufferDesc == NULL) {
WARN("invalid parameter: lpcDSCBufferDesc == NULL\n");
return DSERR_INVALIDPARAM;
}
if (ppobj == NULL) {
WARN("invalid parameter: ppobj == NULL\n");
return DSERR_INVALIDPARAM;
}
@ -609,11 +651,13 @@ DSOUND_CreateDirectSoundCaptureBuffer(
(lpcDSCBufferDesc->dwBufferBytes == 0) ||
(lpcDSCBufferDesc->lpwfxFormat == NULL) ) {
WARN("invalid lpcDSCBufferDesc\n");
*ppobj = NULL;
return DSERR_INVALIDPARAM;
}
if ( !ipDSC->initialized ) {
WARN("not initialized\n");
*ppobj = NULL;
return DSERR_UNINITIALIZED;
}
@ -630,10 +674,12 @@ DSOUND_CreateDirectSoundCaptureBuffer(
memcpy(&(ipDSC->wfx), wfex, sizeof(WAVEFORMATEX));
else {
WARN("non PCM formats not supported\n");
*ppobj = NULL;
return DSERR_BADFORMAT;
}
} else {
WARN("lpcDSCBufferDesc->lpwfxFormat == 0\n");
*ppobj = NULL;
return DSERR_INVALIDPARAM; /* FIXME: DSERR_BADFORMAT ? */
}
@ -642,6 +688,7 @@ DSOUND_CreateDirectSoundCaptureBuffer(
if ( *ppobj == NULL ) {
WARN("out of memory\n");
*ppobj = NULL;
return DSERR_OUTOFMEMORY;
} else {
HRESULT err = DS_OK;
@ -749,6 +796,7 @@ IDirectSoundCaptureBufferImpl_QueryInterface(
}
*ppobj = 0;
WARN("IID_IDirectSoundNotify\n");
return E_FAIL;
}
@ -843,13 +891,24 @@ IDirectSoundCaptureBufferImpl_GetCaps(
ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
TRACE( "(%p,%p)\n", This, lpDSCBCaps );
if ( (This == NULL) || (lpDSCBCaps == NULL) ) {
WARN("invalid parameters\n");
if (This == NULL) {
WARN("invalid parameter: This == NULL\n");
return DSERR_INVALIDPARAM;
}
if ( (lpDSCBCaps->dwSize < sizeof(DSCBCAPS)) || (This->dsound == NULL) ) {
WARN("invalid parameters\n");
if (lpDSCBCaps == NULL) {
WARN("invalid parameter: lpDSCBCaps == NULL\n");
return DSERR_INVALIDPARAM;
}
if (lpDSCBCaps->dwSize < sizeof(DSCBCAPS)) {
WARN("invalid parameter: lpDSCBCaps->dwSize = %ld < %d\n",
lpDSCBCaps->dwSize, sizeof(DSCBCAPS));
return DSERR_INVALIDPARAM;
}
if (This->dsound == NULL) {
WARN("invalid parameter: This->dsound == NULL\n");
return DSERR_INVALIDPARAM;
}
@ -871,13 +930,23 @@ IDirectSoundCaptureBufferImpl_GetCurrentPosition(
ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
TRACE( "(%p,%p,%p)\n", This, lpdwCapturePosition, lpdwReadPosition );
if ( (This == NULL) || (This->dsound == NULL) ) {
WARN("invalid parameter\n");
if (This == NULL) {
WARN("invalid parameter: This == NULL\n");
return DSERR_INVALIDPARAM;
}
if (This->dsound == NULL) {
WARN("invalid parameter: This->dsound == NULL\n");
return DSERR_INVALIDPARAM;
}
if (This->dsound->driver) {
return IDsCaptureDriverBuffer_GetPosition(This->dsound->hwbuf, lpdwCapturePosition, lpdwReadPosition );
HRESULT hres;
hres = IDsCaptureDriverBuffer_GetPosition(This->dsound->hwbuf, lpdwCapturePosition, lpdwReadPosition );
if (hres != DS_OK) {
WARN("IDsCaptureDriverBuffer_GetPosition failed\n");
return hres;
}
} else if (This->dsound->hwi) {
EnterCriticalSection(&(This->dsound->lock));
TRACE("old This->dsound->state=%ld\n",This->dsound->state);
@ -923,8 +992,13 @@ IDirectSoundCaptureBufferImpl_GetFormat(
TRACE( "(%p,%p,0x%08lx,%p)\n", This, lpwfxFormat, dwSizeAllocated,
lpdwSizeWritten );
if ( (This == NULL) || (This->dsound == NULL) ) {
WARN("invalid parameter\n");
if (This == NULL) {
WARN("invalid parameter: This == NULL\n");
return DSERR_INVALIDPARAM;
}
if (This->dsound == NULL) {
WARN("invalid parameter: This->dsound == NULL\n");
return DSERR_INVALIDPARAM;
}
@ -939,7 +1013,7 @@ IDirectSoundCaptureBufferImpl_GetFormat(
if (lpdwSizeWritten)
*lpdwSizeWritten = sizeof(This->dsound->wfx);
else {
TRACE("invalid parameter\n");
TRACE("invalid parameter: lpdwSizeWritten = NULL\n");
return DSERR_INVALIDPARAM;
}
}
@ -956,8 +1030,18 @@ IDirectSoundCaptureBufferImpl_GetStatus(
ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
TRACE( "(%p, %p), thread is %04lx\n", This, lpdwStatus, GetCurrentThreadId() );
if ( (This == NULL ) || (This->dsound == NULL) || (lpdwStatus == NULL) ) {
WARN("invalid parameter\n");
if (This == NULL) {
WARN("invalid parameter: This == NULL\n");
return DSERR_INVALIDPARAM;
}
if (This->dsound == NULL) {
WARN("invalid parameter: This->dsound == NULL\n");
return DSERR_INVALIDPARAM;
}
if (lpdwStatus == NULL) {
WARN("invalid parameter: lpdwStatus == NULL\n");
return DSERR_INVALIDPARAM;
}
@ -1009,9 +1093,23 @@ IDirectSoundCaptureBufferImpl_Lock(
dwReadBytes, lplpvAudioPtr1, lpdwAudioBytes1, lplpvAudioPtr2,
lpdwAudioBytes2, dwFlags, GetTickCount() );
if ( (This == NULL) || (This->dsound == NULL) || (lplpvAudioPtr1 == NULL) ||
(lpdwAudioBytes1 == NULL) ) {
WARN("invalid parameter\n");
if (This == NULL) {
WARN("invalid parameter: This == NULL\n");
return DSERR_INVALIDPARAM;
}
if (This->dsound == NULL) {
WARN("invalid parameter: This->dsound == NULL\n");
return DSERR_INVALIDPARAM;
}
if (lplpvAudioPtr1 == NULL) {
WARN("invalid parameter: lplpvAudioPtr1 == NULL\n");
return DSERR_INVALIDPARAM;
}
if (lpdwAudioBytes1 == NULL) {
WARN("invalid parameter: lpdwAudioBytes1 == NULL\n");
return DSERR_INVALIDPARAM;
}
@ -1021,6 +1119,8 @@ IDirectSoundCaptureBufferImpl_Lock(
err = IDsCaptureDriverBuffer_Lock(This->dsound->hwbuf, lplpvAudioPtr1,
lpdwAudioBytes1, lplpvAudioPtr2, lpdwAudioBytes2,
dwReadCusor, dwReadBytes, dwFlags);
if (err != DS_OK)
WARN("IDsCaptureDriverBuffer_Lock failed\n");
} else if (This->dsound->hwi) {
*lplpvAudioPtr1 = This->dsound->buffer + dwReadCusor;
if ( (dwReadCusor + dwReadBytes) > This->dsound->buflen) {
@ -1055,8 +1155,13 @@ IDirectSoundCaptureBufferImpl_Start(
ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
TRACE( "(%p,0x%08lx)\n", This, dwFlags );
if ( (This == NULL) || (This->dsound == NULL) ) {
WARN("invalid parameter\n");
if (This == NULL) {
WARN("invalid parameter: This == NULL\n");
return DSERR_INVALIDPARAM;
}
if (This->dsound == NULL) {
WARN("invalid parameter: This->dsound == NULL\n");
return DSERR_INVALIDPARAM;
}
@ -1079,6 +1184,8 @@ IDirectSoundCaptureBufferImpl_Start(
if (This->dsound->driver) {
err = IDsCaptureDriverBuffer_Start(This->dsound->hwbuf, dwFlags);
if (err != DS_OK)
WARN("IDsCaptureDriverBuffer_Start failed\n");
return err;
} else {
IDirectSoundCaptureImpl* ipDSC = This->dsound;
@ -1134,6 +1241,7 @@ IDirectSoundCaptureBufferImpl_Start(
err = mmErr(waveInPrepareHeader(ipDSC->hwi,
&(ipDSC->pwave[0]),sizeof(WAVEHDR)));
if (err != DS_OK) {
WARN("waveInPrepareHeader failed\n");
waveInUnprepareHeader(ipDSC->hwi,
&(ipDSC->pwave[0]),sizeof(WAVEHDR));
}
@ -1151,8 +1259,10 @@ IDirectSoundCaptureBufferImpl_Start(
if (err == DS_OK) {
/* start filling the first buffer */
err = mmErr(waveInStart(ipDSC->hwi));
}
}
} else
WARN("waveInAddBuffer failed\n");
} else
WARN("waveInReset failed\n");
}
}
@ -1173,8 +1283,13 @@ IDirectSoundCaptureBufferImpl_Stop( LPDIRECTSOUNDCAPTUREBUFFER8 iface )
ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
TRACE( "(%p)\n", This );
if ( (This == NULL) || (This->dsound == NULL) ) {
WARN("invalid parameter\n");
if (This == NULL) {
WARN("invalid parameter: This == NULL\n");
return DSERR_INVALIDPARAM;
}
if (This->dsound == NULL) {
WARN("invalid parameter: This->dsound == NULL\n");
return DSERR_INVALIDPARAM;
}
@ -1201,7 +1316,8 @@ IDirectSoundCaptureBufferImpl_Stop( LPDIRECTSOUNDCAPTUREBUFFER8 iface )
WARN("IDsCaptureDriver_CreateCaptureBuffer failed\n");
This->dsound->hwbuf = 0;
}
}
} else if (err != DS_OK)
WARN("IDsCaptureDriverBuffer_Stop failed\n");
} else if (This->dsound->hwi) {
err = waveInStop(This->dsound->hwi);
} else {
@ -1225,14 +1341,23 @@ IDirectSoundCaptureBufferImpl_Unlock(
TRACE( "(%p,%p,%08lu,%p,%08lu)\n", This, lpvAudioPtr1, dwAudioBytes1,
lpvAudioPtr2, dwAudioBytes2 );
if ( (This == NULL) || (lpvAudioPtr1 == NULL) ) {
WARN("invalid parameters\n");
if (This == NULL) {
WARN("invalid parameter: This == NULL\n");
return DSERR_INVALIDPARAM;
}
if (lpvAudioPtr1 == NULL) {
WARN("invalid parameter: lpvAudioPtr1 == NULL\n");
return DSERR_INVALIDPARAM;
}
if (This->dsound->driver) {
return IDsCaptureDriverBuffer_Unlock(This->dsound->hwbuf, lpvAudioPtr1,
HRESULT hres;
hres = IDsCaptureDriverBuffer_Unlock(This->dsound->hwbuf, lpvAudioPtr1,
dwAudioBytes1, lpvAudioPtr2, dwAudioBytes2);
if (hres != DS_OK)
WARN("IDsCaptureDriverBuffer_Unlock failed\n");
return hres;
} else if (This->dsound->hwi) {
This->dsound->read_position = (This->dsound->read_position +
(dwAudioBytes1 + dwAudioBytes2)) % This->dsound->buflen;
@ -1346,11 +1471,10 @@ DirectSoundFullDuplexCreate8(
HEAP_ZERO_MEMORY, sizeof(IDirectSoundFullDuplexImpl));
if (*ippDSFD == NULL) {
TRACE("couldn't allocate memory\n");
WARN("out of memory\n");
return DSERR_OUTOFMEMORY;
}
else
{
} else {
HRESULT hres;
ICOM_THIS(IDirectSoundFullDuplexImpl, *ippDSFD);
This->ref = 1;
@ -1358,11 +1482,16 @@ DirectSoundFullDuplexCreate8(
InitializeCriticalSection( &(This->lock) );
return IDirectSoundFullDuplexImpl_Initialize( (LPDIRECTSOUNDFULLDUPLEX)This,
hres = IDirectSoundFullDuplexImpl_Initialize( (LPDIRECTSOUNDFULLDUPLEX)This,
pcGuidCaptureDevice, pcGuidRenderDevice,
pcDSCBufferDesc, pcDSBufferDesc,
hWnd, dwLevel, ppDSCBuffer8, ppDSBuffer8);
if (hres != DS_OK)
WARN("IDirectSoundFullDuplexImpl_Initialize failed\n");
return hres;
}
return DSERR_GENERIC;
}
static HRESULT WINAPI
@ -1431,7 +1560,7 @@ IDirectSoundFullDuplexImpl_Initialize(
IDirectSoundCaptureBufferImpl** ippdscb=(IDirectSoundCaptureBufferImpl**)lplpDirectSoundCaptureBuffer8;
IDirectSoundBufferImpl** ippdsc=(IDirectSoundBufferImpl**)lplpDirectSoundBuffer8;
TRACE( "(%p,%s,%s,%p,%p,%lx,%lx,%p,%p)\n", This, debugstr_guid(pCaptureGuid),
FIXME( "(%p,%s,%s,%p,%p,%lx,%lx,%p,%p) stub!\n", This, debugstr_guid(pCaptureGuid),
debugstr_guid(pRendererGuid), lpDscBufferDesc, lpDsBufferDesc, (DWORD)hWnd, dwLevel,
ippdscb, ippdsc);

View File

@ -252,8 +252,15 @@ void setup_dsound_options(void)
*/
HRESULT WINAPI GetDeviceID(LPCGUID pGuidSrc, LPGUID pGuidDest)
{
if ( ( pGuidSrc == NULL) || (pGuidDest == NULL) ) {
WARN("invalid parameter\n");
TRACE("(%p,%p)\n",pGuidSrc,pGuidDest);
if ( pGuidSrc == NULL) {
WARN("invalid parameter: pGuidSrc == NULL\n");
return DSERR_INVALIDPARAM;
}
if ( pGuidDest == NULL ) {
WARN("invalid parameter: pGuidDest == NULL\n");
return DSERR_INVALIDPARAM;
}
@ -477,11 +484,24 @@ static HRESULT WINAPI IDirectSoundImpl_CreateSoundBuffer(
) {
ICOM_THIS(IDirectSoundImpl,iface);
LPWAVEFORMATEX wfex;
HRESULT hres;
TRACE("(%p,%p,%p,%p)\n",This,dsbd,ppdsb,lpunk);
if ((This == NULL) || (dsbd == NULL) || (ppdsb == NULL))
if (This == NULL) {
WARN("invalid parameter: This == NULL\n");
return DSERR_INVALIDPARAM;
}
if (dsbd == NULL) {
WARN("invalid parameter: dsbd == NULL\n");
return DSERR_INVALIDPARAM;
}
if (ppdsb == NULL) {
WARN("invalid parameter: ppdsb == NULL\n");
return DSERR_INVALIDPARAM;
}
if (TRACE_ON(dsound)) {
TRACE("(structsize=%ld)\n",dsbd->dwSize);
@ -501,10 +521,17 @@ static HRESULT WINAPI IDirectSoundImpl_CreateSoundBuffer(
wfex->nAvgBytesPerSec, wfex->nBlockAlign,
wfex->wBitsPerSample, wfex->cbSize);
if (dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER)
return PrimaryBuffer_Create(This, (PrimaryBufferImpl**)ppdsb, dsbd);
else
return SecondaryBuffer_Create(This, (IDirectSoundBufferImpl**)ppdsb, dsbd);
if (dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER) {
hres = PrimaryBuffer_Create(This, (PrimaryBufferImpl**)ppdsb, dsbd);
if (hres != DS_OK)
WARN("PrimaryBuffer_Create failed\n");
} else {
hres = SecondaryBuffer_Create(This, (IDirectSoundBufferImpl**)ppdsb, dsbd);
if (hres != DS_OK)
WARN("SecondaryBuffer_Create failed\n");
}
return hres;
}
static HRESULT WINAPI IDirectSoundImpl_DuplicateSoundBuffer(
@ -512,108 +539,162 @@ static HRESULT WINAPI IDirectSoundImpl_DuplicateSoundBuffer(
) {
ICOM_THIS(IDirectSoundImpl,iface);
IDirectSoundBufferImpl* ipdsb=(IDirectSoundBufferImpl*)pdsb;
IDirectSoundBufferImpl** ippdsb=(IDirectSoundBufferImpl**)ppdsb;
TRACE("(%p,%p,%p)\n",This,ipdsb,ippdsb);
IDirectSoundBufferImpl* dsb;
TRACE("(%p,%p,%p)\n",This,pdsb,ppdsb);
if (This == NULL) {
WARN("invalid parameter: This == NULL\n");
return DSERR_INVALIDPARAM;
}
if (pdsb == NULL) {
WARN("invalid parameter: pdsb == NULL\n");
return DSERR_INVALIDPARAM;
}
if (ppdsb == NULL) {
WARN("invalid parameter: ppdsb == NULL\n");
return DSERR_INVALIDPARAM;
}
if (ipdsb->dsbd.dwFlags & DSBCAPS_PRIMARYBUFFER) {
ERR("trying to duplicate primary buffer\n");
*ppdsb = NULL;
return DSERR_INVALIDCALL;
}
if (ipdsb->hwbuf) {
FIXME("need to duplicate hardware buffer\n");
*ppdsb = NULL;
return DSERR_INVALIDCALL;
}
if (ipdsb->dsbd.dwFlags & DSBCAPS_CTRL3D) {
FIXME("need to duplicate 3D buffer\n");
}
dsb = (IDirectSoundBufferImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*dsb));
*ippdsb = (IDirectSoundBufferImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirectSoundBufferImpl));
if (dsb == NULL) {
WARN("out of memory\n");
*ppdsb = NULL;
return DSERR_OUTOFMEMORY;
}
IDirectSoundBuffer8_AddRef(pdsb);
memcpy(*ippdsb, ipdsb, sizeof(IDirectSoundBufferImpl));
(*ippdsb)->ref = 1;
(*ippdsb)->state = STATE_STOPPED;
(*ippdsb)->playpos = 0;
(*ippdsb)->buf_mixpos = 0;
(*ippdsb)->dsound = This;
(*ippdsb)->parent = ipdsb;
(*ippdsb)->hwbuf = NULL;
(*ippdsb)->ds3db = NULL; /* FIXME? */
(*ippdsb)->iks = NULL; /* FIXME? */
memcpy(&((*ippdsb)->wfx), &(ipdsb->wfx), sizeof((*ippdsb)->wfx));
InitializeCriticalSection(&(*ippdsb)->lock);
memcpy(dsb, ipdsb, sizeof(IDirectSoundBufferImpl));
dsb->ref = 1;
dsb->state = STATE_STOPPED;
dsb->playpos = 0;
dsb->buf_mixpos = 0;
dsb->dsound = This;
dsb->parent = ipdsb;
dsb->hwbuf = NULL;
if (ipdsb->ds3db != NULL) {
HRESULT hres;
hres = IDirectSound3DBufferImpl_Create(dsb, &(dsb->ds3db));
if (hres != DS_OK) {
WARN("IDirectSound3DBufferImpl_Create failed\n");
} else {
IDirectSound3DBuffer_AddRef((LPDIRECTSOUND3DBUFFER)(dsb->ds3db));
dsb->dsbd.dwFlags |= DSBCAPS_CTRL3D;
memcpy(&(dsb->ds3db->ds3db), &(ipdsb->ds3db->ds3db), sizeof(DS3DBUFFER));
}
} else {
dsb->ds3db = NULL;
}
dsb->iks = NULL; /* FIXME? */
memcpy(&(dsb->wfx), &(ipdsb->wfx), sizeof(dsb->wfx));
InitializeCriticalSection(&(dsb->lock));
/* register buffer */
RtlAcquireResourceExclusive(&(This->lock), TRUE);
{
IDirectSoundBufferImpl **newbuffers = (IDirectSoundBufferImpl**)HeapReAlloc(GetProcessHeap(),0,This->buffers,sizeof(IDirectSoundBufferImpl**)*(This->nrofbuffers+1));
if (newbuffers) {
This->buffers = newbuffers;
This->buffers[This->nrofbuffers] = *ippdsb;
This->buffers[This->nrofbuffers] = dsb;
This->nrofbuffers++;
TRACE("buffer count is now %d\n", This->nrofbuffers);
} else {
ERR("out of memory for buffer list! Current buffer count is %d\n", This->nrofbuffers);
/* FIXME: release buffer */
IDirectSoundBuffer8_Release(pdsb);
DeleteCriticalSection(&(dsb->lock));
RtlReleaseResource(&(This->lock));
HeapFree(GetProcessHeap(),0,dsb);
*ppdsb = 0;
return DSERR_OUTOFMEMORY;
}
}
RtlReleaseResource(&(This->lock));
IDirectSound_AddRef(iface);
*ppdsb = (LPDIRECTSOUNDBUFFER8)dsb;
return DS_OK;
}
static HRESULT WINAPI IDirectSoundImpl_GetCaps(LPDIRECTSOUND8 iface,LPDSCAPS caps) {
static HRESULT WINAPI IDirectSoundImpl_GetCaps(LPDIRECTSOUND8 iface,LPDSCAPS lpDSCaps) {
ICOM_THIS(IDirectSoundImpl,iface);
TRACE("(%p,%p)\n",This,caps);
TRACE("(%p,%p)\n",This,lpDSCaps);
if (caps == NULL || caps->dwSize!=sizeof(*caps))
if (This == NULL) {
WARN("invalid parameter: This == NULL\n");
return DSERR_INVALIDPARAM;
}
caps->dwFlags = This->drvcaps.dwFlags;
TRACE("(flags=0x%08lx)\n",caps->dwFlags);
if (lpDSCaps == NULL) {
WARN("invalid parameter: lpDSCaps = NULL\n");
return DSERR_INVALIDPARAM;
}
/* FIXME: copy caps from This->drvcaps */
caps->dwMinSecondarySampleRate = DSBFREQUENCY_MIN;
caps->dwMaxSecondarySampleRate = DSBFREQUENCY_MAX;
/* check is there is enough room */
if (lpDSCaps->dwSize < sizeof(*lpDSCaps)) {
WARN("invalid parameter: lpDSCaps->dwSize = %ld < %d\n",
lpDSCaps->dwSize, sizeof(*lpDSCaps));
return DSERR_INVALIDPARAM;
}
caps->dwPrimaryBuffers = 1;
lpDSCaps->dwFlags = This->drvcaps.dwFlags;
TRACE("(flags=0x%08lx)\n",lpDSCaps->dwFlags);
caps->dwMaxHwMixingAllBuffers = 0;
caps->dwMaxHwMixingStaticBuffers = 0;
caps->dwMaxHwMixingStreamingBuffers = 0;
/* FIXME: copy caps from This->drv */
lpDSCaps->dwMinSecondarySampleRate = DSBFREQUENCY_MIN;
lpDSCaps->dwMaxSecondarySampleRate = DSBFREQUENCY_MAX;
caps->dwFreeHwMixingAllBuffers = 0;
caps->dwFreeHwMixingStaticBuffers = 0;
caps->dwFreeHwMixingStreamingBuffers = 0;
lpDSCaps->dwPrimaryBuffers = 1;
caps->dwMaxHw3DAllBuffers = 0;
caps->dwMaxHw3DStaticBuffers = 0;
caps->dwMaxHw3DStreamingBuffers = 0;
lpDSCaps->dwMaxHwMixingAllBuffers = 0;
lpDSCaps->dwMaxHwMixingStaticBuffers = 0;
lpDSCaps->dwMaxHwMixingStreamingBuffers = 0;
caps->dwFreeHw3DAllBuffers = 0;
caps->dwFreeHw3DStaticBuffers = 0;
caps->dwFreeHw3DStreamingBuffers = 0;
lpDSCaps->dwFreeHwMixingAllBuffers = 0;
lpDSCaps->dwFreeHwMixingStaticBuffers = 0;
lpDSCaps->dwFreeHwMixingStreamingBuffers = 0;
caps->dwTotalHwMemBytes = 0;
lpDSCaps->dwMaxHw3DAllBuffers = 0;
lpDSCaps->dwMaxHw3DStaticBuffers = 0;
lpDSCaps->dwMaxHw3DStreamingBuffers = 0;
caps->dwFreeHwMemBytes = 0;
lpDSCaps->dwFreeHw3DAllBuffers = 0;
lpDSCaps->dwFreeHw3DStaticBuffers = 0;
lpDSCaps->dwFreeHw3DStreamingBuffers = 0;
caps->dwMaxContigFreeHwMemBytes = 0;
lpDSCaps->dwTotalHwMemBytes = 0;
caps->dwUnlockTransferRateHwBuffers = 4096; /* But we have none... */
lpDSCaps->dwFreeHwMemBytes = 0;
caps->dwPlayCpuOverheadSwBuffers = 1; /* 1% */
lpDSCaps->dwMaxContigFreeHwMemBytes = 0;
lpDSCaps->dwUnlockTransferRateHwBuffers = 4096; /* But we have none... */
lpDSCaps->dwPlayCpuOverheadSwBuffers = 1; /* 1% */
return DS_OK;
}
static ULONG WINAPI IDirectSoundImpl_AddRef(LPDIRECTSOUND8 iface) {
ICOM_THIS(IDirectSoundImpl,iface);
TRACE("(%p) ref was %ld\n", This, This->ref);
return ++(This->ref);
}
static ULONG WINAPI IDirectSoundImpl_Release(LPDIRECTSOUND8 iface) {
HRESULT hres;
ICOM_THIS(IDirectSoundImpl,iface);
TRACE("(%p), ref was %ld\n",This,This->ref);
if (!--(This->ref)) {
@ -627,7 +708,9 @@ static ULONG WINAPI IDirectSoundImpl_Release(LPDIRECTSOUND8 iface) {
IDirectSoundBuffer8_Release((LPDIRECTSOUNDBUFFER8)This->buffers[i]);
}
DSOUND_PrimaryDestroy(This);
hres = DSOUND_PrimaryDestroy(This);
if (hres != DS_OK)
WARN("DSOUND_PrimaryDestroy failed\n");
RtlDeleteResource(&This->lock);
DeleteCriticalSection(&This->mixlock);
@ -693,7 +776,7 @@ static HRESULT WINAPI IDirectSoundImpl_Initialize(
LPCGUID lpcGuid)
{
ICOM_THIS(IDirectSoundImpl,iface);
TRACE("(%p, %p)\n", This, lpcGuid);
TRACE("(%p, %s)\n", This, debugstr_guid(lpcGuid));
return DS_OK;
}
@ -752,7 +835,7 @@ HRESULT WINAPI DirectSoundCreate8(LPCGUID lpcGUID,LPDIRECTSOUND8 *ppDS,IUnknown
TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID),ippDS,pUnkOuter);
if (ippDS == NULL) {
WARN("invalid parameter\n");
WARN("invalid parameter: ippDS == NULL\n");
return DSERR_INVALIDPARAM;
}
@ -764,7 +847,8 @@ HRESULT WINAPI DirectSoundCreate8(LPCGUID lpcGUID,LPDIRECTSOUND8 *ppDS,IUnknown
lpcGUID = &DSDEVID_DefaultPlayback;
if (GetDeviceID(lpcGUID, &devGuid) != DS_OK) {
WARN("invalid parameter\n");
WARN("invalid parameter: lpcGUID\n");
*ippDS = NULL;
return DSERR_INVALIDPARAM;
}
@ -781,7 +865,11 @@ HRESULT WINAPI DirectSoundCreate8(LPCGUID lpcGUID,LPDIRECTSOUND8 *ppDS,IUnknown
/* Enumerate WINMM audio devices and find the one we want */
wodn = waveOutGetNumDevs();
if (!wodn) return DSERR_NODRIVER;
if (!wodn) {
WARN("no driver\n");
*ippDS = NULL;
return DSERR_NODRIVER;
}
TRACE(" expecting GUID %s.\n", debugstr_guid(&devGuid));
@ -790,6 +878,7 @@ HRESULT WINAPI DirectSoundCreate8(LPCGUID lpcGUID,LPDIRECTSOUND8 *ppDS,IUnknown
err = mmErr(waveOutMessage((HWAVEOUT)wod,DRV_QUERYDSOUNDGUID,(DWORD)(&guid),0));
if (err != DS_OK) {
WARN("waveOutMessage failed; err=%lx\n",err);
*ippDS = NULL;
return err;
}
TRACE("got GUID %s for wod %d.\n", debugstr_guid(&guid), wod);
@ -802,6 +891,7 @@ HRESULT WINAPI DirectSoundCreate8(LPCGUID lpcGUID,LPDIRECTSOUND8 *ppDS,IUnknown
if (err != DS_OK) {
WARN("invalid parameter\n");
*ippDS = NULL;
return DSERR_INVALIDPARAM;
}
@ -819,8 +909,10 @@ HRESULT WINAPI DirectSoundCreate8(LPCGUID lpcGUID,LPDIRECTSOUND8 *ppDS,IUnknown
/* Allocate memory */
*ippDS = (IDirectSoundImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirectSoundImpl));
if (*ippDS == NULL)
if (*ippDS == NULL) {
WARN("out of memory\n");
return DSERR_OUTOFMEMORY;
}
(*ippDS)->lpVtbl = &dsvt;
(*ippDS)->ref = 1;
@ -842,7 +934,13 @@ HRESULT WINAPI DirectSoundCreate8(LPCGUID lpcGUID,LPDIRECTSOUND8 *ppDS,IUnknown
/* Get driver description */
if (drv) {
IDsDriver_GetDriverDesc(drv,&((*ippDS)->drvdesc));
err = IDsDriver_GetDriverDesc(drv,&((*ippDS)->drvdesc));
if (err != DS_OK) {
WARN("IDsDriver_GetDriverDesc failed\n");
HeapFree(GetProcessHeap(),0,*ippDS);
*ippDS = NULL;
return err;
}
} else {
/* if no DirectSound interface available, use WINMM API instead */
(*ippDS)->drvdesc.dwFlags = DSDDESC_DOMMSYSTEMOPEN | DSDDESC_DOMMSYSTEMSETFORMAT;
@ -878,25 +976,73 @@ HRESULT WINAPI DirectSoundCreate8(LPCGUID lpcGUID,LPDIRECTSOUND8 *ppDS,IUnknown
(*ippDS)->drvdesc.dnDevNode, &((*ippDS)->wfx),
(DWORD)DSOUND_callback, (DWORD)(*ippDS),
flags));
if (err != DS_OK) {
WARN("waveOutOpen failed\n");
HeapFree(GetProcessHeap(),0,*ippDS);
*ippDS = NULL;
return err;
}
}
if (drv && (err == DS_OK))
err = IDsDriver_Open(drv);
/* FIXME: do we want to handle a temporarily busy device? */
if (err != DS_OK) {
HeapFree(GetProcessHeap(),0,*ippDS);
*ippDS = NULL;
return err;
}
/* the driver is now open, so it's now allowed to call GetCaps */
if (drv) {
IDsDriver_GetCaps(drv,&((*ippDS)->drvcaps));
err = IDsDriver_Open(drv);
if (err != DS_OK) {
WARN("IDsDriver_Open failed\n");
HeapFree(GetProcessHeap(),0,*ippDS);
*ippDS = NULL;
return err;
}
/* the driver is now open, so it's now allowed to call GetCaps */
err = IDsDriver_GetCaps(drv,&((*ippDS)->drvcaps));
if (err != DS_OK) {
WARN("IDsDriver_GetCaps failed\n");
HeapFree(GetProcessHeap(),0,*ippDS);
*ippDS = NULL;
return err;
}
} else {
/* FIXME: We should check the device capabilities */
(*ippDS)->drvcaps.dwFlags =
DSCAPS_PRIMARY16BIT | DSCAPS_PRIMARYSTEREO;
WAVEOUTCAPSA woc;
err = mmErr(waveOutGetDevCapsA((*ippDS)->drvdesc.dnDevNode, &woc, sizeof(woc)));
if (err != DS_OK) {
WARN("waveOutGetDevCaps failed\n");
HeapFree(GetProcessHeap(),0,*ippDS);
*ippDS = NULL;
return err;
}
(*ippDS)->drvcaps.dwFlags = 0;
if ((woc.dwFormats & WAVE_FORMAT_1M08) ||
(woc.dwFormats & WAVE_FORMAT_2M08) ||
(woc.dwFormats & WAVE_FORMAT_4M08) ||
(woc.dwFormats & WAVE_FORMAT_48M08) ||
(woc.dwFormats & WAVE_FORMAT_96M08)) {
(*ippDS)->drvcaps.dwFlags |= DSCAPS_PRIMARY8BIT;
(*ippDS)->drvcaps.dwFlags |= DSCAPS_PRIMARYMONO;
}
if ((woc.dwFormats & WAVE_FORMAT_1M16) ||
(woc.dwFormats & WAVE_FORMAT_2M16) ||
(woc.dwFormats & WAVE_FORMAT_4M16) ||
(woc.dwFormats & WAVE_FORMAT_48M16) ||
(woc.dwFormats & WAVE_FORMAT_96M16)) {
(*ippDS)->drvcaps.dwFlags |= DSCAPS_PRIMARY16BIT;
(*ippDS)->drvcaps.dwFlags |= DSCAPS_PRIMARYMONO;
}
if ((woc.dwFormats & WAVE_FORMAT_1S08) ||
(woc.dwFormats & WAVE_FORMAT_2S08) ||
(woc.dwFormats & WAVE_FORMAT_4S08) ||
(woc.dwFormats & WAVE_FORMAT_48S08) ||
(woc.dwFormats & WAVE_FORMAT_96S08)) {
(*ippDS)->drvcaps.dwFlags |= DSCAPS_PRIMARY8BIT;
(*ippDS)->drvcaps.dwFlags |= DSCAPS_PRIMARYSTEREO;
}
if ((woc.dwFormats & WAVE_FORMAT_1S16) ||
(woc.dwFormats & WAVE_FORMAT_2S16) ||
(woc.dwFormats & WAVE_FORMAT_4S16) ||
(woc.dwFormats & WAVE_FORMAT_48S16) ||
(woc.dwFormats & WAVE_FORMAT_96S16)) {
(*ippDS)->drvcaps.dwFlags |= DSCAPS_PRIMARY16BIT;
(*ippDS)->drvcaps.dwFlags |= DSCAPS_PRIMARYSTEREO;
}
if (ds_emuldriver)
(*ippDS)->drvcaps.dwFlags |= DSCAPS_EMULDRIVER;
}
@ -907,8 +1053,13 @@ HRESULT WINAPI DirectSoundCreate8(LPCGUID lpcGUID,LPDIRECTSOUND8 *ppDS,IUnknown
RtlInitializeResource(&((*ippDS)->lock));
if (!dsound) {
HRESULT hres;
dsound = (*ippDS);
DSOUND_PrimaryCreate(dsound);
hres = DSOUND_PrimaryCreate(dsound);
if (hres != DS_OK) {
WARN("DSOUND_PrimaryCreate failed\n");
return hres;
}
timeBeginPeriod(DS_TIME_RES);
dsound->timerID = timeSetEvent(DS_TIME_DEL, DS_TIME_RES, DSOUND_timer,
(DWORD)dsound, TIME_PERIODIC | TIME_CALLBACK_FUNCTION);
@ -938,12 +1089,14 @@ DSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
static ULONG WINAPI
DSCF_AddRef(LPCLASSFACTORY iface) {
ICOM_THIS(IClassFactoryImpl,iface);
TRACE("(%p) ref was %ld\n", This, This->ref);
return ++(This->ref);
}
static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface) {
ICOM_THIS(IClassFactoryImpl,iface);
/* static class, won't be freed */
TRACE("(%p) ref was %ld\n", This, This->ref);
return --(This->ref);
}

View File

@ -877,8 +877,7 @@ void DSOUND_PerformMix(void)
while (writepos >= dsound->buflen)
writepos -= dsound->buflen;
} else writepos = playpos;
}
else {
} else {
playpos = dsound->pwplay * dsound->fraglen;
writepos = playpos;
if (!paused) {
@ -887,8 +886,9 @@ void DSOUND_PerformMix(void)
writepos -= dsound->buflen;
}
}
TRACE("primary playpos=%ld, writepos=%ld, clrpos=%ld, mixpos=%ld\n",
playpos,writepos,dsound->playpos,dsound->mixpos);
TRACE("primary playpos=%ld, writepos=%ld, clrpos=%ld, mixpos=%ld, buflen=%ld\n",
playpos,writepos,dsound->playpos,dsound->mixpos,dsound->buflen);
assert(dsound->playpos < dsound->buflen);
/* wipe out just-played sound data */
if (playpos < dsound->playpos) {
memset(dsound->buffer + dsound->playpos, nfiller, dsound->buflen - dsound->playpos);
@ -943,7 +943,8 @@ void DSOUND_PerformMix(void)
/* DSOUND_callback may need this lock */
LeaveCriticalSection(&(dsound->mixlock));
#endif
DSOUND_PrimaryStop(dsound);
if (DSOUND_PrimaryStop(dsound) != DS_OK)
WARN("DSOUND_PrimaryStop failed\n");
#ifdef SYNC_CALLBACK
EnterCriticalSection(&(dsound->mixlock));
#endif
@ -988,8 +989,10 @@ void DSOUND_PerformMix(void)
}
LeaveCriticalSection(&(dsound->mixlock));
if (paused) {
DSOUND_PrimaryPlay(dsound);
TRACE("starting playback\n");
if (DSOUND_PrimaryPlay(dsound) != DS_OK)
WARN("DSOUND_PrimaryPlay failed\n");
else
TRACE("starting playback\n");
}
}
else
@ -997,12 +1000,16 @@ void DSOUND_PerformMix(void)
} else {
/* in the DSSCL_WRITEPRIMARY mode, the app is totally in charge... */
if (dsound->state == STATE_STARTING) {
DSOUND_PrimaryPlay(dsound);
dsound->state = STATE_PLAYING;
if (DSOUND_PrimaryPlay(dsound) != DS_OK)
WARN("DSOUND_PrimaryPlay failed\n");
else
dsound->state = STATE_PLAYING;
}
else if (dsound->state == STATE_STOPPING) {
DSOUND_PrimaryStop(dsound);
dsound->state = STATE_STOPPED;
if (DSOUND_PrimaryStop(dsound) != DS_OK)
WARN("DSOUND_PrimaryStop failed\n");
else
dsound->state = STATE_STOPPED;
}
}
TRACE("completed processing at %ld\n", GetTickCount());

View File

@ -118,6 +118,8 @@ static HRESULT DSOUND_PrimaryOpen(IDirectSoundImpl *This)
This->pwplay = 0;
This->pwwrite = 0;
This->pwqueue = 0;
This->playpos = 0;
This->mixpos = 0;
memset(This->buffer, (This->wfx.wBitsPerSample == 16) ? 0 : 128, This->buflen);
TRACE("fraglen=%ld\n", This->fraglen);
DSOUND_WaveQueue(This, (DWORD)-1);
@ -159,6 +161,10 @@ HRESULT DSOUND_PrimaryCreate(IDirectSoundImpl *This)
DSBCAPS_PRIMARYBUFFER,0,
&(This->buflen),&(This->buffer),
(LPVOID*)&(This->hwbuf));
if (err != DS_OK) {
WARN("IDsDriver_CreateSoundBuffer failed\n");
return err;
}
}
if (!This->hwbuf) {
/* Allocate memory for HEL buffer headers */
@ -170,15 +176,19 @@ HRESULT DSOUND_PrimaryCreate(IDirectSoundImpl *This)
while (c--) {
HeapFree(GetProcessHeap(),0,This->pwave[c]);
}
err=DSERR_OUTOFMEMORY;
break;
WARN("out of memory\n");
return DSERR_OUTOFMEMORY;
}
}
}
if (err == DS_OK)
err = DSOUND_PrimaryOpen(This);
if (err != DS_OK)
err = DSOUND_PrimaryOpen(This);
if (err != DS_OK) {
WARN("DSOUND_PrimaryOpen failed\n");
return err;
}
/* calculate fragment size and write lead */
DSOUND_RecalcPrimary(This);
This->state = STATE_STOPPED;
@ -207,10 +217,16 @@ HRESULT DSOUND_PrimaryPlay(IDirectSoundImpl *This)
HRESULT err = DS_OK;
TRACE("(%p)\n",This);
if (This->hwbuf)
if (This->hwbuf) {
err = IDsDriverBuffer_Play(This->hwbuf, 0, 0, DSBPLAY_LOOPING);
else
if (err != DS_OK)
WARN("IDsDriverBuffer_Play failed\n");
} else {
err = mmErr(waveOutRestart(This->hwo));
if (err != DS_OK)
WARN("waveOutRestart failed\n");
}
return err;
}
@ -233,15 +249,24 @@ HRESULT DSOUND_PrimaryStop(IDirectSoundImpl *This)
err = mmErr(waveOutOpen(&(This->hwo), This->drvdesc.dnDevNode,
&(This->wfx), (DWORD)DSOUND_callback, (DWORD)This,
flags));
if (err == DS_OK)
if (err == DS_OK) {
err = IDsDriver_CreateSoundBuffer(This->driver,&(This->wfx),
DSBCAPS_PRIMARYBUFFER,0,
&(This->buflen),&(This->buffer),
(LPVOID)&(This->hwbuf));
if (err != DS_OK)
WARN("IDsDriver_CreateSoundBuffer failed\n");
} else {
WARN("waveOutOpen failed\n");
}
} else if (err != DS_OK) {
WARN("IDsDriverBuffer_Stop failed\n");
}
}
else
} else {
err = mmErr(waveOutPause(This->hwo));
if (err != DS_OK)
WARN("waveOutPause failed\n");
}
return err;
}
@ -251,7 +276,10 @@ HRESULT DSOUND_PrimaryGetPosition(IDirectSoundImpl *This, LPDWORD playpos, LPDWO
if (This->hwbuf) {
HRESULT err=IDsDriverBuffer_GetPosition(This->hwbuf,playpos,writepos);
if (err) return err;
if (err) {
WARN("IDsDriverBuffer_GetPosition failed\n");
return err;
}
}
else {
if (playpos) {
@ -290,13 +318,13 @@ static HRESULT WINAPI PrimaryBufferImpl_SetFormat(
TRACE("(%p,%p)\n",This,wfex);
if (This->dsound->priolevel == DSSCL_NORMAL) {
TRACE("failed priority check!\n");
WARN("failed priority check!\n");
return DSERR_PRIOLEVELNEEDED;
}
/* Let's be pedantic! */
if (wfex == NULL) {
TRACE("wfex==NULL!\n");
WARN("invalid parameter: wfex==NULL!\n");
return DSERR_INVALIDPARAM;
}
TRACE("(formattag=0x%04x,chans=%d,samplerate=%ld,"
@ -309,7 +337,7 @@ static HRESULT WINAPI PrimaryBufferImpl_SetFormat(
(wfex->nChannels < 1) || (wfex->nChannels > 2) ||
(wfex->nSamplesPerSec < 1) ||
((wfex->wBitsPerSample != 8) && (wfex->wBitsPerSample != 16))) {
TRACE("unsupported format!\n");
WARN("invalid paramemer: unsupported format!\n");
return DSERR_INVALIDPARAM;
}
@ -348,8 +376,18 @@ static HRESULT WINAPI PrimaryBufferImpl_SetFormat(
err = mmErr(waveOutOpen(&(dsound->hwo), dsound->drvdesc.dnDevNode,
&(dsound->wfx), (DWORD)DSOUND_callback, (DWORD)dsound,
flags));
if (err == DS_OK)
DSOUND_PrimaryOpen(dsound);
if (err == DS_OK) {
err = DSOUND_PrimaryOpen(dsound);
if (err != DS_OK) {
WARN("DSOUND_PrimaryOpen failed\n");
RtlReleaseResource(&(dsound->lock));
return err;
}
} else {
WARN("waveOutOpen failed\n");
RtlReleaseResource(&(dsound->lock));
return err;
}
}
if (dsound->hwbuf) {
err = IDsDriverBuffer_SetFormat(dsound->hwbuf, &(dsound->wfx));
@ -360,8 +398,17 @@ static HRESULT WINAPI PrimaryBufferImpl_SetFormat(
DSBCAPS_PRIMARYBUFFER,0,
&(dsound->buflen),&(dsound->buffer),
(LPVOID)&(dsound->hwbuf));
if (err != DS_OK) {
WARN("IDsDriver_CreateSoundBuffer failed\n");
RtlReleaseResource(&(dsound->lock));
return err;
}
if (dsound->state == STATE_PLAYING) dsound->state = STATE_STARTING;
else if (dsound->state == STATE_STOPPING) dsound->state = STATE_STOPPED;
} else {
WARN("IDsDriverBuffer_SetFormat failed\n");
RtlReleaseResource(&(dsound->lock));
return err;
}
/* FIXME: should we set err back to DS_OK in all cases ? */
}
@ -383,11 +430,15 @@ static HRESULT WINAPI PrimaryBufferImpl_SetVolume(
TRACE("(%p,%ld)\n",This,vol);
/* I'm not sure if we need this for primary buffer */
if (!(This->dsbd.dwFlags & DSBCAPS_CTRLVOLUME))
if (!(This->dsbd.dwFlags & DSBCAPS_CTRLVOLUME)) {
WARN("control unavailable\n");
return DSERR_CONTROLUNAVAIL;
}
if ((vol > DSBVOLUME_MAX) || (vol < DSBVOLUME_MIN))
if ((vol > DSBVOLUME_MAX) || (vol < DSBVOLUME_MIN)) {
WARN("invalid parameter: vol = %ld\n", vol);
return DSERR_INVALIDPARAM;
}
/* **** */
EnterCriticalSection(&(dsound->mixlock));
@ -398,7 +449,13 @@ static HRESULT WINAPI PrimaryBufferImpl_SetVolume(
if (vol != oldVol) {
if (dsound->hwbuf) {
IDsDriverBuffer_SetVolumePan(dsound->hwbuf, &(dsound->volpan));
HRESULT hres;
hres = IDsDriverBuffer_SetVolumePan(dsound->hwbuf, &(dsound->volpan));
if (hres != DS_OK) {
LeaveCriticalSection(&(dsound->mixlock));
WARN("IDsDriverBuffer_SetVolumePan failed\n");
return hres;
}
}
else {
#if 0 /* should we really do this? */
@ -423,8 +480,10 @@ static HRESULT WINAPI PrimaryBufferImpl_GetVolume(
ICOM_THIS(PrimaryBufferImpl,iface);
TRACE("(%p,%p)\n",This,vol);
if (vol == NULL)
if (vol == NULL) {
WARN("invalid parameter: vol = NULL\n");
return DSERR_INVALIDPARAM;
}
*vol = This->dsound->volpan.lVolume;
return DS_OK;
@ -438,6 +497,7 @@ static HRESULT WINAPI PrimaryBufferImpl_SetFrequency(
TRACE("(%p,%ld)\n",This,freq);
/* You cannot set the frequency of the primary buffer */
WARN("control unavailable\n");
return DSERR_CONTROLUNAVAIL;
}
@ -451,8 +511,10 @@ static HRESULT WINAPI PrimaryBufferImpl_Play(
This,reserved1,reserved2,flags
);
if (!(flags & DSBPLAY_LOOPING))
if (!(flags & DSBPLAY_LOOPING)) {
WARN("invalid parameter: flags = %08lx\n", flags);
return DSERR_INVALIDPARAM;
}
/* **** */
EnterCriticalSection(&(dsound->mixlock));
@ -508,29 +570,40 @@ static DWORD WINAPI PrimaryBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface) {
TRACE("(%p) ref was %ld, thread is %lx\n",This, This->ref, GetCurrentThreadId());
ref = InterlockedDecrement(&(This->ref));
if (ref) return ref;
IDirectSound_Release((LPDIRECTSOUND)This->dsound);
/* the listener has a reference to us which must be removed */
if ((ref == 0) || ((ref == 1) && (This->dsound->listener))) {
IDirectSound_Release((LPDIRECTSOUND)This->dsound);
if (This->dsound->listener) {
IDirectSound3DListener_Release((LPDIRECTSOUND3DLISTENER)This->dsound->listener);
This->dsound->listener = NULL;
ref--;
}
#if 0
if (This->iks) {
HeapFree(GetProcessHeap(), 0, This->iks);
}
if (This->iks) {
HeapFree(GetProcessHeap(), 0, This->iks);
}
#endif
HeapFree(GetProcessHeap(),0,This);
}
HeapFree(GetProcessHeap(),0,This);
return 0;
return ref;
}
static HRESULT WINAPI PrimaryBufferImpl_GetCurrentPosition(
LPDIRECTSOUNDBUFFER8 iface,LPDWORD playpos,LPDWORD writepos
) {
HRESULT hres;
ICOM_THIS(PrimaryBufferImpl,iface);
IDirectSoundImpl* dsound = This->dsound;
TRACE("(%p,%p,%p)\n",This,playpos,writepos);
DSOUND_PrimaryGetPosition(dsound, playpos, writepos);
hres = DSOUND_PrimaryGetPosition(dsound, playpos, writepos);
if (hres != DS_OK) {
WARN("DSOUND_PrimaryGetPosition failed\n");
return hres;
}
if (writepos) {
if (dsound->state != STATE_STOPPED)
/* apply the documented 10ms lead to writepos */
@ -547,8 +620,10 @@ static HRESULT WINAPI PrimaryBufferImpl_GetStatus(
ICOM_THIS(PrimaryBufferImpl,iface);
TRACE("(%p,%p), thread is %lx\n",This,status,GetCurrentThreadId());
if (status == NULL)
if (status == NULL) {
WARN("invalid parameter: status == NULL\n");
return DSERR_INVALIDPARAM;
}
*status = 0;
if ((This->dsound->state == STATE_STARTING) ||
@ -572,11 +647,14 @@ static HRESULT WINAPI PrimaryBufferImpl_GetFormat(
memcpy(lpwf,&(This->dsound->wfx),wfsize);
if (wfwritten)
*wfwritten = wfsize;
} else
} else {
if (wfwritten)
*wfwritten = sizeof(This->dsound->wfx);
else
else {
WARN("invalid parameter: wfwritten == NULL\n");
return DSERR_INVALIDPARAM;
}
}
return DS_OK;
}
@ -599,13 +677,20 @@ static HRESULT WINAPI PrimaryBufferImpl_Lock(
GetTickCount()
);
if (dsound->priolevel != DSSCL_WRITEPRIMARY)
if (dsound->priolevel != DSSCL_WRITEPRIMARY) {
WARN("failed priority check!\n");
return DSERR_PRIOLEVELNEEDED;
}
if (flags & DSBLOCK_FROMWRITECURSOR) {
DWORD writepos;
HRESULT hres;
/* GetCurrentPosition does too much magic to duplicate here */
IDirectSoundBuffer_GetCurrentPosition(iface, NULL, &writepos);
hres = IDirectSoundBuffer_GetCurrentPosition(iface, NULL, &writepos);
if (hres != DS_OK) {
WARN("IDirectSoundBuffer_GetCurrentPosition failed\n");
return hres;
}
writecursor += writepos;
}
while (writecursor >= dsound->buflen)
@ -619,13 +704,17 @@ static HRESULT WINAPI PrimaryBufferImpl_Lock(
assert(lplpaudioptr1!=lplpaudioptr2);
if (!(dsound->drvdesc.dwFlags & DSDDESC_DONTNEEDPRIMARYLOCK) && dsound->hwbuf) {
IDsDriverBuffer_Lock(dsound->hwbuf,
lplpaudioptr1, audiobytes1,
lplpaudioptr2, audiobytes2,
writecursor, writebytes,
0);
}
else {
HRESULT hres;
hres = IDsDriverBuffer_Lock(dsound->hwbuf,
lplpaudioptr1, audiobytes1,
lplpaudioptr2, audiobytes2,
writecursor, writebytes,
0);
if (hres != DS_OK) {
WARN("IDsDriverBuffer_Lock failed\n");
return hres;
}
} else {
if (writecursor+writebytes <= dsound->buflen) {
*(LPBYTE*)lplpaudioptr1 = dsound->buffer+writecursor;
*audiobytes1 = writebytes;
@ -654,6 +743,7 @@ static HRESULT WINAPI PrimaryBufferImpl_SetCurrentPosition(
TRACE("(%p,%ld)\n",This,newpos);
/* You cannot set the position of the primary buffer */
WARN("invalid call\n");
return DSERR_INVALIDCALL;
}
@ -664,6 +754,7 @@ static HRESULT WINAPI PrimaryBufferImpl_SetPan(
TRACE("(%p,%ld)\n",This,pan);
/* You cannot set the pan of the primary buffer */
WARN("control unavailable\n");
return DSERR_CONTROLUNAVAIL;
}
@ -673,8 +764,10 @@ static HRESULT WINAPI PrimaryBufferImpl_GetPan(
ICOM_THIS(PrimaryBufferImpl,iface);
TRACE("(%p,%p)\n",This,pan);
if (pan == NULL)
if (pan == NULL) {
WARN("invalid parameter: pan == NULL\n");
return DSERR_INVALIDPARAM;
}
*pan = This->dsound->volpan.lPan;
@ -689,11 +782,19 @@ static HRESULT WINAPI PrimaryBufferImpl_Unlock(
TRACE("(%p,%p,%ld,%p,%ld):stub\n", This,p1,x1,p2,x2);
if (dsound->priolevel != DSSCL_WRITEPRIMARY)
if (dsound->priolevel != DSSCL_WRITEPRIMARY) {
WARN("failed priority check!\n");
return DSERR_PRIOLEVELNEEDED;
}
if (!(dsound->drvdesc.dwFlags & DSDDESC_DONTNEEDPRIMARYLOCK) && dsound->hwbuf) {
IDsDriverBuffer_Unlock(dsound->hwbuf, p1, x1, p2, x2);
HRESULT hres;
hres = IDsDriverBuffer_Unlock(dsound->hwbuf, p1, x1, p2, x2);
if (hres != DS_OK) {
WARN("IDsDriverBuffer_Unlock failed\n");
return hres;
}
}
return DS_OK;
@ -713,8 +814,10 @@ static HRESULT WINAPI PrimaryBufferImpl_GetFrequency(
ICOM_THIS(PrimaryBufferImpl,iface);
TRACE("(%p,%p)\n",This,freq);
if (freq == NULL)
if (freq == NULL) {
WARN("invalid parameter: freq == NULL\n");
return DSERR_INVALIDPARAM;
}
*freq = This->dsound->wfx.nSamplesPerSec;
TRACE("-> %ld\n", *freq);
@ -733,6 +836,7 @@ static HRESULT WINAPI PrimaryBufferImpl_SetFX(
if (pdwResultCodes)
for (u=0; u<dwEffectsCount; u++) pdwResultCodes[u] = DSFXR_UNKNOWN;
WARN("control unavailable\n");
return DSERR_CONTROLUNAVAIL;
}
@ -747,6 +851,7 @@ static HRESULT WINAPI PrimaryBufferImpl_AcquireResources(
if (pdwResultCodes)
for (u=0; u<dwEffectsCount; u++) pdwResultCodes[u] = DSFXR_UNKNOWN;
WARN("control unavailable\n");
return DSERR_CONTROLUNAVAIL;
}
@ -757,6 +862,7 @@ static HRESULT WINAPI PrimaryBufferImpl_GetObjectInPath(
FIXME("(%p,%s,%lu,%s,%p): stub\n",This,debugstr_guid(rguidObject),dwIndex,debugstr_guid(rguidInterface),ppObject);
WARN("control unavailable\n");
return DSERR_CONTROLUNAVAIL;
}
@ -766,6 +872,7 @@ static HRESULT WINAPI PrimaryBufferImpl_Initialize(
ICOM_THIS(PrimaryBufferImpl,iface);
FIXME("(%p,%p,%p):stub\n",This,dsound,dbsd);
DPRINTF("Re-Init!!!\n");
WARN("already initialized\n");
return DSERR_ALREADYINITIALIZED;
}
@ -775,8 +882,15 @@ static HRESULT WINAPI PrimaryBufferImpl_GetCaps(
ICOM_THIS(PrimaryBufferImpl,iface);
TRACE("(%p)->(%p)\n",This,caps);
if (caps == NULL || caps->dwSize!=sizeof(*caps))
if (caps == NULL) {
WARN("invalid parameter: caps == NULL\n");
return DSERR_INVALIDPARAM;
}
if (caps->dwSize < sizeof(*caps)) {
WARN("invalid parameter: caps->dwSize = %ld: < %d\n", caps->dwSize, sizeof(*caps));
return DSERR_INVALIDPARAM;
}
caps->dwFlags = This->dsbd.dwFlags;
if (This->dsound->hwbuf) caps->dwFlags |= DSBCAPS_LOCHARDWARE;
@ -803,7 +917,7 @@ static HRESULT WINAPI PrimaryBufferImpl_QueryInterface(
if ( IsEqualGUID( &IID_IDirectSoundNotify, riid ) ) {
ERR("app requested IDirectSoundNotify on primary buffer\n");
/* should we support this? */
/* FIXME: should we support this? */
*ppobj = NULL;
return E_FAIL;
}
@ -822,6 +936,8 @@ static HRESULT WINAPI PrimaryBufferImpl_QueryInterface(
IDirectSound3DListener_AddRef((LPDIRECTSOUND3DLISTENER)*ppobj);
return DS_OK;
}
WARN("IID_IDirectSound3DListener failed\n");
*ppobj = NULL;
return E_FAIL;
}
@ -887,10 +1003,20 @@ HRESULT WINAPI PrimaryBuffer_Create(
TRACE("%p,%p,%p)\n",This,pdsb,dsbd);
if (dsbd->lpwfxFormat)
if (dsbd->lpwfxFormat) {
WARN("invalid parameter: dsbd->lpwfxFormat != NULL\n");
*pdsb = NULL;
return DSERR_INVALIDPARAM;
}
dsb = (PrimaryBufferImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*dsb));
if (dsb == NULL) {
WARN("out of memory\n");
*pdsb = NULL;
return DSERR_OUTOFMEMORY;
}
dsb->ref = 1;
dsb->dsound = This;
dsb->lpVtbl = &dspbvt;
@ -905,7 +1031,13 @@ HRESULT WINAPI PrimaryBuffer_Create(
This->wfx.wBitsPerSample, This->wfx.cbSize);
if (dsbd->dwFlags & DSBCAPS_CTRL3D) {
/* FIXME: IDirectSound3DListener */
HRESULT hres;
hres = IDirectSound3DListenerImpl_Create(dsb, &This->listener);
if (hres != DS_OK) {
WARN("IDirectSound3DListenerImpl_Create failed\n");
} else {
IDirectSound3DListener_AddRef((LPDIRECTSOUND3DLISTENER)This->listener);
}
}
IDirectSound8_AddRef((LPDIRECTSOUND8)This);

View File

@ -68,6 +68,7 @@ static ULONG WINAPI IKsPropertySetImpl_AddRef(LPKSPROPERTYSET iface) {
ICOM_THIS(IKsPropertySetImpl,iface);
ULONG ulReturn;
TRACE("(%p) ref was %ld\n", This, This->ref);
ulReturn = InterlockedIncrement(&This->ref);
if (ulReturn == 1)
IDirectSoundBuffer_AddRef((LPDIRECTSOUND3DBUFFER)This->dsb);
@ -78,6 +79,7 @@ static ULONG WINAPI IKsPropertySetImpl_Release(LPKSPROPERTYSET iface) {
ICOM_THIS(IKsPropertySetImpl,iface);
ULONG ulReturn;
TRACE("(%p) ref was %ld\n", This, This->ref);
ulReturn = InterlockedDecrement(&This->ref);
if (ulReturn)
return ulReturn;

View File

@ -187,7 +187,8 @@ static inline D3DVALUE ProjectVector (LPD3DVECTOR a, LPD3DVECTOR p)
static void WINAPI DSOUND_Mix3DBuffer(IDirectSound3DBufferImpl *ds3db)
{
IDirectSound3DListenerImpl *dsl;
TRACE("(%p)\n",ds3db);
/* volume, at which the sound will be played after all calcs. */
D3DVALUE lVolume = 0;
/* intensity (used for distance related stuff) */
@ -333,6 +334,7 @@ static void WINAPI DSOUND_Mix3DBuffer(IDirectSound3DBufferImpl *ds3db)
static void WINAPI DSOUND_ChangeListener(IDirectSound3DListenerImpl *ds3dl)
{
int i;
TRACE("(%p)\n",ds3dl);
for (i = 0; i < ds3dl->dsb->dsound->nrofbuffers; i++)
{
/* some buffers don't have 3d buffer (Ultima IX seems to
@ -687,8 +689,15 @@ HRESULT WINAPI IDirectSound3DBufferImpl_Create(
IDirectSound3DBufferImpl **pds3db)
{
IDirectSound3DBufferImpl *ds3db;
TRACE("(%p,%p)\n",This,pds3db);
ds3db = (IDirectSound3DBufferImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*ds3db));
if (ds3db == NULL) {
WARN("out of memory\n");
return DSERR_OUTOFMEMORY;
}
ds3db = (IDirectSound3DBufferImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(*ds3db));
ds3db->ref = 0;
ds3db->dsb = This;
ds3db->lpVtbl = &ds3dbvt;
@ -732,6 +741,7 @@ static HRESULT WINAPI IDirectSound3DListenerImpl_QueryInterface(
static ULONG WINAPI IDirectSound3DListenerImpl_AddRef(LPDIRECTSOUND3DLISTENER iface)
{
ICOM_THIS(IDirectSound3DListenerImpl,iface);
TRACE("(%p) ref was %ld\n", This, This->ref);
return InterlockedIncrement(&This->ref);
}
@ -1000,8 +1010,15 @@ HRESULT WINAPI IDirectSound3DListenerImpl_Create(
IDirectSound3DListenerImpl **pdsl)
{
IDirectSound3DListenerImpl *dsl;
TRACE("(%p,%p)\n",This,pdsl);
dsl = (IDirectSound3DListenerImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*dsl));
if (dsl == NULL) {
WARN("out of memory\n");
return DSERR_OUTOFMEMORY;
}
dsl = (IDirectSound3DListenerImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(*dsl));
dsl->ref = 1;
dsl->lpVtbl = &ds3dlvt;