From 074d631200f21c9265ac1db56be76410b40f195c Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 1 Aug 2011 23:33:02 -0700 Subject: [PATCH] Add a IDirectSoundBuffer vtable and remove some unsightly casts --- buffer.c | 165 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- dsound8.c | 4 +- dsound_private.h | 1 + duplex.c | 28 +++++++--- primary.c | 6 +- 5 files changed, 186 insertions(+), 18 deletions(-) diff --git a/buffer.c b/buffer.c index 9fed10b..54d467b 100644 --- a/buffer.c +++ b/buffer.c @@ -76,6 +76,7 @@ DEFINE_GUID(KSDATAFORMAT_SUBTYPE_IEEE_FLOAT, 0x00000003, 0x0000, 0x0010, 0x80, 0 * DSERR_BUFFERLOST */ static const IDirectSoundBuffer8Vtbl DS8Buffer_Vtbl; +static const IDirectSoundBufferVtbl DSBuffer_Vtbl; static const IDirectSound3DBufferVtbl DS8Buffer3d_Vtbl; static const IDirectSoundNotifyVtbl DS8BufferNot_Vtbl; static const IKsPropertySetVtbl DS8BufferProp_Vtbl; @@ -85,10 +86,10 @@ static inline DS8Buffer *impl_from_IDirectSoundBuffer8(IDirectSoundBuffer8 *ifac { return CONTAINING_RECORD(iface, DS8Buffer, IDirectSoundBuffer8_iface); } -/* Shares the same vtable */ + static inline DS8Buffer *impl_from_IDirectSoundBuffer(IDirectSoundBuffer *iface) { - return CONTAINING_RECORD(iface, DS8Buffer, IDirectSoundBuffer8_iface); + return CONTAINING_RECORD(iface, DS8Buffer, IDirectSoundBuffer_iface); } static inline DS8Buffer *impl_from_IDirectSound3DBuffer(IDirectSound3DBuffer *iface) @@ -850,6 +851,7 @@ HRESULT DS8Buffer_Create(DS8Buffer **ppv, DS8Primary *prim, IDirectSoundBuffer * if(!This) return DSERR_OUTOFMEMORY; This->IDirectSoundBuffer8_iface.lpVtbl = (IDirectSoundBuffer8Vtbl*)&DS8Buffer_Vtbl; + This->IDirectSoundBuffer_iface.lpVtbl = (IDirectSoundBufferVtbl*)&DSBuffer_Vtbl; This->IDirectSound3DBuffer_iface.lpVtbl = (IDirectSound3DBufferVtbl*)&DS8Buffer3d_Vtbl; This->IDirectSoundNotify_iface.lpVtbl = (IDirectSoundNotifyVtbl*)&DS8BufferNot_Vtbl; This->IKsPropertySet_iface.lpVtbl = (IKsPropertySetVtbl*)&DS8BufferProp_Vtbl; @@ -965,9 +967,10 @@ static HRESULT WINAPI DS8Buffer_QueryInterface(IDirectSoundBuffer8 *iface, REFII TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv); *ppv = NULL; - if(IsEqualIID(riid, &IID_IUnknown) || - IsEqualIID(riid, &IID_IDirectSoundBuffer)) + if(IsEqualIID(riid, &IID_IUnknown)) *ppv = &This->IDirectSoundBuffer8_iface; + else if(IsEqualIID(riid, &IID_IDirectSoundBuffer)) + *ppv = &This->IDirectSoundBuffer_iface; else if(IsEqualIID(riid, &IID_IDirectSoundBuffer8)) { if(This->primary->parent->is_8) @@ -1927,8 +1930,7 @@ static HRESULT WINAPI DS8Buffer_GetObjectInPath(IDirectSoundBuffer8 *iface, REFG return E_NOTIMPL; } -static const IDirectSoundBuffer8Vtbl DS8Buffer_Vtbl = -{ +static const IDirectSoundBuffer8Vtbl DS8Buffer_Vtbl = { DS8Buffer_QueryInterface, DS8Buffer_AddRef, DS8Buffer_Release, @@ -1956,6 +1958,157 @@ static const IDirectSoundBuffer8Vtbl DS8Buffer_Vtbl = }; +static HRESULT WINAPI DSBuffer_QueryInterface(IDirectSoundBuffer *iface, REFIID riid, void **ppv) +{ + DS8Buffer *This = impl_from_IDirectSoundBuffer(iface); + return DS8Buffer_QueryInterface(&This->IDirectSoundBuffer8_iface, riid, ppv); +} + +static ULONG WINAPI DSBuffer_AddRef(IDirectSoundBuffer *iface) +{ + DS8Buffer *This = impl_from_IDirectSoundBuffer(iface); + return DS8Buffer_AddRef(&This->IDirectSoundBuffer8_iface); +} + +static ULONG WINAPI DSBuffer_Release(IDirectSoundBuffer *iface) +{ + DS8Buffer *This = impl_from_IDirectSoundBuffer(iface); + return DS8Buffer_Release(&This->IDirectSoundBuffer8_iface); +} + +static HRESULT WINAPI DSBuffer_GetCaps(IDirectSoundBuffer *iface, DSBCAPS *caps) +{ + DS8Buffer *This = impl_from_IDirectSoundBuffer(iface); + return DS8Buffer_GetCaps(&This->IDirectSoundBuffer8_iface, caps); +} + +static HRESULT WINAPI DSBuffer_GetCurrentPosition(IDirectSoundBuffer *iface, DWORD *playpos, DWORD *curpos) +{ + DS8Buffer *This = impl_from_IDirectSoundBuffer(iface); + return DS8Buffer_GetCurrentPosition(&This->IDirectSoundBuffer8_iface, playpos, curpos); +} + +static HRESULT WINAPI DSBuffer_GetFormat(IDirectSoundBuffer *iface, WAVEFORMATEX *wfx, DWORD allocated, DWORD *written) +{ + DS8Buffer *This = impl_from_IDirectSoundBuffer(iface); + return DS8Buffer_GetFormat(&This->IDirectSoundBuffer8_iface, wfx, allocated, written); +} + +static HRESULT WINAPI DSBuffer_GetVolume(IDirectSoundBuffer *iface, LONG *vol) +{ + DS8Buffer *This = impl_from_IDirectSoundBuffer(iface); + return DS8Buffer_GetVolume(&This->IDirectSoundBuffer8_iface, vol); +} + +static HRESULT WINAPI DSBuffer_GetPan(IDirectSoundBuffer *iface, LONG *pan) +{ + DS8Buffer *This = impl_from_IDirectSoundBuffer(iface); + return DS8Buffer_GetPan(&This->IDirectSoundBuffer8_iface, pan); +} + +static HRESULT WINAPI DSBuffer_GetFrequency(IDirectSoundBuffer *iface, DWORD *freq) +{ + DS8Buffer *This = impl_from_IDirectSoundBuffer(iface); + return DS8Buffer_GetFrequency(&This->IDirectSoundBuffer8_iface, freq); +} + +static HRESULT WINAPI DSBuffer_GetStatus(IDirectSoundBuffer *iface, DWORD *status) +{ + DS8Buffer *This = impl_from_IDirectSoundBuffer(iface); + return DS8Buffer_GetStatus(&This->IDirectSoundBuffer8_iface, status); +} + +static HRESULT WINAPI DSBuffer_Initialize(IDirectSoundBuffer *iface, IDirectSound *ds, const DSBUFFERDESC *desc) +{ + DS8Buffer *This = impl_from_IDirectSoundBuffer(iface); + return DS8Buffer_Initialize(&This->IDirectSoundBuffer8_iface, ds, desc); +} + +static HRESULT WINAPI DSBuffer_Lock(IDirectSoundBuffer *iface, DWORD ofs, DWORD bytes, void **ptr1, DWORD *len1, void **ptr2, DWORD *len2, DWORD flags) +{ + DS8Buffer *This = impl_from_IDirectSoundBuffer(iface); + return DS8Buffer_Lock(&This->IDirectSoundBuffer8_iface, ofs, bytes, ptr1, len1, ptr2, len2, flags); +} + +static HRESULT WINAPI DSBuffer_Play(IDirectSoundBuffer *iface, DWORD res1, DWORD prio, DWORD flags) +{ + DS8Buffer *This = impl_from_IDirectSoundBuffer(iface); + return DS8Buffer_Play(&This->IDirectSoundBuffer8_iface, res1, prio, flags); +} + +static HRESULT WINAPI DSBuffer_SetCurrentPosition(IDirectSoundBuffer *iface, DWORD pos) +{ + DS8Buffer *This = impl_from_IDirectSoundBuffer(iface); + return DS8Buffer_SetCurrentPosition(&This->IDirectSoundBuffer8_iface, pos); +} + +static HRESULT WINAPI DSBuffer_SetFormat(IDirectSoundBuffer *iface, const WAVEFORMATEX *wfx) +{ + DS8Buffer *This = impl_from_IDirectSoundBuffer(iface); + return DS8Buffer_SetFormat(&This->IDirectSoundBuffer8_iface, wfx); +} + +static HRESULT WINAPI DSBuffer_SetVolume(IDirectSoundBuffer *iface, LONG vol) +{ + DS8Buffer *This = impl_from_IDirectSoundBuffer(iface); + return DS8Buffer_SetVolume(&This->IDirectSoundBuffer8_iface, vol); +} + +static HRESULT WINAPI DSBuffer_SetPan(IDirectSoundBuffer *iface, LONG pan) +{ + DS8Buffer *This = impl_from_IDirectSoundBuffer(iface); + return DS8Buffer_SetPan(&This->IDirectSoundBuffer8_iface, pan); +} + +static HRESULT WINAPI DSBuffer_SetFrequency(IDirectSoundBuffer *iface, DWORD freq) +{ + DS8Buffer *This = impl_from_IDirectSoundBuffer(iface); + return DS8Buffer_SetFrequency(&This->IDirectSoundBuffer8_iface, freq); +} + +static HRESULT WINAPI DSBuffer_Stop(IDirectSoundBuffer *iface) +{ + DS8Buffer *This = impl_from_IDirectSoundBuffer(iface); + return DS8Buffer_Stop(&This->IDirectSoundBuffer8_iface); +} + +static HRESULT WINAPI DSBuffer_Unlock(IDirectSoundBuffer *iface, void *ptr1, DWORD len1, void *ptr2, DWORD len2) +{ + DS8Buffer *This = impl_from_IDirectSoundBuffer(iface); + return DS8Buffer_Unlock(&This->IDirectSoundBuffer8_iface, ptr1, len1, ptr2, len2); +} + +static HRESULT WINAPI DSBuffer_Restore(IDirectSoundBuffer *iface) +{ + DS8Buffer *This = impl_from_IDirectSoundBuffer(iface); + return DS8Buffer_Restore(&This->IDirectSoundBuffer8_iface); +} + +static const IDirectSoundBufferVtbl DSBuffer_Vtbl = { + DSBuffer_QueryInterface, + DSBuffer_AddRef, + DSBuffer_Release, + DSBuffer_GetCaps, + DSBuffer_GetCurrentPosition, + DSBuffer_GetFormat, + DSBuffer_GetVolume, + DSBuffer_GetPan, + DSBuffer_GetFrequency, + DSBuffer_GetStatus, + DSBuffer_Initialize, + DSBuffer_Lock, + DSBuffer_Play, + DSBuffer_SetCurrentPosition, + DSBuffer_SetFormat, + DSBuffer_SetVolume, + DSBuffer_SetPan, + DSBuffer_SetFrequency, + DSBuffer_Stop, + DSBuffer_Unlock, + DSBuffer_Restore +}; + + static HRESULT WINAPI DS8Buffer3D_QueryInterface(IDirectSound3DBuffer *iface, REFIID riid, void **ppv) { DS8Buffer *This = impl_from_IDirectSound3DBuffer(iface); diff --git a/dsound8.c b/dsound8.c index db4f1c0..29188a9 100644 --- a/dsound8.c +++ b/dsound8.c @@ -342,7 +342,7 @@ static HRESULT WINAPI DS8_CreateSoundBuffer(IDirectSound8 *iface, LPCDSBUFFERDES else { dsb->bufferlost = (This->prio_level == DSSCL_WRITEPRIMARY); - *buf = (IDirectSoundBuffer*)&dsb->IDirectSoundBuffer8_iface; + *buf = &dsb->IDirectSoundBuffer_iface; } } } @@ -452,7 +452,7 @@ static HRESULT WINAPI DS8_DuplicateSoundBuffer(IDirectSound8 *iface, IDirectSoun hr = DS8Buffer_Create(&buf, This->primary, in); if(SUCCEEDED(hr)) { - *out = (IDirectSoundBuffer*)&buf->IDirectSoundBuffer8_iface; + *out = &buf->IDirectSoundBuffer_iface; hr = IDirectSoundBuffer_Initialize(*out, NULL, NULL); } if(SUCCEEDED(hr)) diff --git a/dsound_private.h b/dsound_private.h index 8593901..9aca216 100644 --- a/dsound_private.h +++ b/dsound_private.h @@ -482,6 +482,7 @@ typedef struct DS8Data { struct DS8Buffer { IDirectSoundBuffer8 IDirectSoundBuffer8_iface; + IDirectSoundBuffer IDirectSoundBuffer_iface; IDirectSound3DBuffer IDirectSound3DBuffer_iface; IDirectSoundNotify IDirectSoundNotify_iface; IKsPropertySet IKsPropertySet_iface; diff --git a/duplex.c b/duplex.c index 865244d..960224c 100644 --- a/duplex.c +++ b/duplex.c @@ -395,7 +395,9 @@ static HRESULT WINAPI IDirectSoundFullDuplexImpl_Initialize( IDirectSoundBuffer8 **lplpDirectSoundBuffer8) { IDirectSoundFullDuplexImpl *This = impl_from_IDirectSoundFullDuplex(iface); - void *device; + IDirectSoundCaptureBuffer *capbuffer; + IDirectSoundBuffer *buffer; + void *ptr; HRESULT hr; TRACE("(%p,%s,%s,%p,%p,%p,%x,%p,%p)\n", This, @@ -412,10 +414,10 @@ static HRESULT WINAPI IDirectSoundFullDuplexImpl_Initialize( return DSERR_ALREADYINITIALIZED; } - hr = DSOUND_Create8(&IID_IDirectSound8, &device); + hr = DSOUND_Create8(&IID_IDirectSound8, &ptr); if(SUCCEEDED(hr)) { - This->renderer_device = device; + This->renderer_device = ptr; hr = IDirectSound_Initialize(This->renderer_device, pRendererGuid); } if(hr != DS_OK) @@ -427,17 +429,23 @@ static HRESULT WINAPI IDirectSoundFullDuplexImpl_Initialize( IDirectSound8_SetCooperativeLevel(This->renderer_device, hWnd, dwLevel); hr = IDirectSound8_CreateSoundBuffer(This->renderer_device, lpDsBufferDesc, - (IDirectSoundBuffer**)lplpDirectSoundBuffer8, NULL); + &buffer, NULL); + if(SUCCEEDED(hr)) + { + hr = IDirectSoundBuffer_QueryInterface(buffer, &IID_IDirectSoundBuffer8, &ptr); + IDirectSoundBuffer_Release(buffer); + } if(hr != DS_OK) { WARN("IDirectSoundBufferImpl_Create() failed\n"); return hr; } + *lplpDirectSoundBuffer8 = ptr; - hr = DSOUND_CaptureCreate8(&IID_IDirectSoundCapture8, &device); + hr = DSOUND_CaptureCreate8(&IID_IDirectSoundCapture8, &ptr); if(SUCCEEDED(hr)) { - This->capture_device = device; + This->capture_device = ptr; hr = IDirectSoundCapture_Initialize(This->capture_device, pCaptureGuid); } if(hr != DS_OK) @@ -447,12 +455,18 @@ static HRESULT WINAPI IDirectSoundFullDuplexImpl_Initialize( } hr = IDirectSoundCapture_CreateCaptureBuffer(This->capture_device, lpDscBufferDesc, - (IDirectSoundCaptureBuffer**)lplpDirectSoundCaptureBuffer8, NULL); + &capbuffer, NULL); + if(SUCCEEDED(hr)) + { + hr = IDirectSoundCaptureBuffer_QueryInterface(capbuffer, &IID_IDirectSoundCaptureBuffer8, &ptr); + IDirectSoundCaptureBuffer_Release(capbuffer); + } if(hr != DS_OK) { WARN("IDirectSoundCaptureBufferImpl_Create() failed\n"); return hr; } + *lplpDirectSoundCaptureBuffer8 = ptr; return hr; } diff --git a/primary.c b/primary.c index 9f896fd..1f5087c 100644 --- a/primary.c +++ b/primary.c @@ -664,7 +664,7 @@ static HRESULT WINAPI DS8Primary_GetStatus(IDirectSoundBuffer *iface, DWORD *sta for(i = 0;i < This->nbuffers;++i) { - hr = IDirectSoundBuffer_GetStatus((IDirectSoundBuffer*)This->buffers[i], &state); + hr = IDirectSoundBuffer8_GetStatus(&This->buffers[i]->IDirectSoundBuffer8_iface, &state); if(SUCCEEDED(hr) && (state&DSBSTATUS_PLAYING)) break; } @@ -1065,7 +1065,7 @@ static inline DS8Primary *impl_from_IDirectSound3DListener(IDirectSound3DListene static HRESULT WINAPI DS8Primary3D_QueryInterface(IDirectSound3DListener *iface, REFIID riid, void **ppv) { DS8Primary *This = impl_from_IDirectSound3DListener(iface); - return IDirectSoundBuffer_QueryInterface((IDirectSoundBuffer*)This, riid, ppv); + return DS8Primary_QueryInterface(&This->IDirectSoundBuffer_iface, riid, ppv); } static ULONG WINAPI DS8Primary3D_AddRef(IDirectSound3DListener *iface) @@ -1656,7 +1656,7 @@ static inline DS8Primary *impl_from_IKsPropertySet(IKsPropertySet *iface) static HRESULT WINAPI DS8PrimaryProp_QueryInterface(IKsPropertySet *iface, REFIID riid, void **ppv) { DS8Primary *This = impl_from_IKsPropertySet(iface); - return IDirectSoundBuffer_QueryInterface((IDirectSoundBuffer*)This, riid, ppv); + return DS8Primary_QueryInterface(&This->IDirectSoundBuffer_iface, riid, ppv); } static ULONG WINAPI DS8PrimaryProp_AddRef(IKsPropertySet *iface) -- 2.11.4.GIT