Merge branch 'feature/spotify-to-use-gst-time' into feature/limit-spotify-data-pushing
Conflicts: mopidy/audio/actor.py mopidy/backends/spotify/playback.py
This commit is contained in:
commit
8505ea7f4e
@ -47,6 +47,7 @@ class Audio(pykka.ThreadingActor):
|
||||
self._volume_set = None
|
||||
|
||||
self._appsrc = None
|
||||
self._appsrc_caps = None
|
||||
self._appsrc_need_data_callback = None
|
||||
self._appsrc_need_data_id = None
|
||||
self._appsrc_enough_data_callback = None
|
||||
@ -88,6 +89,7 @@ class Audio(pykka.ThreadingActor):
|
||||
source, self._appsrc = self._appsrc, None
|
||||
if source is None:
|
||||
return
|
||||
self._appsrc_caps = None
|
||||
if self._appsrc_need_data_id is not None:
|
||||
source.disconnect(self._appsrc_need_data_id)
|
||||
self._appsrc_need_data_id = None
|
||||
@ -103,13 +105,8 @@ class Audio(pykka.ThreadingActor):
|
||||
if not uri or not uri.startswith('appsrc://'):
|
||||
return
|
||||
|
||||
# These caps matches the audio data provided by libspotify
|
||||
default_caps = gst.Caps(
|
||||
b'audio/x-raw-int, endianness=(int)1234, channels=(int)2, '
|
||||
b'width=(int)16, depth=(int)16, signed=(boolean)true, '
|
||||
b'rate=(int)44100')
|
||||
source = element.get_property('source')
|
||||
source.set_property('caps', default_caps)
|
||||
source.set_property('caps', self._appsrc_caps)
|
||||
source.set_property('format', b'time')
|
||||
source.set_property('stream-type', b'seekable')
|
||||
source.set_property('max-bytes', 1024 * 1024) # 1 MB
|
||||
@ -290,12 +287,16 @@ class Audio(pykka.ThreadingActor):
|
||||
"""
|
||||
self._playbin.set_property('uri', uri)
|
||||
|
||||
def set_appsrc(self, need_data=None, enough_data=None, seek_data=None):
|
||||
def set_appsrc(
|
||||
self, caps, need_data=None, enough_data=None, seek_data=None):
|
||||
"""
|
||||
Switch to using appsrc for getting audio to be played.
|
||||
|
||||
You *MUST* call :meth:`prepare_change` before calling this method.
|
||||
|
||||
:param caps: GStreamer caps string describing the audio format to
|
||||
expect
|
||||
:type caps: string
|
||||
:param need_data: callback for when appsrc needs data
|
||||
:type need_data: callable which takes data length hint in ms
|
||||
:param enough_data: callback for when appsrc has enough data
|
||||
@ -304,6 +305,9 @@ class Audio(pykka.ThreadingActor):
|
||||
to continue playback
|
||||
:type seek_data: callable which takes time position in ms
|
||||
"""
|
||||
if isinstance(caps, unicode):
|
||||
caps = caps.encode('utf-8')
|
||||
self._appsrc_caps = gst.Caps(caps)
|
||||
self._appsrc_need_data_callback = need_data
|
||||
self._appsrc_enough_data_callback = enough_data
|
||||
self._appsrc_seek_data_callback = seek_data
|
||||
|
||||
@ -27,6 +27,12 @@ def seek_data_callback(spotify_backend, time_position):
|
||||
|
||||
|
||||
class SpotifyPlaybackProvider(base.BasePlaybackProvider):
|
||||
# These GStreamer caps matches the audio data provided by libspotify
|
||||
_caps = (
|
||||
'audio/x-raw-int, endianness=(int)1234, channels=(int)2, '
|
||||
'width=(int)16, depth=(int)16, signed=(boolean)true, '
|
||||
'rate=(int)44100')
|
||||
|
||||
def play(self, track):
|
||||
if track.uri is None:
|
||||
return False
|
||||
@ -42,6 +48,7 @@ class SpotifyPlaybackProvider(base.BasePlaybackProvider):
|
||||
|
||||
self.audio.prepare_change()
|
||||
self.audio.set_appsrc(
|
||||
self._caps,
|
||||
need_data=None,
|
||||
enough_data=None,
|
||||
seek_data=seek_data_callback_bound)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user