Skip to content

Commit

Permalink
Feedback loop prevention
Browse files Browse the repository at this point in the history
  • Loading branch information
saivert committed Dec 26, 2023
1 parent f1f1f05 commit fc13c95
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/backend/pwchannelobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ impl PwChannelObject {
pub fn set_volume_no_send(&self, volume: f32) {
let imp = self.imp();

if volume == imp.volume.get() {
return;
}

imp.volume.set(volume);
self.notify_volume();
}
Expand Down
13 changes: 10 additions & 3 deletions src/backend/pwnodeobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,11 @@ impl PwNodeObject {

pub(crate) fn set_channel_volumes_vec(&self, values: &[f32]) {
*(self.imp().channel_volumes.borrow_mut()) = values.to_owned();
self.send_volume_using_mixerapi(PropertyChanged::ChannelVolumes);

self.update_channel_objects();
if !self.imp().block.get() {
self.send_volume_using_mixerapi(PropertyChanged::ChannelVolumes);
}
}

pub(crate) fn set_channel_volume(&self, index: u32, volume: f32) {
Expand All @@ -440,7 +444,10 @@ impl PwNodeObject {
*value = volume;
}

self.send_volume_using_mixerapi(PropertyChanged::ChannelVolumes);
self.update_channel_objects();
if !self.imp().block.get() {
self.send_volume_using_mixerapi(PropertyChanged::ChannelVolumes);
}
}

pub(crate) fn set_format(&self, format: AudioFormat) {
Expand Down Expand Up @@ -541,7 +548,7 @@ impl PwNodeObject {

pub(crate) fn node_property<T: FromPipewirePropertyString>(&self, property: &str) -> T {
let node = self.imp().wpnode.get().expect("node");
node.pw_property(property).expect("object.serial")
node.pw_property(property).expect(property)
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/backend/pwnodeobject/mixerapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,13 @@ impl PwNodeObject {
wp::log::critical!("Cannot get channel volumes via mixer-api");
}

// Update the liststore
self.update_channel_objects();

// Wireplumber's mixerapi always sets volume to first channel volume
// instead we will use the max channel
let maxvol: Option<f32> = self
.channel_volumes_vec()
.iter()
.max_by(|a, b| a.total_cmp(b))
.copied();
.copied();

if let Some(maxvol) = maxvol {
self.set_volume(maxvol);
Expand All @@ -171,6 +168,9 @@ impl PwNodeObject {
self.set_mute(m);
wp::log::debug!("Setting mute to {m:?}");
}

// Update the liststore
//self.update_channel_objects();
}
}
}

0 comments on commit fc13c95

Please sign in to comment.