1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
#include "stdafx.h"
#include <initguid.h>
#include "SyncClock.h"
#include "..\..\..\DSUtil\DSUtil.h"
#include <moreuuids.h>
#pragma warning(disable:4355)
#ifdef REGISTER_FILTER
const AMOVIESETUP_FILTER sudFilter[] =
{
{&__uuidof(CSyncClockFilter), L"SyncClock", MERIT_NORMAL, 0, NULL, CLSID_LegacyAmFilterCategory}
};
CFactoryTemplate g_Templates[] =
{
{sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CSyncClockFilter>, NULL, &sudFilter[0]}
};
int g_cTemplates = countof(g_Templates);
STDAPI DllRegisterServer()
{
return AMovieDllRegisterServer2(TRUE);
}
STDAPI DllUnregisterServer()
{
return AMovieDllRegisterServer2(FALSE);
}
#include "..\..\FilterApp.h"
CFilterApp theApp;
#endif
CSyncClockFilter::CSyncClockFilter(LPUNKNOWN pUnk, HRESULT *phr)
: CBaseFilter(NAME("SyncClock"), NULL, &m_Lock, CLSID_NULL)
, m_Clock(static_cast<IBaseFilter*>(this), phr)
{
}
CSyncClockFilter::~CSyncClockFilter()
{
}
STDMETHODIMP CSyncClockFilter::AdjustClock(DOUBLE adjustment)
{
m_Clock.adjustment = adjustment;
return S_OK;
}
STDMETHODIMP CSyncClockFilter::SetBias(DOUBLE bias)
{
m_Clock.bias = bias;
return S_OK;
}
STDMETHODIMP CSyncClockFilter::GetBias(DOUBLE *bias)
{
*bias = m_Clock.bias;
return S_OK;
}
STDMETHODIMP CSyncClockFilter::GetStartTime(REFERENCE_TIME *startTime)
{
*startTime = m_tStart;
return S_OK;
}
STDMETHODIMP CSyncClockFilter::NonDelegatingQueryInterface( REFIID riid, void ** ppv )
{
CheckPointer(ppv, E_POINTER);
if(riid == IID_IReferenceClock)
{
return GetInterface(static_cast<IReferenceClock*>(&m_Clock), ppv);
}
else
if(riid == IID_ISyncClock)
{
return GetInterface(static_cast<ISyncClock*>(this), ppv);
}
else
{
return CBaseFilter::NonDelegatingQueryInterface(riid, ppv);
}
}
int CSyncClockFilter::GetPinCount()
{
return 0;
}
CBasePin *CSyncClockFilter::GetPin(int i)
{
UNREFERENCED_PARAMETER(i);
return NULL;
}
// CSyncClock methods
CSyncClock::CSyncClock(LPUNKNOWN pUnk, HRESULT *phr)
: CBaseReferenceClock(NAME("SyncClock"), pUnk, phr)
, m_pCurrentRefClock(0), m_pPrevRefClock(0)
{
QueryPerformanceFrequency((LARGE_INTEGER*)&m_llPerfFrequency);
m_rtPrivateTime = GetTicks100ns();
m_rtPrevTime = m_rtPrivateTime;
adjustment = 1.0;
bias = 1.0;
}
REFERENCE_TIME CSyncClock::GetPrivateTime()
{
CAutoLock cObjectLock(this);
REFERENCE_TIME rtTime = GetTicks100ns();
REFERENCE_TIME delta = rtTime - m_rtPrevTime;
// We ignore that rtTime may wrap around. Not gonna happen too often
m_rtPrevTime = rtTime;
delta = (REFERENCE_TIME)((DOUBLE)delta * adjustment * bias);
m_rtPrivateTime = m_rtPrivateTime + delta;
return m_rtPrivateTime;
}
REFERENCE_TIME CSyncClock::GetTicks100ns()
{
LONGLONG i64Ticks100ns;
if (m_llPerfFrequency != 0)
{
QueryPerformanceCounter((LARGE_INTEGER*)&i64Ticks100ns);
i64Ticks100ns = LONGLONG((double(i64Ticks100ns) * 10000000) / double(m_llPerfFrequency) + 0.5);
return (REFERENCE_TIME)i64Ticks100ns;
}
return 0;
}
|