From fdb0e95ecfc0a8c011ed589562dd4162551d0f5a Mon Sep 17 00:00:00 2001 From: James Hilliard Date: Mon, 4 Jul 2022 02:33:57 -0700 Subject: [PATCH] [GStreamer][VideoCapture] fix getVideoSizeAndFormatFromCaps/getVideoResolutionFromCaps for video/x-raw mime-type caps without format https://bugs.webkit.org/show_bug.cgi?id=242290 Reviewed by Philippe Normand. Fixes: 0:00:02.001539663 1169 0x5577d2b74810 DEBUG video-info video-info.c:406:gst_video_info_from_caps: parsing caps video/x-raw 0:00:02.001842884 1169 0x5577d2b74810 ERROR video-info video-info.c:546:gst_video_info_from_caps: no format given 0:00:02.002197896 1169 0x5577d2b74810 INFO webkitvideocapturer GStreamerVideoCapturer.cpp:136:setSize: Setting size to 640x480 * Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp: (WebCore::getVideoSizeAndFormatFromCaps): (WebCore::getVideoResolutionFromCaps): Canonical link: https://commits.webkit.org/252112@main --- .../graphics/gstreamer/GStreamerCommon.cpp | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp index 17f35e87bb3f..f9553d70a966 100644 --- a/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp @@ -112,21 +112,8 @@ bool getVideoSizeAndFormatFromCaps(const GstCaps* caps, WebCore::IntSize& size, return false; } - if (areEncryptedCaps(caps)) { - GstStructure* structure = gst_caps_get_structure(caps, 0); - format = GST_VIDEO_FORMAT_ENCODED; - stride = 0; - int width = 0, height = 0; - gst_structure_get_int(structure, "width", &width); - gst_structure_get_int(structure, "height", &height); - if (!gst_structure_get_fraction(structure, "pixel-aspect-ratio", &pixelAspectRatioNumerator, &pixelAspectRatioDenominator)) { - pixelAspectRatioNumerator = 1; - pixelAspectRatioDenominator = 1; - } - - size.setWidth(width); - size.setHeight(height); - } else { + GstStructure* structure = gst_caps_get_structure(caps, 0); + if (!areEncryptedCaps(caps) && (!gst_structure_has_name(structure, "video/x-raw") || gst_structure_has_field(structure, "format"))) { GstVideoInfo info; gst_video_info_init(&info); if (!gst_video_info_from_caps(&info, caps)) @@ -138,6 +125,22 @@ bool getVideoSizeAndFormatFromCaps(const GstCaps* caps, WebCore::IntSize& size, pixelAspectRatioNumerator = GST_VIDEO_INFO_PAR_N(&info); pixelAspectRatioDenominator = GST_VIDEO_INFO_PAR_D(&info); stride = GST_VIDEO_INFO_PLANE_STRIDE(&info, 0); + } else { + if (areEncryptedCaps(caps)) + format = GST_VIDEO_FORMAT_ENCODED; + else + format = GST_VIDEO_FORMAT_UNKNOWN; + stride = 0; + int width = 0, height = 0; + gst_structure_get_int(structure, "width", &width); + gst_structure_get_int(structure, "height", &height); + if (!gst_structure_get_fraction(structure, "pixel-aspect-ratio", &pixelAspectRatioNumerator, &pixelAspectRatioDenominator)) { + pixelAspectRatioNumerator = 1; + pixelAspectRatioDenominator = 1; + } + + size.setWidth(width); + size.setHeight(height); } return true; @@ -153,12 +156,8 @@ std::optional getVideoResolutionFromCaps(const GstCaps* caps) int width = 0, height = 0; int pixelAspectRatioNumerator = 1, pixelAspectRatioDenominator = 1; - if (areEncryptedCaps(caps)) { - GstStructure* structure = gst_caps_get_structure(caps, 0); - gst_structure_get_int(structure, "width", &width); - gst_structure_get_int(structure, "height", &height); - gst_structure_get_fraction(structure, "pixel-aspect-ratio", &pixelAspectRatioNumerator, &pixelAspectRatioDenominator); - } else { + GstStructure* structure = gst_caps_get_structure(caps, 0); + if (!areEncryptedCaps(caps) && (!gst_structure_has_name(structure, "video/x-raw") || gst_structure_has_field(structure, "format"))) { GstVideoInfo info; gst_video_info_init(&info); if (!gst_video_info_from_caps(&info, caps)) @@ -168,6 +167,10 @@ std::optional getVideoResolutionFromCaps(const GstCaps* caps) height = GST_VIDEO_INFO_HEIGHT(&info); pixelAspectRatioNumerator = GST_VIDEO_INFO_PAR_N(&info); pixelAspectRatioDenominator = GST_VIDEO_INFO_PAR_D(&info); + } else { + gst_structure_get_int(structure, "width", &width); + gst_structure_get_int(structure, "height", &height); + gst_structure_get_fraction(structure, "pixel-aspect-ratio", &pixelAspectRatioNumerator, &pixelAspectRatioDenominator); } return std::make_optional(FloatSize(width, height * (static_cast(pixelAspectRatioDenominator) / static_cast(pixelAspectRatioNumerator))));