@@ -588,6 +588,7 @@ func_lib_enable_pipewire()
588588 systemctl --user start wireplumber.service
589589
590590 systemctl --user daemon-reload
591+ sleep 3
591592
592593 systemctl is-active --user --quiet pipewire{,-pulse}.{socket,service} && dlogi " Pipewire started"
593594 systemctl is-active --user --quiet wireplumber.service && dlogi " Wireplumber started"
@@ -609,6 +610,7 @@ func_lib_disable_pipewire()
609610
610611 sudo systemctl --global mask wireplumber.service
611612 sudo systemctl --global mask pipewire{,-pulse}.{socket,service}
613+ sleep 1
612614
613615 if systemctl is-active --user --quiet wireplumber.service; then dlogi " Wireplumber not stopped" ; else dlogi " Wireplumber stopped" ; fi
614616 if systemctl is-active --user --quiet pipewire{,-pulse}.{socket,service}; then dlogi " Pipewire not stopped" ; else dlogi " Pipewire stopped" ; fi
@@ -951,15 +953,9 @@ aplay_opts()
951953 # shellcheck disable=SC2086
952954 tinyplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS -D " $card_nr " -d " $dev_nr " -i wav noise.wav
953955 elif [[ " $SOF_ALSA_TOOL " = " alsa" ]]; then
954- if [[ " $SOF_TEST_PIPEWIRE " == true ]]; then
955- dlogc " timeout -k $duration $duration aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $* " # option -d doesn't work with pipewire so we need timeout
956- # shellcheck disable=SC2086
957- timeout -k " $duration " " $duration " aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS " $@ "
958- else
959- dlogc " aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $* "
960- # shellcheck disable=SC2086
961- aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS " $@ "
962- fi
956+ dlogc " aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $* "
957+ # shellcheck disable=SC2086
958+ aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS " $@ "
963959 else
964960 die " Unknown ALSA tool: ${SOF_ALSA_TOOL} "
965961 fi
@@ -976,20 +972,33 @@ arecord_opts()
976972 # shellcheck disable=SC2086
977973 tinycap $SOF_ALSA_OPTS $SOF_ARECORD_OPTS " $file " -D " $card_nr " -d " $dev_nr " -c " $channel " -t " $duration " -r " $rate " -b " $format "
978974 elif [[ " $SOF_ALSA_TOOL " = " alsa" ]]; then
979- if [[ " $SOF_TEST_PIPEWIRE " == true ]]; then
980- dlogc " timeout -k $duration $duration arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $* " # option -d doesn't work with pipewire so we need timeout
981- # shellcheck disable=SC2086
982- timeout -k " $duration " " $duration " arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS " $@ "
983- else
984- dlogc " arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $* "
985- # shellcheck disable=SC2086
986- arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS " $@ "
987- fi
975+ dlogc " arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $* "
976+ # shellcheck disable=SC2086
977+ arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS " $@ "
988978 else
989979 die " Unknown ALSA tool: ${SOF_ALSA_TOOL} "
990980 fi
991981}
992982
983+ # Get the ID of the first source of a given type, e.g. "Microphone" or "Audio codec". Print an empty line if ID not found.
984+ get_id_of_pipewire_source ()
985+ {
986+ # $ wpctl status returns list of all endpoints managed by wireplumber. We use grep to get only lines after "Sources".
987+ # Then we filter by given sink/source type, which returns something like this:
988+ # │ * 48. sof-soundwire Microphone [vol: 0.40] (or without the * when it's not the current default)
989+ # We filter out everything but ID, and only take the first line of the output (if there's more that one object of that type we ignore the rest)
990+
991+ local object_name=" $1 "
992+ object_id=$( wpctl status | grep " Sources" -A 10 | awk -v name=" $object_name " ' tolower($0) ~ tolower(name) { sub(/\*/,""); sub(/\./,"",$2); print $2; exit }' )
993+
994+ # Check if object_id is a number
995+ re=' ^[0-9]+$'
996+ if [[ " $object_id " =~ $re ]] ; then
997+ printf ' %s' " $object_id "
998+ fi
999+
1000+ }
1001+
9931002# Get the ID of the first sink/source of a given type, e.g. "Speaker" or "Headphones". Print an empty line if ID not found.
9941003get_id_of_pipewire_endpoint ()
9951004{
@@ -1008,6 +1017,42 @@ get_id_of_pipewire_endpoint()
10081017
10091018}
10101019
1020+ # Get pipewire sink name for given alsa pcm
1021+ # Arguments: 1-alsa pcm, ex. hw:0,0
1022+ set_default_pipewire_sink_for_alsa_pcm ()
1023+ {
1024+ card_id=$( echo " $1 " | awk -F' [:,]' ' {print $2}' )
1025+ dev_id=$( echo " $1 " | awk -F' [:,]' ' {print $3}' )
1026+ dlogi " card: $card_id , device: $dev_id "
1027+
1028+ sink_name=$( pactl list sinks \
1029+ | grep -B 20 " alsa.device = \" $dev_id \" " \
1030+ | grep -B 16 " alsa.card = \" $card_id \" " \
1031+ | grep " Name: alsa_output" \
1032+ | cut -d' ' -f2-)
1033+
1034+ dlogi " Setting default sink set to $sink_name "
1035+ pactl set-default-sink " $sink_name "
1036+ }
1037+
1038+ # Get pipewire source name for given alsa pcm
1039+ # Arguments: 1-alsa pcm, ex. hw:0,0
1040+ set_default_pipewire_source_for_alsa_pcm ()
1041+ {
1042+ card_id=$( echo " $1 " | awk -F' [:,]' ' {print $2}' )
1043+ dev_id=$( echo " $1 " | awk -F' [:,]' ' {print $3}' )
1044+ dlogi " card: $card_id , device: $dev_id "
1045+
1046+ sink_name=$( pactl list sources \
1047+ | grep -B 20 " alsa.device = \" $dev_id \" " \
1048+ | grep -B 16 " alsa.card = \" $card_id \" " \
1049+ | grep " Name: alsa_input" \
1050+ | cut -d' ' -f2-)
1051+
1052+ dlogi " Setting default source set to $sink_name "
1053+ pactl set-default-source " $sink_name "
1054+ }
1055+
10111056die ()
10121057{
10131058 dloge " $@ "
0 commit comments