Replace assert in WASAPI WAVEFORMTEX supported format check with bubbled error message.
For our use case, this stops a crash that pops up for some users who encounter this path and allows us to gracefully just not play audio and log a message elsewhere.
when main(or other) thread(s) try to drop the Stream object, they would panic at host/wasapi/stream.rs Stream::drop() if the wasapi thread is dead. this occurs when the user wants to do something after all the cpal objects have been dropped.
* add timeout paramter to DeviceTrait stream builders
This makes it possible for the library client to handle situations where the host
takes too long to respond or even blocks forever, eg. a retry can be applied.
if the timeout passed is "None" the current behaviour is applied, eg. blocking forever.
if the timeout passed is a Duration then it will be applied to the Device Streams.
This is only implemented for ALSA, the other hosts will ignore the parameter for now.
Signed-off-by: Marc Bodmer <marc.bodmer@securiton.ch>
* Create AudioObjectPropertyListener type, providing an easy way to attach a Rust callback.
* Refactor the existing sample rate update mechanism to use AudioObjectPropertyListener.
* Add an optional property listener that registers a callback that is triggered on device disconnection.
* Create a set_on_disconnect method to register the disconnection callback.
I migrated to `windows-rs` in this PR since exposing the buffer size range for hardware-offloaded audio processing requires `IAudioClient2`, which isn't exposed in the `winapi` crate, and `winapi` seems to be more or less unmaintained at this point.
* Basic type conversion
* Make everything compile!
* Fix warnings
* Implement buffer sizing for wasapi
* Convert tabs to spaces
* Run cargo fmt
* Remove winapi from Cargo.toml
* Remove unused commented code from wasapi, and fix lingering TODOs
* Fix compile error
* Update to windows 0.37.0
* Run rustfmt
* Work around rustfmt nested tuple issues
* Improve readability of guid comparison code
In most cases, device with index 0 is NOT the default output device - in my case it happens to be the ear speaker. Returning Device(None) there makes Oboe choose the default input/output device - everything works as expected.
`ndk-glue` suffers one fatal flaw: it's "only" supposed to be used by
the crate providing `fn main()` and only supposed to end up in the
dependency graph once as it has `static` globals which get duplicated
across versions.
In the current case with `winit 0.26` still on `ndk-glue 0.5` but
`cpal` on `ndk-glue 0.6` it'll always panic in `fn native_activity()` as
the `static` globals on this version is not initialized.
Introducing `ndk-context`: a crate that holds these `static`s, with the
intention/premise to not see a breaking release /ever/ and make this a
problem of the past. The crate is currently initialized with the VM and
Android Context on `ndk-glue` 0.5.1 and 0.6.1 (0.4.1 pending) making it
compatible with whatever is current, and the possibility for backporting
to older `ndk-glue` versions too.
See also:
https://github.com/rust-windowing/android-ndk-rs/issues/211https://github.com/rust-windowing/android-ndk-rs/pull/223
COM can prevent undefined behavior in either concurrency model by
performing marshaling when necessary. As a result, CoInitializeEx can be
called with either concurrency model, and in this case STA provides better
compatibility with other code requiring STA, e.g. ASIO backend or winit
drag-and-drop.
To dive into the detail, the entry point of WASAPI, MMDeviceEnumerator, is
registered with "both" threading model, which means that COM objects are
created with whatever the thread's concurrency model is set to. This raises
the concern that when STA is used, marshaling might make audio buffer
operations block on the main thread, breaking continuous audio processing.
However, the implementation actually uses free-threaded marshaller for
interfaces dealing with buffer operations, which effectively bypasses COM's
compatibility marshaling behavior and perform any API calls on the caller's
thread instead. Therefore, the interfaces would operate just fine on either
concurrency model.
For more details on COM's threading model, see [1].
[1] https://thrysoee.dk/InsideCOM+/ch04d.htm
Co-Authored-By: Henrik Rydgård <hrydgard@gmail.com>
Close#59Close#348Close#504Close#530Close#538Close#572
* Always set period before setting buffer size, even if
`BufferSize::Fixed`.
* Set `start_threshold` based on `alsa::Direction` to avoid underruns on
playback streams.
Also refactor the return values of the set params functions to reflect their
actual use and resolve some clippy warnings (including a logic error in
`stream_timestamp()`).
With rust-jack 0.7, the buffer_size callback is moved to
ProcessHandler. This reflects how it is actually called by jack:
it is called synchronously on the process thread, but it is allowed to
perform non-real-time-safe operations. In CPAL, this means that
it is fine to reallocate the temporary interlacing buffers when buffer
size changes.
This removes the need for buffer splitting on the output stream type,
and prevents panics when buffer size is made larger than initially on
the input stream type. (for some reason, buffer splitting was not
implemented for input previously)
This was introduced in 6b91485 and could cause issues with some alsa
configurations like that of pipewire-alsa which caused the audio to be
become weirdly distorted