camilladsp icon indicating copy to clipboard operation
camilladsp copied to clipboard

Jack CpalCapture Panic

Open siraaris opened this issue 9 months ago • 12 comments

Running Camilla (next31 branch), with Jack, I am not able to get a stable startup of CamillaDSP.

Here is the startup log.

root@cardia:/home/aris/proj# camilladsp/target/debug/camilladsp config/v8-96khz.yml 2025-03-30 23:27:21.581836 INFO [camilladsp] <src/bin.rs:794> CamillaDSP version 4.0.0-draft 2025-03-30 23:27:21.581872 INFO [camilladsp] <src/bin.rs:795> Running on linux, x86_64 2025-03-30 23:27:22.198192 ERROR [camillalib::cpaldevice] <src/cpaldevice.rs:536> an error occurred on stream: A backend-specific error has occurred: xrun (buffer over or under run) 2025-03-30 23:27:22.198188 ERROR [camillalib::cpaldevice] <src/cpaldevice.rs:353> an error occurred on stream: A backend-specific error has occurred: xrun (buffer over or under run) 2025-03-30 23:27:22.198218 WARN [camillalib::cpaldevice] <src/cpaldevice.rs:334> Playback interrupted, no data available 2025-03-30 23:27:22.283558 ERROR [camillalib::cpaldevice] <src/cpaldevice.rs:536> an error occurred on stream: A backend-specific error has occurred: xrun (buffer over or under run) 2025-03-30 23:27:22.283558 ERROR [camillalib::cpaldevice] <src/cpaldevice.rs:353> an error occurred on stream: A backend-specific error has occurred: xrun (buffer over or under run) 2025-03-30 23:27:22.283657 ERROR [camillalib::cpaldevice] <src/cpaldevice.rs:353> an error occurred on stream: A backend-specific error has occurred: xrun (buffer over or under run) 2025-03-30 23:27:22.283664 ERROR [camillalib::cpaldevice] <src/cpaldevice.rs:536> an error occurred on stream: A backend-specific error has occurred: xrun (buffer over or under run) 2025-03-30 23:27:22.368949 ERROR [camillalib::cpaldevice] <src/cpaldevice.rs:536> an error occurred on stream: A backend-specific error has occurred: xrun (buffer over or under run) 2025-03-30 23:27:22.368948 ERROR [camillalib::cpaldevice] <src/cpaldevice.rs:353> an error occurred on stream: A backend-specific error has occurred: xrun (buffer over or under run) 2025-03-30 23:27:22.369030 ERROR [camillalib::cpaldevice] <src/cpaldevice.rs:536> an error occurred on stream: A backend-specific error has occurred: xrun (buffer over or under run) 2025-03-30 23:27:22.369034 ERROR [camillalib::cpaldevice] <src/cpaldevice.rs:353> an error occurred on stream: A backend-specific error has occurred: xrun (buffer over or under run) 2025-03-30 23:27:22.454240 ERROR [camillalib::cpaldevice] <src/cpaldevice.rs:536> an error occurred on stream: A backend-specific error has occurred: xrun (buffer over or under run) 2025-03-30 23:27:22.454233 ERROR [camillalib::cpaldevice] <src/cpaldevice.rs:353> an error occurred on stream: A backend-specific error has occurred: xrun (buffer over or under run) 2025-03-30 23:27:22.454320 ERROR [camillalib::cpaldevice] <src/cpaldevice.rs:536> an error occurred on stream: A backend-specific error has occurred: xrun (buffer over or under run) 2025-03-30 23:27:22.454322 ERROR [camillalib::cpaldevice] <src/cpaldevice.rs:353> an error occurred on stream: A backend-specific error has occurred: xrun (buffer over or under run) 2025-03-30 23:27:22.539575 ERROR [camillalib::cpaldevice] <src/cpaldevice.rs:353> an error occurred on stream: A backend-specific error has occurred: xrun (buffer over or under run) 2025-03-30 23:27:22.539576 ERROR [camillalib::cpaldevice] <src/cpaldevice.rs:536> an error occurred on stream: A backend-specific error has occurred: xrun (buffer over or under run) 2025-03-30 23:27:22.539686 ERROR [camillalib::cpaldevice] <src/cpaldevice.rs:353> an error occurred on stream: A backend-specific error has occurred: xrun (buffer over or under run) 2025-03-30 23:27:22.539689 ERROR [camillalib::cpaldevice] <src/cpaldevice.rs:536> an error occurred on stream: A backend-specific error has occurred: xrun (buffer over or under run) 2025-03-30 23:27:22.641067 INFO [camillalib::cpaldevice] <src/cpaldevice.rs:324> Restarting playback after buffer underrun 2025-03-30 23:27:22.696511 WARN [camillalib::cpaldevice] <src/cpaldevice.rs:334> Playback interrupted, no data available 2025-03-30 23:27:22.700993 INFO [camillalib::cpaldevice] <src/cpaldevice.rs:324> Restarting playback after buffer underrun 2025-03-30 23:27:22.756455 WARN [camillalib::cpaldevice] <src/cpaldevice.rs:334> Playback interrupted, no data available 2025-03-30 23:27:22.761152 INFO [camillalib::cpaldevice] <src/cpaldevice.rs:324> Restarting playback after buffer underrun 2025-03-30 23:27:22.880869 ERROR [camillalib::cpaldevice] <src/cpaldevice.rs:353> an error occurred on stream: A backend-specific error has occurred: xrun (buffer over or under run) 2025-03-30 23:27:22.880922 ERROR [camillalib::cpaldevice] <src/cpaldevice.rs:536> an error occurred on stream: A backend-specific error has occurred: xrun (buffer over or under run) 2025-03-30 23:27:22.934545 WARN [camillalib::cpaldevice] <src/cpaldevice.rs:334> Playback interrupted, no data available 2025-03-30 23:27:22.939870 INFO [camillalib::cpaldevice] <src/cpaldevice.rs:324> Restarting playback after buffer underrun ^C2025-03-30 23:27:22.990877 INFO [camilladsp] <src/bin.rs:1006> Shutting down 2025-03-30 23:27:23.008880 ERROR [camillalib::cpaldevice] <src/cpaldevice.rs:353> an error occurred on stream: A backend-specific error has occurred: xrun (buffer over or under run) 2025-03-30 23:27:23.008893 ERROR [camillalib::cpaldevice] <src/cpaldevice.rs:536> an error occurred on stream: A backend-specific error has occurred: xrun (buffer over or under run) 2025-03-30 23:27:23.054032 WARN [camillalib::cpaldevice] <src/cpaldevice.rs:334> Playback interrupted, no data available 2025-03-30 23:27:23.059481 INFO [camillalib::cpaldevice] <src/cpaldevice.rs:324> Restarting playback after buffer underrun

thread 'CpalCapture' panicked at /home/aris/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/crossbeam-channel-0.5.14/src/waker.rs:272:9: assertion failed: self.is_empty.load(Ordering::SeqCst) note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

thread 'CpalCapture' panicked at /home/aris/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/crossbeam-channel-0.5.14/src/waker.rs:170:9: assertion left == right failed left: 1 right: 0 stack backtrace: 0: 0x560cdf6a8189 - std::backtrace_rs::backtrace::libunwind::trace::h957dbee4cbd782c0 at /usr/src/rustc-1.85.0/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5 1: 0x560cdf6a8189 - std::backtrace_rs::backtrace::trace_unsynchronized::he911a28549105692 at /usr/src/rustc-1.85.0/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x560cdf6a8189 - std::sys::backtrace::_print_fmt::h13bda53c948a9e3a at /usr/src/rustc-1.85.0/library/std/src/sys/backtrace.rs:66:9 3: 0x560cdf6a8189 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::he621b98f63f9d3d7 at /usr/src/rustc-1.85.0/library/std/src/sys/backtrace.rs:39:26 4: 0x560cdf6b77d3 - core::fmt::rt::Argument::fmt::hae6b0c0f8268a146 at /usr/src/rustc-1.85.0/library/core/src/fmt/rt.rs:177:76 5: 0x560cdf6b77d3 - core::fmt::write::hde6dfded0b3527b3 at /usr/src/rustc-1.85.0/library/core/src/fmt/mod.rs:1440:21 6: 0x560cdf69889f - std::io::Write::write_fmt::h36296b2095d435c5 at /usr/src/rustc-1.85.0/library/std/src/io/mod.rs:1887:15 7: 0x560cdf6a7fd3 - std::sys::backtrace::BacktraceLock::print::h6afc11248184a26d at /usr/src/rustc-1.85.0/library/std/src/sys/backtrace.rs:42:9 8: 0x560cdf678555 - std::panicking::default_hook::{{closure}}::h10a0643748605a95 9: 0x560cdf678348 - std::panicking::default_hook::hd325ab9c425e39f5 at /usr/src/rustc-1.85.0/library/std/src/panicking.rs:322:9 10: 0x560cdf678b2f - std::panicking::rust_panic_with_hook::h971cc6030e2a4c0c at /usr/src/rustc-1.85.0/library/std/src/panicking.rs:828:13 11: 0x560cdf6a859a - std::panicking::begin_panic_handler::{{closure}}::h2e190a4e7de13958 at /usr/src/rustc-1.85.0/library/std/src/panicking.rs:701:13 12: 0x560cdf6a83c9 - std::sys::backtrace::__rust_end_short_backtrace::hcd8ac5f0f2c9f590 at /usr/src/rustc-1.85.0/library/std/src/sys/backtrace.rs:168:18 13: 0x560cdf67869d - rust_begin_unwind at /usr/src/rustc-1.85.0/library/std/src/panicking.rs:692:5 14: 0x560cde2abc80 - core::panicking::panic_fmt::h7d0ff9f662980bad at /usr/src/rustc-1.85.0/library/core/src/panicking.rs:75:14 15: 0x560cde2ac072 - core::panicking::assert_failed_inner::h5c45ea23e132011a 16: 0x560cde2abef9 - core::panicking::assert_failed::h0b05c5c6dd681f21 at /usr/src/rustc-1.85.0/library/core/src/panicking.rs:364:5 17: 0x560cde88ac5d - <crossbeam_channel::waker::Waker as core::ops::drop::Drop>::drop::hea12ecf1bb4756c7 at /home/aris/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/crossbeam-channel-0.5.14/src/waker.rs:170:9 18: 0x560cde87dd33 - core::ptr::drop_in_place<crossbeam_channel::waker::Waker>::h09ae7a92ee736c7f at /usr/src/rustc-1.85.0/library/core/src/ptr/mod.rs:523:1 19: 0x560cde8828db - core::ptr::drop_in_place<core::cell::UnsafeCell<crossbeam_channel::waker::Waker>>::heba8f7127c8e139b at /usr/src/rustc-1.85.0/library/core/src/ptr/mod.rs:523:1 20: 0x560cde883f2f - core::ptr::drop_in_place<std::sync::poison::mutex::Mutex<crossbeam_channel::waker::Waker>>::h5ed7de61fa9b6769 at /usr/src/rustc-1.85.0/library/core/src/ptr/mod.rs:523:1 21: 0x560cde87ee53 - core::ptr::drop_in_place<crossbeam_channel::waker::SyncWaker>::hfd0aa2c0471aa93b at /usr/src/rustc-1.85.0/library/core/src/ptr/mod.rs:523:1 22: 0x560cde884c13 - core::ptr::drop_in_place<crossbeam_channel::flavors::array::Channel<alloc::vec::Vec>>::h8cb06b0bebdc1de5 at /usr/src/rustc-1.85.0/library/core/src/ptr/mod.rs:523:1 23: 0x560cde878bcb - core::ptr::drop_in_place<crossbeam_channel::counter::Counter<crossbeam_channel::flavors::array::Channel<alloc::vec::Vec>>>::h98b1429dba169976 at /usr/src/rustc-1.85.0/library/core/src/ptr/mod.rs:523:1 24: 0x560cde87a60a - core::ptr::drop_in_place<alloc::boxed::Box<crossbeam_channel::counter::Counter<crossbeam_channel::flavors::array::Channel<alloc::vec::Vec>>>>::hdb2cbe20feb8b190 at /usr/src/rustc-1.85.0/library/core/src/ptr/mod.rs:523:1 25: 0x560cde64705e - core::mem::drop::hed35cbd363dfc1ac at /usr/src/rustc-1.85.0/library/core/src/mem/mod.rs:940:24 26: 0x560cde7335b6 - crossbeam_channel::counter::Receiver<C>::release::h3f399390f7b59a2c at /home/aris/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/crossbeam-channel-0.5.14/src/counter.rs:127:17 27: 0x560cde88c101 - <crossbeam_channel::channel::Receiver<T> as core::ops::drop::Drop>::drop::h4248e5157cc1652a at /home/aris/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/crossbeam-channel-0.5.14/src/channel.rs:1154:48 28: 0x560cde883da7 - core::ptr::drop_in_place<crossbeam_channel::channel::Receiver<alloc::vec::Vec>>::h92ee7c21564b09fb at /usr/src/rustc-1.85.0/library/core/src/ptr/mod.rs:523:1 29: 0x560cdf325051 - <camillalib::cpaldevice::CpalCaptureDevice as camillalib::audiodevice::CaptureDevice>::start::{{closure}}::ha20f70d6e228368c at /home/aris/proj/camilladsp/src/cpaldevice.rs:727:21 30: 0x560cdef1c806 - std::sys::backtrace::_rust_begin_short_backtrace::hde8ac52af04c959e at /usr/src/rustc-1.85.0/library/std/src/sys/backtrace.rs:152:18 31: 0x560cde831fdc - std::thread::Builder::spawn_unchecked::{{closure}}::{{closure}}::h0b9170681064bb69 at /usr/src/rustc-1.85.0/library/std/src/thread/mod.rs:564:17 32: 0x560cdf086964 - <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::ha5fb32d5f2ccada8 at /usr/src/rustc-1.85.0/library/core/src/panic/unwind_safe.rs:272:9 33: 0x560cdf1e2528 - std::panicking::try::do_call::hd348786cda997d39 at /usr/src/rustc-1.85.0/library/std/src/panicking.rs:584:40 34: 0x560cde83495b - _rust_try 35: 0x560cde82dcca - std::panicking::try::h918f1649a470e3c0 at /usr/src/rustc-1.85.0/library/std/src/panicking.rs:547:19 36: 0x560cde82dcca - std::panic::catch_unwind::hab4df7e67f24d9dc at /usr/src/rustc-1.85.0/library/std/src/panic.rs:358:14 37: 0x560cde82dcca - std::thread::Builder::spawn_unchecked::{{closure}}::h63ef84d5c43f9755 at /usr/src/rustc-1.85.0/library/std/src/thread/mod.rs:562:30 38: 0x560cde8721cf - core::ops::function::FnOnce::call_once{{vtable.shim}}::hf3c86ed223016bf7 at /usr/src/rustc-1.85.0/library/core/src/ops/function.rs:250:5 39: 0x560cdf67917b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hda0bf2406b170e32 at /usr/src/rustc-1.85.0/library/alloc/src/boxed.rs:1993:9 40: 0x560cdf67917b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hcaed529c3b7b6a30 at /usr/src/rustc-1.85.0/library/alloc/src/boxed.rs:1993:9 41: 0x560cdf67917b - std::sys::pal::unix::thread::Thread::new::thread_start::hdd15438550d3f0ad at /usr/src/rustc-1.85.0/library/std/src/sys/pal/unix/thread.rs:106:17 42: 0x7ff080922b7b - 43: 0x7ff0809a07b8 - 44: 0x0 -

thread 'CpalCapture' panicked at library/core/src/panicking.rs:226:5: panic in a destructor during cleanup thread caused non-unwinding panic. aborting. Aborted

siraaris avatar Mar 30 '25 12:03 siraaris

I also don't think this is a Jack configuration issue - as the same Jackd startup works with another convolver (Brutefir) that I setup as a test.

siraaris avatar Mar 30 '25 12:03 siraaris

Operating system is Linux (Debian), Trixie on amd64, Jack2 server/libraries.

siraaris avatar Mar 30 '25 12:03 siraaris

The initial xrun / errors are weird also.

For completeness the Jack startup is:

jackd -dalsa -r96000 -p4096 -n2 -D -Chw:Loopback,1 -Phw:HDSPe24081377,0 -i2 -o32

The CamillaDSP configuration is:

devices:

multithreaded: true worker_threads: 8

samplerate: 96000

chunksize: 4096 target_level: 8192

capture: type: Jack device: "default" channels: 2

playback: type: Jack device: "default" channels: 32

siraaris avatar Mar 30 '25 12:03 siraaris

And the panic displays when CamillaDSP is Control-C'ed.

siraaris avatar Mar 30 '25 12:03 siraaris

That looks a bit messy. Unfortunately I'm having a bit of a challenge with supporting and maintaining all backends. Jack is the most problematic since I really don't know it well and I never use jack. There is never enough time to do everything I want so I have to prioritise, and that's why jack hasn't gotten much attention. At this point I'm more considering to drop jack (and the cpal backend) altogether than improving it. In the longer term I anyway want to drop both jack and pulseaudio, and instead add a Pipewire backend.

HEnquist avatar Mar 30 '25 18:03 HEnquist

Completely understand, and the CPAL based backends are probably used by a comparatively narrower audience group than Wasapi, Alsa and Coreaudio.

I was looking at Jack to see if it exhibited the same issue as #346.

I'm pretty sure that Jack worked on v2 CamillaDSP at some point, maybe it's an upstream issue introduced in one of the crates or libraries.

Overall, the ALSA and CoreAudio backends support small and large channel counts (greater than 8 say). It's only with Wasapi that using devices with higher channel becomes problematic and where ASIO is the only option (on Windows of course).

Without CPAL, and hence ASIO, means there won't be a pathway (or an option for a pathway) for using such devices Windows.

I've searched for a WASAPI-ASIO bridge, but the only thing I can find is proprietary from SonarWorks, as part of one of their products.

Of course, the size of the CamillaDSP audience using devices with greater than 8ch channels is likely to be also small!

siraaris avatar Mar 31 '25 10:03 siraaris

I think Pipewire has Jack support, so will probably take care of that, on Linux at least.

siraaris avatar Mar 31 '25 10:03 siraaris

I was looking at Jack to see if it exhibited the same issue as #346.

I think that issue is cause by a small mistake when merging different changes to update the asio branch.

I'm pretty sure that Jack worked on v2 CamillaDSP at some point, maybe it's an upstream issue introduced in one of the crates or libraries.

I wouldn't know, I realize that I haven't tried Jack at all since I added the support something like 4 years ago..

Overall, the ALSA and CoreAudio backends support small and large channel counts (greater than 8 say). It's only with Wasapi that using devices with higher channel becomes problematic and where ASIO is the only option (on Windows of course).

It really depends on the driver. Wasapi itself has no problem with large channel counts, but the drivers for many interfaces present them as a bunch of stereo devices. This is the case with my own Motu M4 for example, that shows up as two stereo devices, and is therefore pretty useless for CamillaDSP on Windows. Any interface using the built-in Windows usb audio driver should be ok, but those might be very rare.

Without CPAL, and hence ASIO, means there won't be a pathway (or an option for a pathway) for using such devices Windows.

After looking at this a bit I believe that ASIO via CPAL is never going to work really well. The ASIO api has quite some quirks, and it's very difficult to handle those with an abstractions layer like CPAL in between. So what is needed is a full ASIO backend that interfaces directly with the ASIO api (which unfortunately isn't likely to ever happen).

There is maybe another way. There was an announcement some time ago that Microsoft is working on an improved USB audio driver, that would support many more devices. IIRC it was supposed to become available some time later this year. This will hopefully work with many class compliant devices that require drivers from the manufacturer today, and that should not split the channels up to stereo pairs.

HEnquist avatar Mar 31 '25 20:03 HEnquist

I was looking at Jack to see if it exhibited the same issue as #346.

I think that issue is cause by a small mistake when merging different changes to update the asio branch.

Happy to test if that the case, just let me know.

Using a Wasapi Loopback device (like VAC) for Capture and Asio for Playback seems to be stable modulo the issue in #346 .

Without CPAL, and hence ASIO, means there won't be a pathway (or an option for a pathway) for using such devices Windows.

After looking at this a bit I believe that ASIO via CPAL is never going to work really well. The ASIO api has quite some quirks, and it's very difficult to handle those with an abstractions layer like CPAL in between. So what is needed is a full ASIO backend that interfaces directly with the ASIO api (which unfortunately isn't likely to ever happen).

Agree.

siraaris avatar Apr 01 '25 05:04 siraaris

dear siraaris,

jack backend with next31 branch is working without any issues.

I am using jack dummy-driver with zita to connect sound hw

good luck markus

mkafaudio avatar Apr 05 '25 20:04 mkafaudio

That's really good to hear! What Linux version are you using please?

siraaris avatar Apr 06 '25 00:04 siraaris

ubuntu(studio) 24 and jackd 1.21

mkafaudio avatar Apr 06 '25 07:04 mkafaudio