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
43 changes: 43 additions & 0 deletions case-lib/apause.exp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,29 @@ proc cr_to_lf {arg} {
#
# arecord $cmd_opts -D $dev -r $rate -c $channel -f $fmt -vv -i $file_name ...
log 0 "$argv0 spawning: $argv"

set device [lindex $argv 2]
set command [lindex $argv 0]

# Determine direction based on the command
if {$command eq "aplay"} {
set direction "p" ; # Playback
} else {
set direction "c" ; # Capture
}

# parse the card number and device
if {![regexp {hw:(\d+),(\d+)} $device match card_number device_id]} {
log 0 "ERROR: Failed to parse hw string: $hw_string"
}

set pcm_status_file "/proc/asound/card${card_number}/pcm${device_id}${direction}/sub0/status"

if {![file exists $pcm_status_file]} {
log 0 "ERROR: PCM status file not found: $pcm_status_file"
exit 1
}

spawn {*}$argv
set start_time_ms [clock milliseconds]; # re-adjust
set last_space_time 0 ; # could not resist that name
Expand Down Expand Up @@ -218,6 +241,26 @@ expect {
log 1 "($pauses_counter/$repeat_count) Found volume ### | __%, active for $_record_for ms"

set _delay [substract_time_since_last_space $_record_for]

# wait 50ms for the PCM status to be RUNNING before pausing
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# wait 50ms for the PCM status to be RUNNING before pausing
# pool for approximately 50ms for the PCM status to be RUNNING before pausing

I bet it's quite a lot more than 50ms in practice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd think it would be a lot less 50ms is really like the worst case

Copy link
Collaborator

@marc-hb marc-hb Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid we are talking across each other. From experience, after 1 waits at least 1 but a lot more in reality. Hence my suggested change.

Unlike me, I suspect you are talking about audio, not about expect?

BTW take a look at the comment on line 63.

# this is to make sure that in the case of an xrun the application
# successfully recovers and restarts the stream.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# successfully recovers and restarts the stream.
# successfully recovers and restarts the stream.
# change `max_attempts` to zero when observing xruns is desired.

set max_attempts 50
set attempt 0
while {$attempt < $max_attempts} {
set pcm_status [exec cat $pcm_status_file]
if {[regexp {state:\s*RUNNING} $pcm_status]} {
break
}
incr attempt
after 1
}
if {$attempt >= $max_attempts} {
log 0 "ERROR: timeout waiting for PCM to be in RUNNING state before pause"
log 0 "Current state: $pcm_status"
exit 1
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logging the number of attempts (at a high log level) would not hurt.


after $_delay "press_space; set state pause_requested"
log 3 "last_space_time=$last_space_time; timer in $_delay"

Expand Down