2004-01-20 01:21:40 +01:00
|
|
|
/* IDirectMusicWave Implementation
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003-2004 Rok Mandeljc
|
|
|
|
*
|
2007-05-30 12:54:07 +02:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2004-01-20 01:21:40 +01:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2007-05-30 12:54:07 +02:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2004-01-20 01:21:40 +01:00
|
|
|
*
|
2007-05-30 12:54:07 +02:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-01-20 01:21:40 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "dswave_private.h"
|
2015-06-10 01:04:56 +02:00
|
|
|
#include "dmobject.h"
|
2004-01-20 01:21:40 +01:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dswave);
|
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(dmfile);
|
2004-02-25 02:30:03 +01:00
|
|
|
|
|
|
|
/* an interface that is, according to my tests, obtained by loader after loading object; is it acting
|
|
|
|
as some sort of bridge between object and loader? */
|
2005-06-01 21:57:42 +02:00
|
|
|
static const GUID IID_IDirectMusicWavePRIVATE = {0x69e934e4,0x97f1,0x4f1d,{0x88,0xe8,0xf2,0xac,0x88,0x67,0x13,0x27}};
|
2004-01-20 01:21:40 +01:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* IDirectMusicWaveImpl implementation
|
|
|
|
*/
|
2015-06-10 01:00:28 +02:00
|
|
|
typedef struct IDirectMusicWaveImpl {
|
|
|
|
IUnknown IUnknown_iface;
|
2015-06-10 01:04:56 +02:00
|
|
|
struct dmobject dmobj;
|
2015-06-10 01:00:28 +02:00
|
|
|
LONG ref;
|
|
|
|
} IDirectMusicWaveImpl;
|
|
|
|
|
2004-01-20 01:21:40 +01:00
|
|
|
/* IDirectMusicWaveImpl IUnknown part: */
|
2015-06-10 01:00:28 +02:00
|
|
|
static inline IDirectMusicWaveImpl *impl_from_IUnknown(IUnknown *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, IDirectMusicWaveImpl, IUnknown_iface);
|
2004-01-20 01:21:40 +01:00
|
|
|
}
|
|
|
|
|
2015-06-10 01:00:28 +02:00
|
|
|
static HRESULT WINAPI IUnknownImpl_QueryInterface(IUnknown *iface, REFIID riid, void **ret_iface)
|
|
|
|
{
|
|
|
|
IDirectMusicWaveImpl *This = impl_from_IUnknown(iface);
|
|
|
|
|
|
|
|
TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ret_iface);
|
|
|
|
|
|
|
|
*ret_iface = NULL;
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown))
|
|
|
|
*ret_iface = iface;
|
|
|
|
else if (IsEqualIID(riid, &IID_IDirectMusicObject))
|
2015-06-10 01:04:56 +02:00
|
|
|
*ret_iface = &This->dmobj.IDirectMusicObject_iface;
|
2015-06-10 01:00:28 +02:00
|
|
|
else if (IsEqualIID(riid, &IID_IPersistStream))
|
2015-06-10 01:04:56 +02:00
|
|
|
*ret_iface = &This->dmobj.IPersistStream_iface;
|
2015-06-10 01:00:28 +02:00
|
|
|
else if (IsEqualIID(riid, &IID_IDirectMusicWavePRIVATE)) {
|
|
|
|
FIXME("(%p, %s, %p): Unsupported private interface\n", This, debugstr_guid(riid), ret_iface);
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
} else {
|
|
|
|
WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ret_iface);
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown*)*ret_iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
2005-01-14 17:02:20 +01:00
|
|
|
|
2015-06-10 01:00:28 +02:00
|
|
|
static ULONG WINAPI IUnknownImpl_AddRef(IUnknown *iface)
|
|
|
|
{
|
|
|
|
IDirectMusicWaveImpl *This = impl_from_IUnknown(iface);
|
|
|
|
LONG ref = InterlockedIncrement(&This->ref);
|
2005-01-14 17:02:20 +01:00
|
|
|
|
2015-06-10 01:00:28 +02:00
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
2005-02-01 15:21:37 +01:00
|
|
|
|
2015-06-10 01:00:28 +02:00
|
|
|
return ref;
|
2004-01-20 01:21:40 +01:00
|
|
|
}
|
|
|
|
|
2015-06-10 01:00:28 +02:00
|
|
|
static ULONG WINAPI IUnknownImpl_Release(IUnknown *iface)
|
|
|
|
{
|
|
|
|
IDirectMusicWaveImpl *This = impl_from_IUnknown(iface);
|
|
|
|
LONG ref = InterlockedDecrement(&This->ref);
|
2005-01-14 17:02:20 +01:00
|
|
|
|
2015-06-10 01:00:28 +02:00
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
2005-01-14 17:02:20 +01:00
|
|
|
|
2015-06-10 01:00:28 +02:00
|
|
|
if (!ref) {
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
DSWAVE_UnlockModule();
|
|
|
|
}
|
2005-02-01 15:21:37 +01:00
|
|
|
|
2015-06-10 01:00:28 +02:00
|
|
|
return ref;
|
2004-01-20 01:21:40 +01:00
|
|
|
}
|
|
|
|
|
2015-06-10 01:00:28 +02:00
|
|
|
static const IUnknownVtbl unknown_vtbl = {
|
|
|
|
IUnknownImpl_QueryInterface,
|
|
|
|
IUnknownImpl_AddRef,
|
|
|
|
IUnknownImpl_Release
|
2004-01-20 01:21:40 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/* IDirectMusicWaveImpl IDirectMusicObject part: */
|
2018-07-17 23:55:33 +02:00
|
|
|
static HRESULT WINAPI wave_IDirectMusicObject_ParseDescriptor(IDirectMusicObject *iface,
|
|
|
|
IStream *stream, DMUS_OBJECTDESC *desc)
|
2015-06-10 01:04:56 +02:00
|
|
|
{
|
2018-07-17 23:55:33 +02:00
|
|
|
struct chunk_entry riff = {0};
|
|
|
|
HRESULT hr;
|
2004-01-20 01:21:40 +01:00
|
|
|
|
2018-07-17 23:55:33 +02:00
|
|
|
TRACE("(%p, %p, %p)\n", iface, stream, desc);
|
2008-02-26 21:20:15 +01:00
|
|
|
|
2018-07-17 23:55:33 +02:00
|
|
|
if (!stream || !desc)
|
|
|
|
return E_POINTER;
|
2008-02-26 21:20:15 +01:00
|
|
|
|
2018-07-17 23:55:33 +02:00
|
|
|
if ((hr = stream_get_chunk(stream, &riff)) != S_OK)
|
|
|
|
return hr;
|
|
|
|
if (riff.id != FOURCC_RIFF || riff.type != mmioFOURCC('W','A','V','E')) {
|
|
|
|
TRACE("loading failed: unexpected %s\n", debugstr_chunk(&riff));
|
|
|
|
stream_skip_chunk(stream, &riff);
|
|
|
|
return DMUS_E_CHUNKNOTFOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = dmobj_parsedescriptor(stream, &riff, desc,
|
|
|
|
DMUS_OBJ_NAME_INFO | DMUS_OBJ_OBJECT | DMUS_OBJ_VERSION);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
2019-12-13 00:29:07 +01:00
|
|
|
TRACE("returning descriptor:\n");
|
|
|
|
dump_DMUS_OBJECTDESC(desc);
|
2018-07-17 23:55:33 +02:00
|
|
|
return S_OK;
|
2004-01-20 01:21:40 +01:00
|
|
|
}
|
|
|
|
|
2015-06-10 01:04:56 +02:00
|
|
|
static const IDirectMusicObjectVtbl dmobject_vtbl = {
|
|
|
|
dmobj_IDirectMusicObject_QueryInterface,
|
|
|
|
dmobj_IDirectMusicObject_AddRef,
|
|
|
|
dmobj_IDirectMusicObject_Release,
|
|
|
|
dmobj_IDirectMusicObject_GetDescriptor,
|
|
|
|
dmobj_IDirectMusicObject_SetDescriptor,
|
2018-07-17 23:55:33 +02:00
|
|
|
wave_IDirectMusicObject_ParseDescriptor
|
2004-01-20 01:21:40 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/* IDirectMusicWaveImpl IPersistStream part: */
|
2015-06-10 01:04:56 +02:00
|
|
|
static inline IDirectMusicWaveImpl *impl_from_IPersistStream(IPersistStream *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, IDirectMusicWaveImpl, dmobj.IPersistStream_iface);
|
2004-01-20 01:21:40 +01:00
|
|
|
}
|
|
|
|
|
2015-06-10 01:04:56 +02:00
|
|
|
static HRESULT WINAPI IPersistStreamImpl_Load(IPersistStream *iface, IStream *pStm)
|
|
|
|
{
|
|
|
|
IDirectMusicWaveImpl *This = impl_from_IPersistStream(iface);
|
2004-02-25 02:30:03 +01:00
|
|
|
DMUS_PRIVATE_CHUNK Chunk;
|
|
|
|
DWORD StreamSize, StreamCount, ListSize[1], ListCount[1];
|
|
|
|
LARGE_INTEGER liMove; /* used when skipping chunks */
|
|
|
|
|
|
|
|
FIXME("(%p, %p): loading not implemented yet (only descriptor is loaded)\n", This, pStm);
|
2008-02-26 21:20:15 +01:00
|
|
|
|
2004-02-25 02:30:03 +01:00
|
|
|
/* FIXME: should this be determined from stream? */
|
2015-06-10 01:06:30 +02:00
|
|
|
This->dmobj.desc.dwValidData |= DMUS_OBJ_CLASS;
|
|
|
|
This->dmobj.desc.guidClass = CLSID_DirectMusicSegment;
|
2008-02-26 21:20:15 +01:00
|
|
|
|
2004-02-25 02:30:03 +01:00
|
|
|
IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
|
2006-10-08 23:50:59 +02:00
|
|
|
TRACE_(dmfile)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
|
2004-02-25 02:30:03 +01:00
|
|
|
switch (Chunk.fccID) {
|
|
|
|
case FOURCC_RIFF: {
|
|
|
|
IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
|
|
|
|
TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
|
|
|
|
StreamSize = Chunk.dwSize - sizeof(FOURCC);
|
|
|
|
StreamCount = 0;
|
|
|
|
if (Chunk.fccID == mmioFOURCC('W','A','V','E')) {
|
|
|
|
TRACE_(dmfile)(": wave form\n");
|
|
|
|
do {
|
|
|
|
IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
|
|
|
|
StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
|
2006-10-08 23:50:59 +02:00
|
|
|
TRACE_(dmfile)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
|
2004-02-25 02:30:03 +01:00
|
|
|
switch (Chunk.fccID) {
|
|
|
|
case DMUS_FOURCC_GUID_CHUNK: {
|
|
|
|
TRACE_(dmfile)(": GUID chunk\n");
|
2015-06-10 01:06:30 +02:00
|
|
|
This->dmobj.desc.dwValidData |= DMUS_OBJ_OBJECT;
|
|
|
|
IStream_Read (pStm, &This->dmobj.desc.guidObject, Chunk.dwSize, NULL);
|
2004-02-25 02:30:03 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DMUS_FOURCC_VERSION_CHUNK: {
|
|
|
|
TRACE_(dmfile)(": version chunk\n");
|
2015-06-10 01:06:30 +02:00
|
|
|
This->dmobj.desc.dwValidData |= DMUS_OBJ_VERSION;
|
|
|
|
IStream_Read (pStm, &This->dmobj.desc.vVersion, Chunk.dwSize, NULL);
|
2004-02-25 02:30:03 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DMUS_FOURCC_CATEGORY_CHUNK: {
|
|
|
|
TRACE_(dmfile)(": category chunk\n");
|
2015-06-10 01:06:30 +02:00
|
|
|
This->dmobj.desc.dwValidData |= DMUS_OBJ_CATEGORY;
|
|
|
|
IStream_Read (pStm, This->dmobj.desc.wszCategory, Chunk.dwSize, NULL);
|
2004-02-25 02:30:03 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case FOURCC_LIST: {
|
|
|
|
IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
|
|
|
|
TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
|
|
|
|
ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
|
|
|
|
ListCount[0] = 0;
|
|
|
|
switch (Chunk.fccID) {
|
|
|
|
/* evil M$ UNFO list, which can (!?) contain INFO elements */
|
|
|
|
case DMUS_FOURCC_UNFO_LIST: {
|
|
|
|
TRACE_(dmfile)(": UNFO list\n");
|
|
|
|
do {
|
|
|
|
IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
|
|
|
|
ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
|
2006-10-08 23:50:59 +02:00
|
|
|
TRACE_(dmfile)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
|
2004-02-25 02:30:03 +01:00
|
|
|
switch (Chunk.fccID) {
|
|
|
|
/* don't ask me why, but M$ puts INFO elements in UNFO list sometimes
|
|
|
|
(though strings seem to be valid unicode) */
|
|
|
|
case mmioFOURCC('I','N','A','M'):
|
|
|
|
case DMUS_FOURCC_UNAM_CHUNK: {
|
|
|
|
TRACE_(dmfile)(": name chunk\n");
|
2015-06-10 01:06:30 +02:00
|
|
|
This->dmobj.desc.dwValidData |= DMUS_OBJ_NAME;
|
|
|
|
IStream_Read (pStm, This->dmobj.desc.wszName, Chunk.dwSize, NULL);
|
2004-02-25 02:30:03 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case mmioFOURCC('I','A','R','T'):
|
|
|
|
case DMUS_FOURCC_UART_CHUNK: {
|
|
|
|
TRACE_(dmfile)(": artist chunk (ignored)\n");
|
|
|
|
liMove.QuadPart = Chunk.dwSize;
|
|
|
|
IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case mmioFOURCC('I','C','O','P'):
|
|
|
|
case DMUS_FOURCC_UCOP_CHUNK: {
|
|
|
|
TRACE_(dmfile)(": copyright chunk (ignored)\n");
|
|
|
|
liMove.QuadPart = Chunk.dwSize;
|
|
|
|
IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case mmioFOURCC('I','S','B','J'):
|
|
|
|
case DMUS_FOURCC_USBJ_CHUNK: {
|
|
|
|
TRACE_(dmfile)(": subject chunk (ignored)\n");
|
|
|
|
liMove.QuadPart = Chunk.dwSize;
|
|
|
|
IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case mmioFOURCC('I','C','M','T'):
|
|
|
|
case DMUS_FOURCC_UCMT_CHUNK: {
|
|
|
|
TRACE_(dmfile)(": comment chunk (ignored)\n");
|
|
|
|
liMove.QuadPart = Chunk.dwSize;
|
|
|
|
IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
2011-07-27 13:38:43 +02:00
|
|
|
TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
|
2004-02-25 02:30:03 +01:00
|
|
|
liMove.QuadPart = Chunk.dwSize;
|
|
|
|
IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-10-08 23:50:59 +02:00
|
|
|
TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
|
2004-02-25 02:30:03 +01:00
|
|
|
} while (ListCount[0] < ListSize[0]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
TRACE_(dmfile)(": unknown (skipping)\n");
|
|
|
|
liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
|
|
|
|
IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
2011-07-27 13:38:43 +02:00
|
|
|
TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
|
2004-02-25 02:30:03 +01:00
|
|
|
liMove.QuadPart = Chunk.dwSize;
|
|
|
|
IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-10-08 23:50:59 +02:00
|
|
|
TRACE_(dmfile)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount, StreamSize);
|
2004-02-25 02:30:03 +01:00
|
|
|
} while (StreamCount < StreamSize);
|
|
|
|
} else {
|
|
|
|
TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
|
|
|
|
liMove.QuadPart = StreamSize;
|
|
|
|
IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE_(dmfile)(": reading finished\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
|
|
|
|
liMove.QuadPart = Chunk.dwSize;
|
|
|
|
IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
|
|
|
|
return DMUS_E_INVALIDFILE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-20 01:21:40 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2015-06-10 01:04:56 +02:00
|
|
|
static const IPersistStreamVtbl persiststream_vtbl = {
|
|
|
|
dmobj_IPersistStream_QueryInterface,
|
|
|
|
dmobj_IPersistStream_AddRef,
|
|
|
|
dmobj_IPersistStream_Release,
|
|
|
|
dmobj_IPersistStream_GetClassID,
|
|
|
|
unimpl_IPersistStream_IsDirty,
|
|
|
|
IPersistStreamImpl_Load,
|
|
|
|
unimpl_IPersistStream_Save,
|
|
|
|
unimpl_IPersistStream_GetSizeMax
|
2004-01-20 01:21:40 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/* for ClassFactory */
|
2014-03-13 23:45:16 +01:00
|
|
|
HRESULT WINAPI create_dswave(REFIID lpcGUID, void **ppobj)
|
|
|
|
{
|
2015-06-10 01:07:49 +02:00
|
|
|
IDirectMusicWaveImpl *obj;
|
2015-06-10 01:00:28 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2015-06-10 01:07:49 +02:00
|
|
|
obj = HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectMusicWaveImpl));
|
|
|
|
if (!obj) {
|
|
|
|
*ppobj = NULL;
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2015-06-10 01:00:28 +02:00
|
|
|
obj->IUnknown_iface.lpVtbl = &unknown_vtbl;
|
|
|
|
obj->ref = 1;
|
2015-06-10 01:04:56 +02:00
|
|
|
dmobject_init(&obj->dmobj, &CLSID_DirectSoundWave, &obj->IUnknown_iface);
|
|
|
|
obj->dmobj.IDirectMusicObject_iface.lpVtbl = &dmobject_vtbl;
|
|
|
|
obj->dmobj.IPersistStream_iface.lpVtbl = &persiststream_vtbl;
|
2008-02-26 21:20:15 +01:00
|
|
|
|
2015-06-10 01:00:28 +02:00
|
|
|
DSWAVE_LockModule();
|
|
|
|
hr = IUnknown_QueryInterface(&obj->IUnknown_iface, lpcGUID, ppobj);
|
|
|
|
IUnknown_Release(&obj->IUnknown_iface);
|
|
|
|
return hr;
|
2004-01-20 01:21:40 +01:00
|
|
|
}
|