feat: rename StreamTrait::play to start, add draining stop#1258
Open
roderickvd wants to merge 13 commits into
Open
feat: rename StreamTrait::play to start, add draining stop#1258roderickvd wants to merge 13 commits into
roderickvd wants to merge 13 commits into
Conversation
0101f48 to
f5cbdac
Compare
This was referenced Jul 4, 2026
Open
This was referenced Jul 4, 2026
f5cbdac to
a36d6d7
Compare
a36d6d7 to
9286187
Compare
9286187 to
a216772
Compare
a216772 to
6fd7141
Compare
6fd7141 to
aa9f4b3
Compare
37cc6a5 to
06c6553
Compare
06c6553 to
86e2405
Compare
86e2405 to
348e1b8
Compare
Comment on lines
+163
to
+165
| fn stop(&self, timeout: Option<std::time::Duration>) -> Result<(), Error> { | ||
| let do_drain = self.is_output && timeout != Some(std::time::Duration::ZERO); | ||
| if do_drain { |
Comment on lines
+520
to
+533
| fn stop(&self, timeout: Option<Duration>) -> Result<(), Error> { | ||
| self.draining.store(true, Ordering::Relaxed); | ||
| crate::host::com::com_initialized(); | ||
|
|
||
| if timeout != Some(Duration::ZERO) { | ||
| let wait = if let Some(ref client) = self.drain_audio_client { | ||
| unsafe { | ||
| let padding = client.GetCurrentPadding().unwrap_or(0); | ||
| let latency_hns = client.GetStreamLatency().unwrap_or(0); | ||
| let mut buffered = | ||
| Duration::from_nanos((latency_hns.max(0) as u64).saturating_mul(100)); | ||
| if let Ok(fmt) = client.GetMixFormat() { | ||
| let sample_rate = (*fmt).nSamplesPerSec; | ||
| Com::CoTaskMemFree(Some(fmt.cast())); |
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 33 out of 33 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
src/host/wasapi/stream.rs:231
- The unsafe
Sendjustification comment is now out of date:Streamgaineddrainingandfill_usecfields, but they are not mentioned in the list of Send fields. For unsafe impls, keeping this rationale accurate is important for future maintenance and auditing.
// SAFETY: Windows Event HANDLEs are safe to send between threads - they are designed for
// synchronization. All fields of Stream are Send:
// - JoinHandle<()> is Send
// - Sender<Command> is Send
// - Foundation::HANDLE is Send (Windows synchronization primitive)
// - Latch is Send
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR introduces
start/pause/stopsemantics onStreamTraitwith drainingstop.Playback
On playback streams, the difference between pausing and stopping is that:
pausehalts as soon as possible, if necessary discarding buffered audiostop(timeout)drains, letting buffered output finish before halting.stopthus blocks until the buffer empties ortimeoutelapses.Capture
Capture streams have nothing to drain and halt immediately on
stop.Behavior details
playis now deprecated and forwards tostart.timeoutofNonewaits indefinitely;Some(Duration::ZERO)halts without draining.start.Backend support
stop, except WebAudio and AudioWorklet where the calling thread can't block.pausenow implements a soft-pause fallback when there is no hardware support.StreamStateatomics in ASIO and JACK fromAcquire/ReleasetoRelaxed(no associated data payload).Related
Fixes: