2 * Copyright 2019 Nikolay Sivov for CodeWeavers
3 * Copyright 2020 Zebediah Figura for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "gst_private.h"
24 #include "wmcodecdsp.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(mfplat
);
32 struct video_processor
34 IMFTransform IMFTransform_iface
;
36 IMFAttributes
*attributes
;
37 IMFAttributes
*output_attributes
;
40 static struct video_processor
*impl_video_processor_from_IMFTransform(IMFTransform
*iface
)
42 return CONTAINING_RECORD(iface
, struct video_processor
, IMFTransform_iface
);
45 static HRESULT WINAPI
video_processor_QueryInterface(IMFTransform
*iface
, REFIID riid
, void **obj
)
47 TRACE("%p, %s, %p.\n", iface
, debugstr_guid(riid
), obj
);
49 if (IsEqualIID(riid
, &IID_IMFTransform
) ||
50 IsEqualIID(riid
, &IID_IUnknown
))
53 IMFTransform_AddRef(iface
);
57 WARN("Unsupported %s.\n", debugstr_guid(riid
));
62 static ULONG WINAPI
video_processor_AddRef(IMFTransform
*iface
)
64 struct video_processor
*transform
= impl_video_processor_from_IMFTransform(iface
);
65 ULONG refcount
= InterlockedIncrement(&transform
->refcount
);
67 TRACE("%p, refcount %lu.\n", iface
, refcount
);
72 static ULONG WINAPI
video_processor_Release(IMFTransform
*iface
)
74 struct video_processor
*transform
= impl_video_processor_from_IMFTransform(iface
);
75 ULONG refcount
= InterlockedDecrement(&transform
->refcount
);
77 TRACE("%p, refcount %lu.\n", iface
, refcount
);
81 if (transform
->attributes
)
82 IMFAttributes_Release(transform
->attributes
);
83 if (transform
->output_attributes
)
84 IMFAttributes_Release(transform
->output_attributes
);
91 static HRESULT WINAPI
video_processor_GetStreamLimits(IMFTransform
*iface
, DWORD
*input_minimum
, DWORD
*input_maximum
,
92 DWORD
*output_minimum
, DWORD
*output_maximum
)
94 TRACE("%p, %p, %p, %p, %p.\n", iface
, input_minimum
, input_maximum
, output_minimum
, output_maximum
);
96 *input_minimum
= *input_maximum
= *output_minimum
= *output_maximum
= 1;
101 static HRESULT WINAPI
video_processor_GetStreamCount(IMFTransform
*iface
, DWORD
*inputs
, DWORD
*outputs
)
103 TRACE("%p, %p, %p.\n", iface
, inputs
, outputs
);
105 *inputs
= *outputs
= 1;
110 static HRESULT WINAPI
video_processor_GetStreamIDs(IMFTransform
*iface
, DWORD input_size
, DWORD
*inputs
,
111 DWORD output_size
, DWORD
*outputs
)
116 static HRESULT WINAPI
video_processor_GetInputStreamInfo(IMFTransform
*iface
, DWORD id
, MFT_INPUT_STREAM_INFO
*info
)
121 static HRESULT WINAPI
video_processor_GetOutputStreamInfo(IMFTransform
*iface
, DWORD id
, MFT_OUTPUT_STREAM_INFO
*info
)
126 static HRESULT WINAPI
video_processor_GetAttributes(IMFTransform
*iface
, IMFAttributes
**attributes
)
128 struct video_processor
*transform
= impl_video_processor_from_IMFTransform(iface
);
130 TRACE("%p, %p.\n", iface
, attributes
);
132 *attributes
= transform
->attributes
;
133 IMFAttributes_AddRef(*attributes
);
138 static HRESULT WINAPI
video_processor_GetInputStreamAttributes(IMFTransform
*iface
, DWORD id
,
139 IMFAttributes
**attributes
)
144 static HRESULT WINAPI
video_processor_GetOutputStreamAttributes(IMFTransform
*iface
, DWORD id
,
145 IMFAttributes
**attributes
)
147 struct video_processor
*transform
= impl_video_processor_from_IMFTransform(iface
);
149 TRACE("%p, %lu, %p.\n", iface
, id
, attributes
);
151 *attributes
= transform
->output_attributes
;
152 IMFAttributes_AddRef(*attributes
);
157 static HRESULT WINAPI
video_processor_DeleteInputStream(IMFTransform
*iface
, DWORD id
)
159 TRACE("%p, %lu.\n", iface
, id
);
164 static HRESULT WINAPI
video_processor_AddInputStreams(IMFTransform
*iface
, DWORD streams
, DWORD
*ids
)
166 TRACE("%p, %lu, %p.\n", iface
, streams
, ids
);
171 static HRESULT WINAPI
video_processor_GetInputAvailableType(IMFTransform
*iface
, DWORD id
, DWORD index
,
174 FIXME("%p, %lu, %lu, %p.\n", iface
, id
, index
, type
);
179 static HRESULT WINAPI
video_processor_GetOutputAvailableType(IMFTransform
*iface
, DWORD id
, DWORD index
,
182 FIXME("%p, %lu, %lu, %p.\n", iface
, id
, index
, type
);
187 static HRESULT WINAPI
video_processor_SetInputType(IMFTransform
*iface
, DWORD id
, IMFMediaType
*type
, DWORD flags
)
189 FIXME("%p, %lu, %p, %#lx.\n", iface
, id
, type
, flags
);
194 static HRESULT WINAPI
video_processor_SetOutputType(IMFTransform
*iface
, DWORD id
, IMFMediaType
*type
, DWORD flags
)
196 FIXME("%p, %lu, %p, %#lx.\n", iface
, id
, type
, flags
);
201 static HRESULT WINAPI
video_processor_GetInputCurrentType(IMFTransform
*iface
, DWORD id
, IMFMediaType
**type
)
203 FIXME("%p, %lu, %p.\n", iface
, id
, type
);
208 static HRESULT WINAPI
video_processor_GetOutputCurrentType(IMFTransform
*iface
, DWORD id
, IMFMediaType
**type
)
210 FIXME("%p, %lu, %p.\n", iface
, id
, type
);
215 static HRESULT WINAPI
video_processor_GetInputStatus(IMFTransform
*iface
, DWORD id
, DWORD
*flags
)
217 FIXME("%p, %lu, %p.\n", iface
, id
, flags
);
222 static HRESULT WINAPI
video_processor_GetOutputStatus(IMFTransform
*iface
, DWORD
*flags
)
224 FIXME("%p, %p.\n", iface
, flags
);
229 static HRESULT WINAPI
video_processor_SetOutputBounds(IMFTransform
*iface
, LONGLONG lower
, LONGLONG upper
)
231 FIXME("%p, %s, %s.\n", iface
, wine_dbgstr_longlong(lower
), wine_dbgstr_longlong(upper
));
236 static HRESULT WINAPI
video_processor_ProcessEvent(IMFTransform
*iface
, DWORD id
, IMFMediaEvent
*event
)
238 TRACE("%p, %lu, %p.\n", iface
, id
, event
);
243 static HRESULT WINAPI
video_processor_ProcessMessage(IMFTransform
*iface
, MFT_MESSAGE_TYPE message
, ULONG_PTR param
)
245 FIXME("%p, %u, %#Ix.\n", iface
, message
, param
);
250 static HRESULT WINAPI
video_processor_ProcessInput(IMFTransform
*iface
, DWORD id
, IMFSample
*sample
, DWORD flags
)
252 FIXME("%p, %lu, %p, %#lx.\n", iface
, id
, sample
, flags
);
257 static HRESULT WINAPI
video_processor_ProcessOutput(IMFTransform
*iface
, DWORD flags
, DWORD count
,
258 MFT_OUTPUT_DATA_BUFFER
*samples
, DWORD
*status
)
260 FIXME("%p, %#lx, %lu, %p, %p.\n", iface
, flags
, count
, samples
, status
);
265 static const IMFTransformVtbl video_processor_vtbl
=
267 video_processor_QueryInterface
,
268 video_processor_AddRef
,
269 video_processor_Release
,
270 video_processor_GetStreamLimits
,
271 video_processor_GetStreamCount
,
272 video_processor_GetStreamIDs
,
273 video_processor_GetInputStreamInfo
,
274 video_processor_GetOutputStreamInfo
,
275 video_processor_GetAttributes
,
276 video_processor_GetInputStreamAttributes
,
277 video_processor_GetOutputStreamAttributes
,
278 video_processor_DeleteInputStream
,
279 video_processor_AddInputStreams
,
280 video_processor_GetInputAvailableType
,
281 video_processor_GetOutputAvailableType
,
282 video_processor_SetInputType
,
283 video_processor_SetOutputType
,
284 video_processor_GetInputCurrentType
,
285 video_processor_GetOutputCurrentType
,
286 video_processor_GetInputStatus
,
287 video_processor_GetOutputStatus
,
288 video_processor_SetOutputBounds
,
289 video_processor_ProcessEvent
,
290 video_processor_ProcessMessage
,
291 video_processor_ProcessInput
,
292 video_processor_ProcessOutput
,
297 IClassFactory IClassFactory_iface
;
299 HRESULT (*create_instance
)(REFIID riid
, void **obj
);
302 static struct class_factory
*impl_from_IClassFactory(IClassFactory
*iface
)
304 return CONTAINING_RECORD(iface
, struct class_factory
, IClassFactory_iface
);
307 static HRESULT WINAPI
class_factory_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **obj
)
309 TRACE("%p, %s, %p.\n", iface
, debugstr_guid(riid
), obj
);
311 if (IsEqualGUID(riid
, &IID_IClassFactory
) ||
312 IsEqualGUID(riid
, &IID_IUnknown
))
315 IClassFactory_AddRef(iface
);
319 WARN("%s is not supported.\n", debugstr_guid(riid
));
321 return E_NOINTERFACE
;
324 static ULONG WINAPI
class_factory_AddRef(IClassFactory
*iface
)
326 struct class_factory
*factory
= impl_from_IClassFactory(iface
);
327 return InterlockedIncrement(&factory
->refcount
);
330 static ULONG WINAPI
class_factory_Release(IClassFactory
*iface
)
332 struct class_factory
*factory
= impl_from_IClassFactory(iface
);
333 ULONG refcount
= InterlockedDecrement(&factory
->refcount
);
341 static HRESULT WINAPI
class_factory_CreateInstance(IClassFactory
*iface
, IUnknown
*outer
, REFIID riid
, void **obj
)
343 struct class_factory
*factory
= impl_from_IClassFactory(iface
);
345 TRACE("%p, %p, %s, %p.\n", iface
, outer
, debugstr_guid(riid
), obj
);
350 return CLASS_E_NOAGGREGATION
;
353 return factory
->create_instance(riid
, obj
);
356 static HRESULT WINAPI
class_factory_LockServer(IClassFactory
*iface
, BOOL dolock
)
358 TRACE("%p, %d.\n", iface
, dolock
);
362 static const IClassFactoryVtbl class_factory_vtbl
=
364 class_factory_QueryInterface
,
365 class_factory_AddRef
,
366 class_factory_Release
,
367 class_factory_CreateInstance
,
368 class_factory_LockServer
,
371 static HRESULT
video_processor_create(REFIID riid
, void **ret
)
373 struct video_processor
*object
;
376 if (!(object
= calloc(1, sizeof(*object
))))
377 return E_OUTOFMEMORY
;
379 object
->IMFTransform_iface
.lpVtbl
= &video_processor_vtbl
;
380 object
->refcount
= 1;
382 if (FAILED(hr
= MFCreateAttributes(&object
->attributes
, 0)))
385 if (FAILED(hr
= MFCreateAttributes(&object
->output_attributes
, 0)))
388 *ret
= &object
->IMFTransform_iface
;
393 IMFTransform_Release(&object
->IMFTransform_iface
);
397 static const GUID CLSID_GStreamerByteStreamHandler
= {0x317df618, 0x5e5a, 0x468a, {0x9f, 0x15, 0xd8, 0x27, 0xa9, 0xa0, 0x81, 0x62}};
399 static const GUID CLSID_WINEAudioConverter
= {0x6a170414,0xaad9,0x4693,{0xb8,0x06,0x3a,0x0c,0x47,0xc5,0x70,0xd6}};
401 static const struct class_object
404 HRESULT (*create_instance
)(REFIID riid
, void **obj
);
408 { &CLSID_VideoProcessorMFT
, &video_processor_create
},
409 { &CLSID_GStreamerByteStreamHandler
, &winegstreamer_stream_handler_create
},
410 { &CLSID_WINEAudioConverter
, &audio_converter_create
},
411 { &CLSID_MSH264DecoderMFT
, &h264_decoder_create
},
414 HRESULT
mfplat_get_class_object(REFCLSID rclsid
, REFIID riid
, void **obj
)
416 struct class_factory
*factory
;
420 for (i
= 0; i
< ARRAY_SIZE(class_objects
); ++i
)
422 if (IsEqualGUID(class_objects
[i
].clsid
, rclsid
))
424 if (!(factory
= malloc(sizeof(*factory
))))
425 return E_OUTOFMEMORY
;
427 factory
->IClassFactory_iface
.lpVtbl
= &class_factory_vtbl
;
428 factory
->refcount
= 1;
429 factory
->create_instance
= class_objects
[i
].create_instance
;
431 hr
= IClassFactory_QueryInterface(&factory
->IClassFactory_iface
, riid
, obj
);
432 IClassFactory_Release(&factory
->IClassFactory_iface
);
437 return CLASS_E_CLASSNOTAVAILABLE
;
440 static WCHAR audio_converterW
[] = L
"Audio Converter";
441 static const GUID
*const audio_converter_supported_types
[] =
444 &MFAudioFormat_Float
,
447 static WCHAR wma_decoderW
[] = L
"WMAudio Decoder MFT";
448 static const GUID
*const wma_decoder_input_types
[] =
450 &MEDIASUBTYPE_MSAUDIO1
,
451 &MFAudioFormat_WMAudioV8
,
452 &MFAudioFormat_WMAudioV9
,
453 &MFAudioFormat_WMAudio_Lossless
,
455 static const GUID
*const wma_decoder_output_types
[] =
458 &MFAudioFormat_Float
,
461 static WCHAR h264_decoderW
[] = L
"Microsoft H264 Video Decoder MFT";
462 static const GUID
*const h264_decoder_input_types
[] =
465 &MFVideoFormat_H264_ES
,
467 static const GUID
*const h264_decoder_output_types
[] =
476 static const struct mft
479 const GUID
*category
;
482 const GUID
*major_type
;
483 const UINT32 input_types_count
;
484 const GUID
*const *input_types
;
485 const UINT32 output_types_count
;
486 const GUID
*const *output_types
;
491 &CLSID_WINEAudioConverter
,
492 &MFT_CATEGORY_AUDIO_EFFECT
,
494 MFT_ENUM_FLAG_SYNCMFT
,
496 ARRAY_SIZE(audio_converter_supported_types
),
497 audio_converter_supported_types
,
498 ARRAY_SIZE(audio_converter_supported_types
),
499 audio_converter_supported_types
,
502 &CLSID_WMADecMediaObject
,
503 &MFT_CATEGORY_AUDIO_DECODER
,
505 MFT_ENUM_FLAG_SYNCMFT
,
507 ARRAY_SIZE(wma_decoder_input_types
),
508 wma_decoder_input_types
,
509 ARRAY_SIZE(wma_decoder_output_types
),
510 wma_decoder_output_types
,
513 &CLSID_MSH264DecoderMFT
,
514 &MFT_CATEGORY_VIDEO_DECODER
,
516 MFT_ENUM_FLAG_SYNCMFT
,
518 ARRAY_SIZE(h264_decoder_input_types
),
519 h264_decoder_input_types
,
520 ARRAY_SIZE(h264_decoder_output_types
),
521 h264_decoder_output_types
,
525 HRESULT
mfplat_DllRegisterServer(void)
529 MFT_REGISTER_TYPE_INFO input_types
[4], output_types
[5];
531 for (i
= 0; i
< ARRAY_SIZE(mfts
); i
++)
533 const struct mft
*cur
= &mfts
[i
];
535 for (j
= 0; j
< cur
->input_types_count
; j
++)
537 input_types
[j
].guidMajorType
= *(cur
->major_type
);
538 input_types
[j
].guidSubtype
= *(cur
->input_types
[j
]);
540 for (j
= 0; j
< cur
->output_types_count
; j
++)
542 output_types
[j
].guidMajorType
= *(cur
->major_type
);
543 output_types
[j
].guidSubtype
= *(cur
->output_types
[j
]);
546 hr
= MFTRegister(*(cur
->clsid
), *(cur
->category
), cur
->name
, cur
->flags
, cur
->input_types_count
,
547 input_types
, cur
->output_types_count
, output_types
, NULL
);
551 FIXME("Failed to register MFT, hr %#lx.\n", hr
);
561 enum wg_video_format format
;
565 {&MFVideoFormat_ARGB32
, WG_VIDEO_FORMAT_BGRA
},
566 {&MFVideoFormat_RGB32
, WG_VIDEO_FORMAT_BGRx
},
567 {&MFVideoFormat_RGB24
, WG_VIDEO_FORMAT_BGR
},
568 {&MFVideoFormat_RGB555
, WG_VIDEO_FORMAT_RGB15
},
569 {&MFVideoFormat_RGB565
, WG_VIDEO_FORMAT_RGB16
},
570 {&MFVideoFormat_AYUV
, WG_VIDEO_FORMAT_AYUV
},
571 {&MFVideoFormat_I420
, WG_VIDEO_FORMAT_I420
},
572 {&MFVideoFormat_IYUV
, WG_VIDEO_FORMAT_I420
},
573 {&MFVideoFormat_NV12
, WG_VIDEO_FORMAT_NV12
},
574 {&MFVideoFormat_UYVY
, WG_VIDEO_FORMAT_UYVY
},
575 {&MFVideoFormat_YUY2
, WG_VIDEO_FORMAT_YUY2
},
576 {&MFVideoFormat_YV12
, WG_VIDEO_FORMAT_YV12
},
577 {&MFVideoFormat_YVYU
, WG_VIDEO_FORMAT_YVYU
},
584 enum wg_audio_format format
;
588 {&MFAudioFormat_PCM
, 8, WG_AUDIO_FORMAT_U8
},
589 {&MFAudioFormat_PCM
, 16, WG_AUDIO_FORMAT_S16LE
},
590 {&MFAudioFormat_PCM
, 24, WG_AUDIO_FORMAT_S24LE
},
591 {&MFAudioFormat_PCM
, 32, WG_AUDIO_FORMAT_S32LE
},
592 {&MFAudioFormat_Float
, 32, WG_AUDIO_FORMAT_F32LE
},
593 {&MFAudioFormat_Float
, 64, WG_AUDIO_FORMAT_F64LE
},
596 static inline UINT64
make_uint64(UINT32 high
, UINT32 low
)
598 return ((UINT64
)high
<< 32) | low
;
601 static IMFMediaType
*mf_media_type_from_wg_format_audio(const struct wg_format
*format
)
606 for (i
= 0; i
< ARRAY_SIZE(audio_formats
); ++i
)
608 if (format
->u
.audio
.format
== audio_formats
[i
].format
)
610 if (FAILED(MFCreateMediaType(&type
)))
613 IMFMediaType_SetGUID(type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Audio
);
614 IMFMediaType_SetGUID(type
, &MF_MT_SUBTYPE
, audio_formats
[i
].subtype
);
615 IMFMediaType_SetUINT32(type
, &MF_MT_AUDIO_BITS_PER_SAMPLE
, audio_formats
[i
].depth
);
616 IMFMediaType_SetUINT32(type
, &MF_MT_AUDIO_SAMPLES_PER_SECOND
, format
->u
.audio
.rate
);
617 IMFMediaType_SetUINT32(type
, &MF_MT_AUDIO_NUM_CHANNELS
, format
->u
.audio
.channels
);
618 IMFMediaType_SetUINT32(type
, &MF_MT_AUDIO_CHANNEL_MASK
, format
->u
.audio
.channel_mask
);
619 IMFMediaType_SetUINT32(type
, &MF_MT_ALL_SAMPLES_INDEPENDENT
, TRUE
);
620 IMFMediaType_SetUINT32(type
, &MF_MT_AUDIO_BLOCK_ALIGNMENT
, format
->u
.audio
.channels
* audio_formats
[i
].depth
/ 8);
629 static IMFMediaType
*mf_media_type_from_wg_format_video(const struct wg_format
*format
)
634 for (i
= 0; i
< ARRAY_SIZE(video_formats
); ++i
)
636 if (format
->u
.video
.format
== video_formats
[i
].format
)
638 if (FAILED(MFCreateMediaType(&type
)))
641 IMFMediaType_SetGUID(type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
642 IMFMediaType_SetGUID(type
, &MF_MT_SUBTYPE
, video_formats
[i
].subtype
);
643 IMFMediaType_SetUINT64(type
, &MF_MT_FRAME_SIZE
,
644 make_uint64(format
->u
.video
.width
, format
->u
.video
.height
));
645 IMFMediaType_SetUINT64(type
, &MF_MT_FRAME_RATE
,
646 make_uint64(format
->u
.video
.fps_n
, format
->u
.video
.fps_d
));
647 IMFMediaType_SetUINT32(type
, &MF_MT_COMPRESSED
, FALSE
);
648 IMFMediaType_SetUINT32(type
, &MF_MT_ALL_SAMPLES_INDEPENDENT
, TRUE
);
649 IMFMediaType_SetUINT32(type
, &MF_MT_VIDEO_ROTATION
, MFVideoRotationFormat_0
);
658 IMFMediaType
*mf_media_type_from_wg_format(const struct wg_format
*format
)
660 switch (format
->major_type
)
662 case WG_MAJOR_TYPE_UNKNOWN
:
665 case WG_MAJOR_TYPE_WMA
:
666 FIXME("WMA format not implemented!\n");
669 case WG_MAJOR_TYPE_AUDIO
:
670 return mf_media_type_from_wg_format_audio(format
);
672 case WG_MAJOR_TYPE_VIDEO
:
673 return mf_media_type_from_wg_format_video(format
);
680 static void mf_media_type_to_wg_format_audio(IMFMediaType
*type
, const GUID
*subtype
, struct wg_format
*format
)
682 UINT32 rate
, channels
, channel_mask
, depth
;
685 if (FAILED(IMFMediaType_GetUINT32(type
, &MF_MT_AUDIO_SAMPLES_PER_SECOND
, &rate
)))
687 FIXME("Sample rate is not set.\n");
690 if (FAILED(IMFMediaType_GetUINT32(type
, &MF_MT_AUDIO_NUM_CHANNELS
, &channels
)))
692 FIXME("Channel count is not set.\n");
695 if (FAILED(IMFMediaType_GetUINT32(type
, &MF_MT_AUDIO_BITS_PER_SAMPLE
, &depth
)))
697 FIXME("Depth is not set.\n");
700 if (FAILED(IMFMediaType_GetUINT32(type
, &MF_MT_AUDIO_CHANNEL_MASK
, &channel_mask
)))
703 channel_mask
= KSAUDIO_SPEAKER_MONO
;
704 else if (channels
== 2)
705 channel_mask
= KSAUDIO_SPEAKER_STEREO
;
708 FIXME("Channel mask is not set.\n");
713 format
->major_type
= WG_MAJOR_TYPE_AUDIO
;
714 format
->u
.audio
.channels
= channels
;
715 format
->u
.audio
.channel_mask
= channel_mask
;
716 format
->u
.audio
.rate
= rate
;
718 for (i
= 0; i
< ARRAY_SIZE(audio_formats
); ++i
)
720 if (IsEqualGUID(subtype
, audio_formats
[i
].subtype
) && depth
== audio_formats
[i
].depth
)
722 format
->u
.audio
.format
= audio_formats
[i
].format
;
726 FIXME("Unrecognized audio subtype %s, depth %u.\n", debugstr_guid(subtype
), depth
);
729 static void mf_media_type_to_wg_format_video(IMFMediaType
*type
, const GUID
*subtype
, struct wg_format
*format
)
731 UINT64 frame_rate
, frame_size
;
734 if (FAILED(IMFMediaType_GetUINT64(type
, &MF_MT_FRAME_SIZE
, &frame_size
)))
736 FIXME("Frame size is not set.\n");
740 format
->major_type
= WG_MAJOR_TYPE_VIDEO
;
741 format
->u
.video
.width
= (UINT32
)(frame_size
>> 32);
742 format
->u
.video
.height
= (UINT32
)frame_size
;
743 format
->u
.video
.fps_n
= 1;
744 format
->u
.video
.fps_d
= 1;
746 if (SUCCEEDED(IMFMediaType_GetUINT64(type
, &MF_MT_FRAME_RATE
, &frame_rate
)) && (UINT32
)frame_rate
)
748 format
->u
.video
.fps_n
= (UINT32
)(frame_rate
>> 32);
749 format
->u
.video
.fps_d
= (UINT32
)frame_rate
;
752 for (i
= 0; i
< ARRAY_SIZE(video_formats
); ++i
)
754 if (IsEqualGUID(subtype
, video_formats
[i
].subtype
))
756 format
->u
.video
.format
= video_formats
[i
].format
;
760 FIXME("Unrecognized video subtype %s.\n", debugstr_guid(subtype
));
763 static void mf_media_type_to_wg_format_wma(IMFMediaType
*type
, const GUID
*subtype
, struct wg_format
*format
)
765 UINT32 rate
, depth
, channels
, block_align
, bytes_per_second
, codec_data_len
;
769 if (FAILED(IMFMediaType_GetUINT32(type
, &MF_MT_AUDIO_SAMPLES_PER_SECOND
, &rate
)))
771 FIXME("Sample rate is not set.\n");
774 if (FAILED(IMFMediaType_GetUINT32(type
, &MF_MT_AUDIO_NUM_CHANNELS
, &channels
)))
776 FIXME("Channel count is not set.\n");
779 if (FAILED(IMFMediaType_GetUINT32(type
, &MF_MT_AUDIO_BLOCK_ALIGNMENT
, &block_align
)))
781 FIXME("Block alignment is not set.\n");
784 if (FAILED(IMFMediaType_GetUINT32(type
, &MF_MT_AUDIO_BITS_PER_SAMPLE
, &depth
)))
786 FIXME("Depth is not set.\n");
789 if (FAILED(IMFMediaType_GetBlob(type
, &MF_MT_USER_DATA
, codec_data
, sizeof(codec_data
), &codec_data_len
)))
791 FIXME("Codec data is not set.\n");
794 if (FAILED(IMFMediaType_GetUINT32(type
, &MF_MT_AUDIO_AVG_BYTES_PER_SECOND
, &bytes_per_second
)))
796 FIXME("Bitrate is not set.\n");
797 bytes_per_second
= 0;
800 if (IsEqualGUID(subtype
, &MEDIASUBTYPE_MSAUDIO1
))
802 else if (IsEqualGUID(subtype
, &MFAudioFormat_WMAudioV8
))
804 else if (IsEqualGUID(subtype
, &MFAudioFormat_WMAudioV9
))
806 else if (IsEqualGUID(subtype
, &MFAudioFormat_WMAudio_Lossless
))
814 format
->major_type
= WG_MAJOR_TYPE_WMA
;
815 format
->u
.wma
.version
= version
;
816 format
->u
.wma
.bitrate
= bytes_per_second
* 8;
817 format
->u
.wma
.rate
= rate
;
818 format
->u
.wma
.depth
= depth
;
819 format
->u
.wma
.channels
= channels
;
820 format
->u
.wma
.block_align
= block_align
;
821 format
->u
.wma
.codec_data_len
= codec_data_len
;
822 memcpy(format
->u
.wma
.codec_data
, codec_data
, codec_data_len
);
825 void mf_media_type_to_wg_format(IMFMediaType
*type
, struct wg_format
*format
)
827 GUID major_type
, subtype
;
829 memset(format
, 0, sizeof(*format
));
831 if (FAILED(IMFMediaType_GetMajorType(type
, &major_type
)))
833 FIXME("Major type is not set.\n");
836 if (FAILED(IMFMediaType_GetGUID(type
, &MF_MT_SUBTYPE
, &subtype
)))
838 FIXME("Subtype is not set.\n");
842 if (IsEqualGUID(&major_type
, &MFMediaType_Audio
))
844 if (IsEqualGUID(&subtype
, &MEDIASUBTYPE_MSAUDIO1
) ||
845 IsEqualGUID(&subtype
, &MFAudioFormat_WMAudioV8
) ||
846 IsEqualGUID(&subtype
, &MFAudioFormat_WMAudioV9
) ||
847 IsEqualGUID(&subtype
, &MFAudioFormat_WMAudio_Lossless
))
848 mf_media_type_to_wg_format_wma(type
, &subtype
, format
);
850 mf_media_type_to_wg_format_audio(type
, &subtype
, format
);
852 else if (IsEqualGUID(&major_type
, &MFMediaType_Video
))
853 mf_media_type_to_wg_format_video(type
, &subtype
, format
);
855 FIXME("Unrecognized major type %s.\n", debugstr_guid(&major_type
));
861 IMFMediaBuffer
*media_buffer
;
862 struct wg_sample wg_sample
;
865 HRESULT
mf_create_wg_sample(IMFSample
*sample
, struct wg_sample
**out
)
867 DWORD current_length
, max_length
;
868 struct mf_sample
*mf_sample
;
872 if (!(mf_sample
= calloc(1, sizeof(*mf_sample
))))
873 return E_OUTOFMEMORY
;
874 if (FAILED(hr
= IMFSample_ConvertToContiguousBuffer(sample
, &mf_sample
->media_buffer
)))
876 if (FAILED(hr
= IMFMediaBuffer_Lock(mf_sample
->media_buffer
, &buffer
, &max_length
, ¤t_length
)))
879 IMFSample_AddRef((mf_sample
->sample
= sample
));
880 mf_sample
->wg_sample
.data
= buffer
;
881 mf_sample
->wg_sample
.size
= current_length
;
882 mf_sample
->wg_sample
.max_size
= max_length
;
884 TRACE("Created mf_sample %p for sample %p.\n", mf_sample
, sample
);
885 *out
= &mf_sample
->wg_sample
;
889 if (mf_sample
->media_buffer
)
890 IMFMediaBuffer_Release(mf_sample
->media_buffer
);
895 void mf_destroy_wg_sample(struct wg_sample
*wg_sample
)
897 struct mf_sample
*mf_sample
= CONTAINING_RECORD(wg_sample
, struct mf_sample
, wg_sample
);
899 IMFMediaBuffer_Unlock(mf_sample
->media_buffer
);
900 IMFMediaBuffer_SetCurrentLength(mf_sample
->media_buffer
, wg_sample
->size
);
901 IMFMediaBuffer_Release(mf_sample
->media_buffer
);
903 IMFSample_Release(mf_sample
->sample
);