From 48cfed3b520d76a581e1ab762799116f454e090a Mon Sep 17 00:00:00 2001 From: Andreas Pehrson Date: Thu, 12 Oct 2023 14:43:07 +0200 Subject: [PATCH] DEBUG4 --- src/backend/mod.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/backend/mod.rs b/src/backend/mod.rs index 8f0f079f..90c83774 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -437,6 +437,7 @@ extern "C" fn audiounit_input_callback( 0, ); if outframes < 0 { + println!("inputcb handler negative outframes ERROR"); stm.stopped.store(true, Ordering::SeqCst); stm.notify_state_changed(State::Error); let queue = stm.queue.clone(); @@ -666,6 +667,7 @@ extern "C" fn audiounit_output_callback( ); if outframes < 0 || outframes > i64::from(output_frames) { + println!("outputcb handler negative outframes ERROR"); stm.stopped.store(true, Ordering::SeqCst); stm.notify_state_changed(State::Error); let queue = stm.queue.clone(); @@ -736,6 +738,10 @@ extern "C" fn audiounit_property_listener_callback( let stm = unsafe { &mut *(user as *mut AudioUnitStream) }; let addrs = unsafe { slice::from_raw_parts(addresses, address_count as usize) }; if stm.switching_device.load(Ordering::SeqCst) { + println!( + "Switching is already taking place. Skipping event for device {}", + id + ); cubeb_log!( "Switching is already taking place. Skipping event for device {}", id @@ -746,6 +752,10 @@ extern "C" fn audiounit_property_listener_callback( let mut input_device_dead = false; + println!( + "({:p}) Handling {} device changed events for device {}", + stm as *const AudioUnitStream, address_count, id + ); cubeb_log!( "({:p}) Handling {} device changed events for device {}", stm as *const AudioUnitStream, @@ -754,6 +764,7 @@ extern "C" fn audiounit_property_listener_callback( ); for (i, addr) in addrs.iter().enumerate() { let p = PropertySelector::from(addr.mSelector); + println!("Event #{}: {}", i, p); cubeb_log!("Event #{}: {}", i, p); assert_ne!(p, PropertySelector::Unknown); if p == PropertySelector::DeviceIsAlive { @@ -763,6 +774,7 @@ extern "C" fn audiounit_property_listener_callback( // Handle the events if input_device_dead { + println!("The user-selected input device is dead, entering error state"); cubeb_log!("The user-selected input device is dead, entering error state"); stm.stopped.store(true, Ordering::SeqCst); stm.core_stream_data.stop_audiounits(); @@ -3513,6 +3525,7 @@ impl<'ctx> AudioUnitStream<'ctx> { } fn reinit(&mut self) -> Result<()> { + println!("reinit"); // Call stop_audiounits to avoid potential data race. If there is a running data callback, // which locks a mutex inside CoreAudio framework, then this call will block the current // thread until the callback is finished since this call asks to lock a mutex inside @@ -3524,6 +3537,7 @@ impl<'ctx> AudioUnitStream<'ctx> { debug_assert!(!self.core_stream_data.unit.is_null()); let vol_rv = get_volume(self.core_stream_data.unit); + println!("reinit close"); self.core_stream_data.close(); // Use the new default device if this stream was set to follow the output device. @@ -3537,6 +3551,7 @@ impl<'ctx> AudioUnitStream<'ctx> { self.core_stream_data.output_device = match create_device_info(kAudioObjectUnknown, DeviceType::OUTPUT) { None => { + println!("reinit failed to create output device info"); cubeb_log!("Fail to create device info for output"); return Err(Error::error()); } @@ -3555,6 +3570,7 @@ impl<'ctx> AudioUnitStream<'ctx> { self.core_stream_data.input_device = match create_device_info(kAudioObjectUnknown, DeviceType::INPUT) { None => { + println!("reinit failed to create input device info"); cubeb_log!("Fail to create device info for input"); return Err(Error::error()); } @@ -3563,6 +3579,7 @@ impl<'ctx> AudioUnitStream<'ctx> { } self.core_stream_data.setup().map_err(|e| { + println!("reinit setup fail"); cubeb_log!("({:p}) Setup failed.", self.core_stream_data.stm_ptr); e })?; @@ -3574,6 +3591,7 @@ impl<'ctx> AudioUnitStream<'ctx> { // If the stream was running, start it again. if !self.stopped.load(Ordering::SeqCst) { self.core_stream_data.start_audiounits().map_err(|e| { + println!("reinit start fail"); cubeb_log!( "({:p}) Start audiounit failed.", self.core_stream_data.stm_ptr @@ -3609,6 +3627,7 @@ impl<'ctx> AudioUnitStream<'ctx> { } if self.reinit().is_err() { + println!("reinit_async: REINIT ERROR"); self.core_stream_data.close(); self.notify_state_changed(State::Error); cubeb_log!( @@ -3627,6 +3646,7 @@ impl<'ctx> AudioUnitStream<'ctx> { // Use a different thread, through the queue, to avoid deadlock when calling // Get/SetProperties method from inside notify callback queue.run_async(move || { + println!("close_on_error: ERROR"); let stm_ptr = self as *const AudioUnitStream; self.core_stream_data.close();