Skip to content

Commit af0715b

Browse files
philncalvaris
authored andcommitted
[GStreamer] Leak fixes for GL display, registries and video encoder
https://bugs.webkit.org/show_bug.cgi?id=266964 Reviewed by Carlos Garcia Campos. The GL display and app contexts were persistent, so never destroyed, thus reported by the leak tracer. The encoder was also leaking a GstElementFactory so its state is now cleared before deinitialization. The MSE registry is also now cleaned-up as well. * Source/WebCore/platform/graphics/PlatformDisplay.h: * Source/WebCore/platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp: (requestGLContext): * Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp: (WebCore::registerWebKitGStreamerElements): (WebCore::registerWebKitGStreamerVideoEncoder): (WebCore::deinitializeGStreamer): * Source/WebCore/platform/graphics/gstreamer/GStreamerRegistryScanner.cpp: (WebCore::GStreamerRegistryScanner::singletonWasInitialized): (WebCore::teardownGStreamerRegistryScanner): (WebCore::GStreamerRegistryScanner::singletonNeedsInitialization): Deleted. * Source/WebCore/platform/graphics/gstreamer/GStreamerRegistryScanner.h: * Source/WebCore/platform/graphics/gstreamer/PlatformDisplayGStreamer.cpp: (WebCore::PlatformDisplay::clearGStreamerGLState): * Source/WebCore/platform/graphics/gstreamer/mse/GStreamerRegistryScannerMSE.cpp: (WebCore::GStreamerRegistryScannerMSE::singleton): (WebCore::teardownGStreamerRegistryScannerMSE): * Source/WebCore/platform/graphics/gstreamer/mse/GStreamerRegistryScannerMSE.h: * Source/WebCore/platform/gstreamer/VideoEncoderPrivateGStreamer.cpp: (teardownVideoEncoderSingleton): * Source/WebCore/platform/gstreamer/VideoEncoderPrivateGStreamer.h: Canonical link: https://commits.webkit.org/272551@main
1 parent b8636c4 commit af0715b

6 files changed

Lines changed: 23 additions & 2 deletions

File tree

Source/WebCore/platform/graphics/PlatformDisplay.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class PlatformDisplay {
9898
#if ENABLE(VIDEO) && USE(GSTREAMER_GL)
9999
GstGLDisplay* gstGLDisplay() const;
100100
GstGLContext* gstGLContext() const;
101+
void clearGStreamerGLState();
101102
#endif
102103

103104
#if USE(LCMS)

Source/WebCore/platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,13 @@ std::optional<GRefPtr<GstContext>> requestGLContext(const char* contextType)
151151
return std::nullopt;
152152

153153
if (!g_strcmp0(contextType, GST_GL_DISPLAY_CONTEXT_TYPE)) {
154-
GRefPtr<GstContext> displayContext = adoptGRef(gst_context_new(GST_GL_DISPLAY_CONTEXT_TYPE, TRUE));
154+
GRefPtr<GstContext> displayContext = adoptGRef(gst_context_new(GST_GL_DISPLAY_CONTEXT_TYPE, FALSE));
155155
gst_context_set_gl_display(displayContext.get(), gstGLDisplay);
156156
return displayContext;
157157
}
158158

159159
if (!g_strcmp0(contextType, "gst.gl.app_context")) {
160-
GRefPtr<GstContext> appContext = adoptGRef(gst_context_new("gst.gl.app_context", TRUE));
160+
GRefPtr<GstContext> appContext = adoptGRef(gst_context_new("gst.gl.app_context", FALSE));
161161
GstStructure* structure = gst_context_writable_structure(appContext.get());
162162
gst_structure_set(structure, "context", GST_TYPE_GL_CONTEXT, gstGLContext, nullptr);
163163
return appContext;

Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "GUniquePtrGStreamer.h"
3434
#include "GstAllocatorFastMalloc.h"
3535
#include "IntSize.h"
36+
#include "PlatformDisplay.h"
3637
#include "RuntimeApplicationChecks.h"
3738
#include "SharedBuffer.h"
3839
#include "WebKitAudioSinkGStreamer.h"
@@ -461,6 +462,10 @@ void unregisterPipeline(const GRefPtr<GstElement>& pipeline)
461462

462463
void deinitializeGStreamer()
463464
{
465+
#if USE(GSTREAMER_GL)
466+
auto& sharedDisplay = PlatformDisplay::sharedDisplayForCompositing();
467+
sharedDisplay.clearGStreamerGLState();
468+
#endif
464469
#if ENABLE(MEDIA_SOURCE)
465470
teardownGStreamerRegistryScannerMSE();
466471
#endif
@@ -489,6 +494,9 @@ void deinitializeGStreamer()
489494
activePipelinesMap().clear();
490495
}
491496

497+
#if ENABLE(VIDEO)
498+
teardownVideoEncoderSingleton();
499+
#endif
492500
gst_deinit();
493501
}
494502

Source/WebCore/platform/graphics/gstreamer/PlatformDisplayGStreamer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,9 @@ GstGLContext* PlatformDisplay::gstGLContext() const
134134
return nullptr;
135135
return m_gstGLContext.get();
136136
}
137+
138+
void PlatformDisplay::clearGStreamerGLState()
139+
{
140+
m_gstGLDisplay = nullptr;
141+
m_gstGLContext = nullptr;
142+
}

Source/WebCore/platform/gstreamer/VideoEncoderPrivateGStreamer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ class Encoders {
170170
}
171171
};
172172

173+
void teardownVideoEncoderSingleton()
174+
{
175+
Encoders::singleton().clear();
176+
}
177+
173178
/* Internal bin structure: videoconvert ! inputCapsFilter ! encoder ! outputCapsFilter ! (optional
174179
parser) ! capsFilter */
175180
struct _WebKitVideoEncoderPrivate {

Source/WebCore/platform/gstreamer/VideoEncoderPrivateGStreamer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ GType webkit_video_encoder_get_type(void);
4646

4747
bool videoEncoderSupportsFormat(WebKitVideoEncoder*, const GRefPtr<GstCaps>&);
4848
bool videoEncoderSetFormat(WebKitVideoEncoder*, GRefPtr<GstCaps>&&);
49+
void teardownVideoEncoderSingleton();

0 commit comments

Comments
 (0)