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