diff options
Diffstat (limited to 'perl-install/harddrake/sound.pm')
-rw-r--r-- | perl-install/harddrake/sound.pm | 903 |
1 files changed, 602 insertions, 301 deletions
diff --git a/perl-install/harddrake/sound.pm b/perl-install/harddrake/sound.pm index 95a6de10d..cdf24c219 100644 --- a/perl-install/harddrake/sound.pm +++ b/perl-install/harddrake/sound.pm @@ -1,14 +1,4 @@ package harddrake::sound; -# lists filled with Danny Tholen help, enhanced by Thierry Vignaud -# -# No ALSA for OSS's -# o isa cards: msnd_pinnacle, pas2, -# o pci cards: ad1889, sam9407 -# No OSS for ALSA's -# o pci cards: snd-als4000, snd-es968, snd-hdsp -# o isa cards: snd-azt2320, snd-cs4231, snd-cs4236, -# snd-dt0197h, snd-korg1212, snd-rme32 -# o pcmcia cards: snd-vxp440 snd-vxpocket # TODO: # o ensure sound is not user (either dsp/midi/sequencer/mixer) @@ -16,348 +6,659 @@ package harddrake::sound; use strict; use common; -use interactive; use run_program; use modules; use list_modules; use detect_devices; use log; +sub is_pulseaudio_enabled { + my ($in) = @_; + my $soundprofile = common::read_alternative('soundprofile'); + return $in->do_pkgs->is_installed('task-pulseaudio') && $soundprofile =~ /pulse$/; +} + +sub set_pulseaudio { + my ($val) = @_; + + my $alterative = '/etc/sound/profiles/' . ($val ? 'pulse' : 'alsa'); + return if ! -d $alterative; + + common::symlinkf_update_alternatives('soundprofile', $alterative); + + # (cg) This config file will eventually be dropped, but it is still needed for now + # as several packages/patches depend on it. + my $config_file = "$::prefix/etc/sysconfig/pulseaudio"; + $val = 'PULSE_SERVER_TYPE=' . ($val ? 'personal' : 'none') . "\n"; + my $done; + substInFile { + if (/^PULSE_SERVER_TYPE=/) { + $_ = $val; + $done = 1; + } + } $config_file; + append_to_file($config_file, $val) if !$done; +} + -our %alsa2oss = - ( - if_(arch() =~ /ppc/, "snd-powermac" => [ "dmasound_pmac" ]), - if_(arch() =~ /sparc/, - "snd-sun-amd7930" => [ "unknown" ], - "snd-sun-cs4231" => [ "unknown" ], - "snd-sun-dbri" => [ "unknown" ], - ), - "snd-ad1816a" => [ "ad1816" ], # isa - "snd-ad1848" => [ "ad1848", "pss" ], # isa - "snd-ali5451" => [ "trident" ], - "snd-als100" => [ "sb" ], # isa - "snd-als4000" => [ "unknown" ], - "snd-atiixp" => [ "unknown" ], - "snd-au8810" => [ "unknown" ], - "snd-au8820" => [ "unknown" ], - "snd-au8830" => [ "unknown" ], - "snd-audigyls" => [ "unknown" ], # pci, renamed as snd-ca0106 - "snd-azt2320" => [ "unknown" ], # isa - "snd-azt3328" => [ "unknown" ], # isa - "snd-azx" => [ "unknown" ], - "snd-bt87x" => [ "btaudio" ], - "snd-ca0106" => [ "unknown" ], # pci - "snd-cmi8330" => [ "sb" ], # isa - "snd-cmipci" => [ "cmpci" ], - "snd-cs4231" => [ "unknown" ], # isa - "snd-cs4232" => [ "cs4232" ], # isa - "snd-cs4236" => [ "ad1848" ], # isa - "snd-cs4281" => [ "cs4281" ], - "snd-cs46xx" => [ "cs46xx" ], - "snd-darla20" => [ "unknown" ], - "snd-darla24" => [ "unknown" ], - "snd-dt0197h" => [ "unknown" ], # isa - "snd-dt019x" => [ "unknown" ], # isa - "snd-emu10k1" => [ "audigy", "emu10k1" ], - "snd-emu10k1x" => [ "unknown" ], - "snd-ens1370" => [ "es1370" ], - "snd-ens1371" => [ "es1371" ], - "snd-es1688" => [ "sb" ], # isa - "snd-es18xx" => [ "sb" ], # isa - "snd-es1938" => [ "esssolo1" ], - "snd-es1968" => [ "maestro" ], # isa - "snd-es968" => [ "sb" ], - "snd-fm801" => [ "forte" ], - "snd-gina20" => [ "unknown" ], - "snd-gina24" => [ "unknown" ], - "snd-gina3g" => [ "unknown" ], - "snd-gusclassic" => [ "gus" ], # isa - "snd-gusextreme" => [ "gus" ], # isa - "snd-gusmax" => [ "gus" ], # isa - "snd-hda-intelp" => [ "unknown" ], - "snd-hdspm" => [ "unknown" ], - "snd-hdsp" => [ "unknown" ], - "snd-ice1712" => [ "unknown" ], # isa - "snd-ice1724" => [ "unknown" ], # isa - "snd-indi" => [ "unknown" ], # pci - "snd-indigo" => [ "unknown" ], # pci - "snd-indigodj" => [ "unknown" ], # pci - "snd-indigoio" => [ "unknown" ], # pci - "snd-intel8x0" => [ "ali5455", "i810_audio", "nvaudio" ], - "snd-interwave" => [ "gus" ], # isa - "snd-interwave-stb" => [ "unknown" ], # isa - "snd-korg1212" => [ "unknown" ], # isa - "snd-layla20" => [ "unknown" ], - "snd-layla24" => [ "unknown" ], - "snd-layla3g" => [ "unknown" ], - "snd-maestro3" => [ "maestro3" ], - "snd-mia" => [ "unknown" ], - "snd-mixart" => [ "unknown" ], - "snd-mona" => [ "unknown" ], - "snd-mpu401" => [ "mpu401" ], - "snd-nm256" => [ "nm256_audio" ], - "snd-opl3sa2" => [ "opl3", "opl3sa", "opl3sa2" ], # isa - "snd-opti92x-ad1848" => [ "unknown" ], # isa - "snd-opti92x-cs4231" => [ "unknown" ], # isa - "snd-opti93x" => [ "mad16" ], - "snd-pcxhr" => [ "unknown" ], # pci - "snd-rme32" => [ "unknown" ], # isa - "snd-rme96" => [ "rme96xx" ], # pci - "snd-rme9652" => [ "rme96xx" ], # pci - "snd-sb16" => ["sscape", "sb"], - "snd-sb8" => [ "sb" ], - "snd-sbawe" => [ "awe_wave" ], - "snd-sgalaxy" => [ "sgalaxy" ], # isa - "snd-sonicvibes" => [ "sonicvibes" ], - "snd-sscape" => [ "sscape" ], # isa - "snd-trident" => [ "trident" ], - "snd-usb-audio" => [ "audio" ], # usb - "snd-via82xx" => [ "via82cxxx_audio" ], - "snd-vx222" => [ "unknown" ], - "snd-vxp440" => [ "unknown" ], # pcmcia - "snd-vxpocket" => [ "unknown" ], # pcmcia - "snd-wavefront" => [ "wavefront" ], # isa - "snd-ymfpci" => [ "ymfpci" ], - ); - - -our %oss2alsa = - ( - if_(arch() =~ /ppc/, "dmasound_pmac" => [ "snd-powermac" ]), - "ad1816" => [ "snd-ad1816a" ], - "ad1848" => [ "snd-ad1848", "snd-cs4236" ], - "ad1889" => [ "unknown" ], - "ali5455" => [ "snd-intel8x0" ], - "audigy" => [ "snd-emu10k1" ], - "audio" => [ "snd-usb-audio" ], # usb - "awe_wave" => [ "snd-sbawe" ], - "btaudio" => [ "snd-bt87x" ], - "cmpci" => [ "snd-cmipci" ], - "cs4232" => [ "snd-cs4232" ], - "cs4281" => [ "snd-cs4281" ], - "cs46xx" => [ "snd-cs46xx" ], - "emu10k1" => [ "snd-emu10k1" ], - "es1370" => [ "snd-ens1370" ], - "es1371" => [ "snd-ens1371" ], - "esssolo1" => [ "snd-es1938" ], - "forte" => [ "snd-fm801" ], - "gus" => ["snd-interwave", "snd-gusclassic", "snd-gusmax", "snd-gusextreme"], - "i810_audio" => [ "snd-intel8x0" ], - "ice1712" => [ "snd-ice1712" ], - "mad16" => [ "snd-opti93x" ], - "maestro" => [ "snd-es1968" ], - "maestro3" => [ "snd-maestro3" ], - "mpu401" => [ "snd-mpu401" ], - "msnd_pinnacle" => [ "unknown" ], - "nm256_audio" => [ "snd-nm256" ], - "nvaudio" => [ "snd-intel8x0" ], - "opl3" => [ "snd-opl3sa2" ], - "opl3sa" => [ "snd-opl3sa2" ], - "opl3sa2" => [ "snd-opl3sa2" ], - "pas2" => [ "unknown" ], - "pss" => [ "snd-ad1848" ], - "rme96xx" => [ "snd-rme96", "snd-rme9652" ], - "sam9407" => [ "unknown" ], - "sb" => [ "snd-als100", "snd-cmi8330", "snd-es1688", "snd-es18xx", "snd-es968", "snd-sb8", "snd-sb16" ], - "sgalaxy" => [ "snd-sgalaxy" ], - "sonicvibes" => [ "snd-sonicvibes" ], - "sscape" => [ "snd-sb16", "snd-sscape" ], - "trident" => [ "snd-ali5451", "snd-trident" ], - "via82cxxx_audio" => [ "snd-via82xx" ], - "wavefront" => [ "snd-wavefront" ], - "ymfpci" => [ "snd-ymfpci" ], - ); - -my @blacklist = qw(cs46xx cs4281); -my $blacklisted = 0; - -sub rooted { run_program::rooted($::prefix, @_) } - -sub unload { modules::unload(@_) if $::isStandalone || $blacklisted } +my $pa_startup_scriptfile = "$::prefix/etc/pulse/default.pa"; + +sub is_pulseaudio_glitchfree_enabled() { + return -f $pa_startup_scriptfile && + cat_($pa_startup_scriptfile) !~ /^load-module\s+module-(udev|hal)-detect\s+tsched=0/m; +} + +sub set_pulseaudio_glitchfree { + my ($val) = @_; + + return if ! -f $pa_startup_scriptfile; + + substInFile { + if ($val) { + s/^(load-module\s+module-(udev|hal)-detect)\s+tsched=0/$1/; + } else { + s/^(load-module\s+module-(udev|hal)-detect).*/$1 tsched=0/; + } + } $pa_startup_scriptfile; +} + +sub is_pipewire_wireplumber_enabled { + my ($in) = @_; + return $in->do_pkgs->is_installed('pipewire') && $in->do_pkgs->is_installed('wireplumber'); +} + +sub is_pipewire_media_session_enabled { + my ($in) = @_; + return $in->do_pkgs->is_installed('pipewire') && $in->do_pkgs->is_installed('pipewire-media-session'); +} + +sub rooted { + run_program::rooted($::prefix, @_); +} + +sub unload { modules::unload(@_) if $::isStandalone } sub load { my ($modules_conf, $name) = @_; - modules::load_and_configure($modules_conf, $name) if $::isStandalone || $blacklisted; + modules::load_and_configure($modules_conf, $name) if $::isStandalone; +} + +sub _pidof { + my ($name) = @_; + rooted('/usr/bin/pidof', $name); +} + +# return the pid of a running command +sub _pidof_pid { + my ($name) = @_; + my ($pid) = chomp_(run_program::rooted_get_stdout($::prefix, '/usr/bin/pidof', $name)); + + return $pid; +} + +# return the username of a running command +sub _user_pid { + my ($name) = @_; + my ($pid) = _pidof_pid($name); + my $user; + + if ($pid) { + ($user) = chomp_(run_program::rooted_get_stdout($::prefix, '/usr/bin/ps', '-o', 'uname=', '-p', $pid)); + } + + return $user; +} + +# stop pulseaudio for the running user +sub stop_pulseaudio { + my ($pulseaudio_user) = _user_pid('/usr/bin/pulseaudio'); + + if ($pulseaudio_user) { + if (-x $::prefix . '/usr/bin/pulseaudio') { + rooted('/usr/bin/su', '-l', $pulseaudio_user, '-c', '/usr/bin/pulseaudio --kill'); + } + } + + # try stopping again (in case the /usr/bin/pulseaudio process is still running, but the executable no longer available) + my ($pulseaudio_user) = _user_pid('/usr/bin/pulseaudio'); + if ($pulseaudio_user) { + my ($pulseaudio_pid) = _pidof_pid('/usr/bin/pulseaudio'); + if ($pulseaudio_pid) { + rooted('/usr/bin/su', '-l', $pulseaudio_user, '-c', '/usr/bin/kill -TERM ' . $pulseaudio_pid); + } + } + return $pulseaudio_user; +} + +# stop pipewire services for the running user +sub stop_pipewire { + my ($pipewire_user) = _user_pid('/usr/bin/pipewire'); + + if ($pipewire_user) { + rooted('/usr/bin/systemctl', '--machine=' . $pipewire_user . '@.host', '--user', 'stop', 'pipewire-pulse.service', 'pipewire-pulse.socket', 'pipewire.service', 'pipewire.socket'); + } + + return $pipewire_user; +} + +# start pulseaudio for the specified user +sub start_pulseaudio { + my ($pulseaudio_user) = @_; + + if ($pulseaudio_user) { + rooted('/usr/bin/su', '-l', $pulseaudio_user, '-c', '/usr/bin/pulseaudio --start'); + } +} + +# start pipewire services for the specified user +sub start_pipewire { + my ($pipewire_user) = @_; + + if ($pipewire_user) { + rooted('/usr/bin/systemctl', '--machine=' . $pipewire_user . '@.host', '--user', 'start', 'pipewire.socket', 'pipewire.service', 'pipewire-pulse.socket', 'pipewire-pulse.service'); + } +} + +# stop wireplumber services for the running user +sub stop_wireplumber { + my ($pipewire_user) = _user_pid('/usr/bin/wireplumber'); + + if ($pipewire_user) { + rooted('/usr/bin/systemctl', '--machine=' . $pipewire_user . '@.host', '--user', 'stop', 'wireplumber.service'); + } + + return $pipewire_user; +} + +# start wireplumber +sub start_wireplumber { + my ($pipewire_user) = @_; + + if ($pipewire_user) { + rooted('/usr/bin/systemctl', '--machine=' . $pipewire_user . '@.host', '--user', 'start', 'wireplumber.service'); + } +} + +# stop pipewire-media-session services for the running user +sub stop_pipewire_media_session { + my ($pipewire_user) = _user_pid('/usr/bin/pipewire-media-session'); + + if ($pipewire_user) { + rooted('/usr/bin/systemctl', '--machine=' . $pipewire_user . '@.host', '--user', 'stop', 'pipewire-media-session.service'); + } + + return $pipewire_user; +} + +# start pipewire-media-session services for the specified user +sub start_pipewire_media_session { + my ($pipewire_user) = @_; + + if ($pipewire_user) { + rooted('/usr/bin/systemctl', '--machine=' . $pipewire_user . '@.host', '--user', 'start', 'pipewire-media-session.service'); + } +} + +sub configure_pipewire_wireplumber { + my ($in) = @_; + my ($pipewire_wp_user); + + # preserve pulseaudio user + my ($pulseaudio_user) = _user_pid('/usr/bin/pulseaudio'); + + # stop pipewire and pipewire-media-session services (if any) before removing any packages + # and preserve pipewire-media-session user + $pipewire_wp_user = stop_pipewire_media_session(); + stop_pipewire(); + + my $plasma_installed = $in->do_pkgs->is_installed('plasma-desktop'); + my @pkgs = ( + 'task-pipewire', + 'wireplumber', + ); + if (!$in->do_pkgs->is_installed('pavucontrol-qt')) { + if ($plasma_installed) { + push(@pkgs, 'pavucontrol-qt'); + } + else { + push(@pkgs, 'pavucontrol'); + } + } + + + my $required_installed = $in->do_pkgs->ensure_are_installed( + \@pkgs + ); + + if (!$required_installed) + { + $in->ask_warn(N("Couldn't install the required packages"), + N("Please check the repositories are correctly configured") + ); + return; + } + + set_pulseaudio(0); + + # first of all disabling what has to be disabled to avoid conflicts + if ($in->do_pkgs->is_installed('pipewire-media-session')) { + rooted('/usr/bin/systemctl', '--global', 'disable', 'pipewire-media-session.service'); + } + + if ($in->do_pkgs->is_installed('pipewire')) { + foreach ('pipewire.socket', 'pipewire.service') { + rooted('/usr/bin/systemctl', '--global', 'enable', $_); + } + } + + if ($in->do_pkgs->is_installed('pipewire-pulseaudio')) { + foreach ('pipewire-pulse.socket', 'pipewire-pulse.service') { + rooted('/usr/bin/systemctl', '--global', 'enable', $_); + } + } + + if ($in->do_pkgs->is_installed('wireplumber')) { + rooted('/usr/bin/systemctl', '--global', 'enable', 'wireplumber.service'); + } + + + # stop pulseaudio process if still floating after the switch + stop_pulseaudio(); + + if ($pulseaudio_user) { + # restart pipewire and wireplumber with the same user as initial pulseaudio + start_pipewire($pulseaudio_user); + start_wireplumber($pulseaudio_user); + } + else { + if ($pipewire_wp_user) { + # restart pipewire and wireplumber with the same user as pipewire-media-session + start_pipewire($pipewire_wp_user); + start_wireplumber($pipewire_wp_user); + } + } + + #Plasma tricks + if ($plasma_installed) { + $in->do_pkgs->ensure_is_installed('kpipewire'); + } +} + +sub configure_pipewire_media_session { + my ($in) = @_; + my ($pipewire_ms_user); + + # preserve pulseaudio user + my ($pulseaudio_user) = _user_pid('/usr/bin/pulseaudio'); + + # stop pipewire and wireplumber services (if any) before removing any package + # and preserve wireplumber user + $pipewire_ms_user = stop_wireplumber(); + stop_pipewire(); + + + my $plasma_installed = $in->do_pkgs->is_installed('plasma-desktop'); + my @pkgs = ( + 'task-pipewire', + 'pipewire-media-session', + ); + if (!$in->do_pkgs->is_installed('pavucontrol-qt')) { + if ($plasma_installed) { + push(@pkgs, 'pavucontrol-qt'); + } + else { + push(@pkgs, 'pavucontrol'); + } + } + + my $required_installed = $in->do_pkgs->ensure_are_installed( + \@pkgs + ); + + if (!$required_installed) + { + $in->ask_warn(N("Couldn't install the required packages"), + N("Please check the repositories are correctly configured") + ); + return; + } + + set_pulseaudio(0); + + # first of all disabling what has to be disabled to avoid conflicts + if ($in->do_pkgs->is_installed('wireplumber')) { + rooted('/usr/bin/systemctl', '--global', 'disable', 'wireplumber.service'); + } + + if ($in->do_pkgs->is_installed('pipewire')) { + foreach ('pipewire.socket', 'pipewire.service') { + rooted('/usr/bin/systemctl', '--global', 'enable', $_); + } + } + + if ($in->do_pkgs->is_installed('pipewire-pulseaudio')) { + foreach ('pipewire-pulse.socket', 'pipewire-pulse.service') { + rooted('/usr/bin/systemctl', '--global', 'enable', $_); + } + } + + if ($in->do_pkgs->is_installed('pipewire-media-session')) { + rooted('/usr/bin/systemctl', '--global', 'enable', 'pipewire-media-session.service'); + } + + # stop pulseaudio process if still floating after the switch + stop_pulseaudio(); + + if ($pulseaudio_user) { + # restart pipewire and wireplumber with the same user as initial pulseaudio + start_pipewire($pulseaudio_user); + start_pipewire_media_session($pulseaudio_user); + } + else { + if ($pipewire_ms_user) { + # restart pipewire and wireplumber with the same user as pipewire-media-session + start_pipewire($pipewire_ms_user); + start_pipewire_media_session($pipewire_ms_user); + } + } + + #Plasma tricks + if ($plasma_installed) { + $in->do_pkgs->ensure_is_installed('kpipewire'); + } } -sub get_alternative { - my ($driver) = @_; - $alsa2oss{$driver} || $oss2alsa{$driver}; +sub disable_all_pipewire { + my ($in) = @_; + + if ($in->do_pkgs->is_installed('wireplumber')) { + rooted('/usr/bin/systemctl', '--global', 'disable', 'wireplumber.service'); + } + + if ($in->do_pkgs->is_installed('pipewire-media-session')) { + rooted('/usr/bin/systemctl', '--global', 'disable', 'pipewire-media-session.service'); + } + + if ($in->do_pkgs->is_installed('pipewire-pulseaudio')) { + foreach ('pipewire-pulse.socket', 'pipewire-pulse.service') { + rooted('/usr/bin/systemctl', '--global', 'disable', $_); + } + } + + if ($in->do_pkgs->is_installed('pipewire')) { + foreach ('pipewire.socket', 'pipewire.service') { + rooted('/usr/bin/systemctl', '--global', 'disable', $_); + } + } } -sub do_switch { - my ($in, $modules_conf, $old_driver, $new_driver, $index) = @_; - return if $old_driver eq $new_driver; - my $_wait = $in->wait_message(N("Please wait"), N("Please Wait... Applying the configuration")); - log::explanations("removing old $old_driver\n"); - if ($::isStandalone) { - rooted("service sound stop") unless $blacklisted; - rooted("service alsa stop") if $old_driver =~ /^snd-/ && !$blacklisted; - unload($old_driver); # run_program("/sbin/modprobe -r $driver"); # just in case ... - } - $modules_conf->remove_module($old_driver); - $modules_conf->set_sound_slot("sound-slot-$index", $new_driver); - $modules_conf->write; - if ($new_driver =~ /^snd-/) { # new driver is an alsa one - $in->do_pkgs->ensure_binary_is_installed('alsa-utils', 'alsactl'); - rooted("service alsa start") if $::isStandalone && !$blacklisted; - rooted("/sbin/chkconfig --add alsa") if $::isStandalone; - load($modules_conf, $new_driver) if $::isStandalone; # service alsa is buggy - } else { rooted("/sbin/chkconfig --del alsa") } - log::explanations("loading new $new_driver\n"); - rooted("/sbin/chkconfig --add sound"); # just in case ... - rooted("service sound start") if $::isStandalone && !$blacklisted; +sub configure_pulseaudio { + my ($in) = @_; + + # preserve pipewire running user + my ($pipewire_user) = _user_pid('/usr/bin/pipewire'); + + # stop pipewire, wireplumber and pipewire-media-session services (if any) before removing any packages + my ($wireplumber_user) = stop_wireplumber(); + my ($pipewire_media_session_user) = stop_pipewire_media_session(); + my ($pipewire_user_preserve) = stop_pipewire(); + + # now packages + $in->do_pkgs->remove('pipewire-alsa'); + + my $plasma_installed = $in->do_pkgs->is_installed('plasma-desktop'); + my @pkgs = 'task-pulseaudio'; + if (!$in->do_pkgs->is_installed('pavucontrol-qt')) { + if ($plasma_installed) { + push(@pkgs, 'pavucontrol-qt'); + } + else { + push(@pkgs, 'pavucontrol'); + } + } + + my $required_installed = $in->do_pkgs->ensure_are_installed( + \@pkgs + ); + + if (!$required_installed) + { + $in->ask_warn(N("Couldn't install the required packages"), + N("Please check the repositories are correctly configured") + ); + + # restore previous pipewire (if any) processes if something goes wrong with pulseaudio installation + if ($pipewire_user_preserve) { + start_pipewire($pipewire_user_preserve); + } + + if ($wireplumber_user) { + start_wireplumber($wireplumber_user); + } + + if ($pipewire_media_session_user) { + start_pipewire_media_session($pipewire_media_session_user); + } + + return; + } + + + # disable all the pipewire stuff before managing packages + disable_all_pipewire($in); + + # start pulseaudio with same pipewire preserved user + if ($pipewire_user) { + start_pulseaudio($pipewire_user); + } } -sub switch { +sub config { my ($in, $modules_conf, $device) = @_; my $driver = $device->{current_driver} || $device->{driver}; - foreach (@blacklist) { $blacklisted = 1 if $driver eq $_ } - my @alternative = @{get_alternative($driver)}; - unless ($driver eq $device->{driver} || member($device->{driver}, @alternative)) { - push @alternative, @{get_alternative($device->{driver})}, $device->{driver}; - } - if (@alternative) { - my $new_driver = $driver; + my @alternative = $driver ne $device->{driver} ? $device->{driver} : (); + if ($driver eq "unknown") { + $in->ask_warn(N("No known driver"), + N("There's no known driver for your sound card (%s)", + $device->{description})); + } else { push @alternative, $driver; my %des = modules::category2modules_and_description('multimedia/sound'); + + my $is_pulseaudio_enabled_val = is_pulseaudio_enabled($in); + my $is_pulseaudio_glitchfree_enabled_val = is_pulseaudio_glitchfree_enabled(); + + my $audiosystem = 'None'; + if ($is_pulseaudio_enabled_val && $is_pulseaudio_glitchfree_enabled_val) { + $audiosystem = 'PulseAudioGF'; + } elsif ($is_pulseaudio_enabled_val) { + $audiosystem = 'PulseAudio'; + } elsif (is_pipewire_wireplumber_enabled($in) || _pidof('/usr/bin/wireplumber')) { + $audiosystem = 'PipeWireWP'; + } elsif (is_pipewire_media_session_enabled($in) || _pidof('/usr/bin/pipewire-media-session')) { + $audiosystem = 'PipeWireMS'; + } + + my $write_config = sub { + if ($audiosystem eq 'None') { + #### ALSA alone + disable_all_pipewire($in); + set_pulseaudio(0); + set_pulseaudio_glitchfree(0); + # TODO check if adding autospawn = no to /etc/pulse/client.conf is needed + } elsif ($audiosystem eq 'PulseAudio') { + #### PulseAudio + configure_pulseaudio($in); + set_pulseaudio(1); + set_pulseaudio_glitchfree(0); + my $lib = get_libdir(); + $in->do_pkgs->ensure_is_installed($lib . 'alsa-plugins-pulseaudio', + '/usr/' . $lib . '/alsa-lib/libasound_module_pcm_pulse.so'); + } elsif ($audiosystem eq 'PulseAudioGF') { + #### PulseAudio with Glitch-Free mode + configure_pulseaudio($in); + set_pulseaudio(1); + set_pulseaudio_glitchfree(1); + my $lib = get_libdir(); + $in->do_pkgs->ensure_is_installed($lib . 'alsa-plugins-pulseaudio', + '/usr/' . $lib . '/alsa-lib/libasound_module_pcm_pulse.so'); + } elsif ($audiosystem eq 'PipeWireWP') { + #### PipeWire with WirePlumber + configure_pipewire_wireplumber($in); + } elsif ($audiosystem eq 'PipeWireMS') { + #### PipeWire with PipeWire Media Session + configure_pipewire_media_session($in); + } else { + #### Unmanaged value + #TODO Error here + } + + $in->ask_warn('', N("You need to reboot for changes to take effect")) if $::isStandalone; + + }; + + my $warn_both = ($in->do_pkgs->is_installed('pipewire') && $in->do_pkgs->is_installed('pulseaudio') && (-e $::prefix . '/etc/systemd/user/sockets.target.wants/pipewire.socket' || -e $::prefix . '/etc/systemd/user/sockets.target.wants/pipewire.service')) ? + N("Warning: both pulseaudio and pipewire are installed and can conflict each other. Please fix your config by applying a choice") : + ""; + + my $is_pipewire_available = $in->do_pkgs->is_available('task-pipewire'); + my $warn_pipewire_unavailable = !$is_pipewire_available ? + N("Warning: task-pipewire is not available in any media sources, so only pulseaudio could be set up. Please fix your repo configuration.") : + ""; - if ($new_driver eq 'unknown') { - $in->ask_from(N("No alternative driver"), - N("There's no known OSS/ALSA alternative driver for your sound card (%s) which currently uses \"%s\"", - $device->{description}, $driver), - [ - get_any_driver_entry($in, $modules_conf, $driver, $device), - ] - ); + my @service_list = ( + 'None', + 'PulseAudio', + 'PulseAudioGF', + ); + if ($is_pipewire_available) { + push @service_list, 'PipeWireWP'; + push @service_list, 'PipeWireMS'; + } + my @common = ( + { + label => N("Select the sound server"), + title => 1, + }, + { + val => \$audiosystem, + list => \@service_list, + format => sub { + my ($choice) = @_; + +{ + 'None' => N("None"), + 'PulseAudio' => N("PulseAudio"), + 'PulseAudioGF' => N("PulseAudio with Glitch-Free mode"), + 'PipeWireWP' => N("PipeWire with WirePlumber"), + 'PipeWireMS' => N("PipeWire with PipeWire Media Session"), + }->{$choice}; + }, + type => 'list', + }, + { + advanced => 1, + val => N("Reset sound mixer to default values"), + clicked => sub { run_program::run('reset_sound') } + }, + { + val => N("Troubleshooting"), disabled => sub {}, + clicked => sub { &trouble($in) } + }, + ); + + my @messages = ("<b><i>" . $device->{description} . "</i></b>", + N("Your card uses the <b>\"%s\"</b> driver\n", $driver)); + + if ($warn_both) { + push @messages, ("<b>" . $warn_both . "</b>"); + } + if (!$is_pipewire_available) { + push @messages, "<b>" . $warn_pipewire_unavailable . "</b>"; + } + if ($driver eq 'unknown') { + if ($in->ask_from_({ + title => N("No alternative driver"), + messages => N("There's no known OSS/ALSA alternative driver for your sound card (%s) which currently uses \"%s\"", + $device->{description}, $driver), + }, + \@common, + )) { + $write_config->(); + } } elsif ($in->ask_from_({ title => N("Sound configuration"), - messages => - N("Here you can select an alternative driver (either OSS or ALSA) for your sound card (%s).", - $device->{description}) . - #-PO: here the first %s is either "OSS" or "ALSA", - #-PO: the second %s is the name of the current driver - #-PO: and the third %s is the name of the default driver - N("\n\nYour card currently use the %s\"%s\" driver (default driver for your card is \"%s\")", ($driver =~ /^snd-/ ? "ALSA " : "OSS "), $driver, $device->{driver}), - interactive_help => sub { - N("OSS (Open Sound System) was the first sound API. It's an OS independent sound API (it's available on most UNIX(tm) systems) but it's a very basic and limited API. -What's more, OSS drivers all reinvent the wheel. - -ALSA (Advanced Linux Sound Architecture) is a modularized architecture which -supports quite a large range of ISA, USB and PCI cards.\n -It also provides a much higher API than OSS.\n -To use alsa, one can either use: -- the old compatibility OSS api -- the new ALSA api that provides many enhanced features but requires using the ALSA library. -"); - }, + interactive_help_id => 'soundConfig', + messages => \@messages }, - [ - { - label => N("Driver:"), val => \$new_driver, list => \@alternative, default => $new_driver, sort =>1, - help => join("\n\n", map { qq("$_": ) . $des{$_} } @alternative), - allow_empty_list => 1, - }, - { - val => N("Trouble shooting"), disabled => sub {}, - clicked => sub { &trouble($in) } - }, - get_any_driver_entry($in, $modules_conf, $driver, $device), - ])) + \@common, + )) { - return if $new_driver eq $device->{current_driver}; - log::explanations("switching audio driver from '" . $device->{current_driver} . "' to '$new_driver'\n"); - $in->ask_warn(N("Warning"), N("The old \"%s\" driver is blacklisted.\n -It has been reported to oops the kernel on unloading.\n -The new \"%s\" driver will only be used on next bootstrap.", $device->{current_driver}, $new_driver)) if $blacklisted; - do_switch($in, $modules_conf, $device->{current_driver}, $new_driver, $device->{sound_slot_index}); - $device->{current_driver} = $new_driver; + $write_config->(); } - } elsif ($driver =~ /^Bad:/) { - $driver =~ s/^Bad://; - $in->ask_warn(N("No open source driver"), - N("There's no free driver for your sound card (%s), but there's a proprietary driver at \"%s\".", - $device->{description}, $driver)); - } elsif ($driver eq "unknown") { - $in->ask_from(N("No known driver"), - N("There's no known driver for your sound card (%s)", - $device->{description}), - [ get_any_driver_entry($in, $modules_conf, $driver, $device) ]); - } else { - $in->ask_warn(N("Unknown driver"), - N("Error: The \"%s\" driver for your sound card is unlisted", - $driver)); } - end: } -sub config { - my ($in, $modules_conf, $device) = @_; - switch($in, $modules_conf, $device); -} - - sub trouble { my ($in) = @_; - $in->ask_warn(N("Sound trouble shooting"), + $in->ask_warn(N("Sound troubleshooting"), formatAlaTeX( #-PO: keep the double empty lines between sections, this is formatted a la LaTeX - N("The classic bug sound tester is to run the following commands: + N("Below are some basic tips to help debug audio problems, but for accurate and up-to-date tips and tricks, please see: + +https://wiki.mageia.org/en/Support:DebuggingSoundProblems + + + +- General Recommendation: Enable PulseAudio. If you have opted to not to use PulseAudio, we would strongly advise you enable it. For the vast majority of desktop use cases, PulseAudio is the recommended and best supported option. + + + +- \"kmix\" (KDE), \"gnome-control-center sound\" (GNOME) and \"pavucontrol\" (generic) will launch graphical applications to allow you to view your sound devices and adjust volume levels + +- \"ps aux | grep pulseaudio\" will check that PulseAudio is running. -- \"lspcidrake -v | fgrep AUDIO\" will tell you which driver your card uses -by default -- \"grep sound-slot /etc/modules.conf\" will tell you what driver it -currently uses +- \"pactl stat\" will check that you can connect to the PulseAudio daemon correctly. -- \"/sbin/lsmod\" will enable you to check if its module (driver) is -loaded or not -- \"/sbin/chkconfig --list sound\" and \"/sbin/chkconfig --list alsa\" will -tell you if sound and alsa services're configured to be run on -initlevel 3 +- \"pactl list sink-inputs\" will tell you which programs are currently playing sound via PulseAudio. -- \"aumix -q\" will tell you if the sound volume is muted or not -- \"/sbin/fuser -v /dev/dsp\" will tell which program uses the sound card. +- \"systemctl status osspd.service\" will tell you the current state of the OSS Proxy Daemon. This is used to enable sound from legacy applications which use the OSS sound API. You should install the \"ossp\" package if you need this functionality. + + +- \"pacmd ls\" will give you a LOT of debug information about the current state of your audio. + + +- \"lspcidrake -v | grep -i audio\" will tell you which low-level driver your card uses by default. + + +- \"/usr/sbin/lsmod | grep snd\" will enable you to check which sound related kernel modules (drivers) are loaded. + + +- \"alsamixer -c 0\" will give you a text-based mixer to the low level ALSA mixer controls for first sound card + + +- \"/usr/sbin/fuser -v /dev/snd/pcm* /dev/dsp\" will tell which programs are currently using the sound card directly (normally this should only show PulseAudio) "))); } -sub get_any_driver_entry { - my ($in, $modules_conf, $driver, $device) = @_; - return () if $::isInstall; - +{ - val => N("Let me pick any driver"), disabled => sub {}, - clicked => sub { - my $old_driver = $driver; - if ($in->ask_from(N("Choosing an arbitrary driver"), - formatAlaTeX( - #-PO: keep the double empty lines between sections, this is formatted a la LaTeX - N("If you really think that you know which driver is the right one for your card -you can pick one in the above list. - -The current driver for your \"%s\" sound card is \"%s\" ", $device->{description}, $driver)), - [ - { label => N("Driver:"), val => \$driver, list => [ category2modules("multimedia/sound") ], type => 'combo', default => $driver, sort =>1, separator => '|' }, - ] - )) { - do_switch($in, $modules_conf, $old_driver, $driver, $device->{sound_slot_index}); - goto end; - } - } - }; +sub configure_one_sound_slot { + my ($modules_conf, $index, $driver) = @_; + $modules_conf->set_sound_slot("sound-slot-$index", $driver); + $modules_conf->set_options($driver, "xbox=1") if $driver eq "snd_intel8x0" && detect_devices::is_xbox(); + $modules_conf->set_options('snd-ac97-codec', "power_save=1") if $driver =~ /^snd/ && detect_devices::isLaptop(); } - sub configure_sound_slots { my ($modules_conf) = @_; my $altered = 0; each_index { my $default_driver = $modules_conf->get_alias("sound-slot-$::i"); - if (!member($default_driver, @{get_alternative($_->{driver})}, $_->{driver})) { + if (!member($default_driver, $_->{driver})) { $altered ||= $default_driver; - $modules_conf->set_sound_slot("sound-slot-$::i", $_->{driver}); + configure_one_sound_slot($modules_conf, $::i, $_->{driver}); } } detect_devices::getSoundDevices(); $modules_conf->write if $altered && $::isStandalone; |