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 #include "dmsynth_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(dmsynth);
28 static inline IDirectMusicSynthSinkImpl *impl_from_IDirectMusicSynthSink(IDirectMusicSynthSink *iface)
30 return CONTAINING_RECORD(iface, IDirectMusicSynthSinkImpl, IDirectMusicSynthSink_iface);
33 /* IDirectMusicSynthSinkImpl IUnknown part: */
34 static HRESULT WINAPI IDirectMusicSynthSinkImpl_QueryInterface(LPDIRECTMUSICSYNTHSINK iface, REFIID riid, LPVOID *ret_iface)
36 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
38 TRACE("(%p)->(%s, %p)\n", iface, debugstr_dmguid(riid), ret_iface);
40 if (IsEqualIID (riid, &IID_IUnknown) ||
41 IsEqualIID (riid, &IID_IDirectMusicSynthSink))
43 IUnknown_AddRef(iface);
47 else if (IsEqualIID(riid, &IID_IKsControl))
49 IUnknown_AddRef(iface);
50 *ret_iface = &This->IKsControl_iface;
56 WARN("(%p)->(%s, %p): not found\n", iface, debugstr_dmguid(riid), ret_iface);
61 static ULONG WINAPI IDirectMusicSynthSinkImpl_AddRef(LPDIRECTMUSICSYNTHSINK iface)
63 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
64 ULONG ref = InterlockedIncrement(&This->ref);
66 TRACE("(%p)->(): new ref = %u\n", This, ref);
73 static ULONG WINAPI IDirectMusicSynthSinkImpl_Release(LPDIRECTMUSICSYNTHSINK iface)
75 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
76 ULONG ref = InterlockedDecrement(&This->ref);
78 TRACE("(%p)->(): new ref = %u\n", This, ref);
81 if (This->latency_clock)
82 IReferenceClock_Release(This->latency_clock);
83 HeapFree(GetProcessHeap(), 0, This);
86 DMSYNTH_UnlockModule();
91 /* IDirectMusicSynthSinkImpl IDirectMusicSynthSink part: */
92 static HRESULT WINAPI IDirectMusicSynthSinkImpl_Init(LPDIRECTMUSICSYNTHSINK iface, IDirectMusicSynth* synth)
94 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
96 FIXME("(%p)->(%p): stub\n", This, synth);
101 static HRESULT WINAPI IDirectMusicSynthSinkImpl_SetMasterClock(LPDIRECTMUSICSYNTHSINK iface, IReferenceClock* clock)
103 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
105 FIXME("(%p)->(%p): stub\n", This, clock);
110 static HRESULT WINAPI IDirectMusicSynthSinkImpl_GetLatencyClock(LPDIRECTMUSICSYNTHSINK iface, IReferenceClock** clock)
112 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
114 TRACE("(%p)->(%p)\n", iface, clock);
119 *clock = This->latency_clock;
120 IReferenceClock_AddRef(This->latency_clock);
125 static HRESULT WINAPI IDirectMusicSynthSinkImpl_Activate(LPDIRECTMUSICSYNTHSINK iface, BOOL enable)
127 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
129 FIXME("(%p)->(%d): stub\n", This, enable);
134 static HRESULT WINAPI IDirectMusicSynthSinkImpl_SampleToRefTime(LPDIRECTMUSICSYNTHSINK iface, LONGLONG sample_time, REFERENCE_TIME* ref_time)
136 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
138 FIXME("(%p)->(0x%s, %p): stub\n", This, wine_dbgstr_longlong(sample_time), ref_time);
143 static HRESULT WINAPI IDirectMusicSynthSinkImpl_RefTimeToSample(LPDIRECTMUSICSYNTHSINK iface, REFERENCE_TIME ref_time, LONGLONG* sample_time)
145 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
147 FIXME("(%p)->(0x%s, %p): stub\n", This, wine_dbgstr_longlong(ref_time), sample_time);
152 static HRESULT WINAPI IDirectMusicSynthSinkImpl_SetDirectSound(LPDIRECTMUSICSYNTHSINK iface, LPDIRECTSOUND dsound, LPDIRECTSOUNDBUFFER dsound_buffer)
154 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
156 FIXME("(%p)->(%p, %p): stub\n", This, dsound, dsound_buffer);
161 static HRESULT WINAPI IDirectMusicSynthSinkImpl_GetDesiredBufferSize(LPDIRECTMUSICSYNTHSINK iface, LPDWORD buffer_size_in_samples)
163 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
165 FIXME("(%p)->(%p): stub\n", This, buffer_size_in_samples);
170 static const IDirectMusicSynthSinkVtbl DirectMusicSynthSink_Vtbl = {
171 IDirectMusicSynthSinkImpl_QueryInterface,
172 IDirectMusicSynthSinkImpl_AddRef,
173 IDirectMusicSynthSinkImpl_Release,
174 IDirectMusicSynthSinkImpl_Init,
175 IDirectMusicSynthSinkImpl_SetMasterClock,
176 IDirectMusicSynthSinkImpl_GetLatencyClock,
177 IDirectMusicSynthSinkImpl_Activate,
178 IDirectMusicSynthSinkImpl_SampleToRefTime,
179 IDirectMusicSynthSinkImpl_RefTimeToSample,
180 IDirectMusicSynthSinkImpl_SetDirectSound,
181 IDirectMusicSynthSinkImpl_GetDesiredBufferSize
184 static inline IDirectMusicSynthSinkImpl *impl_from_IKsControl(IKsControl *iface)
186 return CONTAINING_RECORD(iface, IDirectMusicSynthSinkImpl, IKsControl_iface);
189 static HRESULT WINAPI DMSynthSinkImpl_IKsControl_QueryInterface(IKsControl* iface, REFIID riid, LPVOID *ppobj)
191 IDirectMusicSynthSinkImpl *This = impl_from_IKsControl(iface);
193 return IDirectMusicSynthSinkImpl_QueryInterface(&This->IDirectMusicSynthSink_iface, riid, ppobj);
196 static ULONG WINAPI DMSynthSinkImpl_IKsControl_AddRef(IKsControl* iface)
198 IDirectMusicSynthSinkImpl *This = impl_from_IKsControl(iface);
200 return IDirectMusicSynthSinkImpl_AddRef(&This->IDirectMusicSynthSink_iface);
203 static ULONG WINAPI DMSynthSinkImpl_IKsControl_Release(IKsControl* iface)
205 IDirectMusicSynthSinkImpl *This = impl_from_IKsControl(iface);
207 return IDirectMusicSynthSinkImpl_Release(&This->IDirectMusicSynthSink_iface);
210 static HRESULT WINAPI DMSynthSinkImpl_IKsControl_KsProperty(IKsControl* iface, PKSPROPERTY Property, ULONG PropertyLength, LPVOID PropertyData,
211 ULONG DataLength, ULONG* BytesReturned)
213 TRACE("(%p)->(%p, %u, %p, %u, %p)\n", iface, Property, PropertyLength, PropertyData, DataLength, BytesReturned);
215 TRACE("Property = %s - %u - %u\n", debugstr_guid(&Property->Set), Property->Id, Property->Flags);
217 if (Property->Flags != KSPROPERTY_TYPE_GET)
219 FIXME("Property flags %u not yet supported\n", Property->Flags);
223 if (DataLength < sizeof(DWORD))
224 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
226 if (IsEqualGUID(&Property->Set, &GUID_DMUS_PROP_SinkUsesDSound))
228 *(DWORD*)PropertyData = TRUE;
229 *BytesReturned = sizeof(DWORD);
233 FIXME("Unknown property %s\n", debugstr_guid(&Property->Set));
234 *(DWORD*)PropertyData = FALSE;
235 *BytesReturned = sizeof(DWORD);
241 static HRESULT WINAPI DMSynthSinkImpl_IKsControl_KsMethod(IKsControl* iface, PKSMETHOD Method, ULONG MethodLength, LPVOID MethodData,
242 ULONG DataLength, ULONG* BytesReturned)
244 FIXME("(%p)->(%p, %u, %p, %u, %p): stub\n", iface, Method, MethodLength, MethodData, DataLength, BytesReturned);
249 static HRESULT WINAPI DMSynthSinkImpl_IKsControl_KsEvent(IKsControl* iface, PKSEVENT Event, ULONG EventLength, LPVOID EventData,
250 ULONG DataLength, ULONG* BytesReturned)
252 FIXME("(%p)->(%p, %u, %p, %u, %p): stub\n", iface, Event, EventLength, EventData, DataLength, BytesReturned);
258 static const IKsControlVtbl DMSynthSinkImpl_IKsControl_Vtbl = {
259 DMSynthSinkImpl_IKsControl_QueryInterface,
260 DMSynthSinkImpl_IKsControl_AddRef,
261 DMSynthSinkImpl_IKsControl_Release,
262 DMSynthSinkImpl_IKsControl_KsProperty,
263 DMSynthSinkImpl_IKsControl_KsMethod,
264 DMSynthSinkImpl_IKsControl_KsEvent
267 /* for ClassFactory */
268 HRESULT WINAPI DMUSIC_CreateDirectMusicSynthSinkImpl(LPCGUID riid, LPVOID* ret_iface, LPUNKNOWN unkouter)
270 IDirectMusicSynthSinkImpl *obj;
273 TRACE("(%p,%p,%p)\n", riid, ret_iface, unkouter);
277 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicSynthSinkImpl));
279 return E_OUTOFMEMORY;
281 obj->IDirectMusicSynthSink_iface.lpVtbl = &DirectMusicSynthSink_Vtbl;
282 obj->IKsControl_iface.lpVtbl = &DMSynthSinkImpl_IKsControl_Vtbl;
285 hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&obj->latency_clock);
288 HeapFree(GetProcessHeap(), 0, obj);
292 hr = IDirectMusicSynthSinkImpl_QueryInterface((LPDIRECTMUSICSYNTHSINK)obj, riid, ret_iface);
295 IReferenceClock_Release(obj->latency_clock);
296 HeapFree(GetProcessHeap(), 0, obj);