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
);
25 /* an interface that is, according to my tests, obtained by loader after loading object; is it acting
26 as some sort of bridge between object and loader? */
27 static const GUID IID_IDirectMusicWavePRIVATE
= {0x69e934e4,0x97f1,0x4f1d,{0x88,0xe8,0xf2,0xac,0x88,0x67,0x13,0x27}};
29 /*****************************************************************************
30 * IDirectMusicWaveImpl implementation
32 typedef struct IDirectMusicWaveImpl
{
33 IUnknown IUnknown_iface
;
34 struct dmobject dmobj
;
36 } IDirectMusicWaveImpl
;
38 /* IDirectMusicWaveImpl IUnknown part: */
39 static inline IDirectMusicWaveImpl
*impl_from_IUnknown(IUnknown
*iface
)
41 return CONTAINING_RECORD(iface
, IDirectMusicWaveImpl
, IUnknown_iface
);
44 static HRESULT WINAPI
IUnknownImpl_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ret_iface
)
46 IDirectMusicWaveImpl
*This
= impl_from_IUnknown(iface
);
48 TRACE("(%p, %s, %p)\n", This
, debugstr_dmguid(riid
), ret_iface
);
52 if (IsEqualIID(riid
, &IID_IUnknown
))
54 else if (IsEqualIID(riid
, &IID_IDirectMusicObject
))
55 *ret_iface
= &This
->dmobj
.IDirectMusicObject_iface
;
56 else if (IsEqualIID(riid
, &IID_IPersistStream
))
57 *ret_iface
= &This
->dmobj
.IPersistStream_iface
;
58 else if (IsEqualIID(riid
, &IID_IDirectMusicWavePRIVATE
)) {
59 FIXME("(%p, %s, %p): Unsupported private interface\n", This
, debugstr_guid(riid
), ret_iface
);
62 WARN("(%p, %s, %p): not found\n", This
, debugstr_dmguid(riid
), ret_iface
);
66 IUnknown_AddRef((IUnknown
*)*ret_iface
);
70 static ULONG WINAPI
IUnknownImpl_AddRef(IUnknown
*iface
)
72 IDirectMusicWaveImpl
*This
= impl_from_IUnknown(iface
);
73 LONG ref
= InterlockedIncrement(&This
->ref
);
75 TRACE("(%p) ref=%ld\n", This
, ref
);
80 static ULONG WINAPI
IUnknownImpl_Release(IUnknown
*iface
)
82 IDirectMusicWaveImpl
*This
= impl_from_IUnknown(iface
);
83 LONG ref
= InterlockedDecrement(&This
->ref
);
85 TRACE("(%p) ref=%ld\n", This
, ref
);
92 static const IUnknownVtbl unknown_vtbl
= {
93 IUnknownImpl_QueryInterface
,
98 /* IDirectMusicWaveImpl IDirectMusicObject part: */
99 static HRESULT WINAPI
wave_IDirectMusicObject_ParseDescriptor(IDirectMusicObject
*iface
,
100 IStream
*stream
, DMUS_OBJECTDESC
*desc
)
102 struct chunk_entry riff
= {0};
105 TRACE("(%p, %p, %p)\n", iface
, stream
, desc
);
107 if (!stream
|| !desc
)
110 if ((hr
= stream_get_chunk(stream
, &riff
)) != S_OK
)
112 if (riff
.id
!= FOURCC_RIFF
|| riff
.type
!= mmioFOURCC('W','A','V','E')) {
113 TRACE("loading failed: unexpected %s\n", debugstr_chunk(&riff
));
114 stream_skip_chunk(stream
, &riff
);
115 return DMUS_E_CHUNKNOTFOUND
;
118 hr
= dmobj_parsedescriptor(stream
, &riff
, desc
,
119 DMUS_OBJ_NAME_INFO
| DMUS_OBJ_OBJECT
| DMUS_OBJ_VERSION
);
123 TRACE("returning descriptor:\n");
124 dump_DMUS_OBJECTDESC(desc
);
128 static const IDirectMusicObjectVtbl dmobject_vtbl
= {
129 dmobj_IDirectMusicObject_QueryInterface
,
130 dmobj_IDirectMusicObject_AddRef
,
131 dmobj_IDirectMusicObject_Release
,
132 dmobj_IDirectMusicObject_GetDescriptor
,
133 dmobj_IDirectMusicObject_SetDescriptor
,
134 wave_IDirectMusicObject_ParseDescriptor
137 /* IDirectMusicWaveImpl IPersistStream part: */
138 static inline IDirectMusicWaveImpl
*impl_from_IPersistStream(IPersistStream
*iface
)
140 return CONTAINING_RECORD(iface
, IDirectMusicWaveImpl
, dmobj
.IPersistStream_iface
);
143 static HRESULT WINAPI
wave_IPersistStream_Load(IPersistStream
*iface
, IStream
*stream
)
145 IDirectMusicWaveImpl
*This
= impl_from_IPersistStream(iface
);
146 struct chunk_entry riff
= {0};
148 /* Without the private interface the implementation should go to dmime/segment.c */
149 FIXME("(%p, %p): loading not implemented (only descriptor is loaded)\n", This
, stream
);
154 if (stream_get_chunk(stream
, &riff
) != S_OK
|| riff
.id
!= FOURCC_RIFF
||
155 riff
.type
!= mmioFOURCC('W','A','V','E'))
156 return DMUS_E_UNSUPPORTED_STREAM
;
157 stream_reset_chunk_start(stream
, &riff
);
159 return IDirectMusicObject_ParseDescriptor(&This
->dmobj
.IDirectMusicObject_iface
, stream
,
163 static const IPersistStreamVtbl persiststream_vtbl
= {
164 dmobj_IPersistStream_QueryInterface
,
165 dmobj_IPersistStream_AddRef
,
166 dmobj_IPersistStream_Release
,
167 dmobj_IPersistStream_GetClassID
,
168 unimpl_IPersistStream_IsDirty
,
169 wave_IPersistStream_Load
,
170 unimpl_IPersistStream_Save
,
171 unimpl_IPersistStream_GetSizeMax
174 /* for ClassFactory */
175 HRESULT
create_dswave(REFIID lpcGUID
, void **ppobj
)
177 IDirectMusicWaveImpl
*obj
;
181 if (!(obj
= calloc(1, sizeof(*obj
)))) return E_OUTOFMEMORY
;
182 obj
->IUnknown_iface
.lpVtbl
= &unknown_vtbl
;
184 dmobject_init(&obj
->dmobj
, &CLSID_DirectSoundWave
, &obj
->IUnknown_iface
);
185 obj
->dmobj
.IDirectMusicObject_iface
.lpVtbl
= &dmobject_vtbl
;
186 obj
->dmobj
.IPersistStream_iface
.lpVtbl
= &persiststream_vtbl
;
188 hr
= IUnknown_QueryInterface(&obj
->IUnknown_iface
, lpcGUID
, ppobj
);
189 IUnknown_Release(&obj
->IUnknown_iface
);