Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null mixer to skip volume control #286

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions playback/src/mixer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@ impl Default for MixerConfig {
pub mod softmixer;
use self::softmixer::SoftMixer;

pub mod nullmixer;
use self::nullmixer::NullMixer;

fn mk_sink<M: Mixer + 'static>(device: Option<MixerConfig>) -> Box<Mixer> {
Box::new(M::open(device))
}

pub fn find<T: AsRef<str>>(name: Option<T>) -> Option<fn(Option<MixerConfig>) -> Box<Mixer>> {
match name.as_ref().map(AsRef::as_ref) {
Some("null") => Some(mk_sink::<NullMixer>),
None | Some("softvol") => Some(mk_sink::<SoftMixer>),
#[cfg(feature = "alsa-backend")]
Some("alsa") => Some(mk_sink::<AlsaMixer>),
Expand Down
29 changes: 29 additions & 0 deletions playback/src/mixer/nullmixer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};

use super::AudioFilter;
use super::{Mixer, MixerConfig};

#[derive(Clone)]
pub struct NullMixer {
volume: Arc<AtomicUsize>,
}

impl Mixer for NullMixer {
fn open(_: Option<MixerConfig>) -> NullMixer {
NullMixer {
volume: Arc::new(AtomicUsize::new(0xFFFF)),
}
}
fn start(&self) {}
fn stop(&self) {}
fn volume(&self) -> u16 {
self.volume.load(Ordering::Relaxed) as u16
}
fn set_volume(&self, volume: u16) {
self.volume.store(volume as usize, Ordering::Relaxed);
}
fn get_audio_filter(&self) -> Option<Box<AudioFilter + Send>> {
None
}
}