Skip to content

Commit f04a50e

Browse files
committed
Restore some state in case of reinit failure when device has changed while paused
1 parent 387e7e2 commit f04a50e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/backend/mod.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -4877,6 +4877,8 @@ impl<'ctx> Drop for AudioUnitStream<'ctx> {
48774877

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

@@ -4886,12 +4888,18 @@ impl<'ctx> StreamOps for AudioUnitStream<'ctx> {
48864888
// Need reinitialization: device was changed when paused. It will be started after
48874889
// reinit because self.stopped is false.
48884890
if self.delayed_reinit {
4889-
self.reinit().inspect_err(|_| {
4891+
let rv = self.reinit().inspect_err(|_| {
48904892
cubeb_log!(
48914893
"({:p}) delayed reinit during start failed.",
48924894
self.core_stream_data.stm_ptr
48934895
);
4894-
})?;
4896+
});
4897+
// In case of failure, restore the state
4898+
if rv.is_err() {
4899+
self.stopped.store(was_stopped, Ordering::SeqCst);
4900+
self.draining.store(was_draining, Ordering::SeqCst);
4901+
return Err(Error::error());
4902+
}
48954903
self.delayed_reinit = false;
48964904
Ok(())
48974905
} else {
@@ -4901,7 +4909,7 @@ impl<'ctx> StreamOps for AudioUnitStream<'ctx> {
49014909
})
49024910
}
49034911
})
4904-
.unwrap();
4912+
.unwrap()?;
49054913

49064914
self.notify_state_changed(State::Started);
49074915

0 commit comments

Comments
 (0)