Create a branch for header work.
[reactos.git] / 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_IKsInterfaceHandler = {0xD3ABC7E0, 0x9A61, 0x11D0, {0xA4, 0x0D, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}};
12 const GUID IID_IKsObject = {0x423c13a2, 0x2070, 0x11d0, {0x9e, 0xf7, 0x00, 0xaa, 0x00, 0xa2, 0x16, 0xa1}};
13
14 class CKsInterfaceHandler : public IKsInterfaceHandler
15 {
16 public:
17 STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
18
19 STDMETHODIMP_(ULONG) AddRef()
20 {
21 InterlockedIncrement(&m_Ref);
22 return m_Ref;
23 }
24 STDMETHODIMP_(ULONG) Release()
25 {
26 InterlockedDecrement(&m_Ref);
27
28 if (!m_Ref)
29 {
30 delete this;
31 return 0;
32 }
33 return m_Ref;
34 }
35 HRESULT STDMETHODCALLTYPE KsSetPin(IKsPin *KsPin);
36 HRESULT STDMETHODCALLTYPE KsProcessMediaSamples(IKsDataTypeHandler *KsDataTypeHandler, IMediaSample** SampleList, PLONG SampleCount, KSIOOPERATION IoOperation, PKSSTREAM_SEGMENT *StreamSegment);
37 HRESULT STDMETHODCALLTYPE KsCompleteIo(PKSSTREAM_SEGMENT StreamSegment);
38
39 CKsInterfaceHandler() : m_Ref(0), m_Handle(NULL){};
40 virtual ~CKsInterfaceHandler(){};
41
42 protected:
43 LONG m_Ref;
44 HANDLE m_Handle;
45 };
46
47 HRESULT
48 STDMETHODCALLTYPE
49 CKsInterfaceHandler::QueryInterface(
50 IN REFIID refiid,
51 OUT PVOID* Output)
52 {
53 if (IsEqualGUID(refiid, IID_IUnknown) ||
54 IsEqualGUID(refiid, IID_IKsInterfaceHandler))
55 {
56 *Output = PVOID(this);
57 reinterpret_cast<IUnknown*>(*Output)->AddRef();
58 return NOERROR;
59 }
60 return E_NOINTERFACE;
61 }
62
63 HRESULT
64 STDMETHODCALLTYPE
65 CKsInterfaceHandler::KsSetPin(
66 IKsPin *KsPin)
67 {
68 HRESULT hr;
69 IKsObject * KsObject;
70
71 // check if IKsObject is supported
72 hr = KsPin->QueryInterface(IID_IKsObject, (void**)&KsObject);
73
74 if (SUCCEEDED(hr))
75 {
76 // get pin handle
77 m_Handle = KsObject->KsGetObjectHandle();
78
79 // release IKsObject interface
80 KsObject->Release();
81
82 if (!m_Handle)
83 {
84 // expected a file handle
85 return E_UNEXPECTED;
86 }
87 }
88
89 // done
90 return hr;
91 }
92
93 HRESULT
94 STDMETHODCALLTYPE
95 CKsInterfaceHandler::KsProcessMediaSamples(
96 IKsDataTypeHandler *KsDataTypeHandler,
97 IMediaSample** SampleList,
98 PLONG SampleCount,
99 KSIOOPERATION IoOperation,
100 PKSSTREAM_SEGMENT *StreamSegment)
101 {
102 OutputDebugString("UNIMPLEMENTED\n");
103 return E_NOTIMPL;
104 }
105
106 HRESULT
107 STDMETHODCALLTYPE
108 CKsInterfaceHandler::KsCompleteIo(
109 PKSSTREAM_SEGMENT StreamSegment)
110 {
111 OutputDebugString("UNIMPLEMENTED\n");
112 return E_NOTIMPL;
113 }
114
115 HRESULT
116 WINAPI
117 CKsInterfaceHandler_Constructor(
118 IUnknown * pUnkOuter,
119 REFIID riid,
120 LPVOID * ppv)
121 {
122 CKsInterfaceHandler * handler = new CKsInterfaceHandler();
123
124 if (!handler)
125 return E_OUTOFMEMORY;
126
127 if (FAILED(handler->QueryInterface(riid, ppv)))
128 {
129 /* not supported */
130 delete handler;
131 return E_NOINTERFACE;
132 }
133
134 return NOERROR;
135 }