From 39838168ad34eaaa52b18fac88bba33fbe616eab Mon Sep 17 00:00:00 2001 From: JarbasAI <33701864+JarbasAl@users.noreply.github.com> Date: Thu, 18 Jul 2024 00:08:21 +0100 Subject: [PATCH] fix/drop_OCP_mycroft_hacks (#80) * fix/drop_OCP_mycroft_hacks OCP was loaded as a regular audio plugin, this was the only way to inject it into mycroft-core in OVOS this is no longer needed and OCP is loaded directly as part of ovos-audio (until ovos-media is released) the compat layer is dropped to avoid issues in edge cases, such as it getting selected as the default audio plugin if no others are installed, which can cause an infinite loop at playback time * read config from the old location actually call find_ocp()... forgot that in previous commit * respect self.disable_ocp flag * log old OCP version if detected --- ovos_audio/audio.py | 46 ++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/ovos_audio/audio.py b/ovos_audio/audio.py index c338e79..3065467 100644 --- a/ovos_audio/audio.py +++ b/ovos_audio/audio.py @@ -74,6 +74,7 @@ def __init__(self, bus, autoload=True, disable_ocp=False, self.service_lock = Lock() self.default = None + self.ocp = None self.service = [] self.current = None self.play_start_time = 0 @@ -89,23 +90,25 @@ def __init__(self, bus, autoload=True, disable_ocp=False, self.load_services() def find_ocp(self): + if self.disable_ocp: + LOG.info("classic OCP is disabled in config, OCP bus api not available!") + # NOTE: ovos-core should detect this and use the classic audio service api automatically + return + try: from ovos_plugin_common_play import OCPAudioBackend except ImportError: LOG.debug("classic OCP not installed") return False - - for s in self.service: - if isinstance(s, OCPAudioBackend): - LOG.info('OCP - OVOS Common Play set as default backend') - try: - s.player.validate_source = self.validate_source - s.player.native_sources = self.native_sources - except: - pass # handle older OCP plugin versions - self.default = s - return True - LOG.debug("classic OCP not found") + # config from legacy location in default mycroft.conf + ocp_config = Configuration().get("Audio", {}).get("backends", {}).get("OCP", {}) + self.ocp = OCPAudioBackend(ocp_config, bus=self.bus) + try: + self.ocp.player.validate_source = self.validate_source + self.ocp.player.native_sources = self.native_sources + except Exception as e: + # handle older OCP plugin versions + LOG.warning("old OCP version detected! please update 'ovos_plugin_common_play'") def find_default(self): if not self.service: @@ -113,9 +116,6 @@ def find_default(self): return False # Find default backend default_name = self.config.get('default-backend', '') - if self.disable_ocp and default_name == "OCP": - LOG.warning("default backend set to OCP, but OCP is disabled") - default_name = "" LOG.info('Finding default audio backend...') for s in self.service: if s.name == default_name: @@ -133,7 +133,7 @@ def load_services(self): for the subsystem. """ found_plugins = find_audio_service_plugins() - if 'ovos_common_play' in found_plugins and self.disable_ocp: + if 'ovos_common_play' in found_plugins: found_plugins.pop('ovos_common_play') local = [] @@ -156,13 +156,13 @@ def load_services(self): for s in self.service: s.set_track_start_callback(self.track_start) - if self.disable_ocp: - LOG.debug("disable_ocp flag is set!") - # default to classic audio only service - self.find_default() - else: - # default to OCP, fallback to classic audio only service - self.find_ocp() or self.find_default() + # load OCP + # NOTE: this will be replace by ovos-media in a future release + # and can be disabled in config + self.find_ocp() + + # load audio playback plugins (vlc, mpv, spotify ...) + self.find_default() # Setup event handlers self.bus.on('mycroft.audio.service.play', self._play)