mfplat: Only convert MEDIASUBTYPE for the formats which need it.
[wine.git] / dlls / mfplat / mediatype.c
blob1707df87f6d140b62d5ce27032a2d24d9963b986
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 "uuids.h"
25 #include "strmif.h"
26 #include "initguid.h"
27 #include "ks.h"
28 #include "ksmedia.h"
29 #include "amvideo.h"
30 #include "wmcodecdsp.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(mfplat);
34 DEFINE_MEDIATYPE_GUID(MFVideoFormat_RGB1, D3DFMT_A1);
35 DEFINE_MEDIATYPE_GUID(MFVideoFormat_RGB4, MAKEFOURCC('4','P','x','x'));
36 DEFINE_MEDIATYPE_GUID(MFVideoFormat_ARGB1555, D3DFMT_A1R5G5B5);
37 DEFINE_MEDIATYPE_GUID(MFVideoFormat_ARGB4444, D3DFMT_A4R4G4B4);
38 /* SDK MFVideoFormat_A2R10G10B10 uses D3DFMT_A2B10G10R10, let's name it the other way */
39 DEFINE_MEDIATYPE_GUID(MFVideoFormat_A2B10G10R10, D3DFMT_A2R10G10B10);
41 DEFINE_MEDIATYPE_GUID(MFVideoFormat_IMC1, MAKEFOURCC('I','M','C','1'));
42 DEFINE_MEDIATYPE_GUID(MFVideoFormat_IMC2, MAKEFOURCC('I','M','C','2'));
43 DEFINE_MEDIATYPE_GUID(MFVideoFormat_IMC3, MAKEFOURCC('I','M','C','3'));
44 DEFINE_MEDIATYPE_GUID(MFVideoFormat_IMC4, MAKEFOURCC('I','M','C','4'));
46 struct media_type
48 struct attributes attributes;
49 IMFMediaType IMFMediaType_iface;
50 IMFVideoMediaType IMFVideoMediaType_iface;
51 IMFAudioMediaType IMFAudioMediaType_iface;
52 MFVIDEOFORMAT *video_format;
53 WAVEFORMATEX *audio_format;
56 struct stream_desc
58 struct attributes attributes;
59 IMFStreamDescriptor IMFStreamDescriptor_iface;
60 IMFMediaTypeHandler IMFMediaTypeHandler_iface;
61 DWORD identifier;
62 IMFMediaType **media_types;
63 unsigned int media_types_count;
64 IMFMediaType *current_type;
67 struct presentation_desc_entry
69 IMFStreamDescriptor *descriptor;
70 BOOL selected;
73 struct presentation_desc
75 struct attributes attributes;
76 IMFPresentationDescriptor IMFPresentationDescriptor_iface;
77 struct presentation_desc_entry *descriptors;
78 unsigned int count;
81 static HRESULT presentation_descriptor_init(struct presentation_desc *object, DWORD count);
83 static struct media_type *impl_from_IMFMediaType(IMFMediaType *iface)
85 return CONTAINING_RECORD(iface, struct media_type, IMFMediaType_iface);
88 static struct media_type *impl_from_IMFVideoMediaType(IMFVideoMediaType *iface)
90 return CONTAINING_RECORD(iface, struct media_type, IMFVideoMediaType_iface);
93 static struct media_type *impl_from_IMFAudioMediaType(IMFAudioMediaType *iface)
95 return CONTAINING_RECORD(iface, struct media_type, IMFAudioMediaType_iface);
98 static inline struct stream_desc *impl_from_IMFStreamDescriptor(IMFStreamDescriptor *iface)
100 return CONTAINING_RECORD(iface, struct stream_desc, IMFStreamDescriptor_iface);
103 static struct stream_desc *impl_from_IMFMediaTypeHandler(IMFMediaTypeHandler *iface)
105 return CONTAINING_RECORD(iface, struct stream_desc, IMFMediaTypeHandler_iface);
108 static struct presentation_desc *impl_from_IMFPresentationDescriptor(IMFPresentationDescriptor *iface)
110 return CONTAINING_RECORD(iface, struct presentation_desc, IMFPresentationDescriptor_iface);
113 static HRESULT WINAPI mediatype_QueryInterface(IMFMediaType *iface, REFIID riid, void **out)
115 struct media_type *media_type = impl_from_IMFMediaType(iface);
116 GUID major = { 0 };
118 TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), out);
120 attributes_GetGUID(&media_type->attributes, &MF_MT_MAJOR_TYPE, &major);
122 if (IsEqualGUID(&major, &MFMediaType_Video) && IsEqualIID(riid, &IID_IMFVideoMediaType))
124 *out = &media_type->IMFVideoMediaType_iface;
126 else if (IsEqualGUID(&major, &MFMediaType_Audio) && IsEqualIID(riid, &IID_IMFAudioMediaType))
128 *out = &media_type->IMFAudioMediaType_iface;
130 else if (IsEqualIID(riid, &IID_IMFMediaType) ||
131 IsEqualIID(riid, &IID_IMFAttributes) ||
132 IsEqualIID(riid, &IID_IUnknown))
134 *out = &media_type->IMFMediaType_iface;
136 else
138 WARN("Unsupported %s.\n", debugstr_guid(riid));
139 *out = NULL;
140 return E_NOINTERFACE;
143 IUnknown_AddRef((IUnknown *)*out);
144 return S_OK;
147 static ULONG WINAPI mediatype_AddRef(IMFMediaType *iface)
149 struct media_type *media_type = impl_from_IMFMediaType(iface);
150 ULONG refcount = InterlockedIncrement(&media_type->attributes.ref);
152 TRACE("%p, refcount %lu.\n", iface, refcount);
154 return refcount;
157 static ULONG WINAPI mediatype_Release(IMFMediaType *iface)
159 struct media_type *media_type = impl_from_IMFMediaType(iface);
160 ULONG refcount = InterlockedDecrement(&media_type->attributes.ref);
162 TRACE("%p, refcount %lu.\n", iface, refcount);
164 if (!refcount)
166 clear_attributes_object(&media_type->attributes);
167 CoTaskMemFree(media_type->video_format);
168 CoTaskMemFree(media_type->audio_format);
169 free(media_type);
172 return refcount;
175 static HRESULT WINAPI mediatype_GetItem(IMFMediaType *iface, REFGUID key, PROPVARIANT *value)
177 struct media_type *media_type = impl_from_IMFMediaType(iface);
179 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
181 return attributes_GetItem(&media_type->attributes, key, value);
184 static HRESULT WINAPI mediatype_GetItemType(IMFMediaType *iface, REFGUID key, MF_ATTRIBUTE_TYPE *type)
186 struct media_type *media_type = impl_from_IMFMediaType(iface);
188 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), type);
190 return attributes_GetItemType(&media_type->attributes, key, type);
193 static HRESULT WINAPI mediatype_CompareItem(IMFMediaType *iface, REFGUID key, REFPROPVARIANT value, BOOL *result)
195 struct media_type *media_type = impl_from_IMFMediaType(iface);
197 TRACE("%p, %s, %s, %p.\n", iface, debugstr_attr(key), debugstr_propvar(value), result);
199 return attributes_CompareItem(&media_type->attributes, key, value, result);
202 static HRESULT WINAPI mediatype_Compare(IMFMediaType *iface, IMFAttributes *attrs, MF_ATTRIBUTES_MATCH_TYPE type,
203 BOOL *result)
205 struct media_type *media_type = impl_from_IMFMediaType(iface);
207 TRACE("%p, %p, %d, %p.\n", iface, attrs, type, result);
209 return attributes_Compare(&media_type->attributes, attrs, type, result);
212 static HRESULT WINAPI mediatype_GetUINT32(IMFMediaType *iface, REFGUID key, UINT32 *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_GetUINT32(&media_type->attributes, key, value);
221 static HRESULT WINAPI mediatype_GetUINT64(IMFMediaType *iface, REFGUID key, UINT64 *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_GetUINT64(&media_type->attributes, key, value);
230 static HRESULT WINAPI mediatype_GetDouble(IMFMediaType *iface, REFGUID key, double *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_GetDouble(&media_type->attributes, key, value);
239 static HRESULT WINAPI mediatype_GetGUID(IMFMediaType *iface, REFGUID key, GUID *value)
241 struct media_type *media_type = impl_from_IMFMediaType(iface);
243 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
245 return attributes_GetGUID(&media_type->attributes, key, value);
248 static HRESULT WINAPI mediatype_GetStringLength(IMFMediaType *iface, REFGUID key, UINT32 *length)
250 struct media_type *media_type = impl_from_IMFMediaType(iface);
252 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), length);
254 return attributes_GetStringLength(&media_type->attributes, key, length);
257 static HRESULT WINAPI mediatype_GetString(IMFMediaType *iface, REFGUID key, WCHAR *value,
258 UINT32 size, UINT32 *length)
260 struct media_type *media_type = impl_from_IMFMediaType(iface);
262 TRACE("%p, %s, %p, %u, %p.\n", iface, debugstr_attr(key), value, size, length);
264 return attributes_GetString(&media_type->attributes, key, value, size, length);
267 static HRESULT WINAPI mediatype_GetAllocatedString(IMFMediaType *iface, REFGUID key,
268 WCHAR **value, UINT32 *length)
270 struct media_type *media_type = impl_from_IMFMediaType(iface);
272 TRACE("%p, %s, %p, %p.\n", iface, debugstr_attr(key), value, length);
274 return attributes_GetAllocatedString(&media_type->attributes, key, value, length);
277 static HRESULT WINAPI mediatype_GetBlobSize(IMFMediaType *iface, REFGUID key, UINT32 *size)
279 struct media_type *media_type = impl_from_IMFMediaType(iface);
281 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), size);
283 return attributes_GetBlobSize(&media_type->attributes, key, size);
286 static HRESULT WINAPI mediatype_GetBlob(IMFMediaType *iface, REFGUID key, UINT8 *buf,
287 UINT32 bufsize, UINT32 *blobsize)
289 struct media_type *media_type = impl_from_IMFMediaType(iface);
291 TRACE("%p, %s, %p, %u, %p.\n", iface, debugstr_attr(key), buf, bufsize, blobsize);
293 return attributes_GetBlob(&media_type->attributes, key, buf, bufsize, blobsize);
296 static HRESULT WINAPI mediatype_GetAllocatedBlob(IMFMediaType *iface, REFGUID key, UINT8 **buf, UINT32 *size)
298 struct media_type *media_type = impl_from_IMFMediaType(iface);
300 TRACE("%p, %s, %p, %p.\n", iface, debugstr_attr(key), buf, size);
302 return attributes_GetAllocatedBlob(&media_type->attributes, key, buf, size);
305 static HRESULT WINAPI mediatype_GetUnknown(IMFMediaType *iface, REFGUID key, REFIID riid, void **obj)
307 struct media_type *media_type = impl_from_IMFMediaType(iface);
309 TRACE("%p, %s, %s, %p.\n", iface, debugstr_attr(key), debugstr_guid(riid), obj);
311 return attributes_GetUnknown(&media_type->attributes, key, riid, obj);
314 static HRESULT WINAPI mediatype_SetItem(IMFMediaType *iface, REFGUID key, REFPROPVARIANT value)
316 struct media_type *media_type = impl_from_IMFMediaType(iface);
318 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_propvar(value));
320 return attributes_SetItem(&media_type->attributes, key, value);
323 static HRESULT WINAPI mediatype_DeleteItem(IMFMediaType *iface, REFGUID key)
325 struct media_type *media_type = impl_from_IMFMediaType(iface);
327 TRACE("%p, %s.\n", iface, debugstr_attr(key));
329 return attributes_DeleteItem(&media_type->attributes, key);
332 static HRESULT WINAPI mediatype_DeleteAllItems(IMFMediaType *iface)
334 struct media_type *media_type = impl_from_IMFMediaType(iface);
336 TRACE("%p.\n", iface);
338 return attributes_DeleteAllItems(&media_type->attributes);
341 static HRESULT WINAPI mediatype_SetUINT32(IMFMediaType *iface, REFGUID key, UINT32 value)
343 struct media_type *media_type = impl_from_IMFMediaType(iface);
345 TRACE("%p, %s, %u.\n", iface, debugstr_attr(key), value);
347 return attributes_SetUINT32(&media_type->attributes, key, value);
350 static HRESULT WINAPI mediatype_SetUINT64(IMFMediaType *iface, REFGUID key, UINT64 value)
352 struct media_type *media_type = impl_from_IMFMediaType(iface);
354 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), wine_dbgstr_longlong(value));
356 return attributes_SetUINT64(&media_type->attributes, key, value);
359 static HRESULT WINAPI mediatype_SetDouble(IMFMediaType *iface, REFGUID key, double value)
361 struct media_type *media_type = impl_from_IMFMediaType(iface);
363 TRACE("%p, %s, %f.\n", iface, debugstr_attr(key), value);
365 return attributes_SetDouble(&media_type->attributes, key, value);
368 static HRESULT WINAPI mediatype_SetGUID(IMFMediaType *iface, REFGUID key, REFGUID value)
370 struct media_type *media_type = impl_from_IMFMediaType(iface);
372 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_mf_guid(value));
374 return attributes_SetGUID(&media_type->attributes, key, value);
377 static HRESULT WINAPI mediatype_SetString(IMFMediaType *iface, REFGUID key, const WCHAR *value)
379 struct media_type *media_type = impl_from_IMFMediaType(iface);
381 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_w(value));
383 return attributes_SetString(&media_type->attributes, key, value);
386 static HRESULT WINAPI mediatype_SetBlob(IMFMediaType *iface, REFGUID key, const UINT8 *buf, UINT32 size)
388 struct media_type *media_type = impl_from_IMFMediaType(iface);
390 TRACE("%p, %s, %p, %u.\n", iface, debugstr_attr(key), buf, size);
392 return attributes_SetBlob(&media_type->attributes, key, buf, size);
395 static HRESULT WINAPI mediatype_SetUnknown(IMFMediaType *iface, REFGUID key, IUnknown *unknown)
397 struct media_type *media_type = impl_from_IMFMediaType(iface);
399 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), unknown);
401 return attributes_SetUnknown(&media_type->attributes, key, unknown);
404 static HRESULT WINAPI mediatype_LockStore(IMFMediaType *iface)
406 struct media_type *media_type = impl_from_IMFMediaType(iface);
408 TRACE("%p.\n", iface);
410 return attributes_LockStore(&media_type->attributes);
413 static HRESULT WINAPI mediatype_UnlockStore(IMFMediaType *iface)
415 struct media_type *media_type = impl_from_IMFMediaType(iface);
417 TRACE("%p.\n", iface);
419 return attributes_UnlockStore(&media_type->attributes);
422 static HRESULT WINAPI mediatype_GetCount(IMFMediaType *iface, UINT32 *count)
424 struct media_type *media_type = impl_from_IMFMediaType(iface);
426 TRACE("%p, %p.\n", iface, count);
428 return attributes_GetCount(&media_type->attributes, count);
431 static HRESULT WINAPI mediatype_GetItemByIndex(IMFMediaType *iface, UINT32 index, GUID *key, PROPVARIANT *value)
433 struct media_type *media_type = impl_from_IMFMediaType(iface);
435 TRACE("%p, %u, %p, %p.\n", iface, index, key, value);
437 return attributes_GetItemByIndex(&media_type->attributes, index, key, value);
440 static HRESULT WINAPI mediatype_CopyAllItems(IMFMediaType *iface, IMFAttributes *dest)
442 struct media_type *media_type = impl_from_IMFMediaType(iface);
444 TRACE("%p, %p.\n", iface, dest);
446 return attributes_CopyAllItems(&media_type->attributes, dest);
449 static HRESULT WINAPI mediatype_GetMajorType(IMFMediaType *iface, GUID *guid)
451 struct media_type *media_type = impl_from_IMFMediaType(iface);
453 TRACE("%p, %p.\n", iface, guid);
455 return attributes_GetGUID(&media_type->attributes, &MF_MT_MAJOR_TYPE, guid);
458 static HRESULT mediatype_is_compressed(struct media_type *media_type, BOOL *compressed)
460 UINT32 value;
462 if (FAILED(attributes_GetUINT32(&media_type->attributes, &MF_MT_ALL_SAMPLES_INDEPENDENT, &value)))
464 value = 0;
467 *compressed = !value;
469 return S_OK;
472 static HRESULT WINAPI mediatype_IsCompressedFormat(IMFMediaType *iface, BOOL *compressed)
474 struct media_type *media_type = impl_from_IMFMediaType(iface);
476 TRACE("%p, %p.\n", iface, compressed);
478 return mediatype_is_compressed(media_type, compressed);
481 static HRESULT media_type_is_equal(struct media_type *media_type, IMFMediaType *type, DWORD *flags)
483 const DWORD full_equality_flags = MF_MEDIATYPE_EQUAL_MAJOR_TYPES | MF_MEDIATYPE_EQUAL_FORMAT_TYPES |
484 MF_MEDIATYPE_EQUAL_FORMAT_DATA | MF_MEDIATYPE_EQUAL_FORMAT_USER_DATA;
485 struct comparand
487 IMFAttributes *type;
488 PROPVARIANT value;
489 UINT32 count;
490 GUID guid;
491 HRESULT hr;
492 } left, right, swp;
493 unsigned int i;
494 BOOL result;
496 *flags = 0;
498 left.type = &media_type->attributes.IMFAttributes_iface;
499 right.type = (IMFAttributes *)type;
501 if (FAILED(IMFAttributes_GetGUID(left.type, &MF_MT_MAJOR_TYPE, &left.guid)))
502 return E_INVALIDARG;
504 if (FAILED(IMFAttributes_GetGUID(right.type, &MF_MT_MAJOR_TYPE, &right.guid)))
505 return E_INVALIDARG;
507 if (IsEqualGUID(&left.guid, &right.guid))
508 *flags |= MF_MEDIATYPE_EQUAL_MAJOR_TYPES;
510 /* Subtypes equal or both missing. */
511 left.hr = IMFAttributes_GetGUID(left.type, &MF_MT_SUBTYPE, &left.guid);
512 right.hr = IMFAttributes_GetGUID(right.type, &MF_MT_SUBTYPE, &right.guid);
514 if ((SUCCEEDED(left.hr) && SUCCEEDED(right.hr) && IsEqualGUID(&left.guid, &right.guid)) ||
515 (FAILED(left.hr) && FAILED(right.hr)))
517 *flags |= MF_MEDIATYPE_EQUAL_FORMAT_TYPES;
520 /* Format data */
521 IMFAttributes_GetCount(left.type, &left.count);
522 IMFAttributes_GetCount(right.type, &right.count);
524 if (right.count < left.count)
526 swp = left;
527 left = right;
528 right = swp;
531 *flags |= MF_MEDIATYPE_EQUAL_FORMAT_DATA;
533 for (i = 0; i < left.count; ++i)
535 PROPVARIANT value;
536 GUID key;
538 if (SUCCEEDED(IMFAttributes_GetItemByIndex(left.type, i, &key, &value)))
540 if (IsEqualGUID(&key, &MF_MT_USER_DATA) ||
541 IsEqualGUID(&key, &MF_MT_FRAME_RATE_RANGE_MIN) ||
542 IsEqualGUID(&key, &MF_MT_FRAME_RATE_RANGE_MAX))
544 PropVariantClear(&value);
545 continue;
548 result = FALSE;
549 IMFAttributes_CompareItem(right.type, &key, &value, &result);
550 PropVariantClear(&value);
551 if (!result)
553 *flags &= ~MF_MEDIATYPE_EQUAL_FORMAT_DATA;
554 break;
559 /* User data */
560 PropVariantInit(&left.value);
561 left.hr = IMFAttributes_GetItem(left.type, &MF_MT_USER_DATA, &left.value);
562 PropVariantInit(&right.value);
563 right.hr = IMFAttributes_GetItem(right.type, &MF_MT_USER_DATA, &right.value);
565 /* Compare user data if both types have it, otherwise simply check if both don't. */
566 if (SUCCEEDED(left.hr) && SUCCEEDED(right.hr))
568 result = FALSE;
569 IMFAttributes_CompareItem(left.type, &MF_MT_USER_DATA, &left.value, &result);
571 else
572 result = FAILED(left.hr) && FAILED(right.hr);
574 PropVariantClear(&left.value);
575 PropVariantClear(&right.value);
577 if (result)
578 *flags |= MF_MEDIATYPE_EQUAL_FORMAT_USER_DATA;
580 return *flags == full_equality_flags ? S_OK : S_FALSE;
583 static HRESULT WINAPI mediatype_IsEqual(IMFMediaType *iface, IMFMediaType *type, DWORD *flags)
585 struct media_type *media_type = impl_from_IMFMediaType(iface);
587 TRACE("%p, %p, %p.\n", iface, type, flags);
589 return media_type_is_equal(media_type, type, flags);
592 static HRESULT WINAPI mediatype_GetRepresentation(IMFMediaType *iface, GUID guid, void **representation)
594 FIXME("%p, %s, %p.\n", iface, debugstr_guid(&guid), representation);
596 return E_NOTIMPL;
599 static HRESULT WINAPI mediatype_FreeRepresentation(IMFMediaType *iface, GUID guid, void *representation)
601 FIXME("%p, %s, %p.\n", iface, debugstr_guid(&guid), representation);
603 return E_NOTIMPL;
606 static const IMFMediaTypeVtbl mediatypevtbl =
608 mediatype_QueryInterface,
609 mediatype_AddRef,
610 mediatype_Release,
611 mediatype_GetItem,
612 mediatype_GetItemType,
613 mediatype_CompareItem,
614 mediatype_Compare,
615 mediatype_GetUINT32,
616 mediatype_GetUINT64,
617 mediatype_GetDouble,
618 mediatype_GetGUID,
619 mediatype_GetStringLength,
620 mediatype_GetString,
621 mediatype_GetAllocatedString,
622 mediatype_GetBlobSize,
623 mediatype_GetBlob,
624 mediatype_GetAllocatedBlob,
625 mediatype_GetUnknown,
626 mediatype_SetItem,
627 mediatype_DeleteItem,
628 mediatype_DeleteAllItems,
629 mediatype_SetUINT32,
630 mediatype_SetUINT64,
631 mediatype_SetDouble,
632 mediatype_SetGUID,
633 mediatype_SetString,
634 mediatype_SetBlob,
635 mediatype_SetUnknown,
636 mediatype_LockStore,
637 mediatype_UnlockStore,
638 mediatype_GetCount,
639 mediatype_GetItemByIndex,
640 mediatype_CopyAllItems,
641 mediatype_GetMajorType,
642 mediatype_IsCompressedFormat,
643 mediatype_IsEqual,
644 mediatype_GetRepresentation,
645 mediatype_FreeRepresentation
648 static HRESULT WINAPI video_mediatype_QueryInterface(IMFVideoMediaType *iface, REFIID riid, void **out)
650 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
651 return IMFMediaType_QueryInterface(&media_type->IMFMediaType_iface, riid, out);
654 static ULONG WINAPI video_mediatype_AddRef(IMFVideoMediaType *iface)
656 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
657 return IMFMediaType_AddRef(&media_type->IMFMediaType_iface);
660 static ULONG WINAPI video_mediatype_Release(IMFVideoMediaType *iface)
662 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
663 return IMFMediaType_Release(&media_type->IMFMediaType_iface);
666 static HRESULT WINAPI video_mediatype_GetItem(IMFVideoMediaType *iface, REFGUID key, PROPVARIANT *value)
668 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
670 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
672 return attributes_GetItem(&media_type->attributes, key, value);
675 static HRESULT WINAPI video_mediatype_GetItemType(IMFVideoMediaType *iface, REFGUID key, MF_ATTRIBUTE_TYPE *type)
677 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
679 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), type);
681 return attributes_GetItemType(&media_type->attributes, key, type);
684 static HRESULT WINAPI video_mediatype_CompareItem(IMFVideoMediaType *iface, REFGUID key, REFPROPVARIANT value, BOOL *result)
686 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
688 TRACE("%p, %s, %s, %p.\n", iface, debugstr_attr(key), debugstr_propvar(value), result);
690 return attributes_CompareItem(&media_type->attributes, key, value, result);
693 static HRESULT WINAPI video_mediatype_Compare(IMFVideoMediaType *iface, IMFAttributes *attrs,
694 MF_ATTRIBUTES_MATCH_TYPE type, BOOL *result)
696 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
698 TRACE("%p, %p, %d, %p.\n", iface, attrs, type, result);
700 return attributes_Compare(&media_type->attributes, attrs, type, result);
703 static HRESULT WINAPI video_mediatype_GetUINT32(IMFVideoMediaType *iface, REFGUID key, UINT32 *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_GetUINT32(&media_type->attributes, key, value);
712 static HRESULT WINAPI video_mediatype_GetUINT64(IMFVideoMediaType *iface, REFGUID key, UINT64 *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_GetUINT64(&media_type->attributes, key, value);
721 static HRESULT WINAPI video_mediatype_GetDouble(IMFVideoMediaType *iface, REFGUID key, double *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_GetDouble(&media_type->attributes, key, value);
730 static HRESULT WINAPI video_mediatype_GetGUID(IMFVideoMediaType *iface, REFGUID key, GUID *value)
732 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
734 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
736 return attributes_GetGUID(&media_type->attributes, key, value);
739 static HRESULT WINAPI video_mediatype_GetStringLength(IMFVideoMediaType *iface, REFGUID key, UINT32 *length)
741 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
743 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), length);
745 return attributes_GetStringLength(&media_type->attributes, key, length);
748 static HRESULT WINAPI video_mediatype_GetString(IMFVideoMediaType *iface, REFGUID key, WCHAR *value,
749 UINT32 size, UINT32 *length)
751 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
753 TRACE("%p, %s, %p, %u, %p.\n", iface, debugstr_attr(key), value, size, length);
755 return attributes_GetString(&media_type->attributes, key, value, size, length);
758 static HRESULT WINAPI video_mediatype_GetAllocatedString(IMFVideoMediaType *iface, REFGUID key,
759 WCHAR **value, UINT32 *length)
761 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
763 TRACE("%p, %s, %p, %p.\n", iface, debugstr_attr(key), value, length);
765 return attributes_GetAllocatedString(&media_type->attributes, key, value, length);
768 static HRESULT WINAPI video_mediatype_GetBlobSize(IMFVideoMediaType *iface, REFGUID key, UINT32 *size)
770 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
772 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), size);
774 return attributes_GetBlobSize(&media_type->attributes, key, size);
777 static HRESULT WINAPI video_mediatype_GetBlob(IMFVideoMediaType *iface, REFGUID key, UINT8 *buf,
778 UINT32 bufsize, UINT32 *blobsize)
780 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
782 TRACE("%p, %s, %p, %u, %p.\n", iface, debugstr_attr(key), buf, bufsize, blobsize);
784 return attributes_GetBlob(&media_type->attributes, key, buf, bufsize, blobsize);
787 static HRESULT WINAPI video_mediatype_GetAllocatedBlob(IMFVideoMediaType *iface, REFGUID key, UINT8 **buf, UINT32 *size)
789 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
791 TRACE("%p, %s, %p, %p.\n", iface, debugstr_attr(key), buf, size);
793 return attributes_GetAllocatedBlob(&media_type->attributes, key, buf, size);
796 static HRESULT WINAPI video_mediatype_GetUnknown(IMFVideoMediaType *iface, REFGUID key, REFIID riid, void **obj)
798 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
800 TRACE("%p, %s, %s, %p.\n", iface, debugstr_attr(key), debugstr_guid(riid), obj);
802 return attributes_GetUnknown(&media_type->attributes, key, riid, obj);
805 static HRESULT WINAPI video_mediatype_SetItem(IMFVideoMediaType *iface, REFGUID key, REFPROPVARIANT value)
807 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
809 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_propvar(value));
811 return attributes_SetItem(&media_type->attributes, key, value);
814 static HRESULT WINAPI video_mediatype_DeleteItem(IMFVideoMediaType *iface, REFGUID key)
816 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
818 TRACE("%p, %s.\n", iface, debugstr_attr(key));
820 return attributes_DeleteItem(&media_type->attributes, key);
823 static HRESULT WINAPI video_mediatype_DeleteAllItems(IMFVideoMediaType *iface)
825 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
827 TRACE("%p.\n", iface);
829 return attributes_DeleteAllItems(&media_type->attributes);
832 static HRESULT WINAPI video_mediatype_SetUINT32(IMFVideoMediaType *iface, REFGUID key, UINT32 value)
834 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
836 TRACE("%p, %s, %u.\n", iface, debugstr_attr(key), value);
838 return attributes_SetUINT32(&media_type->attributes, key, value);
841 static HRESULT WINAPI video_mediatype_SetUINT64(IMFVideoMediaType *iface, REFGUID key, UINT64 value)
843 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
845 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), wine_dbgstr_longlong(value));
847 return attributes_SetUINT64(&media_type->attributes, key, value);
850 static HRESULT WINAPI video_mediatype_SetDouble(IMFVideoMediaType *iface, REFGUID key, double value)
852 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
854 TRACE("%p, %s, %f.\n", iface, debugstr_attr(key), value);
856 return attributes_SetDouble(&media_type->attributes, key, value);
859 static HRESULT WINAPI video_mediatype_SetGUID(IMFVideoMediaType *iface, REFGUID key, REFGUID value)
861 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
863 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_mf_guid(value));
865 return attributes_SetGUID(&media_type->attributes, key, value);
868 static HRESULT WINAPI video_mediatype_SetString(IMFVideoMediaType *iface, REFGUID key, const WCHAR *value)
870 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
872 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_w(value));
874 return attributes_SetString(&media_type->attributes, key, value);
877 static HRESULT WINAPI video_mediatype_SetBlob(IMFVideoMediaType *iface, REFGUID key, const UINT8 *buf, UINT32 size)
879 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
881 TRACE("%p, %s, %p, %u.\n", iface, debugstr_attr(key), buf, size);
883 return attributes_SetBlob(&media_type->attributes, key, buf, size);
886 static HRESULT WINAPI video_mediatype_SetUnknown(IMFVideoMediaType *iface, REFGUID key, IUnknown *unknown)
888 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
890 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), unknown);
892 return attributes_SetUnknown(&media_type->attributes, key, unknown);
895 static HRESULT WINAPI video_mediatype_LockStore(IMFVideoMediaType *iface)
897 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
899 TRACE("%p.\n", iface);
901 return attributes_LockStore(&media_type->attributes);
904 static HRESULT WINAPI video_mediatype_UnlockStore(IMFVideoMediaType *iface)
906 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
908 TRACE("%p.\n", iface);
910 return attributes_UnlockStore(&media_type->attributes);
913 static HRESULT WINAPI video_mediatype_GetCount(IMFVideoMediaType *iface, UINT32 *count)
915 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
917 TRACE("%p, %p.\n", iface, count);
919 return attributes_GetCount(&media_type->attributes, count);
922 static HRESULT WINAPI video_mediatype_GetItemByIndex(IMFVideoMediaType *iface, UINT32 index, GUID *key, PROPVARIANT *value)
924 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
926 TRACE("%p, %u, %p, %p.\n", iface, index, key, value);
928 return attributes_GetItemByIndex(&media_type->attributes, index, key, value);
931 static HRESULT WINAPI video_mediatype_CopyAllItems(IMFVideoMediaType *iface, IMFAttributes *dest)
933 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
935 TRACE("%p, %p.\n", iface, dest);
937 return attributes_CopyAllItems(&media_type->attributes, dest);
940 static HRESULT WINAPI video_mediatype_GetMajorType(IMFVideoMediaType *iface, GUID *guid)
942 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
944 TRACE("%p, %p.\n", iface, guid);
946 return attributes_GetGUID(&media_type->attributes, &MF_MT_MAJOR_TYPE, guid);
949 static HRESULT WINAPI video_mediatype_IsCompressedFormat(IMFVideoMediaType *iface, BOOL *compressed)
951 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
953 TRACE("%p, %p.\n", iface, compressed);
955 return mediatype_is_compressed(media_type, compressed);
958 static HRESULT WINAPI video_mediatype_IsEqual(IMFVideoMediaType *iface, IMFMediaType *type, DWORD *flags)
960 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
962 TRACE("%p, %p, %p.\n", iface, type, flags);
964 return media_type_is_equal(media_type, type, flags);
967 static HRESULT WINAPI video_mediatype_GetRepresentation(IMFVideoMediaType *iface, GUID guid, void **representation)
969 FIXME("%p, %s, %p.\n", iface, debugstr_guid(&guid), representation);
971 return E_NOTIMPL;
974 static HRESULT WINAPI video_mediatype_FreeRepresentation(IMFVideoMediaType *iface, GUID guid, void *representation)
976 FIXME("%p, %s, %p.\n", iface, debugstr_guid(&guid), representation);
978 return E_NOTIMPL;
981 static const MFVIDEOFORMAT * WINAPI video_mediatype_GetVideoFormat(IMFVideoMediaType *iface)
983 struct media_type *media_type = impl_from_IMFVideoMediaType(iface);
984 unsigned int size;
985 HRESULT hr;
987 TRACE("%p.\n", iface);
989 CoTaskMemFree(media_type->video_format);
990 media_type->video_format = NULL;
991 if (FAILED(hr = MFCreateMFVideoFormatFromMFMediaType(&media_type->IMFMediaType_iface, &media_type->video_format, &size)))
992 WARN("Failed to create format description, hr %#lx.\n", hr);
994 return media_type->video_format;
997 static HRESULT WINAPI video_mediatype_GetVideoRepresentation(IMFVideoMediaType *iface, GUID representation,
998 void **data, LONG stride)
1000 FIXME("%p, %s, %p, %ld.\n", iface, debugstr_guid(&representation), data, stride);
1002 return E_NOTIMPL;
1005 static const IMFVideoMediaTypeVtbl videomediatypevtbl =
1007 video_mediatype_QueryInterface,
1008 video_mediatype_AddRef,
1009 video_mediatype_Release,
1010 video_mediatype_GetItem,
1011 video_mediatype_GetItemType,
1012 video_mediatype_CompareItem,
1013 video_mediatype_Compare,
1014 video_mediatype_GetUINT32,
1015 video_mediatype_GetUINT64,
1016 video_mediatype_GetDouble,
1017 video_mediatype_GetGUID,
1018 video_mediatype_GetStringLength,
1019 video_mediatype_GetString,
1020 video_mediatype_GetAllocatedString,
1021 video_mediatype_GetBlobSize,
1022 video_mediatype_GetBlob,
1023 video_mediatype_GetAllocatedBlob,
1024 video_mediatype_GetUnknown,
1025 video_mediatype_SetItem,
1026 video_mediatype_DeleteItem,
1027 video_mediatype_DeleteAllItems,
1028 video_mediatype_SetUINT32,
1029 video_mediatype_SetUINT64,
1030 video_mediatype_SetDouble,
1031 video_mediatype_SetGUID,
1032 video_mediatype_SetString,
1033 video_mediatype_SetBlob,
1034 video_mediatype_SetUnknown,
1035 video_mediatype_LockStore,
1036 video_mediatype_UnlockStore,
1037 video_mediatype_GetCount,
1038 video_mediatype_GetItemByIndex,
1039 video_mediatype_CopyAllItems,
1040 video_mediatype_GetMajorType,
1041 video_mediatype_IsCompressedFormat,
1042 video_mediatype_IsEqual,
1043 video_mediatype_GetRepresentation,
1044 video_mediatype_FreeRepresentation,
1045 video_mediatype_GetVideoFormat,
1046 video_mediatype_GetVideoRepresentation,
1049 static HRESULT WINAPI audio_mediatype_QueryInterface(IMFAudioMediaType *iface, REFIID riid, void **out)
1051 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1052 return IMFMediaType_QueryInterface(&media_type->IMFMediaType_iface, riid, out);
1055 static ULONG WINAPI audio_mediatype_AddRef(IMFAudioMediaType *iface)
1057 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1058 return IMFMediaType_AddRef(&media_type->IMFMediaType_iface);
1061 static ULONG WINAPI audio_mediatype_Release(IMFAudioMediaType *iface)
1063 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1064 return IMFMediaType_Release(&media_type->IMFMediaType_iface);
1067 static HRESULT WINAPI audio_mediatype_GetItem(IMFAudioMediaType *iface, REFGUID key, PROPVARIANT *value)
1069 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1071 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
1073 return attributes_GetItem(&media_type->attributes, key, value);
1076 static HRESULT WINAPI audio_mediatype_GetItemType(IMFAudioMediaType *iface, REFGUID key, MF_ATTRIBUTE_TYPE *type)
1078 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1080 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), type);
1082 return attributes_GetItemType(&media_type->attributes, key, type);
1085 static HRESULT WINAPI audio_mediatype_CompareItem(IMFAudioMediaType *iface, REFGUID key, REFPROPVARIANT value, BOOL *result)
1087 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1089 TRACE("%p, %s, %s, %p.\n", iface, debugstr_attr(key), debugstr_propvar(value), result);
1091 return attributes_CompareItem(&media_type->attributes, key, value, result);
1094 static HRESULT WINAPI audio_mediatype_Compare(IMFAudioMediaType *iface, IMFAttributes *attrs,
1095 MF_ATTRIBUTES_MATCH_TYPE type, BOOL *result)
1097 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1099 TRACE("%p, %p, %d, %p.\n", iface, attrs, type, result);
1101 return attributes_Compare(&media_type->attributes, attrs, type, result);
1104 static HRESULT WINAPI audio_mediatype_GetUINT32(IMFAudioMediaType *iface, REFGUID key, UINT32 *value)
1106 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1108 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
1110 return attributes_GetUINT32(&media_type->attributes, key, value);
1113 static HRESULT WINAPI audio_mediatype_GetUINT64(IMFAudioMediaType *iface, REFGUID key, UINT64 *value)
1115 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1117 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
1119 return attributes_GetUINT64(&media_type->attributes, key, value);
1122 static HRESULT WINAPI audio_mediatype_GetDouble(IMFAudioMediaType *iface, REFGUID key, double *value)
1124 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1126 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
1128 return attributes_GetDouble(&media_type->attributes, key, value);
1131 static HRESULT WINAPI audio_mediatype_GetGUID(IMFAudioMediaType *iface, REFGUID key, GUID *value)
1133 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1135 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
1137 return attributes_GetGUID(&media_type->attributes, key, value);
1140 static HRESULT WINAPI audio_mediatype_GetStringLength(IMFAudioMediaType *iface, REFGUID key, UINT32 *length)
1142 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1144 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), length);
1146 return attributes_GetStringLength(&media_type->attributes, key, length);
1149 static HRESULT WINAPI audio_mediatype_GetString(IMFAudioMediaType *iface, REFGUID key, WCHAR *value,
1150 UINT32 size, UINT32 *length)
1152 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1154 TRACE("%p, %s, %p, %u, %p.\n", iface, debugstr_attr(key), value, size, length);
1156 return attributes_GetString(&media_type->attributes, key, value, size, length);
1159 static HRESULT WINAPI audio_mediatype_GetAllocatedString(IMFAudioMediaType *iface, REFGUID key,
1160 WCHAR **value, UINT32 *length)
1162 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1164 TRACE("%p, %s, %p, %p.\n", iface, debugstr_attr(key), value, length);
1166 return attributes_GetAllocatedString(&media_type->attributes, key, value, length);
1169 static HRESULT WINAPI audio_mediatype_GetBlobSize(IMFAudioMediaType *iface, REFGUID key, UINT32 *size)
1171 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1173 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), size);
1175 return attributes_GetBlobSize(&media_type->attributes, key, size);
1178 static HRESULT WINAPI audio_mediatype_GetBlob(IMFAudioMediaType *iface, REFGUID key, UINT8 *buf,
1179 UINT32 bufsize, UINT32 *blobsize)
1181 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1183 TRACE("%p, %s, %p, %u, %p.\n", iface, debugstr_attr(key), buf, bufsize, blobsize);
1185 return attributes_GetBlob(&media_type->attributes, key, buf, bufsize, blobsize);
1188 static HRESULT WINAPI audio_mediatype_GetAllocatedBlob(IMFAudioMediaType *iface, REFGUID key, UINT8 **buf, UINT32 *size)
1190 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1192 TRACE("%p, %s, %p, %p.\n", iface, debugstr_attr(key), buf, size);
1194 return attributes_GetAllocatedBlob(&media_type->attributes, key, buf, size);
1197 static HRESULT WINAPI audio_mediatype_GetUnknown(IMFAudioMediaType *iface, REFGUID key, REFIID riid, void **obj)
1199 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1201 TRACE("%p, %s, %s, %p.\n", iface, debugstr_attr(key), debugstr_guid(riid), obj);
1203 return attributes_GetUnknown(&media_type->attributes, key, riid, obj);
1206 static HRESULT WINAPI audio_mediatype_SetItem(IMFAudioMediaType *iface, REFGUID key, REFPROPVARIANT value)
1208 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1210 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_propvar(value));
1212 return attributes_SetItem(&media_type->attributes, key, value);
1215 static HRESULT WINAPI audio_mediatype_DeleteItem(IMFAudioMediaType *iface, REFGUID key)
1217 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1219 TRACE("%p, %s.\n", iface, debugstr_attr(key));
1221 return attributes_DeleteItem(&media_type->attributes, key);
1224 static HRESULT WINAPI audio_mediatype_DeleteAllItems(IMFAudioMediaType *iface)
1226 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1228 TRACE("%p.\n", iface);
1230 return attributes_DeleteAllItems(&media_type->attributes);
1233 static HRESULT WINAPI audio_mediatype_SetUINT32(IMFAudioMediaType *iface, REFGUID key, UINT32 value)
1235 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1237 TRACE("%p, %s, %u.\n", iface, debugstr_attr(key), value);
1239 return attributes_SetUINT32(&media_type->attributes, key, value);
1242 static HRESULT WINAPI audio_mediatype_SetUINT64(IMFAudioMediaType *iface, REFGUID key, UINT64 value)
1244 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1246 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), wine_dbgstr_longlong(value));
1248 return attributes_SetUINT64(&media_type->attributes, key, value);
1251 static HRESULT WINAPI audio_mediatype_SetDouble(IMFAudioMediaType *iface, REFGUID key, double value)
1253 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1255 TRACE("%p, %s, %f.\n", iface, debugstr_attr(key), value);
1257 return attributes_SetDouble(&media_type->attributes, key, value);
1260 static HRESULT WINAPI audio_mediatype_SetGUID(IMFAudioMediaType *iface, REFGUID key, REFGUID value)
1262 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1264 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_mf_guid(value));
1266 return attributes_SetGUID(&media_type->attributes, key, value);
1269 static HRESULT WINAPI audio_mediatype_SetString(IMFAudioMediaType *iface, REFGUID key, const WCHAR *value)
1271 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1273 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_w(value));
1275 return attributes_SetString(&media_type->attributes, key, value);
1278 static HRESULT WINAPI audio_mediatype_SetBlob(IMFAudioMediaType *iface, REFGUID key, const UINT8 *buf, UINT32 size)
1280 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1282 TRACE("%p, %s, %p, %u.\n", iface, debugstr_attr(key), buf, size);
1284 return attributes_SetBlob(&media_type->attributes, key, buf, size);
1287 static HRESULT WINAPI audio_mediatype_SetUnknown(IMFAudioMediaType *iface, REFGUID key, IUnknown *unknown)
1289 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1291 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), unknown);
1293 return attributes_SetUnknown(&media_type->attributes, key, unknown);
1296 static HRESULT WINAPI audio_mediatype_LockStore(IMFAudioMediaType *iface)
1298 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1300 TRACE("%p.\n", iface);
1302 return attributes_LockStore(&media_type->attributes);
1305 static HRESULT WINAPI audio_mediatype_UnlockStore(IMFAudioMediaType *iface)
1307 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1309 TRACE("%p.\n", iface);
1311 return attributes_UnlockStore(&media_type->attributes);
1314 static HRESULT WINAPI audio_mediatype_GetCount(IMFAudioMediaType *iface, UINT32 *count)
1316 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1318 TRACE("%p, %p.\n", iface, count);
1320 return attributes_GetCount(&media_type->attributes, count);
1323 static HRESULT WINAPI audio_mediatype_GetItemByIndex(IMFAudioMediaType *iface, UINT32 index, GUID *key, PROPVARIANT *value)
1325 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1327 TRACE("%p, %u, %p, %p.\n", iface, index, key, value);
1329 return attributes_GetItemByIndex(&media_type->attributes, index, key, value);
1332 static HRESULT WINAPI audio_mediatype_CopyAllItems(IMFAudioMediaType *iface, IMFAttributes *dest)
1334 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1336 TRACE("%p, %p.\n", iface, dest);
1338 return attributes_CopyAllItems(&media_type->attributes, dest);
1341 static HRESULT WINAPI audio_mediatype_GetMajorType(IMFAudioMediaType *iface, GUID *guid)
1343 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1345 TRACE("%p, %p.\n", iface, guid);
1347 return attributes_GetGUID(&media_type->attributes, &MF_MT_MAJOR_TYPE, guid);
1350 static HRESULT WINAPI audio_mediatype_IsCompressedFormat(IMFAudioMediaType *iface, BOOL *compressed)
1352 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1354 TRACE("%p, %p.\n", iface, compressed);
1356 return mediatype_is_compressed(media_type, compressed);
1359 static HRESULT WINAPI audio_mediatype_IsEqual(IMFAudioMediaType *iface, IMFMediaType *type, DWORD *flags)
1361 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1363 TRACE("%p, %p, %p.\n", iface, type, flags);
1365 return media_type_is_equal(media_type, type, flags);
1368 static HRESULT WINAPI audio_mediatype_GetRepresentation(IMFAudioMediaType *iface, GUID guid, void **representation)
1370 FIXME("%p, %s, %p.\n", iface, debugstr_guid(&guid), representation);
1372 return E_NOTIMPL;
1375 static HRESULT WINAPI audio_mediatype_FreeRepresentation(IMFAudioMediaType *iface, GUID guid, void *representation)
1377 FIXME("%p, %s, %p.\n", iface, debugstr_guid(&guid), representation);
1379 return E_NOTIMPL;
1382 static const WAVEFORMATEX * WINAPI audio_mediatype_GetAudioFormat(IMFAudioMediaType *iface)
1384 struct media_type *media_type = impl_from_IMFAudioMediaType(iface);
1385 unsigned int size;
1386 HRESULT hr;
1388 TRACE("%p.\n", iface);
1390 CoTaskMemFree(media_type->audio_format);
1391 media_type->audio_format = NULL;
1392 if (FAILED(hr = MFCreateWaveFormatExFromMFMediaType(&media_type->IMFMediaType_iface, &media_type->audio_format,
1393 &size, MFWaveFormatExConvertFlag_Normal)))
1395 WARN("Failed to create wave format description, hr %#lx.\n", hr);
1398 return media_type->audio_format;
1401 static const IMFAudioMediaTypeVtbl audiomediatypevtbl =
1403 audio_mediatype_QueryInterface,
1404 audio_mediatype_AddRef,
1405 audio_mediatype_Release,
1406 audio_mediatype_GetItem,
1407 audio_mediatype_GetItemType,
1408 audio_mediatype_CompareItem,
1409 audio_mediatype_Compare,
1410 audio_mediatype_GetUINT32,
1411 audio_mediatype_GetUINT64,
1412 audio_mediatype_GetDouble,
1413 audio_mediatype_GetGUID,
1414 audio_mediatype_GetStringLength,
1415 audio_mediatype_GetString,
1416 audio_mediatype_GetAllocatedString,
1417 audio_mediatype_GetBlobSize,
1418 audio_mediatype_GetBlob,
1419 audio_mediatype_GetAllocatedBlob,
1420 audio_mediatype_GetUnknown,
1421 audio_mediatype_SetItem,
1422 audio_mediatype_DeleteItem,
1423 audio_mediatype_DeleteAllItems,
1424 audio_mediatype_SetUINT32,
1425 audio_mediatype_SetUINT64,
1426 audio_mediatype_SetDouble,
1427 audio_mediatype_SetGUID,
1428 audio_mediatype_SetString,
1429 audio_mediatype_SetBlob,
1430 audio_mediatype_SetUnknown,
1431 audio_mediatype_LockStore,
1432 audio_mediatype_UnlockStore,
1433 audio_mediatype_GetCount,
1434 audio_mediatype_GetItemByIndex,
1435 audio_mediatype_CopyAllItems,
1436 audio_mediatype_GetMajorType,
1437 audio_mediatype_IsCompressedFormat,
1438 audio_mediatype_IsEqual,
1439 audio_mediatype_GetRepresentation,
1440 audio_mediatype_FreeRepresentation,
1441 audio_mediatype_GetAudioFormat,
1444 static HRESULT create_media_type(struct media_type **ret)
1446 struct media_type *object;
1447 HRESULT hr;
1449 if (!(object = calloc(1, sizeof(*object))))
1450 return E_OUTOFMEMORY;
1452 if (FAILED(hr = init_attributes_object(&object->attributes, 0)))
1454 free(object);
1455 return hr;
1457 object->IMFMediaType_iface.lpVtbl = &mediatypevtbl;
1458 object->IMFVideoMediaType_iface.lpVtbl = &videomediatypevtbl;
1459 object->IMFAudioMediaType_iface.lpVtbl = &audiomediatypevtbl;
1461 *ret = object;
1463 return S_OK;
1466 /***********************************************************************
1467 * MFCreateMediaType (mfplat.@)
1469 HRESULT WINAPI MFCreateMediaType(IMFMediaType **media_type)
1471 struct media_type *object;
1472 HRESULT hr;
1474 TRACE("%p.\n", media_type);
1476 if (!media_type)
1477 return E_INVALIDARG;
1479 if (FAILED(hr = create_media_type(&object)))
1480 return hr;
1482 *media_type = &object->IMFMediaType_iface;
1484 TRACE("Created media type %p.\n", *media_type);
1486 return S_OK;
1489 static HRESULT WINAPI stream_descriptor_QueryInterface(IMFStreamDescriptor *iface, REFIID riid, void **out)
1491 TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), out);
1493 if (IsEqualIID(riid, &IID_IMFStreamDescriptor) ||
1494 IsEqualIID(riid, &IID_IMFAttributes) ||
1495 IsEqualIID(riid, &IID_IUnknown))
1497 *out = iface;
1498 IMFStreamDescriptor_AddRef(iface);
1499 return S_OK;
1502 WARN("Unsupported %s.\n", debugstr_guid(riid));
1503 *out = NULL;
1504 return E_NOINTERFACE;
1507 static ULONG WINAPI stream_descriptor_AddRef(IMFStreamDescriptor *iface)
1509 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1510 ULONG refcount = InterlockedIncrement(&stream_desc->attributes.ref);
1512 TRACE("%p, refcount %lu.\n", iface, refcount);
1514 return refcount;
1517 static ULONG WINAPI stream_descriptor_Release(IMFStreamDescriptor *iface)
1519 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1520 ULONG refcount = InterlockedDecrement(&stream_desc->attributes.ref);
1521 unsigned int i;
1523 TRACE("%p, refcount %lu.\n", iface, refcount);
1525 if (!refcount)
1527 for (i = 0; i < stream_desc->media_types_count; ++i)
1529 if (stream_desc->media_types[i])
1530 IMFMediaType_Release(stream_desc->media_types[i]);
1532 free(stream_desc->media_types);
1533 if (stream_desc->current_type)
1534 IMFMediaType_Release(stream_desc->current_type);
1535 clear_attributes_object(&stream_desc->attributes);
1536 free(stream_desc);
1539 return refcount;
1542 static HRESULT WINAPI stream_descriptor_GetItem(IMFStreamDescriptor *iface, REFGUID key, PROPVARIANT *value)
1544 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1546 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
1548 return attributes_GetItem(&stream_desc->attributes, key, value);
1551 static HRESULT WINAPI stream_descriptor_GetItemType(IMFStreamDescriptor *iface, REFGUID key, MF_ATTRIBUTE_TYPE *type)
1553 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1555 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), type);
1557 return attributes_GetItemType(&stream_desc->attributes, key, type);
1560 static HRESULT WINAPI stream_descriptor_CompareItem(IMFStreamDescriptor *iface, REFGUID key, REFPROPVARIANT value,
1561 BOOL *result)
1563 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1565 TRACE("%p, %s, %s, %p.\n", iface, debugstr_attr(key), debugstr_propvar(value), result);
1567 return attributes_CompareItem(&stream_desc->attributes, key, value, result);
1570 static HRESULT WINAPI stream_descriptor_Compare(IMFStreamDescriptor *iface, IMFAttributes *theirs,
1571 MF_ATTRIBUTES_MATCH_TYPE type, BOOL *result)
1573 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1575 TRACE("%p, %p, %d, %p.\n", iface, theirs, type, result);
1577 return attributes_Compare(&stream_desc->attributes, theirs, type, result);
1580 static HRESULT WINAPI stream_descriptor_GetUINT32(IMFStreamDescriptor *iface, REFGUID key, UINT32 *value)
1582 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1584 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
1586 return attributes_GetUINT32(&stream_desc->attributes, key, value);
1589 static HRESULT WINAPI stream_descriptor_GetUINT64(IMFStreamDescriptor *iface, REFGUID key, UINT64 *value)
1591 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1593 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
1595 return attributes_GetUINT64(&stream_desc->attributes, key, value);
1598 static HRESULT WINAPI stream_descriptor_GetDouble(IMFStreamDescriptor *iface, REFGUID key, double *value)
1600 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1602 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
1604 return attributes_GetDouble(&stream_desc->attributes, key, value);
1607 static HRESULT WINAPI stream_descriptor_GetGUID(IMFStreamDescriptor *iface, REFGUID key, GUID *value)
1609 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1611 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
1613 return attributes_GetGUID(&stream_desc->attributes, key, value);
1616 static HRESULT WINAPI stream_descriptor_GetStringLength(IMFStreamDescriptor *iface, REFGUID key, UINT32 *length)
1618 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1620 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), length);
1622 return attributes_GetStringLength(&stream_desc->attributes, key, length);
1625 static HRESULT WINAPI stream_descriptor_GetString(IMFStreamDescriptor *iface, REFGUID key, WCHAR *value,
1626 UINT32 size, UINT32 *length)
1628 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1630 TRACE("%p, %s, %p, %u, %p.\n", iface, debugstr_attr(key), value, size, length);
1632 return attributes_GetString(&stream_desc->attributes, key, value, size, length);
1635 static HRESULT WINAPI stream_descriptor_GetAllocatedString(IMFStreamDescriptor *iface, REFGUID key,
1636 WCHAR **value, UINT32 *length)
1638 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1640 TRACE("%p, %s, %p, %p.\n", iface, debugstr_attr(key), value, length);
1642 return attributes_GetAllocatedString(&stream_desc->attributes, key, value, length);
1645 static HRESULT WINAPI stream_descriptor_GetBlobSize(IMFStreamDescriptor *iface, REFGUID key, UINT32 *size)
1647 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1649 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), size);
1651 return attributes_GetBlobSize(&stream_desc->attributes, key, size);
1654 static HRESULT WINAPI stream_descriptor_GetBlob(IMFStreamDescriptor *iface, REFGUID key, UINT8 *buf,
1655 UINT32 bufsize, UINT32 *blobsize)
1657 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1659 TRACE("%p, %s, %p, %u, %p.\n", iface, debugstr_attr(key), buf, bufsize, blobsize);
1661 return attributes_GetBlob(&stream_desc->attributes, key, buf, bufsize, blobsize);
1664 static HRESULT WINAPI stream_descriptor_GetAllocatedBlob(IMFStreamDescriptor *iface, REFGUID key, UINT8 **buf,
1665 UINT32 *size)
1667 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1669 TRACE("%p, %s, %p, %p.\n", iface, debugstr_attr(key), buf, size);
1671 return attributes_GetAllocatedBlob(&stream_desc->attributes, key, buf, size);
1674 static HRESULT WINAPI stream_descriptor_GetUnknown(IMFStreamDescriptor *iface, REFGUID key, REFIID riid, void **out)
1676 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1678 TRACE("%p, %s, %s, %p.\n", iface, debugstr_attr(key), debugstr_guid(riid), out);
1680 return attributes_GetUnknown(&stream_desc->attributes, key, riid, out);
1683 static HRESULT WINAPI stream_descriptor_SetItem(IMFStreamDescriptor *iface, REFGUID key, REFPROPVARIANT value)
1685 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1687 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_propvar(value));
1689 return attributes_SetItem(&stream_desc->attributes, key, value);
1692 static HRESULT WINAPI stream_descriptor_DeleteItem(IMFStreamDescriptor *iface, REFGUID key)
1694 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1696 TRACE("%p, %s.\n", iface, debugstr_attr(key));
1698 return attributes_DeleteItem(&stream_desc->attributes, key);
1701 static HRESULT WINAPI stream_descriptor_DeleteAllItems(IMFStreamDescriptor *iface)
1703 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1705 TRACE("%p.\n", iface);
1707 return attributes_DeleteAllItems(&stream_desc->attributes);
1710 static HRESULT WINAPI stream_descriptor_SetUINT32(IMFStreamDescriptor *iface, REFGUID key, UINT32 value)
1712 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1714 TRACE("%p, %s, %u.\n", iface, debugstr_attr(key), value);
1716 return attributes_SetUINT32(&stream_desc->attributes, key, value);
1719 static HRESULT WINAPI stream_descriptor_SetUINT64(IMFStreamDescriptor *iface, REFGUID key, UINT64 value)
1721 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1723 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), wine_dbgstr_longlong(value));
1725 return attributes_SetUINT64(&stream_desc->attributes, key, value);
1728 static HRESULT WINAPI stream_descriptor_SetDouble(IMFStreamDescriptor *iface, REFGUID key, double value)
1730 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1732 TRACE("%p, %s, %f.\n", iface, debugstr_attr(key), value);
1734 return attributes_SetDouble(&stream_desc->attributes, key, value);
1737 static HRESULT WINAPI stream_descriptor_SetGUID(IMFStreamDescriptor *iface, REFGUID key, REFGUID value)
1739 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1741 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_mf_guid(value));
1743 return attributes_SetGUID(&stream_desc->attributes, key, value);
1746 static HRESULT WINAPI stream_descriptor_SetString(IMFStreamDescriptor *iface, REFGUID key, const WCHAR *value)
1748 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1750 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_w(value));
1752 return attributes_SetString(&stream_desc->attributes, key, value);
1755 static HRESULT WINAPI stream_descriptor_SetBlob(IMFStreamDescriptor *iface, REFGUID key, const UINT8 *buf, UINT32 size)
1757 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1759 TRACE("%p, %s, %p, %u.\n", iface, debugstr_attr(key), buf, size);
1761 return attributes_SetBlob(&stream_desc->attributes, key, buf, size);
1764 static HRESULT WINAPI stream_descriptor_SetUnknown(IMFStreamDescriptor *iface, REFGUID key, IUnknown *unknown)
1766 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1768 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), unknown);
1770 return attributes_SetUnknown(&stream_desc->attributes, key, unknown);
1773 static HRESULT WINAPI stream_descriptor_LockStore(IMFStreamDescriptor *iface)
1775 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1777 TRACE("%p.\n", iface);
1779 return attributes_LockStore(&stream_desc->attributes);
1782 static HRESULT WINAPI stream_descriptor_UnlockStore(IMFStreamDescriptor *iface)
1784 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1786 TRACE("%p.\n", iface);
1788 return attributes_UnlockStore(&stream_desc->attributes);
1791 static HRESULT WINAPI stream_descriptor_GetCount(IMFStreamDescriptor *iface, UINT32 *count)
1793 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1795 TRACE("%p, %p.\n", iface, count);
1797 return attributes_GetCount(&stream_desc->attributes, count);
1800 static HRESULT WINAPI stream_descriptor_GetItemByIndex(IMFStreamDescriptor *iface, UINT32 index, GUID *key,
1801 PROPVARIANT *value)
1803 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1805 TRACE("%p, %u, %p, %p.\n", iface, index, key, value);
1807 return attributes_GetItemByIndex(&stream_desc->attributes, index, key, value);
1810 static HRESULT WINAPI stream_descriptor_CopyAllItems(IMFStreamDescriptor *iface, IMFAttributes *dest)
1812 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1814 TRACE("%p, %p.\n", iface, dest);
1816 return attributes_CopyAllItems(&stream_desc->attributes, dest);
1819 static HRESULT WINAPI stream_descriptor_GetStreamIdentifier(IMFStreamDescriptor *iface, DWORD *identifier)
1821 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1823 TRACE("%p, %p.\n", iface, identifier);
1825 *identifier = stream_desc->identifier;
1827 return S_OK;
1830 static HRESULT WINAPI stream_descriptor_GetMediaTypeHandler(IMFStreamDescriptor *iface, IMFMediaTypeHandler **handler)
1832 struct stream_desc *stream_desc = impl_from_IMFStreamDescriptor(iface);
1834 TRACE("%p, %p.\n", iface, handler);
1836 *handler = &stream_desc->IMFMediaTypeHandler_iface;
1837 IMFMediaTypeHandler_AddRef(*handler);
1839 return S_OK;
1842 static const IMFStreamDescriptorVtbl streamdescriptorvtbl =
1844 stream_descriptor_QueryInterface,
1845 stream_descriptor_AddRef,
1846 stream_descriptor_Release,
1847 stream_descriptor_GetItem,
1848 stream_descriptor_GetItemType,
1849 stream_descriptor_CompareItem,
1850 stream_descriptor_Compare,
1851 stream_descriptor_GetUINT32,
1852 stream_descriptor_GetUINT64,
1853 stream_descriptor_GetDouble,
1854 stream_descriptor_GetGUID,
1855 stream_descriptor_GetStringLength,
1856 stream_descriptor_GetString,
1857 stream_descriptor_GetAllocatedString,
1858 stream_descriptor_GetBlobSize,
1859 stream_descriptor_GetBlob,
1860 stream_descriptor_GetAllocatedBlob,
1861 stream_descriptor_GetUnknown,
1862 stream_descriptor_SetItem,
1863 stream_descriptor_DeleteItem,
1864 stream_descriptor_DeleteAllItems,
1865 stream_descriptor_SetUINT32,
1866 stream_descriptor_SetUINT64,
1867 stream_descriptor_SetDouble,
1868 stream_descriptor_SetGUID,
1869 stream_descriptor_SetString,
1870 stream_descriptor_SetBlob,
1871 stream_descriptor_SetUnknown,
1872 stream_descriptor_LockStore,
1873 stream_descriptor_UnlockStore,
1874 stream_descriptor_GetCount,
1875 stream_descriptor_GetItemByIndex,
1876 stream_descriptor_CopyAllItems,
1877 stream_descriptor_GetStreamIdentifier,
1878 stream_descriptor_GetMediaTypeHandler
1881 static HRESULT WINAPI mediatype_handler_QueryInterface(IMFMediaTypeHandler *iface, REFIID riid, void **obj)
1883 TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), obj);
1885 if (IsEqualIID(riid, &IID_IMFMediaTypeHandler) ||
1886 IsEqualIID(riid, &IID_IUnknown))
1888 *obj = iface;
1889 IMFMediaTypeHandler_AddRef(iface);
1890 return S_OK;
1893 WARN("Unsupported %s.\n", debugstr_guid(riid));
1894 *obj = NULL;
1895 return E_NOINTERFACE;
1898 static ULONG WINAPI mediatype_handler_AddRef(IMFMediaTypeHandler *iface)
1900 struct stream_desc *stream_desc = impl_from_IMFMediaTypeHandler(iface);
1901 return IMFStreamDescriptor_AddRef(&stream_desc->IMFStreamDescriptor_iface);
1904 static ULONG WINAPI mediatype_handler_Release(IMFMediaTypeHandler *iface)
1906 struct stream_desc *stream_desc = impl_from_IMFMediaTypeHandler(iface);
1907 return IMFStreamDescriptor_Release(&stream_desc->IMFStreamDescriptor_iface);
1910 static BOOL stream_descriptor_is_mediatype_supported(IMFMediaType *media_type, IMFMediaType *candidate)
1912 DWORD flags = 0;
1914 if (FAILED(IMFMediaType_IsEqual(media_type, candidate, &flags)))
1915 return FALSE;
1917 return (flags & (MF_MEDIATYPE_EQUAL_MAJOR_TYPES | MF_MEDIATYPE_EQUAL_FORMAT_TYPES)) ==
1918 (MF_MEDIATYPE_EQUAL_MAJOR_TYPES | MF_MEDIATYPE_EQUAL_FORMAT_TYPES);
1921 static HRESULT WINAPI mediatype_handler_IsMediaTypeSupported(IMFMediaTypeHandler *iface, IMFMediaType *in_type,
1922 IMFMediaType **out_type)
1924 struct stream_desc *stream_desc = impl_from_IMFMediaTypeHandler(iface);
1925 BOOL supported = FALSE;
1926 unsigned int i;
1928 TRACE("%p, %p, %p.\n", iface, in_type, out_type);
1930 if (!in_type)
1931 return E_POINTER;
1933 if (out_type)
1934 *out_type = NULL;
1936 EnterCriticalSection(&stream_desc->attributes.cs);
1938 supported = stream_desc->current_type && stream_descriptor_is_mediatype_supported(stream_desc->current_type, in_type);
1939 if (!supported)
1941 for (i = 0; i < stream_desc->media_types_count; ++i)
1943 if ((supported = stream_descriptor_is_mediatype_supported(stream_desc->media_types[i], in_type)))
1944 break;
1948 LeaveCriticalSection(&stream_desc->attributes.cs);
1950 return supported ? S_OK : MF_E_INVALIDMEDIATYPE;
1953 static HRESULT WINAPI mediatype_handler_GetMediaTypeCount(IMFMediaTypeHandler *iface, DWORD *count)
1955 struct stream_desc *stream_desc = impl_from_IMFMediaTypeHandler(iface);
1957 TRACE("%p, %p.\n", iface, count);
1959 *count = stream_desc->media_types_count;
1961 return S_OK;
1964 static HRESULT WINAPI mediatype_handler_GetMediaTypeByIndex(IMFMediaTypeHandler *iface, DWORD index,
1965 IMFMediaType **type)
1967 struct stream_desc *stream_desc = impl_from_IMFMediaTypeHandler(iface);
1969 TRACE("%p, %lu, %p.\n", iface, index, type);
1971 if (index >= stream_desc->media_types_count)
1972 return MF_E_NO_MORE_TYPES;
1974 if (stream_desc->media_types[index])
1976 *type = stream_desc->media_types[index];
1977 IMFMediaType_AddRef(*type);
1980 return stream_desc->media_types[index] ? S_OK : E_FAIL;
1983 static HRESULT WINAPI mediatype_handler_SetCurrentMediaType(IMFMediaTypeHandler *iface, IMFMediaType *type)
1985 struct stream_desc *stream_desc = impl_from_IMFMediaTypeHandler(iface);
1987 TRACE("%p, %p.\n", iface, type);
1989 if (!type)
1990 return E_POINTER;
1992 EnterCriticalSection(&stream_desc->attributes.cs);
1993 if (stream_desc->current_type)
1994 IMFMediaType_Release(stream_desc->current_type);
1995 stream_desc->current_type = type;
1996 IMFMediaType_AddRef(stream_desc->current_type);
1997 LeaveCriticalSection(&stream_desc->attributes.cs);
1999 return S_OK;
2002 static HRESULT WINAPI mediatype_handler_GetCurrentMediaType(IMFMediaTypeHandler *iface, IMFMediaType **type)
2004 struct stream_desc *stream_desc = impl_from_IMFMediaTypeHandler(iface);
2005 HRESULT hr = S_OK;
2007 TRACE("%p, %p.\n", iface, type);
2009 EnterCriticalSection(&stream_desc->attributes.cs);
2010 if (stream_desc->current_type)
2012 *type = stream_desc->current_type;
2013 IMFMediaType_AddRef(*type);
2015 else
2016 hr = MF_E_NOT_INITIALIZED;
2017 LeaveCriticalSection(&stream_desc->attributes.cs);
2019 return hr;
2022 static HRESULT WINAPI mediatype_handler_GetMajorType(IMFMediaTypeHandler *iface, GUID *type)
2024 struct stream_desc *stream_desc = impl_from_IMFMediaTypeHandler(iface);
2025 HRESULT hr;
2027 TRACE("%p, %p.\n", iface, type);
2029 EnterCriticalSection(&stream_desc->attributes.cs);
2030 hr = IMFMediaType_GetGUID(stream_desc->current_type ? stream_desc->current_type :
2031 stream_desc->media_types[0], &MF_MT_MAJOR_TYPE, type);
2032 LeaveCriticalSection(&stream_desc->attributes.cs);
2034 return hr;
2037 static const IMFMediaTypeHandlerVtbl mediatypehandlervtbl =
2039 mediatype_handler_QueryInterface,
2040 mediatype_handler_AddRef,
2041 mediatype_handler_Release,
2042 mediatype_handler_IsMediaTypeSupported,
2043 mediatype_handler_GetMediaTypeCount,
2044 mediatype_handler_GetMediaTypeByIndex,
2045 mediatype_handler_SetCurrentMediaType,
2046 mediatype_handler_GetCurrentMediaType,
2047 mediatype_handler_GetMajorType,
2050 /***********************************************************************
2051 * MFCreateStreamDescriptor (mfplat.@)
2053 HRESULT WINAPI MFCreateStreamDescriptor(DWORD identifier, DWORD count,
2054 IMFMediaType **types, IMFStreamDescriptor **descriptor)
2056 struct stream_desc *object;
2057 unsigned int i;
2058 HRESULT hr;
2060 TRACE("%ld, %ld, %p, %p.\n", identifier, count, types, descriptor);
2062 if (!count)
2063 return E_INVALIDARG;
2065 if (!(object = calloc(1, sizeof(*object))))
2066 return E_OUTOFMEMORY;
2068 if (FAILED(hr = init_attributes_object(&object->attributes, 0)))
2070 free(object);
2071 return hr;
2073 object->IMFStreamDescriptor_iface.lpVtbl = &streamdescriptorvtbl;
2074 object->IMFMediaTypeHandler_iface.lpVtbl = &mediatypehandlervtbl;
2075 object->identifier = identifier;
2076 object->media_types = calloc(count, sizeof(*object->media_types));
2077 if (!object->media_types)
2079 IMFStreamDescriptor_Release(&object->IMFStreamDescriptor_iface);
2080 return E_OUTOFMEMORY;
2082 for (i = 0; i < count; ++i)
2084 object->media_types[i] = types[i];
2085 if (object->media_types[i])
2086 IMFMediaType_AddRef(object->media_types[i]);
2088 object->media_types_count = count;
2090 *descriptor = &object->IMFStreamDescriptor_iface;
2092 return S_OK;
2095 static HRESULT WINAPI presentation_descriptor_QueryInterface(IMFPresentationDescriptor *iface, REFIID riid, void **out)
2097 TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), out);
2099 if (IsEqualIID(riid, &IID_IMFPresentationDescriptor) ||
2100 IsEqualIID(riid, &IID_IMFAttributes) ||
2101 IsEqualIID(riid, &IID_IUnknown))
2103 *out = iface;
2104 IMFPresentationDescriptor_AddRef(iface);
2105 return S_OK;
2108 WARN("Unsupported %s.\n", debugstr_guid(riid));
2109 *out = NULL;
2110 return E_NOINTERFACE;
2113 static ULONG WINAPI presentation_descriptor_AddRef(IMFPresentationDescriptor *iface)
2115 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2116 ULONG refcount = InterlockedIncrement(&presentation_desc->attributes.ref);
2118 TRACE("%p, refcount %lu.\n", iface, refcount);
2120 return refcount;
2123 static ULONG WINAPI presentation_descriptor_Release(IMFPresentationDescriptor *iface)
2125 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2126 ULONG refcount = InterlockedDecrement(&presentation_desc->attributes.ref);
2127 unsigned int i;
2129 TRACE("%p, refcount %lu.\n", iface, refcount);
2131 if (!refcount)
2133 for (i = 0; i < presentation_desc->count; ++i)
2135 if (presentation_desc->descriptors[i].descriptor)
2136 IMFStreamDescriptor_Release(presentation_desc->descriptors[i].descriptor);
2138 clear_attributes_object(&presentation_desc->attributes);
2139 free(presentation_desc->descriptors);
2140 free(presentation_desc);
2143 return refcount;
2146 static HRESULT WINAPI presentation_descriptor_GetItem(IMFPresentationDescriptor *iface, REFGUID key,
2147 PROPVARIANT *value)
2149 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2151 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
2153 return attributes_GetItem(&presentation_desc->attributes, key, value);
2156 static HRESULT WINAPI presentation_descriptor_GetItemType(IMFPresentationDescriptor *iface, REFGUID key,
2157 MF_ATTRIBUTE_TYPE *type)
2159 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2161 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), type);
2163 return attributes_GetItemType(&presentation_desc->attributes, key, type);
2166 static HRESULT WINAPI presentation_descriptor_CompareItem(IMFPresentationDescriptor *iface, REFGUID key,
2167 REFPROPVARIANT value, BOOL *result)
2169 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2171 TRACE("%p, %s, %s, %p.\n", iface, debugstr_attr(key), debugstr_propvar(value), result);
2173 return attributes_CompareItem(&presentation_desc->attributes, key, value, result);
2176 static HRESULT WINAPI presentation_descriptor_Compare(IMFPresentationDescriptor *iface, IMFAttributes *attrs,
2177 MF_ATTRIBUTES_MATCH_TYPE type, BOOL *result)
2179 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2181 TRACE("%p, %p, %d, %p.\n", iface, attrs, type, result);
2183 return attributes_Compare(&presentation_desc->attributes, attrs, type, result);
2186 static HRESULT WINAPI presentation_descriptor_GetUINT32(IMFPresentationDescriptor *iface, REFGUID key, UINT32 *value)
2188 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2190 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
2192 return attributes_GetUINT32(&presentation_desc->attributes, key, value);
2195 static HRESULT WINAPI presentation_descriptor_GetUINT64(IMFPresentationDescriptor *iface, REFGUID key, UINT64 *value)
2197 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2199 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
2201 return attributes_GetUINT64(&presentation_desc->attributes, key, value);
2204 static HRESULT WINAPI presentation_descriptor_GetDouble(IMFPresentationDescriptor *iface, REFGUID key, double *value)
2206 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2208 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
2210 return attributes_GetDouble(&presentation_desc->attributes, key, value);
2213 static HRESULT WINAPI presentation_descriptor_GetGUID(IMFPresentationDescriptor *iface, REFGUID key, GUID *value)
2215 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2217 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), value);
2219 return attributes_GetGUID(&presentation_desc->attributes, key, value);
2222 static HRESULT WINAPI presentation_descriptor_GetStringLength(IMFPresentationDescriptor *iface, REFGUID key,
2223 UINT32 *length)
2225 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2227 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), length);
2229 return attributes_GetStringLength(&presentation_desc->attributes, key, length);
2232 static HRESULT WINAPI presentation_descriptor_GetString(IMFPresentationDescriptor *iface, REFGUID key, WCHAR *value,
2233 UINT32 size, UINT32 *length)
2235 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2237 TRACE("%p, %s, %p, %u, %p.\n", iface, debugstr_attr(key), value, size, length);
2239 return attributes_GetString(&presentation_desc->attributes, key, value, size, length);
2242 static HRESULT WINAPI presentation_descriptor_GetAllocatedString(IMFPresentationDescriptor *iface, REFGUID key,
2243 WCHAR **value, UINT32 *length)
2245 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2247 TRACE("%p, %s, %p, %p.\n", iface, debugstr_attr(key), value, length);
2249 return attributes_GetAllocatedString(&presentation_desc->attributes, key, value, length);
2252 static HRESULT WINAPI presentation_descriptor_GetBlobSize(IMFPresentationDescriptor *iface, REFGUID key, UINT32 *size)
2254 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2256 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), size);
2258 return attributes_GetBlobSize(&presentation_desc->attributes, key, size);
2261 static HRESULT WINAPI presentation_descriptor_GetBlob(IMFPresentationDescriptor *iface, REFGUID key, UINT8 *buf,
2262 UINT32 bufsize, UINT32 *blobsize)
2264 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2266 TRACE("%p, %s, %p, %u, %p.\n", iface, debugstr_attr(key), buf, bufsize, blobsize);
2268 return attributes_GetBlob(&presentation_desc->attributes, key, buf, bufsize, blobsize);
2271 static HRESULT WINAPI presentation_descriptor_GetAllocatedBlob(IMFPresentationDescriptor *iface, REFGUID key,
2272 UINT8 **buf, UINT32 *size)
2274 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2276 TRACE("%p, %s, %p, %p.\n", iface, debugstr_attr(key), buf, size);
2278 return attributes_GetAllocatedBlob(&presentation_desc->attributes, key, buf, size);
2281 static HRESULT WINAPI presentation_descriptor_GetUnknown(IMFPresentationDescriptor *iface, REFGUID key,
2282 REFIID riid, void **out)
2284 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2286 TRACE("%p, %s, %s, %p.\n", iface, debugstr_attr(key), debugstr_guid(riid), out);
2288 return attributes_GetUnknown(&presentation_desc->attributes, key, riid, out);
2291 static HRESULT WINAPI presentation_descriptor_SetItem(IMFPresentationDescriptor *iface, REFGUID key,
2292 REFPROPVARIANT value)
2294 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2296 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_propvar(value));
2298 return attributes_SetItem(&presentation_desc->attributes, key, value);
2301 static HRESULT WINAPI presentation_descriptor_DeleteItem(IMFPresentationDescriptor *iface, REFGUID key)
2303 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2305 TRACE("%p, %s.\n", iface, debugstr_attr(key));
2307 return attributes_DeleteItem(&presentation_desc->attributes, key);
2310 static HRESULT WINAPI presentation_descriptor_DeleteAllItems(IMFPresentationDescriptor *iface)
2312 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2314 TRACE("%p.\n", iface);
2316 return attributes_DeleteAllItems(&presentation_desc->attributes);
2319 static HRESULT WINAPI presentation_descriptor_SetUINT32(IMFPresentationDescriptor *iface, REFGUID key, UINT32 value)
2321 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2323 TRACE("%p, %s, %u.\n", iface, debugstr_attr(key), value);
2325 return attributes_SetUINT32(&presentation_desc->attributes, key, value);
2328 static HRESULT WINAPI presentation_descriptor_SetUINT64(IMFPresentationDescriptor *iface, REFGUID key, UINT64 value)
2330 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2332 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), wine_dbgstr_longlong(value));
2334 return attributes_SetUINT64(&presentation_desc->attributes, key, value);
2337 static HRESULT WINAPI presentation_descriptor_SetDouble(IMFPresentationDescriptor *iface, REFGUID key, double value)
2339 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2341 TRACE("%p, %s, %f.\n", iface, debugstr_attr(key), value);
2343 return attributes_SetDouble(&presentation_desc->attributes, key, value);
2346 static HRESULT WINAPI presentation_descriptor_SetGUID(IMFPresentationDescriptor *iface, REFGUID key, REFGUID value)
2348 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2350 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_mf_guid(value));
2352 return attributes_SetGUID(&presentation_desc->attributes, key, value);
2355 static HRESULT WINAPI presentation_descriptor_SetString(IMFPresentationDescriptor *iface, REFGUID key,
2356 const WCHAR *value)
2358 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2360 TRACE("%p, %s, %s.\n", iface, debugstr_attr(key), debugstr_w(value));
2362 return attributes_SetString(&presentation_desc->attributes, key, value);
2365 static HRESULT WINAPI presentation_descriptor_SetBlob(IMFPresentationDescriptor *iface, REFGUID key, const UINT8 *buf,
2366 UINT32 size)
2368 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2370 TRACE("%p, %s, %p, %u.\n", iface, debugstr_attr(key), buf, size);
2372 return attributes_SetBlob(&presentation_desc->attributes, key, buf, size);
2375 static HRESULT WINAPI presentation_descriptor_SetUnknown(IMFPresentationDescriptor *iface, REFGUID key,
2376 IUnknown *unknown)
2378 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2380 TRACE("%p, %s, %p.\n", iface, debugstr_attr(key), unknown);
2382 return attributes_SetUnknown(&presentation_desc->attributes, key, unknown);
2385 static HRESULT WINAPI presentation_descriptor_LockStore(IMFPresentationDescriptor *iface)
2387 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2389 TRACE("%p.\n", iface);
2391 return attributes_LockStore(&presentation_desc->attributes);
2394 static HRESULT WINAPI presentation_descriptor_UnlockStore(IMFPresentationDescriptor *iface)
2396 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2398 TRACE("%p.\n", iface);
2400 return attributes_UnlockStore(&presentation_desc->attributes);
2403 static HRESULT WINAPI presentation_descriptor_GetCount(IMFPresentationDescriptor *iface, UINT32 *count)
2405 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2407 TRACE("%p, %p.\n", iface, count);
2409 return attributes_GetCount(&presentation_desc->attributes, count);
2412 static HRESULT WINAPI presentation_descriptor_GetItemByIndex(IMFPresentationDescriptor *iface, UINT32 index, GUID *key,
2413 PROPVARIANT *value)
2415 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2417 TRACE("%p, %u, %p, %p.\n", iface, index, key, value);
2419 return attributes_GetItemByIndex(&presentation_desc->attributes, index, key, value);
2422 static HRESULT WINAPI presentation_descriptor_CopyAllItems(IMFPresentationDescriptor *iface, IMFAttributes *dest)
2424 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2426 TRACE("%p, %p.\n", iface, dest);
2428 return attributes_CopyAllItems(&presentation_desc->attributes, dest);
2431 static HRESULT WINAPI presentation_descriptor_GetStreamDescriptorCount(IMFPresentationDescriptor *iface, DWORD *count)
2433 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2435 TRACE("%p, %p.\n", iface, count);
2437 *count = presentation_desc->count;
2439 return S_OK;
2442 static HRESULT WINAPI presentation_descriptor_GetStreamDescriptorByIndex(IMFPresentationDescriptor *iface, DWORD index,
2443 BOOL *selected, IMFStreamDescriptor **descriptor)
2445 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2447 TRACE("%p, %lu, %p, %p.\n", iface, index, selected, descriptor);
2449 if (index >= presentation_desc->count)
2450 return E_INVALIDARG;
2452 EnterCriticalSection(&presentation_desc->attributes.cs);
2453 *selected = presentation_desc->descriptors[index].selected;
2454 LeaveCriticalSection(&presentation_desc->attributes.cs);
2456 *descriptor = presentation_desc->descriptors[index].descriptor;
2457 IMFStreamDescriptor_AddRef(*descriptor);
2459 return S_OK;
2462 static HRESULT WINAPI presentation_descriptor_SelectStream(IMFPresentationDescriptor *iface, DWORD index)
2464 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2466 TRACE("%p, %lu.\n", iface, index);
2468 if (index >= presentation_desc->count)
2469 return E_INVALIDARG;
2471 EnterCriticalSection(&presentation_desc->attributes.cs);
2472 presentation_desc->descriptors[index].selected = TRUE;
2473 LeaveCriticalSection(&presentation_desc->attributes.cs);
2475 return S_OK;
2478 static HRESULT WINAPI presentation_descriptor_DeselectStream(IMFPresentationDescriptor *iface, DWORD index)
2480 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2482 TRACE("%p, %lu.\n", iface, index);
2484 if (index >= presentation_desc->count)
2485 return E_INVALIDARG;
2487 EnterCriticalSection(&presentation_desc->attributes.cs);
2488 presentation_desc->descriptors[index].selected = FALSE;
2489 LeaveCriticalSection(&presentation_desc->attributes.cs);
2491 return S_OK;
2494 static HRESULT WINAPI presentation_descriptor_Clone(IMFPresentationDescriptor *iface,
2495 IMFPresentationDescriptor **descriptor)
2497 struct presentation_desc *presentation_desc = impl_from_IMFPresentationDescriptor(iface);
2498 struct presentation_desc *object;
2499 unsigned int i;
2501 TRACE("%p, %p.\n", iface, descriptor);
2503 if (!(object = calloc(1, sizeof(*object))))
2504 return E_OUTOFMEMORY;
2506 presentation_descriptor_init(object, presentation_desc->count);
2508 EnterCriticalSection(&presentation_desc->attributes.cs);
2510 for (i = 0; i < presentation_desc->count; ++i)
2512 object->descriptors[i] = presentation_desc->descriptors[i];
2513 IMFStreamDescriptor_AddRef(object->descriptors[i].descriptor);
2516 attributes_CopyAllItems(&presentation_desc->attributes, (IMFAttributes *)&object->IMFPresentationDescriptor_iface);
2518 LeaveCriticalSection(&presentation_desc->attributes.cs);
2520 *descriptor = &object->IMFPresentationDescriptor_iface;
2522 return S_OK;
2525 static const IMFPresentationDescriptorVtbl presentationdescriptorvtbl =
2527 presentation_descriptor_QueryInterface,
2528 presentation_descriptor_AddRef,
2529 presentation_descriptor_Release,
2530 presentation_descriptor_GetItem,
2531 presentation_descriptor_GetItemType,
2532 presentation_descriptor_CompareItem,
2533 presentation_descriptor_Compare,
2534 presentation_descriptor_GetUINT32,
2535 presentation_descriptor_GetUINT64,
2536 presentation_descriptor_GetDouble,
2537 presentation_descriptor_GetGUID,
2538 presentation_descriptor_GetStringLength,
2539 presentation_descriptor_GetString,
2540 presentation_descriptor_GetAllocatedString,
2541 presentation_descriptor_GetBlobSize,
2542 presentation_descriptor_GetBlob,
2543 presentation_descriptor_GetAllocatedBlob,
2544 presentation_descriptor_GetUnknown,
2545 presentation_descriptor_SetItem,
2546 presentation_descriptor_DeleteItem,
2547 presentation_descriptor_DeleteAllItems,
2548 presentation_descriptor_SetUINT32,
2549 presentation_descriptor_SetUINT64,
2550 presentation_descriptor_SetDouble,
2551 presentation_descriptor_SetGUID,
2552 presentation_descriptor_SetString,
2553 presentation_descriptor_SetBlob,
2554 presentation_descriptor_SetUnknown,
2555 presentation_descriptor_LockStore,
2556 presentation_descriptor_UnlockStore,
2557 presentation_descriptor_GetCount,
2558 presentation_descriptor_GetItemByIndex,
2559 presentation_descriptor_CopyAllItems,
2560 presentation_descriptor_GetStreamDescriptorCount,
2561 presentation_descriptor_GetStreamDescriptorByIndex,
2562 presentation_descriptor_SelectStream,
2563 presentation_descriptor_DeselectStream,
2564 presentation_descriptor_Clone,
2567 static HRESULT presentation_descriptor_init(struct presentation_desc *object, DWORD count)
2569 HRESULT hr;
2571 if (FAILED(hr = init_attributes_object(&object->attributes, 0)))
2572 return hr;
2573 object->IMFPresentationDescriptor_iface.lpVtbl = &presentationdescriptorvtbl;
2574 if (!(object->descriptors = calloc(count, sizeof(*object->descriptors))))
2576 IMFPresentationDescriptor_Release(&object->IMFPresentationDescriptor_iface);
2577 return E_OUTOFMEMORY;
2579 object->count = count;
2581 return S_OK;
2584 /***********************************************************************
2585 * MFCreatePresentationDescriptor (mfplat.@)
2587 HRESULT WINAPI MFCreatePresentationDescriptor(DWORD count, IMFStreamDescriptor **descriptors,
2588 IMFPresentationDescriptor **out)
2590 struct presentation_desc *object;
2591 unsigned int i;
2592 HRESULT hr;
2594 TRACE("%lu, %p, %p.\n", count, descriptors, out);
2596 if (!count)
2597 return E_INVALIDARG;
2599 for (i = 0; i < count; ++i)
2601 if (!descriptors[i])
2602 return E_INVALIDARG;
2605 if (!(object = calloc(1, sizeof(*object))))
2606 return E_OUTOFMEMORY;
2608 if (FAILED(hr = presentation_descriptor_init(object, count)))
2610 free(object);
2611 return hr;
2614 for (i = 0; i < count; ++i)
2616 object->descriptors[i].descriptor = descriptors[i];
2617 IMFStreamDescriptor_AddRef(object->descriptors[i].descriptor);
2620 *out = &object->IMFPresentationDescriptor_iface;
2622 return S_OK;
2625 struct uncompressed_video_format
2627 const GUID *subtype;
2628 unsigned char bytes_per_pixel;
2629 unsigned char alignment;
2630 unsigned char bottom_up;
2631 unsigned char yuv;
2634 static int __cdecl uncompressed_video_format_compare(const void *a, const void *b)
2636 const GUID *guid = a;
2637 const struct uncompressed_video_format *format = b;
2638 return memcmp(guid, format->subtype, sizeof(*guid));
2641 static const struct uncompressed_video_format video_formats[] =
2643 { &MFVideoFormat_RGB24, 3, 3, 1, 0 },
2644 { &MFVideoFormat_ARGB32, 4, 3, 1, 0 },
2645 { &MFVideoFormat_RGB32, 4, 3, 1, 0 },
2646 { &MFVideoFormat_RGB565, 2, 3, 1, 0 },
2647 { &MFVideoFormat_RGB555, 2, 3, 1, 0 },
2648 { &MFVideoFormat_A2R10G10B10, 4, 3, 1, 0 },
2649 { &MFVideoFormat_A2B10G10R10, 4, 3, 1, 0 },
2650 { &MFVideoFormat_RGB8, 1, 3, 1, 0 },
2651 { &MFVideoFormat_L8, 1, 3, 1, 0 },
2652 { &MFVideoFormat_AYUV, 4, 3, 0, 1 },
2653 { &MFVideoFormat_I420, 1, 0, 0, 1 },
2654 { &MFVideoFormat_IMC1, 2, 3, 0, 1 },
2655 { &MFVideoFormat_IMC2, 1, 0, 0, 1 },
2656 { &MFVideoFormat_IMC3, 2, 3, 0, 1 },
2657 { &MFVideoFormat_IMC4, 1, 0, 0, 1 },
2658 { &MFVideoFormat_IYUV, 1, 0, 0, 1 },
2659 { &MFVideoFormat_NV11, 1, 0, 0, 1 },
2660 { &MFVideoFormat_NV12, 1, 0, 0, 1 },
2661 { &MFVideoFormat_D16, 2, 3, 0, 0 },
2662 { &MFVideoFormat_L16, 2, 3, 0, 0 },
2663 { &MFVideoFormat_UYVY, 2, 0, 0, 1 },
2664 { &MFVideoFormat_YUY2, 2, 0, 0, 1 },
2665 { &MFVideoFormat_YV12, 1, 0, 0, 1 },
2666 { &MFVideoFormat_YVYU, 2, 0, 0, 1 },
2667 { &MFVideoFormat_A16B16G16R16F, 8, 3, 1, 0 },
2668 { &MEDIASUBTYPE_RGB8, 1, 3, 1, 0 },
2669 { &MEDIASUBTYPE_RGB565, 2, 3, 1, 0 },
2670 { &MEDIASUBTYPE_RGB555, 2, 3, 1, 0 },
2671 { &MEDIASUBTYPE_RGB24, 3, 3, 1, 0 },
2672 { &MEDIASUBTYPE_RGB32, 4, 3, 1, 0 },
2675 static struct uncompressed_video_format *mf_get_video_format(const GUID *subtype)
2677 return bsearch(subtype, video_formats, ARRAY_SIZE(video_formats), sizeof(*video_formats),
2678 uncompressed_video_format_compare);
2681 static unsigned int mf_get_stride_for_format(const struct uncompressed_video_format *format, unsigned int width)
2683 return (width * format->bytes_per_pixel + format->alignment) & ~format->alignment;
2686 unsigned int mf_format_get_stride(const GUID *subtype, unsigned int width, BOOL *is_yuv)
2688 struct uncompressed_video_format *format = mf_get_video_format(subtype);
2690 if (format)
2692 *is_yuv = format->yuv;
2693 return mf_get_stride_for_format(format, width);
2696 return 0;
2699 /***********************************************************************
2700 * MFGetStrideForBitmapInfoHeader (mfplat.@)
2702 HRESULT WINAPI MFGetStrideForBitmapInfoHeader(DWORD fourcc, DWORD width, LONG *stride)
2704 struct uncompressed_video_format *format;
2705 GUID subtype;
2707 TRACE("%s, %lu, %p.\n", mf_debugstr_fourcc(fourcc), width, stride);
2709 memcpy(&subtype, &MFVideoFormat_Base, sizeof(subtype));
2710 subtype.Data1 = fourcc;
2712 if (!(format = mf_get_video_format(&subtype)))
2714 *stride = 0;
2715 return MF_E_INVALIDMEDIATYPE;
2718 *stride = mf_get_stride_for_format(format, width);
2719 if (format->bottom_up)
2720 *stride *= -1;
2722 return S_OK;
2725 /***********************************************************************
2726 * MFCalculateImageSize (mfplat.@)
2728 HRESULT WINAPI MFCalculateImageSize(REFGUID subtype, UINT32 width, UINT32 height, UINT32 *size)
2730 struct uncompressed_video_format *format;
2731 unsigned int stride;
2733 TRACE("%s, %u, %u, %p.\n", debugstr_mf_guid(subtype), width, height, size);
2735 if (!(format = mf_get_video_format(subtype)))
2737 *size = 0;
2738 return E_INVALIDARG;
2741 switch (subtype->Data1)
2743 case MAKEFOURCC('I','M','C','2'):
2744 case MAKEFOURCC('I','M','C','4'):
2745 case MAKEFOURCC('N','V','1','2'):
2746 case MAKEFOURCC('Y','V','1','2'):
2747 case MAKEFOURCC('I','4','2','0'):
2748 case MAKEFOURCC('I','Y','U','V'):
2749 /* 2 x 2 block, interleaving UV for half the height */
2750 *size = ((width + 1) & ~1) * height * 3 / 2;
2751 break;
2752 case MAKEFOURCC('N','V','1','1'):
2753 *size = ((width + 3) & ~3) * height * 3 / 2;
2754 break;
2755 case D3DFMT_L8:
2756 case D3DFMT_L16:
2757 case D3DFMT_D16:
2758 *size = width * format->bytes_per_pixel * height;
2759 break;
2760 default:
2761 stride = mf_get_stride_for_format(format, width);
2762 *size = stride * height;
2765 return S_OK;
2768 /***********************************************************************
2769 * MFGetPlaneSize (mfplat.@)
2771 HRESULT WINAPI MFGetPlaneSize(DWORD fourcc, DWORD width, DWORD height, DWORD *size)
2773 struct uncompressed_video_format *format;
2774 unsigned int stride;
2775 GUID subtype;
2777 TRACE("%s, %lu, %lu, %p.\n", mf_debugstr_fourcc(fourcc), width, height, size);
2779 memcpy(&subtype, &MFVideoFormat_Base, sizeof(subtype));
2780 subtype.Data1 = fourcc;
2782 if ((format = mf_get_video_format(&subtype)))
2783 stride = mf_get_stride_for_format(format, width);
2784 else
2785 stride = 0;
2787 switch (fourcc)
2789 case MAKEFOURCC('I','M','C','2'):
2790 case MAKEFOURCC('I','M','C','4'):
2791 case MAKEFOURCC('N','V','1','2'):
2792 case MAKEFOURCC('Y','V','1','2'):
2793 case MAKEFOURCC('I','4','2','0'):
2794 case MAKEFOURCC('I','Y','U','V'):
2795 case MAKEFOURCC('N','V','1','1'):
2796 *size = stride * height * 3 / 2;
2797 break;
2798 default:
2799 *size = stride * height;
2802 return S_OK;
2805 /***********************************************************************
2806 * MFCompareFullToPartialMediaType (mfplat.@)
2808 BOOL WINAPI MFCompareFullToPartialMediaType(IMFMediaType *full_type, IMFMediaType *partial_type)
2810 BOOL result;
2811 GUID major;
2813 TRACE("%p, %p.\n", full_type, partial_type);
2815 if (FAILED(IMFMediaType_GetMajorType(partial_type, &major)))
2816 return FALSE;
2818 if (FAILED(IMFMediaType_Compare(partial_type, (IMFAttributes *)full_type, MF_ATTRIBUTES_MATCH_OUR_ITEMS, &result)))
2819 return FALSE;
2821 return result;
2824 /***********************************************************************
2825 * MFWrapMediaType (mfplat.@)
2827 HRESULT WINAPI MFWrapMediaType(IMFMediaType *original, REFGUID major, REFGUID subtype, IMFMediaType **ret)
2829 IMFMediaType *mediatype;
2830 UINT8 *buffer;
2831 UINT32 size;
2832 HRESULT hr;
2834 TRACE("%p, %s, %s, %p.\n", original, debugstr_guid(major), debugstr_guid(subtype), ret);
2836 if (FAILED(hr = MFGetAttributesAsBlobSize((IMFAttributes *)original, &size)))
2837 return hr;
2839 if (!(buffer = malloc(size)))
2840 return E_OUTOFMEMORY;
2842 if (FAILED(hr = MFGetAttributesAsBlob((IMFAttributes *)original, buffer, size)))
2843 goto failed;
2845 if (FAILED(hr = MFCreateMediaType(&mediatype)))
2846 goto failed;
2848 if (FAILED(hr = IMFMediaType_SetGUID(mediatype, &MF_MT_MAJOR_TYPE, major)))
2849 goto failed;
2851 if (FAILED(hr = IMFMediaType_SetGUID(mediatype, &MF_MT_SUBTYPE, subtype)))
2852 goto failed;
2854 if (FAILED(hr = IMFMediaType_SetBlob(mediatype, &MF_MT_WRAPPED_TYPE, buffer, size)))
2855 goto failed;
2857 *ret = mediatype;
2859 failed:
2860 free(buffer);
2862 return hr;
2865 /***********************************************************************
2866 * MFUnwrapMediaType (mfplat.@)
2868 HRESULT WINAPI MFUnwrapMediaType(IMFMediaType *wrapper, IMFMediaType **ret)
2870 IMFMediaType *mediatype;
2871 UINT8 *buffer;
2872 UINT32 size;
2873 HRESULT hr;
2875 TRACE("%p, %p.\n", wrapper, ret);
2877 if (FAILED(hr = MFCreateMediaType(&mediatype)))
2878 return hr;
2880 if (FAILED(hr = IMFMediaType_GetAllocatedBlob(wrapper, &MF_MT_WRAPPED_TYPE, &buffer, &size)))
2882 IMFMediaType_Release(mediatype);
2883 return hr;
2886 hr = MFInitAttributesFromBlob((IMFAttributes *)mediatype, buffer, size);
2887 CoTaskMemFree(buffer);
2888 if (FAILED(hr))
2889 return hr;
2891 *ret = mediatype;
2893 return S_OK;
2896 /***********************************************************************
2897 * MFCreateWaveFormatExFromMFMediaType (mfplat.@)
2899 HRESULT WINAPI MFCreateWaveFormatExFromMFMediaType(IMFMediaType *mediatype, WAVEFORMATEX **ret_format,
2900 UINT32 *size, UINT32 flags)
2902 WAVEFORMATEXTENSIBLE *format_ext = NULL;
2903 WAVEFORMATEX *format;
2904 GUID major, subtype;
2905 UINT32 value;
2906 HRESULT hr;
2908 TRACE("%p, %p, %p, %#x.\n", mediatype, ret_format, size, flags);
2910 if (FAILED(hr = IMFMediaType_GetGUID(mediatype, &MF_MT_MAJOR_TYPE, &major)))
2911 return hr;
2913 if (FAILED(hr = IMFMediaType_GetGUID(mediatype, &MF_MT_SUBTYPE, &subtype)))
2914 return hr;
2916 if (!IsEqualGUID(&major, &MFMediaType_Audio))
2917 return E_INVALIDARG;
2919 if (!IsEqualGUID(&subtype, &MFAudioFormat_PCM) && !IsEqualGUID(&subtype, &MFAudioFormat_Float))
2921 FIXME("Unsupported audio format %s.\n", debugstr_guid(&subtype));
2922 return E_NOTIMPL;
2925 /* FIXME: probably WAVE_FORMAT_MPEG/WAVE_FORMAT_MPEGLAYER3 should be handled separately. */
2926 if (flags == MFWaveFormatExConvertFlag_ForceExtensible)
2928 format_ext = CoTaskMemAlloc(sizeof(*format_ext));
2929 *size = sizeof(*format_ext);
2930 format = (WAVEFORMATEX *)format_ext;
2932 else
2934 format = CoTaskMemAlloc(sizeof(*format));
2935 *size = sizeof(*format);
2938 if (!format)
2939 return E_OUTOFMEMORY;
2941 memset(format, 0, *size);
2943 if (format_ext)
2944 format->wFormatTag = WAVE_FORMAT_EXTENSIBLE;
2945 else if (IsEqualGUID(&subtype, &MFAudioFormat_Float))
2946 format->wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
2947 else
2948 format->wFormatTag = WAVE_FORMAT_PCM;
2950 if (SUCCEEDED(IMFMediaType_GetUINT32(mediatype, &MF_MT_AUDIO_NUM_CHANNELS, &value)))
2951 format->nChannels = value;
2952 if (SUCCEEDED(IMFMediaType_GetUINT32(mediatype, &MF_MT_AUDIO_SAMPLES_PER_SECOND, &value)))
2953 format->nSamplesPerSec = value;
2954 if (SUCCEEDED(IMFMediaType_GetUINT32(mediatype, &MF_MT_AUDIO_AVG_BYTES_PER_SECOND, &value)))
2955 format->nAvgBytesPerSec = value;
2956 if (SUCCEEDED(IMFMediaType_GetUINT32(mediatype, &MF_MT_AUDIO_BLOCK_ALIGNMENT, &value)))
2957 format->nBlockAlign = value;
2958 if (SUCCEEDED(IMFMediaType_GetUINT32(mediatype, &MF_MT_AUDIO_BITS_PER_SAMPLE, &value)))
2959 format->wBitsPerSample = value;
2960 if (format_ext)
2962 format->cbSize = sizeof(*format_ext) - sizeof(*format);
2964 if (SUCCEEDED(IMFMediaType_GetUINT32(mediatype, &MF_MT_AUDIO_VALID_BITS_PER_SAMPLE, &value)))
2965 format_ext->Samples.wSamplesPerBlock = value;
2967 if (SUCCEEDED(IMFMediaType_GetUINT32(mediatype, &MF_MT_AUDIO_CHANNEL_MASK, &value)))
2968 format_ext->dwChannelMask = value;
2969 memcpy(&format_ext->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM, sizeof(format_ext->SubFormat));
2972 *ret_format = format;
2974 return S_OK;
2977 static void mediatype_set_uint32(IMFMediaType *mediatype, const GUID *attr, unsigned int value, HRESULT *hr)
2979 if (SUCCEEDED(*hr))
2980 *hr = IMFMediaType_SetUINT32(mediatype, attr, value);
2983 static void mediatype_set_uint64(IMFMediaType *mediatype, const GUID *attr, unsigned int high, unsigned int low, HRESULT *hr)
2985 if (SUCCEEDED(*hr))
2986 *hr = IMFMediaType_SetUINT64(mediatype, attr, (UINT64)high << 32 | low);
2989 static void mediatype_set_guid(IMFMediaType *mediatype, const GUID *attr, const GUID *value, HRESULT *hr)
2991 if (SUCCEEDED(*hr))
2992 *hr = IMFMediaType_SetGUID(mediatype, attr, value);
2995 static void mediatype_set_blob(IMFMediaType *mediatype, const GUID *attr, const UINT8 *data,
2996 unsigned int size, HRESULT *hr)
2998 if (SUCCEEDED(*hr))
2999 *hr = IMFMediaType_SetBlob(mediatype, attr, data, size);
3002 /***********************************************************************
3003 * MFInitMediaTypeFromWaveFormatEx (mfplat.@)
3005 HRESULT WINAPI MFInitMediaTypeFromWaveFormatEx(IMFMediaType *mediatype, const WAVEFORMATEX *format, UINT32 size)
3007 const WAVEFORMATEXTENSIBLE *wfex = (const WAVEFORMATEXTENSIBLE *)format;
3008 GUID subtype;
3009 HRESULT hr;
3011 TRACE("%p, %p, %u.\n", mediatype, format, size);
3013 if (!mediatype || !format)
3014 return E_POINTER;
3016 if (format->cbSize + sizeof(*format) > size)
3017 return E_INVALIDARG;
3019 hr = IMFMediaType_DeleteAllItems(mediatype);
3021 mediatype_set_guid(mediatype, &MF_MT_MAJOR_TYPE, &MFMediaType_Audio, &hr);
3023 if (format->wFormatTag == WAVE_FORMAT_EXTENSIBLE)
3025 memcpy(&subtype, &wfex->SubFormat, sizeof(subtype));
3027 if (wfex->dwChannelMask)
3028 mediatype_set_uint32(mediatype, &MF_MT_AUDIO_CHANNEL_MASK, wfex->dwChannelMask, &hr);
3030 if (format->wBitsPerSample && wfex->Samples.wValidBitsPerSample)
3031 mediatype_set_uint32(mediatype, &MF_MT_AUDIO_VALID_BITS_PER_SAMPLE, wfex->Samples.wValidBitsPerSample, &hr);
3033 else
3035 memcpy(&subtype, &MFAudioFormat_Base, sizeof(subtype));
3036 subtype.Data1 = format->wFormatTag;
3038 mediatype_set_uint32(mediatype, &MF_MT_AUDIO_PREFER_WAVEFORMATEX, 1, &hr);
3040 mediatype_set_guid(mediatype, &MF_MT_SUBTYPE, &subtype, &hr);
3042 if (format->nChannels)
3043 mediatype_set_uint32(mediatype, &MF_MT_AUDIO_NUM_CHANNELS, format->nChannels, &hr);
3045 if (format->nSamplesPerSec)
3046 mediatype_set_uint32(mediatype, &MF_MT_AUDIO_SAMPLES_PER_SECOND, format->nSamplesPerSec, &hr);
3048 if (format->nAvgBytesPerSec)
3049 mediatype_set_uint32(mediatype, &MF_MT_AUDIO_AVG_BYTES_PER_SECOND, format->nAvgBytesPerSec, &hr);
3051 if (format->nBlockAlign)
3052 mediatype_set_uint32(mediatype, &MF_MT_AUDIO_BLOCK_ALIGNMENT, format->nBlockAlign, &hr);
3054 if (format->wBitsPerSample)
3055 mediatype_set_uint32(mediatype, &MF_MT_AUDIO_BITS_PER_SAMPLE, format->wBitsPerSample, &hr);
3057 if (IsEqualGUID(&subtype, &MFAudioFormat_PCM) ||
3058 IsEqualGUID(&subtype, &MFAudioFormat_Float))
3060 mediatype_set_uint32(mediatype, &MF_MT_ALL_SAMPLES_INDEPENDENT, 1, &hr);
3063 if (format->cbSize && format->wFormatTag != WAVE_FORMAT_EXTENSIBLE)
3064 mediatype_set_blob(mediatype, &MF_MT_USER_DATA, (const UINT8 *)(format + 1), format->cbSize, &hr);
3066 return hr;
3069 /***********************************************************************
3070 * MFCreateVideoMediaTypeFromSubtype (mfplat.@)
3072 HRESULT WINAPI MFCreateVideoMediaTypeFromSubtype(const GUID *subtype, IMFVideoMediaType **media_type)
3074 struct media_type *object;
3075 HRESULT hr;
3077 TRACE("%s, %p.\n", debugstr_guid(subtype), media_type);
3079 if (!media_type)
3080 return E_INVALIDARG;
3082 if (FAILED(hr = create_media_type(&object)))
3083 return hr;
3085 IMFMediaType_SetGUID(&object->IMFMediaType_iface, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
3086 IMFMediaType_SetGUID(&object->IMFMediaType_iface, &MF_MT_SUBTYPE, subtype);
3088 *media_type = &object->IMFVideoMediaType_iface;
3090 return S_OK;
3093 /***********************************************************************
3094 * MFCreateAudioMediaType (mfplat.@)
3096 HRESULT WINAPI MFCreateAudioMediaType(const WAVEFORMATEX *format, IMFAudioMediaType **media_type)
3098 struct media_type *object;
3099 HRESULT hr;
3101 TRACE("%p, %p.\n", format, media_type);
3103 if (!media_type)
3104 return E_INVALIDARG;
3106 if (FAILED(hr = create_media_type(&object)))
3107 return hr;
3109 if (FAILED(hr = MFInitMediaTypeFromWaveFormatEx(&object->IMFMediaType_iface, format, sizeof(*format) + format->cbSize)))
3111 IMFMediaType_Release(&object->IMFMediaType_iface);
3112 return hr;
3115 *media_type = &object->IMFAudioMediaType_iface;
3117 return S_OK;
3120 static void media_type_get_ratio(IMFMediaType *media_type, const GUID *attr, DWORD *numerator,
3121 DWORD *denominator)
3123 UINT64 value;
3125 if (SUCCEEDED(IMFMediaType_GetUINT64(media_type, attr, &value)))
3127 *numerator = value >> 32;
3128 *denominator = value;
3132 /***********************************************************************
3133 * MFCreateAMMediaTypeFromMFMediaType (mfplat.@)
3135 HRESULT WINAPI MFCreateAMMediaTypeFromMFMediaType(IMFMediaType *media_type, GUID format, AM_MEDIA_TYPE **am_type)
3137 FIXME("%p, %s, %p stub!\n", media_type, debugstr_mf_guid(&format), am_type);
3138 return E_NOTIMPL;
3141 /***********************************************************************
3142 * MFCreateMFVideoFormatFromMFMediaType (mfplat.@)
3144 HRESULT WINAPI MFCreateMFVideoFormatFromMFMediaType(IMFMediaType *media_type, MFVIDEOFORMAT **video_format, UINT32 *size)
3146 UINT32 flags, palette_size = 0, value;
3147 MFVIDEOFORMAT *format;
3148 INT32 stride;
3149 GUID guid;
3151 TRACE("%p, %p, %p.\n", media_type, video_format, size);
3153 *size = sizeof(*format);
3155 if (SUCCEEDED(IMFMediaType_GetBlobSize(media_type, &MF_MT_PALETTE, &palette_size)))
3156 *size += palette_size;
3158 if (!(format = CoTaskMemAlloc(*size)))
3159 return E_OUTOFMEMORY;
3161 *video_format = format;
3163 memset(format, 0, sizeof(*format));
3164 format->dwSize = *size;
3166 if (SUCCEEDED(IMFMediaType_GetGUID(media_type, &MF_MT_SUBTYPE, &guid)))
3168 memcpy(&format->guidFormat, &guid, sizeof(guid));
3169 format->surfaceInfo.Format = guid.Data1;
3172 media_type_get_ratio(media_type, &MF_MT_FRAME_SIZE, &format->videoInfo.dwWidth, &format->videoInfo.dwHeight);
3173 media_type_get_ratio(media_type, &MF_MT_PIXEL_ASPECT_RATIO, &format->videoInfo.PixelAspectRatio.Numerator,
3174 &format->videoInfo.PixelAspectRatio.Denominator);
3175 media_type_get_ratio(media_type, &MF_MT_FRAME_RATE, &format->videoInfo.FramesPerSecond.Numerator,
3176 &format->videoInfo.FramesPerSecond.Denominator);
3178 IMFMediaType_GetUINT32(media_type, &MF_MT_VIDEO_CHROMA_SITING, &format->videoInfo.SourceChromaSubsampling);
3179 IMFMediaType_GetUINT32(media_type, &MF_MT_INTERLACE_MODE, &format->videoInfo.InterlaceMode);
3180 IMFMediaType_GetUINT32(media_type, &MF_MT_TRANSFER_FUNCTION, &format->videoInfo.TransferFunction);
3181 IMFMediaType_GetUINT32(media_type, &MF_MT_VIDEO_PRIMARIES, &format->videoInfo.ColorPrimaries);
3182 IMFMediaType_GetUINT32(media_type, &MF_MT_YUV_MATRIX, &format->videoInfo.TransferMatrix);
3183 IMFMediaType_GetUINT32(media_type, &MF_MT_VIDEO_LIGHTING, &format->videoInfo.SourceLighting);
3184 IMFMediaType_GetUINT32(media_type, &MF_MT_VIDEO_NOMINAL_RANGE, &format->videoInfo.NominalRange);
3185 IMFMediaType_GetBlob(media_type, &MF_MT_GEOMETRIC_APERTURE, (UINT8 *)&format->videoInfo.GeometricAperture,
3186 sizeof(format->videoInfo.GeometricAperture), NULL);
3187 IMFMediaType_GetBlob(media_type, &MF_MT_MINIMUM_DISPLAY_APERTURE, (UINT8 *)&format->videoInfo.MinimumDisplayAperture,
3188 sizeof(format->videoInfo.MinimumDisplayAperture), NULL);
3190 /* Video flags. */
3191 if (SUCCEEDED(IMFMediaType_GetUINT32(media_type, &MF_MT_PAD_CONTROL_FLAGS, &flags)))
3192 format->videoInfo.VideoFlags |= flags;
3193 if (SUCCEEDED(IMFMediaType_GetUINT32(media_type, &MF_MT_SOURCE_CONTENT_HINT, &flags)))
3194 format->videoInfo.VideoFlags |= flags;
3195 if (SUCCEEDED(IMFMediaType_GetUINT32(media_type, &MF_MT_DRM_FLAGS, &flags)))
3196 format->videoInfo.VideoFlags |= flags;
3197 if (SUCCEEDED(IMFMediaType_GetUINT32(media_type, &MF_MT_PAN_SCAN_ENABLED, &flags)) && !!flags)
3199 format->videoInfo.VideoFlags |= MFVideoFlag_PanScanEnabled;
3200 IMFMediaType_GetBlob(media_type, &MF_MT_PAN_SCAN_APERTURE, (UINT8 *)&format->videoInfo.PanScanAperture,
3201 sizeof(format->videoInfo.PanScanAperture), NULL);
3203 if (SUCCEEDED(IMFMediaType_GetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, (UINT32 *)&stride)) && stride < 0)
3204 format->videoInfo.VideoFlags |= MFVideoFlag_BottomUpLinearRep;
3206 if (SUCCEEDED(IMFMediaType_GetUINT32(media_type, &MF_MT_AVG_BITRATE, &value)))
3207 format->compressedInfo.AvgBitrate = value;
3208 if (SUCCEEDED(IMFMediaType_GetUINT32(media_type, &MF_MT_AVG_BIT_ERROR_RATE, &value)))
3209 format->compressedInfo.AvgBitErrorRate = value;
3210 if (SUCCEEDED(IMFMediaType_GetUINT32(media_type, &MF_MT_MAX_KEYFRAME_SPACING, &value)))
3211 format->compressedInfo.MaxKeyFrameSpacing = value;
3213 /* Palette. */
3214 if (palette_size)
3216 format->surfaceInfo.PaletteEntries = palette_size / sizeof(*format->surfaceInfo.Palette);
3217 IMFMediaType_GetBlob(media_type, &MF_MT_PALETTE, (UINT8 *)format->surfaceInfo.Palette, palette_size, NULL);
3220 return S_OK;
3223 /***********************************************************************
3224 * MFConvertColorInfoToDXVA (mfplat.@)
3226 HRESULT WINAPI MFConvertColorInfoToDXVA(DWORD *dxva_info, const MFVIDEOFORMAT *format)
3228 struct
3230 UINT SampleFormat : 8;
3231 UINT VideoChromaSubsampling : 4;
3232 UINT NominalRange : 3;
3233 UINT VideoTransferMatrix : 3;
3234 UINT VideoLighting : 4;
3235 UINT VideoPrimaries : 5;
3236 UINT VideoTransferFunction : 5;
3237 } *dxva_format = (void *)dxva_info;
3239 TRACE("%p, %p.\n", dxva_info, format);
3241 if (format->videoInfo.InterlaceMode == MFVideoInterlace_MixedInterlaceOrProgressive)
3242 dxva_format->SampleFormat = DXVA2_SampleFieldInterleavedEvenFirst;
3243 else
3244 dxva_format->SampleFormat = format->videoInfo.InterlaceMode;
3246 dxva_format->VideoChromaSubsampling = format->videoInfo.SourceChromaSubsampling;
3247 dxva_format->NominalRange = format->videoInfo.NominalRange;
3248 dxva_format->VideoTransferMatrix = format->videoInfo.TransferMatrix;
3249 dxva_format->VideoLighting = format->videoInfo.SourceLighting;
3250 dxva_format->VideoPrimaries = format->videoInfo.ColorPrimaries;
3251 dxva_format->VideoTransferFunction = format->videoInfo.TransferFunction;
3253 return S_OK;
3256 struct frame_rate
3258 UINT64 key;
3259 UINT64 value;
3262 static int __cdecl frame_rate_compare(const void *a, const void *b)
3264 const UINT64 *key = a;
3265 const struct frame_rate *known_rate = b;
3266 return *key == known_rate->key ? 0 : ( *key < known_rate->key ? 1 : -1 );
3269 /***********************************************************************
3270 * MFFrameRateToAverageTimePerFrame (mfplat.@)
3272 HRESULT WINAPI MFFrameRateToAverageTimePerFrame(UINT32 numerator, UINT32 denominator, UINT64 *avgframetime)
3274 static const struct frame_rate known_rates[] =
3276 #define KNOWN_RATE(n,d,ft) { ((UINT64)n << 32) | d, ft }
3277 KNOWN_RATE(60000, 1001, 166833),
3278 KNOWN_RATE(30000, 1001, 333667),
3279 KNOWN_RATE(24000, 1001, 417188),
3280 KNOWN_RATE(60, 1, 166667),
3281 KNOWN_RATE(50, 1, 200000),
3282 KNOWN_RATE(30, 1, 333333),
3283 KNOWN_RATE(25, 1, 400000),
3284 KNOWN_RATE(24, 1, 416667),
3285 #undef KNOWN_RATE
3287 UINT64 rate = ((UINT64)numerator << 32) | denominator;
3288 const struct frame_rate *entry;
3290 TRACE("%u, %u, %p.\n", numerator, denominator, avgframetime);
3292 if ((entry = bsearch(&rate, known_rates, ARRAY_SIZE(known_rates), sizeof(*known_rates),
3293 frame_rate_compare)))
3295 *avgframetime = entry->value;
3297 else
3298 *avgframetime = numerator ? denominator * (UINT64)10000000 / numerator : 0;
3300 return S_OK;
3303 static unsigned int get_gcd(unsigned int a, unsigned int b)
3305 unsigned int m;
3307 while (b)
3309 m = a % b;
3310 a = b;
3311 b = m;
3314 return a;
3317 /***********************************************************************
3318 * MFAverageTimePerFrameToFrameRate (mfplat.@)
3320 HRESULT WINAPI MFAverageTimePerFrameToFrameRate(UINT64 avgtime, UINT32 *numerator, UINT32 *denominator)
3322 static const struct frame_rate known_rates[] =
3324 #define KNOWN_RATE(ft,n,d) { ft, ((UINT64)n << 32) | d }
3325 KNOWN_RATE(417188, 24000, 1001),
3326 KNOWN_RATE(416667, 24, 1),
3327 KNOWN_RATE(400000, 25, 1),
3328 KNOWN_RATE(333667, 30000, 1001),
3329 KNOWN_RATE(333333, 30, 1),
3330 KNOWN_RATE(200000, 50, 1),
3331 KNOWN_RATE(166833, 60000, 1001),
3332 KNOWN_RATE(166667, 60, 1),
3333 #undef KNOWN_RATE
3335 const struct frame_rate *entry;
3336 unsigned int gcd;
3338 TRACE("%s, %p, %p.\n", wine_dbgstr_longlong(avgtime), numerator, denominator);
3340 if ((entry = bsearch(&avgtime, known_rates, ARRAY_SIZE(known_rates), sizeof(*known_rates),
3341 frame_rate_compare)))
3343 *numerator = entry->value >> 32;
3344 *denominator = entry->value;
3346 else if (avgtime)
3348 if (avgtime > 100000000) avgtime = 100000000;
3349 gcd = get_gcd(10000000, avgtime);
3350 *numerator = 10000000 / gcd;
3351 *denominator = avgtime / gcd;
3353 else
3355 *numerator = *denominator = 0;
3358 return S_OK;
3361 /***********************************************************************
3362 * MFMapDXGIFormatToDX9Format (mfplat.@)
3364 DWORD WINAPI MFMapDXGIFormatToDX9Format(DXGI_FORMAT dxgi_format)
3366 switch (dxgi_format)
3368 case DXGI_FORMAT_R32G32B32A32_FLOAT:
3369 return D3DFMT_A32B32G32R32F;
3370 case DXGI_FORMAT_R16G16B16A16_FLOAT:
3371 return D3DFMT_A16B16G16R16F;
3372 case DXGI_FORMAT_R16G16B16A16_UNORM:
3373 return D3DFMT_A16B16G16R16;
3374 case DXGI_FORMAT_R16G16B16A16_SNORM:
3375 return D3DFMT_Q16W16V16U16;
3376 case DXGI_FORMAT_R32G32_FLOAT:
3377 return D3DFMT_G32R32F;
3378 case DXGI_FORMAT_R10G10B10A2_UNORM:
3379 return D3DFMT_A2B10G10R10;
3380 case DXGI_FORMAT_R8G8B8A8_SNORM:
3381 return D3DFMT_Q8W8V8U8;
3382 case DXGI_FORMAT_R16G16_FLOAT:
3383 return D3DFMT_G16R16F;
3384 case DXGI_FORMAT_R16G16_UNORM:
3385 return D3DFMT_G16R16;
3386 case DXGI_FORMAT_R16G16_SNORM:
3387 return D3DFMT_V16U16;
3388 case DXGI_FORMAT_D32_FLOAT:
3389 return D3DFMT_D32F_LOCKABLE;
3390 case DXGI_FORMAT_R32_FLOAT:
3391 return D3DFMT_R32F;
3392 case DXGI_FORMAT_D24_UNORM_S8_UINT:
3393 return D3DFMT_D24S8;
3394 case DXGI_FORMAT_R8G8_SNORM:
3395 return D3DFMT_V8U8;
3396 case DXGI_FORMAT_R16_FLOAT:
3397 return D3DFMT_R16F;
3398 case DXGI_FORMAT_D16_UNORM:
3399 return D3DFMT_D16_LOCKABLE;
3400 case DXGI_FORMAT_R16_UNORM:
3401 return D3DFMT_L16;
3402 case DXGI_FORMAT_R8_UNORM:
3403 return D3DFMT_L8;
3404 case DXGI_FORMAT_A8_UNORM:
3405 return D3DFMT_A8;
3406 case DXGI_FORMAT_BC1_UNORM:
3407 case DXGI_FORMAT_BC1_UNORM_SRGB:
3408 return D3DFMT_DXT1;
3409 case DXGI_FORMAT_BC2_UNORM:
3410 case DXGI_FORMAT_BC2_UNORM_SRGB:
3411 return D3DFMT_DXT2;
3412 case DXGI_FORMAT_BC3_UNORM:
3413 case DXGI_FORMAT_BC3_UNORM_SRGB:
3414 return D3DFMT_DXT4;
3415 case DXGI_FORMAT_R8G8B8A8_UNORM:
3416 return D3DFMT_A8B8G8R8;
3417 case DXGI_FORMAT_B8G8R8A8_UNORM:
3418 case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
3419 case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
3420 return D3DFMT_A8R8G8B8;
3421 case DXGI_FORMAT_B8G8R8X8_UNORM:
3422 case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB:
3423 return D3DFMT_X8R8G8B8;
3424 case DXGI_FORMAT_AYUV:
3425 return MAKEFOURCC('A','Y','U','V');
3426 case DXGI_FORMAT_Y410:
3427 return MAKEFOURCC('Y','4','1','0');
3428 case DXGI_FORMAT_Y416:
3429 return MAKEFOURCC('Y','4','1','6');
3430 case DXGI_FORMAT_NV12:
3431 return MAKEFOURCC('N','V','1','2');
3432 case DXGI_FORMAT_P010:
3433 return MAKEFOURCC('P','0','1','0');
3434 case DXGI_FORMAT_P016:
3435 return MAKEFOURCC('P','0','1','6');
3436 case DXGI_FORMAT_420_OPAQUE:
3437 return MAKEFOURCC('4','2','0','O');
3438 case DXGI_FORMAT_YUY2:
3439 return D3DFMT_YUY2;
3440 case DXGI_FORMAT_Y210:
3441 return MAKEFOURCC('Y','2','1','0');
3442 case DXGI_FORMAT_Y216:
3443 return MAKEFOURCC('Y','2','1','6');
3444 case DXGI_FORMAT_NV11:
3445 return MAKEFOURCC('N','V','1','1');
3446 case DXGI_FORMAT_AI44:
3447 return MAKEFOURCC('A','I','4','4');
3448 case DXGI_FORMAT_IA44:
3449 return MAKEFOURCC('I','A','4','4');
3450 case DXGI_FORMAT_P8:
3451 return D3DFMT_P8;
3452 case DXGI_FORMAT_A8P8:
3453 return D3DFMT_A8P8;
3454 default:
3455 return 0;
3459 /***********************************************************************
3460 * MFMapDX9FormatToDXGIFormat (mfplat.@)
3462 DXGI_FORMAT WINAPI MFMapDX9FormatToDXGIFormat(DWORD format)
3464 switch (format)
3466 case D3DFMT_A32B32G32R32F:
3467 return DXGI_FORMAT_R32G32B32A32_FLOAT;
3468 case D3DFMT_A16B16G16R16F:
3469 return DXGI_FORMAT_R16G16B16A16_FLOAT;
3470 case D3DFMT_A16B16G16R16:
3471 return DXGI_FORMAT_R16G16B16A16_UNORM;
3472 case D3DFMT_Q16W16V16U16:
3473 return DXGI_FORMAT_R16G16B16A16_SNORM;
3474 case D3DFMT_G32R32F:
3475 return DXGI_FORMAT_R32G32_FLOAT;
3476 case D3DFMT_A2B10G10R10:
3477 return DXGI_FORMAT_R10G10B10A2_UNORM;
3478 case D3DFMT_Q8W8V8U8:
3479 return DXGI_FORMAT_R8G8B8A8_SNORM;
3480 case D3DFMT_G16R16F:
3481 return DXGI_FORMAT_R16G16_FLOAT;
3482 case D3DFMT_G16R16:
3483 return DXGI_FORMAT_R16G16_UNORM;
3484 case D3DFMT_V16U16:
3485 return DXGI_FORMAT_R16G16_SNORM;
3486 case D3DFMT_D32F_LOCKABLE:
3487 return DXGI_FORMAT_D32_FLOAT;
3488 case D3DFMT_R32F:
3489 return DXGI_FORMAT_R32_FLOAT;
3490 case D3DFMT_D24S8:
3491 return DXGI_FORMAT_D24_UNORM_S8_UINT;
3492 case D3DFMT_V8U8:
3493 return DXGI_FORMAT_R8G8_SNORM;
3494 case D3DFMT_R16F:
3495 return DXGI_FORMAT_R16_FLOAT;
3496 case D3DFMT_L16:
3497 return DXGI_FORMAT_R16_UNORM;
3498 case D3DFMT_L8:
3499 return DXGI_FORMAT_R8_UNORM;
3500 case D3DFMT_A8:
3501 return DXGI_FORMAT_A8_UNORM;
3502 case D3DFMT_DXT1:
3503 return DXGI_FORMAT_BC1_UNORM;
3504 case D3DFMT_DXT2:
3505 return DXGI_FORMAT_BC2_UNORM;
3506 case D3DFMT_DXT4:
3507 return DXGI_FORMAT_BC3_UNORM;
3508 case D3DFMT_A8R8G8B8:
3509 return DXGI_FORMAT_B8G8R8A8_UNORM;
3510 case D3DFMT_X8R8G8B8:
3511 return DXGI_FORMAT_B8G8R8X8_UNORM;
3512 case MAKEFOURCC('A','Y','U','V'):
3513 return DXGI_FORMAT_AYUV;
3514 case MAKEFOURCC('Y','4','1','0'):
3515 return DXGI_FORMAT_Y410;
3516 case MAKEFOURCC('Y','4','1','6'):
3517 return DXGI_FORMAT_Y416;
3518 case MAKEFOURCC('N','V','1','2'):
3519 return DXGI_FORMAT_NV12;
3520 case MAKEFOURCC('P','0','1','0'):
3521 return DXGI_FORMAT_P010;
3522 case MAKEFOURCC('P','0','1','6'):
3523 return DXGI_FORMAT_P016;
3524 case MAKEFOURCC('4','2','0','O'):
3525 return DXGI_FORMAT_420_OPAQUE;
3526 case D3DFMT_YUY2:
3527 return DXGI_FORMAT_YUY2;
3528 case MAKEFOURCC('Y','2','1','0'):
3529 return DXGI_FORMAT_Y210;
3530 case MAKEFOURCC('Y','2','1','6'):
3531 return DXGI_FORMAT_Y216;
3532 case MAKEFOURCC('N','V','1','1'):
3533 return DXGI_FORMAT_NV11;
3534 case MAKEFOURCC('A','I','4','4'):
3535 return DXGI_FORMAT_AI44;
3536 case MAKEFOURCC('I','A','4','4'):
3537 return DXGI_FORMAT_IA44;
3538 case D3DFMT_P8:
3539 return DXGI_FORMAT_P8;
3540 case D3DFMT_A8P8:
3541 return DXGI_FORMAT_A8P8;
3542 default:
3543 return DXGI_FORMAT_UNKNOWN;
3547 /***********************************************************************
3548 * MFInitVideoFormat_RGB (mfplat.@)
3550 HRESULT WINAPI MFInitVideoFormat_RGB(MFVIDEOFORMAT *format, DWORD width, DWORD height, DWORD d3dformat)
3552 unsigned int transfer_function;
3554 TRACE("%p, %lu, %lu, %#lx.\n", format, width, height, d3dformat);
3556 if (!format)
3557 return E_INVALIDARG;
3559 if (!d3dformat) d3dformat = D3DFMT_X8R8G8B8;
3561 switch (d3dformat)
3563 case D3DFMT_X8R8G8B8:
3564 case D3DFMT_R8G8B8:
3565 case D3DFMT_A8R8G8B8:
3566 case D3DFMT_R5G6B5:
3567 case D3DFMT_X1R5G5B5:
3568 case D3DFMT_A2B10G10R10:
3569 case D3DFMT_A2R10G10B10:
3570 case D3DFMT_P8:
3571 transfer_function = MFVideoTransFunc_sRGB;
3572 break;
3573 default:
3574 transfer_function = MFVideoTransFunc_10;
3577 memset(format, 0, sizeof(*format));
3578 format->dwSize = sizeof(*format);
3579 format->videoInfo.dwWidth = width;
3580 format->videoInfo.dwHeight = height;
3581 format->videoInfo.PixelAspectRatio.Numerator = 1;
3582 format->videoInfo.PixelAspectRatio.Denominator = 1;
3583 format->videoInfo.InterlaceMode = MFVideoInterlace_Progressive;
3584 format->videoInfo.TransferFunction = transfer_function;
3585 format->videoInfo.ColorPrimaries = MFVideoPrimaries_BT709;
3586 format->videoInfo.SourceLighting = MFVideoLighting_office;
3587 format->videoInfo.FramesPerSecond.Numerator = 60;
3588 format->videoInfo.FramesPerSecond.Denominator = 1;
3589 format->videoInfo.NominalRange = MFNominalRange_Normal;
3590 format->videoInfo.GeometricAperture.Area.cx = width;
3591 format->videoInfo.GeometricAperture.Area.cy = height;
3592 format->videoInfo.MinimumDisplayAperture = format->videoInfo.GeometricAperture;
3593 memcpy(&format->guidFormat, &MFVideoFormat_Base, sizeof(format->guidFormat));
3594 format->guidFormat.Data1 = d3dformat;
3595 format->surfaceInfo.Format = d3dformat;
3597 return S_OK;
3600 static HRESULT mf_get_stride_for_bitmap_info_header(DWORD fourcc, const BITMAPINFOHEADER *bih, LONG *stride)
3602 HRESULT hr;
3604 if (FAILED(hr = MFGetStrideForBitmapInfoHeader(fourcc, bih->biWidth, stride))) return hr;
3605 if (bih->biHeight < 0) *stride *= -1;
3607 return hr;
3610 static const GUID * get_mf_subtype_for_am_subtype(const GUID *subtype)
3612 if (IsEqualGUID(subtype, &MEDIASUBTYPE_RGB1))
3613 return &MFVideoFormat_RGB1;
3614 if (IsEqualGUID(subtype, &MEDIASUBTYPE_RGB4))
3615 return &MFVideoFormat_RGB4;
3616 if (IsEqualGUID(subtype, &MEDIASUBTYPE_RGB8))
3617 return &MFVideoFormat_RGB8;
3618 if (IsEqualGUID(subtype, &MEDIASUBTYPE_RGB555))
3619 return &MFVideoFormat_RGB555;
3620 if (IsEqualGUID(subtype, &MEDIASUBTYPE_RGB565))
3621 return &MFVideoFormat_RGB565;
3622 if (IsEqualGUID(subtype, &MEDIASUBTYPE_RGB24))
3623 return &MFVideoFormat_RGB24;
3624 if (IsEqualGUID(subtype, &MEDIASUBTYPE_RGB32))
3625 return &MFVideoFormat_RGB32;
3626 if (IsEqualGUID(subtype, &MEDIASUBTYPE_ARGB1555))
3627 return &MFVideoFormat_ARGB1555;
3628 if (IsEqualGUID(subtype, &MEDIASUBTYPE_ARGB4444))
3629 return &MFVideoFormat_ARGB4444;
3630 if (IsEqualGUID(subtype, &MEDIASUBTYPE_ARGB32))
3631 return &MFVideoFormat_ARGB32;
3632 if (IsEqualGUID(subtype, &MEDIASUBTYPE_A2R10G10B10))
3633 return &MFVideoFormat_A2B10G10R10;
3634 if (IsEqualGUID(subtype, &MEDIASUBTYPE_A2B10G10R10))
3635 return &MFVideoFormat_A2R10G10B10;
3636 return subtype;
3639 /***********************************************************************
3640 * MFCreateVideoMediaTypeFromVideoInfoHeader (mfplat.@)
3642 HRESULT WINAPI MFCreateVideoMediaTypeFromVideoInfoHeader(const KS_VIDEOINFOHEADER *vih, DWORD size, DWORD pixel_aspect_ratio_x,
3643 DWORD pixel_aspect_ratio_y, MFVideoInterlaceMode interlace_mode, QWORD video_flags, const GUID *subtype,
3644 IMFVideoMediaType **ret)
3646 FIXME("%p, %lu, %lu, %lu, %d, %I64x, %s, %p.\n", vih, size, pixel_aspect_ratio_x, pixel_aspect_ratio_y, interlace_mode,
3647 video_flags, debugstr_guid(subtype), ret);
3649 return E_NOTIMPL;
3652 /***********************************************************************
3653 * MFInitMediaTypeFromVideoInfoHeader (mfplat.@)
3655 HRESULT WINAPI MFInitMediaTypeFromVideoInfoHeader(IMFMediaType *media_type, const VIDEOINFOHEADER *vih, UINT32 size,
3656 const GUID *subtype)
3658 HRESULT hr = S_OK;
3659 DWORD height;
3660 LONG stride;
3662 FIXME("%p, %p, %u, %s.\n", media_type, vih, size, debugstr_guid(subtype));
3664 IMFMediaType_DeleteAllItems(media_type);
3666 if (!subtype)
3668 FIXME("Implicit subtype is not supported.\n");
3669 return E_NOTIMPL;
3672 height = abs(vih->bmiHeader.biHeight);
3674 mediatype_set_guid(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Video, &hr);
3675 mediatype_set_guid(media_type, &MF_MT_SUBTYPE, subtype, &hr);
3676 mediatype_set_uint64(media_type, &MF_MT_PIXEL_ASPECT_RATIO, 1, 1, &hr);
3677 mediatype_set_uint32(media_type, &MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive, &hr);
3678 mediatype_set_uint64(media_type, &MF_MT_FRAME_SIZE, vih->bmiHeader.biWidth, height, &hr);
3680 if (SUCCEEDED(mf_get_stride_for_bitmap_info_header(subtype->Data1, &vih->bmiHeader, &stride)))
3682 mediatype_set_uint32(media_type, &MF_MT_DEFAULT_STRIDE, stride, &hr);
3683 mediatype_set_uint32(media_type, &MF_MT_SAMPLE_SIZE, abs(stride) * height, &hr);
3684 mediatype_set_uint32(media_type, &MF_MT_FIXED_SIZE_SAMPLES, 1, &hr);
3685 mediatype_set_uint32(media_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, 1, &hr);
3688 return hr;
3691 /***********************************************************************
3692 * MFInitAMMediaTypeFromMFMediaType (mfplat.@)
3694 HRESULT WINAPI MFInitAMMediaTypeFromMFMediaType(IMFMediaType *media_type, GUID format, AM_MEDIA_TYPE *am_type)
3696 FIXME("%p, %s, %p\n", media_type, debugstr_guid(&format), am_type);
3697 return E_NOTIMPL;
3700 /***********************************************************************
3701 * MFInitMediaTypeFromAMMediaType (mfplat.@)
3703 HRESULT WINAPI MFInitMediaTypeFromAMMediaType(IMFMediaType *media_type, const AM_MEDIA_TYPE *am_type)
3705 HRESULT hr = S_OK;
3707 TRACE("%p, %p.\n", media_type, am_type);
3709 IMFMediaType_DeleteAllItems(media_type);
3711 if (IsEqualGUID(&am_type->majortype, &MEDIATYPE_Video))
3713 if (IsEqualGUID(&am_type->formattype, &FORMAT_VideoInfo))
3715 const VIDEOINFOHEADER *vih = (const VIDEOINFOHEADER *)am_type->pbFormat;
3716 const GUID *subtype;
3717 DWORD height;
3718 LONG stride;
3720 subtype = get_mf_subtype_for_am_subtype(&am_type->subtype);
3721 height = abs(vih->bmiHeader.biHeight);
3723 mediatype_set_guid(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Video, &hr);
3724 mediatype_set_guid(media_type, &MF_MT_SUBTYPE, subtype, &hr);
3725 mediatype_set_uint64(media_type, &MF_MT_PIXEL_ASPECT_RATIO, 1, 1, &hr);
3726 mediatype_set_uint32(media_type, &MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive, &hr);
3727 mediatype_set_uint64(media_type, &MF_MT_FRAME_SIZE, vih->bmiHeader.biWidth, height, &hr);
3728 mediatype_set_uint32(media_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, 1, &hr);
3730 if (SUCCEEDED(mf_get_stride_for_bitmap_info_header(subtype->Data1, &vih->bmiHeader, &stride)))
3732 mediatype_set_uint32(media_type, &MF_MT_DEFAULT_STRIDE, stride, &hr);
3733 mediatype_set_uint32(media_type, &MF_MT_SAMPLE_SIZE, abs(stride) * height, &hr);
3734 mediatype_set_uint32(media_type, &MF_MT_FIXED_SIZE_SAMPLES, 1, &hr);
3736 else
3738 if (am_type->bFixedSizeSamples)
3739 mediatype_set_uint32(media_type, &MF_MT_FIXED_SIZE_SAMPLES, 1, &hr);
3740 if (am_type->lSampleSize)
3741 mediatype_set_uint32(media_type, &MF_MT_SAMPLE_SIZE, am_type->lSampleSize, &hr);
3744 return hr;
3746 else
3748 FIXME("Unsupported format type %s.\n", debugstr_guid(&am_type->formattype));
3751 else
3752 FIXME("Unsupported major type %s.\n", debugstr_guid(&am_type->majortype));
3754 return E_NOTIMPL;