storage.dll16: Fix get_nth_next_small_blocknr.
[wine.git] / dlls / dmsynth / synthsink.c
blob7d148b0e9fc5e1b0d5cdd942d4e99b8411147a21
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(LPDIRECTMUSICSYNTHSINK iface, REFIID riid, LPVOID *ret_iface)
38 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
40 TRACE("(%p)->(%s, %p)\n", iface, debugstr_dmguid(riid), ret_iface);
42 if (IsEqualIID (riid, &IID_IUnknown) ||
43 IsEqualIID (riid, &IID_IDirectMusicSynthSink))
45 IUnknown_AddRef(iface);
46 *ret_iface = iface;
47 return S_OK;
49 else if (IsEqualIID(riid, &IID_IKsControl))
51 IUnknown_AddRef(iface);
52 *ret_iface = &This->IKsControl_iface;
53 return S_OK;
56 *ret_iface = NULL;
58 WARN("(%p)->(%s, %p): not found\n", iface, debugstr_dmguid(riid), ret_iface);
60 return E_NOINTERFACE;
63 static ULONG WINAPI IDirectMusicSynthSinkImpl_AddRef(LPDIRECTMUSICSYNTHSINK iface)
65 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
66 ULONG ref = InterlockedIncrement(&This->ref);
68 TRACE("(%p)->(): new ref = %u\n", This, ref);
70 return 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);
80 if (!ref) {
81 if (This->latency_clock)
82 IReferenceClock_Release(This->latency_clock);
83 HeapFree(GetProcessHeap(), 0, This);
84 DMSYNTH_UnlockModule();
87 return ref;
90 /* IDirectMusicSynthSinkImpl IDirectMusicSynthSink part: */
91 static HRESULT WINAPI IDirectMusicSynthSinkImpl_Init(LPDIRECTMUSICSYNTHSINK iface, IDirectMusicSynth* synth)
93 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
95 FIXME("(%p)->(%p): stub\n", This, synth);
97 return S_OK;
100 static HRESULT WINAPI IDirectMusicSynthSinkImpl_SetMasterClock(LPDIRECTMUSICSYNTHSINK iface, IReferenceClock* clock)
102 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
104 FIXME("(%p)->(%p): stub\n", This, clock);
106 return S_OK;
109 static HRESULT WINAPI IDirectMusicSynthSinkImpl_GetLatencyClock(LPDIRECTMUSICSYNTHSINK iface, IReferenceClock** clock)
111 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
113 TRACE("(%p)->(%p)\n", iface, clock);
115 if (!clock)
116 return E_POINTER;
118 *clock = This->latency_clock;
119 IReferenceClock_AddRef(This->latency_clock);
121 return S_OK;
124 static HRESULT WINAPI IDirectMusicSynthSinkImpl_Activate(LPDIRECTMUSICSYNTHSINK iface, BOOL enable)
126 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
128 FIXME("(%p)->(%d): stub\n", This, enable);
130 return S_OK;
133 static HRESULT WINAPI IDirectMusicSynthSinkImpl_SampleToRefTime(LPDIRECTMUSICSYNTHSINK iface, LONGLONG sample_time, REFERENCE_TIME* ref_time)
135 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
137 FIXME("(%p)->(0x%s, %p): stub\n", This, wine_dbgstr_longlong(sample_time), ref_time);
139 return S_OK;
142 static HRESULT WINAPI IDirectMusicSynthSinkImpl_RefTimeToSample(LPDIRECTMUSICSYNTHSINK iface, REFERENCE_TIME ref_time, LONGLONG* sample_time)
144 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
146 FIXME("(%p)->(0x%s, %p): stub\n", This, wine_dbgstr_longlong(ref_time), sample_time);
148 return S_OK;
151 static HRESULT WINAPI IDirectMusicSynthSinkImpl_SetDirectSound(LPDIRECTMUSICSYNTHSINK iface, LPDIRECTSOUND dsound, LPDIRECTSOUNDBUFFER dsound_buffer)
153 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
155 FIXME("(%p)->(%p, %p): stub\n", This, dsound, dsound_buffer);
157 return S_OK;
160 static HRESULT WINAPI IDirectMusicSynthSinkImpl_GetDesiredBufferSize(LPDIRECTMUSICSYNTHSINK iface, LPDWORD buffer_size_in_samples)
162 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
164 FIXME("(%p)->(%p): stub\n", This, buffer_size_in_samples);
166 return S_OK;
169 static const IDirectMusicSynthSinkVtbl DirectMusicSynthSink_Vtbl = {
170 IDirectMusicSynthSinkImpl_QueryInterface,
171 IDirectMusicSynthSinkImpl_AddRef,
172 IDirectMusicSynthSinkImpl_Release,
173 IDirectMusicSynthSinkImpl_Init,
174 IDirectMusicSynthSinkImpl_SetMasterClock,
175 IDirectMusicSynthSinkImpl_GetLatencyClock,
176 IDirectMusicSynthSinkImpl_Activate,
177 IDirectMusicSynthSinkImpl_SampleToRefTime,
178 IDirectMusicSynthSinkImpl_RefTimeToSample,
179 IDirectMusicSynthSinkImpl_SetDirectSound,
180 IDirectMusicSynthSinkImpl_GetDesiredBufferSize
183 static inline IDirectMusicSynthSinkImpl *impl_from_IKsControl(IKsControl *iface)
185 return CONTAINING_RECORD(iface, IDirectMusicSynthSinkImpl, IKsControl_iface);
188 static HRESULT WINAPI DMSynthSinkImpl_IKsControl_QueryInterface(IKsControl* iface, REFIID riid, LPVOID *ppobj)
190 IDirectMusicSynthSinkImpl *This = impl_from_IKsControl(iface);
192 return IDirectMusicSynthSinkImpl_QueryInterface(&This->IDirectMusicSynthSink_iface, riid, ppobj);
195 static ULONG WINAPI DMSynthSinkImpl_IKsControl_AddRef(IKsControl* iface)
197 IDirectMusicSynthSinkImpl *This = impl_from_IKsControl(iface);
199 return IDirectMusicSynthSinkImpl_AddRef(&This->IDirectMusicSynthSink_iface);
202 static ULONG WINAPI DMSynthSinkImpl_IKsControl_Release(IKsControl* iface)
204 IDirectMusicSynthSinkImpl *This = impl_from_IKsControl(iface);
206 return IDirectMusicSynthSinkImpl_Release(&This->IDirectMusicSynthSink_iface);
209 static HRESULT WINAPI DMSynthSinkImpl_IKsControl_KsProperty(IKsControl* iface, PKSPROPERTY Property, ULONG PropertyLength, LPVOID PropertyData,
210 ULONG DataLength, ULONG* BytesReturned)
212 TRACE("(%p)->(%p, %u, %p, %u, %p)\n", iface, Property, PropertyLength, PropertyData, DataLength, BytesReturned);
214 TRACE("Property = %s - %u - %u\n", debugstr_guid(&Property->u.s.Set), Property->u.s.Id, Property->u.s.Flags);
216 if (Property->u.s.Flags != KSPROPERTY_TYPE_GET)
218 FIXME("Property flags %u not yet supported\n", Property->u.s.Flags);
219 return S_FALSE;
222 if (DataLength < sizeof(DWORD))
223 return E_NOT_SUFFICIENT_BUFFER;
225 if (IsEqualGUID(&Property->u.s.Set, &GUID_DMUS_PROP_SinkUsesDSound))
227 *(DWORD*)PropertyData = TRUE;
228 *BytesReturned = sizeof(DWORD);
230 else
232 FIXME("Unknown property %s\n", debugstr_guid(&Property->u.s.Set));
233 *(DWORD*)PropertyData = FALSE;
234 *BytesReturned = sizeof(DWORD);
237 return S_OK;
240 static HRESULT WINAPI DMSynthSinkImpl_IKsControl_KsMethod(IKsControl* iface, PKSMETHOD Method, ULONG MethodLength, LPVOID MethodData,
241 ULONG DataLength, ULONG* BytesReturned)
243 FIXME("(%p)->(%p, %u, %p, %u, %p): stub\n", iface, Method, MethodLength, MethodData, DataLength, BytesReturned);
245 return E_NOTIMPL;
248 static HRESULT WINAPI DMSynthSinkImpl_IKsControl_KsEvent(IKsControl* iface, PKSEVENT Event, ULONG EventLength, LPVOID EventData,
249 ULONG DataLength, ULONG* BytesReturned)
251 FIXME("(%p)->(%p, %u, %p, %u, %p): stub\n", iface, Event, EventLength, EventData, DataLength, BytesReturned);
253 return E_NOTIMPL;
257 static const IKsControlVtbl DMSynthSinkImpl_IKsControl_Vtbl = {
258 DMSynthSinkImpl_IKsControl_QueryInterface,
259 DMSynthSinkImpl_IKsControl_AddRef,
260 DMSynthSinkImpl_IKsControl_Release,
261 DMSynthSinkImpl_IKsControl_KsProperty,
262 DMSynthSinkImpl_IKsControl_KsMethod,
263 DMSynthSinkImpl_IKsControl_KsEvent
266 /* for ClassFactory */
267 HRESULT WINAPI DMUSIC_CreateDirectMusicSynthSinkImpl(REFIID riid, void **ret_iface)
269 IDirectMusicSynthSinkImpl *obj;
270 HRESULT hr;
272 TRACE("(%s, %p)\n", debugstr_guid(riid), ret_iface);
274 *ret_iface = NULL;
276 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicSynthSinkImpl));
277 if (!obj)
278 return E_OUTOFMEMORY;
280 obj->IDirectMusicSynthSink_iface.lpVtbl = &DirectMusicSynthSink_Vtbl;
281 obj->IKsControl_iface.lpVtbl = &DMSynthSinkImpl_IKsControl_Vtbl;
282 obj->ref = 1;
284 hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&obj->latency_clock);
285 if (FAILED(hr))
287 HeapFree(GetProcessHeap(), 0, obj);
288 return hr;
291 DMSYNTH_LockModule();
292 hr = IDirectMusicSynthSink_QueryInterface(&obj->IDirectMusicSynthSink_iface, riid, ret_iface);
293 IDirectMusicSynthSink_Release(&obj->IDirectMusicSynthSink_iface);
295 return hr;