ReactOS 0.4.15-dev-8219-ge8b88cf
clockforward.cpp
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS WDM Streaming ActiveMovie Proxy
4 * FILE: dll/directx/ksproxy/clockforward.cpp
5 * PURPOSE: IKsClockForwarder interface
6 *
7 * PROGRAMMERS: Johannes Anderwald (johannes.anderwald@reactos.org)
8 */
9#include "precomp.h"
10
11const GUID IID_IKsClockForwarder = {0x877e4352, 0x6fea, 0x11d0, {0xb8, 0x63, 0x00, 0xaa, 0x00, 0xa2, 0x16, 0xa1}};
12
14
16 public IKsObject
17{
18public:
20
22 {
24 return m_Ref;
25 }
27 {
29
30 if (!m_Ref)
31 {
32 delete this;
33 return 0;
34 }
35 return m_Ref;
36 }
37
38 // IDistributorNotify interface
44
45 // IKsObject interface
47
49 virtual ~CKsClockForwarder(){};
51protected:
62
64};
65
67 HANDLE handle) : m_Ref(0),
68 m_Handle(handle),
69 m_Clock(0),
70 m_hEvent(NULL),
71 m_hThread(NULL),
72 m_ThreadStarted(FALSE),
73 m_PendingStop(FALSE),
74 m_ForceStart(FALSE),
75 m_State(KSSTATE_STOP),
76 m_Time(0)
77{
78}
79
83 IN REFIID refiid,
85{
86 if (IsEqualGUID(refiid, IID_IUnknown))
87 {
88 *Output = PVOID(this);
89 reinterpret_cast<IUnknown*>(*Output)->AddRef();
90 return NOERROR;
91 }
92 if (IsEqualGUID(refiid, IID_IKsObject) ||
94 {
95 *Output = (IKsObject*)(this);
96 reinterpret_cast<IKsObject*>(*Output)->AddRef();
97 return NOERROR;
98 }
99
101 {
102 *Output = (IDistributorNotify*)(this);
103 reinterpret_cast<IDistributorNotify*>(*Output)->AddRef();
104 return NOERROR;
105 }
106
107 return E_NOINTERFACE;
108}
109
110//-------------------------------------------------------------------
111// IDistributorNotify interface
112//
113
114
118{
119#ifdef KSPROXY_TRACE
120 WCHAR Buffer[200];
121 swprintf(Buffer, L"CKsClockForwarder::Stop m_ThreadStarted %u m_PendingStop %u m_hThread %p m_hEvent %p m_Handle %p\n", m_ThreadStarted, m_PendingStop, m_hThread, m_hEvent, m_Handle);
123#endif
124
125 m_Time = 0;
126 if (m_ThreadStarted)
127 {
128 // signal pending stop
129 m_PendingStop = true;
130
133
134 // set stop event
136
137 // wait untill the thread has finished
139
140 // close thread handle
142
143 // zero handle
144 m_hThread = NULL;
145 }
146
147 if (m_hEvent)
148 {
149 // close stop event
151 m_hEvent = NULL;
152 }
153
154 m_PendingStop = false;
155
157 return NOERROR;
158}
159
163{
164#ifdef KSPROXY_TRACE
165 OutputDebugString("CKsClockForwarder::Pause\n");
166#endif
167
168 if (!m_hEvent)
169 {
171 if (!m_hEvent)
173 }
174
175 if (m_State <= KSSTATE_PAUSE)
176 {
177 if (m_State == KSSTATE_STOP)
179
182 }
183 else
184 {
185 if (!m_ForceStart)
186 {
188 }
189 }
190
191 if (!m_hThread)
192 {
194 if (!m_hThread)
196 }
197
198 return NOERROR;
199}
200
204 REFERENCE_TIME tStart)
205{
206#ifdef KSPROXY_TRACE
207 OutputDebugString("CKsClockForwarder::Run\n");
208#endif
209
210 m_Time = tStart;
211
212 if (!m_hEvent || !m_hThread)
213 {
215 HRESULT hr = Pause();
217
218 if (FAILED(hr))
219 return hr;
220 }
221
223
226
227 return NOERROR;
228}
229
233 IReferenceClock *pClock)
234{
235#ifdef KSPROXY_TRACE
236 OutputDebugString("CKsClockForwarder::SetSyncSource\n");
237#endif
238
239 if (pClock)
240 pClock->AddRef();
241
242 if (m_Clock)
243 m_Clock->Release();
244
245
246 m_Clock = pClock;
247 return NOERROR;
248}
249
253{
254#ifdef KSPROXY_TRACE
255 OutputDebugString("CKsClockForwarder::NotifyGraphChange\n");
256#endif
257
258 return NOERROR;
259}
260
261//-------------------------------------------------------------------
262// IKsObject interface
263//
264
265HANDLE
268{
269 return m_Handle;
270}
271
272//-------------------------------------------------------------------
276{
279
283
285 if (SUCCEEDED(hr))
286 m_State = State;
287
288#ifdef KSPROXY_TRACE
289 WCHAR Buffer[100];
290 swprintf(Buffer, L"CKsClockForwarder::SetClockState m_State %u State %u hr %lx\n", m_State, State, hr);
292#endif
293
294 return hr;
295}
296
297DWORD
298WINAPI
300{
303
304 CKsClockForwarder * Fwd = (CKsClockForwarder*)lpParameter;
305
306 Fwd->m_ThreadStarted = TRUE;
307
308 do
309 {
310 if (Fwd->m_PendingStop)
311 break;
312
313 if (Fwd->m_State != KSSTATE_RUN)
315
320
321 Fwd->m_Clock->GetTime(&Time);
322 Time -= Fwd->m_Time;
323
325 }
326 while(TRUE);
327
328 Fwd->m_ThreadStarted = FALSE;
329 return NOERROR;
330}
331
333WINAPI
335 IUnknown * pUnkOuter,
336 REFIID riid,
337 LPVOID * ppv)
338{
339 HRESULT hr;
341
342#ifdef KSPROXY_TRACE
343 OutputDebugStringW(L"CKsClockForwarder_Constructor\n");
344#endif
345
346 // open default clock
348
349 if (hr != NOERROR)
350 {
351#ifdef KSPROXY_TRACE
352 OutputDebugString("CKsClockForwarder_Constructor failed to open device\n");
353#endif
354 return hr;
355 }
356
358
359 if (!clock)
360 {
361 // free clock handle
363 return E_OUTOFMEMORY;
364 }
365
366 if (FAILED(clock->QueryInterface(riid, ppv)))
367 {
368 /* not supported */
369 delete clock;
370 return E_NOINTERFACE;
371 }
372
373 return NOERROR;
374}
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define STDMETHODIMP
Definition: basetyps.h:43
const GUID IID_IUnknown
#define STDMETHODCALLTYPE
Definition: bdasup.h:9
Definition: bufpool.h:45
HRESULT STDMETHODCALLTYPE NotifyGraphChange()
CKsClockForwarder(HANDLE handle)
STDMETHODIMP_(ULONG) Release()
HRESULT STDMETHODCALLTYPE Pause()
HRESULT STDMETHODCALLTYPE Stop()
IReferenceClock * m_Clock
HANDLE STDMETHODCALLTYPE KsGetObjectHandle()
HRESULT STDMETHODCALLTYPE Run(REFERENCE_TIME tStart)
REFERENCE_TIME m_Time
virtual ~CKsClockForwarder()
HRESULT STDMETHODCALLTYPE SetSyncSource(IReferenceClock *pClock)
STDMETHODIMP_(ULONG) AddRef()
HRESULT STDMETHODCALLTYPE SetClockState(KSSTATE State)
STDMETHODIMP QueryInterface(REFIID InterfaceId, PVOID *Interface)
friend DWORD WINAPI CKsClockForwarder_ThreadStartup(LPVOID lpParameter)
const GUID IID_IKsClockForwarder
HRESULT WINAPI CKsClockForwarder_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv)
DWORD WINAPI CKsClockForwarder_ThreadStartup(LPVOID lpParameter)
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
const GUID IID_IKsObject
const GUID IID_IDistributorNotify
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define GENERIC_READ
Definition: compat.h:135
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:137
#define swprintf
Definition: precomp.h:40
#define assert(x)
Definition: debug.h:53
#define MAKE_HRESULT(sev, fac, code)
Definition: dmerror.h:30
LONGLONG REFERENCE_TIME
Definition: dmusicks.h:9
#define INFINITE
Definition: serial.h:102
#define KSPROPERTY_TYPE_SET
Definition: dmksctrl.h:43
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
void WINAPI SHIM_OBJ_NAME() OutputDebugStringW(LPCWSTR lpOutputString)
Definition: ignoredbgout.c:23
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
HRESULT GetTime([out] REFERENCE_TIME *pTime)
ULONG AddRef()
ULONG Release()
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
#define IOCTL_KS_PROPERTY
Definition: ks.h:127
KSSTATE
Definition: ks.h:1214
@ KSSTATE_ACQUIRE
Definition: ks.h:1216
@ KSSTATE_PAUSE
Definition: ks.h:1217
@ KSSTATE_RUN
Definition: ks.h:1218
@ KSSTATE_STOP
Definition: ks.h:1215
@ KSPROPERTY_CLOCK_TIME
Definition: ks.h:318
@ KSPROPERTY_CLOCK_STATE
Definition: ks.h:323
#define KSCATEGORY_CLOCK
Definition: ks.h:215
#define KSPROPSETID_Clock
Definition: ks.h:315
KSDDKAPI HRESULT WINAPI KsSynchronousDeviceControl(HANDLE Handle, ULONG IoControl, PVOID InBuffer, ULONG InLength, PVOID OutBuffer, ULONG OutLength, PULONG BytesReturned)
Definition: ksproxy.cpp:34
KSDDKAPI HRESULT WINAPI KsOpenDefaultDevice(REFGUID Category, ACCESS_MASK Access, PHANDLE DeviceHandle)
Definition: ksproxy.cpp:101
static PLARGE_INTEGER Time
Definition: time.c:105
#define GENERIC_WRITE
Definition: nt_native.h:90
#define L(x)
Definition: ntvdm.h:50
long LONG
Definition: pedump.c:60
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define REFIID
Definition: guiddef.h:118
_Check_return_ _CRTIMP clock_t __cdecl clock(void)
Definition: clock.c:23
@ Output
Definition: arc.h:85
HRESULT hr
Definition: shlfolder.c:183
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:651
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
void * PVOID
Definition: typedefs.h:50
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
struct tagRun Run
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE Interface
Definition: wdffdo.h:465
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_ ULONG _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesReturned
Definition: wdfiotarget.h:1052
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define OutputDebugString
Definition: winbase.h:3890
#define WINAPI
Definition: msvc.h:6
#define E_NOINTERFACE
Definition: winerror.h:2364
#define NOERROR
Definition: winerror.h:2354
#define SEVERITY_ERROR
Definition: winerror.h:65
#define FACILITY_WIN32
Definition: winerror.h:27
__wchar_t WCHAR
Definition: xmlstorage.h:180