dmsynth: Build without -DWINE_NO_LONG_TYPES.
[wine.git] / dlls / dmsynth / synthsink.c
blobfe578086a23b760a36a687044e7756e40c25f9ae
1 /*
2 * IDirectMusicSynthSink Implementation
4 * Copyright (C) 2003-2004 Rok Mandeljc
5 * Copyright (C) 2012 Christian Costa
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define NONAMELESSUNION
23 #define NONAMELESSSTRUCT
24 #include "dmsynth_private.h"
25 #include "initguid.h"
26 #include "uuids.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(dmsynth);
30 static inline IDirectMusicSynthSinkImpl *impl_from_IDirectMusicSynthSink(IDirectMusicSynthSink *iface)
32 return CONTAINING_RECORD(iface, IDirectMusicSynthSinkImpl, IDirectMusicSynthSink_iface);
35 /* IDirectMusicSynthSinkImpl IUnknown part: */
36 static HRESULT WINAPI IDirectMusicSynthSinkImpl_QueryInterface(IDirectMusicSynthSink *iface,
37 REFIID riid, void **ret_iface)
39 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
41 TRACE("(%p)->(%s, %p)\n", iface, debugstr_dmguid(riid), ret_iface);
43 if (IsEqualIID (riid, &IID_IUnknown) ||
44 IsEqualIID (riid, &IID_IDirectMusicSynthSink))
46 IUnknown_AddRef(iface);
47 *ret_iface = iface;
48 return S_OK;
50 else if (IsEqualIID(riid, &IID_IKsControl))
52 IUnknown_AddRef(iface);
53 *ret_iface = &This->IKsControl_iface;
54 return S_OK;
57 *ret_iface = NULL;
59 WARN("(%p)->(%s, %p): not found\n", iface, debugstr_dmguid(riid), ret_iface);
61 return E_NOINTERFACE;
64 static ULONG WINAPI IDirectMusicSynthSinkImpl_AddRef(IDirectMusicSynthSink *iface)
66 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
67 ULONG ref = InterlockedIncrement(&This->ref);
69 TRACE("(%p): new ref = %lu\n", This, ref);
71 return ref;
74 static ULONG WINAPI IDirectMusicSynthSinkImpl_Release(IDirectMusicSynthSink *iface)
76 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
77 ULONG ref = InterlockedDecrement(&This->ref);
79 TRACE("(%p): new ref = %lu\n", This, ref);
81 if (!ref) {
82 if (This->latency_clock)
83 IReferenceClock_Release(This->latency_clock);
84 if (This->master_clock)
85 IReferenceClock_Release(This->master_clock);
86 HeapFree(GetProcessHeap(), 0, This);
87 DMSYNTH_UnlockModule();
90 return ref;
93 /* IDirectMusicSynthSinkImpl IDirectMusicSynthSink part: */
94 static HRESULT WINAPI IDirectMusicSynthSinkImpl_Init(IDirectMusicSynthSink *iface,
95 IDirectMusicSynth *synth)
97 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
99 TRACE("(%p)->(%p)\n", This, synth);
101 /* Not holding a reference to avoid circular dependencies.
102 The synth will release the sink during the synth's destruction. */
103 This->synth = synth;
105 return S_OK;
108 static HRESULT WINAPI IDirectMusicSynthSinkImpl_SetMasterClock(IDirectMusicSynthSink *iface,
109 IReferenceClock *clock)
111 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
113 TRACE("(%p)->(%p)\n", This, clock);
115 if (!clock)
116 return E_POINTER;
117 if (This->active)
118 return E_FAIL;
120 IReferenceClock_AddRef(clock);
121 This->master_clock = clock;
123 return S_OK;
126 static HRESULT WINAPI IDirectMusicSynthSinkImpl_GetLatencyClock(IDirectMusicSynthSink *iface,
127 IReferenceClock **clock)
129 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
131 TRACE("(%p)->(%p)\n", iface, clock);
133 if (!clock)
134 return E_POINTER;
136 *clock = This->latency_clock;
137 IReferenceClock_AddRef(This->latency_clock);
139 return S_OK;
142 static HRESULT WINAPI IDirectMusicSynthSinkImpl_Activate(IDirectMusicSynthSink *iface,
143 BOOL enable)
145 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
147 FIXME("(%p)->(%d): stub\n", This, enable);
149 return S_OK;
152 static HRESULT WINAPI IDirectMusicSynthSinkImpl_SampleToRefTime(IDirectMusicSynthSink *iface,
153 LONGLONG sample_time, REFERENCE_TIME *ref_time)
155 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
157 FIXME("(%p)->(0x%s, %p): stub\n", This, wine_dbgstr_longlong(sample_time), ref_time);
159 return S_OK;
162 static HRESULT WINAPI IDirectMusicSynthSinkImpl_RefTimeToSample(IDirectMusicSynthSink *iface,
163 REFERENCE_TIME ref_time, LONGLONG *sample_time)
165 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
167 FIXME("(%p)->(0x%s, %p): stub\n", This, wine_dbgstr_longlong(ref_time), sample_time);
169 return S_OK;
172 static HRESULT WINAPI IDirectMusicSynthSinkImpl_SetDirectSound(IDirectMusicSynthSink *iface,
173 IDirectSound *dsound, IDirectSoundBuffer *dsound_buffer)
175 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
177 FIXME("(%p)->(%p, %p): stub\n", This, dsound, dsound_buffer);
179 return S_OK;
182 static HRESULT WINAPI IDirectMusicSynthSinkImpl_GetDesiredBufferSize(IDirectMusicSynthSink *iface,
183 DWORD *buffer_size_in_samples)
185 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
187 FIXME("(%p)->(%p): stub\n", This, buffer_size_in_samples);
189 return S_OK;
192 static const IDirectMusicSynthSinkVtbl DirectMusicSynthSink_Vtbl = {
193 IDirectMusicSynthSinkImpl_QueryInterface,
194 IDirectMusicSynthSinkImpl_AddRef,
195 IDirectMusicSynthSinkImpl_Release,
196 IDirectMusicSynthSinkImpl_Init,
197 IDirectMusicSynthSinkImpl_SetMasterClock,
198 IDirectMusicSynthSinkImpl_GetLatencyClock,
199 IDirectMusicSynthSinkImpl_Activate,
200 IDirectMusicSynthSinkImpl_SampleToRefTime,
201 IDirectMusicSynthSinkImpl_RefTimeToSample,
202 IDirectMusicSynthSinkImpl_SetDirectSound,
203 IDirectMusicSynthSinkImpl_GetDesiredBufferSize
206 static inline IDirectMusicSynthSinkImpl *impl_from_IKsControl(IKsControl *iface)
208 return CONTAINING_RECORD(iface, IDirectMusicSynthSinkImpl, IKsControl_iface);
211 static HRESULT WINAPI DMSynthSinkImpl_IKsControl_QueryInterface(IKsControl* iface, REFIID riid, LPVOID *ppobj)
213 IDirectMusicSynthSinkImpl *This = impl_from_IKsControl(iface);
215 return IDirectMusicSynthSinkImpl_QueryInterface(&This->IDirectMusicSynthSink_iface, riid, ppobj);
218 static ULONG WINAPI DMSynthSinkImpl_IKsControl_AddRef(IKsControl* iface)
220 IDirectMusicSynthSinkImpl *This = impl_from_IKsControl(iface);
222 return IDirectMusicSynthSinkImpl_AddRef(&This->IDirectMusicSynthSink_iface);
225 static ULONG WINAPI DMSynthSinkImpl_IKsControl_Release(IKsControl* iface)
227 IDirectMusicSynthSinkImpl *This = impl_from_IKsControl(iface);
229 return IDirectMusicSynthSinkImpl_Release(&This->IDirectMusicSynthSink_iface);
232 static HRESULT WINAPI DMSynthSinkImpl_IKsControl_KsProperty(IKsControl* iface, PKSPROPERTY Property, ULONG PropertyLength, LPVOID PropertyData,
233 ULONG DataLength, ULONG* BytesReturned)
235 TRACE("(%p, %p, %lu, %p, %lu, %p)\n", iface, Property, PropertyLength, PropertyData, DataLength, BytesReturned);
237 TRACE("Property = %s - %lu - %lu\n", debugstr_guid(&Property->u.s.Set), Property->u.s.Id, Property->u.s.Flags);
239 if (Property->u.s.Flags != KSPROPERTY_TYPE_GET)
241 FIXME("Property flags %lu not yet supported\n", Property->u.s.Flags);
242 return S_FALSE;
245 if (DataLength < sizeof(DWORD))
246 return E_NOT_SUFFICIENT_BUFFER;
248 if (IsEqualGUID(&Property->u.s.Set, &GUID_DMUS_PROP_SinkUsesDSound))
250 *(DWORD*)PropertyData = TRUE;
251 *BytesReturned = sizeof(DWORD);
253 else
255 FIXME("Unknown property %s\n", debugstr_guid(&Property->u.s.Set));
256 *(DWORD*)PropertyData = FALSE;
257 *BytesReturned = sizeof(DWORD);
260 return S_OK;
263 static HRESULT WINAPI DMSynthSinkImpl_IKsControl_KsMethod(IKsControl* iface, PKSMETHOD Method, ULONG MethodLength, LPVOID MethodData,
264 ULONG DataLength, ULONG* BytesReturned)
266 FIXME("(%p, %p, %lu, %p, %lu, %p): stub\n", iface, Method, MethodLength, MethodData, DataLength, BytesReturned);
268 return E_NOTIMPL;
271 static HRESULT WINAPI DMSynthSinkImpl_IKsControl_KsEvent(IKsControl* iface, PKSEVENT Event, ULONG EventLength, LPVOID EventData,
272 ULONG DataLength, ULONG* BytesReturned)
274 FIXME("(%p, %p, %lu, %p, %lu, %p): stub\n", iface, Event, EventLength, EventData, DataLength, BytesReturned);
276 return E_NOTIMPL;
280 static const IKsControlVtbl DMSynthSinkImpl_IKsControl_Vtbl = {
281 DMSynthSinkImpl_IKsControl_QueryInterface,
282 DMSynthSinkImpl_IKsControl_AddRef,
283 DMSynthSinkImpl_IKsControl_Release,
284 DMSynthSinkImpl_IKsControl_KsProperty,
285 DMSynthSinkImpl_IKsControl_KsMethod,
286 DMSynthSinkImpl_IKsControl_KsEvent
289 /* for ClassFactory */
290 HRESULT WINAPI DMUSIC_CreateDirectMusicSynthSinkImpl(REFIID riid, void **ret_iface)
292 IDirectMusicSynthSinkImpl *obj;
293 HRESULT hr;
295 TRACE("(%s, %p)\n", debugstr_guid(riid), ret_iface);
297 *ret_iface = NULL;
299 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicSynthSinkImpl));
300 if (!obj)
301 return E_OUTOFMEMORY;
303 obj->IDirectMusicSynthSink_iface.lpVtbl = &DirectMusicSynthSink_Vtbl;
304 obj->IKsControl_iface.lpVtbl = &DMSynthSinkImpl_IKsControl_Vtbl;
305 obj->ref = 1;
307 hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&obj->latency_clock);
308 if (FAILED(hr))
310 HeapFree(GetProcessHeap(), 0, obj);
311 return hr;
314 DMSYNTH_LockModule();
315 hr = IDirectMusicSynthSink_QueryInterface(&obj->IDirectMusicSynthSink_iface, riid, ret_iface);
316 IDirectMusicSynthSink_Release(&obj->IDirectMusicSynthSink_iface);
318 return hr;