From 24f00238a77021bea392e0a91c2125ff6e5d7430 Mon Sep 17 00:00:00 2001 From: Mike Welsh Date: Mon, 11 Apr 2022 12:35:31 -0700 Subject: [PATCH] audio: Fix symphonia feature This feature stopped building with the bump to symphonia 0.5, which added a `Sync` bound to its traits. * Add `Sync` bounds to our own internal audio traits to match. * nellymoser::Decoder was also tweaked to add a Sync bound. * Lock the nellymoser dependency to a specific git commit. --- Cargo.lock | 17 +++++------ core/Cargo.toml | 2 +- core/src/backend/audio/decoders.rs | 12 ++++---- core/src/backend/audio/decoders/adpcm.rs | 4 +-- core/src/backend/audio/decoders/mp3.rs | 10 +++---- core/src/backend/audio/decoders/nellymoser.rs | 4 +-- core/src/backend/audio/decoders/pcm.rs | 4 +-- core/src/backend/audio/mixer.rs | 28 +++++++++---------- 8 files changed, 41 insertions(+), 40 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b6c1397bc..1c2383614 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2290,10 +2290,11 @@ dependencies = [ [[package]] name = "nellymoser-rs" -version = "0.1.0" -source = "git+https://github.com/ruffle-rs/nellymoser#77000f763b58021295429ca5740e3dc3b5228cbd" +version = "0.1.2" +source = "git+https://github.com/ruffle-rs/nellymoser?rev=4a33521c29a918950df8ae9fe07e527ac65553f5#4a33521c29a918950df8ae9fe07e527ac65553f5" dependencies = [ "bitstream-io", + "once_cell", "rustdct", ] @@ -2389,9 +2390,9 @@ dependencies = [ [[package]] name = "num-complex" -version = "0.3.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "747d632c0c558b87dbabbe6a82f3b4ae03720d0646ac5b7b4dae89394be5f2c5" +checksum = "26873667bbbb7c5182d4a37c1add32cdf09f841af72da53318fdb81543c15085" dependencies = [ "num-traits", ] @@ -3197,18 +3198,18 @@ dependencies = [ [[package]] name = "rustdct" -version = "0.6.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fadcb505b98aa64da1dadb1498b912e3642aae4606623cb3ae952cd8da33f80d" +checksum = "620247053ace0eddd3e607c66423537e45c3ae36008e6d6fac1552f51ea1a63a" dependencies = [ "rustfft", ] [[package]] name = "rustfft" -version = "5.1.1" +version = "6.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1869bb2a6ff77380d52ff4bc631f165637035a55855c76aa462c85474dadc42f" +checksum = "b1d089e5c57521629a59f5f39bca7434849ff89bd6873b521afe389c1c602543" dependencies = [ "num-complex", "num-integer", diff --git a/core/Cargo.toml b/core/Cargo.toml index 8ce4f0a55..686b86d64 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -38,7 +38,7 @@ encoding_rs = "0.8.31" rand = { version = "0.8.5", features = ["std", "small_rng"], default-features = false } serde = { version = "1.0.136", features = ["derive"] } serde_json = { version = "1.0", features = ["preserve_order"] } -nellymoser-rs = { git = "https://github.com/ruffle-rs/nellymoser" } +nellymoser-rs = { git = "https://github.com/ruffle-rs/nellymoser", rev = "4a33521c29a918950df8ae9fe07e527ac65553f5" } h263-rs = { git = "https://github.com/ruffle-rs/h263-rs", rev = "023e14c73e565c4c778d41f66cfbac5ece6419b2", optional = true } h263-rs-yuv = { git = "https://github.com/ruffle-rs/h263-rs", rev = "023e14c73e565c4c778d41f66cfbac5ece6419b2", optional = true } regress = "0.4" diff --git a/core/src/backend/audio/decoders.rs b/core/src/backend/audio/decoders.rs index f7c6a093b..b5c8b1d59 100644 --- a/core/src/backend/audio/decoders.rs +++ b/core/src/backend/audio/decoders.rs @@ -22,7 +22,7 @@ type Error = Box; /// An audio decoder. Can be used as an `Iterator` to return stero sample frames. /// If the sound is mono, the sample is duplicated across both channels. -pub trait Decoder: Iterator { +pub trait Decoder: Iterator + Send + Sync { /// The number of channels of this audio decoder. Always 1 or 2. fn num_channels(&self) -> u8; @@ -31,11 +31,11 @@ pub trait Decoder: Iterator { } /// Instantiate a decoder for the compression that the sound data uses. -pub fn make_decoder( +pub fn make_decoder( format: &SoundFormat, data: R, -) -> Result, Error> { - let decoder: Box = match format.compression { +) -> Result, Error> { + let decoder: Box = match format.compression { AudioCompression::UncompressedUnknownEndian => { // Cross fingers that it's little endian. log::warn!("make_decoder: PCM sound is unknown endian; assuming little endian"); @@ -74,7 +74,7 @@ pub fn make_decoder( Ok(decoder) } -impl Decoder for Box { +impl Decoder for Box { #[inline] fn num_channels(&self) -> u8 { self.as_ref().num_channels() @@ -100,7 +100,7 @@ pub trait StreamDecoder: Decoder {} /// and feeds it to the decoder. struct StandardStreamDecoder { /// The underlying decoder. The decoder will get its data from a `StreamTagReader`. - decoder: Box, + decoder: Box, } impl StandardStreamDecoder { diff --git a/core/src/backend/audio/decoders/adpcm.rs b/core/src/backend/audio/decoders/adpcm.rs index af6d8313b..c6cf90d7d 100644 --- a/core/src/backend/audio/decoders/adpcm.rs +++ b/core/src/backend/audio/decoders/adpcm.rs @@ -146,7 +146,7 @@ impl Iterator for AdpcmDecoder { } } -impl Decoder for AdpcmDecoder { +impl Decoder for AdpcmDecoder { #[inline] fn num_channels(&self) -> u8 { self.channels.len() as u8 @@ -158,7 +158,7 @@ impl Decoder for AdpcmDecoder { } } -impl + Default> SeekableDecoder for AdpcmDecoder> { +impl + Default + Send + Sync> SeekableDecoder for AdpcmDecoder> { #[inline] fn reset(&mut self) { // TODO: This is funky. diff --git a/core/src/backend/audio/decoders/mp3.rs b/core/src/backend/audio/decoders/mp3.rs index 30952a7b0..5a90bfaf8 100644 --- a/core/src/backend/audio/decoders/mp3.rs +++ b/core/src/backend/audio/decoders/mp3.rs @@ -38,7 +38,7 @@ pub mod minimp3 { } } - impl Iterator for Mp3Decoder { + impl Iterator for Mp3Decoder { type Item = [i16; 2]; #[inline] @@ -65,7 +65,7 @@ pub mod minimp3 { } } - impl + Default> SeekableDecoder for Mp3Decoder> { + impl + Default + Send + Sync> SeekableDecoder for Mp3Decoder> { #[inline] fn reset(&mut self) { // TODO: This is funky. @@ -79,7 +79,7 @@ pub mod minimp3 { } } - impl Decoder for Mp3Decoder { + impl Decoder for Mp3Decoder { #[inline] fn num_channels(&self) -> u8 { self.num_channels @@ -121,7 +121,7 @@ pub mod symphonia { impl Mp3Decoder { const SAMPLE_BUFFER_DURATION: u64 = 4096; - pub fn new(reader: R) -> Result { + pub fn new(reader: R) -> Result { let source = Box::new(io::ReadOnlySource::new(reader)) as Box; let source = io::MediaSourceStream::new(source, Default::default()); let reader = SymphoniaMp3Reader::try_new(source, &Default::default())?; @@ -145,7 +145,7 @@ pub mod symphonia { }) } - pub fn new_seekable + Send>( + pub fn new_seekable + Send + Sync>( reader: Cursor, ) -> Result { let source = Box::new(reader) as Box; diff --git a/core/src/backend/audio/decoders/nellymoser.rs b/core/src/backend/audio/decoders/nellymoser.rs index 547c736af..aed504549 100644 --- a/core/src/backend/audio/decoders/nellymoser.rs +++ b/core/src/backend/audio/decoders/nellymoser.rs @@ -22,7 +22,7 @@ impl Iterator for NellymoserDecoder { } } -impl Decoder for NellymoserDecoder { +impl Decoder for NellymoserDecoder { #[inline] fn num_channels(&self) -> u8 { 1 @@ -34,7 +34,7 @@ impl Decoder for NellymoserDecoder { } } -impl> SeekableDecoder for NellymoserDecoder> { +impl + Send + Sync> SeekableDecoder for NellymoserDecoder> { #[inline] fn reset(&mut self) { self.decoder.reset(); diff --git a/core/src/backend/audio/decoders/pcm.rs b/core/src/backend/audio/decoders/pcm.rs index 0ecb570e6..097c345f0 100644 --- a/core/src/backend/audio/decoders/pcm.rs +++ b/core/src/backend/audio/decoders/pcm.rs @@ -47,7 +47,7 @@ impl Iterator for PcmDecoder { } } -impl Decoder for PcmDecoder { +impl Decoder for PcmDecoder { #[inline] fn num_channels(&self) -> u8 { if self.is_stereo { @@ -63,7 +63,7 @@ impl Decoder for PcmDecoder { } } -impl> SeekableDecoder for PcmDecoder> { +impl + Send + Sync> SeekableDecoder for PcmDecoder> { #[inline] fn reset(&mut self) { self.inner.set_position(0); diff --git a/core/src/backend/audio/mixer.rs b/core/src/backend/audio/mixer.rs index 718f3eaec..79fa792a7 100644 --- a/core/src/backend/audio/mixer.rs +++ b/core/src/backend/audio/mixer.rs @@ -32,7 +32,7 @@ pub struct AudioMixer { type Error = Box; /// An audio stream. -trait Stream: dasp::signal::Signal + Send { +trait Stream: dasp::signal::Signal + Send + Sync { /// The position of this stream in sample frames. /// /// For infinite streams, this will be the number of sample frames since the start of the @@ -64,7 +64,7 @@ impl DecoderStream { } } -impl Stream for DecoderStream { +impl Stream for DecoderStream { #[inline] fn source_position(&self) -> u32 { self.position @@ -76,7 +76,7 @@ impl Stream for DecoderStream { } } -impl dasp::signal::Signal for DecoderStream { +impl dasp::signal::Signal for DecoderStream { type Frame = [i16; 2]; #[inline] @@ -191,8 +191,8 @@ impl AudioMixer { fn make_seekable_decoder( format: &swf::SoundFormat, data: Cursor, - ) -> Result, Error> { - let decoder: Box = match format.compression { + ) -> Result, Error> { + let decoder: Box = match format.compression { AudioCompression::Uncompressed => Box::new(PcmDecoder::new( data, format.is_stereo, @@ -273,7 +273,7 @@ impl AudioMixer { /// /// This is used for cases where there is no custom envelope or looping on the sound instance. /// Otherwise, `AudioMixer::make_stream_from_event_sound` should be used. - fn make_stream_from_simple_event_sound( + fn make_stream_from_simple_event_sound( &self, format: &swf::SoundFormat, data_stream: R, @@ -548,7 +548,7 @@ impl Default for ArcAsRef { /// A stream for event sound instances with custom envelopes, start/end point, or loop settings. struct EventSoundStream { - decoder: Box, + decoder: Box, num_loops: u16, start_sample_frame: u32, end_sample_frame: Option, @@ -559,7 +559,7 @@ struct EventSoundStream { impl EventSoundStream { fn new_with_settings( - decoder: Box, + decoder: Box, settings: &swf::SoundInfo, num_sample_frames: u32, skip_sample_frames: u16, @@ -652,7 +652,7 @@ where impl Stream for ConverterStream where S: Stream, - I: dasp::interpolate::Interpolator + Send, + I: dasp::interpolate::Interpolator + Send + Sync, { #[inline] fn source_position(&self) -> u32 { @@ -668,7 +668,7 @@ where impl dasp::signal::Signal for ConverterStream where S: Stream, - I: dasp::interpolate::Interpolator + Send, + I: dasp::interpolate::Interpolator + Send + Sync, { type Frame = [i16; 2]; @@ -687,7 +687,7 @@ where struct MulAmpStream where S: Stream, - E: dasp::signal::Signal + Send, + E: dasp::signal::Signal + Send + Sync, { stream: S, envelope: E, @@ -696,7 +696,7 @@ where impl MulAmpStream where S: Stream, - E: dasp::signal::Signal + Send, + E: dasp::signal::Signal + Send + Sync, { fn new(stream: S, envelope: E) -> Self { Self { stream, envelope } @@ -706,7 +706,7 @@ where impl Stream for MulAmpStream where S: Stream, - E: dasp::signal::Signal + Send, + E: dasp::signal::Signal + Send + Sync, { #[inline] fn source_position(&self) -> u32 { @@ -722,7 +722,7 @@ where impl dasp::signal::Signal for MulAmpStream where S: Stream, - E: dasp::signal::Signal + Send, + E: dasp::signal::Signal + Send + Sync, { type Frame = [i16; 2];