dmusic: Pass creation parameters to DMUSIC_CreateDirectMusicBufferImpl then allocate data buffer and set format accordingly.

This commit is contained in:
Christian Costa 2012-04-23 21:25:53 +02:00 committed by Alexandre Julliard
parent 209bc696c1
commit 1b33b1d5cd
3 changed files with 48 additions and 21 deletions

View File

@ -53,6 +53,7 @@ static ULONG WINAPI IDirectMusicBufferImpl_Release (LPDIRECTMUSICBUFFER iface) {
TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
if (!refCount) {
HeapFree(GetProcessHeap(), 0, This->data);
HeapFree(GetProcessHeap(), 0, This);
}
@ -159,17 +160,37 @@ static const IDirectMusicBufferVtbl DirectMusicBuffer_Vtbl = {
IDirectMusicBufferImpl_SetUsedBytes
};
/* for ClassFactory */
HRESULT WINAPI DMUSIC_CreateDirectMusicBufferImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) {
IDirectMusicBufferImpl* dmbuff;
dmbuff = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicBufferImpl));
if (NULL == dmbuff) {
*ppobj = NULL;
return E_OUTOFMEMORY;
}
dmbuff->lpVtbl = &DirectMusicBuffer_Vtbl;
dmbuff->ref = 0; /* will be inited by QueryInterface */
return IDirectMusicBufferImpl_QueryInterface ((LPDIRECTMUSICBUFFER)dmbuff, lpcGUID, ppobj);
HRESULT WINAPI DMUSIC_CreateDirectMusicBufferImpl(LPDMUS_BUFFERDESC desc, LPVOID* ret_iface)
{
IDirectMusicBufferImpl* dmbuffer;
HRESULT hr;
TRACE("(%p, %p)\n", desc, ret_iface);
*ret_iface = NULL;
dmbuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicBufferImpl));
if (!dmbuffer)
return E_OUTOFMEMORY;
dmbuffer->lpVtbl = &DirectMusicBuffer_Vtbl;
dmbuffer->ref = 0; /* Will be inited by QueryInterface */
memcpy(&dmbuffer->format, &desc->guidBufferFormat, sizeof(GUID));
dmbuffer->size = (desc->cbBuffer + 3) & ~3; /* Buffer size must be multiple of 4 bytes */
dmbuffer->data = HeapAlloc(GetProcessHeap(), 0, dmbuffer->size);
if (!dmbuffer->data) {
HeapFree(GetProcessHeap(), 0, dmbuffer);
return E_OUTOFMEMORY;
}
hr = IDirectMusicBufferImpl_QueryInterface((LPDIRECTMUSICBUFFER)dmbuffer, &IID_IDirectMusicBuffer, ret_iface);
if (FAILED(hr))
{
HeapFree(GetProcessHeap(), 0, dmbuffer->data);
HeapFree(GetProcessHeap(), 0, dmbuffer);
}
return hr;
}

View File

@ -165,7 +165,7 @@ static HRESULT WINAPI IDirectMusic8Impl_CreateMusicBuffer(LPDIRECTMUSIC8 iface,
if (!pBufferDesc || !ppBuffer)
return E_POINTER;
return DMUSIC_CreateDirectMusicBufferImpl(&IID_IDirectMusicBuffer, (LPVOID)ppBuffer, NULL);
return DMUSIC_CreateDirectMusicBufferImpl(pBufferDesc, (LPVOID)ppBuffer);
}
static HRESULT WINAPI IDirectMusic8Impl_CreatePort(LPDIRECTMUSIC8 iface, REFCLSID rclsidPort, LPDMUS_PORTPARAMS pPortParams, LPDIRECTMUSICPORT* ppPort, LPUNKNOWN pUnkOuter)

View File

@ -75,13 +75,16 @@ typedef struct DMUSIC_PRIVATE_CHANNEL_GROUP_ {
/*****************************************************************************
* ClassFactory
*/
/* CLSID */
extern HRESULT WINAPI DMUSIC_CreateDirectMusicImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) DECLSPEC_HIDDEN;
extern HRESULT WINAPI DMUSIC_CreateDirectMusicBufferImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) DECLSPEC_HIDDEN;
extern HRESULT WINAPI DMUSIC_CreateDirectMusicCollectionImpl(LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) DECLSPEC_HIDDEN;
/* Internal */
extern HRESULT WINAPI DMUSIC_CreateDirectMusicBufferImpl(LPDMUS_BUFFERDESC desc, LPVOID* ret_iface) DECLSPEC_HIDDEN;
extern HRESULT WINAPI DMUSIC_CreateDirectMusicDownloadedInstrumentImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) DECLSPEC_HIDDEN;
extern HRESULT WINAPI DMUSIC_CreateDirectMusicDownloadImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) DECLSPEC_HIDDEN;
extern HRESULT WINAPI DMUSIC_CreateReferenceClockImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) DECLSPEC_HIDDEN;
extern HRESULT WINAPI DMUSIC_CreateDirectMusicCollectionImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) DECLSPEC_HIDDEN;
extern HRESULT WINAPI DMUSIC_CreateDirectMusicInstrumentImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) DECLSPEC_HIDDEN;
/*****************************************************************************
@ -102,11 +105,14 @@ struct IDirectMusic8Impl {
* IDirectMusicBufferImpl implementation structure
*/
struct IDirectMusicBufferImpl {
/* IUnknown fields */
const IDirectMusicBufferVtbl *lpVtbl;
LONG ref;
/* IUnknown fields */
const IDirectMusicBufferVtbl *lpVtbl;
LONG ref;
/* IDirectMusicBufferImpl fields */
/* IDirectMusicBufferImpl fields */
GUID format;
DWORD size;
LPBYTE data;
};
/*****************************************************************************