From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dmcompos/chordmap.c | 2 -- dlls/dmcompos/chordmaptrack.c | 2 -- dlls/dmcompos/composer.c | 2 -- dlls/dmcompos/dmcompos_main.c | 21 --------------------- dlls/dmcompos/dmcompos_private.h | 7 ------- dlls/dmcompos/signposttrack.c | 2 -- 6 files changed, 36 deletions(-)
diff --git a/dlls/dmcompos/chordmap.c b/dlls/dmcompos/chordmap.c index adc17402f39..86134451846 100644 --- a/dlls/dmcompos/chordmap.c +++ b/dlls/dmcompos/chordmap.c @@ -81,7 +81,6 @@ static ULONG WINAPI IDirectMusicChordMapImpl_Release(IDirectMusicChordMap *iface
if (!ref) { HeapFree(GetProcessHeap(), 0, This); - DMCOMPOS_UnlockModule(); }
return ref; @@ -326,7 +325,6 @@ HRESULT create_dmchordmap(REFIID lpcGUID, void **ppobj) obj->dmobj.IDirectMusicObject_iface.lpVtbl = &dmobject_vtbl; obj->dmobj.IPersistStream_iface.lpVtbl = &persiststream_vtbl;
- DMCOMPOS_LockModule(); hr = IDirectMusicChordMap_QueryInterface(&obj->IDirectMusicChordMap_iface, lpcGUID, ppobj); IDirectMusicChordMap_Release(&obj->IDirectMusicChordMap_iface);
diff --git a/dlls/dmcompos/chordmaptrack.c b/dlls/dmcompos/chordmaptrack.c index 66517340d70..35c64aab4a6 100644 --- a/dlls/dmcompos/chordmaptrack.c +++ b/dlls/dmcompos/chordmaptrack.c @@ -79,7 +79,6 @@ static ULONG WINAPI chordmap_track_Release(IDirectMusicTrack8 *iface)
if (!ref) { HeapFree(GetProcessHeap(), 0, This); - DMCOMPOS_UnlockModule(); }
return ref; @@ -301,7 +300,6 @@ HRESULT create_dmchordmaptrack(REFIID lpcGUID, void **ppobj) (IUnknown *)&track->IDirectMusicTrack8_iface); track->dmobj.IPersistStream_iface.lpVtbl = &persiststream_vtbl;
- DMCOMPOS_LockModule(); hr = IDirectMusicTrack8_QueryInterface(&track->IDirectMusicTrack8_iface, lpcGUID, ppobj); IDirectMusicTrack8_Release(&track->IDirectMusicTrack8_iface);
diff --git a/dlls/dmcompos/composer.c b/dlls/dmcompos/composer.c index a2a58396ee5..47e12358201 100644 --- a/dlls/dmcompos/composer.c +++ b/dlls/dmcompos/composer.c @@ -69,7 +69,6 @@ static ULONG WINAPI IDirectMusicComposerImpl_Release(IDirectMusicComposer *iface
if (ref == 0) { HeapFree(GetProcessHeap(), 0, This); - DMCOMPOS_UnlockModule(); }
return ref; @@ -183,7 +182,6 @@ HRESULT create_dmcomposer(REFIID riid, void **ret_iface) obj->IDirectMusicComposer_iface.lpVtbl = &dmcomposer_vtbl; obj->ref = 1;
- DMCOMPOS_LockModule(); hr = IDirectMusicComposer_QueryInterface(&obj->IDirectMusicComposer_iface, riid, ret_iface); IDirectMusicComposer_Release(&obj->IDirectMusicComposer_iface);
diff --git a/dlls/dmcompos/dmcompos_main.c b/dlls/dmcompos/dmcompos_main.c index dff77aa4d32..f7b5755683e 100644 --- a/dlls/dmcompos/dmcompos_main.c +++ b/dlls/dmcompos/dmcompos_main.c @@ -38,8 +38,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(dmcompos);
-LONG DMCOMPOS_refCount = 0; - typedef struct { IClassFactory IClassFactory_iface; HRESULT (*fnCreateInstance)(REFIID riid, void **ret_iface); @@ -82,15 +80,11 @@ static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID r
static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface) { - DMCOMPOS_LockModule(); - return 2; /* non-heap based object */ }
static ULONG WINAPI ClassFactory_Release(IClassFactory *iface) { - DMCOMPOS_UnlockModule(); - return 1; /* non-heap based object */ }
@@ -112,12 +106,6 @@ static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock) { TRACE("(%d)\n", dolock); - - if (dolock) - DMCOMPOS_LockModule(); - else - DMCOMPOS_UnlockModule(); - return S_OK; }
@@ -135,15 +123,6 @@ static IClassFactoryImpl ChordMapTrack_CF = {{&classfactory_vtbl}, create_dmchor static IClassFactoryImpl Template_CF = {{&classfactory_vtbl}, create_direct_music_template}; static IClassFactoryImpl SignPostTrack_CF = {{&classfactory_vtbl}, create_dmsignposttrack};
-/****************************************************************** - * DllCanUnloadNow (DMCOMPOS.@) - * - * - */ -HRESULT WINAPI DllCanUnloadNow(void) { - return DMCOMPOS_refCount != 0 ? S_FALSE : S_OK; -} -
/****************************************************************** * DllGetClassObject (DMCOMPOS.@) diff --git a/dlls/dmcompos/dmcompos_private.h b/dlls/dmcompos/dmcompos_private.h index c04d7da6060..928b5a5a993 100644 --- a/dlls/dmcompos/dmcompos_private.h +++ b/dlls/dmcompos/dmcompos_private.h @@ -49,11 +49,4 @@ extern HRESULT create_dmcomposer(REFIID riid, void **ret_iface); extern HRESULT create_dmchordmaptrack(REFIID riid, void **ret_iface); extern HRESULT create_dmsignposttrack(REFIID riid, void **ret_iface);
-/********************************************************************** - * Dll lifetime tracking declaration for dmcompos.dll - */ -extern LONG DMCOMPOS_refCount; -static inline void DMCOMPOS_LockModule(void) { InterlockedIncrement( &DMCOMPOS_refCount ); } -static inline void DMCOMPOS_UnlockModule(void) { InterlockedDecrement( &DMCOMPOS_refCount ); } - #endif /* __WINE_DMCOMPOS_PRIVATE_H */ diff --git a/dlls/dmcompos/signposttrack.c b/dlls/dmcompos/signposttrack.c index 249f37b7711..23ed67acebe 100644 --- a/dlls/dmcompos/signposttrack.c +++ b/dlls/dmcompos/signposttrack.c @@ -79,7 +79,6 @@ static ULONG WINAPI signpost_track_Release(IDirectMusicTrack8 *iface)
if (!ref) { HeapFree(GetProcessHeap(), 0, This); - DMCOMPOS_UnlockModule(); }
return ref; @@ -289,7 +288,6 @@ HRESULT create_dmsignposttrack(REFIID lpcGUID, void **ppobj) (IUnknown *)&track->IDirectMusicTrack8_iface); track->dmobj.IPersistStream_iface.lpVtbl = &persiststream_vtbl;
- DMCOMPOS_LockModule(); hr = IDirectMusicTrack8_QueryInterface(&track->IDirectMusicTrack8_iface, lpcGUID, ppobj); IDirectMusicTrack8_Release(&track->IDirectMusicTrack8_iface);
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dmcompos/chordmap.c | 33 ++++++++++++++------------------- dlls/dmcompos/chordmaptrack.c | 11 +++-------- dlls/dmcompos/composer.c | 11 +++-------- dlls/dmcompos/dmobject.c | 7 +++---- dlls/dmcompos/signposttrack.c | 11 +++-------- 5 files changed, 26 insertions(+), 47 deletions(-)
diff --git a/dlls/dmcompos/chordmap.c b/dlls/dmcompos/chordmap.c index 86134451846..2ddddd3fd57 100644 --- a/dlls/dmcompos/chordmap.c +++ b/dlls/dmcompos/chordmap.c @@ -79,9 +79,7 @@ static ULONG WINAPI IDirectMusicChordMapImpl_Release(IDirectMusicChordMap *iface
TRACE("(%p) ref=%ld\n", This, ref);
- if (!ref) { - HeapFree(GetProcessHeap(), 0, This); - } + if (!ref) free(This);
return ref; } @@ -310,23 +308,20 @@ static const IPersistStreamVtbl persiststream_vtbl = { /* for ClassFactory */ HRESULT create_dmchordmap(REFIID lpcGUID, void **ppobj) { - IDirectMusicChordMapImpl* obj; - HRESULT hr; + IDirectMusicChordMapImpl* obj; + HRESULT hr;
- obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicChordMapImpl)); - if (NULL == obj) { - *ppobj = NULL; - return E_OUTOFMEMORY; - } - obj->IDirectMusicChordMap_iface.lpVtbl = &dmchordmap_vtbl; - obj->ref = 1; - dmobject_init(&obj->dmobj, &CLSID_DirectMusicChordMap, - (IUnknown *)&obj->IDirectMusicChordMap_iface); - obj->dmobj.IDirectMusicObject_iface.lpVtbl = &dmobject_vtbl; - obj->dmobj.IPersistStream_iface.lpVtbl = &persiststream_vtbl; + *ppobj = NULL; + if (!(obj = calloc(1, sizeof(*obj)))) return E_OUTOFMEMORY; + obj->IDirectMusicChordMap_iface.lpVtbl = &dmchordmap_vtbl; + obj->ref = 1; + dmobject_init(&obj->dmobj, &CLSID_DirectMusicChordMap, + (IUnknown *)&obj->IDirectMusicChordMap_iface); + obj->dmobj.IDirectMusicObject_iface.lpVtbl = &dmobject_vtbl; + obj->dmobj.IPersistStream_iface.lpVtbl = &persiststream_vtbl;
- hr = IDirectMusicChordMap_QueryInterface(&obj->IDirectMusicChordMap_iface, lpcGUID, ppobj); - IDirectMusicChordMap_Release(&obj->IDirectMusicChordMap_iface); + hr = IDirectMusicChordMap_QueryInterface(&obj->IDirectMusicChordMap_iface, lpcGUID, ppobj); + IDirectMusicChordMap_Release(&obj->IDirectMusicChordMap_iface);
- return hr; + return hr; } diff --git a/dlls/dmcompos/chordmaptrack.c b/dlls/dmcompos/chordmaptrack.c index 35c64aab4a6..36079ef177a 100644 --- a/dlls/dmcompos/chordmaptrack.c +++ b/dlls/dmcompos/chordmaptrack.c @@ -77,9 +77,7 @@ static ULONG WINAPI chordmap_track_Release(IDirectMusicTrack8 *iface)
TRACE("(%p) ref=%ld\n", This, ref);
- if (!ref) { - HeapFree(GetProcessHeap(), 0, This); - } + if (!ref) free(This);
return ref; } @@ -289,11 +287,8 @@ HRESULT create_dmchordmaptrack(REFIID lpcGUID, void **ppobj) IDirectMusicChordMapTrack* track; HRESULT hr;
- track = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*track)); - if (!track) { - *ppobj = NULL; - return E_OUTOFMEMORY; - } + *ppobj = NULL; + if (!(track = calloc(1, sizeof(*track)))) return E_OUTOFMEMORY; track->IDirectMusicTrack8_iface.lpVtbl = &dmtrack8_vtbl; track->ref = 1; dmobject_init(&track->dmobj, &CLSID_DirectMusicChordMapTrack, diff --git a/dlls/dmcompos/composer.c b/dlls/dmcompos/composer.c index 47e12358201..3451f2d4203 100644 --- a/dlls/dmcompos/composer.c +++ b/dlls/dmcompos/composer.c @@ -67,9 +67,7 @@ static ULONG WINAPI IDirectMusicComposerImpl_Release(IDirectMusicComposer *iface
TRACE("(%p) ref=%ld\n", This, ref);
- if (ref == 0) { - HeapFree(GetProcessHeap(), 0, This); - } + if (!ref) free(This);
return ref; } @@ -174,11 +172,8 @@ HRESULT create_dmcomposer(REFIID riid, void **ret_iface) IDirectMusicComposerImpl *obj; HRESULT hr;
- obj = HeapAlloc(GetProcessHeap(), 0, sizeof(*obj)); - if (!obj) { - *ret_iface = NULL; - return E_OUTOFMEMORY; - } + *ret_iface = NULL; + if (!(obj = calloc(1, sizeof(*obj)))) return E_OUTOFMEMORY; obj->IDirectMusicComposer_iface.lpVtbl = &dmcomposer_vtbl; obj->ref = 1;
diff --git a/dlls/dmcompos/dmobject.c b/dlls/dmcompos/dmobject.c index b526b23d031..07d887a376c 100644 --- a/dlls/dmcompos/dmobject.c +++ b/dlls/dmcompos/dmobject.c @@ -28,7 +28,6 @@ #include "dmusics.h" #include "dmobject.h" #include "wine/debug.h" -#include "wine/heap.h"
WINE_DEFAULT_DEBUG_CHANNEL(dmobj); WINE_DECLARE_DEBUG_CHANNEL(dmfile); @@ -375,7 +374,7 @@ HRESULT stream_next_chunk(IStream *stream, struct chunk_entry *chunk) /* Reads chunk data of the form: DWORD - size of array element element[] - Array of elements - The caller needs to heap_free() the array. + The caller needs to free() the array. */ HRESULT stream_chunk_get_array(IStream *stream, const struct chunk_entry *chunk, void **array, unsigned int *count, DWORD elem_size) @@ -400,10 +399,10 @@ HRESULT stream_chunk_get_array(IStream *stream, const struct chunk_entry *chunk,
*count = (chunk->size - sizeof(DWORD)) / elem_size; size = *count * elem_size; - if (!(*array = heap_alloc(size))) + if (!(*array = malloc(size))) return E_OUTOFMEMORY; if (FAILED(hr = stream_read(stream, *array, size))) { - heap_free(*array); + free(*array); *array = NULL; return hr; } diff --git a/dlls/dmcompos/signposttrack.c b/dlls/dmcompos/signposttrack.c index 23ed67acebe..eccf87a4893 100644 --- a/dlls/dmcompos/signposttrack.c +++ b/dlls/dmcompos/signposttrack.c @@ -77,9 +77,7 @@ static ULONG WINAPI signpost_track_Release(IDirectMusicTrack8 *iface)
TRACE("(%p) ref=%ld\n", This, ref);
- if (!ref) { - HeapFree(GetProcessHeap(), 0, This); - } + if (!ref) free(This);
return ref; } @@ -277,11 +275,8 @@ HRESULT create_dmsignposttrack(REFIID lpcGUID, void **ppobj) IDirectMusicSignPostTrack *track; HRESULT hr;
- track = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*track)); - if (!track) { - *ppobj = NULL; - return E_OUTOFMEMORY; - } + *ppobj = NULL; + if (!(track = calloc(1, sizeof(*track)))) return E_OUTOFMEMORY; track->IDirectMusicTrack8_iface.lpVtbl = &dmtrack8_vtbl; track->ref = 1; dmobject_init(&track->dmobj, &CLSID_DirectMusicSignPostTrack,
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dmcompos/Makefile.in | 1 + dlls/dmcompos/dmobject.c | 732 -------------------------------------- dlls/dmcompos/dmobject.h | 124 ------- 3 files changed, 1 insertion(+), 856 deletions(-) delete mode 100644 dlls/dmcompos/dmobject.c delete mode 100644 dlls/dmcompos/dmobject.h
diff --git a/dlls/dmcompos/Makefile.in b/dlls/dmcompos/Makefile.in index d1e9b5e5b45..af5f2134152 100644 --- a/dlls/dmcompos/Makefile.in +++ b/dlls/dmcompos/Makefile.in @@ -1,5 +1,6 @@ MODULE = dmcompos.dll IMPORTS = dxguid uuid ole32 advapi32 +PARENTSRC = ../dmusic
C_SRCS = \ chordmap.c \ diff --git a/dlls/dmcompos/dmobject.c b/dlls/dmcompos/dmobject.c deleted file mode 100644 index 07d887a376c..00000000000 --- a/dlls/dmcompos/dmobject.c +++ /dev/null @@ -1,732 +0,0 @@ -/* - * Base IDirectMusicObject Implementation - * Keep in sync with the master in dlls/dmusic/dmobject.c - * - * Copyright (C) 2003-2004 Rok Mandeljc - * Copyright (C) 2014 Michael Stefaniuc - * - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * 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 - */ - -#define COBJMACROS -#include <assert.h> -#include "objbase.h" -#include "dmusici.h" -#include "dmusicf.h" -#include "dmusics.h" -#include "dmobject.h" -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(dmobj); -WINE_DECLARE_DEBUG_CHANNEL(dmfile); - -/* Debugging helpers */ -const char *debugstr_dmguid(const GUID *id) { - unsigned int i; -#define X(guid) { &guid, #guid } - static const struct { - const GUID *guid; - const char *name; - } guids[] = { - /* CLSIDs */ - X(CLSID_AudioVBScript), - X(CLSID_DirectMusic), - X(CLSID_DirectMusicAudioPathConfig), - X(CLSID_DirectMusicAuditionTrack), - X(CLSID_DirectMusicBand), - X(CLSID_DirectMusicBandTrack), - X(CLSID_DirectMusicChordMapTrack), - X(CLSID_DirectMusicChordMap), - X(CLSID_DirectMusicChordTrack), - X(CLSID_DirectMusicCollection), - X(CLSID_DirectMusicCommandTrack), - X(CLSID_DirectMusicComposer), - X(CLSID_DirectMusicContainer), - X(CLSID_DirectMusicGraph), - X(CLSID_DirectMusicLoader), - X(CLSID_DirectMusicLyricsTrack), - X(CLSID_DirectMusicMarkerTrack), - X(CLSID_DirectMusicMelodyFormulationTrack), - X(CLSID_DirectMusicMotifTrack), - X(CLSID_DirectMusicMuteTrack), - X(CLSID_DirectMusicParamControlTrack), - X(CLSID_DirectMusicPatternTrack), - X(CLSID_DirectMusicPerformance), - X(CLSID_DirectMusicScript), - X(CLSID_DirectMusicScriptAutoImpSegment), - X(CLSID_DirectMusicScriptAutoImpPerformance), - X(CLSID_DirectMusicScriptAutoImpSegmentState), - X(CLSID_DirectMusicScriptAutoImpAudioPathConfig), - X(CLSID_DirectMusicScriptAutoImpAudioPath), - X(CLSID_DirectMusicScriptAutoImpSong), - X(CLSID_DirectMusicScriptSourceCodeLoader), - X(CLSID_DirectMusicScriptTrack), - X(CLSID_DirectMusicSection), - X(CLSID_DirectMusicSegment), - X(CLSID_DirectMusicSegmentState), - X(CLSID_DirectMusicSegmentTriggerTrack), - X(CLSID_DirectMusicSegTriggerTrack), - X(CLSID_DirectMusicSeqTrack), - X(CLSID_DirectMusicSignPostTrack), - X(CLSID_DirectMusicSong), - X(CLSID_DirectMusicStyle), - X(CLSID_DirectMusicStyleTrack), - X(CLSID_DirectMusicSynth), - X(CLSID_DirectMusicSynthSink), - X(CLSID_DirectMusicSysExTrack), - X(CLSID_DirectMusicTemplate), - X(CLSID_DirectMusicTempoTrack), - X(CLSID_DirectMusicTimeSigTrack), - X(CLSID_DirectMusicWaveTrack), - X(CLSID_DirectSoundWave), - /* IIDs */ - X(IID_IDirectMusic), - X(IID_IDirectMusic2), - X(IID_IDirectMusic8), - X(IID_IDirectMusicAudioPath), - X(IID_IDirectMusicBand), - X(IID_IDirectMusicBuffer), - X(IID_IDirectMusicChordMap), - X(IID_IDirectMusicCollection), - X(IID_IDirectMusicComposer), - X(IID_IDirectMusicContainer), - X(IID_IDirectMusicDownload), - X(IID_IDirectMusicDownloadedInstrument), - X(IID_IDirectMusicGetLoader), - X(IID_IDirectMusicGraph), - X(IID_IDirectMusicInstrument), - X(IID_IDirectMusicLoader), - X(IID_IDirectMusicLoader8), - X(IID_IDirectMusicObject), - X(IID_IDirectMusicPatternTrack), - X(IID_IDirectMusicPerformance), - X(IID_IDirectMusicPerformance2), - X(IID_IDirectMusicPerformance8), - X(IID_IDirectMusicPort), - X(IID_IDirectMusicPortDownload), - X(IID_IDirectMusicScript), - X(IID_IDirectMusicSegment), - X(IID_IDirectMusicSegment2), - X(IID_IDirectMusicSegment8), - X(IID_IDirectMusicSegmentState), - X(IID_IDirectMusicSegmentState8), - X(IID_IDirectMusicStyle), - X(IID_IDirectMusicStyle8), - X(IID_IDirectMusicSynth), - X(IID_IDirectMusicSynth8), - X(IID_IDirectMusicSynthSink), - X(IID_IDirectMusicThru), - X(IID_IDirectMusicTool), - X(IID_IDirectMusicTool8), - X(IID_IDirectMusicTrack), - X(IID_IDirectMusicTrack8), - X(IID_IUnknown), - X(IID_IPersistStream), - X(IID_IStream), - X(IID_IClassFactory), - /* GUIDs */ - X(GUID_DirectMusicAllTypes), - X(GUID_NOTIFICATION_CHORD), - X(GUID_NOTIFICATION_COMMAND), - X(GUID_NOTIFICATION_MEASUREANDBEAT), - X(GUID_NOTIFICATION_PERFORMANCE), - X(GUID_NOTIFICATION_RECOMPOSE), - X(GUID_NOTIFICATION_SEGMENT), - X(GUID_BandParam), - X(GUID_ChordParam), - X(GUID_CommandParam), - X(GUID_CommandParam2), - X(GUID_CommandParamNext), - X(GUID_IDirectMusicBand), - X(GUID_IDirectMusicChordMap), - X(GUID_IDirectMusicStyle), - X(GUID_MuteParam), - X(GUID_Play_Marker), - X(GUID_RhythmParam), - X(GUID_TempoParam), - X(GUID_TimeSignature), - X(GUID_Valid_Start_Time), - X(GUID_Clear_All_Bands), - X(GUID_ConnectToDLSCollection), - X(GUID_Disable_Auto_Download), - X(GUID_DisableTempo), - X(GUID_DisableTimeSig), - X(GUID_Download), - X(GUID_DownloadToAudioPath), - X(GUID_Enable_Auto_Download), - X(GUID_EnableTempo), - X(GUID_EnableTimeSig), - X(GUID_IgnoreBankSelectForGM), - X(GUID_SeedVariations), - X(GUID_StandardMIDIFile), - X(GUID_Unload), - X(GUID_UnloadFromAudioPath), - X(GUID_Variations), - X(GUID_PerfMasterTempo), - X(GUID_PerfMasterVolume), - X(GUID_PerfMasterGrooveLevel), - X(GUID_PerfAutoDownload), - X(GUID_DefaultGMCollection), - X(GUID_Synth_Default), - X(GUID_Buffer_Reverb), - X(GUID_Buffer_EnvReverb), - X(GUID_Buffer_Stereo), - X(GUID_Buffer_3D_Dry), - X(GUID_Buffer_Mono), - X(GUID_DMUS_PROP_GM_Hardware), - X(GUID_DMUS_PROP_GS_Capable), - X(GUID_DMUS_PROP_GS_Hardware), - X(GUID_DMUS_PROP_DLS1), - X(GUID_DMUS_PROP_DLS2), - X(GUID_DMUS_PROP_Effects), - X(GUID_DMUS_PROP_INSTRUMENT2), - X(GUID_DMUS_PROP_LegacyCaps), - X(GUID_DMUS_PROP_MemorySize), - X(GUID_DMUS_PROP_SampleMemorySize), - X(GUID_DMUS_PROP_SamplePlaybackRate), - X(GUID_DMUS_PROP_SetSynthSink), - X(GUID_DMUS_PROP_SinkUsesDSound), - X(GUID_DMUS_PROP_SynthSink_DSOUND), - X(GUID_DMUS_PROP_SynthSink_WAVE), - X(GUID_DMUS_PROP_Volume), - X(GUID_DMUS_PROP_WavesReverb), - X(GUID_DMUS_PROP_WriteLatency), - X(GUID_DMUS_PROP_WritePeriod), - X(GUID_DMUS_PROP_XG_Capable), - X(GUID_DMUS_PROP_XG_Hardware) - }; -#undef X - - if (!id) - return "(null)"; - - for (i = 0; i < ARRAY_SIZE(guids); i++) - if (IsEqualGUID(id, guids[i].guid)) - return guids[i].name; - - return debugstr_guid(id); -} - -void dump_DMUS_OBJECTDESC(DMUS_OBJECTDESC *desc) -{ - if (!desc || !TRACE_ON(dmfile)) - return; - - TRACE_(dmfile)("DMUS_OBJECTDESC (%p):", desc); - TRACE_(dmfile)(" - dwSize = %lu\n", desc->dwSize); - -#define X(flag) if (desc->dwValidData & flag) TRACE_(dmfile)(#flag " ") - TRACE_(dmfile)(" - dwValidData = %#08lx ( ", desc->dwValidData); - X(DMUS_OBJ_OBJECT); - X(DMUS_OBJ_CLASS); - X(DMUS_OBJ_NAME); - X(DMUS_OBJ_CATEGORY); - X(DMUS_OBJ_FILENAME); - X(DMUS_OBJ_FULLPATH); - X(DMUS_OBJ_URL); - X(DMUS_OBJ_VERSION); - X(DMUS_OBJ_DATE); - X(DMUS_OBJ_LOADED); - X(DMUS_OBJ_MEMORY); - X(DMUS_OBJ_STREAM); - TRACE_(dmfile)(")\n"); -#undef X - - if (desc->dwValidData & DMUS_OBJ_CLASS) - TRACE_(dmfile)(" - guidClass = %s\n", debugstr_dmguid(&desc->guidClass)); - if (desc->dwValidData & DMUS_OBJ_OBJECT) - TRACE_(dmfile)(" - guidObject = %s\n", debugstr_guid(&desc->guidObject)); - - if (desc->dwValidData & DMUS_OBJ_DATE) { - SYSTEMTIME time; - FileTimeToSystemTime(&desc->ftDate, &time); - TRACE_(dmfile)(" - ftDate = '%04u-%02u-%02u %02u:%02u:%02u'\n", - time.wYear, time.wMonth, time.wDay, time.wHour, time.wMinute, time.wSecond); - } - if (desc->dwValidData & DMUS_OBJ_VERSION) - TRACE_(dmfile)(" - vVersion = '%u,%u,%u,%u'\n", - HIWORD(desc->vVersion.dwVersionMS), LOWORD(desc->vVersion.dwVersionMS), - HIWORD(desc->vVersion.dwVersionLS), LOWORD(desc->vVersion.dwVersionLS)); - if (desc->dwValidData & DMUS_OBJ_NAME) - TRACE_(dmfile)(" - wszName = %s\n", debugstr_w(desc->wszName)); - if (desc->dwValidData & DMUS_OBJ_CATEGORY) - TRACE_(dmfile)(" - wszCategory = %s\n", debugstr_w(desc->wszCategory)); - if (desc->dwValidData & DMUS_OBJ_FILENAME) - TRACE_(dmfile)(" - wszFileName = %s\n", debugstr_w(desc->wszFileName)); - if (desc->dwValidData & DMUS_OBJ_MEMORY) - TRACE_(dmfile)(" - llMemLength = 0x%s - pbMemData = %p\n", - wine_dbgstr_longlong(desc->llMemLength), desc->pbMemData); - if (desc->dwValidData & DMUS_OBJ_STREAM) - TRACE_(dmfile)(" - pStream = %p\n", desc->pStream); -} - - -/* RIFF format parsing */ -#define CHUNK_HDR_SIZE (sizeof(FOURCC) + sizeof(DWORD)) - -const char *debugstr_chunk(const struct chunk_entry *chunk) -{ - const char *type = ""; - - if (!chunk) - return "(null)"; - if (chunk->id == FOURCC_RIFF || chunk->id == FOURCC_LIST) - type = wine_dbg_sprintf("type %s, ", debugstr_fourcc(chunk->type)); - return wine_dbg_sprintf("%s chunk, %ssize %lu", debugstr_fourcc(chunk->id), type, chunk->size); -} - -static HRESULT stream_read(IStream *stream, void *data, ULONG size) -{ - ULONG read; - HRESULT hr; - - hr = IStream_Read(stream, data, size, &read); - if (FAILED(hr)) - TRACE_(dmfile)("IStream_Read failed: %#lx\n", hr); - else if (!read && read < size) { - /* All or nothing: Handle a partial read due to end of stream as an error */ - TRACE_(dmfile)("Short read: %lu < %lu\n", read, size); - return E_FAIL; - } - - return hr; -} - -HRESULT stream_get_chunk(IStream *stream, struct chunk_entry *chunk) -{ - static const LARGE_INTEGER zero; - ULONGLONG ck_end = 0, p_end = 0; - HRESULT hr; - - hr = IStream_Seek(stream, zero, STREAM_SEEK_CUR, &chunk->offset); - if (FAILED(hr)) - return hr; - assert(!(chunk->offset.QuadPart & 1)); - if (chunk->parent) { - p_end = chunk->parent->offset.QuadPart + CHUNK_HDR_SIZE + ((chunk->parent->size + 1) & ~1); - if (chunk->offset.QuadPart == p_end) - return S_FALSE; - ck_end = chunk->offset.QuadPart + CHUNK_HDR_SIZE; - if (ck_end > p_end) { - WARN_(dmfile)("No space for sub-chunk header in parent chunk: ends at offset %s > %s\n", - wine_dbgstr_longlong(ck_end), wine_dbgstr_longlong(p_end)); - return E_FAIL; - } - } - - hr = stream_read(stream, chunk, CHUNK_HDR_SIZE); - if (hr != S_OK) - return hr; - if (chunk->parent) { - ck_end += (chunk->size + 1) & ~1; - if (ck_end > p_end) { - WARN_(dmfile)("No space for sub-chunk data in parent chunk: ends at offset %s > %s\n", - wine_dbgstr_longlong(ck_end), wine_dbgstr_longlong(p_end)); - return E_FAIL; - } - } - - if (chunk->id == FOURCC_LIST || chunk->id == FOURCC_RIFF) { - hr = stream_read(stream, &chunk->type, sizeof(FOURCC)); - if (hr != S_OK) - return hr != S_FALSE ? hr : E_FAIL; - } - - TRACE_(dmfile)("Returning %s\n", debugstr_chunk(chunk)); - - return S_OK; -} - -HRESULT stream_skip_chunk(IStream *stream, const struct chunk_entry *chunk) -{ - LARGE_INTEGER end; - - end.QuadPart = (chunk->offset.QuadPart + CHUNK_HDR_SIZE + chunk->size + 1) & ~(ULONGLONG)1; - - return IStream_Seek(stream, end, STREAM_SEEK_SET, NULL); -} - -HRESULT stream_next_chunk(IStream *stream, struct chunk_entry *chunk) -{ - HRESULT hr; - - if (chunk->id) { - hr = stream_skip_chunk(stream, chunk); - if (FAILED(hr)) - return hr; - } - - return stream_get_chunk(stream, chunk); -} - -/* Reads chunk data of the form: - DWORD - size of array element - element[] - Array of elements - The caller needs to free() the array. -*/ -HRESULT stream_chunk_get_array(IStream *stream, const struct chunk_entry *chunk, void **array, - unsigned int *count, DWORD elem_size) -{ - DWORD size; - HRESULT hr; - - *array = NULL; - *count = 0; - - if (chunk->size < sizeof(DWORD)) { - WARN_(dmfile)("%s: Too short to read element size\n", debugstr_chunk(chunk)); - return E_FAIL; - } - if (FAILED(hr = stream_read(stream, &size, sizeof(DWORD)))) - return hr; - if (size != elem_size) { - WARN_(dmfile)("%s: Array element size mismatch: got %lu, expected %lu\n", - debugstr_chunk(chunk), size, elem_size); - return DMUS_E_UNSUPPORTED_STREAM; - } - - *count = (chunk->size - sizeof(DWORD)) / elem_size; - size = *count * elem_size; - if (!(*array = malloc(size))) - return E_OUTOFMEMORY; - if (FAILED(hr = stream_read(stream, *array, size))) { - free(*array); - *array = NULL; - return hr; - } - - if (chunk->size > size + sizeof(DWORD)) { - WARN_(dmfile)("%s: Extraneous data at end of array\n", debugstr_chunk(chunk)); - stream_skip_chunk(stream, chunk); - return S_FALSE; - } - return S_OK; -} - -HRESULT stream_chunk_get_data(IStream *stream, const struct chunk_entry *chunk, void *data, - ULONG size) -{ - if (chunk->size != size) { - WARN_(dmfile)("Chunk %s (size %lu, offset %s) doesn't contains the expected data size %lu\n", - debugstr_fourcc(chunk->id), chunk->size, - wine_dbgstr_longlong(chunk->offset.QuadPart), size); - return E_FAIL; - } - return stream_read(stream, data, size); -} - -HRESULT stream_chunk_get_wstr(IStream *stream, const struct chunk_entry *chunk, WCHAR *str, - ULONG size) -{ - ULONG len; - HRESULT hr; - - hr = IStream_Read(stream, str, min(chunk->size, size), &len); - if (FAILED(hr)) - return hr; - - /* Don't assume the string is properly zero terminated */ - str[min(len, size - 1)] = 0; - - if (len < chunk->size) - return S_FALSE; - return S_OK; -} - - - -/* Generic IDirectMusicObject methods */ -static inline struct dmobject *impl_from_IDirectMusicObject(IDirectMusicObject *iface) -{ - return CONTAINING_RECORD(iface, struct dmobject, IDirectMusicObject_iface); -} - -HRESULT WINAPI dmobj_IDirectMusicObject_QueryInterface(IDirectMusicObject *iface, REFIID riid, - void **ret_iface) -{ - struct dmobject *This = impl_from_IDirectMusicObject(iface); - return IUnknown_QueryInterface(This->outer_unk, riid, ret_iface); -} - -ULONG WINAPI dmobj_IDirectMusicObject_AddRef(IDirectMusicObject *iface) -{ - struct dmobject *This = impl_from_IDirectMusicObject(iface); - return IUnknown_AddRef(This->outer_unk); -} - -ULONG WINAPI dmobj_IDirectMusicObject_Release(IDirectMusicObject *iface) -{ - struct dmobject *This = impl_from_IDirectMusicObject(iface); - return IUnknown_Release(This->outer_unk); -} - -HRESULT WINAPI dmobj_IDirectMusicObject_GetDescriptor(IDirectMusicObject *iface, - DMUS_OBJECTDESC *desc) -{ - struct dmobject *This = impl_from_IDirectMusicObject(iface); - - TRACE("(%p/%p)->(%p)\n", iface, This, desc); - - if (!desc) - return E_POINTER; - - memcpy(desc, &This->desc, This->desc.dwSize); - - return S_OK; -} - -HRESULT WINAPI dmobj_IDirectMusicObject_SetDescriptor(IDirectMusicObject *iface, - DMUS_OBJECTDESC *desc) -{ - struct dmobject *This = impl_from_IDirectMusicObject(iface); - HRESULT ret = S_OK; - - TRACE("(%p, %p)\n", iface, desc); - - if (!desc) - return E_POINTER; - - /* Immutable property */ - if (desc->dwValidData & DMUS_OBJ_CLASS) - { - desc->dwValidData &= ~DMUS_OBJ_CLASS; - ret = S_FALSE; - } - /* Set only valid fields */ - if (desc->dwValidData & DMUS_OBJ_OBJECT) - This->desc.guidObject = desc->guidObject; - if (desc->dwValidData & DMUS_OBJ_NAME) - lstrcpynW(This->desc.wszName, desc->wszName, DMUS_MAX_NAME); - if (desc->dwValidData & DMUS_OBJ_CATEGORY) - lstrcpynW(This->desc.wszCategory, desc->wszCategory, DMUS_MAX_CATEGORY); - if (desc->dwValidData & DMUS_OBJ_FILENAME) - lstrcpynW(This->desc.wszFileName, desc->wszFileName, DMUS_MAX_FILENAME); - if (desc->dwValidData & DMUS_OBJ_VERSION) - This->desc.vVersion = desc->vVersion; - if (desc->dwValidData & DMUS_OBJ_DATE) - This->desc.ftDate = desc->ftDate; - if (desc->dwValidData & DMUS_OBJ_MEMORY) { - This->desc.llMemLength = desc->llMemLength; - memcpy(This->desc.pbMemData, desc->pbMemData, desc->llMemLength); - } - if (desc->dwValidData & DMUS_OBJ_STREAM) - IStream_Clone(desc->pStream, &This->desc.pStream); - - This->desc.dwValidData |= desc->dwValidData; - - return ret; -} - -/* Helper for IDirectMusicObject::ParseDescriptor */ -static inline void info_get_name(IStream *stream, const struct chunk_entry *info, - DMUS_OBJECTDESC *desc) -{ - struct chunk_entry chunk = {.parent = info}; - char name[DMUS_MAX_NAME]; - ULONG len; - HRESULT hr = E_FAIL; - - while (stream_next_chunk(stream, &chunk) == S_OK) - if (chunk.id == mmioFOURCC('I','N','A','M')) - hr = IStream_Read(stream, name, min(chunk.size, sizeof(name)), &len); - - if (SUCCEEDED(hr)) { - len = MultiByteToWideChar(CP_ACP, 0, name, len, desc->wszName, sizeof(desc->wszName)); - desc->wszName[min(len, sizeof(desc->wszName) - 1)] = 0; - desc->dwValidData |= DMUS_OBJ_NAME; - } -} - -static inline void unfo_get_name(IStream *stream, const struct chunk_entry *unfo, - DMUS_OBJECTDESC *desc, BOOL inam) -{ - struct chunk_entry chunk = {.parent = unfo}; - - while (stream_next_chunk(stream, &chunk) == S_OK) - if (chunk.id == DMUS_FOURCC_UNAM_CHUNK || (inam && chunk.id == mmioFOURCC('I','N','A','M'))) - if (stream_chunk_get_wstr(stream, &chunk, desc->wszName, sizeof(desc->wszName)) == S_OK) - desc->dwValidData |= DMUS_OBJ_NAME; -} - -HRESULT dmobj_parsedescriptor(IStream *stream, const struct chunk_entry *riff, - DMUS_OBJECTDESC *desc, DWORD supported) -{ - struct chunk_entry chunk = {.parent = riff}; - HRESULT hr; - - TRACE("Looking for %#lx in %p: %s\n", supported, stream, debugstr_chunk(riff)); - - desc->dwValidData = 0; - desc->dwSize = sizeof(*desc); - - while ((hr = stream_next_chunk(stream, &chunk)) == S_OK) { - switch (chunk.id) { - case DMUS_FOURCC_CATEGORY_CHUNK: - if ((supported & DMUS_OBJ_CATEGORY) && stream_chunk_get_wstr(stream, &chunk, - desc->wszCategory, sizeof(desc->wszCategory)) == S_OK) - desc->dwValidData |= DMUS_OBJ_CATEGORY; - break; - case DMUS_FOURCC_DATE_CHUNK: - if ((supported & DMUS_OBJ_DATE) && stream_chunk_get_data(stream, &chunk, - &desc->ftDate, sizeof(desc->ftDate)) == S_OK) - desc->dwValidData |= DMUS_OBJ_DATE; - break; - case DMUS_FOURCC_FILE_CHUNK: - if ((supported & DMUS_OBJ_FILENAME) && stream_chunk_get_wstr(stream, &chunk, - desc->wszFileName, sizeof(desc->wszFileName)) == S_OK) - desc->dwValidData |= DMUS_OBJ_FILENAME; - break; - case DMUS_FOURCC_GUID_CHUNK: - if ((supported & DMUS_OBJ_OBJECT) && stream_chunk_get_data(stream, &chunk, - &desc->guidObject, sizeof(desc->guidObject)) == S_OK) - desc->dwValidData |= DMUS_OBJ_OBJECT; - break; - case DMUS_FOURCC_NAME_CHUNK: - if ((supported & DMUS_OBJ_NAME) && stream_chunk_get_wstr(stream, &chunk, - desc->wszName, sizeof(desc->wszName)) == S_OK) - desc->dwValidData |= DMUS_OBJ_NAME; - break; - case DMUS_FOURCC_VERSION_CHUNK: - if ((supported & DMUS_OBJ_VERSION) && stream_chunk_get_data(stream, &chunk, - &desc->vVersion, sizeof(desc->vVersion)) == S_OK) - desc->dwValidData |= DMUS_OBJ_VERSION; - break; - case FOURCC_LIST: - if (chunk.type == DMUS_FOURCC_UNFO_LIST && (supported & DMUS_OBJ_NAME)) - unfo_get_name(stream, &chunk, desc, supported & DMUS_OBJ_NAME_INAM); - else if (chunk.type == DMUS_FOURCC_INFO_LIST && (supported & DMUS_OBJ_NAME_INFO)) - info_get_name(stream, &chunk, desc); - break; - } - } - TRACE("Found %#lx\n", desc->dwValidData); - - return hr; -} - -HRESULT dmobj_parsereference(IStream *stream, const struct chunk_entry *list, - IDirectMusicObject **dmobj) -{ - struct chunk_entry chunk = {.parent = list}; - IDirectMusicGetLoader *getloader; - IDirectMusicLoader *loader; - DMUS_OBJECTDESC desc; - DMUS_IO_REFERENCE reference; - HRESULT hr; - - if (FAILED(hr = stream_next_chunk(stream, &chunk))) - return hr; - if (chunk.id != DMUS_FOURCC_REF_CHUNK) - return DMUS_E_UNSUPPORTED_STREAM; - - if (FAILED(hr = stream_chunk_get_data(stream, &chunk, &reference, sizeof(reference)))) { - WARN("Failed to read data of %s\n", debugstr_chunk(&chunk)); - return hr; - } - TRACE("REFERENCE guidClassID %s, dwValidData %#lx\n", debugstr_dmguid(&reference.guidClassID), - reference.dwValidData); - - if (FAILED(hr = dmobj_parsedescriptor(stream, list, &desc, reference.dwValidData))) - return hr; - desc.guidClass = reference.guidClassID; - desc.dwValidData |= DMUS_OBJ_CLASS; - dump_DMUS_OBJECTDESC(&desc); - - if (FAILED(hr = IStream_QueryInterface(stream, &IID_IDirectMusicGetLoader, (void**)&getloader))) - return hr; - hr = IDirectMusicGetLoader_GetLoader(getloader, &loader); - IDirectMusicGetLoader_Release(getloader); - if (FAILED(hr)) - return hr; - - hr = IDirectMusicLoader_GetObject(loader, &desc, &IID_IDirectMusicObject, (void**)dmobj); - IDirectMusicLoader_Release(loader); - - return hr; -} - -/* Generic IPersistStream methods */ -static inline struct dmobject *impl_from_IPersistStream(IPersistStream *iface) -{ - return CONTAINING_RECORD(iface, struct dmobject, IPersistStream_iface); -} - -HRESULT WINAPI dmobj_IPersistStream_QueryInterface(IPersistStream *iface, REFIID riid, - void **ret_iface) -{ - struct dmobject *This = impl_from_IPersistStream(iface); - return IUnknown_QueryInterface(This->outer_unk, riid, ret_iface); -} - -ULONG WINAPI dmobj_IPersistStream_AddRef(IPersistStream *iface) -{ - struct dmobject *This = impl_from_IPersistStream(iface); - return IUnknown_AddRef(This->outer_unk); -} - -ULONG WINAPI dmobj_IPersistStream_Release(IPersistStream *iface) -{ - struct dmobject *This = impl_from_IPersistStream(iface); - return IUnknown_Release(This->outer_unk); -} - -HRESULT WINAPI dmobj_IPersistStream_GetClassID(IPersistStream *iface, CLSID *class) -{ - struct dmobject *This = impl_from_IPersistStream(iface); - - TRACE("(%p, %p)\n", This, class); - - if (!class) - return E_POINTER; - - *class = This->desc.guidClass; - - return S_OK; -} - -/* IPersistStream methods not implemented in native */ -HRESULT WINAPI unimpl_IPersistStream_GetClassID(IPersistStream *iface, CLSID *class) -{ - TRACE("(%p, %p): method not implemented\n", iface, class); - return E_NOTIMPL; -} - -HRESULT WINAPI unimpl_IPersistStream_IsDirty(IPersistStream *iface) -{ - TRACE("(%p): method not implemented, always returning S_FALSE\n", iface); - return S_FALSE; -} - -HRESULT WINAPI unimpl_IPersistStream_Save(IPersistStream *iface, IStream *stream, - BOOL clear_dirty) -{ - TRACE("(%p, %p, %d): method not implemented\n", iface, stream, clear_dirty); - return E_NOTIMPL; -} - -HRESULT WINAPI unimpl_IPersistStream_GetSizeMax(IPersistStream *iface, ULARGE_INTEGER *size) -{ - TRACE("(%p, %p): method not implemented\n", iface, size); - return E_NOTIMPL; -} - - -void dmobject_init(struct dmobject *dmobj, const GUID *class, IUnknown *outer_unk) -{ - dmobj->outer_unk = outer_unk; - dmobj->desc.dwSize = sizeof(dmobj->desc); - dmobj->desc.dwValidData = DMUS_OBJ_CLASS; - dmobj->desc.guidClass = *class; -} diff --git a/dlls/dmcompos/dmobject.h b/dlls/dmcompos/dmobject.h deleted file mode 100644 index 772be015c80..00000000000 --- a/dlls/dmcompos/dmobject.h +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Base IDirectMusicObject Implementation - * Keep in sync with the master in dlls/dmusic/dmobject.h - * - * Copyright (C) 2014 Michael Stefaniuc - * - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * 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 - */ - -#include "wine/debug.h" - -/* RIFF stream parsing */ -struct chunk_entry; -struct chunk_entry { - FOURCC id; - DWORD size; - FOURCC type; /* valid only for LIST and RIFF chunks */ - ULARGE_INTEGER offset; /* chunk offset from start of stream */ - const struct chunk_entry *parent; /* enclosing RIFF or LIST chunk */ -}; - -HRESULT stream_get_chunk(IStream *stream, struct chunk_entry *chunk); -HRESULT stream_next_chunk(IStream *stream, struct chunk_entry *chunk); -HRESULT stream_skip_chunk(IStream *stream, const struct chunk_entry *chunk); - -HRESULT stream_chunk_get_array(IStream *stream, const struct chunk_entry *chunk, void **array, - unsigned int *count, DWORD elem_size); -HRESULT stream_chunk_get_data(IStream *stream, const struct chunk_entry *chunk, void *data, - ULONG size); -HRESULT stream_chunk_get_wstr(IStream *stream, const struct chunk_entry *chunk, WCHAR *str, - ULONG size); - -static inline HRESULT stream_reset_chunk_data(IStream *stream, const struct chunk_entry *chunk) -{ - LARGE_INTEGER offset; - - offset.QuadPart = chunk->offset.QuadPart + sizeof(FOURCC) + sizeof(DWORD); - if (chunk->id == FOURCC_RIFF || chunk->id == FOURCC_LIST) - offset.QuadPart += sizeof(FOURCC); - - return IStream_Seek(stream, offset, STREAM_SEEK_SET, NULL); -} - -static inline HRESULT stream_reset_chunk_start(IStream *stream, const struct chunk_entry *chunk) -{ - LARGE_INTEGER offset; - - offset.QuadPart = chunk->offset.QuadPart; - - return IStream_Seek(stream, offset, STREAM_SEEK_SET, NULL); -} - - -/* IDirectMusicObject base object */ -struct dmobject { - IDirectMusicObject IDirectMusicObject_iface; - IPersistStream IPersistStream_iface; - IUnknown *outer_unk; - DMUS_OBJECTDESC desc; -}; - -void dmobject_init(struct dmobject *dmobj, const GUID *class, IUnknown *outer_unk); - -/* Generic IDirectMusicObject methods */ -HRESULT WINAPI dmobj_IDirectMusicObject_QueryInterface(IDirectMusicObject *iface, REFIID riid, - void **ret_iface); -ULONG WINAPI dmobj_IDirectMusicObject_AddRef(IDirectMusicObject *iface); -ULONG WINAPI dmobj_IDirectMusicObject_Release(IDirectMusicObject *iface); -HRESULT WINAPI dmobj_IDirectMusicObject_GetDescriptor(IDirectMusicObject *iface, - DMUS_OBJECTDESC *desc); -HRESULT WINAPI dmobj_IDirectMusicObject_SetDescriptor(IDirectMusicObject *iface, - DMUS_OBJECTDESC *desc); - -/* Helper for IDirectMusicObject::ParseDescriptor */ -HRESULT dmobj_parsedescriptor(IStream *stream, const struct chunk_entry *riff, - DMUS_OBJECTDESC *desc, DWORD supported); -/* Additional supported flags for dmobj_parsedescriptor. - DMUS_OBJ_NAME is 'UNAM' chunk in UNFO list */ -#define DMUS_OBJ_NAME_INAM 0x1000 /* 'INAM' chunk in UNFO list */ -#define DMUS_OBJ_NAME_INFO 0x2000 /* 'INAM' chunk in INFO list */ - -/* 'DMRF' (reference list) helper */ -HRESULT dmobj_parsereference(IStream *stream, const struct chunk_entry *list, - IDirectMusicObject **dmobj); - -/* Generic IPersistStream methods */ -HRESULT WINAPI dmobj_IPersistStream_QueryInterface(IPersistStream *iface, REFIID riid, - void **ret_iface); -ULONG WINAPI dmobj_IPersistStream_AddRef(IPersistStream *iface); -ULONG WINAPI dmobj_IPersistStream_Release(IPersistStream *iface); -HRESULT WINAPI dmobj_IPersistStream_GetClassID(IPersistStream *iface, CLSID *class); - -/* IPersistStream methods not implemented in native */ -HRESULT WINAPI unimpl_IPersistStream_GetClassID(IPersistStream *iface, - CLSID *class); -HRESULT WINAPI unimpl_IPersistStream_IsDirty(IPersistStream *iface); -HRESULT WINAPI unimpl_IPersistStream_Save(IPersistStream *iface, IStream *stream, - BOOL clear_dirty); -HRESULT WINAPI unimpl_IPersistStream_GetSizeMax(IPersistStream *iface, - ULARGE_INTEGER *size); - -/* Debugging helpers */ -const char *debugstr_chunk(const struct chunk_entry *chunk); -const char *debugstr_dmguid(const GUID *id); -void dump_DMUS_OBJECTDESC(DMUS_OBJECTDESC *desc); - -static inline const char *debugstr_fourcc(DWORD fourcc) -{ - if (!fourcc) return "''"; - return wine_dbg_sprintf("'%c%c%c%c'", (char)(fourcc), (char)(fourcc >> 8), - (char)(fourcc >> 16), (char)(fourcc >> 24)); -}
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dmloader/container.c | 3 --- dlls/dmloader/dmloader_main.c | 21 --------------------- dlls/dmloader/dmloader_private.h | 5 ----- dlls/dmloader/loader.c | 3 --- 4 files changed, 32 deletions(-)
diff --git a/dlls/dmloader/container.c b/dlls/dmloader/container.c index f2b284e1cb3..747c2a07341 100644 --- a/dlls/dmloader/container.c +++ b/dlls/dmloader/container.c @@ -137,7 +137,6 @@ static ULONG WINAPI IDirectMusicContainerImpl_Release(IDirectMusicContainer *ifa if (This->pStream) destroy_dmcontainer(This); HeapFree(GetProcessHeap(), 0, This); - unlock_module(); }
return ref; @@ -666,8 +665,6 @@ HRESULT create_dmcontainer(REFIID lpcGUID, void **ppobj) obj->pContainedObjects = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(struct list)); list_init (obj->pContainedObjects);
- lock_module(); - hr = IDirectMusicContainer_QueryInterface(&obj->IDirectMusicContainer_iface, lpcGUID, ppobj); IDirectMusicContainer_Release(&obj->IDirectMusicContainer_iface);
diff --git a/dlls/dmloader/dmloader_main.c b/dlls/dmloader/dmloader_main.c index 512e6102d86..96d841e2b2d 100644 --- a/dlls/dmloader/dmloader_main.c +++ b/dlls/dmloader/dmloader_main.c @@ -36,8 +36,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(dmloader);
-LONG module_ref = 0; - typedef struct { IClassFactory IClassFactory_iface; HRESULT (*fnCreateInstance)(REFIID riid, void **ppv); @@ -73,15 +71,11 @@ static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID r
static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface) { - lock_module(); - return 2; /* non-heap based object */ }
static ULONG WINAPI ClassFactory_Release(IClassFactory *iface) { - unlock_module(); - return 1; /* non-heap based object */ }
@@ -103,12 +97,6 @@ static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock) { TRACE("(%d)\n", dolock); - - if (dolock) - lock_module(); - else - unlock_module(); - return S_OK; }
@@ -123,15 +111,6 @@ static const IClassFactoryVtbl classfactory_vtbl = { static IClassFactoryImpl dm_loader_CF = {{&classfactory_vtbl}, create_dmloader}; static IClassFactoryImpl dm_container_CF = {{&classfactory_vtbl}, create_dmcontainer};
-/****************************************************************** - * DllCanUnloadNow (DMLOADER.@) - */ -HRESULT WINAPI DllCanUnloadNow (void) -{ - TRACE("() ref=%ld\n", module_ref); - - return module_ref ? S_FALSE : S_OK; -}
/****************************************************************** * DllGetClassObject (DMLOADER.@) diff --git a/dlls/dmloader/dmloader_private.h b/dlls/dmloader/dmloader_private.h index 204c9689ffb..0aea1ba8499 100644 --- a/dlls/dmloader/dmloader_private.h +++ b/dlls/dmloader/dmloader_private.h @@ -44,11 +44,6 @@
#define ICOM_THIS_MULTI(impl,field,iface) impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
-/* dmloader.dll global (for DllCanUnloadNow) */ -extern LONG module_ref; -static inline void lock_module(void) { InterlockedIncrement( &module_ref ); } -static inline void unlock_module(void) { InterlockedDecrement( &module_ref ); } - /***************************************************************************** * Interfaces */ diff --git a/dlls/dmloader/loader.c b/dlls/dmloader/loader.c index 6c4b29ab5ea..f303f93baaa 100644 --- a/dlls/dmloader/loader.c +++ b/dlls/dmloader/loader.c @@ -157,7 +157,6 @@ static ULONG WINAPI IDirectMusicLoaderImpl_Release(IDirectMusicLoader8 *iface) for (i = 0; i < ARRAY_SIZE(classes); i++) HeapFree(GetProcessHeap(), 0, This->search_paths[i]); HeapFree(GetProcessHeap(), 0, This); - unlock_module(); }
return ref; @@ -940,7 +939,5 @@ HRESULT create_dmloader(REFIID lpcGUID, void **ppobj) dls->bInvalidDefaultDLS = TRUE; }
- lock_module(); - return IDirectMusicLoader_QueryInterface(&obj->IDirectMusicLoader8_iface, lpcGUID, ppobj); }
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dmloader/container.c | 33 +++++++++++++++------------------ dlls/dmloader/dmobject.c | 7 +++---- dlls/dmloader/loader.c | 19 ++++++++----------- dlls/dmloader/loaderstream.c | 28 +++++++++++----------------- 4 files changed, 37 insertions(+), 50 deletions(-)
diff --git a/dlls/dmloader/container.c b/dlls/dmloader/container.c index 747c2a07341..66049e68907 100644 --- a/dlls/dmloader/container.c +++ b/dlls/dmloader/container.c @@ -136,7 +136,7 @@ static ULONG WINAPI IDirectMusicContainerImpl_Release(IDirectMusicContainer *ifa if (!ref) { if (This->pStream) destroy_dmcontainer(This); - HeapFree(GetProcessHeap(), 0, This); + free(This); }
return ref; @@ -388,7 +388,7 @@ static HRESULT WINAPI IPersistStreamImpl_Load(IPersistStream *iface, IStream *pS case DMUS_FOURCC_CONTAINED_OBJECT_LIST: { LPWINE_CONTAINER_ENTRY pNewEntry; TRACE_(dmfile)(": contained object list\n"); - pNewEntry = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(WINE_CONTAINER_ENTRY)); + pNewEntry = calloc(1, sizeof(*pNewEntry)); DM_STRUCT_INIT(&pNewEntry->Desc); do { IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL); @@ -397,7 +397,7 @@ static HRESULT WINAPI IPersistStreamImpl_Load(IPersistStream *iface, IStream *pS switch (Chunk.fccID) { case DMUS_FOURCC_CONTAINED_ALIAS_CHUNK: { TRACE_(dmfile)(": alias chunk\n"); - pNewEntry->wszAlias = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, Chunk.dwSize); + pNewEntry->wszAlias = calloc(1, Chunk.dwSize); IStream_Read (pStm, pNewEntry->wszAlias, Chunk.dwSize, NULL); TRACE_(dmfile)(": alias: %s\n", debugstr_w(pNewEntry->wszAlias)); break; @@ -649,24 +649,21 @@ static const IPersistStreamVtbl persiststream_vtbl = { HRESULT create_dmcontainer(REFIID lpcGUID, void **ppobj) { IDirectMusicContainerImpl* obj; - HRESULT hr; + HRESULT hr;
- obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicContainerImpl)); - if (NULL == obj) { - *ppobj = NULL; - return E_OUTOFMEMORY; - } - obj->IDirectMusicContainer_iface.lpVtbl = &dmcontainer_vtbl; - obj->ref = 1; - dmobject_init(&obj->dmobj, &CLSID_DirectMusicContainer, - (IUnknown*)&obj->IDirectMusicContainer_iface); - obj->dmobj.IDirectMusicObject_iface.lpVtbl = &dmobject_vtbl; - obj->dmobj.IPersistStream_iface.lpVtbl = &persiststream_vtbl; + *ppobj = NULL; + if (!(obj = calloc(1, sizeof(*obj)))) return E_OUTOFMEMORY; + obj->IDirectMusicContainer_iface.lpVtbl = &dmcontainer_vtbl; + obj->ref = 1; + dmobject_init(&obj->dmobj, &CLSID_DirectMusicContainer, + (IUnknown*)&obj->IDirectMusicContainer_iface); + obj->dmobj.IDirectMusicObject_iface.lpVtbl = &dmobject_vtbl; + obj->dmobj.IPersistStream_iface.lpVtbl = &persiststream_vtbl; obj->pContainedObjects = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(struct list)); list_init (obj->pContainedObjects);
- hr = IDirectMusicContainer_QueryInterface(&obj->IDirectMusicContainer_iface, lpcGUID, ppobj); - IDirectMusicContainer_Release(&obj->IDirectMusicContainer_iface); + hr = IDirectMusicContainer_QueryInterface(&obj->IDirectMusicContainer_iface, lpcGUID, ppobj); + IDirectMusicContainer_Release(&obj->IDirectMusicContainer_iface);
- return hr; + return hr; } diff --git a/dlls/dmloader/dmobject.c b/dlls/dmloader/dmobject.c index b526b23d031..07d887a376c 100644 --- a/dlls/dmloader/dmobject.c +++ b/dlls/dmloader/dmobject.c @@ -28,7 +28,6 @@ #include "dmusics.h" #include "dmobject.h" #include "wine/debug.h" -#include "wine/heap.h"
WINE_DEFAULT_DEBUG_CHANNEL(dmobj); WINE_DECLARE_DEBUG_CHANNEL(dmfile); @@ -375,7 +374,7 @@ HRESULT stream_next_chunk(IStream *stream, struct chunk_entry *chunk) /* Reads chunk data of the form: DWORD - size of array element element[] - Array of elements - The caller needs to heap_free() the array. + The caller needs to free() the array. */ HRESULT stream_chunk_get_array(IStream *stream, const struct chunk_entry *chunk, void **array, unsigned int *count, DWORD elem_size) @@ -400,10 +399,10 @@ HRESULT stream_chunk_get_array(IStream *stream, const struct chunk_entry *chunk,
*count = (chunk->size - sizeof(DWORD)) / elem_size; size = *count * elem_size; - if (!(*array = heap_alloc(size))) + if (!(*array = malloc(size))) return E_OUTOFMEMORY; if (FAILED(hr = stream_read(stream, *array, size))) { - heap_free(*array); + free(*array); *array = NULL; return hr; } diff --git a/dlls/dmloader/loader.c b/dlls/dmloader/loader.c index f303f93baaa..7b1fb8d04a5 100644 --- a/dlls/dmloader/loader.c +++ b/dlls/dmloader/loader.c @@ -155,8 +155,8 @@ static ULONG WINAPI IDirectMusicLoaderImpl_Release(IDirectMusicLoader8 *iface)
IDirectMusicLoader8_ClearCache(iface, &GUID_DirectMusicAllTypes); for (i = 0; i < ARRAY_SIZE(classes); i++) - HeapFree(GetProcessHeap(), 0, This->search_paths[i]); - HeapFree(GetProcessHeap(), 0, This); + free(This->search_paths[i]); + free(This); }
return ref; @@ -427,7 +427,7 @@ static HRESULT WINAPI IDirectMusicLoaderImpl_GetObject(IDirectMusicLoader8 *ifac bCache = is_cache_enabled(This, &pDesc->guidClass); if (bCache) { if (!pObjectEntry) { - pObjectEntry = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(*pObjectEntry)); + pObjectEntry = calloc(1, sizeof(*pObjectEntry)); DM_STRUCT_INIT(&pObjectEntry->Desc); DMUSIC_CopyDescriptor (&pObjectEntry->Desc, &GotDesc); pObjectEntry->pObject = pObject; @@ -566,7 +566,7 @@ static HRESULT WINAPI IDirectMusicLoaderImpl_SetObject(IDirectMusicLoader8 *ifac TRACE(": adding alias entry with following info:\n"); if (TRACE_ON(dmloader)) dump_DMUS_OBJECTDESC(pDesc); - pNewEntry = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(*pNewEntry)); + pNewEntry = calloc(1, sizeof(*pNewEntry)); /* use this function instead of pure memcpy due to streams (memcpy just copies pointer), which is basically used further by app that called SetDescriptor... better safety than exception */ DMUSIC_CopyDescriptor (&pNewEntry->Desc, pDesc); @@ -601,7 +601,7 @@ static HRESULT WINAPI IDirectMusicLoaderImpl_SetSearchDirectory(IDirectMusicLoad return S_OK;
if (!This->search_paths[index]) - This->search_paths[index] = HeapAlloc(GetProcessHeap(), 0, MAX_PATH); + This->search_paths[index] = malloc(MAX_PATH); else if (!wcsncmp(This->search_paths[index], path, MAX_PATH)) return S_FALSE;
@@ -743,7 +743,7 @@ static HRESULT WINAPI IDirectMusicLoaderImpl_ClearCache(IDirectMusicLoader8 *ifa /* basically, wrap to ReleaseObject for each object found */ IDirectMusicLoader8_ReleaseObject(iface, obj->pObject); list_remove(&obj->entry); - HeapFree(GetProcessHeap(), 0, obj); + free(obj); } }
@@ -910,11 +910,8 @@ HRESULT create_dmloader(REFIID lpcGUID, void **ppobj) struct list *pEntry;
TRACE("(%s, %p)\n", debugstr_dmguid(lpcGUID), ppobj); - obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicLoaderImpl)); - if (NULL == obj) { - *ppobj = NULL; - return E_OUTOFMEMORY; - } + *ppobj = NULL; + if (!(obj = calloc(1, sizeof(*obj)))) return E_OUTOFMEMORY; obj->IDirectMusicLoader8_iface.lpVtbl = &DirectMusicLoader_Loader_Vtbl; obj->ref = 0; /* Will be inited with QueryInterface */ list_init(&obj->cache); diff --git a/dlls/dmloader/loaderstream.c b/dlls/dmloader/loaderstream.c index 889070be8f6..5d6c5ad3e25 100644 --- a/dlls/dmloader/loaderstream.c +++ b/dlls/dmloader/loaderstream.c @@ -120,7 +120,7 @@ static ULONG WINAPI IDirectMusicLoaderFileStream_IStream_Release (LPSTREAM iface if (dwRef == 0) { if (This->hFile) IDirectMusicLoaderFileStream_Detach (iface); - HeapFree (GetProcessHeap(), 0, This); + free(This); } return dwRef; @@ -290,11 +290,9 @@ HRESULT DMUSIC_CreateDirectMusicLoaderFileStream (void** ppobj) { IDirectMusicLoaderFileStream *obj;
TRACE("(%p)\n", ppobj); - obj = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(IDirectMusicLoaderFileStream)); - if (NULL == obj) { - *ppobj = NULL; - return E_OUTOFMEMORY; - } + + *ppobj = NULL; + if (!(obj = calloc(1, sizeof(*obj)))) return E_OUTOFMEMORY; obj->StreamVtbl = &DirectMusicLoaderFileStream_Stream_Vtbl; obj->GetLoaderVtbl = &DirectMusicLoaderFileStream_GetLoader_Vtbl; obj->dwRef = 0; /* will be inited with QueryInterface */ @@ -367,7 +365,7 @@ static ULONG WINAPI IDirectMusicLoaderResourceStream_IStream_Release (LPSTREAM i TRACE("(%p): ReleaseRef to %ld\n", This, dwRef); if (dwRef == 0) { IDirectMusicLoaderResourceStream_Detach (iface); - HeapFree (GetProcessHeap(), 0, This); + free(This); } return dwRef; @@ -547,11 +545,9 @@ HRESULT DMUSIC_CreateDirectMusicLoaderResourceStream (void** ppobj) { IDirectMusicLoaderResourceStream *obj;
TRACE("(%p)\n", ppobj); - obj = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(IDirectMusicLoaderResourceStream)); - if (NULL == obj) { - *ppobj = NULL; - return E_OUTOFMEMORY; - } + + *ppobj = NULL; + if (!(obj = calloc(1, sizeof(*obj)))) return E_OUTOFMEMORY; obj->StreamVtbl = &DirectMusicLoaderResourceStream_Stream_Vtbl; obj->GetLoaderVtbl = &DirectMusicLoaderResourceStream_GetLoader_Vtbl; obj->dwRef = 0; /* will be inited with QueryInterface */ @@ -799,11 +795,9 @@ HRESULT DMUSIC_CreateDirectMusicLoaderGenericStream (void** ppobj) { IDirectMusicLoaderGenericStream *obj;
TRACE("(%p)\n", ppobj); - obj = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(IDirectMusicLoaderGenericStream)); - if (NULL == obj) { - *ppobj = NULL; - return E_OUTOFMEMORY; - } + + *ppobj = NULL; + if (!(obj = calloc(1, sizeof(*obj)))) return E_OUTOFMEMORY; obj->StreamVtbl = &DirectMusicLoaderGenericStream_Stream_Vtbl; obj->GetLoaderVtbl = &DirectMusicLoaderGenericStream_GetLoader_Vtbl; obj->dwRef = 0; /* will be inited with QueryInterface */
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dmloader/Makefile.in | 1 + dlls/dmloader/dmobject.c | 732 -------------------------------------- dlls/dmloader/dmobject.h | 124 ------- 3 files changed, 1 insertion(+), 856 deletions(-) delete mode 100644 dlls/dmloader/dmobject.c delete mode 100644 dlls/dmloader/dmobject.h
diff --git a/dlls/dmloader/Makefile.in b/dlls/dmloader/Makefile.in index 4aa80c6dfb3..a8d3698ab6c 100644 --- a/dlls/dmloader/Makefile.in +++ b/dlls/dmloader/Makefile.in @@ -1,5 +1,6 @@ MODULE = dmloader.dll IMPORTS = dxguid uuid ole32 advapi32 +PARENTSRC = ../dmusic
C_SRCS = \ container.c \ diff --git a/dlls/dmloader/dmobject.c b/dlls/dmloader/dmobject.c deleted file mode 100644 index 07d887a376c..00000000000 --- a/dlls/dmloader/dmobject.c +++ /dev/null @@ -1,732 +0,0 @@ -/* - * Base IDirectMusicObject Implementation - * Keep in sync with the master in dlls/dmusic/dmobject.c - * - * Copyright (C) 2003-2004 Rok Mandeljc - * Copyright (C) 2014 Michael Stefaniuc - * - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * 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 - */ - -#define COBJMACROS -#include <assert.h> -#include "objbase.h" -#include "dmusici.h" -#include "dmusicf.h" -#include "dmusics.h" -#include "dmobject.h" -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(dmobj); -WINE_DECLARE_DEBUG_CHANNEL(dmfile); - -/* Debugging helpers */ -const char *debugstr_dmguid(const GUID *id) { - unsigned int i; -#define X(guid) { &guid, #guid } - static const struct { - const GUID *guid; - const char *name; - } guids[] = { - /* CLSIDs */ - X(CLSID_AudioVBScript), - X(CLSID_DirectMusic), - X(CLSID_DirectMusicAudioPathConfig), - X(CLSID_DirectMusicAuditionTrack), - X(CLSID_DirectMusicBand), - X(CLSID_DirectMusicBandTrack), - X(CLSID_DirectMusicChordMapTrack), - X(CLSID_DirectMusicChordMap), - X(CLSID_DirectMusicChordTrack), - X(CLSID_DirectMusicCollection), - X(CLSID_DirectMusicCommandTrack), - X(CLSID_DirectMusicComposer), - X(CLSID_DirectMusicContainer), - X(CLSID_DirectMusicGraph), - X(CLSID_DirectMusicLoader), - X(CLSID_DirectMusicLyricsTrack), - X(CLSID_DirectMusicMarkerTrack), - X(CLSID_DirectMusicMelodyFormulationTrack), - X(CLSID_DirectMusicMotifTrack), - X(CLSID_DirectMusicMuteTrack), - X(CLSID_DirectMusicParamControlTrack), - X(CLSID_DirectMusicPatternTrack), - X(CLSID_DirectMusicPerformance), - X(CLSID_DirectMusicScript), - X(CLSID_DirectMusicScriptAutoImpSegment), - X(CLSID_DirectMusicScriptAutoImpPerformance), - X(CLSID_DirectMusicScriptAutoImpSegmentState), - X(CLSID_DirectMusicScriptAutoImpAudioPathConfig), - X(CLSID_DirectMusicScriptAutoImpAudioPath), - X(CLSID_DirectMusicScriptAutoImpSong), - X(CLSID_DirectMusicScriptSourceCodeLoader), - X(CLSID_DirectMusicScriptTrack), - X(CLSID_DirectMusicSection), - X(CLSID_DirectMusicSegment), - X(CLSID_DirectMusicSegmentState), - X(CLSID_DirectMusicSegmentTriggerTrack), - X(CLSID_DirectMusicSegTriggerTrack), - X(CLSID_DirectMusicSeqTrack), - X(CLSID_DirectMusicSignPostTrack), - X(CLSID_DirectMusicSong), - X(CLSID_DirectMusicStyle), - X(CLSID_DirectMusicStyleTrack), - X(CLSID_DirectMusicSynth), - X(CLSID_DirectMusicSynthSink), - X(CLSID_DirectMusicSysExTrack), - X(CLSID_DirectMusicTemplate), - X(CLSID_DirectMusicTempoTrack), - X(CLSID_DirectMusicTimeSigTrack), - X(CLSID_DirectMusicWaveTrack), - X(CLSID_DirectSoundWave), - /* IIDs */ - X(IID_IDirectMusic), - X(IID_IDirectMusic2), - X(IID_IDirectMusic8), - X(IID_IDirectMusicAudioPath), - X(IID_IDirectMusicBand), - X(IID_IDirectMusicBuffer), - X(IID_IDirectMusicChordMap), - X(IID_IDirectMusicCollection), - X(IID_IDirectMusicComposer), - X(IID_IDirectMusicContainer), - X(IID_IDirectMusicDownload), - X(IID_IDirectMusicDownloadedInstrument), - X(IID_IDirectMusicGetLoader), - X(IID_IDirectMusicGraph), - X(IID_IDirectMusicInstrument), - X(IID_IDirectMusicLoader), - X(IID_IDirectMusicLoader8), - X(IID_IDirectMusicObject), - X(IID_IDirectMusicPatternTrack), - X(IID_IDirectMusicPerformance), - X(IID_IDirectMusicPerformance2), - X(IID_IDirectMusicPerformance8), - X(IID_IDirectMusicPort), - X(IID_IDirectMusicPortDownload), - X(IID_IDirectMusicScript), - X(IID_IDirectMusicSegment), - X(IID_IDirectMusicSegment2), - X(IID_IDirectMusicSegment8), - X(IID_IDirectMusicSegmentState), - X(IID_IDirectMusicSegmentState8), - X(IID_IDirectMusicStyle), - X(IID_IDirectMusicStyle8), - X(IID_IDirectMusicSynth), - X(IID_IDirectMusicSynth8), - X(IID_IDirectMusicSynthSink), - X(IID_IDirectMusicThru), - X(IID_IDirectMusicTool), - X(IID_IDirectMusicTool8), - X(IID_IDirectMusicTrack), - X(IID_IDirectMusicTrack8), - X(IID_IUnknown), - X(IID_IPersistStream), - X(IID_IStream), - X(IID_IClassFactory), - /* GUIDs */ - X(GUID_DirectMusicAllTypes), - X(GUID_NOTIFICATION_CHORD), - X(GUID_NOTIFICATION_COMMAND), - X(GUID_NOTIFICATION_MEASUREANDBEAT), - X(GUID_NOTIFICATION_PERFORMANCE), - X(GUID_NOTIFICATION_RECOMPOSE), - X(GUID_NOTIFICATION_SEGMENT), - X(GUID_BandParam), - X(GUID_ChordParam), - X(GUID_CommandParam), - X(GUID_CommandParam2), - X(GUID_CommandParamNext), - X(GUID_IDirectMusicBand), - X(GUID_IDirectMusicChordMap), - X(GUID_IDirectMusicStyle), - X(GUID_MuteParam), - X(GUID_Play_Marker), - X(GUID_RhythmParam), - X(GUID_TempoParam), - X(GUID_TimeSignature), - X(GUID_Valid_Start_Time), - X(GUID_Clear_All_Bands), - X(GUID_ConnectToDLSCollection), - X(GUID_Disable_Auto_Download), - X(GUID_DisableTempo), - X(GUID_DisableTimeSig), - X(GUID_Download), - X(GUID_DownloadToAudioPath), - X(GUID_Enable_Auto_Download), - X(GUID_EnableTempo), - X(GUID_EnableTimeSig), - X(GUID_IgnoreBankSelectForGM), - X(GUID_SeedVariations), - X(GUID_StandardMIDIFile), - X(GUID_Unload), - X(GUID_UnloadFromAudioPath), - X(GUID_Variations), - X(GUID_PerfMasterTempo), - X(GUID_PerfMasterVolume), - X(GUID_PerfMasterGrooveLevel), - X(GUID_PerfAutoDownload), - X(GUID_DefaultGMCollection), - X(GUID_Synth_Default), - X(GUID_Buffer_Reverb), - X(GUID_Buffer_EnvReverb), - X(GUID_Buffer_Stereo), - X(GUID_Buffer_3D_Dry), - X(GUID_Buffer_Mono), - X(GUID_DMUS_PROP_GM_Hardware), - X(GUID_DMUS_PROP_GS_Capable), - X(GUID_DMUS_PROP_GS_Hardware), - X(GUID_DMUS_PROP_DLS1), - X(GUID_DMUS_PROP_DLS2), - X(GUID_DMUS_PROP_Effects), - X(GUID_DMUS_PROP_INSTRUMENT2), - X(GUID_DMUS_PROP_LegacyCaps), - X(GUID_DMUS_PROP_MemorySize), - X(GUID_DMUS_PROP_SampleMemorySize), - X(GUID_DMUS_PROP_SamplePlaybackRate), - X(GUID_DMUS_PROP_SetSynthSink), - X(GUID_DMUS_PROP_SinkUsesDSound), - X(GUID_DMUS_PROP_SynthSink_DSOUND), - X(GUID_DMUS_PROP_SynthSink_WAVE), - X(GUID_DMUS_PROP_Volume), - X(GUID_DMUS_PROP_WavesReverb), - X(GUID_DMUS_PROP_WriteLatency), - X(GUID_DMUS_PROP_WritePeriod), - X(GUID_DMUS_PROP_XG_Capable), - X(GUID_DMUS_PROP_XG_Hardware) - }; -#undef X - - if (!id) - return "(null)"; - - for (i = 0; i < ARRAY_SIZE(guids); i++) - if (IsEqualGUID(id, guids[i].guid)) - return guids[i].name; - - return debugstr_guid(id); -} - -void dump_DMUS_OBJECTDESC(DMUS_OBJECTDESC *desc) -{ - if (!desc || !TRACE_ON(dmfile)) - return; - - TRACE_(dmfile)("DMUS_OBJECTDESC (%p):", desc); - TRACE_(dmfile)(" - dwSize = %lu\n", desc->dwSize); - -#define X(flag) if (desc->dwValidData & flag) TRACE_(dmfile)(#flag " ") - TRACE_(dmfile)(" - dwValidData = %#08lx ( ", desc->dwValidData); - X(DMUS_OBJ_OBJECT); - X(DMUS_OBJ_CLASS); - X(DMUS_OBJ_NAME); - X(DMUS_OBJ_CATEGORY); - X(DMUS_OBJ_FILENAME); - X(DMUS_OBJ_FULLPATH); - X(DMUS_OBJ_URL); - X(DMUS_OBJ_VERSION); - X(DMUS_OBJ_DATE); - X(DMUS_OBJ_LOADED); - X(DMUS_OBJ_MEMORY); - X(DMUS_OBJ_STREAM); - TRACE_(dmfile)(")\n"); -#undef X - - if (desc->dwValidData & DMUS_OBJ_CLASS) - TRACE_(dmfile)(" - guidClass = %s\n", debugstr_dmguid(&desc->guidClass)); - if (desc->dwValidData & DMUS_OBJ_OBJECT) - TRACE_(dmfile)(" - guidObject = %s\n", debugstr_guid(&desc->guidObject)); - - if (desc->dwValidData & DMUS_OBJ_DATE) { - SYSTEMTIME time; - FileTimeToSystemTime(&desc->ftDate, &time); - TRACE_(dmfile)(" - ftDate = '%04u-%02u-%02u %02u:%02u:%02u'\n", - time.wYear, time.wMonth, time.wDay, time.wHour, time.wMinute, time.wSecond); - } - if (desc->dwValidData & DMUS_OBJ_VERSION) - TRACE_(dmfile)(" - vVersion = '%u,%u,%u,%u'\n", - HIWORD(desc->vVersion.dwVersionMS), LOWORD(desc->vVersion.dwVersionMS), - HIWORD(desc->vVersion.dwVersionLS), LOWORD(desc->vVersion.dwVersionLS)); - if (desc->dwValidData & DMUS_OBJ_NAME) - TRACE_(dmfile)(" - wszName = %s\n", debugstr_w(desc->wszName)); - if (desc->dwValidData & DMUS_OBJ_CATEGORY) - TRACE_(dmfile)(" - wszCategory = %s\n", debugstr_w(desc->wszCategory)); - if (desc->dwValidData & DMUS_OBJ_FILENAME) - TRACE_(dmfile)(" - wszFileName = %s\n", debugstr_w(desc->wszFileName)); - if (desc->dwValidData & DMUS_OBJ_MEMORY) - TRACE_(dmfile)(" - llMemLength = 0x%s - pbMemData = %p\n", - wine_dbgstr_longlong(desc->llMemLength), desc->pbMemData); - if (desc->dwValidData & DMUS_OBJ_STREAM) - TRACE_(dmfile)(" - pStream = %p\n", desc->pStream); -} - - -/* RIFF format parsing */ -#define CHUNK_HDR_SIZE (sizeof(FOURCC) + sizeof(DWORD)) - -const char *debugstr_chunk(const struct chunk_entry *chunk) -{ - const char *type = ""; - - if (!chunk) - return "(null)"; - if (chunk->id == FOURCC_RIFF || chunk->id == FOURCC_LIST) - type = wine_dbg_sprintf("type %s, ", debugstr_fourcc(chunk->type)); - return wine_dbg_sprintf("%s chunk, %ssize %lu", debugstr_fourcc(chunk->id), type, chunk->size); -} - -static HRESULT stream_read(IStream *stream, void *data, ULONG size) -{ - ULONG read; - HRESULT hr; - - hr = IStream_Read(stream, data, size, &read); - if (FAILED(hr)) - TRACE_(dmfile)("IStream_Read failed: %#lx\n", hr); - else if (!read && read < size) { - /* All or nothing: Handle a partial read due to end of stream as an error */ - TRACE_(dmfile)("Short read: %lu < %lu\n", read, size); - return E_FAIL; - } - - return hr; -} - -HRESULT stream_get_chunk(IStream *stream, struct chunk_entry *chunk) -{ - static const LARGE_INTEGER zero; - ULONGLONG ck_end = 0, p_end = 0; - HRESULT hr; - - hr = IStream_Seek(stream, zero, STREAM_SEEK_CUR, &chunk->offset); - if (FAILED(hr)) - return hr; - assert(!(chunk->offset.QuadPart & 1)); - if (chunk->parent) { - p_end = chunk->parent->offset.QuadPart + CHUNK_HDR_SIZE + ((chunk->parent->size + 1) & ~1); - if (chunk->offset.QuadPart == p_end) - return S_FALSE; - ck_end = chunk->offset.QuadPart + CHUNK_HDR_SIZE; - if (ck_end > p_end) { - WARN_(dmfile)("No space for sub-chunk header in parent chunk: ends at offset %s > %s\n", - wine_dbgstr_longlong(ck_end), wine_dbgstr_longlong(p_end)); - return E_FAIL; - } - } - - hr = stream_read(stream, chunk, CHUNK_HDR_SIZE); - if (hr != S_OK) - return hr; - if (chunk->parent) { - ck_end += (chunk->size + 1) & ~1; - if (ck_end > p_end) { - WARN_(dmfile)("No space for sub-chunk data in parent chunk: ends at offset %s > %s\n", - wine_dbgstr_longlong(ck_end), wine_dbgstr_longlong(p_end)); - return E_FAIL; - } - } - - if (chunk->id == FOURCC_LIST || chunk->id == FOURCC_RIFF) { - hr = stream_read(stream, &chunk->type, sizeof(FOURCC)); - if (hr != S_OK) - return hr != S_FALSE ? hr : E_FAIL; - } - - TRACE_(dmfile)("Returning %s\n", debugstr_chunk(chunk)); - - return S_OK; -} - -HRESULT stream_skip_chunk(IStream *stream, const struct chunk_entry *chunk) -{ - LARGE_INTEGER end; - - end.QuadPart = (chunk->offset.QuadPart + CHUNK_HDR_SIZE + chunk->size + 1) & ~(ULONGLONG)1; - - return IStream_Seek(stream, end, STREAM_SEEK_SET, NULL); -} - -HRESULT stream_next_chunk(IStream *stream, struct chunk_entry *chunk) -{ - HRESULT hr; - - if (chunk->id) { - hr = stream_skip_chunk(stream, chunk); - if (FAILED(hr)) - return hr; - } - - return stream_get_chunk(stream, chunk); -} - -/* Reads chunk data of the form: - DWORD - size of array element - element[] - Array of elements - The caller needs to free() the array. -*/ -HRESULT stream_chunk_get_array(IStream *stream, const struct chunk_entry *chunk, void **array, - unsigned int *count, DWORD elem_size) -{ - DWORD size; - HRESULT hr; - - *array = NULL; - *count = 0; - - if (chunk->size < sizeof(DWORD)) { - WARN_(dmfile)("%s: Too short to read element size\n", debugstr_chunk(chunk)); - return E_FAIL; - } - if (FAILED(hr = stream_read(stream, &size, sizeof(DWORD)))) - return hr; - if (size != elem_size) { - WARN_(dmfile)("%s: Array element size mismatch: got %lu, expected %lu\n", - debugstr_chunk(chunk), size, elem_size); - return DMUS_E_UNSUPPORTED_STREAM; - } - - *count = (chunk->size - sizeof(DWORD)) / elem_size; - size = *count * elem_size; - if (!(*array = malloc(size))) - return E_OUTOFMEMORY; - if (FAILED(hr = stream_read(stream, *array, size))) { - free(*array); - *array = NULL; - return hr; - } - - if (chunk->size > size + sizeof(DWORD)) { - WARN_(dmfile)("%s: Extraneous data at end of array\n", debugstr_chunk(chunk)); - stream_skip_chunk(stream, chunk); - return S_FALSE; - } - return S_OK; -} - -HRESULT stream_chunk_get_data(IStream *stream, const struct chunk_entry *chunk, void *data, - ULONG size) -{ - if (chunk->size != size) { - WARN_(dmfile)("Chunk %s (size %lu, offset %s) doesn't contains the expected data size %lu\n", - debugstr_fourcc(chunk->id), chunk->size, - wine_dbgstr_longlong(chunk->offset.QuadPart), size); - return E_FAIL; - } - return stream_read(stream, data, size); -} - -HRESULT stream_chunk_get_wstr(IStream *stream, const struct chunk_entry *chunk, WCHAR *str, - ULONG size) -{ - ULONG len; - HRESULT hr; - - hr = IStream_Read(stream, str, min(chunk->size, size), &len); - if (FAILED(hr)) - return hr; - - /* Don't assume the string is properly zero terminated */ - str[min(len, size - 1)] = 0; - - if (len < chunk->size) - return S_FALSE; - return S_OK; -} - - - -/* Generic IDirectMusicObject methods */ -static inline struct dmobject *impl_from_IDirectMusicObject(IDirectMusicObject *iface) -{ - return CONTAINING_RECORD(iface, struct dmobject, IDirectMusicObject_iface); -} - -HRESULT WINAPI dmobj_IDirectMusicObject_QueryInterface(IDirectMusicObject *iface, REFIID riid, - void **ret_iface) -{ - struct dmobject *This = impl_from_IDirectMusicObject(iface); - return IUnknown_QueryInterface(This->outer_unk, riid, ret_iface); -} - -ULONG WINAPI dmobj_IDirectMusicObject_AddRef(IDirectMusicObject *iface) -{ - struct dmobject *This = impl_from_IDirectMusicObject(iface); - return IUnknown_AddRef(This->outer_unk); -} - -ULONG WINAPI dmobj_IDirectMusicObject_Release(IDirectMusicObject *iface) -{ - struct dmobject *This = impl_from_IDirectMusicObject(iface); - return IUnknown_Release(This->outer_unk); -} - -HRESULT WINAPI dmobj_IDirectMusicObject_GetDescriptor(IDirectMusicObject *iface, - DMUS_OBJECTDESC *desc) -{ - struct dmobject *This = impl_from_IDirectMusicObject(iface); - - TRACE("(%p/%p)->(%p)\n", iface, This, desc); - - if (!desc) - return E_POINTER; - - memcpy(desc, &This->desc, This->desc.dwSize); - - return S_OK; -} - -HRESULT WINAPI dmobj_IDirectMusicObject_SetDescriptor(IDirectMusicObject *iface, - DMUS_OBJECTDESC *desc) -{ - struct dmobject *This = impl_from_IDirectMusicObject(iface); - HRESULT ret = S_OK; - - TRACE("(%p, %p)\n", iface, desc); - - if (!desc) - return E_POINTER; - - /* Immutable property */ - if (desc->dwValidData & DMUS_OBJ_CLASS) - { - desc->dwValidData &= ~DMUS_OBJ_CLASS; - ret = S_FALSE; - } - /* Set only valid fields */ - if (desc->dwValidData & DMUS_OBJ_OBJECT) - This->desc.guidObject = desc->guidObject; - if (desc->dwValidData & DMUS_OBJ_NAME) - lstrcpynW(This->desc.wszName, desc->wszName, DMUS_MAX_NAME); - if (desc->dwValidData & DMUS_OBJ_CATEGORY) - lstrcpynW(This->desc.wszCategory, desc->wszCategory, DMUS_MAX_CATEGORY); - if (desc->dwValidData & DMUS_OBJ_FILENAME) - lstrcpynW(This->desc.wszFileName, desc->wszFileName, DMUS_MAX_FILENAME); - if (desc->dwValidData & DMUS_OBJ_VERSION) - This->desc.vVersion = desc->vVersion; - if (desc->dwValidData & DMUS_OBJ_DATE) - This->desc.ftDate = desc->ftDate; - if (desc->dwValidData & DMUS_OBJ_MEMORY) { - This->desc.llMemLength = desc->llMemLength; - memcpy(This->desc.pbMemData, desc->pbMemData, desc->llMemLength); - } - if (desc->dwValidData & DMUS_OBJ_STREAM) - IStream_Clone(desc->pStream, &This->desc.pStream); - - This->desc.dwValidData |= desc->dwValidData; - - return ret; -} - -/* Helper for IDirectMusicObject::ParseDescriptor */ -static inline void info_get_name(IStream *stream, const struct chunk_entry *info, - DMUS_OBJECTDESC *desc) -{ - struct chunk_entry chunk = {.parent = info}; - char name[DMUS_MAX_NAME]; - ULONG len; - HRESULT hr = E_FAIL; - - while (stream_next_chunk(stream, &chunk) == S_OK) - if (chunk.id == mmioFOURCC('I','N','A','M')) - hr = IStream_Read(stream, name, min(chunk.size, sizeof(name)), &len); - - if (SUCCEEDED(hr)) { - len = MultiByteToWideChar(CP_ACP, 0, name, len, desc->wszName, sizeof(desc->wszName)); - desc->wszName[min(len, sizeof(desc->wszName) - 1)] = 0; - desc->dwValidData |= DMUS_OBJ_NAME; - } -} - -static inline void unfo_get_name(IStream *stream, const struct chunk_entry *unfo, - DMUS_OBJECTDESC *desc, BOOL inam) -{ - struct chunk_entry chunk = {.parent = unfo}; - - while (stream_next_chunk(stream, &chunk) == S_OK) - if (chunk.id == DMUS_FOURCC_UNAM_CHUNK || (inam && chunk.id == mmioFOURCC('I','N','A','M'))) - if (stream_chunk_get_wstr(stream, &chunk, desc->wszName, sizeof(desc->wszName)) == S_OK) - desc->dwValidData |= DMUS_OBJ_NAME; -} - -HRESULT dmobj_parsedescriptor(IStream *stream, const struct chunk_entry *riff, - DMUS_OBJECTDESC *desc, DWORD supported) -{ - struct chunk_entry chunk = {.parent = riff}; - HRESULT hr; - - TRACE("Looking for %#lx in %p: %s\n", supported, stream, debugstr_chunk(riff)); - - desc->dwValidData = 0; - desc->dwSize = sizeof(*desc); - - while ((hr = stream_next_chunk(stream, &chunk)) == S_OK) { - switch (chunk.id) { - case DMUS_FOURCC_CATEGORY_CHUNK: - if ((supported & DMUS_OBJ_CATEGORY) && stream_chunk_get_wstr(stream, &chunk, - desc->wszCategory, sizeof(desc->wszCategory)) == S_OK) - desc->dwValidData |= DMUS_OBJ_CATEGORY; - break; - case DMUS_FOURCC_DATE_CHUNK: - if ((supported & DMUS_OBJ_DATE) && stream_chunk_get_data(stream, &chunk, - &desc->ftDate, sizeof(desc->ftDate)) == S_OK) - desc->dwValidData |= DMUS_OBJ_DATE; - break; - case DMUS_FOURCC_FILE_CHUNK: - if ((supported & DMUS_OBJ_FILENAME) && stream_chunk_get_wstr(stream, &chunk, - desc->wszFileName, sizeof(desc->wszFileName)) == S_OK) - desc->dwValidData |= DMUS_OBJ_FILENAME; - break; - case DMUS_FOURCC_GUID_CHUNK: - if ((supported & DMUS_OBJ_OBJECT) && stream_chunk_get_data(stream, &chunk, - &desc->guidObject, sizeof(desc->guidObject)) == S_OK) - desc->dwValidData |= DMUS_OBJ_OBJECT; - break; - case DMUS_FOURCC_NAME_CHUNK: - if ((supported & DMUS_OBJ_NAME) && stream_chunk_get_wstr(stream, &chunk, - desc->wszName, sizeof(desc->wszName)) == S_OK) - desc->dwValidData |= DMUS_OBJ_NAME; - break; - case DMUS_FOURCC_VERSION_CHUNK: - if ((supported & DMUS_OBJ_VERSION) && stream_chunk_get_data(stream, &chunk, - &desc->vVersion, sizeof(desc->vVersion)) == S_OK) - desc->dwValidData |= DMUS_OBJ_VERSION; - break; - case FOURCC_LIST: - if (chunk.type == DMUS_FOURCC_UNFO_LIST && (supported & DMUS_OBJ_NAME)) - unfo_get_name(stream, &chunk, desc, supported & DMUS_OBJ_NAME_INAM); - else if (chunk.type == DMUS_FOURCC_INFO_LIST && (supported & DMUS_OBJ_NAME_INFO)) - info_get_name(stream, &chunk, desc); - break; - } - } - TRACE("Found %#lx\n", desc->dwValidData); - - return hr; -} - -HRESULT dmobj_parsereference(IStream *stream, const struct chunk_entry *list, - IDirectMusicObject **dmobj) -{ - struct chunk_entry chunk = {.parent = list}; - IDirectMusicGetLoader *getloader; - IDirectMusicLoader *loader; - DMUS_OBJECTDESC desc; - DMUS_IO_REFERENCE reference; - HRESULT hr; - - if (FAILED(hr = stream_next_chunk(stream, &chunk))) - return hr; - if (chunk.id != DMUS_FOURCC_REF_CHUNK) - return DMUS_E_UNSUPPORTED_STREAM; - - if (FAILED(hr = stream_chunk_get_data(stream, &chunk, &reference, sizeof(reference)))) { - WARN("Failed to read data of %s\n", debugstr_chunk(&chunk)); - return hr; - } - TRACE("REFERENCE guidClassID %s, dwValidData %#lx\n", debugstr_dmguid(&reference.guidClassID), - reference.dwValidData); - - if (FAILED(hr = dmobj_parsedescriptor(stream, list, &desc, reference.dwValidData))) - return hr; - desc.guidClass = reference.guidClassID; - desc.dwValidData |= DMUS_OBJ_CLASS; - dump_DMUS_OBJECTDESC(&desc); - - if (FAILED(hr = IStream_QueryInterface(stream, &IID_IDirectMusicGetLoader, (void**)&getloader))) - return hr; - hr = IDirectMusicGetLoader_GetLoader(getloader, &loader); - IDirectMusicGetLoader_Release(getloader); - if (FAILED(hr)) - return hr; - - hr = IDirectMusicLoader_GetObject(loader, &desc, &IID_IDirectMusicObject, (void**)dmobj); - IDirectMusicLoader_Release(loader); - - return hr; -} - -/* Generic IPersistStream methods */ -static inline struct dmobject *impl_from_IPersistStream(IPersistStream *iface) -{ - return CONTAINING_RECORD(iface, struct dmobject, IPersistStream_iface); -} - -HRESULT WINAPI dmobj_IPersistStream_QueryInterface(IPersistStream *iface, REFIID riid, - void **ret_iface) -{ - struct dmobject *This = impl_from_IPersistStream(iface); - return IUnknown_QueryInterface(This->outer_unk, riid, ret_iface); -} - -ULONG WINAPI dmobj_IPersistStream_AddRef(IPersistStream *iface) -{ - struct dmobject *This = impl_from_IPersistStream(iface); - return IUnknown_AddRef(This->outer_unk); -} - -ULONG WINAPI dmobj_IPersistStream_Release(IPersistStream *iface) -{ - struct dmobject *This = impl_from_IPersistStream(iface); - return IUnknown_Release(This->outer_unk); -} - -HRESULT WINAPI dmobj_IPersistStream_GetClassID(IPersistStream *iface, CLSID *class) -{ - struct dmobject *This = impl_from_IPersistStream(iface); - - TRACE("(%p, %p)\n", This, class); - - if (!class) - return E_POINTER; - - *class = This->desc.guidClass; - - return S_OK; -} - -/* IPersistStream methods not implemented in native */ -HRESULT WINAPI unimpl_IPersistStream_GetClassID(IPersistStream *iface, CLSID *class) -{ - TRACE("(%p, %p): method not implemented\n", iface, class); - return E_NOTIMPL; -} - -HRESULT WINAPI unimpl_IPersistStream_IsDirty(IPersistStream *iface) -{ - TRACE("(%p): method not implemented, always returning S_FALSE\n", iface); - return S_FALSE; -} - -HRESULT WINAPI unimpl_IPersistStream_Save(IPersistStream *iface, IStream *stream, - BOOL clear_dirty) -{ - TRACE("(%p, %p, %d): method not implemented\n", iface, stream, clear_dirty); - return E_NOTIMPL; -} - -HRESULT WINAPI unimpl_IPersistStream_GetSizeMax(IPersistStream *iface, ULARGE_INTEGER *size) -{ - TRACE("(%p, %p): method not implemented\n", iface, size); - return E_NOTIMPL; -} - - -void dmobject_init(struct dmobject *dmobj, const GUID *class, IUnknown *outer_unk) -{ - dmobj->outer_unk = outer_unk; - dmobj->desc.dwSize = sizeof(dmobj->desc); - dmobj->desc.dwValidData = DMUS_OBJ_CLASS; - dmobj->desc.guidClass = *class; -} diff --git a/dlls/dmloader/dmobject.h b/dlls/dmloader/dmobject.h deleted file mode 100644 index 772be015c80..00000000000 --- a/dlls/dmloader/dmobject.h +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Base IDirectMusicObject Implementation - * Keep in sync with the master in dlls/dmusic/dmobject.h - * - * Copyright (C) 2014 Michael Stefaniuc - * - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * 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 - */ - -#include "wine/debug.h" - -/* RIFF stream parsing */ -struct chunk_entry; -struct chunk_entry { - FOURCC id; - DWORD size; - FOURCC type; /* valid only for LIST and RIFF chunks */ - ULARGE_INTEGER offset; /* chunk offset from start of stream */ - const struct chunk_entry *parent; /* enclosing RIFF or LIST chunk */ -}; - -HRESULT stream_get_chunk(IStream *stream, struct chunk_entry *chunk); -HRESULT stream_next_chunk(IStream *stream, struct chunk_entry *chunk); -HRESULT stream_skip_chunk(IStream *stream, const struct chunk_entry *chunk); - -HRESULT stream_chunk_get_array(IStream *stream, const struct chunk_entry *chunk, void **array, - unsigned int *count, DWORD elem_size); -HRESULT stream_chunk_get_data(IStream *stream, const struct chunk_entry *chunk, void *data, - ULONG size); -HRESULT stream_chunk_get_wstr(IStream *stream, const struct chunk_entry *chunk, WCHAR *str, - ULONG size); - -static inline HRESULT stream_reset_chunk_data(IStream *stream, const struct chunk_entry *chunk) -{ - LARGE_INTEGER offset; - - offset.QuadPart = chunk->offset.QuadPart + sizeof(FOURCC) + sizeof(DWORD); - if (chunk->id == FOURCC_RIFF || chunk->id == FOURCC_LIST) - offset.QuadPart += sizeof(FOURCC); - - return IStream_Seek(stream, offset, STREAM_SEEK_SET, NULL); -} - -static inline HRESULT stream_reset_chunk_start(IStream *stream, const struct chunk_entry *chunk) -{ - LARGE_INTEGER offset; - - offset.QuadPart = chunk->offset.QuadPart; - - return IStream_Seek(stream, offset, STREAM_SEEK_SET, NULL); -} - - -/* IDirectMusicObject base object */ -struct dmobject { - IDirectMusicObject IDirectMusicObject_iface; - IPersistStream IPersistStream_iface; - IUnknown *outer_unk; - DMUS_OBJECTDESC desc; -}; - -void dmobject_init(struct dmobject *dmobj, const GUID *class, IUnknown *outer_unk); - -/* Generic IDirectMusicObject methods */ -HRESULT WINAPI dmobj_IDirectMusicObject_QueryInterface(IDirectMusicObject *iface, REFIID riid, - void **ret_iface); -ULONG WINAPI dmobj_IDirectMusicObject_AddRef(IDirectMusicObject *iface); -ULONG WINAPI dmobj_IDirectMusicObject_Release(IDirectMusicObject *iface); -HRESULT WINAPI dmobj_IDirectMusicObject_GetDescriptor(IDirectMusicObject *iface, - DMUS_OBJECTDESC *desc); -HRESULT WINAPI dmobj_IDirectMusicObject_SetDescriptor(IDirectMusicObject *iface, - DMUS_OBJECTDESC *desc); - -/* Helper for IDirectMusicObject::ParseDescriptor */ -HRESULT dmobj_parsedescriptor(IStream *stream, const struct chunk_entry *riff, - DMUS_OBJECTDESC *desc, DWORD supported); -/* Additional supported flags for dmobj_parsedescriptor. - DMUS_OBJ_NAME is 'UNAM' chunk in UNFO list */ -#define DMUS_OBJ_NAME_INAM 0x1000 /* 'INAM' chunk in UNFO list */ -#define DMUS_OBJ_NAME_INFO 0x2000 /* 'INAM' chunk in INFO list */ - -/* 'DMRF' (reference list) helper */ -HRESULT dmobj_parsereference(IStream *stream, const struct chunk_entry *list, - IDirectMusicObject **dmobj); - -/* Generic IPersistStream methods */ -HRESULT WINAPI dmobj_IPersistStream_QueryInterface(IPersistStream *iface, REFIID riid, - void **ret_iface); -ULONG WINAPI dmobj_IPersistStream_AddRef(IPersistStream *iface); -ULONG WINAPI dmobj_IPersistStream_Release(IPersistStream *iface); -HRESULT WINAPI dmobj_IPersistStream_GetClassID(IPersistStream *iface, CLSID *class); - -/* IPersistStream methods not implemented in native */ -HRESULT WINAPI unimpl_IPersistStream_GetClassID(IPersistStream *iface, - CLSID *class); -HRESULT WINAPI unimpl_IPersistStream_IsDirty(IPersistStream *iface); -HRESULT WINAPI unimpl_IPersistStream_Save(IPersistStream *iface, IStream *stream, - BOOL clear_dirty); -HRESULT WINAPI unimpl_IPersistStream_GetSizeMax(IPersistStream *iface, - ULARGE_INTEGER *size); - -/* Debugging helpers */ -const char *debugstr_chunk(const struct chunk_entry *chunk); -const char *debugstr_dmguid(const GUID *id); -void dump_DMUS_OBJECTDESC(DMUS_OBJECTDESC *desc); - -static inline const char *debugstr_fourcc(DWORD fourcc) -{ - if (!fourcc) return "''"; - return wine_dbg_sprintf("'%c%c%c%c'", (char)(fourcc), (char)(fourcc >> 8), - (char)(fourcc >> 16), (char)(fourcc >> 24)); -}
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dmscript/dmscript_main.c | 22 ---------------------- dlls/dmscript/dmscript_private.h | 7 ------- dlls/dmscript/script.c | 2 -- dlls/dmscript/scripttrack.c | 2 -- 4 files changed, 33 deletions(-)
diff --git a/dlls/dmscript/dmscript_main.c b/dlls/dmscript/dmscript_main.c index f6785176aec..db5f163b829 100644 --- a/dlls/dmscript/dmscript_main.c +++ b/dlls/dmscript/dmscript_main.c @@ -38,8 +38,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(dmscript);
-LONG DMSCRIPT_refCount = 0; - typedef struct { IClassFactory IClassFactory_iface; HRESULT (*fnCreateInstance)(REFIID riid, void **ppv, IUnknown *pUnkOuter); @@ -82,15 +80,11 @@ static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID r
static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface) { - DMSCRIPT_LockModule(); - return 2; /* non-heap based object */ }
static ULONG WINAPI ClassFactory_Release(IClassFactory *iface) { - DMSCRIPT_UnlockModule(); - return 1; /* non-heap based object */ }
@@ -107,12 +101,6 @@ static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock) { TRACE("(%d)\n", dolock); - - if (dolock) - DMSCRIPT_LockModule(); - else - DMSCRIPT_UnlockModule(); - return S_OK; }
@@ -140,16 +128,6 @@ static IClassFactoryImpl ScriptAutoImplAudioPath_CF = {{&classfactory_vtbl}, create_unimpl_instance}; static IClassFactoryImpl ScriptAutoImplSong_CF = {{&classfactory_vtbl}, create_unimpl_instance};
-/****************************************************************** - * DllCanUnloadNow (DMSCRIPT.@) - * - * - */ -HRESULT WINAPI DllCanUnloadNow(void) -{ - return DMSCRIPT_refCount != 0 ? S_FALSE : S_OK; -} -
/****************************************************************** * DllGetClassObject (DMSCRIPT.@) diff --git a/dlls/dmscript/dmscript_private.h b/dlls/dmscript/dmscript_private.h index 90808d59f00..f715c083523 100644 --- a/dlls/dmscript/dmscript_private.h +++ b/dlls/dmscript/dmscript_private.h @@ -48,13 +48,6 @@ extern HRESULT DMUSIC_CreateDirectMusicScriptImpl(REFIID riid, void **ppobj, IUn
extern HRESULT DMUSIC_CreateDirectMusicScriptTrack(REFIID riid, void **ppobj, IUnknown *pUnkOuter);
-/********************************************************************** - * Dll lifetime tracking declaration for dmscript.dll - */ -extern LONG DMSCRIPT_refCount; -static inline void DMSCRIPT_LockModule(void) { InterlockedIncrement( &DMSCRIPT_refCount ); } -static inline void DMSCRIPT_UnlockModule(void) { InterlockedDecrement( &DMSCRIPT_refCount ); } - /***************************************************************************** * Misc. */ diff --git a/dlls/dmscript/script.c b/dlls/dmscript/script.c index 375eebf69aa..dbfcdca7d83 100644 --- a/dlls/dmscript/script.c +++ b/dlls/dmscript/script.c @@ -94,7 +94,6 @@ static ULONG WINAPI IDirectMusicScriptImpl_Release(IDirectMusicScript *iface) HeapFree(GetProcessHeap(), 0, This->pwzLanguage); HeapFree(GetProcessHeap(), 0, This->pwzSource); HeapFree(GetProcessHeap(), 0, This); - DMSCRIPT_UnlockModule(); }
return ref; @@ -508,7 +507,6 @@ HRESULT DMUSIC_CreateDirectMusicScriptImpl(REFIID lpcGUID, void **ppobj, IUnknow obj->dmobj.IDirectMusicObject_iface.lpVtbl = &dmobject_vtbl; obj->dmobj.IPersistStream_iface.lpVtbl = &persiststream_vtbl;
- DMSCRIPT_LockModule(); hr = IDirectMusicScript_QueryInterface(&obj->IDirectMusicScript_iface, lpcGUID, ppobj); IDirectMusicScript_Release(&obj->IDirectMusicScript_iface);
diff --git a/dlls/dmscript/scripttrack.c b/dlls/dmscript/scripttrack.c index fbe454c09e5..92dd6d15ec6 100644 --- a/dlls/dmscript/scripttrack.c +++ b/dlls/dmscript/scripttrack.c @@ -86,7 +86,6 @@ static ULONG WINAPI script_track_Release(IDirectMusicTrack8 *iface)
if (!ref) { HeapFree(GetProcessHeap(), 0, This); - DMSCRIPT_UnlockModule(); }
return ref; @@ -338,7 +337,6 @@ HRESULT DMUSIC_CreateDirectMusicScriptTrack(REFIID riid, void **ret_iface, IUnkn track->desc.guidClass = CLSID_DirectMusicScriptTrack; track->ref = 1;
- DMSCRIPT_LockModule(); hr = IDirectMusicTrack8_QueryInterface(&track->IDirectMusicTrack8_iface, riid, ret_iface); IDirectMusicTrack8_Release(&track->IDirectMusicTrack8_iface);
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dmscript/dmobject.c | 7 +++---- dlls/dmscript/script.c | 27 ++++++++++++--------------- dlls/dmscript/scripttrack.c | 9 ++------- 3 files changed, 17 insertions(+), 26 deletions(-)
diff --git a/dlls/dmscript/dmobject.c b/dlls/dmscript/dmobject.c index b526b23d031..07d887a376c 100644 --- a/dlls/dmscript/dmobject.c +++ b/dlls/dmscript/dmobject.c @@ -28,7 +28,6 @@ #include "dmusics.h" #include "dmobject.h" #include "wine/debug.h" -#include "wine/heap.h"
WINE_DEFAULT_DEBUG_CHANNEL(dmobj); WINE_DECLARE_DEBUG_CHANNEL(dmfile); @@ -375,7 +374,7 @@ HRESULT stream_next_chunk(IStream *stream, struct chunk_entry *chunk) /* Reads chunk data of the form: DWORD - size of array element element[] - Array of elements - The caller needs to heap_free() the array. + The caller needs to free() the array. */ HRESULT stream_chunk_get_array(IStream *stream, const struct chunk_entry *chunk, void **array, unsigned int *count, DWORD elem_size) @@ -400,10 +399,10 @@ HRESULT stream_chunk_get_array(IStream *stream, const struct chunk_entry *chunk,
*count = (chunk->size - sizeof(DWORD)) / elem_size; size = *count * elem_size; - if (!(*array = heap_alloc(size))) + if (!(*array = malloc(size))) return E_OUTOFMEMORY; if (FAILED(hr = stream_read(stream, *array, size))) { - heap_free(*array); + free(*array); *array = NULL; return hr; } diff --git a/dlls/dmscript/script.c b/dlls/dmscript/script.c index dbfcdca7d83..01d4bcd0290 100644 --- a/dlls/dmscript/script.c +++ b/dlls/dmscript/script.c @@ -89,11 +89,11 @@ static ULONG WINAPI IDirectMusicScriptImpl_Release(IDirectMusicScript *iface) TRACE("(%p) ref=%ld\n", This, ref);
if (!ref) { - HeapFree(GetProcessHeap(), 0, This->pHeader); - HeapFree(GetProcessHeap(), 0, This->pVersion); - HeapFree(GetProcessHeap(), 0, This->pwzLanguage); - HeapFree(GetProcessHeap(), 0, This->pwzSource); - HeapFree(GetProcessHeap(), 0, This); + free(This->pHeader); + free(This->pVersion); + free(This->pwzLanguage); + free(This->pwzSource); + free(This); }
return ref; @@ -275,36 +275,36 @@ static HRESULT WINAPI IPersistStreamImpl_Load(IPersistStream *iface, IStream *pS switch (Chunk.fccID) { case DMUS_FOURCC_SCRIPT_CHUNK: { TRACE_(dmfile)(": script header chunk\n"); - This->pHeader = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, Chunk.dwSize); + This->pHeader = calloc(1, Chunk.dwSize); IStream_Read (pStm, This->pHeader, Chunk.dwSize, NULL); break; } case DMUS_FOURCC_SCRIPTVERSION_CHUNK: { TRACE_(dmfile)(": script version chunk\n"); - This->pVersion = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, Chunk.dwSize); + This->pVersion = calloc(1, Chunk.dwSize); IStream_Read (pStm, This->pVersion, Chunk.dwSize, NULL); TRACE_(dmfile)("version: 0x%08lx.0x%08lx\n", This->pVersion->dwVersionMS, This->pVersion->dwVersionLS); break; } case DMUS_FOURCC_SCRIPTLANGUAGE_CHUNK: { TRACE_(dmfile)(": script language chunk\n"); - This->pwzLanguage = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, Chunk.dwSize); + This->pwzLanguage = calloc(1, Chunk.dwSize); IStream_Read (pStm, This->pwzLanguage, Chunk.dwSize, NULL); TRACE_(dmfile)("using language: %s\n", debugstr_w(This->pwzLanguage)); break; } case DMUS_FOURCC_SCRIPTSOURCE_CHUNK: { TRACE_(dmfile)(": script source chunk\n"); - This->pwzSource = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, Chunk.dwSize); + This->pwzSource = calloc(1, Chunk.dwSize); IStream_Read (pStm, This->pwzSource, Chunk.dwSize, NULL); if (TRACE_ON(dmscript)) { int count = WideCharToMultiByte(CP_ACP, 0, This->pwzSource, -1, NULL, 0, NULL, NULL); - LPSTR str = HeapAlloc(GetProcessHeap (), 0, count); + LPSTR str = malloc(count); WideCharToMultiByte(CP_ACP, 0, This->pwzSource, -1, str, count, NULL, NULL); str[count-1] = '\n'; TRACE("source:\n"); fwrite( str, 1, count, stderr ); - HeapFree(GetProcessHeap(), 0, str); + free(str); } break; } @@ -497,10 +497,7 @@ HRESULT DMUSIC_CreateDirectMusicScriptImpl(REFIID lpcGUID, void **ppobj, IUnknow if (pUnkOuter) return CLASS_E_NOAGGREGATION;
- obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicScriptImpl)); - if (!obj) - return E_OUTOFMEMORY; - + if (!(obj = calloc(1, sizeof(*obj)))) return E_OUTOFMEMORY; obj->IDirectMusicScript_iface.lpVtbl = &dmscript_vtbl; obj->ref = 1; dmobject_init(&obj->dmobj, &CLSID_DirectMusicScript, (IUnknown*)&obj->IDirectMusicScript_iface); diff --git a/dlls/dmscript/scripttrack.c b/dlls/dmscript/scripttrack.c index 92dd6d15ec6..74d45afacbe 100644 --- a/dlls/dmscript/scripttrack.c +++ b/dlls/dmscript/scripttrack.c @@ -84,9 +84,7 @@ static ULONG WINAPI script_track_Release(IDirectMusicTrack8 *iface)
TRACE("(%p) ref=%ld\n", This, ref);
- if (!ref) { - HeapFree(GetProcessHeap(), 0, This); - } + if (!ref) free(This);
return ref; } @@ -326,10 +324,7 @@ HRESULT DMUSIC_CreateDirectMusicScriptTrack(REFIID riid, void **ret_iface, IUnkn if (pUnkOuter) return CLASS_E_NOAGGREGATION;
- track = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*track)); - if (!track) - return E_OUTOFMEMORY; - + if (!(track = calloc(1, sizeof(*track)))) return E_OUTOFMEMORY; track->IDirectMusicTrack8_iface.lpVtbl = &dmtrack8_vtbl; track->IPersistStream_iface.lpVtbl = &persist_vtbl; track->desc.dwSize = sizeof(track->desc);
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dmscript/Makefile.in | 1 + dlls/dmscript/dmobject.c | 732 -------------------------------------- dlls/dmscript/dmobject.h | 124 ------- 3 files changed, 1 insertion(+), 856 deletions(-) delete mode 100644 dlls/dmscript/dmobject.c delete mode 100644 dlls/dmscript/dmobject.h
diff --git a/dlls/dmscript/Makefile.in b/dlls/dmscript/Makefile.in index 55107e116c9..9eac24c2d86 100644 --- a/dlls/dmscript/Makefile.in +++ b/dlls/dmscript/Makefile.in @@ -1,5 +1,6 @@ MODULE = dmscript.dll IMPORTS = dxguid uuid ole32 advapi32 +PARENTSRC = ../dmusic
C_SRCS = \ dmobject.c \ diff --git a/dlls/dmscript/dmobject.c b/dlls/dmscript/dmobject.c deleted file mode 100644 index 07d887a376c..00000000000 --- a/dlls/dmscript/dmobject.c +++ /dev/null @@ -1,732 +0,0 @@ -/* - * Base IDirectMusicObject Implementation - * Keep in sync with the master in dlls/dmusic/dmobject.c - * - * Copyright (C) 2003-2004 Rok Mandeljc - * Copyright (C) 2014 Michael Stefaniuc - * - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * 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 - */ - -#define COBJMACROS -#include <assert.h> -#include "objbase.h" -#include "dmusici.h" -#include "dmusicf.h" -#include "dmusics.h" -#include "dmobject.h" -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(dmobj); -WINE_DECLARE_DEBUG_CHANNEL(dmfile); - -/* Debugging helpers */ -const char *debugstr_dmguid(const GUID *id) { - unsigned int i; -#define X(guid) { &guid, #guid } - static const struct { - const GUID *guid; - const char *name; - } guids[] = { - /* CLSIDs */ - X(CLSID_AudioVBScript), - X(CLSID_DirectMusic), - X(CLSID_DirectMusicAudioPathConfig), - X(CLSID_DirectMusicAuditionTrack), - X(CLSID_DirectMusicBand), - X(CLSID_DirectMusicBandTrack), - X(CLSID_DirectMusicChordMapTrack), - X(CLSID_DirectMusicChordMap), - X(CLSID_DirectMusicChordTrack), - X(CLSID_DirectMusicCollection), - X(CLSID_DirectMusicCommandTrack), - X(CLSID_DirectMusicComposer), - X(CLSID_DirectMusicContainer), - X(CLSID_DirectMusicGraph), - X(CLSID_DirectMusicLoader), - X(CLSID_DirectMusicLyricsTrack), - X(CLSID_DirectMusicMarkerTrack), - X(CLSID_DirectMusicMelodyFormulationTrack), - X(CLSID_DirectMusicMotifTrack), - X(CLSID_DirectMusicMuteTrack), - X(CLSID_DirectMusicParamControlTrack), - X(CLSID_DirectMusicPatternTrack), - X(CLSID_DirectMusicPerformance), - X(CLSID_DirectMusicScript), - X(CLSID_DirectMusicScriptAutoImpSegment), - X(CLSID_DirectMusicScriptAutoImpPerformance), - X(CLSID_DirectMusicScriptAutoImpSegmentState), - X(CLSID_DirectMusicScriptAutoImpAudioPathConfig), - X(CLSID_DirectMusicScriptAutoImpAudioPath), - X(CLSID_DirectMusicScriptAutoImpSong), - X(CLSID_DirectMusicScriptSourceCodeLoader), - X(CLSID_DirectMusicScriptTrack), - X(CLSID_DirectMusicSection), - X(CLSID_DirectMusicSegment), - X(CLSID_DirectMusicSegmentState), - X(CLSID_DirectMusicSegmentTriggerTrack), - X(CLSID_DirectMusicSegTriggerTrack), - X(CLSID_DirectMusicSeqTrack), - X(CLSID_DirectMusicSignPostTrack), - X(CLSID_DirectMusicSong), - X(CLSID_DirectMusicStyle), - X(CLSID_DirectMusicStyleTrack), - X(CLSID_DirectMusicSynth), - X(CLSID_DirectMusicSynthSink), - X(CLSID_DirectMusicSysExTrack), - X(CLSID_DirectMusicTemplate), - X(CLSID_DirectMusicTempoTrack), - X(CLSID_DirectMusicTimeSigTrack), - X(CLSID_DirectMusicWaveTrack), - X(CLSID_DirectSoundWave), - /* IIDs */ - X(IID_IDirectMusic), - X(IID_IDirectMusic2), - X(IID_IDirectMusic8), - X(IID_IDirectMusicAudioPath), - X(IID_IDirectMusicBand), - X(IID_IDirectMusicBuffer), - X(IID_IDirectMusicChordMap), - X(IID_IDirectMusicCollection), - X(IID_IDirectMusicComposer), - X(IID_IDirectMusicContainer), - X(IID_IDirectMusicDownload), - X(IID_IDirectMusicDownloadedInstrument), - X(IID_IDirectMusicGetLoader), - X(IID_IDirectMusicGraph), - X(IID_IDirectMusicInstrument), - X(IID_IDirectMusicLoader), - X(IID_IDirectMusicLoader8), - X(IID_IDirectMusicObject), - X(IID_IDirectMusicPatternTrack), - X(IID_IDirectMusicPerformance), - X(IID_IDirectMusicPerformance2), - X(IID_IDirectMusicPerformance8), - X(IID_IDirectMusicPort), - X(IID_IDirectMusicPortDownload), - X(IID_IDirectMusicScript), - X(IID_IDirectMusicSegment), - X(IID_IDirectMusicSegment2), - X(IID_IDirectMusicSegment8), - X(IID_IDirectMusicSegmentState), - X(IID_IDirectMusicSegmentState8), - X(IID_IDirectMusicStyle), - X(IID_IDirectMusicStyle8), - X(IID_IDirectMusicSynth), - X(IID_IDirectMusicSynth8), - X(IID_IDirectMusicSynthSink), - X(IID_IDirectMusicThru), - X(IID_IDirectMusicTool), - X(IID_IDirectMusicTool8), - X(IID_IDirectMusicTrack), - X(IID_IDirectMusicTrack8), - X(IID_IUnknown), - X(IID_IPersistStream), - X(IID_IStream), - X(IID_IClassFactory), - /* GUIDs */ - X(GUID_DirectMusicAllTypes), - X(GUID_NOTIFICATION_CHORD), - X(GUID_NOTIFICATION_COMMAND), - X(GUID_NOTIFICATION_MEASUREANDBEAT), - X(GUID_NOTIFICATION_PERFORMANCE), - X(GUID_NOTIFICATION_RECOMPOSE), - X(GUID_NOTIFICATION_SEGMENT), - X(GUID_BandParam), - X(GUID_ChordParam), - X(GUID_CommandParam), - X(GUID_CommandParam2), - X(GUID_CommandParamNext), - X(GUID_IDirectMusicBand), - X(GUID_IDirectMusicChordMap), - X(GUID_IDirectMusicStyle), - X(GUID_MuteParam), - X(GUID_Play_Marker), - X(GUID_RhythmParam), - X(GUID_TempoParam), - X(GUID_TimeSignature), - X(GUID_Valid_Start_Time), - X(GUID_Clear_All_Bands), - X(GUID_ConnectToDLSCollection), - X(GUID_Disable_Auto_Download), - X(GUID_DisableTempo), - X(GUID_DisableTimeSig), - X(GUID_Download), - X(GUID_DownloadToAudioPath), - X(GUID_Enable_Auto_Download), - X(GUID_EnableTempo), - X(GUID_EnableTimeSig), - X(GUID_IgnoreBankSelectForGM), - X(GUID_SeedVariations), - X(GUID_StandardMIDIFile), - X(GUID_Unload), - X(GUID_UnloadFromAudioPath), - X(GUID_Variations), - X(GUID_PerfMasterTempo), - X(GUID_PerfMasterVolume), - X(GUID_PerfMasterGrooveLevel), - X(GUID_PerfAutoDownload), - X(GUID_DefaultGMCollection), - X(GUID_Synth_Default), - X(GUID_Buffer_Reverb), - X(GUID_Buffer_EnvReverb), - X(GUID_Buffer_Stereo), - X(GUID_Buffer_3D_Dry), - X(GUID_Buffer_Mono), - X(GUID_DMUS_PROP_GM_Hardware), - X(GUID_DMUS_PROP_GS_Capable), - X(GUID_DMUS_PROP_GS_Hardware), - X(GUID_DMUS_PROP_DLS1), - X(GUID_DMUS_PROP_DLS2), - X(GUID_DMUS_PROP_Effects), - X(GUID_DMUS_PROP_INSTRUMENT2), - X(GUID_DMUS_PROP_LegacyCaps), - X(GUID_DMUS_PROP_MemorySize), - X(GUID_DMUS_PROP_SampleMemorySize), - X(GUID_DMUS_PROP_SamplePlaybackRate), - X(GUID_DMUS_PROP_SetSynthSink), - X(GUID_DMUS_PROP_SinkUsesDSound), - X(GUID_DMUS_PROP_SynthSink_DSOUND), - X(GUID_DMUS_PROP_SynthSink_WAVE), - X(GUID_DMUS_PROP_Volume), - X(GUID_DMUS_PROP_WavesReverb), - X(GUID_DMUS_PROP_WriteLatency), - X(GUID_DMUS_PROP_WritePeriod), - X(GUID_DMUS_PROP_XG_Capable), - X(GUID_DMUS_PROP_XG_Hardware) - }; -#undef X - - if (!id) - return "(null)"; - - for (i = 0; i < ARRAY_SIZE(guids); i++) - if (IsEqualGUID(id, guids[i].guid)) - return guids[i].name; - - return debugstr_guid(id); -} - -void dump_DMUS_OBJECTDESC(DMUS_OBJECTDESC *desc) -{ - if (!desc || !TRACE_ON(dmfile)) - return; - - TRACE_(dmfile)("DMUS_OBJECTDESC (%p):", desc); - TRACE_(dmfile)(" - dwSize = %lu\n", desc->dwSize); - -#define X(flag) if (desc->dwValidData & flag) TRACE_(dmfile)(#flag " ") - TRACE_(dmfile)(" - dwValidData = %#08lx ( ", desc->dwValidData); - X(DMUS_OBJ_OBJECT); - X(DMUS_OBJ_CLASS); - X(DMUS_OBJ_NAME); - X(DMUS_OBJ_CATEGORY); - X(DMUS_OBJ_FILENAME); - X(DMUS_OBJ_FULLPATH); - X(DMUS_OBJ_URL); - X(DMUS_OBJ_VERSION); - X(DMUS_OBJ_DATE); - X(DMUS_OBJ_LOADED); - X(DMUS_OBJ_MEMORY); - X(DMUS_OBJ_STREAM); - TRACE_(dmfile)(")\n"); -#undef X - - if (desc->dwValidData & DMUS_OBJ_CLASS) - TRACE_(dmfile)(" - guidClass = %s\n", debugstr_dmguid(&desc->guidClass)); - if (desc->dwValidData & DMUS_OBJ_OBJECT) - TRACE_(dmfile)(" - guidObject = %s\n", debugstr_guid(&desc->guidObject)); - - if (desc->dwValidData & DMUS_OBJ_DATE) { - SYSTEMTIME time; - FileTimeToSystemTime(&desc->ftDate, &time); - TRACE_(dmfile)(" - ftDate = '%04u-%02u-%02u %02u:%02u:%02u'\n", - time.wYear, time.wMonth, time.wDay, time.wHour, time.wMinute, time.wSecond); - } - if (desc->dwValidData & DMUS_OBJ_VERSION) - TRACE_(dmfile)(" - vVersion = '%u,%u,%u,%u'\n", - HIWORD(desc->vVersion.dwVersionMS), LOWORD(desc->vVersion.dwVersionMS), - HIWORD(desc->vVersion.dwVersionLS), LOWORD(desc->vVersion.dwVersionLS)); - if (desc->dwValidData & DMUS_OBJ_NAME) - TRACE_(dmfile)(" - wszName = %s\n", debugstr_w(desc->wszName)); - if (desc->dwValidData & DMUS_OBJ_CATEGORY) - TRACE_(dmfile)(" - wszCategory = %s\n", debugstr_w(desc->wszCategory)); - if (desc->dwValidData & DMUS_OBJ_FILENAME) - TRACE_(dmfile)(" - wszFileName = %s\n", debugstr_w(desc->wszFileName)); - if (desc->dwValidData & DMUS_OBJ_MEMORY) - TRACE_(dmfile)(" - llMemLength = 0x%s - pbMemData = %p\n", - wine_dbgstr_longlong(desc->llMemLength), desc->pbMemData); - if (desc->dwValidData & DMUS_OBJ_STREAM) - TRACE_(dmfile)(" - pStream = %p\n", desc->pStream); -} - - -/* RIFF format parsing */ -#define CHUNK_HDR_SIZE (sizeof(FOURCC) + sizeof(DWORD)) - -const char *debugstr_chunk(const struct chunk_entry *chunk) -{ - const char *type = ""; - - if (!chunk) - return "(null)"; - if (chunk->id == FOURCC_RIFF || chunk->id == FOURCC_LIST) - type = wine_dbg_sprintf("type %s, ", debugstr_fourcc(chunk->type)); - return wine_dbg_sprintf("%s chunk, %ssize %lu", debugstr_fourcc(chunk->id), type, chunk->size); -} - -static HRESULT stream_read(IStream *stream, void *data, ULONG size) -{ - ULONG read; - HRESULT hr; - - hr = IStream_Read(stream, data, size, &read); - if (FAILED(hr)) - TRACE_(dmfile)("IStream_Read failed: %#lx\n", hr); - else if (!read && read < size) { - /* All or nothing: Handle a partial read due to end of stream as an error */ - TRACE_(dmfile)("Short read: %lu < %lu\n", read, size); - return E_FAIL; - } - - return hr; -} - -HRESULT stream_get_chunk(IStream *stream, struct chunk_entry *chunk) -{ - static const LARGE_INTEGER zero; - ULONGLONG ck_end = 0, p_end = 0; - HRESULT hr; - - hr = IStream_Seek(stream, zero, STREAM_SEEK_CUR, &chunk->offset); - if (FAILED(hr)) - return hr; - assert(!(chunk->offset.QuadPart & 1)); - if (chunk->parent) { - p_end = chunk->parent->offset.QuadPart + CHUNK_HDR_SIZE + ((chunk->parent->size + 1) & ~1); - if (chunk->offset.QuadPart == p_end) - return S_FALSE; - ck_end = chunk->offset.QuadPart + CHUNK_HDR_SIZE; - if (ck_end > p_end) { - WARN_(dmfile)("No space for sub-chunk header in parent chunk: ends at offset %s > %s\n", - wine_dbgstr_longlong(ck_end), wine_dbgstr_longlong(p_end)); - return E_FAIL; - } - } - - hr = stream_read(stream, chunk, CHUNK_HDR_SIZE); - if (hr != S_OK) - return hr; - if (chunk->parent) { - ck_end += (chunk->size + 1) & ~1; - if (ck_end > p_end) { - WARN_(dmfile)("No space for sub-chunk data in parent chunk: ends at offset %s > %s\n", - wine_dbgstr_longlong(ck_end), wine_dbgstr_longlong(p_end)); - return E_FAIL; - } - } - - if (chunk->id == FOURCC_LIST || chunk->id == FOURCC_RIFF) { - hr = stream_read(stream, &chunk->type, sizeof(FOURCC)); - if (hr != S_OK) - return hr != S_FALSE ? hr : E_FAIL; - } - - TRACE_(dmfile)("Returning %s\n", debugstr_chunk(chunk)); - - return S_OK; -} - -HRESULT stream_skip_chunk(IStream *stream, const struct chunk_entry *chunk) -{ - LARGE_INTEGER end; - - end.QuadPart = (chunk->offset.QuadPart + CHUNK_HDR_SIZE + chunk->size + 1) & ~(ULONGLONG)1; - - return IStream_Seek(stream, end, STREAM_SEEK_SET, NULL); -} - -HRESULT stream_next_chunk(IStream *stream, struct chunk_entry *chunk) -{ - HRESULT hr; - - if (chunk->id) { - hr = stream_skip_chunk(stream, chunk); - if (FAILED(hr)) - return hr; - } - - return stream_get_chunk(stream, chunk); -} - -/* Reads chunk data of the form: - DWORD - size of array element - element[] - Array of elements - The caller needs to free() the array. -*/ -HRESULT stream_chunk_get_array(IStream *stream, const struct chunk_entry *chunk, void **array, - unsigned int *count, DWORD elem_size) -{ - DWORD size; - HRESULT hr; - - *array = NULL; - *count = 0; - - if (chunk->size < sizeof(DWORD)) { - WARN_(dmfile)("%s: Too short to read element size\n", debugstr_chunk(chunk)); - return E_FAIL; - } - if (FAILED(hr = stream_read(stream, &size, sizeof(DWORD)))) - return hr; - if (size != elem_size) { - WARN_(dmfile)("%s: Array element size mismatch: got %lu, expected %lu\n", - debugstr_chunk(chunk), size, elem_size); - return DMUS_E_UNSUPPORTED_STREAM; - } - - *count = (chunk->size - sizeof(DWORD)) / elem_size; - size = *count * elem_size; - if (!(*array = malloc(size))) - return E_OUTOFMEMORY; - if (FAILED(hr = stream_read(stream, *array, size))) { - free(*array); - *array = NULL; - return hr; - } - - if (chunk->size > size + sizeof(DWORD)) { - WARN_(dmfile)("%s: Extraneous data at end of array\n", debugstr_chunk(chunk)); - stream_skip_chunk(stream, chunk); - return S_FALSE; - } - return S_OK; -} - -HRESULT stream_chunk_get_data(IStream *stream, const struct chunk_entry *chunk, void *data, - ULONG size) -{ - if (chunk->size != size) { - WARN_(dmfile)("Chunk %s (size %lu, offset %s) doesn't contains the expected data size %lu\n", - debugstr_fourcc(chunk->id), chunk->size, - wine_dbgstr_longlong(chunk->offset.QuadPart), size); - return E_FAIL; - } - return stream_read(stream, data, size); -} - -HRESULT stream_chunk_get_wstr(IStream *stream, const struct chunk_entry *chunk, WCHAR *str, - ULONG size) -{ - ULONG len; - HRESULT hr; - - hr = IStream_Read(stream, str, min(chunk->size, size), &len); - if (FAILED(hr)) - return hr; - - /* Don't assume the string is properly zero terminated */ - str[min(len, size - 1)] = 0; - - if (len < chunk->size) - return S_FALSE; - return S_OK; -} - - - -/* Generic IDirectMusicObject methods */ -static inline struct dmobject *impl_from_IDirectMusicObject(IDirectMusicObject *iface) -{ - return CONTAINING_RECORD(iface, struct dmobject, IDirectMusicObject_iface); -} - -HRESULT WINAPI dmobj_IDirectMusicObject_QueryInterface(IDirectMusicObject *iface, REFIID riid, - void **ret_iface) -{ - struct dmobject *This = impl_from_IDirectMusicObject(iface); - return IUnknown_QueryInterface(This->outer_unk, riid, ret_iface); -} - -ULONG WINAPI dmobj_IDirectMusicObject_AddRef(IDirectMusicObject *iface) -{ - struct dmobject *This = impl_from_IDirectMusicObject(iface); - return IUnknown_AddRef(This->outer_unk); -} - -ULONG WINAPI dmobj_IDirectMusicObject_Release(IDirectMusicObject *iface) -{ - struct dmobject *This = impl_from_IDirectMusicObject(iface); - return IUnknown_Release(This->outer_unk); -} - -HRESULT WINAPI dmobj_IDirectMusicObject_GetDescriptor(IDirectMusicObject *iface, - DMUS_OBJECTDESC *desc) -{ - struct dmobject *This = impl_from_IDirectMusicObject(iface); - - TRACE("(%p/%p)->(%p)\n", iface, This, desc); - - if (!desc) - return E_POINTER; - - memcpy(desc, &This->desc, This->desc.dwSize); - - return S_OK; -} - -HRESULT WINAPI dmobj_IDirectMusicObject_SetDescriptor(IDirectMusicObject *iface, - DMUS_OBJECTDESC *desc) -{ - struct dmobject *This = impl_from_IDirectMusicObject(iface); - HRESULT ret = S_OK; - - TRACE("(%p, %p)\n", iface, desc); - - if (!desc) - return E_POINTER; - - /* Immutable property */ - if (desc->dwValidData & DMUS_OBJ_CLASS) - { - desc->dwValidData &= ~DMUS_OBJ_CLASS; - ret = S_FALSE; - } - /* Set only valid fields */ - if (desc->dwValidData & DMUS_OBJ_OBJECT) - This->desc.guidObject = desc->guidObject; - if (desc->dwValidData & DMUS_OBJ_NAME) - lstrcpynW(This->desc.wszName, desc->wszName, DMUS_MAX_NAME); - if (desc->dwValidData & DMUS_OBJ_CATEGORY) - lstrcpynW(This->desc.wszCategory, desc->wszCategory, DMUS_MAX_CATEGORY); - if (desc->dwValidData & DMUS_OBJ_FILENAME) - lstrcpynW(This->desc.wszFileName, desc->wszFileName, DMUS_MAX_FILENAME); - if (desc->dwValidData & DMUS_OBJ_VERSION) - This->desc.vVersion = desc->vVersion; - if (desc->dwValidData & DMUS_OBJ_DATE) - This->desc.ftDate = desc->ftDate; - if (desc->dwValidData & DMUS_OBJ_MEMORY) { - This->desc.llMemLength = desc->llMemLength; - memcpy(This->desc.pbMemData, desc->pbMemData, desc->llMemLength); - } - if (desc->dwValidData & DMUS_OBJ_STREAM) - IStream_Clone(desc->pStream, &This->desc.pStream); - - This->desc.dwValidData |= desc->dwValidData; - - return ret; -} - -/* Helper for IDirectMusicObject::ParseDescriptor */ -static inline void info_get_name(IStream *stream, const struct chunk_entry *info, - DMUS_OBJECTDESC *desc) -{ - struct chunk_entry chunk = {.parent = info}; - char name[DMUS_MAX_NAME]; - ULONG len; - HRESULT hr = E_FAIL; - - while (stream_next_chunk(stream, &chunk) == S_OK) - if (chunk.id == mmioFOURCC('I','N','A','M')) - hr = IStream_Read(stream, name, min(chunk.size, sizeof(name)), &len); - - if (SUCCEEDED(hr)) { - len = MultiByteToWideChar(CP_ACP, 0, name, len, desc->wszName, sizeof(desc->wszName)); - desc->wszName[min(len, sizeof(desc->wszName) - 1)] = 0; - desc->dwValidData |= DMUS_OBJ_NAME; - } -} - -static inline void unfo_get_name(IStream *stream, const struct chunk_entry *unfo, - DMUS_OBJECTDESC *desc, BOOL inam) -{ - struct chunk_entry chunk = {.parent = unfo}; - - while (stream_next_chunk(stream, &chunk) == S_OK) - if (chunk.id == DMUS_FOURCC_UNAM_CHUNK || (inam && chunk.id == mmioFOURCC('I','N','A','M'))) - if (stream_chunk_get_wstr(stream, &chunk, desc->wszName, sizeof(desc->wszName)) == S_OK) - desc->dwValidData |= DMUS_OBJ_NAME; -} - -HRESULT dmobj_parsedescriptor(IStream *stream, const struct chunk_entry *riff, - DMUS_OBJECTDESC *desc, DWORD supported) -{ - struct chunk_entry chunk = {.parent = riff}; - HRESULT hr; - - TRACE("Looking for %#lx in %p: %s\n", supported, stream, debugstr_chunk(riff)); - - desc->dwValidData = 0; - desc->dwSize = sizeof(*desc); - - while ((hr = stream_next_chunk(stream, &chunk)) == S_OK) { - switch (chunk.id) { - case DMUS_FOURCC_CATEGORY_CHUNK: - if ((supported & DMUS_OBJ_CATEGORY) && stream_chunk_get_wstr(stream, &chunk, - desc->wszCategory, sizeof(desc->wszCategory)) == S_OK) - desc->dwValidData |= DMUS_OBJ_CATEGORY; - break; - case DMUS_FOURCC_DATE_CHUNK: - if ((supported & DMUS_OBJ_DATE) && stream_chunk_get_data(stream, &chunk, - &desc->ftDate, sizeof(desc->ftDate)) == S_OK) - desc->dwValidData |= DMUS_OBJ_DATE; - break; - case DMUS_FOURCC_FILE_CHUNK: - if ((supported & DMUS_OBJ_FILENAME) && stream_chunk_get_wstr(stream, &chunk, - desc->wszFileName, sizeof(desc->wszFileName)) == S_OK) - desc->dwValidData |= DMUS_OBJ_FILENAME; - break; - case DMUS_FOURCC_GUID_CHUNK: - if ((supported & DMUS_OBJ_OBJECT) && stream_chunk_get_data(stream, &chunk, - &desc->guidObject, sizeof(desc->guidObject)) == S_OK) - desc->dwValidData |= DMUS_OBJ_OBJECT; - break; - case DMUS_FOURCC_NAME_CHUNK: - if ((supported & DMUS_OBJ_NAME) && stream_chunk_get_wstr(stream, &chunk, - desc->wszName, sizeof(desc->wszName)) == S_OK) - desc->dwValidData |= DMUS_OBJ_NAME; - break; - case DMUS_FOURCC_VERSION_CHUNK: - if ((supported & DMUS_OBJ_VERSION) && stream_chunk_get_data(stream, &chunk, - &desc->vVersion, sizeof(desc->vVersion)) == S_OK) - desc->dwValidData |= DMUS_OBJ_VERSION; - break; - case FOURCC_LIST: - if (chunk.type == DMUS_FOURCC_UNFO_LIST && (supported & DMUS_OBJ_NAME)) - unfo_get_name(stream, &chunk, desc, supported & DMUS_OBJ_NAME_INAM); - else if (chunk.type == DMUS_FOURCC_INFO_LIST && (supported & DMUS_OBJ_NAME_INFO)) - info_get_name(stream, &chunk, desc); - break; - } - } - TRACE("Found %#lx\n", desc->dwValidData); - - return hr; -} - -HRESULT dmobj_parsereference(IStream *stream, const struct chunk_entry *list, - IDirectMusicObject **dmobj) -{ - struct chunk_entry chunk = {.parent = list}; - IDirectMusicGetLoader *getloader; - IDirectMusicLoader *loader; - DMUS_OBJECTDESC desc; - DMUS_IO_REFERENCE reference; - HRESULT hr; - - if (FAILED(hr = stream_next_chunk(stream, &chunk))) - return hr; - if (chunk.id != DMUS_FOURCC_REF_CHUNK) - return DMUS_E_UNSUPPORTED_STREAM; - - if (FAILED(hr = stream_chunk_get_data(stream, &chunk, &reference, sizeof(reference)))) { - WARN("Failed to read data of %s\n", debugstr_chunk(&chunk)); - return hr; - } - TRACE("REFERENCE guidClassID %s, dwValidData %#lx\n", debugstr_dmguid(&reference.guidClassID), - reference.dwValidData); - - if (FAILED(hr = dmobj_parsedescriptor(stream, list, &desc, reference.dwValidData))) - return hr; - desc.guidClass = reference.guidClassID; - desc.dwValidData |= DMUS_OBJ_CLASS; - dump_DMUS_OBJECTDESC(&desc); - - if (FAILED(hr = IStream_QueryInterface(stream, &IID_IDirectMusicGetLoader, (void**)&getloader))) - return hr; - hr = IDirectMusicGetLoader_GetLoader(getloader, &loader); - IDirectMusicGetLoader_Release(getloader); - if (FAILED(hr)) - return hr; - - hr = IDirectMusicLoader_GetObject(loader, &desc, &IID_IDirectMusicObject, (void**)dmobj); - IDirectMusicLoader_Release(loader); - - return hr; -} - -/* Generic IPersistStream methods */ -static inline struct dmobject *impl_from_IPersistStream(IPersistStream *iface) -{ - return CONTAINING_RECORD(iface, struct dmobject, IPersistStream_iface); -} - -HRESULT WINAPI dmobj_IPersistStream_QueryInterface(IPersistStream *iface, REFIID riid, - void **ret_iface) -{ - struct dmobject *This = impl_from_IPersistStream(iface); - return IUnknown_QueryInterface(This->outer_unk, riid, ret_iface); -} - -ULONG WINAPI dmobj_IPersistStream_AddRef(IPersistStream *iface) -{ - struct dmobject *This = impl_from_IPersistStream(iface); - return IUnknown_AddRef(This->outer_unk); -} - -ULONG WINAPI dmobj_IPersistStream_Release(IPersistStream *iface) -{ - struct dmobject *This = impl_from_IPersistStream(iface); - return IUnknown_Release(This->outer_unk); -} - -HRESULT WINAPI dmobj_IPersistStream_GetClassID(IPersistStream *iface, CLSID *class) -{ - struct dmobject *This = impl_from_IPersistStream(iface); - - TRACE("(%p, %p)\n", This, class); - - if (!class) - return E_POINTER; - - *class = This->desc.guidClass; - - return S_OK; -} - -/* IPersistStream methods not implemented in native */ -HRESULT WINAPI unimpl_IPersistStream_GetClassID(IPersistStream *iface, CLSID *class) -{ - TRACE("(%p, %p): method not implemented\n", iface, class); - return E_NOTIMPL; -} - -HRESULT WINAPI unimpl_IPersistStream_IsDirty(IPersistStream *iface) -{ - TRACE("(%p): method not implemented, always returning S_FALSE\n", iface); - return S_FALSE; -} - -HRESULT WINAPI unimpl_IPersistStream_Save(IPersistStream *iface, IStream *stream, - BOOL clear_dirty) -{ - TRACE("(%p, %p, %d): method not implemented\n", iface, stream, clear_dirty); - return E_NOTIMPL; -} - -HRESULT WINAPI unimpl_IPersistStream_GetSizeMax(IPersistStream *iface, ULARGE_INTEGER *size) -{ - TRACE("(%p, %p): method not implemented\n", iface, size); - return E_NOTIMPL; -} - - -void dmobject_init(struct dmobject *dmobj, const GUID *class, IUnknown *outer_unk) -{ - dmobj->outer_unk = outer_unk; - dmobj->desc.dwSize = sizeof(dmobj->desc); - dmobj->desc.dwValidData = DMUS_OBJ_CLASS; - dmobj->desc.guidClass = *class; -} diff --git a/dlls/dmscript/dmobject.h b/dlls/dmscript/dmobject.h deleted file mode 100644 index 772be015c80..00000000000 --- a/dlls/dmscript/dmobject.h +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Base IDirectMusicObject Implementation - * Keep in sync with the master in dlls/dmusic/dmobject.h - * - * Copyright (C) 2014 Michael Stefaniuc - * - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * 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 - */ - -#include "wine/debug.h" - -/* RIFF stream parsing */ -struct chunk_entry; -struct chunk_entry { - FOURCC id; - DWORD size; - FOURCC type; /* valid only for LIST and RIFF chunks */ - ULARGE_INTEGER offset; /* chunk offset from start of stream */ - const struct chunk_entry *parent; /* enclosing RIFF or LIST chunk */ -}; - -HRESULT stream_get_chunk(IStream *stream, struct chunk_entry *chunk); -HRESULT stream_next_chunk(IStream *stream, struct chunk_entry *chunk); -HRESULT stream_skip_chunk(IStream *stream, const struct chunk_entry *chunk); - -HRESULT stream_chunk_get_array(IStream *stream, const struct chunk_entry *chunk, void **array, - unsigned int *count, DWORD elem_size); -HRESULT stream_chunk_get_data(IStream *stream, const struct chunk_entry *chunk, void *data, - ULONG size); -HRESULT stream_chunk_get_wstr(IStream *stream, const struct chunk_entry *chunk, WCHAR *str, - ULONG size); - -static inline HRESULT stream_reset_chunk_data(IStream *stream, const struct chunk_entry *chunk) -{ - LARGE_INTEGER offset; - - offset.QuadPart = chunk->offset.QuadPart + sizeof(FOURCC) + sizeof(DWORD); - if (chunk->id == FOURCC_RIFF || chunk->id == FOURCC_LIST) - offset.QuadPart += sizeof(FOURCC); - - return IStream_Seek(stream, offset, STREAM_SEEK_SET, NULL); -} - -static inline HRESULT stream_reset_chunk_start(IStream *stream, const struct chunk_entry *chunk) -{ - LARGE_INTEGER offset; - - offset.QuadPart = chunk->offset.QuadPart; - - return IStream_Seek(stream, offset, STREAM_SEEK_SET, NULL); -} - - -/* IDirectMusicObject base object */ -struct dmobject { - IDirectMusicObject IDirectMusicObject_iface; - IPersistStream IPersistStream_iface; - IUnknown *outer_unk; - DMUS_OBJECTDESC desc; -}; - -void dmobject_init(struct dmobject *dmobj, const GUID *class, IUnknown *outer_unk); - -/* Generic IDirectMusicObject methods */ -HRESULT WINAPI dmobj_IDirectMusicObject_QueryInterface(IDirectMusicObject *iface, REFIID riid, - void **ret_iface); -ULONG WINAPI dmobj_IDirectMusicObject_AddRef(IDirectMusicObject *iface); -ULONG WINAPI dmobj_IDirectMusicObject_Release(IDirectMusicObject *iface); -HRESULT WINAPI dmobj_IDirectMusicObject_GetDescriptor(IDirectMusicObject *iface, - DMUS_OBJECTDESC *desc); -HRESULT WINAPI dmobj_IDirectMusicObject_SetDescriptor(IDirectMusicObject *iface, - DMUS_OBJECTDESC *desc); - -/* Helper for IDirectMusicObject::ParseDescriptor */ -HRESULT dmobj_parsedescriptor(IStream *stream, const struct chunk_entry *riff, - DMUS_OBJECTDESC *desc, DWORD supported); -/* Additional supported flags for dmobj_parsedescriptor. - DMUS_OBJ_NAME is 'UNAM' chunk in UNFO list */ -#define DMUS_OBJ_NAME_INAM 0x1000 /* 'INAM' chunk in UNFO list */ -#define DMUS_OBJ_NAME_INFO 0x2000 /* 'INAM' chunk in INFO list */ - -/* 'DMRF' (reference list) helper */ -HRESULT dmobj_parsereference(IStream *stream, const struct chunk_entry *list, - IDirectMusicObject **dmobj); - -/* Generic IPersistStream methods */ -HRESULT WINAPI dmobj_IPersistStream_QueryInterface(IPersistStream *iface, REFIID riid, - void **ret_iface); -ULONG WINAPI dmobj_IPersistStream_AddRef(IPersistStream *iface); -ULONG WINAPI dmobj_IPersistStream_Release(IPersistStream *iface); -HRESULT WINAPI dmobj_IPersistStream_GetClassID(IPersistStream *iface, CLSID *class); - -/* IPersistStream methods not implemented in native */ -HRESULT WINAPI unimpl_IPersistStream_GetClassID(IPersistStream *iface, - CLSID *class); -HRESULT WINAPI unimpl_IPersistStream_IsDirty(IPersistStream *iface); -HRESULT WINAPI unimpl_IPersistStream_Save(IPersistStream *iface, IStream *stream, - BOOL clear_dirty); -HRESULT WINAPI unimpl_IPersistStream_GetSizeMax(IPersistStream *iface, - ULARGE_INTEGER *size); - -/* Debugging helpers */ -const char *debugstr_chunk(const struct chunk_entry *chunk); -const char *debugstr_dmguid(const GUID *id); -void dump_DMUS_OBJECTDESC(DMUS_OBJECTDESC *desc); - -static inline const char *debugstr_fourcc(DWORD fourcc) -{ - if (!fourcc) return "''"; - return wine_dbg_sprintf("'%c%c%c%c'", (char)(fourcc), (char)(fourcc >> 8), - (char)(fourcc >> 16), (char)(fourcc >> 24)); -}
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dmime/Makefile.in | 1 + dlls/dmime/dmobject.c | 731 ----------------------------------------- dlls/dmime/dmobject.h | 124 ------- 3 files changed, 1 insertion(+), 855 deletions(-) delete mode 100644 dlls/dmime/dmobject.c delete mode 100644 dlls/dmime/dmobject.h
diff --git a/dlls/dmime/Makefile.in b/dlls/dmime/Makefile.in index 51d1492585f..ef4d0b9bee4 100644 --- a/dlls/dmime/Makefile.in +++ b/dlls/dmime/Makefile.in @@ -1,5 +1,6 @@ MODULE = dmime.dll IMPORTS = dxguid uuid dsound ole32 user32 advapi32 +PARENTSRC = ../dmusic
C_SRCS = \ audiopath.c \ diff --git a/dlls/dmime/dmobject.c b/dlls/dmime/dmobject.c deleted file mode 100644 index e080211dd11..00000000000 --- a/dlls/dmime/dmobject.c +++ /dev/null @@ -1,731 +0,0 @@ -/* - * Base IDirectMusicObject Implementation - * Keep in sync with the master in dlls/dmusic/dmobject.c - * - * Copyright (C) 2003-2004 Rok Mandeljc - * Copyright (C) 2014 Michael Stefaniuc - * - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * 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 - */ - -#define COBJMACROS -#include <assert.h> -#include "objbase.h" -#include "dmusici.h" -#include "dmusicf.h" -#include "dmusics.h" -#include "dmobject.h" -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(dmobj); -WINE_DECLARE_DEBUG_CHANNEL(dmfile); - -/* Debugging helpers */ -const char *debugstr_dmguid(const GUID *id) { - unsigned int i; -#define X(guid) { &guid, #guid } - static const struct { - const GUID *guid; - const char *name; - } guids[] = { - /* CLSIDs */ - X(CLSID_AudioVBScript), - X(CLSID_DirectMusic), - X(CLSID_DirectMusicAudioPathConfig), - X(CLSID_DirectMusicAuditionTrack), - X(CLSID_DirectMusicBand), - X(CLSID_DirectMusicBandTrack), - X(CLSID_DirectMusicChordMapTrack), - X(CLSID_DirectMusicChordMap), - X(CLSID_DirectMusicChordTrack), - X(CLSID_DirectMusicCollection), - X(CLSID_DirectMusicCommandTrack), - X(CLSID_DirectMusicComposer), - X(CLSID_DirectMusicContainer), - X(CLSID_DirectMusicGraph), - X(CLSID_DirectMusicLoader), - X(CLSID_DirectMusicLyricsTrack), - X(CLSID_DirectMusicMarkerTrack), - X(CLSID_DirectMusicMelodyFormulationTrack), - X(CLSID_DirectMusicMotifTrack), - X(CLSID_DirectMusicMuteTrack), - X(CLSID_DirectMusicParamControlTrack), - X(CLSID_DirectMusicPatternTrack), - X(CLSID_DirectMusicPerformance), - X(CLSID_DirectMusicScript), - X(CLSID_DirectMusicScriptAutoImpSegment), - X(CLSID_DirectMusicScriptAutoImpPerformance), - X(CLSID_DirectMusicScriptAutoImpSegmentState), - X(CLSID_DirectMusicScriptAutoImpAudioPathConfig), - X(CLSID_DirectMusicScriptAutoImpAudioPath), - X(CLSID_DirectMusicScriptAutoImpSong), - X(CLSID_DirectMusicScriptSourceCodeLoader), - X(CLSID_DirectMusicScriptTrack), - X(CLSID_DirectMusicSection), - X(CLSID_DirectMusicSegment), - X(CLSID_DirectMusicSegmentState), - X(CLSID_DirectMusicSegmentTriggerTrack), - X(CLSID_DirectMusicSegTriggerTrack), - X(CLSID_DirectMusicSeqTrack), - X(CLSID_DirectMusicSignPostTrack), - X(CLSID_DirectMusicSong), - X(CLSID_DirectMusicStyle), - X(CLSID_DirectMusicStyleTrack), - X(CLSID_DirectMusicSynth), - X(CLSID_DirectMusicSynthSink), - X(CLSID_DirectMusicSysExTrack), - X(CLSID_DirectMusicTemplate), - X(CLSID_DirectMusicTempoTrack), - X(CLSID_DirectMusicTimeSigTrack), - X(CLSID_DirectMusicWaveTrack), - X(CLSID_DirectSoundWave), - /* IIDs */ - X(IID_IDirectMusic), - X(IID_IDirectMusic2), - X(IID_IDirectMusic8), - X(IID_IDirectMusicAudioPath), - X(IID_IDirectMusicBand), - X(IID_IDirectMusicBuffer), - X(IID_IDirectMusicChordMap), - X(IID_IDirectMusicCollection), - X(IID_IDirectMusicComposer), - X(IID_IDirectMusicContainer), - X(IID_IDirectMusicDownload), - X(IID_IDirectMusicDownloadedInstrument), - X(IID_IDirectMusicGetLoader), - X(IID_IDirectMusicGraph), - X(IID_IDirectMusicInstrument), - X(IID_IDirectMusicLoader), - X(IID_IDirectMusicLoader8), - X(IID_IDirectMusicObject), - X(IID_IDirectMusicPatternTrack), - X(IID_IDirectMusicPerformance), - X(IID_IDirectMusicPerformance2), - X(IID_IDirectMusicPerformance8), - X(IID_IDirectMusicPort), - X(IID_IDirectMusicPortDownload), - X(IID_IDirectMusicScript), - X(IID_IDirectMusicSegment), - X(IID_IDirectMusicSegment2), - X(IID_IDirectMusicSegment8), - X(IID_IDirectMusicSegmentState), - X(IID_IDirectMusicSegmentState8), - X(IID_IDirectMusicStyle), - X(IID_IDirectMusicStyle8), - X(IID_IDirectMusicSynth), - X(IID_IDirectMusicSynth8), - X(IID_IDirectMusicSynthSink), - X(IID_IDirectMusicThru), - X(IID_IDirectMusicTool), - X(IID_IDirectMusicTool8), - X(IID_IDirectMusicTrack), - X(IID_IDirectMusicTrack8), - X(IID_IUnknown), - X(IID_IPersistStream), - X(IID_IStream), - X(IID_IClassFactory), - /* GUIDs */ - X(GUID_DirectMusicAllTypes), - X(GUID_NOTIFICATION_CHORD), - X(GUID_NOTIFICATION_COMMAND), - X(GUID_NOTIFICATION_MEASUREANDBEAT), - X(GUID_NOTIFICATION_PERFORMANCE), - X(GUID_NOTIFICATION_RECOMPOSE), - X(GUID_NOTIFICATION_SEGMENT), - X(GUID_BandParam), - X(GUID_ChordParam), - X(GUID_CommandParam), - X(GUID_CommandParam2), - X(GUID_CommandParamNext), - X(GUID_IDirectMusicBand), - X(GUID_IDirectMusicChordMap), - X(GUID_IDirectMusicStyle), - X(GUID_MuteParam), - X(GUID_Play_Marker), - X(GUID_RhythmParam), - X(GUID_TempoParam), - X(GUID_TimeSignature), - X(GUID_Valid_Start_Time), - X(GUID_Clear_All_Bands), - X(GUID_ConnectToDLSCollection), - X(GUID_Disable_Auto_Download), - X(GUID_DisableTempo), - X(GUID_DisableTimeSig), - X(GUID_Download), - X(GUID_DownloadToAudioPath), - X(GUID_Enable_Auto_Download), - X(GUID_EnableTempo), - X(GUID_EnableTimeSig), - X(GUID_IgnoreBankSelectForGM), - X(GUID_SeedVariations), - X(GUID_StandardMIDIFile), - X(GUID_Unload), - X(GUID_UnloadFromAudioPath), - X(GUID_Variations), - X(GUID_PerfMasterTempo), - X(GUID_PerfMasterVolume), - X(GUID_PerfMasterGrooveLevel), - X(GUID_PerfAutoDownload), - X(GUID_DefaultGMCollection), - X(GUID_Synth_Default), - X(GUID_Buffer_Reverb), - X(GUID_Buffer_EnvReverb), - X(GUID_Buffer_Stereo), - X(GUID_Buffer_3D_Dry), - X(GUID_Buffer_Mono), - X(GUID_DMUS_PROP_GM_Hardware), - X(GUID_DMUS_PROP_GS_Capable), - X(GUID_DMUS_PROP_GS_Hardware), - X(GUID_DMUS_PROP_DLS1), - X(GUID_DMUS_PROP_DLS2), - X(GUID_DMUS_PROP_Effects), - X(GUID_DMUS_PROP_INSTRUMENT2), - X(GUID_DMUS_PROP_LegacyCaps), - X(GUID_DMUS_PROP_MemorySize), - X(GUID_DMUS_PROP_SampleMemorySize), - X(GUID_DMUS_PROP_SamplePlaybackRate), - X(GUID_DMUS_PROP_SetSynthSink), - X(GUID_DMUS_PROP_SinkUsesDSound), - X(GUID_DMUS_PROP_SynthSink_DSOUND), - X(GUID_DMUS_PROP_SynthSink_WAVE), - X(GUID_DMUS_PROP_Volume), - X(GUID_DMUS_PROP_WavesReverb), - X(GUID_DMUS_PROP_WriteLatency), - X(GUID_DMUS_PROP_WritePeriod), - X(GUID_DMUS_PROP_XG_Capable), - X(GUID_DMUS_PROP_XG_Hardware) - }; -#undef X - - if (!id) - return "(null)"; - - for (i = 0; i < ARRAY_SIZE(guids); i++) - if (IsEqualGUID(id, guids[i].guid)) - return guids[i].name; - - return debugstr_guid(id); -} - -void dump_DMUS_OBJECTDESC(DMUS_OBJECTDESC *desc) -{ - if (!desc || !TRACE_ON(dmfile)) - return; - - TRACE_(dmfile)("DMUS_OBJECTDESC (%p):", desc); - TRACE_(dmfile)(" - dwSize = %lu\n", desc->dwSize); - -#define X(flag) if (desc->dwValidData & flag) TRACE_(dmfile)(#flag " ") - TRACE_(dmfile)(" - dwValidData = %#08lx ( ", desc->dwValidData); - X(DMUS_OBJ_OBJECT); - X(DMUS_OBJ_CLASS); - X(DMUS_OBJ_NAME); - X(DMUS_OBJ_CATEGORY); - X(DMUS_OBJ_FILENAME); - X(DMUS_OBJ_FULLPATH); - X(DMUS_OBJ_URL); - X(DMUS_OBJ_VERSION); - X(DMUS_OBJ_DATE); - X(DMUS_OBJ_LOADED); - X(DMUS_OBJ_MEMORY); - X(DMUS_OBJ_STREAM); - TRACE_(dmfile)(")\n"); -#undef X - - if (desc->dwValidData & DMUS_OBJ_CLASS) - TRACE_(dmfile)(" - guidClass = %s\n", debugstr_dmguid(&desc->guidClass)); - if (desc->dwValidData & DMUS_OBJ_OBJECT) - TRACE_(dmfile)(" - guidObject = %s\n", debugstr_guid(&desc->guidObject)); - - if (desc->dwValidData & DMUS_OBJ_DATE) { - SYSTEMTIME time; - FileTimeToSystemTime(&desc->ftDate, &time); - TRACE_(dmfile)(" - ftDate = '%04u-%02u-%02u %02u:%02u:%02u'\n", - time.wYear, time.wMonth, time.wDay, time.wHour, time.wMinute, time.wSecond); - } - if (desc->dwValidData & DMUS_OBJ_VERSION) - TRACE_(dmfile)(" - vVersion = '%u,%u,%u,%u'\n", - HIWORD(desc->vVersion.dwVersionMS), LOWORD(desc->vVersion.dwVersionMS), - HIWORD(desc->vVersion.dwVersionLS), LOWORD(desc->vVersion.dwVersionLS)); - if (desc->dwValidData & DMUS_OBJ_NAME) - TRACE_(dmfile)(" - wszName = %s\n", debugstr_w(desc->wszName)); - if (desc->dwValidData & DMUS_OBJ_CATEGORY) - TRACE_(dmfile)(" - wszCategory = %s\n", debugstr_w(desc->wszCategory)); - if (desc->dwValidData & DMUS_OBJ_FILENAME) - TRACE_(dmfile)(" - wszFileName = %s\n", debugstr_w(desc->wszFileName)); - if (desc->dwValidData & DMUS_OBJ_MEMORY) - TRACE_(dmfile)(" - llMemLength = 0x%s - pbMemData = %p\n", - wine_dbgstr_longlong(desc->llMemLength), desc->pbMemData); - if (desc->dwValidData & DMUS_OBJ_STREAM) - TRACE_(dmfile)(" - pStream = %p\n", desc->pStream); -} - - -/* RIFF format parsing */ -#define CHUNK_HDR_SIZE (sizeof(FOURCC) + sizeof(DWORD)) - -const char *debugstr_chunk(const struct chunk_entry *chunk) -{ - const char *type = ""; - - if (!chunk) - return "(null)"; - if (chunk->id == FOURCC_RIFF || chunk->id == FOURCC_LIST) - type = wine_dbg_sprintf("type %s, ", debugstr_fourcc(chunk->type)); - return wine_dbg_sprintf("%s chunk, %ssize %lu", debugstr_fourcc(chunk->id), type, chunk->size); -} - -static HRESULT stream_read(IStream *stream, void *data, ULONG size) -{ - ULONG read; - HRESULT hr; - - hr = IStream_Read(stream, data, size, &read); - if (FAILED(hr)) - TRACE_(dmfile)("IStream_Read failed: %#lx\n", hr); - else if (!read && read < size) { - /* All or nothing: Handle a partial read due to end of stream as an error */ - TRACE_(dmfile)("Short read: %lu < %lu\n", read, size); - return E_FAIL; - } - - return hr; -} - -HRESULT stream_get_chunk(IStream *stream, struct chunk_entry *chunk) -{ - static const LARGE_INTEGER zero; - ULONGLONG ck_end = 0, p_end = 0; - HRESULT hr; - - hr = IStream_Seek(stream, zero, STREAM_SEEK_CUR, &chunk->offset); - if (FAILED(hr)) - return hr; - assert(!(chunk->offset.QuadPart & 1)); - if (chunk->parent) { - p_end = chunk->parent->offset.QuadPart + CHUNK_HDR_SIZE + ((chunk->parent->size + 1) & ~1); - if (chunk->offset.QuadPart == p_end) - return S_FALSE; - ck_end = chunk->offset.QuadPart + CHUNK_HDR_SIZE; - if (ck_end > p_end) { - WARN_(dmfile)("No space for sub-chunk header in parent chunk: ends at offset %s > %s\n", - wine_dbgstr_longlong(ck_end), wine_dbgstr_longlong(p_end)); - return E_FAIL; - } - } - - hr = stream_read(stream, chunk, CHUNK_HDR_SIZE); - if (hr != S_OK) - return hr; - if (chunk->parent) { - ck_end += (chunk->size + 1) & ~1; - if (ck_end > p_end) { - WARN_(dmfile)("No space for sub-chunk data in parent chunk: ends at offset %s > %s\n", - wine_dbgstr_longlong(ck_end), wine_dbgstr_longlong(p_end)); - return E_FAIL; - } - } - - if (chunk->id == FOURCC_LIST || chunk->id == FOURCC_RIFF) { - hr = stream_read(stream, &chunk->type, sizeof(FOURCC)); - if (hr != S_OK) - return hr != S_FALSE ? hr : E_FAIL; - } - - TRACE_(dmfile)("Returning %s\n", debugstr_chunk(chunk)); - - return S_OK; -} - -HRESULT stream_skip_chunk(IStream *stream, const struct chunk_entry *chunk) -{ - LARGE_INTEGER end; - - end.QuadPart = (chunk->offset.QuadPart + CHUNK_HDR_SIZE + chunk->size + 1) & ~(ULONGLONG)1; - - return IStream_Seek(stream, end, STREAM_SEEK_SET, NULL); -} - -HRESULT stream_next_chunk(IStream *stream, struct chunk_entry *chunk) -{ - HRESULT hr; - - if (chunk->id) { - hr = stream_skip_chunk(stream, chunk); - if (FAILED(hr)) - return hr; - } - - return stream_get_chunk(stream, chunk); -} - -/* Reads chunk data of the form: - DWORD - size of array element - element[] - Array of elements - The caller needs to free() the array. -*/ -HRESULT stream_chunk_get_array(IStream *stream, const struct chunk_entry *chunk, void **array, - unsigned int *count, DWORD elem_size) -{ - DWORD size; - HRESULT hr; - - *array = NULL; - *count = 0; - - if (chunk->size < sizeof(DWORD)) { - WARN_(dmfile)("%s: Too short to read element size\n", debugstr_chunk(chunk)); - return E_FAIL; - } - if (FAILED(hr = stream_read(stream, &size, sizeof(DWORD)))) - return hr; - if (size != elem_size) { - WARN_(dmfile)("%s: Array element size mismatch: got %lu, expected %lu\n", - debugstr_chunk(chunk), size, elem_size); - return DMUS_E_UNSUPPORTED_STREAM; - } - - *count = (chunk->size - sizeof(DWORD)) / elem_size; - size = *count * elem_size; - if (!(*array = malloc(size))) return E_OUTOFMEMORY; - if (FAILED(hr = stream_read(stream, *array, size))) { - free(*array); - *array = NULL; - return hr; - } - - if (chunk->size > size + sizeof(DWORD)) { - WARN_(dmfile)("%s: Extraneous data at end of array\n", debugstr_chunk(chunk)); - stream_skip_chunk(stream, chunk); - return S_FALSE; - } - return S_OK; -} - -HRESULT stream_chunk_get_data(IStream *stream, const struct chunk_entry *chunk, void *data, - ULONG size) -{ - if (chunk->size != size) { - WARN_(dmfile)("Chunk %s (size %lu, offset %s) doesn't contains the expected data size %lu\n", - debugstr_fourcc(chunk->id), chunk->size, - wine_dbgstr_longlong(chunk->offset.QuadPart), size); - return E_FAIL; - } - return stream_read(stream, data, size); -} - -HRESULT stream_chunk_get_wstr(IStream *stream, const struct chunk_entry *chunk, WCHAR *str, - ULONG size) -{ - ULONG len; - HRESULT hr; - - hr = IStream_Read(stream, str, min(chunk->size, size), &len); - if (FAILED(hr)) - return hr; - - /* Don't assume the string is properly zero terminated */ - str[min(len, size - 1)] = 0; - - if (len < chunk->size) - return S_FALSE; - return S_OK; -} - - - -/* Generic IDirectMusicObject methods */ -static inline struct dmobject *impl_from_IDirectMusicObject(IDirectMusicObject *iface) -{ - return CONTAINING_RECORD(iface, struct dmobject, IDirectMusicObject_iface); -} - -HRESULT WINAPI dmobj_IDirectMusicObject_QueryInterface(IDirectMusicObject *iface, REFIID riid, - void **ret_iface) -{ - struct dmobject *This = impl_from_IDirectMusicObject(iface); - return IUnknown_QueryInterface(This->outer_unk, riid, ret_iface); -} - -ULONG WINAPI dmobj_IDirectMusicObject_AddRef(IDirectMusicObject *iface) -{ - struct dmobject *This = impl_from_IDirectMusicObject(iface); - return IUnknown_AddRef(This->outer_unk); -} - -ULONG WINAPI dmobj_IDirectMusicObject_Release(IDirectMusicObject *iface) -{ - struct dmobject *This = impl_from_IDirectMusicObject(iface); - return IUnknown_Release(This->outer_unk); -} - -HRESULT WINAPI dmobj_IDirectMusicObject_GetDescriptor(IDirectMusicObject *iface, - DMUS_OBJECTDESC *desc) -{ - struct dmobject *This = impl_from_IDirectMusicObject(iface); - - TRACE("(%p/%p)->(%p)\n", iface, This, desc); - - if (!desc) - return E_POINTER; - - memcpy(desc, &This->desc, This->desc.dwSize); - - return S_OK; -} - -HRESULT WINAPI dmobj_IDirectMusicObject_SetDescriptor(IDirectMusicObject *iface, - DMUS_OBJECTDESC *desc) -{ - struct dmobject *This = impl_from_IDirectMusicObject(iface); - HRESULT ret = S_OK; - - TRACE("(%p, %p)\n", iface, desc); - - if (!desc) - return E_POINTER; - - /* Immutable property */ - if (desc->dwValidData & DMUS_OBJ_CLASS) - { - desc->dwValidData &= ~DMUS_OBJ_CLASS; - ret = S_FALSE; - } - /* Set only valid fields */ - if (desc->dwValidData & DMUS_OBJ_OBJECT) - This->desc.guidObject = desc->guidObject; - if (desc->dwValidData & DMUS_OBJ_NAME) - lstrcpynW(This->desc.wszName, desc->wszName, DMUS_MAX_NAME); - if (desc->dwValidData & DMUS_OBJ_CATEGORY) - lstrcpynW(This->desc.wszCategory, desc->wszCategory, DMUS_MAX_CATEGORY); - if (desc->dwValidData & DMUS_OBJ_FILENAME) - lstrcpynW(This->desc.wszFileName, desc->wszFileName, DMUS_MAX_FILENAME); - if (desc->dwValidData & DMUS_OBJ_VERSION) - This->desc.vVersion = desc->vVersion; - if (desc->dwValidData & DMUS_OBJ_DATE) - This->desc.ftDate = desc->ftDate; - if (desc->dwValidData & DMUS_OBJ_MEMORY) { - This->desc.llMemLength = desc->llMemLength; - memcpy(This->desc.pbMemData, desc->pbMemData, desc->llMemLength); - } - if (desc->dwValidData & DMUS_OBJ_STREAM) - IStream_Clone(desc->pStream, &This->desc.pStream); - - This->desc.dwValidData |= desc->dwValidData; - - return ret; -} - -/* Helper for IDirectMusicObject::ParseDescriptor */ -static inline void info_get_name(IStream *stream, const struct chunk_entry *info, - DMUS_OBJECTDESC *desc) -{ - struct chunk_entry chunk = {.parent = info}; - char name[DMUS_MAX_NAME]; - ULONG len; - HRESULT hr = E_FAIL; - - while (stream_next_chunk(stream, &chunk) == S_OK) - if (chunk.id == mmioFOURCC('I','N','A','M')) - hr = IStream_Read(stream, name, min(chunk.size, sizeof(name)), &len); - - if (SUCCEEDED(hr)) { - len = MultiByteToWideChar(CP_ACP, 0, name, len, desc->wszName, sizeof(desc->wszName)); - desc->wszName[min(len, sizeof(desc->wszName) - 1)] = 0; - desc->dwValidData |= DMUS_OBJ_NAME; - } -} - -static inline void unfo_get_name(IStream *stream, const struct chunk_entry *unfo, - DMUS_OBJECTDESC *desc, BOOL inam) -{ - struct chunk_entry chunk = {.parent = unfo}; - - while (stream_next_chunk(stream, &chunk) == S_OK) - if (chunk.id == DMUS_FOURCC_UNAM_CHUNK || (inam && chunk.id == mmioFOURCC('I','N','A','M'))) - if (stream_chunk_get_wstr(stream, &chunk, desc->wszName, sizeof(desc->wszName)) == S_OK) - desc->dwValidData |= DMUS_OBJ_NAME; -} - -HRESULT dmobj_parsedescriptor(IStream *stream, const struct chunk_entry *riff, - DMUS_OBJECTDESC *desc, DWORD supported) -{ - struct chunk_entry chunk = {.parent = riff}; - HRESULT hr; - - TRACE("Looking for %#lx in %p: %s\n", supported, stream, debugstr_chunk(riff)); - - desc->dwValidData = 0; - desc->dwSize = sizeof(*desc); - - while ((hr = stream_next_chunk(stream, &chunk)) == S_OK) { - switch (chunk.id) { - case DMUS_FOURCC_CATEGORY_CHUNK: - if ((supported & DMUS_OBJ_CATEGORY) && stream_chunk_get_wstr(stream, &chunk, - desc->wszCategory, sizeof(desc->wszCategory)) == S_OK) - desc->dwValidData |= DMUS_OBJ_CATEGORY; - break; - case DMUS_FOURCC_DATE_CHUNK: - if ((supported & DMUS_OBJ_DATE) && stream_chunk_get_data(stream, &chunk, - &desc->ftDate, sizeof(desc->ftDate)) == S_OK) - desc->dwValidData |= DMUS_OBJ_DATE; - break; - case DMUS_FOURCC_FILE_CHUNK: - if ((supported & DMUS_OBJ_FILENAME) && stream_chunk_get_wstr(stream, &chunk, - desc->wszFileName, sizeof(desc->wszFileName)) == S_OK) - desc->dwValidData |= DMUS_OBJ_FILENAME; - break; - case DMUS_FOURCC_GUID_CHUNK: - if ((supported & DMUS_OBJ_OBJECT) && stream_chunk_get_data(stream, &chunk, - &desc->guidObject, sizeof(desc->guidObject)) == S_OK) - desc->dwValidData |= DMUS_OBJ_OBJECT; - break; - case DMUS_FOURCC_NAME_CHUNK: - if ((supported & DMUS_OBJ_NAME) && stream_chunk_get_wstr(stream, &chunk, - desc->wszName, sizeof(desc->wszName)) == S_OK) - desc->dwValidData |= DMUS_OBJ_NAME; - break; - case DMUS_FOURCC_VERSION_CHUNK: - if ((supported & DMUS_OBJ_VERSION) && stream_chunk_get_data(stream, &chunk, - &desc->vVersion, sizeof(desc->vVersion)) == S_OK) - desc->dwValidData |= DMUS_OBJ_VERSION; - break; - case FOURCC_LIST: - if (chunk.type == DMUS_FOURCC_UNFO_LIST && (supported & DMUS_OBJ_NAME)) - unfo_get_name(stream, &chunk, desc, supported & DMUS_OBJ_NAME_INAM); - else if (chunk.type == DMUS_FOURCC_INFO_LIST && (supported & DMUS_OBJ_NAME_INFO)) - info_get_name(stream, &chunk, desc); - break; - } - } - TRACE("Found %#lx\n", desc->dwValidData); - - return hr; -} - -HRESULT dmobj_parsereference(IStream *stream, const struct chunk_entry *list, - IDirectMusicObject **dmobj) -{ - struct chunk_entry chunk = {.parent = list}; - IDirectMusicGetLoader *getloader; - IDirectMusicLoader *loader; - DMUS_OBJECTDESC desc; - DMUS_IO_REFERENCE reference; - HRESULT hr; - - if (FAILED(hr = stream_next_chunk(stream, &chunk))) - return hr; - if (chunk.id != DMUS_FOURCC_REF_CHUNK) - return DMUS_E_UNSUPPORTED_STREAM; - - if (FAILED(hr = stream_chunk_get_data(stream, &chunk, &reference, sizeof(reference)))) { - WARN("Failed to read data of %s\n", debugstr_chunk(&chunk)); - return hr; - } - TRACE("REFERENCE guidClassID %s, dwValidData %#lx\n", debugstr_dmguid(&reference.guidClassID), - reference.dwValidData); - - if (FAILED(hr = dmobj_parsedescriptor(stream, list, &desc, reference.dwValidData))) - return hr; - desc.guidClass = reference.guidClassID; - desc.dwValidData |= DMUS_OBJ_CLASS; - dump_DMUS_OBJECTDESC(&desc); - - if (FAILED(hr = IStream_QueryInterface(stream, &IID_IDirectMusicGetLoader, (void**)&getloader))) - return hr; - hr = IDirectMusicGetLoader_GetLoader(getloader, &loader); - IDirectMusicGetLoader_Release(getloader); - if (FAILED(hr)) - return hr; - - hr = IDirectMusicLoader_GetObject(loader, &desc, &IID_IDirectMusicObject, (void**)dmobj); - IDirectMusicLoader_Release(loader); - - return hr; -} - -/* Generic IPersistStream methods */ -static inline struct dmobject *impl_from_IPersistStream(IPersistStream *iface) -{ - return CONTAINING_RECORD(iface, struct dmobject, IPersistStream_iface); -} - -HRESULT WINAPI dmobj_IPersistStream_QueryInterface(IPersistStream *iface, REFIID riid, - void **ret_iface) -{ - struct dmobject *This = impl_from_IPersistStream(iface); - return IUnknown_QueryInterface(This->outer_unk, riid, ret_iface); -} - -ULONG WINAPI dmobj_IPersistStream_AddRef(IPersistStream *iface) -{ - struct dmobject *This = impl_from_IPersistStream(iface); - return IUnknown_AddRef(This->outer_unk); -} - -ULONG WINAPI dmobj_IPersistStream_Release(IPersistStream *iface) -{ - struct dmobject *This = impl_from_IPersistStream(iface); - return IUnknown_Release(This->outer_unk); -} - -HRESULT WINAPI dmobj_IPersistStream_GetClassID(IPersistStream *iface, CLSID *class) -{ - struct dmobject *This = impl_from_IPersistStream(iface); - - TRACE("(%p, %p)\n", This, class); - - if (!class) - return E_POINTER; - - *class = This->desc.guidClass; - - return S_OK; -} - -/* IPersistStream methods not implemented in native */ -HRESULT WINAPI unimpl_IPersistStream_GetClassID(IPersistStream *iface, CLSID *class) -{ - TRACE("(%p, %p): method not implemented\n", iface, class); - return E_NOTIMPL; -} - -HRESULT WINAPI unimpl_IPersistStream_IsDirty(IPersistStream *iface) -{ - TRACE("(%p): method not implemented, always returning S_FALSE\n", iface); - return S_FALSE; -} - -HRESULT WINAPI unimpl_IPersistStream_Save(IPersistStream *iface, IStream *stream, - BOOL clear_dirty) -{ - TRACE("(%p, %p, %d): method not implemented\n", iface, stream, clear_dirty); - return E_NOTIMPL; -} - -HRESULT WINAPI unimpl_IPersistStream_GetSizeMax(IPersistStream *iface, ULARGE_INTEGER *size) -{ - TRACE("(%p, %p): method not implemented\n", iface, size); - return E_NOTIMPL; -} - - -void dmobject_init(struct dmobject *dmobj, const GUID *class, IUnknown *outer_unk) -{ - dmobj->outer_unk = outer_unk; - dmobj->desc.dwSize = sizeof(dmobj->desc); - dmobj->desc.dwValidData = DMUS_OBJ_CLASS; - dmobj->desc.guidClass = *class; -} diff --git a/dlls/dmime/dmobject.h b/dlls/dmime/dmobject.h deleted file mode 100644 index 772be015c80..00000000000 --- a/dlls/dmime/dmobject.h +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Base IDirectMusicObject Implementation - * Keep in sync with the master in dlls/dmusic/dmobject.h - * - * Copyright (C) 2014 Michael Stefaniuc - * - * 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. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * 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 - */ - -#include "wine/debug.h" - -/* RIFF stream parsing */ -struct chunk_entry; -struct chunk_entry { - FOURCC id; - DWORD size; - FOURCC type; /* valid only for LIST and RIFF chunks */ - ULARGE_INTEGER offset; /* chunk offset from start of stream */ - const struct chunk_entry *parent; /* enclosing RIFF or LIST chunk */ -}; - -HRESULT stream_get_chunk(IStream *stream, struct chunk_entry *chunk); -HRESULT stream_next_chunk(IStream *stream, struct chunk_entry *chunk); -HRESULT stream_skip_chunk(IStream *stream, const struct chunk_entry *chunk); - -HRESULT stream_chunk_get_array(IStream *stream, const struct chunk_entry *chunk, void **array, - unsigned int *count, DWORD elem_size); -HRESULT stream_chunk_get_data(IStream *stream, const struct chunk_entry *chunk, void *data, - ULONG size); -HRESULT stream_chunk_get_wstr(IStream *stream, const struct chunk_entry *chunk, WCHAR *str, - ULONG size); - -static inline HRESULT stream_reset_chunk_data(IStream *stream, const struct chunk_entry *chunk) -{ - LARGE_INTEGER offset; - - offset.QuadPart = chunk->offset.QuadPart + sizeof(FOURCC) + sizeof(DWORD); - if (chunk->id == FOURCC_RIFF || chunk->id == FOURCC_LIST) - offset.QuadPart += sizeof(FOURCC); - - return IStream_Seek(stream, offset, STREAM_SEEK_SET, NULL); -} - -static inline HRESULT stream_reset_chunk_start(IStream *stream, const struct chunk_entry *chunk) -{ - LARGE_INTEGER offset; - - offset.QuadPart = chunk->offset.QuadPart; - - return IStream_Seek(stream, offset, STREAM_SEEK_SET, NULL); -} - - -/* IDirectMusicObject base object */ -struct dmobject { - IDirectMusicObject IDirectMusicObject_iface; - IPersistStream IPersistStream_iface; - IUnknown *outer_unk; - DMUS_OBJECTDESC desc; -}; - -void dmobject_init(struct dmobject *dmobj, const GUID *class, IUnknown *outer_unk); - -/* Generic IDirectMusicObject methods */ -HRESULT WINAPI dmobj_IDirectMusicObject_QueryInterface(IDirectMusicObject *iface, REFIID riid, - void **ret_iface); -ULONG WINAPI dmobj_IDirectMusicObject_AddRef(IDirectMusicObject *iface); -ULONG WINAPI dmobj_IDirectMusicObject_Release(IDirectMusicObject *iface); -HRESULT WINAPI dmobj_IDirectMusicObject_GetDescriptor(IDirectMusicObject *iface, - DMUS_OBJECTDESC *desc); -HRESULT WINAPI dmobj_IDirectMusicObject_SetDescriptor(IDirectMusicObject *iface, - DMUS_OBJECTDESC *desc); - -/* Helper for IDirectMusicObject::ParseDescriptor */ -HRESULT dmobj_parsedescriptor(IStream *stream, const struct chunk_entry *riff, - DMUS_OBJECTDESC *desc, DWORD supported); -/* Additional supported flags for dmobj_parsedescriptor. - DMUS_OBJ_NAME is 'UNAM' chunk in UNFO list */ -#define DMUS_OBJ_NAME_INAM 0x1000 /* 'INAM' chunk in UNFO list */ -#define DMUS_OBJ_NAME_INFO 0x2000 /* 'INAM' chunk in INFO list */ - -/* 'DMRF' (reference list) helper */ -HRESULT dmobj_parsereference(IStream *stream, const struct chunk_entry *list, - IDirectMusicObject **dmobj); - -/* Generic IPersistStream methods */ -HRESULT WINAPI dmobj_IPersistStream_QueryInterface(IPersistStream *iface, REFIID riid, - void **ret_iface); -ULONG WINAPI dmobj_IPersistStream_AddRef(IPersistStream *iface); -ULONG WINAPI dmobj_IPersistStream_Release(IPersistStream *iface); -HRESULT WINAPI dmobj_IPersistStream_GetClassID(IPersistStream *iface, CLSID *class); - -/* IPersistStream methods not implemented in native */ -HRESULT WINAPI unimpl_IPersistStream_GetClassID(IPersistStream *iface, - CLSID *class); -HRESULT WINAPI unimpl_IPersistStream_IsDirty(IPersistStream *iface); -HRESULT WINAPI unimpl_IPersistStream_Save(IPersistStream *iface, IStream *stream, - BOOL clear_dirty); -HRESULT WINAPI unimpl_IPersistStream_GetSizeMax(IPersistStream *iface, - ULARGE_INTEGER *size); - -/* Debugging helpers */ -const char *debugstr_chunk(const struct chunk_entry *chunk); -const char *debugstr_dmguid(const GUID *id); -void dump_DMUS_OBJECTDESC(DMUS_OBJECTDESC *desc); - -static inline const char *debugstr_fourcc(DWORD fourcc) -{ - if (!fourcc) return "''"; - return wine_dbg_sprintf("'%c%c%c%c'", (char)(fourcc), (char)(fourcc >> 8), - (char)(fourcc >> 16), (char)(fourcc >> 24)); -}
Hi,
It looks like your patch introduced the new failures shown below. Please investigate and fix them before resubmitting your patch. If they are not new, fixing them anyway would help a lot. Otherwise please ask for the known failures list to be updated.
The full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=137330
Your paranoid android.
=== debian11 (build log) ===
../wine/dlls/dmscript/dmobject.c:290:16: error: static declaration of ���stream_read��� follows non-static declaration ../wine/dlls/dmcompos/dmobject.c:290:16: error: static declaration of ���stream_read��� follows non-static declaration ../wine/dlls/dmloader/dmobject.c:290:16: error: static declaration of ���stream_read��� follows non-static declaration Task: The win32 Wine build failed
=== debian11b (build log) ===
../wine/dlls/dmcompos/dmobject.c:290:16: error: static declaration of ���stream_read��� follows non-static declaration ../wine/dlls/dmscript/dmobject.c:290:16: error: static declaration of ���stream_read��� follows non-static declaration ../wine/dlls/dmloader/dmobject.c:290:16: error: static declaration of ���stream_read��� follows non-static declaration Task: The wow64 Wine build failed
This merge request was approved by Michael Stefaniuc.