Merge branch 'gstreamer' of github.com:knutz3n/mopidy into gstreamer

This commit is contained in:
Johannes Knutsen 2010-08-10 13:25:14 +02:00
commit 2c8234f505

View File

@ -43,8 +43,7 @@ class LibspotifyBackend(BaseBackend):
self.stored_playlists = LibspotifyStoredPlaylistsController(
backend=self)
self.uri_handlers = [u'spotify:', u'http://open.spotify.com/']
self.audio_controller_class = kwargs.get(
'audio_controller_class', AlsaController)
self.gstreamer_pipeline = gst.Pipeline("spotify_pipeline")
self.spotify = self._connect()
def _connect(self):
@ -52,7 +51,7 @@ class LibspotifyBackend(BaseBackend):
spotify = LibspotifySessionManager(
settings.SPOTIFY_USERNAME, settings.SPOTIFY_PASSWORD,
core_queue=self.core_queue,
audio_controller_class=self.audio_controller_class)
gstreamer_pipeline=self.gstreamer_pipeline)
spotify.start()
return spotify
@ -99,6 +98,7 @@ class LibspotifyPlaybackController(BasePlaybackController):
return False
def _play(self, track):
self.backend.gstreamer_pipeline.set_state(gst.STATE_READY)
if self.state == self.PLAYING:
self.stop()
if track.uri is None:
@ -107,6 +107,7 @@ class LibspotifyPlaybackController(BasePlaybackController):
self.backend.spotify.session.load(
Link.from_string(track.uri).as_track())
self.backend.spotify.session.play(1)
self.backend.gstreamer_pipeline.set_state(gst.STATE_PLAYING)
return True
except SpotifyError as e:
logger.warning('Play %s failed: %s', track.uri, e)
@ -120,6 +121,7 @@ class LibspotifyPlaybackController(BasePlaybackController):
pass # TODO
def _stop(self):
self.backend.gstreamer_pipeline.set_state(gst.STATE_READY)
self.backend.spotify.session.play(0)
return True
@ -194,6 +196,21 @@ class LibspotifyTranslator(object):
tracks=[cls.to_mopidy_track(t) for t in spotify_playlist],
)
class GstreamerMessageBusProcess(threading.Thread):
def __init__(self, core_queue, pipeline):
super(GstreamerMessageBusProcess, self).__init__()
self.core_queue = core_queue
self.bus = pipeline.get_bus()
def run(self):
while True:
message = self.bus.pop()
if message is not None:
logger.debug('Got Gstreamer message of type: %s' % message.type)
if message is not None and (
message.type == gst.MESSAGE_EOS
or message.type == gst.MESSAGE_ERROR):
self.core_queue.put({'command': 'end_of_track'})
class LibspotifySessionManager(SpotifySessionManager, threading.Thread):
cache_location = os.path.expanduser(settings.SPOTIFY_LIB_CACHE)
@ -201,12 +218,13 @@ class LibspotifySessionManager(SpotifySessionManager, threading.Thread):
appkey_file = os.path.expanduser(settings.SPOTIFY_LIB_APPKEY)
user_agent = 'Mopidy %s' % get_version()
def __init__(self, username, password, core_queue, audio_controller_class):
def __init__(self, username, password, core_queue, gstreamer_pipeline):
SpotifySessionManager.__init__(self, username, password)
threading.Thread.__init__(self)
self.core_queue = core_queue
self.connected = threading.Event()
self.session = None
self.gstreamer_pipeline = gstreamer_pipeline
cap_string = """audio/x-raw-int,
endianness=(int)1234,
@ -222,12 +240,12 @@ class LibspotifySessionManager(SpotifySessionManager, threading.Thread):
self.gsink = gst.element_factory_make("autoaudiosink", "autosink")
self.pipeline = gst.Pipeline("spotify_pipeline")
self.pipeline.add(self.gsrc, self.gsink)
self.gstreamer_pipeline.add(self.gsrc, self.gsink)
gst.element_link_many(self.gsrc, self.gsink)
self.pipeline.set_state(gst.STATE_PLAYING)
message_process = GstreamerMessageBusProcess(self.core_queue, self.gstreamer_pipeline)
message_process.start()
def run(self):
self.connect()
@ -292,8 +310,9 @@ class LibspotifySessionManager(SpotifySessionManager, threading.Thread):
def end_of_track(self, session):
"""Callback used by pyspotify"""
logger.debug('End of track')
self.core_queue.put({'command': 'end_of_track'})
logger.debug('End of track.')
self.gsrc.emit('end-of-stream')
logger.debug('End of stream sent to gstreamer.')
def search(self, query, connection):
"""Search method used by Mopidy backend"""