-
Notifications
You must be signed in to change notification settings - Fork 59
case-lib: apause: Make sure the PCM is running before pausing #1287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
redzynix
merged 1 commit into
thesofproject:main
from
ranj063:fix/multiple_pause_resume
Oct 16, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -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 | ||||||||
|
|
@@ -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 | ||||||||
| # this is to make sure that in the case of an xrun the application | ||||||||
| # successfully recovers and restarts the stream. | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| 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 | ||||||||
| } | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||||||||
|
|
||||||||
|
|
||||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I bet it's quite a lot more than 50ms in practice.
There was a problem hiding this comment.
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
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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 1waits 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.