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 WINE_DEFAULT_DEBUG_CHANNEL(dmusic); 24 25 static inline IReferenceClockImpl *impl_from_IReferenceClock(IReferenceClock *iface) 26 { 27 return CONTAINING_RECORD(iface, IReferenceClockImpl, IReferenceClock_iface); 28 } 29 30 /* IReferenceClockImpl IUnknown part: */ 31 static HRESULT WINAPI IReferenceClockImpl_QueryInterface(IReferenceClock *iface, REFIID riid, LPVOID *ppobj) 32 { 33 IReferenceClockImpl *This = impl_from_IReferenceClock(iface); 34 TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj); 35 36 if (IsEqualIID (riid, &IID_IUnknown) || 37 IsEqualIID (riid, &IID_IReferenceClock)) { 38 IUnknown_AddRef(iface); 39 *ppobj = This; 40 return S_OK; 41 } 42 WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj); 43 return E_NOINTERFACE; 44 } 45 46 static ULONG WINAPI IReferenceClockImpl_AddRef(IReferenceClock *iface) 47 { 48 IReferenceClockImpl *This = impl_from_IReferenceClock(iface); 49 ULONG ref = InterlockedIncrement(&This->ref); 50 51 TRACE("(%p)->(): new ref = %u\n", This, ref); 52 53 return ref; 54 } 55 56 static ULONG WINAPI IReferenceClockImpl_Release(IReferenceClock *iface) 57 { 58 IReferenceClockImpl *This = impl_from_IReferenceClock(iface); 59 ULONG ref = InterlockedDecrement(&This->ref); 60 61 TRACE("(%p)->(): new ref = %u\n", This, ref); 62 63 if (!ref) { 64 HeapFree(GetProcessHeap(), 0, This); 65 DMUSIC_UnlockModule(); 66 } 67 68 return ref; 69 } 70 71 /* IReferenceClockImpl IReferenceClock part: */ 72 static HRESULT WINAPI IReferenceClockImpl_GetTime(IReferenceClock *iface, REFERENCE_TIME* pTime) 73 { 74 IReferenceClockImpl *This = impl_from_IReferenceClock(iface); 75 76 TRACE("(%p)->(%p)\n", This, pTime); 77 78 *pTime = This->rtTime; 79 80 return S_OK; 81 } 82 83 static HRESULT WINAPI IReferenceClockImpl_AdviseTime(IReferenceClock *iface, REFERENCE_TIME baseTime, REFERENCE_TIME streamTime, HANDLE hEvent, DWORD* pdwAdviseCookie) 84 { 85 IReferenceClockImpl *This = impl_from_IReferenceClock(iface); 86 87 FIXME("(%p)->(0x%s, 0x%s, %p, %p): stub\n", This, wine_dbgstr_longlong(baseTime), wine_dbgstr_longlong(streamTime), hEvent, pdwAdviseCookie); 88 89 return S_OK; 90 } 91 92 static HRESULT WINAPI IReferenceClockImpl_AdvisePeriodic(IReferenceClock *iface, REFERENCE_TIME startTime, REFERENCE_TIME periodTime, HANDLE hSemaphore, DWORD* pdwAdviseCookie) 93 { 94 IReferenceClockImpl *This = impl_from_IReferenceClock(iface); 95 96 FIXME("(%p)->(0x%s, 0x%s, %p, %p): stub\n", This, wine_dbgstr_longlong(startTime), wine_dbgstr_longlong(periodTime), hSemaphore, pdwAdviseCookie); 97 98 return S_OK; 99 } 100 101 static HRESULT WINAPI IReferenceClockImpl_Unadvise(IReferenceClock *iface, DWORD dwAdviseCookie) 102 { 103 IReferenceClockImpl *This = impl_from_IReferenceClock(iface); 104 105 FIXME("(%p)->(%d): stub\n", This, dwAdviseCookie); 106 107 return S_OK; 108 } 109 110 static const IReferenceClockVtbl ReferenceClock_Vtbl = { 111 IReferenceClockImpl_QueryInterface, 112 IReferenceClockImpl_AddRef, 113 IReferenceClockImpl_Release, 114 IReferenceClockImpl_GetTime, 115 IReferenceClockImpl_AdviseTime, 116 IReferenceClockImpl_AdvisePeriodic, 117 IReferenceClockImpl_Unadvise 118 }; 119 120 /* for ClassFactory */ 121 HRESULT DMUSIC_CreateReferenceClockImpl(LPCGUID riid, LPVOID* ret_iface, LPUNKNOWN unkouter) 122 { 123 IReferenceClockImpl* clock; 124 HRESULT hr; 125 126 TRACE("(%s, %p, %p)\n", debugstr_guid(riid), ret_iface, unkouter); 127 128 clock = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IReferenceClockImpl)); 129 if (!clock) { 130 *ret_iface = NULL; 131 return E_OUTOFMEMORY; 132 } 133 134 clock->IReferenceClock_iface.lpVtbl = &ReferenceClock_Vtbl; 135 clock->ref = 1; 136 clock->rtTime = 0; 137 clock->pClockInfo.dwSize = sizeof (DMUS_CLOCKINFO); 138 139 DMUSIC_LockModule(); 140 hr = IReferenceClockImpl_QueryInterface(&clock->IReferenceClock_iface, riid, ret_iface); 141 IReferenceClock_Release(&clock->IReferenceClock_iface); 142 143 return hr; 144 } 145