wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / mfplat / mediatype.c
blob85219c74dd551201390f61bf313cfedcd3c32a3a
1 /*
2 * Copyright 2017 Alistair Leslie-Hughes
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define COBJMACROS
21 #include "mfplat_private.h"
23 #include "dxva2api.h"
24 #include "initguid.h"
25 #include "ks.h"
26 #include "ksmedia.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(mfplat);
32 DEFINE_MEDIATYPE_GUID(MFVideoFormat_IMC1, MAKEFOURCC('I','M','C','1'));
33 DEFINE_MEDIATYPE_GUID(MFVideoFormat_IMC2, MAKEFOURCC('I','M','C','2'));
34 DEFINE_MEDIATYPE_GUID(MFVideoFormat_IMC3, MAKEFOURCC('I','M','C','3'));
35 DEFINE_MEDIATYPE_GUID(MFVideoFormat_IMC4, MAKEFOURCC('I','M','C','4'));
37 struct media_type
39 struct attributes attributes;
40 IMFMediaType IMFMediaType_iface;
41 IMFVideoMediaType IMFVideoMediaType_iface;
42 IMFAudioMediaType IMFAudioMediaType_iface;
43 MFVIDEOFORMAT *video_format;
46 struct stream_desc
48 struct attributes attributes;
49 IMFStreamDescriptor IMFStreamDescriptor_iface;
50 IMFMediaTypeHandler IMFMediaTypeHandler_iface;
51 DWORD identifier;
52 IMFMediaType **media_types;
53 unsigned int media_types_count;
54 IMFMediaType *current_type;
57 struct presentation_desc_entry
59 IMFStreamDescriptor *descriptor;
60 BOOL selected;
63 struct presentation_desc
65 struct attributes attributes;
66 IMFPresentationDescriptor IMFPresentationDescriptor_iface;
67 struct presentation_desc_entry *descriptors;
68 unsigned int count;
71 static HRESULT presentation_descriptor_init(struct presentation_desc *object, DWORD count);
73 static struct media_type *impl_from_IMFMediaType(IMFMediaType *iface)
75 return CONTAINING_RECORD(iface, struct media_type, IMFMediaType_iface);
78 static struct media_type *impl_from_IMFVideoMediaType(IMFVideoMediaType *iface)
80 return CONTAINING_RECORD(iface, struct media_type, IMFVideoMediaType_iface);
83 static struct media_type *impl_from_IMFAudioMediaType(IMFAudioMediaType *iface)
85 return CONTAINING_RECORD(iface, struct media_type, IMFAudioMediaType_iface);
88 static inline struct stream_desc *impl_from_IMFStreamDescriptor(IMFStreamDescriptor *iface)
90 return CONTAINING_RECORD(iface, struct stream_desc, IMFStreamDescriptor_iface);
93 static struct stream_desc *impl_from_IMFMediaTypeHandler(IMFMediaTypeHandler *iface)
95 return CONTAINING_RECORD(iface, struct stream_desc, IMFMediaTypeHandler_iface);
98 static struct presentation_desc *impl_from_IMFPresentationDescriptor(IMFPresentationDescriptor *iface)
100 return CONTAINING_RECORD(iface, struct presentation_desc, IMFPresentationDescriptor_iface);
103 static HRESULT WINAPI mediatype_QueryInterface(IMFMediaType *iface, REFIID riid, void **out)
105 struct media_type *media_type = impl_from_IMFMediaType(iface);
106 GUID major = { 0 };
108 TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), out);
110 attributes_GetGUID(&media_type->attributes, &MF_MT_MAJOR_TYPE, &major);
112 if (IsEqualGUID(&major, &MFMediaType_Video) && IsEqualIID(riid, &IID_IMFVideoMediaType))
114 *out = &media_type->IMFVideoMediaType_iface;
116 else if (IsEqualGUID(&major, &MFMediaType_Audio) && IsEqualIID(riid, &IID_IMFAudioMediaType))
118 *out = &media_type->IMFAudioMediaType_iface;
120 else if (IsEqualIID(riid, &IID_IMFMediaType) ||
121 IsEqualIID(riid, &IID_IMFAttributes) ||
122 IsEqualIID(riid, &IID_IUnknown))
124 *out = &media_type->IMFMediaType_iface;
126 else
128 WARN("Unsupported %s.\n", debugstr_guid(riid));
129 *out = NULL;
130 return E_NOINTERFACE;
133 IUnknown_AddRef((IUnknown *)*out);
134 return S_OK;
137 static ULONG WINAPI mediatype_AddRef(IMFMediaType *iface)
139 struct media_type *media_type = impl_from_IMFMediaType(iface);
140 ULONG refcount = InterlockedIncrement(&media_type->attributes.ref);
142 TRACE("%p, refcount %u.\n", iface, refcount);
144 return refcount;
147 static ULONG WINAPI mediatype_Release(IMFMediaType *iface)
149 struct media_type *media_type = impl_from_IMFMediaType(iface);
150 ULONG refcount = InterlockedDecrement(&media_type->attributes.ref);
152 TRACE("%p, refcount %u.\n", iface, refcount);
154 if (!refcount)
156 clear_attributes_object(&media_type->attributes);
157 heap_free(media_type);
160 return refcount;
163 static HRESULT WINAPI mediatype_GetItem(IMFMediaType *iface, REFGUID key, PROPVARIANT *value)
165 struct media_type *media_type = impl_from_IMFMediaType(iface);
167 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
169 return attributes_GetItem(&media_type->attributes, key, value);
172 static HRESULT WINAPI mediatype_GetItemType(IMFMediaType *iface, REFGUID key, MF_ATTRIBUTE_TYPE *type)
174 struct media_type *media_type = impl_from_IMFMediaType(iface);
176 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), type);
178 return attributes_GetItemType(&media_type->attributes, key, type);
181 static HRESULT WINAPI mediatype_CompareItem(IMFMediaType *iface, REFGUID key, REFPROPVARIANT value, BOOL *result)
183 struct media_type *media_type = impl_from_IMFMediaType(iface);
185 TRACE("%p, %s, %s, %p.\n", iface, debugstr_attr(key), debugstr_propvar(value), result);
187 return attributes_CompareItem(&media_type->attributes, key, value, result);
190 static HRESULT WINAPI mediatype_Compare(IMFMediaType *iface, IMFAttributes *attrs, MF_ATTRIBUTES_MATCH_TYPE type,
191 BOOL *result)
193 struct media_type *media_type = impl_from_IMFMediaType(iface);
195 TRACE("%p, %p, %d, %p.\n", iface, attrs, type, result);
197 return attributes_Compare(&media_type->attributes, attrs, type, result);
200 static HRESULT WINAPI mediatype_GetUINT32(IMFMediaType *iface, REFGUID key, UINT32 *value)
202 struct media_type *media_type = impl_from_IMFMediaType(iface);
204 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
206 return attributes_GetUINT32(&media_type->attributes, key, value);
209 static HRESULT WINAPI mediatype_GetUINT64(IMFMediaType *iface, REFGUID key, UINT64 *value)
211 struct media_type *media_type = impl_from_IMFMediaType(iface);
213 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
215 return attributes_GetUINT64(&media_type->attributes, key, value);
218 static HRESULT WINAPI mediatype_GetDouble(IMFMediaType *iface, REFGUID key, double *value)
220 struct media_type *media_type = impl_from_IMFMediaType(iface);
222 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
224 return attributes_GetDouble(&media_type->attributes, key, value);
227 static HRESULT WINAPI mediatype_GetGUID(IMFMediaType *iface, REFGUID key, GUID *value)
229 struct media_type *media_type = impl_from_IMFMediaType(iface);
231 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
233 return attributes_GetGUID(&media_type->attributes, key, value);
236 static HRESULT WINAPI mediatype_GetStringLength(IMFMediaType *iface, REFGUID key, UINT32 *length)
238 struct media_type *media_type = impl_from_IMFMediaType(iface);
240 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), length);
242 return attributes_GetStringLength(&media_type->attributes, key, length);
245 static HRESULT WINAPI mediatype_GetString(IMFMediaType *iface, REFGUID key, WCHAR *value,
246 UINT32 size, UINT32 *length)
248 struct media_type *media_type = impl_from_IMFMediaType(iface);
250 TRACE("%p, %s, %p, %u, %p.\n", iface, debugstr_attr(key), value, size, length);
252 return attributes_GetString(&media_type->attributes, key, value, size, length);
255 static HRESULT WINAPI mediatype_GetAllocatedString(IMFMediaType *iface, REFGUID key,
256 WCHAR **value, UINT32 *length)
258 struct media_type *media_type = impl_from_IMFMediaType(iface);
260 TRACE("%p, %s, %p, %p.\n", iface, debugstr_attr(key), value, length);
262 return attributes_GetAllocatedString(&media_type->attributes, key, value, length);
265 static HRESULT WINAPI mediatype_GetBlobSize(IMFMediaType *iface, REFGUID key, UINT32 *size)
267 struct media_type *media_type = impl_from_IMFMediaType(iface);
269 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), size);
271 return attributes_GetBlobSize(&media_type->attributes, key, size);
274 static HRESULT WINAPI mediatype_GetBlob(IMFMediaType *iface, REFGUID key, UINT8 *buf,
275 UINT32 bufsize, UINT32 *blobsize)
277 struct media_type *media_type = impl_from_IMFMediaType(iface);
279 TRACE("%p, %s, %p, %u, %p.\n", iface, debugstr_attr(key), buf, bufsize, blobsize);
281 return attributes_GetBlob(&media_type->attributes, key, buf, bufsize, blobsize);
284 static HRESULT WINAPI mediatype_GetAllocatedBlob(IMFMediaType *iface, REFGUID key, UINT8 **buf, UINT32 *size)
286 struct media_type *media_type = impl_from_IMFMediaType(iface);
288 TRACE("%p, %s, %p, %p.\n", iface, debugstr_attr(key), buf, size);
290 return attributes_GetAllocatedBlob(&media_type->attributes, key, buf, size);
293 static HRESULT WINAPI mediatype_GetUnknown(IMFMediaType *iface, REFGUID key, REFIID riid, void **obj)
295 struct media_type *media_type = impl_from_IMFMediaType(iface);
297 TRACE("%p, %s, %s, %p.\n", iface, debugstr_attr(key), debugstr_guid(riid), obj);
299 return attributes_GetUnknown(&media_type->attributes, key, riid, obj);
302 static HRESULT WINAPI mediatype_SetItem(IMFMediaType *iface, REFGUID key, REFPROPVARIANT value)
304 struct media_type *media_type = impl_from_IMFMediaType(iface);
306 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_propvar(value));
308 return attributes_SetItem(&media_type->attributes, key, value);
311 static HRESULT WINAPI mediatype_DeleteItem(IMFMediaType *iface, REFGUID key)
313 struct media_type *media_type = impl_from_IMFMediaType(iface);
315 TRACE("%p, %s.\n", iface, debugstr_attr(key));
317 return attributes_DeleteItem(&media_type->attributes, key);
320 static HRESULT WINAPI mediatype_DeleteAllItems(IMFMediaType *iface)
322 struct media_type *media_type = impl_from_IMFMediaType(iface);
324 TRACE("%p.\n", iface);
326 return attributes_DeleteAllItems(&media_type->attributes);
329 static HRESULT WINAPI mediatype_SetUINT32(IMFMediaType *iface, REFGUID key, UINT32 value)
331 struct media_type *media_type = impl_from_IMFMediaType(iface);
333 TRACE("%p, %s, %u.\n", iface, debugstr_attr(key), value);
335 return attributes_SetUINT32(&media_type->attributes, key, value);
338 static HRESULT WINAPI mediatype_SetUINT64(IMFMediaType *iface, REFGUID key, UINT64 value)
340 struct media_type *media_type = impl_from_IMFMediaType(iface);
342 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), wine_dbgstr_longlong(value));
344 return attributes_SetUINT64(&media_type->attributes, key, value);
347 static HRESULT WINAPI mediatype_SetDouble(IMFMediaType *iface, REFGUID key, double value)
349 struct media_type *media_type = impl_from_IMFMediaType(iface);
351 TRACE("%p, %s, %f.\n", iface, debugstr_attr(key), value);
353 return attributes_SetDouble(&media_type->attributes, key, value);
356 static HRESULT WINAPI mediatype_SetGUID(IMFMediaType *iface, REFGUID key, REFGUID value)
358 struct media_type *media_type = impl_from_IMFMediaType(iface);
360 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_mf_guid(value));
362 return attributes_SetGUID(&media_type->attributes, key, value);
365 static HRESULT WINAPI mediatype_SetString(IMFMediaType *iface, REFGUID key, const WCHAR *value)
367 struct media_type *media_type = impl_from_IMFMediaType(iface);
369 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_w(value));
371 return attributes_SetString(&media_type->attributes, key, value);
374 static HRESULT WINAPI mediatype_SetBlob(IMFMediaType *iface, REFGUID key, const UINT8 *buf, UINT32 size)
376 struct media_type *media_type = impl_from_IMFMediaType(iface);
378 TRACE("%p, %s, %p, %u.\n", iface, debugstr_attr(key), buf, size);
380 return attributes_SetBlob(&media_type->attributes, key, buf, size);
383 static HRESULT WINAPI mediatype_SetUnknown(IMFMediaType *iface, REFGUID key, IUnknown *unknown)
385 struct media_type *media_type = impl_from_IMFMediaType(iface);
387 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), unknown);
389 return attributes_SetUnknown(&media_type->attributes, key, unknown);
392 static HRESULT WINAPI mediatype_LockStore(IMFMediaType *iface)
394 struct media_type *media_type = impl_from_IMFMediaType(iface);
396 TRACE("%p.\n", iface);
398 return attributes_LockStore(&media_type->attributes);
401 static HRESULT WINAPI mediatype_UnlockStore(IMFMediaType *iface)
403 struct media_type *media_type = impl_from_IMFMediaType(iface);
405 TRACE("%p.\n", iface);
407 return attributes_UnlockStore(&media_type->attributes);
410 static HRESULT WINAPI mediatype_GetCount(IMFMediaType *iface, UINT32 *count)
412 struct media_type *media_type = impl_from_IMFMediaType(iface);
414 TRACE("%p, %p.\n", iface, count);
416 return attributes_GetCount(&media_type->attributes, count);
419 static HRESULT WINAPI mediatype_GetItemByIndex(IMFMediaType *iface, UINT32 index, GUID *key, PROPVARIANT *value)
421 struct media_type *media_type = impl_from_IMFMediaType(iface);
423 TRACE("%p, %u, %p, %p.\n", iface, index, key, value);
425 return attributes_GetItemByIndex(&media_type->attributes, index, key, value);
428 static HRESULT WINAPI mediatype_CopyAllItems(IMFMediaType *iface, IMFAttributes *dest)
430 struct media_type *media_type = impl_from_IMFMediaType(iface);
432 TRACE("%p, %p.\n", iface, dest);
434 return attributes_CopyAllItems(&media_type->attributes, dest);
437 static HRESULT WINAPI mediatype_GetMajorType(IMFMediaType *iface, GUID *guid)
439 struct media_type *media_type = impl_from_IMFMediaType(iface);
441 TRACE("%p, %p.\n", iface, guid);
443 return attributes_GetGUID(&media_type->attributes, &MF_MT_MAJOR_TYPE, guid);
446 static HRESULT mediatype_is_compressed(struct media_type *media_type, BOOL *compressed)
448 UINT32 value;
450 if (FAILED(attributes_GetUINT32(&media_type->attributes, &MF_MT_ALL_SAMPLES_INDEPENDENT, &value)))
452 value = 0;
455 *compressed = !value;
457 return S_OK;
460 static HRESULT WINAPI mediatype_IsCompressedFormat(IMFMediaType *iface, BOOL *compressed)
462 struct media_type *media_type = impl_from_IMFMediaType(iface);
464 TRACE("%p, %p.\n", iface, compressed);
466 return mediatype_is_compressed(media_type, compressed);
469 static HRESULT media_type_is_equal(struct media_type *media_type, IMFMediaType *type, DWORD *flags)
471 const DWORD full_equality_flags = MF_MEDIATYPE_EQUAL_MAJOR_TYPES | MF_MEDIATYPE_EQUAL_FORMAT_TYPES |
472 MF_MEDIATYPE_EQUAL_FORMAT_DATA | MF_MEDIATYPE_EQUAL_FORMAT_USER_DATA;
473 struct comparand
475 IMFAttributes *type;
476 PROPVARIANT value;
477 UINT32 count;
478 GUID guid;
479 HRESULT hr;
480 } left, right, swp;
481 unsigned int i;
482 BOOL result;
484 *flags = 0;
486 left.type = &media_type->attributes.IMFAttributes_iface;
487 right.type = (IMFAttributes *)type;
489 if (FAILED(IMFAttributes_GetGUID(left.type, &MF_MT_MAJOR_TYPE, &left.guid)))
490 return E_INVALIDARG;
492 if (FAILED(IMFAttributes_GetGUID(right.type, &MF_MT_MAJOR_TYPE, &right.guid)))
493 return E_INVALIDARG;
495 if (IsEqualGUID(&left.guid, &right.guid))
496 *flags |= MF_MEDIATYPE_EQUAL_MAJOR_TYPES;
498 /* Subtypes equal or both missing. */
499 left.hr = IMFAttributes_GetGUID(left.type, &MF_MT_SUBTYPE, &left.guid);
500 right.hr = IMFAttributes_GetGUID(right.type, &MF_MT_SUBTYPE, &right.guid);
502 if ((SUCCEEDED(left.hr) && SUCCEEDED(right.hr) && IsEqualGUID(&left.guid, &right.guid)) ||
503 (FAILED(left.hr) && FAILED(right.hr)))
505 *flags |= MF_MEDIATYPE_EQUAL_FORMAT_TYPES;
508 /* Format data */
509 IMFAttributes_GetCount(left.type, &left.count);
510 IMFAttributes_GetCount(right.type, &right.count);
512 if (right.count < left.count)
514 swp = left;
515 left = right;
516 right = swp;
519 *flags |= MF_MEDIATYPE_EQUAL_FORMAT_DATA;
521 for (i = 0; i < left.count; ++i)
523 PROPVARIANT value;
524 GUID key;
526 if (SUCCEEDED(IMFAttributes_GetItemByIndex(left.type, i, &key, &value)))
528 if (IsEqualGUID(&key, &MF_MT_USER_DATA) ||
529 IsEqualGUID(&key, &MF_MT_FRAME_RATE_RANGE_MIN) ||
530 IsEqualGUID(&key, &MF_MT_FRAME_RATE_RANGE_MAX))
532 PropVariantClear(&value);
533 continue;
536 result = FALSE;
537 IMFAttributes_CompareItem(right.type, &key, &value, &result);
538 PropVariantClear(&value);
539 if (!result)
541 *flags &= ~MF_MEDIATYPE_EQUAL_FORMAT_DATA;
542 break;
547 /* User data */
548 PropVariantInit(&left.value);
549 left.hr = IMFAttributes_GetItem(left.type, &MF_MT_USER_DATA, &left.value);
550 PropVariantInit(&right.value);
551 right.hr = IMFAttributes_GetItem(right.type, &MF_MT_USER_DATA, &right.value);
553 /* Compare user data if both types have it, otherwise simply check if both don't. */
554 if (SUCCEEDED(left.hr) && SUCCEEDED(right.hr))
556 result = FALSE;
557 IMFAttributes_CompareItem(left.type, &MF_MT_USER_DATA, &left.value, &result);
559 else
560 result = FAILED(left.hr) && FAILED(right.hr);
562 PropVariantClear(&left.value);
563 PropVariantClear(&right.value);
565 if (result)
566 *flags |= MF_MEDIATYPE_EQUAL_FORMAT_USER_DATA;
568 return *flags == full_equality_flags ? S_OK : S_FALSE;
571 static HRESULT WINAPI mediatype_IsEqual(IMFMediaType *iface, IMFMediaType *type, DWORD *flags)
573 struct media_type *media_type = impl_from_IMFMediaType(iface);
575 TRACE("%p, %p, %p.\n", iface, type, flags);
577 return media_type_is_equal(media_type, type, flags);
580 static HRESULT WINAPI mediatype_GetRepresentation(IMFMediaType *iface, GUID guid, void **representation)
582 FIXME("%p, %s, %p.\n", iface, debugstr_guid(&guid), representation);
584 return E_NOTIMPL;
587 static HRESULT WINAPI mediatype_FreeRepresentation(IMFMediaType *iface, GUID guid, void *representation)
589 FIXME("%p, %s, %p.\n", iface, debugstr_guid(&guid), representation);
591 return E_NOTIMPL;
594 static const IMFMediaTypeVtbl mediatypevtbl =
596 mediatype_QueryInterface,
597 mediatype_AddRef,
598 mediatype_Release,
599 mediatype_GetItem,
600 mediatype_GetItemType,
601 mediatype_CompareItem,
602 mediatype_Compare,
603 mediatype_GetUINT32,
604 mediatype_GetUINT64,
605 mediatype_GetDouble,
606 mediatype_GetGUID,
607 mediatype_GetStringLength,
608 mediatype_GetString,
609 mediatype_GetAllocatedString,
610 mediatype_GetBlobSize,
611 mediatype_GetBlob,
612 mediatype_GetAllocatedBlob,
613 mediatype_GetUnknown,
614 mediatype_SetItem,
615 mediatype_DeleteItem,
616 mediatype_DeleteAllItems,
617 mediatype_SetUINT32,
618 mediatype_SetUINT64,
619 mediatype_SetDouble,
620 mediatype_SetGUID,
621 mediatype_SetString,
622 mediatype_SetBlob,
623 mediatype_SetUnknown,
624 mediatype_LockStore,
625 mediatype_UnlockStore,
626 mediatype_GetCount,
627 mediatype_GetItemByIndex,
628 mediatype_CopyAllItems,
629 mediatype_GetMajorType,
630 mediatype_IsCompressedFormat,
631 mediatype_IsEqual,
632 mediatype_GetRepresentation,
633 mediatype_FreeRepresentation
636 static HRESULT WINAPI video_mediatype_QueryInterface(IMFVideoMediaType *iface, REFIID riid, void **out)
638 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
639 return IMFMediaType_QueryInterface(&media_type->IMFMediaType_iface, riid, out);
642 static ULONG WINAPI video_mediatype_AddRef(IMFVideoMediaType *iface)
644 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
645 return IMFMediaType_AddRef(&media_type->IMFMediaType_iface);
648 static ULONG WINAPI video_mediatype_Release(IMFVideoMediaType *iface)
650 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
651 return IMFMediaType_Release(&media_type->IMFMediaType_iface);
654 static HRESULT WINAPI video_mediatype_GetItem(IMFVideoMediaType *iface, REFGUID key, PROPVARIANT *value)
656 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
658 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
660 return attributes_GetItem(&media_type->attributes, key, value);
663 static HRESULT WINAPI video_mediatype_GetItemType(IMFVideoMediaType *iface, REFGUID key, MF_ATTRIBUTE_TYPE *type)
665 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
667 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), type);
669 return attributes_GetItemType(&media_type->attributes, key, type);
672 static HRESULT WINAPI video_mediatype_CompareItem(IMFVideoMediaType *iface, REFGUID key, REFPROPVARIANT value, BOOL *result)
674 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
676 TRACE("%p, %s, %s, %p.\n", iface, debugstr_attr(key), debugstr_propvar(value), result);
678 return attributes_CompareItem(&media_type->attributes, key, value, result);
681 static HRESULT WINAPI video_mediatype_Compare(IMFVideoMediaType *iface, IMFAttributes *attrs,
682 MF_ATTRIBUTES_MATCH_TYPE type, BOOL *result)
684 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
686 TRACE("%p, %p, %d, %p.\n", iface, attrs, type, result);
688 return attributes_Compare(&media_type->attributes, attrs, type, result);
691 static HRESULT WINAPI video_mediatype_GetUINT32(IMFVideoMediaType *iface, REFGUID key, UINT32 *value)
693 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
695 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
697 return attributes_GetUINT32(&media_type->attributes, key, value);
700 static HRESULT WINAPI video_mediatype_GetUINT64(IMFVideoMediaType *iface, REFGUID key, UINT64 *value)
702 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
704 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
706 return attributes_GetUINT64(&media_type->attributes, key, value);
709 static HRESULT WINAPI video_mediatype_GetDouble(IMFVideoMediaType *iface, REFGUID key, double *value)
711 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
713 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
715 return attributes_GetDouble(&media_type->attributes, key, value);
718 static HRESULT WINAPI video_mediatype_GetGUID(IMFVideoMediaType *iface, REFGUID key, GUID *value)
720 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
722 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
724 return attributes_GetGUID(&media_type->attributes, key, value);
727 static HRESULT WINAPI video_mediatype_GetStringLength(IMFVideoMediaType *iface, REFGUID key, UINT32 *length)
729 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
731 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), length);
733 return attributes_GetStringLength(&media_type->attributes, key, length);
736 static HRESULT WINAPI video_mediatype_GetString(IMFVideoMediaType *iface, REFGUID key, WCHAR *value,
737 UINT32 size, UINT32 *length)
739 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
741 TRACE("%p, %s, %p, %u, %p.\n", iface, debugstr_attr(key), value, size, length);
743 return attributes_GetString(&media_type->attributes, key, value, size, length);
746 static HRESULT WINAPI video_mediatype_GetAllocatedString(IMFVideoMediaType *iface, REFGUID key,
747 WCHAR **value, UINT32 *length)
749 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
751 TRACE("%p, %s, %p, %p.\n", iface, debugstr_attr(key), value, length);
753 return attributes_GetAllocatedString(&media_type->attributes, key, value, length);
756 static HRESULT WINAPI video_mediatype_GetBlobSize(IMFVideoMediaType *iface, REFGUID key, UINT32 *size)
758 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
760 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), size);
762 return attributes_GetBlobSize(&media_type->attributes, key, size);
765 static HRESULT WINAPI video_mediatype_GetBlob(IMFVideoMediaType *iface, REFGUID key, UINT8 *buf,
766 UINT32 bufsize, UINT32 *blobsize)
768 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
770 TRACE("%p, %s, %p, %u, %p.\n", iface, debugstr_attr(key), buf, bufsize, blobsize);
772 return attributes_GetBlob(&media_type->attributes, key, buf, bufsize, blobsize);
775 static HRESULT WINAPI video_mediatype_GetAllocatedBlob(IMFVideoMediaType *iface, REFGUID key, UINT8 **buf, UINT32 *size)
777 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
779 TRACE("%p, %s, %p, %p.\n", iface, debugstr_attr(key), buf, size);
781 return attributes_GetAllocatedBlob(&media_type->attributes, key, buf, size);
784 static HRESULT WINAPI video_mediatype_GetUnknown(IMFVideoMediaType *iface, REFGUID key, REFIID riid, void **obj)
786 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
788 TRACE("%p, %s, %s, %p.\n", iface, debugstr_attr(key), debugstr_guid(riid), obj);
790 return attributes_GetUnknown(&media_type->attributes, key, riid, obj);
793 static HRESULT WINAPI video_mediatype_SetItem(IMFVideoMediaType *iface, REFGUID key, REFPROPVARIANT value)
795 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
797 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_propvar(value));
799 return attributes_SetItem(&media_type->attributes, key, value);
802 static HRESULT WINAPI video_mediatype_DeleteItem(IMFVideoMediaType *iface, REFGUID key)
804 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
806 TRACE("%p, %s.\n", iface, debugstr_attr(key));
808 return attributes_DeleteItem(&media_type->attributes, key);
811 static HRESULT WINAPI video_mediatype_DeleteAllItems(IMFVideoMediaType *iface)
813 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
815 TRACE("%p.\n", iface);
817 return attributes_DeleteAllItems(&media_type->attributes);
820 static HRESULT WINAPI video_mediatype_SetUINT32(IMFVideoMediaType *iface, REFGUID key, UINT32 value)
822 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
824 TRACE("%p, %s, %u.\n", iface, debugstr_attr(key), value);
826 return attributes_SetUINT32(&media_type->attributes, key, value);
829 static HRESULT WINAPI video_mediatype_SetUINT64(IMFVideoMediaType *iface, REFGUID key, UINT64 value)
831 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
833 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), wine_dbgstr_longlong(value));
835 return attributes_SetUINT64(&media_type->attributes, key, value);
838 static HRESULT WINAPI video_mediatype_SetDouble(IMFVideoMediaType *iface, REFGUID key, double value)
840 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
842 TRACE("%p, %s, %f.\n", iface, debugstr_attr(key), value);
844 return attributes_SetDouble(&media_type->attributes, key, value);
847 static HRESULT WINAPI video_mediatype_SetGUID(IMFVideoMediaType *iface, REFGUID key, REFGUID value)
849 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
851 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_mf_guid(value));
853 return attributes_SetGUID(&media_type->attributes, key, value);
856 static HRESULT WINAPI video_mediatype_SetString(IMFVideoMediaType *iface, REFGUID key, const WCHAR *value)
858 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
860 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_w(value));
862 return attributes_SetString(&media_type->attributes, key, value);
865 static HRESULT WINAPI video_mediatype_SetBlob(IMFVideoMediaType *iface, REFGUID key, const UINT8 *buf, UINT32 size)
867 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
869 TRACE("%p, %s, %p, %u.\n", iface, debugstr_attr(key), buf, size);
871 return attributes_SetBlob(&media_type->attributes, key, buf, size);
874 static HRESULT WINAPI video_mediatype_SetUnknown(IMFVideoMediaType *iface, REFGUID key, IUnknown *unknown)
876 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
878 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), unknown);
880 return attributes_SetUnknown(&media_type->attributes, key, unknown);
883 static HRESULT WINAPI video_mediatype_LockStore(IMFVideoMediaType *iface)
885 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
887 TRACE("%p.\n", iface);
889 return attributes_LockStore(&media_type->attributes);
892 static HRESULT WINAPI video_mediatype_UnlockStore(IMFVideoMediaType *iface)
894 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
896 TRACE("%p.\n", iface);
898 return attributes_UnlockStore(&media_type->attributes);
901 static HRESULT WINAPI video_mediatype_GetCount(IMFVideoMediaType *iface, UINT32 *count)
903 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
905 TRACE("%p, %p.\n", iface, count);
907 return attributes_GetCount(&media_type->attributes, count);
910 static HRESULT WINAPI video_mediatype_GetItemByIndex(IMFVideoMediaType *iface, UINT32 index, GUID *key, PROPVARIANT *value)
912 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
914 TRACE("%p, %u, %p, %p.\n", iface, index, key, value);
916 return attributes_GetItemByIndex(&media_type->attributes, index, key, value);
919 static HRESULT WINAPI video_mediatype_CopyAllItems(IMFVideoMediaType *iface, IMFAttributes *dest)
921 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
923 TRACE("%p, %p.\n", iface, dest);
925 return attributes_CopyAllItems(&media_type->attributes, dest);
928 static HRESULT WINAPI video_mediatype_GetMajorType(IMFVideoMediaType *iface, GUID *guid)
930 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
932 TRACE("%p, %p.\n", iface, guid);
934 return attributes_GetGUID(&media_type->attributes, &MF_MT_MAJOR_TYPE, guid);
937 static HRESULT WINAPI video_mediatype_IsCompressedFormat(IMFVideoMediaType *iface, BOOL *compressed)
939 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
941 TRACE("%p, %p.\n", iface, compressed);
943 return mediatype_is_compressed(media_type, compressed);
946 static HRESULT WINAPI video_mediatype_IsEqual(IMFVideoMediaType *iface, IMFMediaType *type, DWORD *flags)
948 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
950 TRACE("%p, %p, %p.\n", iface, type, flags);
952 return media_type_is_equal(media_type, type, flags);
955 static HRESULT WINAPI video_mediatype_GetRepresentation(IMFVideoMediaType *iface, GUID guid, void **representation)
957 FIXME("%p, %s, %p.\n", iface, debugstr_guid(&guid), representation);
959 return E_NOTIMPL;
962 static HRESULT WINAPI video_mediatype_FreeRepresentation(IMFVideoMediaType *iface, GUID guid, void *representation)
964 FIXME("%p, %s, %p.\n", iface, debugstr_guid(&guid), representation);
966 return E_NOTIMPL;
969 static const MFVIDEOFORMAT * WINAPI video_mediatype_GetVideoFormat(IMFVideoMediaType *iface)
971 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
972 unsigned int size;
973 HRESULT hr;
975 TRACE("%p.\n", iface);
977 CoTaskMemFree(media_type->video_format);
978 if (FAILED(hr = MFCreateMFVideoFormatFromMFMediaType((IMFMediaType *)iface, &media_type->video_format, &size)))
979 WARN("Failed to create format description, hr %#x.\n", hr);
981 return media_type->video_format;
984 static HRESULT WINAPI video_mediatype_GetVideoRepresentation(IMFVideoMediaType *iface, GUID representation,
985 void **data, LONG stride)
987 FIXME("%p, %s, %p, %d.\n", iface, debugstr_guid(&representation), data, stride);
989 return E_NOTIMPL;
992 static const IMFVideoMediaTypeVtbl videomediatypevtbl =
994 video_mediatype_QueryInterface,
995 video_mediatype_AddRef,
996 video_mediatype_Release,
997 video_mediatype_GetItem,
998 video_mediatype_GetItemType,
999 video_mediatype_CompareItem,
1000 video_mediatype_Compare,
1001 video_mediatype_GetUINT32,
1002 video_mediatype_GetUINT64,
1003 video_mediatype_GetDouble,
1004 video_mediatype_GetGUID,
1005 video_mediatype_GetStringLength,
1006 video_mediatype_GetString,
1007 video_mediatype_GetAllocatedString,
1008 video_mediatype_GetBlobSize,
1009 video_mediatype_GetBlob,
1010 video_mediatype_GetAllocatedBlob,
1011 video_mediatype_GetUnknown,
1012 video_mediatype_SetItem,
1013 video_mediatype_DeleteItem,
1014 video_mediatype_DeleteAllItems,
1015 video_mediatype_SetUINT32,
1016 video_mediatype_SetUINT64,
1017 video_mediatype_SetDouble,
1018 video_mediatype_SetGUID,
1019 video_mediatype_SetString,
1020 video_mediatype_SetBlob,
1021 video_mediatype_SetUnknown,
1022 video_mediatype_LockStore,
1023 video_mediatype_UnlockStore,
1024 video_mediatype_GetCount,
1025 video_mediatype_GetItemByIndex,
1026 video_mediatype_CopyAllItems,
1027 video_mediatype_GetMajorType,
1028 video_mediatype_IsCompressedFormat,
1029 video_mediatype_IsEqual,
1030 video_mediatype_GetRepresentation,
1031 video_mediatype_FreeRepresentation,
1032 video_mediatype_GetVideoFormat,
1033 video_mediatype_GetVideoRepresentation,
1036 static HRESULT WINAPI audio_mediatype_QueryInterface(IMFAudioMediaType *iface, REFIID riid, void **out)
1038 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1039 return IMFMediaType_QueryInterface(&media_type->IMFMediaType_iface, riid, out);
1042 static ULONG WINAPI audio_mediatype_AddRef(IMFAudioMediaType *iface)
1044 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1045 return IMFMediaType_AddRef(&media_type->IMFMediaType_iface);
1048 static ULONG WINAPI audio_mediatype_Release(IMFAudioMediaType *iface)
1050 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1051 return IMFMediaType_Release(&media_type->IMFMediaType_iface);
1054 static HRESULT WINAPI audio_mediatype_GetItem(IMFAudioMediaType *iface, REFGUID key, PROPVARIANT *value)
1056 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1058 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
1060 return attributes_GetItem(&media_type->attributes, key, value);
1063 static HRESULT WINAPI audio_mediatype_GetItemType(IMFAudioMediaType *iface, REFGUID key, MF_ATTRIBUTE_TYPE *type)
1065 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1067 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), type);
1069 return attributes_GetItemType(&media_type->attributes, key, type);
1072 static HRESULT WINAPI audio_mediatype_CompareItem(IMFAudioMediaType *iface, REFGUID key, REFPROPVARIANT value, BOOL *result)
1074 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1076 TRACE("%p, %s, %s, %p.\n", iface, debugstr_attr(key), debugstr_propvar(value), result);
1078 return attributes_CompareItem(&media_type->attributes, key, value, result);
1081 static HRESULT WINAPI audio_mediatype_Compare(IMFAudioMediaType *iface, IMFAttributes *attrs,
1082 MF_ATTRIBUTES_MATCH_TYPE type, BOOL *result)
1084 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1086 TRACE("%p, %p, %d, %p.\n", iface, attrs, type, result);
1088 return attributes_Compare(&media_type->attributes, attrs, type, result);
1091 static HRESULT WINAPI audio_mediatype_GetUINT32(IMFAudioMediaType *iface, REFGUID key, UINT32 *value)
1093 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1095 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
1097 return attributes_GetUINT32(&media_type->attributes, key, value);
1100 static HRESULT WINAPI audio_mediatype_GetUINT64(IMFAudioMediaType *iface, REFGUID key, UINT64 *value)
1102 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1104 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
1106 return attributes_GetUINT64(&media_type->attributes, key, value);
1109 static HRESULT WINAPI audio_mediatype_GetDouble(IMFAudioMediaType *iface, REFGUID key, double *value)
1111 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1113 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
1115 return attributes_GetDouble(&media_type->attributes, key, value);
1118 static HRESULT WINAPI audio_mediatype_GetGUID(IMFAudioMediaType *iface, REFGUID key, GUID *value)
1120 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1122 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
1124 return attributes_GetGUID(&media_type->attributes, key, value);
1127 static HRESULT WINAPI audio_mediatype_GetStringLength(IMFAudioMediaType *iface, REFGUID key, UINT32 *length)
1129 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1131 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), length);
1133 return attributes_GetStringLength(&media_type->attributes, key, length);
1136 static HRESULT WINAPI audio_mediatype_GetString(IMFAudioMediaType *iface, REFGUID key, WCHAR *value,
1137 UINT32 size, UINT32 *length)
1139 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1141 TRACE("%p, %s, %p, %u, %p.\n", iface, debugstr_attr(key), value, size, length);
1143 return attributes_GetString(&media_type->attributes, key, value, size, length);
1146 static HRESULT WINAPI audio_mediatype_GetAllocatedString(IMFAudioMediaType *iface, REFGUID key,
1147 WCHAR **value, UINT32 *length)
1149 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1151 TRACE("%p, %s, %p, %p.\n", iface, debugstr_attr(key), value, length);
1153 return attributes_GetAllocatedString(&media_type->attributes, key, value, length);
1156 static HRESULT WINAPI audio_mediatype_GetBlobSize(IMFAudioMediaType *iface, REFGUID key, UINT32 *size)
1158 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1160 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), size);
1162 return attributes_GetBlobSize(&media_type->attributes, key, size);
1165 static HRESULT WINAPI audio_mediatype_GetBlob(IMFAudioMediaType *iface, REFGUID key, UINT8 *buf,
1166 UINT32 bufsize, UINT32 *blobsize)
1168 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1170 TRACE("%p, %s, %p, %u, %p.\n", iface, debugstr_attr(key), buf, bufsize, blobsize);
1172 return attributes_GetBlob(&media_type->attributes, key, buf, bufsize, blobsize);
1175 static HRESULT WINAPI audio_mediatype_GetAllocatedBlob(IMFAudioMediaType *iface, REFGUID key, UINT8 **buf, UINT32 *size)
1177 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1179 TRACE("%p, %s, %p, %p.\n", iface, debugstr_attr(key), buf, size);
1181 return attributes_GetAllocatedBlob(&media_type->attributes, key, buf, size);
1184 static HRESULT WINAPI audio_mediatype_GetUnknown(IMFAudioMediaType *iface, REFGUID key, REFIID riid, void **obj)
1186 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1188 TRACE("%p, %s, %s, %p.\n", iface, debugstr_attr(key), debugstr_guid(riid), obj);
1190 return attributes_GetUnknown(&media_type->attributes, key, riid, obj);
1193 static HRESULT WINAPI audio_mediatype_SetItem(IMFAudioMediaType *iface, REFGUID key, REFPROPVARIANT value)
1195 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1197 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_propvar(value));
1199 return attributes_SetItem(&media_type->attributes, key, value);
1202 static HRESULT WINAPI audio_mediatype_DeleteItem(IMFAudioMediaType *iface, REFGUID key)
1204 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1206 TRACE("%p, %s.\n", iface, debugstr_attr(key));
1208 return attributes_DeleteItem(&media_type->attributes, key);
1211 static HRESULT WINAPI audio_mediatype_DeleteAllItems(IMFAudioMediaType *iface)
1213 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1215 TRACE("%p.\n", iface);
1217 return attributes_DeleteAllItems(&media_type->attributes);
1220 static HRESULT WINAPI audio_mediatype_SetUINT32(IMFAudioMediaType *iface, REFGUID key, UINT32 value)
1222 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1224 TRACE("%p, %s, %u.\n", iface, debugstr_attr(key), value);
1226 return attributes_SetUINT32(&media_type->attributes, key, value);
1229 static HRESULT WINAPI audio_mediatype_SetUINT64(IMFAudioMediaType *iface, REFGUID key, UINT64 value)
1231 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1233 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), wine_dbgstr_longlong(value));
1235 return attributes_SetUINT64(&media_type->attributes, key, value);
1238 static HRESULT WINAPI audio_mediatype_SetDouble(IMFAudioMediaType *iface, REFGUID key, double value)
1240 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1242 TRACE("%p, %s, %f.\n", iface, debugstr_attr(key), value);
1244 return attributes_SetDouble(&media_type->attributes, key, value);
1247 static HRESULT WINAPI audio_mediatype_SetGUID(IMFAudioMediaType *iface, REFGUID key, REFGUID value)
1249 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1251 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_mf_guid(value));
1253 return attributes_SetGUID(&media_type->attributes, key, value);
1256 static HRESULT WINAPI audio_mediatype_SetString(IMFAudioMediaType *iface, REFGUID key, const WCHAR *value)
1258 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1260 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_w(value));
1262 return attributes_SetString(&media_type->attributes, key, value);
1265 static HRESULT WINAPI audio_mediatype_SetBlob(IMFAudioMediaType *iface, REFGUID key, const UINT8 *buf, UINT32 size)
1267 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1269 TRACE("%p, %s, %p, %u.\n", iface, debugstr_attr(key), buf, size);
1271 return attributes_SetBlob(&media_type->attributes, key, buf, size);
1274 static HRESULT WINAPI audio_mediatype_SetUnknown(IMFAudioMediaType *iface, REFGUID key, IUnknown *unknown)
1276 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1278 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), unknown);
1280 return attributes_SetUnknown(&media_type->attributes, key, unknown);
1283 static HRESULT WINAPI audio_mediatype_LockStore(IMFAudioMediaType *iface)
1285 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1287 TRACE("%p.\n", iface);
1289 return attributes_LockStore(&media_type->attributes);
1292 static HRESULT WINAPI audio_mediatype_UnlockStore(IMFAudioMediaType *iface)
1294 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1296 TRACE("%p.\n", iface);
1298 return attributes_UnlockStore(&media_type->attributes);
1301 static HRESULT WINAPI audio_mediatype_GetCount(IMFAudioMediaType *iface, UINT32 *count)
1303 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1305 TRACE("%p, %p.\n", iface, count);
1307 return attributes_GetCount(&media_type->attributes, count);
1310 static HRESULT WINAPI audio_mediatype_GetItemByIndex(IMFAudioMediaType *iface, UINT32 index, GUID *key, PROPVARIANT *value)
1312 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1314 TRACE("%p, %u, %p, %p.\n", iface, index, key, value);
1316 return attributes_GetItemByIndex(&media_type->attributes, index, key, value);
1319 static HRESULT WINAPI audio_mediatype_CopyAllItems(IMFAudioMediaType *iface, IMFAttributes *dest)
1321 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1323 TRACE("%p, %p.\n", iface, dest);
1325 return attributes_CopyAllItems(&media_type->attributes, dest);
1328 static HRESULT WINAPI audio_mediatype_GetMajorType(IMFAudioMediaType *iface, GUID *guid)
1330 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1332 TRACE("%p, %p.\n", iface, guid);
1334 return attributes_GetGUID(&media_type->attributes, &MF_MT_MAJOR_TYPE, guid);
1337 static HRESULT WINAPI audio_mediatype_IsCompressedFormat(IMFAudioMediaType *iface, BOOL *compressed)
1339 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1341 TRACE("%p, %p.\n", iface, compressed);
1343 return mediatype_is_compressed(media_type, compressed);
1346 static HRESULT WINAPI audio_mediatype_IsEqual(IMFAudioMediaType *iface, IMFMediaType *type, DWORD *flags)
1348 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1350 TRACE("%p, %p, %p.\n", iface, type, flags);
1352 return media_type_is_equal(media_type, type, flags);
1355 static HRESULT WINAPI audio_mediatype_GetRepresentation(IMFAudioMediaType *iface, GUID guid, void **representation)
1357 FIXME("%p, %s, %p.\n", iface, debugstr_guid(&guid), representation);
1359 return E_NOTIMPL;
1362 static HRESULT WINAPI audio_mediatype_FreeRepresentation(IMFAudioMediaType *iface, GUID guid, void *representation)
1364 FIXME("%p, %s, %p.\n", iface, debugstr_guid(&guid), representation);
1366 return E_NOTIMPL;
1369 static const WAVEFORMATEX * WINAPI audio_mediatype_GetAudioFormat(IMFAudioMediaType *iface)
1371 FIXME("%p.\n", iface);
1373 return NULL;
1376 static const IMFAudioMediaTypeVtbl audiomediatypevtbl =
1378 audio_mediatype_QueryInterface,
1379 audio_mediatype_AddRef,
1380 audio_mediatype_Release,
1381 audio_mediatype_GetItem,
1382 audio_mediatype_GetItemType,
1383 audio_mediatype_CompareItem,
1384 audio_mediatype_Compare,
1385 audio_mediatype_GetUINT32,
1386 audio_mediatype_GetUINT64,
1387 audio_mediatype_GetDouble,
1388 audio_mediatype_GetGUID,
1389 audio_mediatype_GetStringLength,
1390 audio_mediatype_GetString,
1391 audio_mediatype_GetAllocatedString,
1392 audio_mediatype_GetBlobSize,
1393 audio_mediatype_GetBlob,
1394 audio_mediatype_GetAllocatedBlob,
1395 audio_mediatype_GetUnknown,
1396 audio_mediatype_SetItem,
1397 audio_mediatype_DeleteItem,
1398 audio_mediatype_DeleteAllItems,
1399 audio_mediatype_SetUINT32,
1400 audio_mediatype_SetUINT64,
1401 audio_mediatype_SetDouble,
1402 audio_mediatype_SetGUID,
1403 audio_mediatype_SetString,
1404 audio_mediatype_SetBlob,
1405 audio_mediatype_SetUnknown,
1406 audio_mediatype_LockStore,
1407 audio_mediatype_UnlockStore,
1408 audio_mediatype_GetCount,
1409 audio_mediatype_GetItemByIndex,
1410 audio_mediatype_CopyAllItems,
1411 audio_mediatype_GetMajorType,
1412 audio_mediatype_IsCompressedFormat,
1413 audio_mediatype_IsEqual,
1414 audio_mediatype_GetRepresentation,
1415 audio_mediatype_FreeRepresentation,
1416 audio_mediatype_GetAudioFormat,
1419 static HRESULT create_media_type(struct media_type **ret)
1421 struct media_type *object;
1422 HRESULT hr;
1424 object = heap_alloc_zero(sizeof(*object));
1425 if (!object)
1426 return E_OUTOFMEMORY;
1428 if (FAILED(hr = init_attributes_object(&object->attributes, 0)))
1430 heap_free(object);
1431 return hr;
1433 object->IMFMediaType_iface.lpVtbl = &mediatypevtbl;
1434 object->IMFVideoMediaType_iface.lpVtbl = &videomediatypevtbl;
1435 object->IMFAudioMediaType_iface.lpVtbl = &audiomediatypevtbl;
1437 *ret = object;
1439 return S_OK;
1442 /***********************************************************************
1443 * MFCreateMediaType (mfplat.@)
1445 HRESULT WINAPI MFCreateMediaType(IMFMediaType **media_type)
1447 struct media_type *object;
1448 HRESULT hr;
1450 TRACE("%p.\n", media_type);
1452 if (!media_type)
1453 return E_INVALIDARG;
1455 if (FAILED(hr = create_media_type(&object)))
1456 return hr;
1458 *media_type = &object->IMFMediaType_iface;
1460 TRACE("Created media type %p.\n", *media_type);
1462 return S_OK;
1465 static HRESULT WINAPI stream_descriptor_QueryInterface(IMFStreamDescriptor *iface, REFIID riid, void **out)
1467 TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), out);
1469 if (IsEqualIID(riid, &IID_IMFStreamDescriptor) ||
1470 IsEqualIID(riid, &IID_IMFAttributes) ||
1471 IsEqualIID(riid, &IID_IUnknown))
1473 *out = iface;
1474 IMFStreamDescriptor_AddRef(iface);
1475 return S_OK;
1478 WARN("Unsupported %s.\n", debugstr_guid(riid));
1479 *out = NULL;
1480 return E_NOINTERFACE;
1483 static ULONG WINAPI stream_descriptor_AddRef(IMFStreamDescriptor *iface)
1485 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1486 ULONG refcount = InterlockedIncrement(&stream_desc->attributes.ref);
1488 TRACE("%p, refcount %u.\n", iface, refcount);
1490 return refcount;
1493 static ULONG WINAPI stream_descriptor_Release(IMFStreamDescriptor *iface)
1495 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1496 ULONG refcount = InterlockedDecrement(&stream_desc->attributes.ref);
1497 unsigned int i;
1499 TRACE("%p, refcount %u.\n", iface, refcount);
1501 if (!refcount)
1503 for (i = 0; i < stream_desc->media_types_count; ++i)
1505 if (stream_desc->media_types[i])
1506 IMFMediaType_Release(stream_desc->media_types[i]);
1508 heap_free(stream_desc->media_types);
1509 if (stream_desc->current_type)
1510 IMFMediaType_Release(stream_desc->current_type);
1511 clear_attributes_object(&stream_desc->attributes);
1512 heap_free(stream_desc);
1515 return refcount;
1518 static HRESULT WINAPI stream_descriptor_GetItem(IMFStreamDescriptor *iface, REFGUID key, PROPVARIANT *value)
1520 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1522 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
1524 return attributes_GetItem(&stream_desc->attributes, key, value);
1527 static HRESULT WINAPI stream_descriptor_GetItemType(IMFStreamDescriptor *iface, REFGUID key, MF_ATTRIBUTE_TYPE *type)
1529 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1531 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), type);
1533 return attributes_GetItemType(&stream_desc->attributes, key, type);
1536 static HRESULT WINAPI stream_descriptor_CompareItem(IMFStreamDescriptor *iface, REFGUID key, REFPROPVARIANT value,
1537 BOOL *result)
1539 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1541 TRACE("%p, %s, %s, %p.\n", iface, debugstr_attr(key), debugstr_propvar(value), result);
1543 return attributes_CompareItem(&stream_desc->attributes, key, value, result);
1546 static HRESULT WINAPI stream_descriptor_Compare(IMFStreamDescriptor *iface, IMFAttributes *theirs,
1547 MF_ATTRIBUTES_MATCH_TYPE type, BOOL *result)
1549 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1551 TRACE("%p, %p, %d, %p.\n", iface, theirs, type, result);
1553 return attributes_Compare(&stream_desc->attributes, theirs, type, result);
1556 static HRESULT WINAPI stream_descriptor_GetUINT32(IMFStreamDescriptor *iface, REFGUID key, UINT32 *value)
1558 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1560 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
1562 return attributes_GetUINT32(&stream_desc->attributes, key, value);
1565 static HRESULT WINAPI stream_descriptor_GetUINT64(IMFStreamDescriptor *iface, REFGUID key, UINT64 *value)
1567 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1569 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
1571 return attributes_GetUINT64(&stream_desc->attributes, key, value);
1574 static HRESULT WINAPI stream_descriptor_GetDouble(IMFStreamDescriptor *iface, REFGUID key, double *value)
1576 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1578 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
1580 return attributes_GetDouble(&stream_desc->attributes, key, value);
1583 static HRESULT WINAPI stream_descriptor_GetGUID(IMFStreamDescriptor *iface, REFGUID key, GUID *value)
1585 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1587 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
1589 return attributes_GetGUID(&stream_desc->attributes, key, value);
1592 static HRESULT WINAPI stream_descriptor_GetStringLength(IMFStreamDescriptor *iface, REFGUID key, UINT32 *length)
1594 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1596 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), length);
1598 return attributes_GetStringLength(&stream_desc->attributes, key, length);
1601 static HRESULT WINAPI stream_descriptor_GetString(IMFStreamDescriptor *iface, REFGUID key, WCHAR *value,
1602 UINT32 size, UINT32 *length)
1604 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1606 TRACE("%p, %s, %p, %u, %p.\n", iface, debugstr_attr(key), value, size, length);
1608 return attributes_GetString(&stream_desc->attributes, key, value, size, length);
1611 static HRESULT WINAPI stream_descriptor_GetAllocatedString(IMFStreamDescriptor *iface, REFGUID key,
1612 WCHAR **value, UINT32 *length)
1614 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1616 TRACE("%p, %s, %p, %p.\n", iface, debugstr_attr(key), value, length);
1618 return attributes_GetAllocatedString(&stream_desc->attributes, key, value, length);
1621 static HRESULT WINAPI stream_descriptor_GetBlobSize(IMFStreamDescriptor *iface, REFGUID key, UINT32 *size)
1623 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1625 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), size);
1627 return attributes_GetBlobSize(&stream_desc->attributes, key, size);
1630 static HRESULT WINAPI stream_descriptor_GetBlob(IMFStreamDescriptor *iface, REFGUID key, UINT8 *buf,
1631 UINT32 bufsize, UINT32 *blobsize)
1633 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1635 TRACE("%p, %s, %p, %u, %p.\n", iface, debugstr_attr(key), buf, bufsize, blobsize);
1637 return attributes_GetBlob(&stream_desc->attributes, key, buf, bufsize, blobsize);
1640 static HRESULT WINAPI stream_descriptor_GetAllocatedBlob(IMFStreamDescriptor *iface, REFGUID key, UINT8 **buf,
1641 UINT32 *size)
1643 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1645 TRACE("%p, %s, %p, %p.\n", iface, debugstr_attr(key), buf, size);
1647 return attributes_GetAllocatedBlob(&stream_desc->attributes, key, buf, size);
1650 static HRESULT WINAPI stream_descriptor_GetUnknown(IMFStreamDescriptor *iface, REFGUID key, REFIID riid, void **out)
1652 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1654 TRACE("%p, %s, %s, %p.\n", iface, debugstr_attr(key), debugstr_guid(riid), out);
1656 return attributes_GetUnknown(&stream_desc->attributes, key, riid, out);
1659 static HRESULT WINAPI stream_descriptor_SetItem(IMFStreamDescriptor *iface, REFGUID key, REFPROPVARIANT value)
1661 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1663 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_propvar(value));
1665 return attributes_SetItem(&stream_desc->attributes, key, value);
1668 static HRESULT WINAPI stream_descriptor_DeleteItem(IMFStreamDescriptor *iface, REFGUID key)
1670 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1672 TRACE("%p, %s.\n", iface, debugstr_attr(key));
1674 return attributes_DeleteItem(&stream_desc->attributes, key);
1677 static HRESULT WINAPI stream_descriptor_DeleteAllItems(IMFStreamDescriptor *iface)
1679 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1681 TRACE("%p.\n", iface);
1683 return attributes_DeleteAllItems(&stream_desc->attributes);
1686 static HRESULT WINAPI stream_descriptor_SetUINT32(IMFStreamDescriptor *iface, REFGUID key, UINT32 value)
1688 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1690 TRACE("%p, %s, %u.\n", iface, debugstr_attr(key), value);
1692 return attributes_SetUINT32(&stream_desc->attributes, key, value);
1695 static HRESULT WINAPI stream_descriptor_SetUINT64(IMFStreamDescriptor *iface, REFGUID key, UINT64 value)
1697 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1699 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), wine_dbgstr_longlong(value));
1701 return attributes_SetUINT64(&stream_desc->attributes, key, value);
1704 static HRESULT WINAPI stream_descriptor_SetDouble(IMFStreamDescriptor *iface, REFGUID key, double value)
1706 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1708 TRACE("%p, %s, %f.\n", iface, debugstr_attr(key), value);
1710 return attributes_SetDouble(&stream_desc->attributes, key, value);
1713 static HRESULT WINAPI stream_descriptor_SetGUID(IMFStreamDescriptor *iface, REFGUID key, REFGUID value)
1715 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1717 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_mf_guid(value));
1719 return attributes_SetGUID(&stream_desc->attributes, key, value);
1722 static HRESULT WINAPI stream_descriptor_SetString(IMFStreamDescriptor *iface, REFGUID key, const WCHAR *value)
1724 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1726 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_w(value));
1728 return attributes_SetString(&stream_desc->attributes, key, value);
1731 static HRESULT WINAPI stream_descriptor_SetBlob(IMFStreamDescriptor *iface, REFGUID key, const UINT8 *buf, UINT32 size)
1733 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1735 TRACE("%p, %s, %p, %u.\n", iface, debugstr_attr(key), buf, size);
1737 return attributes_SetBlob(&stream_desc->attributes, key, buf, size);
1740 static HRESULT WINAPI stream_descriptor_SetUnknown(IMFStreamDescriptor *iface, REFGUID key, IUnknown *unknown)
1742 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1744 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), unknown);
1746 return attributes_SetUnknown(&stream_desc->attributes, key, unknown);
1749 static HRESULT WINAPI stream_descriptor_LockStore(IMFStreamDescriptor *iface)
1751 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1753 TRACE("%p.\n", iface);
1755 return attributes_LockStore(&stream_desc->attributes);
1758 static HRESULT WINAPI stream_descriptor_UnlockStore(IMFStreamDescriptor *iface)
1760 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1762 TRACE("%p.\n", iface);
1764 return attributes_UnlockStore(&stream_desc->attributes);
1767 static HRESULT WINAPI stream_descriptor_GetCount(IMFStreamDescriptor *iface, UINT32 *count)
1769 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1771 TRACE("%p, %p.\n", iface, count);
1773 return attributes_GetCount(&stream_desc->attributes, count);
1776 static HRESULT WINAPI stream_descriptor_GetItemByIndex(IMFStreamDescriptor *iface, UINT32 index, GUID *key,
1777 PROPVARIANT *value)
1779 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1781 TRACE("%p, %u, %p, %p.\n", iface, index, key, value);
1783 return attributes_GetItemByIndex(&stream_desc->attributes, index, key, value);
1786 static HRESULT WINAPI stream_descriptor_CopyAllItems(IMFStreamDescriptor *iface, IMFAttributes *dest)
1788 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1790 TRACE("%p, %p.\n", iface, dest);
1792 return attributes_CopyAllItems(&stream_desc->attributes, dest);
1795 static HRESULT WINAPI stream_descriptor_GetStreamIdentifier(IMFStreamDescriptor *iface, DWORD *identifier)
1797 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1799 TRACE("%p, %p.\n", iface, identifier);
1801 *identifier = stream_desc->identifier;
1803 return S_OK;
1806 static HRESULT WINAPI stream_descriptor_GetMediaTypeHandler(IMFStreamDescriptor *iface, IMFMediaTypeHandler **handler)
1808 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1810 TRACE("%p, %p.\n", iface, handler);
1812 *handler = &stream_desc->IMFMediaTypeHandler_iface;
1813 IMFMediaTypeHandler_AddRef(*handler);
1815 return S_OK;
1818 static const IMFStreamDescriptorVtbl streamdescriptorvtbl =
1820 stream_descriptor_QueryInterface,
1821 stream_descriptor_AddRef,
1822 stream_descriptor_Release,
1823 stream_descriptor_GetItem,
1824 stream_descriptor_GetItemType,
1825 stream_descriptor_CompareItem,
1826 stream_descriptor_Compare,
1827 stream_descriptor_GetUINT32,
1828 stream_descriptor_GetUINT64,
1829 stream_descriptor_GetDouble,
1830 stream_descriptor_GetGUID,
1831 stream_descriptor_GetStringLength,
1832 stream_descriptor_GetString,
1833 stream_descriptor_GetAllocatedString,
1834 stream_descriptor_GetBlobSize,
1835 stream_descriptor_GetBlob,
1836 stream_descriptor_GetAllocatedBlob,
1837 stream_descriptor_GetUnknown,
1838 stream_descriptor_SetItem,
1839 stream_descriptor_DeleteItem,
1840 stream_descriptor_DeleteAllItems,
1841 stream_descriptor_SetUINT32,
1842 stream_descriptor_SetUINT64,
1843 stream_descriptor_SetDouble,
1844 stream_descriptor_SetGUID,
1845 stream_descriptor_SetString,
1846 stream_descriptor_SetBlob,
1847 stream_descriptor_SetUnknown,
1848 stream_descriptor_LockStore,
1849 stream_descriptor_UnlockStore,
1850 stream_descriptor_GetCount,
1851 stream_descriptor_GetItemByIndex,
1852 stream_descriptor_CopyAllItems,
1853 stream_descriptor_GetStreamIdentifier,
1854 stream_descriptor_GetMediaTypeHandler
1857 static HRESULT WINAPI mediatype_handler_QueryInterface(IMFMediaTypeHandler *iface, REFIID riid, void **obj)
1859 TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), obj);
1861 if (IsEqualIID(riid, &IID_IMFMediaTypeHandler) ||
1862 IsEqualIID(riid, &IID_IUnknown))
1864 *obj = iface;
1865 IMFMediaTypeHandler_AddRef(iface);
1866 return S_OK;
1869 WARN("Unsupported %s.\n", debugstr_guid(riid));
1870 *obj = NULL;
1871 return E_NOINTERFACE;
1874 static ULONG WINAPI mediatype_handler_AddRef(IMFMediaTypeHandler *iface)
1876 struct stream_desc *stream_desc = impl_from_IMFMediaTypeHandler(iface);
1877 return IMFStreamDescriptor_AddRef(&stream_desc->IMFStreamDescriptor_iface);
1880 static ULONG WINAPI mediatype_handler_Release(IMFMediaTypeHandler *iface)
1882 struct stream_desc *stream_desc = impl_from_IMFMediaTypeHandler(iface);
1883 return IMFStreamDescriptor_Release(&stream_desc->IMFStreamDescriptor_iface);
1886 static BOOL stream_descriptor_is_mediatype_supported(IMFMediaType *media_type, IMFMediaType *candidate)
1888 DWORD flags = 0;
1890 if (FAILED(IMFMediaType_IsEqual(media_type, candidate, &flags)))
1891 return FALSE;
1893 return (flags & (MF_MEDIATYPE_EQUAL_MAJOR_TYPES | MF_MEDIATYPE_EQUAL_FORMAT_TYPES)) ==
1894 (MF_MEDIATYPE_EQUAL_MAJOR_TYPES | MF_MEDIATYPE_EQUAL_FORMAT_TYPES);
1897 static HRESULT WINAPI mediatype_handler_IsMediaTypeSupported(IMFMediaTypeHandler *iface, IMFMediaType *in_type,
1898 IMFMediaType **out_type)
1900 struct stream_desc *stream_desc = impl_from_IMFMediaTypeHandler(iface);
1901 BOOL supported = FALSE;
1902 unsigned int i;
1904 TRACE("%p, %p, %p.\n", iface, in_type, out_type);
1906 if (!in_type)
1907 return E_POINTER;
1909 if (out_type)
1910 *out_type = NULL;
1912 EnterCriticalSection(&stream_desc->attributes.cs);
1914 supported = stream_desc->current_type && stream_descriptor_is_mediatype_supported(stream_desc->current_type, in_type);
1915 if (!supported)
1917 for (i = 0; i < stream_desc->media_types_count; ++i)
1919 if ((supported = stream_descriptor_is_mediatype_supported(stream_desc->media_types[i], in_type)))
1920 break;
1924 LeaveCriticalSection(&stream_desc->attributes.cs);
1926 return supported ? S_OK : MF_E_INVALIDMEDIATYPE;
1929 static HRESULT WINAPI mediatype_handler_GetMediaTypeCount(IMFMediaTypeHandler *iface, DWORD *count)
1931 struct stream_desc *stream_desc = impl_from_IMFMediaTypeHandler(iface);
1933 TRACE("%p, %p.\n", iface, count);
1935 *count = stream_desc->media_types_count;
1937 return S_OK;
1940 static HRESULT WINAPI mediatype_handler_GetMediaTypeByIndex(IMFMediaTypeHandler *iface, DWORD index,
1941 IMFMediaType **type)
1943 struct stream_desc *stream_desc = impl_from_IMFMediaTypeHandler(iface);
1945 TRACE("%p, %u, %p.\n", iface, index, type);
1947 if (index >= stream_desc->media_types_count)
1948 return MF_E_NO_MORE_TYPES;
1950 if (stream_desc->media_types[index])
1952 *type = stream_desc->media_types[index];
1953 IMFMediaType_AddRef(*type);
1956 return stream_desc->media_types[index] ? S_OK : E_FAIL;
1959 static HRESULT WINAPI mediatype_handler_SetCurrentMediaType(IMFMediaTypeHandler *iface, IMFMediaType *type)
1961 struct stream_desc *stream_desc = impl_from_IMFMediaTypeHandler(iface);
1963 TRACE("%p, %p.\n", iface, type);
1965 if (!type)
1966 return E_POINTER;
1968 EnterCriticalSection(&stream_desc->attributes.cs);
1969 if (stream_desc->current_type)
1970 IMFMediaType_Release(stream_desc->current_type);
1971 stream_desc->current_type = type;
1972 IMFMediaType_AddRef(stream_desc->current_type);
1973 LeaveCriticalSection(&stream_desc->attributes.cs);
1975 return S_OK;
1978 static HRESULT WINAPI mediatype_handler_GetCurrentMediaType(IMFMediaTypeHandler *iface, IMFMediaType **type)
1980 struct stream_desc *stream_desc = impl_from_IMFMediaTypeHandler(iface);
1981 HRESULT hr = S_OK;
1983 TRACE("%p, %p.\n", iface, type);
1985 EnterCriticalSection(&stream_desc->attributes.cs);
1986 if (stream_desc->current_type)
1988 *type = stream_desc->current_type;
1989 IMFMediaType_AddRef(*type);
1991 else
1992 hr = MF_E_NOT_INITIALIZED;
1993 LeaveCriticalSection(&stream_desc->attributes.cs);
1995 return hr;
1998 static HRESULT WINAPI mediatype_handler_GetMajorType(IMFMediaTypeHandler *iface, GUID *type)
2000 struct stream_desc *stream_desc = impl_from_IMFMediaTypeHandler(iface);
2001 HRESULT hr;
2003 TRACE("%p, %p.\n", iface, type);
2005 EnterCriticalSection(&stream_desc->attributes.cs);
2006 hr = IMFMediaType_GetGUID(stream_desc->current_type ? stream_desc->current_type :
2007 stream_desc->media_types[0], &MF_MT_MAJOR_TYPE, type);
2008 LeaveCriticalSection(&stream_desc->attributes.cs);
2010 return hr;
2013 static const IMFMediaTypeHandlerVtbl mediatypehandlervtbl =
2015 mediatype_handler_QueryInterface,
2016 mediatype_handler_AddRef,
2017 mediatype_handler_Release,
2018 mediatype_handler_IsMediaTypeSupported,
2019 mediatype_handler_GetMediaTypeCount,
2020 mediatype_handler_GetMediaTypeByIndex,
2021 mediatype_handler_SetCurrentMediaType,
2022 mediatype_handler_GetCurrentMediaType,
2023 mediatype_handler_GetMajorType,
2026 /***********************************************************************
2027 * MFCreateStreamDescriptor (mfplat.@)
2029 HRESULT WINAPI MFCreateStreamDescriptor(DWORD identifier, DWORD count,
2030 IMFMediaType **types, IMFStreamDescriptor **descriptor)
2032 struct stream_desc *object;
2033 unsigned int i;
2034 HRESULT hr;
2036 TRACE("%d, %d, %p, %p.\n", identifier, count, types, descriptor);
2038 if (!count)
2039 return E_INVALIDARG;
2041 object = heap_alloc_zero(sizeof(*object));
2042 if (!object)
2043 return E_OUTOFMEMORY;
2045 if (FAILED(hr = init_attributes_object(&object->attributes, 0)))
2047 heap_free(object);
2048 return hr;
2050 object->IMFStreamDescriptor_iface.lpVtbl = &streamdescriptorvtbl;
2051 object->IMFMediaTypeHandler_iface.lpVtbl = &mediatypehandlervtbl;
2052 object->identifier = identifier;
2053 object->media_types = heap_alloc(count * sizeof(*object->media_types));
2054 if (!object->media_types)
2056 IMFStreamDescriptor_Release(&object->IMFStreamDescriptor_iface);
2057 return E_OUTOFMEMORY;
2059 for (i = 0; i < count; ++i)
2061 object->media_types[i] = types[i];
2062 if (object->media_types[i])
2063 IMFMediaType_AddRef(object->media_types[i]);
2065 object->media_types_count = count;
2067 *descriptor = &object->IMFStreamDescriptor_iface;
2069 return S_OK;
2072 static HRESULT WINAPI presentation_descriptor_QueryInterface(IMFPresentationDescriptor *iface, REFIID riid, void **out)
2074 TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), out);
2076 if (IsEqualIID(riid, &IID_IMFPresentationDescriptor) ||
2077 IsEqualIID(riid, &IID_IMFAttributes) ||
2078 IsEqualIID(riid, &IID_IUnknown))
2080 *out = iface;
2081 IMFPresentationDescriptor_AddRef(iface);
2082 return S_OK;
2085 WARN("Unsupported %s.\n", debugstr_guid(riid));
2086 *out = NULL;
2087 return E_NOINTERFACE;
2090 static ULONG WINAPI presentation_descriptor_AddRef(IMFPresentationDescriptor *iface)
2092 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2093 ULONG refcount = InterlockedIncrement(&presentation_desc->attributes.ref);
2095 TRACE("%p, refcount %u.\n", iface, refcount);
2097 return refcount;
2100 static ULONG WINAPI presentation_descriptor_Release(IMFPresentationDescriptor *iface)
2102 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2103 ULONG refcount = InterlockedDecrement(&presentation_desc->attributes.ref);
2104 unsigned int i;
2106 TRACE("%p, refcount %u.\n", iface, refcount);
2108 if (!refcount)
2110 for (i = 0; i < presentation_desc->count; ++i)
2112 if (presentation_desc->descriptors[i].descriptor)
2113 IMFStreamDescriptor_Release(presentation_desc->descriptors[i].descriptor);
2115 clear_attributes_object(&presentation_desc->attributes);
2116 heap_free(presentation_desc->descriptors);
2117 heap_free(presentation_desc);
2120 return refcount;
2123 static HRESULT WINAPI presentation_descriptor_GetItem(IMFPresentationDescriptor *iface, REFGUID key,
2124 PROPVARIANT *value)
2126 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2128 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
2130 return attributes_GetItem(&presentation_desc->attributes, key, value);
2133 static HRESULT WINAPI presentation_descriptor_GetItemType(IMFPresentationDescriptor *iface, REFGUID key,
2134 MF_ATTRIBUTE_TYPE *type)
2136 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2138 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), type);
2140 return attributes_GetItemType(&presentation_desc->attributes, key, type);
2143 static HRESULT WINAPI presentation_descriptor_CompareItem(IMFPresentationDescriptor *iface, REFGUID key,
2144 REFPROPVARIANT value, BOOL *result)
2146 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2148 TRACE("%p, %s, %s, %p.\n", iface, debugstr_attr(key), debugstr_propvar(value), result);
2150 return attributes_CompareItem(&presentation_desc->attributes, key, value, result);
2153 static HRESULT WINAPI presentation_descriptor_Compare(IMFPresentationDescriptor *iface, IMFAttributes *attrs,
2154 MF_ATTRIBUTES_MATCH_TYPE type, BOOL *result)
2156 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2158 TRACE("%p, %p, %d, %p.\n", iface, attrs, type, result);
2160 return attributes_Compare(&presentation_desc->attributes, attrs, type, result);
2163 static HRESULT WINAPI presentation_descriptor_GetUINT32(IMFPresentationDescriptor *iface, REFGUID key, UINT32 *value)
2165 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2167 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
2169 return attributes_GetUINT32(&presentation_desc->attributes, key, value);
2172 static HRESULT WINAPI presentation_descriptor_GetUINT64(IMFPresentationDescriptor *iface, REFGUID key, UINT64 *value)
2174 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2176 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
2178 return attributes_GetUINT64(&presentation_desc->attributes, key, value);
2181 static HRESULT WINAPI presentation_descriptor_GetDouble(IMFPresentationDescriptor *iface, REFGUID key, double *value)
2183 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2185 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
2187 return attributes_GetDouble(&presentation_desc->attributes, key, value);
2190 static HRESULT WINAPI presentation_descriptor_GetGUID(IMFPresentationDescriptor *iface, REFGUID key, GUID *value)
2192 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2194 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
2196 return attributes_GetGUID(&presentation_desc->attributes, key, value);
2199 static HRESULT WINAPI presentation_descriptor_GetStringLength(IMFPresentationDescriptor *iface, REFGUID key,
2200 UINT32 *length)
2202 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2204 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), length);
2206 return attributes_GetStringLength(&presentation_desc->attributes, key, length);
2209 static HRESULT WINAPI presentation_descriptor_GetString(IMFPresentationDescriptor *iface, REFGUID key, WCHAR *value,
2210 UINT32 size, UINT32 *length)
2212 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2214 TRACE("%p, %s, %p, %u, %p.\n", iface, debugstr_attr(key), value, size, length);
2216 return attributes_GetString(&presentation_desc->attributes, key, value, size, length);
2219 static HRESULT WINAPI presentation_descriptor_GetAllocatedString(IMFPresentationDescriptor *iface, REFGUID key,
2220 WCHAR **value, UINT32 *length)
2222 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2224 TRACE("%p, %s, %p, %p.\n", iface, debugstr_attr(key), value, length);
2226 return attributes_GetAllocatedString(&presentation_desc->attributes, key, value, length);
2229 static HRESULT WINAPI presentation_descriptor_GetBlobSize(IMFPresentationDescriptor *iface, REFGUID key, UINT32 *size)
2231 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2233 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), size);
2235 return attributes_GetBlobSize(&presentation_desc->attributes, key, size);
2238 static HRESULT WINAPI presentation_descriptor_GetBlob(IMFPresentationDescriptor *iface, REFGUID key, UINT8 *buf,
2239 UINT32 bufsize, UINT32 *blobsize)
2241 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2243 TRACE("%p, %s, %p, %u, %p.\n", iface, debugstr_attr(key), buf, bufsize, blobsize);
2245 return attributes_GetBlob(&presentation_desc->attributes, key, buf, bufsize, blobsize);
2248 static HRESULT WINAPI presentation_descriptor_GetAllocatedBlob(IMFPresentationDescriptor *iface, REFGUID key,
2249 UINT8 **buf, UINT32 *size)
2251 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2253 TRACE("%p, %s, %p, %p.\n", iface, debugstr_attr(key), buf, size);
2255 return attributes_GetAllocatedBlob(&presentation_desc->attributes, key, buf, size);
2258 static HRESULT WINAPI presentation_descriptor_GetUnknown(IMFPresentationDescriptor *iface, REFGUID key,
2259 REFIID riid, void **out)
2261 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2263 TRACE("%p, %s, %s, %p.\n", iface, debugstr_attr(key), debugstr_guid(riid), out);
2265 return attributes_GetUnknown(&presentation_desc->attributes, key, riid, out);
2268 static HRESULT WINAPI presentation_descriptor_SetItem(IMFPresentationDescriptor *iface, REFGUID key,
2269 REFPROPVARIANT value)
2271 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2273 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_propvar(value));
2275 return attributes_SetItem(&presentation_desc->attributes, key, value);
2278 static HRESULT WINAPI presentation_descriptor_DeleteItem(IMFPresentationDescriptor *iface, REFGUID key)
2280 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2282 TRACE("%p, %s.\n", iface, debugstr_attr(key));
2284 return attributes_DeleteItem(&presentation_desc->attributes, key);
2287 static HRESULT WINAPI presentation_descriptor_DeleteAllItems(IMFPresentationDescriptor *iface)
2289 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2291 TRACE("%p.\n", iface);
2293 return attributes_DeleteAllItems(&presentation_desc->attributes);
2296 static HRESULT WINAPI presentation_descriptor_SetUINT32(IMFPresentationDescriptor *iface, REFGUID key, UINT32 value)
2298 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2300 TRACE("%p, %s, %u.\n", iface, debugstr_attr(key), value);
2302 return attributes_SetUINT32(&presentation_desc->attributes, key, value);
2305 static HRESULT WINAPI presentation_descriptor_SetUINT64(IMFPresentationDescriptor *iface, REFGUID key, UINT64 value)
2307 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2309 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), wine_dbgstr_longlong(value));
2311 return attributes_SetUINT64(&presentation_desc->attributes, key, value);
2314 static HRESULT WINAPI presentation_descriptor_SetDouble(IMFPresentationDescriptor *iface, REFGUID key, double value)
2316 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2318 TRACE("%p, %s, %f.\n", iface, debugstr_attr(key), value);
2320 return attributes_SetDouble(&presentation_desc->attributes, key, value);
2323 static HRESULT WINAPI presentation_descriptor_SetGUID(IMFPresentationDescriptor *iface, REFGUID key, REFGUID value)
2325 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2327 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_mf_guid(value));
2329 return attributes_SetGUID(&presentation_desc->attributes, key, value);
2332 static HRESULT WINAPI presentation_descriptor_SetString(IMFPresentationDescriptor *iface, REFGUID key,
2333 const WCHAR *value)
2335 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2337 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_w(value));
2339 return attributes_SetString(&presentation_desc->attributes, key, value);
2342 static HRESULT WINAPI presentation_descriptor_SetBlob(IMFPresentationDescriptor *iface, REFGUID key, const UINT8 *buf,
2343 UINT32 size)
2345 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2347 TRACE("%p, %s, %p, %u.\n", iface, debugstr_attr(key), buf, size);
2349 return attributes_SetBlob(&presentation_desc->attributes, key, buf, size);
2352 static HRESULT WINAPI presentation_descriptor_SetUnknown(IMFPresentationDescriptor *iface, REFGUID key,
2353 IUnknown *unknown)
2355 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2357 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), unknown);
2359 return attributes_SetUnknown(&presentation_desc->attributes, key, unknown);
2362 static HRESULT WINAPI presentation_descriptor_LockStore(IMFPresentationDescriptor *iface)
2364 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2366 TRACE("%p.\n", iface);
2368 return attributes_LockStore(&presentation_desc->attributes);
2371 static HRESULT WINAPI presentation_descriptor_UnlockStore(IMFPresentationDescriptor *iface)
2373 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2375 TRACE("%p.\n", iface);
2377 return attributes_UnlockStore(&presentation_desc->attributes);
2380 static HRESULT WINAPI presentation_descriptor_GetCount(IMFPresentationDescriptor *iface, UINT32 *count)
2382 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2384 TRACE("%p, %p.\n", iface, count);
2386 return attributes_GetCount(&presentation_desc->attributes, count);
2389 static HRESULT WINAPI presentation_descriptor_GetItemByIndex(IMFPresentationDescriptor *iface, UINT32 index, GUID *key,
2390 PROPVARIANT *value)
2392 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2394 TRACE("%p, %u, %p, %p.\n", iface, index, key, value);
2396 return attributes_GetItemByIndex(&presentation_desc->attributes, index, key, value);
2399 static HRESULT WINAPI presentation_descriptor_CopyAllItems(IMFPresentationDescriptor *iface, IMFAttributes *dest)
2401 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2403 TRACE("%p, %p.\n", iface, dest);
2405 return attributes_CopyAllItems(&presentation_desc->attributes, dest);
2408 static HRESULT WINAPI presentation_descriptor_GetStreamDescriptorCount(IMFPresentationDescriptor *iface, DWORD *count)
2410 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2412 TRACE("%p, %p.\n", iface, count);
2414 *count = presentation_desc->count;
2416 return S_OK;
2419 static HRESULT WINAPI presentation_descriptor_GetStreamDescriptorByIndex(IMFPresentationDescriptor *iface, DWORD index,
2420 BOOL *selected, IMFStreamDescriptor **descriptor)
2422 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2424 TRACE("%p, %u, %p, %p.\n", iface, index, selected, descriptor);
2426 if (index >= presentation_desc->count)
2427 return E_INVALIDARG;
2429 EnterCriticalSection(&presentation_desc->attributes.cs);
2430 *selected = presentation_desc->descriptors[index].selected;
2431 LeaveCriticalSection(&presentation_desc->attributes.cs);
2433 *descriptor = presentation_desc->descriptors[index].descriptor;
2434 IMFStreamDescriptor_AddRef(*descriptor);
2436 return S_OK;
2439 static HRESULT WINAPI presentation_descriptor_SelectStream(IMFPresentationDescriptor *iface, DWORD index)
2441 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2443 TRACE("%p, %u.\n", iface, index);
2445 if (index >= presentation_desc->count)
2446 return E_INVALIDARG;
2448 EnterCriticalSection(&presentation_desc->attributes.cs);
2449 presentation_desc->descriptors[index].selected = TRUE;
2450 LeaveCriticalSection(&presentation_desc->attributes.cs);
2452 return S_OK;
2455 static HRESULT WINAPI presentation_descriptor_DeselectStream(IMFPresentationDescriptor *iface, DWORD index)
2457 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2459 TRACE("%p, %u.\n", iface, index);
2461 if (index >= presentation_desc->count)
2462 return E_INVALIDARG;
2464 EnterCriticalSection(&presentation_desc->attributes.cs);
2465 presentation_desc->descriptors[index].selected = FALSE;
2466 LeaveCriticalSection(&presentation_desc->attributes.cs);
2468 return S_OK;
2471 static HRESULT WINAPI presentation_descriptor_Clone(IMFPresentationDescriptor *iface,
2472 IMFPresentationDescriptor **descriptor)
2474 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2475 struct presentation_desc *object;
2476 unsigned int i;
2478 TRACE("%p, %p.\n", iface, descriptor);
2480 object = heap_alloc_zero(sizeof(*object));
2481 if (!object)
2482 return E_OUTOFMEMORY;
2484 presentation_descriptor_init(object, presentation_desc->count);
2486 EnterCriticalSection(&presentation_desc->attributes.cs);
2488 for (i = 0; i < presentation_desc->count; ++i)
2490 object->descriptors[i] = presentation_desc->descriptors[i];
2491 IMFStreamDescriptor_AddRef(object->descriptors[i].descriptor);
2494 attributes_CopyAllItems(&presentation_desc->attributes, (IMFAttributes *)&object->IMFPresentationDescriptor_iface);
2496 LeaveCriticalSection(&presentation_desc->attributes.cs);
2498 *descriptor = &object->IMFPresentationDescriptor_iface;
2500 return S_OK;
2503 static const IMFPresentationDescriptorVtbl presentationdescriptorvtbl =
2505 presentation_descriptor_QueryInterface,
2506 presentation_descriptor_AddRef,
2507 presentation_descriptor_Release,
2508 presentation_descriptor_GetItem,
2509 presentation_descriptor_GetItemType,
2510 presentation_descriptor_CompareItem,
2511 presentation_descriptor_Compare,
2512 presentation_descriptor_GetUINT32,
2513 presentation_descriptor_GetUINT64,
2514 presentation_descriptor_GetDouble,
2515 presentation_descriptor_GetGUID,
2516 presentation_descriptor_GetStringLength,
2517 presentation_descriptor_GetString,
2518 presentation_descriptor_GetAllocatedString,
2519 presentation_descriptor_GetBlobSize,
2520 presentation_descriptor_GetBlob,
2521 presentation_descriptor_GetAllocatedBlob,
2522 presentation_descriptor_GetUnknown,
2523 presentation_descriptor_SetItem,
2524 presentation_descriptor_DeleteItem,
2525 presentation_descriptor_DeleteAllItems,
2526 presentation_descriptor_SetUINT32,
2527 presentation_descriptor_SetUINT64,
2528 presentation_descriptor_SetDouble,
2529 presentation_descriptor_SetGUID,
2530 presentation_descriptor_SetString,
2531 presentation_descriptor_SetBlob,
2532 presentation_descriptor_SetUnknown,
2533 presentation_descriptor_LockStore,
2534 presentation_descriptor_UnlockStore,
2535 presentation_descriptor_GetCount,
2536 presentation_descriptor_GetItemByIndex,
2537 presentation_descriptor_CopyAllItems,
2538 presentation_descriptor_GetStreamDescriptorCount,
2539 presentation_descriptor_GetStreamDescriptorByIndex,
2540 presentation_descriptor_SelectStream,
2541 presentation_descriptor_DeselectStream,
2542 presentation_descriptor_Clone,
2545 static HRESULT presentation_descriptor_init(struct presentation_desc *object, DWORD count)
2547 HRESULT hr;
2549 if (FAILED(hr = init_attributes_object(&object->attributes, 0)))
2550 return hr;
2551 object->IMFPresentationDescriptor_iface.lpVtbl = &presentationdescriptorvtbl;
2552 object->descriptors = heap_alloc_zero(count * sizeof(*object->descriptors));
2553 if (!object->descriptors)
2555 IMFPresentationDescriptor_Release(&object->IMFPresentationDescriptor_iface);
2556 return E_OUTOFMEMORY;
2558 object->count = count;
2560 return S_OK;
2563 /***********************************************************************
2564 * MFCreatePresentationDescriptor (mfplat.@)
2566 HRESULT WINAPI MFCreatePresentationDescriptor(DWORD count, IMFStreamDescriptor **descriptors,
2567 IMFPresentationDescriptor **out)
2569 struct presentation_desc *object;
2570 unsigned int i;
2571 HRESULT hr;
2573 TRACE("%u, %p, %p.\n", count, descriptors, out);
2575 if (!count)
2576 return E_INVALIDARG;
2578 for (i = 0; i < count; ++i)
2580 if (!descriptors[i])
2581 return E_INVALIDARG;
2584 object = heap_alloc_zero(sizeof(*object));
2585 if (!object)
2586 return E_OUTOFMEMORY;
2588 if (FAILED(hr = presentation_descriptor_init(object, count)))
2590 heap_free(object);
2591 return hr;
2594 for (i = 0; i < count; ++i)
2596 object->descriptors[i].descriptor = descriptors[i];
2597 IMFStreamDescriptor_AddRef(object->descriptors[i].descriptor);
2600 *out = &object->IMFPresentationDescriptor_iface;
2602 return S_OK;
2605 struct uncompressed_video_format
2607 const GUID *subtype;
2608 unsigned char bytes_per_pixel;
2609 unsigned char alignment;
2610 unsigned char bottom_up;
2611 unsigned char yuv;
2614 static int __cdecl uncompressed_video_format_compare(const void *a, const void *b)
2616 const GUID *guid = a;
2617 const struct uncompressed_video_format *format = b;
2618 return memcmp(guid, format->subtype, sizeof(*guid));
2621 static const struct uncompressed_video_format video_formats[] =
2623 { &MFVideoFormat_RGB24, 4, 3, 1, 0 },
2624 { &MFVideoFormat_ARGB32, 4, 3, 1, 0 },
2625 { &MFVideoFormat_RGB32, 4, 3, 1, 0 },
2626 { &MFVideoFormat_RGB565, 2, 3, 1, 0 },
2627 { &MFVideoFormat_RGB555, 2, 3, 1, 0 },
2628 { &MFVideoFormat_A2R10G10B10, 4, 3, 1, 0 },
2629 { &MFVideoFormat_RGB8, 1, 3, 1, 0 },
2630 { &MFVideoFormat_L8, 1, 3, 1, 0 },
2631 { &MFVideoFormat_AYUV, 4, 3, 0, 1 },
2632 { &MFVideoFormat_I420, 1, 0, 0, 1 },
2633 { &MFVideoFormat_IMC1, 2, 3, 0, 1 },
2634 { &MFVideoFormat_IMC2, 1, 0, 0, 1 },
2635 { &MFVideoFormat_IMC3, 2, 3, 0, 1 },
2636 { &MFVideoFormat_IMC4, 1, 0, 0, 1 },
2637 { &MFVideoFormat_NV12, 1, 0, 0, 1 },
2638 { &MFVideoFormat_D16, 2, 3, 0, 0 },
2639 { &MFVideoFormat_L16, 2, 3, 0, 0 },
2640 { &MFVideoFormat_UYVY, 2, 0, 0, 1 },
2641 { &MFVideoFormat_YUY2, 2, 0, 0, 1 },
2642 { &MFVideoFormat_YV12, 1, 0, 0, 1 },
2643 { &MFVideoFormat_A16B16G16R16F, 8, 3, 1, 0 },
2646 static struct uncompressed_video_format *mf_get_video_format(const GUID *subtype)
2648 return bsearch(subtype, video_formats, ARRAY_SIZE(video_formats), sizeof(*video_formats),
2649 uncompressed_video_format_compare);
2652 static unsigned int mf_get_stride_for_format(const struct uncompressed_video_format *format, unsigned int width)
2654 return (width * format->bytes_per_pixel + format->alignment) & ~format->alignment;
2657 unsigned int mf_format_get_stride(const GUID *subtype, unsigned int width, BOOL *is_yuv)
2659 struct uncompressed_video_format *format = mf_get_video_format(subtype);
2661 if (format)
2663 *is_yuv = format->yuv;
2664 return mf_get_stride_for_format(format, width);
2667 return 0;
2670 /***********************************************************************
2671 * MFGetStrideForBitmapInfoHeader (mfplat.@)
2673 HRESULT WINAPI MFGetStrideForBitmapInfoHeader(DWORD fourcc, DWORD width, LONG *stride)
2675 struct uncompressed_video_format *format;
2676 GUID subtype;
2678 TRACE("%s, %u, %p.\n", debugstr_fourcc(fourcc), width, stride);
2680 memcpy(&subtype, &MFVideoFormat_Base, sizeof(subtype));
2681 subtype.Data1 = fourcc;
2683 if (!(format = mf_get_video_format(&subtype)))
2685 *stride = 0;
2686 return MF_E_INVALIDMEDIATYPE;
2689 *stride = mf_get_stride_for_format(format, width);
2690 if (format->bottom_up)
2691 *stride *= -1;
2693 return S_OK;
2696 /***********************************************************************
2697 * MFCalculateImageSize (mfplat.@)
2699 HRESULT WINAPI MFCalculateImageSize(REFGUID subtype, UINT32 width, UINT32 height, UINT32 *size)
2701 struct uncompressed_video_format *format;
2702 unsigned int stride;
2704 TRACE("%s, %u, %u, %p.\n", debugstr_mf_guid(subtype), width, height, size);
2706 if (!(format = mf_get_video_format(subtype)))
2708 *size = 0;
2709 return E_INVALIDARG;
2712 switch (subtype->Data1)
2714 case MAKEFOURCC('I','M','C','2'):
2715 case MAKEFOURCC('I','M','C','4'):
2716 case MAKEFOURCC('N','V','1','2'):
2717 case MAKEFOURCC('Y','V','1','2'):
2718 case MAKEFOURCC('I','4','2','0'):
2719 /* 2 x 2 block, interleaving UV for half the height */
2720 *size = ((width + 1) & ~1) * height * 3 / 2;
2721 break;
2722 case D3DFMT_L8:
2723 case D3DFMT_L16:
2724 case D3DFMT_D16:
2725 *size = width * format->bytes_per_pixel * height;
2726 break;
2727 default:
2728 stride = mf_get_stride_for_format(format, width);
2729 *size = stride * height;
2732 return S_OK;
2735 /***********************************************************************
2736 * MFGetPlaneSize (mfplat.@)
2738 HRESULT WINAPI MFGetPlaneSize(DWORD fourcc, DWORD width, DWORD height, DWORD *size)
2740 struct uncompressed_video_format *format;
2741 unsigned int stride;
2742 GUID subtype;
2744 TRACE("%s, %u, %u, %p.\n", debugstr_fourcc(fourcc), width, height, size);
2746 memcpy(&subtype, &MFVideoFormat_Base, sizeof(subtype));
2747 subtype.Data1 = fourcc;
2749 if (!(format = mf_get_video_format(&subtype)))
2750 return MF_E_INVALIDMEDIATYPE;
2752 stride = mf_get_stride_for_format(format, width);
2754 switch (fourcc)
2756 case MAKEFOURCC('I','M','C','2'):
2757 case MAKEFOURCC('I','M','C','4'):
2758 case MAKEFOURCC('N','V','1','2'):
2759 case MAKEFOURCC('Y','V','1','2'):
2760 case MAKEFOURCC('I','4','2','0'):
2761 *size = stride * height * 3 / 2;
2762 break;
2763 default:
2764 *size = stride * height;
2767 return S_OK;
2770 /***********************************************************************
2771 * MFCompareFullToPartialMediaType (mfplat.@)
2773 BOOL WINAPI MFCompareFullToPartialMediaType(IMFMediaType *full_type, IMFMediaType *partial_type)
2775 BOOL result;
2776 GUID major;
2778 TRACE("%p, %p.\n", full_type, partial_type);
2780 if (FAILED(IMFMediaType_GetMajorType(partial_type, &major)))
2781 return FALSE;
2783 if (FAILED(IMFMediaType_Compare(partial_type, (IMFAttributes *)full_type, MF_ATTRIBUTES_MATCH_OUR_ITEMS, &result)))
2784 return FALSE;
2786 return result;
2789 /***********************************************************************
2790 * MFWrapMediaType (mfplat.@)
2792 HRESULT WINAPI MFWrapMediaType(IMFMediaType *original, REFGUID major, REFGUID subtype, IMFMediaType **ret)
2794 IMFMediaType *mediatype;
2795 UINT8 *buffer;
2796 UINT32 size;
2797 HRESULT hr;
2799 TRACE("%p, %s, %s, %p.\n", original, debugstr_guid(major), debugstr_guid(subtype), ret);
2801 if (FAILED(hr = MFGetAttributesAsBlobSize((IMFAttributes *)original, &size)))
2802 return hr;
2804 if (!(buffer = heap_alloc(size)))
2805 return E_OUTOFMEMORY;
2807 if (FAILED(hr = MFGetAttributesAsBlob((IMFAttributes *)original, buffer, size)))
2808 goto failed;
2810 if (FAILED(hr = MFCreateMediaType(&mediatype)))
2811 goto failed;
2813 if (FAILED(hr = IMFMediaType_SetGUID(mediatype, &MF_MT_MAJOR_TYPE, major)))
2814 goto failed;
2816 if (FAILED(hr = IMFMediaType_SetGUID(mediatype, &MF_MT_SUBTYPE, subtype)))
2817 goto failed;
2819 if (FAILED(hr = IMFMediaType_SetBlob(mediatype, &MF_MT_WRAPPED_TYPE, buffer, size)))
2820 goto failed;
2822 *ret = mediatype;
2824 failed:
2825 heap_free(buffer);
2827 return hr;
2830 /***********************************************************************
2831 * MFUnwrapMediaType (mfplat.@)
2833 HRESULT WINAPI MFUnwrapMediaType(IMFMediaType *wrapper, IMFMediaType **ret)
2835 IMFMediaType *mediatype;
2836 UINT8 *buffer;
2837 UINT32 size;
2838 HRESULT hr;
2840 TRACE("%p, %p.\n", wrapper, ret);
2842 if (FAILED(hr = MFCreateMediaType(&mediatype)))
2843 return hr;
2845 if (FAILED(hr = IMFMediaType_GetAllocatedBlob(wrapper, &MF_MT_WRAPPED_TYPE, &buffer, &size)))
2847 IMFMediaType_Release(mediatype);
2848 return hr;
2851 hr = MFInitAttributesFromBlob((IMFAttributes *)mediatype, buffer, size);
2852 CoTaskMemFree(buffer);
2853 if (FAILED(hr))
2854 return hr;
2856 *ret = mediatype;
2858 return S_OK;
2861 /***********************************************************************
2862 * MFCreateWaveFormatExFromMFMediaType (mfplat.@)
2864 HRESULT WINAPI MFCreateWaveFormatExFromMFMediaType(IMFMediaType *mediatype, WAVEFORMATEX **ret_format,
2865 UINT32 *size, UINT32 flags)
2867 WAVEFORMATEXTENSIBLE *format_ext = NULL;
2868 WAVEFORMATEX *format;
2869 GUID major, subtype;
2870 UINT32 value;
2871 HRESULT hr;
2873 TRACE("%p, %p, %p, %#x.\n", mediatype, ret_format, size, flags);
2875 if (FAILED(hr = IMFMediaType_GetGUID(mediatype, &MF_MT_MAJOR_TYPE, &major)))
2876 return hr;
2878 if (FAILED(hr = IMFMediaType_GetGUID(mediatype, &MF_MT_SUBTYPE, &subtype)))
2879 return hr;
2881 if (!IsEqualGUID(&major, &MFMediaType_Audio))
2882 return E_INVALIDARG;
2884 if (!IsEqualGUID(&subtype, &MFAudioFormat_PCM))
2886 FIXME("Unsupported audio format %s.\n", debugstr_guid(&subtype));
2887 return E_NOTIMPL;
2890 /* FIXME: probably WAVE_FORMAT_MPEG/WAVE_FORMAT_MPEGLAYER3 should be handled separately. */
2891 if (flags == MFWaveFormatExConvertFlag_ForceExtensible)
2893 format_ext = CoTaskMemAlloc(sizeof(*format_ext));
2894 *size = sizeof(*format_ext);
2895 format = (WAVEFORMATEX *)format_ext;
2897 else
2899 format = CoTaskMemAlloc(sizeof(*format));
2900 *size = sizeof(*format);
2903 if (!format)
2904 return E_OUTOFMEMORY;
2906 memset(format, 0, *size);
2908 format->wFormatTag = format_ext ? WAVE_FORMAT_EXTENSIBLE : WAVE_FORMAT_PCM;
2910 if (SUCCEEDED(IMFMediaType_GetUINT32(mediatype, &MF_MT_AUDIO_NUM_CHANNELS, &value)))
2911 format->nChannels = value;
2912 IMFMediaType_GetUINT32(mediatype, &MF_MT_AUDIO_SAMPLES_PER_SECOND, &format->nSamplesPerSec);
2913 IMFMediaType_GetUINT32(mediatype, &MF_MT_AUDIO_AVG_BYTES_PER_SECOND, &format->nAvgBytesPerSec);
2914 if (SUCCEEDED(IMFMediaType_GetUINT32(mediatype, &MF_MT_AUDIO_BLOCK_ALIGNMENT, &value)))
2915 format->nBlockAlign = value;
2916 if (SUCCEEDED(IMFMediaType_GetUINT32(mediatype, &MF_MT_AUDIO_BITS_PER_SAMPLE, &value)))
2917 format->wBitsPerSample = value;
2918 if (format_ext)
2920 format->cbSize = sizeof(*format_ext) - sizeof(*format);
2922 if (SUCCEEDED(IMFMediaType_GetUINT32(mediatype, &MF_MT_AUDIO_VALID_BITS_PER_SAMPLE, &value)))
2923 format_ext->Samples.wSamplesPerBlock = value;
2925 IMFMediaType_GetUINT32(mediatype, &MF_MT_AUDIO_CHANNEL_MASK, &format_ext->dwChannelMask);
2926 memcpy(&format_ext->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM, sizeof(format_ext->SubFormat));
2929 *ret_format = format;
2931 return S_OK;
2934 static void mediatype_set_uint32(IMFMediaType *mediatype, const GUID *attr, unsigned int value, HRESULT *hr)
2936 if (SUCCEEDED(*hr))
2937 *hr = IMFMediaType_SetUINT32(mediatype, attr, value);
2940 static void mediatype_set_guid(IMFMediaType *mediatype, const GUID *attr, const GUID *value, HRESULT *hr)
2942 if (SUCCEEDED(*hr))
2943 *hr = IMFMediaType_SetGUID(mediatype, attr, value);
2946 static void mediatype_set_blob(IMFMediaType *mediatype, const GUID *attr, const UINT8 *data,
2947 unsigned int size, HRESULT *hr)
2949 if (SUCCEEDED(*hr))
2950 *hr = IMFMediaType_SetBlob(mediatype, attr, data, size);
2953 /***********************************************************************
2954 * MFInitMediaTypeFromWaveFormatEx (mfplat.@)
2956 HRESULT WINAPI MFInitMediaTypeFromWaveFormatEx(IMFMediaType *mediatype, const WAVEFORMATEX *format, UINT32 size)
2958 const WAVEFORMATEXTENSIBLE *wfex = (const WAVEFORMATEXTENSIBLE *)format;
2959 GUID subtype;
2960 HRESULT hr;
2962 TRACE("%p, %p, %u.\n", mediatype, format, size);
2964 if (!mediatype || !format)
2965 return E_POINTER;
2967 if (format->cbSize + sizeof(*format) > size)
2968 return E_INVALIDARG;
2970 hr = IMFMediaType_DeleteAllItems(mediatype);
2972 mediatype_set_guid(mediatype, &MF_MT_MAJOR_TYPE, &MFMediaType_Audio, &hr);
2974 if (format->wFormatTag == WAVE_FORMAT_EXTENSIBLE)
2976 memcpy(&subtype, &wfex->SubFormat, sizeof(subtype));
2978 if (wfex->dwChannelMask)
2979 mediatype_set_uint32(mediatype, &MF_MT_AUDIO_CHANNEL_MASK, wfex->dwChannelMask, &hr);
2981 if (format->wBitsPerSample && wfex->Samples.wValidBitsPerSample)
2982 mediatype_set_uint32(mediatype, &MF_MT_AUDIO_VALID_BITS_PER_SAMPLE, wfex->Samples.wValidBitsPerSample, &hr);
2984 else
2986 memcpy(&subtype, &MFAudioFormat_Base, sizeof(subtype));
2987 subtype.Data1 = format->wFormatTag;
2989 mediatype_set_uint32(mediatype, &MF_MT_AUDIO_PREFER_WAVEFORMATEX, 1, &hr);
2991 mediatype_set_guid(mediatype, &MF_MT_SUBTYPE, &subtype, &hr);
2993 if (format->nChannels)
2994 mediatype_set_uint32(mediatype, &MF_MT_AUDIO_NUM_CHANNELS, format->nChannels, &hr);
2996 if (format->nSamplesPerSec)
2997 mediatype_set_uint32(mediatype, &MF_MT_AUDIO_SAMPLES_PER_SECOND, format->nSamplesPerSec, &hr);
2999 if (format->nAvgBytesPerSec)
3000 mediatype_set_uint32(mediatype, &MF_MT_AUDIO_AVG_BYTES_PER_SECOND, format->nAvgBytesPerSec, &hr);
3002 if (format->nBlockAlign)
3003 mediatype_set_uint32(mediatype, &MF_MT_AUDIO_BLOCK_ALIGNMENT, format->nBlockAlign, &hr);
3005 if (format->wBitsPerSample)
3006 mediatype_set_uint32(mediatype, &MF_MT_AUDIO_BITS_PER_SAMPLE, format->wBitsPerSample, &hr);
3008 if (IsEqualGUID(&subtype, &MFAudioFormat_PCM) ||
3009 IsEqualGUID(&subtype, &MFAudioFormat_Float))
3011 mediatype_set_uint32(mediatype, &MF_MT_ALL_SAMPLES_INDEPENDENT, 1, &hr);
3014 if (format->cbSize && format->wFormatTag != WAVE_FORMAT_EXTENSIBLE)
3015 mediatype_set_blob(mediatype, &MF_MT_USER_DATA, (const UINT8 *)(format + 1), format->cbSize, &hr);
3017 return hr;
3020 /***********************************************************************
3021 * MFCreateVideoMediaTypeFromSubtype (mfplat.@)
3023 HRESULT WINAPI MFCreateVideoMediaTypeFromSubtype(const GUID *subtype, IMFVideoMediaType **media_type)
3025 struct media_type *object;
3026 HRESULT hr;
3028 TRACE("%s, %p.\n", debugstr_guid(subtype), media_type);
3030 if (!media_type)
3031 return E_INVALIDARG;
3033 if (FAILED(hr = create_media_type(&object)))
3034 return hr;
3036 IMFMediaType_SetGUID(&object->IMFMediaType_iface, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
3037 IMFMediaType_SetGUID(&object->IMFMediaType_iface, &MF_MT_SUBTYPE, subtype);
3039 *media_type = &object->IMFVideoMediaType_iface;
3041 return S_OK;
3044 static void media_type_get_ratio(UINT64 value, UINT32 *numerator, UINT32 *denominator)
3046 *numerator = value >> 32;
3047 *denominator = value;
3050 /***********************************************************************
3051 * MFCreateMFVideoFormatFromMFMediaType (mfplat.@)
3053 HRESULT WINAPI MFCreateMFVideoFormatFromMFMediaType(IMFMediaType *media_type, MFVIDEOFORMAT **video_format, UINT32 *size)
3055 UINT32 flags, palette_size = 0, avgrate;
3056 MFVIDEOFORMAT *format;
3057 UINT64 value;
3058 INT32 stride;
3059 GUID guid;
3061 TRACE("%p, %p, %p.\n", media_type, video_format, size);
3063 *size = sizeof(*format);
3065 if (SUCCEEDED(IMFMediaType_GetBlobSize(media_type, &MF_MT_PALETTE, &palette_size)))
3066 *size += palette_size;
3068 if (!(format = CoTaskMemAlloc(*size)))
3069 return E_OUTOFMEMORY;
3071 *video_format = format;
3073 memset(format, 0, sizeof(*format));
3074 format->dwSize = *size;
3076 if (SUCCEEDED(IMFMediaType_GetGUID(media_type, &MF_MT_SUBTYPE, &guid)))
3078 memcpy(&format->guidFormat, &guid, sizeof(guid));
3079 format->surfaceInfo.Format = guid.Data1;
3082 if (SUCCEEDED(IMFMediaType_GetUINT64(media_type, &MF_MT_FRAME_SIZE, &value)))
3083 media_type_get_ratio(value, &format->videoInfo.dwWidth, &format->videoInfo.dwHeight);
3085 if (SUCCEEDED(IMFMediaType_GetUINT64(media_type, &MF_MT_PIXEL_ASPECT_RATIO, &value)))
3087 media_type_get_ratio(value, &format->videoInfo.PixelAspectRatio.Numerator,
3088 &format->videoInfo.PixelAspectRatio.Denominator);
3091 IMFMediaType_GetUINT32(media_type, &MF_MT_VIDEO_CHROMA_SITING, &format->videoInfo.SourceChromaSubsampling);
3092 IMFMediaType_GetUINT32(media_type, &MF_MT_INTERLACE_MODE, &format->videoInfo.InterlaceMode);
3093 IMFMediaType_GetUINT32(media_type, &MF_MT_TRANSFER_FUNCTION, &format->videoInfo.TransferFunction);
3094 IMFMediaType_GetUINT32(media_type, &MF_MT_VIDEO_PRIMARIES, &format->videoInfo.ColorPrimaries);
3095 IMFMediaType_GetUINT32(media_type, &MF_MT_YUV_MATRIX, &format->videoInfo.TransferMatrix);
3096 IMFMediaType_GetUINT32(media_type, &MF_MT_VIDEO_LIGHTING, &format->videoInfo.SourceLighting);
3098 if (SUCCEEDED(IMFMediaType_GetUINT64(media_type, &MF_MT_FRAME_RATE, &value)))
3100 media_type_get_ratio(value, &format->videoInfo.FramesPerSecond.Numerator,
3101 &format->videoInfo.FramesPerSecond.Denominator);
3104 IMFMediaType_GetUINT32(media_type, &MF_MT_VIDEO_NOMINAL_RANGE, &format->videoInfo.NominalRange);
3105 IMFMediaType_GetBlob(media_type, &MF_MT_GEOMETRIC_APERTURE, (UINT8 *)&format->videoInfo.GeometricAperture,
3106 sizeof(format->videoInfo.GeometricAperture), NULL);
3107 IMFMediaType_GetBlob(media_type, &MF_MT_MINIMUM_DISPLAY_APERTURE, (UINT8 *)&format->videoInfo.MinimumDisplayAperture,
3108 sizeof(format->videoInfo.MinimumDisplayAperture), NULL);
3110 /* Video flags. */
3111 if (SUCCEEDED(IMFMediaType_GetUINT32(media_type, &MF_MT_PAD_CONTROL_FLAGS, &flags)))
3112 format->videoInfo.VideoFlags |= flags;
3113 if (SUCCEEDED(IMFMediaType_GetUINT32(media_type, &MF_MT_SOURCE_CONTENT_HINT, &flags)))
3114 format->videoInfo.VideoFlags |= flags;
3115 if (SUCCEEDED(IMFMediaType_GetUINT32(media_type, &MF_MT_DRM_FLAGS, &flags)))
3116 format->videoInfo.VideoFlags |= flags;
3117 if (SUCCEEDED(IMFMediaType_GetUINT32(media_type, &MF_MT_PAN_SCAN_ENABLED, &flags)) && !!flags)
3119 format->videoInfo.VideoFlags |= MFVideoFlag_PanScanEnabled;
3120 IMFMediaType_GetBlob(media_type, &MF_MT_PAN_SCAN_APERTURE, (UINT8 *)&format->videoInfo.PanScanAperture,
3121 sizeof(format->videoInfo.PanScanAperture), NULL);
3123 if (SUCCEEDED(IMFMediaType_GetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, (UINT32 *)&stride)) && stride < 0)
3124 format->videoInfo.VideoFlags |= MFVideoFlag_BottomUpLinearRep;
3126 if (SUCCEEDED(IMFMediaType_GetUINT32(media_type, &MF_MT_AVG_BITRATE, &avgrate)))
3127 format->compressedInfo.AvgBitrate = avgrate;
3128 if (SUCCEEDED(IMFMediaType_GetUINT32(media_type, &MF_MT_AVG_BIT_ERROR_RATE, &avgrate)))
3129 format->compressedInfo.AvgBitErrorRate = avgrate;
3130 IMFMediaType_GetUINT32(media_type, &MF_MT_MAX_KEYFRAME_SPACING, &format->compressedInfo.MaxKeyFrameSpacing);
3132 /* Palette. */
3133 if (palette_size)
3135 format->surfaceInfo.PaletteEntries = palette_size / sizeof(*format->surfaceInfo.Palette);
3136 IMFMediaType_GetBlob(media_type, &MF_MT_PALETTE, (UINT8 *)format->surfaceInfo.Palette, palette_size, NULL);
3139 return S_OK;
3142 /***********************************************************************
3143 * MFConvertColorInfoToDXVA (mfplat.@)
3145 HRESULT WINAPI MFConvertColorInfoToDXVA(DWORD *dxva_info, const MFVIDEOFORMAT *format)
3147 struct
3149 UINT SampleFormat : 8;
3150 UINT VideoChromaSubsampling : 4;
3151 UINT NominalRange : 3;
3152 UINT VideoTransferMatrix : 3;
3153 UINT VideoLighting : 4;
3154 UINT VideoPrimaries : 5;
3155 UINT VideoTransferFunction : 5;
3156 } *dxva_format = (void *)dxva_info;
3158 TRACE("%p, %p.\n", dxva_info, format);
3160 if (format->videoInfo.InterlaceMode == MFVideoInterlace_MixedInterlaceOrProgressive)
3161 dxva_format->SampleFormat = DXVA2_SampleFieldInterleavedEvenFirst;
3162 else
3163 dxva_format->SampleFormat = format->videoInfo.InterlaceMode;
3165 dxva_format->VideoChromaSubsampling = format->videoInfo.SourceChromaSubsampling;
3166 dxva_format->NominalRange = format->videoInfo.NominalRange;
3167 dxva_format->VideoTransferMatrix = format->videoInfo.TransferMatrix;
3168 dxva_format->VideoLighting = format->videoInfo.SourceLighting;
3169 dxva_format->VideoPrimaries = format->videoInfo.ColorPrimaries;
3170 dxva_format->VideoTransferFunction = format->videoInfo.TransferFunction;
3172 return S_OK;
3175 struct frame_rate
3177 UINT64 rate;
3178 UINT64 frame_time;
3181 static int __cdecl frame_rate_compare(const void *a, const void *b)
3183 const UINT64 *rate = a;
3184 const struct frame_rate *known_rate = b;
3185 return *rate == known_rate->rate ? 0 : ( *rate < known_rate->rate ? 1 : -1 );
3188 /***********************************************************************
3189 * MFFrameRateToAverageTimePerFrame (mfplat.@)
3191 HRESULT WINAPI MFFrameRateToAverageTimePerFrame(UINT32 numerator, UINT32 denominator, UINT64 *avgframetime)
3193 static const struct frame_rate known_rates[] =
3195 #define KNOWN_RATE(n,d,ft) { ((UINT64)n << 32) | d, ft }
3196 KNOWN_RATE(60000, 1001, 166833),
3197 KNOWN_RATE(30000, 1001, 333667),
3198 KNOWN_RATE(24000, 1001, 417188),
3199 KNOWN_RATE(60, 1, 166667),
3200 KNOWN_RATE(50, 1, 200000),
3201 KNOWN_RATE(30, 1, 333333),
3202 KNOWN_RATE(25, 1, 400000),
3203 KNOWN_RATE(24, 1, 416667),
3204 #undef KNOWN_RATE
3206 UINT64 rate = ((UINT64)numerator << 32) | denominator;
3207 const struct frame_rate *entry;
3209 TRACE("%u, %u, %p.\n", numerator, denominator, avgframetime);
3211 if ((entry = bsearch(&rate, known_rates, ARRAY_SIZE(known_rates), sizeof(*known_rates),
3212 frame_rate_compare)))
3214 *avgframetime = entry->frame_time;
3216 else
3217 *avgframetime = numerator ? denominator * (UINT64)10000000 / numerator : 0;
3219 return S_OK;
3222 /***********************************************************************
3223 * MFMapDXGIFormatToDX9Format (mfplat.@)
3225 DWORD WINAPI MFMapDXGIFormatToDX9Format(DXGI_FORMAT dxgi_format)
3227 switch (dxgi_format)
3229 case DXGI_FORMAT_R32G32B32A32_FLOAT:
3230 return D3DFMT_A32B32G32R32F;
3231 case DXGI_FORMAT_R16G16B16A16_FLOAT:
3232 return D3DFMT_A16B16G16R16F;
3233 case DXGI_FORMAT_R16G16B16A16_UNORM:
3234 return D3DFMT_A16B16G16R16;
3235 case DXGI_FORMAT_R16G16B16A16_SNORM:
3236 return D3DFMT_Q16W16V16U16;
3237 case DXGI_FORMAT_R32G32_FLOAT:
3238 return D3DFMT_G32R32F;
3239 case DXGI_FORMAT_R10G10B10A2_UNORM:
3240 return D3DFMT_A2B10G10R10;
3241 case DXGI_FORMAT_R8G8B8A8_SNORM:
3242 return D3DFMT_Q8W8V8U8;
3243 case DXGI_FORMAT_R16G16_FLOAT:
3244 return D3DFMT_G16R16F;
3245 case DXGI_FORMAT_R16G16_UNORM:
3246 return D3DFMT_G16R16;
3247 case DXGI_FORMAT_R16G16_SNORM:
3248 return D3DFMT_V16U16;
3249 case DXGI_FORMAT_D32_FLOAT:
3250 return D3DFMT_D32F_LOCKABLE;
3251 case DXGI_FORMAT_R32_FLOAT:
3252 return D3DFMT_R32F;
3253 case DXGI_FORMAT_D24_UNORM_S8_UINT:
3254 return D3DFMT_D24S8;
3255 case DXGI_FORMAT_R8G8_SNORM:
3256 return D3DFMT_V8U8;
3257 case DXGI_FORMAT_R16_FLOAT:
3258 return D3DFMT_R16F;
3259 case DXGI_FORMAT_D16_UNORM:
3260 return D3DFMT_D16_LOCKABLE;
3261 case DXGI_FORMAT_R16_UNORM:
3262 return D3DFMT_L16;
3263 case DXGI_FORMAT_R8_UNORM:
3264 return D3DFMT_L8;
3265 case DXGI_FORMAT_A8_UNORM:
3266 return D3DFMT_A8;
3267 case DXGI_FORMAT_BC1_UNORM:
3268 case DXGI_FORMAT_BC1_UNORM_SRGB:
3269 return D3DFMT_DXT1;
3270 case DXGI_FORMAT_BC2_UNORM:
3271 case DXGI_FORMAT_BC2_UNORM_SRGB:
3272 return D3DFMT_DXT2;
3273 case DXGI_FORMAT_BC3_UNORM:
3274 case DXGI_FORMAT_BC3_UNORM_SRGB:
3275 return D3DFMT_DXT4;
3276 case DXGI_FORMAT_R8G8B8A8_UNORM:
3277 return D3DFMT_A8B8G8R8;
3278 case DXGI_FORMAT_B8G8R8A8_UNORM:
3279 case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
3280 case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
3281 return D3DFMT_A8R8G8B8;
3282 case DXGI_FORMAT_B8G8R8X8_UNORM:
3283 case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB:
3284 return D3DFMT_X8R8G8B8;
3285 case DXGI_FORMAT_AYUV:
3286 return MAKEFOURCC('A','Y','U','V');
3287 case DXGI_FORMAT_Y410:
3288 return MAKEFOURCC('Y','4','1','0');
3289 case DXGI_FORMAT_Y416:
3290 return MAKEFOURCC('Y','4','1','6');
3291 case DXGI_FORMAT_NV12:
3292 return MAKEFOURCC('N','V','1','2');
3293 case DXGI_FORMAT_P010:
3294 return MAKEFOURCC('P','0','1','0');
3295 case DXGI_FORMAT_P016:
3296 return MAKEFOURCC('P','0','1','6');
3297 case DXGI_FORMAT_420_OPAQUE:
3298 return MAKEFOURCC('4','2','0','O');
3299 case DXGI_FORMAT_YUY2:
3300 return D3DFMT_YUY2;
3301 case DXGI_FORMAT_Y210:
3302 return MAKEFOURCC('Y','2','1','0');
3303 case DXGI_FORMAT_Y216:
3304 return MAKEFOURCC('Y','2','1','6');
3305 case DXGI_FORMAT_NV11:
3306 return MAKEFOURCC('N','V','1','1');
3307 case DXGI_FORMAT_AI44:
3308 return MAKEFOURCC('A','I','4','4');
3309 case DXGI_FORMAT_IA44:
3310 return MAKEFOURCC('I','A','4','4');
3311 case DXGI_FORMAT_P8:
3312 return D3DFMT_P8;
3313 case DXGI_FORMAT_A8P8:
3314 return D3DFMT_A8P8;
3315 default:
3316 return 0;
3320 /***********************************************************************
3321 * MFMapDX9FormatToDXGIFormat (mfplat.@)
3323 DXGI_FORMAT WINAPI MFMapDX9FormatToDXGIFormat(DWORD format)
3325 switch (format)
3327 case D3DFMT_A32B32G32R32F:
3328 return DXGI_FORMAT_R32G32B32A32_FLOAT;
3329 case D3DFMT_A16B16G16R16F:
3330 return DXGI_FORMAT_R16G16B16A16_FLOAT;
3331 case D3DFMT_A16B16G16R16:
3332 return DXGI_FORMAT_R16G16B16A16_UNORM;
3333 case D3DFMT_Q16W16V16U16:
3334 return DXGI_FORMAT_R16G16B16A16_SNORM;
3335 case D3DFMT_G32R32F:
3336 return DXGI_FORMAT_R32G32_FLOAT;
3337 case D3DFMT_A2B10G10R10:
3338 return DXGI_FORMAT_R10G10B10A2_UNORM;
3339 case D3DFMT_Q8W8V8U8:
3340 return DXGI_FORMAT_R8G8B8A8_SNORM;
3341 case D3DFMT_G16R16F:
3342 return DXGI_FORMAT_R16G16_FLOAT;
3343 case D3DFMT_G16R16:
3344 return DXGI_FORMAT_R16G16_UNORM;
3345 case D3DFMT_V16U16:
3346 return DXGI_FORMAT_R16G16_SNORM;
3347 case D3DFMT_D32F_LOCKABLE:
3348 return DXGI_FORMAT_D32_FLOAT;
3349 case D3DFMT_R32F:
3350 return DXGI_FORMAT_R32_FLOAT;
3351 case D3DFMT_D24S8:
3352 return DXGI_FORMAT_D24_UNORM_S8_UINT;
3353 case D3DFMT_V8U8:
3354 return DXGI_FORMAT_R8G8_SNORM;
3355 case D3DFMT_R16F:
3356 return DXGI_FORMAT_R16_FLOAT;
3357 case D3DFMT_L16:
3358 return DXGI_FORMAT_R16_UNORM;
3359 case D3DFMT_L8:
3360 return DXGI_FORMAT_R8_UNORM;
3361 case D3DFMT_A8:
3362 return DXGI_FORMAT_A8_UNORM;
3363 case D3DFMT_DXT1:
3364 return DXGI_FORMAT_BC1_UNORM;
3365 case D3DFMT_DXT2:
3366 return DXGI_FORMAT_BC2_UNORM;
3367 case D3DFMT_DXT4:
3368 return DXGI_FORMAT_BC3_UNORM;
3369 case D3DFMT_A8R8G8B8:
3370 return DXGI_FORMAT_B8G8R8A8_UNORM;
3371 case D3DFMT_X8R8G8B8:
3372 return DXGI_FORMAT_B8G8R8X8_UNORM;
3373 case MAKEFOURCC('A','Y','U','V'):
3374 return DXGI_FORMAT_AYUV;
3375 case MAKEFOURCC('Y','4','1','0'):
3376 return DXGI_FORMAT_Y410;
3377 case MAKEFOURCC('Y','4','1','6'):
3378 return DXGI_FORMAT_Y416;
3379 case MAKEFOURCC('N','V','1','2'):
3380 return DXGI_FORMAT_NV12;
3381 case MAKEFOURCC('P','0','1','0'):
3382 return DXGI_FORMAT_P010;
3383 case MAKEFOURCC('P','0','1','6'):
3384 return DXGI_FORMAT_P016;
3385 case MAKEFOURCC('4','2','0','O'):
3386 return DXGI_FORMAT_420_OPAQUE;
3387 case D3DFMT_YUY2:
3388 return DXGI_FORMAT_YUY2;
3389 case MAKEFOURCC('Y','2','1','0'):
3390 return DXGI_FORMAT_Y210;
3391 case MAKEFOURCC('Y','2','1','6'):
3392 return DXGI_FORMAT_Y216;
3393 case MAKEFOURCC('N','V','1','1'):
3394 return DXGI_FORMAT_NV11;
3395 case MAKEFOURCC('A','I','4','4'):
3396 return DXGI_FORMAT_AI44;
3397 case MAKEFOURCC('I','A','4','4'):
3398 return DXGI_FORMAT_IA44;
3399 case D3DFMT_P8:
3400 return DXGI_FORMAT_P8;
3401 case D3DFMT_A8P8:
3402 return DXGI_FORMAT_A8P8;
3403 default:
3404 return DXGI_FORMAT_UNKNOWN;