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