[PATCH 5/6] dsound: Simplify duplex code

Maarten Lankhorst (none) mlankhorst at patser.
Sat Nov 14 09:18:02 CST 2009


---
 dlls/dsound/capture.c        |   13 +-
 dlls/dsound/dsound_private.h |   16 --
 dlls/dsound/duplex.c         |  433 ++++++++++-------------------------------
 3 files changed, 115 insertions(+), 347 deletions(-)

diff --git a/dlls/dsound/capture.c b/dlls/dsound/capture.c
index 93c711d..e9c9508 100644
--- a/dlls/dsound/capture.c
+++ b/dlls/dsound/capture.c
@@ -381,7 +381,12 @@ IDirectSoundCaptureImpl_Release( LPDIRECTSOUNDCAPTURE iface )
     return ref;
 }
 
-HRESULT WINAPI IDirectSoundCaptureImpl_CreateCaptureBuffer(
+static HRESULT IDirectSoundCaptureBufferImpl_Create(
+    DirectSoundCaptureDevice *device,
+    IDirectSoundCaptureBufferImpl ** ppobj,
+    LPCDSCBUFFERDESC lpcDSCBufferDesc);
+
+static HRESULT WINAPI IDirectSoundCaptureImpl_CreateCaptureBuffer(
     LPDIRECTSOUNDCAPTURE iface,
     LPCDSCBUFFERDESC lpcDSCBufferDesc,
     LPDIRECTSOUNDCAPTUREBUFFER* lplpDSCaptureBuffer,
@@ -422,7 +427,7 @@ HRESULT WINAPI IDirectSoundCaptureImpl_CreateCaptureBuffer(
     return hr;
 }
 
-HRESULT WINAPI IDirectSoundCaptureImpl_GetCaps(
+static HRESULT WINAPI IDirectSoundCaptureImpl_GetCaps(
     LPDIRECTSOUNDCAPTURE iface,
     LPDSCCAPS lpDSCCaps )
 {
@@ -454,7 +459,7 @@ HRESULT WINAPI IDirectSoundCaptureImpl_GetCaps(
     return DS_OK;
 }
 
-HRESULT WINAPI IDirectSoundCaptureImpl_Initialize(
+static HRESULT WINAPI IDirectSoundCaptureImpl_Initialize(
     LPDIRECTSOUNDCAPTURE iface,
     LPCGUID lpcGUID )
 {
@@ -1193,7 +1198,7 @@ static const IDirectSoundCaptureBuffer8Vtbl dscbvt =
     IDirectSoundCaptureBufferImpl_GetFXStatus
 };
 
-HRESULT IDirectSoundCaptureBufferImpl_Create(
+static HRESULT IDirectSoundCaptureBufferImpl_Create(
     DirectSoundCaptureDevice *device,
     IDirectSoundCaptureBufferImpl ** ppobj,
     LPCDSCBUFFERDESC lpcDSCBufferDesc)
diff --git a/dlls/dsound/dsound_private.h b/dlls/dsound/dsound_private.h
index e1567e5..4a1b7de 100644
--- a/dlls/dsound/dsound_private.h
+++ b/dlls/dsound/dsound_private.h
@@ -299,11 +299,6 @@ struct IDirectSoundCaptureBufferImpl
     PIDSDRIVERNOTIFY                    hwnotify;
 };
 
-HRESULT IDirectSoundCaptureBufferImpl_Create(
-    DirectSoundCaptureDevice *device,
-    IDirectSoundCaptureBufferImpl ** ppobj,
-    LPCDSCBUFFERDESC lpcDSCBufferDesc);
-
 /*****************************************************************************
  *  IDirectSound3DListener implementation structure
  */
@@ -414,17 +409,6 @@ void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb);
  
 HRESULT DSOUND_CaptureCreate(REFIID riid, LPDIRECTSOUNDCAPTURE *ppDSC);
 HRESULT DSOUND_CaptureCreate8(REFIID riid, LPDIRECTSOUNDCAPTURE8 *ppDSC8);
-HRESULT WINAPI IDirectSoundCaptureImpl_CreateCaptureBuffer(
-    LPDIRECTSOUNDCAPTURE iface,
-    LPCDSCBUFFERDESC lpcDSCBufferDesc,
-    LPDIRECTSOUNDCAPTUREBUFFER* lplpDSCaptureBuffer,
-    LPUNKNOWN pUnk);
-HRESULT WINAPI IDirectSoundCaptureImpl_GetCaps(
-    LPDIRECTSOUNDCAPTURE iface,
-    LPDSCCAPS lpDSCCaps);
-HRESULT WINAPI IDirectSoundCaptureImpl_Initialize(
-    LPDIRECTSOUNDCAPTURE iface,
-    LPCGUID lpcGUID);
 
 #define STATE_STOPPED   0
 #define STATE_STARTING  1
diff --git a/dlls/dsound/duplex.c b/dlls/dsound/duplex.c
index 8fbf1d6..b228d3c 100644
--- a/dlls/dsound/duplex.c
+++ b/dlls/dsound/duplex.c
@@ -24,6 +24,8 @@
 
 #define NONAMELESSSTRUCT
 #define NONAMELESSUNION
+#define COBJMACROS
+#define CINTERFACE
 #include "windef.h"
 #include "winbase.h"
 #include "winuser.h"
@@ -48,37 +50,20 @@ typedef struct IDirectSoundFullDuplexImpl
 
     /* IDirectSoundFullDuplexImpl fields */
     DirectSoundDevice                *renderer_device;
-    DirectSoundCaptureDevice         *capture_device;
-
-    LPUNKNOWN                         pUnknown;
-    LPDIRECTSOUND                     pDS;
-    LPDIRECTSOUND8                    pDS8;
-    LPDIRECTSOUNDCAPTURE              pDSC;
+    IDirectSoundCapture *capture_device;
+
+    const IUnknownVtbl *lpUnkVtbl;
+    const IDirectSoundVtbl *lpDSVtbl;
+    const IDirectSound8Vtbl *lpDS8Vtbl;
+    const IDirectSoundCaptureVtbl *lpDSCVtbl;
+    LONG unk_ref;
+    LONG ds_ref;
+    LONG ds8_ref;
+    LONG dsc_ref;
 } IDirectSoundFullDuplexImpl;
 
-typedef struct IDirectSoundFullDuplex_IUnknown {
-    const IUnknownVtbl         *lpVtbl;
-    LONG                        ref;
-    IDirectSoundFullDuplexImpl *pdsfd;
-} IDirectSoundFullDuplex_IUnknown;
-
-typedef struct IDirectSoundFullDuplex_IDirectSound {
-    const IDirectSoundVtbl     *lpVtbl;
-    LONG                        ref;
-    IDirectSoundFullDuplexImpl *pdsfd;
-} IDirectSoundFullDuplex_IDirectSound;
-
-typedef struct IDirectSoundFullDuplex_IDirectSound8 {
-    const IDirectSound8Vtbl    *lpVtbl;
-    LONG                        ref;
-    IDirectSoundFullDuplexImpl *pdsfd;
-} IDirectSoundFullDuplex_IDirectSound8;
-
-typedef struct IDirectSoundFullDuplex_IDirectSoundCapture {
-    const IDirectSoundCaptureVtbl *lpVtbl;
-    LONG                           ref;
-    IDirectSoundFullDuplexImpl    *pdsfd;
-} IDirectSoundFullDuplex_IDirectSoundCapture;
+#define ICOM_THIS_MULTI(impl,field,iface) \
+    impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
 
 /*******************************************************************************
  * IUnknown
@@ -88,16 +73,16 @@ static HRESULT WINAPI IDirectSoundFullDuplex_IUnknown_QueryInterface(
     REFIID riid,
     LPVOID * ppobj)
 {
-    IDirectSoundFullDuplex_IUnknown *This = (IDirectSoundFullDuplex_IUnknown *)iface;
+    ICOM_THIS_MULTI(IDirectSoundFullDuplexImpl,lpUnkVtbl,iface);
     TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
-    return IDirectSoundFullDuplex_QueryInterface((LPDIRECTSOUNDFULLDUPLEX)This->pdsfd, riid, ppobj);
+    return IDirectSoundFullDuplex_QueryInterface((LPDIRECTSOUNDFULLDUPLEX)This, riid, ppobj);
 }
 
 static ULONG WINAPI IDirectSoundFullDuplex_IUnknown_AddRef(
     LPUNKNOWN iface)
 {
-    IDirectSoundFullDuplex_IUnknown *This = (IDirectSoundFullDuplex_IUnknown *)iface;
-    ULONG ref = InterlockedIncrement(&(This->ref));
+    ICOM_THIS_MULTI(IDirectSoundFullDuplexImpl,lpUnkVtbl,iface);
+    ULONG ref = InterlockedIncrement(&(This->unk_ref));
     TRACE("(%p) ref was %d\n", This, ref - 1);
     return ref;
 }
@@ -105,14 +90,9 @@ static ULONG WINAPI IDirectSoundFullDuplex_IUnknown_AddRef(
 static ULONG WINAPI IDirectSoundFullDuplex_IUnknown_Release(
     LPUNKNOWN iface)
 {
-    IDirectSoundFullDuplex_IUnknown *This = (IDirectSoundFullDuplex_IUnknown *)iface;
-    ULONG ref = InterlockedDecrement(&(This->ref));
+    ICOM_THIS_MULTI(IDirectSoundFullDuplexImpl,lpUnkVtbl,iface);
+    ULONG ref = InterlockedDecrement(&(This->unk_ref));
     TRACE("(%p) ref was %d\n", This, ref + 1);
-    if (!ref) {
-        IDirectSound_Release(This->pdsfd->pUnknown);
-        HeapFree(GetProcessHeap(), 0, This);
-        TRACE("(%p) released\n", This);
-    }
     return ref;
 }
 
@@ -123,39 +103,6 @@ static const IUnknownVtbl DirectSoundFullDuplex_Unknown_Vtbl =
     IDirectSoundFullDuplex_IUnknown_Release
 };
 
-static HRESULT IDirectSoundFullDuplex_IUnknown_Create(
-    LPDIRECTSOUNDFULLDUPLEX pdsfd,
-    LPUNKNOWN * ppunk)
-{
-    IDirectSoundFullDuplex_IUnknown * pdsfdunk;
-    TRACE("(%p,%p)\n",pdsfd,ppunk);
-
-    if (pdsfd == NULL) {
-        ERR("invalid parameter: pdsfd == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (ppunk == NULL) {
-        ERR("invalid parameter: ppunk == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    pdsfdunk = HeapAlloc(GetProcessHeap(),0,sizeof(*pdsfdunk));
-    if (pdsfdunk == NULL) {
-        WARN("out of memory\n");
-        *ppunk = NULL;
-        return DSERR_OUTOFMEMORY;
-    }
-
-    pdsfdunk->lpVtbl = &DirectSoundFullDuplex_Unknown_Vtbl;
-    pdsfdunk->ref = 0;
-    pdsfdunk->pdsfd = (IDirectSoundFullDuplexImpl *)pdsfd;
-
-    *ppunk = (LPUNKNOWN)pdsfdunk;
-
-    return DS_OK;
-}
-
 /*******************************************************************************
  * IDirectSoundFullDuplex_IDirectSound
  */
@@ -164,16 +111,16 @@ static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound_QueryInterface(
     REFIID riid,
     LPVOID * ppobj)
 {
-    IDirectSoundFullDuplex_IDirectSound *This = (IDirectSoundFullDuplex_IDirectSound *)iface;
+    ICOM_THIS_MULTI(IDirectSoundFullDuplexImpl,lpDSVtbl,iface);
     TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
-    return IDirectSoundFullDuplex_QueryInterface((LPDIRECTSOUNDFULLDUPLEX)This->pdsfd, riid, ppobj);
+    return IDirectSoundFullDuplex_QueryInterface((LPDIRECTSOUNDFULLDUPLEX)This, riid, ppobj);
 }
 
 static ULONG WINAPI IDirectSoundFullDuplex_IDirectSound_AddRef(
     LPDIRECTSOUND iface)
 {
-    IDirectSoundFullDuplex_IDirectSound *This = (IDirectSoundFullDuplex_IDirectSound *)iface;
-    ULONG ref = InterlockedIncrement(&(This->ref));
+    ICOM_THIS_MULTI(IDirectSoundFullDuplexImpl,lpDSVtbl,iface);
+    ULONG ref = InterlockedIncrement(&(This->ds_ref));
     TRACE("(%p) ref was %d\n", This, ref - 1);
     return ref;
 }
@@ -181,14 +128,9 @@ static ULONG WINAPI IDirectSoundFullDuplex_IDirectSound_AddRef(
 static ULONG WINAPI IDirectSoundFullDuplex_IDirectSound_Release(
     LPDIRECTSOUND iface)
 {
-    IDirectSoundFullDuplex_IDirectSound *This = (IDirectSoundFullDuplex_IDirectSound *)iface;
-    ULONG ref = InterlockedDecrement(&(This->ref));
+    ICOM_THIS_MULTI(IDirectSoundFullDuplexImpl,lpDSVtbl,iface);
+    ULONG ref = InterlockedDecrement(&(This->ds_ref));
     TRACE("(%p) ref was %d\n", This, ref + 1);
-    if (!ref) {
-        IDirectSound_Release(This->pdsfd->pDS);
-        HeapFree(GetProcessHeap(), 0, This);
-        TRACE("(%p) released\n", This);
-    }
     return ref;
 }
 
@@ -198,18 +140,18 @@ static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound_CreateSoundBuffer(
     LPLPDIRECTSOUNDBUFFER ppdsb,
     LPUNKNOWN lpunk)
 {
-    IDirectSoundFullDuplex_IDirectSound *This = (IDirectSoundFullDuplex_IDirectSound *)iface;
+    ICOM_THIS_MULTI(IDirectSoundFullDuplexImpl,lpDSVtbl,iface);
     TRACE("(%p,%p,%p,%p)\n",This,dsbd,ppdsb,lpunk);
-    return DirectSoundDevice_CreateSoundBuffer(This->pdsfd->renderer_device,dsbd,ppdsb,lpunk,FALSE);
+    return DirectSoundDevice_CreateSoundBuffer(This->renderer_device,dsbd,ppdsb,lpunk,FALSE);
 }
 
 static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound_GetCaps(
     LPDIRECTSOUND iface,
     LPDSCAPS lpDSCaps)
 {
-    IDirectSoundFullDuplex_IDirectSound *This = (IDirectSoundFullDuplex_IDirectSound *)iface;
+    ICOM_THIS_MULTI(IDirectSoundFullDuplexImpl,lpDSVtbl,iface);
     TRACE("(%p,%p)\n",This,lpDSCaps);
-    return DirectSoundDevice_GetCaps(This->pdsfd->renderer_device, lpDSCaps);
+    return DirectSoundDevice_GetCaps(This->renderer_device, lpDSCaps);
 }
 
 static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound_DuplicateSoundBuffer(
@@ -217,9 +159,9 @@ static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound_DuplicateSoundBuffer(
     LPDIRECTSOUNDBUFFER psb,
     LPLPDIRECTSOUNDBUFFER ppdsb)
 {
-    IDirectSoundFullDuplex_IDirectSound *This = (IDirectSoundFullDuplex_IDirectSound *)iface;
+    ICOM_THIS_MULTI(IDirectSoundFullDuplexImpl,lpDSVtbl,iface);
     TRACE("(%p,%p,%p)\n",This,psb,ppdsb);
-    return DirectSoundDevice_DuplicateSoundBuffer(This->pdsfd->renderer_device,psb,ppdsb);
+    return DirectSoundDevice_DuplicateSoundBuffer(This->renderer_device,psb,ppdsb);
 }
 
 static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound_SetCooperativeLevel(
@@ -227,44 +169,44 @@ static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound_SetCooperativeLevel(
     HWND hwnd,
     DWORD level)
 {
-    IDirectSoundFullDuplex_IDirectSound *This = (IDirectSoundFullDuplex_IDirectSound *)iface;
+    ICOM_THIS_MULTI(IDirectSoundFullDuplexImpl,lpDSVtbl,iface);
     TRACE("(%p,%p,%s)\n",This,hwnd,dumpCooperativeLevel(level));
-    return DirectSoundDevice_SetCooperativeLevel(This->pdsfd->renderer_device,hwnd,level);
+    return DirectSoundDevice_SetCooperativeLevel(This->renderer_device,hwnd,level);
 }
 
 static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound_Compact(
     LPDIRECTSOUND iface)
 {
-    IDirectSoundFullDuplex_IDirectSound *This = (IDirectSoundFullDuplex_IDirectSound *)iface;
+    ICOM_THIS_MULTI(IDirectSoundFullDuplexImpl,lpDSVtbl,iface);
     TRACE("(%p)\n", This);
-    return DirectSoundDevice_Compact(This->pdsfd->renderer_device);
+    return DirectSoundDevice_Compact(This->renderer_device);
 }
 
 static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound_GetSpeakerConfig(
     LPDIRECTSOUND iface,
     LPDWORD lpdwSpeakerConfig)
 {
-    IDirectSoundFullDuplex_IDirectSound *This = (IDirectSoundFullDuplex_IDirectSound *)iface;
+    ICOM_THIS_MULTI(IDirectSoundFullDuplexImpl,lpDSVtbl,iface);
     TRACE("(%p, %p)\n", This, lpdwSpeakerConfig);
-    return DirectSoundDevice_GetSpeakerConfig(This->pdsfd->renderer_device,lpdwSpeakerConfig);
+    return DirectSoundDevice_GetSpeakerConfig(This->renderer_device,lpdwSpeakerConfig);
 }
 
 static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound_SetSpeakerConfig(
     LPDIRECTSOUND iface,
     DWORD config)
 {
-    IDirectSoundFullDuplex_IDirectSound *This = (IDirectSoundFullDuplex_IDirectSound *)iface;
+    ICOM_THIS_MULTI(IDirectSoundFullDuplexImpl,lpDSVtbl,iface);
     TRACE("(%p,0x%08x)\n",This,config);
-    return DirectSoundDevice_SetSpeakerConfig(This->pdsfd->renderer_device,config);
+    return DirectSoundDevice_SetSpeakerConfig(This->renderer_device,config);
 }
 
 static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound_Initialize(
     LPDIRECTSOUND iface,
     LPCGUID lpcGuid)
 {
-    IDirectSoundFullDuplex_IDirectSound *This = (IDirectSoundFullDuplex_IDirectSound *)iface;
+    ICOM_THIS_MULTI(IDirectSoundFullDuplexImpl,lpDSVtbl,iface);
     TRACE("(%p, %s)\n", This, debugstr_guid(lpcGuid));
-    return DirectSoundDevice_Initialize(&This->pdsfd->renderer_device,lpcGuid);
+    return DirectSoundDevice_Initialize(&This->renderer_device,lpcGuid);
 }
 
 static const IDirectSoundVtbl DirectSoundFullDuplex_DirectSound_Vtbl =
@@ -282,45 +224,6 @@ static const IDirectSoundVtbl DirectSoundFullDuplex_DirectSound_Vtbl =
     IDirectSoundFullDuplex_IDirectSound_Initialize
 };
 
-static HRESULT IDirectSoundFullDuplex_IDirectSound_Create(
-    LPDIRECTSOUNDFULLDUPLEX pdsfd,
-    LPDIRECTSOUND * ppds)
-{
-    IDirectSoundFullDuplex_IDirectSound * pdsfdds;
-    TRACE("(%p,%p)\n",pdsfd,ppds);
-
-    if (pdsfd == NULL) {
-        ERR("invalid parameter: pdsfd == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (ppds == NULL) {
-        ERR("invalid parameter: ppds == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (((IDirectSoundFullDuplexImpl*)pdsfd)->renderer_device == NULL) {
-        WARN("not initialized\n");
-        *ppds = NULL;
-        return DSERR_UNINITIALIZED;
-    }
-
-    pdsfdds = HeapAlloc(GetProcessHeap(),0,sizeof(*pdsfdds));
-    if (pdsfdds == NULL) {
-        WARN("out of memory\n");
-        *ppds = NULL;
-        return DSERR_OUTOFMEMORY;
-    }
-
-    pdsfdds->lpVtbl = &DirectSoundFullDuplex_DirectSound_Vtbl;
-    pdsfdds->ref = 0;
-    pdsfdds->pdsfd = (IDirectSoundFullDuplexImpl *)pdsfd;
-
-    *ppds = (LPDIRECTSOUND)pdsfdds;
-
-    return DS_OK;
-}
-
 /*******************************************************************************
  * IDirectSoundFullDuplex_IDirectSound8
  */
@@ -329,16 +232,16 @@ static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound8_QueryInterface(
     REFIID riid,
     LPVOID * ppobj)
 {
-    IDirectSoundFullDuplex_IDirectSound8 *This = (IDirectSoundFullDuplex_IDirectSound8 *)iface;
+    ICOM_THIS_MULTI(IDirectSoundFullDuplexImpl,lpDS8Vtbl,iface);
     TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
-    return IDirectSoundFullDuplex_QueryInterface((LPDIRECTSOUNDFULLDUPLEX)This->pdsfd, riid, ppobj);
+    return IDirectSoundFullDuplex_QueryInterface((LPDIRECTSOUNDFULLDUPLEX)This, riid, ppobj);
 }
 
 static ULONG WINAPI IDirectSoundFullDuplex_IDirectSound8_AddRef(
     LPDIRECTSOUND8 iface)
 {
-    IDirectSoundFullDuplex_IDirectSound8 *This = (IDirectSoundFullDuplex_IDirectSound8 *)iface;
-    ULONG ref = InterlockedIncrement(&(This->ref));
+    ICOM_THIS_MULTI(IDirectSoundFullDuplexImpl,lpDS8Vtbl,iface);
+    ULONG ref = InterlockedIncrement(&(This->ds8_ref));
     TRACE("(%p) ref was %d\n", This, ref - 1);
     return ref;
 }
@@ -346,14 +249,9 @@ static ULONG WINAPI IDirectSoundFullDuplex_IDirectSound8_AddRef(
 static ULONG WINAPI IDirectSoundFullDuplex_IDirectSound8_Release(
     LPDIRECTSOUND8 iface)
 {
-    IDirectSoundFullDuplex_IDirectSound8 *This = (IDirectSoundFullDuplex_IDirectSound8 *)iface;
-    ULONG ref = InterlockedDecrement(&(This->ref));
+    ICOM_THIS_MULTI(IDirectSoundFullDuplexImpl,lpDS8Vtbl,iface);
+    ULONG ref = InterlockedDecrement(&(This->ds8_ref));
     TRACE("(%p) ref was %d\n", This, ref + 1);
-    if (!ref) {
-        IDirectSound_Release(This->pdsfd->pDS8);
-        HeapFree(GetProcessHeap(), 0, This);
-        TRACE("(%p) released\n", This);
-    }
     return ref;
 }
 
@@ -363,18 +261,18 @@ static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound8_CreateSoundBuffer(
     LPLPDIRECTSOUNDBUFFER ppdsb,
     LPUNKNOWN lpunk)
 {
-    IDirectSoundFullDuplex_IDirectSound8 *This = (IDirectSoundFullDuplex_IDirectSound8 *)iface;
+    ICOM_THIS_MULTI(IDirectSoundFullDuplexImpl,lpDS8Vtbl,iface);
     TRACE("(%p,%p,%p,%p)\n",This,dsbd,ppdsb,lpunk);
-    return DirectSoundDevice_CreateSoundBuffer(This->pdsfd->renderer_device,dsbd,ppdsb,lpunk,TRUE);
+    return DirectSoundDevice_CreateSoundBuffer(This->renderer_device,dsbd,ppdsb,lpunk,TRUE);
 }
 
 static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound8_GetCaps(
     LPDIRECTSOUND8 iface,
     LPDSCAPS lpDSCaps)
 {
-    IDirectSoundFullDuplex_IDirectSound8 *This = (IDirectSoundFullDuplex_IDirectSound8 *)iface;
+    ICOM_THIS_MULTI(IDirectSoundFullDuplexImpl,lpDS8Vtbl,iface);
     TRACE("(%p,%p)\n",This,lpDSCaps);
-    return DirectSoundDevice_GetCaps(This->pdsfd->renderer_device, lpDSCaps);
+    return DirectSoundDevice_GetCaps(This->renderer_device, lpDSCaps);
 }
 
 static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound8_DuplicateSoundBuffer(
@@ -382,9 +280,9 @@ static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound8_DuplicateSoundBuffer(
     LPDIRECTSOUNDBUFFER psb,
     LPLPDIRECTSOUNDBUFFER ppdsb)
 {
-    IDirectSoundFullDuplex_IDirectSound8 *This = (IDirectSoundFullDuplex_IDirectSound8 *)iface;
+    ICOM_THIS_MULTI(IDirectSoundFullDuplexImpl,lpDS8Vtbl,iface);
     TRACE("(%p,%p,%p)\n",This,psb,ppdsb);
-    return DirectSoundDevice_DuplicateSoundBuffer(This->pdsfd->renderer_device,psb,ppdsb);
+    return DirectSoundDevice_DuplicateSoundBuffer(This->renderer_device,psb,ppdsb);
 }
 
 static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound8_SetCooperativeLevel(
@@ -392,44 +290,44 @@ static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound8_SetCooperativeLevel(
     HWND hwnd,
     DWORD level)
 {
-    IDirectSoundFullDuplex_IDirectSound8 *This = (IDirectSoundFullDuplex_IDirectSound8 *)iface;
+    ICOM_THIS_MULTI(IDirectSoundFullDuplexImpl,lpDS8Vtbl,iface);
     TRACE("(%p,%p,%s)\n",This,hwnd,dumpCooperativeLevel(level));
-    return DirectSoundDevice_SetCooperativeLevel(This->pdsfd->renderer_device,hwnd,level);
+    return DirectSoundDevice_SetCooperativeLevel(This->renderer_device,hwnd,level);
 }
 
 static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound8_Compact(
     LPDIRECTSOUND8 iface)
 {
-    IDirectSoundFullDuplex_IDirectSound8 *This = (IDirectSoundFullDuplex_IDirectSound8 *)iface;
+    ICOM_THIS_MULTI(IDirectSoundFullDuplexImpl,lpDS8Vtbl,iface);
     TRACE("(%p)\n", This);
-    return DirectSoundDevice_Compact(This->pdsfd->renderer_device);
+    return DirectSoundDevice_Compact(This->renderer_device);
 }
 
 static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound8_GetSpeakerConfig(
     LPDIRECTSOUND8 iface,
     LPDWORD lpdwSpeakerConfig)
 {
-    IDirectSoundFullDuplex_IDirectSound8 *This = (IDirectSoundFullDuplex_IDirectSound8 *)iface;
+    ICOM_THIS_MULTI(IDirectSoundFullDuplexImpl,lpDS8Vtbl,iface);
     TRACE("(%p, %p)\n", This, lpdwSpeakerConfig);
-    return DirectSoundDevice_GetSpeakerConfig(This->pdsfd->renderer_device,lpdwSpeakerConfig);
+    return DirectSoundDevice_GetSpeakerConfig(This->renderer_device,lpdwSpeakerConfig);
 }
 
 static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound8_SetSpeakerConfig(
     LPDIRECTSOUND8 iface,
     DWORD config)
 {
-    IDirectSoundFullDuplex_IDirectSound8 *This = (IDirectSoundFullDuplex_IDirectSound8 *)iface;
+    ICOM_THIS_MULTI(IDirectSoundFullDuplexImpl,lpDS8Vtbl,iface);
     TRACE("(%p,0x%08x)\n",This,config);
-    return DirectSoundDevice_SetSpeakerConfig(This->pdsfd->renderer_device,config);
+    return DirectSoundDevice_SetSpeakerConfig(This->renderer_device,config);
 }
 
 static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSound8_Initialize(
     LPDIRECTSOUND8 iface,
     LPCGUID lpcGuid)
 {
-    IDirectSoundFullDuplex_IDirectSound8 *This = (IDirectSoundFullDuplex_IDirectSound8 *)iface;
+    ICOM_THIS_MULTI(IDirectSoundFullDuplexImpl,lpDS8Vtbl,iface);
     TRACE("(%p, %s)\n", This, debugstr_guid(lpcGuid));
-    return DirectSoundDevice_Initialize(&This->pdsfd->renderer_device,lpcGuid);
+    return DirectSoundDevice_Initialize(&This->renderer_device,lpcGuid);
 }
 
 static const IDirectSound8Vtbl DirectSoundFullDuplex_DirectSound8_Vtbl =
@@ -447,45 +345,6 @@ static const IDirectSound8Vtbl DirectSoundFullDuplex_DirectSound8_Vtbl =
     IDirectSoundFullDuplex_IDirectSound8_Initialize
 };
 
-static HRESULT IDirectSoundFullDuplex_IDirectSound8_Create(
-    LPDIRECTSOUNDFULLDUPLEX pdsfd,
-    LPDIRECTSOUND8 * ppds8)
-{
-    IDirectSoundFullDuplex_IDirectSound8 * pdsfdds8;
-    TRACE("(%p,%p)\n",pdsfd,ppds8);
-
-    if (pdsfd == NULL) {
-        ERR("invalid parameter: pdsfd == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (ppds8 == NULL) {
-        ERR("invalid parameter: ppds8 == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (((IDirectSoundFullDuplexImpl*)pdsfd)->renderer_device == NULL) {
-        WARN("not initialized\n");
-        *ppds8 = NULL;
-        return DSERR_UNINITIALIZED;
-    }
-
-    pdsfdds8 = HeapAlloc(GetProcessHeap(),0,sizeof(*pdsfdds8));
-    if (pdsfdds8 == NULL) {
-        WARN("out of memory\n");
-        *ppds8 = NULL;
-        return DSERR_OUTOFMEMORY;
-    }
-
-    pdsfdds8->lpVtbl = &DirectSoundFullDuplex_DirectSound8_Vtbl;
-    pdsfdds8->ref = 0;
-    pdsfdds8->pdsfd = (IDirectSoundFullDuplexImpl *)pdsfd;
-
-    *ppds8 = (LPDIRECTSOUND8)pdsfdds8;
-
-    return DS_OK;
-}
-
 /*******************************************************************************
  * IDirectSoundFullDuplex_IDirectSoundCapture
  */
@@ -494,16 +353,16 @@ static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSoundCapture_QueryInterface(
     REFIID riid,
     LPVOID * ppobj)
 {
-    IDirectSoundFullDuplex_IDirectSoundCapture *This = (IDirectSoundFullDuplex_IDirectSoundCapture *)iface;
+    ICOM_THIS_MULTI(IDirectSoundFullDuplexImpl,lpDSCVtbl,iface);
     TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
-    return IDirectSoundFullDuplex_QueryInterface((LPDIRECTSOUNDFULLDUPLEX)This->pdsfd, riid, ppobj);
+    return IDirectSoundFullDuplex_QueryInterface((LPDIRECTSOUNDFULLDUPLEX)This, riid, ppobj);
 }
 
 static ULONG WINAPI IDirectSoundFullDuplex_IDirectSoundCapture_AddRef(
     LPDIRECTSOUNDCAPTURE iface)
 {
-    IDirectSoundFullDuplex_IDirectSoundCapture *This = (IDirectSoundFullDuplex_IDirectSoundCapture *)iface;
-    ULONG ref = InterlockedIncrement(&(This->ref));
+    ICOM_THIS_MULTI(IDirectSoundFullDuplexImpl,lpDSCVtbl,iface);
+    ULONG ref = InterlockedIncrement(&(This->dsc_ref));
     TRACE("(%p) ref was %d\n", This, ref - 1);
     return ref;
 }
@@ -511,14 +370,9 @@ static ULONG WINAPI IDirectSoundFullDuplex_IDirectSoundCapture_AddRef(
 static ULONG WINAPI IDirectSoundFullDuplex_IDirectSoundCapture_Release(
     LPDIRECTSOUNDCAPTURE iface)
 {
-    IDirectSoundFullDuplex_IDirectSoundCapture *This = (IDirectSoundFullDuplex_IDirectSoundCapture *)iface;
-    ULONG ref = InterlockedDecrement(&(This->ref));
+    ICOM_THIS_MULTI(IDirectSoundFullDuplexImpl,lpDSCVtbl,iface);
+    ULONG ref = InterlockedDecrement(&(This->dsc_ref));
     TRACE("(%p) ref was %d\n", This, ref + 1);
-    if (!ref) {
-        IDirectSoundCapture_Release(This->pdsfd->pDSC);
-        HeapFree(GetProcessHeap(), 0, This);
-        TRACE("(%p) released\n", This);
-    }
     return ref;
 }
 
@@ -528,27 +382,27 @@ static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSoundCapture_CreateCaptureBu
     LPDIRECTSOUNDCAPTUREBUFFER* lplpDSCaptureBuffer,
     LPUNKNOWN pUnk)
 {
-    IDirectSoundFullDuplex_IDirectSoundCapture *This = (IDirectSoundFullDuplex_IDirectSoundCapture *)iface;
+    ICOM_THIS_MULTI(IDirectSoundFullDuplexImpl,lpDSCVtbl,iface);
     TRACE("(%p,%p,%p,%p)\n",This,lpcDSCBufferDesc,lplpDSCaptureBuffer,pUnk);
-    return IDirectSoundCaptureImpl_CreateCaptureBuffer(This->pdsfd->pDSC,lpcDSCBufferDesc,lplpDSCaptureBuffer,pUnk);
+    return IDirectSoundCapture_CreateCaptureBuffer(This->capture_device,lpcDSCBufferDesc,lplpDSCaptureBuffer,pUnk);
 }
 
 static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSoundCapture_GetCaps(
     LPDIRECTSOUNDCAPTURE iface,
     LPDSCCAPS lpDSCCaps)
 {
-    IDirectSoundFullDuplex_IDirectSoundCapture *This = (IDirectSoundFullDuplex_IDirectSoundCapture *)iface;
+    ICOM_THIS_MULTI(IDirectSoundFullDuplexImpl,lpDSCVtbl,iface);
     TRACE("(%p,%p)\n",This,lpDSCCaps);
-    return IDirectSoundCaptureImpl_GetCaps(This->pdsfd->pDSC, lpDSCCaps);
+    return IDirectSoundCapture_GetCaps(This->capture_device, lpDSCCaps);
 }
 
 static HRESULT WINAPI IDirectSoundFullDuplex_IDirectSoundCapture_Initialize(
     LPDIRECTSOUNDCAPTURE iface,
     LPCGUID lpcGUID)
 {
-    IDirectSoundFullDuplex_IDirectSoundCapture *This = (IDirectSoundFullDuplex_IDirectSoundCapture *)iface;
+    ICOM_THIS_MULTI(IDirectSoundFullDuplexImpl,lpDSCVtbl,iface);
     TRACE("(%p, %s)\n", This, debugstr_guid(lpcGUID));
-    return IDirectSoundCaptureImpl_Initialize(This->pdsfd->pDSC,lpcGUID);
+    return IDirectSoundCapture_Initialize(This->capture_device,lpcGUID);
 }
 
 static const IDirectSoundCaptureVtbl DirectSoundFullDuplex_DirectSoundCapture_Vtbl =
@@ -561,45 +415,6 @@ static const IDirectSoundCaptureVtbl DirectSoundFullDuplex_DirectSoundCapture_Vt
     IDirectSoundFullDuplex_IDirectSoundCapture_Initialize
 };
 
-static HRESULT IDirectSoundFullDuplex_IDirectSoundCapture_Create(
-    LPDIRECTSOUNDFULLDUPLEX pdsfd,
-    LPDIRECTSOUNDCAPTURE8 * ppdsc8)
-{
-    IDirectSoundFullDuplex_IDirectSoundCapture * pdsfddsc;
-    TRACE("(%p,%p)\n",pdsfd,ppdsc8);
-
-    if (pdsfd == NULL) {
-        ERR("invalid parameter: pdsfd == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (ppdsc8 == NULL) {
-        ERR("invalid parameter: ppdsc8 == NULL\n");
-        return DSERR_INVALIDPARAM;
-    }
-
-    if (((IDirectSoundFullDuplexImpl*)pdsfd)->capture_device == NULL) {
-        WARN("not initialized\n");
-        *ppdsc8 = NULL;
-        return DSERR_UNINITIALIZED;
-    }
-
-    pdsfddsc = HeapAlloc(GetProcessHeap(),0,sizeof(*pdsfddsc));
-    if (pdsfddsc == NULL) {
-        WARN("out of memory\n");
-        *ppdsc8 = NULL;
-        return DSERR_OUTOFMEMORY;
-    }
-
-    pdsfddsc->lpVtbl = &DirectSoundFullDuplex_DirectSoundCapture_Vtbl;
-    pdsfddsc->ref = 0;
-    pdsfddsc->pdsfd = (IDirectSoundFullDuplexImpl *)pdsfd;
-
-    *ppdsc8 = (LPDIRECTSOUNDCAPTURE)pdsfddsc;
-
-    return DS_OK;
-}
-
 /***************************************************************************
  * IDirectSoundFullDuplexImpl
  */
@@ -629,56 +444,22 @@ IDirectSoundFullDuplexImpl_QueryInterface(
     *ppobj = NULL;
 
     if (IsEqualIID(riid, &IID_IUnknown)) {
-        if (!This->pUnknown) {
-            IDirectSoundFullDuplex_IUnknown_Create(iface, &This->pUnknown);
-            if (!This->pUnknown) {
-                WARN("IDirectSoundFullDuplex_IUnknown_Create() failed\n");
-                *ppobj = NULL;
-                return E_NOINTERFACE;
-            }
-        }
-        IDirectSoundFullDuplex_IUnknown_AddRef(This->pUnknown);
-        *ppobj = This->pUnknown;
-        return S_OK;
+        *ppobj = &This->lpUnkVtbl;
     } else if (IsEqualIID(riid, &IID_IDirectSoundFullDuplex)) {
-        IDirectSoundFullDuplexImpl_AddRef(iface);
         *ppobj = This;
-        return S_OK;
     } else if (IsEqualIID(riid, &IID_IDirectSound)) {
-        if (!This->pDS) {
-            IDirectSoundFullDuplex_IDirectSound_Create(iface, &This->pDS);
-            if (!This->pDS) {
-                WARN("IDirectSoundFullDuplex_IDirectSound_Create() failed\n");
-                *ppobj = NULL;
-                return E_NOINTERFACE;
-            }
-        }
-        IDirectSoundFullDuplex_IDirectSound_AddRef(This->pDS);
-        *ppobj = This->pDS;
-        return S_OK;
+        if (!This->renderer_device) return E_NOINTERFACE;
+        *ppobj = &This->lpDSVtbl;
     } else if (IsEqualIID(riid, &IID_IDirectSound8)) {
-        if (!This->pDS8) {
-            IDirectSoundFullDuplex_IDirectSound8_Create(iface, &This->pDS8);
-            if (!This->pDS8) {
-                WARN("IDirectSoundFullDuplex_IDirectSound8_Create() failed\n");
-                *ppobj = NULL;
-                return E_NOINTERFACE;
-            }
-        }
-        IDirectSoundFullDuplex_IDirectSound8_AddRef(This->pDS8);
-        *ppobj = This->pDS8;
-        return S_OK;
+        if (!This->renderer_device) return E_NOINTERFACE;
+        *ppobj = &This->lpDS8Vtbl;
     } else if (IsEqualIID(riid, &IID_IDirectSoundCapture)) {
-        if (!This->pDSC) {
-            IDirectSoundFullDuplex_IDirectSoundCapture_Create(iface, &This->pDSC);
-            if (!This->pDSC) {
-                WARN("IDirectSoundFullDuplex_IDirectSoundCapture_Create() failed\n");
-                *ppobj = NULL;
-                return E_NOINTERFACE;
-            }
-        }
-        IDirectSoundFullDuplex_IDirectSoundCapture_AddRef(This->pDSC);
-        *ppobj = This->pDSC;
+        if (!This->capture_device) return E_NOINTERFACE;
+        *ppobj = &This->lpDSCVtbl;
+    }
+    if (*ppobj)
+    {
+        IUnknown_AddRef((IUnknown*)*ppobj);
         return S_OK;
     }
 
@@ -694,7 +475,7 @@ IDirectSoundFullDuplexImpl_Release( LPDIRECTSOUNDFULLDUPLEX iface )
 
     if (!ref) {
         if (This->capture_device)
-            DirectSoundCaptureDevice_Release(This->capture_device);
+            IDirectSoundCapture_Release(This->capture_device);
         if (This->renderer_device)
             DirectSoundDevice_Release(This->renderer_device);
         HeapFree( GetProcessHeap(), 0, This );
@@ -718,6 +499,7 @@ IDirectSoundFullDuplexImpl_Initialize(
     HRESULT hr;
     IDirectSoundFullDuplexImpl *This = (IDirectSoundFullDuplexImpl *)iface;
     IDirectSoundBufferImpl * dsb;
+    IDirectSoundCaptureBuffer *buf;
 
     TRACE("(%p,%s,%s,%p,%p,%p,%x,%p,%p)\n", This,
         debugstr_guid(pCaptureGuid), debugstr_guid(pRendererGuid),
@@ -769,7 +551,10 @@ IDirectSoundFullDuplexImpl_Initialize(
     }
     IDirectSoundBuffer8_AddRef(*lplpDirectSoundBuffer8);
 
-    hr = DirectSoundCaptureDevice_Initialize(&This->capture_device, pCaptureGuid);
+    hr = DSOUND_CaptureCreate8(&IID_IDirectSoundCapture, &This->capture_device);
+
+    if (SUCCEEDED(hr))
+        hr = IDirectSoundCapture_Initialize(This->capture_device, pCaptureGuid);
     if (hr != DS_OK) {
         WARN("DirectSoundCaptureDevice_Initialize() failed\n");
         *lplpDirectSoundCaptureBuffer8 = NULL;
@@ -777,9 +562,13 @@ IDirectSoundFullDuplexImpl_Initialize(
         return hr;
     }
 
-    hr = IDirectSoundCaptureBufferImpl_Create(This->capture_device,
-         (IDirectSoundCaptureBufferImpl **)lplpDirectSoundCaptureBuffer8,
-         lpDscBufferDesc);
+    hr = IDirectSoundCapture_CreateCaptureBuffer(This->capture_device,
+         lpDscBufferDesc, &buf, NULL);
+    if (SUCCEEDED(hr))
+    {
+        hr = IUnknown_QueryInterface(buf, &IID_IDirectSoundCaptureBuffer8, (void **)lplpDirectSoundCaptureBuffer8);
+        IUnknown_Release(buf);
+    }
     if (hr != DS_OK) {
         WARN("IDirectSoundCaptureBufferImpl_Create() failed\n");
         *lplpDirectSoundCaptureBuffer8 = NULL;
@@ -832,6 +621,10 @@ HRESULT DSOUND_FullDuplexCreate(
     }
 
     This->lpVtbl = &dsfdvt;
+    This->lpUnkVtbl = &DirectSoundFullDuplex_Unknown_Vtbl;
+    This->lpDSVtbl = &DirectSoundFullDuplex_DirectSound_Vtbl;
+    This->lpDS8Vtbl = &DirectSoundFullDuplex_DirectSound8_Vtbl;
+    This->lpDSCVtbl = &DirectSoundFullDuplex_DirectSoundCapture_Vtbl;
     This->ref = 1;
     This->capture_device = NULL;
     This->renderer_device = NULL;
@@ -918,22 +711,8 @@ DirectSoundFullDuplexCreate(
         return DSERR_INVALIDPARAM;
     }
 
-    /* Get dsound configuration */
-    setup_dsound_options();
-
-    This = HeapAlloc(GetProcessHeap(),
-        HEAP_ZERO_MEMORY, sizeof(IDirectSoundFullDuplexImpl));
-
-    if (This == NULL) {
-        WARN("out of memory\n");
-        *ppDSFD = NULL;
-        return DSERR_OUTOFMEMORY;
-    }
-
-    This->lpVtbl = &dsfdvt;
-    This->ref = 1;
-    This->capture_device = NULL;
-    This->renderer_device = NULL;
+    hres = DSOUND_FullDuplexCreate(&IID_IDirectSoundFullDuplex, (LPDIRECTSOUNDFULLDUPLEX*)&This);
+    if (FAILED(hres)) return hres;
 
     hres = IDirectSoundFullDuplexImpl_Initialize((LPDIRECTSOUNDFULLDUPLEX)This,
                                                  pcGuidCaptureDevice,
-- 
1.6.5.2


--------------070202060701000401010901--



More information about the wine-patches mailing list