/// Calculates and applies updates to the internal and external volume levels of the given audio
/// stream.
///
/// This method needs to know the external volume level before changes were made in order to
/// determine if a changed event should be sent to listeners of the base setting.
// TODO(fxbug.dev/67784): consider keeping copy of external audio info so previous external
// volume doesn't need to be calculated.
Calculates and applies updates to the internal and external volume levels of the given audio
stream.

This method needs to know the external volume level before changes were made in order to
determine if a changed event should be sent to listeners of the base setting.
TODO(fxbug.dev/67784): consider keeping copy of external audio info so previous external
volume doesn't need to be calculated.
Calculates and applies updates to the internal and external volume levels of the given audio stream . This method needs to know the external volume level before changes were made in order to determine if a changed event should be sent to listeners of the base setting . TODO ( fxbug . dev / 67784 ) : consider keeping copy of external audio info so previous external volume doesn ' t need to be calculated .
async fn apply_policy_transforms(
        &mut self,
        target: PropertyTarget,
        audio_info: AudioInfo,
        previous_external_volume: f32,
    ) -> Result<(), policy_base::response::Error> {
        let original = *audio_info
            .streams
            .iter()
            .find(|stream| stream.stream_type == target)
            .ok_or(policy_base::response::Error::Unexpected)?;
        // Make a copy to apply policy transforms on.
        let mut transformed = original;
        transformed.user_volume_level =
            self.clamp_internal_volume(target, original.user_volume_level);
        transformed.user_volume_muted =
            original.user_volume_muted & self.calculate_can_mute(target);
        let new_external_volume =
            self.calculate_external_volume(target, transformed.user_volume_level);
        // Set internal/external volume state as needed.
        if transformed != original {
            // When the internal volume level should change, send a Set request to the audio
            // controller.
            self.client_proxy.send_setting_request(
                SettingType::Audio,
                SettingRequest::SetVolume(vec![transformed]),
            );
        } else if (new_external_volume - previous_external_volume).abs() > f32::EPSILON {
            // In some cases, such as when a max volume limit is removed, the internal volume may
            // not change but the external volume should still be updated. We send a Rebroadcast
            // request to the setting proxy, triggering an update for external clients.
            self.client_proxy.request_rebroadcast(SettingType::Audio);
        }
        Ok(())
    }
async fn apply_policy_transforms ( & mut self , target : PropertyTarget , audio_info : AudioInfo , previous_external_volume : f32 , ) -> Result < ( ) , policy_base :: response :: Error > { let original = * audio_info . streams . iter ( ) . find ( | stream | stream . stream_type == target ) . ok_or ( policy_base :: response :: Error :: Unexpected ) ? ; // Make a copy to apply policy transforms on. let mut transformed = original ; transformed . user_volume_level = self . clamp_internal_volume ( target , original . user_volume_level ) ; transformed . user_volume_muted = original . user_volume_muted & self . calculate_can_mute ( target ) ; let new_external_volume = self . calculate_external_volume ( target , transformed . user_volume_level ) ; // Set internal/external volume state as needed. if transformed != original { // When the internal volume level should change, send a Set request to the audio // controller. self . client_proxy . send_setting_request ( SettingType :: Audio , SettingRequest :: SetVolume ( vec ! [ transformed ] ) , ) ; } else if ( new_external_volume - previous_external_volume ) . abs ( ) > f32 :: EPSILON { // In some cases, such as when a max volume limit is removed, the internal volume may // not change but the external volume should still be updated. We send a Rebroadcast // request to the setting proxy, triggering an update for external clients. self . client_proxy . request_rebroadcast ( SettingType :: Audio ) ; } Ok ( ( ) ) }
Calculates and applies updates to the internal and external volume levels of the given audio
stream.
Calculates and applies updates to the internal and external volume levels of the given audio stream .
&mut self
target
PropertyTarget
audio_info
AudioInfo
previous_external_volume
f32