Merge pull request #692 from Johannesd3/move-decoder-to-playback

Move decoder to playback crate
This commit is contained in:
Sasha Hilton 2021-05-12 00:30:02 +01:00 committed by GitHub
commit b7685e3ac2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 116 additions and 111 deletions

View file

@ -99,7 +99,6 @@ jobs:
- run: cargo hack --workspace --remove-dev-deps - run: cargo hack --workspace --remove-dev-deps
- run: cargo build -p librespot-core --no-default-features - run: cargo build -p librespot-core --no-default-features
- run: cargo build -p librespot-core - run: cargo build -p librespot-core
- run: cargo hack build --each-feature -p librespot-audio
- run: cargo build -p librespot-connect - run: cargo build -p librespot-connect
- run: cargo build -p librespot-connect --no-default-features --features with-dns-sd - run: cargo build -p librespot-connect --no-default-features --features with-dns-sd
- run: cargo hack build --each-feature - run: cargo hack build --each-feature

View file

@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Removed
* [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.
## [0.2.0] - 2021-05-04 ## [0.2.0] - 2021-05-04
## [0.1.6] - 2021-02-22 ## [0.1.6] - 2021-02-22

11
Cargo.lock generated
View file

@ -1159,17 +1159,11 @@ dependencies = [
"aes-ctr", "aes-ctr",
"byteorder", "byteorder",
"bytes", "bytes",
"cfg-if 1.0.0",
"futures-util", "futures-util",
"lewton",
"librespot-core", "librespot-core",
"librespot-tremor",
"log", "log",
"ogg",
"tempfile", "tempfile",
"tokio", "tokio",
"vorbis",
"zerocopy",
] ]
[[package]] [[package]]
@ -1257,6 +1251,7 @@ version = "0.2.0"
dependencies = [ dependencies = [
"alsa", "alsa",
"byteorder", "byteorder",
"cfg-if 1.0.0",
"cpal", "cpal",
"futures-executor", "futures-executor",
"futures-util", "futures-util",
@ -1264,18 +1259,22 @@ dependencies = [
"gstreamer", "gstreamer",
"gstreamer-app", "gstreamer-app",
"jack 0.7.0", "jack 0.7.0",
"lewton",
"libpulse-binding", "libpulse-binding",
"libpulse-simple-binding", "libpulse-simple-binding",
"librespot-audio", "librespot-audio",
"librespot-core", "librespot-core",
"librespot-metadata", "librespot-metadata",
"librespot-tremor",
"log", "log",
"ogg",
"portaudio-rs", "portaudio-rs",
"rodio", "rodio",
"sdl2", "sdl2",
"shell-words", "shell-words",
"thiserror", "thiserror",
"tokio", "tokio",
"vorbis",
"zerocopy", "zerocopy",
] ]

View file

@ -69,8 +69,8 @@ rodiojack-backend = ["librespot-playback/rodiojack-backend"]
sdl-backend = ["librespot-playback/sdl-backend"] sdl-backend = ["librespot-playback/sdl-backend"]
gstreamer-backend = ["librespot-playback/gstreamer-backend"] gstreamer-backend = ["librespot-playback/gstreamer-backend"]
with-tremor = ["librespot-audio/with-tremor"] with-tremor = ["librespot-playback/with-tremor"]
with-vorbis = ["librespot-audio/with-vorbis"] with-vorbis = ["librespot-playback/with-vorbis"]
with-dns-sd = ["librespot-connect/with-dns-sd"] with-dns-sd = ["librespot-connect/with-dns-sd"]

View file

@ -14,18 +14,7 @@ version = "0.2.0"
aes-ctr = "0.6" aes-ctr = "0.6"
byteorder = "1.4" byteorder = "1.4"
bytes = "1.0" bytes = "1.0"
cfg-if = "1"
lewton = "0.10"
log = "0.4" log = "0.4"
futures-util = { version = "0.3", default_features = false } futures-util = { version = "0.3", default_features = false }
ogg = "0.8"
tempfile = "3.1" tempfile = "3.1"
tokio = { version = "1", features = ["sync", "macros"] } tokio = { version = "1", features = ["sync", "macros"] }
zerocopy = "0.3"
librespot-tremor = { version = "0.2", optional = true }
vorbis = { version ="0.0", optional = true }
[features]
with-tremor = ["librespot-tremor"]
with-vorbis = ["vorbis"]

View file

@ -3,25 +3,9 @@
#[macro_use] #[macro_use]
extern crate log; extern crate log;
pub mod convert;
mod decrypt; mod decrypt;
mod fetch; mod fetch;
use cfg_if::cfg_if;
cfg_if! {
if #[cfg(any(feature = "with-tremor", feature = "with-vorbis"))] {
mod libvorbis_decoder;
pub use crate::libvorbis_decoder::{VorbisDecoder, VorbisError};
} else {
mod lewton_decoder;
pub use lewton_decoder::{VorbisDecoder, VorbisError};
}
}
mod passthrough_decoder;
pub use passthrough_decoder::{PassthroughDecoder, PassthroughError};
mod range_set; mod range_set;
pub use decrypt::AudioDecrypt; pub use decrypt::AudioDecrypt;
@ -30,64 +14,3 @@ pub use fetch::{
READ_AHEAD_BEFORE_PLAYBACK_ROUNDTRIPS, READ_AHEAD_BEFORE_PLAYBACK_SECONDS, READ_AHEAD_BEFORE_PLAYBACK_ROUNDTRIPS, READ_AHEAD_BEFORE_PLAYBACK_SECONDS,
READ_AHEAD_DURING_PLAYBACK_ROUNDTRIPS, READ_AHEAD_DURING_PLAYBACK_SECONDS, READ_AHEAD_DURING_PLAYBACK_ROUNDTRIPS, READ_AHEAD_DURING_PLAYBACK_SECONDS,
}; };
use std::fmt;
pub enum AudioPacket {
Samples(Vec<f32>),
OggData(Vec<u8>),
}
impl AudioPacket {
pub fn samples(&self) -> &[f32] {
match self {
AudioPacket::Samples(s) => s,
AudioPacket::OggData(_) => panic!("can't return OggData on samples"),
}
}
pub fn oggdata(&self) -> &[u8] {
match self {
AudioPacket::Samples(_) => panic!("can't return samples on OggData"),
AudioPacket::OggData(d) => d,
}
}
pub fn is_empty(&self) -> bool {
match self {
AudioPacket::Samples(s) => s.is_empty(),
AudioPacket::OggData(d) => d.is_empty(),
}
}
}
#[derive(Debug)]
pub enum AudioError {
PassthroughError(PassthroughError),
VorbisError(VorbisError),
}
impl fmt::Display for AudioError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
AudioError::PassthroughError(err) => write!(f, "PassthroughError({})", err),
AudioError::VorbisError(err) => write!(f, "VorbisError({})", err),
}
}
}
impl From<VorbisError> for AudioError {
fn from(err: VorbisError) -> AudioError {
AudioError::VorbisError(err)
}
}
impl From<PassthroughError> for AudioError {
fn from(err: PassthroughError) -> AudioError {
AudioError::PassthroughError(err)
}
}
pub trait AudioDecoder {
fn seek(&mut self, ms: i64) -> Result<(), AudioError>;
fn next_packet(&mut self) -> Result<Option<AudioPacket>, AudioError>;
}

View file

@ -18,12 +18,14 @@ path = "../metadata"
version = "0.2.0" version = "0.2.0"
[dependencies] [dependencies]
cfg-if = "1.0"
futures-executor = "0.3" futures-executor = "0.3"
futures-util = { version = "0.3", default_features = false, features = ["alloc"] } futures-util = { version = "0.3", default_features = false, features = ["alloc"] }
log = "0.4" log = "0.4"
byteorder = "1.4" byteorder = "1.4"
shell-words = "1.0.0" shell-words = "1.0.0"
tokio = { version = "1", features = ["sync"] } tokio = { version = "1", features = ["sync"] }
zerocopy = { version = "0.3" }
alsa = { version = "0.5", optional = true } alsa = { version = "0.5", optional = true }
portaudio-rs = { version = "0.3", optional = true } portaudio-rs = { version = "0.3", optional = true }
@ -34,13 +36,18 @@ sdl2 = { version = "0.34.3", optional = true }
gstreamer = { version = "0.16", optional = true } gstreamer = { version = "0.16", optional = true }
gstreamer-app = { version = "0.16", optional = true } gstreamer-app = { version = "0.16", optional = true }
glib = { version = "0.10", optional = true } glib = { version = "0.10", optional = true }
zerocopy = { version = "0.3" }
# Rodio dependencies # Rodio dependencies
rodio = { version = "0.13", optional = true, default-features = false } rodio = { version = "0.13", optional = true, default-features = false }
cpal = { version = "0.13", optional = true } cpal = { version = "0.13", optional = true }
thiserror = { version = "1", optional = true } thiserror = { version = "1", optional = true }
# Decoders
lewton = "0.10" # Currently not optional because of limitations of cargo features
librespot-tremor = { version = "0.2", optional = true }
ogg = "0.8"
vorbis = { version ="0.0", optional = true }
[features] [features]
alsa-backend = ["alsa"] alsa-backend = ["alsa"]
portaudio-backend = ["portaudio-rs"] portaudio-backend = ["portaudio-rs"]
@ -50,3 +57,6 @@ rodio-backend = ["rodio", "cpal", "thiserror"]
rodiojack-backend = ["rodio", "cpal/jack", "thiserror"] rodiojack-backend = ["rodio", "cpal/jack", "thiserror"]
sdl-backend = ["sdl2"] sdl-backend = ["sdl2"]
gstreamer-backend = ["gstreamer", "gstreamer-app", "glib"] gstreamer-backend = ["gstreamer", "gstreamer-app", "glib"]
with-tremor = ["librespot-tremor"]
with-vorbis = ["vorbis"]

View file

@ -1,6 +1,6 @@
use super::{Open, Sink, SinkAsBytes}; use super::{Open, Sink, SinkAsBytes};
use crate::audio::AudioPacket;
use crate::config::AudioFormat; use crate::config::AudioFormat;
use crate::decoder::AudioPacket;
use crate::player::{NUM_CHANNELS, SAMPLES_PER_SECOND, SAMPLE_RATE}; use crate::player::{NUM_CHANNELS, SAMPLES_PER_SECOND, SAMPLE_RATE};
use alsa::device_name::HintIter; use alsa::device_name::HintIter;
use alsa::pcm::{Access, Format, Frames, HwParams, PCM}; use alsa::pcm::{Access, Format, Frames, HwParams, PCM};

View file

@ -1,6 +1,6 @@
use super::{Open, Sink, SinkAsBytes}; use super::{Open, Sink, SinkAsBytes};
use crate::audio::AudioPacket;
use crate::config::AudioFormat; use crate::config::AudioFormat;
use crate::decoder::AudioPacket;
use crate::player::{NUM_CHANNELS, SAMPLE_RATE}; use crate::player::{NUM_CHANNELS, SAMPLE_RATE};
use gstreamer as gst; use gstreamer as gst;

View file

@ -1,6 +1,6 @@
use super::{Open, Sink}; use super::{Open, Sink};
use crate::audio::AudioPacket;
use crate::config::AudioFormat; use crate::config::AudioFormat;
use crate::decoder::AudioPacket;
use crate::player::NUM_CHANNELS; use crate::player::NUM_CHANNELS;
use jack::{ use jack::{
AsyncClient, AudioOut, Client, ClientOptions, Control, Port, ProcessHandler, ProcessScope, AsyncClient, AudioOut, Client, ClientOptions, Control, Port, ProcessHandler, ProcessScope,

View file

@ -1,5 +1,5 @@
use crate::audio::AudioPacket;
use crate::config::AudioFormat; use crate::config::AudioFormat;
use crate::decoder::AudioPacket;
use std::io; use std::io;
pub trait Open { pub trait Open {
@ -26,7 +26,7 @@ fn mk_sink<S: Sink + Open + 'static>(device: Option<String>, format: AudioFormat
macro_rules! sink_as_bytes { macro_rules! sink_as_bytes {
() => { () => {
fn write(&mut self, packet: &AudioPacket) -> io::Result<()> { fn write(&mut self, packet: &AudioPacket) -> io::Result<()> {
use crate::audio::convert::{self, i24}; use crate::convert::{self, i24};
use zerocopy::AsBytes; use zerocopy::AsBytes;
match packet { match packet {
AudioPacket::Samples(samples) => match self.format { AudioPacket::Samples(samples) => match self.format {

View file

@ -1,6 +1,6 @@
use super::{Open, Sink, SinkAsBytes}; use super::{Open, Sink, SinkAsBytes};
use crate::audio::AudioPacket;
use crate::config::AudioFormat; use crate::config::AudioFormat;
use crate::decoder::AudioPacket;
use std::fs::OpenOptions; use std::fs::OpenOptions;
use std::io::{self, Write}; use std::io::{self, Write};

View file

@ -1,6 +1,7 @@
use super::{Open, Sink}; use super::{Open, Sink};
use crate::audio::{convert, AudioPacket};
use crate::config::AudioFormat; use crate::config::AudioFormat;
use crate::convert;
use crate::decoder::AudioPacket;
use crate::player::{NUM_CHANNELS, SAMPLE_RATE}; use crate::player::{NUM_CHANNELS, SAMPLE_RATE};
use portaudio_rs::device::{get_default_output_index, DeviceIndex, DeviceInfo}; use portaudio_rs::device::{get_default_output_index, DeviceIndex, DeviceInfo};
use portaudio_rs::stream::*; use portaudio_rs::stream::*;

View file

@ -1,6 +1,6 @@
use super::{Open, Sink, SinkAsBytes}; use super::{Open, Sink, SinkAsBytes};
use crate::audio::AudioPacket;
use crate::config::AudioFormat; use crate::config::AudioFormat;
use crate::decoder::AudioPacket;
use crate::player::{NUM_CHANNELS, SAMPLE_RATE}; use crate::player::{NUM_CHANNELS, SAMPLE_RATE};
use libpulse_binding::{self as pulse, stream::Direction}; use libpulse_binding::{self as pulse, stream::Direction};
use libpulse_simple_binding::Simple; use libpulse_simple_binding::Simple;

View file

@ -5,8 +5,9 @@ use cpal::traits::{DeviceTrait, HostTrait};
use thiserror::Error; use thiserror::Error;
use super::Sink; use super::Sink;
use crate::audio::{convert, AudioPacket};
use crate::config::AudioFormat; use crate::config::AudioFormat;
use crate::convert;
use crate::decoder::AudioPacket;
use crate::player::{NUM_CHANNELS, SAMPLE_RATE}; use crate::player::{NUM_CHANNELS, SAMPLE_RATE};
#[cfg(all( #[cfg(all(

View file

@ -1,6 +1,7 @@
use super::{Open, Sink}; use super::{Open, Sink};
use crate::audio::{convert, AudioPacket};
use crate::config::AudioFormat; use crate::config::AudioFormat;
use crate::convert;
use crate::decoder::AudioPacket;
use crate::player::{NUM_CHANNELS, SAMPLE_RATE}; use crate::player::{NUM_CHANNELS, SAMPLE_RATE};
use sdl2::audio::{AudioQueue, AudioSpecDesired}; use sdl2::audio::{AudioQueue, AudioSpecDesired};
use std::{io, thread, time}; use std::{io, thread, time};

View file

@ -1,6 +1,6 @@
use super::{Open, Sink, SinkAsBytes}; use super::{Open, Sink, SinkAsBytes};
use crate::audio::AudioPacket;
use crate::config::AudioFormat; use crate::config::AudioFormat;
use crate::decoder::AudioPacket;
use shell_words::split; use shell_words::split;
use std::io::{self, Write}; use std::io::{self, Write};

View file

@ -1,4 +1,4 @@
use crate::audio::convert::i24; use crate::convert::i24;
use std::convert::TryFrom; use std::convert::TryFrom;
use std::mem; use std::mem;
use std::str::FromStr; use std::str::FromStr;

View file

@ -0,0 +1,76 @@
use std::fmt;
use cfg_if::cfg_if;
cfg_if! {
if #[cfg(any(feature = "with-tremor", feature = "with-vorbis"))] {
mod libvorbis_decoder;
pub use libvorbis_decoder::{VorbisDecoder, VorbisError};
} else {
mod lewton_decoder;
pub use lewton_decoder::{VorbisDecoder, VorbisError};
}
}
mod passthrough_decoder;
pub use passthrough_decoder::{PassthroughDecoder, PassthroughError};
pub enum AudioPacket {
Samples(Vec<f32>),
OggData(Vec<u8>),
}
impl AudioPacket {
pub fn samples(&self) -> &[f32] {
match self {
AudioPacket::Samples(s) => s,
AudioPacket::OggData(_) => panic!("can't return OggData on samples"),
}
}
pub fn oggdata(&self) -> &[u8] {
match self {
AudioPacket::Samples(_) => panic!("can't return samples on OggData"),
AudioPacket::OggData(d) => d,
}
}
pub fn is_empty(&self) -> bool {
match self {
AudioPacket::Samples(s) => s.is_empty(),
AudioPacket::OggData(d) => d.is_empty(),
}
}
}
#[derive(Debug)]
pub enum AudioError {
PassthroughError(PassthroughError),
VorbisError(VorbisError),
}
impl fmt::Display for AudioError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
AudioError::PassthroughError(err) => write!(f, "PassthroughError({})", err),
AudioError::VorbisError(err) => write!(f, "VorbisError({})", err),
}
}
}
impl From<VorbisError> for AudioError {
fn from(err: VorbisError) -> AudioError {
AudioError::VorbisError(err)
}
}
impl From<PassthroughError> for AudioError {
fn from(err: PassthroughError) -> AudioError {
AudioError::PassthroughError(err)
}
}
pub trait AudioDecoder {
fn seek(&mut self, ms: i64) -> Result<(), AudioError>;
fn next_packet(&mut self) -> Result<Option<AudioPacket>, AudioError>;
}

View file

@ -7,5 +7,7 @@ use librespot_metadata as metadata;
pub mod audio_backend; pub mod audio_backend;
pub mod config; pub mod config;
mod convert;
mod decoder;
pub mod mixer; pub mod mixer;
pub mod player; pub mod player;

View file

@ -11,7 +11,6 @@ use futures_util::stream::futures_unordered::FuturesUnordered;
use futures_util::{future, StreamExt, TryFutureExt}; use futures_util::{future, StreamExt, TryFutureExt};
use tokio::sync::{mpsc, oneshot}; use tokio::sync::{mpsc, oneshot};
use crate::audio::{AudioDecoder, AudioError, AudioPacket, PassthroughDecoder, VorbisDecoder};
use crate::audio::{AudioDecrypt, AudioFile, StreamLoaderController}; use crate::audio::{AudioDecrypt, AudioFile, StreamLoaderController};
use crate::audio::{ use crate::audio::{
READ_AHEAD_BEFORE_PLAYBACK_ROUNDTRIPS, READ_AHEAD_BEFORE_PLAYBACK_SECONDS, READ_AHEAD_BEFORE_PLAYBACK_ROUNDTRIPS, READ_AHEAD_BEFORE_PLAYBACK_SECONDS,
@ -22,6 +21,7 @@ use crate::config::{Bitrate, NormalisationMethod, NormalisationType, PlayerConfi
use crate::core::session::Session; use crate::core::session::Session;
use crate::core::spotify_id::SpotifyId; use crate::core::spotify_id::SpotifyId;
use crate::core::util::SeqGenerator; use crate::core::util::SeqGenerator;
use crate::decoder::{AudioDecoder, AudioError, AudioPacket, PassthroughDecoder, VorbisDecoder};
use crate::metadata::{AudioItem, FileFormat}; use crate::metadata::{AudioItem, FileFormat};
use crate::mixer::AudioFilter; use crate::mixer::AudioFilter;