Skip to content

Commit

Permalink
[WPE][Debug]: fast/mediastream/captureStream/canvas3d.html crashes wi…
Browse files Browse the repository at this point in the history
…th error gst_sample_get_caps: assertion 'GST_IS_SAMPLE (sample)' failed

https://bugs.webkit.org/show_bug.cgi?id=259915

Reviewed by Carlos Garcia Campos.

Report video frame conversion errors and gracefully handle them in the player.

* Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::videoFrameForCurrentTime):
* Source/WebCore/platform/graphics/gstreamer/VideoFrameGStreamer.cpp:
(WebCore::VideoFrameGStreamer::convert):

Canonical link: https://commits.webkit.org/266723@main
  • Loading branch information
philn committed Aug 9, 2023
1 parent 84a762a commit 6204c35
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3873,6 +3873,9 @@ RefPtr<VideoFrame> MediaPlayerPrivateGStreamer::videoFrameForCurrentTime()
auto* buffer = gst_sample_get_buffer(m_sample.get());
auto frame = VideoFrameGStreamer::createWrappedSample(m_sample.get(), fromGstClockTime(GST_BUFFER_PTS(buffer)));
auto convertedSample = frame->downloadSample(GST_VIDEO_FORMAT_BGRA);
if (!convertedSample)
return nullptr;

auto size = getVideoResolutionFromCaps(gst_sample_get_caps(m_sample.get())).value_or(FloatSize { 0, 0 });
return VideoFrameGStreamer::create(WTFMove(convertedSample), size);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,25 +466,27 @@ GRefPtr<GstSample> VideoFrameGStreamer::resizedSample(const IntSize& destination
GRefPtr<GstSample> VideoFrameGStreamer::convert(GstVideoFormat format, const IntSize& destinationSize)
{
auto* caps = gst_sample_get_caps(m_sample.get());

const auto* structure = gst_caps_get_structure(caps, 0);
int frameRateNumerator, frameRateDenominator;
if (!gst_structure_get_fraction(structure, "framerate", &frameRateNumerator, &frameRateDenominator)) {
frameRateNumerator = 1;
frameRateDenominator = 1;
}

GstVideoInfo inputInfo;
gst_video_info_from_caps(&inputInfo, caps);

auto width = destinationSize.width();
auto height = destinationSize.height();
auto outputCaps = adoptGRef(gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, gst_video_format_to_string(format), "width", G_TYPE_INT, width, "height", G_TYPE_INT, height, "framerate", GST_TYPE_FRACTION, frameRateNumerator, frameRateDenominator, nullptr));
const char* formatName = gst_video_format_to_string(format);
auto outputCaps = adoptGRef(gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, formatName, "width", G_TYPE_INT, width, "height", G_TYPE_INT, height, "framerate", GST_TYPE_FRACTION, frameRateNumerator, frameRateDenominator, nullptr));

if (gst_caps_is_equal(caps, outputCaps.get()))
return GRefPtr<GstSample>(m_sample);

return adoptGRef(gst_video_convert_sample(m_sample.get(), outputCaps.get(), GST_CLOCK_TIME_NONE, nullptr));
GUniqueOutPtr<GError> error;
auto convertedSample = adoptGRef(gst_video_convert_sample(m_sample.get(), outputCaps.get(), GST_CLOCK_TIME_NONE, &error.outPtr()));
if (!convertedSample)
GST_ERROR("Conversion to %s failed: %s", formatName, error->message);

return convertedSample;
}

GRefPtr<GstSample> VideoFrameGStreamer::downloadSample(std::optional<GstVideoFormat> destinationFormat)
Expand Down

0 comments on commit 6204c35

Please sign in to comment.