@@ -594,6 +594,7 @@ func_lib_enable_pipewire()
594594 systemctl --user start wireplumber.service
595595
596596 systemctl --user daemon-reload
597+ sleep 3
597598
598599 systemctl is-active --user --quiet pipewire{,-pulse}.{socket,service} && dlogi " Pipewire started"
599600 systemctl is-active --user --quiet wireplumber.service && dlogi " Wireplumber started"
@@ -615,6 +616,7 @@ func_lib_disable_pipewire()
615616
616617 sudo systemctl --global mask wireplumber.service
617618 sudo systemctl --global mask pipewire{,-pulse}.{socket,service}
619+ sleep 1
618620
619621 if systemctl is-active --user --quiet wireplumber.service; then dlogi " Wireplumber not stopped" ; else dlogi " Wireplumber stopped" ; fi
620622 if systemctl is-active --user --quiet pipewire{,-pulse}.{socket,service}; then dlogi " Pipewire not stopped" ; else dlogi " Pipewire stopped" ; fi
@@ -957,15 +959,9 @@ aplay_opts()
957959 # shellcheck disable=SC2086
958960 tinyplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS -D " $card_nr " -d " $dev_nr " -i wav noise.wav
959961 elif [[ " $SOF_ALSA_TOOL " = " alsa" ]]; then
960- if [[ " $SOF_TEST_PIPEWIRE " == true ]]; then
961- dlogc " timeout -k $duration $duration aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $* " # option -d doesn't work with pipewire so we need timeout
962- # shellcheck disable=SC2086
963- timeout -k " $duration " " $duration " aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS " $@ "
964- else
965- dlogc " aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $* "
966- # shellcheck disable=SC2086
967- aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS " $@ "
968- fi
962+ dlogc " aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $* "
963+ # shellcheck disable=SC2086
964+ aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS " $@ "
969965 else
970966 die " Unknown ALSA tool: ${SOF_ALSA_TOOL} "
971967 fi
@@ -982,20 +978,33 @@ arecord_opts()
982978 # shellcheck disable=SC2086
983979 tinycap $SOF_ALSA_OPTS $SOF_ARECORD_OPTS " $file " -D " $card_nr " -d " $dev_nr " -c " $channel " -t " $duration " -r " $rate " -b " $format "
984980 elif [[ " $SOF_ALSA_TOOL " = " alsa" ]]; then
985- if [[ " $SOF_TEST_PIPEWIRE " == true ]]; then
986- dlogc " timeout -k $duration $duration arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $* " # option -d doesn't work with pipewire so we need timeout
987- # shellcheck disable=SC2086
988- timeout -k " $duration " " $duration " arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS " $@ "
989- else
990- dlogc " arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $* "
991- # shellcheck disable=SC2086
992- arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS " $@ "
993- fi
981+ dlogc " arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $* "
982+ # shellcheck disable=SC2086
983+ arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS " $@ "
994984 else
995985 die " Unknown ALSA tool: ${SOF_ALSA_TOOL} "
996986 fi
997987}
998988
989+ # 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.
990+ get_id_of_pipewire_source ()
991+ {
992+ # $ wpctl status returns list of all endpoints managed by wireplumber. We use grep to get only lines after "Sources".
993+ # Then we filter by given sink/source type, which returns something like this:
994+ # │ * 48. sof-soundwire Microphone [vol: 0.40] (or without the * when it's not the current default)
995+ # 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)
996+
997+ local object_name=" $1 "
998+ object_id=$( wpctl status | grep " Sources" -A 10 | awk -v name=" $object_name " ' tolower($0) ~ tolower(name) { sub(/\*/,""); sub(/\./,"",$2); print $2; exit }' )
999+
1000+ # Check if object_id is a number
1001+ re=' ^[0-9]+$'
1002+ if [[ " $object_id " =~ $re ]] ; then
1003+ printf ' %s' " $object_id "
1004+ fi
1005+
1006+ }
1007+
9991008# 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.
10001009get_id_of_pipewire_endpoint ()
10011010{
@@ -1014,6 +1023,42 @@ get_id_of_pipewire_endpoint()
10141023
10151024}
10161025
1026+ # Get pipewire sink name for given alsa pcm
1027+ # Arguments: 1-alsa pcm, ex. hw:0,0
1028+ set_default_pipewire_sink_for_alsa_pcm ()
1029+ {
1030+ card_id=$( echo " $1 " | awk -F' [:,]' ' {print $2}' )
1031+ dev_id=$( echo " $1 " | awk -F' [:,]' ' {print $3}' )
1032+ dlogi " card: $card_id , device: $dev_id "
1033+
1034+ sink_name=$( pactl list sinks \
1035+ | grep -B 20 " alsa.device = \" $dev_id \" " \
1036+ | grep -B 16 " alsa.card = \" $card_id \" " \
1037+ | grep " Name: alsa_output" \
1038+ | cut -d' ' -f2-)
1039+
1040+ dlogi " Setting default sink set to $sink_name "
1041+ pactl set-default-sink " $sink_name "
1042+ }
1043+
1044+ # Get pipewire source name for given alsa pcm
1045+ # Arguments: 1-alsa pcm, ex. hw:0,0
1046+ set_default_pipewire_source_for_alsa_pcm ()
1047+ {
1048+ card_id=$( echo " $1 " | awk -F' [:,]' ' {print $2}' )
1049+ dev_id=$( echo " $1 " | awk -F' [:,]' ' {print $3}' )
1050+ dlogi " card: $card_id , device: $dev_id "
1051+
1052+ sink_name=$( pactl list sources \
1053+ | grep -B 20 " alsa.device = \" $dev_id \" " \
1054+ | grep -B 16 " alsa.card = \" $card_id \" " \
1055+ | grep " Name: alsa_input" \
1056+ | cut -d' ' -f2-)
1057+
1058+ dlogi " Setting default source set to $sink_name "
1059+ pactl set-default-source " $sink_name "
1060+ }
1061+
10171062die ()
10181063{
10191064 dloge " $@ "
0 commit comments