Skip to content

Commit

Permalink
More feature gating. Disable the subprocess backend. Add some Conne…
Browse files Browse the repository at this point in the history
…ct mode preparation work...
  • Loading branch information
michaelherger committed Sep 24, 2024
1 parent 9b8cba5 commit 4d7c718
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 6 deletions.
2 changes: 2 additions & 0 deletions playback/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,7 @@ rodio-backend = ["rodio", "cpal"]
rodiojack-backend = ["rodio", "cpal/jack"]
sdl-backend = ["sdl2"]
gstreamer-backend = ["gstreamer", "gstreamer-app", "gstreamer-audio", "glib"]
spotty = []

passthrough-decoder = ["ogg"]
default = ["passthrough-decoder", "spotty"]
3 changes: 3 additions & 0 deletions playback/src/audio_backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ use self::sdl::SdlSink;
mod pipe;
use self::pipe::StdoutSink;

#[cfg(not(feature = "spotty"))]
mod subprocess;
#[cfg(not(feature = "spotty"))]
use self::subprocess::SubprocessSink;

pub const BACKENDS: &[(&str, SinkBuilder)] = &[
Expand All @@ -138,6 +140,7 @@ pub const BACKENDS: &[(&str, SinkBuilder)] = &[
#[cfg(feature = "sdl-backend")]
(SdlSink::NAME, mk_sink::<SdlSink>),
(StdoutSink::NAME, mk_sink::<StdoutSink>),
#[cfg(not(feature = "spotty"))]
(SubprocessSink::NAME, mk_sink::<SubprocessSink>),
];

Expand Down
23 changes: 23 additions & 0 deletions playback/src/audio_backend/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ use std::io::{self, Write};
use std::process::exit;
use thiserror::Error;

#[cfg(feature = "spotty")]
use std::thread;
#[cfg(feature = "spotty")]
use std::time::Duration;

#[cfg(all(target_os = "windows", feature = "spotty"))]
const NULLDEVICE: &str = "NUL";
#[cfg(all(not(target_os = "windows"), feature = "spotty"))]
const NULLDEVICE: &str = "/dev/null";

#[derive(Debug, Error)]
enum StdoutError {
#[error("<StdoutSink> {0}")]
Expand Down Expand Up @@ -101,6 +111,19 @@ impl SinkAsBytes for StdoutSink {
.write_all(data)
.map_err(StdoutError::OnWrite)?;

#[cfg(feature = "spotty")]
match self.file.clone().as_deref() {
Some(NULLDEVICE) => {
// can we sleep for the duration of the "data" packets?
let ms: u64 = ((data.len() * 8 * 1000) / (1411 * 1024))
.try_into()
.unwrap();
eprintln!("NullSink::write_bytes: {:?} - {:?}", data.len(), ms);
thread::sleep(Duration::from_millis(ms));
}
_ => {}
}

Ok(())
}
}
Expand Down
3 changes: 3 additions & 0 deletions playback/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ pub struct PlayerConfig {
// (thereby circumventing Send bounds that they might not satisfy)
pub ditherer: Option<DithererBuilder>,

#[cfg(feature = "spotty")]
pub lms_connect_mode: bool,
}

Expand All @@ -158,6 +159,8 @@ impl Default for PlayerConfig {
normalisation_knee_db: 5.0,
passthrough: false,
ditherer: Some(mk_ditherer::<TriangularDitherer>),

#[cfg(feature = "spotty")]
lms_connect_mode: false,
}
}
Expand Down
8 changes: 8 additions & 0 deletions playback/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1662,14 +1662,22 @@ impl PlayerInternal {
}
}

#[cfg(feature = "spotty")]
if let Err(_e) = self.sink.write(packet, &mut self.converter) {
// error!("{}", e);
exit(1);
}

#[cfg(not(feature = "spotty"))]
if let Err(e) = self.sink.write(packet, &mut self.converter) {
error!("{}", e);
self.handle_pause();
}
}
}

None => {
#[cfg(feature = "spotty")]
if self.config.lms_connect_mode {
// info!("In LMS Connect mode - ignore end of track");

Expand Down
23 changes: 17 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ mod spotty;

const VERSION: &str = concat!(env!("CARGO_PKG_NAME"), " v", env!("CARGO_PKG_VERSION"));

// #[cfg(all(target_os = "windows", feature = "spotty"))]
// const NULLDEVICE: &str = "NUL";
// #[cfg(all(not(target_os = "windows"), feature = "spotty"))]
// const NULLDEVICE: &str = "/dev/null";
#[cfg(all(target_os = "windows", feature = "spotty"))]
const NULLDEVICE: &str = "NUL";
#[cfg(all(not(target_os = "windows"), feature = "spotty"))]
const NULLDEVICE: &str = "/dev/null";

#[cfg(feature = "alsa-backend")]
use librespot::playback::mixer::alsamixer::AlsaMixer;
Expand Down Expand Up @@ -956,6 +956,9 @@ fn get_setup() -> Setup {
exit(1);
});

#[cfg(feature = "spotty")]
let backend = audio_backend::find(None).unwrap();

#[cfg(not(feature = "spotty"))]
let format = opt_str(FORMAT)
.as_deref()
Expand All @@ -975,6 +978,13 @@ fn get_setup() -> Setup {
})
.unwrap_or_default();

#[cfg(feature = "spotty")]
let format = AudioFormat::default();

#[cfg(feature = "spotty")]
let device = Some(NULLDEVICE.to_string());

#[cfg(not(feature = "spotty"))]
let device = opt_str(DEVICE);
if let Some(ref value) = device {
if value == "?" {
Expand Down Expand Up @@ -1875,15 +1885,16 @@ fn get_setup() -> Setup {
let save_token = opt_str(SAVE_TOKEN).unwrap_or_else(|| "".to_string());
let client_id = opt_str(CLIENT_ID).unwrap_or_else(|| include_str!("client_id.txt").to_string());

// #[cfg(feature = "spotty")]
// let lms = LMS::new(
// opt_str(LYRION_MUSIC_SERVER),
// opt_str(PLAYER_MAC),
// opt_str(LMS_AUTH),
// );

Setup {
format: AudioFormat::default(),
backend: audio_backend::find(None).unwrap(),
format,
backend,
device,
mixer,
cache,
Expand Down

0 comments on commit 4d7c718

Please sign in to comment.