1 /* IDirectMusicWave Implementation
3 * Copyright (C) 2003-2004 Rok Mandeljc
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "dswave_private.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(dswave
);
24 WINE_DECLARE_DEBUG_CHANNEL(dmfile
);
26 /* an interface that is, according to my tests, obtained by loader after loading object; is it acting
27 as some sort of bridge between object and loader? */
28 static const GUID IID_IDirectMusicWavePRIVATE
= {0x69e934e4,0x97f1,0x4f1d,{0x88,0xe8,0xf2,0xac,0x88,0x67,0x13,0x27}};
30 /*****************************************************************************
31 * IDirectMusicWaveImpl implementation
33 typedef struct IDirectMusicWaveImpl
{
34 IUnknown IUnknown_iface
;
35 struct dmobject dmobj
;
37 } IDirectMusicWaveImpl
;
39 /* IDirectMusicWaveImpl IUnknown part: */
40 static inline IDirectMusicWaveImpl
*impl_from_IUnknown(IUnknown
*iface
)
42 return CONTAINING_RECORD(iface
, IDirectMusicWaveImpl
, IUnknown_iface
);
45 static HRESULT WINAPI
IUnknownImpl_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ret_iface
)
47 IDirectMusicWaveImpl
*This
= impl_from_IUnknown(iface
);
49 TRACE("(%p, %s, %p)\n", This
, debugstr_dmguid(riid
), ret_iface
);
53 if (IsEqualIID(riid
, &IID_IUnknown
))
55 else if (IsEqualIID(riid
, &IID_IDirectMusicObject
))
56 *ret_iface
= &This
->dmobj
.IDirectMusicObject_iface
;
57 else if (IsEqualIID(riid
, &IID_IPersistStream
))
58 *ret_iface
= &This
->dmobj
.IPersistStream_iface
;
59 else if (IsEqualIID(riid
, &IID_IDirectMusicWavePRIVATE
)) {
60 FIXME("(%p, %s, %p): Unsupported private interface\n", This
, debugstr_guid(riid
), ret_iface
);
63 WARN("(%p, %s, %p): not found\n", This
, debugstr_dmguid(riid
), ret_iface
);
67 IUnknown_AddRef((IUnknown
*)*ret_iface
);
71 static ULONG WINAPI
IUnknownImpl_AddRef(IUnknown
*iface
)
73 IDirectMusicWaveImpl
*This
= impl_from_IUnknown(iface
);
74 LONG ref
= InterlockedIncrement(&This
->ref
);
76 TRACE("(%p) ref=%d\n", This
, ref
);
81 static ULONG WINAPI
IUnknownImpl_Release(IUnknown
*iface
)
83 IDirectMusicWaveImpl
*This
= impl_from_IUnknown(iface
);
84 LONG ref
= InterlockedDecrement(&This
->ref
);
86 TRACE("(%p) ref=%d\n", This
, ref
);
89 HeapFree(GetProcessHeap(), 0, This
);
90 DSWAVE_UnlockModule();
96 static const IUnknownVtbl unknown_vtbl
= {
97 IUnknownImpl_QueryInterface
,
102 /* IDirectMusicWaveImpl IDirectMusicObject part: */
103 static HRESULT WINAPI
wave_IDirectMusicObject_ParseDescriptor(IDirectMusicObject
*iface
,
104 IStream
*stream
, DMUS_OBJECTDESC
*desc
)
106 struct chunk_entry riff
= {0};
109 TRACE("(%p, %p, %p)\n", iface
, stream
, desc
);
111 if (!stream
|| !desc
)
114 if ((hr
= stream_get_chunk(stream
, &riff
)) != S_OK
)
116 if (riff
.id
!= FOURCC_RIFF
|| riff
.type
!= mmioFOURCC('W','A','V','E')) {
117 TRACE("loading failed: unexpected %s\n", debugstr_chunk(&riff
));
118 stream_skip_chunk(stream
, &riff
);
119 return DMUS_E_CHUNKNOTFOUND
;
122 hr
= dmobj_parsedescriptor(stream
, &riff
, desc
,
123 DMUS_OBJ_NAME_INFO
| DMUS_OBJ_OBJECT
| DMUS_OBJ_VERSION
);
127 TRACE("returning descriptor:\n%s\n", debugstr_DMUS_OBJECTDESC(desc
));
131 static const IDirectMusicObjectVtbl dmobject_vtbl
= {
132 dmobj_IDirectMusicObject_QueryInterface
,
133 dmobj_IDirectMusicObject_AddRef
,
134 dmobj_IDirectMusicObject_Release
,
135 dmobj_IDirectMusicObject_GetDescriptor
,
136 dmobj_IDirectMusicObject_SetDescriptor
,
137 wave_IDirectMusicObject_ParseDescriptor
140 /* IDirectMusicWaveImpl IPersistStream part: */
141 static inline IDirectMusicWaveImpl
*impl_from_IPersistStream(IPersistStream
*iface
)
143 return CONTAINING_RECORD(iface
, IDirectMusicWaveImpl
, dmobj
.IPersistStream_iface
);
146 static HRESULT WINAPI
IPersistStreamImpl_Load(IPersistStream
*iface
, IStream
*pStm
)
148 IDirectMusicWaveImpl
*This
= impl_from_IPersistStream(iface
);
149 DMUS_PRIVATE_CHUNK Chunk
;
150 DWORD StreamSize
, StreamCount
, ListSize
[1], ListCount
[1];
151 LARGE_INTEGER liMove
; /* used when skipping chunks */
153 FIXME("(%p, %p): loading not implemented yet (only descriptor is loaded)\n", This
, pStm
);
155 /* FIXME: should this be determined from stream? */
156 This
->dmobj
.desc
.dwValidData
|= DMUS_OBJ_CLASS
;
157 This
->dmobj
.desc
.guidClass
= CLSID_DirectMusicSegment
;
159 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
160 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
161 switch (Chunk
.fccID
) {
163 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
164 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
165 StreamSize
= Chunk
.dwSize
- sizeof(FOURCC
);
167 if (Chunk
.fccID
== mmioFOURCC('W','A','V','E')) {
168 TRACE_(dmfile
)(": wave form\n");
170 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
171 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
172 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
173 switch (Chunk
.fccID
) {
174 case DMUS_FOURCC_GUID_CHUNK
: {
175 TRACE_(dmfile
)(": GUID chunk\n");
176 This
->dmobj
.desc
.dwValidData
|= DMUS_OBJ_OBJECT
;
177 IStream_Read (pStm
, &This
->dmobj
.desc
.guidObject
, Chunk
.dwSize
, NULL
);
180 case DMUS_FOURCC_VERSION_CHUNK
: {
181 TRACE_(dmfile
)(": version chunk\n");
182 This
->dmobj
.desc
.dwValidData
|= DMUS_OBJ_VERSION
;
183 IStream_Read (pStm
, &This
->dmobj
.desc
.vVersion
, Chunk
.dwSize
, NULL
);
186 case DMUS_FOURCC_CATEGORY_CHUNK
: {
187 TRACE_(dmfile
)(": category chunk\n");
188 This
->dmobj
.desc
.dwValidData
|= DMUS_OBJ_CATEGORY
;
189 IStream_Read (pStm
, This
->dmobj
.desc
.wszCategory
, Chunk
.dwSize
, NULL
);
193 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
194 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
195 ListSize
[0] = Chunk
.dwSize
- sizeof(FOURCC
);
197 switch (Chunk
.fccID
) {
198 /* evil M$ UNFO list, which can (!?) contain INFO elements */
199 case DMUS_FOURCC_UNFO_LIST
: {
200 TRACE_(dmfile
)(": UNFO list\n");
202 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
203 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
204 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
205 switch (Chunk
.fccID
) {
206 /* don't ask me why, but M$ puts INFO elements in UNFO list sometimes
207 (though strings seem to be valid unicode) */
208 case mmioFOURCC('I','N','A','M'):
209 case DMUS_FOURCC_UNAM_CHUNK
: {
210 TRACE_(dmfile
)(": name chunk\n");
211 This
->dmobj
.desc
.dwValidData
|= DMUS_OBJ_NAME
;
212 IStream_Read (pStm
, This
->dmobj
.desc
.wszName
, Chunk
.dwSize
, NULL
);
215 case mmioFOURCC('I','A','R','T'):
216 case DMUS_FOURCC_UART_CHUNK
: {
217 TRACE_(dmfile
)(": artist chunk (ignored)\n");
218 liMove
.QuadPart
= Chunk
.dwSize
;
219 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
222 case mmioFOURCC('I','C','O','P'):
223 case DMUS_FOURCC_UCOP_CHUNK
: {
224 TRACE_(dmfile
)(": copyright chunk (ignored)\n");
225 liMove
.QuadPart
= Chunk
.dwSize
;
226 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
229 case mmioFOURCC('I','S','B','J'):
230 case DMUS_FOURCC_USBJ_CHUNK
: {
231 TRACE_(dmfile
)(": subject chunk (ignored)\n");
232 liMove
.QuadPart
= Chunk
.dwSize
;
233 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
236 case mmioFOURCC('I','C','M','T'):
237 case DMUS_FOURCC_UCMT_CHUNK
: {
238 TRACE_(dmfile
)(": comment chunk (ignored)\n");
239 liMove
.QuadPart
= Chunk
.dwSize
;
240 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
244 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
245 liMove
.QuadPart
= Chunk
.dwSize
;
246 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
250 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
251 } while (ListCount
[0] < ListSize
[0]);
255 TRACE_(dmfile
)(": unknown (skipping)\n");
256 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
257 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
264 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
265 liMove
.QuadPart
= Chunk
.dwSize
;
266 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
270 TRACE_(dmfile
)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount
, StreamSize
);
271 } while (StreamCount
< StreamSize
);
273 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
274 liMove
.QuadPart
= StreamSize
;
275 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
279 TRACE_(dmfile
)(": reading finished\n");
283 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
284 liMove
.QuadPart
= Chunk
.dwSize
;
285 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
286 return DMUS_E_INVALIDFILE
;
293 static const IPersistStreamVtbl persiststream_vtbl
= {
294 dmobj_IPersistStream_QueryInterface
,
295 dmobj_IPersistStream_AddRef
,
296 dmobj_IPersistStream_Release
,
297 dmobj_IPersistStream_GetClassID
,
298 unimpl_IPersistStream_IsDirty
,
299 IPersistStreamImpl_Load
,
300 unimpl_IPersistStream_Save
,
301 unimpl_IPersistStream_GetSizeMax
304 /* for ClassFactory */
305 HRESULT WINAPI
create_dswave(REFIID lpcGUID
, void **ppobj
)
307 IDirectMusicWaveImpl
*obj
;
310 obj
= HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectMusicWaveImpl
));
313 return E_OUTOFMEMORY
;
315 obj
->IUnknown_iface
.lpVtbl
= &unknown_vtbl
;
317 dmobject_init(&obj
->dmobj
, &CLSID_DirectSoundWave
, &obj
->IUnknown_iface
);
318 obj
->dmobj
.IDirectMusicObject_iface
.lpVtbl
= &dmobject_vtbl
;
319 obj
->dmobj
.IPersistStream_iface
.lpVtbl
= &persiststream_vtbl
;
322 hr
= IUnknown_QueryInterface(&obj
->IUnknown_iface
, lpcGUID
, ppobj
);
323 IUnknown_Release(&obj
->IUnknown_iface
);