Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No_std support for symphonia-core #244

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Thom Chiovoloni <chiovolonit@gmail.com>
# Please keep this section sorted in ascending order.

aschey [https://github.com/aschey]
atoktoto [https://github.com/atoktoto]
BlackHoleFox [https://github.com/blackholefox]
darksv [https://github.com/darksv]
dedobbin [https://github.com/dedobbin]
Expand Down
10 changes: 7 additions & 3 deletions symphonia-bundle-flac/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ rust-version = "1.53"

[dependencies]
log = "0.4"
symphonia-core = { version = "0.5.2", path = "../symphonia-core" }
symphonia-metadata = { version = "0.5.2", path = "../symphonia-metadata" }
symphonia-utils-xiph = { version = "0.5.2", path = "../symphonia-utils-xiph" }
symphonia-core = { version = "0.5.2", path = "../symphonia-core", default-features = false }
symphonia-metadata = { version = "0.5.2", path = "../symphonia-metadata", default-features = false }
symphonia-utils-xiph = { version = "0.5.2", path = "../symphonia-utils-xiph", default-features = false }

[features]
std = ["symphonia-core/std", "symphonia-metadata/std", "symphonia-utils-xiph/std"]
default = ["std"]
9 changes: 5 additions & 4 deletions symphonia-bundle-flac/src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +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 std::convert::TryInto;
use std::num::Wrapping;
use alloc::string::String;
use core::cmp;
use core::convert::TryInto;
use core::num::Wrapping;

use symphonia_core::audio::{AsAudioBufferRef, AudioBuffer, AudioBufferRef};
use symphonia_core::audio::{Signal, SignalSpec};
Expand Down Expand Up @@ -263,7 +264,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);
Expand Down
4 changes: 2 additions & 2 deletions symphonia-bundle-flac/src/demuxer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::io::{Seek, SeekFrom};

use alloc::boxed::Box;
use alloc::vec::Vec;
use symphonia_core::support_format;

use symphonia_core::codecs::{CodecParameters, VerificationCheck, CODEC_TYPE_FLAC};
Expand Down
3 changes: 3 additions & 0 deletions symphonia-bundle-flac/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#![allow(clippy::excessive_precision)]
#![allow(clippy::identity_op)]
#![allow(clippy::manual_range_contains)]
#![no_std]

extern crate alloc;

mod decoder;
mod demuxer;
Expand Down
3 changes: 3 additions & 0 deletions symphonia-bundle-flac/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
// 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 alloc::boxed::Box;
use alloc::vec;
use alloc::vec::Vec;
use symphonia_core::checksum::Crc16Ansi;
use symphonia_core::errors::Result;
use symphonia_core::formats::Packet;
Expand Down
4 changes: 2 additions & 2 deletions symphonia-bundle-flac/src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 alloc::vec::Vec;
use core::mem;

use symphonia_core::audio::{AudioBuffer, Signal};
use symphonia_core::checksum::Md5;
Expand Down
2 changes: 0 additions & 2 deletions symphonia-bundle-mp3/src/demuxer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ use symphonia_core::probe::{Descriptor, Instantiate, QueryDescriptor};
use crate::common::{FrameHeader, MpegLayer};
use crate::header::{self, MAX_MPEG_FRAME_SIZE, MPEG_HEADER_LEN};

use std::io::{Seek, SeekFrom};

use log::{debug, info, warn};

/// MPEG1 and MPEG2 audio elementary stream reader.
Expand Down
5 changes: 3 additions & 2 deletions symphonia-bundle-mp3/src/layer3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
use std::fmt;

use symphonia_core::audio::{AudioBuffer, Signal};
use symphonia_core::errors::{decode_error, Error, Result};
use symphonia_core::errors::SymphoniaError as Error;
use symphonia_core::errors::{decode_error, Result};
use symphonia_core::io::{BitReaderLtr, BufReader, ReadBitsLtr, ReadBytes};

mod bitstream;
Expand Down Expand Up @@ -356,7 +357,7 @@ impl Layer3 {
// IO error to a decode error.
frame_data.granules[gr].channels[ch].rzero = match huffman_result {
Ok(rzero) => rzero,
Err(Error::IoError(e)) if e.kind() == std::io::ErrorKind::Other => {
Err(Error::IoError(_)) => {
return decode_error("mpa: huffman decode overrun");
}
Err(err) => return Err(err),
Expand Down
2 changes: 2 additions & 0 deletions symphonia-bundle-mp3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#![allow(clippy::identity_op)]
#![allow(clippy::manual_range_contains)]

extern crate alloc;

// Shared modules.
mod common;
mod header;
Expand Down
5 changes: 3 additions & 2 deletions symphonia-check/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ use std::process::{Command, Stdio};

use symphonia::core::audio::{AudioBufferRef, SampleBuffer};
use symphonia::core::codecs::{Decoder, DecoderOptions};
use symphonia::core::errors::{Error, Result};
use symphonia::core::errors::Result;
use symphonia::core::errors::SymphoniaError as Error;
use symphonia::core::formats::{FormatOptions, FormatReader};
use symphonia::core::io::{MediaSourceStream, ReadOnlySource};
use symphonia::core::meta::MetadataOptions;
Expand Down Expand Up @@ -396,7 +397,7 @@ fn main() {
println!();

match run_test(path, &opts, &mut res) {
Err(Error::IoError(err)) if err.kind() == std::io::ErrorKind::UnexpectedEof => (),
Err(Error::EndOfFile) => (),
Err(err) => {
eprintln!("Test interrupted by error: {}", err);
std::process::exit(2);
Expand Down
7 changes: 4 additions & 3 deletions symphonia-codec-aac/src/aac/codebooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +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 symphonia_core::errors::Result;
use symphonia_core::io::{vlc::*, ReadBitsLtr};

use lazy_static::lazy_static;
Expand Down Expand Up @@ -500,7 +501,7 @@ pub struct QuadsCodebook {

impl QuadsCodebook {
#[inline(always)]
pub fn read_quant<B: ReadBitsLtr>(&self, bs: &mut B) -> std::io::Result<(u8, u8, u8, u8)> {
pub fn read_quant<B: ReadBitsLtr>(&self, bs: &mut B) -> Result<(u8, u8, u8, u8)> {
bs.read_codebook(&self.codebook).map(|(cw, _)| AAC_QUADS[cw as usize])
}
}
Expand All @@ -522,7 +523,7 @@ pub struct PairsCodebook {

impl PairsCodebook {
#[inline(always)]
pub fn read_dequant<B: ReadBitsLtr>(&self, bs: &mut B) -> std::io::Result<(f32, f32)> {
pub fn read_dequant<B: ReadBitsLtr>(&self, bs: &mut B) -> Result<(f32, f32)> {
bs.read_codebook(&self.codebook).map(|(cw, _)| self.values[cw as usize])
}
}
Expand All @@ -543,7 +544,7 @@ pub struct EscapeCodebook {

impl EscapeCodebook {
#[inline(always)]
pub fn read_quant<B: ReadBitsLtr>(&self, bs: &mut B) -> std::io::Result<(u16, u16)> {
pub fn read_quant<B: ReadBitsLtr>(&self, bs: &mut B) -> Result<(u16, u16)> {
bs.read_codebook(&self.codebook).map(|(cw, _)| self.values[cw as usize])
}
}
Expand Down
3 changes: 1 addition & 2 deletions symphonia-codec-aac/src/adts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ use symphonia_core::io::*;
use symphonia_core::meta::{Metadata, MetadataLog};
use symphonia_core::probe::{Descriptor, Instantiate, QueryDescriptor};

use std::io::{Seek, SeekFrom};

use super::common::{map_channels, M4AType, AAC_SAMPLE_RATES, M4A_TYPES};

use log::debug;
use symphonia_core::io::Seek;

const SAMPLES_PER_AAC_PACKET: u64 = 1024;

Expand Down
2 changes: 2 additions & 0 deletions symphonia-codec-aac/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
// TODO: Remove this when refactoring AAC.
#![allow(clippy::needless_range_loop)]

extern crate alloc;

mod aac;
mod adts;
mod common;
Expand Down
2 changes: 1 addition & 1 deletion symphonia-codec-aac/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ fn invalid_channels_aac() {

let err = test_decode(file).unwrap_err();

assert!(matches!(err, errors::Error::Unsupported(_)));
assert!(matches!(err, errors::SymphoniaError::Unsupported(_)));
}
2 changes: 2 additions & 0 deletions symphonia-codec-adpcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ use symphonia_core::errors::{unsupported_error, Result};
use symphonia_core::formats::Packet;
use symphonia_core::io::ReadBytes;

extern crate alloc;

mod codec_ima;
mod codec_ms;
mod common;
Expand Down
2 changes: 2 additions & 0 deletions symphonia-codec-alac/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ use symphonia_core::formats::Packet;
use symphonia_core::io::{BitReaderLtr, BufReader, FiniteStream, ReadBitsLtr, ReadBytes};
use symphonia_core::support_codec;

extern crate alloc;

/// Supported ALAC version.
const ALAC_VERSION: u8 = 0;

Expand Down
2 changes: 1 addition & 1 deletion symphonia-codec-pcm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ rust-version = "1.53"

[dependencies]
log = "0.4"
symphonia-core = { version = "0.5.2", path = "../symphonia-core" }
symphonia-core = { version = "0.5.2", path = "../symphonia-core", default-features = false }
3 changes: 3 additions & 0 deletions symphonia-codec-pcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@

#![warn(rust_2018_idioms)]
#![forbid(unsafe_code)]
#![no_std]
// The following lints are allowed in all Symphonia crates. Please see clippy.toml for their
// justification.
#![allow(clippy::comparison_chain)]
#![allow(clippy::excessive_precision)]
#![allow(clippy::identity_op)]
#![allow(clippy::manual_range_contains)]

extern crate alloc;

use symphonia_core::support_codec;

use symphonia_core::audio::{AsAudioBufferRef, AudioBuffer, AudioBufferRef, Signal, SignalSpec};
Expand Down
7 changes: 4 additions & 3 deletions symphonia-codec-vorbis/src/floor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
use std::cmp::min;
use std::collections::HashSet;

use symphonia_core::errors::{decode_error, Error, Result};
use symphonia_core::errors::SymphoniaError as Error;
use symphonia_core::errors::{decode_error, Result};
use symphonia_core::io::{BitReaderRtl, ReadBitsRtl};

use super::codebook::VorbisCodebook;
Expand Down Expand Up @@ -92,7 +93,7 @@ macro_rules! io_try_or_ret {
// An end-of-bitstream error is classified under ErrorKind::Other. This condition
// should not be treated as an error, rather, it should return from the function
// immediately without error.
Err(ref e) if e.kind() == std::io::ErrorKind::Other => return Ok(()),
Err(Error::EndOfFile) => return Ok(()),
Err(e) => return Err(e.into()),
}
};
Expand All @@ -105,7 +106,7 @@ macro_rules! try_or_ret {
// An end-of-bitstream error is classified under ErrorKind::Other. This condition
// should not be treated as an error, rather, it should return from the function
// immediately without error.
Err(Error::IoError(ref e)) if e.kind() == std::io::ErrorKind::Other => return Ok(()),
Err(Error::EndOfFile) => return Ok(()),
Err(e) => return Err(e),
}
};
Expand Down
2 changes: 2 additions & 0 deletions symphonia-codec-vorbis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
// Disable to better express the specification.
#![allow(clippy::collapsible_else_if)]

extern crate alloc;

use symphonia_core::audio::{AsAudioBufferRef, AudioBuffer, AudioBufferRef};
use symphonia_core::audio::{Signal, SignalSpec};
use symphonia_core::codecs::{CodecDescriptor, CodecParameters, CODEC_TYPE_VORBIS};
Expand Down
6 changes: 3 additions & 3 deletions symphonia-codec-vorbis/src/residue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

use std::cmp::min;
use std::convert::TryInto;
use std::io;

use symphonia_core::errors::{decode_error, Error, Result};
use symphonia_core::errors::SymphoniaError as Error;
use symphonia_core::errors::{decode_error, Result};
use symphonia_core::io::{BitReaderRtl, ReadBitsRtl};

use super::codebook::VorbisCodebook;
Expand Down Expand Up @@ -155,7 +155,7 @@ impl Residue {
Ok(_) => (),
// An end-of-bitstream error is classified under ErrorKind::Other. This condition
// should not be treated as an error.
Err(Error::IoError(ref e)) if e.kind() == io::ErrorKind::Other => (),
Err(Error::EndOfFile) => (),
Err(e) => return Err(e),
};

Expand Down
7 changes: 5 additions & 2 deletions symphonia-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ edition = "2018"
rust-version = "1.53"

[features]
default = []
std = ["arrayvec/std"]
fft = ["rustfft"]
default = ["std", "fft"]

# SIMD support.
opt-simd-sse = ["rustfft/sse"]
Expand All @@ -28,11 +30,12 @@ opt-simd = [
]

[dependencies]
arrayvec = "0.7.1"
arrayvec = { version = "0.7.1", default-features = false }
bitflags = "1.2.1"
bytemuck = "1.7"
lazy_static = "1.4.0"
log = "0.4"
libm = { version = "0.2.8" }

[dependencies.rustfft]
version = "6.1.0"
Expand Down
12 changes: 7 additions & 5 deletions symphonia-core/src/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
//! 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 alloc::boxed::Box;
use alloc::vec;
use alloc::vec::Vec;
use core::fmt;
use core::marker::PhantomData;
use core::mem;

use arrayvec::ArrayVec;
use bitflags::bitflags;
Expand Down
2 changes: 1 addition & 1 deletion symphonia-core/src/checksum/md5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down