advapi32/tests: Allow ERROR_ACCESS_DENIED for newer Win10.
[wine.git] / dlls / dmime / audiopath.c
blob21aaa4d41291aaa6be4428dfcc2634ad3be5b0e9
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): AddRef from %d\n", This, ref - 1);
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): ReleaseRef to %d\n", This, ref);
110 if (ref == 0) {
111 if (This->pDSBuffer)
112 IDirectSoundBuffer_Release(This->pDSBuffer);
113 This->pPerf = NULL;
114 HeapFree(GetProcessHeap(), 0, This);
117 DMIME_UnlockModule();
118 return ref;
121 static HRESULT WINAPI IDirectMusicAudioPathImpl_GetObjectInPath (IDirectMusicAudioPath *iface, DWORD dwPChannel, DWORD dwStage, DWORD dwBuffer,
122 REFGUID guidObject, WORD dwIndex, REFGUID iidInterface, void** ppObject)
124 struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
125 HRESULT hr;
127 FIXME("(%p, %d, %d, %d, %s, %d, %s, %p): stub\n", This, dwPChannel, dwStage, dwBuffer, debugstr_dmguid(guidObject),
128 dwIndex, debugstr_dmguid(iidInterface), ppObject);
130 switch (dwStage) {
131 case DMUS_PATH_BUFFER:
132 if (This->pDSBuffer)
134 if (IsEqualIID (iidInterface, &IID_IUnknown) ||
135 IsEqualIID (iidInterface, &IID_IDirectSoundBuffer) ||
136 IsEqualIID (iidInterface, &IID_IDirectSoundBuffer8) ||
137 IsEqualIID (iidInterface, &IID_IDirectSound3DBuffer)) {
138 return IDirectSoundBuffer_QueryInterface(This->pDSBuffer, iidInterface, ppObject);
141 WARN("Unsupported interface %s\n", debugstr_dmguid(iidInterface));
142 *ppObject = NULL;
143 return E_NOINTERFACE;
145 break;
147 case DMUS_PATH_PRIMARY_BUFFER: {
148 if (IsEqualIID (iidInterface, &IID_IDirectSound3DListener)) {
149 IDirectSoundBuffer_QueryInterface(This->pPrimary, &IID_IDirectSound3DListener, ppObject);
150 return S_OK;
151 } else {
152 FIXME("bad iid...\n");
155 break;
157 case DMUS_PATH_AUDIOPATH_GRAPH:
159 if (IsEqualIID (iidInterface, &IID_IDirectMusicGraph)) {
160 if (NULL == This->pToolGraph) {
161 IDirectMusicGraphImpl* pGraph;
162 hr = create_dmgraph(&IID_IDirectMusicGraph, (void**)&pGraph);
163 if (FAILED(hr))
164 return hr;
165 This->pToolGraph = (IDirectMusicGraph*) pGraph;
167 *ppObject = This->pToolGraph;
168 IDirectMusicGraph_AddRef((LPDIRECTMUSICGRAPH) *ppObject);
169 return S_OK;
172 break;
174 case DMUS_PATH_AUDIOPATH_TOOL:
176 /* TODO */
178 break;
180 case DMUS_PATH_PERFORMANCE:
182 /* TODO check wanted GUID */
183 *ppObject = This->pPerf;
184 IUnknown_AddRef((LPUNKNOWN) *ppObject);
185 return S_OK;
187 break;
189 case DMUS_PATH_PERFORMANCE_GRAPH:
191 IDirectMusicGraph* pPerfoGraph = NULL;
192 IDirectMusicPerformance8_GetGraph(This->pPerf, &pPerfoGraph);
193 if (NULL == pPerfoGraph) {
194 IDirectMusicGraphImpl* pGraph = NULL;
195 hr = create_dmgraph(&IID_IDirectMusicGraph, (void**)&pGraph);
196 if (FAILED(hr))
197 return hr;
198 IDirectMusicPerformance8_SetGraph(This->pPerf, (IDirectMusicGraph*) pGraph);
199 /* we need release as SetGraph do an AddRef */
200 IDirectMusicGraph_Release((LPDIRECTMUSICGRAPH) pGraph);
201 pPerfoGraph = (LPDIRECTMUSICGRAPH) pGraph;
203 *ppObject = pPerfoGraph;
204 return S_OK;
206 break;
208 case DMUS_PATH_PERFORMANCE_TOOL:
209 default:
210 break;
213 *ppObject = NULL;
214 return E_INVALIDARG;
217 static HRESULT WINAPI IDirectMusicAudioPathImpl_Activate (IDirectMusicAudioPath *iface, BOOL fActivate)
219 struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
220 FIXME("(%p, %d): stub\n", This, fActivate);
221 if (!fActivate) {
222 if (!This->fActive) return S_OK;
223 This->fActive = FALSE;
224 } else {
225 if (This->fActive) return S_OK;
226 This->fActive = TRUE;
227 if (NULL != This->pDSBuffer) {
228 IDirectSoundBuffer_Stop(This->pDSBuffer);
231 return S_OK;
234 static HRESULT WINAPI IDirectMusicAudioPathImpl_SetVolume (IDirectMusicAudioPath *iface, LONG lVolume, DWORD dwDuration)
236 struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
237 FIXME("(%p, %i, %d): stub\n", This, lVolume, dwDuration);
238 return S_OK;
241 static HRESULT WINAPI IDirectMusicAudioPathImpl_ConvertPChannel (IDirectMusicAudioPath *iface, DWORD dwPChannelIn, DWORD* pdwPChannelOut)
243 struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
244 FIXME("(%p, %d, %p): stub\n", This, dwPChannelIn, pdwPChannelOut);
245 return S_OK;
248 static const IDirectMusicAudioPathVtbl DirectMusicAudioPathVtbl = {
249 IDirectMusicAudioPathImpl_QueryInterface,
250 IDirectMusicAudioPathImpl_AddRef,
251 IDirectMusicAudioPathImpl_Release,
252 IDirectMusicAudioPathImpl_GetObjectInPath,
253 IDirectMusicAudioPathImpl_Activate,
254 IDirectMusicAudioPathImpl_SetVolume,
255 IDirectMusicAudioPathImpl_ConvertPChannel
258 /* IDirectMusicObject */
259 static HRESULT WINAPI path_IDirectMusicObject_ParseDescriptor(IDirectMusicObject *iface,
260 IStream *stream, DMUS_OBJECTDESC *desc)
262 struct chunk_entry riff = {0};
263 HRESULT hr;
265 TRACE("(%p, %p, %p)\n", iface, stream, desc);
267 if (!stream)
268 return E_POINTER;
269 if (!desc || desc->dwSize != sizeof(*desc))
270 return E_INVALIDARG;
272 if ((hr = stream_get_chunk(stream, &riff)) != S_OK)
273 return hr;
274 if (riff.id != FOURCC_RIFF || riff.type != DMUS_FOURCC_AUDIOPATH_FORM) {
275 TRACE("loading failed: unexpected %s\n", debugstr_chunk(&riff));
276 stream_skip_chunk(stream, &riff);
277 return DMUS_E_CHUNKNOTFOUND;
280 hr = dmobj_parsedescriptor(stream, &riff, desc,
281 DMUS_OBJ_OBJECT|DMUS_OBJ_NAME|DMUS_OBJ_CATEGORY|DMUS_OBJ_VERSION);
282 if (FAILED(hr))
283 return hr;
285 desc->guidClass = CLSID_DirectMusicAudioPathConfig;
286 desc->dwValidData |= DMUS_OBJ_CLASS;
288 TRACE("returning descriptor:\n%s\n", debugstr_DMUS_OBJECTDESC (desc));
289 return S_OK;
292 static const IDirectMusicObjectVtbl dmobject_vtbl = {
293 dmobj_IDirectMusicObject_QueryInterface,
294 dmobj_IDirectMusicObject_AddRef,
295 dmobj_IDirectMusicObject_Release,
296 dmobj_IDirectMusicObject_GetDescriptor,
297 dmobj_IDirectMusicObject_SetDescriptor,
298 path_IDirectMusicObject_ParseDescriptor
301 /* IPersistStream */
302 static HRESULT WINAPI path_IPersistStream_Load(IPersistStream *iface, IStream *stream)
304 struct IDirectMusicAudioPathImpl *This = impl_from_IPersistStream(iface);
306 FIXME("(%p, %p): Loading not implemented yet\n", This, stream);
308 return IDirectMusicObject_ParseDescriptor(&This->dmobj.IDirectMusicObject_iface, stream,
309 &This->dmobj.desc);
312 static const IPersistStreamVtbl persiststream_vtbl = {
313 dmobj_IPersistStream_QueryInterface,
314 dmobj_IPersistStream_AddRef,
315 dmobj_IPersistStream_Release,
316 dmobj_IPersistStream_GetClassID,
317 unimpl_IPersistStream_IsDirty,
318 path_IPersistStream_Load,
319 unimpl_IPersistStream_Save,
320 unimpl_IPersistStream_GetSizeMax
323 /* for ClassFactory */
324 HRESULT WINAPI create_dmaudiopath(REFIID riid, void **ppobj)
326 IDirectMusicAudioPathImpl* obj;
327 HRESULT hr;
329 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicAudioPathImpl));
330 if (NULL == obj) {
331 *ppobj = NULL;
332 return E_OUTOFMEMORY;
334 obj->IDirectMusicAudioPath_iface.lpVtbl = &DirectMusicAudioPathVtbl;
335 obj->ref = 1;
336 dmobject_init(&obj->dmobj, &CLSID_DirectMusicAudioPathConfig,
337 (IUnknown *)&obj->IDirectMusicAudioPath_iface);
338 obj->dmobj.IDirectMusicObject_iface.lpVtbl = &dmobject_vtbl;
339 obj->dmobj.IPersistStream_iface.lpVtbl = &persiststream_vtbl;
341 hr = IDirectMusicAudioPath_QueryInterface(&obj->IDirectMusicAudioPath_iface, riid, ppobj);
342 IDirectMusicAudioPath_Release(&obj->IDirectMusicAudioPath_iface);
343 return hr;