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
This commit is contained in:
Thomas Scholtes 2014-03-29 15:10:56 +01:00
parent ed918fc7ff
commit 4d287697e4

View File

@ -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()