Fixed some broken macros.
[wine/multimedia.git] / dlls / quartz / imem.c
blob4dc0d677d4d3dae6e4975c2add145822dbcbbef0
1 /*
2 * Implementation of CLSID_MemoryAllocator.
4 * FIXME - stub.
6 * hidenori@a2.ctktv.ne.jp
7 */
9 #include "config.h"
11 #include "windef.h"
12 #include "winbase.h"
13 #include "wingdi.h"
14 #include "winerror.h"
15 #include "wine/obj_base.h"
16 #include "strmif.h"
17 #include "uuids.h"
19 #include "debugtools.h"
20 DEFAULT_DEBUG_CHANNEL(quartz);
22 #include "quartz_private.h"
23 #include "memalloc.h"
26 static HRESULT WINAPI
27 IMemAllocator_fnQueryInterface(IMemAllocator* iface,REFIID riid,void** ppobj)
29 CMemoryAllocator_THIS(iface,memalloc);
31 TRACE("(%p)->()\n",This);
33 return IUnknown_QueryInterface(This->unk.punkControl,riid,ppobj);
36 static ULONG WINAPI
37 IMemAllocator_fnAddRef(IMemAllocator* iface)
39 CMemoryAllocator_THIS(iface,memalloc);
41 TRACE("(%p)->()\n",This);
43 return IUnknown_AddRef(This->unk.punkControl);
46 static ULONG WINAPI
47 IMemAllocator_fnRelease(IMemAllocator* iface)
49 CMemoryAllocator_THIS(iface,memalloc);
51 TRACE("(%p)->()\n",This);
53 return IUnknown_Release(This->unk.punkControl);
56 static HRESULT WINAPI
57 IMemAllocator_fnSetProperties(IMemAllocator* iface,ALLOCATOR_PROPERTIES* pPropReq,ALLOCATOR_PROPERTIES* pPropActual)
59 CMemoryAllocator_THIS(iface,memalloc);
60 long padding;
62 TRACE( "(%p)->(%p,%p)\n", This, pPropReq, pPropActual );
64 if ( pPropReq == NULL || pPropActual == NULL )
65 return E_POINTER;
66 if ( pPropReq->cBuffers < 0 ||
67 pPropReq->cbBuffer < 0 ||
68 pPropReq->cbAlign < 0 ||
69 pPropReq->cbPrefix < 0 )
70 return E_INVALIDARG;
72 if ( ( pPropReq->cbAlign & (pPropReq->cbAlign-1) ) != 0 )
73 return E_INVALIDARG;
75 EnterCriticalSection( &This->csMem );
77 This->prop.cBuffers = pPropReq->cBuffers;
78 This->prop.cbBuffer = pPropReq->cbBuffer;
79 This->prop.cbAlign = pPropReq->cbAlign;
80 This->prop.cbPrefix = pPropReq->cbPrefix;
82 if ( This->prop.cbAlign == 0 )
83 This->prop.cbAlign = 1;
84 padding = This->prop.cbAlign -
85 ( (This->prop.cbBuffer+This->prop.cbPrefix) % This->prop.cbAlign );
87 This->prop.cbBuffer += padding;
89 memcpy( pPropActual, &This->prop, sizeof(ALLOCATOR_PROPERTIES) );
91 LeaveCriticalSection( &This->csMem );
93 return NOERROR;
96 static HRESULT WINAPI
97 IMemAllocator_fnGetProperties(IMemAllocator* iface,ALLOCATOR_PROPERTIES* pProp)
99 CMemoryAllocator_THIS(iface,memalloc);
101 TRACE( "(%p)->(%p)\n", This, pProp );
103 if ( pProp == NULL )
104 return E_POINTER;
106 EnterCriticalSection( &This->csMem );
108 memcpy( pProp, &This->prop, sizeof(ALLOCATOR_PROPERTIES) );
110 LeaveCriticalSection( &This->csMem );
112 return NOERROR;
115 static HRESULT WINAPI
116 IMemAllocator_fnCommit(IMemAllocator* iface)
118 CMemoryAllocator_THIS(iface,memalloc);
120 FIXME( "(%p)->() stub!\n", This );
121 return E_NOTIMPL;
124 static HRESULT WINAPI
125 IMemAllocator_fnDecommit(IMemAllocator* iface)
127 CMemoryAllocator_THIS(iface,memalloc);
129 FIXME( "(%p)->() stub!\n", This );
130 return E_NOTIMPL;
133 static HRESULT WINAPI
134 IMemAllocator_fnGetBuffer(IMemAllocator* iface,IMediaSample** ppSample,REFERENCE_TIME* prtStart,REFERENCE_TIME* prtEnd,DWORD dwFlags)
136 CMemoryAllocator_THIS(iface,memalloc);
138 FIXME( "(%p)->() stub!\n", This );
139 return E_NOTIMPL;
142 static HRESULT WINAPI
143 IMemAllocator_fnReleaseBuffer(IMemAllocator* iface,IMediaSample* pSample)
145 CMemoryAllocator_THIS(iface,memalloc);
147 FIXME( "(%p)->() stub!\n", This );
148 return E_NOTIMPL;
153 static ICOM_VTABLE(IMemAllocator) imemalloc =
155 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
156 /* IUnknown fields */
157 IMemAllocator_fnQueryInterface,
158 IMemAllocator_fnAddRef,
159 IMemAllocator_fnRelease,
160 /* IMemAllocator fields */
161 IMemAllocator_fnSetProperties,
162 IMemAllocator_fnGetProperties,
163 IMemAllocator_fnCommit,
164 IMemAllocator_fnDecommit,
165 IMemAllocator_fnGetBuffer,
166 IMemAllocator_fnReleaseBuffer,
170 HRESULT CMemoryAllocator_InitIMemAllocator( CMemoryAllocator* pma )
172 TRACE("(%p)\n",pma);
174 ICOM_VTBL(&pma->memalloc) = &imemalloc;
176 ZeroMemory( &pma->prop, sizeof(pma->prop) );
178 InitializeCriticalSection( &pma->csMem );
180 return NOERROR;
183 void CMemoryAllocator_UninitIMemAllocator( CMemoryAllocator* pma )
185 TRACE("(%p)\n",pma);
187 IMemAllocator_Decommit( (IMemAllocator*)(&pma->memalloc) );
189 DeleteCriticalSection( &pma->csMem );