Skip to content

Commit

Permalink
[GStreamer][VideoCapture] fix getVideoSizeAndFormatFromCaps/getVideoR…
Browse files Browse the repository at this point in the history
…esolutionFromCaps 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
  • Loading branch information
jameshilliard authored and philn committed Jul 4, 2022
1 parent d2b5507 commit fdb0e95
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp
Expand Up @@ -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))
Expand All @@ -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;
Expand All @@ -153,12 +156,8 @@ std::optional<FloatSize> 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))
Expand All @@ -168,6 +167,10 @@ std::optional<FloatSize> 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<float>(pixelAspectRatioDenominator) / static_cast<float>(pixelAspectRatioNumerator))));
Expand Down

0 comments on commit fdb0e95

Please sign in to comment.