Integrate hardware volume control in PlaybackEngine
- Add hardware_volume parameter to PlaybackEngine::new_alsa_direct() - Update all three call sites in player.rs to pass alsa_hardware_volume setting - Implement conditional volume control: hardware mixer or DAC/amplifier - Add device_id() getter to AlsaDirectStream for mixer access - Hardware volume disabled by default for maximum compatibility
This commit is contained in:
1 parent
c87b41894d
commit
61688bd1ea
3 files changed
+40
-8
No files matched your search
@@ -952,7 +952,12 @@ impl Player {
|
||||
StreamType::AlsaDirect(alsa_stream) => {
|
||||
*consecutive_sink_failures = 0;
|
||||
thread_state.set_stream_error(false);
|
||||
PlaybackEngine::new_alsa_direct(alsa_stream.clone())
|
||||
let hardware_volume = thread_settings
|
||||
.lock()
|
||||
.ok()
|
||||
.map(|s| s.alsa_hardware_volume)
|
||||
.unwrap_or(false);
|
||||
PlaybackEngine::new_alsa_direct(alsa_stream.clone(), hardware_volume)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1035,7 +1040,12 @@ impl Player {
|
||||
}
|
||||
#[cfg(target_os = "linux")]
|
||||
StreamType::AlsaDirect(alsa_stream) => {
|
||||
PlaybackEngine::new_alsa_direct(alsa_stream.clone())
|
||||
let hardware_volume = thread_settings
|
||||
.lock()
|
||||
.ok()
|
||||
.map(|s| s.alsa_hardware_volume)
|
||||
.unwrap_or(false);
|
||||
PlaybackEngine::new_alsa_direct(alsa_stream.clone(), hardware_volume)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1130,7 +1140,12 @@ impl Player {
|
||||
}
|
||||
#[cfg(target_os = "linux")]
|
||||
StreamType::AlsaDirect(alsa_stream) => {
|
||||
PlaybackEngine::new_alsa_direct(alsa_stream.clone())
|
||||
let hardware_volume = thread_settings
|
||||
.lock()
|
||||
.ok()
|
||||
.map(|s| s.alsa_hardware_volume)
|
||||
.unwrap_or(false);
|
||||
PlaybackEngine::new_alsa_direct(alsa_stream.clone(), hardware_volume)
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ pub enum PlaybackEngine {
|
||||
position_frames: Arc<AtomicU64>,
|
||||
duration_frames: Arc<AtomicU64>,
|
||||
playback_thread: Option<thread::JoinHandle<()>>,
|
||||
hardware_volume: bool, // Use ALSA mixer for volume control
|
||||
},
|
||||
}
|
||||
|
||||
@@ -39,13 +40,14 @@ impl PlaybackEngine {
|
||||
}
|
||||
|
||||
/// Create ALSA Direct engine
|
||||
pub fn new_alsa_direct(stream: Arc<AlsaDirectStream>) -> Self {
|
||||
pub fn new_alsa_direct(stream: Arc<AlsaDirectStream>, hardware_volume: bool) -> Self {
|
||||
Self::AlsaDirect {
|
||||
stream,
|
||||
is_playing: Arc::new(AtomicBool::new(false)),
|
||||
position_frames: Arc::new(AtomicU64::new(0)),
|
||||
duration_frames: Arc::new(AtomicU64::new(0)),
|
||||
playback_thread: None,
|
||||
hardware_volume,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +67,7 @@ impl PlaybackEngine {
|
||||
position_frames,
|
||||
duration_frames,
|
||||
playback_thread,
|
||||
hardware_volume: _,
|
||||
} => {
|
||||
// For ALSA Direct, we need to spawn a thread that:
|
||||
// 1. Streams samples from source (no buffering entire file)
|
||||
@@ -195,10 +198,19 @@ impl PlaybackEngine {
|
||||
pub fn set_volume(&self, volume: f32) {
|
||||
match self {
|
||||
Self::Rodio { sink } => sink.set_volume(volume),
|
||||
Self::AlsaDirect { .. } => {
|
||||
// TODO: Implement software volume or ALSA mixer control
|
||||
// For now, ALSA Direct uses hardware volume
|
||||
log::warn!("[ALSA Direct Engine] Software volume not yet implemented");
|
||||
Self::AlsaDirect { stream, hardware_volume, .. } => {
|
||||
if *hardware_volume {
|
||||
// Try hardware mixer control
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
if let Err(e) = stream.set_hardware_volume(volume) {
|
||||
log::warn!("[ALSA Direct Engine] Hardware volume failed: {}. Volume slider may not work.", e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Hardware volume disabled - volume control is handled by DAC/amplifier
|
||||
log::debug!("[ALSA Direct Engine] Hardware volume control disabled (use DAC/amplifier)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user