Skip to content

Commit

Permalink
feat/bump_ocp
Browse files Browse the repository at this point in the history
validate message source in OCP

pass validate_source kwarg from audio service to OCP plugin

more logs

fix lower_volume without self.current being set

companion to OpenVoiceOS/ovos-ocp-audio-plugin#120
  • Loading branch information
JarbasAl committed Jun 6, 2024
1 parent 7c3de2e commit 14d6e7b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
22 changes: 13 additions & 9 deletions ovos_audio/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import time
from threading import Lock

import time
from ovos_bus_client.message import Message
from ovos_config.config import Configuration
from ovos_plugin_manager.audio import load_audio_service_plugins as load_plugins, find_audio_service_plugins, setup_audio_service
from ovos_plugin_manager.templates.audio import RemoteAudioBackend
from ovos_utils.log import LOG
from ovos_utils.process_utils import MonotonicEvent
from ovos_audio.utils import validate_message_context

try:
from ovos_plugin_common_play import OCPAudioBackend
except ImportError:
OCPAudioBackend = None
from ovos_audio.utils import validate_message_context

try:
from ovos_utils.ocp import MediaState
Expand Down Expand Up @@ -58,7 +54,6 @@ class MediaState(IntEnum):
# The current media cannot be played. PlayerState == STOPPED
INVALID_MEDIA = 8


MINUTES = 60 # Seconds in a minute


Expand Down Expand Up @@ -90,11 +85,19 @@ def __init__(self, bus, autoload=True, disable_ocp=False, validate_source=True):
self.load_services()

def find_ocp(self):
try:
from ovos_plugin_common_play import OCPAudioBackend
except ImportError:
LOG.debug("classic OCP not installed")
return False

for s in self.service:
if OCPAudioBackend is not None and isinstance(s, OCPAudioBackend):
if isinstance(s, OCPAudioBackend):
LOG.info('OCP - OVOS Common Play set as default backend')
s.player.validate_source = self.validate_source
self.default = s
return True
LOG.debug("classic OCP not found")

def find_default(self):
# Find default backend
Expand Down Expand Up @@ -143,6 +146,7 @@ def load_services(self):
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:
Expand Down Expand Up @@ -330,7 +334,7 @@ def _restore_volume_after_record(self, message=None):
return

def restore_volume(msg=message):
if self.volume_is_low:
if self.volume_is_low and self.current:
LOG.debug('restoring volume')
self.current.restore_volume()

Expand Down
1 change: 1 addition & 0 deletions ovos_audio/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def __init__(self, ready_hook=on_ready, error_hook=on_error,
if disable_ocp is None:
disable_ocp = self.config.get("disable_ocp", False) # TODO default to True soon
self.disable_ocp = disable_ocp
LOG.debug(f"legacy audio service enabled: {self.audio_enabled}")
if self.audio_enabled:
try:
self.audio = AudioService(self.bus, disable_ocp=disable_ocp, validate_source=validate_source)
Expand Down

0 comments on commit 14d6e7b

Please sign in to comment.