4289cd1fc118a94c60a9a7b321133da884c2b499
[reactos.git] / reactos / dll / directx / ksproxy / interface.cpp
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS WDM Streaming ActiveMovie Proxy
4 * FILE: dll/directx/ksproxy/interface.cpp
5 * PURPOSE: IKsInterfaceHandler interface
6 *
7 * PROGRAMMERS: Johannes Anderwald (janderwald@reactos.org)
8 */
9 #include "precomp.h"
10
11 const GUID IID_IKsObject = {0x423c13a2, 0x2070, 0x11d0, {0x9e, 0xf7, 0x00, 0xaa, 0x00, 0xa2, 0x16, 0xa1}};
12
13 class CKsInterfaceHandler : public IKsInterfaceHandler
14 {
15 public:
16 STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
17
18 STDMETHODIMP_(ULONG) AddRef()
19 {
20 InterlockedIncrement(&m_Ref);
21 return m_Ref;
22 }
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 HRESULT STDMETHODCALLTYPE KsSetPin(IKsPin *KsPin);
35 HRESULT STDMETHODCALLTYPE KsProcessMediaSamples(IKsDataTypeHandler *KsDataTypeHandler, IMediaSample** SampleList, PLONG SampleCount, KSIOOPERATION IoOperation, PKSSTREAM_SEGMENT *StreamSegment);
36 HRESULT STDMETHODCALLTYPE KsCompleteIo(PKSSTREAM_SEGMENT StreamSegment);
37
38 CKsInterfaceHandler() : m_Ref(0), m_Handle(NULL){};
39 virtual ~CKsInterfaceHandler(){};
40
41 protected:
42 LONG m_Ref;
43 HANDLE m_Handle;
44 };
45
46 HRESULT
47 STDMETHODCALLTYPE
48 CKsInterfaceHandler::QueryInterface(
49 IN REFIID refiid,
50 OUT PVOID* Output)
51 {
52 if (IsEqualGUID(refiid, IID_IUnknown) ||
53 IsEqualGUID(refiid, IID_IKsInterfaceHandler))
54 {
55 *Output = PVOID(this);
56 reinterpret_cast<IUnknown*>(*Output)->AddRef();
57 return NOERROR;
58 }
59 return E_NOINTERFACE;
60 }
61
62 HRESULT
63 STDMETHODCALLTYPE
64 CKsInterfaceHandler::KsSetPin(
65 IKsPin *KsPin)
66 {
67 HRESULT hr;
68 IKsObject * KsObject;
69
70 // check if IKsObject is supported
71 hr = KsPin->QueryInterface(IID_IKsObject, (void**)&KsObject);
72
73 if (SUCCEEDED(hr))
74 {
75 // get pin handle
76 m_Handle = KsObject->KsGetObjectHandle();
77
78 // release IKsObject interface
79 KsObject->Release();
80
81 if (!m_Handle)
82 {
83 // expected a file handle
84 return E_UNEXPECTED;
85 }
86 }
87
88 // done
89 return hr;
90 }
91
92 HRESULT
93 STDMETHODCALLTYPE
94 CKsInterfaceHandler::KsProcessMediaSamples(
95 IKsDataTypeHandler *KsDataTypeHandler,
96 IMediaSample** SampleList,
97 PLONG SampleCount,
98 KSIOOPERATION IoOperation,
99 PKSSTREAM_SEGMENT *StreamSegment)
100 {
101 OutputDebugString("UNIMPLEMENTED\n");
102 return E_NOTIMPL;
103 }
104
105 HRESULT
106 STDMETHODCALLTYPE
107 CKsInterfaceHandler::KsCompleteIo(
108 PKSSTREAM_SEGMENT StreamSegment)
109 {
110 OutputDebugString("UNIMPLEMENTED\n");
111 return E_NOTIMPL;
112 }
113
114 HRESULT
115 WINAPI
116 CKsInterfaceHandler_Constructor(
117 IUnknown * pUnkOuter,
118 REFIID riid,
119 LPVOID * ppv)
120 {
121 OutputDebugStringW(L"CKsInterfaceHandler_Constructor\n");
122
123 CKsInterfaceHandler * handler = new CKsInterfaceHandler();
124
125 if (!handler)
126 return E_OUTOFMEMORY;
127
128 if (FAILED(handler->QueryInterface(riid, ppv)))
129 {
130 /* not supported */
131 delete handler;
132 return E_NOINTERFACE;
133 }
134
135 return NOERROR;
136 }