clock.c 4.52 KB
Newer Older
1 2
/*
 * IReferenceClock Implementation
3
 *
4
 * Copyright (C) 2003-2004 Rok Mandeljc
5
 *
6 7 8 9
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
10 11 12
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
15
 *
16 17 18
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 20 21 22 23 24
 */

#include "dmusic_private.h"

WINE_DEFAULT_DEBUG_CHANNEL(dmusic);

25 26 27 28 29
static inline IReferenceClockImpl *impl_from_IReferenceClock(IReferenceClock *iface)
{
    return CONTAINING_RECORD(iface, IReferenceClockImpl, IReferenceClock_iface);
}

30
/* IReferenceClockImpl IUnknown part: */
31 32 33
static HRESULT WINAPI IReferenceClockImpl_QueryInterface(IReferenceClock *iface, REFIID riid, LPVOID *ppobj)
{
	IReferenceClockImpl *This = impl_from_IReferenceClock(iface);
34
	TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
35

36 37
	if (IsEqualIID (riid, &IID_IUnknown) || 
	    IsEqualIID (riid, &IID_IReferenceClock)) {
38
		IUnknown_AddRef(iface);
39 40 41
		*ppobj = This;
		return S_OK;
	}
42
	WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
43 44 45
	return E_NOINTERFACE;
}

46 47
static ULONG WINAPI IReferenceClockImpl_AddRef(IReferenceClock *iface)
{
48 49
    IReferenceClockImpl *This = impl_from_IReferenceClock(iface);
    ULONG ref = InterlockedIncrement(&This->ref);
50

51
    TRACE("(%p)->(): new ref = %u\n", This, ref);
52

53
    return ref;
54 55
}

56 57
static ULONG WINAPI IReferenceClockImpl_Release(IReferenceClock *iface)
{
58 59
    IReferenceClockImpl *This = impl_from_IReferenceClock(iface);
    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 66
        DMUSIC_UnlockModule();
    }
67

68
    return ref;
69 70
}

71
/* IReferenceClockImpl IReferenceClock part: */
72 73 74 75 76 77 78 79 80
static HRESULT WINAPI IReferenceClockImpl_GetTime(IReferenceClock *iface, REFERENCE_TIME* pTime)
{
    IReferenceClockImpl *This = impl_from_IReferenceClock(iface);

    TRACE("(%p)->(%p)\n", This, pTime);

    *pTime = This->rtTime;

    return S_OK;
81 82
}

83 84 85 86 87 88 89
static HRESULT WINAPI IReferenceClockImpl_AdviseTime(IReferenceClock *iface, REFERENCE_TIME baseTime, REFERENCE_TIME streamTime, HANDLE hEvent, DWORD* pdwAdviseCookie)
{
    IReferenceClockImpl *This = impl_from_IReferenceClock(iface);

    FIXME("(%p)->(0x%s, 0x%s, %p, %p): stub\n", This, wine_dbgstr_longlong(baseTime), wine_dbgstr_longlong(streamTime), hEvent, pdwAdviseCookie);

    return S_OK;
90 91
}

92 93 94 95 96 97 98
static HRESULT WINAPI IReferenceClockImpl_AdvisePeriodic(IReferenceClock *iface, REFERENCE_TIME startTime, REFERENCE_TIME periodTime, HANDLE hSemaphore, DWORD* pdwAdviseCookie)
{
    IReferenceClockImpl *This = impl_from_IReferenceClock(iface);

    FIXME("(%p)->(0x%s, 0x%s, %p, %p): stub\n", This, wine_dbgstr_longlong(startTime), wine_dbgstr_longlong(periodTime), hSemaphore, pdwAdviseCookie);

    return S_OK;
99 100
}

101 102 103 104 105 106 107
static HRESULT WINAPI IReferenceClockImpl_Unadvise(IReferenceClock *iface, DWORD dwAdviseCookie)
{
    IReferenceClockImpl *This = impl_from_IReferenceClock(iface);

    FIXME("(%p)->(%d): stub\n", This, dwAdviseCookie);

    return S_OK;
108 109
}

110
static const IReferenceClockVtbl ReferenceClock_Vtbl = {
111 112 113 114 115 116 117 118 119 120
	IReferenceClockImpl_QueryInterface,
	IReferenceClockImpl_AddRef,
	IReferenceClockImpl_Release,
	IReferenceClockImpl_GetTime,
	IReferenceClockImpl_AdviseTime,
	IReferenceClockImpl_AdvisePeriodic,
	IReferenceClockImpl_Unadvise
};

/* 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 129 130 131 132 133

    clock = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IReferenceClockImpl));
    if (!clock) {
        *ret_iface = NULL;
        return E_OUTOFMEMORY;
    }

134
    clock->IReferenceClock_iface.lpVtbl = &ReferenceClock_Vtbl;
135
    clock->ref = 1;
136 137 138
    clock->rtTime = 0;
    clock->pClockInfo.dwSize = sizeof (DMUS_CLOCKINFO);

139 140
    DMUSIC_LockModule();
    hr = IReferenceClockImpl_QueryInterface(&clock->IReferenceClock_iface, riid, ret_iface);
141
    IReferenceClock_Release(&clock->IReferenceClock_iface);
142 143

    return hr;
144
}