Browse files

Fixes to gstreamer sink based on comments in merge-review.

  • Loading branch information...
1 parent eedf05a commit 3b8dddf3b0a82b9dbd3a7e0a7cf2bf5dfb8b3a6e @wuurrd wuurrd committed Feb 15, 2012
View
13 examples/jukebox.py
@@ -28,6 +28,7 @@ def __init__(self, jukebox):
def run(self):
container_loaded.wait()
+ container_loaded.clear()
try:
self.cmdloop()
except Exception, e:
@@ -267,7 +268,6 @@ def tracks_removed(self, p, t, u):
class JukeboxContainerManager(SpotifyContainerManager):
def container_loaded(self, c, u):
container_loaded.set()
- container_loaded.clear()
def playlist_added(self, c, p, i, u):
print 'Container: playlist "%s" added.' % p.name()
@@ -287,10 +287,7 @@ class Jukebox(SpotifySessionManager):
def __init__(self, *a, **kw):
SpotifySessionManager.__init__(self, *a, **kw)
- self.audio = AudioSink()
- if self.audio.async:
- self.audio.backend = self
- self.audio.setup()
+ self.audio = AudioSink(backend=self)
self.ui = JukeboxUI(self)
self.ctr = None
self.playing = False
@@ -388,11 +385,7 @@ def next(self):
self.stop()
def end_of_track(self, sess):
- if self.audio.async:
- self.audio.emit_EOS()
- return
- print "track ends."
- self.next()
+ self.audio.end_of_track()
def search(self, *args, **kwargs):
self.session.search(*args, **kwargs)
View
10 spotify/audiosink/__init__.py
@@ -55,9 +55,9 @@ class BaseAudioSink(object):
it easy to play audio data received from Spotify.
"""
- def __init__(self):
+ def __init__(self, backend=None):
self._call_cache = {}
- self.async = False
+ self.backend = backend
def music_delivery(self, session, frames, frame_size, num_frames,
sample_type, sample_rate, channels):
@@ -87,6 +87,12 @@ def music_delivery(self, session, frames, frame_size, num_frames,
"""
raise NotImplementedError
+ def end_of_track(self, session):
+ self.end_of_track_data(session)
+
+ def end_of_track_data(self):
+ self.backend.next()
+
def start(self):
"""
Should be called when audio output starts.
View
6 spotify/audiosink/alsa.py
@@ -6,10 +6,10 @@
class AlsaSink(BaseAudioSink):
"""Audio sink wrapper for systems with ALSA, e.g. most Linux systems"""
- def __init__(self, mode=alsaaudio.PCM_NORMAL):
- super(AlsaSink, self).__init__()
+ def __init__(self, **kwargs):
+ self._mode = kwargs.popitem('mode', alsaaudio.PCM_NORMAL)
+ super(AlsaSink, self).__init__(**kwargs)
self._device = None
- self._mode = mode
if sys.byteorder == 'little':
self._format = alsaaudio.PCM_FORMAT_S16_LE
elif sys.byteorder == 'big':
View
21 spotify/audiosink/gstreamer.py
@@ -1,10 +1,12 @@
import threading
+import logging
import gobject
import gst
import sys
from spotify.audiosink import BaseAudioSink
+log = logging.getLogger(__name__)
gobject.threads_init()
CAPS_TEMPLATE = """
@@ -23,8 +25,8 @@ class GstreamerSink(BaseAudioSink):
Linux, Mac OS X, and Windows systems.
"""
- def __init__(self):
- super(GstreamerSink, self).__init__()
+ def __init__(self, **kwargs):
+ super(GstreamerSink, self).__init__(**kwargs)
if sys.byteorder == 'little':
self._endianness = '1234'
elif sys.byteorder == 'big':
@@ -42,21 +44,16 @@ def __init__(self):
]))
self._source = self._pipeline.get_by_name('application_src')
self._source.set_property('caps', caps)
- self.async = True
- self.backend = None
self.mainloop = None
self.mainloop_thread = threading.Thread(target=self.start_glib)
self.mainloop_thread.setDaemon(True)
self.mainloop_thread.start()
-
+ self._setup_message_processor()
def start_glib(self):
self.mainloop = gobject.MainLoop()
self.mainloop.run()
- print 'Mainloop running'
-
- def setup(self):
- self._setup_message_processor()
+ log.info('Mainloop running')
def _setup_message_processor(self):
bus = self._pipeline.get_bus()
@@ -65,11 +62,11 @@ def _setup_message_processor(self):
def _on_message(self, bus, message):
if message.type == gst.MESSAGE_EOS:
- print 'track ended'
+ log.info('track ended')
self._pipeline.set_state(gst.STATE_NULL)
- self.backend.next()
+ self.end_of_track_data()
- def emit_EOS(self):
+ def end_of_track(self):
self._source.emit('end-of-stream')
def music_delivery(self, session, frames, frame_size, num_frames,
View
4 spotify/audiosink/oss.py
@@ -6,8 +6,8 @@
class OssSink(BaseAudioSink):
"""Audio sink wrapper for systems with OSS, e.g. older Linux systems"""
- def __init__(self):
- super(OssSink, self).__init__()
+ def __init__(self, **kwargs):
+ super(OssSink, self).__init__(**kwargs)
self._device = None
if sys.byteorder == 'little':
self._format = ossaudiodev.AFMT_S16_LE
View
4 spotify/audiosink/portaudio.py
@@ -8,8 +8,8 @@ class PortAudioSink(BaseAudioSink):
include Linux, Mac OS X, and Windows systems.
"""
- def __init__(self):
- super(PortAudioSink, self).__init__()
+ def __init__(self, **kwargs):
+ super(PortAudioSink, self).__init__(**kwargs)
self._device = pyaudio.PyAudio()
self._stream = None

0 comments on commit 3b8dddf

Please sign in to comment.