Skip to content

Commit

Permalink
fix/drop_OCP_mycroft_hacks (#80)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
JarbasAl authored Jul 17, 2024
1 parent 2fcea0b commit 3983816
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions ovos_audio/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -89,33 +90,32 @@ 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:
LOG.error("No audio player plugins found!")
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:
Expand All @@ -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 = []
Expand All @@ -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)
Expand Down

0 comments on commit 3983816

Please sign in to comment.