mshtml: Added IHTMLBodyElement::onload property implementation.
[wine] / dlls / dmsynth / synthsink.c
1 /*
2  * IDirectMusicSynthSink Implementation
3  *
4  * Copyright (C) 2003-2004 Rok Mandeljc
5  * Copyright (C) 2012 Christian Costa
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #include "dmsynth_private.h"
23 #include "initguid.h"
24 #include "uuids.h"
25
26 WINE_DEFAULT_DEBUG_CHANNEL(dmsynth);
27
28 static inline IDirectMusicSynthSinkImpl *impl_from_IDirectMusicSynthSink(IDirectMusicSynthSink *iface)
29 {
30     return CONTAINING_RECORD(iface, IDirectMusicSynthSinkImpl, IDirectMusicSynthSink_iface);
31 }
32
33 /* IDirectMusicSynthSinkImpl IUnknown part: */
34 static HRESULT WINAPI IDirectMusicSynthSinkImpl_QueryInterface(LPDIRECTMUSICSYNTHSINK iface, REFIID riid, LPVOID *ret_iface)
35 {
36     IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
37
38     TRACE("(%p)->(%s, %p)\n", iface, debugstr_dmguid(riid), ret_iface);
39
40     if (IsEqualIID (riid, &IID_IUnknown) ||
41         IsEqualIID (riid, &IID_IDirectMusicSynthSink))
42     {
43         IUnknown_AddRef(iface);
44         *ret_iface = iface;
45         return S_OK;
46     }
47     else if (IsEqualIID(riid, &IID_IKsControl))
48     {
49         IUnknown_AddRef(iface);
50         *ret_iface = &This->IKsControl_iface;
51         return S_OK;
52     }
53
54     *ret_iface = NULL;
55
56     WARN("(%p)->(%s, %p): not found\n", iface, debugstr_dmguid(riid), ret_iface);
57
58     return E_NOINTERFACE;
59 }
60
61 static ULONG WINAPI IDirectMusicSynthSinkImpl_AddRef(LPDIRECTMUSICSYNTHSINK iface)
62 {
63     IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
64     ULONG ref = InterlockedIncrement(&This->ref);
65
66     TRACE("(%p)->(): new ref = %u\n", This, ref);
67
68     DMSYNTH_LockModule();
69
70     return ref;
71 }
72
73 static ULONG WINAPI IDirectMusicSynthSinkImpl_Release(LPDIRECTMUSICSYNTHSINK iface)
74 {
75     IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
76     ULONG ref = InterlockedDecrement(&This->ref);
77
78     TRACE("(%p)->(): new ref = %u\n", This, ref);
79
80     if (!ref) {
81         if (This->latency_clock)
82             IReferenceClock_Release(This->latency_clock);
83         HeapFree(GetProcessHeap(), 0, This);
84     }
85
86     DMSYNTH_UnlockModule();
87
88     return ref;
89 }
90
91 /* IDirectMusicSynthSinkImpl IDirectMusicSynthSink part: */
92 static HRESULT WINAPI IDirectMusicSynthSinkImpl_Init(LPDIRECTMUSICSYNTHSINK iface, IDirectMusicSynth* synth)
93 {
94     IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
95
96     FIXME("(%p)->(%p): stub\n", This, synth);
97
98     return S_OK;
99 }
100
101 static HRESULT WINAPI IDirectMusicSynthSinkImpl_SetMasterClock(LPDIRECTMUSICSYNTHSINK iface, IReferenceClock* clock)
102 {
103     IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
104
105     FIXME("(%p)->(%p): stub\n", This, clock);
106
107     return S_OK;
108 }
109
110 static HRESULT WINAPI IDirectMusicSynthSinkImpl_GetLatencyClock(LPDIRECTMUSICSYNTHSINK iface, IReferenceClock** clock)
111 {
112     IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
113
114     TRACE("(%p)->(%p)\n", iface, clock);
115
116     if (!clock)
117         return E_POINTER;
118
119     *clock = This->latency_clock;
120     IReferenceClock_AddRef(This->latency_clock);
121
122     return S_OK;
123 }
124
125 static HRESULT WINAPI IDirectMusicSynthSinkImpl_Activate(LPDIRECTMUSICSYNTHSINK iface, BOOL enable)
126 {
127     IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
128
129     FIXME("(%p)->(%d): stub\n", This, enable);
130
131     return S_OK;
132 }
133
134 static HRESULT WINAPI IDirectMusicSynthSinkImpl_SampleToRefTime(LPDIRECTMUSICSYNTHSINK iface, LONGLONG sample_time, REFERENCE_TIME* ref_time)
135 {
136     IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
137
138     FIXME("(%p)->(0x%s, %p): stub\n", This, wine_dbgstr_longlong(sample_time), ref_time);
139
140     return S_OK;
141 }
142
143 static HRESULT WINAPI IDirectMusicSynthSinkImpl_RefTimeToSample(LPDIRECTMUSICSYNTHSINK iface, REFERENCE_TIME ref_time, LONGLONG* sample_time)
144 {
145     IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
146
147     FIXME("(%p)->(0x%s, %p): stub\n", This, wine_dbgstr_longlong(ref_time), sample_time);
148
149     return S_OK;
150 }
151
152 static HRESULT WINAPI IDirectMusicSynthSinkImpl_SetDirectSound(LPDIRECTMUSICSYNTHSINK iface, LPDIRECTSOUND dsound, LPDIRECTSOUNDBUFFER dsound_buffer)
153 {
154     IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
155
156     FIXME("(%p)->(%p, %p): stub\n", This, dsound, dsound_buffer);
157
158     return S_OK;
159 }
160
161 static HRESULT WINAPI IDirectMusicSynthSinkImpl_GetDesiredBufferSize(LPDIRECTMUSICSYNTHSINK iface, LPDWORD buffer_size_in_samples)
162 {
163     IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
164
165     FIXME("(%p)->(%p): stub\n", This, buffer_size_in_samples);
166
167     return S_OK;
168 }
169
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
182 };
183
184 static inline IDirectMusicSynthSinkImpl *impl_from_IKsControl(IKsControl *iface)
185 {
186     return CONTAINING_RECORD(iface, IDirectMusicSynthSinkImpl, IKsControl_iface);
187 }
188
189 static HRESULT WINAPI DMSynthSinkImpl_IKsControl_QueryInterface(IKsControl* iface, REFIID riid, LPVOID *ppobj)
190 {
191     IDirectMusicSynthSinkImpl *This = impl_from_IKsControl(iface);
192
193     return IDirectMusicSynthSinkImpl_QueryInterface(&This->IDirectMusicSynthSink_iface, riid, ppobj);
194 }
195
196 static ULONG WINAPI DMSynthSinkImpl_IKsControl_AddRef(IKsControl* iface)
197 {
198     IDirectMusicSynthSinkImpl *This = impl_from_IKsControl(iface);
199
200     return IDirectMusicSynthSinkImpl_AddRef(&This->IDirectMusicSynthSink_iface);
201 }
202
203 static ULONG WINAPI DMSynthSinkImpl_IKsControl_Release(IKsControl* iface)
204 {
205     IDirectMusicSynthSinkImpl *This = impl_from_IKsControl(iface);
206
207     return IDirectMusicSynthSinkImpl_Release(&This->IDirectMusicSynthSink_iface);
208 }
209
210 static HRESULT WINAPI DMSynthSinkImpl_IKsControl_KsProperty(IKsControl* iface, PKSPROPERTY Property, ULONG PropertyLength, LPVOID PropertyData,
211                                                             ULONG DataLength, ULONG* BytesReturned)
212 {
213     TRACE("(%p)->(%p, %u, %p, %u, %p)\n", iface, Property, PropertyLength, PropertyData, DataLength, BytesReturned);
214
215     TRACE("Property = %s - %u - %u\n", debugstr_guid(&Property->Set), Property->Id, Property->Flags);
216
217     if (Property->Flags != KSPROPERTY_TYPE_GET)
218     {
219         FIXME("Property flags %u not yet supported\n", Property->Flags);
220         return S_FALSE;
221     }
222
223     if (DataLength <  sizeof(DWORD))
224         return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
225
226     if (IsEqualGUID(&Property->Set, &GUID_DMUS_PROP_SinkUsesDSound))
227     {
228         *(DWORD*)PropertyData = TRUE;
229         *BytesReturned = sizeof(DWORD);
230     }
231     else
232     {
233         FIXME("Unknown property %s\n", debugstr_guid(&Property->Set));
234         *(DWORD*)PropertyData = FALSE;
235         *BytesReturned = sizeof(DWORD);
236     }
237
238     return S_OK;
239 }
240
241 static HRESULT WINAPI DMSynthSinkImpl_IKsControl_KsMethod(IKsControl* iface, PKSMETHOD Method, ULONG MethodLength, LPVOID MethodData,
242                                                           ULONG DataLength, ULONG* BytesReturned)
243 {
244     FIXME("(%p)->(%p, %u, %p, %u, %p): stub\n", iface, Method, MethodLength, MethodData, DataLength, BytesReturned);
245
246     return E_NOTIMPL;
247 }
248
249 static HRESULT WINAPI DMSynthSinkImpl_IKsControl_KsEvent(IKsControl* iface, PKSEVENT Event, ULONG EventLength, LPVOID EventData,
250                                                          ULONG DataLength, ULONG* BytesReturned)
251 {
252     FIXME("(%p)->(%p, %u, %p, %u, %p): stub\n", iface, Event, EventLength, EventData, DataLength, BytesReturned);
253
254     return E_NOTIMPL;
255 }
256
257
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
265 };
266
267 /* for ClassFactory */
268 HRESULT WINAPI DMUSIC_CreateDirectMusicSynthSinkImpl(LPCGUID riid, LPVOID* ret_iface, LPUNKNOWN unkouter)
269 {
270     IDirectMusicSynthSinkImpl *obj;
271     HRESULT hr;
272
273     TRACE("(%p,%p,%p)\n", riid, ret_iface, unkouter);
274
275     *ret_iface = NULL;
276
277     obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicSynthSinkImpl));
278     if (!obj)
279         return E_OUTOFMEMORY;
280
281     obj->IDirectMusicSynthSink_iface.lpVtbl = &DirectMusicSynthSink_Vtbl;
282     obj->IKsControl_iface.lpVtbl = &DMSynthSinkImpl_IKsControl_Vtbl;
283     obj->ref = 0;
284
285     hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&obj->latency_clock);
286     if (FAILED(hr))
287     {
288         HeapFree(GetProcessHeap(), 0, obj);
289         return hr;
290     }
291
292     hr = IDirectMusicSynthSinkImpl_QueryInterface((LPDIRECTMUSICSYNTHSINK)obj, riid, ret_iface);
293     if (FAILED(hr))
294     {
295         IReferenceClock_Release(obj->latency_clock);
296         HeapFree(GetProcessHeap(), 0, obj);
297         return hr;
298     }
299
300     return S_OK;
301 }