Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7b95f9a0 authored by Jeremy Wu's avatar Jeremy Wu
Browse files

Floss: expose DBus method to allow AudioState query

Upon the audio stack sending StartAudioRequest, this method will be used
to periodically query the AudioState until it has transitioned to the
'Started' state so that the audio stack can start sending data over.

Bug: 236769419
Tag: #floss
Test: Build and verify DBus method exposed
Change-Id: Ia954ed2cee02565acf24e1d72c54f02c7658749b
parent 87f17efb
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -140,6 +140,11 @@ impl IBluetoothMedia for IBluetoothMediaDBus {
        dbus_generated!()
    }

    #[dbus_method("GetA2dpAudioStarted")]
    fn get_a2dp_audio_started(&mut self) -> bool {
        dbus_generated!()
    }

    #[dbus_method("StopAudioRequest")]
    fn stop_audio_request(&mut self) {
        dbus_generated!()
+23 −7
Original line number Diff line number Diff line
@@ -3,7 +3,8 @@
use bt_topshim::btif::{BluetoothInterface, RawAddress};
use bt_topshim::profiles::a2dp::{
    A2dp, A2dpCallbacks, A2dpCallbacksDispatcher, A2dpCodecBitsPerSample, A2dpCodecChannelMode,
    A2dpCodecConfig, A2dpCodecSampleRate, BtavConnectionState, PresentationPosition,
    A2dpCodecConfig, A2dpCodecSampleRate, BtavAudioState, BtavConnectionState,
    PresentationPosition,
};
use bt_topshim::profiles::avrcp::{Avrcp, AvrcpCallbacks, AvrcpCallbacksDispatcher};
use bt_topshim::profiles::hfp::{
@@ -58,6 +59,7 @@ pub trait IBluetoothMedia {
    fn set_hfp_volume(&mut self, volume: u8, address: String);
    fn start_audio_request(&mut self);
    fn stop_audio_request(&mut self);
    fn get_a2dp_audio_started(&mut self) -> bool;
    fn get_presentation_position(&mut self) -> PresentationPosition;

    fn start_sco_call(&mut self, address: String);
@@ -126,6 +128,7 @@ pub struct BluetoothMedia {
    a2dp: Option<A2dp>,
    avrcp: Option<Avrcp>,
    a2dp_states: HashMap<RawAddress, BtavConnectionState>,
    a2dp_audio_state: BtavAudioState,
    hfp: Option<Hfp>,
    hfp_states: HashMap<RawAddress, BthfConnectionState>,
    selectable_caps: HashMap<RawAddress, Vec<A2dpCodecConfig>>,
@@ -146,6 +149,7 @@ impl BluetoothMedia {
            a2dp: None,
            avrcp: None,
            a2dp_states: HashMap::new(),
            a2dp_audio_state: BtavAudioState::RemoteSuspend,
            hfp: None,
            hfp_states: HashMap::new(),
            selectable_caps: HashMap::new(),
@@ -173,18 +177,23 @@ impl BluetoothMedia {
                        self.notify_media_capability_added(addr);
                        self.a2dp_states.insert(addr, state);
                    }
                    BtavConnectionState::Disconnected => match self.a2dp_states.remove(&addr) {
                    BtavConnectionState::Disconnected => {
                        self.a2dp_audio_state = BtavAudioState::RemoteSuspend;
                        match self.a2dp_states.remove(&addr) {
                            Some(_) => self.notify_media_capability_removed(addr),
                            None => {
                                warn!("[{}]: Unknown address a2dp disconnected.", addr.to_string());
                            }
                    },
                        }
                    }
                    _ => {
                        self.a2dp_states.insert(addr, state);
                    }
                }
            }
            A2dpCallbacks::AudioState(_addr, _state) => {}
            A2dpCallbacks::AudioState(_addr, state) => {
                self.a2dp_audio_state = state;
            }
            A2dpCallbacks::AudioConfig(addr, _config, _local_caps, selectable_caps) => {
                self.selectable_caps.insert(addr, selectable_caps);
            }
@@ -608,6 +617,13 @@ impl IBluetoothMedia for BluetoothMedia {
        }
    }

    fn get_a2dp_audio_started(&mut self) -> bool {
        match self.a2dp_audio_state {
            BtavAudioState::Started => true,
            _ => false,
        }
    }

    fn get_presentation_position(&mut self) -> PresentationPosition {
        let position = self.a2dp.as_mut().unwrap().get_presentation_position();
        PresentationPosition {