1 #include <assert.h>
2
3 @H_197_145@//@H_197_145@ Helper class to implement IMFAttributes.
4
5 @H_197_145@//@H_197_145@ This is an abstract class; the derived class must implement the IUnkNown
6 @H_197_145@//@H_197_145@ methods. This class is a wrapper for the standard attribute store provided
7 @H_197_145@//@H_197_145@ in Media Foundation.
8
9 @H_197_145@//@H_197_145@ template parameter:
10 @H_197_145@//@H_197_145@ ThE interface you are implemenTing,either IMFAttributes or an interface
11 @H_197_145@//@H_197_145@ that inherits IMFAttributes,such as IMFActivate
12
13 template <class IFACE=IMFAttributes>
14 class CBaseAttributes : public@H_419_119@ IFACE
15 @H_419_119@{
16 protected@H_419_119@:
17 IMFAttributes *@H_419_119@m_pAttributes;
18
19 @H_197_145@//@H_197_145@ This version of the constructor does not initialize the
20 @H_197_145@//@H_197_145@ attribute store. The derived class must call Initialize() in
21 @H_197_145@//@H_197_145@ its own constructor.
22 @H_419_119@ CBaseAttributes() : m_pAttributes(NULL)
23 @H_419_119@ {
24 @H_419_119@ }
25
26 @H_197_145@//@H_197_145@ This version of the constructor initializes the attribute
27 @H_197_145@//@H_197_145@ store,but the derived class must pass an HRESULT parameter
28 @H_197_145@//@H_197_145@ to the constructor.
29
30 CBaseAttributes(HRESULT& hr,UINT32 cInitialSize = 0@H_419_119@) : m_pAttributes(NULL)
31 @H_419_119@ {
32 hr =@H_419_119@ Initialize(cInitialSizE);
33 @H_419_119@ }
34
35 @H_197_145@//@H_197_145@ The next version of the constructor uses a caller-provided
36 @H_197_145@//@H_197_145@ implementation of IMFAttributes.
37
38 @H_197_145@//@H_197_145@ (Sometimes you want to delegate IMFAttributes calls to some
39 @H_197_145@//@H_197_145@ other object that implements IMFAttributes,rather than using
40 @H_197_145@//@H_197_145@ MFCreateAttributes.)
41
42 CBaseAttributes(HRESULT& hr,IUnkNown *@H_419_119@pUnk)
43 @H_419_119@ {
44 hr =@H_419_119@ Initialize(pUnk);
45 @H_419_119@ }
46
47 virtual ~@H_419_119@CBaseAttributes()
48 @H_419_119@ {
49 if@H_419_119@ (m_pAttributes)
50 @H_419_119@ {
51 m_pAttributes->@H_419_119@Release();
52 @H_419_119@ }
53 @H_419_119@ }
54
55 @H_197_145@//@H_197_145@ Initializes the object by creaTing the standard Media Foundation attribute store.
56 HRESULT Initialize(UINT32 cInitialSize = 0@H_419_119@)
57 @H_419_119@ {
58 if (m_pAttributes ==@H_419_119@ NULL)
59 @H_419_119@ {
60 return MFCreateAttributes(&@H_419_119@m_pAttributes,cInitialSizE);
61 @H_419_119@ }
62 else
63 @H_419_119@ {
64 return@H_419_119@ S_OK;
65 @H_419_119@ }
66 @H_419_119@ }
67
68 @H_197_145@//@H_197_145@ Initializes this object from a caller-provided attribute store.
69 @H_197_145@//@H_197_145@ pUnk: Pointer to an object that exposes IMFAttributes.
70 HRESULT Initialize(IUnkNown *@H_419_119@pUnk)
71 @H_419_119@ {
72 if@H_419_119@ (m_pAttributes)
73 @H_419_119@ {
74 m_pAttributes->@H_419_119@Release();
75 m_pAttributes =@H_419_119@ NULL;
76 @H_419_119@ }
77
78
79 return pUnk->QueryInterface(IID_PPV_ARGS(&@H_419_119@m_pAttributes));
80 @H_419_119@ }
81
82 public@H_419_119@:
83
84 @H_197_145@//@H_197_145@ IMFAttributes methods
85
86 STDMETHODIMP GetItem(REFGUID guidKey,PROPVARIANT*@H_419_119@ pvalue)
87 @H_419_119@ {
88 @H_419_119@ assert(m_pAttributes);
89 return m_pAttributes->@H_419_119@GetItem(guidKey,pvalue);
90 @H_419_119@ }
91
92 STDMETHODIMP GetItemType(REFGUID guidKey,MF_ATTRIBUTE_TYPE*@H_419_119@ pTypE)
93 @H_419_119@ {
94 @H_419_119@ assert(m_pAttributes);
95 return m_pAttributes->@H_419_119@GetItemType(guidKey,pTypE);
96 @H_419_119@ }
97
98 STDMETHODIMP CompareItem(REFGUID guidKey,REFPROPVARIANT Value,BOOL*@H_419_119@ pbResult)
99 @H_419_119@ {
100 @H_419_119@ assert(m_pAttributes);
101 return m_pAttributes->@H_419_119@CompareItem(guidKey,Value,pbResult);
102 @H_419_119@ }
103
104 @H_419_119@ STDMETHODIMP Compare(
105 IMFAttributes*@H_419_119@ ptheirs,106 @H_419_119@ MF_ATTRIBUTES_MATCH_TYPE MatchType,107 BOOL*@H_419_119@ pbResult
108 @H_419_119@ )
109 @H_419_119@ {
110 @H_419_119@ assert(m_pAttributes);
111 return m_pAttributes->@H_419_119@Compare(ptheirs,MatchType,pbResult);
112 @H_419_119@ }
113
114 STDMETHODIMP GetUINT32(REFGUID guidKey,UINT32*@H_419_119@ punvalue)
115 @H_419_119@ {
116 @H_419_119@ assert(m_pAttributes);
117 return m_pAttributes->@H_419_119@GetUINT32(guidKey,punvalue);
118 @H_419_119@ }
119
120 STDMETHODIMP GetUINT64(REFGUID guidKey,UINT64*@H_419_119@ punvalue)
121 @H_419_119@ {
122 @H_419_119@ assert(m_pAttributes);
123 return m_pAttributes->@H_419_119@GetUINT64(guidKey,punvalue);
124 @H_419_119@ }
125
126 STDMETHODIMP GetDouble(REFGUID guidKey,double*@H_419_119@ pfvalue)
127 @H_419_119@ {
128 @H_419_119@ assert(m_pAttributes);
129 return m_pAttributes->@H_419_119@GetDouble(guidKey,pfvalue);
130 @H_419_119@ }
131
132 STDMETHODIMP GetGUID(REFGUID guidKey,GUID*@H_419_119@ pguidvalue)
133 @H_419_119@ {
134 @H_419_119@ assert(m_pAttributes);
135 return m_pAttributes->@H_419_119@GetGUID(guidKey,pguidvalue);
136 @H_419_119@ }
137
138 STDMETHODIMP GetStringLength(REFGUID guidKey,UINT32*@H_419_119@ pcchLength)
139 @H_419_119@ {
140 @H_419_119@ assert(m_pAttributes);
141 return m_pAttributes->@H_419_119@GetStringLength(guidKey,pcchLength);
142 @H_419_119@ }
143
144 STDMETHODIMP GetString(REFGUID guidKey,LPWSTR pwszValue,UINT32 cchBufSize,UINT32*@H_419_119@ pcchLength)
145 @H_419_119@ {
146 @H_419_119@ assert(m_pAttributes);
147 return m_pAttributes->@H_419_119@GetString(guidKey,pwszValue,cchBufSize,pcchLength);
148 @H_419_119@ }
149
150 STDMETHODIMP GetAllocatedString(REFGUID guidKey,LPWSTR* ppwszValue,UINT32*@H_419_119@ pcchLength)
151 @H_419_119@ {
152 @H_419_119@ assert(m_pAttributes);
153 return m_pAttributes->@H_419_119@GetAllocatedString(guidKey,ppwszValue,pcchLength);
154 @H_419_119@ }
155
156 STDMETHODIMP GetBlobSize(REFGUID guidKey,UINT32*@H_419_119@ pcbBlobSizE)
157 @H_419_119@ {
158 @H_419_119@ assert(m_pAttributes);
159 return m_pAttributes->@H_419_119@GetBlobSize(guidKey,pcbBlobSizE);
160 @H_419_119@ }
161
162 STDMETHODIMP GetBlob(REFGUID guidKey,UINT8* pBuf,UINT32 cbBufSize,UINT32*@H_419_119@ pcbBlobSizE)
163 @H_419_119@ {
164 @H_419_119@ assert(m_pAttributes);
165 return m_pAttributes->@H_419_119@GetBlob(guidKey,pBuf,cbBufSize,pcbBlobSizE);
166 @H_419_119@ }
167
168 STDMETHODIMP GetAllocatedBlob(REFGUID guidKey,UINT8** ppBuf,UINT32*@H_419_119@ pcbSizE)
169 @H_419_119@ {
170 @H_419_119@ assert(m_pAttributes);
171 return m_pAttributes->@H_419_119@GetAllocatedBlob(guidKey,ppBuf,pcbSizE);
172 @H_419_119@ }
173
174 STDMETHODIMP GetUnkNown(REFGUID guidKey,REFIID riid,LPvoid*@H_419_119@ ppv)
175 @H_419_119@ {
176 @H_419_119@ assert(m_pAttributes);
177 return m_pAttributes->@H_419_119@GetUnkNown(guidKey,riid,ppv);
178 @H_419_119@ }
179
180 @H_419_119@ STDMETHODIMP SetItem(REFGUID guidKey,REFPROPVARIANT value)
181 @H_419_119@ {
182 @H_419_119@ assert(m_pAttributes);
183 return m_pAttributes->@H_419_119@SetItem(guidKey,value);
184 @H_419_119@ }
185
186 @H_419_119@ STDMETHODIMP deleteItem(REFGUID guidKey)
187 @H_419_119@ {
188 @H_419_119@ assert(m_pAttributes);
189 return m_pAttributes->@H_419_119@deleteItem(guidKey);
190 @H_419_119@ }
191
192 @H_419_119@ STDMETHODIMP deleteAllItems()
193 @H_419_119@ {
194 @H_419_119@ assert(m_pAttributes);
195 return m_pAttributes->@H_419_119@deleteAllItems();
196 @H_419_119@ }
197
198 @H_419_119@ STDMETHODIMP SetUINT32(REFGUID guidKey,UINT32 unvalue)
199 @H_419_119@ {
200 @H_419_119@ assert(m_pAttributes);
201 return m_pAttributes->@H_419_119@SetUINT32(guidKey,unvalue);
202 @H_419_119@ }
203
204 @H_419_119@ STDMETHODIMP SetUINT64(REFGUID guidKey,UINT64 unvalue)
205 @H_419_119@ {
206 @H_419_119@ assert(m_pAttributes);
207 return m_pAttributes->@H_419_119@SetUINT64(guidKey,unvalue);
208 @H_419_119@ }
209
210 STDMETHODIMP SetDouble(REFGUID guidKey,double@H_419_119@ fvalue)
211 @H_419_119@ {
212 @H_419_119@ assert(m_pAttributes);
213 return m_pAttributes->@H_419_119@SetDouble(guidKey,fvalue);
214 @H_419_119@ }
215
216 @H_419_119@ STDMETHODIMP SetGUID(REFGUID guidKey,REFGUID guidvalue)
217 @H_419_119@ {
218 @H_419_119@ assert(m_pAttributes);
219 return m_pAttributes->@H_419_119@SetGUID(guidKey,guidvalue);
220 @H_419_119@ }
221
222 @H_419_119@ STDMETHODIMP SetString(REFGUID guidKey,LPCWSTR wszvalue)
223 @H_419_119@ {
224 @H_419_119@ assert(m_pAttributes);
225 return m_pAttributes->@H_419_119@SetString(guidKey,wszvalue);
226 @H_419_119@ }
227
228 STDMETHODIMP SetBlob(REFGUID guidKey,const UINT8*@H_419_119@ pBuf,UINT32 cbBufSizE)
229 @H_419_119@ {
230 @H_419_119@ assert(m_pAttributes);
231 return m_pAttributes->@H_419_119@SetBlob(guidKey,cbBufSizE);
232 @H_419_119@ }
233
234 STDMETHODIMP SetUnkNown(REFGUID guidKey,IUnkNown*@H_419_119@ pUnkNown)
235 @H_419_119@ {
236 @H_419_119@ assert(m_pAttributes);
237 return m_pAttributes->@H_419_119@SetUnkNown(guidKey,pUnkNown);
238 @H_419_119@ }
239
240 @H_419_119@ STDMETHODIMP LockStore()
241 @H_419_119@ {
242 @H_419_119@ assert(m_pAttributes);
243 return m_pAttributes->@H_419_119@LockStore();
244 @H_419_119@ }
245
246 @H_419_119@ STDMETHODIMP UnlockStore()
247 @H_419_119@ {
248 @H_419_119@ assert(m_pAttributes);
249 return m_pAttributes->@H_419_119@UnlockStore();
250 @H_419_119@ }
251
252 STDMETHODIMP GetCount(UINT32*@H_419_119@ pcItems)
253 @H_419_119@ {
254 @H_419_119@ assert(m_pAttributes);
255 return m_pAttributes->@H_419_119@GetCount(pcItems);
256 @H_419_119@ }
257
258 STDMETHODIMP GetItemByIndex(UINT32 unIndex,GUID* pguidKey,PROPVARIANT*@H_419_119@ pvalue)
259 @H_419_119@ {
260 @H_419_119@ assert(m_pAttributes);
261 return m_pAttributes->@H_419_119@GetItemByIndex(unIndex,pguidKey,pvalue);
262 @H_419_119@ }
263
264 STDMETHODIMP CopyAllItems(IMFAttributes*@H_419_119@ pDest)
265 @H_419_119@ {
266 @H_419_119@ assert(m_pAttributes);
267 return m_pAttributes->@H_419_119@CopyAllItems(pDest);
268 @H_419_119@ }
269
270 @H_197_145@//@H_197_145@ Helper functions
271
272 HRESULT @R_450_9464@lizeToStream(DWORD dwOptions,IStream*@H_419_119@ pStm)
273 @H_197_145@//@H_197_145@ dwOptions: Flags from MF_ATTRIBUTE_@R_450_9464@LIZE_OPTIONS
274 @H_419_119@ {
275 @H_419_119@ assert(m_pAttributes);
276 return@H_419_119@ MF@R_450_9464@lizeAttributesToStream(m_pAttributes,dwOptions,pStm);
277 @H_419_119@ }
278
279 HRESULT De@R_450_9464@lizeFromStream(DWORD dwOptions,IStream*@H_419_119@ pStm)
280 @H_419_119@ {
281 @H_419_119@ assert(m_pAttributes);
282 return@H_419_119@ MFDe@R_450_9464@lizeAttributesFromStream(m_pAttributes,pStm);
283 @H_419_119@ }
284
285 @H_197_145@//@H_197_145@ @R_450_9464@lizeToBlob: Stores the attributes in a byte array.
286 @H_197_145@//
287 @H_197_145@//@H_197_145@ ppBuf: Receives a pointer to the byte array.
288 @H_197_145@//@H_197_145@ pcbSize: Receives the size of the byte array.
289 @H_197_145@//
290 @H_197_145@//@H_197_145@ The caller must free the array using CoTaskMemFree.
291 HRESULT @R_450_9464@lizeToBlob(UINT8 **ppBuffer,UINT32 *@H_419_119@pcbSizE)
292 @H_419_119@ {
293 @H_419_119@ assert(m_pAttributes);
294
295 if (ppBuffer ==@H_419_119@ NULL)
296 @H_419_119@ {
297 return@H_419_119@ E_POINTER;
298 @H_419_119@ }
299 if (pcbSize ==@H_419_119@ NULL)
300 @H_419_119@ {
301 return@H_419_119@ E_POINTER;
302 @H_419_119@ }
303
304 *ppBuffer =@H_419_119@ NULL;
305 *pcbSize = 0@H_419_119@;
306
307 UINT32 cbSize = 0@H_419_119@;
308 BYTE *pBuffer =@H_419_119@ NULL;
309
310 HRESULT hr = MfgetAttributesAsBlobSize(m_pAttributes,&@H_419_119@cbSizE);
311
312 if@H_419_119@ (Failed(hr))
313 @H_419_119@ {
314 return@H_419_119@ hr;
315 @H_419_119@ }
316
317 pBuffer = (BYTE*@H_419_119@)CoTaskMemAlloc(cbSizE);
318 if (pBuffer ==@H_419_119@ NULL)
319 @H_419_119@ {
320 return@H_419_119@ E_OUTOFMEMORY;
321 @H_419_119@ }
322
323 hr =@H_419_119@ MfgetAttributesAsBlob(m_pAttributes,pBuffer,cbSizE);
324
325 if@H_419_119@ (SUCCEEDED(hr))
326 @H_419_119@ {
327 *ppBuffer =@H_419_119@ pBuffer;
328 *pcbSize =@H_419_119@ cbSize;
329 @H_419_119@ }
330 else
331 @H_419_119@ {
332 @H_419_119@ CoTaskMemFree(pBuffer);
333 @H_419_119@ }
334 return@H_419_119@ hr;
335 @H_419_119@ }
336
337 HRESULT De@R_450_9464@lizeFromBlob(const UINT8*@H_419_119@ pBuffer,UINT cbSizE)
338 @H_419_119@ {
339 @H_419_119@ assert(m_pAttributes);
340 return@H_419_119@ MFInitAttributesFromBlob(m_pAttributes,cbSizE);
341 @H_419_119@ }
342
343 HRESULT GetRatio(REFGUID guidKey,UINT32* pnNumerator,UINT32*@H_419_119@ punDenominator)
344 @H_419_119@ {
345 @H_419_119@ assert(m_pAttributes);
346 return@H_419_119@ MfgetAttributeRatio(m_pAttributes,guidKey,pnNumerator,punDenominator);
347 @H_419_119@ }
348
349 @H_419_119@ HRESULT SetRatio(REFGUID guidKey,UINT32 unNumerator,UINT32 unDenominator)
350 @H_419_119@ {
351 @H_419_119@ assert(m_pAttributes);
352 return@H_419_119@ MFSetAttributeRatio(m_pAttributes,unNumerator,unDenominator);
353 @H_419_119@ }
354
355 @H_197_145@//@H_197_145@ Gets an attribute whose value represents the size of something (eg a video framE).
356 HRESULT GetSize(REFGUID guidKey,UINT32* punWidth,UINT32*@H_419_119@ punHeight)
357 @H_419_119@ {
358 @H_419_119@ assert(m_pAttributes);
359 return@H_419_119@ MfgetAttributeSize(m_pAttributes,punWidth,punHeight);
360 @H_419_119@ }
361
362 @H_197_145@//@H_197_145@ Sets an attribute whose value represents the size of something (eg a video framE).
363 @H_419_119@ HRESULT SetSize(REFGUID guidKey,UINT32 unWidth,UINT32 unHeight)
364 @H_419_119@ {
365 @H_419_119@ assert(m_pAttributes);
366 return@H_419_119@ MFSetAttributeSize (m_pAttributes,unWidth,unHeight);
367 @H_419_119@ }
368 };