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"
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(mfplat
);
30 struct video_processor
32 IMFTransform IMFTransform_iface
;
34 IMFAttributes
*attributes
;
35 IMFAttributes
*output_attributes
;
38 static struct video_processor
*impl_video_processor_from_IMFTransform(IMFTransform
*iface
)
40 return CONTAINING_RECORD(iface
, struct video_processor
, IMFTransform_iface
);
43 static HRESULT WINAPI
video_processor_QueryInterface(IMFTransform
*iface
, REFIID riid
, void **obj
)
45 TRACE("%p, %s, %p.\n", iface
, debugstr_guid(riid
), obj
);
47 if (IsEqualIID(riid
, &IID_IMFTransform
) ||
48 IsEqualIID(riid
, &IID_IUnknown
))
51 IMFTransform_AddRef(iface
);
55 WARN("Unsupported %s.\n", debugstr_guid(riid
));
60 static ULONG WINAPI
video_processor_AddRef(IMFTransform
*iface
)
62 struct video_processor
*transform
= impl_video_processor_from_IMFTransform(iface
);
63 ULONG refcount
= InterlockedIncrement(&transform
->refcount
);
65 TRACE("%p, refcount %u.\n", iface
, refcount
);
70 static ULONG WINAPI
video_processor_Release(IMFTransform
*iface
)
72 struct video_processor
*transform
= impl_video_processor_from_IMFTransform(iface
);
73 ULONG refcount
= InterlockedDecrement(&transform
->refcount
);
75 TRACE("%p, refcount %u.\n", iface
, refcount
);
79 if (transform
->attributes
)
80 IMFAttributes_Release(transform
->attributes
);
81 if (transform
->output_attributes
)
82 IMFAttributes_Release(transform
->output_attributes
);
89 static HRESULT WINAPI
video_processor_GetStreamLimits(IMFTransform
*iface
, DWORD
*input_minimum
, DWORD
*input_maximum
,
90 DWORD
*output_minimum
, DWORD
*output_maximum
)
92 TRACE("%p, %p, %p, %p, %p.\n", iface
, input_minimum
, input_maximum
, output_minimum
, output_maximum
);
94 *input_minimum
= *input_maximum
= *output_minimum
= *output_maximum
= 1;
99 static HRESULT WINAPI
video_processor_GetStreamCount(IMFTransform
*iface
, DWORD
*inputs
, DWORD
*outputs
)
101 TRACE("%p, %p, %p.\n", iface
, inputs
, outputs
);
103 *inputs
= *outputs
= 1;
108 static HRESULT WINAPI
video_processor_GetStreamIDs(IMFTransform
*iface
, DWORD input_size
, DWORD
*inputs
,
109 DWORD output_size
, DWORD
*outputs
)
114 static HRESULT WINAPI
video_processor_GetInputStreamInfo(IMFTransform
*iface
, DWORD id
, MFT_INPUT_STREAM_INFO
*info
)
119 static HRESULT WINAPI
video_processor_GetOutputStreamInfo(IMFTransform
*iface
, DWORD id
, MFT_OUTPUT_STREAM_INFO
*info
)
124 static HRESULT WINAPI
video_processor_GetAttributes(IMFTransform
*iface
, IMFAttributes
**attributes
)
126 struct video_processor
*transform
= impl_video_processor_from_IMFTransform(iface
);
128 TRACE("%p, %p.\n", iface
, attributes
);
130 *attributes
= transform
->attributes
;
131 IMFAttributes_AddRef(*attributes
);
136 static HRESULT WINAPI
video_processor_GetInputStreamAttributes(IMFTransform
*iface
, DWORD id
,
137 IMFAttributes
**attributes
)
142 static HRESULT WINAPI
video_processor_GetOutputStreamAttributes(IMFTransform
*iface
, DWORD id
,
143 IMFAttributes
**attributes
)
145 struct video_processor
*transform
= impl_video_processor_from_IMFTransform(iface
);
147 TRACE("%p, %u, %p.\n", iface
, id
, attributes
);
149 *attributes
= transform
->output_attributes
;
150 IMFAttributes_AddRef(*attributes
);
155 static HRESULT WINAPI
video_processor_DeleteInputStream(IMFTransform
*iface
, DWORD id
)
157 TRACE("%p, %u.\n", iface
, id
);
162 static HRESULT WINAPI
video_processor_AddInputStreams(IMFTransform
*iface
, DWORD streams
, DWORD
*ids
)
164 TRACE("%p, %u, %p.\n", iface
, streams
, ids
);
169 static HRESULT WINAPI
video_processor_GetInputAvailableType(IMFTransform
*iface
, DWORD id
, DWORD index
,
172 FIXME("%p, %u, %u, %p.\n", iface
, id
, index
, type
);
177 static HRESULT WINAPI
video_processor_GetOutputAvailableType(IMFTransform
*iface
, DWORD id
, DWORD index
,
180 FIXME("%p, %u, %u, %p.\n", iface
, id
, index
, type
);
185 static HRESULT WINAPI
video_processor_SetInputType(IMFTransform
*iface
, DWORD id
, IMFMediaType
*type
, DWORD flags
)
187 FIXME("%p, %u, %p, %#x.\n", iface
, id
, type
, flags
);
192 static HRESULT WINAPI
video_processor_SetOutputType(IMFTransform
*iface
, DWORD id
, IMFMediaType
*type
, DWORD flags
)
194 FIXME("%p, %u, %p, %#x.\n", iface
, id
, type
, flags
);
199 static HRESULT WINAPI
video_processor_GetInputCurrentType(IMFTransform
*iface
, DWORD id
, IMFMediaType
**type
)
201 FIXME("%p, %u, %p.\n", iface
, id
, type
);
206 static HRESULT WINAPI
video_processor_GetOutputCurrentType(IMFTransform
*iface
, DWORD id
, IMFMediaType
**type
)
208 FIXME("%p, %u, %p.\n", iface
, id
, type
);
213 static HRESULT WINAPI
video_processor_GetInputStatus(IMFTransform
*iface
, DWORD id
, DWORD
*flags
)
215 FIXME("%p, %u, %p.\n", iface
, id
, flags
);
220 static HRESULT WINAPI
video_processor_GetOutputStatus(IMFTransform
*iface
, DWORD
*flags
)
222 FIXME("%p, %p.\n", iface
, flags
);
227 static HRESULT WINAPI
video_processor_SetOutputBounds(IMFTransform
*iface
, LONGLONG lower
, LONGLONG upper
)
229 FIXME("%p, %s, %s.\n", iface
, wine_dbgstr_longlong(lower
), wine_dbgstr_longlong(upper
));
234 static HRESULT WINAPI
video_processor_ProcessEvent(IMFTransform
*iface
, DWORD id
, IMFMediaEvent
*event
)
236 TRACE("%p, %u, %p.\n", iface
, id
, event
);
241 static HRESULT WINAPI
video_processor_ProcessMessage(IMFTransform
*iface
, MFT_MESSAGE_TYPE message
, ULONG_PTR param
)
243 FIXME("%p, %u.\n", iface
, message
);
248 static HRESULT WINAPI
video_processor_ProcessInput(IMFTransform
*iface
, DWORD id
, IMFSample
*sample
, DWORD flags
)
250 FIXME("%p, %u, %p, %#x.\n", iface
, id
, sample
, flags
);
255 static HRESULT WINAPI
video_processor_ProcessOutput(IMFTransform
*iface
, DWORD flags
, DWORD count
,
256 MFT_OUTPUT_DATA_BUFFER
*samples
, DWORD
*status
)
258 FIXME("%p, %#x, %u, %p, %p.\n", iface
, flags
, count
, samples
, status
);
263 static const IMFTransformVtbl video_processor_vtbl
=
265 video_processor_QueryInterface
,
266 video_processor_AddRef
,
267 video_processor_Release
,
268 video_processor_GetStreamLimits
,
269 video_processor_GetStreamCount
,
270 video_processor_GetStreamIDs
,
271 video_processor_GetInputStreamInfo
,
272 video_processor_GetOutputStreamInfo
,
273 video_processor_GetAttributes
,
274 video_processor_GetInputStreamAttributes
,
275 video_processor_GetOutputStreamAttributes
,
276 video_processor_DeleteInputStream
,
277 video_processor_AddInputStreams
,
278 video_processor_GetInputAvailableType
,
279 video_processor_GetOutputAvailableType
,
280 video_processor_SetInputType
,
281 video_processor_SetOutputType
,
282 video_processor_GetInputCurrentType
,
283 video_processor_GetOutputCurrentType
,
284 video_processor_GetInputStatus
,
285 video_processor_GetOutputStatus
,
286 video_processor_SetOutputBounds
,
287 video_processor_ProcessEvent
,
288 video_processor_ProcessMessage
,
289 video_processor_ProcessInput
,
290 video_processor_ProcessOutput
,
295 IClassFactory IClassFactory_iface
;
297 HRESULT (*create_instance
)(REFIID riid
, void **obj
);
300 static struct class_factory
*impl_from_IClassFactory(IClassFactory
*iface
)
302 return CONTAINING_RECORD(iface
, struct class_factory
, IClassFactory_iface
);
305 static HRESULT WINAPI
class_factory_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **obj
)
307 TRACE("%p, %s, %p.\n", iface
, debugstr_guid(riid
), obj
);
309 if (IsEqualGUID(riid
, &IID_IClassFactory
) ||
310 IsEqualGUID(riid
, &IID_IUnknown
))
313 IClassFactory_AddRef(iface
);
317 WARN("%s is not supported.\n", debugstr_guid(riid
));
319 return E_NOINTERFACE
;
322 static ULONG WINAPI
class_factory_AddRef(IClassFactory
*iface
)
324 struct class_factory
*factory
= impl_from_IClassFactory(iface
);
325 return InterlockedIncrement(&factory
->refcount
);
328 static ULONG WINAPI
class_factory_Release(IClassFactory
*iface
)
330 struct class_factory
*factory
= impl_from_IClassFactory(iface
);
331 ULONG refcount
= InterlockedDecrement(&factory
->refcount
);
339 static HRESULT WINAPI
class_factory_CreateInstance(IClassFactory
*iface
, IUnknown
*outer
, REFIID riid
, void **obj
)
341 struct class_factory
*factory
= impl_from_IClassFactory(iface
);
343 TRACE("%p, %p, %s, %p.\n", iface
, outer
, debugstr_guid(riid
), obj
);
348 return CLASS_E_NOAGGREGATION
;
351 return factory
->create_instance(riid
, obj
);
354 static HRESULT WINAPI
class_factory_LockServer(IClassFactory
*iface
, BOOL dolock
)
356 TRACE("%p, %d.\n", iface
, dolock
);
359 InterlockedIncrement(&object_locks
);
361 InterlockedDecrement(&object_locks
);
366 static const IClassFactoryVtbl class_factory_vtbl
=
368 class_factory_QueryInterface
,
369 class_factory_AddRef
,
370 class_factory_Release
,
371 class_factory_CreateInstance
,
372 class_factory_LockServer
,
375 static HRESULT
video_processor_create(REFIID riid
, void **ret
)
377 struct video_processor
*object
;
380 if (!(object
= calloc(1, sizeof(*object
))))
381 return E_OUTOFMEMORY
;
383 object
->IMFTransform_iface
.lpVtbl
= &video_processor_vtbl
;
384 object
->refcount
= 1;
386 if (FAILED(hr
= MFCreateAttributes(&object
->attributes
, 0)))
389 if (FAILED(hr
= MFCreateAttributes(&object
->output_attributes
, 0)))
392 *ret
= &object
->IMFTransform_iface
;
397 IMFTransform_Release(&object
->IMFTransform_iface
);
401 static const GUID CLSID_GStreamerByteStreamHandler
= {0x317df618, 0x5e5a, 0x468a, {0x9f, 0x15, 0xd8, 0x27, 0xa9, 0xa0, 0x81, 0x62}};
403 static const GUID CLSID_WINEAudioConverter
= {0x6a170414,0xaad9,0x4693,{0xb8,0x06,0x3a,0x0c,0x47,0xc5,0x70,0xd6}};
405 static const struct class_object
408 HRESULT (*create_instance
)(REFIID riid
, void **obj
);
412 { &CLSID_VideoProcessorMFT
, &video_processor_create
},
413 { &CLSID_GStreamerByteStreamHandler
, &winegstreamer_stream_handler_create
},
414 { &CLSID_WINEAudioConverter
, &audio_converter_create
},
417 HRESULT
mfplat_get_class_object(REFCLSID rclsid
, REFIID riid
, void **obj
)
419 struct class_factory
*factory
;
423 for (i
= 0; i
< ARRAY_SIZE(class_objects
); ++i
)
425 if (IsEqualGUID(class_objects
[i
].clsid
, rclsid
))
427 if (!(factory
= malloc(sizeof(*factory
))))
428 return E_OUTOFMEMORY
;
430 factory
->IClassFactory_iface
.lpVtbl
= &class_factory_vtbl
;
431 factory
->refcount
= 1;
432 factory
->create_instance
= class_objects
[i
].create_instance
;
434 hr
= IClassFactory_QueryInterface(&factory
->IClassFactory_iface
, riid
, obj
);
435 IClassFactory_Release(&factory
->IClassFactory_iface
);
440 return CLASS_E_CLASSNOTAVAILABLE
;
443 static WCHAR audio_converterW
[] = L
"Audio Converter";
444 static const GUID
*audio_converter_supported_types
[] =
447 &MFAudioFormat_Float
,
450 static const struct mft
453 const GUID
*category
;
456 const GUID
*major_type
;
457 const UINT32 input_types_count
;
458 const GUID
**input_types
;
459 const UINT32 output_types_count
;
460 const GUID
**output_types
;
465 &CLSID_WINEAudioConverter
,
466 &MFT_CATEGORY_AUDIO_EFFECT
,
468 MFT_ENUM_FLAG_SYNCMFT
,
470 ARRAY_SIZE(audio_converter_supported_types
),
471 audio_converter_supported_types
,
472 ARRAY_SIZE(audio_converter_supported_types
),
473 audio_converter_supported_types
,
477 HRESULT
mfplat_DllRegisterServer(void)
481 MFT_REGISTER_TYPE_INFO input_types
[2], output_types
[2];
483 for (i
= 0; i
< ARRAY_SIZE(mfts
); i
++)
485 const struct mft
*cur
= &mfts
[i
];
487 for (j
= 0; j
< cur
->input_types_count
; j
++)
489 input_types
[j
].guidMajorType
= *(cur
->major_type
);
490 input_types
[j
].guidSubtype
= *(cur
->input_types
[j
]);
492 for (j
= 0; j
< cur
->output_types_count
; j
++)
494 output_types
[j
].guidMajorType
= *(cur
->major_type
);
495 output_types
[j
].guidSubtype
= *(cur
->output_types
[j
]);
498 hr
= MFTRegister(*(cur
->clsid
), *(cur
->category
), cur
->name
, cur
->flags
, cur
->input_types_count
,
499 input_types
, cur
->output_types_count
, output_types
, NULL
);
503 FIXME("Failed to register MFT, hr %#x\n", hr
);
513 enum wg_video_format format
;
517 {&MFVideoFormat_ARGB32
, WG_VIDEO_FORMAT_BGRA
},
518 {&MFVideoFormat_RGB32
, WG_VIDEO_FORMAT_BGRx
},
519 {&MFVideoFormat_RGB24
, WG_VIDEO_FORMAT_BGR
},
520 {&MFVideoFormat_RGB555
, WG_VIDEO_FORMAT_RGB15
},
521 {&MFVideoFormat_RGB565
, WG_VIDEO_FORMAT_RGB16
},
522 {&MFVideoFormat_AYUV
, WG_VIDEO_FORMAT_AYUV
},
523 {&MFVideoFormat_I420
, WG_VIDEO_FORMAT_I420
},
524 {&MFVideoFormat_IYUV
, WG_VIDEO_FORMAT_I420
},
525 {&MFVideoFormat_NV12
, WG_VIDEO_FORMAT_NV12
},
526 {&MFVideoFormat_UYVY
, WG_VIDEO_FORMAT_UYVY
},
527 {&MFVideoFormat_YUY2
, WG_VIDEO_FORMAT_YUY2
},
528 {&MFVideoFormat_YV12
, WG_VIDEO_FORMAT_YV12
},
529 {&MFVideoFormat_YVYU
, WG_VIDEO_FORMAT_YVYU
},
536 enum wg_audio_format format
;
540 {&MFAudioFormat_PCM
, 8, WG_AUDIO_FORMAT_U8
},
541 {&MFAudioFormat_PCM
, 16, WG_AUDIO_FORMAT_S16LE
},
542 {&MFAudioFormat_PCM
, 24, WG_AUDIO_FORMAT_S24LE
},
543 {&MFAudioFormat_PCM
, 32, WG_AUDIO_FORMAT_S32LE
},
544 {&MFAudioFormat_Float
, 32, WG_AUDIO_FORMAT_F32LE
},
545 {&MFAudioFormat_Float
, 64, WG_AUDIO_FORMAT_F64LE
},
548 static inline UINT64
make_uint64(UINT32 high
, UINT32 low
)
550 return ((UINT64
)high
<< 32) | low
;
553 static IMFMediaType
*mf_media_type_from_wg_format_audio(const struct wg_format
*format
)
558 for (i
= 0; i
< ARRAY_SIZE(audio_formats
); ++i
)
560 if (format
->u
.audio
.format
== audio_formats
[i
].format
)
562 if (FAILED(MFCreateMediaType(&type
)))
565 IMFMediaType_SetGUID(type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Audio
);
566 IMFMediaType_SetGUID(type
, &MF_MT_SUBTYPE
, audio_formats
[i
].subtype
);
567 IMFMediaType_SetUINT32(type
, &MF_MT_AUDIO_BITS_PER_SAMPLE
, audio_formats
[i
].depth
);
568 IMFMediaType_SetUINT32(type
, &MF_MT_AUDIO_SAMPLES_PER_SECOND
, format
->u
.audio
.rate
);
569 IMFMediaType_SetUINT32(type
, &MF_MT_AUDIO_NUM_CHANNELS
, format
->u
.audio
.channels
);
570 IMFMediaType_SetUINT32(type
, &MF_MT_AUDIO_CHANNEL_MASK
, format
->u
.audio
.channel_mask
);
579 static IMFMediaType
*mf_media_type_from_wg_format_video(const struct wg_format
*format
)
584 for (i
= 0; i
< ARRAY_SIZE(video_formats
); ++i
)
586 if (format
->u
.video
.format
== video_formats
[i
].format
)
588 if (FAILED(MFCreateMediaType(&type
)))
591 IMFMediaType_SetGUID(type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
592 IMFMediaType_SetGUID(type
, &MF_MT_SUBTYPE
, video_formats
[i
].subtype
);
593 IMFMediaType_SetUINT64(type
, &MF_MT_FRAME_SIZE
,
594 make_uint64(format
->u
.video
.width
, format
->u
.video
.height
));
595 IMFMediaType_SetUINT64(type
, &MF_MT_FRAME_RATE
,
596 make_uint64(format
->u
.video
.fps_n
, format
->u
.video
.fps_d
));
597 IMFMediaType_SetUINT32(type
, &MF_MT_COMPRESSED
, FALSE
);
606 IMFMediaType
*mf_media_type_from_wg_format(const struct wg_format
*format
)
608 switch (format
->major_type
)
610 case WG_MAJOR_TYPE_UNKNOWN
:
613 case WG_MAJOR_TYPE_AUDIO
:
614 return mf_media_type_from_wg_format_audio(format
);
616 case WG_MAJOR_TYPE_VIDEO
:
617 return mf_media_type_from_wg_format_video(format
);
624 static void mf_media_type_to_wg_format_audio(IMFMediaType
*type
, struct wg_format
*format
)
626 UINT32 rate
, channels
, channel_mask
, depth
;
630 if (FAILED(IMFMediaType_GetGUID(type
, &MF_MT_SUBTYPE
, &subtype
)))
632 FIXME("Subtype is not set.\n");
635 if (FAILED(IMFMediaType_GetUINT32(type
, &MF_MT_AUDIO_SAMPLES_PER_SECOND
, &rate
)))
637 FIXME("Sample rate is not set.\n");
640 if (FAILED(IMFMediaType_GetUINT32(type
, &MF_MT_AUDIO_NUM_CHANNELS
, &channels
)))
642 FIXME("Channel count is not set.\n");
645 if (FAILED(IMFMediaType_GetUINT32(type
, &MF_MT_AUDIO_BITS_PER_SAMPLE
, &depth
)))
647 FIXME("Depth is not set.\n");
650 if (FAILED(IMFMediaType_GetUINT32(type
, &MF_MT_AUDIO_CHANNEL_MASK
, &channel_mask
)))
653 channel_mask
= KSAUDIO_SPEAKER_MONO
;
654 else if (channels
== 2)
655 channel_mask
= KSAUDIO_SPEAKER_STEREO
;
658 FIXME("Channel mask is not set.\n");
663 format
->major_type
= WG_MAJOR_TYPE_AUDIO
;
664 format
->u
.audio
.channels
= channels
;
665 format
->u
.audio
.channel_mask
= channel_mask
;
666 format
->u
.audio
.rate
= rate
;
668 for (i
= 0; i
< ARRAY_SIZE(audio_formats
); ++i
)
670 if (IsEqualGUID(&subtype
, audio_formats
[i
].subtype
) && depth
== audio_formats
[i
].depth
)
672 format
->u
.audio
.format
= audio_formats
[i
].format
;
676 FIXME("Unrecognized audio subtype %s, depth %u.\n", debugstr_guid(&subtype
), depth
);
679 static void mf_media_type_to_wg_format_video(IMFMediaType
*type
, struct wg_format
*format
)
681 UINT64 frame_rate
, frame_size
;
685 if (FAILED(IMFMediaType_GetGUID(type
, &MF_MT_SUBTYPE
, &subtype
)))
687 FIXME("Subtype is not set.\n");
690 if (FAILED(IMFMediaType_GetUINT64(type
, &MF_MT_FRAME_SIZE
, &frame_size
)))
692 FIXME("Frame size is not set.\n");
696 format
->major_type
= WG_MAJOR_TYPE_VIDEO
;
697 format
->u
.video
.width
= (UINT32
)(frame_size
>> 32);
698 format
->u
.video
.height
= (UINT32
)frame_size
;
699 format
->u
.video
.fps_n
= 1;
700 format
->u
.video
.fps_d
= 1;
702 if (SUCCEEDED(IMFMediaType_GetUINT64(type
, &MF_MT_FRAME_RATE
, &frame_rate
)) && (UINT32
)frame_rate
)
704 format
->u
.video
.fps_n
= (UINT32
)(frame_rate
>> 32);
705 format
->u
.video
.fps_d
= (UINT32
)frame_rate
;
708 for (i
= 0; i
< ARRAY_SIZE(video_formats
); ++i
)
710 if (IsEqualGUID(&subtype
, video_formats
[i
].subtype
))
712 format
->u
.video
.format
= video_formats
[i
].format
;
716 FIXME("Unrecognized video subtype %s.\n", debugstr_guid(&subtype
));
719 void mf_media_type_to_wg_format(IMFMediaType
*type
, struct wg_format
*format
)
723 memset(format
, 0, sizeof(*format
));
725 if (FAILED(IMFMediaType_GetMajorType(type
, &major_type
)))
727 FIXME("Major type is not set.\n");
731 if (IsEqualGUID(&major_type
, &MFMediaType_Audio
))
732 mf_media_type_to_wg_format_audio(type
, format
);
733 else if (IsEqualGUID(&major_type
, &MFMediaType_Video
))
734 mf_media_type_to_wg_format_video(type
, format
);
736 FIXME("Unrecognized major type %s.\n", debugstr_guid(&major_type
));