From 14f6d9a53f5158eb81703b44b70f601c960d2b12 Mon Sep 17 00:00:00 2001 From: Philippe Normand Date: Wed, 25 Dec 2024 15:04:03 +0100 Subject: [PATCH] wpevideosrc: Clear cached SHM buffers after caps re-negotiation Otherwise buffers not corresponding to the negotiated caps might be pushed downstream. Fixes #4094 Part-of: --- .../ext/wpe/gstwpethreadedview.cpp | 31 +++++++++++++++++++ .../ext/wpe/gstwpethreadedview.h | 1 + .../ext/wpe/gstwpevideosrc.cpp | 5 +++ 3 files changed, 37 insertions(+) diff --git a/subprojects/gst-plugins-bad/ext/wpe/gstwpethreadedview.cpp b/subprojects/gst-plugins-bad/ext/wpe/gstwpethreadedview.cpp index 05f16154b2..159a6c3acf 100644 --- a/subprojects/gst-plugins-bad/ext/wpe/gstwpethreadedview.cpp +++ b/subprojects/gst-plugins-bad/ext/wpe/gstwpethreadedview.cpp @@ -711,6 +711,37 @@ void GstWPEThreadedView::resize(int width, int height) }); } +void GstWPEThreadedView::clearBuffers() +{ + bool dispatchFrameComplete = false; + { + GMutexHolder lock(images_mutex); + + if (shm.pending) { + auto meta = gst_buffer_get_video_meta(shm.pending); + if (static_cast(meta->width) != wpe.width || static_cast(meta->height) != wpe.height) { + gst_clear_buffer(&shm.pending); + dispatchFrameComplete = true; + } + } + + if (shm.committed) { + auto meta = gst_buffer_get_video_meta(shm.committed); + if (static_cast(meta->width) != wpe.width || static_cast(meta->height) != wpe.height) { + gst_clear_buffer(&shm.committed); + dispatchFrameComplete = true; + } + } + } + + if (dispatchFrameComplete) { + frameComplete(); + // Wait until the next SHM buffer has been received. + threading.ready = false; + waitLoadCompletion(); + } +} + void GstWPEThreadedView::frameComplete() { GST_TRACE("frame complete"); diff --git a/subprojects/gst-plugins-bad/ext/wpe/gstwpethreadedview.h b/subprojects/gst-plugins-bad/ext/wpe/gstwpethreadedview.h index 7c5b578f1d..8e31aae3d4 100644 --- a/subprojects/gst-plugins-bad/ext/wpe/gstwpethreadedview.h +++ b/subprojects/gst-plugins-bad/ext/wpe/gstwpethreadedview.h @@ -45,6 +45,7 @@ public: void loadData(GBytes*); void runJavascript(const gchar*); void setDrawBackground(gboolean); + void clearBuffers(); GstEGLImage* image(); GstBuffer* buffer(); diff --git a/subprojects/gst-plugins-bad/ext/wpe/gstwpevideosrc.cpp b/subprojects/gst-plugins-bad/ext/wpe/gstwpevideosrc.cpp index 90d385f303..ceb28ca6d3 100644 --- a/subprojects/gst-plugins-bad/ext/wpe/gstwpevideosrc.cpp +++ b/subprojects/gst-plugins-bad/ext/wpe/gstwpevideosrc.cpp @@ -329,6 +329,11 @@ gst_wpe_video_src_start (GstWpeVideoSrc * src) return FALSE; } + if (!created_view) { + GST_INFO_OBJECT (src, "Re-starting after re-negotiation, clearing cached SHM buffers"); + src->view->clearBuffers (); + } + GST_OBJECT_LOCK (src); bytes = src->bytes; src->bytes = NULL;