summaryrefslogtreecommitdiff
diff options
authorLi-Hao Liao (Leon Liao) <leon.liao@canonical.com>2020-07-23 15:03:46 +0800
committerLi-Hao Liao (Leon Liao) <leon.liao@canonical.com>2020-10-12 15:29:35 +0800
commiteaf611e91a68bd3ad4c09f181e17a5088f7d446f (patch)
treef0b4e7c934fc938e1429132194ceb120ac739edc
parentf2c2e6d3b23779abefe7d9a4128be13164b49a85 (diff)
bin/audio_test.py: Fix the "Unable to control recording volume..." bug
Fix: 1. Remove the method parameter from PAVolumeController.__init__(): Assum PAVolumeController class only be used in this audio_test.py. 2. Don't check the return value of self.method(command): In PAVolumeController._pactl_output(), when failed to execute the pactl command the exception will be thrown. 3. When pactl command fail (after retry 3 times), let audio_test stop. Original issue: In PAVolumeController class: In set_volume() and mute(), the self.method(command) returns a zero-length string. So, the set_volume() and mute() always return False. Then, in get_volume(), the self._volume always won't be set. This is the root cause of the "Unable to control recording volume..." issue. More detail: 1. There is no ouptu from the `pactl set-souerce-volume ...` command. 2. The PAVolumeController._pactl_output fucntion will return subprocess.check_output(). The subprocess.check_output function return the output of "command". LP: #1890526
-rwxr-xr-xbin/audio_test.py25
1 files changed, 7 insertions, 18 deletions
diff --git a/bin/audio_test.py b/bin/audio_test.py
index 2a56df4..4b3f89c 100755
--- a/bin/audio_test.py
+++ b/bin/audio_test.py
@@ -24,10 +24,6 @@ except ImportError:
print((sys.version), file=sys.stderr)
sys.exit(127)
-try:
- from collections.abc import Callable
-except ImportError:
- from collections import Callable # backward compatible
# Frequency bands for FFT
BINS = 256
@@ -115,22 +111,16 @@ class PIDController(object):
class PAVolumeController(object):
pa_types = {'input': 'source', 'output': 'sink'}
- def __init__(self, type, method=None, logger=None):
+ def __init__(self, type, logger=None):
"""Initializes the volume controller.
Arguments:
type: either input or output
- method: a method that will run a command and return pulseaudio
- information in the described format, as a single string with
- line breaks (to be processed with str.splitlines())
"""
self.type = type
self._volume = None
self.identifier = None
- self.method = method
- if not isinstance(method, Callable):
- self.method = self._pactl_output
self.logger = logger
def set_volume(self, volume):
@@ -142,8 +132,7 @@ class PAVolumeController(object):
'set-%s-volume' % (self.pa_types[self.type]),
str(self.identifier[0]),
str(int(volume)) + "%"]
- if not self.method(command):
- return False
+ self._pactl_output(command)
self._volume = volume
return True
@@ -160,8 +149,7 @@ class PAVolumeController(object):
'set-%s-mute' % (self.pa_types[self.type]),
str(self.identifier[0]),
mute]
- if not self.method(command):
- return False
+ self._pactl_output(command)
return True
def get_identifier(self):
@@ -192,7 +180,7 @@ class PAVolumeController(object):
# <ID>\t<NAME>\t<MODULE>\t<SAMPLE_SPEC_WITH_SPACES>\t<STATE>
# What we need to return is the ID for the first element on this list
# that does not contain auto_null or monitor.
- pa_info = self.method(command)
+ pa_info = self._pactl_output(command)
valid_elements = None
if pa_info:
@@ -221,7 +209,8 @@ class PAVolumeController(object):
universal_newlines=True)
except (subprocess.CalledProcessError):
time.sleep(5)
- return False
+ self.logger.error("Fail to execute: {}".format(command))
+ sys.exit(1)
class FileDumper(object):
@@ -369,7 +358,7 @@ class GStreamerMessageHandler(object):
# we can't control it :(
current_volume = volume_controller.get_volume()
if current_volume is None:
- self.logger.error("Unable to control recording volume."
+ self.logger.error("Unable to control recording volume. "
"Test results may be wrong")
return
self.current_level = level