wordpress   发布时间:2022-04-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Microsoft Media Foundation官方文档翻译(9、10)《Media Foundation Primitives》《Attributes in Media Foundation》大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

官方英文文档链接:https://docs.microsoft.com/en-us/windows/desktop/medfound/media-foundation-primitives 基于05/31/2018   Media Foundation 定义了几种在整个 Media Foundation API 中都会用到的基本对象类型。 Topic Description Attributes

官方英文文档链接https://docs.microsoft.com/en-us/windows/desktop/medfound/media-foundation-primitives

基于05/31/2018

 

@H_75_18@media Foundation 定义了几种在整个 Media Foundation API 中都会用到的基本对象类型。

Topic Description
Attributes Attributes 和 properties 是存储在对象中的键值对
Media Types 描述媒体格式
Media Buffers 管理一块内存,并且可以在对象之间分享
Media Samples 是包含了 media buffer 列表的对象

官方英文文档链接https://docs.microsoft.com/en-us/windows/desktop/medfound/attributes-and-properties

基于05/31/2018

 

Attribute(属性) 是键值对,key 是 GUID,value 是一个 PROPVARIANT。@H_153_70@microsoft Media Foundation 中使用 attribute 用来配置对象,描述媒体格式,查询对象属性等等。

此文包含以下内容

About Attributes

Attribute 是键值对,key 是 GUID,value 是一个 PROPVARIANT。Attribute 值仅限以下几种类型:

  • Unsigned 32-bit Integer (UINT32).
  • Unsigned 64-bit Integer (UINT64).
  • 64-bit floaTing-point number.
  • GUID.
  • Null-terminated wide-character String.
  • Byte array.
  • IUnkNown pointer.

这些类型定义在 MF_ATTRIBUTE_TYPE 枚举中。如果需要设置或检索 Attribute,使用 IMFAttributes 接口。这个接口在设置数据的时候会使用“类型安全”(就是根据数据类型调用不同的方法)的方法。例如要设置一个32位 int,就调用 IMFAttributes::SetUINT32。 Attribute keys 在一个对象中是唯一的,如果对同一个 key 设置了两次不同的数值,那么第二次会覆盖第一次。

很多 Media Foundation 接口都继承了 IMFAttributes 接口。应用程序应该通过对象设置这些属性,bjects that expose this interface have optional or mandatory attributes that the application should set on the object,or have attributes that the application can retrieve. 此外,某些方法IMFAttributes 指针作为参数传递,使应用程序能够进行设置。应用程序必须创建一个新的 attribute 对象来存储设置。要创建新的 attribute ,调用 MFCreateAttributes

下面的代码包含两个方法。第一个方法创建了一个新的 attribute 对象来存储设置,这个属性叫做 MY_ATTRIBUTE ,值是一个 String。第二个函数获取属性的值。

 

 1 extern const@H_419_119@ GUID MY_ATTRIBUTE;
 2 
 3 HRESULT ShowCreateAttributeStore(IMFAttributes **@H_419_119@ppAttributes)
 4 @H_419_119@{
 5     IMFAttributes *pAttributes =@H_419_119@ NULL;
 6     const UINT32 cElements = 10;  @H_197_145@//@H_197_145@ StarTing size.
 7 
 8     @H_197_145@//@H_197_145@ Create the empty attribute store.
 9     HRESULT hr = MFCreateAttributes(&@H_419_119@pAttributes,cElements);
10 
11     @H_197_145@//@H_197_145@ Set the MY_ATTRIBUTE attribute with a String value.
12     if@H_419_119@ (SUCCEEDED(hr))
13 @H_419_119@    {
14         hr = pAttributes->@H_419_119@SetString(
15 @H_419_119@            MY_ATTRIBUTE,16             L"This is a String value"
17 @H_419_119@            );
18 @H_419_119@    }
19 
20     @H_197_145@//@H_197_145@ Return the IMFAttributes pointer to the caller.
21     if@H_419_119@ (SUCCEEDED(hr))
22 @H_419_119@    {
23         *ppAttributes =@H_419_119@ pAttributes;
24         (*ppAttributes)->@H_419_119@AddRef();
25 @H_419_119@    }
26 
27 @H_419_119@    SAFE_RELEASE(pAttributes);
28 
29     return@H_419_119@ hr;
30 @H_419_119@}
31 
32 @H_419_119@HRESULT ShowGetAttributes()
33 @H_419_119@{
34     IMFAttributes *pAttributes =@H_419_119@ NULL;
35     WCHAR *pwszValue =@H_419_119@ NULL;
36     UINT32 cchLength = 0@H_419_119@;
37 
38     @H_197_145@//@H_197_145@ Create the attribute store.
39     HRESULT hr = ShowCreateAttributeStore(&@H_419_119@pAttributes);
40 
41     @H_197_145@//@H_197_145@ Get the attribute.
42     if@H_419_119@ (SUCCEEDED(hr))
43 @H_419_119@    {
44         hr = pAttributes->@H_419_119@GetAllocatedString(
45 @H_419_119@            MY_ATTRIBUTE,46             &@H_419_119@pwszValue,47             &@H_419_119@cchLength
48 @H_419_119@            );
49 @H_419_119@    }
50 
51 @H_419_119@    CoTaskMemFree(pwszvalue);
52 @H_419_119@    SAFE_RELEASE(pAttributes);
53 
54     return@H_419_119@ hr;
55 }

 

@H_673_290@@H_673_290@Microsoft Media Foundation官方文档翻译(9、10)《Media Foundation Primitives》《Attributes in Media Foundation》

有关 Media Foundation 属性(attribute)的完整列表,查看 Media Foundation Attributes。. The expected data type for each attribute is documented there.

@R_450_9464@lizing Attributes(序列化属性

@H_75_18@media Foundation 有两个用于属性序列化存储的方法一个是将属性写入一个数组,另一个是将属性写入支持 IStream 接口的流。每个方法都有一个对应的函数来加载属性(就是反向,还原)

Operation Byte Array IStream
存储 MFGetAttributesAsBlob MFSerializeAttributesToStream
加载 MFInitAttributesFromBlob MFDeserializeAttributesFromStream

 

要将属性存储的内容写入数组,调用 MFGetAttributesAsBlob。值为 IUnkNow 指针的属性将被忽略(?原话Attributes with IUnkNown pointer values are ignored.)。要将属性加载回 attribute,调用 MFInitAttributesFromBlob

若要将属性存储写入流,调用 MFSerializeAttributesToStream。这个方法可以封装发送 IUnkNown 指针值。调用者必须提供实现了 IStream 接口的对象。要把属性从流加载回 attribute 对象,调用 MFDeserializeAttributesFromStream

ImplemenTing IMFAttributes

@H_75_18@media Foundation 提供了 IMFAttributes 的(stock implementation),包含在 MFCreateAttributes 中。大多数情况下应使用此实现。

不过这里有一种情况你需要自己去实现 IMFAttributes 接口:如果你要实现一个继承自 IMFAttributes 的接口,在这种情况下,你必须自己实现 IMFAttributes 的各个方法

在这种情况下,建议建议包装 Media Foundation 对 IMFAttributes 的现有实现。下面的代码展示了一个类模板,该类包含一个 IMFAttributes 指针和所有的 IMFAttributes 方法IUnkNown除外)。

 

  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 };

 

@H_673_290@@H_673_290@Microsoft Media Foundation官方文档翻译(9、10)《Media Foundation Primitives》《Attributes in Media Foundation》

下面的代码展示了如何用这个类模板来实例化一个类:

 

 1 #include <shlwapi.h>
 2 
 3 class MyObject : public CBaseAttributes<>
 4 @H_419_119@{
 5     MyObject() : m_nRefCount(1@H_419_119@) { }
 6     ~@H_419_119@myObject() { }
 7 
 8     long@H_419_119@ m_nRefCount;
 9 
10 public@H_419_119@:
11 
12     @H_197_145@//@H_197_145@ IUnkNown
13     STDMETHODIMP MyObject::QueryInterface(REFIID riid,void**@H_419_119@ ppv)
14 @H_419_119@    {
15         static const QITAB qit[] = 
16 @H_419_119@        {
17 @H_419_119@            QITABENT(MyObject,IMFAttributes),18             { 0@H_419_119@ },19 @H_419_119@        };
20         return QISearch(this@H_419_119@,qit,ppv);
21 @H_419_119@    }
22 
23 @H_419_119@    STDMETHODIMP_(ULONG) MyObject::AddRef()
24 @H_419_119@    {
25         return InterlockedIncrement(&@H_419_119@m_nRefCount);
26 @H_419_119@    }
27 
28 @H_419_119@    STDMETHODIMP_(ULONG) MyObject::release()
29 @H_419_119@    {
30         ULONG uCount = InterlockedDecrement(&@H_419_119@m_nRefCount);
31         if (uCount == 0@H_419_119@)
32 @H_419_119@        {
33             delete this@H_419_119@;
34 @H_419_119@        }
35         return@H_419_119@ uCount;
36 @H_419_119@    }
37 
38     @H_197_145@//@H_197_145@ Static function to create an instance of the object.
39 
40     static HRESULT CreateInstance(MyObject **@H_419_119@ppObject)
41 @H_419_119@    {
42         HRESULT hr =@H_419_119@ S_OK;
43 
44         MyObject *pObject = new@H_419_119@ MyObject();
45         if (pObject ==@H_419_119@ NULL)
46 @H_419_119@        {
47             return@H_419_119@ E_OUTOFMEMORY;
48 @H_419_119@        }
49 
50         @H_197_145@//@H_197_145@ Initialize the attribute store.
51         hr = pObject->@H_419_119@Initialize();
52 
53         if@H_419_119@ (Failed(hr))
54 @H_419_119@        {
55             delete@H_419_119@ pObject;
56             return@H_419_119@ hr;
57 @H_419_119@        }
58 
59         *ppObject =@H_419_119@ pObject;
60         (*ppObject)->@H_419_119@AddRef();
61 
62         return@H_419_119@ S_OK;
63 @H_419_119@    }
64 };

 

@H_673_290@@H_673_290@Microsoft Media Foundation官方文档翻译(9、10)《Media Foundation Primitives》《Attributes in Media Foundation》

你必须调用 CBaseAttributes::Initialize 来创建一个 attribute store。在上面的代码中,这一步在一个静态的创建方法(static HRESULT CreateInstance(MyObject **ppObject);)中完成。 

模板参数是一个接口类型,认是 IMFAttributes 。如果要实例化继承自 IMFAttributes 的接口,例如 IMFActivate,设置模板参数为派生接口名称即可。

大佬总结

以上是大佬教程为你收集整理的Microsoft Media Foundation官方文档翻译(9、10)《Media Foundation Primitives》《Attributes in Media Foundation》全部内容,希望文章能够帮你解决Microsoft Media Foundation官方文档翻译(9、10)《Media Foundation Primitives》《Attributes in Media Foundation》所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。