1 /* IDirectMusicAudioPath 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 "dmime_private.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(dmime
);
25 struct IDirectMusicAudioPathImpl
{
26 IDirectMusicAudioPath IDirectMusicAudioPath_iface
;
27 struct dmobject dmobj
;
29 IDirectMusicPerformance8
* pPerf
;
30 IDirectMusicGraph
* pToolGraph
;
31 IDirectSoundBuffer
* pDSBuffer
;
32 IDirectSoundBuffer
* pPrimary
;
37 static inline struct IDirectMusicAudioPathImpl
*impl_from_IDirectMusicAudioPath(IDirectMusicAudioPath
*iface
)
39 return CONTAINING_RECORD(iface
, struct IDirectMusicAudioPathImpl
, IDirectMusicAudioPath_iface
);
42 static inline struct IDirectMusicAudioPathImpl
*impl_from_IDirectMusicObject(IDirectMusicObject
*iface
)
44 return CONTAINING_RECORD(iface
, struct IDirectMusicAudioPathImpl
, dmobj
.IDirectMusicObject_iface
);
47 static inline struct IDirectMusicAudioPathImpl
*impl_from_IPersistStream(IPersistStream
*iface
)
49 return CONTAINING_RECORD(iface
, struct IDirectMusicAudioPathImpl
, dmobj
.IPersistStream_iface
);
52 void set_audiopath_perf_pointer(IDirectMusicAudioPath
*iface
, IDirectMusicPerformance8
*performance
)
54 struct IDirectMusicAudioPathImpl
*This
= impl_from_IDirectMusicAudioPath(iface
);
55 This
->pPerf
= performance
;
58 void set_audiopath_dsound_buffer(IDirectMusicAudioPath
*iface
, IDirectSoundBuffer
*buffer
)
60 struct IDirectMusicAudioPathImpl
*This
= impl_from_IDirectMusicAudioPath(iface
);
61 This
->pDSBuffer
= buffer
;
64 void set_audiopath_primary_dsound_buffer(IDirectMusicAudioPath
*iface
, IDirectSoundBuffer
*buffer
)
66 struct IDirectMusicAudioPathImpl
*This
= impl_from_IDirectMusicAudioPath(iface
);
67 This
->pPrimary
= buffer
;
70 /*****************************************************************************
71 * IDirectMusicAudioPathImpl implementation
73 static HRESULT WINAPI
IDirectMusicAudioPathImpl_QueryInterface (IDirectMusicAudioPath
*iface
, REFIID riid
, void **ppobj
)
75 struct IDirectMusicAudioPathImpl
*This
= impl_from_IDirectMusicAudioPath(iface
);
77 TRACE("(%p, %s, %p)\n", This
, debugstr_dmguid(riid
), ppobj
);
81 if (IsEqualIID (riid
, &IID_IDirectMusicAudioPath
) || IsEqualIID (riid
, &IID_IUnknown
))
82 *ppobj
= &This
->IDirectMusicAudioPath_iface
;
83 else if (IsEqualIID (riid
, &IID_IDirectMusicObject
))
84 *ppobj
= &This
->dmobj
.IDirectMusicObject_iface
;
85 else if (IsEqualIID (riid
, &IID_IPersistStream
))
86 *ppobj
= &This
->dmobj
.IPersistStream_iface
;
89 IUnknown_AddRef((IUnknown
*)*ppobj
);
93 WARN("(%p, %s, %p): not found\n", This
, debugstr_dmguid(riid
), ppobj
);
97 static ULONG WINAPI
IDirectMusicAudioPathImpl_AddRef (IDirectMusicAudioPath
*iface
)
99 struct IDirectMusicAudioPathImpl
*This
= impl_from_IDirectMusicAudioPath(iface
);
100 ULONG ref
= InterlockedIncrement(&This
->ref
);
102 TRACE("(%p): AddRef from %d\n", This
, ref
- 1);
108 static ULONG WINAPI
IDirectMusicAudioPathImpl_Release (IDirectMusicAudioPath
*iface
)
110 struct IDirectMusicAudioPathImpl
*This
= impl_from_IDirectMusicAudioPath(iface
);
111 ULONG ref
= InterlockedDecrement(&This
->ref
);
113 TRACE("(%p): ReleaseRef to %d\n", This
, ref
);
117 IDirectSoundBuffer8_Release(This
->pDSBuffer
);
119 HeapFree(GetProcessHeap(), 0, This
);
122 DMIME_UnlockModule();
126 static HRESULT WINAPI
IDirectMusicAudioPathImpl_GetObjectInPath (IDirectMusicAudioPath
*iface
, DWORD dwPChannel
, DWORD dwStage
, DWORD dwBuffer
,
127 REFGUID guidObject
, WORD dwIndex
, REFGUID iidInterface
, void** ppObject
)
129 struct IDirectMusicAudioPathImpl
*This
= impl_from_IDirectMusicAudioPath(iface
);
132 FIXME("(%p, %d, %d, %d, %s, %d, %s, %p): stub\n", This
, dwPChannel
, dwStage
, dwBuffer
, debugstr_dmguid(guidObject
),
133 dwIndex
, debugstr_dmguid(iidInterface
), ppObject
);
136 case DMUS_PATH_BUFFER
:
139 if (IsEqualIID (iidInterface
, &IID_IUnknown
) ||
140 IsEqualIID (iidInterface
, &IID_IDirectSoundBuffer
) ||
141 IsEqualIID (iidInterface
, &IID_IDirectSoundBuffer8
) ||
142 IsEqualIID (iidInterface
, &IID_IDirectSound3DBuffer
)) {
143 return IDirectSoundBuffer8_QueryInterface (This
->pDSBuffer
, iidInterface
, ppObject
);
146 WARN("Unsupported interface %s\n", debugstr_dmguid(iidInterface
));
148 return E_NOINTERFACE
;
152 case DMUS_PATH_PRIMARY_BUFFER
: {
153 if (IsEqualIID (iidInterface
, &IID_IDirectSound3DListener
)) {
154 IDirectSoundBuffer8_QueryInterface (This
->pPrimary
, &IID_IDirectSound3DListener
, ppObject
);
157 FIXME("bad iid...\n");
162 case DMUS_PATH_AUDIOPATH_GRAPH
:
164 if (IsEqualIID (iidInterface
, &IID_IDirectMusicGraph
)) {
165 if (NULL
== This
->pToolGraph
) {
166 IDirectMusicGraphImpl
* pGraph
;
167 hr
= create_dmgraph(&IID_IDirectMusicGraph
, (void**)&pGraph
);
170 This
->pToolGraph
= (IDirectMusicGraph
*) pGraph
;
172 *ppObject
= This
->pToolGraph
;
173 IDirectMusicGraph_AddRef((LPDIRECTMUSICGRAPH
) *ppObject
);
179 case DMUS_PATH_AUDIOPATH_TOOL
:
185 case DMUS_PATH_PERFORMANCE
:
187 /* TODO check wanted GUID */
188 *ppObject
= This
->pPerf
;
189 IUnknown_AddRef((LPUNKNOWN
) *ppObject
);
194 case DMUS_PATH_PERFORMANCE_GRAPH
:
196 IDirectMusicGraph
* pPerfoGraph
= NULL
;
197 IDirectMusicPerformance8_GetGraph(This
->pPerf
, &pPerfoGraph
);
198 if (NULL
== pPerfoGraph
) {
199 IDirectMusicGraphImpl
* pGraph
= NULL
;
200 hr
= create_dmgraph(&IID_IDirectMusicGraph
, (void**)&pGraph
);
203 IDirectMusicPerformance8_SetGraph(This
->pPerf
, (IDirectMusicGraph
*) pGraph
);
204 /* we need release as SetGraph do an AddRef */
205 IDirectMusicGraph_Release((LPDIRECTMUSICGRAPH
) pGraph
);
206 pPerfoGraph
= (LPDIRECTMUSICGRAPH
) pGraph
;
208 *ppObject
= pPerfoGraph
;
213 case DMUS_PATH_PERFORMANCE_TOOL
:
222 static HRESULT WINAPI
IDirectMusicAudioPathImpl_Activate (IDirectMusicAudioPath
*iface
, BOOL fActivate
)
224 struct IDirectMusicAudioPathImpl
*This
= impl_from_IDirectMusicAudioPath(iface
);
225 FIXME("(%p, %d): stub\n", This
, fActivate
);
227 if (!This
->fActive
) return S_OK
;
228 This
->fActive
= FALSE
;
230 if (This
->fActive
) return S_OK
;
231 This
->fActive
= TRUE
;
232 if (NULL
!= This
->pDSBuffer
) {
233 IDirectSoundBuffer_Stop(This
->pDSBuffer
);
239 static HRESULT WINAPI
IDirectMusicAudioPathImpl_SetVolume (IDirectMusicAudioPath
*iface
, LONG lVolume
, DWORD dwDuration
)
241 struct IDirectMusicAudioPathImpl
*This
= impl_from_IDirectMusicAudioPath(iface
);
242 FIXME("(%p, %i, %d): stub\n", This
, lVolume
, dwDuration
);
246 static HRESULT WINAPI
IDirectMusicAudioPathImpl_ConvertPChannel (IDirectMusicAudioPath
*iface
, DWORD dwPChannelIn
, DWORD
* pdwPChannelOut
)
248 struct IDirectMusicAudioPathImpl
*This
= impl_from_IDirectMusicAudioPath(iface
);
249 FIXME("(%p, %d, %p): stub\n", This
, dwPChannelIn
, pdwPChannelOut
);
253 static const IDirectMusicAudioPathVtbl DirectMusicAudioPathVtbl
= {
254 IDirectMusicAudioPathImpl_QueryInterface
,
255 IDirectMusicAudioPathImpl_AddRef
,
256 IDirectMusicAudioPathImpl_Release
,
257 IDirectMusicAudioPathImpl_GetObjectInPath
,
258 IDirectMusicAudioPathImpl_Activate
,
259 IDirectMusicAudioPathImpl_SetVolume
,
260 IDirectMusicAudioPathImpl_ConvertPChannel
263 /* IDirectMusicObject */
264 static HRESULT WINAPI
path_IDirectMusicObject_ParseDescriptor(IDirectMusicObject
*iface
,
265 IStream
*stream
, DMUS_OBJECTDESC
*desc
)
267 struct chunk_entry riff
= {0};
270 TRACE("(%p, %p, %p)\n", iface
, stream
, desc
);
274 if (!desc
|| desc
->dwSize
!= sizeof(*desc
))
277 if ((hr
= stream_get_chunk(stream
, &riff
)) != S_OK
)
279 if (riff
.id
!= FOURCC_RIFF
|| riff
.type
!= DMUS_FOURCC_AUDIOPATH_FORM
) {
280 TRACE("loading failed: unexpected %s\n", debugstr_chunk(&riff
));
281 stream_skip_chunk(stream
, &riff
);
282 return DMUS_E_CHUNKNOTFOUND
;
285 hr
= dmobj_parsedescriptor(stream
, &riff
, desc
,
286 DMUS_OBJ_OBJECT
|DMUS_OBJ_NAME
|DMUS_OBJ_CATEGORY
|DMUS_OBJ_VERSION
);
290 desc
->guidClass
= CLSID_DirectMusicAudioPathConfig
;
291 desc
->dwValidData
|= DMUS_OBJ_CLASS
;
293 TRACE("returning descriptor:\n%s\n", debugstr_DMUS_OBJECTDESC (desc
));
297 static const IDirectMusicObjectVtbl dmobject_vtbl
= {
298 dmobj_IDirectMusicObject_QueryInterface
,
299 dmobj_IDirectMusicObject_AddRef
,
300 dmobj_IDirectMusicObject_Release
,
301 dmobj_IDirectMusicObject_GetDescriptor
,
302 dmobj_IDirectMusicObject_SetDescriptor
,
303 path_IDirectMusicObject_ParseDescriptor
307 static HRESULT WINAPI
path_IPersistStream_Load(IPersistStream
*iface
, IStream
*stream
)
309 struct IDirectMusicAudioPathImpl
*This
= impl_from_IPersistStream(iface
);
311 FIXME("(%p, %p): Loading not implemented yet\n", This
, stream
);
313 return IDirectMusicObject_ParseDescriptor(&This
->dmobj
.IDirectMusicObject_iface
, stream
,
317 static const IPersistStreamVtbl persiststream_vtbl
= {
318 dmobj_IPersistStream_QueryInterface
,
319 dmobj_IPersistStream_AddRef
,
320 dmobj_IPersistStream_Release
,
321 dmobj_IPersistStream_GetClassID
,
322 unimpl_IPersistStream_IsDirty
,
323 path_IPersistStream_Load
,
324 unimpl_IPersistStream_Save
,
325 unimpl_IPersistStream_GetSizeMax
328 /* for ClassFactory */
329 HRESULT WINAPI
create_dmaudiopath(REFIID riid
, void **ppobj
)
331 IDirectMusicAudioPathImpl
* obj
;
334 obj
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectMusicAudioPathImpl
));
337 return E_OUTOFMEMORY
;
339 obj
->IDirectMusicAudioPath_iface
.lpVtbl
= &DirectMusicAudioPathVtbl
;
341 dmobject_init(&obj
->dmobj
, &CLSID_DirectMusicAudioPathConfig
,
342 (IUnknown
*)&obj
->IDirectMusicAudioPath_iface
);
343 obj
->dmobj
.IDirectMusicObject_iface
.lpVtbl
= &dmobject_vtbl
;
344 obj
->dmobj
.IPersistStream_iface
.lpVtbl
= &persiststream_vtbl
;
346 hr
= IDirectMusicAudioPath_QueryInterface(&obj
->IDirectMusicAudioPath_iface
, riid
, ppobj
);
347 IDirectMusicAudioPath_Release(&obj
->IDirectMusicAudioPath_iface
);