ReactOS  0.4.14-dev-323-g6fe6a88
enum_mediatypes.cpp
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS Network Provider for MPEG2 based networks
4  * FILE: dll/directx/ksproxy/enum_mediatypes.cpp
5  * PURPOSE: IEnumMediaTypes interface
6  *
7  * PROGRAMMERS: Johannes Anderwald (johannes.anderwald@reactos.org)
8  */
9 #include "precomp.h"
10 
12 {
13 public:
15 
17  {
19  return m_Ref;
20  }
22  {
24  if (!m_Ref)
25  {
26  delete this;
27  return 0;
28  }
29  return m_Ref;
30  }
31 
32  HRESULT STDMETHODCALLTYPE Next(ULONG cMediaTypes, AM_MEDIA_TYPE **ppMediaTypes, ULONG *pcFetched);
33  HRESULT STDMETHODCALLTYPE Skip(ULONG cMediaTypes);
36 
37 
38  CEnumMediaTypes(ULONG MediaTypeCount, AM_MEDIA_TYPE * MediaTypes) : m_Ref(0), m_MediaTypeCount(MediaTypeCount), m_MediaTypes(MediaTypes), m_Index(0){};
39  virtual ~CEnumMediaTypes(){};
40 
41 protected:
42  LONG m_Ref;
46 };
47 
48 HRESULT
51  IN REFIID refiid,
52  OUT PVOID* Output)
53 {
54  if (IsEqualGUID(refiid, IID_IUnknown))
55  {
56  *Output = PVOID(this);
57  reinterpret_cast<IUnknown*>(*Output)->AddRef();
58  return NOERROR;
59  }
60  if (IsEqualGUID(refiid, IID_IEnumMediaTypes))
61  {
62  *Output = (IEnumMediaTypes*)(this);
63  reinterpret_cast<IEnumMediaTypes*>(*Output)->AddRef();
64  return NOERROR;
65  }
66 
67  return E_NOINTERFACE;
68 }
69 
70 //-------------------------------------------------------------------
71 // IEnumMediaTypes
72 //
73 
74 HRESULT
77  ULONG cMediaTypes,
78  AM_MEDIA_TYPE **ppMediaTypes,
79  ULONG *pcFetched)
80 {
81  ULONG i = 0;
82  AM_MEDIA_TYPE * MediaType;
83 
84  if (!ppMediaTypes)
85  return E_POINTER;
86 
87  if (cMediaTypes > 1 && !pcFetched)
88  return E_INVALIDARG;
89 
90  while(i < cMediaTypes)
91  {
92  if (m_Index + i >= m_MediaTypeCount)
93  break;
94 
95  MediaType = (AM_MEDIA_TYPE*)CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE));
96  if (!MediaType)
97  break;
98 
99  if (m_MediaTypes[m_Index + i].cbFormat)
100  {
101  LPBYTE pFormat = (LPBYTE)CoTaskMemAlloc(m_MediaTypes[m_Index + i].cbFormat);
102  if (!pFormat)
103  {
104  CoTaskMemFree(MediaType);
105  break;
106  }
107 
108  CopyMemory(MediaType, &m_MediaTypes[m_Index + i], sizeof(AM_MEDIA_TYPE));
109  MediaType->pbFormat = pFormat;
110  CopyMemory(MediaType->pbFormat, m_MediaTypes[m_Index + i].pbFormat, m_MediaTypes[m_Index + i].cbFormat);
111  MediaType->pUnk = (IUnknown *)this;
112  MediaType->pUnk->AddRef();
113  }
114  else
115  {
116  CopyMemory(MediaType, &m_MediaTypes[m_Index + i], sizeof(AM_MEDIA_TYPE));
117  }
118 
119  if (MediaType->pUnk)
120  {
121  MediaType->pUnk->AddRef();
122  }
123 
124  ppMediaTypes[i] = MediaType;
125  i++;
126  }
127 
128  if (pcFetched)
129  {
130  *pcFetched = i;
131  }
132 
133  m_Index += i;
134  if (i < cMediaTypes)
135  return S_FALSE;
136  else
137  return S_OK;
138 }
139 
140 HRESULT
143  ULONG cMediaTypes)
144 {
145  if (cMediaTypes + m_Index >= m_MediaTypeCount)
146  {
147  return S_FALSE;
148  }
149 
150  m_Index += cMediaTypes;
151  return S_OK;
152 }
153 
154 HRESULT
157 {
158  m_Index = 0;
159  return S_OK;
160 }
161 
162 HRESULT
165  IEnumMediaTypes **ppEnum)
166 {
167 #ifdef KSPROXY_TRACE
168  OutputDebugStringW(L"CEnumMediaTypes::Clone : NotImplemented\n");
169 #endif
170  return E_NOTIMPL;
171 }
172 
173 HRESULT
174 WINAPI
176  ULONG MediaTypeCount,
177  AM_MEDIA_TYPE * MediaTypes,
178  REFIID riid,
179  LPVOID * ppv)
180 {
181  CEnumMediaTypes * handler = new CEnumMediaTypes(MediaTypeCount, MediaTypes);
182 
183 #ifdef KSPROXY_TRACE
185  LPOLESTR lpstr;
187  swprintf(Buffer, L"CEnumMediaTypes_fnConstructor riid %s\n", lpstr);
189 #endif
190 
191  if (!handler)
192  {
193  CoTaskMemFree(MediaTypes);
194  return E_OUTOFMEMORY;
195  }
196 
197  if (FAILED(handler->QueryInterface(riid, ppv)))
198  {
199  /* not supported */
200  delete handler;
201  return E_NOINTERFACE;
202  }
203 
204  return NOERROR;
205 }
206 
#define IN
Definition: typedefs.h:38
#define REFIID
Definition: guiddef.h:118
#define E_NOINTERFACE
Definition: winerror.h:2364
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:420
#define NOERROR
Definition: winerror.h:2354
REFIID riid
Definition: precomp.h:44
HRESULT WINAPI CEnumMediaTypes_fnConstructor(ULONG MediaTypeCount, AM_MEDIA_TYPE *MediaTypes, REFIID riid, LPVOID *ppv)
REFIID LPVOID * ppv
Definition: atlbase.h:39
static LPOLESTR
Definition: stg_prop.c:27
virtual ~CEnumMediaTypes()
void WINAPI SHIM_OBJ_NAME() OutputDebugStringW(LPCWSTR lpOutputString)
Definition: ignoredbgout.c:23
STDMETHODIMP_(ULONG) Release()
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned char * LPBYTE
Definition: typedefs.h:52
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
long LONG
Definition: pedump.c:60
AM_MEDIA_TYPE * m_MediaTypes
#define STDMETHODIMP
Definition: basetyps.h:43
ULONG Release()
#define S_FALSE
Definition: winerror.h:2357
#define E_INVALIDARG
Definition: ddrawi.h:101
Definition: bufpool.h:45
void * PVOID
Definition: retypes.h:9
IN PVOID IN PVOID IN USHORT IN USHORT IN PINTERFACE Interface
Definition: pci.h:359
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
const GUID IID_IUnknown
HRESULT STDMETHODCALLTYPE Reset()
#define MAX_PATH
Definition: compat.h:26
#define swprintf(buf, format,...)
Definition: sprintf.c:56
#define WINAPI
Definition: msvc.h:8
#define CopyMemory
Definition: winbase.h:1640
#define STDMETHODCALLTYPE
Definition: bdasup.h:9
ULONG AddRef()
HRESULT STDMETHODCALLTYPE Skip(ULONG cMediaTypes)
static const WCHAR L[]
Definition: oid.c:1250
#define InterlockedDecrement
Definition: armddk.h:52
Definition: arc.h:85
CEnumMediaTypes(ULONG MediaTypeCount, AM_MEDIA_TYPE *MediaTypes)
STDMETHODIMP_(ULONG) AddRef()
#define S_OK
Definition: intsafe.h:59
#define InterlockedIncrement
Definition: armddk.h:53
#define E_NOTIMPL
Definition: ddrawi.h:99
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4112
HRESULT STDMETHODCALLTYPE Next(ULONG cMediaTypes, AM_MEDIA_TYPE **ppMediaTypes, ULONG *pcFetched)
STDMETHODIMP QueryInterface(REFIID InterfaceId, PVOID *Interface)
#define OUT
Definition: typedefs.h:39
unsigned int ULONG
Definition: retypes.h:1
static LPCSTR lpstr
Definition: font.c:51
UINT(* handler)(MSIPACKAGE *)
Definition: action.c:7786
#define E_POINTER
Definition: winerror.h:2365
HRESULT STDMETHODCALLTYPE Clone(IEnumMediaTypes **ppEnum)
LPVOID WINAPI CoTaskMemAlloc(SIZE_T size)
Definition: ifs.c:404
HRESULT WINAPI StringFromCLSID(REFCLSID id, LPOLESTR *idstr)
Definition: compobj.c:2412