Skip to content

Commit

Permalink
Add optional Symphonia backend (#376)
Browse files Browse the repository at this point in the history
* add symphonia decoder

* add symphonia-flac

* better compile errors

* remove unsafe send

* update ci

* sudo

* disable duration check because symphonia does not support it

* add error handling

* cleanup

* update symphonia and fix breaking changes

* update to published symphonia version

* update docs

* reduce namespace duplication

* remove extra reference to current frame

* pr comments

* exclude decoders from module if unused

* fix flac test

* recommend disabling default features with symphonia
  • Loading branch information
aschey authored Jun 29, 2021
1 parent dfb4bd6 commit 0988e8c
Show file tree
Hide file tree
Showing 11 changed files with 475 additions and 61 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: install linux deps
run: |
sudo apt update
sudo apt install --no-install-recommends libasound2-dev pkg-config
sudo apt install -y --no-install-recommends libasound2-dev pkg-config
if: contains(matrix.os, 'ubuntu')

- name: install ${{ matrix.toolchain }} toolchain
Expand All @@ -55,7 +55,8 @@ jobs:
cargo fmt --all -- --check
if: matrix.toolchain == 'stable' && matrix.os == 'ubuntu-latest'
- run: cargo test --all-targets --all-features
- run: cargo test --all-targets
- run: cargo test --features=symphonia-all --all-targets
cargo-publish:
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
env:
Expand All @@ -66,7 +67,7 @@ jobs:
- name: Update apt
run: sudo apt update
- name: Install alsa
run: sudo apt install --no-install-recommends libasound2-dev pkg-config
run: sudo apt install -y --no-install-recommends libasound2-dev pkg-config
- name: Run cargo publish for rodio
continue-on-error: true
run: |
Expand Down
11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ claxon = { version = "0.4.2", optional = true }
hound = { version = "3.3.1", optional = true }
lewton = { version = "0.10", optional = true }
minimp3 = { version = "0.5.0", optional = true }
symphonia = {version = "0.3", optional = true }

[features]
default = ["flac", "vorbis", "wav", "mp3"]
Expand All @@ -24,6 +25,16 @@ vorbis = ["lewton"]
wav = ["hound"]
mp3 = ["minimp3"]
wasm-bindgen = ["cpal/wasm-bindgen"]
symphonia-aac = ["symphonia/aac"]
symphonia-all = ["symphonia-aac", "symphonia-flac", "symphonia-isomp4", "symphonia-mp3", "symphonia-wav"]
symphonia-flac = ["symphonia/flac"]
symphonia-isomp4 = ["symphonia/isomp4"]
symphonia-mp3 = ["symphonia/mp3"]
symphonia-wav = ["symphonia/wav", "symphonia/pcm"]

[dev-dependencies]
quickcheck = "0.9.2"

[[example]]
name = "music_m4a"
required-features = ["symphonia-isomp4", "symphonia-aac"]
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Rust playback library.
- WAV decoding is handled by [hound](https://github.com/ruud-v-a/hound).
- Vorbis decoding is handled by [lewton](https://github.com/est31/lewton).
- Flac decoding is handled by [claxon](https://github.com/ruuda/claxon).
- MP4 and AAC (both disabled by default) are handled by [Symphonia](https://github.com/pdeljanov/Symphonia).

Alternatively, Symphonia can be used to decode any of the other codecs above with the exception of Vorbis. See the docs for more details on backends.

# [Documentation](http://docs.rs/rodio)

Expand All @@ -28,4 +31,4 @@ at your option.

### License of your contributions

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Binary file added examples/music.m4a
Binary file not shown.
11 changes: 11 additions & 0 deletions examples/music_m4a.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use std::io::BufReader;

fn main() {
let (_stream, handle) = rodio::OutputStream::try_default().unwrap();
let sink = rodio::Sink::try_new(&handle).unwrap();

let file = std::fs::File::open("examples/music.m4a").unwrap();
sink.append(rodio::Decoder::new(BufReader::new(file)).unwrap());

sink.sleep_until_end();
}
Loading

0 comments on commit 0988e8c

Please sign in to comment.