From e387c506a0dfe4b62a9e8beedc76d1abcc177c24 Mon Sep 17 00:00:00 2001
From: christophe.dumez <christophe.dumez@intel.com>
Date: Mon, 4 Mar 2013 11:26:04 +0100
Subject: [PATCH] [gstreamer] MediaPlayerPrivateGStreamer should take ownership of the playbin

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

Reviewed by Philippe Normand.

In gstreamer 1.0, gst_element_factory_make() now returns a floating reference.
MediaPlayerPrivateGStreamer calls gst_element_factory_make() to create the
playbin object but does not take ownership of the object. As a consequence,
the object keeps floating until it is unref'd in the
MediaPlayerPrivateGStreamer destructor.

This patch uses a GRefPtr<GstElement> to store the playbin object and only
adopt the object returned by gst_element_factory_make() if gstreamer 0.10
is used. When gstreamer 1.0 is used, the returned object will not be adopted,
which will remove the floating reference. This way, we ensure that the
playbin object is owned by MediaPlayerPrivateGStreamer.

No new tests, no behavior change for layout tests.

* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::MediaPlayerPrivateGStreamer):
(WebCore::MediaPlayerPrivateGStreamer::~MediaPlayerPrivateGStreamer):
(WebCore::MediaPlayerPrivateGStreamer::load):
(WebCore::MediaPlayerPrivateGStreamer::playbackPosition):
(WebCore::MediaPlayerPrivateGStreamer::changePipelineState):
(WebCore::MediaPlayerPrivateGStreamer::duration):
(WebCore::MediaPlayerPrivateGStreamer::seek):
(WebCore::MediaPlayerPrivateGStreamer::paused):
(WebCore::MediaPlayerPrivateGStreamer::notifyPlayerOfVideo):
(WebCore::MediaPlayerPrivateGStreamer::notifyPlayerOfAudio):
(WebCore::MediaPlayerPrivateGStreamer::setVolume):
(WebCore::MediaPlayerPrivateGStreamer::notifyPlayerOfVolumeChange):
(WebCore::MediaPlayerPrivateGStreamer::setRate):
(WebCore::MediaPlayerPrivateGStreamer::buffered):
(WebCore::MediaPlayerPrivateGStreamer::handleMessage):
(WebCore::MediaPlayerPrivateGStreamer::fillTimerFired):
* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h:
(MediaPlayerPrivateGStreamer):

Change-Id: I441285d33189c4afc26e9608bc0993716c24d7ed
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@140414 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Reviewed-by: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
---
 .../gstreamer/MediaPlayerPrivateGStreamer.cpp      |  128 ++++++++++----------
 .../gstreamer/MediaPlayerPrivateGStreamer.h        |    2 +-
 2 files changed, 66 insertions(+), 64 deletions(-)

diff --git a/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp
index 736fd5a..cd34c18 100644
--- a/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp
+++ b/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp
@@ -204,7 +204,6 @@ bool MediaPlayerPrivateGStreamer::isAvai
 
 MediaPlayerPrivateGStreamer::MediaPlayerPrivateGStreamer(MediaPlayer* player)
     : m_player(player)
-    , m_playBin(0)
     , m_webkitVideoSink(0)
     , m_fpsSink(0)
     , m_source(0)
@@ -270,8 +269,7 @@ MediaPlayerPrivateGStreamer::~MediaPlaye
 #endif
 
     if (m_playBin) {
-        gst_element_set_state(m_playBin, GST_STATE_NULL);
-        gst_object_unref(GST_OBJECT(m_playBin));
+        gst_element_set_state(m_playBin.get(), GST_STATE_NULL);
         m_playBin = 0;
     }
 
@@ -301,7 +299,7 @@ void MediaPlayerPrivateGStreamer::load(c
         cleanUrl = cleanUrl.substring(0, kurl.pathEnd());
 
     m_url = KURL(KURL(), cleanUrl);
-    g_object_set(m_playBin, "uri", cleanUrl.utf8().data(), NULL);
+    g_object_set(m_playBin.get(), "uri", cleanUrl.utf8().data(), NULL);
 
     LOG_MEDIA_MESSAGE("Load %s", cleanUrl.utf8().data());
 
@@ -319,7 +317,7 @@ void MediaPlayerPrivateGStreamer::load(c
 
     // GStreamer needs to have the pipeline set to a paused state to
     // start providing anything useful.
-    gst_element_set_state(m_playBin, GST_STATE_PAUSED);
+    gst_element_set_state(m_playBin.get(), GST_STATE_PAUSED);
 
     if (!m_delayingLoad)
         commitLoad();
@@ -348,7 +346,7 @@ float MediaPlayerPrivateGStreamer::playb
     float ret = 0.0f;
 
     GstQuery* query = gst_query_new_position(GST_FORMAT_TIME);
-    if (!gst_element_query(m_playBin, query)) {
+    if (!gst_element_query(m_playBin.get(), query)) {
         LOG_MEDIA_MESSAGE("Position query failed...");
         gst_query_unref(query);
         return ret;
@@ -376,12 +374,12 @@ bool MediaPlayerPrivateGStreamer::change
     GstState currentState;
     GstState pending;
 
-    gst_element_get_state(m_playBin, &currentState, &pending, 0);
+    gst_element_get_state(m_playBin.get(), &currentState, &pending, 0);
     LOG_MEDIA_MESSAGE("Current state: %s, pending: %s", gst_element_state_get_name(currentState), gst_element_state_get_name(pending));
     if (currentState == newState || pending == newState)
         return true;
 
-    GstStateChangeReturn setStateResult = gst_element_set_state(m_playBin, newState);
+    GstStateChangeReturn setStateResult = gst_element_set_state(m_playBin.get(), newState);
     GstState pausedOrPlaying = newState == GST_STATE_PLAYING ? GST_STATE_PAUSED : GST_STATE_PLAYING;
     if (currentState != pausedOrPlaying && setStateResult == GST_STATE_CHANGE_FAILURE) {
         loadingFailed(MediaPlayer::Empty);
@@ -437,9 +435,9 @@ float MediaPlayerPrivateGStreamer::durat
     gint64 timeLength = 0;
 
 #ifdef GST_API_VERSION_1
-    bool failure = !gst_element_query_duration(m_playBin, timeFormat, &timeLength) || static_cast<guint64>(timeLength) == GST_CLOCK_TIME_NONE;
+    bool failure = !gst_element_query_duration(m_playBin.get(), timeFormat, &timeLength) || static_cast<guint64>(timeLength) == GST_CLOCK_TIME_NONE;
 #else
-    bool failure = !gst_element_query_duration(m_playBin, &timeFormat, &timeLength) || timeFormat != GST_FORMAT_TIME || static_cast<guint64>(timeLength) == GST_CLOCK_TIME_NONE;
+    bool failure = !gst_element_query_duration(m_playBin.get(), &timeFormat, &timeLength) || timeFormat != GST_FORMAT_TIME || static_cast<guint64>(timeLength) == GST_CLOCK_TIME_NONE;
 #endif
     if (failure) {
         LOG_MEDIA_MESSAGE("Time duration query failed for %s", m_url.string().utf8().data());
@@ -502,7 +500,7 @@ void MediaPlayerPrivateGStreamer::seek(f
     GstClockTime clockTime = GST_TIMEVAL_TO_TIME(timeValue);
     LOG_MEDIA_MESSAGE("Seek: %" GST_TIME_FORMAT, GST_TIME_ARGS(clockTime));
 
-    if (!gst_element_seek(m_playBin, m_player->rate(),
+    if (!gst_element_seek(m_playBin.get(), m_player->rate(),
             GST_FORMAT_TIME,
             (GstSeekFlags)(GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE),
             GST_SEEK_TYPE_SET, clockTime,
@@ -522,7 +520,7 @@ bool MediaPlayerPrivateGStreamer::paused
     }
 
     GstState state;
-    gst_element_get_state(m_playBin, &state, 0, 0);
+    gst_element_get_state(m_playBin.get(), &state, 0, 0);
     return state == GST_STATE_PAUSED;
 }
 
@@ -604,7 +602,7 @@ void MediaPlayerPrivateGStreamer::notify
 
     gint videoTracks = 0;
     if (m_playBin)
-        g_object_get(m_playBin, "n-video", &videoTracks, NULL);
+        g_object_get(m_playBin.get(), "n-video", &videoTracks, NULL);
 
     m_hasVideo = videoTracks > 0;
 
@@ -626,7 +624,7 @@ void MediaPlayerPrivateGStreamer::notify
 
     gint audioTracks = 0;
     if (m_playBin)
-        g_object_get(m_playBin, "n-audio", &audioTracks, NULL);
+        g_object_get(m_playBin.get(), "n-audio", &audioTracks, NULL);
     m_hasAudio = audioTracks > 0;
     m_player->mediaPlayerClient()->mediaPlayerEngineUpdated(m_player);
 }
@@ -636,7 +634,7 @@ void MediaPlayerPrivateGStreamer::setVol
     if (!m_playBin)
         return;
 
-    gst_stream_volume_set_volume(GST_STREAM_VOLUME(m_playBin), GST_STREAM_VOLUME_FORMAT_CUBIC,
+    gst_stream_volume_set_volume(GST_STREAM_VOLUME(m_playBin.get()), GST_STREAM_VOLUME_FORMAT_CUBIC,
                                  static_cast<double>(volume));
 }
 
@@ -647,7 +645,7 @@ void MediaPlayerPrivateGStreamer::notify
     if (!m_player || !m_playBin)
         return;
     double volume;
-    volume = gst_stream_volume_get_volume(GST_STREAM_VOLUME(m_playBin), GST_STREAM_VOLUME_FORMAT_CUBIC);
+    volume = gst_stream_volume_get_volume(GST_STREAM_VOLUME(m_playBin.get()), GST_STREAM_VOLUME_FORMAT_CUBIC);
     // get_volume() can return values superior to 1.0 if the user
     // applies software user gain via third party application (GNOME
     // volume control for instance).
@@ -671,7 +669,7 @@ void MediaPlayerPrivateGStreamer::setRat
     GstState state;
     GstState pending;
 
-    gst_element_get_state(m_playBin, &state, &pending, 0);
+    gst_element_get_state(m_playBin.get(), &state, &pending, 0);
     if ((state != GST_STATE_PLAYING && state != GST_STATE_PAUSED)
         || (pending == GST_STATE_PAUSED))
         return;
@@ -683,7 +681,7 @@ void MediaPlayerPrivateGStreamer::setRat
     m_changingRate = true;
 
     if (!rate) {
-        gst_element_set_state(m_playBin, GST_STATE_PAUSED);
+        gst_element_set_state(m_playBin.get(), GST_STATE_PAUSED);
         return;
     }
 
@@ -713,12 +711,12 @@ void MediaPlayerPrivateGStreamer::setRat
 
     LOG_MEDIA_MESSAGE("Need to mute audio: %d", (int) mute);
 
-    if (!gst_element_seek(m_playBin, rate, GST_FORMAT_TIME, flags,
+    if (!gst_element_seek(m_playBin.get(), rate, GST_FORMAT_TIME, flags,
                           GST_SEEK_TYPE_SET, start,
                           GST_SEEK_TYPE_SET, end))
         LOG_MEDIA_MESSAGE("Set rate to %f failed", rate);
     else
-        g_object_set(m_playBin, "mute", mute, NULL);
+        g_object_set(m_playBin.get(), "mute", mute, NULL);
 }
 
 MediaPlayer::NetworkState MediaPlayerPrivateGStreamer::networkState() const
@@ -744,7 +742,7 @@ PassRefPtr<TimeRanges> MediaPlayerPrivat
 
     GstQuery* query = gst_query_new_buffering(GST_FORMAT_PERCENT);
 
-    if (!gst_element_query(m_playBin, query)) {
+    if (!gst_element_query(m_playBin.get(), query)) {
         gst_query_unref(query);
         return timeRanges.release();
     }
@@ -799,7 +797,7 @@ gboolean MediaPlayerPrivateGStreamer::ha
         gst_message_parse_error(message, &err.outPtr(), &debug.outPtr());
         LOG_MEDIA_MESSAGE("Error %d: %s (url=%s)", err->code, err->message, m_url.string().utf8().data());
 
-        GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS(GST_BIN(m_playBin), GST_DEBUG_GRAPH_SHOW_ALL, "webkit-video.error");
+        GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS(GST_BIN(m_playBin.get()), GST_DEBUG_GRAPH_SHOW_ALL, "webkit-video.error");
 
         error = MediaPlayer::Empty;
         if (err->code == GST_STREAM_ERROR_CODEC_NOT_FOUND
@@ -840,7 +838,7 @@ gboolean MediaPlayerPrivateGStreamer::ha
 
         // Ignore state changes from internal elements. They are
         // forwarded to playbin2 anyway.
-        if (GST_MESSAGE_SRC(message) == reinterpret_cast<GstObject*>(m_playBin)) {
+        if (GST_MESSAGE_SRC(message) == reinterpret_cast<GstObject*>(m_playBin.get())) {
             updateStates();
 
             // Construct a filename for the graphviz dot file output.
@@ -851,7 +849,7 @@ gboolean MediaPlayerPrivateGStreamer::ha
                                                  gst_element_state_get_name(oldState),
                                                  gst_element_state_get_name(newState)).utf8();
 
-            GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS(GST_BIN(m_playBin), GST_DEBUG_GRAPH_SHOW_ALL, dotFileName.data());
+            GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS(GST_BIN(m_playBin.get()), GST_DEBUG_GRAPH_SHOW_ALL, dotFileName.data());
         }
         break;
     case GST_MESSAGE_BUFFERING:
@@ -908,7 +906,7 @@ void MediaPlayerPrivateGStreamer::fillTi
 {
     GstQuery* query = gst_query_new_buffering(GST_FORMAT_PERCENT);
 
-    if (!gst_element_query(m_playBin, query)) {
+    if (!gst_element_query(m_playBin.get(), query)) {
         gst_query_unref(query);
         return;
     }
@@ -1107,7 +1105,7 @@ void MediaPlayerPrivateGStreamer::update
 
     GstElement* sinkPtr = 0;
 
-    g_object_get(m_playBin, "audio-sink", &sinkPtr, NULL);
+    g_object_get(m_playBin.get(), "audio-sink", &sinkPtr, NULL);
     m_webkitAudioSink = adoptGRef(sinkPtr);
 
 }
@@ -1117,7 +1115,7 @@ void MediaPlayerPrivateGStreamer::source
 {
     GstElement* srcPtr = 0;
 
-    g_object_get(m_playBin, "source", &srcPtr, NULL);
+    g_object_get(m_playBin.get(), "source", &srcPtr, NULL);
     m_source = adoptGRef(srcPtr);
 
     if (WEBKIT_IS_WEB_SRC(m_source.get()))
@@ -1130,7 +1128,7 @@ void MediaPlayerPrivateGStreamer::cancel
         return;
 
     if (m_playBin)
-        gst_element_set_state(m_playBin, GST_STATE_NULL);
+        gst_element_set_state(m_playBin.get(), GST_STATE_NULL);
 }
 
 void MediaPlayerPrivateGStreamer::updateStates()
@@ -1146,7 +1144,7 @@ void MediaPlayerPrivateGStreamer::update
     GstState state;
     GstState pending;
 
-    GstStateChangeReturn ret = gst_element_get_state(m_playBin,
+    GstStateChangeReturn ret = gst_element_get_state(m_playBin.get(),
         &state, &pending, 250 * GST_NSECOND);
 
     bool shouldUpdateAfterSeek = false;
@@ -1195,7 +1193,7 @@ void MediaPlayerPrivateGStreamer::update
 
                 if (!m_paused) {
                     LOG_MEDIA_MESSAGE("[Buffering] Restarting playback.");
-                    gst_element_set_state(m_playBin, GST_STATE_PLAYING);
+                    gst_element_set_state(m_playBin.get(), GST_STATE_PLAYING);
                 }
             } else if (!m_buffering && (currentTime() < duration())) {
                 m_paused = true;
@@ -1210,7 +1208,7 @@ void MediaPlayerPrivateGStreamer::update
 
                 LOG_MEDIA_MESSAGE("[Buffering] Pausing stream for buffering.");
 
-                gst_element_set_state(m_playBin, GST_STATE_PAUSED);
+                gst_element_set_state(m_playBin.get(), GST_STATE_PAUSED);
             }
         } else
             m_paused = true;
@@ -1241,14 +1239,14 @@ void MediaPlayerPrivateGStreamer::update
         // pipeline.
         if (state == GST_STATE_READY && isLiveStream() && m_preload == MediaPlayer::Auto) {
             setPreload(MediaPlayer::None);
-            gst_element_set_state(m_playBin, GST_STATE_NULL);
-            gst_element_set_state(m_playBin, GST_STATE_PAUSED);
+            gst_element_set_state(m_playBin.get(), GST_STATE_NULL);
+            gst_element_set_state(m_playBin.get(), GST_STATE_PAUSED);
         }
 
         // A live stream was paused, reset the pipeline.
         if (state == GST_STATE_PAUSED && pending == GST_STATE_PLAYING && isLiveStream()) {
-            gst_element_set_state(m_playBin, GST_STATE_NULL);
-            gst_element_set_state(m_playBin, GST_STATE_PLAYING);
+            gst_element_set_state(m_playBin.get(), GST_STATE_NULL);
+            gst_element_set_state(m_playBin.get(), GST_STATE_PLAYING);
         }
 
         if (!isLiveStream() && !m_buffering)
@@ -1284,9 +1282,9 @@ void MediaPlayerPrivateGStreamer::update
             shouldUpdateAfterSeek = true;
             m_seeking = false;
             if (!m_paused)
-                gst_element_set_state(m_playBin, GST_STATE_PLAYING);
+                gst_element_set_state(m_playBin.get(), GST_STATE_PLAYING);
         } else if (!m_paused)
-            gst_element_set_state(m_playBin, GST_STATE_PLAYING);
+            gst_element_set_state(m_playBin.get(), GST_STATE_PLAYING);
 
         m_networkState = MediaPlayer::Loading;
         break;
@@ -1372,7 +1370,7 @@ bool MediaPlayerPrivateGStreamer::loadNe
         // append the value of new-location to it.
 
         gchar* currentLocation = 0;
-        g_object_get(m_playBin, "uri", &currentLocation, NULL);
+        g_object_get(m_playBin.get(), "uri", &currentLocation, NULL);
 
         KURL currentUrl(KURL(), currentLocation);
         g_free(currentLocation);
@@ -1396,14 +1394,14 @@ bool MediaPlayerPrivateGStreamer::loadNe
 
             // Reset pipeline state.
             m_resetPipeline = true;
-            gst_element_set_state(m_playBin, GST_STATE_READY);
+            gst_element_set_state(m_playBin.get(), GST_STATE_READY);
 
             GstState state;
-            gst_element_get_state(m_playBin, &state, 0, 0);
+            gst_element_get_state(m_playBin.get(), &state, 0, 0);
             if (state <= GST_STATE_READY) {
                 // Set the new uri and start playing.
-                g_object_set(m_playBin, "uri", newUrl.string().utf8().data(), NULL);
-                gst_element_set_state(m_playBin, GST_STATE_PLAYING);
+                g_object_set(m_playBin.get(), "uri", newUrl.string().utf8().data(), NULL);
+                gst_element_set_state(m_playBin.get(), GST_STATE_PLAYING);
                 return true;
             }
         }
@@ -1446,7 +1444,7 @@ void MediaPlayerPrivateGStreamer::didEnd
 
     if (!m_player->mediaPlayerClient()->mediaPlayerIsLooping()) {
         m_paused = true;
-        gst_element_set_state(m_playBin, GST_STATE_NULL);
+        gst_element_set_state(m_playBin.get(), GST_STATE_NULL);
     }
 }
 
@@ -1457,7 +1455,7 @@ void MediaPlayerPrivateGStreamer::cacheD
 
     // And re-cache it if possible.
     GstState state;
-    gst_element_get_state(m_playBin, &state, 0, 0);
+    gst_element_get_state(m_playBin.get(), &state, 0, 0);
     float newDuration = duration();
 
     if (state <= GST_STATE_READY) {
@@ -1491,8 +1489,8 @@ void MediaPlayerPrivateGStreamer::durati
         m_totalBytes = -1;
         if (totalBytes() && !isLiveStream()) {
             setPreload(MediaPlayer::Auto);
-            gst_element_set_state(m_playBin, GST_STATE_NULL);
-            gst_element_set_state(m_playBin, GST_STATE_PAUSED);
+            gst_element_set_state(m_playBin.get(), GST_STATE_NULL);
+            gst_element_set_state(m_playBin.get(), GST_STATE_PAUSED);
         }
     }
 }
@@ -1507,7 +1505,7 @@ void MediaPlayerPrivateGStreamer::setMut
     if (!m_playBin)
         return;
 
-    g_object_set(m_playBin, "mute", muted, NULL);
+    g_object_set(m_playBin.get(), "mute", muted, NULL);
 }
 
 void MediaPlayerPrivateGStreamer::notifyPlayerOfMute()
@@ -1518,7 +1516,7 @@ void MediaPlayerPrivateGStreamer::notify
         return;
 
     gboolean muted;
-    g_object_get(m_playBin, "mute", &muted, NULL);
+    g_object_get(m_playBin.get(), "mute", &muted, NULL);
     m_player->muteChanged(static_cast<bool>(muted));
 }
 
@@ -1744,13 +1742,13 @@ void MediaPlayerPrivateGStreamer::setPre
     ASSERT(m_playBin);
 
     GstPlayFlags flags;
-    g_object_get(m_playBin, "flags", &flags, NULL);
+    g_object_get(m_playBin.get(), "flags", &flags, NULL);
     if (m_preload == MediaPlayer::Auto) {
         LOG_MEDIA_MESSAGE("Enabling on-disk buffering");
-        g_object_set(m_playBin, "flags", flags | GST_PLAY_FLAG_DOWNLOAD, NULL);
+        g_object_set(m_playBin.get(), "flags", flags | GST_PLAY_FLAG_DOWNLOAD, NULL);
     } else {
         LOG_MEDIA_MESSAGE("Disabling on-disk buffering");
-        g_object_set(m_playBin, "flags", flags & ~GST_PLAY_FLAG_DOWNLOAD, NULL);
+        g_object_set(m_playBin.get(), "flags", flags & ~GST_PLAY_FLAG_DOWNLOAD, NULL);
     }
 
     if (m_delayingLoad && m_preload != MediaPlayer::None) {
@@ -1762,24 +1760,27 @@ void MediaPlayerPrivateGStreamer::setPre
 void MediaPlayerPrivateGStreamer::createGSTPlayBin()
 {
     ASSERT(!m_playBin);
+
+    // gst_element_factory_make() returns a floating reference so
+    // we should not adopt.
     m_playBin = gst_element_factory_make(gPlaybinName, "play");
 
 #ifndef GST_API_VERSION_1
-    m_gstGWorld = GStreamerGWorld::createGWorld(m_playBin);
+    m_gstGWorld = GStreamerGWorld::createGWorld(m_playBin.get());
 #endif
 
-    GstBus* bus = gst_pipeline_get_bus(GST_PIPELINE(m_playBin));
+    GstBus* bus = gst_pipeline_get_bus(GST_PIPELINE(m_playBin.get()));
     gst_bus_add_signal_watch(bus);
     g_signal_connect(bus, "message", G_CALLBACK(mediaPlayerPrivateMessageCallback), this);
     gst_object_unref(bus);
 
-    g_object_set(m_playBin, "mute", m_player->muted(), NULL);
+    g_object_set(m_playBin.get(), "mute", m_player->muted(), NULL);
 
-    g_signal_connect(m_playBin, "notify::volume", G_CALLBACK(mediaPlayerPrivateVolumeChangedCallback), this);
-    g_signal_connect(m_playBin, "notify::source", G_CALLBACK(mediaPlayerPrivateSourceChangedCallback), this);
-    g_signal_connect(m_playBin, "notify::mute", G_CALLBACK(mediaPlayerPrivateMuteChangedCallback), this);
-    g_signal_connect(m_playBin, "video-changed", G_CALLBACK(mediaPlayerPrivateVideoChangedCallback), this);
-    g_signal_connect(m_playBin, "audio-changed", G_CALLBACK(mediaPlayerPrivateAudioChangedCallback), this);
+    g_signal_connect(m_playBin.get(), "notify::volume", G_CALLBACK(mediaPlayerPrivateVolumeChangedCallback), this);
+    g_signal_connect(m_playBin.get(), "notify::source", G_CALLBACK(mediaPlayerPrivateSourceChangedCallback), this);
+    g_signal_connect(m_playBin.get(), "notify::mute", G_CALLBACK(mediaPlayerPrivateMuteChangedCallback), this);
+    g_signal_connect(m_playBin.get(), "video-changed", G_CALLBACK(mediaPlayerPrivateVideoChangedCallback), this);
+    g_signal_connect(m_playBin.get(), "audio-changed", G_CALLBACK(mediaPlayerPrivateAudioChangedCallback), this);
 
 #ifndef GST_API_VERSION_1
     m_webkitVideoSink = webkitVideoSinkNew(m_gstGWorld.get());
@@ -1862,9 +1863,9 @@ void MediaPlayerPrivateGStreamer::create
     gst_element_add_pad(m_videoSinkBin, gst_ghost_pad_new("sink", pad.get()));
 
     // Set the bin as video sink of playbin.
-    g_object_set(m_playBin, "video-sink", m_videoSinkBin, NULL);
+    g_object_set(m_playBin.get(), "video-sink", m_videoSinkBin, NULL);
 #else
-    g_object_set(m_playBin, "video-sink", actualVideoSink, NULL);
+    g_object_set(m_playBin.get(), "video-sink", actualVideoSink, NULL);
 #endif
 
     GRefPtr<GstPad> videoSinkPad = adoptGRef(gst_element_get_static_pad(m_webkitVideoSink, "sink"));
diff --git a/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h b/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h
index d14d004..1f7b3f3 100644
--- a/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h
+++ b/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h
@@ -157,7 +157,7 @@ class MediaPlayerPrivateGStreamer : public MediaPlayerPrivateInterface {
 
         private:
             MediaPlayer* m_player;
-            GstElement* m_playBin;
+            GRefPtr<GstElement> m_playBin;
             GstElement* m_webkitVideoSink;
             GstElement* m_videoSinkBin;
             GstElement* m_fpsSink;
-- 
1.7.1

