Commit 196aa817 authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

dmloader: Get rid of the custom generic stream wrapper.

parent 975f2629
...@@ -61,7 +61,6 @@ extern HRESULT create_dmloader(REFIID riid, void **ret_iface); ...@@ -61,7 +61,6 @@ extern HRESULT create_dmloader(REFIID riid, void **ret_iface);
extern HRESULT create_dmcontainer(REFIID riid, void **ret_iface); extern HRESULT create_dmcontainer(REFIID riid, void **ret_iface);
extern HRESULT DMUSIC_CreateDirectMusicLoaderFileStream(void **ppobj); extern HRESULT DMUSIC_CreateDirectMusicLoaderFileStream(void **ppobj);
extern HRESULT DMUSIC_CreateDirectMusicLoaderResourceStream(void **ppobj); extern HRESULT DMUSIC_CreateDirectMusicLoaderResourceStream(void **ppobj);
extern HRESULT DMUSIC_CreateDirectMusicLoaderGenericStream(void **ppobj);
/***************************************************************************** /*****************************************************************************
* IDirectMusicLoaderFileStream implementation structure * IDirectMusicLoaderFileStream implementation structure
...@@ -98,21 +97,6 @@ struct IDirectMusicLoaderResourceStream { ...@@ -98,21 +97,6 @@ struct IDirectMusicLoaderResourceStream {
extern HRESULT WINAPI IDirectMusicLoaderResourceStream_Attach(LPSTREAM iface, LPBYTE pbMemData, extern HRESULT WINAPI IDirectMusicLoaderResourceStream_Attach(LPSTREAM iface, LPBYTE pbMemData,
LONGLONG llMemLength, LONGLONG llPos); LONGLONG llMemLength, LONGLONG llPos);
/*****************************************************************************
* IDirectMusicLoaderGenericStream implementation structure
*/
struct IDirectMusicLoaderGenericStream {
/* IUnknown fields */
const IStreamVtbl *StreamVtbl;
/* reference counter */
LONG dwRef;
/* stream */
LPSTREAM pStream;
};
/* Custom: */
extern HRESULT WINAPI IDirectMusicLoaderGenericStream_Attach(LPSTREAM iface, LPSTREAM pStream);
extern HRESULT loader_stream_create(IDirectMusicLoader *loader, IStream *stream, IStream **ret_iface); extern HRESULT loader_stream_create(IDirectMusicLoader *loader, IStream *stream, IStream **ret_iface);
#include "debug.h" #include "debug.h"
......
...@@ -356,23 +356,13 @@ static HRESULT WINAPI loader_GetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDE ...@@ -356,23 +356,13 @@ static HRESULT WINAPI loader_GetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDE
return result; return result;
} }
} }
else if (pDesc->dwValidData & DMUS_OBJ_STREAM) { else if (pDesc->dwValidData & DMUS_OBJ_STREAM)
/* load object from stream */
TRACE(": loading from stream\n");
/* create universal stream and associate it with given one */
result = DMUSIC_CreateDirectMusicLoaderGenericStream ((LPVOID*)&pStream);
if (FAILED(result)) {
ERR(": could not create generic stream\n");
return result;
}
result = IDirectMusicLoaderGenericStream_Attach(pStream, pDesc->pStream);
if (FAILED(result))
{ {
ERR(": failed to attach stream\n"); pStream = pDesc->pStream;
IStream_Release (pStream); IStream_AddRef(pStream);
return result;
} }
} else { else
{
/* nowhere to load from */ /* nowhere to load from */
FIXME(": unknown/unsupported way of loading\n"); FIXME(": unknown/unsupported way of loading\n");
return DMUS_E_LOADER_NOFILENAME; /* test shows this is returned */ return DMUS_E_LOADER_NOFILENAME; /* test shows this is returned */
...@@ -499,21 +489,10 @@ static HRESULT WINAPI loader_SetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDE ...@@ -499,21 +489,10 @@ static HRESULT WINAPI loader_SetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDE
return DMUS_E_LOADER_FAILEDOPEN; return DMUS_E_LOADER_FAILEDOPEN;
} }
} }
else if (pDesc->dwValidData & DMUS_OBJ_STREAM) { else if (pDesc->dwValidData & DMUS_OBJ_STREAM)
/* create stream */
hr = DMUSIC_CreateDirectMusicLoaderGenericStream ((LPVOID*)&pStream);
if (FAILED(hr)) {
ERR(": could not create generic stream\n");
return DMUS_E_LOADER_FAILEDOPEN;
}
/* attach stream */
hr = IDirectMusicLoaderGenericStream_Attach(pStream, pDesc->pStream);
if (FAILED(hr))
{ {
ERR(": could not attach stream\n"); pStream = pDesc->pStream;
IStream_Release (pStream); IStream_AddRef(pStream);
return DMUS_E_LOADER_FAILEDOPEN;
}
} }
else if (pDesc->dwValidData & DMUS_OBJ_MEMORY) { else if (pDesc->dwValidData & DMUS_OBJ_MEMORY) {
/* create stream */ /* create stream */
......
...@@ -286,7 +286,6 @@ HRESULT loader_stream_create(IDirectMusicLoader *loader, IStream *stream, ...@@ -286,7 +286,6 @@ HRESULT loader_stream_create(IDirectMusicLoader *loader, IStream *stream,
static ULONG WINAPI IDirectMusicLoaderFileStream_IStream_AddRef (LPSTREAM iface); static ULONG WINAPI IDirectMusicLoaderFileStream_IStream_AddRef (LPSTREAM iface);
static ULONG WINAPI IDirectMusicLoaderResourceStream_IStream_AddRef (LPSTREAM iface); static ULONG WINAPI IDirectMusicLoaderResourceStream_IStream_AddRef (LPSTREAM iface);
static ULONG WINAPI IDirectMusicLoaderGenericStream_IStream_AddRef (LPSTREAM iface);
/***************************************************************************** /*****************************************************************************
...@@ -710,210 +709,3 @@ HRESULT DMUSIC_CreateDirectMusicLoaderResourceStream (void** ppobj) { ...@@ -710,210 +709,3 @@ HRESULT DMUSIC_CreateDirectMusicLoaderResourceStream (void** ppobj) {
return IDirectMusicLoaderResourceStream_IStream_QueryInterface ((LPSTREAM)&obj->StreamVtbl, &IID_IStream, ppobj); return IDirectMusicLoaderResourceStream_IStream_QueryInterface ((LPSTREAM)&obj->StreamVtbl, &IID_IStream, ppobj);
} }
/*****************************************************************************
* IDirectMusicLoaderGenericStream implementation
*/
/* Custom : */
static void IDirectMusicLoaderGenericStream_Detach (LPSTREAM iface) {
ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
if (This->pStream)
IStream_Release (This->pStream);
This->pStream = NULL;
}
HRESULT WINAPI IDirectMusicLoaderGenericStream_Attach (LPSTREAM iface, LPSTREAM pStream) {
ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
TRACE("(%p, %p)\n", This, pStream);
if (!pStream) {
WARN(": invalid pStream\n");
return E_FAIL;
}
IDirectMusicLoaderGenericStream_Detach (iface);
IStream_Clone (pStream, &This->pStream);
return S_OK;
}
/* IUnknown/IStream part: */
static HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_QueryInterface (LPSTREAM iface, REFIID riid, void** ppobj) {
ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
if (IsEqualIID (riid, &IID_IUnknown) ||
IsEqualIID (riid, &IID_IStream)) {
*ppobj = &This->StreamVtbl;
IDirectMusicLoaderGenericStream_IStream_AddRef ((LPSTREAM)&This->StreamVtbl);
return S_OK;
}
WARN(": not found\n");
return E_NOINTERFACE;
}
static ULONG WINAPI IDirectMusicLoaderGenericStream_IStream_AddRef (LPSTREAM iface) {
ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
TRACE("(%p): AddRef from %ld\n", This, This->dwRef);
return InterlockedIncrement (&This->dwRef);
}
static ULONG WINAPI IDirectMusicLoaderGenericStream_IStream_Release (LPSTREAM iface) {
ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
DWORD dwRef = InterlockedDecrement (&This->dwRef);
TRACE("(%p): ReleaseRef to %ld\n", This, dwRef);
if (dwRef == 0) {
IDirectMusicLoaderGenericStream_Detach (iface);
HeapFree (GetProcessHeap(), 0, This);
}
return dwRef;
}
static HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_Read (LPSTREAM iface, void* pv, ULONG cb, ULONG* pcbRead) {
ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
TRACE_(dmfileraw)("(%p, %p, %#lx, %p): redirecting to low-level stream\n", This, pv, cb, pcbRead);
if (!This->pStream)
return E_FAIL;
return IStream_Read (This->pStream, pv, cb, pcbRead);
}
static HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_Seek (LPSTREAM iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition) {
ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
TRACE_(dmfileraw)("(%p, %s, %s, %p): redirecting to low-level stream\n", This, wine_dbgstr_longlong(dlibMove.QuadPart), resolve_STREAM_SEEK(dwOrigin), plibNewPosition);
if (!This->pStream)
return E_FAIL;
return IStream_Seek (This->pStream, dlibMove, dwOrigin, plibNewPosition);
}
static HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_Clone (LPSTREAM iface, IStream** ppstm) {
ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
LPSTREAM pOther = NULL;
LPSTREAM pLowLevel = NULL;
HRESULT result;
TRACE("(%p, %p)\n", iface, ppstm);
result = DMUSIC_CreateDirectMusicLoaderGenericStream ((LPVOID*)&pOther);
if (FAILED(result)) return result;
if (FAILED(IStream_Clone (This->pStream, &pLowLevel))) {
IStream_Release(pOther);
return E_FAIL;
}
IDirectMusicLoaderGenericStream_Attach (pOther, pLowLevel);
TRACE(": succeeded\n");
*ppstm = pOther;
return S_OK;
}
static HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_Write (LPSTREAM iface, const void* pv, ULONG cb, ULONG* pcbWritten) {
ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
TRACE_(dmfileraw)("(%p, %p, %#lx, %p): redirecting to low-level stream\n", This, pv, cb, pcbWritten);
if (!This->pStream)
return E_FAIL;
return IStream_Write (This->pStream, pv, cb, pcbWritten);
}
static HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_SetSize (LPSTREAM iface, ULARGE_INTEGER libNewSize) {
ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
TRACE("(%p, %s): redirecting to low-level stream\n", This, wine_dbgstr_longlong(libNewSize.QuadPart));
if (!This->pStream)
return E_FAIL;
return IStream_SetSize (This->pStream, libNewSize);
}
static HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_CopyTo (LPSTREAM iface, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten) {
ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
TRACE("(%p, %p, %s, %p, %p): redirecting to low-level stream\n", This, pstm, wine_dbgstr_longlong(cb.QuadPart), pcbRead, pcbWritten);
if (!This->pStream)
return E_FAIL;
return IStream_CopyTo (This->pStream, pstm, cb, pcbRead, pcbWritten);
}
static HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_Commit (LPSTREAM iface, DWORD grfCommitFlags) {
ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
TRACE("(%p, %#lx): redirecting to low-level stream\n", This, grfCommitFlags);
if (!This->pStream)
return E_FAIL;
return IStream_Commit (This->pStream, grfCommitFlags);
}
static HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_Revert (LPSTREAM iface) {
ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
TRACE("(%p): redirecting to low-level stream\n", This);
if (!This->pStream)
return E_FAIL;
return IStream_Revert (This->pStream);
}
static HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_LockRegion (LPSTREAM iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) {
ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
TRACE("(%p, %s, %s, %#lx): redirecting to low-level stream\n", This, wine_dbgstr_longlong(libOffset.QuadPart), wine_dbgstr_longlong(cb.QuadPart), dwLockType);
if (!This->pStream)
return E_FAIL;
return IStream_LockRegion (This->pStream, libOffset, cb, dwLockType);
}
static HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_UnlockRegion (LPSTREAM iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) {
ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
TRACE("(%p, %s, %s, %#lx): redirecting to low-level stream\n", This, wine_dbgstr_longlong(libOffset.QuadPart), wine_dbgstr_longlong(cb.QuadPart), dwLockType);
if (!This->pStream)
return E_FAIL;
return IStream_UnlockRegion (This->pStream, libOffset, cb, dwLockType);
}
static HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_Stat (LPSTREAM iface, STATSTG* pstatstg, DWORD grfStatFlag) {
ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
TRACE("(%p, %p, %#lx): redirecting to low-level stream\n", This, pstatstg, grfStatFlag);
if (!This->pStream)
return E_FAIL;
return IStream_Stat (This->pStream, pstatstg, grfStatFlag);
}
static const IStreamVtbl DirectMusicLoaderGenericStream_Stream_Vtbl = {
IDirectMusicLoaderGenericStream_IStream_QueryInterface,
IDirectMusicLoaderGenericStream_IStream_AddRef,
IDirectMusicLoaderGenericStream_IStream_Release,
IDirectMusicLoaderGenericStream_IStream_Read,
IDirectMusicLoaderGenericStream_IStream_Write,
IDirectMusicLoaderGenericStream_IStream_Seek,
IDirectMusicLoaderGenericStream_IStream_SetSize,
IDirectMusicLoaderGenericStream_IStream_CopyTo,
IDirectMusicLoaderGenericStream_IStream_Commit,
IDirectMusicLoaderGenericStream_IStream_Revert,
IDirectMusicLoaderGenericStream_IStream_LockRegion,
IDirectMusicLoaderGenericStream_IStream_UnlockRegion,
IDirectMusicLoaderGenericStream_IStream_Stat,
IDirectMusicLoaderGenericStream_IStream_Clone
};
HRESULT DMUSIC_CreateDirectMusicLoaderGenericStream (void** ppobj) {
IDirectMusicLoaderGenericStream *obj;
TRACE("(%p)\n", ppobj);
*ppobj = NULL;
if (!(obj = calloc(1, sizeof(*obj)))) return E_OUTOFMEMORY;
obj->StreamVtbl = &DirectMusicLoaderGenericStream_Stream_Vtbl;
obj->dwRef = 0; /* will be inited with QueryInterface */
return IDirectMusicLoaderGenericStream_IStream_QueryInterface ((LPSTREAM)&obj->StreamVtbl, &IID_IStream, ppobj);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment