From 426e9389047427c1501db0fefdcfae03b497ae59 Mon Sep 17 00:00:00 2001 From: mooman219 Date: Tue, 28 Dec 2021 21:14:31 -0800 Subject: [PATCH] 1:1 conversions --- symphonia-bundle-flac/src/decoder.rs | 6 ++--- symphonia-bundle-flac/src/lib.rs | 2 ++ symphonia-bundle-flac/src/parser.rs | 4 ++-- symphonia-bundle-flac/src/validate.rs | 4 ++-- symphonia-bundle-mp3/src/demuxer.rs | 4 ++-- .../src/layer3/hybrid_synthesis.rs | 8 +++---- symphonia-bundle-mp3/src/layer3/mod.rs | 2 +- symphonia-bundle-mp3/src/layer3/requantize.rs | 4 ++-- symphonia-bundle-mp3/src/layer3/stereo.rs | 4 ++-- symphonia-bundle-mp3/src/synthesis.rs | 2 +- symphonia-check/src/main.rs | 2 +- symphonia-codec-aac/src/aac.rs | 4 ++-- symphonia-codec-aac/src/window.rs | 2 +- symphonia-codec-alac/src/lib.rs | 2 +- symphonia-codec-vorbis/Cargo.toml | 1 + symphonia-codec-vorbis/src/codebook.rs | 4 ++-- symphonia-codec-vorbis/src/floor.rs | 6 ++--- symphonia-codec-vorbis/src/residue.rs | 2 +- symphonia-codec-vorbis/src/window.rs | 2 +- symphonia-core/Cargo.toml | 1 + symphonia-core/src/audio.rs | 10 ++++----- symphonia-core/src/checksum/md5.rs | 2 +- symphonia-core/src/codecs.rs | 6 ++--- symphonia-core/src/conv.rs | 4 ++-- symphonia-core/src/dsp/dct.rs | 4 ++-- symphonia-core/src/dsp/mdct.rs | 4 ++-- symphonia-core/src/errors.rs | 2 +- symphonia-core/src/io/bit.rs | 22 +++++++++---------- symphonia-core/src/io/buf_reader.rs | 2 +- symphonia-core/src/io/media_source_stream.rs | 8 +++---- symphonia-core/src/io/mod.rs | 6 ++--- symphonia-core/src/io/scoped_stream.rs | 6 ++--- symphonia-core/src/lib.rs | 2 ++ symphonia-core/src/meta.rs | 10 ++++----- symphonia-core/src/sample.rs | 2 +- symphonia-core/src/util.rs | 2 +- symphonia-format-isomp4/src/atoms/mdhd.rs | 2 +- symphonia-format-isomp4/src/atoms/meta.rs | 4 ++-- symphonia-format-isomp4/src/atoms/mod.rs | 2 +- symphonia-format-isomp4/src/atoms/mvhd.rs | 2 +- symphonia-format-isomp4/src/demuxer.rs | 2 +- symphonia-format-isomp4/src/fourcc.rs | 2 +- symphonia-format-isomp4/src/lib.rs | 2 ++ symphonia-format-isomp4/src/stream.rs | 2 +- symphonia-format-ogg/src/demuxer.rs | 2 +- symphonia-format-ogg/src/lib.rs | 2 ++ symphonia-format-ogg/src/logical.rs | 2 +- symphonia-format-ogg/src/physical.rs | 2 +- symphonia-format-wav/src/chunks.rs | 4 ++-- symphonia-format-wav/src/lib.rs | 2 +- symphonia-metadata/Cargo.toml | 1 + symphonia-metadata/src/id3v2/frames.rs | 12 +++++----- symphonia-metadata/src/itunes.rs | 2 +- symphonia-metadata/src/lib.rs | 2 ++ symphonia-metadata/src/riff.rs | 2 +- symphonia-metadata/src/vorbis.rs | 2 +- symphonia-play/src/output.rs | 12 +++++----- symphonia-utils-xiph/src/flac/metadata.rs | 4 ++-- 58 files changed, 120 insertions(+), 107 deletions(-) diff --git a/symphonia-bundle-flac/src/decoder.rs b/symphonia-bundle-flac/src/decoder.rs index 5651671b..237a1aec 100644 --- a/symphonia-bundle-flac/src/decoder.rs +++ b/symphonia-bundle-flac/src/decoder.rs @@ -5,8 +5,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use std::cmp; -use std::num::Wrapping; +use core::cmp; +use core::num::Wrapping; use symphonia_core::audio::{AudioBuffer, AudioBufferRef, AsAudioBufferRef}; use symphonia_core::audio::{Signal, SignalSpec}; @@ -252,7 +252,7 @@ impl Decoder for FlacDecoder { // Only generate the expected and decoded MD5 checksum strings if logging is // enabled at the debug level. if log_enabled!(log::Level::Debug) { - use std::fmt::Write; + use core::fmt::Write; let mut expected_s = String::with_capacity(32); let mut decoded_s = String::with_capacity(32); diff --git a/symphonia-bundle-flac/src/lib.rs b/symphonia-bundle-flac/src/lib.rs index 50d2472b..6cd68981 100644 --- a/symphonia-bundle-flac/src/lib.rs +++ b/symphonia-bundle-flac/src/lib.rs @@ -15,6 +15,8 @@ #![allow(clippy::identity_op)] #![allow(clippy::manual_range_contains)] +extern crate alloc; + mod decoder; mod demuxer; mod frame; diff --git a/symphonia-bundle-flac/src/parser.rs b/symphonia-bundle-flac/src/parser.rs index 68b9182f..5282cb3f 100644 --- a/symphonia-bundle-flac/src/parser.rs +++ b/symphonia-bundle-flac/src/parser.rs @@ -5,8 +5,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use std::cmp::min; -use std::collections::VecDeque; +use core::cmp::min; +use alloc::collections::VecDeque; use symphonia_core::checksum::Crc16Ansi; use symphonia_core::errors::{Result, Error}; diff --git a/symphonia-bundle-flac/src/validate.rs b/symphonia-bundle-flac/src/validate.rs index 0dfb8d64..e4522d4d 100755 --- a/symphonia-bundle-flac/src/validate.rs +++ b/symphonia-bundle-flac/src/validate.rs @@ -5,8 +5,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use std::mem; -use std::vec::Vec; +use core::mem; +use alloc::vec::Vec; use symphonia_core::audio::{AudioBuffer, Signal}; use symphonia_core::checksum::Md5; diff --git a/symphonia-bundle-mp3/src/demuxer.rs b/symphonia-bundle-mp3/src/demuxer.rs index 4aa593f3..0d69c1ad 100644 --- a/symphonia-bundle-mp3/src/demuxer.rs +++ b/symphonia-bundle-mp3/src/demuxer.rs @@ -191,7 +191,7 @@ impl FormatReader for Mp3Reader { let header = header::parse_frame_header(header::sync_frame(&mut self.reader)?)?; // Position of the frame header. - let frame_pos = self.reader.pos() - std::mem::size_of::() as u64; + let frame_pos = self.reader.pos() - core::mem::size_of::() as u64; // Calculate the duration of the frame. let duration = SAMPLES_PER_GRANULE * header.n_granules() as u64; @@ -225,7 +225,7 @@ impl FormatReader for Mp3Reader { if main_data_begin > 0 { // The maximum number of reference frames is limited to the number of frames // read and the number of previous frames recorded. - let max_ref_frames = std::cmp::min(n_frames, frames.len()); + let max_ref_frames = core::cmp::min(n_frames, frames.len()); while n_ref_frames < max_ref_frames { ref_frame = &frames[(n_frames - n_ref_frames - 1) & REF_FRAMES_MASK]; diff --git a/symphonia-bundle-mp3/src/layer3/hybrid_synthesis.rs b/symphonia-bundle-mp3/src/layer3/hybrid_synthesis.rs index fb4956a1..fbd463c7 100644 --- a/symphonia-bundle-mp3/src/layer3/hybrid_synthesis.rs +++ b/symphonia-bundle-mp3/src/layer3/hybrid_synthesis.rs @@ -8,7 +8,7 @@ // Justification: Some loops are better expressed without a range loop. #![allow(clippy::needless_range_loop)] -use std::f64; +use core::f64; use lazy_static::lazy_static; @@ -445,7 +445,7 @@ pub fn frequency_inversion(samples: &mut [f32; 576]) { mod tests { use super::IMDCT_WINDOWS; use super::imdct12_win; - use std::f64; + use core::f64; fn imdct12_analytical(x: &[f32; 6]) -> [f32; 12] { const PI_24: f64 = f64::consts::PI / 24.0; @@ -623,7 +623,7 @@ mod imdct36 { 1.931_851_652_578_136_6, // m=1 1.812_615_574_073_299_9, // m=2 1.638_304_088_577_983_6, // m=3 - std::f32::consts::SQRT_2, // m=4 + core::f32::consts::SQRT_2, // m=4 1.147_152_872_702_092_3, // m=5 0.845_236_523_481_398_9, // m=6 0.517_638_090_205_041_9, // m=7 @@ -735,7 +735,7 @@ mod imdct36 { #[cfg(test)] mod tests { use super::imdct36; - use std::f64; + use core::f64; fn imdct36_analytical(x: &[f32; 18]) -> [f32; 36] { let mut result = [0f32; 36]; diff --git a/symphonia-bundle-mp3/src/layer3/mod.rs b/symphonia-bundle-mp3/src/layer3/mod.rs index cad25be8..6e85e641 100644 --- a/symphonia-bundle-mp3/src/layer3/mod.rs +++ b/symphonia-bundle-mp3/src/layer3/mod.rs @@ -5,7 +5,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use std::fmt; +use core::fmt; use symphonia_core::audio::{AudioBuffer, Signal}; use symphonia_core::errors::{Result, decode_error, Error}; diff --git a/symphonia-bundle-mp3/src/layer3/requantize.rs b/symphonia-bundle-mp3/src/layer3/requantize.rs index fdf4bc68..52e89eda 100755 --- a/symphonia-bundle-mp3/src/layer3/requantize.rs +++ b/symphonia-bundle-mp3/src/layer3/requantize.rs @@ -5,8 +5,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use std::cmp::min; -use std::{f32, f64}; +use core::cmp::min; +use core::{f32, f64}; use symphonia_core::errors::Result; use symphonia_core::io::ReadBitsLtr; diff --git a/symphonia-bundle-mp3/src/layer3/stereo.rs b/symphonia-bundle-mp3/src/layer3/stereo.rs index 4dcd4a24..1ad011fa 100644 --- a/symphonia-bundle-mp3/src/layer3/stereo.rs +++ b/symphonia-bundle-mp3/src/layer3/stereo.rs @@ -5,8 +5,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use std::cmp::max; -use std::{f64, f32}; +use core::cmp::max; +use core::{f64, f32}; use symphonia_core::errors::{Result, decode_error}; diff --git a/symphonia-bundle-mp3/src/synthesis.rs b/symphonia-bundle-mp3/src/synthesis.rs index 20fbb16c..30fda6b5 100644 --- a/symphonia-bundle-mp3/src/synthesis.rs +++ b/symphonia-bundle-mp3/src/synthesis.rs @@ -898,7 +898,7 @@ fn dct32(x: &[f32; 32], y: &mut [f32; 32]) { #[cfg(test)] mod tests { use super::dct32; - use std::f64; + use core::f64; fn dct32_analytical(x: &[f32; 32]) -> [f32; 32] { const PI_32: f64 = f64::consts::PI / 32.0; diff --git a/symphonia-check/src/main.rs b/symphonia-check/src/main.rs index cca63a46..3f75fd62 100644 --- a/symphonia-check/src/main.rs +++ b/symphonia-check/src/main.rs @@ -217,7 +217,7 @@ fn run_check( // The number of samples that can be compared given the current state of the reference // and target sample buffers. - let n_test_samples = std::cmp::min(ref_samples.len(), tgt_samples.len()); + let n_test_samples = core::cmp::min(ref_samples.len(), tgt_samples.len()); // Perform the comparison. for (&t, &r) in tgt_samples[..n_test_samples].iter() diff --git a/symphonia-codec-aac/src/aac.rs b/symphonia-codec-aac/src/aac.rs index c4bcb4a6..c607e7c5 100644 --- a/symphonia-codec-aac/src/aac.rs +++ b/symphonia-codec-aac/src/aac.rs @@ -11,8 +11,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use std::f32::consts; -use std::fmt; +use core::f32::consts; +use core::fmt; use symphonia_core::errors::{decode_error, unsupported_error, Result}; use symphonia_core::io::{ReadBitsLtr, FiniteBitStream, BitReaderLtr}; diff --git a/symphonia-codec-aac/src/window.rs b/symphonia-codec-aac/src/window.rs index 325fe931..86b3f8c3 100644 --- a/symphonia-codec-aac/src/window.rs +++ b/symphonia-codec-aac/src/window.rs @@ -11,7 +11,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use std::f32::consts; +use core::f32::consts; /// Window types. #[derive(Debug,Clone,Copy,PartialEq)] diff --git a/symphonia-codec-alac/src/lib.rs b/symphonia-codec-alac/src/lib.rs index 38703674..dc91d24a 100644 --- a/symphonia-codec-alac/src/lib.rs +++ b/symphonia-codec-alac/src/lib.rs @@ -16,7 +16,7 @@ // Disable to better express the specification. #![allow(clippy::collapsible_else_if)] -use std::cmp::min; +use core::cmp::min; use symphonia_core::audio::{ AsAudioBufferRef, AudioBuffer, AudioBufferRef, Channels, Signal, SignalSpec, diff --git a/symphonia-codec-vorbis/Cargo.toml b/symphonia-codec-vorbis/Cargo.toml index 39417bc4..eb564faa 100644 --- a/symphonia-codec-vorbis/Cargo.toml +++ b/symphonia-codec-vorbis/Cargo.toml @@ -13,5 +13,6 @@ edition = "2018" [dependencies] log = "0.4" +hashbrown = "0.11.2" symphonia-core = { version = "0.4", path = "../symphonia-core" } symphonia-utils-xiph = { version = "0.4", path = "../symphonia-utils-xiph" } \ No newline at end of file diff --git a/symphonia-codec-vorbis/src/codebook.rs b/symphonia-codec-vorbis/src/codebook.rs index 36edcbd7..fc07d00a 100755 --- a/symphonia-codec-vorbis/src/codebook.rs +++ b/symphonia-codec-vorbis/src/codebook.rs @@ -5,7 +5,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use std::usize; +use core::usize; use symphonia_core::errors::{Result, decode_error}; use symphonia_core::io::{vlc::{BitOrder, Codebook, CodebookBuilder, Entry32x32}, ReadBitsRtl}; @@ -283,7 +283,7 @@ impl VorbisCodebook { let num = bs.read_bits_leq32(num_bits)?; - code_lens.extend(std::iter::repeat(cur_len as u8).take(num as usize)); + code_lens.extend(core::iter::repeat(cur_len as u8).take(num as usize)); cur_len += 1; cur_entry += num; diff --git a/symphonia-codec-vorbis/src/floor.rs b/symphonia-codec-vorbis/src/floor.rs index 788c1efc..e534382d 100644 --- a/symphonia-codec-vorbis/src/floor.rs +++ b/symphonia-codec-vorbis/src/floor.rs @@ -5,8 +5,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use std::cmp::min; -use std::collections::HashSet; +use core::cmp::min; +use hashbrown::HashSet; use symphonia_core::errors::{Error, Result, decode_error}; use symphonia_core::io::{ReadBitsRtl, BitReaderRtl}; @@ -286,7 +286,7 @@ impl Floor for Floor0 { &self.setup.floor0_map_long }; - let omega_step = std::f32::consts::PI / f32::from(self.setup.floor0_bark_map_size); + let omega_step = core::f32::consts::PI / f32::from(self.setup.floor0_bark_map_size); let mut i = 0; diff --git a/symphonia-codec-vorbis/src/residue.rs b/symphonia-codec-vorbis/src/residue.rs index 903d5f6c..f0985529 100644 --- a/symphonia-codec-vorbis/src/residue.rs +++ b/symphonia-codec-vorbis/src/residue.rs @@ -5,7 +5,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use std::cmp::min; +use core::cmp::min; use std::io; use symphonia_core::errors::{Error, Result, decode_error}; diff --git a/symphonia-codec-vorbis/src/window.rs b/symphonia-codec-vorbis/src/window.rs index 795e41f2..a53c2435 100644 --- a/symphonia-codec-vorbis/src/window.rs +++ b/symphonia-codec-vorbis/src/window.rs @@ -5,7 +5,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use std::f64::consts; +use core::f64::consts; /// For a given window size, generates the curve of the left-half of the window. fn generate_win_curve(bs: usize) -> Vec { diff --git a/symphonia-core/Cargo.toml b/symphonia-core/Cargo.toml index f782b039..b9b50308 100644 --- a/symphonia-core/Cargo.toml +++ b/symphonia-core/Cargo.toml @@ -17,3 +17,4 @@ bitflags = "1.2.1" bytemuck = "1.7" lazy_static = "1.4.0" log = "0.4" +hashbrown = "0.11.2" \ No newline at end of file diff --git a/symphonia-core/src/audio.rs b/symphonia-core/src/audio.rs index d613f9af..f1629675 100644 --- a/symphonia-core/src/audio.rs +++ b/symphonia-core/src/audio.rs @@ -8,11 +8,11 @@ //! The `audio` module provides primitives for working with multi-channel audio buffers of varying //! sample formats. -use std::borrow::Cow; -use std::fmt; -use std::marker::PhantomData; -use std::mem; -use std::vec::Vec; +use alloc::borrow::Cow; +use core::fmt; +use core::marker::PhantomData; +use core::mem; +use alloc::vec::Vec; use arrayvec::ArrayVec; use bitflags::bitflags; diff --git a/symphonia-core/src/checksum/md5.rs b/symphonia-core/src/checksum/md5.rs index 026ba376..6771664b 100644 --- a/symphonia-core/src/checksum/md5.rs +++ b/symphonia-core/src/checksum/md5.rs @@ -5,7 +5,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use std::cmp; +use core::cmp; use crate::io::Monitor; diff --git a/symphonia-core/src/codecs.rs b/symphonia-core/src/codecs.rs index e7e007e1..74efe0b1 100644 --- a/symphonia-core/src/codecs.rs +++ b/symphonia-core/src/codecs.rs @@ -8,9 +8,9 @@ //! The `codec` module provides the traits and support structures necessary to implement audio codec //! decoders. -use std::collections::HashMap; -use std::default::Default; -use std::fmt; +use hashbrown::HashMap; +use core::default::Default; +use core::fmt; use crate::audio::{AudioBufferRef, Channels, Layout}; use crate::errors::{Result, unsupported_error}; diff --git a/symphonia-core/src/conv.rs b/symphonia-core/src/conv.rs index fc90f836..d53a54d4 100755 --- a/symphonia-core/src/conv.rs +++ b/symphonia-core/src/conv.rs @@ -26,7 +26,7 @@ pub mod dither { //! Multiple dithering algorithms are provided, each drawing noise from a different probability //! distribution. In addition to different distributions, a dithering algorithm may also shape //! the noise such that the bulk of the noise is placed in an inaudible frequency range. - use std::marker::PhantomData; + use core::marker::PhantomData; use super::FromSample; use crate::sample::{u24, i24}; use crate::sample::Sample; @@ -638,7 +638,7 @@ where #[cfg(test)] mod tests { - use std::{u8, i8, u16, i16, u32, i32}; + use core::{u8, i8, u16, i16, u32, i32}; use crate::sample::{u24, i24, Sample}; use super::FromSample; diff --git a/symphonia-core/src/dsp/dct.rs b/symphonia-core/src/dsp/dct.rs index 9c09c6b1..214d294b 100644 --- a/symphonia-core/src/dsp/dct.rs +++ b/symphonia-core/src/dsp/dct.rs @@ -10,7 +10,7 @@ //! The (I)DCT algorithms in this module are not general purpose and are specialized for use in //! typical audio compression applications. Therefore, some constraints may apply. -use std::f64; +use core::f64; use lazy_static::lazy_static; @@ -711,7 +711,7 @@ fn dct_ii_32(x: &mut [f32]) { #[cfg(test)] mod tests { use super::*; - use std::f64; + use core::f64; fn dct_analytical(x: &[f32], y: &mut [f32]) { let n = x.len(); diff --git a/symphonia-core/src/dsp/mdct.rs b/symphonia-core/src/dsp/mdct.rs index 43b9b73a..c4f8b2f8 100644 --- a/symphonia-core/src/dsp/mdct.rs +++ b/symphonia-core/src/dsp/mdct.rs @@ -10,7 +10,7 @@ //! The (I)MDCT algorithms in this module are not general purpose and are specialized for use in //! typical audio compression applications. Therefore, some constraints may apply. -use std::f64; +use core::f64; use super::dct::Dct; @@ -134,7 +134,7 @@ impl Imdct { #[cfg(test)] mod tests { - use std::f64; + use core::f64; use super::*; fn imdct_analytical(x: &[f32], y: &mut [f32], scale: f64) { diff --git a/symphonia-core/src/errors.rs b/symphonia-core/src/errors.rs index 3a52dd9d..43d5af8a 100644 --- a/symphonia-core/src/errors.rs +++ b/symphonia-core/src/errors.rs @@ -8,7 +8,7 @@ //! The `errors` module defines the common error type. use std::error; -use std::fmt; +use core::fmt; use std::io; use std::result; diff --git a/symphonia-core/src/io/bit.rs b/symphonia-core/src/io/bit.rs index 130a27e5..344fca8e 100755 --- a/symphonia-core/src/io/bit.rs +++ b/symphonia-core/src/io/bit.rs @@ -5,7 +5,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use std::cmp::min; +use core::cmp::min; use std::io; use crate::util::bits::*; @@ -18,8 +18,8 @@ fn end_of_bitstream_error() -> io::Result { pub mod vlc { //! The `vlc` module provides support for decoding variable-length codes (VLC). - use std::cmp::max; - use std::collections::{BTreeMap, VecDeque}; + use core::cmp::max; + use alloc::collections::{BTreeMap, VecDeque}; use std::io; fn codebook_error(desc: &'static str) -> io::Result { @@ -922,7 +922,7 @@ impl<'a> BitReaderLtr<'a> { impl<'a> private::FetchBitsLtr for BitReaderLtr<'a> { fn fetch_bits_partial(&mut self) -> io::Result<()> { - let mut buf = [0u8; std::mem::size_of::()]; + let mut buf = [0u8; core::mem::size_of::()]; let read_len = min(self.buf.len(), (u64::BITS - self.n_bits_left) as usize >> 3); @@ -941,9 +941,9 @@ impl<'a> private::FetchBitsLtr for BitReaderLtr<'a> { } fn fetch_bits(&mut self) -> io::Result<()> { - let mut buf = [0u8; std::mem::size_of::()]; + let mut buf = [0u8; core::mem::size_of::()]; - let read_len = min(self.buf.len(), std::mem::size_of::()); + let read_len = min(self.buf.len(), core::mem::size_of::()); if read_len == 0 { return end_of_bitstream_error(); @@ -1391,7 +1391,7 @@ impl<'a> BitReaderRtl<'a> { impl<'a> private::FetchBitsRtl for BitReaderRtl<'a> { fn fetch_bits_partial(&mut self) -> io::Result<()> { - let mut buf = [0u8; std::mem::size_of::()]; + let mut buf = [0u8; core::mem::size_of::()]; let read_len = min(self.buf.len(), (u64::BITS - self.n_bits_left) as usize >> 3); @@ -1410,9 +1410,9 @@ impl<'a> private::FetchBitsRtl for BitReaderRtl<'a> { } fn fetch_bits(&mut self) -> io::Result<()> { - let mut buf = [0u8; std::mem::size_of::()]; + let mut buf = [0u8; core::mem::size_of::()]; - let read_len = min(self.buf.len(), std::mem::size_of::()); + let read_len = min(self.buf.len(), core::mem::size_of::()); if read_len == 0 { return end_of_bitstream_error(); @@ -1844,7 +1844,7 @@ mod tests { .map(|_| bs.read_codebook(&codebook).unwrap().0) .collect(); - assert_eq!(text, std::str::from_utf8(&decoded).unwrap()); + assert_eq!(text, core::str::from_utf8(&decoded).unwrap()); } // BitStreamRtl @@ -2160,6 +2160,6 @@ mod tests { .map(|_| bs.read_codebook(&codebook).unwrap().0) .collect(); - assert_eq!(text, std::str::from_utf8(&decoded).unwrap()); + assert_eq!(text, core::str::from_utf8(&decoded).unwrap()); } } diff --git a/symphonia-core/src/io/buf_reader.rs b/symphonia-core/src/io/buf_reader.rs index 624f834e..b79892d9 100644 --- a/symphonia-core/src/io/buf_reader.rs +++ b/symphonia-core/src/io/buf_reader.rs @@ -5,7 +5,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use std::cmp; +use core::cmp; use std::io; use super::{ReadBytes, FiniteStream}; diff --git a/symphonia-core/src/io/media_source_stream.rs b/symphonia-core/src/io/media_source_stream.rs index adfa3fa1..831db05e 100644 --- a/symphonia-core/src/io/media_source_stream.rs +++ b/symphonia-core/src/io/media_source_stream.rs @@ -5,10 +5,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use std::cmp; +use core::cmp; use std::io; use std::io::{Seek, Read, IoSliceMut}; -use std::ops::Sub; +use core::ops::Sub; use super::SeekBuffered; use super::{ReadBytes, MediaSource}; @@ -448,12 +448,12 @@ impl SeekBuffered for MediaSourceStream { // Forward seek. let delta = if pos > old_pos { - assert!(pos - old_pos < std::isize::MAX as u64); + assert!(pos - old_pos < core::isize::MAX as u64); (pos - old_pos) as isize } else if pos < old_pos { // Backward seek. - assert!(old_pos - pos < std::isize::MAX as u64); + assert!(old_pos - pos < core::isize::MAX as u64); -((old_pos - pos) as isize) } else { diff --git a/symphonia-core/src/io/mod.rs b/symphonia-core/src/io/mod.rs index 4cf8a3bd..c6902ad9 100644 --- a/symphonia-core/src/io/mod.rs +++ b/symphonia-core/src/io/mod.rs @@ -20,7 +20,7 @@ //! consume bits. use std::io; -use std::mem; +use core::mem; mod bit; mod buf_reader; @@ -74,7 +74,7 @@ impl MediaSource for std::fs::File { } } -impl + Send> MediaSource for io::Cursor { +impl + Send> MediaSource for io::Cursor { /// Always returns true since a `io::Cursor` is always seekable. fn is_seekable(&self) -> bool { true @@ -408,7 +408,7 @@ pub trait SeekBuffered { /// This function is identical to [`SeekBuffered::seek_buffered_rel`] when a negative delta is /// provided. fn seek_buffered_rev(&mut self, delta: usize) { - assert!(delta < std::isize::MAX as usize); + assert!(delta < core::isize::MAX as usize); self.seek_buffered_rel(-(delta as isize)); } } diff --git a/symphonia-core/src/io/scoped_stream.rs b/symphonia-core/src/io/scoped_stream.rs index b24ee38e..fe5ff871 100644 --- a/symphonia-core/src/io/scoped_stream.rs +++ b/symphonia-core/src/io/scoped_stream.rs @@ -5,7 +5,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use std::cmp; +use core::cmp; use std::io; use super::{FiniteStream, ReadBytes, SeekBuffered}; @@ -186,8 +186,8 @@ impl SeekBuffered for ScopedStream { fn seek_buffered_rel(&mut self, delta: isize) -> u64 { // Clamp the delta value such that the absolute position after the buffered seek will be // within the bounds of the ScopedStream. - let max_back = self.read.min(std::isize::MAX as u64) as isize; - let max_forward = (self.len - self.read).min(std::isize::MAX as u64) as isize; + let max_back = self.read.min(core::isize::MAX as u64) as isize; + let max_forward = (self.len - self.read).min(core::isize::MAX as u64) as isize; self.inner.seek_buffered_rel(delta.clamp(-max_back, max_forward)) } } \ No newline at end of file diff --git a/symphonia-core/src/lib.rs b/symphonia-core/src/lib.rs index ad76c6b4..fd60d16a 100644 --- a/symphonia-core/src/lib.rs +++ b/symphonia-core/src/lib.rs @@ -13,6 +13,8 @@ #![allow(clippy::identity_op)] #![allow(clippy::manual_range_contains)] +extern crate alloc; + pub mod audio; pub mod checksum; pub mod codecs; diff --git a/symphonia-core/src/meta.rs b/symphonia-core/src/meta.rs index 9ff629db..6d24857e 100644 --- a/symphonia-core/src/meta.rs +++ b/symphonia-core/src/meta.rs @@ -7,11 +7,11 @@ //! The `meta` module defines basic metadata elements, and management structures. -use std::borrow::Cow; -use std::collections::VecDeque; -use std::convert::From; -use std::fmt; -use std::num::NonZeroU32; +use alloc::borrow::Cow; +use alloc::collections::VecDeque; +use core::convert::From; +use core::fmt; +use core::num::NonZeroU32; use crate::errors::Result; use crate::io::MediaSourceStream; diff --git a/symphonia-core/src/sample.rs b/symphonia-core/src/sample.rs index b4566fe6..a7cf3364 100644 --- a/symphonia-core/src/sample.rs +++ b/symphonia-core/src/sample.rs @@ -7,7 +7,7 @@ //! The `sample` module defines the core audio sample trait and any non-primitive sample data types. -use std::fmt; +use core::fmt; use crate::util::clamp::{clamp_i24, clamp_u24}; diff --git a/symphonia-core/src/util.rs b/symphonia-core/src/util.rs index f3af9358..9c783d1e 100644 --- a/symphonia-core/src/util.rs +++ b/symphonia-core/src/util.rs @@ -330,7 +330,7 @@ pub mod clamp { #[cfg(test)] mod tests { - use std::{u8, i8, u16, i16, u32, i32, u64, i64}; + use core::{u8, i8, u16, i16, u32, i32, u64, i64}; use super::*; #[test] diff --git a/symphonia-format-isomp4/src/atoms/mdhd.rs b/symphonia-format-isomp4/src/atoms/mdhd.rs index 297235d2..9407c663 100644 --- a/symphonia-format-isomp4/src/atoms/mdhd.rs +++ b/symphonia-format-isomp4/src/atoms/mdhd.rs @@ -67,7 +67,7 @@ impl Atom for MdhdAtom { mdhd.timescale = reader.read_be_u32()?; // 0xffff_ffff is a special case. mdhd.duration = match reader.read_be_u32()? { - std::u32::MAX => std::u64::MAX, + core::u32::MAX => core::u64::MAX, duration => u64::from(duration), }; } diff --git a/symphonia-format-isomp4/src/atoms/meta.rs b/symphonia-format-isomp4/src/atoms/meta.rs index b29da6f7..8a71effc 100644 --- a/symphonia-format-isomp4/src/atoms/meta.rs +++ b/symphonia-format-isomp4/src/atoms/meta.rs @@ -5,7 +5,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use std::fmt::Debug; +use core::fmt::Debug; use symphonia_core::errors::Result; use symphonia_core::io::ReadBytes; @@ -22,7 +22,7 @@ pub struct MetaAtom { } impl Debug for MetaAtom { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "(redacted)") } } diff --git a/symphonia-format-isomp4/src/atoms/mod.rs b/symphonia-format-isomp4/src/atoms/mod.rs index d2e6d0f7..b16b2efa 100644 --- a/symphonia-format-isomp4/src/atoms/mod.rs +++ b/symphonia-format-isomp4/src/atoms/mod.rs @@ -453,7 +453,7 @@ impl AtomIterator { // An atom with a length of zero is defined to span to the end of the stream. If // len is available, use it for the next atom start position, otherwise, use u64 max // which will trip an end of stream error on the next iteration. - self.len.unwrap_or(std::u64::MAX) - self.next_atom_pos + self.len.unwrap_or(core::u64::MAX) - self.next_atom_pos } len => len, }; diff --git a/symphonia-format-isomp4/src/atoms/mvhd.rs b/symphonia-format-isomp4/src/atoms/mvhd.rs index e46553b5..0085cff5 100644 --- a/symphonia-format-isomp4/src/atoms/mvhd.rs +++ b/symphonia-format-isomp4/src/atoms/mvhd.rs @@ -53,7 +53,7 @@ impl Atom for MvhdAtom { mvhd.timescale = reader.read_be_u32()?; // 0xffff_ffff is a special case. mvhd.duration = match reader.read_be_u32()? { - std::u32::MAX => std::u64::MAX, + core::u32::MAX => core::u64::MAX, duration => u64::from(duration), }; } diff --git a/symphonia-format-isomp4/src/demuxer.rs b/symphonia-format-isomp4/src/demuxer.rs index c9eeb2d4..d389febc 100644 --- a/symphonia-format-isomp4/src/demuxer.rs +++ b/symphonia-format-isomp4/src/demuxer.rs @@ -17,7 +17,7 @@ use symphonia_core::probe::{Descriptor, Instantiate, QueryDescriptor}; use symphonia_core::units::Time; use std::io::{Seek, SeekFrom}; -use std::sync::Arc; +use alloc::sync::Arc; use crate::atoms::{AtomIterator, AtomType}; use crate::atoms::{FtypAtom, MoovAtom, MoofAtom, SidxAtom, TrakAtom, MetaAtom, MvexAtom}; diff --git a/symphonia-format-isomp4/src/fourcc.rs b/symphonia-format-isomp4/src/fourcc.rs index 197eac47..30970220 100644 --- a/symphonia-format-isomp4/src/fourcc.rs +++ b/symphonia-format-isomp4/src/fourcc.rs @@ -5,7 +5,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use std::fmt; +use core::fmt; /// Four character codes for typical Ftyps (reference: http://ftyps.com/). #[derive(PartialEq, Eq, Clone, Copy)] diff --git a/symphonia-format-isomp4/src/lib.rs b/symphonia-format-isomp4/src/lib.rs index e6f4559b..efeb73d3 100644 --- a/symphonia-format-isomp4/src/lib.rs +++ b/symphonia-format-isomp4/src/lib.rs @@ -14,6 +14,8 @@ #![allow(clippy::identity_op)] #![allow(clippy::manual_range_contains)] +extern crate alloc; + mod atoms; mod demuxer; mod fourcc; diff --git a/symphonia-format-isomp4/src/stream.rs b/symphonia-format-isomp4/src/stream.rs index c43ce7fc..ea1af591 100644 --- a/symphonia-format-isomp4/src/stream.rs +++ b/symphonia-format-isomp4/src/stream.rs @@ -8,7 +8,7 @@ use symphonia_core::errors::{Error, Result, decode_error}; use crate::atoms::{MoofAtom, MoovAtom, StcoAtom, Co64Atom, MvexAtom, stsz::SampleSize}; -use std::sync::Arc; +use alloc::sync::Arc; pub struct SampleDataDesc { pub base_pos: u64, diff --git a/symphonia-format-ogg/src/demuxer.rs b/symphonia-format-ogg/src/demuxer.rs index ec7af205..023899b9 100644 --- a/symphonia-format-ogg/src/demuxer.rs +++ b/symphonia-format-ogg/src/demuxer.rs @@ -5,7 +5,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use std::collections::BTreeMap; +use alloc::collections::BTreeMap; use std::io::{Seek, SeekFrom}; use symphonia_core::errors::{Error, Result, SeekErrorKind}; diff --git a/symphonia-format-ogg/src/lib.rs b/symphonia-format-ogg/src/lib.rs index 10acabba..08db6a70 100644 --- a/symphonia-format-ogg/src/lib.rs +++ b/symphonia-format-ogg/src/lib.rs @@ -15,6 +15,8 @@ #![allow(clippy::identity_op)] #![allow(clippy::manual_range_contains)] +extern crate alloc; + mod common; mod demuxer; mod logical; diff --git a/symphonia-format-ogg/src/logical.rs b/symphonia-format-ogg/src/logical.rs index fe250106..cadb680e 100644 --- a/symphonia-format-ogg/src/logical.rs +++ b/symphonia-format-ogg/src/logical.rs @@ -5,7 +5,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use std::collections::VecDeque; +use alloc::collections::VecDeque; use symphonia_core::codecs::CodecParameters; use symphonia_core::errors::{Result, decode_error}; diff --git a/symphonia-format-ogg/src/physical.rs b/symphonia-format-ogg/src/physical.rs index aecccb21..c0a9a3ec 100644 --- a/symphonia-format-ogg/src/physical.rs +++ b/symphonia-format-ogg/src/physical.rs @@ -4,7 +4,7 @@ // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use std::collections::{BTreeMap, BTreeSet}; +use alloc::collections::{BTreeMap, BTreeSet}; use std::io::{Seek, SeekFrom}; use symphonia_core::errors::Result; diff --git a/symphonia-format-wav/src/chunks.rs b/symphonia-format-wav/src/chunks.rs index cbc66000..a701c13a 100644 --- a/symphonia-format-wav/src/chunks.rs +++ b/symphonia-format-wav/src/chunks.rs @@ -5,8 +5,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use std::fmt; -use std::marker::PhantomData; +use core::fmt; +use core::marker::PhantomData; use symphonia_core::audio::Channels; use symphonia_core::codecs::{ diff --git a/symphonia-format-wav/src/lib.rs b/symphonia-format-wav/src/lib.rs index 0dc6d35e..0d046fbb 100644 --- a/symphonia-format-wav/src/lib.rs +++ b/symphonia-format-wav/src/lib.rs @@ -91,7 +91,7 @@ impl FormatReader for WavReader { // The RIFF chunk contains WAVE data. if riff_form != WAVE_RIFF_FORM { - error!("riff form is not wave ({})", std::str::from_utf8(&riff_form).unwrap()); + error!("riff form is not wave ({})", core::str::from_utf8(&riff_form).unwrap()); return unsupported_error("wav: riff form is not wave"); } diff --git a/symphonia-metadata/Cargo.toml b/symphonia-metadata/Cargo.toml index 5acae8f7..9e5aa5a0 100644 --- a/symphonia-metadata/Cargo.toml +++ b/symphonia-metadata/Cargo.toml @@ -15,4 +15,5 @@ edition = "2018" encoding_rs = "0.8.17" lazy_static = "1.4.0" log = "0.4" +hashbrown = "0.11.2" symphonia-core = { version = "0.4", path = "../symphonia-core" } \ No newline at end of file diff --git a/symphonia-metadata/src/id3v2/frames.rs b/symphonia-metadata/src/id3v2/frames.rs index 7f192376..59fe7cd8 100644 --- a/symphonia-metadata/src/id3v2/frames.rs +++ b/symphonia-metadata/src/id3v2/frames.rs @@ -4,10 +4,10 @@ // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use std::borrow::Cow; -use std::collections::HashMap; +use alloc::borrow::Cow; +use hashbrown::HashMap; use std::io; -use std::str; +use core::str; use symphonia_core::errors::{Result, unsupported_error, decode_error}; use symphonia_core::io::{ReadBytes, BufReader, FiniteStream}; @@ -438,7 +438,7 @@ pub fn read_id3v2p2_frame(reader: &mut B) -> Result { // A frame must be atleast 1 byte as per the specification. if size == 0 { - warn!("frame size of 0 for {}", std::str::from_utf8(&id).unwrap()); + warn!("frame size of 0 for {}", core::str::from_utf8(&id).unwrap()); } let data = reader.read_boxed_slice_exact(size as usize)?; @@ -503,7 +503,7 @@ pub fn read_id3v2p3_frame(reader: &mut B) -> Result { // A frame must be atleast 1 byte as per the specification. if size == 0 { - warn!("frame size of 0 for {}", std::str::from_utf8(&id).unwrap()); + warn!("frame size of 0 for {}", core::str::from_utf8(&id).unwrap()); } let data = reader.read_boxed_slice_exact(size as usize)?; @@ -576,7 +576,7 @@ pub fn read_id3v2p4_frame(reader: &mut B) -> Result // A frame must be atleast 1 byte as per the specification. if size == 0 { - warn!("frame size of 0 for {}", std::str::from_utf8(&id).unwrap()); + warn!("frame size of 0 for {}", core::str::from_utf8(&id).unwrap()); } // Read the frame body into a new buffer. This is, unfortunate. The original plan was to use an diff --git a/symphonia-metadata/src/itunes.rs b/symphonia-metadata/src/itunes.rs index 1dcac049..11aa209b 100644 --- a/symphonia-metadata/src/itunes.rs +++ b/symphonia-metadata/src/itunes.rs @@ -9,7 +9,7 @@ use symphonia_core::meta::StandardTagKey; -use std::collections::HashMap; +use hashbrown::HashMap; use lazy_static::lazy_static; diff --git a/symphonia-metadata/src/lib.rs b/symphonia-metadata/src/lib.rs index f70bdc9e..0d702132 100644 --- a/symphonia-metadata/src/lib.rs +++ b/symphonia-metadata/src/lib.rs @@ -15,6 +15,8 @@ #![allow(clippy::identity_op)] #![allow(clippy::manual_range_contains)] +extern crate alloc; + pub mod id3v1; pub mod id3v2; pub mod itunes; diff --git a/symphonia-metadata/src/riff.rs b/symphonia-metadata/src/riff.rs index f53af78c..0bffc4b2 100644 --- a/symphonia-metadata/src/riff.rs +++ b/symphonia-metadata/src/riff.rs @@ -7,7 +7,7 @@ //! A RIFF INFO metadata reader. -use std::collections::HashMap; +use hashbrown::HashMap; use lazy_static::lazy_static; use symphonia_core::meta::{StandardTagKey, Tag, Value}; diff --git a/symphonia-metadata/src/vorbis.rs b/symphonia-metadata/src/vorbis.rs index c5ce1931..e64f48e5 100644 --- a/symphonia-metadata/src/vorbis.rs +++ b/symphonia-metadata/src/vorbis.rs @@ -7,7 +7,7 @@ //! A Vorbic COMMENT metadata reader for FLAC or OGG formats. -use std::collections::HashMap; +use hashbrown::HashMap; use lazy_static::lazy_static; use symphonia_core::errors::Result; use symphonia_core::io::ReadBytes; diff --git a/symphonia-play/src/output.rs b/symphonia-play/src/output.rs index 6e91983c..cfa9707e 100644 --- a/symphonia-play/src/output.rs +++ b/symphonia-play/src/output.rs @@ -7,7 +7,7 @@ //! Platform-dependant Audio Outputs -use std::result; +use core::result; use symphonia::core::audio::{AudioBufferRef, SignalSpec}; use symphonia::core::units::Duration; @@ -66,11 +66,11 @@ mod pulseaudio { // attributes for very short audio streams. // // let pa_buf_attr = pulse::def::BufferAttr { - // maxlength: std::u32::MAX, + // maxlength: core::u32::MAX, // tlength: 1024, - // prebuf: std::u32::MAX, - // minreq: std::u32::MAX, - // fragsize: std::u32::MAX, + // prebuf: core::u32::MAX, + // minreq: core::u32::MAX, + // fragsize: core::u32::MAX, // }; // Create a PulseAudio connection. @@ -188,7 +188,7 @@ mod cpal { cpal::Sample + ConvertibleSample + RawSample + - std::marker::Send + + core::marker::Send + 'static {} impl AudioOutputSample for f32 { } diff --git a/symphonia-utils-xiph/src/flac/metadata.rs b/symphonia-utils-xiph/src/flac/metadata.rs index 74f42429..efc283c3 100644 --- a/symphonia-utils-xiph/src/flac/metadata.rs +++ b/symphonia-utils-xiph/src/flac/metadata.rs @@ -5,8 +5,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use std::ascii; -use std::num::NonZeroU32; +use core::ascii; +use core::num::NonZeroU32; use symphonia_core::audio::Channels; use symphonia_core::errors::{Result, decode_error};