msvcirt: Add implementation of streambuf::sputbackc.
[wine.git] / dlls / dmsynth / synthsink.c
blob498c39067b848c79bd2d49eff59e08e616be784e
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 DMSYNTH_LockModule();
72 return ref;
75 static ULONG WINAPI IDirectMusicSynthSinkImpl_Release(LPDIRECTMUSICSYNTHSINK iface)
77 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
78 ULONG ref = InterlockedDecrement(&This->ref);
80 TRACE("(%p)->(): new ref = %u\n", This, ref);
82 if (!ref) {
83 if (This->latency_clock)
84 IReferenceClock_Release(This->latency_clock);
85 HeapFree(GetProcessHeap(), 0, This);
88 DMSYNTH_UnlockModule();
90 return ref;
93 /* IDirectMusicSynthSinkImpl IDirectMusicSynthSink part: */
94 static HRESULT WINAPI IDirectMusicSynthSinkImpl_Init(LPDIRECTMUSICSYNTHSINK iface, IDirectMusicSynth* synth)
96 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
98 FIXME("(%p)->(%p): stub\n", This, synth);
100 return S_OK;
103 static HRESULT WINAPI IDirectMusicSynthSinkImpl_SetMasterClock(LPDIRECTMUSICSYNTHSINK iface, 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(LPDIRECTMUSICSYNTHSINK iface, IReferenceClock** clock)
114 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
116 TRACE("(%p)->(%p)\n", iface, clock);
118 if (!clock)
119 return E_POINTER;
121 *clock = This->latency_clock;
122 IReferenceClock_AddRef(This->latency_clock);
124 return S_OK;
127 static HRESULT WINAPI IDirectMusicSynthSinkImpl_Activate(LPDIRECTMUSICSYNTHSINK iface, BOOL enable)
129 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
131 FIXME("(%p)->(%d): stub\n", This, enable);
133 return S_OK;
136 static HRESULT WINAPI IDirectMusicSynthSinkImpl_SampleToRefTime(LPDIRECTMUSICSYNTHSINK iface, LONGLONG sample_time, REFERENCE_TIME* ref_time)
138 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
140 FIXME("(%p)->(0x%s, %p): stub\n", This, wine_dbgstr_longlong(sample_time), ref_time);
142 return S_OK;
145 static HRESULT WINAPI IDirectMusicSynthSinkImpl_RefTimeToSample(LPDIRECTMUSICSYNTHSINK iface, REFERENCE_TIME ref_time, LONGLONG* sample_time)
147 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
149 FIXME("(%p)->(0x%s, %p): stub\n", This, wine_dbgstr_longlong(ref_time), sample_time);
151 return S_OK;
154 static HRESULT WINAPI IDirectMusicSynthSinkImpl_SetDirectSound(LPDIRECTMUSICSYNTHSINK iface, LPDIRECTSOUND dsound, LPDIRECTSOUNDBUFFER dsound_buffer)
156 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
158 FIXME("(%p)->(%p, %p): stub\n", This, dsound, dsound_buffer);
160 return S_OK;
163 static HRESULT WINAPI IDirectMusicSynthSinkImpl_GetDesiredBufferSize(LPDIRECTMUSICSYNTHSINK iface, LPDWORD buffer_size_in_samples)
165 IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
167 FIXME("(%p)->(%p): stub\n", This, buffer_size_in_samples);
169 return S_OK;
172 static const IDirectMusicSynthSinkVtbl DirectMusicSynthSink_Vtbl = {
173 IDirectMusicSynthSinkImpl_QueryInterface,
174 IDirectMusicSynthSinkImpl_AddRef,
175 IDirectMusicSynthSinkImpl_Release,
176 IDirectMusicSynthSinkImpl_Init,
177 IDirectMusicSynthSinkImpl_SetMasterClock,
178 IDirectMusicSynthSinkImpl_GetLatencyClock,
179 IDirectMusicSynthSinkImpl_Activate,
180 IDirectMusicSynthSinkImpl_SampleToRefTime,
181 IDirectMusicSynthSinkImpl_RefTimeToSample,
182 IDirectMusicSynthSinkImpl_SetDirectSound,
183 IDirectMusicSynthSinkImpl_GetDesiredBufferSize
186 static inline IDirectMusicSynthSinkImpl *impl_from_IKsControl(IKsControl *iface)
188 return CONTAINING_RECORD(iface, IDirectMusicSynthSinkImpl, IKsControl_iface);
191 static HRESULT WINAPI DMSynthSinkImpl_IKsControl_QueryInterface(IKsControl* iface, REFIID riid, LPVOID *ppobj)
193 IDirectMusicSynthSinkImpl *This = impl_from_IKsControl(iface);
195 return IDirectMusicSynthSinkImpl_QueryInterface(&This->IDirectMusicSynthSink_iface, riid, ppobj);
198 static ULONG WINAPI DMSynthSinkImpl_IKsControl_AddRef(IKsControl* iface)
200 IDirectMusicSynthSinkImpl *This = impl_from_IKsControl(iface);
202 return IDirectMusicSynthSinkImpl_AddRef(&This->IDirectMusicSynthSink_iface);
205 static ULONG WINAPI DMSynthSinkImpl_IKsControl_Release(IKsControl* iface)
207 IDirectMusicSynthSinkImpl *This = impl_from_IKsControl(iface);
209 return IDirectMusicSynthSinkImpl_Release(&This->IDirectMusicSynthSink_iface);
212 static HRESULT WINAPI DMSynthSinkImpl_IKsControl_KsProperty(IKsControl* iface, PKSPROPERTY Property, ULONG PropertyLength, LPVOID PropertyData,
213 ULONG DataLength, ULONG* BytesReturned)
215 TRACE("(%p)->(%p, %u, %p, %u, %p)\n", iface, Property, PropertyLength, PropertyData, DataLength, BytesReturned);
217 TRACE("Property = %s - %u - %u\n", debugstr_guid(&Property->u.s.Set), Property->u.s.Id, Property->u.s.Flags);
219 if (Property->u.s.Flags != KSPROPERTY_TYPE_GET)
221 FIXME("Property flags %u not yet supported\n", Property->u.s.Flags);
222 return S_FALSE;
225 if (DataLength < sizeof(DWORD))
226 return E_NOT_SUFFICIENT_BUFFER;
228 if (IsEqualGUID(&Property->u.s.Set, &GUID_DMUS_PROP_SinkUsesDSound))
230 *(DWORD*)PropertyData = TRUE;
231 *BytesReturned = sizeof(DWORD);
233 else
235 FIXME("Unknown property %s\n", debugstr_guid(&Property->u.s.Set));
236 *(DWORD*)PropertyData = FALSE;
237 *BytesReturned = sizeof(DWORD);
240 return S_OK;
243 static HRESULT WINAPI DMSynthSinkImpl_IKsControl_KsMethod(IKsControl* iface, PKSMETHOD Method, ULONG MethodLength, LPVOID MethodData,
244 ULONG DataLength, ULONG* BytesReturned)
246 FIXME("(%p)->(%p, %u, %p, %u, %p): stub\n", iface, Method, MethodLength, MethodData, DataLength, BytesReturned);
248 return E_NOTIMPL;
251 static HRESULT WINAPI DMSynthSinkImpl_IKsControl_KsEvent(IKsControl* iface, PKSEVENT Event, ULONG EventLength, LPVOID EventData,
252 ULONG DataLength, ULONG* BytesReturned)
254 FIXME("(%p)->(%p, %u, %p, %u, %p): stub\n", iface, Event, EventLength, EventData, DataLength, BytesReturned);
256 return E_NOTIMPL;
260 static const IKsControlVtbl DMSynthSinkImpl_IKsControl_Vtbl = {
261 DMSynthSinkImpl_IKsControl_QueryInterface,
262 DMSynthSinkImpl_IKsControl_AddRef,
263 DMSynthSinkImpl_IKsControl_Release,
264 DMSynthSinkImpl_IKsControl_KsProperty,
265 DMSynthSinkImpl_IKsControl_KsMethod,
266 DMSynthSinkImpl_IKsControl_KsEvent
269 /* for ClassFactory */
270 HRESULT WINAPI DMUSIC_CreateDirectMusicSynthSinkImpl(LPCGUID riid, LPVOID* ret_iface, LPUNKNOWN unkouter)
272 IDirectMusicSynthSinkImpl *obj;
273 HRESULT hr;
275 TRACE("(%p,%p,%p)\n", riid, ret_iface, unkouter);
277 *ret_iface = NULL;
279 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicSynthSinkImpl));
280 if (!obj)
281 return E_OUTOFMEMORY;
283 obj->IDirectMusicSynthSink_iface.lpVtbl = &DirectMusicSynthSink_Vtbl;
284 obj->IKsControl_iface.lpVtbl = &DMSynthSinkImpl_IKsControl_Vtbl;
285 obj->ref = 0;
287 hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&obj->latency_clock);
288 if (FAILED(hr))
290 HeapFree(GetProcessHeap(), 0, obj);
291 return hr;
294 hr = IDirectMusicSynthSinkImpl_QueryInterface((LPDIRECTMUSICSYNTHSINK)obj, riid, ret_iface);
295 if (FAILED(hr))
297 IReferenceClock_Release(obj->latency_clock);
298 HeapFree(GetProcessHeap(), 0, obj);
299 return hr;
302 return S_OK;