1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS WDM Streaming ActiveMovie Proxy
4 * FILE: dll/directx/ksproxy/qualityforward.cpp
5 * PURPOSE: IKsClockForwarder interface
6 *
7 * PROGRAMMERS: Johannes Anderwald (johannes.anderwald@reactos.org)
8 */
9 #include "precomp.h"
10
11 #define IID_IKsQualityForwarder KSCATEGORY_QUALITY
12
13 class CKsQualityForwarder : public IKsQualityForwarder
14 {
15 public:
16 STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
17
AddRef()18 STDMETHODIMP_(ULONG) AddRef()
19 {
20 InterlockedIncrement(&m_Ref);
21 return m_Ref;
22 }
Release()23 STDMETHODIMP_(ULONG) Release()
24 {
25 InterlockedDecrement(&m_Ref);
26
27 if (!m_Ref)
28 {
29 delete this;
30 return 0;
31 }
32 return m_Ref;
33 }
34
35 // IKsObject interface
36 HANDLE STDMETHODCALLTYPE KsGetObjectHandle();
37
38 // IKsQualityForwarder
39 VOID STDMETHODCALLTYPE KsFlushClient(IN IKsPin *Pin);
40
CKsQualityForwarder(HANDLE handle)41 CKsQualityForwarder(HANDLE handle) : m_Ref(0), m_Handle(handle){}
~CKsQualityForwarder()42 virtual ~CKsQualityForwarder(){ if (m_Handle) CloseHandle(m_Handle);}
43
44 protected:
45 LONG m_Ref;
46 HANDLE m_Handle;
47
48
49 };
50
51 HRESULT
52 STDMETHODCALLTYPE
QueryInterface(IN REFIID refiid,OUT PVOID * Output)53 CKsQualityForwarder::QueryInterface(
54 IN REFIID refiid,
55 OUT PVOID* Output)
56 {
57 if (IsEqualGUID(refiid, IID_IUnknown) ||
58 IsEqualGUID(refiid, IID_IKsQualityForwarder))
59 {
60 *Output = PVOID(this);
61 reinterpret_cast<IUnknown*>(*Output)->AddRef();
62 return NOERROR;
63 }
64
65 return E_NOINTERFACE;
66 }
67
68 //-------------------------------------------------------------------
69 // IKsObject interface
70 //
71
72 HANDLE
73 STDMETHODCALLTYPE
KsGetObjectHandle()74 CKsQualityForwarder::KsGetObjectHandle()
75 {
76 return m_Handle;
77 }
78
79 //-------------------------------------------------------------------
80 // IKsQualityForwarder interface
81 //
82 VOID
83 STDMETHODCALLTYPE
KsFlushClient(IN IKsPin * Pin)84 CKsQualityForwarder::KsFlushClient(
85 IN IKsPin *Pin)
86 {
87 #ifdef KSPROXY_TRACE
88 OutputDebugString("UNIMPLEMENTED\n");
89 #endif
90 }
91
92 HRESULT
93 WINAPI
CKsQualityForwarder_Constructor(IUnknown * pUnkOuter,REFIID riid,LPVOID * ppv)94 CKsQualityForwarder_Constructor(
95 IUnknown * pUnkOuter,
96 REFIID riid,
97 LPVOID * ppv)
98 {
99 HRESULT hr;
100 HANDLE handle;
101
102 #ifdef KSPROXY_TRACE
103 OutputDebugStringW(L"CKsQualityForwarder_Constructor\n");
104 #endif
105
106 // open default clock
107 hr = KsOpenDefaultDevice(KSCATEGORY_QUALITY, GENERIC_READ | GENERIC_WRITE, &handle);
108
109 if (hr != NOERROR)
110 {
111 #ifdef KSPROXY_TRACE
112 OutputDebugString("CKsClockForwarder_Constructor failed to open device\n");
113 #endif
114 return hr;
115 }
116
117 CKsQualityForwarder * quality = new CKsQualityForwarder(handle);
118
119 if (!quality)
120 {
121 // free clock handle
122 CloseHandle(handle);
123 return E_OUTOFMEMORY;
124 }
125
126 if (FAILED(quality->QueryInterface(riid, ppv)))
127 {
128 /* not supported */
129 delete quality;
130 return E_NOINTERFACE;
131 }
132
133 return NOERROR;
134 }
135