audio: Use new config system
This commit is contained in:
parent
1ca6ffc6fb
commit
42707f50df
@ -9,7 +9,6 @@ import logging
|
||||
|
||||
import pykka
|
||||
|
||||
from mopidy import settings
|
||||
from mopidy.utils import process
|
||||
|
||||
from . import mixers, utils
|
||||
@ -28,11 +27,14 @@ class Audio(pykka.ThreadingActor):
|
||||
"""
|
||||
Audio output through `GStreamer <http://gstreamer.freedesktop.org/>`_.
|
||||
|
||||
**Settings:**
|
||||
**Default config:**
|
||||
|
||||
- :attr:`mopidy.settings.OUTPUT`
|
||||
- :attr:`mopidy.settings.MIXER`
|
||||
- :attr:`mopidy.settings.MIXER_TRACK`
|
||||
.. code-block:: ini
|
||||
|
||||
[audio]
|
||||
mixer = autoaudiomixer
|
||||
mixer_track =
|
||||
output = autoaudiosink
|
||||
"""
|
||||
|
||||
#: The GStreamer state mapped to :class:`mopidy.audio.PlaybackState`
|
||||
@ -41,6 +43,8 @@ class Audio(pykka.ThreadingActor):
|
||||
def __init__(self, config):
|
||||
super(Audio, self).__init__()
|
||||
|
||||
self._config = config
|
||||
|
||||
self._playbin = None
|
||||
self._signal_ids = {} # {(element, event): signal_id}
|
||||
|
||||
@ -143,47 +147,51 @@ class Audio(pykka.ThreadingActor):
|
||||
self._playbin.set_state(gst.STATE_NULL)
|
||||
|
||||
def _setup_output(self):
|
||||
output_desc = self._config['audio']['output']
|
||||
try:
|
||||
output = gst.parse_bin_from_description(
|
||||
settings.OUTPUT, ghost_unconnected_pads=True)
|
||||
output_desc, ghost_unconnected_pads=True)
|
||||
self._playbin.set_property('audio-sink', output)
|
||||
logger.info('Audio output set to "%s"', settings.OUTPUT)
|
||||
logger.info('Audio output set to "%s"', output_desc)
|
||||
except gobject.GError as ex:
|
||||
logger.error(
|
||||
'Failed to create audio output "%s": %s', settings.OUTPUT, ex)
|
||||
'Failed to create audio output "%s": %s', output_desc, ex)
|
||||
process.exit_process()
|
||||
|
||||
def _setup_mixer(self):
|
||||
if not settings.MIXER:
|
||||
mixer_desc = self._config['audio']['mixer']
|
||||
track_desc = self._config['audio']['mixer_track']
|
||||
|
||||
if mixer_desc is None:
|
||||
logger.info('Not setting up audio mixer')
|
||||
return
|
||||
|
||||
if settings.MIXER == 'software':
|
||||
if mixer_desc == 'software':
|
||||
self._software_mixing = True
|
||||
logger.info('Audio mixer is using software mixing')
|
||||
return
|
||||
|
||||
try:
|
||||
mixerbin = gst.parse_bin_from_description(
|
||||
settings.MIXER, ghost_unconnected_pads=False)
|
||||
mixer_desc, ghost_unconnected_pads=False)
|
||||
except gobject.GError as ex:
|
||||
logger.warning(
|
||||
'Failed to create audio mixer "%s": %s', settings.MIXER, ex)
|
||||
'Failed to create audio mixer "%s": %s', mixer_desc, ex)
|
||||
return
|
||||
|
||||
# We assume that the bin will contain a single mixer.
|
||||
mixer = mixerbin.get_by_interface(b'GstMixer')
|
||||
if not mixer:
|
||||
logger.warning(
|
||||
'Did not find any audio mixers in "%s"', settings.MIXER)
|
||||
'Did not find any audio mixers in "%s"', mixer_desc)
|
||||
return
|
||||
|
||||
if mixerbin.set_state(gst.STATE_READY) != gst.STATE_CHANGE_SUCCESS:
|
||||
logger.warning(
|
||||
'Setting audio mixer "%s" to READY failed', settings.MIXER)
|
||||
'Setting audio mixer "%s" to READY failed', mixer_desc)
|
||||
return
|
||||
|
||||
track = self._select_mixer_track(mixer, settings.MIXER_TRACK)
|
||||
track = self._select_mixer_track(mixer, track_desc)
|
||||
if not track:
|
||||
logger.warning('Could not find usable audio mixer track')
|
||||
return
|
||||
@ -198,8 +206,9 @@ class Audio(pykka.ThreadingActor):
|
||||
|
||||
def _select_mixer_track(self, mixer, track_label):
|
||||
# Ignore tracks without volumes, then look for track with
|
||||
# label == settings.MIXER_TRACK, otherwise fallback to first usable
|
||||
# track hoping the mixer gave them to us in a sensible order.
|
||||
# label equal to the audio/mixer_track config value, otherwise fallback
|
||||
# to first usable track hoping the mixer gave them to us in a sensible
|
||||
# order.
|
||||
|
||||
usable_tracks = []
|
||||
for track in mixer.list_tracks():
|
||||
|
||||
@ -6,9 +6,9 @@ This is Mopidy's default mixer.
|
||||
|
||||
None
|
||||
|
||||
**Settings**
|
||||
**Configuration**
|
||||
|
||||
If this wasn't the default, you would set :attr:`mopidy.settings.MIXER` to
|
||||
If this wasn't the default, you would set the ``audio/mixer`` config value to
|
||||
``autoaudiomixer`` to use this mixer.
|
||||
"""
|
||||
|
||||
|
||||
@ -4,9 +4,9 @@
|
||||
|
||||
None
|
||||
|
||||
**Settings**
|
||||
**Configuration**
|
||||
|
||||
Set :attr:`mopidy.settings.MIXER` to ``fakemixer`` to use this mixer.
|
||||
Set the ``audio/mixer`` config value to ``fakemixer`` to use this mixer.
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
@ -7,10 +7,10 @@ serial cable.
|
||||
|
||||
.. literalinclude:: ../../../../requirements/external_mixers.txt
|
||||
|
||||
**Settings**
|
||||
**Configuration**
|
||||
|
||||
Set :attr:`mopidy.settings.MIXER` to ``nadmixer`` to use it. You probably also
|
||||
needs to add some properties to the ``MIXER`` setting.
|
||||
Set the ``audio/mixer`` config value to ``nadmixer`` to use it. You probably
|
||||
also needs to add some properties to the ``audio/mixer`` config value.
|
||||
|
||||
Supported properties includes:
|
||||
|
||||
@ -34,15 +34,13 @@ Supported properties includes:
|
||||
Configuration examples::
|
||||
|
||||
# Minimum configuration, if the amplifier is available at /dev/ttyUSB0
|
||||
MIXER = u'nadmixer'
|
||||
mixer = nadmixer
|
||||
|
||||
# Minimum configuration, if the amplifier is available elsewhere
|
||||
MIXER = u'nadmixer port=/dev/ttyUSB3'
|
||||
mixer = nadmixer port=/dev/ttyUSB3
|
||||
|
||||
# Full configuration
|
||||
MIXER = (
|
||||
u'nadmixer port=/dev/ttyUSB0 '
|
||||
u'source=aux speakers-a=on speakers-b=off')
|
||||
mixer = nadmixer port=/dev/ttyUSB0 source=aux speakers-a=on speakers-b=off
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
@ -132,7 +130,7 @@ class NadTalker(pykka.ThreadingActor):
|
||||
calibrating the NAD amplifier's volume.
|
||||
"""
|
||||
|
||||
# Serial link settings
|
||||
# Serial link config
|
||||
BAUDRATE = 115200
|
||||
BYTESIZE = 8
|
||||
PARITY = 'N'
|
||||
|
||||
@ -6,7 +6,7 @@ import gst
|
||||
|
||||
import pykka
|
||||
|
||||
from mopidy import audio, settings
|
||||
from mopidy import audio
|
||||
from mopidy.utils.path import path_to_uri
|
||||
|
||||
from tests import unittest, path_to_data_dir
|
||||
@ -14,14 +14,18 @@ from tests import unittest, path_to_data_dir
|
||||
|
||||
class AudioTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
settings.MIXER = 'fakemixer track_max_volume=65536'
|
||||
settings.OUTPUT = 'fakesink'
|
||||
config = {
|
||||
'audio': {
|
||||
'mixer': 'fakemixer track_max_volume=65536',
|
||||
'mixer_track': None,
|
||||
'output': 'fakesink',
|
||||
}
|
||||
}
|
||||
self.song_uri = path_to_uri(path_to_data_dir('song1.wav'))
|
||||
self.audio = audio.Audio.start(config=None).proxy()
|
||||
self.audio = audio.Audio.start(config=config).proxy()
|
||||
|
||||
def tearDown(self):
|
||||
pykka.ActorRegistry.stop_all()
|
||||
settings.runtime.clear()
|
||||
|
||||
def prepare_uri(self, uri):
|
||||
self.audio.prepare_change()
|
||||
@ -59,8 +63,14 @@ class AudioTest(unittest.TestCase):
|
||||
self.assertEqual(value, self.audio.get_volume().get())
|
||||
|
||||
def test_set_volume_with_mixer_max_below_100(self):
|
||||
settings.MIXER = 'fakemixer track_max_volume=40'
|
||||
self.audio = audio.Audio.start(config=None).proxy()
|
||||
config = {
|
||||
'audio': {
|
||||
'mixer': 'fakemixer track_max_volume=40',
|
||||
'mixer_track': None,
|
||||
'output': 'fakesink',
|
||||
}
|
||||
}
|
||||
self.audio = audio.Audio.start(config=config).proxy()
|
||||
|
||||
for value in range(0, 101):
|
||||
self.assertTrue(self.audio.set_volume(value).get())
|
||||
|
||||
Loading…
Reference in New Issue
Block a user