[gnome-music/wip/jfelder/40-high-cpu-stopped] gstplayer: Unschedule the clock when stopped




commit 4ece0379509d1021f7ae98f277ac66f6e810b808
Author: Jean Felder <jfelder src gnome org>
Date:   Fri Apr 30 18:50:29 2021 +0200

    gstplayer: Unschedule the clock when stopped
    
    This is a follow-up of commit ad31ba0f9c695ab8f42af9be252f789af0a39bdc
    which unschedules the clock when the player is paused.
    
    When the player is paused or stopped, the clock "wait" times out and
    causes a high cpu usage (this only happens with gstreamer 1.18).
    
    This commit unschedules the clock when the player is stopped.
    
    See https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/673

 gnomemusic/gstplayer.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
---
diff --git a/gnomemusic/gstplayer.py b/gnomemusic/gstplayer.py
index c46edb205..3e2bd4558 100644
--- a/gnomemusic/gstplayer.py
+++ b/gnomemusic/gstplayer.py
@@ -151,6 +151,12 @@ class GstPlayer(GObject.GObject):
             self._clock.get_time(), 1 * Gst.SECOND)
         self._clock.id_wait_async(self._clock_id, self._on_clock_tick, None)
 
+    def _destroy_clock_tick(self):
+        if (self._clock_id > 0
+                and self._clock is not None):
+            self._clock.id_unschedule(self._clock_id)
+            self._clock_id = 0
+
     def _on_new_clock(self, bus, message):
         self._clock_id = 0
         self._clock = message.parse_new_clock()
@@ -184,9 +190,7 @@ class GstPlayer(GObject.GObject):
 
         if new_state == Gst.State.PAUSED:
             self._state = Playback.PAUSED
-            if self._clock_id > 0:
-                self._clock.id_unschedule(self._clock_id)
-                self._clock_id = 0
+            self._destroy_clock_tick()
         elif new_state == Gst.State.PLAYING:
             self._state = Playback.PLAYING
             self._create_clock_tick()
@@ -244,6 +248,7 @@ class GstPlayer(GObject.GObject):
             self._player.set_state(Gst.State.NULL)
             self._state = Playback.STOPPED
             self.notify("state")
+            self._destroy_clock_tick()
         if state == Playback.LOADING:
             self._player.set_state(Gst.State.READY)
         if state == Playback.PLAYING:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]