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

Commit ab27e306 authored by Cheney Ni's avatar Cheney Ni Committed by Automerger Merge Worker
Browse files

service: A2DP source callback to query the preferred codec am: 8617330d

Change-Id: Ic2ef3f132aa689b1b738dedf2f8067aa3afc32e0
parents 149a59f5 8617330d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ btserviceBaseTestSrc = [
    "hal/fake_bluetooth_gatt_interface.cc",
    "hal/fake_bluetooth_interface.cc",
    "test/a2dp_sink_unittest.cc",
    "test/a2dp_source_unittest.cc",
    "test/adapter_unittest.cc",
    "test/advertise_data_unittest.cc",
    "test/fake_hal_util.cc",
+7 −0
Original line number Diff line number Diff line
@@ -199,6 +199,13 @@ void A2dpSource::AudioConfigCallback(
                             codecs_selectable_capabilities);
}

bool A2dpSource::MandatoryCodecPreferredCallback(BluetoothAvInterface* iface,
                                                 const RawAddress& bd_addr) {
  LockGuard lock(delegate_mutex_);
  // Do nothing. Optional codecs are preferred by default.
  return false;
}

// A2dpSourceFactory implementation
// ========================================================
A2dpSourceFactory::A2dpSourceFactory() = default;
+2 −0
Original line number Diff line number Diff line
@@ -82,6 +82,8 @@ class A2dpSource : public BluetoothInstance,
      const std::vector<btav_a2dp_codec_config_t> codecs_local_capabilities,
      const std::vector<btav_a2dp_codec_config_t>
          codecs_selectable_capabilities) override;
  bool MandatoryCodecPreferredCallback(hal::BluetoothAvInterface* iface,
                                       const RawAddress& bd_addr) override;

  // For |GetAppIdentifier|.
  const Uuid app_identifier_;
+20 −2
Original line number Diff line number Diff line
@@ -46,11 +46,11 @@ GetA2dpSourceObservers();
base::ObserverList<BluetoothAvInterface::A2dpSinkObserver>*
GetA2dpSinkObservers();

#define VERIFY_INTERFACE_OR_RETURN()                                   \
#define VERIFY_INTERFACE_OR_RETURN(...)                                \
  do {                                                                 \
    if (!g_interface) {                                                \
      LOG(WARNING) << "Callback received while |g_interface| is NULL"; \
      return;                                                          \
      return __VA_ARGS__;                                              \
    }                                                                  \
  } while (0)

@@ -88,6 +88,17 @@ void SourceAudioConfigCallback(
  }
}

bool SourceMandatoryCodecPreferredCallback(const RawAddress& bd_addr) {
  VERIFY_INTERFACE_OR_RETURN(false);
  // The mandatory codec is preferred only when all observers disable their
  // optional codecs.
  for (auto& observer : *GetA2dpSourceObservers()) {
    if (!observer.MandatoryCodecPreferredCallback(g_interface, bd_addr))
      return false;
  }
  return true;
}

void SinkConnectionStateCallback(const RawAddress& bd_addr,
                                 btav_connection_state_t state) {
  std::shared_lock<shared_mutex_impl> lock(g_instance_lock);
@@ -121,6 +132,7 @@ btav_source_callbacks_t av_source_callbacks = {
    .connection_state_cb = SourceConnectionStateCallback,
    .audio_state_cb = SourceAudioStateCallback,
    .audio_config_cb = SourceAudioConfigCallback,
    .mandatory_codec_preferred_cb = SourceMandatoryCodecPreferredCallback,
};

btav_sink_callbacks_t av_sink_callbacks = {
@@ -297,6 +309,12 @@ void BluetoothAvInterface::A2dpSourceObserver::AudioConfigCallback(
  // Do nothing.
}

bool BluetoothAvInterface::A2dpSourceObserver::MandatoryCodecPreferredCallback(
    BluetoothAvInterface* iface, const RawAddress& bd_addr) {
  // Do nothing.
  return false;
}

void BluetoothAvInterface::A2dpSinkObserver::ConnectionStateCallback(
    BluetoothAvInterface* iface, const RawAddress& bd_addr,
    btav_connection_state_t state) {
+2 −0
Original line number Diff line number Diff line
@@ -41,6 +41,8 @@ class BluetoothAvInterface {
        const std::vector<btav_a2dp_codec_config_t> codecs_local_capabilities,
        const std::vector<btav_a2dp_codec_config_t>
            codecs_selectable_capabilities);
    virtual bool MandatoryCodecPreferredCallback(BluetoothAvInterface* iface,
                                                 const RawAddress& bd_addr);

   protected:
    virtual ~A2dpSourceObserver() = default;
Loading