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

Commit 1ce307dd authored by Alice Kuo's avatar Alice Kuo Committed by Automerger Merge Worker
Browse files

Add onSessionEnded handle for HIDL 2.2 am: f33cea94 am: 6fe71755 am: 99a712ab

Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/1928381

Change-Id: I83b9e0f240a9d8ace9204c8ded063063d7663148
parents 4ae017c4 99a712ab
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -76,6 +76,12 @@ class BluetoothAudioSessionControl_2_2 {
    } else if (session_type ==
    } else if (session_type ==
               SessionType_2_1::A2DP_HARDWARE_OFFLOAD_DATAPATH) {
               SessionType_2_1::A2DP_HARDWARE_OFFLOAD_DATAPATH) {
      return BluetoothAudioSession_2_2::kInvalidOffloadAudioConfiguration;
      return BluetoothAudioSession_2_2::kInvalidOffloadAudioConfiguration;
    } else if (
        session_type ==
            SessionType_2_1::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH ||
        session_type ==
            SessionType_2_1::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH) {
      return BluetoothAudioSession_2_2::kInvalidLeOffloadAudioConfiguration;
    } else {
    } else {
      return BluetoothAudioSession_2_2::kInvalidSoftwareAudioConfiguration;
      return BluetoothAudioSession_2_2::kInvalidSoftwareAudioConfiguration;
    }
    }
+1 −1
Original line number Original line Diff line number Diff line
@@ -48,7 +48,7 @@ class BluetoothAudioSessionReport_2_2 {
    std::shared_ptr<BluetoothAudioSession_2_2> session_ptr =
    std::shared_ptr<BluetoothAudioSession_2_2> session_ptr =
        BluetoothAudioSessionInstance_2_2::GetSessionInstance(session_type);
        BluetoothAudioSessionInstance_2_2::GetSessionInstance(session_type);
    if (session_ptr != nullptr) {
    if (session_ptr != nullptr) {
      session_ptr->GetAudioSession()->OnSessionEnded();
      session_ptr->OnSessionEnded();
    }
    }
  }
  }
  // The API reports the Bluetooth stack has replied the result of startStream
  // The API reports the Bluetooth stack has replied the result of startStream
+69 −5
Original line number Original line Diff line number Diff line
@@ -29,6 +29,13 @@ namespace audio {
using ::android::hardware::audio::common::V5_0::AudioSource;
using ::android::hardware::audio::common::V5_0::AudioSource;
using ::android::hardware::audio::common::V5_0::RecordTrackMetadata;
using ::android::hardware::audio::common::V5_0::RecordTrackMetadata;
using ::android::hardware::audio::common::V5_0::SinkMetadata;
using ::android::hardware::audio::common::V5_0::SinkMetadata;
using ::android::hardware::bluetooth::audio::V2_0::BitsPerSample;
using ::android::hardware::bluetooth::audio::V2_0::ChannelMode;
using ::android::hardware::bluetooth::audio::V2_2::LeAudioConfiguration;
using ::android::hardware::bluetooth::audio::V2_2::LeAudioMode;
using PcmParameters_2_1 =
    ::android::hardware::bluetooth::audio::V2_1::PcmParameters;
using SampleRate_2_1 = ::android::hardware::bluetooth::audio::V2_1::SampleRate;


using SessionType_2_1 =
using SessionType_2_1 =
    ::android::hardware::bluetooth::audio::V2_1::SessionType;
    ::android::hardware::bluetooth::audio::V2_1::SessionType;
@@ -38,10 +45,24 @@ using SessionType_2_0 =
using AudioConfiguration_2_1 =
using AudioConfiguration_2_1 =
    ::android::hardware::bluetooth::audio::V2_1::AudioConfiguration;
    ::android::hardware::bluetooth::audio::V2_1::AudioConfiguration;


static constexpr PcmParameters_2_1 kInvalidPcmParameters = {
    .sampleRate = SampleRate_2_1::RATE_UNKNOWN,
    .channelMode = ChannelMode::UNKNOWN,
    .bitsPerSample = BitsPerSample::BITS_UNKNOWN,
    .dataIntervalUs = 0,
};

static LeAudioConfiguration kInvalidLeAudioConfig = {
    .mode = LeAudioMode::UNKNOWN,
    .config = {},
};

::android::hardware::bluetooth::audio::V2_2::AudioConfiguration
::android::hardware::bluetooth::audio::V2_2::AudioConfiguration
    BluetoothAudioSession_2_2::invalidSoftwareAudioConfiguration = {};
    BluetoothAudioSession_2_2::invalidSoftwareAudioConfiguration = {};
::android::hardware::bluetooth::audio::V2_2::AudioConfiguration
::android::hardware::bluetooth::audio::V2_2::AudioConfiguration
    BluetoothAudioSession_2_2::invalidOffloadAudioConfiguration = {};
    BluetoothAudioSession_2_2::invalidOffloadAudioConfiguration = {};
::android::hardware::bluetooth::audio::V2_2::AudioConfiguration
    BluetoothAudioSession_2_2::invalidLeOffloadAudioConfiguration = {};


using IBluetoothAudioPort_2_2 =
using IBluetoothAudioPort_2_2 =
    ::android::hardware::bluetooth::audio::V2_2::IBluetoothAudioPort;
    ::android::hardware::bluetooth::audio::V2_2::IBluetoothAudioPort;
@@ -72,6 +93,10 @@ BluetoothAudioSession_2_2::BluetoothAudioSession_2_2(
  } else {
  } else {
    session_type_2_1_ = (session_type);
    session_type_2_1_ = (session_type);
  }
  }
  invalidSoftwareAudioConfiguration.pcmConfig(kInvalidPcmParameters);
  invalidOffloadAudioConfiguration.codecConfig(
      audio_session->kInvalidCodecConfiguration);
  invalidLeOffloadAudioConfiguration.leAudioConfig(kInvalidLeAudioConfig);
}
}


bool BluetoothAudioSession_2_2::IsSessionReady() {
bool BluetoothAudioSession_2_2::IsSessionReady() {
@@ -149,9 +174,17 @@ const ::android::hardware::bluetooth::audio::V2_2::AudioConfiguration
BluetoothAudioSession_2_2::GetAudioConfig() {
BluetoothAudioSession_2_2::GetAudioConfig() {
  std::lock_guard<std::recursive_mutex> guard(audio_session->mutex_);
  std::lock_guard<std::recursive_mutex> guard(audio_session->mutex_);
  if (IsSessionReady()) {
  if (IsSessionReady()) {
    auto audio_config_discriminator = audio_config_2_2_.getDiscriminator();
    // If session is unknown it means it should be 2.0 type
    // If session is unknown it means it should be 2.0 type
    if (session_type_2_1_ != SessionType_2_1::UNKNOWN) {
    if (session_type_2_1_ != SessionType_2_1::UNKNOWN) {
      if (audio_config_2_2_ != invalidSoftwareAudioConfiguration)
      if ((audio_config_discriminator ==
               ::android::hardware::bluetooth::audio::V2_2::AudioConfiguration::
                   hidl_discriminator::pcmConfig &&
           audio_config_2_2_ != kInvalidSoftwareAudioConfiguration) ||
          (audio_config_discriminator ==
               ::android::hardware::bluetooth::audio::V2_2::AudioConfiguration::
                   hidl_discriminator::leAudioConfig &&
           audio_config_2_2_ != kInvalidLeOffloadAudioConfiguration))
        return audio_config_2_2_;
        return audio_config_2_2_;


      ::android::hardware::bluetooth::audio::V2_2::AudioConfiguration toConf;
      ::android::hardware::bluetooth::audio::V2_2::AudioConfiguration toConf;
@@ -181,8 +214,10 @@ BluetoothAudioSession_2_2::GetAudioConfig() {
    }
    }
    return toConf;
    return toConf;
  } else if (session_type_2_1_ ==
  } else if (session_type_2_1_ ==
             SessionType_2_1::A2DP_HARDWARE_OFFLOAD_DATAPATH) {
                 SessionType_2_1::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH ||
    return kInvalidOffloadAudioConfiguration;
             session_type_2_1_ ==
                 SessionType_2_1::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH) {
    return kInvalidLeOffloadAudioConfiguration;
  } else {
  } else {
    return kInvalidSoftwareAudioConfiguration;
    return kInvalidSoftwareAudioConfiguration;
  }
  }
@@ -314,8 +349,11 @@ void BluetoothAudioSession_2_2::OnSessionStarted(
      LOG(ERROR) << __func__ << " - SessionType=" << toString(session_type_2_1_)
      LOG(ERROR) << __func__ << " - SessionType=" << toString(session_type_2_1_)
                 << " DataMQ Invalid";
                 << " DataMQ Invalid";
      audio_config_2_2_ =
      audio_config_2_2_ =
          (session_type_2_1_ == SessionType_2_1::A2DP_HARDWARE_OFFLOAD_DATAPATH
          ((session_type_2_1_ ==
               ? kInvalidOffloadAudioConfiguration
                SessionType_2_1::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH ||
            session_type_2_1_ ==
                SessionType_2_1::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH)
               ? kInvalidLeOffloadAudioConfiguration
               : kInvalidSoftwareAudioConfiguration);
               : kInvalidSoftwareAudioConfiguration);
    } else {
    } else {
      audio_session->stack_iface_ = stack_iface;
      audio_session->stack_iface_ = stack_iface;
@@ -326,6 +364,32 @@ void BluetoothAudioSession_2_2::OnSessionStarted(
  }
  }
}
}


// The report function is used to report that the Bluetooth stack has ended the
// session, and will invoke session_changed_cb_ to notify registered
// bluetooth_audio outputs
void BluetoothAudioSession_2_2::OnSessionEnded() {
  std::lock_guard<std::recursive_mutex> guard(audio_session->mutex_);
  bool toggled = IsSessionReady();
  LOG(INFO) << __func__ << " - SessionType=" << toString(session_type_2_1_);
  if (session_type_2_1_ == SessionType_2_1::UNKNOWN) {
    audio_session->OnSessionEnded();
    return;
  }

  audio_config_2_2_ =
      ((session_type_2_1_ ==
            SessionType_2_1::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH ||
        session_type_2_1_ ==
            SessionType_2_1::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH)
           ? kInvalidLeOffloadAudioConfiguration
           : kInvalidSoftwareAudioConfiguration);
  audio_session->stack_iface_ = nullptr;
  audio_session->UpdateDataPath(nullptr);
  if (toggled) {
    audio_session->ReportSessionStatus();
  }
}

std::unique_ptr<BluetoothAudioSessionInstance_2_2>
std::unique_ptr<BluetoothAudioSessionInstance_2_2>
    BluetoothAudioSessionInstance_2_2::instance_ptr =
    BluetoothAudioSessionInstance_2_2::instance_ptr =
        std::unique_ptr<BluetoothAudioSessionInstance_2_2>(
        std::unique_ptr<BluetoothAudioSessionInstance_2_2>(
+10 −0
Original line number Original line Diff line number Diff line
@@ -47,6 +47,8 @@ class BluetoothAudioSession_2_2 {
      invalidSoftwareAudioConfiguration;
      invalidSoftwareAudioConfiguration;
  static ::android::hardware::bluetooth::audio::V2_2::AudioConfiguration
  static ::android::hardware::bluetooth::audio::V2_2::AudioConfiguration
      invalidOffloadAudioConfiguration;
      invalidOffloadAudioConfiguration;
  static ::android::hardware::bluetooth::audio::V2_2::AudioConfiguration
      invalidLeOffloadAudioConfiguration;


 public:
 public:
  BluetoothAudioSession_2_2(
  BluetoothAudioSession_2_2(
@@ -69,6 +71,11 @@ class BluetoothAudioSession_2_2 {
      const ::android::hardware::bluetooth::audio::V2_2::AudioConfiguration&
      const ::android::hardware::bluetooth::audio::V2_2::AudioConfiguration&
          audio_config);
          audio_config);


  // The report function is used to report that the Bluetooth stack has ended
  // the session, and will invoke session_changed_cb_ to notify registered
  // bluetooth_audio outputs
  void OnSessionEnded();

  // Those control functions are for the bluetooth_audio module to start,
  // Those control functions are for the bluetooth_audio module to start,
  // suspend, stop stream, to check position, and to update metadata.
  // suspend, stop stream, to check position, and to update metadata.
  bool StartStream();
  bool StartStream();
@@ -88,6 +95,9 @@ class BluetoothAudioSession_2_2 {
  static constexpr ::android::hardware::bluetooth::audio::V2_2::
  static constexpr ::android::hardware::bluetooth::audio::V2_2::
      AudioConfiguration& kInvalidOffloadAudioConfiguration =
      AudioConfiguration& kInvalidOffloadAudioConfiguration =
          invalidOffloadAudioConfiguration;
          invalidOffloadAudioConfiguration;
  static constexpr ::android::hardware::bluetooth::audio::V2_2::
      AudioConfiguration& kInvalidLeOffloadAudioConfiguration =
          invalidLeOffloadAudioConfiguration;
};
};


class BluetoothAudioSessionInstance_2_2 {
class BluetoothAudioSessionInstance_2_2 {