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
21 #include "mfplat_private.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(mfplat
);
32 DEFINE_MEDIATYPE_GUID(MFVideoFormat_IMC1
, MAKEFOURCC('I','M','C','1'));
33 DEFINE_MEDIATYPE_GUID(MFVideoFormat_IMC2
, MAKEFOURCC('I','M','C','2'));
34 DEFINE_MEDIATYPE_GUID(MFVideoFormat_IMC3
, MAKEFOURCC('I','M','C','3'));
35 DEFINE_MEDIATYPE_GUID(MFVideoFormat_IMC4
, MAKEFOURCC('I','M','C','4'));
39 struct attributes attributes
;
40 IMFMediaType IMFMediaType_iface
;
41 IMFVideoMediaType IMFVideoMediaType_iface
;
42 IMFAudioMediaType IMFAudioMediaType_iface
;
43 MFVIDEOFORMAT
*video_format
;
44 WAVEFORMATEX
*audio_format
;
49 struct attributes attributes
;
50 IMFStreamDescriptor IMFStreamDescriptor_iface
;
51 IMFMediaTypeHandler IMFMediaTypeHandler_iface
;
53 IMFMediaType
**media_types
;
54 unsigned int media_types_count
;
55 IMFMediaType
*current_type
;
58 struct presentation_desc_entry
60 IMFStreamDescriptor
*descriptor
;
64 struct presentation_desc
66 struct attributes attributes
;
67 IMFPresentationDescriptor IMFPresentationDescriptor_iface
;
68 struct presentation_desc_entry
*descriptors
;
72 static HRESULT
presentation_descriptor_init(struct presentation_desc
*object
, DWORD count
);
74 static struct media_type
*impl_from_IMFMediaType(IMFMediaType
*iface
)
76 return CONTAINING_RECORD(iface
, struct media_type
, IMFMediaType_iface
);
79 static struct media_type
*impl_from_IMFVideoMediaType(IMFVideoMediaType
*iface
)
81 return CONTAINING_RECORD(iface
, struct media_type
, IMFVideoMediaType_iface
);
84 static struct media_type
*impl_from_IMFAudioMediaType(IMFAudioMediaType
*iface
)
86 return CONTAINING_RECORD(iface
, struct media_type
, IMFAudioMediaType_iface
);
89 static inline struct stream_desc
*impl_from_IMFStreamDescriptor(IMFStreamDescriptor
*iface
)
91 return CONTAINING_RECORD(iface
, struct stream_desc
, IMFStreamDescriptor_iface
);
94 static struct stream_desc
*impl_from_IMFMediaTypeHandler(IMFMediaTypeHandler
*iface
)
96 return CONTAINING_RECORD(iface
, struct stream_desc
, IMFMediaTypeHandler_iface
);
99 static struct presentation_desc
*impl_from_IMFPresentationDescriptor(IMFPresentationDescriptor
*iface
)
101 return CONTAINING_RECORD(iface
, struct presentation_desc
, IMFPresentationDescriptor_iface
);
104 static HRESULT WINAPI
mediatype_QueryInterface(IMFMediaType
*iface
, REFIID riid
, void **out
)
106 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
109 TRACE("%p, %s, %p.\n", iface
, debugstr_guid(riid
), out
);
111 attributes_GetGUID(&media_type
->attributes
, &MF_MT_MAJOR_TYPE
, &major
);
113 if (IsEqualGUID(&major
, &MFMediaType_Video
) && IsEqualIID(riid
, &IID_IMFVideoMediaType
))
115 *out
= &media_type
->IMFVideoMediaType_iface
;
117 else if (IsEqualGUID(&major
, &MFMediaType_Audio
) && IsEqualIID(riid
, &IID_IMFAudioMediaType
))
119 *out
= &media_type
->IMFAudioMediaType_iface
;
121 else if (IsEqualIID(riid
, &IID_IMFMediaType
) ||
122 IsEqualIID(riid
, &IID_IMFAttributes
) ||
123 IsEqualIID(riid
, &IID_IUnknown
))
125 *out
= &media_type
->IMFMediaType_iface
;
129 WARN("Unsupported %s.\n", debugstr_guid(riid
));
131 return E_NOINTERFACE
;
134 IUnknown_AddRef((IUnknown
*)*out
);
138 static ULONG WINAPI
mediatype_AddRef(IMFMediaType
*iface
)
140 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
141 ULONG refcount
= InterlockedIncrement(&media_type
->attributes
.ref
);
143 TRACE("%p, refcount %lu.\n", iface
, refcount
);
148 static ULONG WINAPI
mediatype_Release(IMFMediaType
*iface
)
150 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
151 ULONG refcount
= InterlockedDecrement(&media_type
->attributes
.ref
);
153 TRACE("%p, refcount %lu.\n", iface
, refcount
);
157 clear_attributes_object(&media_type
->attributes
);
158 CoTaskMemFree(media_type
->video_format
);
159 CoTaskMemFree(media_type
->audio_format
);
166 static HRESULT WINAPI
mediatype_GetItem(IMFMediaType
*iface
, REFGUID key
, PROPVARIANT
*value
)
168 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
170 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), value
);
172 return attributes_GetItem(&media_type
->attributes
, key
, value
);
175 static HRESULT WINAPI
mediatype_GetItemType(IMFMediaType
*iface
, REFGUID key
, MF_ATTRIBUTE_TYPE
*type
)
177 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
179 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), type
);
181 return attributes_GetItemType(&media_type
->attributes
, key
, type
);
184 static HRESULT WINAPI
mediatype_CompareItem(IMFMediaType
*iface
, REFGUID key
, REFPROPVARIANT value
, BOOL
*result
)
186 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
188 TRACE("%p, %s, %s, %p.\n", iface
, debugstr_attr(key
), debugstr_propvar(value
), result
);
190 return attributes_CompareItem(&media_type
->attributes
, key
, value
, result
);
193 static HRESULT WINAPI
mediatype_Compare(IMFMediaType
*iface
, IMFAttributes
*attrs
, MF_ATTRIBUTES_MATCH_TYPE type
,
196 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
198 TRACE("%p, %p, %d, %p.\n", iface
, attrs
, type
, result
);
200 return attributes_Compare(&media_type
->attributes
, attrs
, type
, result
);
203 static HRESULT WINAPI
mediatype_GetUINT32(IMFMediaType
*iface
, REFGUID key
, UINT32
*value
)
205 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
207 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), value
);
209 return attributes_GetUINT32(&media_type
->attributes
, key
, value
);
212 static HRESULT WINAPI
mediatype_GetUINT64(IMFMediaType
*iface
, REFGUID key
, UINT64
*value
)
214 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
216 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), value
);
218 return attributes_GetUINT64(&media_type
->attributes
, key
, value
);
221 static HRESULT WINAPI
mediatype_GetDouble(IMFMediaType
*iface
, REFGUID key
, double *value
)
223 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
225 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), value
);
227 return attributes_GetDouble(&media_type
->attributes
, key
, value
);
230 static HRESULT WINAPI
mediatype_GetGUID(IMFMediaType
*iface
, REFGUID key
, GUID
*value
)
232 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
234 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), value
);
236 return attributes_GetGUID(&media_type
->attributes
, key
, value
);
239 static HRESULT WINAPI
mediatype_GetStringLength(IMFMediaType
*iface
, REFGUID key
, UINT32
*length
)
241 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
243 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), length
);
245 return attributes_GetStringLength(&media_type
->attributes
, key
, length
);
248 static HRESULT WINAPI
mediatype_GetString(IMFMediaType
*iface
, REFGUID key
, WCHAR
*value
,
249 UINT32 size
, UINT32
*length
)
251 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
253 TRACE("%p, %s, %p, %u, %p.\n", iface
, debugstr_attr(key
), value
, size
, length
);
255 return attributes_GetString(&media_type
->attributes
, key
, value
, size
, length
);
258 static HRESULT WINAPI
mediatype_GetAllocatedString(IMFMediaType
*iface
, REFGUID key
,
259 WCHAR
**value
, UINT32
*length
)
261 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
263 TRACE("%p, %s, %p, %p.\n", iface
, debugstr_attr(key
), value
, length
);
265 return attributes_GetAllocatedString(&media_type
->attributes
, key
, value
, length
);
268 static HRESULT WINAPI
mediatype_GetBlobSize(IMFMediaType
*iface
, REFGUID key
, UINT32
*size
)
270 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
272 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), size
);
274 return attributes_GetBlobSize(&media_type
->attributes
, key
, size
);
277 static HRESULT WINAPI
mediatype_GetBlob(IMFMediaType
*iface
, REFGUID key
, UINT8
*buf
,
278 UINT32 bufsize
, UINT32
*blobsize
)
280 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
282 TRACE("%p, %s, %p, %u, %p.\n", iface
, debugstr_attr(key
), buf
, bufsize
, blobsize
);
284 return attributes_GetBlob(&media_type
->attributes
, key
, buf
, bufsize
, blobsize
);
287 static HRESULT WINAPI
mediatype_GetAllocatedBlob(IMFMediaType
*iface
, REFGUID key
, UINT8
**buf
, UINT32
*size
)
289 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
291 TRACE("%p, %s, %p, %p.\n", iface
, debugstr_attr(key
), buf
, size
);
293 return attributes_GetAllocatedBlob(&media_type
->attributes
, key
, buf
, size
);
296 static HRESULT WINAPI
mediatype_GetUnknown(IMFMediaType
*iface
, REFGUID key
, REFIID riid
, void **obj
)
298 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
300 TRACE("%p, %s, %s, %p.\n", iface
, debugstr_attr(key
), debugstr_guid(riid
), obj
);
302 return attributes_GetUnknown(&media_type
->attributes
, key
, riid
, obj
);
305 static HRESULT WINAPI
mediatype_SetItem(IMFMediaType
*iface
, REFGUID key
, REFPROPVARIANT value
)
307 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
309 TRACE("%p, %s, %s.\n", iface
, debugstr_attr(key
), debugstr_propvar(value
));
311 return attributes_SetItem(&media_type
->attributes
, key
, value
);
314 static HRESULT WINAPI
mediatype_DeleteItem(IMFMediaType
*iface
, REFGUID key
)
316 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
318 TRACE("%p, %s.\n", iface
, debugstr_attr(key
));
320 return attributes_DeleteItem(&media_type
->attributes
, key
);
323 static HRESULT WINAPI
mediatype_DeleteAllItems(IMFMediaType
*iface
)
325 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
327 TRACE("%p.\n", iface
);
329 return attributes_DeleteAllItems(&media_type
->attributes
);
332 static HRESULT WINAPI
mediatype_SetUINT32(IMFMediaType
*iface
, REFGUID key
, UINT32 value
)
334 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
336 TRACE("%p, %s, %u.\n", iface
, debugstr_attr(key
), value
);
338 return attributes_SetUINT32(&media_type
->attributes
, key
, value
);
341 static HRESULT WINAPI
mediatype_SetUINT64(IMFMediaType
*iface
, REFGUID key
, UINT64 value
)
343 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
345 TRACE("%p, %s, %s.\n", iface
, debugstr_attr(key
), wine_dbgstr_longlong(value
));
347 return attributes_SetUINT64(&media_type
->attributes
, key
, value
);
350 static HRESULT WINAPI
mediatype_SetDouble(IMFMediaType
*iface
, REFGUID key
, double value
)
352 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
354 TRACE("%p, %s, %f.\n", iface
, debugstr_attr(key
), value
);
356 return attributes_SetDouble(&media_type
->attributes
, key
, value
);
359 static HRESULT WINAPI
mediatype_SetGUID(IMFMediaType
*iface
, REFGUID key
, REFGUID value
)
361 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
363 TRACE("%p, %s, %s.\n", iface
, debugstr_attr(key
), debugstr_mf_guid(value
));
365 return attributes_SetGUID(&media_type
->attributes
, key
, value
);
368 static HRESULT WINAPI
mediatype_SetString(IMFMediaType
*iface
, REFGUID key
, const WCHAR
*value
)
370 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
372 TRACE("%p, %s, %s.\n", iface
, debugstr_attr(key
), debugstr_w(value
));
374 return attributes_SetString(&media_type
->attributes
, key
, value
);
377 static HRESULT WINAPI
mediatype_SetBlob(IMFMediaType
*iface
, REFGUID key
, const UINT8
*buf
, UINT32 size
)
379 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
381 TRACE("%p, %s, %p, %u.\n", iface
, debugstr_attr(key
), buf
, size
);
383 return attributes_SetBlob(&media_type
->attributes
, key
, buf
, size
);
386 static HRESULT WINAPI
mediatype_SetUnknown(IMFMediaType
*iface
, REFGUID key
, IUnknown
*unknown
)
388 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
390 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), unknown
);
392 return attributes_SetUnknown(&media_type
->attributes
, key
, unknown
);
395 static HRESULT WINAPI
mediatype_LockStore(IMFMediaType
*iface
)
397 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
399 TRACE("%p.\n", iface
);
401 return attributes_LockStore(&media_type
->attributes
);
404 static HRESULT WINAPI
mediatype_UnlockStore(IMFMediaType
*iface
)
406 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
408 TRACE("%p.\n", iface
);
410 return attributes_UnlockStore(&media_type
->attributes
);
413 static HRESULT WINAPI
mediatype_GetCount(IMFMediaType
*iface
, UINT32
*count
)
415 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
417 TRACE("%p, %p.\n", iface
, count
);
419 return attributes_GetCount(&media_type
->attributes
, count
);
422 static HRESULT WINAPI
mediatype_GetItemByIndex(IMFMediaType
*iface
, UINT32 index
, GUID
*key
, PROPVARIANT
*value
)
424 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
426 TRACE("%p, %u, %p, %p.\n", iface
, index
, key
, value
);
428 return attributes_GetItemByIndex(&media_type
->attributes
, index
, key
, value
);
431 static HRESULT WINAPI
mediatype_CopyAllItems(IMFMediaType
*iface
, IMFAttributes
*dest
)
433 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
435 TRACE("%p, %p.\n", iface
, dest
);
437 return attributes_CopyAllItems(&media_type
->attributes
, dest
);
440 static HRESULT WINAPI
mediatype_GetMajorType(IMFMediaType
*iface
, GUID
*guid
)
442 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
444 TRACE("%p, %p.\n", iface
, guid
);
446 return attributes_GetGUID(&media_type
->attributes
, &MF_MT_MAJOR_TYPE
, guid
);
449 static HRESULT
mediatype_is_compressed(struct media_type
*media_type
, BOOL
*compressed
)
453 if (FAILED(attributes_GetUINT32(&media_type
->attributes
, &MF_MT_ALL_SAMPLES_INDEPENDENT
, &value
)))
458 *compressed
= !value
;
463 static HRESULT WINAPI
mediatype_IsCompressedFormat(IMFMediaType
*iface
, BOOL
*compressed
)
465 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
467 TRACE("%p, %p.\n", iface
, compressed
);
469 return mediatype_is_compressed(media_type
, compressed
);
472 static HRESULT
media_type_is_equal(struct media_type
*media_type
, IMFMediaType
*type
, DWORD
*flags
)
474 const DWORD full_equality_flags
= MF_MEDIATYPE_EQUAL_MAJOR_TYPES
| MF_MEDIATYPE_EQUAL_FORMAT_TYPES
|
475 MF_MEDIATYPE_EQUAL_FORMAT_DATA
| MF_MEDIATYPE_EQUAL_FORMAT_USER_DATA
;
489 left
.type
= &media_type
->attributes
.IMFAttributes_iface
;
490 right
.type
= (IMFAttributes
*)type
;
492 if (FAILED(IMFAttributes_GetGUID(left
.type
, &MF_MT_MAJOR_TYPE
, &left
.guid
)))
495 if (FAILED(IMFAttributes_GetGUID(right
.type
, &MF_MT_MAJOR_TYPE
, &right
.guid
)))
498 if (IsEqualGUID(&left
.guid
, &right
.guid
))
499 *flags
|= MF_MEDIATYPE_EQUAL_MAJOR_TYPES
;
501 /* Subtypes equal or both missing. */
502 left
.hr
= IMFAttributes_GetGUID(left
.type
, &MF_MT_SUBTYPE
, &left
.guid
);
503 right
.hr
= IMFAttributes_GetGUID(right
.type
, &MF_MT_SUBTYPE
, &right
.guid
);
505 if ((SUCCEEDED(left
.hr
) && SUCCEEDED(right
.hr
) && IsEqualGUID(&left
.guid
, &right
.guid
)) ||
506 (FAILED(left
.hr
) && FAILED(right
.hr
)))
508 *flags
|= MF_MEDIATYPE_EQUAL_FORMAT_TYPES
;
512 IMFAttributes_GetCount(left
.type
, &left
.count
);
513 IMFAttributes_GetCount(right
.type
, &right
.count
);
515 if (right
.count
< left
.count
)
522 *flags
|= MF_MEDIATYPE_EQUAL_FORMAT_DATA
;
524 for (i
= 0; i
< left
.count
; ++i
)
529 if (SUCCEEDED(IMFAttributes_GetItemByIndex(left
.type
, i
, &key
, &value
)))
531 if (IsEqualGUID(&key
, &MF_MT_USER_DATA
) ||
532 IsEqualGUID(&key
, &MF_MT_FRAME_RATE_RANGE_MIN
) ||
533 IsEqualGUID(&key
, &MF_MT_FRAME_RATE_RANGE_MAX
))
535 PropVariantClear(&value
);
540 IMFAttributes_CompareItem(right
.type
, &key
, &value
, &result
);
541 PropVariantClear(&value
);
544 *flags
&= ~MF_MEDIATYPE_EQUAL_FORMAT_DATA
;
551 PropVariantInit(&left
.value
);
552 left
.hr
= IMFAttributes_GetItem(left
.type
, &MF_MT_USER_DATA
, &left
.value
);
553 PropVariantInit(&right
.value
);
554 right
.hr
= IMFAttributes_GetItem(right
.type
, &MF_MT_USER_DATA
, &right
.value
);
556 /* Compare user data if both types have it, otherwise simply check if both don't. */
557 if (SUCCEEDED(left
.hr
) && SUCCEEDED(right
.hr
))
560 IMFAttributes_CompareItem(left
.type
, &MF_MT_USER_DATA
, &left
.value
, &result
);
563 result
= FAILED(left
.hr
) && FAILED(right
.hr
);
565 PropVariantClear(&left
.value
);
566 PropVariantClear(&right
.value
);
569 *flags
|= MF_MEDIATYPE_EQUAL_FORMAT_USER_DATA
;
571 return *flags
== full_equality_flags
? S_OK
: S_FALSE
;
574 static HRESULT WINAPI
mediatype_IsEqual(IMFMediaType
*iface
, IMFMediaType
*type
, DWORD
*flags
)
576 struct media_type
*media_type
= impl_from_IMFMediaType(iface
);
578 TRACE("%p, %p, %p.\n", iface
, type
, flags
);
580 return media_type_is_equal(media_type
, type
, flags
);
583 static HRESULT WINAPI
mediatype_GetRepresentation(IMFMediaType
*iface
, GUID guid
, void **representation
)
585 FIXME("%p, %s, %p.\n", iface
, debugstr_guid(&guid
), representation
);
590 static HRESULT WINAPI
mediatype_FreeRepresentation(IMFMediaType
*iface
, GUID guid
, void *representation
)
592 FIXME("%p, %s, %p.\n", iface
, debugstr_guid(&guid
), representation
);
597 static const IMFMediaTypeVtbl mediatypevtbl
=
599 mediatype_QueryInterface
,
603 mediatype_GetItemType
,
604 mediatype_CompareItem
,
610 mediatype_GetStringLength
,
612 mediatype_GetAllocatedString
,
613 mediatype_GetBlobSize
,
615 mediatype_GetAllocatedBlob
,
616 mediatype_GetUnknown
,
618 mediatype_DeleteItem
,
619 mediatype_DeleteAllItems
,
626 mediatype_SetUnknown
,
628 mediatype_UnlockStore
,
630 mediatype_GetItemByIndex
,
631 mediatype_CopyAllItems
,
632 mediatype_GetMajorType
,
633 mediatype_IsCompressedFormat
,
635 mediatype_GetRepresentation
,
636 mediatype_FreeRepresentation
639 static HRESULT WINAPI
video_mediatype_QueryInterface(IMFVideoMediaType
*iface
, REFIID riid
, void **out
)
641 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
642 return IMFMediaType_QueryInterface(&media_type
->IMFMediaType_iface
, riid
, out
);
645 static ULONG WINAPI
video_mediatype_AddRef(IMFVideoMediaType
*iface
)
647 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
648 return IMFMediaType_AddRef(&media_type
->IMFMediaType_iface
);
651 static ULONG WINAPI
video_mediatype_Release(IMFVideoMediaType
*iface
)
653 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
654 return IMFMediaType_Release(&media_type
->IMFMediaType_iface
);
657 static HRESULT WINAPI
video_mediatype_GetItem(IMFVideoMediaType
*iface
, REFGUID key
, PROPVARIANT
*value
)
659 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
661 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), value
);
663 return attributes_GetItem(&media_type
->attributes
, key
, value
);
666 static HRESULT WINAPI
video_mediatype_GetItemType(IMFVideoMediaType
*iface
, REFGUID key
, MF_ATTRIBUTE_TYPE
*type
)
668 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
670 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), type
);
672 return attributes_GetItemType(&media_type
->attributes
, key
, type
);
675 static HRESULT WINAPI
video_mediatype_CompareItem(IMFVideoMediaType
*iface
, REFGUID key
, REFPROPVARIANT value
, BOOL
*result
)
677 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
679 TRACE("%p, %s, %s, %p.\n", iface
, debugstr_attr(key
), debugstr_propvar(value
), result
);
681 return attributes_CompareItem(&media_type
->attributes
, key
, value
, result
);
684 static HRESULT WINAPI
video_mediatype_Compare(IMFVideoMediaType
*iface
, IMFAttributes
*attrs
,
685 MF_ATTRIBUTES_MATCH_TYPE type
, BOOL
*result
)
687 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
689 TRACE("%p, %p, %d, %p.\n", iface
, attrs
, type
, result
);
691 return attributes_Compare(&media_type
->attributes
, attrs
, type
, result
);
694 static HRESULT WINAPI
video_mediatype_GetUINT32(IMFVideoMediaType
*iface
, REFGUID key
, UINT32
*value
)
696 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
698 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), value
);
700 return attributes_GetUINT32(&media_type
->attributes
, key
, value
);
703 static HRESULT WINAPI
video_mediatype_GetUINT64(IMFVideoMediaType
*iface
, REFGUID key
, UINT64
*value
)
705 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
707 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), value
);
709 return attributes_GetUINT64(&media_type
->attributes
, key
, value
);
712 static HRESULT WINAPI
video_mediatype_GetDouble(IMFVideoMediaType
*iface
, REFGUID key
, double *value
)
714 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
716 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), value
);
718 return attributes_GetDouble(&media_type
->attributes
, key
, value
);
721 static HRESULT WINAPI
video_mediatype_GetGUID(IMFVideoMediaType
*iface
, REFGUID key
, GUID
*value
)
723 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
725 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), value
);
727 return attributes_GetGUID(&media_type
->attributes
, key
, value
);
730 static HRESULT WINAPI
video_mediatype_GetStringLength(IMFVideoMediaType
*iface
, REFGUID key
, UINT32
*length
)
732 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
734 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), length
);
736 return attributes_GetStringLength(&media_type
->attributes
, key
, length
);
739 static HRESULT WINAPI
video_mediatype_GetString(IMFVideoMediaType
*iface
, REFGUID key
, WCHAR
*value
,
740 UINT32 size
, UINT32
*length
)
742 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
744 TRACE("%p, %s, %p, %u, %p.\n", iface
, debugstr_attr(key
), value
, size
, length
);
746 return attributes_GetString(&media_type
->attributes
, key
, value
, size
, length
);
749 static HRESULT WINAPI
video_mediatype_GetAllocatedString(IMFVideoMediaType
*iface
, REFGUID key
,
750 WCHAR
**value
, UINT32
*length
)
752 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
754 TRACE("%p, %s, %p, %p.\n", iface
, debugstr_attr(key
), value
, length
);
756 return attributes_GetAllocatedString(&media_type
->attributes
, key
, value
, length
);
759 static HRESULT WINAPI
video_mediatype_GetBlobSize(IMFVideoMediaType
*iface
, REFGUID key
, UINT32
*size
)
761 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
763 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), size
);
765 return attributes_GetBlobSize(&media_type
->attributes
, key
, size
);
768 static HRESULT WINAPI
video_mediatype_GetBlob(IMFVideoMediaType
*iface
, REFGUID key
, UINT8
*buf
,
769 UINT32 bufsize
, UINT32
*blobsize
)
771 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
773 TRACE("%p, %s, %p, %u, %p.\n", iface
, debugstr_attr(key
), buf
, bufsize
, blobsize
);
775 return attributes_GetBlob(&media_type
->attributes
, key
, buf
, bufsize
, blobsize
);
778 static HRESULT WINAPI
video_mediatype_GetAllocatedBlob(IMFVideoMediaType
*iface
, REFGUID key
, UINT8
**buf
, UINT32
*size
)
780 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
782 TRACE("%p, %s, %p, %p.\n", iface
, debugstr_attr(key
), buf
, size
);
784 return attributes_GetAllocatedBlob(&media_type
->attributes
, key
, buf
, size
);
787 static HRESULT WINAPI
video_mediatype_GetUnknown(IMFVideoMediaType
*iface
, REFGUID key
, REFIID riid
, void **obj
)
789 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
791 TRACE("%p, %s, %s, %p.\n", iface
, debugstr_attr(key
), debugstr_guid(riid
), obj
);
793 return attributes_GetUnknown(&media_type
->attributes
, key
, riid
, obj
);
796 static HRESULT WINAPI
video_mediatype_SetItem(IMFVideoMediaType
*iface
, REFGUID key
, REFPROPVARIANT value
)
798 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
800 TRACE("%p, %s, %s.\n", iface
, debugstr_attr(key
), debugstr_propvar(value
));
802 return attributes_SetItem(&media_type
->attributes
, key
, value
);
805 static HRESULT WINAPI
video_mediatype_DeleteItem(IMFVideoMediaType
*iface
, REFGUID key
)
807 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
809 TRACE("%p, %s.\n", iface
, debugstr_attr(key
));
811 return attributes_DeleteItem(&media_type
->attributes
, key
);
814 static HRESULT WINAPI
video_mediatype_DeleteAllItems(IMFVideoMediaType
*iface
)
816 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
818 TRACE("%p.\n", iface
);
820 return attributes_DeleteAllItems(&media_type
->attributes
);
823 static HRESULT WINAPI
video_mediatype_SetUINT32(IMFVideoMediaType
*iface
, REFGUID key
, UINT32 value
)
825 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
827 TRACE("%p, %s, %u.\n", iface
, debugstr_attr(key
), value
);
829 return attributes_SetUINT32(&media_type
->attributes
, key
, value
);
832 static HRESULT WINAPI
video_mediatype_SetUINT64(IMFVideoMediaType
*iface
, REFGUID key
, UINT64 value
)
834 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
836 TRACE("%p, %s, %s.\n", iface
, debugstr_attr(key
), wine_dbgstr_longlong(value
));
838 return attributes_SetUINT64(&media_type
->attributes
, key
, value
);
841 static HRESULT WINAPI
video_mediatype_SetDouble(IMFVideoMediaType
*iface
, REFGUID key
, double value
)
843 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
845 TRACE("%p, %s, %f.\n", iface
, debugstr_attr(key
), value
);
847 return attributes_SetDouble(&media_type
->attributes
, key
, value
);
850 static HRESULT WINAPI
video_mediatype_SetGUID(IMFVideoMediaType
*iface
, REFGUID key
, REFGUID value
)
852 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
854 TRACE("%p, %s, %s.\n", iface
, debugstr_attr(key
), debugstr_mf_guid(value
));
856 return attributes_SetGUID(&media_type
->attributes
, key
, value
);
859 static HRESULT WINAPI
video_mediatype_SetString(IMFVideoMediaType
*iface
, REFGUID key
, const WCHAR
*value
)
861 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
863 TRACE("%p, %s, %s.\n", iface
, debugstr_attr(key
), debugstr_w(value
));
865 return attributes_SetString(&media_type
->attributes
, key
, value
);
868 static HRESULT WINAPI
video_mediatype_SetBlob(IMFVideoMediaType
*iface
, REFGUID key
, const UINT8
*buf
, UINT32 size
)
870 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
872 TRACE("%p, %s, %p, %u.\n", iface
, debugstr_attr(key
), buf
, size
);
874 return attributes_SetBlob(&media_type
->attributes
, key
, buf
, size
);
877 static HRESULT WINAPI
video_mediatype_SetUnknown(IMFVideoMediaType
*iface
, REFGUID key
, IUnknown
*unknown
)
879 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
881 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), unknown
);
883 return attributes_SetUnknown(&media_type
->attributes
, key
, unknown
);
886 static HRESULT WINAPI
video_mediatype_LockStore(IMFVideoMediaType
*iface
)
888 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
890 TRACE("%p.\n", iface
);
892 return attributes_LockStore(&media_type
->attributes
);
895 static HRESULT WINAPI
video_mediatype_UnlockStore(IMFVideoMediaType
*iface
)
897 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
899 TRACE("%p.\n", iface
);
901 return attributes_UnlockStore(&media_type
->attributes
);
904 static HRESULT WINAPI
video_mediatype_GetCount(IMFVideoMediaType
*iface
, UINT32
*count
)
906 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
908 TRACE("%p, %p.\n", iface
, count
);
910 return attributes_GetCount(&media_type
->attributes
, count
);
913 static HRESULT WINAPI
video_mediatype_GetItemByIndex(IMFVideoMediaType
*iface
, UINT32 index
, GUID
*key
, PROPVARIANT
*value
)
915 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
917 TRACE("%p, %u, %p, %p.\n", iface
, index
, key
, value
);
919 return attributes_GetItemByIndex(&media_type
->attributes
, index
, key
, value
);
922 static HRESULT WINAPI
video_mediatype_CopyAllItems(IMFVideoMediaType
*iface
, IMFAttributes
*dest
)
924 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
926 TRACE("%p, %p.\n", iface
, dest
);
928 return attributes_CopyAllItems(&media_type
->attributes
, dest
);
931 static HRESULT WINAPI
video_mediatype_GetMajorType(IMFVideoMediaType
*iface
, GUID
*guid
)
933 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
935 TRACE("%p, %p.\n", iface
, guid
);
937 return attributes_GetGUID(&media_type
->attributes
, &MF_MT_MAJOR_TYPE
, guid
);
940 static HRESULT WINAPI
video_mediatype_IsCompressedFormat(IMFVideoMediaType
*iface
, BOOL
*compressed
)
942 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
944 TRACE("%p, %p.\n", iface
, compressed
);
946 return mediatype_is_compressed(media_type
, compressed
);
949 static HRESULT WINAPI
video_mediatype_IsEqual(IMFVideoMediaType
*iface
, IMFMediaType
*type
, DWORD
*flags
)
951 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
953 TRACE("%p, %p, %p.\n", iface
, type
, flags
);
955 return media_type_is_equal(media_type
, type
, flags
);
958 static HRESULT WINAPI
video_mediatype_GetRepresentation(IMFVideoMediaType
*iface
, GUID guid
, void **representation
)
960 FIXME("%p, %s, %p.\n", iface
, debugstr_guid(&guid
), representation
);
965 static HRESULT WINAPI
video_mediatype_FreeRepresentation(IMFVideoMediaType
*iface
, GUID guid
, void *representation
)
967 FIXME("%p, %s, %p.\n", iface
, debugstr_guid(&guid
), representation
);
972 static const MFVIDEOFORMAT
* WINAPI
video_mediatype_GetVideoFormat(IMFVideoMediaType
*iface
)
974 struct media_type
*media_type
= impl_from_IMFVideoMediaType(iface
);
978 TRACE("%p.\n", iface
);
980 CoTaskMemFree(media_type
->video_format
);
981 media_type
->video_format
= NULL
;
982 if (FAILED(hr
= MFCreateMFVideoFormatFromMFMediaType(&media_type
->IMFMediaType_iface
, &media_type
->video_format
, &size
)))
983 WARN("Failed to create format description, hr %#lx.\n", hr
);
985 return media_type
->video_format
;
988 static HRESULT WINAPI
video_mediatype_GetVideoRepresentation(IMFVideoMediaType
*iface
, GUID representation
,
989 void **data
, LONG stride
)
991 FIXME("%p, %s, %p, %ld.\n", iface
, debugstr_guid(&representation
), data
, stride
);
996 static const IMFVideoMediaTypeVtbl videomediatypevtbl
=
998 video_mediatype_QueryInterface
,
999 video_mediatype_AddRef
,
1000 video_mediatype_Release
,
1001 video_mediatype_GetItem
,
1002 video_mediatype_GetItemType
,
1003 video_mediatype_CompareItem
,
1004 video_mediatype_Compare
,
1005 video_mediatype_GetUINT32
,
1006 video_mediatype_GetUINT64
,
1007 video_mediatype_GetDouble
,
1008 video_mediatype_GetGUID
,
1009 video_mediatype_GetStringLength
,
1010 video_mediatype_GetString
,
1011 video_mediatype_GetAllocatedString
,
1012 video_mediatype_GetBlobSize
,
1013 video_mediatype_GetBlob
,
1014 video_mediatype_GetAllocatedBlob
,
1015 video_mediatype_GetUnknown
,
1016 video_mediatype_SetItem
,
1017 video_mediatype_DeleteItem
,
1018 video_mediatype_DeleteAllItems
,
1019 video_mediatype_SetUINT32
,
1020 video_mediatype_SetUINT64
,
1021 video_mediatype_SetDouble
,
1022 video_mediatype_SetGUID
,
1023 video_mediatype_SetString
,
1024 video_mediatype_SetBlob
,
1025 video_mediatype_SetUnknown
,
1026 video_mediatype_LockStore
,
1027 video_mediatype_UnlockStore
,
1028 video_mediatype_GetCount
,
1029 video_mediatype_GetItemByIndex
,
1030 video_mediatype_CopyAllItems
,
1031 video_mediatype_GetMajorType
,
1032 video_mediatype_IsCompressedFormat
,
1033 video_mediatype_IsEqual
,
1034 video_mediatype_GetRepresentation
,
1035 video_mediatype_FreeRepresentation
,
1036 video_mediatype_GetVideoFormat
,
1037 video_mediatype_GetVideoRepresentation
,
1040 static HRESULT WINAPI
audio_mediatype_QueryInterface(IMFAudioMediaType
*iface
, REFIID riid
, void **out
)
1042 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1043 return IMFMediaType_QueryInterface(&media_type
->IMFMediaType_iface
, riid
, out
);
1046 static ULONG WINAPI
audio_mediatype_AddRef(IMFAudioMediaType
*iface
)
1048 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1049 return IMFMediaType_AddRef(&media_type
->IMFMediaType_iface
);
1052 static ULONG WINAPI
audio_mediatype_Release(IMFAudioMediaType
*iface
)
1054 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1055 return IMFMediaType_Release(&media_type
->IMFMediaType_iface
);
1058 static HRESULT WINAPI
audio_mediatype_GetItem(IMFAudioMediaType
*iface
, REFGUID key
, PROPVARIANT
*value
)
1060 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1062 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), value
);
1064 return attributes_GetItem(&media_type
->attributes
, key
, value
);
1067 static HRESULT WINAPI
audio_mediatype_GetItemType(IMFAudioMediaType
*iface
, REFGUID key
, MF_ATTRIBUTE_TYPE
*type
)
1069 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1071 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), type
);
1073 return attributes_GetItemType(&media_type
->attributes
, key
, type
);
1076 static HRESULT WINAPI
audio_mediatype_CompareItem(IMFAudioMediaType
*iface
, REFGUID key
, REFPROPVARIANT value
, BOOL
*result
)
1078 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1080 TRACE("%p, %s, %s, %p.\n", iface
, debugstr_attr(key
), debugstr_propvar(value
), result
);
1082 return attributes_CompareItem(&media_type
->attributes
, key
, value
, result
);
1085 static HRESULT WINAPI
audio_mediatype_Compare(IMFAudioMediaType
*iface
, IMFAttributes
*attrs
,
1086 MF_ATTRIBUTES_MATCH_TYPE type
, BOOL
*result
)
1088 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1090 TRACE("%p, %p, %d, %p.\n", iface
, attrs
, type
, result
);
1092 return attributes_Compare(&media_type
->attributes
, attrs
, type
, result
);
1095 static HRESULT WINAPI
audio_mediatype_GetUINT32(IMFAudioMediaType
*iface
, REFGUID key
, UINT32
*value
)
1097 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1099 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), value
);
1101 return attributes_GetUINT32(&media_type
->attributes
, key
, value
);
1104 static HRESULT WINAPI
audio_mediatype_GetUINT64(IMFAudioMediaType
*iface
, REFGUID key
, UINT64
*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_GetUINT64(&media_type
->attributes
, key
, value
);
1113 static HRESULT WINAPI
audio_mediatype_GetDouble(IMFAudioMediaType
*iface
, REFGUID key
, double *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_GetDouble(&media_type
->attributes
, key
, value
);
1122 static HRESULT WINAPI
audio_mediatype_GetGUID(IMFAudioMediaType
*iface
, REFGUID key
, GUID
*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_GetGUID(&media_type
->attributes
, key
, value
);
1131 static HRESULT WINAPI
audio_mediatype_GetStringLength(IMFAudioMediaType
*iface
, REFGUID key
, UINT32
*length
)
1133 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1135 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), length
);
1137 return attributes_GetStringLength(&media_type
->attributes
, key
, length
);
1140 static HRESULT WINAPI
audio_mediatype_GetString(IMFAudioMediaType
*iface
, REFGUID key
, WCHAR
*value
,
1141 UINT32 size
, UINT32
*length
)
1143 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1145 TRACE("%p, %s, %p, %u, %p.\n", iface
, debugstr_attr(key
), value
, size
, length
);
1147 return attributes_GetString(&media_type
->attributes
, key
, value
, size
, length
);
1150 static HRESULT WINAPI
audio_mediatype_GetAllocatedString(IMFAudioMediaType
*iface
, REFGUID key
,
1151 WCHAR
**value
, UINT32
*length
)
1153 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1155 TRACE("%p, %s, %p, %p.\n", iface
, debugstr_attr(key
), value
, length
);
1157 return attributes_GetAllocatedString(&media_type
->attributes
, key
, value
, length
);
1160 static HRESULT WINAPI
audio_mediatype_GetBlobSize(IMFAudioMediaType
*iface
, REFGUID key
, UINT32
*size
)
1162 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1164 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), size
);
1166 return attributes_GetBlobSize(&media_type
->attributes
, key
, size
);
1169 static HRESULT WINAPI
audio_mediatype_GetBlob(IMFAudioMediaType
*iface
, REFGUID key
, UINT8
*buf
,
1170 UINT32 bufsize
, UINT32
*blobsize
)
1172 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1174 TRACE("%p, %s, %p, %u, %p.\n", iface
, debugstr_attr(key
), buf
, bufsize
, blobsize
);
1176 return attributes_GetBlob(&media_type
->attributes
, key
, buf
, bufsize
, blobsize
);
1179 static HRESULT WINAPI
audio_mediatype_GetAllocatedBlob(IMFAudioMediaType
*iface
, REFGUID key
, UINT8
**buf
, UINT32
*size
)
1181 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1183 TRACE("%p, %s, %p, %p.\n", iface
, debugstr_attr(key
), buf
, size
);
1185 return attributes_GetAllocatedBlob(&media_type
->attributes
, key
, buf
, size
);
1188 static HRESULT WINAPI
audio_mediatype_GetUnknown(IMFAudioMediaType
*iface
, REFGUID key
, REFIID riid
, void **obj
)
1190 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1192 TRACE("%p, %s, %s, %p.\n", iface
, debugstr_attr(key
), debugstr_guid(riid
), obj
);
1194 return attributes_GetUnknown(&media_type
->attributes
, key
, riid
, obj
);
1197 static HRESULT WINAPI
audio_mediatype_SetItem(IMFAudioMediaType
*iface
, REFGUID key
, REFPROPVARIANT value
)
1199 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1201 TRACE("%p, %s, %s.\n", iface
, debugstr_attr(key
), debugstr_propvar(value
));
1203 return attributes_SetItem(&media_type
->attributes
, key
, value
);
1206 static HRESULT WINAPI
audio_mediatype_DeleteItem(IMFAudioMediaType
*iface
, REFGUID key
)
1208 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1210 TRACE("%p, %s.\n", iface
, debugstr_attr(key
));
1212 return attributes_DeleteItem(&media_type
->attributes
, key
);
1215 static HRESULT WINAPI
audio_mediatype_DeleteAllItems(IMFAudioMediaType
*iface
)
1217 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1219 TRACE("%p.\n", iface
);
1221 return attributes_DeleteAllItems(&media_type
->attributes
);
1224 static HRESULT WINAPI
audio_mediatype_SetUINT32(IMFAudioMediaType
*iface
, REFGUID key
, UINT32 value
)
1226 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1228 TRACE("%p, %s, %u.\n", iface
, debugstr_attr(key
), value
);
1230 return attributes_SetUINT32(&media_type
->attributes
, key
, value
);
1233 static HRESULT WINAPI
audio_mediatype_SetUINT64(IMFAudioMediaType
*iface
, REFGUID key
, UINT64 value
)
1235 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1237 TRACE("%p, %s, %s.\n", iface
, debugstr_attr(key
), wine_dbgstr_longlong(value
));
1239 return attributes_SetUINT64(&media_type
->attributes
, key
, value
);
1242 static HRESULT WINAPI
audio_mediatype_SetDouble(IMFAudioMediaType
*iface
, REFGUID key
, double value
)
1244 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1246 TRACE("%p, %s, %f.\n", iface
, debugstr_attr(key
), value
);
1248 return attributes_SetDouble(&media_type
->attributes
, key
, value
);
1251 static HRESULT WINAPI
audio_mediatype_SetGUID(IMFAudioMediaType
*iface
, REFGUID key
, REFGUID value
)
1253 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1255 TRACE("%p, %s, %s.\n", iface
, debugstr_attr(key
), debugstr_mf_guid(value
));
1257 return attributes_SetGUID(&media_type
->attributes
, key
, value
);
1260 static HRESULT WINAPI
audio_mediatype_SetString(IMFAudioMediaType
*iface
, REFGUID key
, const WCHAR
*value
)
1262 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1264 TRACE("%p, %s, %s.\n", iface
, debugstr_attr(key
), debugstr_w(value
));
1266 return attributes_SetString(&media_type
->attributes
, key
, value
);
1269 static HRESULT WINAPI
audio_mediatype_SetBlob(IMFAudioMediaType
*iface
, REFGUID key
, const UINT8
*buf
, UINT32 size
)
1271 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1273 TRACE("%p, %s, %p, %u.\n", iface
, debugstr_attr(key
), buf
, size
);
1275 return attributes_SetBlob(&media_type
->attributes
, key
, buf
, size
);
1278 static HRESULT WINAPI
audio_mediatype_SetUnknown(IMFAudioMediaType
*iface
, REFGUID key
, IUnknown
*unknown
)
1280 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1282 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), unknown
);
1284 return attributes_SetUnknown(&media_type
->attributes
, key
, unknown
);
1287 static HRESULT WINAPI
audio_mediatype_LockStore(IMFAudioMediaType
*iface
)
1289 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1291 TRACE("%p.\n", iface
);
1293 return attributes_LockStore(&media_type
->attributes
);
1296 static HRESULT WINAPI
audio_mediatype_UnlockStore(IMFAudioMediaType
*iface
)
1298 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1300 TRACE("%p.\n", iface
);
1302 return attributes_UnlockStore(&media_type
->attributes
);
1305 static HRESULT WINAPI
audio_mediatype_GetCount(IMFAudioMediaType
*iface
, UINT32
*count
)
1307 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1309 TRACE("%p, %p.\n", iface
, count
);
1311 return attributes_GetCount(&media_type
->attributes
, count
);
1314 static HRESULT WINAPI
audio_mediatype_GetItemByIndex(IMFAudioMediaType
*iface
, UINT32 index
, GUID
*key
, PROPVARIANT
*value
)
1316 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1318 TRACE("%p, %u, %p, %p.\n", iface
, index
, key
, value
);
1320 return attributes_GetItemByIndex(&media_type
->attributes
, index
, key
, value
);
1323 static HRESULT WINAPI
audio_mediatype_CopyAllItems(IMFAudioMediaType
*iface
, IMFAttributes
*dest
)
1325 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1327 TRACE("%p, %p.\n", iface
, dest
);
1329 return attributes_CopyAllItems(&media_type
->attributes
, dest
);
1332 static HRESULT WINAPI
audio_mediatype_GetMajorType(IMFAudioMediaType
*iface
, GUID
*guid
)
1334 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1336 TRACE("%p, %p.\n", iface
, guid
);
1338 return attributes_GetGUID(&media_type
->attributes
, &MF_MT_MAJOR_TYPE
, guid
);
1341 static HRESULT WINAPI
audio_mediatype_IsCompressedFormat(IMFAudioMediaType
*iface
, BOOL
*compressed
)
1343 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1345 TRACE("%p, %p.\n", iface
, compressed
);
1347 return mediatype_is_compressed(media_type
, compressed
);
1350 static HRESULT WINAPI
audio_mediatype_IsEqual(IMFAudioMediaType
*iface
, IMFMediaType
*type
, DWORD
*flags
)
1352 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1354 TRACE("%p, %p, %p.\n", iface
, type
, flags
);
1356 return media_type_is_equal(media_type
, type
, flags
);
1359 static HRESULT WINAPI
audio_mediatype_GetRepresentation(IMFAudioMediaType
*iface
, GUID guid
, void **representation
)
1361 FIXME("%p, %s, %p.\n", iface
, debugstr_guid(&guid
), representation
);
1366 static HRESULT WINAPI
audio_mediatype_FreeRepresentation(IMFAudioMediaType
*iface
, GUID guid
, void *representation
)
1368 FIXME("%p, %s, %p.\n", iface
, debugstr_guid(&guid
), representation
);
1373 static const WAVEFORMATEX
* WINAPI
audio_mediatype_GetAudioFormat(IMFAudioMediaType
*iface
)
1375 struct media_type
*media_type
= impl_from_IMFAudioMediaType(iface
);
1379 TRACE("%p.\n", iface
);
1381 CoTaskMemFree(media_type
->audio_format
);
1382 media_type
->audio_format
= NULL
;
1383 if (FAILED(hr
= MFCreateWaveFormatExFromMFMediaType(&media_type
->IMFMediaType_iface
, &media_type
->audio_format
,
1384 &size
, MFWaveFormatExConvertFlag_Normal
)))
1386 WARN("Failed to create wave format description, hr %#lx.\n", hr
);
1389 return media_type
->audio_format
;
1392 static const IMFAudioMediaTypeVtbl audiomediatypevtbl
=
1394 audio_mediatype_QueryInterface
,
1395 audio_mediatype_AddRef
,
1396 audio_mediatype_Release
,
1397 audio_mediatype_GetItem
,
1398 audio_mediatype_GetItemType
,
1399 audio_mediatype_CompareItem
,
1400 audio_mediatype_Compare
,
1401 audio_mediatype_GetUINT32
,
1402 audio_mediatype_GetUINT64
,
1403 audio_mediatype_GetDouble
,
1404 audio_mediatype_GetGUID
,
1405 audio_mediatype_GetStringLength
,
1406 audio_mediatype_GetString
,
1407 audio_mediatype_GetAllocatedString
,
1408 audio_mediatype_GetBlobSize
,
1409 audio_mediatype_GetBlob
,
1410 audio_mediatype_GetAllocatedBlob
,
1411 audio_mediatype_GetUnknown
,
1412 audio_mediatype_SetItem
,
1413 audio_mediatype_DeleteItem
,
1414 audio_mediatype_DeleteAllItems
,
1415 audio_mediatype_SetUINT32
,
1416 audio_mediatype_SetUINT64
,
1417 audio_mediatype_SetDouble
,
1418 audio_mediatype_SetGUID
,
1419 audio_mediatype_SetString
,
1420 audio_mediatype_SetBlob
,
1421 audio_mediatype_SetUnknown
,
1422 audio_mediatype_LockStore
,
1423 audio_mediatype_UnlockStore
,
1424 audio_mediatype_GetCount
,
1425 audio_mediatype_GetItemByIndex
,
1426 audio_mediatype_CopyAllItems
,
1427 audio_mediatype_GetMajorType
,
1428 audio_mediatype_IsCompressedFormat
,
1429 audio_mediatype_IsEqual
,
1430 audio_mediatype_GetRepresentation
,
1431 audio_mediatype_FreeRepresentation
,
1432 audio_mediatype_GetAudioFormat
,
1435 static HRESULT
create_media_type(struct media_type
**ret
)
1437 struct media_type
*object
;
1440 if (!(object
= calloc(1, sizeof(*object
))))
1441 return E_OUTOFMEMORY
;
1443 if (FAILED(hr
= init_attributes_object(&object
->attributes
, 0)))
1448 object
->IMFMediaType_iface
.lpVtbl
= &mediatypevtbl
;
1449 object
->IMFVideoMediaType_iface
.lpVtbl
= &videomediatypevtbl
;
1450 object
->IMFAudioMediaType_iface
.lpVtbl
= &audiomediatypevtbl
;
1457 /***********************************************************************
1458 * MFCreateMediaType (mfplat.@)
1460 HRESULT WINAPI
MFCreateMediaType(IMFMediaType
**media_type
)
1462 struct media_type
*object
;
1465 TRACE("%p.\n", media_type
);
1468 return E_INVALIDARG
;
1470 if (FAILED(hr
= create_media_type(&object
)))
1473 *media_type
= &object
->IMFMediaType_iface
;
1475 TRACE("Created media type %p.\n", *media_type
);
1480 static HRESULT WINAPI
stream_descriptor_QueryInterface(IMFStreamDescriptor
*iface
, REFIID riid
, void **out
)
1482 TRACE("%p, %s, %p.\n", iface
, debugstr_guid(riid
), out
);
1484 if (IsEqualIID(riid
, &IID_IMFStreamDescriptor
) ||
1485 IsEqualIID(riid
, &IID_IMFAttributes
) ||
1486 IsEqualIID(riid
, &IID_IUnknown
))
1489 IMFStreamDescriptor_AddRef(iface
);
1493 WARN("Unsupported %s.\n", debugstr_guid(riid
));
1495 return E_NOINTERFACE
;
1498 static ULONG WINAPI
stream_descriptor_AddRef(IMFStreamDescriptor
*iface
)
1500 struct stream_desc
*stream_desc
= impl_from_IMFStreamDescriptor(iface
);
1501 ULONG refcount
= InterlockedIncrement(&stream_desc
->attributes
.ref
);
1503 TRACE("%p, refcount %lu.\n", iface
, refcount
);
1508 static ULONG WINAPI
stream_descriptor_Release(IMFStreamDescriptor
*iface
)
1510 struct stream_desc
*stream_desc
= impl_from_IMFStreamDescriptor(iface
);
1511 ULONG refcount
= InterlockedDecrement(&stream_desc
->attributes
.ref
);
1514 TRACE("%p, refcount %lu.\n", iface
, refcount
);
1518 for (i
= 0; i
< stream_desc
->media_types_count
; ++i
)
1520 if (stream_desc
->media_types
[i
])
1521 IMFMediaType_Release(stream_desc
->media_types
[i
]);
1523 free(stream_desc
->media_types
);
1524 if (stream_desc
->current_type
)
1525 IMFMediaType_Release(stream_desc
->current_type
);
1526 clear_attributes_object(&stream_desc
->attributes
);
1533 static HRESULT WINAPI
stream_descriptor_GetItem(IMFStreamDescriptor
*iface
, REFGUID key
, PROPVARIANT
*value
)
1535 struct stream_desc
*stream_desc
= impl_from_IMFStreamDescriptor(iface
);
1537 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), value
);
1539 return attributes_GetItem(&stream_desc
->attributes
, key
, value
);
1542 static HRESULT WINAPI
stream_descriptor_GetItemType(IMFStreamDescriptor
*iface
, REFGUID key
, MF_ATTRIBUTE_TYPE
*type
)
1544 struct stream_desc
*stream_desc
= impl_from_IMFStreamDescriptor(iface
);
1546 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), type
);
1548 return attributes_GetItemType(&stream_desc
->attributes
, key
, type
);
1551 static HRESULT WINAPI
stream_descriptor_CompareItem(IMFStreamDescriptor
*iface
, REFGUID key
, REFPROPVARIANT value
,
1554 struct stream_desc
*stream_desc
= impl_from_IMFStreamDescriptor(iface
);
1556 TRACE("%p, %s, %s, %p.\n", iface
, debugstr_attr(key
), debugstr_propvar(value
), result
);
1558 return attributes_CompareItem(&stream_desc
->attributes
, key
, value
, result
);
1561 static HRESULT WINAPI
stream_descriptor_Compare(IMFStreamDescriptor
*iface
, IMFAttributes
*theirs
,
1562 MF_ATTRIBUTES_MATCH_TYPE type
, BOOL
*result
)
1564 struct stream_desc
*stream_desc
= impl_from_IMFStreamDescriptor(iface
);
1566 TRACE("%p, %p, %d, %p.\n", iface
, theirs
, type
, result
);
1568 return attributes_Compare(&stream_desc
->attributes
, theirs
, type
, result
);
1571 static HRESULT WINAPI
stream_descriptor_GetUINT32(IMFStreamDescriptor
*iface
, REFGUID key
, UINT32
*value
)
1573 struct stream_desc
*stream_desc
= impl_from_IMFStreamDescriptor(iface
);
1575 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), value
);
1577 return attributes_GetUINT32(&stream_desc
->attributes
, key
, value
);
1580 static HRESULT WINAPI
stream_descriptor_GetUINT64(IMFStreamDescriptor
*iface
, REFGUID key
, UINT64
*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_GetUINT64(&stream_desc
->attributes
, key
, value
);
1589 static HRESULT WINAPI
stream_descriptor_GetDouble(IMFStreamDescriptor
*iface
, REFGUID key
, double *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_GetDouble(&stream_desc
->attributes
, key
, value
);
1598 static HRESULT WINAPI
stream_descriptor_GetGUID(IMFStreamDescriptor
*iface
, REFGUID key
, GUID
*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_GetGUID(&stream_desc
->attributes
, key
, value
);
1607 static HRESULT WINAPI
stream_descriptor_GetStringLength(IMFStreamDescriptor
*iface
, REFGUID key
, UINT32
*length
)
1609 struct stream_desc
*stream_desc
= impl_from_IMFStreamDescriptor(iface
);
1611 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), length
);
1613 return attributes_GetStringLength(&stream_desc
->attributes
, key
, length
);
1616 static HRESULT WINAPI
stream_descriptor_GetString(IMFStreamDescriptor
*iface
, REFGUID key
, WCHAR
*value
,
1617 UINT32 size
, UINT32
*length
)
1619 struct stream_desc
*stream_desc
= impl_from_IMFStreamDescriptor(iface
);
1621 TRACE("%p, %s, %p, %u, %p.\n", iface
, debugstr_attr(key
), value
, size
, length
);
1623 return attributes_GetString(&stream_desc
->attributes
, key
, value
, size
, length
);
1626 static HRESULT WINAPI
stream_descriptor_GetAllocatedString(IMFStreamDescriptor
*iface
, REFGUID key
,
1627 WCHAR
**value
, UINT32
*length
)
1629 struct stream_desc
*stream_desc
= impl_from_IMFStreamDescriptor(iface
);
1631 TRACE("%p, %s, %p, %p.\n", iface
, debugstr_attr(key
), value
, length
);
1633 return attributes_GetAllocatedString(&stream_desc
->attributes
, key
, value
, length
);
1636 static HRESULT WINAPI
stream_descriptor_GetBlobSize(IMFStreamDescriptor
*iface
, REFGUID key
, UINT32
*size
)
1638 struct stream_desc
*stream_desc
= impl_from_IMFStreamDescriptor(iface
);
1640 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), size
);
1642 return attributes_GetBlobSize(&stream_desc
->attributes
, key
, size
);
1645 static HRESULT WINAPI
stream_descriptor_GetBlob(IMFStreamDescriptor
*iface
, REFGUID key
, UINT8
*buf
,
1646 UINT32 bufsize
, UINT32
*blobsize
)
1648 struct stream_desc
*stream_desc
= impl_from_IMFStreamDescriptor(iface
);
1650 TRACE("%p, %s, %p, %u, %p.\n", iface
, debugstr_attr(key
), buf
, bufsize
, blobsize
);
1652 return attributes_GetBlob(&stream_desc
->attributes
, key
, buf
, bufsize
, blobsize
);
1655 static HRESULT WINAPI
stream_descriptor_GetAllocatedBlob(IMFStreamDescriptor
*iface
, REFGUID key
, UINT8
**buf
,
1658 struct stream_desc
*stream_desc
= impl_from_IMFStreamDescriptor(iface
);
1660 TRACE("%p, %s, %p, %p.\n", iface
, debugstr_attr(key
), buf
, size
);
1662 return attributes_GetAllocatedBlob(&stream_desc
->attributes
, key
, buf
, size
);
1665 static HRESULT WINAPI
stream_descriptor_GetUnknown(IMFStreamDescriptor
*iface
, REFGUID key
, REFIID riid
, void **out
)
1667 struct stream_desc
*stream_desc
= impl_from_IMFStreamDescriptor(iface
);
1669 TRACE("%p, %s, %s, %p.\n", iface
, debugstr_attr(key
), debugstr_guid(riid
), out
);
1671 return attributes_GetUnknown(&stream_desc
->attributes
, key
, riid
, out
);
1674 static HRESULT WINAPI
stream_descriptor_SetItem(IMFStreamDescriptor
*iface
, REFGUID key
, REFPROPVARIANT value
)
1676 struct stream_desc
*stream_desc
= impl_from_IMFStreamDescriptor(iface
);
1678 TRACE("%p, %s, %s.\n", iface
, debugstr_attr(key
), debugstr_propvar(value
));
1680 return attributes_SetItem(&stream_desc
->attributes
, key
, value
);
1683 static HRESULT WINAPI
stream_descriptor_DeleteItem(IMFStreamDescriptor
*iface
, REFGUID key
)
1685 struct stream_desc
*stream_desc
= impl_from_IMFStreamDescriptor(iface
);
1687 TRACE("%p, %s.\n", iface
, debugstr_attr(key
));
1689 return attributes_DeleteItem(&stream_desc
->attributes
, key
);
1692 static HRESULT WINAPI
stream_descriptor_DeleteAllItems(IMFStreamDescriptor
*iface
)
1694 struct stream_desc
*stream_desc
= impl_from_IMFStreamDescriptor(iface
);
1696 TRACE("%p.\n", iface
);
1698 return attributes_DeleteAllItems(&stream_desc
->attributes
);
1701 static HRESULT WINAPI
stream_descriptor_SetUINT32(IMFStreamDescriptor
*iface
, REFGUID key
, UINT32 value
)
1703 struct stream_desc
*stream_desc
= impl_from_IMFStreamDescriptor(iface
);
1705 TRACE("%p, %s, %u.\n", iface
, debugstr_attr(key
), value
);
1707 return attributes_SetUINT32(&stream_desc
->attributes
, key
, value
);
1710 static HRESULT WINAPI
stream_descriptor_SetUINT64(IMFStreamDescriptor
*iface
, REFGUID key
, UINT64 value
)
1712 struct stream_desc
*stream_desc
= impl_from_IMFStreamDescriptor(iface
);
1714 TRACE("%p, %s, %s.\n", iface
, debugstr_attr(key
), wine_dbgstr_longlong(value
));
1716 return attributes_SetUINT64(&stream_desc
->attributes
, key
, value
);
1719 static HRESULT WINAPI
stream_descriptor_SetDouble(IMFStreamDescriptor
*iface
, REFGUID key
, double value
)
1721 struct stream_desc
*stream_desc
= impl_from_IMFStreamDescriptor(iface
);
1723 TRACE("%p, %s, %f.\n", iface
, debugstr_attr(key
), value
);
1725 return attributes_SetDouble(&stream_desc
->attributes
, key
, value
);
1728 static HRESULT WINAPI
stream_descriptor_SetGUID(IMFStreamDescriptor
*iface
, REFGUID key
, REFGUID value
)
1730 struct stream_desc
*stream_desc
= impl_from_IMFStreamDescriptor(iface
);
1732 TRACE("%p, %s, %s.\n", iface
, debugstr_attr(key
), debugstr_mf_guid(value
));
1734 return attributes_SetGUID(&stream_desc
->attributes
, key
, value
);
1737 static HRESULT WINAPI
stream_descriptor_SetString(IMFStreamDescriptor
*iface
, REFGUID key
, const WCHAR
*value
)
1739 struct stream_desc
*stream_desc
= impl_from_IMFStreamDescriptor(iface
);
1741 TRACE("%p, %s, %s.\n", iface
, debugstr_attr(key
), debugstr_w(value
));
1743 return attributes_SetString(&stream_desc
->attributes
, key
, value
);
1746 static HRESULT WINAPI
stream_descriptor_SetBlob(IMFStreamDescriptor
*iface
, REFGUID key
, const UINT8
*buf
, UINT32 size
)
1748 struct stream_desc
*stream_desc
= impl_from_IMFStreamDescriptor(iface
);
1750 TRACE("%p, %s, %p, %u.\n", iface
, debugstr_attr(key
), buf
, size
);
1752 return attributes_SetBlob(&stream_desc
->attributes
, key
, buf
, size
);
1755 static HRESULT WINAPI
stream_descriptor_SetUnknown(IMFStreamDescriptor
*iface
, REFGUID key
, IUnknown
*unknown
)
1757 struct stream_desc
*stream_desc
= impl_from_IMFStreamDescriptor(iface
);
1759 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), unknown
);
1761 return attributes_SetUnknown(&stream_desc
->attributes
, key
, unknown
);
1764 static HRESULT WINAPI
stream_descriptor_LockStore(IMFStreamDescriptor
*iface
)
1766 struct stream_desc
*stream_desc
= impl_from_IMFStreamDescriptor(iface
);
1768 TRACE("%p.\n", iface
);
1770 return attributes_LockStore(&stream_desc
->attributes
);
1773 static HRESULT WINAPI
stream_descriptor_UnlockStore(IMFStreamDescriptor
*iface
)
1775 struct stream_desc
*stream_desc
= impl_from_IMFStreamDescriptor(iface
);
1777 TRACE("%p.\n", iface
);
1779 return attributes_UnlockStore(&stream_desc
->attributes
);
1782 static HRESULT WINAPI
stream_descriptor_GetCount(IMFStreamDescriptor
*iface
, UINT32
*count
)
1784 struct stream_desc
*stream_desc
= impl_from_IMFStreamDescriptor(iface
);
1786 TRACE("%p, %p.\n", iface
, count
);
1788 return attributes_GetCount(&stream_desc
->attributes
, count
);
1791 static HRESULT WINAPI
stream_descriptor_GetItemByIndex(IMFStreamDescriptor
*iface
, UINT32 index
, GUID
*key
,
1794 struct stream_desc
*stream_desc
= impl_from_IMFStreamDescriptor(iface
);
1796 TRACE("%p, %u, %p, %p.\n", iface
, index
, key
, value
);
1798 return attributes_GetItemByIndex(&stream_desc
->attributes
, index
, key
, value
);
1801 static HRESULT WINAPI
stream_descriptor_CopyAllItems(IMFStreamDescriptor
*iface
, IMFAttributes
*dest
)
1803 struct stream_desc
*stream_desc
= impl_from_IMFStreamDescriptor(iface
);
1805 TRACE("%p, %p.\n", iface
, dest
);
1807 return attributes_CopyAllItems(&stream_desc
->attributes
, dest
);
1810 static HRESULT WINAPI
stream_descriptor_GetStreamIdentifier(IMFStreamDescriptor
*iface
, DWORD
*identifier
)
1812 struct stream_desc
*stream_desc
= impl_from_IMFStreamDescriptor(iface
);
1814 TRACE("%p, %p.\n", iface
, identifier
);
1816 *identifier
= stream_desc
->identifier
;
1821 static HRESULT WINAPI
stream_descriptor_GetMediaTypeHandler(IMFStreamDescriptor
*iface
, IMFMediaTypeHandler
**handler
)
1823 struct stream_desc
*stream_desc
= impl_from_IMFStreamDescriptor(iface
);
1825 TRACE("%p, %p.\n", iface
, handler
);
1827 *handler
= &stream_desc
->IMFMediaTypeHandler_iface
;
1828 IMFMediaTypeHandler_AddRef(*handler
);
1833 static const IMFStreamDescriptorVtbl streamdescriptorvtbl
=
1835 stream_descriptor_QueryInterface
,
1836 stream_descriptor_AddRef
,
1837 stream_descriptor_Release
,
1838 stream_descriptor_GetItem
,
1839 stream_descriptor_GetItemType
,
1840 stream_descriptor_CompareItem
,
1841 stream_descriptor_Compare
,
1842 stream_descriptor_GetUINT32
,
1843 stream_descriptor_GetUINT64
,
1844 stream_descriptor_GetDouble
,
1845 stream_descriptor_GetGUID
,
1846 stream_descriptor_GetStringLength
,
1847 stream_descriptor_GetString
,
1848 stream_descriptor_GetAllocatedString
,
1849 stream_descriptor_GetBlobSize
,
1850 stream_descriptor_GetBlob
,
1851 stream_descriptor_GetAllocatedBlob
,
1852 stream_descriptor_GetUnknown
,
1853 stream_descriptor_SetItem
,
1854 stream_descriptor_DeleteItem
,
1855 stream_descriptor_DeleteAllItems
,
1856 stream_descriptor_SetUINT32
,
1857 stream_descriptor_SetUINT64
,
1858 stream_descriptor_SetDouble
,
1859 stream_descriptor_SetGUID
,
1860 stream_descriptor_SetString
,
1861 stream_descriptor_SetBlob
,
1862 stream_descriptor_SetUnknown
,
1863 stream_descriptor_LockStore
,
1864 stream_descriptor_UnlockStore
,
1865 stream_descriptor_GetCount
,
1866 stream_descriptor_GetItemByIndex
,
1867 stream_descriptor_CopyAllItems
,
1868 stream_descriptor_GetStreamIdentifier
,
1869 stream_descriptor_GetMediaTypeHandler
1872 static HRESULT WINAPI
mediatype_handler_QueryInterface(IMFMediaTypeHandler
*iface
, REFIID riid
, void **obj
)
1874 TRACE("%p, %s, %p.\n", iface
, debugstr_guid(riid
), obj
);
1876 if (IsEqualIID(riid
, &IID_IMFMediaTypeHandler
) ||
1877 IsEqualIID(riid
, &IID_IUnknown
))
1880 IMFMediaTypeHandler_AddRef(iface
);
1884 WARN("Unsupported %s.\n", debugstr_guid(riid
));
1886 return E_NOINTERFACE
;
1889 static ULONG WINAPI
mediatype_handler_AddRef(IMFMediaTypeHandler
*iface
)
1891 struct stream_desc
*stream_desc
= impl_from_IMFMediaTypeHandler(iface
);
1892 return IMFStreamDescriptor_AddRef(&stream_desc
->IMFStreamDescriptor_iface
);
1895 static ULONG WINAPI
mediatype_handler_Release(IMFMediaTypeHandler
*iface
)
1897 struct stream_desc
*stream_desc
= impl_from_IMFMediaTypeHandler(iface
);
1898 return IMFStreamDescriptor_Release(&stream_desc
->IMFStreamDescriptor_iface
);
1901 static BOOL
stream_descriptor_is_mediatype_supported(IMFMediaType
*media_type
, IMFMediaType
*candidate
)
1905 if (FAILED(IMFMediaType_IsEqual(media_type
, candidate
, &flags
)))
1908 return (flags
& (MF_MEDIATYPE_EQUAL_MAJOR_TYPES
| MF_MEDIATYPE_EQUAL_FORMAT_TYPES
)) ==
1909 (MF_MEDIATYPE_EQUAL_MAJOR_TYPES
| MF_MEDIATYPE_EQUAL_FORMAT_TYPES
);
1912 static HRESULT WINAPI
mediatype_handler_IsMediaTypeSupported(IMFMediaTypeHandler
*iface
, IMFMediaType
*in_type
,
1913 IMFMediaType
**out_type
)
1915 struct stream_desc
*stream_desc
= impl_from_IMFMediaTypeHandler(iface
);
1916 BOOL supported
= FALSE
;
1919 TRACE("%p, %p, %p.\n", iface
, in_type
, out_type
);
1927 EnterCriticalSection(&stream_desc
->attributes
.cs
);
1929 supported
= stream_desc
->current_type
&& stream_descriptor_is_mediatype_supported(stream_desc
->current_type
, in_type
);
1932 for (i
= 0; i
< stream_desc
->media_types_count
; ++i
)
1934 if ((supported
= stream_descriptor_is_mediatype_supported(stream_desc
->media_types
[i
], in_type
)))
1939 LeaveCriticalSection(&stream_desc
->attributes
.cs
);
1941 return supported
? S_OK
: MF_E_INVALIDMEDIATYPE
;
1944 static HRESULT WINAPI
mediatype_handler_GetMediaTypeCount(IMFMediaTypeHandler
*iface
, DWORD
*count
)
1946 struct stream_desc
*stream_desc
= impl_from_IMFMediaTypeHandler(iface
);
1948 TRACE("%p, %p.\n", iface
, count
);
1950 *count
= stream_desc
->media_types_count
;
1955 static HRESULT WINAPI
mediatype_handler_GetMediaTypeByIndex(IMFMediaTypeHandler
*iface
, DWORD index
,
1956 IMFMediaType
**type
)
1958 struct stream_desc
*stream_desc
= impl_from_IMFMediaTypeHandler(iface
);
1960 TRACE("%p, %lu, %p.\n", iface
, index
, type
);
1962 if (index
>= stream_desc
->media_types_count
)
1963 return MF_E_NO_MORE_TYPES
;
1965 if (stream_desc
->media_types
[index
])
1967 *type
= stream_desc
->media_types
[index
];
1968 IMFMediaType_AddRef(*type
);
1971 return stream_desc
->media_types
[index
] ? S_OK
: E_FAIL
;
1974 static HRESULT WINAPI
mediatype_handler_SetCurrentMediaType(IMFMediaTypeHandler
*iface
, IMFMediaType
*type
)
1976 struct stream_desc
*stream_desc
= impl_from_IMFMediaTypeHandler(iface
);
1978 TRACE("%p, %p.\n", iface
, type
);
1983 EnterCriticalSection(&stream_desc
->attributes
.cs
);
1984 if (stream_desc
->current_type
)
1985 IMFMediaType_Release(stream_desc
->current_type
);
1986 stream_desc
->current_type
= type
;
1987 IMFMediaType_AddRef(stream_desc
->current_type
);
1988 LeaveCriticalSection(&stream_desc
->attributes
.cs
);
1993 static HRESULT WINAPI
mediatype_handler_GetCurrentMediaType(IMFMediaTypeHandler
*iface
, IMFMediaType
**type
)
1995 struct stream_desc
*stream_desc
= impl_from_IMFMediaTypeHandler(iface
);
1998 TRACE("%p, %p.\n", iface
, type
);
2000 EnterCriticalSection(&stream_desc
->attributes
.cs
);
2001 if (stream_desc
->current_type
)
2003 *type
= stream_desc
->current_type
;
2004 IMFMediaType_AddRef(*type
);
2007 hr
= MF_E_NOT_INITIALIZED
;
2008 LeaveCriticalSection(&stream_desc
->attributes
.cs
);
2013 static HRESULT WINAPI
mediatype_handler_GetMajorType(IMFMediaTypeHandler
*iface
, GUID
*type
)
2015 struct stream_desc
*stream_desc
= impl_from_IMFMediaTypeHandler(iface
);
2018 TRACE("%p, %p.\n", iface
, type
);
2020 EnterCriticalSection(&stream_desc
->attributes
.cs
);
2021 hr
= IMFMediaType_GetGUID(stream_desc
->current_type
? stream_desc
->current_type
:
2022 stream_desc
->media_types
[0], &MF_MT_MAJOR_TYPE
, type
);
2023 LeaveCriticalSection(&stream_desc
->attributes
.cs
);
2028 static const IMFMediaTypeHandlerVtbl mediatypehandlervtbl
=
2030 mediatype_handler_QueryInterface
,
2031 mediatype_handler_AddRef
,
2032 mediatype_handler_Release
,
2033 mediatype_handler_IsMediaTypeSupported
,
2034 mediatype_handler_GetMediaTypeCount
,
2035 mediatype_handler_GetMediaTypeByIndex
,
2036 mediatype_handler_SetCurrentMediaType
,
2037 mediatype_handler_GetCurrentMediaType
,
2038 mediatype_handler_GetMajorType
,
2041 /***********************************************************************
2042 * MFCreateStreamDescriptor (mfplat.@)
2044 HRESULT WINAPI
MFCreateStreamDescriptor(DWORD identifier
, DWORD count
,
2045 IMFMediaType
**types
, IMFStreamDescriptor
**descriptor
)
2047 struct stream_desc
*object
;
2051 TRACE("%ld, %ld, %p, %p.\n", identifier
, count
, types
, descriptor
);
2054 return E_INVALIDARG
;
2056 if (!(object
= calloc(1, sizeof(*object
))))
2057 return E_OUTOFMEMORY
;
2059 if (FAILED(hr
= init_attributes_object(&object
->attributes
, 0)))
2064 object
->IMFStreamDescriptor_iface
.lpVtbl
= &streamdescriptorvtbl
;
2065 object
->IMFMediaTypeHandler_iface
.lpVtbl
= &mediatypehandlervtbl
;
2066 object
->identifier
= identifier
;
2067 object
->media_types
= calloc(count
, sizeof(*object
->media_types
));
2068 if (!object
->media_types
)
2070 IMFStreamDescriptor_Release(&object
->IMFStreamDescriptor_iface
);
2071 return E_OUTOFMEMORY
;
2073 for (i
= 0; i
< count
; ++i
)
2075 object
->media_types
[i
] = types
[i
];
2076 if (object
->media_types
[i
])
2077 IMFMediaType_AddRef(object
->media_types
[i
]);
2079 object
->media_types_count
= count
;
2081 *descriptor
= &object
->IMFStreamDescriptor_iface
;
2086 static HRESULT WINAPI
presentation_descriptor_QueryInterface(IMFPresentationDescriptor
*iface
, REFIID riid
, void **out
)
2088 TRACE("%p, %s, %p.\n", iface
, debugstr_guid(riid
), out
);
2090 if (IsEqualIID(riid
, &IID_IMFPresentationDescriptor
) ||
2091 IsEqualIID(riid
, &IID_IMFAttributes
) ||
2092 IsEqualIID(riid
, &IID_IUnknown
))
2095 IMFPresentationDescriptor_AddRef(iface
);
2099 WARN("Unsupported %s.\n", debugstr_guid(riid
));
2101 return E_NOINTERFACE
;
2104 static ULONG WINAPI
presentation_descriptor_AddRef(IMFPresentationDescriptor
*iface
)
2106 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2107 ULONG refcount
= InterlockedIncrement(&presentation_desc
->attributes
.ref
);
2109 TRACE("%p, refcount %lu.\n", iface
, refcount
);
2114 static ULONG WINAPI
presentation_descriptor_Release(IMFPresentationDescriptor
*iface
)
2116 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2117 ULONG refcount
= InterlockedDecrement(&presentation_desc
->attributes
.ref
);
2120 TRACE("%p, refcount %lu.\n", iface
, refcount
);
2124 for (i
= 0; i
< presentation_desc
->count
; ++i
)
2126 if (presentation_desc
->descriptors
[i
].descriptor
)
2127 IMFStreamDescriptor_Release(presentation_desc
->descriptors
[i
].descriptor
);
2129 clear_attributes_object(&presentation_desc
->attributes
);
2130 free(presentation_desc
->descriptors
);
2131 free(presentation_desc
);
2137 static HRESULT WINAPI
presentation_descriptor_GetItem(IMFPresentationDescriptor
*iface
, REFGUID key
,
2140 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2142 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), value
);
2144 return attributes_GetItem(&presentation_desc
->attributes
, key
, value
);
2147 static HRESULT WINAPI
presentation_descriptor_GetItemType(IMFPresentationDescriptor
*iface
, REFGUID key
,
2148 MF_ATTRIBUTE_TYPE
*type
)
2150 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2152 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), type
);
2154 return attributes_GetItemType(&presentation_desc
->attributes
, key
, type
);
2157 static HRESULT WINAPI
presentation_descriptor_CompareItem(IMFPresentationDescriptor
*iface
, REFGUID key
,
2158 REFPROPVARIANT value
, BOOL
*result
)
2160 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2162 TRACE("%p, %s, %s, %p.\n", iface
, debugstr_attr(key
), debugstr_propvar(value
), result
);
2164 return attributes_CompareItem(&presentation_desc
->attributes
, key
, value
, result
);
2167 static HRESULT WINAPI
presentation_descriptor_Compare(IMFPresentationDescriptor
*iface
, IMFAttributes
*attrs
,
2168 MF_ATTRIBUTES_MATCH_TYPE type
, BOOL
*result
)
2170 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2172 TRACE("%p, %p, %d, %p.\n", iface
, attrs
, type
, result
);
2174 return attributes_Compare(&presentation_desc
->attributes
, attrs
, type
, result
);
2177 static HRESULT WINAPI
presentation_descriptor_GetUINT32(IMFPresentationDescriptor
*iface
, REFGUID key
, UINT32
*value
)
2179 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2181 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), value
);
2183 return attributes_GetUINT32(&presentation_desc
->attributes
, key
, value
);
2186 static HRESULT WINAPI
presentation_descriptor_GetUINT64(IMFPresentationDescriptor
*iface
, REFGUID key
, UINT64
*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_GetUINT64(&presentation_desc
->attributes
, key
, value
);
2195 static HRESULT WINAPI
presentation_descriptor_GetDouble(IMFPresentationDescriptor
*iface
, REFGUID key
, double *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_GetDouble(&presentation_desc
->attributes
, key
, value
);
2204 static HRESULT WINAPI
presentation_descriptor_GetGUID(IMFPresentationDescriptor
*iface
, REFGUID key
, GUID
*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_GetGUID(&presentation_desc
->attributes
, key
, value
);
2213 static HRESULT WINAPI
presentation_descriptor_GetStringLength(IMFPresentationDescriptor
*iface
, REFGUID key
,
2216 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2218 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), length
);
2220 return attributes_GetStringLength(&presentation_desc
->attributes
, key
, length
);
2223 static HRESULT WINAPI
presentation_descriptor_GetString(IMFPresentationDescriptor
*iface
, REFGUID key
, WCHAR
*value
,
2224 UINT32 size
, UINT32
*length
)
2226 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2228 TRACE("%p, %s, %p, %u, %p.\n", iface
, debugstr_attr(key
), value
, size
, length
);
2230 return attributes_GetString(&presentation_desc
->attributes
, key
, value
, size
, length
);
2233 static HRESULT WINAPI
presentation_descriptor_GetAllocatedString(IMFPresentationDescriptor
*iface
, REFGUID key
,
2234 WCHAR
**value
, UINT32
*length
)
2236 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2238 TRACE("%p, %s, %p, %p.\n", iface
, debugstr_attr(key
), value
, length
);
2240 return attributes_GetAllocatedString(&presentation_desc
->attributes
, key
, value
, length
);
2243 static HRESULT WINAPI
presentation_descriptor_GetBlobSize(IMFPresentationDescriptor
*iface
, REFGUID key
, UINT32
*size
)
2245 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2247 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), size
);
2249 return attributes_GetBlobSize(&presentation_desc
->attributes
, key
, size
);
2252 static HRESULT WINAPI
presentation_descriptor_GetBlob(IMFPresentationDescriptor
*iface
, REFGUID key
, UINT8
*buf
,
2253 UINT32 bufsize
, UINT32
*blobsize
)
2255 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2257 TRACE("%p, %s, %p, %u, %p.\n", iface
, debugstr_attr(key
), buf
, bufsize
, blobsize
);
2259 return attributes_GetBlob(&presentation_desc
->attributes
, key
, buf
, bufsize
, blobsize
);
2262 static HRESULT WINAPI
presentation_descriptor_GetAllocatedBlob(IMFPresentationDescriptor
*iface
, REFGUID key
,
2263 UINT8
**buf
, UINT32
*size
)
2265 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2267 TRACE("%p, %s, %p, %p.\n", iface
, debugstr_attr(key
), buf
, size
);
2269 return attributes_GetAllocatedBlob(&presentation_desc
->attributes
, key
, buf
, size
);
2272 static HRESULT WINAPI
presentation_descriptor_GetUnknown(IMFPresentationDescriptor
*iface
, REFGUID key
,
2273 REFIID riid
, void **out
)
2275 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2277 TRACE("%p, %s, %s, %p.\n", iface
, debugstr_attr(key
), debugstr_guid(riid
), out
);
2279 return attributes_GetUnknown(&presentation_desc
->attributes
, key
, riid
, out
);
2282 static HRESULT WINAPI
presentation_descriptor_SetItem(IMFPresentationDescriptor
*iface
, REFGUID key
,
2283 REFPROPVARIANT value
)
2285 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2287 TRACE("%p, %s, %s.\n", iface
, debugstr_attr(key
), debugstr_propvar(value
));
2289 return attributes_SetItem(&presentation_desc
->attributes
, key
, value
);
2292 static HRESULT WINAPI
presentation_descriptor_DeleteItem(IMFPresentationDescriptor
*iface
, REFGUID key
)
2294 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2296 TRACE("%p, %s.\n", iface
, debugstr_attr(key
));
2298 return attributes_DeleteItem(&presentation_desc
->attributes
, key
);
2301 static HRESULT WINAPI
presentation_descriptor_DeleteAllItems(IMFPresentationDescriptor
*iface
)
2303 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2305 TRACE("%p.\n", iface
);
2307 return attributes_DeleteAllItems(&presentation_desc
->attributes
);
2310 static HRESULT WINAPI
presentation_descriptor_SetUINT32(IMFPresentationDescriptor
*iface
, REFGUID key
, UINT32 value
)
2312 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2314 TRACE("%p, %s, %u.\n", iface
, debugstr_attr(key
), value
);
2316 return attributes_SetUINT32(&presentation_desc
->attributes
, key
, value
);
2319 static HRESULT WINAPI
presentation_descriptor_SetUINT64(IMFPresentationDescriptor
*iface
, REFGUID key
, UINT64 value
)
2321 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2323 TRACE("%p, %s, %s.\n", iface
, debugstr_attr(key
), wine_dbgstr_longlong(value
));
2325 return attributes_SetUINT64(&presentation_desc
->attributes
, key
, value
);
2328 static HRESULT WINAPI
presentation_descriptor_SetDouble(IMFPresentationDescriptor
*iface
, REFGUID key
, double value
)
2330 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2332 TRACE("%p, %s, %f.\n", iface
, debugstr_attr(key
), value
);
2334 return attributes_SetDouble(&presentation_desc
->attributes
, key
, value
);
2337 static HRESULT WINAPI
presentation_descriptor_SetGUID(IMFPresentationDescriptor
*iface
, REFGUID key
, REFGUID value
)
2339 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2341 TRACE("%p, %s, %s.\n", iface
, debugstr_attr(key
), debugstr_mf_guid(value
));
2343 return attributes_SetGUID(&presentation_desc
->attributes
, key
, value
);
2346 static HRESULT WINAPI
presentation_descriptor_SetString(IMFPresentationDescriptor
*iface
, REFGUID key
,
2349 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2351 TRACE("%p, %s, %s.\n", iface
, debugstr_attr(key
), debugstr_w(value
));
2353 return attributes_SetString(&presentation_desc
->attributes
, key
, value
);
2356 static HRESULT WINAPI
presentation_descriptor_SetBlob(IMFPresentationDescriptor
*iface
, REFGUID key
, const UINT8
*buf
,
2359 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2361 TRACE("%p, %s, %p, %u.\n", iface
, debugstr_attr(key
), buf
, size
);
2363 return attributes_SetBlob(&presentation_desc
->attributes
, key
, buf
, size
);
2366 static HRESULT WINAPI
presentation_descriptor_SetUnknown(IMFPresentationDescriptor
*iface
, REFGUID key
,
2369 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2371 TRACE("%p, %s, %p.\n", iface
, debugstr_attr(key
), unknown
);
2373 return attributes_SetUnknown(&presentation_desc
->attributes
, key
, unknown
);
2376 static HRESULT WINAPI
presentation_descriptor_LockStore(IMFPresentationDescriptor
*iface
)
2378 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2380 TRACE("%p.\n", iface
);
2382 return attributes_LockStore(&presentation_desc
->attributes
);
2385 static HRESULT WINAPI
presentation_descriptor_UnlockStore(IMFPresentationDescriptor
*iface
)
2387 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2389 TRACE("%p.\n", iface
);
2391 return attributes_UnlockStore(&presentation_desc
->attributes
);
2394 static HRESULT WINAPI
presentation_descriptor_GetCount(IMFPresentationDescriptor
*iface
, UINT32
*count
)
2396 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2398 TRACE("%p, %p.\n", iface
, count
);
2400 return attributes_GetCount(&presentation_desc
->attributes
, count
);
2403 static HRESULT WINAPI
presentation_descriptor_GetItemByIndex(IMFPresentationDescriptor
*iface
, UINT32 index
, GUID
*key
,
2406 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2408 TRACE("%p, %u, %p, %p.\n", iface
, index
, key
, value
);
2410 return attributes_GetItemByIndex(&presentation_desc
->attributes
, index
, key
, value
);
2413 static HRESULT WINAPI
presentation_descriptor_CopyAllItems(IMFPresentationDescriptor
*iface
, IMFAttributes
*dest
)
2415 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2417 TRACE("%p, %p.\n", iface
, dest
);
2419 return attributes_CopyAllItems(&presentation_desc
->attributes
, dest
);
2422 static HRESULT WINAPI
presentation_descriptor_GetStreamDescriptorCount(IMFPresentationDescriptor
*iface
, DWORD
*count
)
2424 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2426 TRACE("%p, %p.\n", iface
, count
);
2428 *count
= presentation_desc
->count
;
2433 static HRESULT WINAPI
presentation_descriptor_GetStreamDescriptorByIndex(IMFPresentationDescriptor
*iface
, DWORD index
,
2434 BOOL
*selected
, IMFStreamDescriptor
**descriptor
)
2436 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2438 TRACE("%p, %lu, %p, %p.\n", iface
, index
, selected
, descriptor
);
2440 if (index
>= presentation_desc
->count
)
2441 return E_INVALIDARG
;
2443 EnterCriticalSection(&presentation_desc
->attributes
.cs
);
2444 *selected
= presentation_desc
->descriptors
[index
].selected
;
2445 LeaveCriticalSection(&presentation_desc
->attributes
.cs
);
2447 *descriptor
= presentation_desc
->descriptors
[index
].descriptor
;
2448 IMFStreamDescriptor_AddRef(*descriptor
);
2453 static HRESULT WINAPI
presentation_descriptor_SelectStream(IMFPresentationDescriptor
*iface
, DWORD index
)
2455 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2457 TRACE("%p, %lu.\n", iface
, index
);
2459 if (index
>= presentation_desc
->count
)
2460 return E_INVALIDARG
;
2462 EnterCriticalSection(&presentation_desc
->attributes
.cs
);
2463 presentation_desc
->descriptors
[index
].selected
= TRUE
;
2464 LeaveCriticalSection(&presentation_desc
->attributes
.cs
);
2469 static HRESULT WINAPI
presentation_descriptor_DeselectStream(IMFPresentationDescriptor
*iface
, DWORD index
)
2471 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2473 TRACE("%p, %lu.\n", iface
, index
);
2475 if (index
>= presentation_desc
->count
)
2476 return E_INVALIDARG
;
2478 EnterCriticalSection(&presentation_desc
->attributes
.cs
);
2479 presentation_desc
->descriptors
[index
].selected
= FALSE
;
2480 LeaveCriticalSection(&presentation_desc
->attributes
.cs
);
2485 static HRESULT WINAPI
presentation_descriptor_Clone(IMFPresentationDescriptor
*iface
,
2486 IMFPresentationDescriptor
**descriptor
)
2488 struct presentation_desc
*presentation_desc
= impl_from_IMFPresentationDescriptor(iface
);
2489 struct presentation_desc
*object
;
2492 TRACE("%p, %p.\n", iface
, descriptor
);
2494 if (!(object
= calloc(1, sizeof(*object
))))
2495 return E_OUTOFMEMORY
;
2497 presentation_descriptor_init(object
, presentation_desc
->count
);
2499 EnterCriticalSection(&presentation_desc
->attributes
.cs
);
2501 for (i
= 0; i
< presentation_desc
->count
; ++i
)
2503 object
->descriptors
[i
] = presentation_desc
->descriptors
[i
];
2504 IMFStreamDescriptor_AddRef(object
->descriptors
[i
].descriptor
);
2507 attributes_CopyAllItems(&presentation_desc
->attributes
, (IMFAttributes
*)&object
->IMFPresentationDescriptor_iface
);
2509 LeaveCriticalSection(&presentation_desc
->attributes
.cs
);
2511 *descriptor
= &object
->IMFPresentationDescriptor_iface
;
2516 static const IMFPresentationDescriptorVtbl presentationdescriptorvtbl
=
2518 presentation_descriptor_QueryInterface
,
2519 presentation_descriptor_AddRef
,
2520 presentation_descriptor_Release
,
2521 presentation_descriptor_GetItem
,
2522 presentation_descriptor_GetItemType
,
2523 presentation_descriptor_CompareItem
,
2524 presentation_descriptor_Compare
,
2525 presentation_descriptor_GetUINT32
,
2526 presentation_descriptor_GetUINT64
,
2527 presentation_descriptor_GetDouble
,
2528 presentation_descriptor_GetGUID
,
2529 presentation_descriptor_GetStringLength
,
2530 presentation_descriptor_GetString
,
2531 presentation_descriptor_GetAllocatedString
,
2532 presentation_descriptor_GetBlobSize
,
2533 presentation_descriptor_GetBlob
,
2534 presentation_descriptor_GetAllocatedBlob
,
2535 presentation_descriptor_GetUnknown
,
2536 presentation_descriptor_SetItem
,
2537 presentation_descriptor_DeleteItem
,
2538 presentation_descriptor_DeleteAllItems
,
2539 presentation_descriptor_SetUINT32
,
2540 presentation_descriptor_SetUINT64
,
2541 presentation_descriptor_SetDouble
,
2542 presentation_descriptor_SetGUID
,
2543 presentation_descriptor_SetString
,
2544 presentation_descriptor_SetBlob
,
2545 presentation_descriptor_SetUnknown
,
2546 presentation_descriptor_LockStore
,
2547 presentation_descriptor_UnlockStore
,
2548 presentation_descriptor_GetCount
,
2549 presentation_descriptor_GetItemByIndex
,
2550 presentation_descriptor_CopyAllItems
,
2551 presentation_descriptor_GetStreamDescriptorCount
,
2552 presentation_descriptor_GetStreamDescriptorByIndex
,
2553 presentation_descriptor_SelectStream
,
2554 presentation_descriptor_DeselectStream
,
2555 presentation_descriptor_Clone
,
2558 static HRESULT
presentation_descriptor_init(struct presentation_desc
*object
, DWORD count
)
2562 if (FAILED(hr
= init_attributes_object(&object
->attributes
, 0)))
2564 object
->IMFPresentationDescriptor_iface
.lpVtbl
= &presentationdescriptorvtbl
;
2565 if (!(object
->descriptors
= calloc(count
, sizeof(*object
->descriptors
))))
2567 IMFPresentationDescriptor_Release(&object
->IMFPresentationDescriptor_iface
);
2568 return E_OUTOFMEMORY
;
2570 object
->count
= count
;
2575 /***********************************************************************
2576 * MFCreatePresentationDescriptor (mfplat.@)
2578 HRESULT WINAPI
MFCreatePresentationDescriptor(DWORD count
, IMFStreamDescriptor
**descriptors
,
2579 IMFPresentationDescriptor
**out
)
2581 struct presentation_desc
*object
;
2585 TRACE("%lu, %p, %p.\n", count
, descriptors
, out
);
2588 return E_INVALIDARG
;
2590 for (i
= 0; i
< count
; ++i
)
2592 if (!descriptors
[i
])
2593 return E_INVALIDARG
;
2596 if (!(object
= calloc(1, sizeof(*object
))))
2597 return E_OUTOFMEMORY
;
2599 if (FAILED(hr
= presentation_descriptor_init(object
, count
)))
2605 for (i
= 0; i
< count
; ++i
)
2607 object
->descriptors
[i
].descriptor
= descriptors
[i
];
2608 IMFStreamDescriptor_AddRef(object
->descriptors
[i
].descriptor
);
2611 *out
= &object
->IMFPresentationDescriptor_iface
;
2616 struct uncompressed_video_format
2618 const GUID
*subtype
;
2619 unsigned char bytes_per_pixel
;
2620 unsigned char alignment
;
2621 unsigned char bottom_up
;
2625 static int __cdecl
uncompressed_video_format_compare(const void *a
, const void *b
)
2627 const GUID
*guid
= a
;
2628 const struct uncompressed_video_format
*format
= b
;
2629 return memcmp(guid
, format
->subtype
, sizeof(*guid
));
2632 static const struct uncompressed_video_format video_formats
[] =
2634 { &MFVideoFormat_RGB24
, 4, 3, 1, 0 },
2635 { &MFVideoFormat_ARGB32
, 4, 3, 1, 0 },
2636 { &MFVideoFormat_RGB32
, 4, 3, 1, 0 },
2637 { &MFVideoFormat_RGB565
, 2, 3, 1, 0 },
2638 { &MFVideoFormat_RGB555
, 2, 3, 1, 0 },
2639 { &MFVideoFormat_A2R10G10B10
, 4, 3, 1, 0 },
2640 { &MFVideoFormat_RGB8
, 1, 3, 1, 0 },
2641 { &MFVideoFormat_L8
, 1, 3, 1, 0 },
2642 { &MFVideoFormat_AYUV
, 4, 3, 0, 1 },
2643 { &MFVideoFormat_I420
, 1, 0, 0, 1 },
2644 { &MFVideoFormat_IMC1
, 2, 3, 0, 1 },
2645 { &MFVideoFormat_IMC2
, 1, 0, 0, 1 },
2646 { &MFVideoFormat_IMC3
, 2, 3, 0, 1 },
2647 { &MFVideoFormat_IMC4
, 1, 0, 0, 1 },
2648 { &MFVideoFormat_IYUV
, 1, 0, 0, 1 },
2649 { &MFVideoFormat_NV12
, 1, 0, 0, 1 },
2650 { &MFVideoFormat_D16
, 2, 3, 0, 0 },
2651 { &MFVideoFormat_L16
, 2, 3, 0, 0 },
2652 { &MFVideoFormat_UYVY
, 2, 0, 0, 1 },
2653 { &MFVideoFormat_YUY2
, 2, 0, 0, 1 },
2654 { &MFVideoFormat_YV12
, 1, 0, 0, 1 },
2655 { &MFVideoFormat_A16B16G16R16F
, 8, 3, 1, 0 },
2658 static struct uncompressed_video_format
*mf_get_video_format(const GUID
*subtype
)
2660 return bsearch(subtype
, video_formats
, ARRAY_SIZE(video_formats
), sizeof(*video_formats
),
2661 uncompressed_video_format_compare
);
2664 static unsigned int mf_get_stride_for_format(const struct uncompressed_video_format
*format
, unsigned int width
)
2666 return (width
* format
->bytes_per_pixel
+ format
->alignment
) & ~format
->alignment
;
2669 unsigned int mf_format_get_stride(const GUID
*subtype
, unsigned int width
, BOOL
*is_yuv
)
2671 struct uncompressed_video_format
*format
= mf_get_video_format(subtype
);
2675 *is_yuv
= format
->yuv
;
2676 return mf_get_stride_for_format(format
, width
);
2682 /***********************************************************************
2683 * MFGetStrideForBitmapInfoHeader (mfplat.@)
2685 HRESULT WINAPI
MFGetStrideForBitmapInfoHeader(DWORD fourcc
, DWORD width
, LONG
*stride
)
2687 struct uncompressed_video_format
*format
;
2690 TRACE("%s, %lu, %p.\n", debugstr_fourcc(fourcc
), width
, stride
);
2692 memcpy(&subtype
, &MFVideoFormat_Base
, sizeof(subtype
));
2693 subtype
.Data1
= fourcc
;
2695 if (!(format
= mf_get_video_format(&subtype
)))
2698 return MF_E_INVALIDMEDIATYPE
;
2701 *stride
= mf_get_stride_for_format(format
, width
);
2702 if (format
->bottom_up
)
2708 /***********************************************************************
2709 * MFCalculateImageSize (mfplat.@)
2711 HRESULT WINAPI
MFCalculateImageSize(REFGUID subtype
, UINT32 width
, UINT32 height
, UINT32
*size
)
2713 struct uncompressed_video_format
*format
;
2714 unsigned int stride
;
2716 TRACE("%s, %u, %u, %p.\n", debugstr_mf_guid(subtype
), width
, height
, size
);
2718 if (!(format
= mf_get_video_format(subtype
)))
2721 return E_INVALIDARG
;
2724 switch (subtype
->Data1
)
2726 case MAKEFOURCC('I','M','C','2'):
2727 case MAKEFOURCC('I','M','C','4'):
2728 case MAKEFOURCC('N','V','1','2'):
2729 case MAKEFOURCC('Y','V','1','2'):
2730 case MAKEFOURCC('I','4','2','0'):
2731 case MAKEFOURCC('I','Y','U','V'):
2732 /* 2 x 2 block, interleaving UV for half the height */
2733 *size
= ((width
+ 1) & ~1) * height
* 3 / 2;
2738 *size
= width
* format
->bytes_per_pixel
* height
;
2741 stride
= mf_get_stride_for_format(format
, width
);
2742 *size
= stride
* height
;
2748 /***********************************************************************
2749 * MFGetPlaneSize (mfplat.@)
2751 HRESULT WINAPI
MFGetPlaneSize(DWORD fourcc
, DWORD width
, DWORD height
, DWORD
*size
)
2753 struct uncompressed_video_format
*format
;
2754 unsigned int stride
;
2757 TRACE("%s, %lu, %lu, %p.\n", debugstr_fourcc(fourcc
), width
, height
, size
);
2759 memcpy(&subtype
, &MFVideoFormat_Base
, sizeof(subtype
));
2760 subtype
.Data1
= fourcc
;
2762 if ((format
= mf_get_video_format(&subtype
)))
2763 stride
= mf_get_stride_for_format(format
, width
);
2769 case MAKEFOURCC('I','M','C','2'):
2770 case MAKEFOURCC('I','M','C','4'):
2771 case MAKEFOURCC('N','V','1','2'):
2772 case MAKEFOURCC('Y','V','1','2'):
2773 case MAKEFOURCC('I','4','2','0'):
2774 case MAKEFOURCC('I','Y','U','V'):
2775 *size
= stride
* height
* 3 / 2;
2778 *size
= stride
* height
;
2784 /***********************************************************************
2785 * MFCompareFullToPartialMediaType (mfplat.@)
2787 BOOL WINAPI
MFCompareFullToPartialMediaType(IMFMediaType
*full_type
, IMFMediaType
*partial_type
)
2792 TRACE("%p, %p.\n", full_type
, partial_type
);
2794 if (FAILED(IMFMediaType_GetMajorType(partial_type
, &major
)))
2797 if (FAILED(IMFMediaType_Compare(partial_type
, (IMFAttributes
*)full_type
, MF_ATTRIBUTES_MATCH_OUR_ITEMS
, &result
)))
2803 /***********************************************************************
2804 * MFWrapMediaType (mfplat.@)
2806 HRESULT WINAPI
MFWrapMediaType(IMFMediaType
*original
, REFGUID major
, REFGUID subtype
, IMFMediaType
**ret
)
2808 IMFMediaType
*mediatype
;
2813 TRACE("%p, %s, %s, %p.\n", original
, debugstr_guid(major
), debugstr_guid(subtype
), ret
);
2815 if (FAILED(hr
= MFGetAttributesAsBlobSize((IMFAttributes
*)original
, &size
)))
2818 if (!(buffer
= malloc(size
)))
2819 return E_OUTOFMEMORY
;
2821 if (FAILED(hr
= MFGetAttributesAsBlob((IMFAttributes
*)original
, buffer
, size
)))
2824 if (FAILED(hr
= MFCreateMediaType(&mediatype
)))
2827 if (FAILED(hr
= IMFMediaType_SetGUID(mediatype
, &MF_MT_MAJOR_TYPE
, major
)))
2830 if (FAILED(hr
= IMFMediaType_SetGUID(mediatype
, &MF_MT_SUBTYPE
, subtype
)))
2833 if (FAILED(hr
= IMFMediaType_SetBlob(mediatype
, &MF_MT_WRAPPED_TYPE
, buffer
, size
)))
2844 /***********************************************************************
2845 * MFUnwrapMediaType (mfplat.@)
2847 HRESULT WINAPI
MFUnwrapMediaType(IMFMediaType
*wrapper
, IMFMediaType
**ret
)
2849 IMFMediaType
*mediatype
;
2854 TRACE("%p, %p.\n", wrapper
, ret
);
2856 if (FAILED(hr
= MFCreateMediaType(&mediatype
)))
2859 if (FAILED(hr
= IMFMediaType_GetAllocatedBlob(wrapper
, &MF_MT_WRAPPED_TYPE
, &buffer
, &size
)))
2861 IMFMediaType_Release(mediatype
);
2865 hr
= MFInitAttributesFromBlob((IMFAttributes
*)mediatype
, buffer
, size
);
2866 CoTaskMemFree(buffer
);
2875 /***********************************************************************
2876 * MFCreateWaveFormatExFromMFMediaType (mfplat.@)
2878 HRESULT WINAPI
MFCreateWaveFormatExFromMFMediaType(IMFMediaType
*mediatype
, WAVEFORMATEX
**ret_format
,
2879 UINT32
*size
, UINT32 flags
)
2881 WAVEFORMATEXTENSIBLE
*format_ext
= NULL
;
2882 WAVEFORMATEX
*format
;
2883 GUID major
, subtype
;
2887 TRACE("%p, %p, %p, %#x.\n", mediatype
, ret_format
, size
, flags
);
2889 if (FAILED(hr
= IMFMediaType_GetGUID(mediatype
, &MF_MT_MAJOR_TYPE
, &major
)))
2892 if (FAILED(hr
= IMFMediaType_GetGUID(mediatype
, &MF_MT_SUBTYPE
, &subtype
)))
2895 if (!IsEqualGUID(&major
, &MFMediaType_Audio
))
2896 return E_INVALIDARG
;
2898 if (!IsEqualGUID(&subtype
, &MFAudioFormat_PCM
) && !IsEqualGUID(&subtype
, &MFAudioFormat_Float
))
2900 FIXME("Unsupported audio format %s.\n", debugstr_guid(&subtype
));
2904 /* FIXME: probably WAVE_FORMAT_MPEG/WAVE_FORMAT_MPEGLAYER3 should be handled separately. */
2905 if (flags
== MFWaveFormatExConvertFlag_ForceExtensible
)
2907 format_ext
= CoTaskMemAlloc(sizeof(*format_ext
));
2908 *size
= sizeof(*format_ext
);
2909 format
= (WAVEFORMATEX
*)format_ext
;
2913 format
= CoTaskMemAlloc(sizeof(*format
));
2914 *size
= sizeof(*format
);
2918 return E_OUTOFMEMORY
;
2920 memset(format
, 0, *size
);
2923 format
->wFormatTag
= WAVE_FORMAT_EXTENSIBLE
;
2924 else if (IsEqualGUID(&subtype
, &MFAudioFormat_Float
))
2925 format
->wFormatTag
= WAVE_FORMAT_IEEE_FLOAT
;
2927 format
->wFormatTag
= WAVE_FORMAT_PCM
;
2929 if (SUCCEEDED(IMFMediaType_GetUINT32(mediatype
, &MF_MT_AUDIO_NUM_CHANNELS
, &value
)))
2930 format
->nChannels
= value
;
2931 if (SUCCEEDED(IMFMediaType_GetUINT32(mediatype
, &MF_MT_AUDIO_SAMPLES_PER_SECOND
, &value
)))
2932 format
->nSamplesPerSec
= value
;
2933 if (SUCCEEDED(IMFMediaType_GetUINT32(mediatype
, &MF_MT_AUDIO_AVG_BYTES_PER_SECOND
, &value
)))
2934 format
->nAvgBytesPerSec
= value
;
2935 if (SUCCEEDED(IMFMediaType_GetUINT32(mediatype
, &MF_MT_AUDIO_BLOCK_ALIGNMENT
, &value
)))
2936 format
->nBlockAlign
= value
;
2937 if (SUCCEEDED(IMFMediaType_GetUINT32(mediatype
, &MF_MT_AUDIO_BITS_PER_SAMPLE
, &value
)))
2938 format
->wBitsPerSample
= value
;
2941 format
->cbSize
= sizeof(*format_ext
) - sizeof(*format
);
2943 if (SUCCEEDED(IMFMediaType_GetUINT32(mediatype
, &MF_MT_AUDIO_VALID_BITS_PER_SAMPLE
, &value
)))
2944 format_ext
->Samples
.wSamplesPerBlock
= value
;
2946 if (SUCCEEDED(IMFMediaType_GetUINT32(mediatype
, &MF_MT_AUDIO_CHANNEL_MASK
, &value
)))
2947 format_ext
->dwChannelMask
= value
;
2948 memcpy(&format_ext
->SubFormat
, &KSDATAFORMAT_SUBTYPE_PCM
, sizeof(format_ext
->SubFormat
));
2951 *ret_format
= format
;
2956 static void mediatype_set_uint32(IMFMediaType
*mediatype
, const GUID
*attr
, unsigned int value
, HRESULT
*hr
)
2959 *hr
= IMFMediaType_SetUINT32(mediatype
, attr
, value
);
2962 static void mediatype_set_uint64(IMFMediaType
*mediatype
, const GUID
*attr
, unsigned int high
, unsigned int low
, HRESULT
*hr
)
2965 *hr
= IMFMediaType_SetUINT64(mediatype
, attr
, (UINT64
)high
<< 32 | low
);
2968 static void mediatype_set_guid(IMFMediaType
*mediatype
, const GUID
*attr
, const GUID
*value
, HRESULT
*hr
)
2971 *hr
= IMFMediaType_SetGUID(mediatype
, attr
, value
);
2974 static void mediatype_set_blob(IMFMediaType
*mediatype
, const GUID
*attr
, const UINT8
*data
,
2975 unsigned int size
, HRESULT
*hr
)
2978 *hr
= IMFMediaType_SetBlob(mediatype
, attr
, data
, size
);
2981 /***********************************************************************
2982 * MFInitMediaTypeFromWaveFormatEx (mfplat.@)
2984 HRESULT WINAPI
MFInitMediaTypeFromWaveFormatEx(IMFMediaType
*mediatype
, const WAVEFORMATEX
*format
, UINT32 size
)
2986 const WAVEFORMATEXTENSIBLE
*wfex
= (const WAVEFORMATEXTENSIBLE
*)format
;
2990 TRACE("%p, %p, %u.\n", mediatype
, format
, size
);
2992 if (!mediatype
|| !format
)
2995 if (format
->cbSize
+ sizeof(*format
) > size
)
2996 return E_INVALIDARG
;
2998 hr
= IMFMediaType_DeleteAllItems(mediatype
);
3000 mediatype_set_guid(mediatype
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Audio
, &hr
);
3002 if (format
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
)
3004 memcpy(&subtype
, &wfex
->SubFormat
, sizeof(subtype
));
3006 if (wfex
->dwChannelMask
)
3007 mediatype_set_uint32(mediatype
, &MF_MT_AUDIO_CHANNEL_MASK
, wfex
->dwChannelMask
, &hr
);
3009 if (format
->wBitsPerSample
&& wfex
->Samples
.wValidBitsPerSample
)
3010 mediatype_set_uint32(mediatype
, &MF_MT_AUDIO_VALID_BITS_PER_SAMPLE
, wfex
->Samples
.wValidBitsPerSample
, &hr
);
3014 memcpy(&subtype
, &MFAudioFormat_Base
, sizeof(subtype
));
3015 subtype
.Data1
= format
->wFormatTag
;
3017 mediatype_set_uint32(mediatype
, &MF_MT_AUDIO_PREFER_WAVEFORMATEX
, 1, &hr
);
3019 mediatype_set_guid(mediatype
, &MF_MT_SUBTYPE
, &subtype
, &hr
);
3021 if (format
->nChannels
)
3022 mediatype_set_uint32(mediatype
, &MF_MT_AUDIO_NUM_CHANNELS
, format
->nChannels
, &hr
);
3024 if (format
->nSamplesPerSec
)
3025 mediatype_set_uint32(mediatype
, &MF_MT_AUDIO_SAMPLES_PER_SECOND
, format
->nSamplesPerSec
, &hr
);
3027 if (format
->nAvgBytesPerSec
)
3028 mediatype_set_uint32(mediatype
, &MF_MT_AUDIO_AVG_BYTES_PER_SECOND
, format
->nAvgBytesPerSec
, &hr
);
3030 if (format
->nBlockAlign
)
3031 mediatype_set_uint32(mediatype
, &MF_MT_AUDIO_BLOCK_ALIGNMENT
, format
->nBlockAlign
, &hr
);
3033 if (format
->wBitsPerSample
)
3034 mediatype_set_uint32(mediatype
, &MF_MT_AUDIO_BITS_PER_SAMPLE
, format
->wBitsPerSample
, &hr
);
3036 if (IsEqualGUID(&subtype
, &MFAudioFormat_PCM
) ||
3037 IsEqualGUID(&subtype
, &MFAudioFormat_Float
))
3039 mediatype_set_uint32(mediatype
, &MF_MT_ALL_SAMPLES_INDEPENDENT
, 1, &hr
);
3042 if (format
->cbSize
&& format
->wFormatTag
!= WAVE_FORMAT_EXTENSIBLE
)
3043 mediatype_set_blob(mediatype
, &MF_MT_USER_DATA
, (const UINT8
*)(format
+ 1), format
->cbSize
, &hr
);
3048 /***********************************************************************
3049 * MFCreateVideoMediaTypeFromSubtype (mfplat.@)
3051 HRESULT WINAPI
MFCreateVideoMediaTypeFromSubtype(const GUID
*subtype
, IMFVideoMediaType
**media_type
)
3053 struct media_type
*object
;
3056 TRACE("%s, %p.\n", debugstr_guid(subtype
), media_type
);
3059 return E_INVALIDARG
;
3061 if (FAILED(hr
= create_media_type(&object
)))
3064 IMFMediaType_SetGUID(&object
->IMFMediaType_iface
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
3065 IMFMediaType_SetGUID(&object
->IMFMediaType_iface
, &MF_MT_SUBTYPE
, subtype
);
3067 *media_type
= &object
->IMFVideoMediaType_iface
;
3072 /***********************************************************************
3073 * MFCreateAudioMediaType (mfplat.@)
3075 HRESULT WINAPI
MFCreateAudioMediaType(const WAVEFORMATEX
*format
, IMFAudioMediaType
**media_type
)
3077 struct media_type
*object
;
3080 TRACE("%p, %p.\n", format
, media_type
);
3083 return E_INVALIDARG
;
3085 if (FAILED(hr
= create_media_type(&object
)))
3088 if (FAILED(hr
= MFInitMediaTypeFromWaveFormatEx(&object
->IMFMediaType_iface
, format
, sizeof(*format
) + format
->cbSize
)))
3090 IMFMediaType_Release(&object
->IMFMediaType_iface
);
3094 *media_type
= &object
->IMFAudioMediaType_iface
;
3099 static void media_type_get_ratio(IMFMediaType
*media_type
, const GUID
*attr
, DWORD
*numerator
,
3104 if (SUCCEEDED(IMFMediaType_GetUINT64(media_type
, attr
, &value
)))
3106 *numerator
= value
>> 32;
3107 *denominator
= value
;
3111 /***********************************************************************
3112 * MFCreateMFVideoFormatFromMFMediaType (mfplat.@)
3114 HRESULT WINAPI
MFCreateMFVideoFormatFromMFMediaType(IMFMediaType
*media_type
, MFVIDEOFORMAT
**video_format
, UINT32
*size
)
3116 UINT32 flags
, palette_size
= 0, value
;
3117 MFVIDEOFORMAT
*format
;
3121 TRACE("%p, %p, %p.\n", media_type
, video_format
, size
);
3123 *size
= sizeof(*format
);
3125 if (SUCCEEDED(IMFMediaType_GetBlobSize(media_type
, &MF_MT_PALETTE
, &palette_size
)))
3126 *size
+= palette_size
;
3128 if (!(format
= CoTaskMemAlloc(*size
)))
3129 return E_OUTOFMEMORY
;
3131 *video_format
= format
;
3133 memset(format
, 0, sizeof(*format
));
3134 format
->dwSize
= *size
;
3136 if (SUCCEEDED(IMFMediaType_GetGUID(media_type
, &MF_MT_SUBTYPE
, &guid
)))
3138 memcpy(&format
->guidFormat
, &guid
, sizeof(guid
));
3139 format
->surfaceInfo
.Format
= guid
.Data1
;
3142 media_type_get_ratio(media_type
, &MF_MT_FRAME_SIZE
, &format
->videoInfo
.dwWidth
, &format
->videoInfo
.dwHeight
);
3143 media_type_get_ratio(media_type
, &MF_MT_PIXEL_ASPECT_RATIO
, &format
->videoInfo
.PixelAspectRatio
.Numerator
,
3144 &format
->videoInfo
.PixelAspectRatio
.Denominator
);
3145 media_type_get_ratio(media_type
, &MF_MT_FRAME_RATE
, &format
->videoInfo
.FramesPerSecond
.Numerator
,
3146 &format
->videoInfo
.FramesPerSecond
.Denominator
);
3148 IMFMediaType_GetUINT32(media_type
, &MF_MT_VIDEO_CHROMA_SITING
, &format
->videoInfo
.SourceChromaSubsampling
);
3149 IMFMediaType_GetUINT32(media_type
, &MF_MT_INTERLACE_MODE
, &format
->videoInfo
.InterlaceMode
);
3150 IMFMediaType_GetUINT32(media_type
, &MF_MT_TRANSFER_FUNCTION
, &format
->videoInfo
.TransferFunction
);
3151 IMFMediaType_GetUINT32(media_type
, &MF_MT_VIDEO_PRIMARIES
, &format
->videoInfo
.ColorPrimaries
);
3152 IMFMediaType_GetUINT32(media_type
, &MF_MT_YUV_MATRIX
, &format
->videoInfo
.TransferMatrix
);
3153 IMFMediaType_GetUINT32(media_type
, &MF_MT_VIDEO_LIGHTING
, &format
->videoInfo
.SourceLighting
);
3154 IMFMediaType_GetUINT32(media_type
, &MF_MT_VIDEO_NOMINAL_RANGE
, &format
->videoInfo
.NominalRange
);
3155 IMFMediaType_GetBlob(media_type
, &MF_MT_GEOMETRIC_APERTURE
, (UINT8
*)&format
->videoInfo
.GeometricAperture
,
3156 sizeof(format
->videoInfo
.GeometricAperture
), NULL
);
3157 IMFMediaType_GetBlob(media_type
, &MF_MT_MINIMUM_DISPLAY_APERTURE
, (UINT8
*)&format
->videoInfo
.MinimumDisplayAperture
,
3158 sizeof(format
->videoInfo
.MinimumDisplayAperture
), NULL
);
3161 if (SUCCEEDED(IMFMediaType_GetUINT32(media_type
, &MF_MT_PAD_CONTROL_FLAGS
, &flags
)))
3162 format
->videoInfo
.VideoFlags
|= flags
;
3163 if (SUCCEEDED(IMFMediaType_GetUINT32(media_type
, &MF_MT_SOURCE_CONTENT_HINT
, &flags
)))
3164 format
->videoInfo
.VideoFlags
|= flags
;
3165 if (SUCCEEDED(IMFMediaType_GetUINT32(media_type
, &MF_MT_DRM_FLAGS
, &flags
)))
3166 format
->videoInfo
.VideoFlags
|= flags
;
3167 if (SUCCEEDED(IMFMediaType_GetUINT32(media_type
, &MF_MT_PAN_SCAN_ENABLED
, &flags
)) && !!flags
)
3169 format
->videoInfo
.VideoFlags
|= MFVideoFlag_PanScanEnabled
;
3170 IMFMediaType_GetBlob(media_type
, &MF_MT_PAN_SCAN_APERTURE
, (UINT8
*)&format
->videoInfo
.PanScanAperture
,
3171 sizeof(format
->videoInfo
.PanScanAperture
), NULL
);
3173 if (SUCCEEDED(IMFMediaType_GetUINT32(media_type
, &MF_MT_DEFAULT_STRIDE
, (UINT32
*)&stride
)) && stride
< 0)
3174 format
->videoInfo
.VideoFlags
|= MFVideoFlag_BottomUpLinearRep
;
3176 if (SUCCEEDED(IMFMediaType_GetUINT32(media_type
, &MF_MT_AVG_BITRATE
, &value
)))
3177 format
->compressedInfo
.AvgBitrate
= value
;
3178 if (SUCCEEDED(IMFMediaType_GetUINT32(media_type
, &MF_MT_AVG_BIT_ERROR_RATE
, &value
)))
3179 format
->compressedInfo
.AvgBitErrorRate
= value
;
3180 if (SUCCEEDED(IMFMediaType_GetUINT32(media_type
, &MF_MT_MAX_KEYFRAME_SPACING
, &value
)))
3181 format
->compressedInfo
.MaxKeyFrameSpacing
= value
;
3186 format
->surfaceInfo
.PaletteEntries
= palette_size
/ sizeof(*format
->surfaceInfo
.Palette
);
3187 IMFMediaType_GetBlob(media_type
, &MF_MT_PALETTE
, (UINT8
*)format
->surfaceInfo
.Palette
, palette_size
, NULL
);
3193 /***********************************************************************
3194 * MFConvertColorInfoToDXVA (mfplat.@)
3196 HRESULT WINAPI
MFConvertColorInfoToDXVA(DWORD
*dxva_info
, const MFVIDEOFORMAT
*format
)
3200 UINT SampleFormat
: 8;
3201 UINT VideoChromaSubsampling
: 4;
3202 UINT NominalRange
: 3;
3203 UINT VideoTransferMatrix
: 3;
3204 UINT VideoLighting
: 4;
3205 UINT VideoPrimaries
: 5;
3206 UINT VideoTransferFunction
: 5;
3207 } *dxva_format
= (void *)dxva_info
;
3209 TRACE("%p, %p.\n", dxva_info
, format
);
3211 if (format
->videoInfo
.InterlaceMode
== MFVideoInterlace_MixedInterlaceOrProgressive
)
3212 dxva_format
->SampleFormat
= DXVA2_SampleFieldInterleavedEvenFirst
;
3214 dxva_format
->SampleFormat
= format
->videoInfo
.InterlaceMode
;
3216 dxva_format
->VideoChromaSubsampling
= format
->videoInfo
.SourceChromaSubsampling
;
3217 dxva_format
->NominalRange
= format
->videoInfo
.NominalRange
;
3218 dxva_format
->VideoTransferMatrix
= format
->videoInfo
.TransferMatrix
;
3219 dxva_format
->VideoLighting
= format
->videoInfo
.SourceLighting
;
3220 dxva_format
->VideoPrimaries
= format
->videoInfo
.ColorPrimaries
;
3221 dxva_format
->VideoTransferFunction
= format
->videoInfo
.TransferFunction
;
3232 static int __cdecl
frame_rate_compare(const void *a
, const void *b
)
3234 const UINT64
*key
= a
;
3235 const struct frame_rate
*known_rate
= b
;
3236 return *key
== known_rate
->key
? 0 : ( *key
< known_rate
->key
? 1 : -1 );
3239 /***********************************************************************
3240 * MFFrameRateToAverageTimePerFrame (mfplat.@)
3242 HRESULT WINAPI
MFFrameRateToAverageTimePerFrame(UINT32 numerator
, UINT32 denominator
, UINT64
*avgframetime
)
3244 static const struct frame_rate known_rates
[] =
3246 #define KNOWN_RATE(n,d,ft) { ((UINT64)n << 32) | d, ft }
3247 KNOWN_RATE(60000, 1001, 166833),
3248 KNOWN_RATE(30000, 1001, 333667),
3249 KNOWN_RATE(24000, 1001, 417188),
3250 KNOWN_RATE(60, 1, 166667),
3251 KNOWN_RATE(50, 1, 200000),
3252 KNOWN_RATE(30, 1, 333333),
3253 KNOWN_RATE(25, 1, 400000),
3254 KNOWN_RATE(24, 1, 416667),
3257 UINT64 rate
= ((UINT64
)numerator
<< 32) | denominator
;
3258 const struct frame_rate
*entry
;
3260 TRACE("%u, %u, %p.\n", numerator
, denominator
, avgframetime
);
3262 if ((entry
= bsearch(&rate
, known_rates
, ARRAY_SIZE(known_rates
), sizeof(*known_rates
),
3263 frame_rate_compare
)))
3265 *avgframetime
= entry
->value
;
3268 *avgframetime
= numerator
? denominator
* (UINT64
)10000000 / numerator
: 0;
3273 static unsigned int get_gcd(unsigned int a
, unsigned int b
)
3287 /***********************************************************************
3288 * MFAverageTimePerFrameToFrameRate (mfplat.@)
3290 HRESULT WINAPI
MFAverageTimePerFrameToFrameRate(UINT64 avgtime
, UINT32
*numerator
, UINT32
*denominator
)
3292 static const struct frame_rate known_rates
[] =
3294 #define KNOWN_RATE(ft,n,d) { ft, ((UINT64)n << 32) | d }
3295 KNOWN_RATE(417188, 24000, 1001),
3296 KNOWN_RATE(416667, 24, 1),
3297 KNOWN_RATE(400000, 25, 1),
3298 KNOWN_RATE(333667, 30000, 1001),
3299 KNOWN_RATE(333333, 30, 1),
3300 KNOWN_RATE(200000, 50, 1),
3301 KNOWN_RATE(166833, 60000, 1001),
3302 KNOWN_RATE(166667, 60, 1),
3305 const struct frame_rate
*entry
;
3308 TRACE("%s, %p, %p.\n", wine_dbgstr_longlong(avgtime
), numerator
, denominator
);
3310 if ((entry
= bsearch(&avgtime
, known_rates
, ARRAY_SIZE(known_rates
), sizeof(*known_rates
),
3311 frame_rate_compare
)))
3313 *numerator
= entry
->value
>> 32;
3314 *denominator
= entry
->value
;
3318 if (avgtime
> 100000000) avgtime
= 100000000;
3319 gcd
= get_gcd(10000000, avgtime
);
3320 *numerator
= 10000000 / gcd
;
3321 *denominator
= avgtime
/ gcd
;
3325 *numerator
= *denominator
= 0;
3331 /***********************************************************************
3332 * MFMapDXGIFormatToDX9Format (mfplat.@)
3334 DWORD WINAPI
MFMapDXGIFormatToDX9Format(DXGI_FORMAT dxgi_format
)
3336 switch (dxgi_format
)
3338 case DXGI_FORMAT_R32G32B32A32_FLOAT
:
3339 return D3DFMT_A32B32G32R32F
;
3340 case DXGI_FORMAT_R16G16B16A16_FLOAT
:
3341 return D3DFMT_A16B16G16R16F
;
3342 case DXGI_FORMAT_R16G16B16A16_UNORM
:
3343 return D3DFMT_A16B16G16R16
;
3344 case DXGI_FORMAT_R16G16B16A16_SNORM
:
3345 return D3DFMT_Q16W16V16U16
;
3346 case DXGI_FORMAT_R32G32_FLOAT
:
3347 return D3DFMT_G32R32F
;
3348 case DXGI_FORMAT_R10G10B10A2_UNORM
:
3349 return D3DFMT_A2B10G10R10
;
3350 case DXGI_FORMAT_R8G8B8A8_SNORM
:
3351 return D3DFMT_Q8W8V8U8
;
3352 case DXGI_FORMAT_R16G16_FLOAT
:
3353 return D3DFMT_G16R16F
;
3354 case DXGI_FORMAT_R16G16_UNORM
:
3355 return D3DFMT_G16R16
;
3356 case DXGI_FORMAT_R16G16_SNORM
:
3357 return D3DFMT_V16U16
;
3358 case DXGI_FORMAT_D32_FLOAT
:
3359 return D3DFMT_D32F_LOCKABLE
;
3360 case DXGI_FORMAT_R32_FLOAT
:
3362 case DXGI_FORMAT_D24_UNORM_S8_UINT
:
3363 return D3DFMT_D24S8
;
3364 case DXGI_FORMAT_R8G8_SNORM
:
3366 case DXGI_FORMAT_R16_FLOAT
:
3368 case DXGI_FORMAT_D16_UNORM
:
3369 return D3DFMT_D16_LOCKABLE
;
3370 case DXGI_FORMAT_R16_UNORM
:
3372 case DXGI_FORMAT_R8_UNORM
:
3374 case DXGI_FORMAT_A8_UNORM
:
3376 case DXGI_FORMAT_BC1_UNORM
:
3377 case DXGI_FORMAT_BC1_UNORM_SRGB
:
3379 case DXGI_FORMAT_BC2_UNORM
:
3380 case DXGI_FORMAT_BC2_UNORM_SRGB
:
3382 case DXGI_FORMAT_BC3_UNORM
:
3383 case DXGI_FORMAT_BC3_UNORM_SRGB
:
3385 case DXGI_FORMAT_R8G8B8A8_UNORM
:
3386 return D3DFMT_A8B8G8R8
;
3387 case DXGI_FORMAT_B8G8R8A8_UNORM
:
3388 case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB
:
3389 case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
:
3390 return D3DFMT_A8R8G8B8
;
3391 case DXGI_FORMAT_B8G8R8X8_UNORM
:
3392 case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB
:
3393 return D3DFMT_X8R8G8B8
;
3394 case DXGI_FORMAT_AYUV
:
3395 return MAKEFOURCC('A','Y','U','V');
3396 case DXGI_FORMAT_Y410
:
3397 return MAKEFOURCC('Y','4','1','0');
3398 case DXGI_FORMAT_Y416
:
3399 return MAKEFOURCC('Y','4','1','6');
3400 case DXGI_FORMAT_NV12
:
3401 return MAKEFOURCC('N','V','1','2');
3402 case DXGI_FORMAT_P010
:
3403 return MAKEFOURCC('P','0','1','0');
3404 case DXGI_FORMAT_P016
:
3405 return MAKEFOURCC('P','0','1','6');
3406 case DXGI_FORMAT_420_OPAQUE
:
3407 return MAKEFOURCC('4','2','0','O');
3408 case DXGI_FORMAT_YUY2
:
3410 case DXGI_FORMAT_Y210
:
3411 return MAKEFOURCC('Y','2','1','0');
3412 case DXGI_FORMAT_Y216
:
3413 return MAKEFOURCC('Y','2','1','6');
3414 case DXGI_FORMAT_NV11
:
3415 return MAKEFOURCC('N','V','1','1');
3416 case DXGI_FORMAT_AI44
:
3417 return MAKEFOURCC('A','I','4','4');
3418 case DXGI_FORMAT_IA44
:
3419 return MAKEFOURCC('I','A','4','4');
3420 case DXGI_FORMAT_P8
:
3422 case DXGI_FORMAT_A8P8
:
3429 /***********************************************************************
3430 * MFMapDX9FormatToDXGIFormat (mfplat.@)
3432 DXGI_FORMAT WINAPI
MFMapDX9FormatToDXGIFormat(DWORD format
)
3436 case D3DFMT_A32B32G32R32F
:
3437 return DXGI_FORMAT_R32G32B32A32_FLOAT
;
3438 case D3DFMT_A16B16G16R16F
:
3439 return DXGI_FORMAT_R16G16B16A16_FLOAT
;
3440 case D3DFMT_A16B16G16R16
:
3441 return DXGI_FORMAT_R16G16B16A16_UNORM
;
3442 case D3DFMT_Q16W16V16U16
:
3443 return DXGI_FORMAT_R16G16B16A16_SNORM
;
3444 case D3DFMT_G32R32F
:
3445 return DXGI_FORMAT_R32G32_FLOAT
;
3446 case D3DFMT_A2B10G10R10
:
3447 return DXGI_FORMAT_R10G10B10A2_UNORM
;
3448 case D3DFMT_Q8W8V8U8
:
3449 return DXGI_FORMAT_R8G8B8A8_SNORM
;
3450 case D3DFMT_G16R16F
:
3451 return DXGI_FORMAT_R16G16_FLOAT
;
3453 return DXGI_FORMAT_R16G16_UNORM
;
3455 return DXGI_FORMAT_R16G16_SNORM
;
3456 case D3DFMT_D32F_LOCKABLE
:
3457 return DXGI_FORMAT_D32_FLOAT
;
3459 return DXGI_FORMAT_R32_FLOAT
;
3461 return DXGI_FORMAT_D24_UNORM_S8_UINT
;
3463 return DXGI_FORMAT_R8G8_SNORM
;
3465 return DXGI_FORMAT_R16_FLOAT
;
3467 return DXGI_FORMAT_R16_UNORM
;
3469 return DXGI_FORMAT_R8_UNORM
;
3471 return DXGI_FORMAT_A8_UNORM
;
3473 return DXGI_FORMAT_BC1_UNORM
;
3475 return DXGI_FORMAT_BC2_UNORM
;
3477 return DXGI_FORMAT_BC3_UNORM
;
3478 case D3DFMT_A8R8G8B8
:
3479 return DXGI_FORMAT_B8G8R8A8_UNORM
;
3480 case D3DFMT_X8R8G8B8
:
3481 return DXGI_FORMAT_B8G8R8X8_UNORM
;
3482 case MAKEFOURCC('A','Y','U','V'):
3483 return DXGI_FORMAT_AYUV
;
3484 case MAKEFOURCC('Y','4','1','0'):
3485 return DXGI_FORMAT_Y410
;
3486 case MAKEFOURCC('Y','4','1','6'):
3487 return DXGI_FORMAT_Y416
;
3488 case MAKEFOURCC('N','V','1','2'):
3489 return DXGI_FORMAT_NV12
;
3490 case MAKEFOURCC('P','0','1','0'):
3491 return DXGI_FORMAT_P010
;
3492 case MAKEFOURCC('P','0','1','6'):
3493 return DXGI_FORMAT_P016
;
3494 case MAKEFOURCC('4','2','0','O'):
3495 return DXGI_FORMAT_420_OPAQUE
;
3497 return DXGI_FORMAT_YUY2
;
3498 case MAKEFOURCC('Y','2','1','0'):
3499 return DXGI_FORMAT_Y210
;
3500 case MAKEFOURCC('Y','2','1','6'):
3501 return DXGI_FORMAT_Y216
;
3502 case MAKEFOURCC('N','V','1','1'):
3503 return DXGI_FORMAT_NV11
;
3504 case MAKEFOURCC('A','I','4','4'):
3505 return DXGI_FORMAT_AI44
;
3506 case MAKEFOURCC('I','A','4','4'):
3507 return DXGI_FORMAT_IA44
;
3509 return DXGI_FORMAT_P8
;
3511 return DXGI_FORMAT_A8P8
;
3513 return DXGI_FORMAT_UNKNOWN
;
3517 /***********************************************************************
3518 * MFInitVideoFormat_RGB (mfplat.@)
3520 HRESULT WINAPI
MFInitVideoFormat_RGB(MFVIDEOFORMAT
*format
, DWORD width
, DWORD height
, DWORD d3dformat
)
3522 unsigned int transfer_function
;
3524 TRACE("%p, %lu, %lu, %#lx.\n", format
, width
, height
, d3dformat
);
3527 return E_INVALIDARG
;
3529 if (!d3dformat
) d3dformat
= D3DFMT_X8R8G8B8
;
3533 case D3DFMT_X8R8G8B8
:
3535 case D3DFMT_A8R8G8B8
:
3537 case D3DFMT_X1R5G5B5
:
3538 case D3DFMT_A2B10G10R10
:
3540 transfer_function
= MFVideoTransFunc_sRGB
;
3543 transfer_function
= MFVideoTransFunc_10
;
3546 memset(format
, 0, sizeof(*format
));
3547 format
->dwSize
= sizeof(*format
);
3548 format
->videoInfo
.dwWidth
= width
;
3549 format
->videoInfo
.dwHeight
= height
;
3550 format
->videoInfo
.PixelAspectRatio
.Numerator
= 1;
3551 format
->videoInfo
.PixelAspectRatio
.Denominator
= 1;
3552 format
->videoInfo
.InterlaceMode
= MFVideoInterlace_Progressive
;
3553 format
->videoInfo
.TransferFunction
= transfer_function
;
3554 format
->videoInfo
.ColorPrimaries
= MFVideoPrimaries_BT709
;
3555 format
->videoInfo
.SourceLighting
= MFVideoLighting_office
;
3556 format
->videoInfo
.FramesPerSecond
.Numerator
= 60;
3557 format
->videoInfo
.FramesPerSecond
.Denominator
= 1;
3558 format
->videoInfo
.NominalRange
= MFNominalRange_Normal
;
3559 format
->videoInfo
.GeometricAperture
.Area
.cx
= width
;
3560 format
->videoInfo
.GeometricAperture
.Area
.cy
= height
;
3561 format
->videoInfo
.MinimumDisplayAperture
= format
->videoInfo
.GeometricAperture
;
3562 memcpy(&format
->guidFormat
, &MFVideoFormat_Base
, sizeof(format
->guidFormat
));
3563 format
->guidFormat
.Data1
= d3dformat
;
3564 format
->surfaceInfo
.Format
= d3dformat
;
3569 static HRESULT
mf_get_stride_for_bitmap_info_header(DWORD fourcc
, const BITMAPINFOHEADER
*bih
, LONG
*stride
)
3573 if (FAILED(hr
= MFGetStrideForBitmapInfoHeader(fourcc
, bih
->biWidth
, stride
))) return hr
;
3574 if (bih
->biHeight
< 0) *stride
*= -1;
3579 static const GUID
* get_mf_subtype_for_am_subtype(const GUID
*subtype
)
3581 static const GUID null
;
3583 if (IsEqualGUID(subtype
, &MEDIASUBTYPE_RGB32
))
3584 return &MFVideoFormat_RGB32
;
3587 FIXME("Unknown subtype %s.\n", debugstr_guid(subtype
));
3592 /***********************************************************************
3593 * MFCreateVideoMediaTypeFromVideoInfoHeader (mfplat.@)
3595 HRESULT WINAPI
MFCreateVideoMediaTypeFromVideoInfoHeader(const KS_VIDEOINFOHEADER
*vih
, DWORD size
, DWORD pixel_aspect_ratio_x
,
3596 DWORD pixel_aspect_ratio_y
, MFVideoInterlaceMode interlace_mode
, QWORD video_flags
, const GUID
*subtype
,
3597 IMFVideoMediaType
**ret
)
3599 FIXME("%p, %lu, %lu, %lu, %d, %I64x, %s, %p.\n", vih
, size
, pixel_aspect_ratio_x
, pixel_aspect_ratio_y
, interlace_mode
,
3600 video_flags
, debugstr_guid(subtype
), ret
);
3605 /***********************************************************************
3606 * MFInitMediaTypeFromVideoInfoHeader (mfplat.@)
3608 HRESULT WINAPI
MFInitMediaTypeFromVideoInfoHeader(IMFMediaType
*media_type
, const VIDEOINFOHEADER
*vih
, UINT32 size
,
3609 const GUID
*subtype
)
3615 FIXME("%p, %p, %u, %s.\n", media_type
, vih
, size
, debugstr_guid(subtype
));
3617 IMFMediaType_DeleteAllItems(media_type
);
3621 FIXME("Implicit subtype is not supported.\n");
3625 height
= abs(vih
->bmiHeader
.biHeight
);
3627 mediatype_set_guid(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
, &hr
);
3628 mediatype_set_guid(media_type
, &MF_MT_SUBTYPE
, subtype
, &hr
);
3629 mediatype_set_uint64(media_type
, &MF_MT_PIXEL_ASPECT_RATIO
, 1, 1, &hr
);
3630 mediatype_set_uint32(media_type
, &MF_MT_INTERLACE_MODE
, MFVideoInterlace_Progressive
, &hr
);
3631 mediatype_set_uint64(media_type
, &MF_MT_FRAME_SIZE
, vih
->bmiHeader
.biWidth
, height
, &hr
);
3633 if (SUCCEEDED(mf_get_stride_for_bitmap_info_header(subtype
->Data1
, &vih
->bmiHeader
, &stride
)))
3635 mediatype_set_uint32(media_type
, &MF_MT_DEFAULT_STRIDE
, stride
, &hr
);
3636 mediatype_set_uint32(media_type
, &MF_MT_SAMPLE_SIZE
, abs(stride
) * height
, &hr
);
3637 mediatype_set_uint32(media_type
, &MF_MT_FIXED_SIZE_SAMPLES
, 1, &hr
);
3638 mediatype_set_uint32(media_type
, &MF_MT_ALL_SAMPLES_INDEPENDENT
, 1, &hr
);
3644 /***********************************************************************
3645 * MFInitMediaTypeFromAMMediaType (mfplat.@)
3647 HRESULT WINAPI
MFInitMediaTypeFromAMMediaType(IMFMediaType
*media_type
, const AM_MEDIA_TYPE
*am_type
)
3651 TRACE("%p, %p.\n", media_type
, am_type
);
3653 IMFMediaType_DeleteAllItems(media_type
);
3655 if (IsEqualGUID(&am_type
->majortype
, &MEDIATYPE_Video
))
3657 if (IsEqualGUID(&am_type
->formattype
, &FORMAT_VideoInfo
))
3659 const VIDEOINFOHEADER
*vih
= (const VIDEOINFOHEADER
*)am_type
->pbFormat
;
3660 const GUID
*subtype
;
3664 subtype
= get_mf_subtype_for_am_subtype(&am_type
->subtype
);
3665 height
= abs(vih
->bmiHeader
.biHeight
);
3667 mediatype_set_guid(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
, &hr
);
3668 mediatype_set_guid(media_type
, &MF_MT_SUBTYPE
, subtype
, &hr
);
3669 mediatype_set_uint64(media_type
, &MF_MT_PIXEL_ASPECT_RATIO
, 1, 1, &hr
);
3670 mediatype_set_uint32(media_type
, &MF_MT_INTERLACE_MODE
, MFVideoInterlace_Progressive
, &hr
);
3671 mediatype_set_uint64(media_type
, &MF_MT_FRAME_SIZE
, vih
->bmiHeader
.biWidth
, height
, &hr
);
3672 mediatype_set_uint32(media_type
, &MF_MT_ALL_SAMPLES_INDEPENDENT
, 1, &hr
);
3674 if (SUCCEEDED(mf_get_stride_for_bitmap_info_header(subtype
->Data1
, &vih
->bmiHeader
, &stride
)))
3676 mediatype_set_uint32(media_type
, &MF_MT_DEFAULT_STRIDE
, stride
, &hr
);
3677 mediatype_set_uint32(media_type
, &MF_MT_SAMPLE_SIZE
, abs(stride
) * height
, &hr
);
3678 mediatype_set_uint32(media_type
, &MF_MT_FIXED_SIZE_SAMPLES
, 1, &hr
);
3682 if (am_type
->bFixedSizeSamples
)
3683 mediatype_set_uint32(media_type
, &MF_MT_FIXED_SIZE_SAMPLES
, 1, &hr
);
3684 if (am_type
->lSampleSize
)
3685 mediatype_set_uint32(media_type
, &MF_MT_SAMPLE_SIZE
, am_type
->lSampleSize
, &hr
);
3692 FIXME("Unsupported format type %s.\n", debugstr_guid(&am_type
->formattype
));
3696 FIXME("Unsupported major type %s.\n", debugstr_guid(&am_type
->majortype
));