ReactOS 0.4.16-dev-92-g0c2cdca
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 */
12const GUID IID_IUnknown = {0x00000000, 0x0000, 0x0000, {0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}};
13const GUID IID_IClassFactory = {0x00000001, 0x0000, 0x0000, {0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}};
14
15class CKsDataTypeHandler : public IKsDataTypeHandler
16{
17public:
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
59protected:
62};
63
64
68 IN REFIID refiid,
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
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
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
168 IN OUT IMediaSample *Sample,
169 IN OUT PVOID StreamHeader,
170 IN KSIOOPERATION IoOperation)
171{
172 return NOERROR;
173}
174
178 OUT ULONG* ExtendedSize)
179{
180 /* no header extension required */
181 *ExtendedSize = 0;
182 return NOERROR;
183}
184
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
227WINAPI
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}
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define STDMETHODIMP
Definition: basetyps.h:43
#define STDMETHODCALLTYPE
Definition: bdasup.h:9
_In_ BOOLEAN Release
Definition: cdrom.h:920
STDMETHODIMP_(ULONG) Release()
Definition: datatype.cpp:25
AM_MEDIA_TYPE * m_Type
Definition: datatype.cpp:61
HRESULT STDMETHODCALLTYPE KsIsMediaTypeInRanges(IN PVOID DataRanges)
Definition: datatype.cpp:96
HRESULT STDMETHODCALLTYPE KsSetMediaType(IN const AM_MEDIA_TYPE *AmMediaType)
Definition: datatype.cpp:187
HRESULT STDMETHODCALLTYPE KsPrepareIoOperation(IN OUT IMediaSample *Sample, IN OUT PVOID StreamHeader, IN KSIOOPERATION IoOperation)
Definition: datatype.cpp:167
virtual ~CKsDataTypeHandler()
Definition: datatype.cpp:44
STDMETHODIMP QueryInterface(REFIID InterfaceId, PVOID *Interface)
Definition: datatype.cpp:67
STDMETHODIMP_(ULONG) AddRef()
Definition: datatype.cpp:20
HRESULT STDMETHODCALLTYPE KsQueryExtendedSize(OUT ULONG *ExtendedSize)
Definition: datatype.cpp:177
HRESULT STDMETHODCALLTYPE KsCompleteIoOperation(IN OUT IMediaSample *Sample, IN OUT PVOID StreamHeader, IN KSIOOPERATION IoOperation, IN BOOL Cancelled)
Definition: datatype.cpp:84
const GUID IID_IUnknown
Definition: datatype.cpp:12
const GUID IID_IClassFactory
Definition: datatype.cpp:13
HRESULT WINAPI CKsDataTypeHandler_Constructor(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv)
Definition: datatype.cpp:228
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_FAIL
Definition: ddrawi.h:102
#define FALSE
Definition: types.h:117
UINT(* handler)(MSIPACKAGE *)
Definition: action.c:7512
unsigned int BOOL
Definition: ntddk_ex.h:94
_Must_inspect_result_ _Out_writes_to_ DataLength PHIDP_DATA DataList
Definition: hidpi.h:333
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:442
LPVOID WINAPI CoTaskMemAlloc(SIZE_T size)
Definition: ifs.c:426
void WINAPI SHIM_OBJ_NAME() OutputDebugStringW(LPCWSTR lpOutputString)
Definition: ignoredbgout.c:23
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
ULONG AddRef()
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
#define GUID_NULL
Definition: ks.h:106
union KSDATAFORMAT * PKSDATARANGE
struct KSMULTIPLE_ITEM * PKSMULTIPLE_ITEM
struct _WAVEFORMATEX * LPWAVEFORMATEX
static ULONG WINAPI AddRef(IStream *iface)
Definition: clist.c:90
#define L(x)
Definition: ntvdm.h:50
long LONG
Definition: pedump.c:60
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define REFIID
Definition: guiddef.h:118
@ Output
Definition: arc.h:85
int nChannels
Definition: imaadp32.c:63
void * PVOID
Definition: typedefs.h:50
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
_In_ WDFCOLLECTION _In_ ULONG Index
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE Interface
Definition: wdffdo.h:465
#define CopyMemory
Definition: winbase.h:1710
#define OutputDebugString
Definition: winbase.h:3890
#define WINAPI
Definition: msvc.h:6
#define E_NOINTERFACE
Definition: winerror.h:2364
#define NOERROR
Definition: winerror.h:2354
unsigned char BYTE
Definition: xxhash.c:193