1 /*
2  * COPYRIGHT:       See COPYING in the top level directory
3  * PROJECT:         ReactOS BDA Proxy
4  * FILE:            dll/directx/bdaplgin/digitaldemo.cpp
5  * PURPOSE:         IBDA_DigitalDemodulator interface
6  *
7  * PROGRAMMERS:     Johannes Anderwald (johannes.anderwald@reactos.org)
8  */
9 
10 #include "precomp.h"
11 
12 #ifndef _MSC_VER
13 const GUID IID_IBDA_DigitalDemodulator = {0xef30f379, 0x985b, 0x4d10, {0xb6, 0x40, 0xa7, 0x9d, 0x5e, 0x04, 0xe1, 0xe0}};
14 const GUID KSPROPSETID_BdaDigitalDemodulator = {0xef30f379, 0x985b, 0x4d10, {0xb6, 0x40, 0xa7, 0x9d, 0x5e, 0x4, 0xe1, 0xe0}};
15 #endif
16 
17 class CBDADigitalDemodulator : public IBDA_DigitalDemodulator
18 {
19 public:
20     STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
21 
AddRef()22     STDMETHODIMP_(ULONG) AddRef()
23     {
24         InterlockedIncrement(&m_Ref);
25         return m_Ref;
26     }
Release()27     STDMETHODIMP_(ULONG) Release()
28     {
29         InterlockedDecrement(&m_Ref);
30         if (!m_Ref)
31         {
32             delete this;
33             return 0;
34         }
35         return m_Ref;
36     }
37     //IBDA_DigitalDemodulator methods
38     HRESULT STDMETHODCALLTYPE put_ModulationType(ModulationType *pModulationType);
39     HRESULT STDMETHODCALLTYPE get_ModulationType(ModulationType *pModulationType);
40     HRESULT STDMETHODCALLTYPE put_InnerFECMethod(FECMethod *pFECMethod);
41     HRESULT STDMETHODCALLTYPE get_InnerFECMethod(FECMethod *pFECMethod);
42     HRESULT STDMETHODCALLTYPE put_InnerFECRate(BinaryConvolutionCodeRate *pFECRate);
43     HRESULT STDMETHODCALLTYPE get_InnerFECRate(BinaryConvolutionCodeRate *pFECRate);
44     HRESULT STDMETHODCALLTYPE put_OuterFECMethod(FECMethod *pFECMethod);
45     HRESULT STDMETHODCALLTYPE get_OuterFECMethod(FECMethod *pFECMethod);
46     HRESULT STDMETHODCALLTYPE put_OuterFECRate(BinaryConvolutionCodeRate *pFECRate);
47     HRESULT STDMETHODCALLTYPE get_OuterFECRate(BinaryConvolutionCodeRate *pFECRate);
48     HRESULT STDMETHODCALLTYPE put_SymbolRate(ULONG *pSymbolRate);
49     HRESULT STDMETHODCALLTYPE get_SymbolRate(ULONG *pSymbolRate);
50     HRESULT STDMETHODCALLTYPE put_SpectralInversion(SpectralInversion *pSpectralInversion);
51     HRESULT STDMETHODCALLTYPE get_SpectralInversion(SpectralInversion *pSpectralInversion);
52 
CBDADigitalDemodulator(IKsPropertySet * pProperty,ULONG NodeId)53     CBDADigitalDemodulator(IKsPropertySet * pProperty, ULONG NodeId) : m_Ref(0), m_pProperty(pProperty), m_NodeId(NodeId){};
~CBDADigitalDemodulator()54     ~CBDADigitalDemodulator(){};
55 
56 protected:
57     LONG m_Ref;
58     IKsPropertySet * m_pProperty;
59     ULONG m_NodeId;
60 };
61 
62 HRESULT
63 STDMETHODCALLTYPE
QueryInterface(IN REFIID refiid,OUT PVOID * Output)64 CBDADigitalDemodulator::QueryInterface(
65     IN  REFIID refiid,
66     OUT PVOID* Output)
67 {
68     *Output = NULL;
69 
70     if (IsEqualGUID(refiid, IID_IUnknown))
71     {
72         *Output = PVOID(this);
73         reinterpret_cast<IUnknown*>(*Output)->AddRef();
74         return NOERROR;
75     }
76 
77     if (IsEqualGUID(refiid, IID_IBDA_DigitalDemodulator))
78     {
79         *Output = (IBDA_DigitalDemodulator*)(this);
80         reinterpret_cast<IBDA_DigitalDemodulator*>(*Output)->AddRef();
81         return NOERROR;
82     }
83 
84 #ifdef BDAPLGIN_TRACE
85     WCHAR Buffer[MAX_PATH];
86     LPOLESTR lpstr;
87     StringFromCLSID(refiid, &lpstr);
88     swprintf(Buffer, L"CBDADigitalDemodulator::QueryInterface: NoInterface for %s", lpstr);
89     OutputDebugStringW(Buffer);
90     CoTaskMemFree(lpstr);
91 DebugBreak();
92 #endif
93 
94     return E_NOINTERFACE;
95 }
96 
97 HRESULT
98 STDMETHODCALLTYPE
put_ModulationType(ModulationType * pModulationType)99 CBDADigitalDemodulator::put_ModulationType(ModulationType *pModulationType)
100 {
101     KSP_NODE Node;
102     HRESULT hr;
103 
104     // setup request
105     Node.NodeId = m_NodeId;
106     Node.Reserved = 0;
107 
108     // perform request
109     hr = m_pProperty->Set(KSPROPSETID_BdaDigitalDemodulator, KSPROPERTY_BDA_MODULATION_TYPE, &Node.NodeId, sizeof(KSP_NODE)-sizeof(KSPROPERTY), pModulationType, sizeof(ModulationType));
110 
111 
112 #ifdef BDAPLGIN_TRACE
113     WCHAR Buffer[100];
114     swprintf(Buffer, L"CBDADigitalDemodulator::put_ModulationType: pModulationType %lu hr %lx\n", *pModulationType, hr);
115     OutputDebugStringW(Buffer);
116 #endif
117 
118     return hr;
119 }
120 
121 HRESULT
122 STDMETHODCALLTYPE
get_ModulationType(ModulationType * pModulationType)123 CBDADigitalDemodulator::get_ModulationType(ModulationType *pModulationType)
124 {
125     return E_NOINTERFACE;
126 }
127 
128 HRESULT
129 STDMETHODCALLTYPE
put_InnerFECMethod(FECMethod * pFECMethod)130 CBDADigitalDemodulator::put_InnerFECMethod(FECMethod *pFECMethod)
131 {
132     KSP_NODE Node;
133     HRESULT hr;
134 
135     // setup request
136     Node.NodeId = m_NodeId;
137     Node.Reserved = 0;
138 
139     // perform request
140     hr = m_pProperty->Set(KSPROPSETID_BdaDigitalDemodulator, KSPROPERTY_BDA_INNER_FEC_TYPE, &Node.NodeId, sizeof(KSP_NODE)-sizeof(KSPROPERTY), pFECMethod, sizeof(FECMethod));
141 
142 
143 #ifdef BDAPLGIN_TRACE
144     WCHAR Buffer[100];
145     swprintf(Buffer, L"CBDADigitalDemodulator::put_InnerFECMethod: pFECMethod %lu hr %lx\n", *pFECMethod, hr);
146     OutputDebugStringW(Buffer);
147 #endif
148 
149     return hr;
150 }
151 
152 HRESULT
153 STDMETHODCALLTYPE
get_InnerFECMethod(FECMethod * pFECMethod)154 CBDADigitalDemodulator::get_InnerFECMethod(FECMethod *pFECMethod)
155 {
156     return E_NOINTERFACE;
157 }
158 
159 HRESULT
160 STDMETHODCALLTYPE
put_InnerFECRate(BinaryConvolutionCodeRate * pFECRate)161 CBDADigitalDemodulator::put_InnerFECRate(BinaryConvolutionCodeRate *pFECRate)
162 {
163     KSP_NODE Node;
164     HRESULT hr;
165 
166     // setup request
167     Node.NodeId = m_NodeId;
168     Node.Reserved = 0;
169 
170     // perform request
171     hr = m_pProperty->Set(KSPROPSETID_BdaDigitalDemodulator, KSPROPERTY_BDA_INNER_FEC_RATE, &Node.NodeId, sizeof(KSP_NODE)-sizeof(KSPROPERTY), pFECRate, sizeof(BinaryConvolutionCodeRate));
172 
173 #ifdef BDAPLGIN_TRACE
174     WCHAR Buffer[100];
175     swprintf(Buffer, L"CBDADigitalDemodulator::put_InnerFECRate: pFECRate %lu hr %lx\n", *pFECRate, hr);
176     OutputDebugStringW(Buffer);
177 #endif
178 
179     return hr;
180 }
181 
182 HRESULT
183 STDMETHODCALLTYPE
get_InnerFECRate(BinaryConvolutionCodeRate * pFECRate)184 CBDADigitalDemodulator::get_InnerFECRate(BinaryConvolutionCodeRate *pFECRate)
185 {
186     return E_NOINTERFACE;
187 }
188 
189 HRESULT
190 STDMETHODCALLTYPE
put_OuterFECMethod(FECMethod * pFECMethod)191 CBDADigitalDemodulator::put_OuterFECMethod(FECMethod *pFECMethod)
192 {
193     KSP_NODE Node;
194     HRESULT hr;
195 
196     // setup request
197     Node.NodeId = m_NodeId;
198     Node.Reserved = 0;
199 
200     // perform request
201     hr = m_pProperty->Set(KSPROPSETID_BdaDigitalDemodulator, KSPROPERTY_BDA_OUTER_FEC_TYPE, &Node.NodeId, sizeof(KSP_NODE)-sizeof(KSPROPERTY), pFECMethod, sizeof(FECMethod));
202 
203 #ifdef BDAPLGIN_TRACE
204     WCHAR Buffer[100];
205     swprintf(Buffer, L"CBDADigitalDemodulator::put_OuterFECMethod: pFECMethod %lu hr %lx\n", *pFECMethod, hr);
206     OutputDebugStringW(Buffer);
207 #endif
208 
209     return hr;
210 }
211 
212 
213 HRESULT
get_OuterFECMethod(FECMethod * pFECMethod)214 STDMETHODCALLTYPE CBDADigitalDemodulator::get_OuterFECMethod(FECMethod *pFECMethod)
215 {
216     return E_NOINTERFACE;
217 }
218 
219 HRESULT
220 STDMETHODCALLTYPE
put_OuterFECRate(BinaryConvolutionCodeRate * pFECRate)221 CBDADigitalDemodulator::put_OuterFECRate(BinaryConvolutionCodeRate *pFECRate)
222 {
223     KSP_NODE Node;
224     HRESULT hr;
225 
226     // setup request
227     Node.NodeId = m_NodeId;
228     Node.Reserved = 0;
229 
230     // perform request
231     hr = m_pProperty->Set(KSPROPSETID_BdaDigitalDemodulator, KSPROPERTY_BDA_OUTER_FEC_RATE, &Node.NodeId, sizeof(KSP_NODE)-sizeof(KSPROPERTY), pFECRate, sizeof(BinaryConvolutionCodeRate));
232 
233 #ifdef BDAPLGIN_TRACE
234     WCHAR Buffer[100];
235     swprintf(Buffer, L"CBDADigitalDemodulator::put_OuterFECRate: pFECRate %lu hr %lx\n", *pFECRate, hr);
236     OutputDebugStringW(Buffer);
237 #endif
238 
239     return hr;
240 }
241 
242 HRESULT
243 STDMETHODCALLTYPE
get_OuterFECRate(BinaryConvolutionCodeRate * pFECRate)244 CBDADigitalDemodulator::get_OuterFECRate(BinaryConvolutionCodeRate *pFECRate)
245 {
246     return E_NOINTERFACE;
247 }
248 
249 HRESULT
250 STDMETHODCALLTYPE
put_SymbolRate(ULONG * pSymbolRate)251 CBDADigitalDemodulator::put_SymbolRate(ULONG *pSymbolRate)
252 {
253     KSP_NODE Node;
254     HRESULT hr;
255 
256     // setup request
257     Node.NodeId = m_NodeId;
258     Node.Reserved = 0;
259 
260     // perform request
261     hr = m_pProperty->Set(KSPROPSETID_BdaDigitalDemodulator, KSPROPERTY_BDA_SYMBOL_RATE, &Node.NodeId, sizeof(KSP_NODE)-sizeof(KSPROPERTY), pSymbolRate, sizeof(ULONG));
262 
263 #ifdef BDAPLGIN_TRACE
264     WCHAR Buffer[100];
265     swprintf(Buffer, L"CBDADigitalDemodulator::put_SymbolRate: pSymbolRate %lu hr %lx\n", *pSymbolRate, hr);
266     OutputDebugStringW(Buffer);
267 #endif
268 
269     return hr;
270 }
271 
272 HRESULT
273 STDMETHODCALLTYPE
get_SymbolRate(ULONG * pSymbolRate)274 CBDADigitalDemodulator::get_SymbolRate(ULONG *pSymbolRate)
275 {
276     return E_NOINTERFACE;
277 }
278 
279 HRESULT
280 STDMETHODCALLTYPE
put_SpectralInversion(SpectralInversion * pSpectralInversion)281 CBDADigitalDemodulator::put_SpectralInversion(SpectralInversion *pSpectralInversion)
282 {
283     KSP_NODE Node;
284     HRESULT hr;
285 
286     // setup request
287     Node.NodeId = m_NodeId;
288     Node.Reserved = 0;
289 
290     // perform request
291     hr = m_pProperty->Set(KSPROPSETID_BdaDigitalDemodulator, KSPROPERTY_BDA_SPECTRAL_INVERSION, &Node.NodeId, sizeof(KSP_NODE)-sizeof(KSPROPERTY), pSpectralInversion, sizeof(SpectralInversion));
292 
293 #ifdef BDAPLGIN_TRACE
294     WCHAR Buffer[100];
295     swprintf(Buffer, L"CBDADigitalDemodulator::put_SpectralInversion: pSpectralInversion %lu hr %lx\n", *pSpectralInversion, hr);
296     OutputDebugStringW(Buffer);
297 #endif
298 
299     return hr;
300 }
301 
302 HRESULT
303 STDMETHODCALLTYPE
get_SpectralInversion(SpectralInversion * pSpectralInversion)304 CBDADigitalDemodulator::get_SpectralInversion(SpectralInversion *pSpectralInversion)
305 {
306     return E_NOINTERFACE;
307 }
308 
309 
310 HRESULT
311 WINAPI
CBDADigitalDemodulator_fnConstructor(IKsPropertySet * pProperty,ULONG NodeId,REFIID riid,LPVOID * ppv)312 CBDADigitalDemodulator_fnConstructor(
313     IKsPropertySet * pProperty,
314     ULONG NodeId,
315     REFIID riid,
316     LPVOID * ppv)
317 {
318     // construct device control
319     CBDADigitalDemodulator * handler = new CBDADigitalDemodulator(pProperty, NodeId);
320 
321 #ifdef BDAPLGIN_TRACE
322     OutputDebugStringW(L"CBDADigitalDemodulator_fnConstructor\n");
323 #endif
324 
325     if (!handler)
326         return E_OUTOFMEMORY;
327 
328     if (FAILED(handler->QueryInterface(riid, ppv)))
329     {
330         /* not supported */
331         delete handler;
332         return E_NOINTERFACE;
333     }
334 
335     return NOERROR;
336 }
337