ReactOS  0.4.14-dev-323-g6fe6a88
datatype.cpp
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS WDM Streaming ActiveMovie Proxy
4  * FILE: dll/directx/ksproxy/datatype.cpp
5  * PURPOSE: IKsDataTypeHandler interface
6  *
7  * PROGRAMMERS: Johannes Anderwald (johannes.anderwald@reactos.org)
8  */
9 #include "precomp.h"
10 
11 /* FIXME guid mess */
12 const GUID IID_IUnknown = {0x00000000, 0x0000, 0x0000, {0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}};
13 const GUID IID_IClassFactory = {0x00000001, 0x0000, 0x0000, {0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}};
14 
15 class CKsDataTypeHandler : public IKsDataTypeHandler
16 {
17 public:
19 
21  {
23  return m_Ref;
24  }
26  {
28 
29  if (!m_Ref)
30  {
31  delete this;
32  return 0;
33  }
34  return m_Ref;
35  }
36 
37  HRESULT STDMETHODCALLTYPE KsCompleteIoOperation(IN OUT IMediaSample *Sample, IN OUT PVOID StreamHeader, IN KSIOOPERATION IoOperation, IN BOOL Cancelled);
39  HRESULT STDMETHODCALLTYPE KsPrepareIoOperation(IN OUT IMediaSample *Sample, IN OUT PVOID StreamHeader, IN KSIOOPERATION IoOperation);
42 
45  {
46  if (m_Type)
47  {
48  if (m_Type->pbFormat)
49  CoTaskMemFree(m_Type->pbFormat);
50 
51  if (m_Type->pUnk)
52  m_Type->pUnk->Release();
53 
55  }
56 
57  };
58 
59 protected:
60  LONG m_Ref;
62 };
63 
64 
65 HRESULT
68  IN REFIID refiid,
69  OUT PVOID* Output)
70 {
71  if (IsEqualGUID(refiid, IID_IUnknown) ||
72  IsEqualGUID(refiid, IID_IKsDataTypeHandler))
73  {
74  *Output = PVOID(this);
75  reinterpret_cast<IUnknown*>(*Output)->AddRef();
76  return NOERROR;
77  }
78  return E_NOINTERFACE;
79 }
80 
81 
82 HRESULT
85  IN OUT IMediaSample *Sample,
86  IN OUT PVOID StreamHeader,
87  IN KSIOOPERATION IoOperation,
88  IN BOOL Cancelled)
89 {
90  return NOERROR;
91 }
92 
93 
94 HRESULT
97  IN PVOID DataRanges)
98 {
100  PKSDATARANGE DataRange;
101  ULONG Index;
102  //HRESULT hr = S_FALSE;
103 
104 #ifdef KSPROXY_TRACE
105  OutputDebugStringW(L"CKsDataTypeHandler::KsIsMediaTypeInRanges\n");
106 #endif
107 
108  DataList = (PKSMULTIPLE_ITEM)DataRanges;
109  DataRange = (PKSDATARANGE)(DataList + 1);
110 
111  for(Index = 0; Index < DataList->Count; Index++)
112  {
113  BOOL bMatch = FALSE;
114 
115  if (DataRange->FormatSize >= sizeof(KSDATARANGE))
116  {
117  bMatch = IsEqualGUID(DataRange->MajorFormat, GUID_NULL);
118  }
119 
120  if (!bMatch && DataRange->FormatSize >= sizeof(KSDATARANGE_AUDIO))
121  {
122  bMatch = IsEqualGUID(DataRange->MajorFormat, MEDIATYPE_Audio);
123  }
124 
125  if (bMatch)
126  {
127  if (IsEqualGUID(DataRange->SubFormat, m_Type->subtype) ||
128  IsEqualGUID(DataRange->SubFormat, GUID_NULL))
129  {
130  if (IsEqualGUID(DataRange->Specifier, m_Type->formattype) ||
131  IsEqualGUID(DataRange->Specifier, GUID_NULL))
132  {
133  if (!IsEqualGUID(m_Type->formattype, FORMAT_WaveFormatEx) && !IsEqualGUID(DataRange->Specifier, FORMAT_WaveFormatEx))
134  {
135  //found match
136  //hr = S_OK;
137  break;
138  }
139 
140  if (DataRange->FormatSize >= sizeof(KSDATARANGE_AUDIO) && m_Type->cbFormat >= sizeof(WAVEFORMATEX))
141  {
143  PKSDATARANGE_AUDIO AudioRange = (PKSDATARANGE_AUDIO)DataRange;
144 
145  if (Format->nSamplesPerSec >= AudioRange->MinimumSampleFrequency &&
146  Format->nSamplesPerSec <= AudioRange->MaximumSampleFrequency &&
147  Format->wBitsPerSample >= AudioRange->MinimumSampleFrequency &&
148  Format->wBitsPerSample <= AudioRange->MaximumBitsPerSample &&
149  Format->nChannels <= AudioRange->MaximumChannels)
150  {
151  // found match
152  //hr = S_OK;
153  break;
154  }
155  }
156  }
157  }
158  }
159 
160  DataRange = (PKSDATARANGE)(((ULONG_PTR)DataRange + DataRange->FormatSize + 7) & ~7);
161  }
162  return S_OK;
163 }
164 
165 HRESULT
168  IN OUT IMediaSample *Sample,
169  IN OUT PVOID StreamHeader,
170  IN KSIOOPERATION IoOperation)
171 {
172  return NOERROR;
173 }
174 
175 HRESULT
178  OUT ULONG* ExtendedSize)
179 {
180  /* no header extension required */
181  *ExtendedSize = 0;
182  return NOERROR;
183 }
184 
185 HRESULT
188  IN const AM_MEDIA_TYPE* AmMediaType)
189 {
190 #ifdef KSPROXY_TRACE
191  OutputDebugString("CKsDataTypeHandler::KsSetMediaType\n");
192 #endif
193 
194  if (m_Type)
195  {
196  /* media type can only be set once */
197  return E_FAIL;
198  }
199 
201  if (!m_Type)
202  return E_OUTOFMEMORY;
203 
204  CopyMemory(m_Type, AmMediaType, sizeof(AM_MEDIA_TYPE));
205 
206  if (m_Type->cbFormat)
207  {
208  m_Type->pbFormat = (BYTE*)CoTaskMemAlloc(m_Type->cbFormat);
209 
210  if (!m_Type->pbFormat)
211  {
213  return E_OUTOFMEMORY;
214  }
215 
216  CopyMemory(m_Type->pbFormat, AmMediaType->pbFormat, m_Type->cbFormat);
217  }
218 
219  if (m_Type->pUnk)
220  m_Type->pUnk->AddRef();
221 
222 
223  return S_OK;
224 }
225 
226 HRESULT
227 WINAPI
229  IUnknown * pUnkOuter,
230  REFIID riid,
231  LPVOID * ppv)
232 {
233 #ifdef KSPROXY_TRACE
234  OutputDebugStringW(L"CKsDataTypeHandler_Constructor\n");
235 #endif
236 
238 
239  if (!handler)
240  return E_OUTOFMEMORY;
241 
242  if (FAILED(handler->QueryInterface(riid, ppv)))
243  {
244  /* not supported */
245  delete handler;
246  return E_NOINTERFACE;
247  }
248 
249  return NOERROR;
250 }
virtual ~CKsDataTypeHandler()
Definition: datatype.cpp:44
#define IN
Definition: typedefs.h:38
#define REFIID
Definition: guiddef.h:118
#define E_NOINTERFACE
Definition: winerror.h:2364
HRESULT STDMETHODCALLTYPE KsPrepareIoOperation(IN OUT IMediaSample *Sample, IN OUT PVOID StreamHeader, IN KSIOOPERATION IoOperation)
Definition: datatype.cpp:167
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:420
_In_ BOOLEAN Release
Definition: classpnp.h:929
#define NOERROR
Definition: winerror.h:2354
REFIID riid
Definition: precomp.h:44
REFIID LPVOID * ppv
Definition: atlbase.h:39
int nChannels
Definition: imaadp32.c:63
AM_MEDIA_TYPE * m_Type
Definition: datatype.cpp:61
#define OutputDebugString
Definition: winbase.h:3714
#define E_FAIL
Definition: ddrawi.h:102
uint32_t ULONG_PTR
Definition: typedefs.h:63
void WINAPI SHIM_OBJ_NAME() OutputDebugStringW(LPCWSTR lpOutputString)
Definition: ignoredbgout.c:23
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
#define STDMETHODIMP
Definition: basetyps.h:43
struct _WAVEFORMATEX * LPWAVEFORMATEX
_Must_inspect_result_ _Out_writes_to_ DataLength PHIDP_DATA DataList
Definition: hidpi.h:333
HRESULT STDMETHODCALLTYPE KsIsMediaTypeInRanges(IN PVOID DataRanges)
Definition: datatype.cpp:96
void * PVOID
Definition: retypes.h:9
HRESULT STDMETHODCALLTYPE KsCompleteIoOperation(IN OUT IMediaSample *Sample, IN OUT PVOID StreamHeader, IN KSIOOPERATION IoOperation, IN BOOL Cancelled)
Definition: datatype.cpp:84
IN PVOID IN PVOID IN USHORT IN USHORT IN PINTERFACE Interface
Definition: pci.h:359
LONG HRESULT
Definition: typedefs.h:77
HRESULT STDMETHODCALLTYPE KsQueryExtendedSize(OUT ULONG *ExtendedSize)
Definition: datatype.cpp:177
#define WINAPI
Definition: msvc.h:8
#define CopyMemory
Definition: winbase.h:1640
static const UCHAR Index[8]
Definition: usbohci.c:18
#define STDMETHODCALLTYPE
Definition: bdasup.h:9
static const WCHAR L[]
Definition: oid.c:1250
HRESULT WINAPI CKsDataTypeHandler_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv)
Definition: datatype.cpp:228
#define InterlockedDecrement
Definition: armddk.h:52
Definition: arc.h:85
unsigned char BYTE
Definition: mem.h:68
#define GUID_NULL
Definition: ks.h:106
struct KSMULTIPLE_ITEM * PKSMULTIPLE_ITEM
union KSDATAFORMAT * PKSDATARANGE
#define S_OK
Definition: intsafe.h:59
STDMETHODIMP_(ULONG) AddRef()
Definition: datatype.cpp:20
#define InterlockedIncrement
Definition: armddk.h:53
STDMETHODIMP QueryInterface(REFIID InterfaceId, PVOID *Interface)
Definition: datatype.cpp:67
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4112
static ULONG WINAPI AddRef(IStream *iface)
Definition: clist.c:90
#define OUT
Definition: typedefs.h:39
unsigned int ULONG
Definition: retypes.h:1
UINT(* handler)(MSIPACKAGE *)
Definition: action.c:7786
const GUID IID_IUnknown
Definition: datatype.cpp:12
LPVOID WINAPI CoTaskMemAlloc(SIZE_T size)
Definition: ifs.c:404
HRESULT STDMETHODCALLTYPE KsSetMediaType(IN const AM_MEDIA_TYPE *AmMediaType)
Definition: datatype.cpp:187
const GUID IID_IClassFactory
Definition: datatype.cpp:13
STDMETHODIMP_(ULONG) Release()
Definition: datatype.cpp:25