d3d10/effect: Use case-insensitive comparison in GetMemberTypeBySemantic().
[wine.git] / dlls / mfplat / mediatype.c
blob4f24ccbd237b5ef8e868ebbccd255fe8a227ea5a
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;
44 WAVEFORMATEX *audio_format;
47 struct stream_desc
49 struct attributes attributes;
50 IMFStreamDescriptor IMFStreamDescriptor_iface;
51 IMFMediaTypeHandler IMFMediaTypeHandler_iface;
52 DWORD identifier;
53 IMFMediaType **media_types;
54 unsigned int media_types_count;
55 IMFMediaType *current_type;
58 struct presentation_desc_entry
60 IMFStreamDescriptor *descriptor;
61 BOOL selected;
64 struct presentation_desc
66 struct attributes attributes;
67 IMFPresentationDescriptor IMFPresentationDescriptor_iface;
68 struct presentation_desc_entry *descriptors;
69 unsigned int count;
72 static HRESULT presentation_descriptor_init(struct presentation_desc *object, DWORD count);
74 static struct media_type *impl_from_IMFMediaType(IMFMediaType *iface)
76 return CONTAINING_RECORD(iface, struct media_type, IMFMediaType_iface);
79 static struct media_type *impl_from_IMFVideoMediaType(IMFVideoMediaType *iface)
81 return CONTAINING_RECORD(iface, struct media_type, IMFVideoMediaType_iface);
84 static struct media_type *impl_from_IMFAudioMediaType(IMFAudioMediaType *iface)
86 return CONTAINING_RECORD(iface, struct media_type, IMFAudioMediaType_iface);
89 static inline struct stream_desc *impl_from_IMFStreamDescriptor(IMFStreamDescriptor *iface)
91 return CONTAINING_RECORD(iface, struct stream_desc, IMFStreamDescriptor_iface);
94 static struct stream_desc *impl_from_IMFMediaTypeHandler(IMFMediaTypeHandler *iface)
96 return CONTAINING_RECORD(iface, struct stream_desc, IMFMediaTypeHandler_iface);
99 static struct presentation_desc *impl_from_IMFPresentationDescriptor(IMFPresentationDescriptor *iface)
101 return CONTAINING_RECORD(iface, struct presentation_desc, IMFPresentationDescriptor_iface);
104 static HRESULT WINAPI mediatype_QueryInterface(IMFMediaType *iface, REFIID riid, void **out)
106 struct media_type *media_type = impl_from_IMFMediaType(iface);
107 GUID major = { 0 };
109 TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), out);
111 attributes_GetGUID(&media_type->attributes, &MF_MT_MAJOR_TYPE, &major);
113 if (IsEqualGUID(&major, &MFMediaType_Video) && IsEqualIID(riid, &IID_IMFVideoMediaType))
115 *out = &media_type->IMFVideoMediaType_iface;
117 else if (IsEqualGUID(&major, &MFMediaType_Audio) && IsEqualIID(riid, &IID_IMFAudioMediaType))
119 *out = &media_type->IMFAudioMediaType_iface;
121 else if (IsEqualIID(riid, &IID_IMFMediaType) ||
122 IsEqualIID(riid, &IID_IMFAttributes) ||
123 IsEqualIID(riid, &IID_IUnknown))
125 *out = &media_type->IMFMediaType_iface;
127 else
129 WARN("Unsupported %s.\n", debugstr_guid(riid));
130 *out = NULL;
131 return E_NOINTERFACE;
134 IUnknown_AddRef((IUnknown *)*out);
135 return S_OK;
138 static ULONG WINAPI mediatype_AddRef(IMFMediaType *iface)
140 struct media_type *media_type = impl_from_IMFMediaType(iface);
141 ULONG refcount = InterlockedIncrement(&media_type->attributes.ref);
143 TRACE("%p, refcount %u.\n", iface, refcount);
145 return refcount;
148 static ULONG WINAPI mediatype_Release(IMFMediaType *iface)
150 struct media_type *media_type = impl_from_IMFMediaType(iface);
151 ULONG refcount = InterlockedDecrement(&media_type->attributes.ref);
153 TRACE("%p, refcount %u.\n", iface, refcount);
155 if (!refcount)
157 clear_attributes_object(&media_type->attributes);
158 CoTaskMemFree(media_type->video_format);
159 CoTaskMemFree(media_type->audio_format);
160 free(media_type);
163 return refcount;
166 static HRESULT WINAPI mediatype_GetItem(IMFMediaType *iface, REFGUID key, PROPVARIANT *value)
168 struct media_type *media_type = impl_from_IMFMediaType(iface);
170 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
172 return attributes_GetItem(&media_type->attributes, key, value);
175 static HRESULT WINAPI mediatype_GetItemType(IMFMediaType *iface, REFGUID key, MF_ATTRIBUTE_TYPE *type)
177 struct media_type *media_type = impl_from_IMFMediaType(iface);
179 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), type);
181 return attributes_GetItemType(&media_type->attributes, key, type);
184 static HRESULT WINAPI mediatype_CompareItem(IMFMediaType *iface, REFGUID key, REFPROPVARIANT value, BOOL *result)
186 struct media_type *media_type = impl_from_IMFMediaType(iface);
188 TRACE("%p, %s, %s, %p.\n", iface, debugstr_attr(key), debugstr_propvar(value), result);
190 return attributes_CompareItem(&media_type->attributes, key, value, result);
193 static HRESULT WINAPI mediatype_Compare(IMFMediaType *iface, IMFAttributes *attrs, MF_ATTRIBUTES_MATCH_TYPE type,
194 BOOL *result)
196 struct media_type *media_type = impl_from_IMFMediaType(iface);
198 TRACE("%p, %p, %d, %p.\n", iface, attrs, type, result);
200 return attributes_Compare(&media_type->attributes, attrs, type, result);
203 static HRESULT WINAPI mediatype_GetUINT32(IMFMediaType *iface, REFGUID key, UINT32 *value)
205 struct media_type *media_type = impl_from_IMFMediaType(iface);
207 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
209 return attributes_GetUINT32(&media_type->attributes, key, value);
212 static HRESULT WINAPI mediatype_GetUINT64(IMFMediaType *iface, REFGUID key, UINT64 *value)
214 struct media_type *media_type = impl_from_IMFMediaType(iface);
216 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
218 return attributes_GetUINT64(&media_type->attributes, key, value);
221 static HRESULT WINAPI mediatype_GetDouble(IMFMediaType *iface, REFGUID key, double *value)
223 struct media_type *media_type = impl_from_IMFMediaType(iface);
225 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
227 return attributes_GetDouble(&media_type->attributes, key, value);
230 static HRESULT WINAPI mediatype_GetGUID(IMFMediaType *iface, REFGUID key, GUID *value)
232 struct media_type *media_type = impl_from_IMFMediaType(iface);
234 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
236 return attributes_GetGUID(&media_type->attributes, key, value);
239 static HRESULT WINAPI mediatype_GetStringLength(IMFMediaType *iface, REFGUID key, UINT32 *length)
241 struct media_type *media_type = impl_from_IMFMediaType(iface);
243 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), length);
245 return attributes_GetStringLength(&media_type->attributes, key, length);
248 static HRESULT WINAPI mediatype_GetString(IMFMediaType *iface, REFGUID key, WCHAR *value,
249 UINT32 size, UINT32 *length)
251 struct media_type *media_type = impl_from_IMFMediaType(iface);
253 TRACE("%p, %s, %p, %u, %p.\n", iface, debugstr_attr(key), value, size, length);
255 return attributes_GetString(&media_type->attributes, key, value, size, length);
258 static HRESULT WINAPI mediatype_GetAllocatedString(IMFMediaType *iface, REFGUID key,
259 WCHAR **value, UINT32 *length)
261 struct media_type *media_type = impl_from_IMFMediaType(iface);
263 TRACE("%p, %s, %p, %p.\n", iface, debugstr_attr(key), value, length);
265 return attributes_GetAllocatedString(&media_type->attributes, key, value, length);
268 static HRESULT WINAPI mediatype_GetBlobSize(IMFMediaType *iface, REFGUID key, UINT32 *size)
270 struct media_type *media_type = impl_from_IMFMediaType(iface);
272 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), size);
274 return attributes_GetBlobSize(&media_type->attributes, key, size);
277 static HRESULT WINAPI mediatype_GetBlob(IMFMediaType *iface, REFGUID key, UINT8 *buf,
278 UINT32 bufsize, UINT32 *blobsize)
280 struct media_type *media_type = impl_from_IMFMediaType(iface);
282 TRACE("%p, %s, %p, %u, %p.\n", iface, debugstr_attr(key), buf, bufsize, blobsize);
284 return attributes_GetBlob(&media_type->attributes, key, buf, bufsize, blobsize);
287 static HRESULT WINAPI mediatype_GetAllocatedBlob(IMFMediaType *iface, REFGUID key, UINT8 **buf, UINT32 *size)
289 struct media_type *media_type = impl_from_IMFMediaType(iface);
291 TRACE("%p, %s, %p, %p.\n", iface, debugstr_attr(key), buf, size);
293 return attributes_GetAllocatedBlob(&media_type->attributes, key, buf, size);
296 static HRESULT WINAPI mediatype_GetUnknown(IMFMediaType *iface, REFGUID key, REFIID riid, void **obj)
298 struct media_type *media_type = impl_from_IMFMediaType(iface);
300 TRACE("%p, %s, %s, %p.\n", iface, debugstr_attr(key), debugstr_guid(riid), obj);
302 return attributes_GetUnknown(&media_type->attributes, key, riid, obj);
305 static HRESULT WINAPI mediatype_SetItem(IMFMediaType *iface, REFGUID key, REFPROPVARIANT value)
307 struct media_type *media_type = impl_from_IMFMediaType(iface);
309 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_propvar(value));
311 return attributes_SetItem(&media_type->attributes, key, value);
314 static HRESULT WINAPI mediatype_DeleteItem(IMFMediaType *iface, REFGUID key)
316 struct media_type *media_type = impl_from_IMFMediaType(iface);
318 TRACE("%p, %s.\n", iface, debugstr_attr(key));
320 return attributes_DeleteItem(&media_type->attributes, key);
323 static HRESULT WINAPI mediatype_DeleteAllItems(IMFMediaType *iface)
325 struct media_type *media_type = impl_from_IMFMediaType(iface);
327 TRACE("%p.\n", iface);
329 return attributes_DeleteAllItems(&media_type->attributes);
332 static HRESULT WINAPI mediatype_SetUINT32(IMFMediaType *iface, REFGUID key, UINT32 value)
334 struct media_type *media_type = impl_from_IMFMediaType(iface);
336 TRACE("%p, %s, %u.\n", iface, debugstr_attr(key), value);
338 return attributes_SetUINT32(&media_type->attributes, key, value);
341 static HRESULT WINAPI mediatype_SetUINT64(IMFMediaType *iface, REFGUID key, UINT64 value)
343 struct media_type *media_type = impl_from_IMFMediaType(iface);
345 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), wine_dbgstr_longlong(value));
347 return attributes_SetUINT64(&media_type->attributes, key, value);
350 static HRESULT WINAPI mediatype_SetDouble(IMFMediaType *iface, REFGUID key, double value)
352 struct media_type *media_type = impl_from_IMFMediaType(iface);
354 TRACE("%p, %s, %f.\n", iface, debugstr_attr(key), value);
356 return attributes_SetDouble(&media_type->attributes, key, value);
359 static HRESULT WINAPI mediatype_SetGUID(IMFMediaType *iface, REFGUID key, REFGUID value)
361 struct media_type *media_type = impl_from_IMFMediaType(iface);
363 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_mf_guid(value));
365 return attributes_SetGUID(&media_type->attributes, key, value);
368 static HRESULT WINAPI mediatype_SetString(IMFMediaType *iface, REFGUID key, const WCHAR *value)
370 struct media_type *media_type = impl_from_IMFMediaType(iface);
372 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_w(value));
374 return attributes_SetString(&media_type->attributes, key, value);
377 static HRESULT WINAPI mediatype_SetBlob(IMFMediaType *iface, REFGUID key, const UINT8 *buf, UINT32 size)
379 struct media_type *media_type = impl_from_IMFMediaType(iface);
381 TRACE("%p, %s, %p, %u.\n", iface, debugstr_attr(key), buf, size);
383 return attributes_SetBlob(&media_type->attributes, key, buf, size);
386 static HRESULT WINAPI mediatype_SetUnknown(IMFMediaType *iface, REFGUID key, IUnknown *unknown)
388 struct media_type *media_type = impl_from_IMFMediaType(iface);
390 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), unknown);
392 return attributes_SetUnknown(&media_type->attributes, key, unknown);
395 static HRESULT WINAPI mediatype_LockStore(IMFMediaType *iface)
397 struct media_type *media_type = impl_from_IMFMediaType(iface);
399 TRACE("%p.\n", iface);
401 return attributes_LockStore(&media_type->attributes);
404 static HRESULT WINAPI mediatype_UnlockStore(IMFMediaType *iface)
406 struct media_type *media_type = impl_from_IMFMediaType(iface);
408 TRACE("%p.\n", iface);
410 return attributes_UnlockStore(&media_type->attributes);
413 static HRESULT WINAPI mediatype_GetCount(IMFMediaType *iface, UINT32 *count)
415 struct media_type *media_type = impl_from_IMFMediaType(iface);
417 TRACE("%p, %p.\n", iface, count);
419 return attributes_GetCount(&media_type->attributes, count);
422 static HRESULT WINAPI mediatype_GetItemByIndex(IMFMediaType *iface, UINT32 index, GUID *key, PROPVARIANT *value)
424 struct media_type *media_type = impl_from_IMFMediaType(iface);
426 TRACE("%p, %u, %p, %p.\n", iface, index, key, value);
428 return attributes_GetItemByIndex(&media_type->attributes, index, key, value);
431 static HRESULT WINAPI mediatype_CopyAllItems(IMFMediaType *iface, IMFAttributes *dest)
433 struct media_type *media_type = impl_from_IMFMediaType(iface);
435 TRACE("%p, %p.\n", iface, dest);
437 return attributes_CopyAllItems(&media_type->attributes, dest);
440 static HRESULT WINAPI mediatype_GetMajorType(IMFMediaType *iface, GUID *guid)
442 struct media_type *media_type = impl_from_IMFMediaType(iface);
444 TRACE("%p, %p.\n", iface, guid);
446 return attributes_GetGUID(&media_type->attributes, &MF_MT_MAJOR_TYPE, guid);
449 static HRESULT mediatype_is_compressed(struct media_type *media_type, BOOL *compressed)
451 UINT32 value;
453 if (FAILED(attributes_GetUINT32(&media_type->attributes, &MF_MT_ALL_SAMPLES_INDEPENDENT, &value)))
455 value = 0;
458 *compressed = !value;
460 return S_OK;
463 static HRESULT WINAPI mediatype_IsCompressedFormat(IMFMediaType *iface, BOOL *compressed)
465 struct media_type *media_type = impl_from_IMFMediaType(iface);
467 TRACE("%p, %p.\n", iface, compressed);
469 return mediatype_is_compressed(media_type, compressed);
472 static HRESULT media_type_is_equal(struct media_type *media_type, IMFMediaType *type, DWORD *flags)
474 const DWORD full_equality_flags = MF_MEDIATYPE_EQUAL_MAJOR_TYPES | MF_MEDIATYPE_EQUAL_FORMAT_TYPES |
475 MF_MEDIATYPE_EQUAL_FORMAT_DATA | MF_MEDIATYPE_EQUAL_FORMAT_USER_DATA;
476 struct comparand
478 IMFAttributes *type;
479 PROPVARIANT value;
480 UINT32 count;
481 GUID guid;
482 HRESULT hr;
483 } left, right, swp;
484 unsigned int i;
485 BOOL result;
487 *flags = 0;
489 left.type = &media_type->attributes.IMFAttributes_iface;
490 right.type = (IMFAttributes *)type;
492 if (FAILED(IMFAttributes_GetGUID(left.type, &MF_MT_MAJOR_TYPE, &left.guid)))
493 return E_INVALIDARG;
495 if (FAILED(IMFAttributes_GetGUID(right.type, &MF_MT_MAJOR_TYPE, &right.guid)))
496 return E_INVALIDARG;
498 if (IsEqualGUID(&left.guid, &right.guid))
499 *flags |= MF_MEDIATYPE_EQUAL_MAJOR_TYPES;
501 /* Subtypes equal or both missing. */
502 left.hr = IMFAttributes_GetGUID(left.type, &MF_MT_SUBTYPE, &left.guid);
503 right.hr = IMFAttributes_GetGUID(right.type, &MF_MT_SUBTYPE, &right.guid);
505 if ((SUCCEEDED(left.hr) && SUCCEEDED(right.hr) && IsEqualGUID(&left.guid, &right.guid)) ||
506 (FAILED(left.hr) && FAILED(right.hr)))
508 *flags |= MF_MEDIATYPE_EQUAL_FORMAT_TYPES;
511 /* Format data */
512 IMFAttributes_GetCount(left.type, &left.count);
513 IMFAttributes_GetCount(right.type, &right.count);
515 if (right.count < left.count)
517 swp = left;
518 left = right;
519 right = swp;
522 *flags |= MF_MEDIATYPE_EQUAL_FORMAT_DATA;
524 for (i = 0; i < left.count; ++i)
526 PROPVARIANT value;
527 GUID key;
529 if (SUCCEEDED(IMFAttributes_GetItemByIndex(left.type, i, &key, &value)))
531 if (IsEqualGUID(&key, &MF_MT_USER_DATA) ||
532 IsEqualGUID(&key, &MF_MT_FRAME_RATE_RANGE_MIN) ||
533 IsEqualGUID(&key, &MF_MT_FRAME_RATE_RANGE_MAX))
535 PropVariantClear(&value);
536 continue;
539 result = FALSE;
540 IMFAttributes_CompareItem(right.type, &key, &value, &result);
541 PropVariantClear(&value);
542 if (!result)
544 *flags &= ~MF_MEDIATYPE_EQUAL_FORMAT_DATA;
545 break;
550 /* User data */
551 PropVariantInit(&left.value);
552 left.hr = IMFAttributes_GetItem(left.type, &MF_MT_USER_DATA, &left.value);
553 PropVariantInit(&right.value);
554 right.hr = IMFAttributes_GetItem(right.type, &MF_MT_USER_DATA, &right.value);
556 /* Compare user data if both types have it, otherwise simply check if both don't. */
557 if (SUCCEEDED(left.hr) && SUCCEEDED(right.hr))
559 result = FALSE;
560 IMFAttributes_CompareItem(left.type, &MF_MT_USER_DATA, &left.value, &result);
562 else
563 result = FAILED(left.hr) && FAILED(right.hr);
565 PropVariantClear(&left.value);
566 PropVariantClear(&right.value);
568 if (result)
569 *flags |= MF_MEDIATYPE_EQUAL_FORMAT_USER_DATA;
571 return *flags == full_equality_flags ? S_OK : S_FALSE;
574 static HRESULT WINAPI mediatype_IsEqual(IMFMediaType *iface, IMFMediaType *type, DWORD *flags)
576 struct media_type *media_type = impl_from_IMFMediaType(iface);
578 TRACE("%p, %p, %p.\n", iface, type, flags);
580 return media_type_is_equal(media_type, type, flags);
583 static HRESULT WINAPI mediatype_GetRepresentation(IMFMediaType *iface, GUID guid, void **representation)
585 FIXME("%p, %s, %p.\n", iface, debugstr_guid(&guid), representation);
587 return E_NOTIMPL;
590 static HRESULT WINAPI mediatype_FreeRepresentation(IMFMediaType *iface, GUID guid, void *representation)
592 FIXME("%p, %s, %p.\n", iface, debugstr_guid(&guid), representation);
594 return E_NOTIMPL;
597 static const IMFMediaTypeVtbl mediatypevtbl =
599 mediatype_QueryInterface,
600 mediatype_AddRef,
601 mediatype_Release,
602 mediatype_GetItem,
603 mediatype_GetItemType,
604 mediatype_CompareItem,
605 mediatype_Compare,
606 mediatype_GetUINT32,
607 mediatype_GetUINT64,
608 mediatype_GetDouble,
609 mediatype_GetGUID,
610 mediatype_GetStringLength,
611 mediatype_GetString,
612 mediatype_GetAllocatedString,
613 mediatype_GetBlobSize,
614 mediatype_GetBlob,
615 mediatype_GetAllocatedBlob,
616 mediatype_GetUnknown,
617 mediatype_SetItem,
618 mediatype_DeleteItem,
619 mediatype_DeleteAllItems,
620 mediatype_SetUINT32,
621 mediatype_SetUINT64,
622 mediatype_SetDouble,
623 mediatype_SetGUID,
624 mediatype_SetString,
625 mediatype_SetBlob,
626 mediatype_SetUnknown,
627 mediatype_LockStore,
628 mediatype_UnlockStore,
629 mediatype_GetCount,
630 mediatype_GetItemByIndex,
631 mediatype_CopyAllItems,
632 mediatype_GetMajorType,
633 mediatype_IsCompressedFormat,
634 mediatype_IsEqual,
635 mediatype_GetRepresentation,
636 mediatype_FreeRepresentation
639 static HRESULT WINAPI video_mediatype_QueryInterface(IMFVideoMediaType *iface, REFIID riid, void **out)
641 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
642 return IMFMediaType_QueryInterface(&media_type->IMFMediaType_iface, riid, out);
645 static ULONG WINAPI video_mediatype_AddRef(IMFVideoMediaType *iface)
647 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
648 return IMFMediaType_AddRef(&media_type->IMFMediaType_iface);
651 static ULONG WINAPI video_mediatype_Release(IMFVideoMediaType *iface)
653 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
654 return IMFMediaType_Release(&media_type->IMFMediaType_iface);
657 static HRESULT WINAPI video_mediatype_GetItem(IMFVideoMediaType *iface, REFGUID key, PROPVARIANT *value)
659 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
661 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
663 return attributes_GetItem(&media_type->attributes, key, value);
666 static HRESULT WINAPI video_mediatype_GetItemType(IMFVideoMediaType *iface, REFGUID key, MF_ATTRIBUTE_TYPE *type)
668 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
670 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), type);
672 return attributes_GetItemType(&media_type->attributes, key, type);
675 static HRESULT WINAPI video_mediatype_CompareItem(IMFVideoMediaType *iface, REFGUID key, REFPROPVARIANT value, BOOL *result)
677 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
679 TRACE("%p, %s, %s, %p.\n", iface, debugstr_attr(key), debugstr_propvar(value), result);
681 return attributes_CompareItem(&media_type->attributes, key, value, result);
684 static HRESULT WINAPI video_mediatype_Compare(IMFVideoMediaType *iface, IMFAttributes *attrs,
685 MF_ATTRIBUTES_MATCH_TYPE type, BOOL *result)
687 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
689 TRACE("%p, %p, %d, %p.\n", iface, attrs, type, result);
691 return attributes_Compare(&media_type->attributes, attrs, type, result);
694 static HRESULT WINAPI video_mediatype_GetUINT32(IMFVideoMediaType *iface, REFGUID key, UINT32 *value)
696 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
698 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
700 return attributes_GetUINT32(&media_type->attributes, key, value);
703 static HRESULT WINAPI video_mediatype_GetUINT64(IMFVideoMediaType *iface, REFGUID key, UINT64 *value)
705 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
707 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
709 return attributes_GetUINT64(&media_type->attributes, key, value);
712 static HRESULT WINAPI video_mediatype_GetDouble(IMFVideoMediaType *iface, REFGUID key, double *value)
714 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
716 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
718 return attributes_GetDouble(&media_type->attributes, key, value);
721 static HRESULT WINAPI video_mediatype_GetGUID(IMFVideoMediaType *iface, REFGUID key, GUID *value)
723 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
725 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
727 return attributes_GetGUID(&media_type->attributes, key, value);
730 static HRESULT WINAPI video_mediatype_GetStringLength(IMFVideoMediaType *iface, REFGUID key, UINT32 *length)
732 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
734 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), length);
736 return attributes_GetStringLength(&media_type->attributes, key, length);
739 static HRESULT WINAPI video_mediatype_GetString(IMFVideoMediaType *iface, REFGUID key, WCHAR *value,
740 UINT32 size, UINT32 *length)
742 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
744 TRACE("%p, %s, %p, %u, %p.\n", iface, debugstr_attr(key), value, size, length);
746 return attributes_GetString(&media_type->attributes, key, value, size, length);
749 static HRESULT WINAPI video_mediatype_GetAllocatedString(IMFVideoMediaType *iface, REFGUID key,
750 WCHAR **value, UINT32 *length)
752 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
754 TRACE("%p, %s, %p, %p.\n", iface, debugstr_attr(key), value, length);
756 return attributes_GetAllocatedString(&media_type->attributes, key, value, length);
759 static HRESULT WINAPI video_mediatype_GetBlobSize(IMFVideoMediaType *iface, REFGUID key, UINT32 *size)
761 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
763 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), size);
765 return attributes_GetBlobSize(&media_type->attributes, key, size);
768 static HRESULT WINAPI video_mediatype_GetBlob(IMFVideoMediaType *iface, REFGUID key, UINT8 *buf,
769 UINT32 bufsize, UINT32 *blobsize)
771 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
773 TRACE("%p, %s, %p, %u, %p.\n", iface, debugstr_attr(key), buf, bufsize, blobsize);
775 return attributes_GetBlob(&media_type->attributes, key, buf, bufsize, blobsize);
778 static HRESULT WINAPI video_mediatype_GetAllocatedBlob(IMFVideoMediaType *iface, REFGUID key, UINT8 **buf, UINT32 *size)
780 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
782 TRACE("%p, %s, %p, %p.\n", iface, debugstr_attr(key), buf, size);
784 return attributes_GetAllocatedBlob(&media_type->attributes, key, buf, size);
787 static HRESULT WINAPI video_mediatype_GetUnknown(IMFVideoMediaType *iface, REFGUID key, REFIID riid, void **obj)
789 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
791 TRACE("%p, %s, %s, %p.\n", iface, debugstr_attr(key), debugstr_guid(riid), obj);
793 return attributes_GetUnknown(&media_type->attributes, key, riid, obj);
796 static HRESULT WINAPI video_mediatype_SetItem(IMFVideoMediaType *iface, REFGUID key, REFPROPVARIANT value)
798 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
800 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_propvar(value));
802 return attributes_SetItem(&media_type->attributes, key, value);
805 static HRESULT WINAPI video_mediatype_DeleteItem(IMFVideoMediaType *iface, REFGUID key)
807 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
809 TRACE("%p, %s.\n", iface, debugstr_attr(key));
811 return attributes_DeleteItem(&media_type->attributes, key);
814 static HRESULT WINAPI video_mediatype_DeleteAllItems(IMFVideoMediaType *iface)
816 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
818 TRACE("%p.\n", iface);
820 return attributes_DeleteAllItems(&media_type->attributes);
823 static HRESULT WINAPI video_mediatype_SetUINT32(IMFVideoMediaType *iface, REFGUID key, UINT32 value)
825 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
827 TRACE("%p, %s, %u.\n", iface, debugstr_attr(key), value);
829 return attributes_SetUINT32(&media_type->attributes, key, value);
832 static HRESULT WINAPI video_mediatype_SetUINT64(IMFVideoMediaType *iface, REFGUID key, UINT64 value)
834 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
836 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), wine_dbgstr_longlong(value));
838 return attributes_SetUINT64(&media_type->attributes, key, value);
841 static HRESULT WINAPI video_mediatype_SetDouble(IMFVideoMediaType *iface, REFGUID key, double value)
843 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
845 TRACE("%p, %s, %f.\n", iface, debugstr_attr(key), value);
847 return attributes_SetDouble(&media_type->attributes, key, value);
850 static HRESULT WINAPI video_mediatype_SetGUID(IMFVideoMediaType *iface, REFGUID key, REFGUID value)
852 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
854 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_mf_guid(value));
856 return attributes_SetGUID(&media_type->attributes, key, value);
859 static HRESULT WINAPI video_mediatype_SetString(IMFVideoMediaType *iface, REFGUID key, const WCHAR *value)
861 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
863 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_w(value));
865 return attributes_SetString(&media_type->attributes, key, value);
868 static HRESULT WINAPI video_mediatype_SetBlob(IMFVideoMediaType *iface, REFGUID key, const UINT8 *buf, UINT32 size)
870 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
872 TRACE("%p, %s, %p, %u.\n", iface, debugstr_attr(key), buf, size);
874 return attributes_SetBlob(&media_type->attributes, key, buf, size);
877 static HRESULT WINAPI video_mediatype_SetUnknown(IMFVideoMediaType *iface, REFGUID key, IUnknown *unknown)
879 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
881 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), unknown);
883 return attributes_SetUnknown(&media_type->attributes, key, unknown);
886 static HRESULT WINAPI video_mediatype_LockStore(IMFVideoMediaType *iface)
888 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
890 TRACE("%p.\n", iface);
892 return attributes_LockStore(&media_type->attributes);
895 static HRESULT WINAPI video_mediatype_UnlockStore(IMFVideoMediaType *iface)
897 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
899 TRACE("%p.\n", iface);
901 return attributes_UnlockStore(&media_type->attributes);
904 static HRESULT WINAPI video_mediatype_GetCount(IMFVideoMediaType *iface, UINT32 *count)
906 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
908 TRACE("%p, %p.\n", iface, count);
910 return attributes_GetCount(&media_type->attributes, count);
913 static HRESULT WINAPI video_mediatype_GetItemByIndex(IMFVideoMediaType *iface, UINT32 index, GUID *key, PROPVARIANT *value)
915 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
917 TRACE("%p, %u, %p, %p.\n", iface, index, key, value);
919 return attributes_GetItemByIndex(&media_type->attributes, index, key, value);
922 static HRESULT WINAPI video_mediatype_CopyAllItems(IMFVideoMediaType *iface, IMFAttributes *dest)
924 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
926 TRACE("%p, %p.\n", iface, dest);
928 return attributes_CopyAllItems(&media_type->attributes, dest);
931 static HRESULT WINAPI video_mediatype_GetMajorType(IMFVideoMediaType *iface, GUID *guid)
933 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
935 TRACE("%p, %p.\n", iface, guid);
937 return attributes_GetGUID(&media_type->attributes, &MF_MT_MAJOR_TYPE, guid);
940 static HRESULT WINAPI video_mediatype_IsCompressedFormat(IMFVideoMediaType *iface, BOOL *compressed)
942 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
944 TRACE("%p, %p.\n", iface, compressed);
946 return mediatype_is_compressed(media_type, compressed);
949 static HRESULT WINAPI video_mediatype_IsEqual(IMFVideoMediaType *iface, IMFMediaType *type, DWORD *flags)
951 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
953 TRACE("%p, %p, %p.\n", iface, type, flags);
955 return media_type_is_equal(media_type, type, flags);
958 static HRESULT WINAPI video_mediatype_GetRepresentation(IMFVideoMediaType *iface, GUID guid, void **representation)
960 FIXME("%p, %s, %p.\n", iface, debugstr_guid(&guid), representation);
962 return E_NOTIMPL;
965 static HRESULT WINAPI video_mediatype_FreeRepresentation(IMFVideoMediaType *iface, GUID guid, void *representation)
967 FIXME("%p, %s, %p.\n", iface, debugstr_guid(&guid), representation);
969 return E_NOTIMPL;
972 static const MFVIDEOFORMAT * WINAPI video_mediatype_GetVideoFormat(IMFVideoMediaType *iface)
974 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
975 unsigned int size;
976 HRESULT hr;
978 TRACE("%p.\n", iface);
980 CoTaskMemFree(media_type->video_format);
981 if (FAILED(hr = MFCreateMFVideoFormatFromMFMediaType(&media_type->IMFMediaType_iface, &media_type->video_format, &size)))
982 WARN("Failed to create format description, hr %#x.\n", hr);
984 return media_type->video_format;
987 static HRESULT WINAPI video_mediatype_GetVideoRepresentation(IMFVideoMediaType *iface, GUID representation,
988 void **data, LONG stride)
990 FIXME("%p, %s, %p, %d.\n", iface, debugstr_guid(&representation), data, stride);
992 return E_NOTIMPL;
995 static const IMFVideoMediaTypeVtbl videomediatypevtbl =
997 video_mediatype_QueryInterface,
998 video_mediatype_AddRef,
999 video_mediatype_Release,
1000 video_mediatype_GetItem,
1001 video_mediatype_GetItemType,
1002 video_mediatype_CompareItem,
1003 video_mediatype_Compare,
1004 video_mediatype_GetUINT32,
1005 video_mediatype_GetUINT64,
1006 video_mediatype_GetDouble,
1007 video_mediatype_GetGUID,
1008 video_mediatype_GetStringLength,
1009 video_mediatype_GetString,
1010 video_mediatype_GetAllocatedString,
1011 video_mediatype_GetBlobSize,
1012 video_mediatype_GetBlob,
1013 video_mediatype_GetAllocatedBlob,
1014 video_mediatype_GetUnknown,
1015 video_mediatype_SetItem,
1016 video_mediatype_DeleteItem,
1017 video_mediatype_DeleteAllItems,
1018 video_mediatype_SetUINT32,
1019 video_mediatype_SetUINT64,
1020 video_mediatype_SetDouble,
1021 video_mediatype_SetGUID,
1022 video_mediatype_SetString,
1023 video_mediatype_SetBlob,
1024 video_mediatype_SetUnknown,
1025 video_mediatype_LockStore,
1026 video_mediatype_UnlockStore,
1027 video_mediatype_GetCount,
1028 video_mediatype_GetItemByIndex,
1029 video_mediatype_CopyAllItems,
1030 video_mediatype_GetMajorType,
1031 video_mediatype_IsCompressedFormat,
1032 video_mediatype_IsEqual,
1033 video_mediatype_GetRepresentation,
1034 video_mediatype_FreeRepresentation,
1035 video_mediatype_GetVideoFormat,
1036 video_mediatype_GetVideoRepresentation,
1039 static HRESULT WINAPI audio_mediatype_QueryInterface(IMFAudioMediaType *iface, REFIID riid, void **out)
1041 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1042 return IMFMediaType_QueryInterface(&media_type->IMFMediaType_iface, riid, out);
1045 static ULONG WINAPI audio_mediatype_AddRef(IMFAudioMediaType *iface)
1047 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1048 return IMFMediaType_AddRef(&media_type->IMFMediaType_iface);
1051 static ULONG WINAPI audio_mediatype_Release(IMFAudioMediaType *iface)
1053 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1054 return IMFMediaType_Release(&media_type->IMFMediaType_iface);
1057 static HRESULT WINAPI audio_mediatype_GetItem(IMFAudioMediaType *iface, REFGUID key, PROPVARIANT *value)
1059 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1061 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
1063 return attributes_GetItem(&media_type->attributes, key, value);
1066 static HRESULT WINAPI audio_mediatype_GetItemType(IMFAudioMediaType *iface, REFGUID key, MF_ATTRIBUTE_TYPE *type)
1068 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1070 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), type);
1072 return attributes_GetItemType(&media_type->attributes, key, type);
1075 static HRESULT WINAPI audio_mediatype_CompareItem(IMFAudioMediaType *iface, REFGUID key, REFPROPVARIANT value, BOOL *result)
1077 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1079 TRACE("%p, %s, %s, %p.\n", iface, debugstr_attr(key), debugstr_propvar(value), result);
1081 return attributes_CompareItem(&media_type->attributes, key, value, result);
1084 static HRESULT WINAPI audio_mediatype_Compare(IMFAudioMediaType *iface, IMFAttributes *attrs,
1085 MF_ATTRIBUTES_MATCH_TYPE type, BOOL *result)
1087 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1089 TRACE("%p, %p, %d, %p.\n", iface, attrs, type, result);
1091 return attributes_Compare(&media_type->attributes, attrs, type, result);
1094 static HRESULT WINAPI audio_mediatype_GetUINT32(IMFAudioMediaType *iface, REFGUID key, UINT32 *value)
1096 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1098 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
1100 return attributes_GetUINT32(&media_type->attributes, key, value);
1103 static HRESULT WINAPI audio_mediatype_GetUINT64(IMFAudioMediaType *iface, REFGUID key, UINT64 *value)
1105 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1107 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
1109 return attributes_GetUINT64(&media_type->attributes, key, value);
1112 static HRESULT WINAPI audio_mediatype_GetDouble(IMFAudioMediaType *iface, REFGUID key, double *value)
1114 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1116 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
1118 return attributes_GetDouble(&media_type->attributes, key, value);
1121 static HRESULT WINAPI audio_mediatype_GetGUID(IMFAudioMediaType *iface, REFGUID key, GUID *value)
1123 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1125 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
1127 return attributes_GetGUID(&media_type->attributes, key, value);
1130 static HRESULT WINAPI audio_mediatype_GetStringLength(IMFAudioMediaType *iface, REFGUID key, UINT32 *length)
1132 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1134 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), length);
1136 return attributes_GetStringLength(&media_type->attributes, key, length);
1139 static HRESULT WINAPI audio_mediatype_GetString(IMFAudioMediaType *iface, REFGUID key, WCHAR *value,
1140 UINT32 size, UINT32 *length)
1142 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1144 TRACE("%p, %s, %p, %u, %p.\n", iface, debugstr_attr(key), value, size, length);
1146 return attributes_GetString(&media_type->attributes, key, value, size, length);
1149 static HRESULT WINAPI audio_mediatype_GetAllocatedString(IMFAudioMediaType *iface, REFGUID key,
1150 WCHAR **value, UINT32 *length)
1152 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1154 TRACE("%p, %s, %p, %p.\n", iface, debugstr_attr(key), value, length);
1156 return attributes_GetAllocatedString(&media_type->attributes, key, value, length);
1159 static HRESULT WINAPI audio_mediatype_GetBlobSize(IMFAudioMediaType *iface, REFGUID key, UINT32 *size)
1161 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1163 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), size);
1165 return attributes_GetBlobSize(&media_type->attributes, key, size);
1168 static HRESULT WINAPI audio_mediatype_GetBlob(IMFAudioMediaType *iface, REFGUID key, UINT8 *buf,
1169 UINT32 bufsize, UINT32 *blobsize)
1171 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1173 TRACE("%p, %s, %p, %u, %p.\n", iface, debugstr_attr(key), buf, bufsize, blobsize);
1175 return attributes_GetBlob(&media_type->attributes, key, buf, bufsize, blobsize);
1178 static HRESULT WINAPI audio_mediatype_GetAllocatedBlob(IMFAudioMediaType *iface, REFGUID key, UINT8 **buf, UINT32 *size)
1180 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1182 TRACE("%p, %s, %p, %p.\n", iface, debugstr_attr(key), buf, size);
1184 return attributes_GetAllocatedBlob(&media_type->attributes, key, buf, size);
1187 static HRESULT WINAPI audio_mediatype_GetUnknown(IMFAudioMediaType *iface, REFGUID key, REFIID riid, void **obj)
1189 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1191 TRACE("%p, %s, %s, %p.\n", iface, debugstr_attr(key), debugstr_guid(riid), obj);
1193 return attributes_GetUnknown(&media_type->attributes, key, riid, obj);
1196 static HRESULT WINAPI audio_mediatype_SetItem(IMFAudioMediaType *iface, REFGUID key, REFPROPVARIANT value)
1198 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1200 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_propvar(value));
1202 return attributes_SetItem(&media_type->attributes, key, value);
1205 static HRESULT WINAPI audio_mediatype_DeleteItem(IMFAudioMediaType *iface, REFGUID key)
1207 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1209 TRACE("%p, %s.\n", iface, debugstr_attr(key));
1211 return attributes_DeleteItem(&media_type->attributes, key);
1214 static HRESULT WINAPI audio_mediatype_DeleteAllItems(IMFAudioMediaType *iface)
1216 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1218 TRACE("%p.\n", iface);
1220 return attributes_DeleteAllItems(&media_type->attributes);
1223 static HRESULT WINAPI audio_mediatype_SetUINT32(IMFAudioMediaType *iface, REFGUID key, UINT32 value)
1225 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1227 TRACE("%p, %s, %u.\n", iface, debugstr_attr(key), value);
1229 return attributes_SetUINT32(&media_type->attributes, key, value);
1232 static HRESULT WINAPI audio_mediatype_SetUINT64(IMFAudioMediaType *iface, REFGUID key, UINT64 value)
1234 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1236 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), wine_dbgstr_longlong(value));
1238 return attributes_SetUINT64(&media_type->attributes, key, value);
1241 static HRESULT WINAPI audio_mediatype_SetDouble(IMFAudioMediaType *iface, REFGUID key, double value)
1243 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1245 TRACE("%p, %s, %f.\n", iface, debugstr_attr(key), value);
1247 return attributes_SetDouble(&media_type->attributes, key, value);
1250 static HRESULT WINAPI audio_mediatype_SetGUID(IMFAudioMediaType *iface, REFGUID key, REFGUID value)
1252 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1254 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_mf_guid(value));
1256 return attributes_SetGUID(&media_type->attributes, key, value);
1259 static HRESULT WINAPI audio_mediatype_SetString(IMFAudioMediaType *iface, REFGUID key, const WCHAR *value)
1261 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1263 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_w(value));
1265 return attributes_SetString(&media_type->attributes, key, value);
1268 static HRESULT WINAPI audio_mediatype_SetBlob(IMFAudioMediaType *iface, REFGUID key, const UINT8 *buf, UINT32 size)
1270 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1272 TRACE("%p, %s, %p, %u.\n", iface, debugstr_attr(key), buf, size);
1274 return attributes_SetBlob(&media_type->attributes, key, buf, size);
1277 static HRESULT WINAPI audio_mediatype_SetUnknown(IMFAudioMediaType *iface, REFGUID key, IUnknown *unknown)
1279 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1281 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), unknown);
1283 return attributes_SetUnknown(&media_type->attributes, key, unknown);
1286 static HRESULT WINAPI audio_mediatype_LockStore(IMFAudioMediaType *iface)
1288 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1290 TRACE("%p.\n", iface);
1292 return attributes_LockStore(&media_type->attributes);
1295 static HRESULT WINAPI audio_mediatype_UnlockStore(IMFAudioMediaType *iface)
1297 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1299 TRACE("%p.\n", iface);
1301 return attributes_UnlockStore(&media_type->attributes);
1304 static HRESULT WINAPI audio_mediatype_GetCount(IMFAudioMediaType *iface, UINT32 *count)
1306 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1308 TRACE("%p, %p.\n", iface, count);
1310 return attributes_GetCount(&media_type->attributes, count);
1313 static HRESULT WINAPI audio_mediatype_GetItemByIndex(IMFAudioMediaType *iface, UINT32 index, GUID *key, PROPVARIANT *value)
1315 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1317 TRACE("%p, %u, %p, %p.\n", iface, index, key, value);
1319 return attributes_GetItemByIndex(&media_type->attributes, index, key, value);
1322 static HRESULT WINAPI audio_mediatype_CopyAllItems(IMFAudioMediaType *iface, IMFAttributes *dest)
1324 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1326 TRACE("%p, %p.\n", iface, dest);
1328 return attributes_CopyAllItems(&media_type->attributes, dest);
1331 static HRESULT WINAPI audio_mediatype_GetMajorType(IMFAudioMediaType *iface, GUID *guid)
1333 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1335 TRACE("%p, %p.\n", iface, guid);
1337 return attributes_GetGUID(&media_type->attributes, &MF_MT_MAJOR_TYPE, guid);
1340 static HRESULT WINAPI audio_mediatype_IsCompressedFormat(IMFAudioMediaType *iface, BOOL *compressed)
1342 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1344 TRACE("%p, %p.\n", iface, compressed);
1346 return mediatype_is_compressed(media_type, compressed);
1349 static HRESULT WINAPI audio_mediatype_IsEqual(IMFAudioMediaType *iface, IMFMediaType *type, DWORD *flags)
1351 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1353 TRACE("%p, %p, %p.\n", iface, type, flags);
1355 return media_type_is_equal(media_type, type, flags);
1358 static HRESULT WINAPI audio_mediatype_GetRepresentation(IMFAudioMediaType *iface, GUID guid, void **representation)
1360 FIXME("%p, %s, %p.\n", iface, debugstr_guid(&guid), representation);
1362 return E_NOTIMPL;
1365 static HRESULT WINAPI audio_mediatype_FreeRepresentation(IMFAudioMediaType *iface, GUID guid, void *representation)
1367 FIXME("%p, %s, %p.\n", iface, debugstr_guid(&guid), representation);
1369 return E_NOTIMPL;
1372 static const WAVEFORMATEX * WINAPI audio_mediatype_GetAudioFormat(IMFAudioMediaType *iface)
1374 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1375 unsigned int size;
1376 HRESULT hr;
1378 TRACE("%p.\n", iface);
1380 CoTaskMemFree(media_type->audio_format);
1381 if (FAILED(hr = MFCreateWaveFormatExFromMFMediaType(&media_type->IMFMediaType_iface, &media_type->audio_format,
1382 &size, MFWaveFormatExConvertFlag_Normal)))
1384 WARN("Failed to create wave format description, hr %#x.\n", hr);
1387 return media_type->audio_format;
1390 static const IMFAudioMediaTypeVtbl audiomediatypevtbl =
1392 audio_mediatype_QueryInterface,
1393 audio_mediatype_AddRef,
1394 audio_mediatype_Release,
1395 audio_mediatype_GetItem,
1396 audio_mediatype_GetItemType,
1397 audio_mediatype_CompareItem,
1398 audio_mediatype_Compare,
1399 audio_mediatype_GetUINT32,
1400 audio_mediatype_GetUINT64,
1401 audio_mediatype_GetDouble,
1402 audio_mediatype_GetGUID,
1403 audio_mediatype_GetStringLength,
1404 audio_mediatype_GetString,
1405 audio_mediatype_GetAllocatedString,
1406 audio_mediatype_GetBlobSize,
1407 audio_mediatype_GetBlob,
1408 audio_mediatype_GetAllocatedBlob,
1409 audio_mediatype_GetUnknown,
1410 audio_mediatype_SetItem,
1411 audio_mediatype_DeleteItem,
1412 audio_mediatype_DeleteAllItems,
1413 audio_mediatype_SetUINT32,
1414 audio_mediatype_SetUINT64,
1415 audio_mediatype_SetDouble,
1416 audio_mediatype_SetGUID,
1417 audio_mediatype_SetString,
1418 audio_mediatype_SetBlob,
1419 audio_mediatype_SetUnknown,
1420 audio_mediatype_LockStore,
1421 audio_mediatype_UnlockStore,
1422 audio_mediatype_GetCount,
1423 audio_mediatype_GetItemByIndex,
1424 audio_mediatype_CopyAllItems,
1425 audio_mediatype_GetMajorType,
1426 audio_mediatype_IsCompressedFormat,
1427 audio_mediatype_IsEqual,
1428 audio_mediatype_GetRepresentation,
1429 audio_mediatype_FreeRepresentation,
1430 audio_mediatype_GetAudioFormat,
1433 static HRESULT create_media_type(struct media_type **ret)
1435 struct media_type *object;
1436 HRESULT hr;
1438 if (!(object = calloc(1, sizeof(*object))))
1439 return E_OUTOFMEMORY;
1441 if (FAILED(hr = init_attributes_object(&object->attributes, 0)))
1443 free(object);
1444 return hr;
1446 object->IMFMediaType_iface.lpVtbl = &mediatypevtbl;
1447 object->IMFVideoMediaType_iface.lpVtbl = &videomediatypevtbl;
1448 object->IMFAudioMediaType_iface.lpVtbl = &audiomediatypevtbl;
1450 *ret = object;
1452 return S_OK;
1455 /***********************************************************************
1456 * MFCreateMediaType (mfplat.@)
1458 HRESULT WINAPI MFCreateMediaType(IMFMediaType **media_type)
1460 struct media_type *object;
1461 HRESULT hr;
1463 TRACE("%p.\n", media_type);
1465 if (!media_type)
1466 return E_INVALIDARG;
1468 if (FAILED(hr = create_media_type(&object)))
1469 return hr;
1471 *media_type = &object->IMFMediaType_iface;
1473 TRACE("Created media type %p.\n", *media_type);
1475 return S_OK;
1478 static HRESULT WINAPI stream_descriptor_QueryInterface(IMFStreamDescriptor *iface, REFIID riid, void **out)
1480 TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), out);
1482 if (IsEqualIID(riid, &IID_IMFStreamDescriptor) ||
1483 IsEqualIID(riid, &IID_IMFAttributes) ||
1484 IsEqualIID(riid, &IID_IUnknown))
1486 *out = iface;
1487 IMFStreamDescriptor_AddRef(iface);
1488 return S_OK;
1491 WARN("Unsupported %s.\n", debugstr_guid(riid));
1492 *out = NULL;
1493 return E_NOINTERFACE;
1496 static ULONG WINAPI stream_descriptor_AddRef(IMFStreamDescriptor *iface)
1498 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1499 ULONG refcount = InterlockedIncrement(&stream_desc->attributes.ref);
1501 TRACE("%p, refcount %u.\n", iface, refcount);
1503 return refcount;
1506 static ULONG WINAPI stream_descriptor_Release(IMFStreamDescriptor *iface)
1508 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1509 ULONG refcount = InterlockedDecrement(&stream_desc->attributes.ref);
1510 unsigned int i;
1512 TRACE("%p, refcount %u.\n", iface, refcount);
1514 if (!refcount)
1516 for (i = 0; i < stream_desc->media_types_count; ++i)
1518 if (stream_desc->media_types[i])
1519 IMFMediaType_Release(stream_desc->media_types[i]);
1521 free(stream_desc->media_types);
1522 if (stream_desc->current_type)
1523 IMFMediaType_Release(stream_desc->current_type);
1524 clear_attributes_object(&stream_desc->attributes);
1525 free(stream_desc);
1528 return refcount;
1531 static HRESULT WINAPI stream_descriptor_GetItem(IMFStreamDescriptor *iface, REFGUID key, PROPVARIANT *value)
1533 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1535 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
1537 return attributes_GetItem(&stream_desc->attributes, key, value);
1540 static HRESULT WINAPI stream_descriptor_GetItemType(IMFStreamDescriptor *iface, REFGUID key, MF_ATTRIBUTE_TYPE *type)
1542 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1544 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), type);
1546 return attributes_GetItemType(&stream_desc->attributes, key, type);
1549 static HRESULT WINAPI stream_descriptor_CompareItem(IMFStreamDescriptor *iface, REFGUID key, REFPROPVARIANT value,
1550 BOOL *result)
1552 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1554 TRACE("%p, %s, %s, %p.\n", iface, debugstr_attr(key), debugstr_propvar(value), result);
1556 return attributes_CompareItem(&stream_desc->attributes, key, value, result);
1559 static HRESULT WINAPI stream_descriptor_Compare(IMFStreamDescriptor *iface, IMFAttributes *theirs,
1560 MF_ATTRIBUTES_MATCH_TYPE type, BOOL *result)
1562 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1564 TRACE("%p, %p, %d, %p.\n", iface, theirs, type, result);
1566 return attributes_Compare(&stream_desc->attributes, theirs, type, result);
1569 static HRESULT WINAPI stream_descriptor_GetUINT32(IMFStreamDescriptor *iface, REFGUID key, UINT32 *value)
1571 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1573 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
1575 return attributes_GetUINT32(&stream_desc->attributes, key, value);
1578 static HRESULT WINAPI stream_descriptor_GetUINT64(IMFStreamDescriptor *iface, REFGUID key, UINT64 *value)
1580 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1582 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
1584 return attributes_GetUINT64(&stream_desc->attributes, key, value);
1587 static HRESULT WINAPI stream_descriptor_GetDouble(IMFStreamDescriptor *iface, REFGUID key, double *value)
1589 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1591 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
1593 return attributes_GetDouble(&stream_desc->attributes, key, value);
1596 static HRESULT WINAPI stream_descriptor_GetGUID(IMFStreamDescriptor *iface, REFGUID key, GUID *value)
1598 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1600 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
1602 return attributes_GetGUID(&stream_desc->attributes, key, value);
1605 static HRESULT WINAPI stream_descriptor_GetStringLength(IMFStreamDescriptor *iface, REFGUID key, UINT32 *length)
1607 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1609 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), length);
1611 return attributes_GetStringLength(&stream_desc->attributes, key, length);
1614 static HRESULT WINAPI stream_descriptor_GetString(IMFStreamDescriptor *iface, REFGUID key, WCHAR *value,
1615 UINT32 size, UINT32 *length)
1617 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1619 TRACE("%p, %s, %p, %u, %p.\n", iface, debugstr_attr(key), value, size, length);
1621 return attributes_GetString(&stream_desc->attributes, key, value, size, length);
1624 static HRESULT WINAPI stream_descriptor_GetAllocatedString(IMFStreamDescriptor *iface, REFGUID key,
1625 WCHAR **value, UINT32 *length)
1627 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1629 TRACE("%p, %s, %p, %p.\n", iface, debugstr_attr(key), value, length);
1631 return attributes_GetAllocatedString(&stream_desc->attributes, key, value, length);
1634 static HRESULT WINAPI stream_descriptor_GetBlobSize(IMFStreamDescriptor *iface, REFGUID key, UINT32 *size)
1636 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1638 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), size);
1640 return attributes_GetBlobSize(&stream_desc->attributes, key, size);
1643 static HRESULT WINAPI stream_descriptor_GetBlob(IMFStreamDescriptor *iface, REFGUID key, UINT8 *buf,
1644 UINT32 bufsize, UINT32 *blobsize)
1646 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1648 TRACE("%p, %s, %p, %u, %p.\n", iface, debugstr_attr(key), buf, bufsize, blobsize);
1650 return attributes_GetBlob(&stream_desc->attributes, key, buf, bufsize, blobsize);
1653 static HRESULT WINAPI stream_descriptor_GetAllocatedBlob(IMFStreamDescriptor *iface, REFGUID key, UINT8 **buf,
1654 UINT32 *size)
1656 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1658 TRACE("%p, %s, %p, %p.\n", iface, debugstr_attr(key), buf, size);
1660 return attributes_GetAllocatedBlob(&stream_desc->attributes, key, buf, size);
1663 static HRESULT WINAPI stream_descriptor_GetUnknown(IMFStreamDescriptor *iface, REFGUID key, REFIID riid, void **out)
1665 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1667 TRACE("%p, %s, %s, %p.\n", iface, debugstr_attr(key), debugstr_guid(riid), out);
1669 return attributes_GetUnknown(&stream_desc->attributes, key, riid, out);
1672 static HRESULT WINAPI stream_descriptor_SetItem(IMFStreamDescriptor *iface, REFGUID key, REFPROPVARIANT value)
1674 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1676 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_propvar(value));
1678 return attributes_SetItem(&stream_desc->attributes, key, value);
1681 static HRESULT WINAPI stream_descriptor_DeleteItem(IMFStreamDescriptor *iface, REFGUID key)
1683 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1685 TRACE("%p, %s.\n", iface, debugstr_attr(key));
1687 return attributes_DeleteItem(&stream_desc->attributes, key);
1690 static HRESULT WINAPI stream_descriptor_DeleteAllItems(IMFStreamDescriptor *iface)
1692 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1694 TRACE("%p.\n", iface);
1696 return attributes_DeleteAllItems(&stream_desc->attributes);
1699 static HRESULT WINAPI stream_descriptor_SetUINT32(IMFStreamDescriptor *iface, REFGUID key, UINT32 value)
1701 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1703 TRACE("%p, %s, %u.\n", iface, debugstr_attr(key), value);
1705 return attributes_SetUINT32(&stream_desc->attributes, key, value);
1708 static HRESULT WINAPI stream_descriptor_SetUINT64(IMFStreamDescriptor *iface, REFGUID key, UINT64 value)
1710 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1712 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), wine_dbgstr_longlong(value));
1714 return attributes_SetUINT64(&stream_desc->attributes, key, value);
1717 static HRESULT WINAPI stream_descriptor_SetDouble(IMFStreamDescriptor *iface, REFGUID key, double value)
1719 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1721 TRACE("%p, %s, %f.\n", iface, debugstr_attr(key), value);
1723 return attributes_SetDouble(&stream_desc->attributes, key, value);
1726 static HRESULT WINAPI stream_descriptor_SetGUID(IMFStreamDescriptor *iface, REFGUID key, REFGUID value)
1728 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1730 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_mf_guid(value));
1732 return attributes_SetGUID(&stream_desc->attributes, key, value);
1735 static HRESULT WINAPI stream_descriptor_SetString(IMFStreamDescriptor *iface, REFGUID key, const WCHAR *value)
1737 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1739 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_w(value));
1741 return attributes_SetString(&stream_desc->attributes, key, value);
1744 static HRESULT WINAPI stream_descriptor_SetBlob(IMFStreamDescriptor *iface, REFGUID key, const UINT8 *buf, UINT32 size)
1746 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1748 TRACE("%p, %s, %p, %u.\n", iface, debugstr_attr(key), buf, size);
1750 return attributes_SetBlob(&stream_desc->attributes, key, buf, size);
1753 static HRESULT WINAPI stream_descriptor_SetUnknown(IMFStreamDescriptor *iface, REFGUID key, IUnknown *unknown)
1755 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1757 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), unknown);
1759 return attributes_SetUnknown(&stream_desc->attributes, key, unknown);
1762 static HRESULT WINAPI stream_descriptor_LockStore(IMFStreamDescriptor *iface)
1764 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1766 TRACE("%p.\n", iface);
1768 return attributes_LockStore(&stream_desc->attributes);
1771 static HRESULT WINAPI stream_descriptor_UnlockStore(IMFStreamDescriptor *iface)
1773 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1775 TRACE("%p.\n", iface);
1777 return attributes_UnlockStore(&stream_desc->attributes);
1780 static HRESULT WINAPI stream_descriptor_GetCount(IMFStreamDescriptor *iface, UINT32 *count)
1782 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1784 TRACE("%p, %p.\n", iface, count);
1786 return attributes_GetCount(&stream_desc->attributes, count);
1789 static HRESULT WINAPI stream_descriptor_GetItemByIndex(IMFStreamDescriptor *iface, UINT32 index, GUID *key,
1790 PROPVARIANT *value)
1792 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1794 TRACE("%p, %u, %p, %p.\n", iface, index, key, value);
1796 return attributes_GetItemByIndex(&stream_desc->attributes, index, key, value);
1799 static HRESULT WINAPI stream_descriptor_CopyAllItems(IMFStreamDescriptor *iface, IMFAttributes *dest)
1801 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1803 TRACE("%p, %p.\n", iface, dest);
1805 return attributes_CopyAllItems(&stream_desc->attributes, dest);
1808 static HRESULT WINAPI stream_descriptor_GetStreamIdentifier(IMFStreamDescriptor *iface, DWORD *identifier)
1810 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1812 TRACE("%p, %p.\n", iface, identifier);
1814 *identifier = stream_desc->identifier;
1816 return S_OK;
1819 static HRESULT WINAPI stream_descriptor_GetMediaTypeHandler(IMFStreamDescriptor *iface, IMFMediaTypeHandler **handler)
1821 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1823 TRACE("%p, %p.\n", iface, handler);
1825 *handler = &stream_desc->IMFMediaTypeHandler_iface;
1826 IMFMediaTypeHandler_AddRef(*handler);
1828 return S_OK;
1831 static const IMFStreamDescriptorVtbl streamdescriptorvtbl =
1833 stream_descriptor_QueryInterface,
1834 stream_descriptor_AddRef,
1835 stream_descriptor_Release,
1836 stream_descriptor_GetItem,
1837 stream_descriptor_GetItemType,
1838 stream_descriptor_CompareItem,
1839 stream_descriptor_Compare,
1840 stream_descriptor_GetUINT32,
1841 stream_descriptor_GetUINT64,
1842 stream_descriptor_GetDouble,
1843 stream_descriptor_GetGUID,
1844 stream_descriptor_GetStringLength,
1845 stream_descriptor_GetString,
1846 stream_descriptor_GetAllocatedString,
1847 stream_descriptor_GetBlobSize,
1848 stream_descriptor_GetBlob,
1849 stream_descriptor_GetAllocatedBlob,
1850 stream_descriptor_GetUnknown,
1851 stream_descriptor_SetItem,
1852 stream_descriptor_DeleteItem,
1853 stream_descriptor_DeleteAllItems,
1854 stream_descriptor_SetUINT32,
1855 stream_descriptor_SetUINT64,
1856 stream_descriptor_SetDouble,
1857 stream_descriptor_SetGUID,
1858 stream_descriptor_SetString,
1859 stream_descriptor_SetBlob,
1860 stream_descriptor_SetUnknown,
1861 stream_descriptor_LockStore,
1862 stream_descriptor_UnlockStore,
1863 stream_descriptor_GetCount,
1864 stream_descriptor_GetItemByIndex,
1865 stream_descriptor_CopyAllItems,
1866 stream_descriptor_GetStreamIdentifier,
1867 stream_descriptor_GetMediaTypeHandler
1870 static HRESULT WINAPI mediatype_handler_QueryInterface(IMFMediaTypeHandler *iface, REFIID riid, void **obj)
1872 TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), obj);
1874 if (IsEqualIID(riid, &IID_IMFMediaTypeHandler) ||
1875 IsEqualIID(riid, &IID_IUnknown))
1877 *obj = iface;
1878 IMFMediaTypeHandler_AddRef(iface);
1879 return S_OK;
1882 WARN("Unsupported %s.\n", debugstr_guid(riid));
1883 *obj = NULL;
1884 return E_NOINTERFACE;
1887 static ULONG WINAPI mediatype_handler_AddRef(IMFMediaTypeHandler *iface)
1889 struct stream_desc *stream_desc = impl_from_IMFMediaTypeHandler(iface);
1890 return IMFStreamDescriptor_AddRef(&stream_desc->IMFStreamDescriptor_iface);
1893 static ULONG WINAPI mediatype_handler_Release(IMFMediaTypeHandler *iface)
1895 struct stream_desc *stream_desc = impl_from_IMFMediaTypeHandler(iface);
1896 return IMFStreamDescriptor_Release(&stream_desc->IMFStreamDescriptor_iface);
1899 static BOOL stream_descriptor_is_mediatype_supported(IMFMediaType *media_type, IMFMediaType *candidate)
1901 DWORD flags = 0;
1903 if (FAILED(IMFMediaType_IsEqual(media_type, candidate, &flags)))
1904 return FALSE;
1906 return (flags & (MF_MEDIATYPE_EQUAL_MAJOR_TYPES | MF_MEDIATYPE_EQUAL_FORMAT_TYPES)) ==
1907 (MF_MEDIATYPE_EQUAL_MAJOR_TYPES | MF_MEDIATYPE_EQUAL_FORMAT_TYPES);
1910 static HRESULT WINAPI mediatype_handler_IsMediaTypeSupported(IMFMediaTypeHandler *iface, IMFMediaType *in_type,
1911 IMFMediaType **out_type)
1913 struct stream_desc *stream_desc = impl_from_IMFMediaTypeHandler(iface);
1914 BOOL supported = FALSE;
1915 unsigned int i;
1917 TRACE("%p, %p, %p.\n", iface, in_type, out_type);
1919 if (!in_type)
1920 return E_POINTER;
1922 if (out_type)
1923 *out_type = NULL;
1925 EnterCriticalSection(&stream_desc->attributes.cs);
1927 supported = stream_desc->current_type && stream_descriptor_is_mediatype_supported(stream_desc->current_type, in_type);
1928 if (!supported)
1930 for (i = 0; i < stream_desc->media_types_count; ++i)
1932 if ((supported = stream_descriptor_is_mediatype_supported(stream_desc->media_types[i], in_type)))
1933 break;
1937 LeaveCriticalSection(&stream_desc->attributes.cs);
1939 return supported ? S_OK : MF_E_INVALIDMEDIATYPE;
1942 static HRESULT WINAPI mediatype_handler_GetMediaTypeCount(IMFMediaTypeHandler *iface, DWORD *count)
1944 struct stream_desc *stream_desc = impl_from_IMFMediaTypeHandler(iface);
1946 TRACE("%p, %p.\n", iface, count);
1948 *count = stream_desc->media_types_count;
1950 return S_OK;
1953 static HRESULT WINAPI mediatype_handler_GetMediaTypeByIndex(IMFMediaTypeHandler *iface, DWORD index,
1954 IMFMediaType **type)
1956 struct stream_desc *stream_desc = impl_from_IMFMediaTypeHandler(iface);
1958 TRACE("%p, %u, %p.\n", iface, index, type);
1960 if (index >= stream_desc->media_types_count)
1961 return MF_E_NO_MORE_TYPES;
1963 if (stream_desc->media_types[index])
1965 *type = stream_desc->media_types[index];
1966 IMFMediaType_AddRef(*type);
1969 return stream_desc->media_types[index] ? S_OK : E_FAIL;
1972 static HRESULT WINAPI mediatype_handler_SetCurrentMediaType(IMFMediaTypeHandler *iface, IMFMediaType *type)
1974 struct stream_desc *stream_desc = impl_from_IMFMediaTypeHandler(iface);
1976 TRACE("%p, %p.\n", iface, type);
1978 if (!type)
1979 return E_POINTER;
1981 EnterCriticalSection(&stream_desc->attributes.cs);
1982 if (stream_desc->current_type)
1983 IMFMediaType_Release(stream_desc->current_type);
1984 stream_desc->current_type = type;
1985 IMFMediaType_AddRef(stream_desc->current_type);
1986 LeaveCriticalSection(&stream_desc->attributes.cs);
1988 return S_OK;
1991 static HRESULT WINAPI mediatype_handler_GetCurrentMediaType(IMFMediaTypeHandler *iface, IMFMediaType **type)
1993 struct stream_desc *stream_desc = impl_from_IMFMediaTypeHandler(iface);
1994 HRESULT hr = S_OK;
1996 TRACE("%p, %p.\n", iface, type);
1998 EnterCriticalSection(&stream_desc->attributes.cs);
1999 if (stream_desc->current_type)
2001 *type = stream_desc->current_type;
2002 IMFMediaType_AddRef(*type);
2004 else
2005 hr = MF_E_NOT_INITIALIZED;
2006 LeaveCriticalSection(&stream_desc->attributes.cs);
2008 return hr;
2011 static HRESULT WINAPI mediatype_handler_GetMajorType(IMFMediaTypeHandler *iface, GUID *type)
2013 struct stream_desc *stream_desc = impl_from_IMFMediaTypeHandler(iface);
2014 HRESULT hr;
2016 TRACE("%p, %p.\n", iface, type);
2018 EnterCriticalSection(&stream_desc->attributes.cs);
2019 hr = IMFMediaType_GetGUID(stream_desc->current_type ? stream_desc->current_type :
2020 stream_desc->media_types[0], &MF_MT_MAJOR_TYPE, type);
2021 LeaveCriticalSection(&stream_desc->attributes.cs);
2023 return hr;
2026 static const IMFMediaTypeHandlerVtbl mediatypehandlervtbl =
2028 mediatype_handler_QueryInterface,
2029 mediatype_handler_AddRef,
2030 mediatype_handler_Release,
2031 mediatype_handler_IsMediaTypeSupported,
2032 mediatype_handler_GetMediaTypeCount,
2033 mediatype_handler_GetMediaTypeByIndex,
2034 mediatype_handler_SetCurrentMediaType,
2035 mediatype_handler_GetCurrentMediaType,
2036 mediatype_handler_GetMajorType,
2039 /***********************************************************************
2040 * MFCreateStreamDescriptor (mfplat.@)
2042 HRESULT WINAPI MFCreateStreamDescriptor(DWORD identifier, DWORD count,
2043 IMFMediaType **types, IMFStreamDescriptor **descriptor)
2045 struct stream_desc *object;
2046 unsigned int i;
2047 HRESULT hr;
2049 TRACE("%d, %d, %p, %p.\n", identifier, count, types, descriptor);
2051 if (!count)
2052 return E_INVALIDARG;
2054 if (!(object = calloc(1, sizeof(*object))))
2055 return E_OUTOFMEMORY;
2057 if (FAILED(hr = init_attributes_object(&object->attributes, 0)))
2059 free(object);
2060 return hr;
2062 object->IMFStreamDescriptor_iface.lpVtbl = &streamdescriptorvtbl;
2063 object->IMFMediaTypeHandler_iface.lpVtbl = &mediatypehandlervtbl;
2064 object->identifier = identifier;
2065 object->media_types = calloc(count, sizeof(*object->media_types));
2066 if (!object->media_types)
2068 IMFStreamDescriptor_Release(&object->IMFStreamDescriptor_iface);
2069 return E_OUTOFMEMORY;
2071 for (i = 0; i < count; ++i)
2073 object->media_types[i] = types[i];
2074 if (object->media_types[i])
2075 IMFMediaType_AddRef(object->media_types[i]);
2077 object->media_types_count = count;
2079 *descriptor = &object->IMFStreamDescriptor_iface;
2081 return S_OK;
2084 static HRESULT WINAPI presentation_descriptor_QueryInterface(IMFPresentationDescriptor *iface, REFIID riid, void **out)
2086 TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), out);
2088 if (IsEqualIID(riid, &IID_IMFPresentationDescriptor) ||
2089 IsEqualIID(riid, &IID_IMFAttributes) ||
2090 IsEqualIID(riid, &IID_IUnknown))
2092 *out = iface;
2093 IMFPresentationDescriptor_AddRef(iface);
2094 return S_OK;
2097 WARN("Unsupported %s.\n", debugstr_guid(riid));
2098 *out = NULL;
2099 return E_NOINTERFACE;
2102 static ULONG WINAPI presentation_descriptor_AddRef(IMFPresentationDescriptor *iface)
2104 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2105 ULONG refcount = InterlockedIncrement(&presentation_desc->attributes.ref);
2107 TRACE("%p, refcount %u.\n", iface, refcount);
2109 return refcount;
2112 static ULONG WINAPI presentation_descriptor_Release(IMFPresentationDescriptor *iface)
2114 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2115 ULONG refcount = InterlockedDecrement(&presentation_desc->attributes.ref);
2116 unsigned int i;
2118 TRACE("%p, refcount %u.\n", iface, refcount);
2120 if (!refcount)
2122 for (i = 0; i < presentation_desc->count; ++i)
2124 if (presentation_desc->descriptors[i].descriptor)
2125 IMFStreamDescriptor_Release(presentation_desc->descriptors[i].descriptor);
2127 clear_attributes_object(&presentation_desc->attributes);
2128 free(presentation_desc->descriptors);
2129 free(presentation_desc);
2132 return refcount;
2135 static HRESULT WINAPI presentation_descriptor_GetItem(IMFPresentationDescriptor *iface, REFGUID key,
2136 PROPVARIANT *value)
2138 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2140 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
2142 return attributes_GetItem(&presentation_desc->attributes, key, value);
2145 static HRESULT WINAPI presentation_descriptor_GetItemType(IMFPresentationDescriptor *iface, REFGUID key,
2146 MF_ATTRIBUTE_TYPE *type)
2148 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2150 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), type);
2152 return attributes_GetItemType(&presentation_desc->attributes, key, type);
2155 static HRESULT WINAPI presentation_descriptor_CompareItem(IMFPresentationDescriptor *iface, REFGUID key,
2156 REFPROPVARIANT value, BOOL *result)
2158 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2160 TRACE("%p, %s, %s, %p.\n", iface, debugstr_attr(key), debugstr_propvar(value), result);
2162 return attributes_CompareItem(&presentation_desc->attributes, key, value, result);
2165 static HRESULT WINAPI presentation_descriptor_Compare(IMFPresentationDescriptor *iface, IMFAttributes *attrs,
2166 MF_ATTRIBUTES_MATCH_TYPE type, BOOL *result)
2168 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2170 TRACE("%p, %p, %d, %p.\n", iface, attrs, type, result);
2172 return attributes_Compare(&presentation_desc->attributes, attrs, type, result);
2175 static HRESULT WINAPI presentation_descriptor_GetUINT32(IMFPresentationDescriptor *iface, REFGUID key, UINT32 *value)
2177 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2179 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
2181 return attributes_GetUINT32(&presentation_desc->attributes, key, value);
2184 static HRESULT WINAPI presentation_descriptor_GetUINT64(IMFPresentationDescriptor *iface, REFGUID key, UINT64 *value)
2186 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2188 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
2190 return attributes_GetUINT64(&presentation_desc->attributes, key, value);
2193 static HRESULT WINAPI presentation_descriptor_GetDouble(IMFPresentationDescriptor *iface, REFGUID key, double *value)
2195 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2197 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
2199 return attributes_GetDouble(&presentation_desc->attributes, key, value);
2202 static HRESULT WINAPI presentation_descriptor_GetGUID(IMFPresentationDescriptor *iface, REFGUID key, GUID *value)
2204 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2206 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
2208 return attributes_GetGUID(&presentation_desc->attributes, key, value);
2211 static HRESULT WINAPI presentation_descriptor_GetStringLength(IMFPresentationDescriptor *iface, REFGUID key,
2212 UINT32 *length)
2214 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2216 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), length);
2218 return attributes_GetStringLength(&presentation_desc->attributes, key, length);
2221 static HRESULT WINAPI presentation_descriptor_GetString(IMFPresentationDescriptor *iface, REFGUID key, WCHAR *value,
2222 UINT32 size, UINT32 *length)
2224 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2226 TRACE("%p, %s, %p, %u, %p.\n", iface, debugstr_attr(key), value, size, length);
2228 return attributes_GetString(&presentation_desc->attributes, key, value, size, length);
2231 static HRESULT WINAPI presentation_descriptor_GetAllocatedString(IMFPresentationDescriptor *iface, REFGUID key,
2232 WCHAR **value, UINT32 *length)
2234 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2236 TRACE("%p, %s, %p, %p.\n", iface, debugstr_attr(key), value, length);
2238 return attributes_GetAllocatedString(&presentation_desc->attributes, key, value, length);
2241 static HRESULT WINAPI presentation_descriptor_GetBlobSize(IMFPresentationDescriptor *iface, REFGUID key, UINT32 *size)
2243 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2245 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), size);
2247 return attributes_GetBlobSize(&presentation_desc->attributes, key, size);
2250 static HRESULT WINAPI presentation_descriptor_GetBlob(IMFPresentationDescriptor *iface, REFGUID key, UINT8 *buf,
2251 UINT32 bufsize, UINT32 *blobsize)
2253 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2255 TRACE("%p, %s, %p, %u, %p.\n", iface, debugstr_attr(key), buf, bufsize, blobsize);
2257 return attributes_GetBlob(&presentation_desc->attributes, key, buf, bufsize, blobsize);
2260 static HRESULT WINAPI presentation_descriptor_GetAllocatedBlob(IMFPresentationDescriptor *iface, REFGUID key,
2261 UINT8 **buf, UINT32 *size)
2263 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2265 TRACE("%p, %s, %p, %p.\n", iface, debugstr_attr(key), buf, size);
2267 return attributes_GetAllocatedBlob(&presentation_desc->attributes, key, buf, size);
2270 static HRESULT WINAPI presentation_descriptor_GetUnknown(IMFPresentationDescriptor *iface, REFGUID key,
2271 REFIID riid, void **out)
2273 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2275 TRACE("%p, %s, %s, %p.\n", iface, debugstr_attr(key), debugstr_guid(riid), out);
2277 return attributes_GetUnknown(&presentation_desc->attributes, key, riid, out);
2280 static HRESULT WINAPI presentation_descriptor_SetItem(IMFPresentationDescriptor *iface, REFGUID key,
2281 REFPROPVARIANT value)
2283 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2285 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_propvar(value));
2287 return attributes_SetItem(&presentation_desc->attributes, key, value);
2290 static HRESULT WINAPI presentation_descriptor_DeleteItem(IMFPresentationDescriptor *iface, REFGUID key)
2292 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2294 TRACE("%p, %s.\n", iface, debugstr_attr(key));
2296 return attributes_DeleteItem(&presentation_desc->attributes, key);
2299 static HRESULT WINAPI presentation_descriptor_DeleteAllItems(IMFPresentationDescriptor *iface)
2301 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2303 TRACE("%p.\n", iface);
2305 return attributes_DeleteAllItems(&presentation_desc->attributes);
2308 static HRESULT WINAPI presentation_descriptor_SetUINT32(IMFPresentationDescriptor *iface, REFGUID key, UINT32 value)
2310 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2312 TRACE("%p, %s, %u.\n", iface, debugstr_attr(key), value);
2314 return attributes_SetUINT32(&presentation_desc->attributes, key, value);
2317 static HRESULT WINAPI presentation_descriptor_SetUINT64(IMFPresentationDescriptor *iface, REFGUID key, UINT64 value)
2319 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2321 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), wine_dbgstr_longlong(value));
2323 return attributes_SetUINT64(&presentation_desc->attributes, key, value);
2326 static HRESULT WINAPI presentation_descriptor_SetDouble(IMFPresentationDescriptor *iface, REFGUID key, double value)
2328 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2330 TRACE("%p, %s, %f.\n", iface, debugstr_attr(key), value);
2332 return attributes_SetDouble(&presentation_desc->attributes, key, value);
2335 static HRESULT WINAPI presentation_descriptor_SetGUID(IMFPresentationDescriptor *iface, REFGUID key, REFGUID value)
2337 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2339 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_mf_guid(value));
2341 return attributes_SetGUID(&presentation_desc->attributes, key, value);
2344 static HRESULT WINAPI presentation_descriptor_SetString(IMFPresentationDescriptor *iface, REFGUID key,
2345 const WCHAR *value)
2347 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2349 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_w(value));
2351 return attributes_SetString(&presentation_desc->attributes, key, value);
2354 static HRESULT WINAPI presentation_descriptor_SetBlob(IMFPresentationDescriptor *iface, REFGUID key, const UINT8 *buf,
2355 UINT32 size)
2357 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2359 TRACE("%p, %s, %p, %u.\n", iface, debugstr_attr(key), buf, size);
2361 return attributes_SetBlob(&presentation_desc->attributes, key, buf, size);
2364 static HRESULT WINAPI presentation_descriptor_SetUnknown(IMFPresentationDescriptor *iface, REFGUID key,
2365 IUnknown *unknown)
2367 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2369 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), unknown);
2371 return attributes_SetUnknown(&presentation_desc->attributes, key, unknown);
2374 static HRESULT WINAPI presentation_descriptor_LockStore(IMFPresentationDescriptor *iface)
2376 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2378 TRACE("%p.\n", iface);
2380 return attributes_LockStore(&presentation_desc->attributes);
2383 static HRESULT WINAPI presentation_descriptor_UnlockStore(IMFPresentationDescriptor *iface)
2385 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2387 TRACE("%p.\n", iface);
2389 return attributes_UnlockStore(&presentation_desc->attributes);
2392 static HRESULT WINAPI presentation_descriptor_GetCount(IMFPresentationDescriptor *iface, UINT32 *count)
2394 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2396 TRACE("%p, %p.\n", iface, count);
2398 return attributes_GetCount(&presentation_desc->attributes, count);
2401 static HRESULT WINAPI presentation_descriptor_GetItemByIndex(IMFPresentationDescriptor *iface, UINT32 index, GUID *key,
2402 PROPVARIANT *value)
2404 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2406 TRACE("%p, %u, %p, %p.\n", iface, index, key, value);
2408 return attributes_GetItemByIndex(&presentation_desc->attributes, index, key, value);
2411 static HRESULT WINAPI presentation_descriptor_CopyAllItems(IMFPresentationDescriptor *iface, IMFAttributes *dest)
2413 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2415 TRACE("%p, %p.\n", iface, dest);
2417 return attributes_CopyAllItems(&presentation_desc->attributes, dest);
2420 static HRESULT WINAPI presentation_descriptor_GetStreamDescriptorCount(IMFPresentationDescriptor *iface, DWORD *count)
2422 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2424 TRACE("%p, %p.\n", iface, count);
2426 *count = presentation_desc->count;
2428 return S_OK;
2431 static HRESULT WINAPI presentation_descriptor_GetStreamDescriptorByIndex(IMFPresentationDescriptor *iface, DWORD index,
2432 BOOL *selected, IMFStreamDescriptor **descriptor)
2434 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2436 TRACE("%p, %u, %p, %p.\n", iface, index, selected, descriptor);
2438 if (index >= presentation_desc->count)
2439 return E_INVALIDARG;
2441 EnterCriticalSection(&presentation_desc->attributes.cs);
2442 *selected = presentation_desc->descriptors[index].selected;
2443 LeaveCriticalSection(&presentation_desc->attributes.cs);
2445 *descriptor = presentation_desc->descriptors[index].descriptor;
2446 IMFStreamDescriptor_AddRef(*descriptor);
2448 return S_OK;
2451 static HRESULT WINAPI presentation_descriptor_SelectStream(IMFPresentationDescriptor *iface, DWORD index)
2453 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2455 TRACE("%p, %u.\n", iface, index);
2457 if (index >= presentation_desc->count)
2458 return E_INVALIDARG;
2460 EnterCriticalSection(&presentation_desc->attributes.cs);
2461 presentation_desc->descriptors[index].selected = TRUE;
2462 LeaveCriticalSection(&presentation_desc->attributes.cs);
2464 return S_OK;
2467 static HRESULT WINAPI presentation_descriptor_DeselectStream(IMFPresentationDescriptor *iface, DWORD index)
2469 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2471 TRACE("%p, %u.\n", iface, index);
2473 if (index >= presentation_desc->count)
2474 return E_INVALIDARG;
2476 EnterCriticalSection(&presentation_desc->attributes.cs);
2477 presentation_desc->descriptors[index].selected = FALSE;
2478 LeaveCriticalSection(&presentation_desc->attributes.cs);
2480 return S_OK;
2483 static HRESULT WINAPI presentation_descriptor_Clone(IMFPresentationDescriptor *iface,
2484 IMFPresentationDescriptor **descriptor)
2486 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2487 struct presentation_desc *object;
2488 unsigned int i;
2490 TRACE("%p, %p.\n", iface, descriptor);
2492 if (!(object = calloc(1, sizeof(*object))))
2493 return E_OUTOFMEMORY;
2495 presentation_descriptor_init(object, presentation_desc->count);
2497 EnterCriticalSection(&presentation_desc->attributes.cs);
2499 for (i = 0; i < presentation_desc->count; ++i)
2501 object->descriptors[i] = presentation_desc->descriptors[i];
2502 IMFStreamDescriptor_AddRef(object->descriptors[i].descriptor);
2505 attributes_CopyAllItems(&presentation_desc->attributes, (IMFAttributes *)&object->IMFPresentationDescriptor_iface);
2507 LeaveCriticalSection(&presentation_desc->attributes.cs);
2509 *descriptor = &object->IMFPresentationDescriptor_iface;
2511 return S_OK;
2514 static const IMFPresentationDescriptorVtbl presentationdescriptorvtbl =
2516 presentation_descriptor_QueryInterface,
2517 presentation_descriptor_AddRef,
2518 presentation_descriptor_Release,
2519 presentation_descriptor_GetItem,
2520 presentation_descriptor_GetItemType,
2521 presentation_descriptor_CompareItem,
2522 presentation_descriptor_Compare,
2523 presentation_descriptor_GetUINT32,
2524 presentation_descriptor_GetUINT64,
2525 presentation_descriptor_GetDouble,
2526 presentation_descriptor_GetGUID,
2527 presentation_descriptor_GetStringLength,
2528 presentation_descriptor_GetString,
2529 presentation_descriptor_GetAllocatedString,
2530 presentation_descriptor_GetBlobSize,
2531 presentation_descriptor_GetBlob,
2532 presentation_descriptor_GetAllocatedBlob,
2533 presentation_descriptor_GetUnknown,
2534 presentation_descriptor_SetItem,
2535 presentation_descriptor_DeleteItem,
2536 presentation_descriptor_DeleteAllItems,
2537 presentation_descriptor_SetUINT32,
2538 presentation_descriptor_SetUINT64,
2539 presentation_descriptor_SetDouble,
2540 presentation_descriptor_SetGUID,
2541 presentation_descriptor_SetString,
2542 presentation_descriptor_SetBlob,
2543 presentation_descriptor_SetUnknown,
2544 presentation_descriptor_LockStore,
2545 presentation_descriptor_UnlockStore,
2546 presentation_descriptor_GetCount,
2547 presentation_descriptor_GetItemByIndex,
2548 presentation_descriptor_CopyAllItems,
2549 presentation_descriptor_GetStreamDescriptorCount,
2550 presentation_descriptor_GetStreamDescriptorByIndex,
2551 presentation_descriptor_SelectStream,
2552 presentation_descriptor_DeselectStream,
2553 presentation_descriptor_Clone,
2556 static HRESULT presentation_descriptor_init(struct presentation_desc *object, DWORD count)
2558 HRESULT hr;
2560 if (FAILED(hr = init_attributes_object(&object->attributes, 0)))
2561 return hr;
2562 object->IMFPresentationDescriptor_iface.lpVtbl = &presentationdescriptorvtbl;
2563 if (!(object->descriptors = calloc(count, sizeof(*object->descriptors))))
2565 IMFPresentationDescriptor_Release(&object->IMFPresentationDescriptor_iface);
2566 return E_OUTOFMEMORY;
2568 object->count = count;
2570 return S_OK;
2573 /***********************************************************************
2574 * MFCreatePresentationDescriptor (mfplat.@)
2576 HRESULT WINAPI MFCreatePresentationDescriptor(DWORD count, IMFStreamDescriptor **descriptors,
2577 IMFPresentationDescriptor **out)
2579 struct presentation_desc *object;
2580 unsigned int i;
2581 HRESULT hr;
2583 TRACE("%u, %p, %p.\n", count, descriptors, out);
2585 if (!count)
2586 return E_INVALIDARG;
2588 for (i = 0; i < count; ++i)
2590 if (!descriptors[i])
2591 return E_INVALIDARG;
2594 if (!(object = calloc(1, sizeof(*object))))
2595 return E_OUTOFMEMORY;
2597 if (FAILED(hr = presentation_descriptor_init(object, count)))
2599 free(object);
2600 return hr;
2603 for (i = 0; i < count; ++i)
2605 object->descriptors[i].descriptor = descriptors[i];
2606 IMFStreamDescriptor_AddRef(object->descriptors[i].descriptor);
2609 *out = &object->IMFPresentationDescriptor_iface;
2611 return S_OK;
2614 struct uncompressed_video_format
2616 const GUID *subtype;
2617 unsigned char bytes_per_pixel;
2618 unsigned char alignment;
2619 unsigned char bottom_up;
2620 unsigned char yuv;
2623 static int __cdecl uncompressed_video_format_compare(const void *a, const void *b)
2625 const GUID *guid = a;
2626 const struct uncompressed_video_format *format = b;
2627 return memcmp(guid, format->subtype, sizeof(*guid));
2630 static const struct uncompressed_video_format video_formats[] =
2632 { &MFVideoFormat_RGB24, 4, 3, 1, 0 },
2633 { &MFVideoFormat_ARGB32, 4, 3, 1, 0 },
2634 { &MFVideoFormat_RGB32, 4, 3, 1, 0 },
2635 { &MFVideoFormat_RGB565, 2, 3, 1, 0 },
2636 { &MFVideoFormat_RGB555, 2, 3, 1, 0 },
2637 { &MFVideoFormat_A2R10G10B10, 4, 3, 1, 0 },
2638 { &MFVideoFormat_RGB8, 1, 3, 1, 0 },
2639 { &MFVideoFormat_L8, 1, 3, 1, 0 },
2640 { &MFVideoFormat_AYUV, 4, 3, 0, 1 },
2641 { &MFVideoFormat_I420, 1, 0, 0, 1 },
2642 { &MFVideoFormat_IMC1, 2, 3, 0, 1 },
2643 { &MFVideoFormat_IMC2, 1, 0, 0, 1 },
2644 { &MFVideoFormat_IMC3, 2, 3, 0, 1 },
2645 { &MFVideoFormat_IMC4, 1, 0, 0, 1 },
2646 { &MFVideoFormat_IYUV, 1, 0, 0, 1 },
2647 { &MFVideoFormat_NV12, 1, 0, 0, 1 },
2648 { &MFVideoFormat_D16, 2, 3, 0, 0 },
2649 { &MFVideoFormat_L16, 2, 3, 0, 0 },
2650 { &MFVideoFormat_UYVY, 2, 0, 0, 1 },
2651 { &MFVideoFormat_YUY2, 2, 0, 0, 1 },
2652 { &MFVideoFormat_YV12, 1, 0, 0, 1 },
2653 { &MFVideoFormat_A16B16G16R16F, 8, 3, 1, 0 },
2656 static struct uncompressed_video_format *mf_get_video_format(const GUID *subtype)
2658 return bsearch(subtype, video_formats, ARRAY_SIZE(video_formats), sizeof(*video_formats),
2659 uncompressed_video_format_compare);
2662 static unsigned int mf_get_stride_for_format(const struct uncompressed_video_format *format, unsigned int width)
2664 return (width * format->bytes_per_pixel + format->alignment) & ~format->alignment;
2667 unsigned int mf_format_get_stride(const GUID *subtype, unsigned int width, BOOL *is_yuv)
2669 struct uncompressed_video_format *format = mf_get_video_format(subtype);
2671 if (format)
2673 *is_yuv = format->yuv;
2674 return mf_get_stride_for_format(format, width);
2677 return 0;
2680 /***********************************************************************
2681 * MFGetStrideForBitmapInfoHeader (mfplat.@)
2683 HRESULT WINAPI MFGetStrideForBitmapInfoHeader(DWORD fourcc, DWORD width, LONG *stride)
2685 struct uncompressed_video_format *format;
2686 GUID subtype;
2688 TRACE("%s, %u, %p.\n", debugstr_fourcc(fourcc), width, stride);
2690 memcpy(&subtype, &MFVideoFormat_Base, sizeof(subtype));
2691 subtype.Data1 = fourcc;
2693 if (!(format = mf_get_video_format(&subtype)))
2695 *stride = 0;
2696 return MF_E_INVALIDMEDIATYPE;
2699 *stride = mf_get_stride_for_format(format, width);
2700 if (format->bottom_up)
2701 *stride *= -1;
2703 return S_OK;
2706 /***********************************************************************
2707 * MFCalculateImageSize (mfplat.@)
2709 HRESULT WINAPI MFCalculateImageSize(REFGUID subtype, UINT32 width, UINT32 height, UINT32 *size)
2711 struct uncompressed_video_format *format;
2712 unsigned int stride;
2714 TRACE("%s, %u, %u, %p.\n", debugstr_mf_guid(subtype), width, height, size);
2716 if (!(format = mf_get_video_format(subtype)))
2718 *size = 0;
2719 return E_INVALIDARG;
2722 switch (subtype->Data1)
2724 case MAKEFOURCC('I','M','C','2'):
2725 case MAKEFOURCC('I','M','C','4'):
2726 case MAKEFOURCC('N','V','1','2'):
2727 case MAKEFOURCC('Y','V','1','2'):
2728 case MAKEFOURCC('I','4','2','0'):
2729 case MAKEFOURCC('I','Y','U','V'):
2730 /* 2 x 2 block, interleaving UV for half the height */
2731 *size = ((width + 1) & ~1) * height * 3 / 2;
2732 break;
2733 case D3DFMT_L8:
2734 case D3DFMT_L16:
2735 case D3DFMT_D16:
2736 *size = width * format->bytes_per_pixel * height;
2737 break;
2738 default:
2739 stride = mf_get_stride_for_format(format, width);
2740 *size = stride * height;
2743 return S_OK;
2746 /***********************************************************************
2747 * MFGetPlaneSize (mfplat.@)
2749 HRESULT WINAPI MFGetPlaneSize(DWORD fourcc, DWORD width, DWORD height, DWORD *size)
2751 struct uncompressed_video_format *format;
2752 unsigned int stride;
2753 GUID subtype;
2755 TRACE("%s, %u, %u, %p.\n", debugstr_fourcc(fourcc), width, height, size);
2757 memcpy(&subtype, &MFVideoFormat_Base, sizeof(subtype));
2758 subtype.Data1 = fourcc;
2760 if (!(format = mf_get_video_format(&subtype)))
2761 return MF_E_INVALIDMEDIATYPE;
2763 stride = mf_get_stride_for_format(format, width);
2765 switch (fourcc)
2767 case MAKEFOURCC('I','M','C','2'):
2768 case MAKEFOURCC('I','M','C','4'):
2769 case MAKEFOURCC('N','V','1','2'):
2770 case MAKEFOURCC('Y','V','1','2'):
2771 case MAKEFOURCC('I','4','2','0'):
2772 case MAKEFOURCC('I','Y','U','V'):
2773 *size = stride * height * 3 / 2;
2774 break;
2775 default:
2776 *size = stride * height;
2779 return S_OK;
2782 /***********************************************************************
2783 * MFCompareFullToPartialMediaType (mfplat.@)
2785 BOOL WINAPI MFCompareFullToPartialMediaType(IMFMediaType *full_type, IMFMediaType *partial_type)
2787 BOOL result;
2788 GUID major;
2790 TRACE("%p, %p.\n", full_type, partial_type);
2792 if (FAILED(IMFMediaType_GetMajorType(partial_type, &major)))
2793 return FALSE;
2795 if (FAILED(IMFMediaType_Compare(partial_type, (IMFAttributes *)full_type, MF_ATTRIBUTES_MATCH_OUR_ITEMS, &result)))
2796 return FALSE;
2798 return result;
2801 /***********************************************************************
2802 * MFWrapMediaType (mfplat.@)
2804 HRESULT WINAPI MFWrapMediaType(IMFMediaType *original, REFGUID major, REFGUID subtype, IMFMediaType **ret)
2806 IMFMediaType *mediatype;
2807 UINT8 *buffer;
2808 UINT32 size;
2809 HRESULT hr;
2811 TRACE("%p, %s, %s, %p.\n", original, debugstr_guid(major), debugstr_guid(subtype), ret);
2813 if (FAILED(hr = MFGetAttributesAsBlobSize((IMFAttributes *)original, &size)))
2814 return hr;
2816 if (!(buffer = malloc(size)))
2817 return E_OUTOFMEMORY;
2819 if (FAILED(hr = MFGetAttributesAsBlob((IMFAttributes *)original, buffer, size)))
2820 goto failed;
2822 if (FAILED(hr = MFCreateMediaType(&mediatype)))
2823 goto failed;
2825 if (FAILED(hr = IMFMediaType_SetGUID(mediatype, &MF_MT_MAJOR_TYPE, major)))
2826 goto failed;
2828 if (FAILED(hr = IMFMediaType_SetGUID(mediatype, &MF_MT_SUBTYPE, subtype)))
2829 goto failed;
2831 if (FAILED(hr = IMFMediaType_SetBlob(mediatype, &MF_MT_WRAPPED_TYPE, buffer, size)))
2832 goto failed;
2834 *ret = mediatype;
2836 failed:
2837 free(buffer);
2839 return hr;
2842 /***********************************************************************
2843 * MFUnwrapMediaType (mfplat.@)
2845 HRESULT WINAPI MFUnwrapMediaType(IMFMediaType *wrapper, IMFMediaType **ret)
2847 IMFMediaType *mediatype;
2848 UINT8 *buffer;
2849 UINT32 size;
2850 HRESULT hr;
2852 TRACE("%p, %p.\n", wrapper, ret);
2854 if (FAILED(hr = MFCreateMediaType(&mediatype)))
2855 return hr;
2857 if (FAILED(hr = IMFMediaType_GetAllocatedBlob(wrapper, &MF_MT_WRAPPED_TYPE, &buffer, &size)))
2859 IMFMediaType_Release(mediatype);
2860 return hr;
2863 hr = MFInitAttributesFromBlob((IMFAttributes *)mediatype, buffer, size);
2864 CoTaskMemFree(buffer);
2865 if (FAILED(hr))
2866 return hr;
2868 *ret = mediatype;
2870 return S_OK;
2873 /***********************************************************************
2874 * MFCreateWaveFormatExFromMFMediaType (mfplat.@)
2876 HRESULT WINAPI MFCreateWaveFormatExFromMFMediaType(IMFMediaType *mediatype, WAVEFORMATEX **ret_format,
2877 UINT32 *size, UINT32 flags)
2879 WAVEFORMATEXTENSIBLE *format_ext = NULL;
2880 WAVEFORMATEX *format;
2881 GUID major, subtype;
2882 UINT32 value;
2883 HRESULT hr;
2885 TRACE("%p, %p, %p, %#x.\n", mediatype, ret_format, size, flags);
2887 if (FAILED(hr = IMFMediaType_GetGUID(mediatype, &MF_MT_MAJOR_TYPE, &major)))
2888 return hr;
2890 if (FAILED(hr = IMFMediaType_GetGUID(mediatype, &MF_MT_SUBTYPE, &subtype)))
2891 return hr;
2893 if (!IsEqualGUID(&major, &MFMediaType_Audio))
2894 return E_INVALIDARG;
2896 if (!IsEqualGUID(&subtype, &MFAudioFormat_PCM) && !IsEqualGUID(&subtype, &MFAudioFormat_Float))
2898 FIXME("Unsupported audio format %s.\n", debugstr_guid(&subtype));
2899 return E_NOTIMPL;
2902 /* FIXME: probably WAVE_FORMAT_MPEG/WAVE_FORMAT_MPEGLAYER3 should be handled separately. */
2903 if (flags == MFWaveFormatExConvertFlag_ForceExtensible)
2905 format_ext = CoTaskMemAlloc(sizeof(*format_ext));
2906 *size = sizeof(*format_ext);
2907 format = (WAVEFORMATEX *)format_ext;
2909 else
2911 format = CoTaskMemAlloc(sizeof(*format));
2912 *size = sizeof(*format);
2915 if (!format)
2916 return E_OUTOFMEMORY;
2918 memset(format, 0, *size);
2920 if (format_ext)
2921 format->wFormatTag = WAVE_FORMAT_EXTENSIBLE;
2922 else if (IsEqualGUID(&subtype, &MFAudioFormat_Float))
2923 format->wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
2924 else
2925 format->wFormatTag = WAVE_FORMAT_PCM;
2927 if (SUCCEEDED(IMFMediaType_GetUINT32(mediatype, &MF_MT_AUDIO_NUM_CHANNELS, &value)))
2928 format->nChannels = value;
2929 IMFMediaType_GetUINT32(mediatype, &MF_MT_AUDIO_SAMPLES_PER_SECOND, &format->nSamplesPerSec);
2930 IMFMediaType_GetUINT32(mediatype, &MF_MT_AUDIO_AVG_BYTES_PER_SECOND, &format->nAvgBytesPerSec);
2931 if (SUCCEEDED(IMFMediaType_GetUINT32(mediatype, &MF_MT_AUDIO_BLOCK_ALIGNMENT, &value)))
2932 format->nBlockAlign = value;
2933 if (SUCCEEDED(IMFMediaType_GetUINT32(mediatype, &MF_MT_AUDIO_BITS_PER_SAMPLE, &value)))
2934 format->wBitsPerSample = value;
2935 if (format_ext)
2937 format->cbSize = sizeof(*format_ext) - sizeof(*format);
2939 if (SUCCEEDED(IMFMediaType_GetUINT32(mediatype, &MF_MT_AUDIO_VALID_BITS_PER_SAMPLE, &value)))
2940 format_ext->Samples.wSamplesPerBlock = value;
2942 IMFMediaType_GetUINT32(mediatype, &MF_MT_AUDIO_CHANNEL_MASK, &format_ext->dwChannelMask);
2943 memcpy(&format_ext->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM, sizeof(format_ext->SubFormat));
2946 *ret_format = format;
2948 return S_OK;
2951 static void mediatype_set_uint32(IMFMediaType *mediatype, const GUID *attr, unsigned int value, HRESULT *hr)
2953 if (SUCCEEDED(*hr))
2954 *hr = IMFMediaType_SetUINT32(mediatype, attr, value);
2957 static void mediatype_set_guid(IMFMediaType *mediatype, const GUID *attr, const GUID *value, HRESULT *hr)
2959 if (SUCCEEDED(*hr))
2960 *hr = IMFMediaType_SetGUID(mediatype, attr, value);
2963 static void mediatype_set_blob(IMFMediaType *mediatype, const GUID *attr, const UINT8 *data,
2964 unsigned int size, HRESULT *hr)
2966 if (SUCCEEDED(*hr))
2967 *hr = IMFMediaType_SetBlob(mediatype, attr, data, size);
2970 /***********************************************************************
2971 * MFInitMediaTypeFromWaveFormatEx (mfplat.@)
2973 HRESULT WINAPI MFInitMediaTypeFromWaveFormatEx(IMFMediaType *mediatype, const WAVEFORMATEX *format, UINT32 size)
2975 const WAVEFORMATEXTENSIBLE *wfex = (const WAVEFORMATEXTENSIBLE *)format;
2976 GUID subtype;
2977 HRESULT hr;
2979 TRACE("%p, %p, %u.\n", mediatype, format, size);
2981 if (!mediatype || !format)
2982 return E_POINTER;
2984 if (format->cbSize + sizeof(*format) > size)
2985 return E_INVALIDARG;
2987 hr = IMFMediaType_DeleteAllItems(mediatype);
2989 mediatype_set_guid(mediatype, &MF_MT_MAJOR_TYPE, &MFMediaType_Audio, &hr);
2991 if (format->wFormatTag == WAVE_FORMAT_EXTENSIBLE)
2993 memcpy(&subtype, &wfex->SubFormat, sizeof(subtype));
2995 if (wfex->dwChannelMask)
2996 mediatype_set_uint32(mediatype, &MF_MT_AUDIO_CHANNEL_MASK, wfex->dwChannelMask, &hr);
2998 if (format->wBitsPerSample && wfex->Samples.wValidBitsPerSample)
2999 mediatype_set_uint32(mediatype, &MF_MT_AUDIO_VALID_BITS_PER_SAMPLE, wfex->Samples.wValidBitsPerSample, &hr);
3001 else
3003 memcpy(&subtype, &MFAudioFormat_Base, sizeof(subtype));
3004 subtype.Data1 = format->wFormatTag;
3006 mediatype_set_uint32(mediatype, &MF_MT_AUDIO_PREFER_WAVEFORMATEX, 1, &hr);
3008 mediatype_set_guid(mediatype, &MF_MT_SUBTYPE, &subtype, &hr);
3010 if (format->nChannels)
3011 mediatype_set_uint32(mediatype, &MF_MT_AUDIO_NUM_CHANNELS, format->nChannels, &hr);
3013 if (format->nSamplesPerSec)
3014 mediatype_set_uint32(mediatype, &MF_MT_AUDIO_SAMPLES_PER_SECOND, format->nSamplesPerSec, &hr);
3016 if (format->nAvgBytesPerSec)
3017 mediatype_set_uint32(mediatype, &MF_MT_AUDIO_AVG_BYTES_PER_SECOND, format->nAvgBytesPerSec, &hr);
3019 if (format->nBlockAlign)
3020 mediatype_set_uint32(mediatype, &MF_MT_AUDIO_BLOCK_ALIGNMENT, format->nBlockAlign, &hr);
3022 if (format->wBitsPerSample)
3023 mediatype_set_uint32(mediatype, &MF_MT_AUDIO_BITS_PER_SAMPLE, format->wBitsPerSample, &hr);
3025 if (IsEqualGUID(&subtype, &MFAudioFormat_PCM) ||
3026 IsEqualGUID(&subtype, &MFAudioFormat_Float))
3028 mediatype_set_uint32(mediatype, &MF_MT_ALL_SAMPLES_INDEPENDENT, 1, &hr);
3031 if (format->cbSize && format->wFormatTag != WAVE_FORMAT_EXTENSIBLE)
3032 mediatype_set_blob(mediatype, &MF_MT_USER_DATA, (const UINT8 *)(format + 1), format->cbSize, &hr);
3034 return hr;
3037 /***********************************************************************
3038 * MFCreateVideoMediaTypeFromSubtype (mfplat.@)
3040 HRESULT WINAPI MFCreateVideoMediaTypeFromSubtype(const GUID *subtype, IMFVideoMediaType **media_type)
3042 struct media_type *object;
3043 HRESULT hr;
3045 TRACE("%s, %p.\n", debugstr_guid(subtype), media_type);
3047 if (!media_type)
3048 return E_INVALIDARG;
3050 if (FAILED(hr = create_media_type(&object)))
3051 return hr;
3053 IMFMediaType_SetGUID(&object->IMFMediaType_iface, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
3054 IMFMediaType_SetGUID(&object->IMFMediaType_iface, &MF_MT_SUBTYPE, subtype);
3056 *media_type = &object->IMFVideoMediaType_iface;
3058 return S_OK;
3061 /***********************************************************************
3062 * MFCreateAudioMediaType (mfplat.@)
3064 HRESULT WINAPI MFCreateAudioMediaType(const WAVEFORMATEX *format, IMFAudioMediaType **media_type)
3066 struct media_type *object;
3067 HRESULT hr;
3069 TRACE("%p, %p.\n", format, media_type);
3071 if (!media_type)
3072 return E_INVALIDARG;
3074 if (FAILED(hr = create_media_type(&object)))
3075 return hr;
3077 if (FAILED(hr = MFInitMediaTypeFromWaveFormatEx(&object->IMFMediaType_iface, format, sizeof(*format) + format->cbSize)))
3079 IMFMediaType_Release(&object->IMFMediaType_iface);
3080 return hr;
3083 *media_type = &object->IMFAudioMediaType_iface;
3085 return S_OK;
3088 static void media_type_get_ratio(IMFMediaType *media_type, const GUID *attr, UINT32 *numerator,
3089 UINT32 *denominator)
3091 UINT64 value;
3093 if (SUCCEEDED(IMFMediaType_GetUINT64(media_type, attr, &value)))
3095 *numerator = value >> 32;
3096 *denominator = value;
3100 /***********************************************************************
3101 * MFCreateMFVideoFormatFromMFMediaType (mfplat.@)
3103 HRESULT WINAPI MFCreateMFVideoFormatFromMFMediaType(IMFMediaType *media_type, MFVIDEOFORMAT **video_format, UINT32 *size)
3105 UINT32 flags, palette_size = 0, avgrate;
3106 MFVIDEOFORMAT *format;
3107 INT32 stride;
3108 GUID guid;
3110 TRACE("%p, %p, %p.\n", media_type, video_format, size);
3112 *size = sizeof(*format);
3114 if (SUCCEEDED(IMFMediaType_GetBlobSize(media_type, &MF_MT_PALETTE, &palette_size)))
3115 *size += palette_size;
3117 if (!(format = CoTaskMemAlloc(*size)))
3118 return E_OUTOFMEMORY;
3120 *video_format = format;
3122 memset(format, 0, sizeof(*format));
3123 format->dwSize = *size;
3125 if (SUCCEEDED(IMFMediaType_GetGUID(media_type, &MF_MT_SUBTYPE, &guid)))
3127 memcpy(&format->guidFormat, &guid, sizeof(guid));
3128 format->surfaceInfo.Format = guid.Data1;
3131 media_type_get_ratio(media_type, &MF_MT_FRAME_SIZE, &format->videoInfo.dwWidth, &format->videoInfo.dwHeight);
3132 media_type_get_ratio(media_type, &MF_MT_PIXEL_ASPECT_RATIO, &format->videoInfo.PixelAspectRatio.Numerator,
3133 &format->videoInfo.PixelAspectRatio.Denominator);
3134 media_type_get_ratio(media_type, &MF_MT_FRAME_RATE, &format->videoInfo.FramesPerSecond.Numerator,
3135 &format->videoInfo.FramesPerSecond.Denominator);
3137 IMFMediaType_GetUINT32(media_type, &MF_MT_VIDEO_CHROMA_SITING, &format->videoInfo.SourceChromaSubsampling);
3138 IMFMediaType_GetUINT32(media_type, &MF_MT_INTERLACE_MODE, &format->videoInfo.InterlaceMode);
3139 IMFMediaType_GetUINT32(media_type, &MF_MT_TRANSFER_FUNCTION, &format->videoInfo.TransferFunction);
3140 IMFMediaType_GetUINT32(media_type, &MF_MT_VIDEO_PRIMARIES, &format->videoInfo.ColorPrimaries);
3141 IMFMediaType_GetUINT32(media_type, &MF_MT_YUV_MATRIX, &format->videoInfo.TransferMatrix);
3142 IMFMediaType_GetUINT32(media_type, &MF_MT_VIDEO_LIGHTING, &format->videoInfo.SourceLighting);
3143 IMFMediaType_GetUINT32(media_type, &MF_MT_VIDEO_NOMINAL_RANGE, &format->videoInfo.NominalRange);
3144 IMFMediaType_GetBlob(media_type, &MF_MT_GEOMETRIC_APERTURE, (UINT8 *)&format->videoInfo.GeometricAperture,
3145 sizeof(format->videoInfo.GeometricAperture), NULL);
3146 IMFMediaType_GetBlob(media_type, &MF_MT_MINIMUM_DISPLAY_APERTURE, (UINT8 *)&format->videoInfo.MinimumDisplayAperture,
3147 sizeof(format->videoInfo.MinimumDisplayAperture), NULL);
3149 /* Video flags. */
3150 if (SUCCEEDED(IMFMediaType_GetUINT32(media_type, &MF_MT_PAD_CONTROL_FLAGS, &flags)))
3151 format->videoInfo.VideoFlags |= flags;
3152 if (SUCCEEDED(IMFMediaType_GetUINT32(media_type, &MF_MT_SOURCE_CONTENT_HINT, &flags)))
3153 format->videoInfo.VideoFlags |= flags;
3154 if (SUCCEEDED(IMFMediaType_GetUINT32(media_type, &MF_MT_DRM_FLAGS, &flags)))
3155 format->videoInfo.VideoFlags |= flags;
3156 if (SUCCEEDED(IMFMediaType_GetUINT32(media_type, &MF_MT_PAN_SCAN_ENABLED, &flags)) && !!flags)
3158 format->videoInfo.VideoFlags |= MFVideoFlag_PanScanEnabled;
3159 IMFMediaType_GetBlob(media_type, &MF_MT_PAN_SCAN_APERTURE, (UINT8 *)&format->videoInfo.PanScanAperture,
3160 sizeof(format->videoInfo.PanScanAperture), NULL);
3162 if (SUCCEEDED(IMFMediaType_GetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, (UINT32 *)&stride)) && stride < 0)
3163 format->videoInfo.VideoFlags |= MFVideoFlag_BottomUpLinearRep;
3165 if (SUCCEEDED(IMFMediaType_GetUINT32(media_type, &MF_MT_AVG_BITRATE, &avgrate)))
3166 format->compressedInfo.AvgBitrate = avgrate;
3167 if (SUCCEEDED(IMFMediaType_GetUINT32(media_type, &MF_MT_AVG_BIT_ERROR_RATE, &avgrate)))
3168 format->compressedInfo.AvgBitErrorRate = avgrate;
3169 IMFMediaType_GetUINT32(media_type, &MF_MT_MAX_KEYFRAME_SPACING, &format->compressedInfo.MaxKeyFrameSpacing);
3171 /* Palette. */
3172 if (palette_size)
3174 format->surfaceInfo.PaletteEntries = palette_size / sizeof(*format->surfaceInfo.Palette);
3175 IMFMediaType_GetBlob(media_type, &MF_MT_PALETTE, (UINT8 *)format->surfaceInfo.Palette, palette_size, NULL);
3178 return S_OK;
3181 /***********************************************************************
3182 * MFConvertColorInfoToDXVA (mfplat.@)
3184 HRESULT WINAPI MFConvertColorInfoToDXVA(DWORD *dxva_info, const MFVIDEOFORMAT *format)
3186 struct
3188 UINT SampleFormat : 8;
3189 UINT VideoChromaSubsampling : 4;
3190 UINT NominalRange : 3;
3191 UINT VideoTransferMatrix : 3;
3192 UINT VideoLighting : 4;
3193 UINT VideoPrimaries : 5;
3194 UINT VideoTransferFunction : 5;
3195 } *dxva_format = (void *)dxva_info;
3197 TRACE("%p, %p.\n", dxva_info, format);
3199 if (format->videoInfo.InterlaceMode == MFVideoInterlace_MixedInterlaceOrProgressive)
3200 dxva_format->SampleFormat = DXVA2_SampleFieldInterleavedEvenFirst;
3201 else
3202 dxva_format->SampleFormat = format->videoInfo.InterlaceMode;
3204 dxva_format->VideoChromaSubsampling = format->videoInfo.SourceChromaSubsampling;
3205 dxva_format->NominalRange = format->videoInfo.NominalRange;
3206 dxva_format->VideoTransferMatrix = format->videoInfo.TransferMatrix;
3207 dxva_format->VideoLighting = format->videoInfo.SourceLighting;
3208 dxva_format->VideoPrimaries = format->videoInfo.ColorPrimaries;
3209 dxva_format->VideoTransferFunction = format->videoInfo.TransferFunction;
3211 return S_OK;
3214 struct frame_rate
3216 UINT64 rate;
3217 UINT64 frame_time;
3220 static int __cdecl frame_rate_compare(const void *a, const void *b)
3222 const UINT64 *rate = a;
3223 const struct frame_rate *known_rate = b;
3224 return *rate == known_rate->rate ? 0 : ( *rate < known_rate->rate ? 1 : -1 );
3227 /***********************************************************************
3228 * MFFrameRateToAverageTimePerFrame (mfplat.@)
3230 HRESULT WINAPI MFFrameRateToAverageTimePerFrame(UINT32 numerator, UINT32 denominator, UINT64 *avgframetime)
3232 static const struct frame_rate known_rates[] =
3234 #define KNOWN_RATE(n,d,ft) { ((UINT64)n << 32) | d, ft }
3235 KNOWN_RATE(60000, 1001, 166833),
3236 KNOWN_RATE(30000, 1001, 333667),
3237 KNOWN_RATE(24000, 1001, 417188),
3238 KNOWN_RATE(60, 1, 166667),
3239 KNOWN_RATE(50, 1, 200000),
3240 KNOWN_RATE(30, 1, 333333),
3241 KNOWN_RATE(25, 1, 400000),
3242 KNOWN_RATE(24, 1, 416667),
3243 #undef KNOWN_RATE
3245 UINT64 rate = ((UINT64)numerator << 32) | denominator;
3246 const struct frame_rate *entry;
3248 TRACE("%u, %u, %p.\n", numerator, denominator, avgframetime);
3250 if ((entry = bsearch(&rate, known_rates, ARRAY_SIZE(known_rates), sizeof(*known_rates),
3251 frame_rate_compare)))
3253 *avgframetime = entry->frame_time;
3255 else
3256 *avgframetime = numerator ? denominator * (UINT64)10000000 / numerator : 0;
3258 return S_OK;
3261 /***********************************************************************
3262 * MFMapDXGIFormatToDX9Format (mfplat.@)
3264 DWORD WINAPI MFMapDXGIFormatToDX9Format(DXGI_FORMAT dxgi_format)
3266 switch (dxgi_format)
3268 case DXGI_FORMAT_R32G32B32A32_FLOAT:
3269 return D3DFMT_A32B32G32R32F;
3270 case DXGI_FORMAT_R16G16B16A16_FLOAT:
3271 return D3DFMT_A16B16G16R16F;
3272 case DXGI_FORMAT_R16G16B16A16_UNORM:
3273 return D3DFMT_A16B16G16R16;
3274 case DXGI_FORMAT_R16G16B16A16_SNORM:
3275 return D3DFMT_Q16W16V16U16;
3276 case DXGI_FORMAT_R32G32_FLOAT:
3277 return D3DFMT_G32R32F;
3278 case DXGI_FORMAT_R10G10B10A2_UNORM:
3279 return D3DFMT_A2B10G10R10;
3280 case DXGI_FORMAT_R8G8B8A8_SNORM:
3281 return D3DFMT_Q8W8V8U8;
3282 case DXGI_FORMAT_R16G16_FLOAT:
3283 return D3DFMT_G16R16F;
3284 case DXGI_FORMAT_R16G16_UNORM:
3285 return D3DFMT_G16R16;
3286 case DXGI_FORMAT_R16G16_SNORM:
3287 return D3DFMT_V16U16;
3288 case DXGI_FORMAT_D32_FLOAT:
3289 return D3DFMT_D32F_LOCKABLE;
3290 case DXGI_FORMAT_R32_FLOAT:
3291 return D3DFMT_R32F;
3292 case DXGI_FORMAT_D24_UNORM_S8_UINT:
3293 return D3DFMT_D24S8;
3294 case DXGI_FORMAT_R8G8_SNORM:
3295 return D3DFMT_V8U8;
3296 case DXGI_FORMAT_R16_FLOAT:
3297 return D3DFMT_R16F;
3298 case DXGI_FORMAT_D16_UNORM:
3299 return D3DFMT_D16_LOCKABLE;
3300 case DXGI_FORMAT_R16_UNORM:
3301 return D3DFMT_L16;
3302 case DXGI_FORMAT_R8_UNORM:
3303 return D3DFMT_L8;
3304 case DXGI_FORMAT_A8_UNORM:
3305 return D3DFMT_A8;
3306 case DXGI_FORMAT_BC1_UNORM:
3307 case DXGI_FORMAT_BC1_UNORM_SRGB:
3308 return D3DFMT_DXT1;
3309 case DXGI_FORMAT_BC2_UNORM:
3310 case DXGI_FORMAT_BC2_UNORM_SRGB:
3311 return D3DFMT_DXT2;
3312 case DXGI_FORMAT_BC3_UNORM:
3313 case DXGI_FORMAT_BC3_UNORM_SRGB:
3314 return D3DFMT_DXT4;
3315 case DXGI_FORMAT_R8G8B8A8_UNORM:
3316 return D3DFMT_A8B8G8R8;
3317 case DXGI_FORMAT_B8G8R8A8_UNORM:
3318 case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
3319 case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
3320 return D3DFMT_A8R8G8B8;
3321 case DXGI_FORMAT_B8G8R8X8_UNORM:
3322 case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB:
3323 return D3DFMT_X8R8G8B8;
3324 case DXGI_FORMAT_AYUV:
3325 return MAKEFOURCC('A','Y','U','V');
3326 case DXGI_FORMAT_Y410:
3327 return MAKEFOURCC('Y','4','1','0');
3328 case DXGI_FORMAT_Y416:
3329 return MAKEFOURCC('Y','4','1','6');
3330 case DXGI_FORMAT_NV12:
3331 return MAKEFOURCC('N','V','1','2');
3332 case DXGI_FORMAT_P010:
3333 return MAKEFOURCC('P','0','1','0');
3334 case DXGI_FORMAT_P016:
3335 return MAKEFOURCC('P','0','1','6');
3336 case DXGI_FORMAT_420_OPAQUE:
3337 return MAKEFOURCC('4','2','0','O');
3338 case DXGI_FORMAT_YUY2:
3339 return D3DFMT_YUY2;
3340 case DXGI_FORMAT_Y210:
3341 return MAKEFOURCC('Y','2','1','0');
3342 case DXGI_FORMAT_Y216:
3343 return MAKEFOURCC('Y','2','1','6');
3344 case DXGI_FORMAT_NV11:
3345 return MAKEFOURCC('N','V','1','1');
3346 case DXGI_FORMAT_AI44:
3347 return MAKEFOURCC('A','I','4','4');
3348 case DXGI_FORMAT_IA44:
3349 return MAKEFOURCC('I','A','4','4');
3350 case DXGI_FORMAT_P8:
3351 return D3DFMT_P8;
3352 case DXGI_FORMAT_A8P8:
3353 return D3DFMT_A8P8;
3354 default:
3355 return 0;
3359 /***********************************************************************
3360 * MFMapDX9FormatToDXGIFormat (mfplat.@)
3362 DXGI_FORMAT WINAPI MFMapDX9FormatToDXGIFormat(DWORD format)
3364 switch (format)
3366 case D3DFMT_A32B32G32R32F:
3367 return DXGI_FORMAT_R32G32B32A32_FLOAT;
3368 case D3DFMT_A16B16G16R16F:
3369 return DXGI_FORMAT_R16G16B16A16_FLOAT;
3370 case D3DFMT_A16B16G16R16:
3371 return DXGI_FORMAT_R16G16B16A16_UNORM;
3372 case D3DFMT_Q16W16V16U16:
3373 return DXGI_FORMAT_R16G16B16A16_SNORM;
3374 case D3DFMT_G32R32F:
3375 return DXGI_FORMAT_R32G32_FLOAT;
3376 case D3DFMT_A2B10G10R10:
3377 return DXGI_FORMAT_R10G10B10A2_UNORM;
3378 case D3DFMT_Q8W8V8U8:
3379 return DXGI_FORMAT_R8G8B8A8_SNORM;
3380 case D3DFMT_G16R16F:
3381 return DXGI_FORMAT_R16G16_FLOAT;
3382 case D3DFMT_G16R16:
3383 return DXGI_FORMAT_R16G16_UNORM;
3384 case D3DFMT_V16U16:
3385 return DXGI_FORMAT_R16G16_SNORM;
3386 case D3DFMT_D32F_LOCKABLE:
3387 return DXGI_FORMAT_D32_FLOAT;
3388 case D3DFMT_R32F:
3389 return DXGI_FORMAT_R32_FLOAT;
3390 case D3DFMT_D24S8:
3391 return DXGI_FORMAT_D24_UNORM_S8_UINT;
3392 case D3DFMT_V8U8:
3393 return DXGI_FORMAT_R8G8_SNORM;
3394 case D3DFMT_R16F:
3395 return DXGI_FORMAT_R16_FLOAT;
3396 case D3DFMT_L16:
3397 return DXGI_FORMAT_R16_UNORM;
3398 case D3DFMT_L8:
3399 return DXGI_FORMAT_R8_UNORM;
3400 case D3DFMT_A8:
3401 return DXGI_FORMAT_A8_UNORM;
3402 case D3DFMT_DXT1:
3403 return DXGI_FORMAT_BC1_UNORM;
3404 case D3DFMT_DXT2:
3405 return DXGI_FORMAT_BC2_UNORM;
3406 case D3DFMT_DXT4:
3407 return DXGI_FORMAT_BC3_UNORM;
3408 case D3DFMT_A8R8G8B8:
3409 return DXGI_FORMAT_B8G8R8A8_UNORM;
3410 case D3DFMT_X8R8G8B8:
3411 return DXGI_FORMAT_B8G8R8X8_UNORM;
3412 case MAKEFOURCC('A','Y','U','V'):
3413 return DXGI_FORMAT_AYUV;
3414 case MAKEFOURCC('Y','4','1','0'):
3415 return DXGI_FORMAT_Y410;
3416 case MAKEFOURCC('Y','4','1','6'):
3417 return DXGI_FORMAT_Y416;
3418 case MAKEFOURCC('N','V','1','2'):
3419 return DXGI_FORMAT_NV12;
3420 case MAKEFOURCC('P','0','1','0'):
3421 return DXGI_FORMAT_P010;
3422 case MAKEFOURCC('P','0','1','6'):
3423 return DXGI_FORMAT_P016;
3424 case MAKEFOURCC('4','2','0','O'):
3425 return DXGI_FORMAT_420_OPAQUE;
3426 case D3DFMT_YUY2:
3427 return DXGI_FORMAT_YUY2;
3428 case MAKEFOURCC('Y','2','1','0'):
3429 return DXGI_FORMAT_Y210;
3430 case MAKEFOURCC('Y','2','1','6'):
3431 return DXGI_FORMAT_Y216;
3432 case MAKEFOURCC('N','V','1','1'):
3433 return DXGI_FORMAT_NV11;
3434 case MAKEFOURCC('A','I','4','4'):
3435 return DXGI_FORMAT_AI44;
3436 case MAKEFOURCC('I','A','4','4'):
3437 return DXGI_FORMAT_IA44;
3438 case D3DFMT_P8:
3439 return DXGI_FORMAT_P8;
3440 case D3DFMT_A8P8:
3441 return DXGI_FORMAT_A8P8;
3442 default:
3443 return DXGI_FORMAT_UNKNOWN;
3447 /***********************************************************************
3448 * MFInitVideoFormat_RGB (mfplat.@)
3450 HRESULT WINAPI MFInitVideoFormat_RGB(MFVIDEOFORMAT *format, DWORD width, DWORD height, DWORD d3dformat)
3452 unsigned int transfer_function;
3454 TRACE("%p, %u, %u, %#x.\n", format, width, height, d3dformat);
3456 if (!format)
3457 return E_INVALIDARG;
3459 if (!d3dformat) d3dformat = D3DFMT_X8R8G8B8;
3461 switch (d3dformat)
3463 case D3DFMT_X8R8G8B8:
3464 case D3DFMT_R8G8B8:
3465 case D3DFMT_A8R8G8B8:
3466 case D3DFMT_R5G6B5:
3467 case D3DFMT_X1R5G5B5:
3468 case D3DFMT_A2B10G10R10:
3469 case D3DFMT_P8:
3470 transfer_function = MFVideoTransFunc_sRGB;
3471 break;
3472 default:
3473 transfer_function = MFVideoTransFunc_10;
3476 memset(format, 0, sizeof(*format));
3477 format->dwSize = sizeof(*format);
3478 format->videoInfo.dwWidth = width;
3479 format->videoInfo.dwHeight = height;
3480 format->videoInfo.PixelAspectRatio.Numerator = 1;
3481 format->videoInfo.PixelAspectRatio.Denominator = 1;
3482 format->videoInfo.InterlaceMode = MFVideoInterlace_Progressive;
3483 format->videoInfo.TransferFunction = transfer_function;
3484 format->videoInfo.ColorPrimaries = MFVideoPrimaries_BT709;
3485 format->videoInfo.SourceLighting = MFVideoLighting_office;
3486 format->videoInfo.FramesPerSecond.Numerator = 60;
3487 format->videoInfo.FramesPerSecond.Denominator = 1;
3488 format->videoInfo.NominalRange = MFNominalRange_Normal;
3489 format->videoInfo.GeometricAperture.Area.cx = width;
3490 format->videoInfo.GeometricAperture.Area.cy = height;
3491 format->videoInfo.MinimumDisplayAperture = format->videoInfo.GeometricAperture;
3492 memcpy(&format->guidFormat, &MFVideoFormat_Base, sizeof(format->guidFormat));
3493 format->guidFormat.Data1 = d3dformat;
3494 format->surfaceInfo.Format = d3dformat;
3496 return S_OK;