Merge branch 'master' into wordWrappingEndOfScreenBell

This commit is contained in:
chrys 2016-11-15 23:33:46 +01:00
commit e0906aa05d
4 changed files with 16 additions and 22 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,9 +0,0 @@
#!/bin/python
import time
from sound.gstreamer import sound
s = sound()
s.playSoundFile('/home/chrys/Projekte/fenrir/fenrir/src/fenrir-package/1ChangeTTY.opus')
time.sleep(10)

View File

@ -6,8 +6,9 @@
from core import debug from core import debug
import gi import gi
import time import time, threading
from gi.repository import GLib gi.require_version('Gtk', '3.0')
from gi.repository import GLib, Gtk
try: try:
gi.require_version('Gst', '1.0') gi.require_version('Gst', '1.0')
@ -23,12 +24,12 @@ class driver:
self._source = None self._source = None
self._sink = None self._sink = None
self.volume = 1 self.volume = 1
if not _gstreamerAvailable:
return
def initialize(self, environment): def initialize(self, environment):
if self._initialized: if self._initialized:
return return
global _gstreamerAvailable
if not _gstreamerAvailable: if not _gstreamerAvailable:
self.environment['runtime']['debug'].writeDebugOut('Gstreamer not available',debug.debugLevel.ERROR)
return return
self.env = environment self.env = environment
self._player = Gst.ElementFactory.make('playbin', 'player') self._player = Gst.ElementFactory.make('playbin', 'player')
@ -48,12 +49,14 @@ class driver:
self._source.link(self._sink) self._source.link(self._sink)
self._initialized = True self._initialized = True
return self.thread = threading.Thread(target=self.main)
self.thread.start()
def shutdown(self): def shutdown(self):
global _gstreamerAvailable global _gstreamerAvailable
if not _gstreamerAvailable: if not _gstreamerAvailable:
return return
self.cancel() self.cancel()
Gtk.main_quit()
self._initialized = False self._initialized = False
_gstreamerAvailable = False _gstreamerAvailable = False
@ -63,27 +66,25 @@ class driver:
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()
print(error, info) self.env['runtime']['debug'].writeDebugOut('GSTREAMER: _onPlayerMessage'+ str(error) + str(info),debug.debugLevel.WARNING)
print('_onPlayerMessage')
def _onPipelineMessage(self, bus, message): def _onPipelineMessage(self, bus, message):
if message.type == Gst.MessageType.EOS: if message.type == Gst.MessageType.EOS:
self._pipeline.set_state(Gst.State.NULL) self._pipeline.set_state(Gst.State.NULL)
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()
print(error, info) self.env['runtime']['debug'].writeDebugOut('GSTREAMER: _onPipelineMessage'+ str(error) + str(info),debug.debugLevel.WARNING)
print('_onPipelineMessage')
def _onTimeout(self, element): def _onTimeout(self, element):
element.set_state(Gst.State.NULL) element.set_state(Gst.State.NULL)
return False
def playSoundFile(self, fileName, interrupt=True): def playSoundFile(self, fileName, interrupt=True):
if interrupt: if interrupt:
self.cancel() self.cancel()
self._player.set_property('uri', 'file://%s' % fileName) self._player.set_property('uri', 'file://%s' % fileName)
self._player.set_state(Gst.State.PLAYING) self._player.set_state(Gst.State.PLAYING)
print('playSoundFile')
def playFrequence(self, frequence, duration, adjustVolume, interrupt=True): def playFrequence(self, frequence, duration, adjustVolume, interrupt=True):
if interrupt: if interrupt:
self.cancel() self.cancel()
@ -93,8 +94,10 @@ class driver:
self._pipeline.set_state(Gst.State.PLAYING) self._pipeline.set_state(Gst.State.PLAYING)
duration = int(1000 * tone.duration) duration = int(1000 * tone.duration)
GLib.timeout_add(duration, self._onTimeout, self._pipeline) GLib.timeout_add(duration, self._onTimeout, self._pipeline)
def main(self):
Gtk.main()
def cancel(self, element=None): def cancel(self, element=None):
global _gstreamerAvailable
if not _gstreamerAvailable: if not _gstreamerAvailable:
return return
if element: if element: