ReactOS  0.4.14-dev-323-g6fe6a88
mediatype.c
Go to the documentation of this file.
1 /*
2  * Implementation of MedaType utility functions
3  *
4  * Copyright 2003 Robert Shearman
5  * Copyright 2010 Aric Stewart, CodeWeavers
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21 #include <stdarg.h>
22 
23 #define COBJMACROS
24 #include "dshow.h"
25 
26 #include "wine/strmbase.h"
27 #include "wine/debug.h"
28 
30 
32 {
33  *dest = *src;
34  if (src->pbFormat)
35  {
36  dest->pbFormat = CoTaskMemAlloc(src->cbFormat);
37  if (!dest->pbFormat)
38  return E_OUTOFMEMORY;
39  memcpy(dest->pbFormat, src->pbFormat, src->cbFormat);
40  }
41  if (dest->pUnk)
42  IUnknown_AddRef(dest->pUnk);
43  return S_OK;
44 }
45 
47 {
48  if (pMediaType->pbFormat)
49  {
50  CoTaskMemFree(pMediaType->pbFormat);
51  pMediaType->pbFormat = NULL;
52  }
53  if (pMediaType->pUnk)
54  {
55  IUnknown_Release(pMediaType->pUnk);
56  pMediaType->pUnk = NULL;
57  }
58 }
59 
61 {
62  AM_MEDIA_TYPE * pDest;
63 
64  pDest = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE));
65  if (!pDest)
66  return NULL;
67 
68  if (FAILED(CopyMediaType(pDest, pSrc)))
69  {
70  CoTaskMemFree(pDest);
71  return NULL;
72  }
73 
74  return pDest;
75 }
76 
78 {
79  FreeMediaType(pMediaType);
80  CoTaskMemFree(pMediaType);
81 }
82 
83 typedef struct tagENUMEDIADETAILS
84 {
88 
89 typedef struct IEnumMediaTypesImpl
90 {
92  LONG refCount;
98  ULONG uIndex;
100 
102 {
103  return CONTAINING_RECORD(iface, IEnumMediaTypesImpl, IEnumMediaTypes_iface);
104 }
105 
106 static const struct IEnumMediaTypesVtbl IEnumMediaTypesImpl_Vtbl;
107 
109 {
110  ULONG i;
111  IEnumMediaTypesImpl * pEnumMediaTypes = CoTaskMemAlloc(sizeof(IEnumMediaTypesImpl));
112  AM_MEDIA_TYPE amt;
113 
114  *ppEnum = NULL;
115 
116  if (!pEnumMediaTypes)
117  return E_OUTOFMEMORY;
118 
119  pEnumMediaTypes->IEnumMediaTypes_iface.lpVtbl = &IEnumMediaTypesImpl_Vtbl;
120  pEnumMediaTypes->refCount = 1;
121  pEnumMediaTypes->uIndex = 0;
122  pEnumMediaTypes->enumMediaFunction = enumFunc;
123  pEnumMediaTypes->mediaVersionFunction = versionFunc;
124  IPin_AddRef(&basePin->IPin_iface);
125  pEnumMediaTypes->basePin = basePin;
126 
127  i = 0;
128  while (enumFunc(basePin, i, &amt) == S_OK)
129  {
130  FreeMediaType(&amt);
131  i++;
132  }
133 
134  pEnumMediaTypes->enumMediaDetails.cMediaTypes = i;
135  pEnumMediaTypes->enumMediaDetails.pMediaTypes = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE) * i);
136  memset(pEnumMediaTypes->enumMediaDetails.pMediaTypes, 0, sizeof(AM_MEDIA_TYPE) * i);
137  for (i = 0; i < pEnumMediaTypes->enumMediaDetails.cMediaTypes; i++)
138  {
139  HRESULT hr;
140 
141  if (FAILED(hr = enumFunc(basePin, i, &pEnumMediaTypes->enumMediaDetails.pMediaTypes[i])))
142  {
143  IEnumMediaTypes_Release(&pEnumMediaTypes->IEnumMediaTypes_iface);
144  return hr;
145  }
146  }
147  *ppEnum = &pEnumMediaTypes->IEnumMediaTypes_iface;
148  pEnumMediaTypes->currentVersion = versionFunc(basePin);
149  return S_OK;
150 }
151 
153 {
154  TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ret_iface);
155 
156  if (IsEqualIID(riid, &IID_IUnknown) ||
157  IsEqualIID(riid, &IID_IEnumMediaTypes))
158  {
159  IEnumMediaTypes_AddRef(iface);
160  *ret_iface = iface;
161  return S_OK;
162  }
163 
164  *ret_iface = NULL;
165 
166  WARN("No interface for %s\n", debugstr_guid(riid));
167 
168  return E_NOINTERFACE;
169 }
170 
172 {
174  ULONG ref = InterlockedIncrement(&This->refCount);
175 
176  TRACE("(%p)->(): new ref = %u\n", iface, ref);
177 
178  return ref;
179 }
180 
182 {
184  ULONG ref = InterlockedDecrement(&This->refCount);
185 
186  TRACE("(%p)->(): new ref = %u\n", iface, ref);
187 
188  if (!ref)
189  {
190  ULONG i;
191  for (i = 0; i < This->enumMediaDetails.cMediaTypes; i++)
192  FreeMediaType(&This->enumMediaDetails.pMediaTypes[i]);
193  CoTaskMemFree(This->enumMediaDetails.pMediaTypes);
194  IPin_Release(&This->basePin->IPin_iface);
196  }
197  return ref;
198 }
199 
200 static HRESULT WINAPI IEnumMediaTypesImpl_Next(IEnumMediaTypes * iface, ULONG cMediaTypes, AM_MEDIA_TYPE ** ppMediaTypes, ULONG * pcFetched)
201 {
202  ULONG cFetched;
204 
205  TRACE("(%p)->(%u, %p, %p)\n", iface, cMediaTypes, ppMediaTypes, pcFetched);
206 
207  cFetched = min(This->enumMediaDetails.cMediaTypes, This->uIndex + cMediaTypes) - This->uIndex;
208 
209  if (This->currentVersion != This->mediaVersionFunction(This->basePin))
210  return VFW_E_ENUM_OUT_OF_SYNC;
211 
212  TRACE("Next uIndex: %u, cFetched: %u\n", This->uIndex, cFetched);
213 
214  if (cFetched > 0)
215  {
216  ULONG i;
217  for (i = 0; i < cFetched; i++)
218  if (!(ppMediaTypes[i] = CreateMediaType(&This->enumMediaDetails.pMediaTypes[This->uIndex + i])))
219  {
220  while (i--)
221  DeleteMediaType(ppMediaTypes[i]);
222  *pcFetched = 0;
223  return E_OUTOFMEMORY;
224  }
225  }
226 
227  if ((cMediaTypes != 1) || pcFetched)
228  *pcFetched = cFetched;
229 
230  This->uIndex += cFetched;
231 
232  if (cFetched != cMediaTypes)
233  return S_FALSE;
234  return S_OK;
235 }
236 
238 {
240 
241  TRACE("(%p)->(%u)\n", iface, cMediaTypes);
242 
243  if (This->currentVersion != This->mediaVersionFunction(This->basePin))
244  return VFW_E_ENUM_OUT_OF_SYNC;
245 
246  if (This->uIndex + cMediaTypes < This->enumMediaDetails.cMediaTypes)
247  {
248  This->uIndex += cMediaTypes;
249  return S_OK;
250  }
251  return S_FALSE;
252 }
253 
255 {
256  ULONG i;
257  AM_MEDIA_TYPE amt;
259 
260  TRACE("(%p)->()\n", iface);
261 
262  for (i = 0; i < This->enumMediaDetails.cMediaTypes; i++)
263  FreeMediaType(&This->enumMediaDetails.pMediaTypes[i]);
264  CoTaskMemFree(This->enumMediaDetails.pMediaTypes);
265 
266  i = 0;
267  while (This->enumMediaFunction(This->basePin, i, &amt) == S_OK) i++;
268 
269  This->enumMediaDetails.cMediaTypes = i;
270  This->enumMediaDetails.pMediaTypes = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE) * i);
271  for (i = 0; i < This->enumMediaDetails.cMediaTypes; i++)
272  {
273  This->enumMediaFunction(This->basePin, i,&amt);
274  if (FAILED(CopyMediaType(&This->enumMediaDetails.pMediaTypes[i], &amt)))
275  {
276  while (i--)
277  FreeMediaType(&This->enumMediaDetails.pMediaTypes[i]);
278  CoTaskMemFree(This->enumMediaDetails.pMediaTypes);
279  return E_OUTOFMEMORY;
280  }
281  }
282 
283  This->currentVersion = This->mediaVersionFunction(This->basePin);
284  This->uIndex = 0;
285 
286  return S_OK;
287 }
288 
290 {
291  HRESULT hr;
293 
294  TRACE("(%p)->(%p)\n", iface, ppEnum);
295 
296  hr = EnumMediaTypes_Construct(This->basePin, This->enumMediaFunction, This->mediaVersionFunction, ppEnum);
297  if (FAILED(hr))
298  return hr;
299  return IEnumMediaTypes_Skip(*ppEnum, This->uIndex);
300 }
301 
302 static const IEnumMediaTypesVtbl IEnumMediaTypesImpl_Vtbl =
303 {
311 };
static IEnumMediaTypesImpl * impl_from_IEnumMediaTypes(IEnumMediaTypes *iface)
Definition: mediatype.c:101
static ULONG WINAPI IEnumMediaTypesImpl_AddRef(IEnumMediaTypes *iface)
Definition: mediatype.c:171
#define REFIID
Definition: guiddef.h:118
#define E_NOINTERFACE
Definition: winerror.h:2364
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:420
HRESULT hr
Definition: shlfolder.c:183
BasePin * basePin
Definition: mediatype.c:93
REFIID riid
Definition: precomp.h:44
static HRESULT WINAPI IEnumMediaTypesImpl_Next(IEnumMediaTypes *iface, ULONG cMediaTypes, AM_MEDIA_TYPE **ppMediaTypes, ULONG *pcFetched)
Definition: mediatype.c:200
IPin IPin_iface
Definition: strmbase.h:35
#define WARN(fmt,...)
Definition: debug.h:111
struct IEnumMediaTypesImpl IEnumMediaTypesImpl
static ULONG WINAPI IEnumMediaTypesImpl_Release(IEnumMediaTypes *iface)
Definition: mediatype.c:181
Definition: send.c:47
HRESULT WINAPI CopyMediaType(AM_MEDIA_TYPE *dest, const AM_MEDIA_TYPE *src)
Definition: mediatype.c:31
WINE_DEFAULT_DEBUG_CHANNEL(strmbase)
static const struct IEnumMediaTypesVtbl IEnumMediaTypesImpl_Vtbl
Definition: mediatype.c:106
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
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
long LONG
Definition: pedump.c:60
GLenum GLint ref
Definition: glext.h:6028
#define S_FALSE
Definition: winerror.h:2357
smooth NULL
Definition: ftsmooth.c:416
static HRESULT WINAPI IEnumMediaTypesImpl_Skip(IEnumMediaTypes *iface, ULONG cMediaTypes)
Definition: mediatype.c:237
static HRESULT WINAPI IEnumMediaTypesImpl_Clone(IEnumMediaTypes *iface, IEnumMediaTypes **ppEnum)
Definition: mediatype.c:289
#define debugstr_guid
Definition: kernel32.h:35
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
void WINAPI FreeMediaType(AM_MEDIA_TYPE *pMediaType)
Definition: mediatype.c:46
#define TRACE(s)
Definition: solgame.cpp:4
LONG HRESULT
Definition: typedefs.h:77
const GUID IID_IUnknown
#define WINAPI
Definition: msvc.h:8
struct tagENUMEDIADETAILS ENUMMEDIADETAILS
AM_MEDIA_TYPE * pMediaTypes
Definition: mediatype.c:86
HRESULT WINAPI EnumMediaTypes_Construct(BasePin *basePin, BasePin_GetMediaType enumFunc, BasePin_GetMediaTypeVersion versionFunc, IEnumMediaTypes **ppEnum)
Definition: mediatype.c:108
BasePin_GetMediaType enumMediaFunction
Definition: mediatype.c:94
#define InterlockedDecrement
Definition: armddk.h:52
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum src
Definition: glext.h:6340
void WINAPI DeleteMediaType(AM_MEDIA_TYPE *pMediaType)
Definition: mediatype.c:77
static HRESULT WINAPI IEnumMediaTypesImpl_Reset(IEnumMediaTypes *iface)
Definition: mediatype.c:254
#define S_OK
Definition: intsafe.h:59
#define InterlockedIncrement
Definition: armddk.h:53
BasePin_GetMediaTypeVersion mediaVersionFunction
Definition: mediatype.c:95
#define VFW_E_ENUM_OUT_OF_SYNC
Definition: vfwmsgs.h:42
ENUMMEDIADETAILS enumMediaDetails
Definition: mediatype.c:97
IEnumMediaTypes IEnumMediaTypes_iface
Definition: filtergraph.c:749
#define min(a, b)
Definition: monoChain.cc:55
static HRESULT WINAPI IEnumMediaTypesImpl_QueryInterface(IEnumMediaTypes *iface, REFIID riid, void **ret_iface)
Definition: mediatype.c:152
LONG(WINAPI * BasePin_GetMediaTypeVersion)(BasePin *This)
Definition: strmbase.h:50
unsigned int ULONG
Definition: retypes.h:1
static char * dest
Definition: rtl.c:135
#define memset(x, y, z)
Definition: compat.h:39
AM_MEDIA_TYPE *WINAPI CreateMediaType(AM_MEDIA_TYPE const *pSrc)
Definition: mediatype.c:60
LPVOID WINAPI CoTaskMemAlloc(SIZE_T size)
Definition: ifs.c:404
HRESULT(WINAPI * BasePin_GetMediaType)(BasePin *This, int iPosition, AM_MEDIA_TYPE *amt)
Definition: strmbase.h:51
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95