diff --git a/cargo-count.dot b/cargo-count.dot new file mode 100644 index 00000000..cd5e3cc3 --- /dev/null +++ b/cargo-count.dot @@ -0,0 +1,102 @@ +digraph dependencies { + N0[label="cubeb-coreaudio",shape=diamond,color=green]; + N1[label="memchr",shape=diamond,color=green]; + N2[label="atomic",shape=diamond,color=green]; + N3[label="audio-mixer",shape=diamond,color=green]; + N4[label="bitflags",shape=diamond,color=green]; + N5[label="autocfg",shape=diamond,color=green]; + N6[label="bindgen",shape=diamond,color=green]; + N7[label="cexpr",shape=diamond,color=green]; + N8[label="cfg-if",shape=diamond,color=green]; + N9[label="clang-sys",shape=diamond,color=green]; + N10[label="lazy_static",shape=diamond,color=green]; + N11[label="peeking_take_while",shape=diamond,color=green]; + N12[label="proc-macro2",shape=diamond,color=green]; + N13[label="quote",shape=diamond,color=green]; + N14[label="regex",shape=diamond,color=green]; + N15[label="rustc-hash",shape=diamond,color=green]; + N16[label="shlex",shape=diamond,color=green]; + N17[label="byteorder",shape=diamond,color=green]; + N18[label="cc",shape=diamond,color=green]; + N19[label="nom",shape=diamond,color=green]; + N20[label="glob",shape=diamond,color=green]; + N21[label="libc",shape=diamond,color=green]; + N22[label="libloading",shape=diamond,color=green]; + N23[label="cmake",shape=diamond,color=green]; + N24[label="core-foundation-sys",shape=diamond,color=green]; + N25[label="coreaudio-sys",shape=diamond,color=green]; + N26[label="coreaudio-sys-utils",shape=diamond,color=green]; + N27[label="cubeb-backend",shape=diamond,color=green]; + N28[label="cubeb-core",shape=diamond,color=green]; + N29[label="cubeb-sys",shape=diamond,color=green]; + N30[label="aho-corasick",shape=diamond,color=green]; + N31[label="float-cmp",shape=diamond,color=green]; + N32[label="mach",shape=diamond,color=green]; + N33[label="ringbuf",shape=diamond,color=green]; + N34[label="pkg-config",shape=diamond,color=green]; + N35[label="num-traits",shape=diamond,color=green]; + N36[label="winapi",shape=diamond,color=green]; + N37[label="version_check",shape=diamond,color=green]; + N38[label="unicode-xid",shape=diamond,color=green]; + N39[label="regex-syntax",shape=diamond,color=green]; + N40[label="thread_local",shape=diamond,color=green]; + N41[label="utf8-ranges",shape=diamond,color=green]; + N42[label="ucd-util",shape=diamond,color=green]; + N43[label="winapi-i686-pc-windows-gnu",shape=diamond,color=green]; + N44[label="winapi-x86_64-pc-windows-gnu",shape=diamond,color=green]; + N0 -> N2[label="",color=orange]; + N0 -> N3[label="",color=orange]; + N0 -> N4[label="",color=orange]; + N0 -> N10[label="",color=orange]; + N0 -> N21[label="",color=orange]; + N0 -> N26[label="",color=orange]; + N0 -> N27[label="",color=orange]; + N0 -> N31[label="",color=orange]; + N0 -> N32[label="",color=orange]; + N0 -> N33[label="",color=orange]; + N3 -> N4[label="",color=orange]; + N6 -> N4[label=""]; + N6 -> N7[label=""]; + N6 -> N8[label=""]; + N6 -> N9[label=""]; + N6 -> N10[label=""]; + N6 -> N11[label=""]; + N6 -> N12[label=""]; + N6 -> N13[label=""]; + N6 -> N14[label=""]; + N6 -> N15[label=""]; + N6 -> N16[label=""]; + N7 -> N19[label=""]; + N9 -> N20[label=""]; + N9 -> N21[label=""]; + N9 -> N22[label=""]; + N12 -> N38[label=""]; + N13 -> N12[label=""]; + N14 -> N1[label=""]; + N14 -> N30[label=""]; + N14 -> N39[label=""]; + N14 -> N40[label=""]; + N14 -> N41[label=""]; + N15 -> N17[label=""]; + N19 -> N1[label=""]; + N19 -> N37[label=""]; + N22 -> N18[label=""]; + N22 -> N36[label=""]; + N23 -> N18[label=""]; + N25 -> N6[label=""]; + N26 -> N24[label="",color=orange]; + N26 -> N25[label="",color=orange]; + N27 -> N28[label="",color=orange]; + N28 -> N4[label="",color=orange]; + N28 -> N29[label="",color=orange]; + N29 -> N23[label="",color=orange]; + N29 -> N34[label="",color=orange]; + N30 -> N1[label=""]; + N31 -> N35[label="",color=orange]; + N32 -> N21[label="",color=orange]; + N35 -> N5[label="",color=orange]; + N36 -> N43[label=""]; + N36 -> N44[label=""]; + N39 -> N42[label=""]; + N40 -> N10[label=""]; +} diff --git a/rainbow-graph.png b/rainbow-graph.png new file mode 100644 index 00000000..bf891377 Binary files /dev/null and b/rainbow-graph.png differ diff --git a/src/backend/mod.rs b/src/backend/mod.rs index f3987caf..8c2a73d7 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -559,6 +559,9 @@ extern "C" fn audiounit_output_callback( .store(output_latency_frames, Ordering::SeqCst); } + let now = unsafe { mach_absolute_time() }; + stm.output_callback_tstamp.store(now, Ordering::SeqCst); + cubeb_logv!( "({:p}) output: buffers {}, size {}, channels {}, frames {}.", stm as *const AudioUnitStream, @@ -3153,6 +3156,7 @@ struct AudioUnitStream<'ctx> { current_input_latency_frames: AtomicU32, total_output_latency_frames: AtomicU32, total_input_latency_frames: AtomicU32, + output_callback_tstamp: AtomicU64, // This is true if a device change callback is currently running. switching_device: AtomicBool, core_stream_data: CoreStreamData<'ctx>, @@ -3186,6 +3190,7 @@ impl<'ctx> AudioUnitStream<'ctx> { current_input_latency_frames: AtomicU32::new(0), total_output_latency_frames: AtomicU32::new(0), total_input_latency_frames: AtomicU32::new(0), + output_callback_tstamp: AtomicU64::new(0), switching_device: AtomicBool::new(false), core_stream_data: CoreStreamData::default(), } @@ -3473,7 +3478,15 @@ impl<'ctx> StreamOps for AudioUnitStream<'ctx> { let position = if current_output_latency_frames > frames_played { 0 } else { - frames_played - current_output_latency_frames + // Interpolate here to match other cubeb backends. Only return an interpolated time + // if we've played enough frames. + const NS2S: u64 = 1_000_000_000; + let now = unsafe { mach_absolute_time() }; + let diff = now - self.output_callback_tstamp.load(Ordering::SeqCst); + let frames = (host_time_to_ns(diff) + * self.core_stream_data.output_stream_params.rate() as u64) + / NS2S; + (frames_played - current_output_latency_frames) + frames }; return Ok(position); }