sync with trunk r46493
[reactos.git] / dll / directx / msdvbnp / pin.cpp
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Network Provider for MPEG2 based networks
4 * FILE: dll/directx/msdvbnp/pin.cpp
5 * PURPOSE: IPin interface
6 *
7 * PROGRAMMERS: Johannes Anderwald (janderwald@reactos.org)
8 */
9 #include "precomp.h"
10
11 #ifndef _MSC_VER
12 const GUID KSDATAFORMAT_TYPE_BDA_ANTENNA = {0x71985f41, 0x1ca1, 0x11d3, {0x9c, 0xc8, 0x0, 0xc0, 0x4f, 0x79, 0x71, 0xe0}};
13 const GUID GUID_NULL = {0x00000000L, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
14 #endif
15
16 class CPin : public IPin
17 {
18 public:
19 STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
20
21 STDMETHODIMP_(ULONG) AddRef()
22 {
23 InterlockedIncrement(&m_Ref);
24 return m_Ref;
25 }
26 STDMETHODIMP_(ULONG) Release()
27 {
28 InterlockedDecrement(&m_Ref);
29 if (!m_Ref)
30 {
31 delete this;
32 return 0;
33 }
34 return m_Ref;
35 }
36
37 //IPin methods
38 HRESULT STDMETHODCALLTYPE Connect(IPin *pReceivePin, const AM_MEDIA_TYPE *pmt);
39 HRESULT STDMETHODCALLTYPE ReceiveConnection(IPin *pConnector, const AM_MEDIA_TYPE *pmt);
40 HRESULT STDMETHODCALLTYPE Disconnect();
41 HRESULT STDMETHODCALLTYPE ConnectedTo(IPin **pPin);
42 HRESULT STDMETHODCALLTYPE ConnectionMediaType(AM_MEDIA_TYPE *pmt);
43 HRESULT STDMETHODCALLTYPE QueryPinInfo(PIN_INFO *pInfo);
44 HRESULT STDMETHODCALLTYPE QueryDirection(PIN_DIRECTION *pPinDir);
45 HRESULT STDMETHODCALLTYPE QueryId(LPWSTR *Id);
46 HRESULT STDMETHODCALLTYPE QueryAccept(const AM_MEDIA_TYPE *pmt);
47 HRESULT STDMETHODCALLTYPE EnumMediaTypes(IEnumMediaTypes **ppEnum);
48 HRESULT STDMETHODCALLTYPE QueryInternalConnections(IPin **apPin, ULONG *nPin);
49 HRESULT STDMETHODCALLTYPE EndOfStream();
50 HRESULT STDMETHODCALLTYPE BeginFlush();
51 HRESULT STDMETHODCALLTYPE EndFlush();
52 HRESULT STDMETHODCALLTYPE NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
53
54 CPin(IBaseFilter * ParentFilter) : m_Ref(0), m_ParentFilter(ParentFilter){};
55 virtual ~CPin(){};
56
57 static LPCWSTR PIN_ID;
58
59 protected:
60 LONG m_Ref;
61 IBaseFilter * m_ParentFilter;
62 };
63
64
65 LPCWSTR CPin::PIN_ID = L"Antenna Out";
66
67 HRESULT
68 STDMETHODCALLTYPE
69 CPin::QueryInterface(
70 IN REFIID refiid,
71 OUT PVOID* Output)
72 {
73 if (IsEqualGUID(refiid, IID_IUnknown))
74 {
75 *Output = PVOID(this);
76 reinterpret_cast<IUnknown*>(*Output)->AddRef();
77 return NOERROR;
78 }
79 if (IsEqualGUID(refiid, IID_IPin))
80 {
81 *Output = (IPin*)(this);
82 reinterpret_cast<IPin*>(*Output)->AddRef();
83 return NOERROR;
84 }
85
86 WCHAR Buffer[MAX_PATH];
87 LPOLESTR lpstr;
88 StringFromCLSID(refiid, &lpstr);
89 swprintf(Buffer, L"CPin::QueryInterface: NoInterface for %s\n", lpstr);
90 OutputDebugStringW(Buffer);
91 CoTaskMemFree(lpstr);
92
93 return E_NOINTERFACE;
94 }
95
96 //-------------------------------------------------------------------
97 // IPin interface
98 //
99 HRESULT
100 STDMETHODCALLTYPE
101 CPin::Connect(IPin *pReceivePin, const AM_MEDIA_TYPE *pmt)
102 {
103 OutputDebugStringW(L"CPin::Connect called\n");
104 return E_NOTIMPL;
105 }
106
107 HRESULT
108 STDMETHODCALLTYPE
109 CPin::ReceiveConnection(IPin *pConnector, const AM_MEDIA_TYPE *pmt)
110 {
111 OutputDebugStringW(L"CPin::ReceiveConnection called\n");
112 return E_NOTIMPL;
113 }
114 HRESULT
115 STDMETHODCALLTYPE
116 CPin::Disconnect( void)
117 {
118 OutputDebugStringW(L"CPin::Disconnect called\n");
119 return E_NOTIMPL;
120 }
121 HRESULT
122 STDMETHODCALLTYPE
123 CPin::ConnectedTo(IPin **pPin)
124 {
125 OutputDebugStringW(L"CPin::ConnectedTo called\n");
126 return VFW_E_NOT_CONNECTED;
127 }
128 HRESULT
129 STDMETHODCALLTYPE
130 CPin::ConnectionMediaType(AM_MEDIA_TYPE *pmt)
131 {
132 OutputDebugStringW(L"CPin::ConnectionMediaType called\n");
133 return E_NOTIMPL;
134 }
135 HRESULT
136 STDMETHODCALLTYPE
137 CPin::QueryPinInfo(PIN_INFO *pInfo)
138 {
139 wcscpy(pInfo->achName, PIN_ID);
140 pInfo->dir = PINDIR_OUTPUT;
141 pInfo->pFilter = m_ParentFilter;
142 m_ParentFilter->AddRef();
143
144 return S_OK;
145 }
146 HRESULT
147 STDMETHODCALLTYPE
148 CPin::QueryDirection(PIN_DIRECTION *pPinDir)
149 {
150 if (pPinDir)
151 {
152 *pPinDir = PINDIR_OUTPUT;
153 return S_OK;
154 }
155
156 return E_POINTER;
157 }
158 HRESULT
159 STDMETHODCALLTYPE
160 CPin::QueryId(LPWSTR *Id)
161 {
162 *Id = (LPWSTR)CoTaskMemAlloc(sizeof(PIN_ID));
163 if (!*Id)
164 return E_OUTOFMEMORY;
165
166 wcscpy(*Id, PIN_ID);
167 return S_OK;
168 }
169 HRESULT
170 STDMETHODCALLTYPE
171 CPin::QueryAccept(const AM_MEDIA_TYPE *pmt)
172 {
173 OutputDebugStringW(L"CPin::QueryAccept called\n");
174 return E_NOTIMPL;
175 }
176 HRESULT
177 STDMETHODCALLTYPE
178 CPin::EnumMediaTypes(IEnumMediaTypes **ppEnum)
179 {
180 AM_MEDIA_TYPE *MediaType = (AM_MEDIA_TYPE*)CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE));
181
182 if (!MediaType)
183 {
184 return E_OUTOFMEMORY;
185 }
186
187 MediaType->majortype = KSDATAFORMAT_TYPE_BDA_ANTENNA;
188 MediaType->subtype = MEDIASUBTYPE_None;
189 MediaType->formattype = FORMAT_None;
190 MediaType->bFixedSizeSamples = true;
191 MediaType->bTemporalCompression = false;
192 MediaType->lSampleSize = sizeof(CHAR);
193 MediaType->pUnk = NULL;
194 MediaType->cbFormat = 0;
195 MediaType->pbFormat = NULL;
196
197 return CEnumMediaTypes_fnConstructor(NULL, 1, MediaType, IID_IEnumMediaTypes, (void**)ppEnum);
198 }
199 HRESULT
200 STDMETHODCALLTYPE
201 CPin::QueryInternalConnections(IPin **apPin, ULONG *nPin)
202 {
203 OutputDebugStringW(L"CPin::QueryInternalConnections called\n");
204 return E_NOTIMPL;
205 }
206 HRESULT
207 STDMETHODCALLTYPE
208 CPin::EndOfStream( void)
209 {
210 OutputDebugStringW(L"CPin::EndOfStream called\n");
211 return E_NOTIMPL;
212 }
213 HRESULT
214 STDMETHODCALLTYPE
215 CPin::BeginFlush( void)
216 {
217 OutputDebugStringW(L"CPin::BeginFlush called\n");
218 return E_NOTIMPL;
219 }
220 HRESULT
221 STDMETHODCALLTYPE
222 CPin::EndFlush( void)
223 {
224 OutputDebugStringW(L"CPin::EndFlush called\n");
225 return E_NOTIMPL;
226 }
227 HRESULT
228 STDMETHODCALLTYPE
229 CPin::NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate)
230 {
231 OutputDebugStringW(L"CPin::NewSegment called\n");
232 return E_NOTIMPL;
233 }
234
235 HRESULT
236 WINAPI
237 CPin_fnConstructor(
238 IUnknown *pUnknown,
239 IBaseFilter * ParentFilter,
240 REFIID riid,
241 LPVOID * ppv)
242 {
243 CPin * handler = new CPin(ParentFilter);
244
245 #ifdef MSDVBNP_TRACE
246 WCHAR Buffer[MAX_PATH];
247 LPOLESTR lpstr;
248 StringFromCLSID(riid, &lpstr);
249 swprintf(Buffer, L"CPin_fnConstructor riid %s pUnknown %p\n", lpstr, pUnknown);
250 OutputDebugStringW(Buffer);
251 #endif
252
253 if (!handler)
254 return E_OUTOFMEMORY;
255
256 if (FAILED(handler->QueryInterface(riid, ppv)))
257 {
258 /* not supported */
259 delete handler;
260 return E_NOINTERFACE;
261 }
262
263 return NOERROR;
264 }