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"
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
);
49 else if (IsEqualIID(riid
, &IID_IKsControl
))
51 IUnknown_AddRef(iface
);
52 *ret_iface
= &This
->IKsControl_iface
;
58 WARN("(%p)->(%s, %p): not found\n", iface
, debugstr_dmguid(riid
), ret_iface
);
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
);
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
);
83 if (This
->latency_clock
)
84 IReferenceClock_Release(This
->latency_clock
);
85 HeapFree(GetProcessHeap(), 0, This
);
88 DMSYNTH_UnlockModule();
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
);
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
);
112 static HRESULT WINAPI
IDirectMusicSynthSinkImpl_GetLatencyClock(LPDIRECTMUSICSYNTHSINK iface
, IReferenceClock
** clock
)
114 IDirectMusicSynthSinkImpl
*This
= impl_from_IDirectMusicSynthSink(iface
);
116 TRACE("(%p)->(%p)\n", iface
, clock
);
121 *clock
= This
->latency_clock
;
122 IReferenceClock_AddRef(This
->latency_clock
);
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
);
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
);
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
);
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
);
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
);
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
);
225 if (DataLength
< sizeof(DWORD
))
226 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
228 if (IsEqualGUID(&Property
->u
.s
.Set
, &GUID_DMUS_PROP_SinkUsesDSound
))
230 *(DWORD
*)PropertyData
= TRUE
;
231 *BytesReturned
= sizeof(DWORD
);
235 FIXME("Unknown property %s\n", debugstr_guid(&Property
->u
.s
.Set
));
236 *(DWORD
*)PropertyData
= FALSE
;
237 *BytesReturned
= sizeof(DWORD
);
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
);
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
);
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
;
275 TRACE("(%p,%p,%p)\n", riid
, ret_iface
, unkouter
);
279 obj
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectMusicSynthSinkImpl
));
281 return E_OUTOFMEMORY
;
283 obj
->IDirectMusicSynthSink_iface
.lpVtbl
= &DirectMusicSynthSink_Vtbl
;
284 obj
->IKsControl_iface
.lpVtbl
= &DMSynthSinkImpl_IKsControl_Vtbl
;
287 hr
= CoCreateInstance(&CLSID_SystemClock
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IReferenceClock
, (LPVOID
*)&obj
->latency_clock
);
290 HeapFree(GetProcessHeap(), 0, obj
);
294 hr
= IDirectMusicSynthSinkImpl_QueryInterface((LPDIRECTMUSICSYNTHSINK
)obj
, riid
, ret_iface
);
297 IReferenceClock_Release(obj
->latency_clock
);
298 HeapFree(GetProcessHeap(), 0, obj
);