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

Commit 44b7ec7a authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "floss: avrcp: add a few DBUS methods for media information"

parents 1191d751 ec5583f7
Loading
Loading
Loading
Loading
+73 −0
Original line number Diff line number Diff line
use bt_topshim::profiles::a2dp::{A2dpCodecConfig, PresentationPosition};
use bt_topshim::profiles::avrcp::PlayerMetadata;
use bt_topshim::profiles::hfp::HfpCodecCapability;
use btstack::bluetooth_media::{BluetoothAudioDevice, IBluetoothMedia, IBluetoothMediaCallback};
use btstack::RPCProxy;
@@ -88,6 +89,60 @@ pub struct PresentationPositionDBus {
    data_position_nsec: i32,
}

impl DBusArg for PlayerMetadata {
    type DBusType = dbus::arg::PropMap;
    fn from_dbus(
        data: dbus::arg::PropMap,
        _conn: Option<std::sync::Arc<dbus::nonblock::SyncConnection>>,
        _remote: Option<dbus::strings::BusName<'static>>,
        _disconnect_watcher: Option<
            std::sync::Arc<std::sync::Mutex<dbus_projection::DisconnectWatcher>>,
        >,
    ) -> Result<PlayerMetadata, Box<dyn std::error::Error>> {
        let mut metadata = PlayerMetadata::default();

        for (key, variant) in data {
            if variant.arg_type() != dbus::arg::ArgType::Variant {
                return Err(Box::new(DBusArgError::new(format!("{} must be a variant", key))));
            }
            match key.as_str() {
                "title" => {
                    metadata.title = String::ref_arg_to_rust(
                        variant.as_static_inner(0).unwrap(),
                        String::from("PlayerMetadata::Title"),
                    )?
                }
                "artist" => {
                    metadata.artist = String::ref_arg_to_rust(
                        variant.as_static_inner(0).unwrap(),
                        String::from("PlayerMetadata::Artist"),
                    )?
                }
                "album" => {
                    metadata.album = String::ref_arg_to_rust(
                        variant.as_static_inner(0).unwrap(),
                        String::from("PlayerMetadata::Album"),
                    )?
                }
                "length" => {
                    metadata.length = i64::ref_arg_to_rust(
                        variant.as_static_inner(0).unwrap(),
                        String::from("PlayerMetadata::Length"),
                    )?
                }
                _ => {}
            }
        }
        return Ok(metadata);
    }

    fn to_dbus(
        _metadata: PlayerMetadata,
    ) -> Result<dbus::arg::PropMap, Box<dyn std::error::Error>> {
        Ok(std::collections::HashMap::new())
    }
}

#[generate_dbus_exporter(export_bluetooth_media_dbus_intf, "org.chromium.bluetooth.BluetoothMedia")]
impl IBluetoothMedia for IBluetoothMediaDBus {
    #[dbus_method("RegisterCallback")]
@@ -179,4 +234,22 @@ impl IBluetoothMedia for IBluetoothMediaDBus {
    fn get_presentation_position(&mut self) -> PresentationPosition {
        dbus_generated!()
    }

    // Temporary AVRCP-related meida DBUS APIs. The following APIs intercept between Chrome CRAS
    // and cras_server as an expedited solution for AVRCP implementation. The APIs are subject to
    // change when retiring Chrome CRAS.
    #[dbus_method("SetPlayerPlaybackStatus")]
    fn set_player_playback_status(&mut self, status: String) {
        dbus_generated!()
    }

    #[dbus_method("SetPlayerPosition")]
    fn set_player_posistion(&mut self, position: i64) {
        dbus_generated!()
    }

    #[dbus_method("SetPlayerMetadata")]
    fn set_player_metadata(&mut self, metadata: PlayerMetadata) {
        dbus_generated!()
    }
}
+18 −1
Original line number Diff line number Diff line
@@ -6,7 +6,9 @@ use bt_topshim::profiles::a2dp::{
    A2dpCodecConfig, A2dpCodecSampleRate, BtavAudioState, BtavConnectionState,
    PresentationPosition,
};
use bt_topshim::profiles::avrcp::{Avrcp, AvrcpCallbacks, AvrcpCallbacksDispatcher};
use bt_topshim::profiles::avrcp::{
    Avrcp, AvrcpCallbacks, AvrcpCallbacksDispatcher, PlayerMetadata,
};
use bt_topshim::profiles::hfp::{
    BthfAudioState, BthfConnectionState, Hfp, HfpCallbacks, HfpCallbacksDispatcher,
    HfpCodecCapability,
@@ -84,6 +86,17 @@ pub trait IBluetoothMedia {
    // Start the SCO setup to connect audio
    fn start_sco_call(&mut self, address: String, sco_offload: bool, force_cvsd: bool);
    fn stop_sco_call(&mut self, address: String);

    /// Set the current playback status: e.g., playing, paused, stopped, etc. The method is a copy
    /// of the existing CRAS API, hence not following Floss API conventions.
    fn set_player_playback_status(&mut self, status: String);
    /// Set the position of the current media in microseconds. The method is a copy of the existing
    /// CRAS API, hence not following Floss API conventions.
    fn set_player_posistion(&mut self, position: i64);
    /// Set the media metadata, including title, artist, album, and length. The method is a
    /// copy of the existing CRAS API, hence not following Floss API conventions. PlayerMetadata is
    /// a custom data type that requires special handlng.
    fn set_player_metadata(&mut self, metadata: PlayerMetadata);
}

pub trait IBluetoothMediaCallback: RPCProxy {
@@ -1216,4 +1229,8 @@ impl IBluetoothMedia for BluetoothMedia {
            data_position_nsec: position.data_position_nsec,
        }
    }

    fn set_player_playback_status(&mut self, _status: String) {}
    fn set_player_posistion(&mut self, _position: i64) {}
    fn set_player_metadata(&mut self, _metadata: PlayerMetadata) {}
}
+8 −0
Original line number Diff line number Diff line
@@ -4,6 +4,14 @@ use crate::topstack::get_dispatchers;
use std::sync::{Arc, Mutex};
use topshim_macros::cb_variant;

#[derive(Debug, Default)]
pub struct PlayerMetadata {
    pub title: String,
    pub artist: String,
    pub album: String,
    pub length: i64,
}

#[cxx::bridge(namespace = bluetooth::topshim::rust)]
pub mod ffi {
    #[derive(Debug, Copy, Clone)]