[gnome-music/wip/jfelder/gstplayer-higcpu-eos: 4/4] gstplayer: Unschedule the clock when stopped




commit 533fdef95ea23f13c23cd1507ab5566a67652413
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 88c780cbc..d7a6fea4d 100644
--- a/gnomemusic/gstplayer.py
+++ b/gnomemusic/gstplayer.py
@@ -157,6 +157,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 _unschedule_clock_tick(self) -> None:
+        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()
@@ -190,9 +196,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._unschedule_clock_tick()
         elif new_state == Gst.State.PLAYING:
             self._state = Playback.PLAYING
             self._create_clock_tick()
@@ -250,6 +254,7 @@ class GstPlayer(GObject.GObject):
             self._player.set_state(Gst.State.NULL)
             self._state = Playback.STOPPED
             self.notify("state")
+            self._unschedule_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]