fix gstreamer soundDriver
This commit is contained in:
parent
7bc4745e2a
commit
e31ef5d8c4
@ -4,7 +4,7 @@ enabled=True
|
|||||||
|
|
||||||
# Select the driver used to play sounds, choices are generic and gstreamer.
|
# Select the driver used to play sounds, choices are generic and gstreamer.
|
||||||
# Sox is the default.
|
# Sox is the default.
|
||||||
driver=generic
|
driver=gstreamer
|
||||||
|
|
||||||
# Sound themes. This is the pack of sounds used for sound alerts.
|
# Sound themes. This is the pack of sounds used for sound alerts.
|
||||||
# Sound packs may be located at /usr/share/sounds
|
# Sound packs may be located at /usr/share/sounds
|
||||||
|
@ -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:
|
||||||
|
Loading…
Reference in New Issue
Block a user