Skip to content

Commit

Permalink
Restore some state in case of reinit failure when device has changed …
Browse files Browse the repository at this point in the history
…while paused
  • Loading branch information
padenot committed Aug 9, 2024
1 parent 387e7e2 commit f04a50e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4877,6 +4877,8 @@ impl<'ctx> Drop for AudioUnitStream<'ctx> {

impl<'ctx> StreamOps for AudioUnitStream<'ctx> {
fn start(&mut self) -> Result<()> {
let was_stopped = self.stopped.load(Ordering::SeqCst);
let was_draining = self.draining.load(Ordering::SeqCst);
self.stopped.store(false, Ordering::SeqCst);
self.draining.store(false, Ordering::SeqCst);

Expand All @@ -4886,12 +4888,18 @@ impl<'ctx> StreamOps for AudioUnitStream<'ctx> {
// Need reinitialization: device was changed when paused. It will be started after
// reinit because self.stopped is false.
if self.delayed_reinit {
self.reinit().inspect_err(|_| {
let rv = self.reinit().inspect_err(|_| {
cubeb_log!(
"({:p}) delayed reinit during start failed.",
self.core_stream_data.stm_ptr
);
})?;
});
// In case of failure, restore the state
if rv.is_err() {
self.stopped.store(was_stopped, Ordering::SeqCst);
self.draining.store(was_draining, Ordering::SeqCst);
return Err(Error::error());
}
self.delayed_reinit = false;
Ok(())
} else {
Expand All @@ -4901,7 +4909,7 @@ impl<'ctx> StreamOps for AudioUnitStream<'ctx> {
})
}
})
.unwrap();
.unwrap()?;

self.notify_state_changed(State::Started);

Expand Down

0 comments on commit f04a50e

Please sign in to comment.