From e31ef5d8c45176c828ddc3984c280a8ce464e438 Mon Sep 17 00:00:00 2001 From: chrys Date: Tue, 15 Nov 2016 23:31:20 +0100 Subject: [PATCH] fix gstreamer soundDriver --- config/settings/settings.conf | 2 +- src/fenrir/soundDriver/gstreamer.py | 29 ++++++++++++++++------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/config/settings/settings.conf b/config/settings/settings.conf index eb8146df..fc322b66 100644 --- a/config/settings/settings.conf +++ b/config/settings/settings.conf @@ -4,7 +4,7 @@ enabled=True # Select the driver used to play sounds, choices are generic and gstreamer. # Sox is the default. -driver=generic +driver=gstreamer # Sound themes. This is the pack of sounds used for sound alerts. # Sound packs may be located at /usr/share/sounds diff --git a/src/fenrir/soundDriver/gstreamer.py b/src/fenrir/soundDriver/gstreamer.py index 5e232532..aba0de06 100644 --- a/src/fenrir/soundDriver/gstreamer.py +++ b/src/fenrir/soundDriver/gstreamer.py @@ -6,8 +6,9 @@ from core import debug import gi -import time -from gi.repository import GLib +import time, threading +gi.require_version('Gtk', '3.0') +from gi.repository import GLib, Gtk try: gi.require_version('Gst', '1.0') @@ -23,12 +24,12 @@ class driver: self._source = None self._sink = None self.volume = 1 - if not _gstreamerAvailable: - return def initialize(self, environment): if self._initialized: return + global _gstreamerAvailable if not _gstreamerAvailable: + self.environment['runtime']['debug'].writeDebugOut('Gstreamer not available',debug.debugLevel.ERROR) return self.env = environment self._player = Gst.ElementFactory.make('playbin', 'player') @@ -48,12 +49,14 @@ class driver: self._source.link(self._sink) self._initialized = True - return + self.thread = threading.Thread(target=self.main) + self.thread.start() def shutdown(self): - global _gstreamerAvailable + global _gstreamerAvailable if not _gstreamerAvailable: return self.cancel() + Gtk.main_quit() self._initialized = False _gstreamerAvailable = False @@ -63,27 +66,25 @@ class driver: elif message.type == Gst.MessageType.ERROR: self._player.set_state(Gst.State.NULL) error, info = message.parse_error() - print(error, info) - print('_onPlayerMessage') + self.env['runtime']['debug'].writeDebugOut('GSTREAMER: _onPlayerMessage'+ str(error) + str(info),debug.debugLevel.WARNING) + def _onPipelineMessage(self, bus, message): if message.type == Gst.MessageType.EOS: self._pipeline.set_state(Gst.State.NULL) elif message.type == Gst.MessageType.ERROR: self._pipeline.set_state(Gst.State.NULL) error, info = message.parse_error() - print(error, info) - print('_onPipelineMessage') + self.env['runtime']['debug'].writeDebugOut('GSTREAMER: _onPipelineMessage'+ str(error) + str(info),debug.debugLevel.WARNING) def _onTimeout(self, element): element.set_state(Gst.State.NULL) - return False def playSoundFile(self, fileName, interrupt=True): if interrupt: self.cancel() self._player.set_property('uri', 'file://%s' % fileName) self._player.set_state(Gst.State.PLAYING) - print('playSoundFile') + def playFrequence(self, frequence, duration, adjustVolume, interrupt=True): if interrupt: self.cancel() @@ -93,8 +94,10 @@ class driver: self._pipeline.set_state(Gst.State.PLAYING) duration = int(1000 * tone.duration) GLib.timeout_add(duration, self._onTimeout, self._pipeline) - + def main(self): + Gtk.main() def cancel(self, element=None): + global _gstreamerAvailable if not _gstreamerAvailable: return if element: