[PATCH 2/3] dsound: Merge IKsPropertySet into the secondary buffer object.
Michael Stefaniuc
mstefani at redhat.de
Mon Jan 16 18:53:10 CST 2012
---
dlls/dsound/buffer.c | 104 +++++++++++++----------------------------
dlls/dsound/dsound_private.h | 25 +---------
2 files changed, 36 insertions(+), 93 deletions(-)
diff --git a/dlls/dsound/buffer.c b/dlls/dsound/buffer.c
index d76d837..b905782 100644
--- a/dlls/dsound/buffer.c
+++ b/dlls/dsound/buffer.c
@@ -829,15 +829,9 @@ static HRESULT WINAPI IDirectSoundBufferImpl_QueryInterface(IDirectSoundBuffer8
}
if ( IsEqualGUID( &IID_IKsPropertySet, riid ) ) {
- if (!This->iks)
- IKsBufferPropertySetImpl_Create(This, &(This->iks));
- if (This->iks) {
- IKsPropertySet_AddRef((LPKSPROPERTYSET)This->iks);
- *ppobj = This->iks;
- return S_OK;
- }
- WARN("IID_IKsPropertySet\n");
- return E_NOINTERFACE;
+ IKsPropertySet_AddRef(&This->IKsPropertySet_iface);
+ *ppobj = &This->IKsPropertySet_iface;
+ return S_OK;
}
FIXME( "Unknown IID %s\n", debugstr_guid( riid ) );
@@ -901,10 +895,11 @@ HRESULT IDirectSoundBufferImpl_Create(
TRACE("Created buffer at %p\n", dsb);
dsb->ref = 0;
+ dsb->refiks = 0;
dsb->numIfaces = 0;
dsb->device = device;
dsb->IDirectSoundBuffer8_iface.lpVtbl = &dsbvt;
- dsb->iks = NULL;
+ dsb->IKsPropertySet_iface.lpVtbl = &iksbvt;
/* size depends on version */
CopyMemory(&dsb->dsbd, dsbd, dsbd->dwSize);
@@ -1045,12 +1040,6 @@ HRESULT IDirectSoundBufferImpl_Destroy(
* this object until it is ready to be deleted */
InterlockedIncrement(&pdsb->numIfaces);
- if (pdsb->iks) {
- WARN("iks not NULL\n");
- IKsBufferPropertySetImpl_Destroy(pdsb->iks);
- pdsb->iks = NULL;
- }
-
if (pdsb->ds3db) {
WARN("ds3db not NULL\n");
IDirectSound3DBufferImpl_Destroy(pdsb->ds3db);
@@ -1094,8 +1083,9 @@ HRESULT IDirectSoundBufferImpl_Duplicate(
dsb->buffer->ref++;
list_add_head(&dsb->buffer->buffers, &dsb->entry);
- dsb->ref = 1;
- dsb->numIfaces = 1;
+ dsb->ref = 0;
+ dsb->refiks = 0;
+ dsb->numIfaces = 0;
dsb->state = STATE_STOPPED;
dsb->buf_mixpos = dsb->sec_mixpos = 0;
dsb->notify = NULL;
@@ -1103,7 +1093,6 @@ HRESULT IDirectSoundBufferImpl_Duplicate(
dsb->nrofnotifies = 0;
dsb->device = device;
dsb->ds3db = NULL;
- dsb->iks = NULL; /* FIXME? */
DSOUND_RecalcFormat(dsb);
RtlInitializeResource(&dsb->lock);
@@ -1119,6 +1108,7 @@ HRESULT IDirectSoundBufferImpl_Duplicate(
dsb = NULL;
}
+ IDirectSoundBuffer8_AddRef(&dsb->IDirectSoundBuffer8_iface);
*ppdsb = dsb;
return hres;
}
@@ -1127,36 +1117,44 @@ HRESULT IDirectSoundBufferImpl_Duplicate(
* IKsPropertySet
*/
+static inline IDirectSoundBufferImpl *impl_from_IKsPropertySet(IKsPropertySet *iface)
+{
+ return CONTAINING_RECORD(iface, IDirectSoundBufferImpl, IKsPropertySet_iface);
+}
+
/* IUnknown methods */
static HRESULT WINAPI IKsPropertySetImpl_QueryInterface(IKsPropertySet *iface, REFIID riid,
void **ppobj)
{
- IKsBufferPropertySetImpl *This = (IKsBufferPropertySetImpl *)iface;
+ IDirectSoundBufferImpl *This = impl_from_IKsPropertySet(iface);
+
TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
- return IDirectSoundBuffer_QueryInterface((LPDIRECTSOUNDBUFFER8)This->dsb, riid, ppobj);
+ return IDirectSoundBuffer_QueryInterface(&This->IDirectSoundBuffer8_iface, riid, ppobj);
}
static ULONG WINAPI IKsPropertySetImpl_AddRef(IKsPropertySet *iface)
{
- IKsBufferPropertySetImpl *This = (IKsBufferPropertySetImpl *)iface;
- ULONG ref = InterlockedIncrement(&(This->ref));
+ IDirectSoundBufferImpl *This = impl_from_IKsPropertySet(iface);
+ ULONG ref = InterlockedIncrement(&This->refiks);
+
TRACE("(%p) ref was %d\n", This, ref - 1);
+
+ if(ref == 1)
+ InterlockedIncrement(&This->numIfaces);
+
return ref;
}
static ULONG WINAPI IKsPropertySetImpl_Release(IKsPropertySet *iface)
{
- IKsBufferPropertySetImpl *This = (IKsBufferPropertySetImpl *)iface;
- ULONG ref = InterlockedDecrement(&(This->ref));
+ IDirectSoundBufferImpl *This = impl_from_IKsPropertySet(iface);
+ ULONG ref = InterlockedDecrement(&This->refiks);
+
TRACE("(%p) ref was %d\n", This, ref + 1);
- if (!ref) {
- This->dsb->iks = 0;
- IDirectSoundBuffer_Release((LPDIRECTSOUND3DBUFFER)This->dsb);
- HeapFree(GetProcessHeap(), 0, This);
- TRACE("(%p) released\n", This);
- }
+ if (!ref && !InterlockedDecrement(&This->numIfaces))
+ secondarybuffer_destroy(This);
return ref;
}
@@ -1164,7 +1162,7 @@ static HRESULT WINAPI IKsPropertySetImpl_Get(IKsPropertySet *iface, REFGUID guid
ULONG dwPropID, void *pInstanceData, ULONG cbInstanceData, void *pPropData,
ULONG cbPropData, ULONG *pcbReturned)
{
- IKsBufferPropertySetImpl *This = (IKsBufferPropertySetImpl *)iface;
+ IDirectSoundBufferImpl *This = impl_from_IKsPropertySet(iface);
TRACE("(iface=%p,guidPropSet=%s,dwPropID=%d,pInstanceData=%p,cbInstanceData=%d,pPropData=%p,cbPropData=%d,pcbReturned=%p)\n",
This,debugstr_guid(guidPropSet),dwPropID,pInstanceData,cbInstanceData,pPropData,cbPropData,pcbReturned);
@@ -1176,7 +1174,7 @@ static HRESULT WINAPI IKsPropertySetImpl_Set(IKsPropertySet *iface, REFGUID guid
ULONG dwPropID, void *pInstanceData, ULONG cbInstanceData, void *pPropData,
ULONG cbPropData)
{
- IKsBufferPropertySetImpl *This = (IKsBufferPropertySetImpl *)iface;
+ IDirectSoundBufferImpl *This = impl_from_IKsPropertySet(iface);
TRACE("(%p,%s,%d,%p,%d,%p,%d)\n",This,debugstr_guid(guidPropSet),dwPropID,pInstanceData,cbInstanceData,pPropData,cbPropData);
@@ -1186,14 +1184,14 @@ static HRESULT WINAPI IKsPropertySetImpl_Set(IKsPropertySet *iface, REFGUID guid
static HRESULT WINAPI IKsPropertySetImpl_QuerySupport(IKsPropertySet *iface, REFGUID guidPropSet,
ULONG dwPropID, ULONG *pTypeSupport)
{
- IKsBufferPropertySetImpl *This = (IKsBufferPropertySetImpl *)iface;
+ IDirectSoundBufferImpl *This = impl_from_IKsPropertySet(iface);
TRACE("(%p,%s,%d,%p)\n",This,debugstr_guid(guidPropSet),dwPropID,pTypeSupport);
return E_PROP_ID_UNSUPPORTED;
}
-static const IKsPropertySetVtbl iksbvt = {
+const IKsPropertySetVtbl iksbvt = {
IKsPropertySetImpl_QueryInterface,
IKsPropertySetImpl_AddRef,
IKsPropertySetImpl_Release,
@@ -1201,39 +1199,3 @@ static const IKsPropertySetVtbl iksbvt = {
IKsPropertySetImpl_Set,
IKsPropertySetImpl_QuerySupport
};
-
-HRESULT IKsBufferPropertySetImpl_Create(
- IDirectSoundBufferImpl *dsb,
- IKsBufferPropertySetImpl **piks)
-{
- IKsBufferPropertySetImpl *iks;
- TRACE("(%p,%p)\n",dsb,piks);
- *piks = NULL;
-
- iks = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*iks));
- if (iks == 0) {
- WARN("out of memory\n");
- *piks = NULL;
- return DSERR_OUTOFMEMORY;
- }
-
- iks->ref = 0;
- iks->dsb = dsb;
- dsb->iks = iks;
- iks->lpVtbl = &iksbvt;
-
- IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER)dsb);
-
- *piks = iks;
- return S_OK;
-}
-
-HRESULT IKsBufferPropertySetImpl_Destroy(
- IKsBufferPropertySetImpl *piks)
-{
- TRACE("(%p)\n",piks);
-
- while (IKsPropertySetImpl_Release((LPKSPROPERTYSET)piks) > 0);
-
- return S_OK;
-}
diff --git a/dlls/dsound/dsound_private.h b/dlls/dsound/dsound_private.h
index d945b41..92faff7 100644
--- a/dlls/dsound/dsound_private.h
+++ b/dlls/dsound/dsound_private.h
@@ -50,7 +50,6 @@ typedef struct IDirectSoundCaptureImpl IDirectSoundCaptureImpl;
typedef struct IDirectSoundCaptureBufferImpl IDirectSoundCaptureBufferImpl;
typedef struct IDirectSoundNotifyImpl IDirectSoundNotifyImpl;
typedef struct IDirectSound3DBufferImpl IDirectSound3DBufferImpl;
-typedef struct IKsBufferPropertySetImpl IKsBufferPropertySetImpl;
typedef struct DirectSoundDevice DirectSoundDevice;
typedef struct DirectSoundCaptureDevice DirectSoundCaptureDevice;
@@ -166,8 +165,9 @@ struct IDirectSoundBufferImpl
{
IDirectSoundBuffer8 IDirectSoundBuffer8_iface;
IDirectSound3DListener IDirectSound3DListener_iface; /* only primary buffer */
+ IKsPropertySet IKsPropertySet_iface;
LONG numIfaces; /* "in use interfaces" refcount */
- LONG ref, ref3D;
+ LONG ref, ref3D, refiks;
/* IDirectSoundBufferImpl fields */
DirectSoundDevice* device;
RTL_RWLOCK lock;
@@ -194,9 +194,7 @@ struct IDirectSoundBufferImpl
DS3DBUFFER ds3db_ds3db;
LONG ds3db_lVolume;
BOOL ds3db_need_recalc;
-
/* IKsPropertySet fields */
- IKsBufferPropertySetImpl* iks;
bitsconvertfunc convert;
struct list entry;
};
@@ -213,6 +211,7 @@ HRESULT IDirectSoundBufferImpl_Duplicate(
IDirectSoundBufferImpl *pdsb) DECLSPEC_HIDDEN;
void secondarybuffer_destroy(IDirectSoundBufferImpl *This) DECLSPEC_HIDDEN;
const IDirectSound3DListenerVtbl ds3dlvt DECLSPEC_HIDDEN;
+const IKsPropertySetVtbl iksbvt DECLSPEC_HIDDEN;
/*****************************************************************************
* DirectSoundCaptureDevice implementation structure
@@ -259,24 +258,6 @@ struct IDirectSoundCaptureBufferImpl
int nrofnotifies;
};
-/*****************************************************************************
- * IKsBufferPropertySet implementation structure
- */
-struct IKsBufferPropertySetImpl
-{
- /* IUnknown fields */
- const IKsPropertySetVtbl *lpVtbl;
- LONG ref;
- /* IKsPropertySetImpl fields */
- IDirectSoundBufferImpl* dsb;
-};
-
-HRESULT IKsBufferPropertySetImpl_Create(
- IDirectSoundBufferImpl *dsb,
- IKsBufferPropertySetImpl **piks) DECLSPEC_HIDDEN;
-HRESULT IKsBufferPropertySetImpl_Destroy(
- IKsBufferPropertySetImpl *piks) DECLSPEC_HIDDEN;
-
HRESULT IKsPrivatePropertySetImpl_Create(REFIID riid, IKsPropertySet **piks) DECLSPEC_HIDDEN;
/*****************************************************************************
--
1.7.6.5
More information about the wine-patches
mailing list