cmd: DIR command outputs free space for the path.
[wine.git] / dlls / dmime / audiopath.c
blob0857ed77c4813c44e3ac3393e1f48fa65b553a7b
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"
21 #include "dmobject.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(dmime);
25 struct IDirectMusicAudioPathImpl {
26 IDirectMusicAudioPath IDirectMusicAudioPath_iface;
27 struct dmobject dmobj;
28 LONG ref;
29 IDirectMusicPerformance8* pPerf;
30 IDirectMusicGraph* pToolGraph;
31 IDirectSoundBuffer* pDSBuffer;
32 IDirectSoundBuffer* pPrimary;
34 BOOL fActive;
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_IPersistStream(IPersistStream *iface)
44 return CONTAINING_RECORD(iface, struct IDirectMusicAudioPathImpl, dmobj.IPersistStream_iface);
47 void set_audiopath_perf_pointer(IDirectMusicAudioPath *iface, IDirectMusicPerformance8 *performance)
49 struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
50 This->pPerf = performance;
53 void set_audiopath_dsound_buffer(IDirectMusicAudioPath *iface, IDirectSoundBuffer *buffer)
55 struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
56 This->pDSBuffer = buffer;
59 void set_audiopath_primary_dsound_buffer(IDirectMusicAudioPath *iface, IDirectSoundBuffer *buffer)
61 struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
62 This->pPrimary = buffer;
65 /*****************************************************************************
66 * IDirectMusicAudioPathImpl implementation
68 static HRESULT WINAPI IDirectMusicAudioPathImpl_QueryInterface (IDirectMusicAudioPath *iface, REFIID riid, void **ppobj)
70 struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
72 TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
74 *ppobj = NULL;
76 if (IsEqualIID (riid, &IID_IDirectMusicAudioPath) || IsEqualIID (riid, &IID_IUnknown))
77 *ppobj = &This->IDirectMusicAudioPath_iface;
78 else if (IsEqualIID (riid, &IID_IDirectMusicObject))
79 *ppobj = &This->dmobj.IDirectMusicObject_iface;
80 else if (IsEqualIID (riid, &IID_IPersistStream))
81 *ppobj = &This->dmobj.IPersistStream_iface;
83 if (*ppobj) {
84 IUnknown_AddRef((IUnknown*)*ppobj);
85 return S_OK;
88 WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
89 return E_NOINTERFACE;
92 static ULONG WINAPI IDirectMusicAudioPathImpl_AddRef (IDirectMusicAudioPath *iface)
94 struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
95 ULONG ref = InterlockedIncrement(&This->ref);
97 TRACE("(%p): ref=%ld\n", This, ref);
99 DMIME_LockModule();
100 return ref;
103 static ULONG WINAPI IDirectMusicAudioPathImpl_Release (IDirectMusicAudioPath *iface)
105 struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
106 ULONG ref = InterlockedDecrement(&This->ref);
108 TRACE("(%p): ref=%ld\n", This, ref);
110 if (ref == 0) {
111 if (This->pPrimary)
112 IDirectSoundBuffer_Release(This->pPrimary);
113 if (This->pDSBuffer)
114 IDirectSoundBuffer_Release(This->pDSBuffer);
115 This->pPerf = NULL;
116 HeapFree(GetProcessHeap(), 0, This);
119 DMIME_UnlockModule();
120 return ref;
123 static HRESULT WINAPI IDirectMusicAudioPathImpl_GetObjectInPath (IDirectMusicAudioPath *iface, DWORD dwPChannel, DWORD dwStage, DWORD dwBuffer,
124 REFGUID guidObject, WORD dwIndex, REFGUID iidInterface, void** ppObject)
126 struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
127 HRESULT hr;
129 FIXME("(%p, %ld, %ld, %ld, %s, %d, %s, %p): stub\n", This, dwPChannel, dwStage, dwBuffer, debugstr_dmguid(guidObject),
130 dwIndex, debugstr_dmguid(iidInterface), ppObject);
132 switch (dwStage) {
133 case DMUS_PATH_BUFFER:
134 if (This->pDSBuffer)
136 if (IsEqualIID (iidInterface, &IID_IUnknown) ||
137 IsEqualIID (iidInterface, &IID_IDirectSoundBuffer) ||
138 IsEqualIID (iidInterface, &IID_IDirectSoundBuffer8) ||
139 IsEqualIID (iidInterface, &IID_IDirectSound3DBuffer)) {
140 return IDirectSoundBuffer_QueryInterface(This->pDSBuffer, iidInterface, ppObject);
143 WARN("Unsupported interface %s\n", debugstr_dmguid(iidInterface));
144 *ppObject = NULL;
145 return E_NOINTERFACE;
147 break;
149 case DMUS_PATH_PRIMARY_BUFFER: {
150 if (IsEqualIID (iidInterface, &IID_IDirectSound3DListener)) {
151 IDirectSoundBuffer_QueryInterface(This->pPrimary, &IID_IDirectSound3DListener, ppObject);
152 return S_OK;
153 } else {
154 FIXME("bad iid...\n");
157 break;
159 case DMUS_PATH_AUDIOPATH_GRAPH:
161 if (IsEqualIID (iidInterface, &IID_IDirectMusicGraph)) {
162 if (NULL == This->pToolGraph) {
163 IDirectMusicGraphImpl* pGraph;
164 hr = create_dmgraph(&IID_IDirectMusicGraph, (void**)&pGraph);
165 if (FAILED(hr))
166 return hr;
167 This->pToolGraph = (IDirectMusicGraph*) pGraph;
169 *ppObject = This->pToolGraph;
170 IDirectMusicGraph_AddRef((LPDIRECTMUSICGRAPH) *ppObject);
171 return S_OK;
174 break;
176 case DMUS_PATH_AUDIOPATH_TOOL:
178 /* TODO */
180 break;
182 case DMUS_PATH_PERFORMANCE:
184 /* TODO check wanted GUID */
185 *ppObject = This->pPerf;
186 IUnknown_AddRef((LPUNKNOWN) *ppObject);
187 return S_OK;
189 break;
191 case DMUS_PATH_PERFORMANCE_GRAPH:
193 IDirectMusicGraph* pPerfoGraph = NULL;
194 IDirectMusicPerformance8_GetGraph(This->pPerf, &pPerfoGraph);
195 if (NULL == pPerfoGraph) {
196 IDirectMusicGraphImpl* pGraph = NULL;
197 hr = create_dmgraph(&IID_IDirectMusicGraph, (void**)&pGraph);
198 if (FAILED(hr))
199 return hr;
200 IDirectMusicPerformance8_SetGraph(This->pPerf, (IDirectMusicGraph*) pGraph);
201 /* we need release as SetGraph do an AddRef */
202 IDirectMusicGraph_Release((LPDIRECTMUSICGRAPH) pGraph);
203 pPerfoGraph = (LPDIRECTMUSICGRAPH) pGraph;
205 *ppObject = pPerfoGraph;
206 return S_OK;
208 break;
210 case DMUS_PATH_PERFORMANCE_TOOL:
211 default:
212 break;
215 *ppObject = NULL;
216 return E_INVALIDARG;
219 static HRESULT WINAPI IDirectMusicAudioPathImpl_Activate(IDirectMusicAudioPath *iface, BOOL activate)
221 struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
223 FIXME("(%p, %d): semi-stub\n", This, activate);
225 if (!!activate == This->fActive)
226 return S_FALSE;
228 if (!activate && This->pDSBuffer) {
229 /* Path is being deactivated */
230 IDirectSoundBuffer_Stop(This->pDSBuffer);
233 This->fActive = !!activate;
235 return S_OK;
238 static HRESULT WINAPI IDirectMusicAudioPathImpl_SetVolume (IDirectMusicAudioPath *iface, LONG lVolume, DWORD dwDuration)
240 struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
241 FIXME("(%p, %li, %ld): stub\n", This, lVolume, dwDuration);
242 return S_OK;
245 static HRESULT WINAPI IDirectMusicAudioPathImpl_ConvertPChannel (IDirectMusicAudioPath *iface, DWORD dwPChannelIn, DWORD* pdwPChannelOut)
247 struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
248 FIXME("(%p, %ld, %p): stub\n", This, dwPChannelIn, pdwPChannelOut);
249 return S_OK;
252 static const IDirectMusicAudioPathVtbl DirectMusicAudioPathVtbl = {
253 IDirectMusicAudioPathImpl_QueryInterface,
254 IDirectMusicAudioPathImpl_AddRef,
255 IDirectMusicAudioPathImpl_Release,
256 IDirectMusicAudioPathImpl_GetObjectInPath,
257 IDirectMusicAudioPathImpl_Activate,
258 IDirectMusicAudioPathImpl_SetVolume,
259 IDirectMusicAudioPathImpl_ConvertPChannel
262 /* IDirectMusicObject */
263 static HRESULT WINAPI path_IDirectMusicObject_ParseDescriptor(IDirectMusicObject *iface,
264 IStream *stream, DMUS_OBJECTDESC *desc)
266 struct chunk_entry riff = {0};
267 HRESULT hr;
269 TRACE("(%p, %p, %p)\n", iface, stream, desc);
271 if (!stream)
272 return E_POINTER;
273 if (!desc || desc->dwSize != sizeof(*desc))
274 return E_INVALIDARG;
276 if ((hr = stream_get_chunk(stream, &riff)) != S_OK)
277 return hr;
278 if (riff.id != FOURCC_RIFF || riff.type != DMUS_FOURCC_AUDIOPATH_FORM) {
279 TRACE("loading failed: unexpected %s\n", debugstr_chunk(&riff));
280 stream_skip_chunk(stream, &riff);
281 return DMUS_E_CHUNKNOTFOUND;
284 hr = dmobj_parsedescriptor(stream, &riff, desc,
285 DMUS_OBJ_OBJECT|DMUS_OBJ_NAME|DMUS_OBJ_CATEGORY|DMUS_OBJ_VERSION);
286 if (FAILED(hr))
287 return hr;
289 desc->guidClass = CLSID_DirectMusicAudioPathConfig;
290 desc->dwValidData |= DMUS_OBJ_CLASS;
292 dump_DMUS_OBJECTDESC(desc);
293 return S_OK;
296 static const IDirectMusicObjectVtbl dmobject_vtbl = {
297 dmobj_IDirectMusicObject_QueryInterface,
298 dmobj_IDirectMusicObject_AddRef,
299 dmobj_IDirectMusicObject_Release,
300 dmobj_IDirectMusicObject_GetDescriptor,
301 dmobj_IDirectMusicObject_SetDescriptor,
302 path_IDirectMusicObject_ParseDescriptor
305 /* IPersistStream */
306 static HRESULT WINAPI path_IPersistStream_Load(IPersistStream *iface, IStream *stream)
308 struct IDirectMusicAudioPathImpl *This = impl_from_IPersistStream(iface);
310 FIXME("(%p, %p): Loading not implemented yet\n", This, stream);
312 return IDirectMusicObject_ParseDescriptor(&This->dmobj.IDirectMusicObject_iface, stream,
313 &This->dmobj.desc);
316 static const IPersistStreamVtbl persiststream_vtbl = {
317 dmobj_IPersistStream_QueryInterface,
318 dmobj_IPersistStream_AddRef,
319 dmobj_IPersistStream_Release,
320 dmobj_IPersistStream_GetClassID,
321 unimpl_IPersistStream_IsDirty,
322 path_IPersistStream_Load,
323 unimpl_IPersistStream_Save,
324 unimpl_IPersistStream_GetSizeMax
327 /* for ClassFactory */
328 HRESULT create_dmaudiopath(REFIID riid, void **ppobj)
330 IDirectMusicAudioPathImpl* obj;
331 HRESULT hr;
333 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicAudioPathImpl));
334 if (NULL == obj) {
335 *ppobj = NULL;
336 return E_OUTOFMEMORY;
338 obj->IDirectMusicAudioPath_iface.lpVtbl = &DirectMusicAudioPathVtbl;
339 obj->ref = 1;
340 dmobject_init(&obj->dmobj, &CLSID_DirectMusicAudioPathConfig,
341 (IUnknown *)&obj->IDirectMusicAudioPath_iface);
342 obj->dmobj.IDirectMusicObject_iface.lpVtbl = &dmobject_vtbl;
343 obj->dmobj.IPersistStream_iface.lpVtbl = &persiststream_vtbl;
345 hr = IDirectMusicAudioPath_QueryInterface(&obj->IDirectMusicAudioPath_iface, riid, ppobj);
346 IDirectMusicAudioPath_Release(&obj->IDirectMusicAudioPath_iface);
347 return hr;