From: Yuxuan Shui <yshui@codeweavers.com> --- dlls/mfreadwrite/reader.c | 36 +++++++++++++++++++++++++++++++-- dlls/mfreadwrite/tests/mfplat.c | 14 ++++++------- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/dlls/mfreadwrite/reader.c b/dlls/mfreadwrite/reader.c index 718c8817198..27c357179d6 100644 --- a/dlls/mfreadwrite/reader.c +++ b/dlls/mfreadwrite/reader.c @@ -714,19 +714,51 @@ static void media_type_try_copy_attr(IMFMediaType *dst, IMFMediaType *src, const PropVariantClear(&value); } +static HRESULT media_type_get_uint32_pair(IMFMediaType *type, const GUID *key, UINT32 *hi, UINT32 *lo) +{ + UINT64 data; + HRESULT hr = IMFMediaType_GetUINT64(type, key, &data); + if (FAILED(hr)) return hr; + + *hi = data >> 32; + *lo = data & 0xffffffff; + return hr; +} /* Update a media type with additional attributes reported by another media type, */ /* also present as update_media_type_from_upstream in mf/topology_loader.c pipeline. */ HRESULT update_media_type(IMFMediaType *dst_type, IMFMediaType *src_type, BOOL advanced) { HRESULT hr = S_OK; + UINT64 dst_frame_size; + UINT32 par_w, par_h, w, h; + + if (advanced && SUCCEEDED(media_type_get_uint32_pair(src_type, &MF_MT_FRAME_SIZE, &w, &h)) && + FAILED(IMFMediaType_GetUINT64(dst_type, &MF_MT_FRAME_SIZE, &dst_frame_size)) && + SUCCEEDED(media_type_get_uint32_pair(src_type, &MF_MT_PIXEL_ASPECT_RATIO, &par_w, &par_h))) + { + /* Video processor should rectify the aspect ratio so the output has aspect ratio of 1:1. + * We are doing this here by explicitly changing the target frame size. */ + + UINT64 new_h = h, new_w = w; + if (par_w < par_h) new_h = h * par_h / par_w; + else new_w = w * par_w / par_h; + + new_h = (new_h + 1) & ~1; + new_w = (new_w + 1) & ~1; + + IMFMediaType_SetUINT64(dst_type, &MF_MT_FRAME_SIZE, ((UINT64)new_w << 32) + new_h); + } + else + { + media_type_try_copy_attr(dst_type, src_type, &MF_MT_FRAME_SIZE, &hr); + media_type_try_copy_attr(dst_type, src_type, &MF_MT_PIXEL_ASPECT_RATIO, &hr); + } /* propagate common video attributes */ - media_type_try_copy_attr(dst_type, src_type, &MF_MT_FRAME_SIZE, &hr); media_type_try_copy_attr(dst_type, src_type, &MF_MT_FRAME_RATE, &hr); media_type_try_copy_attr(dst_type, src_type, &MF_MT_VIDEO_ROTATION, &hr); media_type_try_copy_attr(dst_type, src_type, &MF_MT_FIXED_SIZE_SAMPLES, &hr); - media_type_try_copy_attr(dst_type, src_type, &MF_MT_PIXEL_ASPECT_RATIO, &hr); media_type_try_copy_attr(dst_type, src_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, &hr); media_type_try_copy_attr(dst_type, src_type, &MF_MT_MINIMUM_DISPLAY_APERTURE, &hr); diff --git a/dlls/mfreadwrite/tests/mfplat.c b/dlls/mfreadwrite/tests/mfplat.c index 4dfe4aa9d05..1da6d7a2664 100644 --- a/dlls/mfreadwrite/tests/mfplat.c +++ b/dlls/mfreadwrite/tests/mfplat.c @@ -1194,14 +1194,14 @@ static void test_source_reader_aspect_ratio(void) { ATTR_GUID(MF_MT_MAJOR_TYPE, MFMediaType_Video), ATTR_GUID(MF_MT_SUBTYPE, MFVideoFormat_ARGB32), - ATTR_RATIO(MF_MT_FRAME_SIZE, 128, 128, .todo_value = TRUE), - ATTR_RATIO(MF_MT_PIXEL_ASPECT_RATIO, 3, 4, .not_present = TRUE, .todo = TRUE), + ATTR_RATIO(MF_MT_FRAME_SIZE, 128, 128), + ATTR_RATIO(MF_MT_PIXEL_ASPECT_RATIO, 1, 1, .not_present = TRUE, .todo = TRUE), {0}, }, { ATTR_GUID(MF_MT_MAJOR_TYPE, MFMediaType_Video), ATTR_GUID(MF_MT_SUBTYPE, MFVideoFormat_ARGB32), - ATTR_RATIO(MF_MT_FRAME_SIZE, 128, 128, .todo_value = TRUE), + ATTR_RATIO(MF_MT_FRAME_SIZE, 128, 128), ATTR_RATIO(MF_MT_PIXEL_ASPECT_RATIO, 4, 3, .not_present = TRUE, .todo = TRUE), {0}, }, @@ -1258,10 +1258,10 @@ static void test_source_reader_aspect_ratio(void) }; static const struct attribute_desc output_desc_for_input_desc[] = { - ATTR_RATIO(MF_MT_FRAME_SIZE, 128, 128, .todo_value = TRUE), - ATTR_RATIO(MF_MT_FRAME_SIZE, 128, 214, .todo_value = TRUE), - ATTR_RATIO(MF_MT_FRAME_SIZE, 128, 128, .todo_value = TRUE), - ATTR_RATIO(MF_MT_FRAME_SIZE, 96, 256, .todo_value = TRUE), + ATTR_RATIO(MF_MT_FRAME_SIZE, 128, 128), + ATTR_RATIO(MF_MT_FRAME_SIZE, 128, 214), + ATTR_RATIO(MF_MT_FRAME_SIZE, 128, 128), + ATTR_RATIO(MF_MT_FRAME_SIZE, 96, 256), }; IMFStreamDescriptor *video_streams[4]; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10535