Update gstreamer.py
This commit is contained in:
parent
f486d2beb0
commit
efd302bf16
@ -9,9 +9,6 @@ except:
|
|||||||
else:
|
else:
|
||||||
_gstreamerAvailable, args = Gst.init_check(None)
|
_gstreamerAvailable, args = Gst.init_check(None)
|
||||||
|
|
||||||
from . import debug
|
|
||||||
from .sound_generator import Icon, Tone
|
|
||||||
|
|
||||||
class sound:
|
class sound:
|
||||||
"""Plays Icons and Tones."""
|
"""Plays Icons and Tones."""
|
||||||
|
|
||||||
@ -19,12 +16,8 @@ class sound:
|
|||||||
self._initialized = False
|
self._initialized = False
|
||||||
self._source = None
|
self._source = None
|
||||||
self._sink = None
|
self._sink = None
|
||||||
|
|
||||||
if not _gstreamerAvailable:
|
if not _gstreamerAvailable:
|
||||||
msg = 'SOUND ERROR: Gstreamer is not available'
|
|
||||||
debug.println(debug.LEVEL_INFO, msg, True)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
self.init()
|
self.init()
|
||||||
|
|
||||||
def _onPlayerMessage(self, bus, message):
|
def _onPlayerMessage(self, bus, message):
|
||||||
@ -33,8 +26,6 @@ class sound:
|
|||||||
elif message.type == Gst.MessageType.ERROR:
|
elif message.type == Gst.MessageType.ERROR:
|
||||||
self._player.set_state(Gst.State.NULL)
|
self._player.set_state(Gst.State.NULL)
|
||||||
error, info = message.parse_error()
|
error, info = message.parse_error()
|
||||||
msg = 'SOUND ERROR: %s' % error
|
|
||||||
debug.println(debug.LEVEL_INFO, msg, True)
|
|
||||||
|
|
||||||
def _onPipelineMessage(self, bus, message):
|
def _onPipelineMessage(self, bus, message):
|
||||||
if message.type == Gst.MessageType.EOS:
|
if message.type == Gst.MessageType.EOS:
|
||||||
@ -42,28 +33,20 @@ class sound:
|
|||||||
elif message.type == Gst.MessageType.ERROR:
|
elif message.type == Gst.MessageType.ERROR:
|
||||||
self._pipeline.set_state(Gst.State.NULL)
|
self._pipeline.set_state(Gst.State.NULL)
|
||||||
error, info = message.parse_error()
|
error, info = message.parse_error()
|
||||||
msg = 'SOUND ERROR: %s' % error
|
|
||||||
debug.println(debug.LEVEL_INFO, msg, True)
|
|
||||||
|
|
||||||
def _onTimeout(self, element):
|
def _onTimeout(self, element):
|
||||||
element.set_state(Gst.State.NULL)
|
element.set_state(Gst.State.NULL)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _playIcon(self, icon, interrupt=True):
|
def playSoundFile(self, fileName, interrupt=True):
|
||||||
"""Plays a sound icon, interrupting the current play first unless specified."""
|
|
||||||
|
|
||||||
if interrupt:
|
if interrupt:
|
||||||
self._player.set_state(Gst.State.NULL)
|
self.stop()
|
||||||
|
self._player.set_property('uri', 'file://%s' % fileName)
|
||||||
self._player.set_property('uri', 'file://%s' % icon.path)
|
|
||||||
self._player.set_state(Gst.State.PLAYING)
|
self._player.set_state(Gst.State.PLAYING)
|
||||||
|
|
||||||
def _playTone(self, tone, interrupt=True):
|
def playFrequence(self, frequence, duration, adjustVolume, interrupt=True):
|
||||||
"""Plays a tone, interrupting the current play first unless specified."""
|
|
||||||
|
|
||||||
if interrupt:
|
if interrupt:
|
||||||
self._pipeline.set_state(Gst.State.NULL)
|
self.stop()
|
||||||
|
|
||||||
self._source.set_property('volume', tone.volume)
|
self._source.set_property('volume', tone.volume)
|
||||||
self._source.set_property('freq', tone.frequency)
|
self._source.set_property('freq', tone.frequency)
|
||||||
self._source.set_property('wave', tone.wave)
|
self._source.set_property('wave', tone.wave)
|
||||||
@ -73,10 +56,8 @@ class sound:
|
|||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
"""(Re)Initializes the Player."""
|
"""(Re)Initializes the Player."""
|
||||||
|
|
||||||
if self._initialized:
|
if self._initialized:
|
||||||
return
|
return
|
||||||
|
|
||||||
if not _gstreamerAvailable:
|
if not _gstreamerAvailable:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -85,7 +66,7 @@ class sound:
|
|||||||
bus.add_signal_watch()
|
bus.add_signal_watch()
|
||||||
bus.connect("message", self._onPlayerMessage)
|
bus.connect("message", self._onPlayerMessage)
|
||||||
|
|
||||||
self._pipeline = Gst.Pipeline(name='orca-pipeline')
|
self._pipeline = Gst.Pipeline(name='fenrir-pipeline')
|
||||||
bus = self._pipeline.get_bus()
|
bus = self._pipeline.get_bus()
|
||||||
bus.add_signal_watch()
|
bus.add_signal_watch()
|
||||||
bus.connect("message", self._onPipelineMessage)
|
bus.connect("message", self._onPipelineMessage)
|
||||||
@ -98,37 +79,19 @@ class sound:
|
|||||||
|
|
||||||
self._initialized = True
|
self._initialized = True
|
||||||
|
|
||||||
def play(self, item, interrupt=True):
|
|
||||||
"""Plays a sound, interrupting the current play first unless specified."""
|
|
||||||
|
|
||||||
if isinstance(item, Icon):
|
|
||||||
self._playIcon(item, interrupt)
|
|
||||||
elif isinstance(item, Tone):
|
|
||||||
self._playTone(item, interrupt)
|
|
||||||
else:
|
|
||||||
msg = 'SOUND ERROR: %s is not an Icon or Tone' % item
|
|
||||||
debug.println(debug.LEVEL_INFO, msg, True)
|
|
||||||
|
|
||||||
def stop(self, element=None):
|
def stop(self, element=None):
|
||||||
"""Stops play."""
|
|
||||||
|
|
||||||
if not _gstreamerAvailable:
|
if not _gstreamerAvailable:
|
||||||
return
|
return
|
||||||
|
|
||||||
if element:
|
if element:
|
||||||
element.set_state(Gst.State.NULL)
|
element.set_state(Gst.State.NULL)
|
||||||
return
|
return
|
||||||
|
|
||||||
self._player.set_state(Gst.State.NULL)
|
self._player.set_state(Gst.State.NULL)
|
||||||
self._pipeline.set_state(Gst.State.NULL)
|
self._pipeline.set_state(Gst.State.NULL)
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
"""Shuts down the sound utilities."""
|
|
||||||
|
|
||||||
global _gstreamerAvailable
|
global _gstreamerAvailable
|
||||||
if not _gstreamerAvailable:
|
if not _gstreamerAvailable:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.stop()
|
self.stop()
|
||||||
self._initialized = False
|
self._initialized = False
|
||||||
_gstreamerAvailable = False
|
_gstreamerAvailable = False
|
||||||
|
Loading…
Reference in New Issue
Block a user