ubuntu 系统声音静音问题
在硬件设备中发现了系统声音重启被静音的问题,导致设备声音不可用。Bug情况暂未复现。无法从根本解决问题。只能想一个临时的问题。记录一下,临时的解决方案。主要还是通过 gnome-control-center
、pactl
、amixer
来解决。
gnome-control-center
代码语言:javascript复制gnome-control-center list
gnome-control-center -v
gnome-control-center sound -v
gnome-control-center主要来定位具体的音频设备。上述命令在实际操作中,会打开 Debug模式,输出panel和key,等一些详细信息。每一步,点击了什么按钮以及做过什么设置都有详细的日志。
上文的日志是通过gnome-control-center sound -v
来打印的。
代码语言:javascript复制Log
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.987: The canonical name for 'input:analog-stereo' is 'input:analog-stereo'
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.987: Adding profile to combobox: 'input:analog-stereo' - 'Analog Stereo Input'
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.987: The canonical name for 'input:analog-stereo' is 'input:analog-stereo'
(gnome-control-center:16210): sound-cc-panel-DEBUG: 16:25:53.987: Add input ui entry with id :9
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.987: create_ui_device_from_port, direction 0, description 'Microphone', origin 'OrbiCam', port available 1
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.987: Updating client: index=1 name='Login Session 4'
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.987: Updating client: index=2 name='GNOME Shell'
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.987: Updating client: index=3 name='GNOME Shell Volume Control'
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.987: Updating client: index=9 name='XSMP Session on gnome-session as 10ae70087fe8582620163539954145314500000013770055'
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.987: Updating client: index=10 name='GNOME Volume Control Media Keys'
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.987: Updating client: index=20 name='Login Session 319'
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.987: Updating client: index=21 name='Login Session 320'
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.987: Updating client: index=45 name='GNOME Volume Control Dialog'
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.987: Updating sink: index=0 name='alsa_output.pci-0000_00_1f.3.analog-stereo' description='Built-in Audio Analog Stereo' map='front-left,front-right'
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.987: update sink - is new
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.987: Attempt to match_stream update_with_existing_outputs - Try description : 'Line Out', origin : 'Built-in Audio', device port name : 'analog-output-lineout', card : 0x55db708bb890, AGAINST stream port: 'analog-output-lineout', sink card id 0
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.987: Match device with stream: We have a match with description: 'Line Out', origin: 'Built-in Audio', cached already with device id 6, so set stream id to 1
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.987: gvc-mixer-output-set-property - sink/source id: 1
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.987: lookup-device-from-stream found device: device description 'Line Out', device port = 'analog-output-lineout', device stream id 1 AND stream port = 'analog-output-lineout' stream id '1' and stream description 'Built-in Audio Analog Stereo'
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.987: gvc_mixer_control_lookup_device_from_stream - Could not find a device for stream 'Built-in Audio Analog Stereo'
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.987: active_sink change
(gnome-control-center:16210): sound-cc-panel-DEBUG: 16:25:53.987: active output update device id = 6
(gnome-control-center:16210): sound-cc-panel-DEBUG: 16:25:53.988: Updating output settings
(gnome-control-center:16210): sound-cc-panel-DEBUG: 16:25:53.988: Volume changed (for Balance bar)
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.991: Matching profile for 'output:analog-stereo input:analog-stereo' is 'output:analog-stereo'
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.991: Updating source: index=0 name='alsa_output.pci-0000_00_1f.3.analog-stereo.monitor' description='Monitor of Built-in Audio Analog Stereo'
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.991: Updating source: index=1 name='alsa_input.pci-0000_00_1f.3.analog-stereo' description='Built-in Audio Analog Stereo'
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.991: update source
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.991: Attempt to match_stream update_with_existing_outputs - Try description : 'Microphone', origin : 'OrbiCam', device port name : 'analog-input-mic', card : 0x55db70aaae10, AGAINST stream port: 'analog-input-mic', sink card id 0
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.991: Attempt to match_stream update_with_existing_outputs - Try description : 'Digital Input (S/PDIF)', origin : 'OrbiCam', device port name : 'iec958-stereo-input', card : 0x55db70aaae10, AGAINST stream port: 'analog-input-mic', sink card id 0
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.991: Attempt to match_stream update_with_existing_outputs - Try description : 'Microphone', origin : 'Built-in Audio', device port name : 'analog-input-mic', card : 0x55db708bb890, AGAINST stream port: 'analog-input-mic', sink card id 0
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.991: Match device with stream: We have a match with description: 'Microphone', origin: 'Built-in Audio', cached already with device id 7, so set stream id to 2
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.991: gvc-mixer-output-set-property - sink/source id: 2
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.991: Updating source: index=3 name='alsa_input.usb-046d_HD_Pro_Webcam_C920_49FF4DDF-02.analog-stereo' description='OrbiCam Analog Stereo'
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.991: update source
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.991: Attempt to match_stream update_with_existing_outputs - Try description : 'Microphone', origin : 'OrbiCam', device port name : 'analog-input-mic', card : 0x55db70aaae10, AGAINST stream port: 'analog-input-mic', sink card id 2
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.991: Match device with stream: We have a match with description: 'Microphone', origin: 'OrbiCam', cached already with device id 9, so set stream id to 3
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.991: gvc-mixer-output-set-property - sink/source id: 3
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.991: lookup-device-from-stream found device: device description 'Microphone', device port = 'analog-input-mic', device stream id 3 AND stream port = 'analog-input-mic' stream id '3' and stream description 'OrbiCam Analog Stereo'
(gnome-control-center:16210): Gvc-DEBUG: 16:25:53.991: gvc_mixer_control_lookup_device_from_stream - Could not find a device for stream 'OrbiCam Analog Stereo'
(gnome-control-center:16210): sound-cc-panel-DEBUG: 16:25:53.991: active_input_update device id = 9
(gnome-control-center:16210): sound-cc-panel-DEBUG: 16:25:53.991: Updating input settings
(gnome-control-center:16210): sound-cc-panel-DEBUG: 16:25:53.991: Create monitor for 3
(gnome-control-center:16210): sound-cc-panel-DEBUG: 16:25:53.992: Adding effects stream
(gnome-control-center:16210): Gvc-DEBUG: 16:25:54.260: Updating source: index=3 name='alsa_input.usb-046d_HD_Pro_Webcam_C920_49FF4DDF-02.analog-stereo' description='OrbiCam Analog Stereo'
(gnome-control-center:16210): Gvc-DEBUG: 16:25:54.260: update source
(gnome-control-center:16210): Gvc-DEBUG: 16:25:54.260: Updating source output: index=12 name='Peak detect' client=45 source=3
(gnome-control-center:16210): Gvc-DEBUG: 16:25:58.286: Updating sink: index=0 name='alsa_output.pci-0000_00_1f.3.analog-stereo' description='Built-in Audio Analog Stereo' map='front-left,front-right'
(gnome-control-center:16210): sound-cc-panel-DEBUG: 16:26:00.482: Setting stream volume 65536,000000 (rounded: 65536,000000) for bar '_Output volume:'
(gnome-control-center:16210): Gvc-DEBUG: 16:26:00.485: Updating sink: index=0 name='alsa_output.pci-0000_00_1f.3.analog-stereo' description='Built-in Audio Analog Stereo' map='front-left,front-right'
(gnome-control-center:16210): Gvc-DEBUG: 16:26:01.819: Updating sink: index=0 name='alsa_output.pci-0000_00_1f.3.analog-stereo' description='Built-in Audio Analog Stereo' map='front-left,front-right'
通过上述日志定位到 alsa_output.pci-0000_00_1f.3.analog-stereo
设备,下述就是进行相关设置。
pactl
命令相关简介;
代码语言:javascript复制~# pactl --help
pactl [options] stat
pactl [options] info
pactl [options] list [short] [TYPE]
pactl [options] exit
pactl [options] upload-sample FILENAME [NAME]
pactl [options] play-sample NAME [SINK]
pactl [options] remove-sample NAME
pactl [options] load-module NAME [ARGS ...]
pactl [options] unload-module NAME|#N
pactl [options] move-(sink-input|source-output) #N SINK|SOURCE
pactl [options] suspend-(sink|source) NAME|#N 1|0
pactl [options] set-card-profile CARD PROFILE
pactl [options] set-default-(sink|source) NAME
pactl [options] set-(sink|source)-port NAME|#N PORT
pactl [options] set-(sink|source)-volume NAME|#N VOLUME [VOLUME ...]
pactl [options] set-(sink-input|source-output)-volume #N VOLUME [VOLUME ...]
pactl [options] set-(sink|source)-mute NAME|#N 1|0|toggle
pactl [options] set-(sink-input|source-output)-mute #N 1|0|toggle
pactl [options] set-sink-formats #N FORMATS
pactl [options] set-port-latency-offset CARD-NAME|CARD-#N PORT OFFSET
pactl [options] subscribe
The special names @DEFAULT_SINK@, @DEFAULT_SOURCE@ and @DEFAULT_MONITOR@
can be used to specify the default sink, source and monitor.
-h, --help Show this help
--version Show version
-s, --server=SERVER The name of the server to connect to
-n, --client-name=NAME How to call this client on the server
定位音频设备以及音频设备相关信息:
在上述相关命令中,发现关于 mute即静音相关命令是,pactl [options] set-(sink|source)-mute NAME|#N 1|0|toggle
发现有两类设备。音频设备为sink类的。获取设备列表
pactl list sinks |grep 'alsa_output.pci-0000_00_1f.3.analog-stereo'
输出结果;
代码语言:javascript复制xcb_connection_has_error() returned true
Sink #0
State: SUSPENDED
Name: alsa_output.pci-0000_00_1f.3.analog-stereo
Description: Built-in Audio Analog Stereo
Driver: module-alsa-card.c
Sample Specification: s16le 2ch 44100Hz
Channel Map: front-left,front-right
Owner Module: 7
Mute: yes
Volume: front-left: 65536 / 100% / 0,00 dB, front-right: 65536 / 100% / 0,00 dB
balance 0,00
Base Volume: 65536 / 100% / 0,00 dB
Monitor Source: alsa_output.pci-0000_00_1f.3.analog-stereo.monitor
Latency: 0 usec, configured 0 usec
Flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY
Properties:
alsa.resolution_bits = "16"
device.api = "alsa"
device.class = "sound"
alsa.class = "generic"
alsa.subclass = "generic-mix"
alsa.name = "ALC892 Analog"
alsa.id = "ALC892 Analog"
alsa.subdevice = "0"
alsa.subdevice_name = "subdevice #0"
alsa.device = "0"
alsa.card = "0"
alsa.card_name = "HDA Intel PCH"
alsa.long_card_name = "HDA Intel PCH at 0xdf120000 irq 128"
alsa.driver_name = "snd_hda_intel"
device.bus_path = "pci-0000:00:1f.3"
sysfs.path = "/devices/pci0000:00/0000:00:1f.3/sound/card0"
device.bus = "pci"
device.vendor.id = "8086"
device.vendor.name = "Intel Corporation"
device.product.id = "a2f0"
device.product.name = "200 Series PCH HD Audio"
device.form_factor = "internal"
device.string = "front:0"
device.buffering.buffer_size = "65536"
device.buffering.fragment_size = "32768"
device.access_mode = "mmap timer"
device.profile.name = "analog-stereo"
device.profile.description = "Analog Stereo"
device.description = "Built-in Audio Analog Stereo"
alsa.mixer_name = "Realtek ALC892"
alsa.components = "HDA:10ec0892,10ec0892,00100302 HDA:8086280b,80860101,00100000"
module-udev-detect.discovered = "1"
device.icon_name = "audio-card-pci"
Ports:
analog-output-lineout: Line Out (priority: 9900)
Active Port: analog-output-lineout
Formats:
pcm
其中 sink #0 和 Name: alsa_output.pci-0000_00_1f.3.analog-stereo,过滤到之后,0为sink id。
随后利用命令进行相关设置。
代码语言:javascript复制pactl set-sink-mute 0 0 #取消静音
pactl set-sink-mute 0 1 #静音
pactl set-sink-mute 0 toggle #取反。静音状态取消静音,非静音设置为静音
amixer
amixer与pactl功能类似,amixer主要设置音频相关设备,pactl还可以设置其他类型设备,比如 显卡等。
命令帮助;
代码语言:javascript复制~# amixer --help
Usage: amixer <options> [command]
Available options:
-h,--help this help
-c,--card N select the card
-D,--device N select the device, default 'default'
-d,--debug debug mode
-n,--nocheck do not perform range checking
-v,--version print version of this program
-q,--quiet be quiet
-i,--inactive show also inactive controls
-a,--abstract L select abstraction level (none or basic)
-s,--stdin Read and execute commands from stdin sequentially
-R,--raw-volume Use the raw value (default)
-M,--mapped-volume Use the mapped volume
Available commands:
scontrols show all mixer simple controls
scontents show contents of all mixer simple controls (default command)
sset sID P set contents for one mixer simple control
sget sID get contents for one mixer simple control
controls show all controls for given card
contents show contents of all controls for given card
cset cID P set control contents for one control
cget cID get control contents for one control
查看设备列表;
代码语言:javascript复制#amixer scontrols
代码语言:javascript复制Simple mixer control 'Master',0
Simple mixer control 'PCM',0
Simple mixer control 'Mic',0
Simple mixer control 'Mic Boost',0
Simple mixer control 'IEC958',0
Simple mixer control 'IEC958',1
Simple mixer control 'IEC958',2
Simple mixer control 'IEC958',3
Simple mixer control 'IEC958',4
Simple mixer control 'Capture',0
Simple mixer control 'Loopback Mixing',0
查看设备状态详细信息:
代码语言:javascript复制amixer scontents
代码语言:javascript复制Simple mixer control 'Master',0
Capabilities: pvolume pswitch
Playback channels: Front Left - Front Right
Limits: Playback 0 - 64
Mono:
Front Left: Playback 64 [100%] [0.00dB] [off] #off 表示为静音
Front Right: Playback 64 [100%] [0.00dB] [off]
Simple mixer control 'PCM',0
Capabilities: pvolume
Playback channels: Front Left - Front Right
Limits: Playback 0 - 255
Mono:
Front Left: Playback 255 [100%] [0.00dB]
Front Right: Playback 255 [100%] [0.00dB]
Simple mixer control 'Mic',0
Capabilities: pvolume pswitch
Playback channels: Front Left - Front Right
Limits: Playback 0 - 31
Mono:
Front Left: Playback 0 [0%] [-34.50dB] [off]
Front Right: Playback 0 [0%] [-34.50dB] [off]
Simple mixer control 'Mic Boost',0
Capabilities: volume
Playback channels: Front Left - Front Right
Capture channels: Front Left - Front Right
Limits: 0 - 3
Front Left: 0 [0%] [0.00dB]
Front Right: 0 [0%] [0.00dB]
Simple mixer control 'IEC958',0
Capabilities: pswitch pswitch-joined
Playback channels: Mono
Mono: Playback [off]
Simple mixer control 'IEC958',1
Capabilities: pswitch pswitch-joined
Playback channels: Mono
Mono: Playback [on]
Simple mixer control 'IEC958',2
Capabilities: pswitch pswitch-joined
Playback channels: Mono
Mono: Playback [on]
Simple mixer control 'IEC958',3
Capabilities: pswitch pswitch-joined
Playback channels: Mono
Mono: Playback [on]
Simple mixer control 'IEC958',4
Capabilities: pswitch pswitch-joined
Playback channels: Mono
Mono: Playback [on]
Simple mixer control 'Capture',0
Capabilities: cvolume cswitch
Capture channels: Front Left - Front Right
Limits: Capture 0 - 46
Front Left: Capture 28 [61%] [12.00dB] [on]
Front Right: Capture 28 [61%] [12.00dB] [on]
Simple mixer control 'Loopback Mixing',0
Capabilities: enum
Items: 'Disabled' 'Enabled'
Item0: 'Disabled'
代码语言:javascript复制设置静音
amixer -D pulse sset Master off|on|toggle|value
代码语言:javascript复制取消静音
amixer -D pulse sset Master on
代码语言:javascript复制xcb_connection_has_error() returned true
Simple mixer control 'Master',0
Capabilities: pvolume pswitch pswitch-joined
Playback channels: Front Left - Front Right
Limits: Playback 0 - 65536
Mono:
Front Left: Playback 1 [0%] [on]
Front Right: Playback 1 [0%] [on]
注意:声音打开之后,音量值为0%,等同于静音。
代码语言:javascript复制静音
amixer -D pulse sset Master off
代码语言:javascript复制xcb_connection_has_error() returned true
Simple mixer control 'Master',0
Capabilities: pvolume pswitch pswitch-joined
Playback channels: Front Left - Front Right
Limits: Playback 0 - 65536
Mono:
Front Left: Playback 1 [0%] [off]
Front Right: Playback 1 [0%] [off]
代码语言:javascript复制设置其他音量
amixer -D pulse sset Master 100%
代码语言:javascript复制xcb_connection_has_error() returned true
Simple mixer control 'Master',0
Capabilities: pvolume pswitch pswitch-joined
Playback channels: Front Left - Front Right
Limits: Playback 0 - 65536
Mono:
Front Left: Playback 65536 [100%] [on]
Front Right: Playback 65536 [100%] [on]
other
注意到不管用什么命令设置,都发现在日志输出中xcb_connection_has_error() returned true
。目前猜测为 xcb,相关事件,是否可以通过代码层面来解决,直接获取xcb-event,来进行相关音频的检测,实现动态修正。