ntdll: Implement NtCreateDebugObject().
[wine.git] / dlls / dmsynth / synthsink.c
blob46011eae27acbe9e79a9828e420a35c67c9693d9
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 = %u\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 = %u\n", This, ref);
81 if (!ref) {
82 if (This->latency_clock)
83 IReferenceClock_Release(This->latency_clock);
84 HeapFree(GetProcessHeap(), 0, This);
85 DMSYNTH_UnlockModule();
88 return ref;
91 /* IDirectMusicSynthSinkImpl IDirectMusicSynthSink part: */
92 static HRESULT WINAPI IDirectMusicSynthSinkImpl_Init(IDirectMusicSynthSink *iface,
93 IDirectMusicSynth *synth)
95 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
97 FIXME("(%p)->(%p): stub\n", This, synth);
99 return S_OK;
102 static HRESULT WINAPI IDirectMusicSynthSinkImpl_SetMasterClock(IDirectMusicSynthSink *iface,
103 IReferenceClock *clock)
105 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
107 FIXME("(%p)->(%p): stub\n", This, clock);
109 return S_OK;
112 static HRESULT WINAPI IDirectMusicSynthSinkImpl_GetLatencyClock(IDirectMusicSynthSink *iface,
113 IReferenceClock **clock)
115 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
117 TRACE("(%p)->(%p)\n", iface, clock);
119 if (!clock)
120 return E_POINTER;
122 *clock = This->latency_clock;
123 IReferenceClock_AddRef(This->latency_clock);
125 return S_OK;
128 static HRESULT WINAPI IDirectMusicSynthSinkImpl_Activate(IDirectMusicSynthSink *iface,
129 BOOL enable)
131 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
133 FIXME("(%p)->(%d): stub\n", This, enable);
135 return S_OK;
138 static HRESULT WINAPI IDirectMusicSynthSinkImpl_SampleToRefTime(IDirectMusicSynthSink *iface,
139 LONGLONG sample_time, REFERENCE_TIME *ref_time)
141 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
143 FIXME("(%p)->(0x%s, %p): stub\n", This, wine_dbgstr_longlong(sample_time), ref_time);
145 return S_OK;
148 static HRESULT WINAPI IDirectMusicSynthSinkImpl_RefTimeToSample(IDirectMusicSynthSink *iface,
149 REFERENCE_TIME ref_time, LONGLONG *sample_time)
151 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
153 FIXME("(%p)->(0x%s, %p): stub\n", This, wine_dbgstr_longlong(ref_time), sample_time);
155 return S_OK;
158 static HRESULT WINAPI IDirectMusicSynthSinkImpl_SetDirectSound(IDirectMusicSynthSink *iface,
159 IDirectSound *dsound, IDirectSoundBuffer *dsound_buffer)
161 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
163 FIXME("(%p)->(%p, %p): stub\n", This, dsound, dsound_buffer);
165 return S_OK;
168 static HRESULT WINAPI IDirectMusicSynthSinkImpl_GetDesiredBufferSize(IDirectMusicSynthSink *iface,
169 DWORD *buffer_size_in_samples)
171 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
173 FIXME("(%p)->(%p): stub\n", This, buffer_size_in_samples);
175 return S_OK;
178 static const IDirectMusicSynthSinkVtbl DirectMusicSynthSink_Vtbl = {
179 IDirectMusicSynthSinkImpl_QueryInterface,
180 IDirectMusicSynthSinkImpl_AddRef,
181 IDirectMusicSynthSinkImpl_Release,
182 IDirectMusicSynthSinkImpl_Init,
183 IDirectMusicSynthSinkImpl_SetMasterClock,
184 IDirectMusicSynthSinkImpl_GetLatencyClock,
185 IDirectMusicSynthSinkImpl_Activate,
186 IDirectMusicSynthSinkImpl_SampleToRefTime,
187 IDirectMusicSynthSinkImpl_RefTimeToSample,
188 IDirectMusicSynthSinkImpl_SetDirectSound,
189 IDirectMusicSynthSinkImpl_GetDesiredBufferSize
192 static inline IDirectMusicSynthSinkImpl *impl_from_IKsControl(IKsControl *iface)
194 return CONTAINING_RECORD(iface, IDirectMusicSynthSinkImpl, IKsControl_iface);
197 static HRESULT WINAPI DMSynthSinkImpl_IKsControl_QueryInterface(IKsControl* iface, REFIID riid, LPVOID *ppobj)
199 IDirectMusicSynthSinkImpl *This = impl_from_IKsControl(iface);
201 return IDirectMusicSynthSinkImpl_QueryInterface(&This->IDirectMusicSynthSink_iface, riid, ppobj);
204 static ULONG WINAPI DMSynthSinkImpl_IKsControl_AddRef(IKsControl* iface)
206 IDirectMusicSynthSinkImpl *This = impl_from_IKsControl(iface);
208 return IDirectMusicSynthSinkImpl_AddRef(&This->IDirectMusicSynthSink_iface);
211 static ULONG WINAPI DMSynthSinkImpl_IKsControl_Release(IKsControl* iface)
213 IDirectMusicSynthSinkImpl *This = impl_from_IKsControl(iface);
215 return IDirectMusicSynthSinkImpl_Release(&This->IDirectMusicSynthSink_iface);
218 static HRESULT WINAPI DMSynthSinkImpl_IKsControl_KsProperty(IKsControl* iface, PKSPROPERTY Property, ULONG PropertyLength, LPVOID PropertyData,
219 ULONG DataLength, ULONG* BytesReturned)
221 TRACE("(%p)->(%p, %u, %p, %u, %p)\n", iface, Property, PropertyLength, PropertyData, DataLength, BytesReturned);
223 TRACE("Property = %s - %u - %u\n", debugstr_guid(&Property->u.s.Set), Property->u.s.Id, Property->u.s.Flags);
225 if (Property->u.s.Flags != KSPROPERTY_TYPE_GET)
227 FIXME("Property flags %u not yet supported\n", Property->u.s.Flags);
228 return S_FALSE;
231 if (DataLength < sizeof(DWORD))
232 return E_NOT_SUFFICIENT_BUFFER;
234 if (IsEqualGUID(&Property->u.s.Set, &GUID_DMUS_PROP_SinkUsesDSound))
236 *(DWORD*)PropertyData = TRUE;
237 *BytesReturned = sizeof(DWORD);
239 else
241 FIXME("Unknown property %s\n", debugstr_guid(&Property->u.s.Set));
242 *(DWORD*)PropertyData = FALSE;
243 *BytesReturned = sizeof(DWORD);
246 return S_OK;
249 static HRESULT WINAPI DMSynthSinkImpl_IKsControl_KsMethod(IKsControl* iface, PKSMETHOD Method, ULONG MethodLength, LPVOID MethodData,
250 ULONG DataLength, ULONG* BytesReturned)
252 FIXME("(%p)->(%p, %u, %p, %u, %p): stub\n", iface, Method, MethodLength, MethodData, DataLength, BytesReturned);
254 return E_NOTIMPL;
257 static HRESULT WINAPI DMSynthSinkImpl_IKsControl_KsEvent(IKsControl* iface, PKSEVENT Event, ULONG EventLength, LPVOID EventData,
258 ULONG DataLength, ULONG* BytesReturned)
260 FIXME("(%p)->(%p, %u, %p, %u, %p): stub\n", iface, Event, EventLength, EventData, DataLength, BytesReturned);
262 return E_NOTIMPL;
266 static const IKsControlVtbl DMSynthSinkImpl_IKsControl_Vtbl = {
267 DMSynthSinkImpl_IKsControl_QueryInterface,
268 DMSynthSinkImpl_IKsControl_AddRef,
269 DMSynthSinkImpl_IKsControl_Release,
270 DMSynthSinkImpl_IKsControl_KsProperty,
271 DMSynthSinkImpl_IKsControl_KsMethod,
272 DMSynthSinkImpl_IKsControl_KsEvent
275 /* for ClassFactory */
276 HRESULT WINAPI DMUSIC_CreateDirectMusicSynthSinkImpl(REFIID riid, void **ret_iface)
278 IDirectMusicSynthSinkImpl *obj;
279 HRESULT hr;
281 TRACE("(%s, %p)\n", debugstr_guid(riid), ret_iface);
283 *ret_iface = NULL;
285 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicSynthSinkImpl));
286 if (!obj)
287 return E_OUTOFMEMORY;
289 obj->IDirectMusicSynthSink_iface.lpVtbl = &DirectMusicSynthSink_Vtbl;
290 obj->IKsControl_iface.lpVtbl = &DMSynthSinkImpl_IKsControl_Vtbl;
291 obj->ref = 1;
293 hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&obj->latency_clock);
294 if (FAILED(hr))
296 HeapFree(GetProcessHeap(), 0, obj);
297 return hr;
300 DMSYNTH_LockModule();
301 hr = IDirectMusicSynthSink_QueryInterface(&obj->IDirectMusicSynthSink_iface, riid, ret_iface);
302 IDirectMusicSynthSink_Release(&obj->IDirectMusicSynthSink_iface);
304 return hr;