Signed-off-by: Derek Lesho dlesho@codeweavers.com --- dlls/winegstreamer/gst_private.h | 3 ++ dlls/winegstreamer/mfplat.c | 81 ++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+)
diff --git a/dlls/winegstreamer/gst_private.h b/dlls/winegstreamer/gst_private.h index e6fb841fc8..7d693ced9a 100644 --- a/dlls/winegstreamer/gst_private.h +++ b/dlls/winegstreamer/gst_private.h @@ -36,6 +36,7 @@ #include "winuser.h" #include "dshow.h" #include "strmif.h" +#include "mfobjects.h" #include "wine/heap.h" #include "wine/strmbase.h"
@@ -54,4 +55,6 @@ void start_dispatch_thread(void) DECLSPEC_HIDDEN;
extern HRESULT mfplat_get_class_object(REFCLSID rclsid, REFIID riid, void **obj) DECLSPEC_HIDDEN;
+IMFMediaType* media_type_from_caps(GstCaps *caps); + #endif /* __GST_PRIVATE_INCLUDED__ */ diff --git a/dlls/winegstreamer/mfplat.c b/dlls/winegstreamer/mfplat.c index 55b9b08876..4af50624e0 100644 --- a/dlls/winegstreamer/mfplat.c +++ b/dlls/winegstreamer/mfplat.c @@ -16,6 +16,11 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
+#include "config.h" +#include <gst/gst.h> + +#include "gst_private.h" + #include <stdarg.h>
#include "gst_private.h" @@ -433,3 +438,79 @@ HRESULT mfplat_get_class_object(REFCLSID rclsid, REFIID riid, void **obj)
return CLASS_E_CLASSNOTAVAILABLE; } + +/* IMPORTANT: caps will be modified to represent the exact type needed for the format */ +IMFMediaType* media_type_from_caps(GstCaps *caps) +{ + IMFMediaType *media_type; + GstStructure *info; + const char *mime_type; + gchar *human_readable; + + human_readable = gst_caps_to_string(caps); + TRACE("caps = %s\n", human_readable); + g_free(human_readable); + + if (FAILED(MFCreateMediaType(&media_type))) + { + return NULL; + } + + info = gst_caps_get_structure(caps, 0); + mime_type = gst_structure_get_name(info); + + if (!(strncmp(mime_type, "video", 5))) + { + gint width, height, framerate_num, framerate_den; + + IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Video); + + if (gst_structure_get_int(info, "width", &width) && gst_structure_get_int(info, "height", &height)) + { + IMFMediaType_SetUINT64(media_type, &MF_MT_FRAME_SIZE, ((UINT64)width << 32) | height); + } + if (gst_structure_get_fraction(info, "framerate", &framerate_num, &framerate_den)) + { + IMFMediaType_SetUINT64(media_type, &MF_MT_FRAME_RATE, ((UINT64)framerate_num << 32) | framerate_den); + } + + if (!(strcmp(mime_type, "video/x-raw"))) + { + const char *fourcc = gst_structure_get_string(info, "stream-format"); + IMFMediaType_SetUINT32(media_type, &MF_MT_COMPRESSED, FALSE); + if (fourcc && (strlen(fourcc) == 4)) + { + GUID fourcc_subtype = MFVideoFormat_Base; + fourcc_subtype.Data1 = MAKEFOURCC( + toupper(fourcc[0]), toupper(fourcc[1]), toupper(fourcc[2]), toupper(fourcc[3])); + IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &fourcc_subtype); + } + else + ERR("uncompressed video has no stream-format\n"); + } + else + ERR("Unrecognized video format %s\n", mime_type); + } + else if (!(strncmp(mime_type, "audio", 5))) + { + IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Audio); + + if (!(strcmp(mime_type, "audio/x-raw"))) + { + IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFAudioFormat_Float); + + gst_caps_set_simple(caps, "format", G_TYPE_STRING, "F32LE", NULL); + } + else + ERR("Unrecognized audio format %s\n", mime_type); + } + else + { + goto fail; + } + + return media_type; + fail: + IMFMediaType_Release(media_type); + return NULL; +}