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

Commit 48ab22ed authored by Hansong Zhang's avatar Hansong Zhang
Browse files

Bluetooth media: Add cleanup() and avrcp object

* Add a cleanup() corresponding to initialize().  Note: we may
initialize automatically when we start the stack in the future.
* Add and initialize the default Avrcp object on topshim.  A2dp depends
on Avrcp running in some places.

Test: audio streaming
Tag: #floss
Bug: 190730870
Change-Id: I0d9ea23d2d7a36c3eb39465357bb2d70162d7799
parent b54462a8
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -37,6 +37,11 @@ impl IBluetoothMedia for IBluetoothMediaDBus {
        true
    }

    #[dbus_method("Cleanup")]
    fn cleanup(&mut self) -> bool {
        true
    }

    #[dbus_method("Connect")]
    fn connect(&mut self, device: String) {}

+16 −1
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ use bt_topshim::profiles::a2dp::{
    A2dp, A2dpCallbacks, A2dpCallbacksDispatcher, A2dpCodecBitsPerSample, A2dpCodecChannelMode,
    A2dpCodecSampleRate, BtavConnectionState,
};
use bt_topshim::profiles::avrcp::Avrcp;
use bt_topshim::topstack;

use std::convert::TryFrom;
@@ -19,8 +20,12 @@ pub trait IBluetoothMedia {
    ///
    fn register_callback(&mut self, callback: Box<dyn IBluetoothMediaCallback + Send>) -> bool;

    ///
    /// initializes media (both A2dp and AVRCP) stack
    fn initialize(&mut self) -> bool;

    /// clean up media stack
    fn cleanup(&mut self) -> bool;

    fn connect(&mut self, device: String);
    fn set_active_device(&mut self, device: String);
    fn disconnect(&mut self, device: String);
@@ -49,6 +54,7 @@ pub struct BluetoothMedia {
    callback_last_id: u32,
    tx: Sender<Message>,
    a2dp: Option<A2dp>,
    avrcp: Option<Avrcp>,
}

impl BluetoothMedia {
@@ -60,6 +66,7 @@ impl BluetoothMedia {
            callback_last_id: 0,
            tx,
            a2dp: None,
            avrcp: None,
        }
    }

@@ -113,6 +120,10 @@ impl IBluetoothMedia for BluetoothMedia {
        let a2dp_dispatcher = get_a2dp_dispatcher(self.tx.clone());
        self.a2dp = Some(A2dp::new(&self.intf.lock().unwrap()));
        self.a2dp.as_mut().unwrap().initialize(a2dp_dispatcher);

        // AVRCP
        self.avrcp = Some(Avrcp::new(&self.intf.lock().unwrap()));
        self.avrcp.as_mut().unwrap().initialize();
        true
    }

@@ -120,6 +131,10 @@ impl IBluetoothMedia for BluetoothMedia {
        self.a2dp.as_mut().unwrap().connect(device);
    }

    fn cleanup(&mut self) -> bool {
        true
    }

    fn set_active_device(&mut self, device: String) {
        self.a2dp.as_mut().unwrap().set_active_device(device);
    }