From 4d287697e42a53575fc6be34af9211851f728d37 Mon Sep 17 00:00:00 2001 From: Thomas Scholtes Date: Sat, 29 Mar 2014 15:10:56 +0100 Subject: [PATCH] Pause gstreamer when buffering When the `playbin2` pipeline is in `PLAYING` state and its buffer is empty the pipeline will consume arriving data immediately. If the source is an HTTP stream this leads to choppy playback. To fix this we pause playing when the buffer is nearly empty and wait for it to fill up until we resume playing. This approach is recommended in the gstreamer manual [1]. We might want to extract the hard-coded 10% mark and make it configurable. [1]: http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/chapter-buffering.html --- mopidy/audio/actor.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mopidy/audio/actor.py b/mopidy/audio/actor.py index ca023125..93b2769e 100644 --- a/mopidy/audio/actor.py +++ b/mopidy/audio/actor.py @@ -278,6 +278,10 @@ class Audio(pykka.ThreadingActor): self._on_playbin_state_changed(old_state, new_state, pending_state) elif message.type == gst.MESSAGE_BUFFERING: percent = message.parse_buffering() + if percent < 10: + self._playbin.set_state(gst.STATE_PAUSED) + if percent == 100: + self._playbin.set_state(gst.STATE_PLAYING) logger.debug('Buffer %d%% full', percent) elif message.type == gst.MESSAGE_EOS: self._on_end_of_stream()