Module: wine Branch: master Commit: e497f0e88d32fc2a5f566cca4abd83004437c108 URL: https://gitlab.winehq.org/wine/wine/-/commit/e497f0e88d32fc2a5f566cca4abd830...
Author: Rémi Bernon rbernon@codeweavers.com Date: Sat Feb 17 14:07:00 2024 +0100
mfplat/mediatype: Implement implicit MFInitMediaTypeFromVideoInfoHeader subtype.
---
dlls/mfplat/mediatype.c | 37 +++++++++++++++++++++++++++++-------- dlls/mfplat/tests/mfplat.c | 28 +++++++--------------------- 2 files changed, 36 insertions(+), 29 deletions(-)
diff --git a/dlls/mfplat/mediatype.c b/dlls/mfplat/mediatype.c index 66c0aaa2c62..afe611000a5 100644 --- a/dlls/mfplat/mediatype.c +++ b/dlls/mfplat/mediatype.c @@ -2697,13 +2697,14 @@ struct uncompressed_video_format
static int __cdecl uncompressed_video_format_compare(const void *a, const void *b) { - const GUID *guid = a; - const struct uncompressed_video_format *format = b; - return memcmp(guid, format->subtype, sizeof(*guid)); + const struct uncompressed_video_format *a_format = a, *b_format = b; + return memcmp(a_format->subtype, b_format->subtype, sizeof(GUID)); }
-static const struct uncompressed_video_format video_formats[] = +static struct uncompressed_video_format video_formats[] = { + { &MFVideoFormat_RGB1, 1, 0, 1, 0, BI_RGB }, + { &MFVideoFormat_RGB4, 4, 0, 1, 0, BI_RGB }, { &MFVideoFormat_RGB24, 24, 3, 1, 0, BI_RGB }, { &MFVideoFormat_ARGB32, 32, 3, 1, 0, BI_RGB }, { &MFVideoFormat_RGB32, 32, 3, 1, 0, BI_RGB }, @@ -2736,14 +2737,26 @@ static const struct uncompressed_video_format video_formats[] = { &MEDIASUBTYPE_RGB32, 32, 3, 1, 0, BI_RGB }, };
+static BOOL WINAPI mf_video_formats_init(INIT_ONCE *once, void *param, void **context) +{ + qsort(video_formats, ARRAY_SIZE(video_formats), sizeof(*video_formats), uncompressed_video_format_compare); + return TRUE; +} + static struct uncompressed_video_format *mf_get_video_format(const GUID *subtype) { - return bsearch(subtype, video_formats, ARRAY_SIZE(video_formats), sizeof(*video_formats), + static INIT_ONCE init_once = INIT_ONCE_STATIC_INIT; + struct uncompressed_video_format key = {.subtype = subtype}; + + InitOnceExecuteOnce(&init_once, mf_video_formats_init, NULL, NULL); + + return bsearch(&key, video_formats, ARRAY_SIZE(video_formats), sizeof(*video_formats), uncompressed_video_format_compare); }
static unsigned int mf_get_stride_for_format(const struct uncompressed_video_format *format, unsigned int width) { + if (format->bpp < 8) return (width * format->bpp) / 8; return (width * (format->bpp / 8) + format->alignment) & ~format->alignment; }
@@ -3743,14 +3756,22 @@ HRESULT WINAPI MFInitMediaTypeFromVideoInfoHeader(IMFMediaType *media_type, cons DWORD height; LONG stride;
- FIXME("%p, %p, %u, %s.\n", media_type, vih, size, debugstr_guid(subtype)); + TRACE("%p, %p, %u, %s.\n", media_type, vih, size, debugstr_guid(subtype));
IMFMediaType_DeleteAllItems(media_type);
if (!subtype) { - FIXME("Implicit subtype is not supported.\n"); - return E_NOTIMPL; + switch (vih->bmiHeader.biBitCount) + { + case 1: subtype = &MFVideoFormat_RGB1; break; + case 4: subtype = &MFVideoFormat_RGB4; break; + case 8: subtype = &MFVideoFormat_RGB8; break; + case 16: subtype = &MFVideoFormat_RGB555; break; + case 24: subtype = &MFVideoFormat_RGB24; break; + case 32: subtype = &MFVideoFormat_RGB32; break; + default: return E_INVALIDARG; + } }
height = abs(vih->bmiHeader.biHeight); diff --git a/dlls/mfplat/tests/mfplat.c b/dlls/mfplat/tests/mfplat.c index 2c48852b4d4..30f6d4b248e 100644 --- a/dlls/mfplat/tests/mfplat.c +++ b/dlls/mfplat/tests/mfplat.c @@ -9854,10 +9854,8 @@ static void test_MFInitMediaTypeFromVideoInfoHeader(void)
memset(&vih, 0, sizeof(vih)); hr = MFInitMediaTypeFromVideoInfoHeader(media_type, &vih, 0, NULL); - todo_wine ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr); hr = MFInitMediaTypeFromVideoInfoHeader(media_type, &vih, sizeof(vih), NULL); - todo_wine ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
hr = MFInitMediaTypeFromVideoInfoHeader(media_type, &vih, sizeof(vih), &GUID_NULL); @@ -9974,7 +9972,6 @@ static void test_MFInitMediaTypeFromVideoInfoHeader(void)
/* biBitCount is used for implicit RGB format if GUID is NULL */ hr = MFInitMediaTypeFromVideoInfoHeader(media_type, &vih, sizeof(vih), NULL); - todo_wine ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
for (vih.bmiHeader.biBitCount = 1; vih.bmiHeader.biBitCount <= 32; vih.bmiHeader.biBitCount++) @@ -9984,35 +9981,31 @@ static void test_MFInitMediaTypeFromVideoInfoHeader(void) hr = MFInitMediaTypeFromVideoInfoHeader(media_type, &vih, sizeof(vih), NULL); if (vih.bmiHeader.biBitCount != 1 && vih.bmiHeader.biBitCount != 4 && vih.bmiHeader.biBitCount != 8 && vih.bmiHeader.biBitCount != 16 && vih.bmiHeader.biBitCount != 24 && vih.bmiHeader.biBitCount != 32) - todo_wine ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr); + ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr); else { - todo_wine ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
memset(&guid, 0xcd, sizeof(guid)); hr = IMFMediaType_GetGUID(media_type, &MF_MT_SUBTYPE, &guid); - todo_wine ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); if (vih.bmiHeader.biBitCount == 32) - todo_wine ok(IsEqualGUID(&guid, &MFVideoFormat_RGB32), "Unexpected guid %s.\n", debugstr_guid(&guid)); + ok(IsEqualGUID(&guid, &MFVideoFormat_RGB32), "Unexpected guid %s.\n", debugstr_guid(&guid)); else if (vih.bmiHeader.biBitCount == 24) - todo_wine ok(IsEqualGUID(&guid, &MFVideoFormat_RGB24), "Unexpected guid %s.\n", debugstr_guid(&guid)); + ok(IsEqualGUID(&guid, &MFVideoFormat_RGB24), "Unexpected guid %s.\n", debugstr_guid(&guid)); else if (vih.bmiHeader.biBitCount == 16) - todo_wine ok(IsEqualGUID(&guid, &MFVideoFormat_RGB555), "Unexpected guid %s.\n", debugstr_guid(&guid)); + ok(IsEqualGUID(&guid, &MFVideoFormat_RGB555), "Unexpected guid %s.\n", debugstr_guid(&guid)); else if (vih.bmiHeader.biBitCount == 8) - todo_wine ok(IsEqualGUID(&guid, &MFVideoFormat_RGB8), "Unexpected guid %s.\n", debugstr_guid(&guid)); + ok(IsEqualGUID(&guid, &MFVideoFormat_RGB8), "Unexpected guid %s.\n", debugstr_guid(&guid)); else if (vih.bmiHeader.biBitCount == 4) - todo_wine ok(IsEqualGUID(&guid, &MFVideoFormat_RGB4), "Unexpected guid %s.\n", debugstr_guid(&guid)); + ok(IsEqualGUID(&guid, &MFVideoFormat_RGB4), "Unexpected guid %s.\n", debugstr_guid(&guid)); else if (vih.bmiHeader.biBitCount == 1) - todo_wine ok(IsEqualGUID(&guid, &MFVideoFormat_RGB1), "Unexpected guid %s.\n", debugstr_guid(&guid)); + ok(IsEqualGUID(&guid, &MFVideoFormat_RGB1), "Unexpected guid %s.\n", debugstr_guid(&guid));
value32 = 0xdeadbeef; hr = IMFMediaType_GetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, &value32); - todo_wine ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); if (vih.bmiHeader.biBitCount > 1) - todo_wine ok(value32 == 16 * vih.bmiHeader.biBitCount / 8, "Unexpected value %#x.\n", value32); else todo_wine ok(value32 == -4, "Unexpected value %#x.\n", value32); @@ -10025,27 +10018,20 @@ static void test_MFInitMediaTypeFromVideoInfoHeader(void)
value32 = 0xdeadbeef; hr = IMFMediaType_GetUINT32(media_type, &MF_MT_FIXED_SIZE_SAMPLES, &value32); - todo_wine ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); - todo_wine ok(value32 == 1, "Unexpected value %#x.\n", value32); value32 = 0xdeadbeef; hr = IMFMediaType_GetUINT32(media_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, &value32); - todo_wine ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); - todo_wine ok(value32 == 1, "Unexpected value %#x.\n", value32);
value32 = 0xdeadbeef; vih.bmiHeader.biHeight = 32; hr = MFInitMediaTypeFromVideoInfoHeader(media_type, &vih, sizeof(vih), NULL); - todo_wine ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); hr = IMFMediaType_GetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, &value32); - todo_wine ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); if (vih.bmiHeader.biBitCount > 1) - todo_wine ok(value32 == -16 * vih.bmiHeader.biBitCount / 8, "Unexpected value %#x.\n", value32); else todo_wine ok(value32 == -4, "Unexpected value %#x.\n", value32);