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=%d\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=%d\n", This
, ref
);
88 HeapFree(GetProcessHeap(), 0, This
);
89 DSWAVE_UnlockModule();
95 static const IUnknownVtbl unknown_vtbl
= {
96 IUnknownImpl_QueryInterface
,
101 /* IDirectMusicWaveImpl IDirectMusicObject part: */
102 static HRESULT WINAPI
wave_IDirectMusicObject_ParseDescriptor(IDirectMusicObject
*iface
,
103 IStream
*stream
, DMUS_OBJECTDESC
*desc
)
105 struct chunk_entry riff
= {0};
108 TRACE("(%p, %p, %p)\n", iface
, stream
, desc
);
110 if (!stream
|| !desc
)
113 if ((hr
= stream_get_chunk(stream
, &riff
)) != S_OK
)
115 if (riff
.id
!= FOURCC_RIFF
|| riff
.type
!= mmioFOURCC('W','A','V','E')) {
116 TRACE("loading failed: unexpected %s\n", debugstr_chunk(&riff
));
117 stream_skip_chunk(stream
, &riff
);
118 return DMUS_E_CHUNKNOTFOUND
;
121 hr
= dmobj_parsedescriptor(stream
, &riff
, desc
,
122 DMUS_OBJ_NAME_INFO
| DMUS_OBJ_OBJECT
| DMUS_OBJ_VERSION
);
126 TRACE("returning descriptor:\n");
127 dump_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
wave_IPersistStream_Load(IPersistStream
*iface
, IStream
*stream
)
148 IDirectMusicWaveImpl
*This
= impl_from_IPersistStream(iface
);
149 struct chunk_entry riff
= {0};
151 /* Without the private interface the implementation should go to dmime/segment.c */
152 FIXME("(%p, %p): loading not implemented (only descriptor is loaded)\n", This
, stream
);
157 if (stream_get_chunk(stream
, &riff
) != S_OK
|| riff
.id
!= FOURCC_RIFF
||
158 riff
.type
!= mmioFOURCC('W','A','V','E'))
159 return DMUS_E_UNSUPPORTED_STREAM
;
160 stream_reset_chunk_start(stream
, &riff
);
162 return IDirectMusicObject_ParseDescriptor(&This
->dmobj
.IDirectMusicObject_iface
, stream
,
166 static const IPersistStreamVtbl persiststream_vtbl
= {
167 dmobj_IPersistStream_QueryInterface
,
168 dmobj_IPersistStream_AddRef
,
169 dmobj_IPersistStream_Release
,
170 dmobj_IPersistStream_GetClassID
,
171 unimpl_IPersistStream_IsDirty
,
172 wave_IPersistStream_Load
,
173 unimpl_IPersistStream_Save
,
174 unimpl_IPersistStream_GetSizeMax
177 /* for ClassFactory */
178 HRESULT WINAPI
create_dswave(REFIID lpcGUID
, void **ppobj
)
180 IDirectMusicWaveImpl
*obj
;
183 obj
= HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectMusicWaveImpl
));
186 return E_OUTOFMEMORY
;
188 obj
->IUnknown_iface
.lpVtbl
= &unknown_vtbl
;
190 dmobject_init(&obj
->dmobj
, &CLSID_DirectSoundWave
, &obj
->IUnknown_iface
);
191 obj
->dmobj
.IDirectMusicObject_iface
.lpVtbl
= &dmobject_vtbl
;
192 obj
->dmobj
.IPersistStream_iface
.lpVtbl
= &persiststream_vtbl
;
195 hr
= IUnknown_QueryInterface(&obj
->IUnknown_iface
, lpcGUID
, ppobj
);
196 IUnknown_Release(&obj
->IUnknown_iface
);