fix gstreamer soundDriver

This commit is contained in:
chrys 2016-11-15 23:31:20 +01:00
parent 7bc4745e2a
commit e31ef5d8c4
2 changed files with 17 additions and 14 deletions

View File

@ -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

View File

@ -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: