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
);
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
);
81 if (This
->latency_clock
)
82 IReferenceClock_Release(This
->latency_clock
);
83 HeapFree(GetProcessHeap(), 0, This
);
84 DMSYNTH_UnlockModule();
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
);
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
);
109 static HRESULT WINAPI
IDirectMusicSynthSinkImpl_GetLatencyClock(LPDIRECTMUSICSYNTHSINK iface
, IReferenceClock
** clock
)
111 IDirectMusicSynthSinkImpl
*This
= impl_from_IDirectMusicSynthSink(iface
);
113 TRACE("(%p)->(%p)\n", iface
, clock
);
118 *clock
= This
->latency_clock
;
119 IReferenceClock_AddRef(This
->latency_clock
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
232 FIXME("Unknown property %s\n", debugstr_guid(&Property
->u
.s
.Set
));
233 *(DWORD
*)PropertyData
= FALSE
;
234 *BytesReturned
= sizeof(DWORD
);
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
);
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
);
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
;
272 TRACE("(%s, %p)\n", debugstr_guid(riid
), ret_iface
);
276 obj
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectMusicSynthSinkImpl
));
278 return E_OUTOFMEMORY
;
280 obj
->IDirectMusicSynthSink_iface
.lpVtbl
= &DirectMusicSynthSink_Vtbl
;
281 obj
->IKsControl_iface
.lpVtbl
= &DMSynthSinkImpl_IKsControl_Vtbl
;
284 hr
= CoCreateInstance(&CLSID_SystemClock
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IReferenceClock
, (LPVOID
*)&obj
->latency_clock
);
287 HeapFree(GetProcessHeap(), 0, obj
);
291 DMSYNTH_LockModule();
292 hr
= IDirectMusicSynthSink_QueryInterface(&obj
->IDirectMusicSynthSink_iface
, riid
, ret_iface
);
293 IDirectMusicSynthSink_Release(&obj
->IDirectMusicSynthSink_iface
);