Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 40 additions & 5 deletions Runner/suites/Multimedia/Audio/AudioRecord/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,34 @@ case "$AUDIO_BACKEND:$SRC_CHOICE" in
esac

# ---- Dynamic fallback when mic is missing on the chosen backend ----
# Stay on PipeWire even if SRC_ID is empty; pw-record can use the default source.
# For real mic capture, do not allow PipeWire to record from an implicit
# default source when no concrete source was discovered. On systems without
# a real capture source, this can record from dummy/null/default paths or fail
# after creating empty files.
if [ -z "$SRC_ID" ] && [ "$SRC_CHOICE" = "mic" ] && [ "$AUDIO_BACKEND" = "pipewire" ]; then
log_warn "$TESTNAME: no concrete PipeWire mic source found; probing direct ALSA capture path"

if audio_probe_alsa_capture_profile; then
ALSA_CAPTURE_PROBED=1
AUDIO_BACKEND="alsa"
AUDIO_SYSTEMD_MANAGED=0
export AUDIO_SYSTEMD_MANAGED

SRC_ID="$AUDIO_ALSA_CAPTURE_DEVICE"
SRC_LABEL="$SRC_ID"

log_warn "$TESTNAME: falling back to direct ALSA capture device: $SRC_ID"
else
log_skip "$TESTNAME SKIP - no real capture source available; PipeWire mic source missing and ALSA capture probe failed: ${AUDIO_ALSA_CAPTURE_REASON:-capture path unavailable}"
echo "$RESULT_TESTNAME SKIP" > "$RES_FILE"
exit 0
fi
fi

if [ -z "$SRC_ID" ] && [ "$SRC_CHOICE" = "mic" ] && [ "$AUDIO_BACKEND" != "pipewire" ]; then
for b in $BACKENDS_TO_TRY; do
[ "$b" = "$AUDIO_BACKEND" ] && continue

case "$b" in
pipewire)
cand="$(pw_default_mic)"
Expand All @@ -535,17 +559,28 @@ if [ -z "$SRC_ID" ] && [ "$SRC_CHOICE" = "mic" ] && [ "$AUDIO_BACKEND" != "pipew
fi
;;
alsa)
cand="$(alsa_pick_capture)"
if [ -n "$cand" ]; then
if audio_probe_alsa_capture_profile; then
ALSA_CAPTURE_PROBED=1
AUDIO_BACKEND="alsa"
SRC_ID="$cand"
AUDIO_SYSTEMD_MANAGED=0
export AUDIO_SYSTEMD_MANAGED

SRC_ID="$AUDIO_ALSA_CAPTURE_DEVICE"
SRC_LABEL="$SRC_ID"

log_info "Falling back to backend: alsa (device=$SRC_ID)"
break
fi
;;
esac
done
fi

if [ -z "$SRC_ID" ]; then
log_skip "$TESTNAME SKIP - requested source '$SRC_CHOICE' not available on any backend (${BACKENDS_TO_TRY:-unknown})"
echo "$RESULT_TESTNAME SKIP" > "$RES_FILE"
exit 0
fi

# Only skip if no source AND not on PipeWire.
if [ -z "$SRC_ID" ] && [ "$AUDIO_BACKEND" != "pipewire" ]; then
Expand Down Expand Up @@ -592,7 +627,7 @@ fi
if [ "$AUDIO_BACKEND" = "pipewire" ]; then
if [ -n "$SRC_ID" ]; then
SRC_LABEL="$(pw_source_label_safe "$SRC_ID")"
wpctl set-default "$SRC_ID" >/dev/null 2>&1 || true
pw_set_default_source "$SRC_ID" >/dev/null 2>&1 || true
[ -z "$SRC_LABEL" ] && SRC_LABEL="unknown"
log_info "Routing to source: id/name=$SRC_ID label='$SRC_LABEL' choice=$SRC_CHOICE"
else
Expand Down
Loading