aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mumd/Cargo.toml15
-rw-r--r--mumd/src/audio.rs12
-rw-r--r--mumd/src/notify.rs6
3 files changed, 26 insertions, 7 deletions
diff --git a/mumd/Cargo.toml b/mumd/Cargo.toml
index a7a5ef8..1096041 100644
--- a/mumd/Cargo.toml
+++ b/mumd/Cargo.toml
@@ -9,7 +9,13 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
-default = ["libnotify"]
+default = []
+
+all = ["libnotify", "hound", "samplerate"]
+
+notifications = ["libnotify"]
+
+sounds = ["hound", "samplerate"]
[dependencies]
mumlib = { path = "../mumlib" }
@@ -23,16 +29,17 @@ ipc-channel = "0.14"
log = "0.4"
mumble-protocol = "0.3"
native-tls = "0.2"
-openssl = { version = "0.10", optional = true }
+openssl = { version = "0.10" }
opus = "0.2"
serde = { version = "1.0", features = ["derive"] }
tokio = { version = "0.2", features = ["full"] }
tokio-tls = "0.3"
tokio-util = { version = "0.3", features = ["codec", "udp"] }
-hound = "3.4.0"
-samplerate = "0.2.2"
libnotify = { version = "1.0", optional = true }
+hound = { version = "3.4.0", optional = true }
+samplerate = { version = "0.2.2", optional = true }
+
#compressor = "0.3"
#daemonize = "0.4"
diff --git a/mumd/src/audio.rs b/mumd/src/audio.rs
index a51c2f2..316d66b 100644
--- a/mumd/src/audio.rs
+++ b/mumd/src/audio.rs
@@ -1,12 +1,14 @@
pub mod input;
pub mod output;
+#[cfg(any(feature = "sounds", feature = "all"))]
use crate::audio::output::SaturatingAdd;
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
use cpal::{SampleFormat, SampleRate, Stream, StreamConfig};
use log::*;
use mumble_protocol::voice::VoicePacketPayload;
use opus::Channels;
+#[cfg(any(feature = "sounds", feature = "all"))]
use samplerate::ConverterType;
use std::collections::hash_map::Entry;
use std::collections::{HashMap, VecDeque};
@@ -14,6 +16,7 @@ use std::sync::{Arc, Mutex};
use tokio::sync::{mpsc, watch};
//TODO? move to mumlib
+#[cfg(any(feature = "sounds", feature = "all"))]
pub const EVENT_SOUNDS: &[(&str, NotificationEvents)] = &[
("resources/connect.wav", NotificationEvents::ServerConnect),
(
@@ -72,8 +75,10 @@ pub struct Audio {
client_streams: Arc<Mutex<HashMap<u32, output::ClientStream>>>,
+ #[cfg(any(feature = "sounds", feature = "all"))]
sounds: HashMap<NotificationEvents, Vec<f32>>,
+ #[cfg(any(feature = "sounds", feature = "all"))]
play_sounds: Arc<Mutex<VecDeque<f32>>>,
}
@@ -215,6 +220,7 @@ impl Audio {
output_stream.play().unwrap();
+ #[cfg(any(feature = "sounds", feature = "all"))]
let sounds = EVENT_SOUNDS
.iter()
.map(|(path, event)| {
@@ -249,9 +255,11 @@ impl Audio {
input_volume_sender,
input_channel_receiver: Some(input_receiver),
client_streams,
+ #[cfg(any(feature = "sounds", feature = "all"))]
sounds,
output_volume_sender,
user_volumes,
+ #[cfg(any(feature = "sounds", feature = "all"))]
play_sounds,
}
}
@@ -335,6 +343,7 @@ impl Audio {
}
}
+ #[cfg(any(feature = "sounds", feature = "all"))]
pub fn play_effect(&self, effect: NotificationEvents) {
let samples = self.sounds.get(&effect).unwrap();
@@ -347,4 +356,7 @@ impl Audio {
let l = play_sounds.len();
play_sounds.extend(samples.iter().skip(l));
}
+
+ #[cfg(not(any(feature = "sounds", feature = "all")))]
+ pub fn play_effect(&self, _: NotificationEvents) {}
}
diff --git a/mumd/src/notify.rs b/mumd/src/notify.rs
index 0739c58..eaed3dc 100644
--- a/mumd/src/notify.rs
+++ b/mumd/src/notify.rs
@@ -1,9 +1,9 @@
pub fn init() {
- #[cfg(feature = "libnotify")]
+ #[cfg(any(feature = "notifications", feature = "all"))]
libnotify::init("mumd").unwrap();
}
-#[cfg(feature = "libnotify")]
+#[cfg(any(feature = "notifications", feature = "all"))]
pub fn send(msg: String) -> Option<bool> {
match libnotify::Notification::new("mumd", Some(msg.as_str()), None).show() {
Ok(_) => Some(true),
@@ -14,7 +14,7 @@ pub fn send(msg: String) -> Option<bool> {
}
}
-#[cfg(not(feature = "libnotify"))]
+#[cfg(not(any(feature = "notifications", feature = "all")))]
pub fn send(_: String) -> Option<bool> {
None
}