From 755a6f3b521212beb61c48727ff4d95c7e0ac8de Mon Sep 17 00:00:00 2001 From: "christophe.dumez@intel.com" Date: Tue, 22 Jan 2013 19:15:38 +0000 Subject: [PATCH] [CherryPick] [gstreamer] GstBus signal watch should be removed on clean up [Title] [gstreamer] GstBus signal watch should be removed on clean up [Issues] NA [Problem] Memory leak fix in WebAudio. [Solution] Cherry picked. [Cherry-Picker] Praveen R Jadhav https://bugs.webkit.org/show_bug.cgi?id=107544 Reviewed by Philippe Normand. Our gstreamer backend code currently calls gst_bus_add_signal_watch() on GstBus to add a signal watch. As per the gstreamer documentation, "To clean up, the caller is responsible for calling gst_bus_remove_signal_watch() as many times as this function is called". This is because gst_bus_add_signal_watch() causes the GstBus object to be ref'd and gst_bus_remove_signal_watch() needs to be called to properly unref it. This patch makes sure that gst_bus_remove_signal_watch() is called on the GstBus object when cleaning up. This patch also uses smart pointers for GstBus objects for consistency. No new tests, no behavior change for layout tests. * platform/audio/gstreamer/AudioDestinationGStreamer.cpp: (WebCore::AudioDestinationGStreamer::AudioDestinationGStreamer): (WebCore::AudioDestinationGStreamer::~AudioDestinationGStreamer): * platform/audio/gstreamer/AudioFileReaderGStreamer.cpp: (WebCore::AudioFileReader::~AudioFileReader): (WebCore::AudioFileReader::decodeAudioForBusCreation): * platform/graphics/gstreamer/GStreamerGWorld.cpp: (WebCore::GStreamerGWorld::GStreamerGWorld): * platform/graphics/gstreamer/GStreamerVersioning.cpp: (webkitGstPipelineGetBus): * platform/graphics/gstreamer/GStreamerVersioning.h: * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::~MediaPlayerPrivateGStreamer): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@140443 268f45cc-cd09-0410-ab3c-d52691b4dbfc Conflicts: Source/WebCore/ChangeLog Source/WebCore/platform/graphics/gstreamer/GStreamerGWorld.cpp Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp Change-Id: Ib1142fe97c9641e7c40cdba75f5e7a4ba2d28ff0 --- .../audio/gstreamer/AudioDestinationGStreamer.cpp | 20 +++++++------------ .../audio/gstreamer/AudioFileReaderGStreamer.cpp | 23 +++++++--------------- 2 files changed, 14 insertions(+), 29 deletions(-) diff --git a/Source/WebCore/platform/audio/gstreamer/AudioDestinationGStreamer.cpp b/Source/WebCore/platform/audio/gstreamer/AudioDestinationGStreamer.cpp index 9e3cde4..9df5401 100644 --- a/Source/WebCore/platform/audio/gstreamer/AudioDestinationGStreamer.cpp +++ b/Source/WebCore/platform/audio/gstreamer/AudioDestinationGStreamer.cpp @@ -125,22 +125,15 @@ AudioDestinationGStreamer::AudioDestinationGStreamer(AudioIOCallback& callback, , m_audioSessionManager(AudioSessionManagerGStreamerTizen::createAudioSessionManager()) #endif { -#if !ENABLE(TIZEN_WEB_AUDIO) - static bool gstInitialized = false; - if (!gstInitialized) - gstInitialized = gst_init_check(0, 0, 0); - ASSERT_WITH_MESSAGE(gstInitialized, "GStreamer initialization failed"); -#endif #if ENABLE(TIZEN_GSTREAMER_AUDIO) if (m_audioSessionManager) m_audioSessionManager->registerAudioSessionManager(MM_SESSION_TYPE_SHARE, AudioDestinationAudioSessionNotifyCallback, this); #endif m_pipeline = gst_pipeline_new("play"); - GstBus* bus = gst_pipeline_get_bus(GST_PIPELINE(m_pipeline)); + GRefPtr bus = webkitGstPipelineGetBus(GST_PIPELINE(m_pipeline)); ASSERT(bus); - gst_bus_add_signal_watch(bus); - g_signal_connect(bus, "message", G_CALLBACK(messageCallback), this); - gst_object_unref(bus); + gst_bus_add_signal_watch(bus.get()); + g_signal_connect(bus.get(), "message", G_CALLBACK(messageCallback), this); GstElement* webkitAudioSrc = reinterpret_cast(g_object_new(WEBKIT_TYPE_WEB_AUDIO_SRC, "rate", sampleRate, @@ -169,10 +162,11 @@ AudioDestinationGStreamer::AudioDestinationGStreamer(AudioIOCallback& callback, AudioDestinationGStreamer::~AudioDestinationGStreamer() { - GstBus* bus = gst_pipeline_get_bus(GST_PIPELINE(m_pipeline)); + GRefPtr bus = webkitGstPipelineGetBus(GST_PIPELINE(m_pipeline)); ASSERT(bus); - g_signal_handlers_disconnect_by_func(bus, reinterpret_cast(messageCallback), this); - gst_object_unref(bus); + g_signal_handlers_disconnect_by_func(bus.get(), reinterpret_cast(messageCallback), this); + gst_bus_remove_signal_watch(bus.get()); + gst_element_set_state(m_pipeline, GST_STATE_NULL); #if ENABLE(TIZEN_GSTREAMER_AUDIO) diff --git a/Source/WebCore/platform/audio/gstreamer/AudioFileReaderGStreamer.cpp b/Source/WebCore/platform/audio/gstreamer/AudioFileReaderGStreamer.cpp index ac692a7..5a9126b 100644 --- a/Source/WebCore/platform/audio/gstreamer/AudioFileReaderGStreamer.cpp +++ b/Source/WebCore/platform/audio/gstreamer/AudioFileReaderGStreamer.cpp @@ -175,10 +175,11 @@ AudioFileReader::AudioFileReader(const void* data, size_t dataSize) AudioFileReader::~AudioFileReader() { if (m_pipeline) { - GstBus* bus = gst_pipeline_get_bus(GST_PIPELINE(m_pipeline)); + GRefPtr bus = webkitGstPipelineGetBus(GST_PIPELINE(m_pipeline)); ASSERT(bus); - g_signal_handlers_disconnect_by_func(bus, reinterpret_cast(messageCallback), this); - gst_object_unref(bus); + g_signal_handlers_disconnect_by_func(bus.get(), reinterpret_cast(messageCallback), this); + gst_bus_remove_signal_watch(bus.get()); + gst_element_set_state(m_pipeline, GST_STATE_NULL); gst_object_unref(GST_OBJECT(m_pipeline)); } @@ -422,11 +423,10 @@ void AudioFileReader::decodeAudioForBusCreation() // A deinterleave element is added once a src pad becomes available in decodebin. m_pipeline = gst_pipeline_new(0); - GstBus* bus = gst_pipeline_get_bus(GST_PIPELINE(m_pipeline)); + GRefPtr bus = webkitGstPipelineGetBus(GST_PIPELINE(m_pipeline)); ASSERT(bus); - gst_bus_add_signal_watch(bus); - g_signal_connect(bus, "message", G_CALLBACK(messageCallback), this); - gst_object_unref(bus); + gst_bus_add_signal_watch(bus.get()); + g_signal_connect(bus.get(), "message", G_CALLBACK(messageCallback), this); GstElement* source; if (m_data) { @@ -451,15 +451,6 @@ PassOwnPtr AudioFileReader::createBus(float sampleRate, bool mixToMono { m_sampleRate = sampleRate; -#if !ENABLE(TIZEN_WEB_AUDIO) - static bool gstInitialized = false; - if (!gstInitialized) - gstInitialized = gst_init_check(0, 0, 0); - - if (!gstInitialized) - return nullptr; -#endif - m_frontLeftBuffers = gst_buffer_list_new(); m_frontRightBuffers = gst_buffer_list_new(); -- 2.7.4