Michael Stefaniuc : dsound: Merge the DirectSoundCapture create functions.

Alexandre Julliard julliard at winehq.org
Thu Aug 16 15:26:11 CDT 2012


Module: wine
Branch: master
Commit: b8ffb4930fe1d9a482bfb6aef093a0a0d673f2e2
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=b8ffb4930fe1d9a482bfb6aef093a0a0d673f2e2

Author: Michael Stefaniuc <mstefani at redhat.de>
Date:   Thu Aug 16 01:20:01 2012 +0200

dsound: Merge the DirectSoundCapture create functions.

---

 dlls/dsound/capture.c        |   89 +++++++++++------------------------------
 dlls/dsound/dsound_main.c    |    4 +-
 dlls/dsound/dsound_private.h |    4 +-
 dlls/dsound/duplex.c         |    2 +-
 4 files changed, 29 insertions(+), 70 deletions(-)

diff --git a/dlls/dsound/capture.c b/dlls/dsound/capture.c
index 7970537..40df315 100644
--- a/dlls/dsound/capture.c
+++ b/dlls/dsound/capture.c
@@ -1000,6 +1000,7 @@ struct IDirectSoundCaptureImpl
     IDirectSoundCapture      IDirectSoundCapture_iface;
     LONG                     ref;
     DirectSoundCaptureDevice *device;
+    BOOL                     has_dsc8;
 };
 
 static inline struct IDirectSoundCaptureImpl *impl_from_IDirectSoundCapture(IDirectSoundCapture *iface)
@@ -1161,83 +1162,41 @@ static const IDirectSoundCaptureVtbl dscvt =
     IDirectSoundCaptureImpl_Initialize
 };
 
-static HRESULT IDirectSoundCaptureImpl_Create(
-    LPDIRECTSOUNDCAPTURE8 * ppDSC)
+static HRESULT IDirectSoundCaptureImpl_Create(REFIID riid, void **ppv, BOOL has_dsc8)
 {
-    IDirectSoundCaptureImpl *pDSC;
-    TRACE("(%p)\n", ppDSC);
+    IDirectSoundCaptureImpl *obj;
+    HRESULT hr;
 
-    /* Allocate memory */
-    pDSC = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirectSoundCaptureImpl));
-    if (pDSC == NULL) {
+    TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
+
+    *ppv = NULL;
+    obj = HeapAlloc(GetProcessHeap(), 0, sizeof(*obj));
+    if (obj == NULL) {
         WARN("out of memory\n");
-        *ppDSC = NULL;
         return DSERR_OUTOFMEMORY;
     }
 
-    pDSC->IDirectSoundCapture_iface.lpVtbl = &dscvt;
-    pDSC->ref    = 0;
-    pDSC->device = NULL;
-
-    *ppDSC = (LPDIRECTSOUNDCAPTURE8)pDSC;
-
-    return DS_OK;
-}
-
-HRESULT DSOUND_CaptureCreate(REFIID riid, IDirectSoundCapture **ppDSC)
-{
-    IDirectSoundCapture *pDSC;
-    HRESULT hr;
-    TRACE("(%s, %p)\n", debugstr_guid(riid), ppDSC);
-
-    if (!IsEqualIID(riid, &IID_IUnknown) &&
-        !IsEqualIID(riid, &IID_IDirectSoundCapture)) {
-        *ppDSC = 0;
-        return E_NOINTERFACE;
-    }
-
-    /* Get dsound configuration */
     setup_dsound_options();
 
-    hr = IDirectSoundCaptureImpl_Create(&pDSC);
-    if (hr == DS_OK) {
-        IDirectSoundCapture_AddRef(pDSC);
-        *ppDSC = pDSC;
-    } else {
-        WARN("IDirectSoundCaptureImpl_Create failed\n");
-        *ppDSC = 0;
-    }
+    obj->IDirectSoundCapture_iface.lpVtbl = &dscvt;
+    obj->ref = 1;
+    obj->device = NULL;
+    obj->has_dsc8 = has_dsc8;
+
+    hr = IDirectSoundCapture_QueryInterface(&obj->IDirectSoundCapture_iface, riid, ppv);
+    IDirectSoundCapture_Release(&obj->IDirectSoundCapture_iface);
 
     return hr;
 }
 
-HRESULT DSOUND_CaptureCreate8(
-    REFIID riid,
-    LPDIRECTSOUNDCAPTURE8 *ppDSC8)
+HRESULT DSOUND_CaptureCreate(REFIID riid, void **ppv)
 {
-    LPDIRECTSOUNDCAPTURE8 pDSC8;
-    HRESULT hr;
-    TRACE("(%s, %p)\n", debugstr_guid(riid), ppDSC8);
-
-    if (!IsEqualIID(riid, &IID_IUnknown) &&
-        !IsEqualIID(riid, &IID_IDirectSoundCapture8)) {
-        *ppDSC8 = 0;
-        return E_NOINTERFACE;
-    }
-
-    /* Get dsound configuration */
-    setup_dsound_options();
-
-    hr = IDirectSoundCaptureImpl_Create(&pDSC8);
-    if (hr == DS_OK) {
-        IDirectSoundCapture_AddRef(pDSC8);
-        *ppDSC8 = pDSC8;
-    } else {
-        WARN("IDirectSoundCaptureImpl_Create failed\n");
-        *ppDSC8 = 0;
-    }
+    return IDirectSoundCaptureImpl_Create(riid, ppv, FALSE);
+}
 
-    return hr;
+HRESULT DSOUND_CaptureCreate8(REFIID riid, void **ppv)
+{
+    return IDirectSoundCaptureImpl_Create(riid, ppv, TRUE);
 }
 
 /***************************************************************************
@@ -1280,7 +1239,7 @@ HRESULT WINAPI DirectSoundCaptureCreate(LPCGUID lpcGUID, IDirectSoundCapture **p
         return DSERR_NOAGGREGATION;
     }
 
-    hr = DSOUND_CaptureCreate(&IID_IDirectSoundCapture, &pDSC);
+    hr = DSOUND_CaptureCreate(&IID_IDirectSoundCapture, (void**)&pDSC);
     if (hr == DS_OK) {
         hr = IDirectSoundCapture_Initialize(pDSC, lpcGUID);
         if (hr != DS_OK) {
@@ -1336,7 +1295,7 @@ HRESULT WINAPI DirectSoundCaptureCreate8(
         return DSERR_NOAGGREGATION;
     }
 
-    hr = DSOUND_CaptureCreate8(&IID_IDirectSoundCapture8, &pDSC8);
+    hr = DSOUND_CaptureCreate8(&IID_IDirectSoundCapture8, (void**)&pDSC8);
     if (hr == DS_OK) {
         hr = IDirectSoundCapture_Initialize(pDSC8, lpcGUID);
         if (hr != DS_OK) {
diff --git a/dlls/dsound/dsound_main.c b/dlls/dsound/dsound_main.c
index e1969a1..34b23a5 100644
--- a/dlls/dsound/dsound_main.c
+++ b/dlls/dsound/dsound_main.c
@@ -721,8 +721,8 @@ static const IClassFactoryVtbl DSCF_Vtbl = {
 static IClassFactoryImpl DSOUND_CF[] = {
     { { &DSCF_Vtbl }, &CLSID_DirectSound, DSOUND_Create },
     { { &DSCF_Vtbl }, &CLSID_DirectSound8, DSOUND_Create8 },
-    { { &DSCF_Vtbl }, &CLSID_DirectSoundCapture, (FnCreateInstance)DSOUND_CaptureCreate },
-    { { &DSCF_Vtbl }, &CLSID_DirectSoundCapture8, (FnCreateInstance)DSOUND_CaptureCreate8 },
+    { { &DSCF_Vtbl }, &CLSID_DirectSoundCapture, DSOUND_CaptureCreate },
+    { { &DSCF_Vtbl }, &CLSID_DirectSoundCapture8, DSOUND_CaptureCreate8 },
     { { &DSCF_Vtbl }, &CLSID_DirectSoundFullDuplex, (FnCreateInstance)DSOUND_FullDuplexCreate },
     { { &DSCF_Vtbl }, &CLSID_DirectSoundPrivate, (FnCreateInstance)IKsPrivatePropertySetImpl_Create },
     { { NULL }, NULL, NULL }
diff --git a/dlls/dsound/dsound_private.h b/dlls/dsound/dsound_private.h
index be40797..107cbab 100644
--- a/dlls/dsound/dsound_private.h
+++ b/dlls/dsound/dsound_private.h
@@ -299,8 +299,8 @@ void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb) DECLSPEC_HIDDEN;
 
 /* capture.c */
  
-HRESULT DSOUND_CaptureCreate(REFIID riid, LPDIRECTSOUNDCAPTURE *ppDSC) DECLSPEC_HIDDEN;
-HRESULT DSOUND_CaptureCreate8(REFIID riid, LPDIRECTSOUNDCAPTURE8 *ppDSC8) DECLSPEC_HIDDEN;
+HRESULT DSOUND_CaptureCreate(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
+HRESULT DSOUND_CaptureCreate8(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
 
 #define STATE_STOPPED   0
 #define STATE_STARTING  1
diff --git a/dlls/dsound/duplex.c b/dlls/dsound/duplex.c
index ccb0c9b..b473c03 100644
--- a/dlls/dsound/duplex.c
+++ b/dlls/dsound/duplex.c
@@ -578,7 +578,7 @@ IDirectSoundFullDuplexImpl_Initialize(
         return hr;
     }
 
-    hr = DSOUND_CaptureCreate8(&IID_IDirectSoundCapture8, &This->capture_device);
+    hr = DSOUND_CaptureCreate8(&IID_IDirectSoundCapture8, (void**)&This->capture_device);
     if (SUCCEEDED(hr))
         hr = IDirectSoundCapture_Initialize(This->capture_device, pCaptureGuid);
     if (hr != DS_OK) {




More information about the wine-cvs mailing list