Skip to content

Commit

Permalink
DEBUG4
Browse files Browse the repository at this point in the history
  • Loading branch information
Pehrsons committed Oct 12, 2023
1 parent f043174 commit 48cfed3
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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 {
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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());
}
Expand All @@ -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());
}
Expand All @@ -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
})?;
Expand All @@ -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
Expand Down Expand Up @@ -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!(
Expand All @@ -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();
Expand Down

0 comments on commit 48cfed3

Please sign in to comment.