wined3d: Merge wined3d_surface_upload_data() into texture2d_upload_data().
[wine.git] / dlls / dmime / audiopath.c
blobd6560586a50d8c3f886c8c5acdafd81d7f3643b4
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_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);
79 *ppobj = NULL;
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;
88 if (*ppobj) {
89 IUnknown_AddRef((IUnknown*)*ppobj);
90 return S_OK;
93 WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
94 return E_NOINTERFACE;
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);
104 DMIME_LockModule();
105 return ref;
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);
115 if (ref == 0) {
116 if (This->pDSBuffer)
117 IDirectSoundBuffer8_Release(This->pDSBuffer);
118 This->pPerf = NULL;
119 HeapFree(GetProcessHeap(), 0, This);
122 DMIME_UnlockModule();
123 return ref;
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);
130 HRESULT hr;
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);
135 switch (dwStage) {
136 case DMUS_PATH_BUFFER:
137 if (This->pDSBuffer)
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));
147 *ppObject = NULL;
148 return E_NOINTERFACE;
150 break;
152 case DMUS_PATH_PRIMARY_BUFFER: {
153 if (IsEqualIID (iidInterface, &IID_IDirectSound3DListener)) {
154 IDirectSoundBuffer8_QueryInterface (This->pPrimary, &IID_IDirectSound3DListener, ppObject);
155 return S_OK;
156 } else {
157 FIXME("bad iid...\n");
160 break;
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);
168 if (FAILED(hr))
169 return hr;
170 This->pToolGraph = (IDirectMusicGraph*) pGraph;
172 *ppObject = This->pToolGraph;
173 IDirectMusicGraph_AddRef((LPDIRECTMUSICGRAPH) *ppObject);
174 return S_OK;
177 break;
179 case DMUS_PATH_AUDIOPATH_TOOL:
181 /* TODO */
183 break;
185 case DMUS_PATH_PERFORMANCE:
187 /* TODO check wanted GUID */
188 *ppObject = This->pPerf;
189 IUnknown_AddRef((LPUNKNOWN) *ppObject);
190 return S_OK;
192 break;
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);
201 if (FAILED(hr))
202 return hr;
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;
209 return S_OK;
211 break;
213 case DMUS_PATH_PERFORMANCE_TOOL:
214 default:
215 break;
218 *ppObject = NULL;
219 return E_INVALIDARG;
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);
226 if (!fActivate) {
227 if (!This->fActive) return S_OK;
228 This->fActive = FALSE;
229 } else {
230 if (This->fActive) return S_OK;
231 This->fActive = TRUE;
232 if (NULL != This->pDSBuffer) {
233 IDirectSoundBuffer_Stop(This->pDSBuffer);
236 return S_OK;
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);
243 return S_OK;
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);
250 return S_OK;
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};
268 HRESULT hr;
270 TRACE("(%p, %p, %p)\n", iface, stream, desc);
272 if (!stream)
273 return E_POINTER;
274 if (!desc || desc->dwSize != sizeof(*desc))
275 return E_INVALIDARG;
277 if ((hr = stream_get_chunk(stream, &riff)) != S_OK)
278 return hr;
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);
287 if (FAILED(hr))
288 return hr;
290 desc->guidClass = CLSID_DirectMusicAudioPathConfig;
291 desc->dwValidData |= DMUS_OBJ_CLASS;
293 TRACE("returning descriptor:\n%s\n", debugstr_DMUS_OBJECTDESC (desc));
294 return S_OK;
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
306 /* IPersistStream */
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,
314 &This->dmobj.desc);
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;
332 HRESULT hr;
334 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicAudioPathImpl));
335 if (NULL == obj) {
336 *ppobj = NULL;
337 return E_OUTOFMEMORY;
339 obj->IDirectMusicAudioPath_iface.lpVtbl = &DirectMusicAudioPathVtbl;
340 obj->ref = 1;
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);
348 return hr;