Skip to content

Commit 0cb500e

Browse files
committed
Merge branch 'eng/1191' into wpe-2.38
Fix for several leaks.
2 parents cf37b74 + 7c4fe25 commit 0cb500e

15 files changed

Lines changed: 78 additions & 38 deletions

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/GRefPtrGStreamer.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,25 @@ template<> void derefGPtr<GstMiniObject>(GstMiniObject* ptr)
5555
gst_mini_object_unref(ptr);
5656
}
5757

58+
template<> GRefPtr<GstObject> adoptGRef(GstObject* ptr)
59+
{
60+
return GRefPtr<GstObject>(ptr, GRefPtrAdopt);
61+
}
62+
63+
template<> GstObject* refGPtr<GstObject>(GstObject* ptr)
64+
{
65+
if (ptr)
66+
gst_object_ref(ptr);
67+
68+
return ptr;
69+
}
70+
71+
template<> void derefGPtr<GstObject>(GstObject* ptr)
72+
{
73+
if (ptr)
74+
gst_object_unref(ptr);
75+
}
76+
5877
template <> GRefPtr<GstElement> adoptGRef(GstElement* ptr)
5978
{
6079
ASSERT(!ptr || !g_object_is_floating(ptr));

Source/WebCore/platform/graphics/gstreamer/GRefPtrGStreamer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ template<> GRefPtr<GstMiniObject> adoptGRef(GstMiniObject* ptr);
5656
template<> GstMiniObject* refGPtr<GstMiniObject>(GstMiniObject* ptr);
5757
template<> void derefGPtr<GstMiniObject>(GstMiniObject* ptr);
5858

59+
template<> GRefPtr<GstObject> adoptGRef(GstObject* ptr);
60+
template<> GstObject* refGPtr<GstObject>(GstObject* ptr);
61+
template<> void derefGPtr<GstObject>(GstObject* ptr);
62+
5963
template<> GRefPtr<GstElement> adoptGRef(GstElement* ptr);
6064
template<> GstElement* refGPtr<GstElement>(GstElement* ptr);
6165
template<> void derefGPtr<GstElement>(GstElement* ptr);

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/GStreamerSinksWorkarounds.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static WorkaroundMode getWorkAroundModeFromEnvironment(const char* environmentVa
6969
}
7070

7171
// Workaround for: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3471 basesink: Support position queries after non-resetting flushes.
72-
// Fix will land in GStreamer 1.24.0.
72+
// Fix merged in 1.23, will ship in GStreamer 1.24.0.
7373

7474
class BaseSinkPositionFlushWorkaroundProbe {
7575
public:
@@ -99,7 +99,10 @@ class BaseSinkPositionFlushWorkaroundProbe {
9999

100100
static bool checkIsNeeded()
101101
{
102-
GST_DEBUG("BaseSinkPositionFlushWorkaroundProbe: running GStreamer %s, the bug fix is expected to land in 1.24.0.", gst_version_string());
102+
#ifndef GST_DISABLE_GST_DEBUG
103+
GUniquePtr<char> versionString(gst_version_string());
104+
GST_DEBUG("BaseSinkPositionFlushWorkaroundProbe: running GStreamer %s, the bug fix is was merged in 1.23 and is expected to ship in 1.24.0.", versionString.get());
105+
#endif
103106
WorkaroundMode mode = getWorkAroundModeFromEnvironment("WEBKIT_GST_WORKAROUND_BASE_SINK_POSITION_FLUSH", WEBKIT_GST_WORKAROUND_BASE_SINK_POSITION_FLUSH_DEFAULT_MODE);
104107
if (mode == WorkaroundMode::ForceEnable) {
105108
GST_DEBUG("BaseSinkPositionFlushWorkaroundProbe: forcing workaround to be enabled.");
@@ -110,7 +113,7 @@ class BaseSinkPositionFlushWorkaroundProbe {
110113
return false;
111114
}
112115

113-
return !webkitGstCheckVersion(1, 24, 0);
116+
return !webkitGstCheckVersion(1, 23, 0);
114117
}
115118

116119
static void initializeIsNeeded()
@@ -201,7 +204,10 @@ class AppSinkFlushCapsWorkaroundProbe {
201204
return false;
202205
}
203206

204-
GST_DEBUG("AppSinkFlushCapsWorkaroundProbe: gst-plugins-base version is %s, bug was fixed in 1.21.1 and backported to 1.20.3.", gst_plugins_base_version_string());
207+
#ifndef GST_DISABLE_GST_DEBUG
208+
GUniquePtr<char> version(gst_plugins_base_version_string());
209+
GST_DEBUG("AppSinkFlushCapsWorkaroundProbe: gst-plugins-base version is %s, bug was fixed in 1.21.1 and backported to 1.20.3.", version.get());
210+
#endif
205211
WorkaroundMode mode = getWorkAroundModeFromEnvironment("WEBKIT_GST_WORKAROUND_APP_SINK_FLUSH_CAPS", WEBKIT_GST_WORKAROUND_APP_SINK_FLUSH_CAPS_DEFAULT_MODE);
206212
if (mode == WorkaroundMode::ForceEnable) {
207213
GST_DEBUG("AppSinkFlushCapsWorkaroundProbe: forcing workaround to be enabled.");

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ static void gst_allocator_fast_malloc_init(GstAllocatorFastMalloc* allocator)
148148
{
149149
auto* baseAllocator = GST_ALLOCATOR_CAST(allocator);
150150

151+
GST_OBJECT_FLAG_SET(allocator, GST_OBJECT_FLAG_MAY_BE_LEAKED);
152+
151153
baseAllocator->mem_type = "FastMalloc";
152154
baseAllocator->mem_map = reinterpret_cast<GstMemoryMapFunction>(gstAllocatorFastMallocMemMap);
153155
baseAllocator->mem_unmap = reinterpret_cast<GstMemoryUnmapFunction>(gstAllocatorFastMallocMemUnmap);

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,16 +1339,6 @@ GstElement* MediaPlayerPrivateGStreamer::createAudioSink()
13391339
#endif
13401340
}
13411341

1342-
GstElement* MediaPlayerPrivateGStreamer::audioSink() const
1343-
{
1344-
if (!m_pipeline)
1345-
return nullptr;
1346-
1347-
GstElement* sink;
1348-
g_object_get(m_pipeline.get(), "audio-sink", &sink, nullptr);
1349-
return sink;
1350-
}
1351-
13521342
bool MediaPlayerPrivateGStreamer::isMediaStreamPlayer() const
13531343
{
13541344
#if ENABLE(MEDIA_STREAM)
@@ -2094,8 +2084,8 @@ void MediaPlayerPrivateGStreamer::handleMessage(GstMessage* message)
20942084
GST_DEBUG_OBJECT(m_pipeline.get(), "Received STREAMS_SELECTED message selecting the following streams:");
20952085
unsigned numStreams = gst_message_streams_selected_get_size(message);
20962086
for (unsigned i = 0; i < numStreams; i++) {
2097-
GstStream* stream = gst_message_streams_selected_get_stream(message, i);
2098-
GST_DEBUG_OBJECT(pipeline(), "#%u %s %s", i, gst_stream_type_get_name(gst_stream_get_stream_type(stream)), gst_stream_get_stream_id(stream));
2087+
auto stream = adoptGRef(gst_message_streams_selected_get_stream(message, i));
2088+
GST_DEBUG_OBJECT(pipeline(), "#%u %s %s", i, gst_stream_type_get_name(gst_stream_get_stream_type(stream.get())), gst_stream_get_stream_id(stream.get()));
20992089
}
21002090
#endif
21012091
GST_DEBUG_OBJECT(m_pipeline.get(), "Setting m_waitingForStreamsSelectedEvent to false.");

Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ class MediaPlayerPrivateGStreamer : public MediaPlayerPrivateInterface
498498

499499
GstElement* createVideoSink();
500500
GstElement* createAudioSink();
501-
GstElement* audioSink() const;
501+
GstElement* audioSink() const { return m_audioSink.get(); }
502502

503503
bool isMediaStreamPlayer() const;
504504

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+
}

0 commit comments

Comments
 (0)