Merge plainbox-provider-checkbox:fix-audio-test-get-source-sink-ids into plainbox-provider-checkbox:master

Proposed by Yao Wei
Status: Needs review
Proposed branch: plainbox-provider-checkbox:fix-audio-test-get-source-sink-ids
Merge into: plainbox-provider-checkbox:master
Diff against target: 103 lines (+30/-34)
1 file modified
bin/audio_test.py (+30/-34)
Reviewer Review Type Date Requested Status
Checkbox Developers Pending
Review via email: mp+431179@code.launchpad.net

Commit message

bin:audio_test.py: use pactl get-default-source and get-default-sink

This is to make getting default source/sink more reliable instead of manually filtering through the list.

To post a comment you must log in.
Revision history for this message
Kai-Chuan Hsieh (kchsieh) wrote :

Hello Yao,

I tested on KRPL-SFF-DVT-C1_202208-30552, it will show
ubuntu@ubuntu:~$ pactl get-default-sink
alsa_output.pci-0000_00_1f.3.analog-stereo
ubuntu@ubuntu:~$ pactl get-default-source
alsa_output.pci-0000_00_1f.3.analog-stereo.monitor

The original logic seems filter out monitor.
Will it impact the result if you just return the output of $ pactl get-default-{sink,source}?

Thanks,

Revision history for this message
Yao Wei (medicalwei) wrote (last edit ):

The command that controls the volume and unmutes

pactl set-source-volume
pactl set-source-mute
pactl set-sink-volume
pactl set-sink-mute

can actually use the identifier string (instead of numeric ID) to change the settings.

However, your concern is correct that it should disregard .monitor from the default source. It's now updated that if default source contains .monitor in the end of the string, it would return None.

Revision history for this message
jeremyszu (os369510) wrote :

@Wei,

This seems good to me, could you please move it to
https://github.com/canonical/checkbox
?

Revision history for this message
Atlas Yu (pseudoc) wrote :

I run the related test job on some platform, and the unmute logic is not working properly, and the get-default-{source,sink} could solve this problem perfectly.

Unmerged commits

47ff52c... by Yao Wei

bin:audio_test.py: use pactl get-default-source and get-default-sink

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/bin/audio_test.py b/bin/audio_test.py
2index 4b3f89c..c229a4d 100755
3--- a/bin/audio_test.py
4+++ b/bin/audio_test.py
5@@ -128,10 +128,12 @@ class PAVolumeController(object):
6 return False
7 if not self.identifier:
8 return False
9- command = ['pactl',
10- 'set-%s-volume' % (self.pa_types[self.type]),
11- str(self.identifier[0]),
12- str(int(volume)) + "%"]
13+ command = [
14+ "pactl",
15+ "set-%s-volume" % (self.pa_types[self.type]),
16+ self.identifier,
17+ str(int(volume)) + "%",
18+ ]
19 self._pactl_output(command)
20 self._volume = volume
21 return True
22@@ -145,10 +147,12 @@ class PAVolumeController(object):
23 mute = str(int(mute))
24 if not self.identifier:
25 return False
26- command = ['pactl',
27- 'set-%s-mute' % (self.pa_types[self.type]),
28- str(self.identifier[0]),
29- mute]
30+ command = [
31+ "pactl",
32+ "set-%s-mute" % (self.pa_types[self.type]),
33+ self.identifier,
34+ mute,
35+ ]
36 self._pactl_output(command)
37 return True
38
39@@ -156,46 +160,38 @@ class PAVolumeController(object):
40 if self.type:
41 self.identifier = self._get_identifier_for(self.type)
42 if self.identifier and self.logger:
43- message = "Using PulseAudio identifier %s (%s) for %s" %\
44- (self.identifier + (self.type,))
45+ message = "Using PulseAudio identifier %s for %s" % (
46+ self.identifier,
47+ self.type,
48+ )
49 self.logger.info(message)
50 return self.identifier
51
52 def _get_identifier_for(self, type):
53 """Gets default PulseAudio identifier for given type.
54
55- Arguments:
56- type: either input or output
57+ Arguments:
58+ type: either input or output
59
60- Returns:
61- A tuple: (pa_id, pa_description)
62+ Returns:
63+ A string: device_name
64
65 """
66
67 if type not in self.pa_types:
68 return None
69- command = ['pactl', 'list', self.pa_types[type] + "s", 'short']
70-
71- # Expect lines of this form (field separator is tab):
72- # <ID>\t<NAME>\t<MODULE>\t<SAMPLE_SPEC_WITH_SPACES>\t<STATE>
73- # What we need to return is the ID for the first element on this list
74- # that does not contain auto_null or monitor.
75- pa_info = self._pactl_output(command)
76- valid_elements = None
77-
78- if pa_info:
79- reject_regex = '.*(monitor|auto_null).*'
80- valid_elements = [element for element in pa_info.splitlines()
81- if not re.match(reject_regex, element)]
82- if not valid_elements:
83+
84+ command = ["pactl", "get-default-" + self.pa_types[type]]
85+ name = self._pactl_output(command).strip()
86+ if name.startswith("auto_null") or name.endswith(".monitor"):
87 if self.logger:
88- self.logger.error("No valid PulseAudio elements"
89- " for %s" % (self.type))
90+ self.logger.error(
91+ "Default PulseAudio element for %s is invalid (%s)"
92+ % (self.type, name)
93+ )
94 return None
95- # We only need the pulseaudio numeric ID and long name for each element
96- valid_elements = [(int(e.split()[0]), e.split()[1])
97- for e in valid_elements]
98- return valid_elements[0]
99+
100+ return name
101
102 def _pactl_output(self, command):
103 # This method mainly calls pactl (hence the name). Since pactl may

Subscribers

People subscribed via source and target branches

to all changes: