[DMUSIC] Sync with Wine Staging 1.9.23. CORE-12409
[reactos.git] / reactos / dll / directx / wine / dmusic / clock.c
1 /*
2 * IReferenceClock Implementation
3 *
4 * Copyright (C) 2003-2004 Rok Mandeljc
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include "dmusic_private.h"
22
23 static inline IReferenceClockImpl *impl_from_IReferenceClock(IReferenceClock *iface)
24 {
25 return CONTAINING_RECORD(iface, IReferenceClockImpl, IReferenceClock_iface);
26 }
27
28 /* IReferenceClockImpl IUnknown part: */
29 static HRESULT WINAPI IReferenceClockImpl_QueryInterface(IReferenceClock *iface, REFIID riid, LPVOID *ppobj)
30 {
31 IReferenceClockImpl *This = impl_from_IReferenceClock(iface);
32 TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
33
34 if (IsEqualIID (riid, &IID_IUnknown) ||
35 IsEqualIID (riid, &IID_IReferenceClock)) {
36 IUnknown_AddRef(iface);
37 *ppobj = This;
38 return S_OK;
39 }
40 WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
41 return E_NOINTERFACE;
42 }
43
44 static ULONG WINAPI IReferenceClockImpl_AddRef(IReferenceClock *iface)
45 {
46 IReferenceClockImpl *This = impl_from_IReferenceClock(iface);
47 ULONG ref = InterlockedIncrement(&This->ref);
48
49 TRACE("(%p)->(): new ref = %u\n", This, ref);
50
51 return ref;
52 }
53
54 static ULONG WINAPI IReferenceClockImpl_Release(IReferenceClock *iface)
55 {
56 IReferenceClockImpl *This = impl_from_IReferenceClock(iface);
57 ULONG ref = InterlockedDecrement(&This->ref);
58
59 TRACE("(%p)->(): new ref = %u\n", This, ref);
60
61 if (!ref) {
62 HeapFree(GetProcessHeap(), 0, This);
63 DMUSIC_UnlockModule();
64 }
65
66 return ref;
67 }
68
69 /* IReferenceClockImpl IReferenceClock part: */
70 static HRESULT WINAPI IReferenceClockImpl_GetTime(IReferenceClock *iface, REFERENCE_TIME* pTime)
71 {
72 IReferenceClockImpl *This = impl_from_IReferenceClock(iface);
73
74 TRACE("(%p)->(%p)\n", This, pTime);
75
76 *pTime = This->rtTime;
77
78 return S_OK;
79 }
80
81 static HRESULT WINAPI IReferenceClockImpl_AdviseTime(IReferenceClock *iface, REFERENCE_TIME baseTime, REFERENCE_TIME streamTime, HANDLE hEvent, DWORD* pdwAdviseCookie)
82 {
83 IReferenceClockImpl *This = impl_from_IReferenceClock(iface);
84
85 FIXME("(%p)->(0x%s, 0x%s, %p, %p): stub\n", This, wine_dbgstr_longlong(baseTime), wine_dbgstr_longlong(streamTime), hEvent, pdwAdviseCookie);
86
87 return S_OK;
88 }
89
90 static HRESULT WINAPI IReferenceClockImpl_AdvisePeriodic(IReferenceClock *iface, REFERENCE_TIME startTime, REFERENCE_TIME periodTime, HANDLE hSemaphore, DWORD* pdwAdviseCookie)
91 {
92 IReferenceClockImpl *This = impl_from_IReferenceClock(iface);
93
94 FIXME("(%p)->(0x%s, 0x%s, %p, %p): stub\n", This, wine_dbgstr_longlong(startTime), wine_dbgstr_longlong(periodTime), hSemaphore, pdwAdviseCookie);
95
96 return S_OK;
97 }
98
99 static HRESULT WINAPI IReferenceClockImpl_Unadvise(IReferenceClock *iface, DWORD dwAdviseCookie)
100 {
101 IReferenceClockImpl *This = impl_from_IReferenceClock(iface);
102
103 FIXME("(%p)->(%d): stub\n", This, dwAdviseCookie);
104
105 return S_OK;
106 }
107
108 static const IReferenceClockVtbl ReferenceClock_Vtbl = {
109 IReferenceClockImpl_QueryInterface,
110 IReferenceClockImpl_AddRef,
111 IReferenceClockImpl_Release,
112 IReferenceClockImpl_GetTime,
113 IReferenceClockImpl_AdviseTime,
114 IReferenceClockImpl_AdvisePeriodic,
115 IReferenceClockImpl_Unadvise
116 };
117
118 /* for ClassFactory */
119 HRESULT DMUSIC_CreateReferenceClockImpl(LPCGUID riid, LPVOID* ret_iface, LPUNKNOWN unkouter)
120 {
121 IReferenceClockImpl* clock;
122 HRESULT hr;
123
124 TRACE("(%s, %p, %p)\n", debugstr_guid(riid), ret_iface, unkouter);
125
126 clock = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IReferenceClockImpl));
127 if (!clock) {
128 *ret_iface = NULL;
129 return E_OUTOFMEMORY;
130 }
131
132 clock->IReferenceClock_iface.lpVtbl = &ReferenceClock_Vtbl;
133 clock->ref = 1;
134 clock->rtTime = 0;
135 clock->pClockInfo.dwSize = sizeof (DMUS_CLOCKINFO);
136
137 DMUSIC_LockModule();
138 hr = IReferenceClockImpl_QueryInterface(&clock->IReferenceClock_iface, riid, ret_iface);
139 IReferenceClock_Release(&clock->IReferenceClock_iface);
140
141 return hr;
142 }