Skip to content

Commit

Permalink
Mixer to skip volume control
Browse files Browse the repository at this point in the history
Implement a null mixer that does not control volume with software.
  • Loading branch information
lautis committed Jun 24, 2019
1 parent 4e3576b commit 44713b9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
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
}
}

0 comments on commit 44713b9

Please sign in to comment.