diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fc3fb732..92c574498 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Changed + +- Breaking: Updated `cpal` to v0.18.2. Wherever rodio exposed a cpal error type + (`StreamError`, `BuildStreamError`, `PlayStreamError`, `DevicesError`, + `DefaultStreamConfigError`, `SupportedStreamConfigsError`) it now uses the + unified `cpal::Error`, re-exported as `CpalError` together with + `CpalErrorKind`. `rodio::DevicesError` is removed. + ## Version [0.22.2] (2026-02-22) ### Fixed diff --git a/Cargo.lock b/Cargo.lock index 0404fd09a..450fc7de6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -127,12 +127,6 @@ dependencies = [ "shlex", ] -[[package]] -name = "cesu8" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" - [[package]] name = "cfg-if" version = "1.0.4" @@ -209,9 +203,9 @@ dependencies = [ [[package]] name = "coreaudio-rs" -version = "0.14.0" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d15c3c3cee7c087938f7ad1c3098840b3ef1f1bdc7f6e496336c3b1e7a6f3914" +checksum = "7d5d7dca3ebcf65a035582c9ad4385371a9d9ee6537474d2a278f4e1e475bb58" dependencies = [ "bitflags 2.11.0", "libc", @@ -223,17 +217,20 @@ dependencies = [ [[package]] name = "cpal" -version = "0.17.3" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8942da362c0f0d895d7cac616263f2f9424edc5687364dfd1d25ef7eba506d7" +checksum = "6f02e8d0327b42d3e2e4ab2119af397344eb9fc54a34bf0ddeaa1277af8681f1" dependencies = [ "alsa", + "block2", "coreaudio-rs", "dasp_sample", + "futures-channel", + "futures-util", "jni", "js-sys", "libc", - "mach2 0.5.0", + "mach2 0.6.0", "ndk", "ndk-context", "num-derive", @@ -249,6 +246,7 @@ dependencies = [ "wasm-bindgen-futures", "web-sys", "windows", + "windows-core", ] [[package]] @@ -443,6 +441,15 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" +[[package]] +name = "futures-channel" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d" +dependencies = [ + "futures-core", +] + [[package]] name = "futures-core" version = "0.3.32" @@ -592,18 +599,32 @@ checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" [[package]] name = "jni" -version = "0.21.1" +version = "0.22.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97" +checksum = "5efd9a482cf3a427f00d6b35f14332adc7902ce91efb778580e180ff90fa3498" dependencies = [ - "cesu8", "cfg-if", "combine", - "jni-sys", + "jni-macros", + "jni-sys 0.4.1", "log", - "thiserror 1.0.69", + "simd_cesu8", + "thiserror 2.0.18", "walkdir", - "windows-sys 0.45.0", + "windows-link", +] + +[[package]] +name = "jni-macros" +version = "0.22.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a00109accc170f0bdb141fed3e393c565b6f5e072365c3bd58f5b062591560a3" +dependencies = [ + "proc-macro2", + "quote", + "rustc_version", + "simd_cesu8", + "syn", ] [[package]] @@ -612,6 +633,25 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" +[[package]] +name = "jni-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6377a88cb3910bee9b0fa88d4f42e1d2da8e79915598f65fb0c7ee14c878af2" +dependencies = [ + "jni-sys-macros", +] + +[[package]] +name = "jni-sys-macros" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38c0b942f458fe50cdac086d2f946512305e5631e720728f2a61aabcd47a6264" +dependencies = [ + "quote", + "syn", +] + [[package]] name = "js-sys" version = "0.3.85" @@ -695,12 +735,9 @@ dependencies = [ [[package]] name = "mach2" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a1b95cd5421ec55b445b5ae102f5ea0e768de1f82bd3001e11f426c269c3aea" -dependencies = [ - "libc", -] +checksum = "dae608c151f68243f2b000364e1f7b186d9c29845f7d2d85bd31b9ad77ad552b" [[package]] name = "memchr" @@ -747,7 +784,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3f42e7bbe13d351b6bead8286a43aac9534b82bd3cc43e47037f012ebfd62d4" dependencies = [ "bitflags 2.11.0", - "jni-sys", + "jni-sys 0.3.0", "log", "ndk-sys", "num_enum", @@ -766,7 +803,7 @@ version = "0.6.0+11769913" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee6cda3051665f1fb8d9e08fc35c96d5a244fb1be711a03b71118828afc9a873" dependencies = [ - "jni-sys", + "jni-sys 0.3.0", ] [[package]] @@ -881,6 +918,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13a380031deed8e99db00065c45937da434ca987c034e13b87e4441f9e4090be" dependencies = [ + "bitflags 2.11.0", "objc2", "objc2-foundation", ] @@ -1384,6 +1422,22 @@ dependencies = [ "libc", ] +[[package]] +name = "simd_cesu8" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11031e251abf8611c80f460e19dbdeb54a66db918e49c65a7065b46ac7aec520" +dependencies = [ + "rustc_version", + "simdutf8", +] + +[[package]] +name = "simdutf8" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" + [[package]] name = "slab" version = "0.4.12" @@ -2058,22 +2112,13 @@ dependencies = [ "windows-link", ] -[[package]] -name = "windows-sys" -version = "0.45.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" -dependencies = [ - "windows-targets 0.42.2", -] - [[package]] name = "windows-sys" version = "0.60.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" dependencies = [ - "windows-targets 0.53.5", + "windows-targets", ] [[package]] @@ -2085,21 +2130,6 @@ dependencies = [ "windows-link", ] -[[package]] -name = "windows-targets" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" -dependencies = [ - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", -] - [[package]] name = "windows-targets" version = "0.53.5" @@ -2107,14 +2137,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" dependencies = [ "windows-link", - "windows_aarch64_gnullvm 0.53.1", - "windows_aarch64_msvc 0.53.1", - "windows_i686_gnu 0.53.1", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", "windows_i686_gnullvm", - "windows_i686_msvc 0.53.1", - "windows_x86_64_gnu 0.53.1", - "windows_x86_64_gnullvm 0.53.1", - "windows_x86_64_msvc 0.53.1", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] [[package]] @@ -2126,36 +2156,18 @@ dependencies = [ "windows-link", ] -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" - [[package]] name = "windows_aarch64_gnullvm" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" -[[package]] -name = "windows_aarch64_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" - [[package]] name = "windows_aarch64_msvc" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" -[[package]] -name = "windows_i686_gnu" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" - [[package]] name = "windows_i686_gnu" version = "0.53.1" @@ -2168,48 +2180,24 @@ version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" -[[package]] -name = "windows_i686_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" - [[package]] name = "windows_i686_msvc" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" -[[package]] -name = "windows_x86_64_gnu" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" - [[package]] name = "windows_x86_64_gnu" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" - [[package]] name = "windows_x86_64_gnullvm" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" -[[package]] -name = "windows_x86_64_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" - [[package]] name = "windows_x86_64_msvc" version = "0.53.1" diff --git a/Cargo.toml b/Cargo.toml index 3badd73d2..88335134b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -108,7 +108,7 @@ rustdoc-args = ["--cfg", "docsrs"] cargo-args = ["-Zunstable-options"] [dependencies] -cpal = { version = "0.17", optional = true } +cpal = { version = "0.18.2", optional = true } dasp_sample = "0.11" claxon = { version = "0.4", optional = true } hound = { version = "3.5", optional = true } diff --git a/UPGRADE.md b/UPGRADE.md index d78102d07..098d0f1f9 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -6,7 +6,18 @@ The list below only contains required code changes. For a complete list of changes and new features, see [CHANGELOG.md](CHANGELOG.md). # rodio 0.22 to current github version -Nothing yet! +- cpal is updated to 0.18, which replaces its separate error types with a single + `cpal::Error` (`rodio::CpalError` in rodio). `rodio::DevicesError` is removed. + - The callback passed to `DeviceSinkBuilder::with_error_callback` now takes + `cpal::Error`. The error callback type of `SpeakersBuilder` and + `MicrophoneBuilder` is now `FnMut(cpal::Error)`. + - Instead of matching the old enum variants, check `err.kind()` + (`cpal::ErrorKind`, `rodio::CpalErrorKind` in rodio), for example + `ErrorKind::DeviceNotAvailable`. + - `BufferUnderrun` is now `ErrorKind::Xrun`. + + If you use cpal directly, see the + [cpal upgrade guide](https://github.com/RustAudio/cpal/blob/v0.18.2/UPGRADING.md). # rodio 0.21.1 to 0.22 - _Sink_ terms are replaced with _Player_ and _Stream_ terms replaced diff --git a/examples/error_callback.rs b/examples/error_callback.rs index 89db86090..25ff28683 100644 --- a/examples/error_callback.rs +++ b/examples/error_callback.rs @@ -16,11 +16,11 @@ fn main() -> Result<(), Box> { .with_error_callback(move |err| { // Filter for where err is an actionable error. if matches!( - err, - cpal::StreamError::DeviceNotAvailable | cpal::StreamError::StreamInvalidated + err.kind(), + cpal::ErrorKind::DeviceNotAvailable | cpal::ErrorKind::StreamInvalidated ) { if let Err(e) = tx.send(err) { - eprintln!("Error emitting StreamError: {e}"); + eprintln!("Error emitting stream error: {e}"); } } }) diff --git a/src/lib.rs b/src/lib.rs index 27bda4aee..e90326760 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -184,8 +184,8 @@ #[cfg(feature = "playback")] pub use cpal::{ - self, traits::DeviceTrait, Device, Devices, DevicesError, InputDevices, OutputDevices, - SupportedStreamConfig, + self, traits::DeviceTrait, Device, Devices, Error as CpalError, ErrorKind as CpalErrorKind, + InputDevices, OutputDevices, SupportedStreamConfig, }; mod common; diff --git a/src/microphone.rs b/src/microphone.rs index cc9788a71..74d0b0316 100644 --- a/src/microphone.rs +++ b/src/microphone.rs @@ -121,7 +121,7 @@ use rtrb::RingBuffer; /// Error that can occur when we can not list the input devices #[derive(Debug, thiserror::Error, Clone)] #[error("Could not list input devices")] -pub struct ListError(#[source] cpal::DevicesError); +pub struct ListError(#[source] cpal::Error); assert_error_traits! {ListError} /// An input device @@ -248,13 +248,13 @@ impl Iterator for Microphone { pub enum OpenError { /// Failed to build the input stream. #[error("Could not open microphone")] - BuildStream(#[source] cpal::BuildStreamError), + BuildStream(#[source] cpal::Error), /// This is a bug please report it #[error("This is a bug, please report it")] UnsupportedSampleFormat, /// Failed to start the input stream. #[error("Could not start the input stream")] - Play(#[source] cpal::PlayStreamError), + Play(#[source] cpal::Error), } assert_error_traits! {OpenError} @@ -262,7 +262,7 @@ impl Microphone { fn open( device: Device, config: InputConfig, - mut error_callback: impl FnMut(cpal::StreamError) + Send + 'static, + mut error_callback: impl FnMut(cpal::Error) + Send + 'static, ) -> Result { let timeout = Some(Duration::from_millis(100)); let hundred_ms_of_samples = @@ -282,7 +282,7 @@ impl Microphone { match config.sample_format { $( cpal::SampleFormat::$sample_format => device.build_input_stream::<$generic, _, _>( - &config.stream_config(), + config.stream_config(), move |data, _info| { for sample in SampleTypeConverter::<_, Sample>::new(data.into_iter().copied()) { let _skip_if_player_is_behind = tx.push(sample); diff --git a/src/microphone/builder.rs b/src/microphone/builder.rs index dd2c723a7..a698424bd 100644 --- a/src/microphone/builder.rs +++ b/src/microphone/builder.rs @@ -22,14 +22,14 @@ pub enum Error { #[error("Could not get default input configuration for input device: '{device_name}'")] DefaultInputConfig { #[source] - source: cpal::DefaultStreamConfigError, + source: cpal::Error, device_name: String, }, /// Failed to get the supported input configurations for the device. #[error("Could not get supported input configurations for input device: '{device_name}'")] InputConfigs { #[source] - source: cpal::SupportedStreamConfigsError, + source: cpal::Error, device_name: String, }, /// The requested input configuration is not supported by the device. @@ -56,9 +56,9 @@ pub struct DeviceNotSet; /// Builder for configuring and opening microphone input streams. #[must_use] -pub struct MicrophoneBuilder +pub struct MicrophoneBuilder where - E: FnMut(cpal::StreamError) + Send + Clone + 'static, + E: FnMut(cpal::Error) + Send + Clone + 'static, { device: Option<(cpal::Device, Vec)>, config: Option, @@ -70,7 +70,7 @@ where impl Debug for MicrophoneBuilder where - E: FnMut(cpal::StreamError) + Send + Clone + 'static, + E: FnMut(cpal::Error) + Send + Clone + 'static, { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("MicrophoneBuilder") @@ -100,28 +100,28 @@ impl Default for MicrophoneBuilder { } } -fn default_error_callback(err: cpal::StreamError) { +fn default_error_callback(err: cpal::Error) { #[cfg(feature = "tracing")] tracing::error!("audio stream error: {err}"); #[cfg(not(feature = "tracing"))] eprintln!("audio stream error: {err}"); } -impl MicrophoneBuilder { +impl MicrophoneBuilder { /// Creates a new microphone builder. /// /// # Example /// ```no_run /// let builder = rodio::microphone::MicrophoneBuilder::new(); /// ``` - pub fn new() -> MicrophoneBuilder { + pub fn new() -> MicrophoneBuilder { Self::default() } } impl MicrophoneBuilder where - E: FnMut(cpal::StreamError) + Send + Clone + 'static, + E: FnMut(cpal::Error) + Send + Clone + 'static, { /// Sets the input device to use. /// @@ -190,7 +190,7 @@ where impl MicrophoneBuilder where - E: FnMut(cpal::StreamError) + Send + Clone + 'static, + E: FnMut(cpal::Error) + Send + Clone + 'static, { /// Uses the device's default input configuration. /// @@ -287,7 +287,7 @@ where impl MicrophoneBuilder where - E: FnMut(cpal::StreamError) + Send + Clone + 'static, + E: FnMut(cpal::Error) + Send + Clone + 'static, { /// Sets the sample rate for input. /// @@ -509,7 +509,7 @@ where impl MicrophoneBuilder where - E: FnMut(cpal::StreamError) + Send + Clone + 'static, + E: FnMut(cpal::Error) + Send + Clone + 'static, { /// Returns the current input configuration. /// @@ -531,7 +531,7 @@ where impl MicrophoneBuilder where - E: FnMut(cpal::StreamError) + Send + Clone + 'static, + E: FnMut(cpal::Error) + Send + Clone + 'static, { /// Opens the microphone input stream. /// diff --git a/src/source/from_iter.rs b/src/source/from_iter.rs index c8c14062e..208215121 100644 --- a/src/source/from_iter.rs +++ b/src/source/from_iter.rs @@ -53,11 +53,7 @@ where } } - if let Some(src) = self.iterator.next() { - self.current_source = Some(src); - } else { - return None; - } + self.current_source = Some(self.iterator.next()?); } } diff --git a/src/speakers.rs b/src/speakers.rs index 8ef628cc6..1f7ae7500 100644 --- a/src/speakers.rs +++ b/src/speakers.rs @@ -114,7 +114,7 @@ pub use config::{BufferSize, OutputConfig}; /// Error that can occur when we can not list the output devices #[derive(Debug, thiserror::Error, Clone)] #[error("Could not list output devices")] -pub struct ListError(#[source] cpal::DevicesError); +pub struct ListError(#[source] cpal::Error); assert_error_traits! {ListError} /// An output device diff --git a/src/speakers/builder.rs b/src/speakers/builder.rs index 3745552ed..0ad891656 100644 --- a/src/speakers/builder.rs +++ b/src/speakers/builder.rs @@ -25,14 +25,14 @@ pub enum Error { #[error("Could not get default output configuration for output device: '{device_name}'")] DefaultOutputConfig { #[source] - source: cpal::DefaultStreamConfigError, + source: cpal::Error, device_name: String, }, /// Failed to get the supported output configurations for the device. #[error("Could not get supported output configurations for output device: '{device_name}'")] OutputConfigs { #[source] - source: cpal::SupportedStreamConfigsError, + source: cpal::Error, device_name: String, }, /// The requested output configuration is not supported by the device. @@ -59,9 +59,9 @@ pub struct DeviceNotSet; /// Builder for configuring and opening an OS-Sink, usually a speaker or headphone. #[must_use] -pub struct SpeakersBuilder +pub struct SpeakersBuilder where - E: FnMut(cpal::StreamError) + Send + Clone + 'static, + E: FnMut(cpal::Error) + Send + Clone + 'static, { device: Option<(cpal::Device, Vec)>, config: Option, @@ -73,7 +73,7 @@ where impl Debug for SpeakersBuilder where - E: FnMut(cpal::StreamError) + Send + Clone + 'static, + E: FnMut(cpal::Error) + Send + Clone + 'static, { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("SpeakersBuilder") @@ -102,28 +102,28 @@ impl Default for SpeakersBuilder { } } -fn default_error_callback(err: cpal::StreamError) { +fn default_error_callback(err: cpal::Error) { #[cfg(feature = "tracing")] tracing::error!("audio stream error: {err}"); #[cfg(not(feature = "tracing"))] eprintln!("audio stream error: {err}"); } -impl SpeakersBuilder { +impl SpeakersBuilder { /// Creates a new speakers builder. /// /// # Example /// ```no_run /// let builder = rodio::speakers::SpeakersBuilder::new(); /// ``` - pub fn new() -> SpeakersBuilder { + pub fn new() -> SpeakersBuilder { Self::default() } } impl SpeakersBuilder where - E: FnMut(cpal::StreamError) + Send + Clone + 'static, + E: FnMut(cpal::Error) + Send + Clone + 'static, { /// Sets the output device to use. /// @@ -190,7 +190,7 @@ where impl SpeakersBuilder where - E: FnMut(cpal::StreamError) + Send + Clone + 'static, + E: FnMut(cpal::Error) + Send + Clone + 'static, { /// Uses the device's default output configuration. /// @@ -285,7 +285,7 @@ where impl SpeakersBuilder where - E: FnMut(cpal::StreamError) + Send + Clone + 'static, + E: FnMut(cpal::Error) + Send + Clone + 'static, { /// Sets the sample rate for output. /// @@ -511,7 +511,7 @@ where impl SpeakersBuilder where - E: FnMut(cpal::StreamError) + Send + Clone + 'static, + E: FnMut(cpal::Error) + Send + Clone + 'static, { /// Returns the current output configuration. /// @@ -533,7 +533,7 @@ where impl SpeakersBuilder where - E: FnMut(cpal::StreamError) + Send + Clone + 'static, + E: FnMut(cpal::Error) + Send + Clone + 'static, { /// Opens the OS-Sink and provide a mixer for playing sources on it. /// @@ -596,7 +596,7 @@ where match config.sample_format { $( cpal::SampleFormat::$sample_format => device.build_output_stream::<$generic, _, _>( - &cpal_config2, + cpal_config2, move |data, _| { data.iter_mut().for_each(|d| { *d = source diff --git a/src/speakers/builder/buffer_duration.rs b/src/speakers/builder/buffer_duration.rs index 79bad4eff..5a862412a 100644 --- a/src/speakers/builder/buffer_duration.rs +++ b/src/speakers/builder/buffer_duration.rs @@ -12,7 +12,7 @@ use super::{ConfigIsSet, DeviceIsSet}; impl SpeakersBuilder where - E: FnMut(cpal::StreamError) + Send + Clone + 'static, + E: FnMut(cpal::Error) + Send + Clone + 'static, { /// Sets the buffer duration for the output. The buffer size is calculated /// from this and the sample rate and channel count when we build the diff --git a/src/stream.rs b/src/stream.rs index c9a4d314e..75d12674d 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -161,7 +161,7 @@ impl core::fmt::Debug for DeviceSinkBuilder { } } -fn default_error_callback(err: cpal::StreamError) { +fn default_error_callback(err: cpal::Error) { #[cfg(feature = "tracing")] tracing::error!("audio stream error: {err}"); #[cfg(not(feature = "tracing"))] @@ -174,9 +174,9 @@ fn default_error_callback(err: cpal::StreamError) { /// ///
When the DeviceSink is dropped playback will end, and the associated /// OS-Sink will be disposed
-pub struct DeviceSinkBuilder +pub struct DeviceSinkBuilder where - E: FnMut(cpal::StreamError) + Send + 'static, + E: FnMut(cpal::Error) + Send + 'static, { device: Option, config: DeviceSinkConfig, @@ -262,7 +262,7 @@ impl DeviceSinkBuilder { impl DeviceSinkBuilder where - E: FnMut(cpal::StreamError) + Send + 'static, + E: FnMut(cpal::Error) + Send + 'static, { /// Sets output audio device keeping all existing stream parameters intact. /// This method is useful if you want to set other parameters yourself. @@ -367,7 +367,7 @@ where /// Set a callback that will be called when an error occurs with the stream pub fn with_error_callback(self, callback: F) -> DeviceSinkBuilder where - F: FnMut(cpal::StreamError) + Send + 'static, + F: FnMut(cpal::Error) + Send + 'static, { DeviceSinkBuilder { device: self.device, @@ -454,21 +454,18 @@ assert_error_traits!(PlayError); /// Errors that might occur when interfacing with audio output. #[derive(Debug, thiserror::Error)] pub enum DeviceSinkError { - /// Could not start playing the sink, see [cpal::PlayStreamError] for - /// details. + /// Could not start playing the sink. #[error("Could not start playing the stream")] - PlayError(#[source] cpal::PlayStreamError), - /// Failed to get the stream config for the given device. See - /// [cpal::DefaultStreamConfigError] for details. + PlayError(#[source] cpal::Error), + /// Failed to get the stream config for the given device. #[error("Failed to get the config for the given device")] - DefaultSinkConfigError(#[source] cpal::DefaultStreamConfigError), - /// Error opening sink with OS. See [cpal::BuildStreamError] for details. + DefaultSinkConfigError(#[source] cpal::Error), + /// Error opening sink with OS. #[error("Error opening the stream with the OS")] - BuildError(#[source] cpal::BuildStreamError), - /// Could not list supported configs for the device. Maybe it - /// disconnected. For details see: [cpal::SupportedStreamConfigsError]. + BuildError(#[source] cpal::Error), + /// Could not list supported configs for the device. Maybe it disconnected. #[error("Could not list supported configs for the device. Maybe its disconnected?")] - SupportedConfigsError(#[source] cpal::SupportedStreamConfigsError), + SupportedConfigsError(#[source] cpal::Error), /// Could not find any output device #[error("Could not find any output device")] NoDevice, @@ -491,7 +488,7 @@ impl MixerDeviceSink { error_callback: E, ) -> Result where - E: FnMut(cpal::StreamError) + Send + 'static, + E: FnMut(cpal::Error) + Send + 'static, { Self::validate_config(config); let (controller, source) = mixer(config.channel_count, config.sample_rate); @@ -514,7 +511,7 @@ impl MixerDeviceSink { ) -> Result where S: Source + Send + 'static, - E: FnMut(cpal::StreamError) + Send + 'static, + E: FnMut(cpal::Error) + Send + 'static, { let cpal_config = config.into(); @@ -523,7 +520,7 @@ impl MixerDeviceSink { match config.sample_format { $( cpal::SampleFormat::$sample_format => device.build_output_stream::<$generic, _, _>( - &cpal_config, + cpal_config, move |data, _| { data.iter_mut().for_each(|d| { *d = samples