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

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

Merge "topshim: a2dp - Expose SetAudioConfig method to dbus"

parents 271ca2e1 fc349937
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -34,8 +34,8 @@ struct AudioConfig {
      BTAV_A2DP_CODEC_CHANNEL_MODE_STEREO;
};

// Invoked by audio server to notify Bluetooth about audio config
bool Init(AudioConfig);
// Invoked by audio server to set audio config (PCM for now)
bool SetAudioConfig(AudioConfig);

// Invoked by audio server when it has audio data to stream.
bool StartRequest();
+14 −4
Original line number Diff line number Diff line
@@ -46,9 +46,19 @@ impl IBluetoothMedia for IBluetoothMediaDBus {
    #[dbus_method("Disconnect")]
    fn disconnect(&mut self, device: String) {}

    #[dbus_method("StartSession")]
    fn start_session(&mut self) {}
    #[dbus_method("SetAudioConfig")]
    fn set_audio_config(
        &mut self,
        sample_rate: i32,
        bits_per_sample: i32,
        channel_mode: i32,
    ) -> bool {
        true
    }

    #[dbus_method("StartAudioRequest")]
    fn start_audio_request(&mut self) {}

    #[dbus_method("StopSession")]
    fn stop_session(&mut self) {}
    #[dbus_method("StopAudioRequest")]
    fn stop_audio_request(&mut self) {}
}
+32 −7
Original line number Diff line number Diff line
@@ -2,10 +2,12 @@

use bt_topshim::btif::BluetoothInterface;
use bt_topshim::profiles::a2dp::{
    A2dp, A2dpCallbacks, A2dpCallbacksDispatcher, BtavConnectionState,
    A2dp, A2dpCallbacks, A2dpCallbacksDispatcher, A2dpCodecBitsPerSample, A2dpCodecChannelMode,
    A2dpCodecSampleRate, BtavConnectionState,
};
use bt_topshim::topstack;

use std::convert::TryFrom;
use std::sync::Arc;
use std::sync::Mutex;

@@ -22,8 +24,14 @@ pub trait IBluetoothMedia {
    fn connect(&mut self, device: String);
    fn set_active_device(&mut self, device: String);
    fn disconnect(&mut self, device: String);
    fn start_session(&mut self);
    fn stop_session(&mut self);
    fn set_audio_config(
        &mut self,
        sample_rate: i32,
        bits_per_sample: i32,
        channel_mode: i32,
    ) -> bool;
    fn start_audio_request(&mut self);
    fn stop_audio_request(&mut self);
}

pub trait IBluetoothMediaCallback {
@@ -120,10 +128,27 @@ impl IBluetoothMedia for BluetoothMedia {
        self.a2dp.as_mut().unwrap().disconnect(device);
    }

    fn start_session(&mut self) {
        self.a2dp.as_mut().unwrap().start_session();
    fn set_audio_config(
        &mut self,
        sample_rate: i32,
        bits_per_sample: i32,
        channel_mode: i32,
    ) -> bool {
        if !A2dpCodecSampleRate::validate_bits(sample_rate)
            || !A2dpCodecBitsPerSample::validate_bits(bits_per_sample)
            || !A2dpCodecChannelMode::validate_bits(channel_mode)
        {
            return false;
        }
    fn stop_session(&mut self) {
        self.a2dp.as_mut().unwrap().stop_session();
        self.a2dp.as_mut().unwrap().set_audio_config(sample_rate, bits_per_sample, channel_mode);
        true
    }

    fn start_audio_request(&mut self) {
        self.a2dp.as_mut().unwrap().start_audio_request();
    }

    fn stop_audio_request(&mut self) {
        self.a2dp.as_mut().unwrap().stop_audio_request();
    }
}
+8 −0
Original line number Diff line number Diff line
@@ -203,6 +203,14 @@ int A2dpIntf::config_codec(RustRawAddress bt_addr, ::rust::Vec<A2dpCodecConfig>
void A2dpIntf::cleanup() {
  // TODO: Implement.
}
bool A2dpIntf::set_audio_config(A2dpCodecConfig rconfig) {
  bluetooth::audio::a2dp::AudioConfig config = {
      .sample_rate = static_cast<btav_a2dp_codec_sample_rate_t>(rconfig.sample_rate),
      .bits_per_sample = static_cast<btav_a2dp_codec_bits_per_sample_t>(rconfig.bits_per_sample),
      .channel_mode = static_cast<btav_a2dp_codec_channel_mode_t>(rconfig.channel_mode),
  };
  return bluetooth::audio::a2dp::SetAudioConfig(config);
}
bool A2dpIntf::start_audio_request() {
  return bluetooth::audio::a2dp::StartRequest();
}
+1 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ class A2dpIntf {
  void cleanup();

  // interface for Audio server
  bool set_audio_config(A2dpCodecConfig rconfig);
  bool start_audio_request();
  bool stop_audio_request();
  bluetooth::audio::a2dp::PresentationPosition get_presentation_position();
Loading