[PATCH v3 5/6] winegstreamer: Check H264 ProcessOutput sample against actual image size.

Rémi Bernon wine at gitlab.winehq.org
Thu Jun 23 12:12:42 CDT 2022


From: Rémi Bernon <rbernon at codeweavers.com>

Instead of maximum output sample size returned from GetOutputStreamInfo.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=45988
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=47084
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=49715
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=52183
Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
 dlls/mf/tests/mf.c                | 114 ++++++------------------------
 dlls/winegstreamer/h264_decoder.c |  14 ++--
 2 files changed, 32 insertions(+), 96 deletions(-)

diff --git a/dlls/mf/tests/mf.c b/dlls/mf/tests/mf.c
index 7b598ba7dac..5108d2b2523 100644
--- a/dlls/mf/tests/mf.c
+++ b/dlls/mf/tests/mf.c
@@ -6675,8 +6675,6 @@ static void test_h264_decoder(void)
         },
     };
     static const DWORD input_width = 120, input_height = 248;
-    static const DWORD align_input_width = (input_width + 15) & ~15;
-    static const DWORD align_input_height = (input_height + 15) & ~15;
     const media_type_desc default_outputs[] =
     {
         {
@@ -6688,6 +6686,9 @@ static void test_h264_decoder(void)
             ATTR_UINT32(MF_MT_INTERLACE_MODE, 7),
             ATTR_UINT32(MF_MT_FIXED_SIZE_SAMPLES, 1),
             ATTR_UINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, 1),
+            ATTR_RATIO(MF_MT_FRAME_SIZE, input_width, input_height),
+            ATTR_UINT32(MF_MT_SAMPLE_SIZE, input_width * input_height * 3 / 2),
+            /* ATTR_UINT32(MF_MT_VIDEO_ROTATION, 0), missing on Win7 */
         },
         {
             ATTR_GUID(MF_MT_MAJOR_TYPE, MFMediaType_Video),
@@ -6698,6 +6699,9 @@ static void test_h264_decoder(void)
             ATTR_UINT32(MF_MT_INTERLACE_MODE, 7),
             ATTR_UINT32(MF_MT_FIXED_SIZE_SAMPLES, 1),
             ATTR_UINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, 1),
+            ATTR_RATIO(MF_MT_FRAME_SIZE, input_width, input_height),
+            ATTR_UINT32(MF_MT_SAMPLE_SIZE, input_width * input_height * 3 / 2),
+            /* ATTR_UINT32(MF_MT_VIDEO_ROTATION, 0), missing on Win7 */
         },
         {
             ATTR_GUID(MF_MT_MAJOR_TYPE, MFMediaType_Video),
@@ -6708,6 +6712,9 @@ static void test_h264_decoder(void)
             ATTR_UINT32(MF_MT_INTERLACE_MODE, 7),
             ATTR_UINT32(MF_MT_FIXED_SIZE_SAMPLES, 1),
             ATTR_UINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, 1),
+            ATTR_RATIO(MF_MT_FRAME_SIZE, input_width, input_height),
+            ATTR_UINT32(MF_MT_SAMPLE_SIZE, input_width * input_height * 3 / 2),
+            /* ATTR_UINT32(MF_MT_VIDEO_ROTATION, 0), missing on Win7 */
         },
         {
             ATTR_GUID(MF_MT_MAJOR_TYPE, MFMediaType_Video),
@@ -6718,6 +6725,9 @@ static void test_h264_decoder(void)
             ATTR_UINT32(MF_MT_INTERLACE_MODE, 7),
             ATTR_UINT32(MF_MT_FIXED_SIZE_SAMPLES, 1),
             ATTR_UINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, 1),
+            ATTR_RATIO(MF_MT_FRAME_SIZE, input_width, input_height),
+            ATTR_UINT32(MF_MT_SAMPLE_SIZE, input_width * input_height * 3 / 2),
+            /* ATTR_UINT32(MF_MT_VIDEO_ROTATION, 0), missing on Win7 */
         },
         {
             ATTR_GUID(MF_MT_MAJOR_TYPE, MFMediaType_Video),
@@ -6728,57 +6738,9 @@ static void test_h264_decoder(void)
             ATTR_UINT32(MF_MT_INTERLACE_MODE, 7),
             ATTR_UINT32(MF_MT_FIXED_SIZE_SAMPLES, 1),
             ATTR_UINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, 1),
-        },
-    };
-    const media_type_desc default_outputs_extra[] =
-    {
-        {
-            ATTR_RATIO(MF_MT_FRAME_SIZE, input_width, input_height),
-            ATTR_UINT32(MF_MT_SAMPLE_SIZE, input_width * input_height * 3 / 2),
-            ATTR_UINT32(MF_MT_VIDEO_ROTATION, 0),
-        },
-        {
-            ATTR_RATIO(MF_MT_FRAME_SIZE, input_width, input_height),
-            ATTR_UINT32(MF_MT_SAMPLE_SIZE, input_width * input_height * 3 / 2),
-            ATTR_UINT32(MF_MT_VIDEO_ROTATION, 0),
-        },
-        {
-            ATTR_RATIO(MF_MT_FRAME_SIZE, input_width, input_height),
-            ATTR_UINT32(MF_MT_SAMPLE_SIZE, input_width * input_height * 3 / 2),
-            ATTR_UINT32(MF_MT_VIDEO_ROTATION, 0),
-        },
-        {
-            ATTR_RATIO(MF_MT_FRAME_SIZE, input_width, input_height),
-            ATTR_UINT32(MF_MT_SAMPLE_SIZE, input_width * input_height * 3 / 2),
-            ATTR_UINT32(MF_MT_VIDEO_ROTATION, 0),
-        },
-        {
             ATTR_RATIO(MF_MT_FRAME_SIZE, input_width, input_height),
             ATTR_UINT32(MF_MT_SAMPLE_SIZE, input_width * input_height * 2),
-            ATTR_UINT32(MF_MT_VIDEO_ROTATION, 0),
-        },
-    };
-    const media_type_desc default_outputs_win7[] =
-    {
-        {
-            ATTR_RATIO(MF_MT_FRAME_SIZE, align_input_width, align_input_height),
-            ATTR_UINT32(MF_MT_SAMPLE_SIZE, align_input_width * align_input_height * 3 / 2),
-        },
-        {
-            ATTR_RATIO(MF_MT_FRAME_SIZE, align_input_width, align_input_height),
-            ATTR_UINT32(MF_MT_SAMPLE_SIZE, align_input_width * align_input_height * 3 / 2),
-        },
-        {
-            ATTR_RATIO(MF_MT_FRAME_SIZE, align_input_width, align_input_height),
-            ATTR_UINT32(MF_MT_SAMPLE_SIZE, align_input_width * align_input_height * 3 / 2),
-        },
-        {
-            ATTR_RATIO(MF_MT_FRAME_SIZE, align_input_width, align_input_height),
-            ATTR_UINT32(MF_MT_SAMPLE_SIZE, align_input_width * align_input_height * 3 / 2),
-        },
-        {
-            ATTR_RATIO(MF_MT_FRAME_SIZE, align_input_width, align_input_height),
-            ATTR_UINT32(MF_MT_SAMPLE_SIZE, align_input_width * align_input_height * 2),
+            /* ATTR_UINT32(MF_MT_VIDEO_ROTATION, 0), missing on Win7 */
         },
     };
     const struct attribute_desc input_type_desc[] =
@@ -6807,18 +6769,6 @@ static void test_h264_decoder(void)
         ATTR_UINT32(MF_MT_VIDEO_ROTATION, 0),
         {0},
     };
-    const struct attribute_desc output_type_desc_win7[] =
-    {
-        ATTR_GUID(MF_MT_MAJOR_TYPE, MFMediaType_Video),
-        ATTR_GUID(MF_MT_SUBTYPE, MFVideoFormat_NV12),
-        ATTR_RATIO(MF_MT_FRAME_SIZE, align_input_width, align_input_height),
-        ATTR_RATIO(MF_MT_FRAME_RATE, 60000, 1000),
-        ATTR_RATIO(MF_MT_PIXEL_ASPECT_RATIO, 2, 1),
-        ATTR_UINT32(MF_MT_DEFAULT_STRIDE, 3840),
-        ATTR_UINT32(MF_MT_SAMPLE_SIZE, 3840 * align_input_height * 3 / 2),
-        ATTR_UINT32(MF_MT_VIDEO_ROTATION, 0),
-        {0},
-    };
     static const struct attribute_desc new_output_type_desc[] =
     {
         ATTR_GUID(MF_MT_MAJOR_TYPE, MFMediaType_Video),
@@ -6828,15 +6778,6 @@ static void test_h264_decoder(void)
         ATTR_RATIO(MF_MT_PIXEL_ASPECT_RATIO, 1, 2),
         {0},
     };
-    static const struct attribute_desc new_output_type_desc_win7[] =
-    {
-        ATTR_GUID(MF_MT_MAJOR_TYPE, MFMediaType_Video),
-        ATTR_GUID(MF_MT_SUBTYPE, MFVideoFormat_I420),
-        ATTR_RATIO(MF_MT_FRAME_SIZE, 96, 96),
-        ATTR_RATIO(MF_MT_FRAME_RATE, 1, 1),
-        ATTR_RATIO(MF_MT_PIXEL_ASPECT_RATIO, 1, 2),
-        {0},
-    };
     static const MFVideoArea actual_aperture = {.Area={82,84}};
     static const DWORD actual_width = 96, actual_height = 96;
     const media_type_desc actual_outputs[] =
@@ -6928,7 +6869,6 @@ static void test_h264_decoder(void)
     IMFMediaType *media_type;
     LONGLONG time, duration;
     IMFTransform *transform;
-    BOOL is_win7 = FALSE;
     ULONG i, ret, flags;
     HANDLE output_file;
     IMFSample *sample;
@@ -7033,9 +6973,7 @@ static void test_h264_decoder(void)
     ok(hr == S_OK, "GetOutputStreamInfo returned %#lx\n", hr);
     ok(output_info.dwFlags == flags, "got dwFlags %#lx\n", output_info.dwFlags);
     todo_wine
-    ok(output_info.cbSize == input_width * input_height * 2
-            || broken(output_info.cbSize == align_input_width * align_input_height * 2) /* Win7 */,
-            "got cbSize %#lx\n", output_info.cbSize);
+    ok(output_info.cbSize == input_width * input_height * 2, "got cbSize %#lx\n", output_info.cbSize);
     ok(output_info.cbAlignment == 0, "got cbAlignment %#lx\n", output_info.cbAlignment);
 
     /* output types can now be enumerated (though they are actually the same for all input types) */
@@ -7046,9 +6984,6 @@ static void test_h264_decoder(void)
         winetest_push_context("out %lu", i);
         ok(hr == S_OK, "GetOutputAvailableType returned %#lx\n", hr);
         check_media_type(media_type, default_outputs[i], -1);
-        hr = IMFMediaType_GetItem(media_type, &MF_MT_VIDEO_ROTATION, NULL);
-        is_win7 = broken(FAILED(hr));
-        check_media_type(media_type, is_win7 ? default_outputs_win7[i] : default_outputs_extra[i], -1);
         ret = IMFMediaType_Release(media_type);
         ok(ret == 0, "Release returned %lu\n", ret);
         winetest_pop_context();
@@ -7076,8 +7011,8 @@ static void test_h264_decoder(void)
         init_media_type(media_type, minimal_output_type_desc, i + 1);
     }
     hr = IMFTransform_SetOutputType(transform, 0, media_type, 0);
-    ok(hr == (is_win7 ? MF_E_INVALIDMEDIATYPE : S_OK), "SetOutputType returned %#lx.\n", hr);
-    init_media_type(media_type, is_win7 ? output_type_desc_win7 : output_type_desc, -1);
+    ok(hr == S_OK, "SetOutputType returned %#lx.\n", hr);
+    init_media_type(media_type, output_type_desc, -1);
     hr = IMFTransform_SetOutputType(transform, 0, media_type, 0);
     ok(hr == S_OK, "SetOutputType returned %#lx.\n", hr);
     ret = IMFMediaType_Release(media_type);
@@ -7085,7 +7020,7 @@ static void test_h264_decoder(void)
 
     hr = IMFTransform_GetOutputCurrentType(transform, 0, &media_type);
     ok(hr == S_OK, "GetOutputCurrentType returned %#lx\n", hr);
-    check_media_type(media_type, is_win7 ? output_type_desc_win7 : output_type_desc, -1);
+    check_media_type(media_type, output_type_desc, -1);
     ret = IMFMediaType_Release(media_type);
     ok(ret == 0, "Release returned %lu\n", ret);
 
@@ -7097,7 +7032,6 @@ static void test_h264_decoder(void)
         winetest_push_context("out %lu", i);
         ok(hr == S_OK, "GetOutputAvailableType returned %#lx\n", hr);
         check_media_type(media_type, default_outputs[i], -1);
-        check_media_type(media_type, is_win7 ? default_outputs_win7[i] : default_outputs_extra[i], -1);
         ret = IMFMediaType_Release(media_type);
         ok(ret == 0, "Release returned %lu\n", ret);
         winetest_pop_context();
@@ -7121,9 +7055,7 @@ static void test_h264_decoder(void)
     ok(hr == S_OK, "GetOutputStreamInfo returned %#lx\n", hr);
     ok(output_info.dwFlags == flags, "got dwFlags %#lx\n", output_info.dwFlags);
     todo_wine
-    ok(output_info.cbSize == input_width * input_height * 2
-            || broken(output_info.cbSize == align_input_width * align_input_height * 2) /* Win7 */,
-            "got cbSize %#lx\n", output_info.cbSize);
+    ok(output_info.cbSize == input_width * input_height * 2, "got cbSize %#lx\n", output_info.cbSize);
     ok(output_info.cbAlignment == 0, "got cbAlignment %#lx\n", output_info.cbAlignment);
 
     input_count = output_count = 0xdeadbeef;
@@ -7234,7 +7166,7 @@ static void test_h264_decoder(void)
     /* current output type is still the one we selected */
     hr = IMFTransform_GetOutputCurrentType(transform, 0, &media_type);
     ok(hr == S_OK, "GetOutputCurrentType returned %#lx\n", hr);
-    check_media_type(media_type, is_win7 ? output_type_desc_win7 : output_type_desc, -1);
+    check_media_type(media_type, output_type_desc, -1);
     hr = IMFMediaType_GetItemType(media_type, &MF_MT_MINIMUM_DISPLAY_APERTURE, NULL);
     ok(hr == MF_E_ATTRIBUTENOTFOUND, "GetItemType returned %#lx\n", hr);
     ret = IMFMediaType_Release(media_type);
@@ -7254,7 +7186,7 @@ static void test_h264_decoder(void)
 
     status = 0;
     memset(&output, 0, sizeof(output));
-    output.pSample = create_sample(NULL, actual_width * actual_height * 2);
+    output.pSample = create_sample(NULL, actual_width * actual_height * 3 / 2);
     hr = IMFTransform_ProcessOutput(transform, 0, 1, &output, &status);
     ok(hr == S_OK, "ProcessOutput returned %#lx\n", hr);
     ok(output.dwStreamID == 0, "got dwStreamID %lu\n", output.dwStreamID);
@@ -7318,10 +7250,10 @@ static void test_h264_decoder(void)
     /* we can change it, but only with the correct frame size */
     hr = MFCreateMediaType(&media_type);
     ok(hr == S_OK, "MFCreateMediaType returned %#lx\n", hr);
-    init_media_type(media_type, is_win7 ? output_type_desc_win7 : output_type_desc, -1);
+    init_media_type(media_type, output_type_desc, -1);
     hr = IMFTransform_SetOutputType(transform, 0, media_type, 0);
     ok(hr == MF_E_INVALIDMEDIATYPE, "SetOutputType returned %#lx.\n", hr);
-    init_media_type(media_type, is_win7 ? new_output_type_desc_win7 : new_output_type_desc, -1);
+    init_media_type(media_type, new_output_type_desc, -1);
     hr = IMFTransform_SetOutputType(transform, 0, media_type, 0);
     ok(hr == S_OK, "SetOutputType returned %#lx.\n", hr);
     ret = IMFMediaType_Release(media_type);
@@ -7329,7 +7261,7 @@ static void test_h264_decoder(void)
 
     hr = IMFTransform_GetOutputCurrentType(transform, 0, &media_type);
     ok(hr == S_OK, "GetOutputCurrentType returned %#lx\n", hr);
-    check_media_type(media_type, is_win7 ? new_output_type_desc_win7 : new_output_type_desc, -1);
+    check_media_type(media_type, new_output_type_desc, -1);
     hr = IMFMediaType_GetItemType(media_type, &MF_MT_MINIMUM_DISPLAY_APERTURE, NULL);
     ok(hr == MF_E_ATTRIBUTENOTFOUND, "GetItemType returned %#lx\n", hr);
     ret = IMFMediaType_Release(media_type);
diff --git a/dlls/winegstreamer/h264_decoder.c b/dlls/winegstreamer/h264_decoder.c
index 2ece7dee5b1..561a3c1578c 100644
--- a/dlls/winegstreamer/h264_decoder.c
+++ b/dlls/winegstreamer/h264_decoder.c
@@ -581,10 +581,11 @@ static HRESULT WINAPI transform_ProcessOutput(IMFTransform *iface, DWORD flags,
         MFT_OUTPUT_DATA_BUFFER *samples, DWORD *status)
 {
     struct h264_decoder *decoder = impl_from_IMFTransform(iface);
-    MFT_OUTPUT_STREAM_INFO info;
     struct wg_sample *wg_sample;
     struct wg_format wg_format;
+    UINT32 sample_size;
     UINT64 frame_rate;
+    GUID subtype;
     HRESULT hr;
 
     TRACE("iface %p, flags %#lx, count %lu, samples %p, status %p.\n", iface, flags, count, samples, status);
@@ -592,9 +593,6 @@ static HRESULT WINAPI transform_ProcessOutput(IMFTransform *iface, DWORD flags,
     if (count != 1)
         return E_INVALIDARG;
 
-    if (FAILED(hr = IMFTransform_GetOutputStreamInfo(iface, 0, &info)))
-        return hr;
-
     if (!decoder->wg_transform)
         return MF_E_TRANSFORM_TYPE_NOT_SET;
 
@@ -602,10 +600,16 @@ static HRESULT WINAPI transform_ProcessOutput(IMFTransform *iface, DWORD flags,
     samples[0].dwStatus = 0;
     if (!samples[0].pSample) return E_INVALIDARG;
 
+    if (FAILED(hr = IMFMediaType_GetGUID(decoder->output_type, &MF_MT_SUBTYPE, &subtype)))
+        return hr;
+    if (FAILED(hr = MFCalculateImageSize(&subtype, decoder->wg_format.u.video.width,
+            decoder->wg_format.u.video.height, &sample_size)))
+        return hr;
+
     if (FAILED(hr = wg_sample_create_mf(samples[0].pSample, &wg_sample)))
         return hr;
 
-    if (wg_sample->max_size < info.cbSize)
+    if (wg_sample->max_size < sample_size)
     {
         wg_sample_release(wg_sample);
         return MF_E_BUFFERTOOSMALL;
-- 
GitLab


https://gitlab.winehq.org/wine/wine/-/merge_requests/302



More information about the wine-devel mailing list