Skip to content

Commit 555274b

Browse files
committed
Move decoder to playback crate
1 parent 255f0c6 commit 555274b

25 files changed

Lines changed: 116 additions & 111 deletions

.github/workflows/test.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ jobs:
9999
- run: cargo hack --workspace --remove-dev-deps
100100
- run: cargo build -p librespot-core --no-default-features
101101
- run: cargo build -p librespot-core
102-
- run: cargo hack build --each-feature -p librespot-audio
103102
- run: cargo build -p librespot-connect
104103
- run: cargo build -p librespot-connect --no-default-features --features with-dns-sd
105104
- run: cargo hack build --each-feature

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Removed
11+
12+
* [librespot-audio] Removed `VorbisDecoder`, `VorbisError`, `AudioPacket`, `PassthroughDecoder`, `PassthroughError`, `AudioError`, `AudioDecoder` and the `convert` module from `librespot_audio`. The underlying crates `vorbis`, `librespot-tremor`, `lewton` and `ogg` should be used directly.
13+
1014
## [0.2.0] - 2021-05-04
1115

1216
## [0.1.6] - 2021-02-22

Cargo.lock

Lines changed: 5 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ rodiojack-backend = ["librespot-playback/rodiojack-backend"]
6969
sdl-backend = ["librespot-playback/sdl-backend"]
7070
gstreamer-backend = ["librespot-playback/gstreamer-backend"]
7171

72-
with-tremor = ["librespot-audio/with-tremor"]
73-
with-vorbis = ["librespot-audio/with-vorbis"]
72+
with-tremor = ["librespot-playback/with-tremor"]
73+
with-vorbis = ["librespot-playback/with-vorbis"]
7474

7575
with-dns-sd = ["librespot-connect/with-dns-sd"]
7676

audio/Cargo.toml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,7 @@ version = "0.2.0"
1414
aes-ctr = "0.6"
1515
byteorder = "1.4"
1616
bytes = "1.0"
17-
cfg-if = "1"
18-
lewton = "0.10"
1917
log = "0.4"
2018
futures-util = { version = "0.3", default_features = false }
21-
ogg = "0.8"
2219
tempfile = "3.1"
2320
tokio = { version = "1", features = ["sync", "macros"] }
24-
zerocopy = "0.3"
25-
26-
librespot-tremor = { version = "0.2", optional = true }
27-
vorbis = { version ="0.0", optional = true }
28-
29-
[features]
30-
with-tremor = ["librespot-tremor"]
31-
with-vorbis = ["vorbis"]

audio/src/lib.rs

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,9 @@
33
#[macro_use]
44
extern crate log;
55

6-
pub mod convert;
76
mod decrypt;
87
mod fetch;
98

10-
use cfg_if::cfg_if;
11-
12-
cfg_if! {
13-
if #[cfg(any(feature = "with-tremor", feature = "with-vorbis"))] {
14-
mod libvorbis_decoder;
15-
pub use crate::libvorbis_decoder::{VorbisDecoder, VorbisError};
16-
} else {
17-
mod lewton_decoder;
18-
pub use lewton_decoder::{VorbisDecoder, VorbisError};
19-
}
20-
}
21-
22-
mod passthrough_decoder;
23-
pub use passthrough_decoder::{PassthroughDecoder, PassthroughError};
24-
259
mod range_set;
2610

2711
pub use decrypt::AudioDecrypt;
@@ -30,64 +14,3 @@ pub use fetch::{
3014
READ_AHEAD_BEFORE_PLAYBACK_ROUNDTRIPS, READ_AHEAD_BEFORE_PLAYBACK_SECONDS,
3115
READ_AHEAD_DURING_PLAYBACK_ROUNDTRIPS, READ_AHEAD_DURING_PLAYBACK_SECONDS,
3216
};
33-
use std::fmt;
34-
35-
pub enum AudioPacket {
36-
Samples(Vec<f32>),
37-
OggData(Vec<u8>),
38-
}
39-
40-
impl AudioPacket {
41-
pub fn samples(&self) -> &[f32] {
42-
match self {
43-
AudioPacket::Samples(s) => s,
44-
AudioPacket::OggData(_) => panic!("can't return OggData on samples"),
45-
}
46-
}
47-
48-
pub fn oggdata(&self) -> &[u8] {
49-
match self {
50-
AudioPacket::Samples(_) => panic!("can't return samples on OggData"),
51-
AudioPacket::OggData(d) => d,
52-
}
53-
}
54-
55-
pub fn is_empty(&self) -> bool {
56-
match self {
57-
AudioPacket::Samples(s) => s.is_empty(),
58-
AudioPacket::OggData(d) => d.is_empty(),
59-
}
60-
}
61-
}
62-
63-
#[derive(Debug)]
64-
pub enum AudioError {
65-
PassthroughError(PassthroughError),
66-
VorbisError(VorbisError),
67-
}
68-
69-
impl fmt::Display for AudioError {
70-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
71-
match self {
72-
AudioError::PassthroughError(err) => write!(f, "PassthroughError({})", err),
73-
AudioError::VorbisError(err) => write!(f, "VorbisError({})", err),
74-
}
75-
}
76-
}
77-
78-
impl From<VorbisError> for AudioError {
79-
fn from(err: VorbisError) -> AudioError {
80-
AudioError::VorbisError(err)
81-
}
82-
}
83-
84-
impl From<PassthroughError> for AudioError {
85-
fn from(err: PassthroughError) -> AudioError {
86-
AudioError::PassthroughError(err)
87-
}
88-
}
89-
90-
pub trait AudioDecoder {
91-
fn seek(&mut self, ms: i64) -> Result<(), AudioError>;
92-
fn next_packet(&mut self) -> Result<Option<AudioPacket>, AudioError>;
93-
}

playback/Cargo.toml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ path = "../metadata"
1818
version = "0.2.0"
1919

2020
[dependencies]
21+
cfg-if = "1.0"
2122
futures-executor = "0.3"
2223
futures-util = { version = "0.3", default_features = false, features = ["alloc"] }
2324
log = "0.4"
2425
byteorder = "1.4"
2526
shell-words = "1.0.0"
2627
tokio = { version = "1", features = ["sync"] }
28+
zerocopy = { version = "0.3" }
2729

2830
alsa = { version = "0.5", optional = true }
2931
portaudio-rs = { version = "0.3", optional = true }
@@ -34,13 +36,18 @@ sdl2 = { version = "0.34.3", optional = true }
3436
gstreamer = { version = "0.16", optional = true }
3537
gstreamer-app = { version = "0.16", optional = true }
3638
glib = { version = "0.10", optional = true }
37-
zerocopy = { version = "0.3" }
3839

3940
# Rodio dependencies
4041
rodio = { version = "0.13", optional = true, default-features = false }
4142
cpal = { version = "0.13", optional = true }
4243
thiserror = { version = "1", optional = true }
4344

45+
# Decoders
46+
lewton = "0.10" # Currently not optional because of limitations of cargo features
47+
librespot-tremor = { version = "0.2", optional = true }
48+
ogg = "0.8"
49+
vorbis = { version ="0.0", optional = true }
50+
4451
[features]
4552
alsa-backend = ["alsa"]
4653
portaudio-backend = ["portaudio-rs"]
@@ -50,3 +57,6 @@ rodio-backend = ["rodio", "cpal", "thiserror"]
5057
rodiojack-backend = ["rodio", "cpal/jack", "thiserror"]
5158
sdl-backend = ["sdl2"]
5259
gstreamer-backend = ["gstreamer", "gstreamer-app", "glib"]
60+
61+
with-tremor = ["librespot-tremor"]
62+
with-vorbis = ["vorbis"]

playback/src/audio_backend/alsa.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{Open, Sink, SinkAsBytes};
2-
use crate::audio::AudioPacket;
32
use crate::config::AudioFormat;
3+
use crate::decoder::AudioPacket;
44
use crate::player::{NUM_CHANNELS, SAMPLES_PER_SECOND, SAMPLE_RATE};
55
use alsa::device_name::HintIter;
66
use alsa::pcm::{Access, Format, Frames, HwParams, PCM};

playback/src/audio_backend/gstreamer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{Open, Sink, SinkAsBytes};
2-
use crate::audio::AudioPacket;
32
use crate::config::AudioFormat;
3+
use crate::decoder::AudioPacket;
44
use crate::player::{NUM_CHANNELS, SAMPLE_RATE};
55

66
use gstreamer as gst;

playback/src/audio_backend/jackaudio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{Open, Sink};
2-
use crate::audio::AudioPacket;
32
use crate::config::AudioFormat;
3+
use crate::decoder::AudioPacket;
44
use crate::player::NUM_CHANNELS;
55
use jack::{
66
AsyncClient, AudioOut, Client, ClientOptions, Control, Port, ProcessHandler, ProcessScope,

0 commit comments

Comments
 (0)