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

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

Merge "Add support for bluetooth.audio@2.2 HIDL version"

parents c060d785 c5275a3c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ cc_library_shared {
    shared_libs: [
        "android.hardware.bluetooth.audio@2.0",
        "android.hardware.bluetooth.audio@2.1",
        "android.hardware.bluetooth.audio@2.2",
        "libaudioutils",
        "libbase",
        "libbluetooth_audio_session",
+19 −19
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@
#include <log/log.h>
#include <stdlib.h>

#include "BluetoothAudioSessionControl_2_1.h"
#include "BluetoothAudioSessionControl_2_2.h"
#include "device_port_proxy.h"
#include "stream_apis.h"
#include "utils.h"
@@ -33,7 +33,7 @@ namespace bluetooth {
namespace audio {

using ::android::base::StringPrintf;
using ::android::bluetooth::audio::BluetoothAudioSessionControl_2_1;
using ::android::bluetooth::audio::BluetoothAudioSessionControl_2_2;
using ::android::hardware::bluetooth::audio::V2_0::BitsPerSample;
using ::android::hardware::bluetooth::audio::V2_0::ChannelMode;
using ::android::hardware::bluetooth::audio::V2_0::PcmParameters;
@@ -151,7 +151,7 @@ bool BluetoothAudioPort::SetUp(audio_devices_t devices) {
  ::android::bluetooth::audio::PortStatusCallbacks cbacks = {
      .control_result_cb_ = control_result_cb,
      .session_changed_cb_ = session_changed_cb};
  cookie_ = BluetoothAudioSessionControl_2_1::RegisterControlResultCback(
  cookie_ = BluetoothAudioSessionControl_2_2::RegisterControlResultCback(
      session_type_, cbacks);
  LOG(INFO) << __func__ << ": session_type=" << toString(session_type_) << ", cookie=" << StringPrintf("%#hx", cookie_);

@@ -195,7 +195,7 @@ bool BluetoothAudioPort::init_session_type(audio_devices_t device) {
      return false;
  }

  if (!BluetoothAudioSessionControl_2_1::IsSessionReady(session_type_)) {
  if (!BluetoothAudioSessionControl_2_2::IsSessionReady(session_type_)) {
    LOG(ERROR) << __func__ << ": device=" << StringPrintf("%#x", device) << ", session_type=" << toString(session_type_)
               << " is not ready";
    return false;
@@ -211,7 +211,7 @@ void BluetoothAudioPort::TearDown() {
  }

  LOG(INFO) << __func__ << ": session_type=" << toString(session_type_) << ", cookie=" << StringPrintf("%#hx", cookie_);
  BluetoothAudioSessionControl_2_1::UnregisterControlResultCback(session_type_,
  BluetoothAudioSessionControl_2_2::UnregisterControlResultCback(session_type_,
                                                                 cookie_);
  cookie_ = android::bluetooth::audio::kObserversCookieUndefined;
}
@@ -293,11 +293,11 @@ bool BluetoothAudioPortOut::LoadAudioConfig(audio_config_t* audio_cfg) const {
    return false;
  }

  const ::android::hardware::bluetooth::audio::V2_1::AudioConfiguration&
  const ::android::hardware::bluetooth::audio::V2_2::AudioConfiguration&
      hal_audio_cfg =
          BluetoothAudioSessionControl_2_1::GetAudioConfig(session_type_);
          BluetoothAudioSessionControl_2_2::GetAudioConfig(session_type_);
  if (hal_audio_cfg.getDiscriminator() !=
      ::android::hardware::bluetooth::audio::V2_1::AudioConfiguration::
      ::android::hardware::bluetooth::audio::V2_2::AudioConfiguration::
          hidl_discriminator::pcmConfig) {
    audio_cfg->sample_rate = kBluetoothDefaultSampleRate;
    audio_cfg->channel_mask = kBluetoothDefaultOutputChannelModeMask;
@@ -332,11 +332,11 @@ bool BluetoothAudioPortIn::LoadAudioConfig(audio_config_t* audio_cfg) const {
    return false;
  }

  const ::android::hardware::bluetooth::audio::V2_1::AudioConfiguration&
  const ::android::hardware::bluetooth::audio::V2_2::AudioConfiguration&
      hal_audio_cfg =
          BluetoothAudioSessionControl_2_1::GetAudioConfig(session_type_);
          BluetoothAudioSessionControl_2_2::GetAudioConfig(session_type_);
  if (hal_audio_cfg.getDiscriminator() !=
      ::android::hardware::bluetooth::audio::V2_1::AudioConfiguration::
      ::android::hardware::bluetooth::audio::V2_2::AudioConfiguration::
          hidl_discriminator::pcmConfig) {
    audio_cfg->sample_rate = kBluetoothDefaultSampleRate;
    audio_cfg->channel_mask = kBluetoothDefaultInputChannelModeMask;
@@ -401,7 +401,7 @@ bool BluetoothAudioPort::Start() {
  bool retval = false;
  if (state_ == BluetoothStreamState::STANDBY) {
    state_ = BluetoothStreamState::STARTING;
    if (BluetoothAudioSessionControl_2_1::StartStream(session_type_)) {
    if (BluetoothAudioSessionControl_2_2::StartStream(session_type_)) {
      retval = CondwaitState(BluetoothStreamState::STARTING);
    } else {
      LOG(ERROR) << __func__ << ": session_type=" << toString(session_type_)
@@ -432,7 +432,7 @@ bool BluetoothAudioPort::Suspend() {
  bool retval = false;
  if (state_ == BluetoothStreamState::STARTED) {
    state_ = BluetoothStreamState::SUSPENDING;
    if (BluetoothAudioSessionControl_2_1::SuspendStream(session_type_)) {
    if (BluetoothAudioSessionControl_2_2::SuspendStream(session_type_)) {
      retval = CondwaitState(BluetoothStreamState::SUSPENDING);
    } else {
      LOG(ERROR) << __func__ << ": session_type=" << toString(session_type_)
@@ -459,7 +459,7 @@ void BluetoothAudioPort::Stop() {
  LOG(INFO) << __func__ << ": session_type=" << toString(session_type_) << ", cookie=" << StringPrintf("%#hx", cookie_)
            << ", state=" << state_ << " request";
  state_ = BluetoothStreamState::DISABLED;
  BluetoothAudioSessionControl_2_1::StopStream(session_type_);
  BluetoothAudioSessionControl_2_2::StopStream(session_type_);
  LOG(INFO) << __func__ << ": session_type=" << toString(session_type_) << ", cookie=" << StringPrintf("%#hx", cookie_)
            << ", state=" << state_ << " done";
}
@@ -467,7 +467,7 @@ void BluetoothAudioPort::Stop() {
size_t BluetoothAudioPortOut::WriteData(const void* buffer, size_t bytes) const {
  if (!in_use()) return 0;
  if (!is_stereo_to_mono_) {
    return BluetoothAudioSessionControl_2_1::OutWritePcmData(session_type_,
    return BluetoothAudioSessionControl_2_2::OutWritePcmData(session_type_,
                                                             buffer, bytes);
  }

@@ -478,14 +478,14 @@ size_t BluetoothAudioPortOut::WriteData(const void* buffer, size_t bytes) const
  std::unique_ptr<int16_t[]> dst{new int16_t[write_frames]};
  downmix_to_mono_i16_from_stereo_i16(dst.get(), src, write_frames);
  // a frame is 16 bits, and the size of a mono frame is equal to half a stereo.
  return BluetoothAudioSessionControl_2_1::OutWritePcmData(
  return BluetoothAudioSessionControl_2_2::OutWritePcmData(
             session_type_, dst.get(), write_frames * 2) *
         2;
}

size_t BluetoothAudioPortIn::ReadData(void* buffer, size_t bytes) const {
  if (!in_use()) return 0;
  return BluetoothAudioSessionControl_2_1::InReadPcmData(session_type_, buffer,
  return BluetoothAudioSessionControl_2_2::InReadPcmData(session_type_, buffer,
                                                         bytes);
}

@@ -496,7 +496,7 @@ bool BluetoothAudioPort::GetPresentationPosition(uint64_t* delay_ns,
    LOG(ERROR) << __func__ << ": BluetoothAudioPort is not in use";
    return false;
  }
  bool retval = BluetoothAudioSessionControl_2_1::GetPresentationPosition(
  bool retval = BluetoothAudioSessionControl_2_2::GetPresentationPosition(
      session_type_, delay_ns, bytes, timestamp);
  LOG(VERBOSE) << __func__ << ": session_type=" << StringPrintf("%#hhx", session_type_)
               << ", cookie=" << StringPrintf("%#hx", cookie_) << ", state=" << state_ << ", delay=" << *delay_ns
@@ -515,7 +515,7 @@ void BluetoothAudioPort::UpdateMetadata(
  LOG(DEBUG) << __func__ << ": session_type=" << toString(session_type_) << ", cookie=" << StringPrintf("%#hx", cookie_)
             << ", state=" << state_ << ", " << source_metadata->track_count << " track(s)";
  if (source_metadata->track_count == 0) return;
  BluetoothAudioSessionControl_2_1::UpdateTracksMetadata(session_type_,
  BluetoothAudioSessionControl_2_2::UpdateTracksMetadata(session_type_,
                                                         source_metadata);
}

+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

#pragma once

#include <android/hardware/bluetooth/audio/2.1/types.h>
#include <android/hardware/bluetooth/audio/2.2/types.h>
#include <hardware/audio.h>
#include <condition_variable>
#include <mutex>
+2 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ cc_library_static {
    shared_libs: [
        "android.hardware.bluetooth.audio@2.0",
        "android.hardware.bluetooth.audio@2.1",
        "android.hardware.bluetooth.audio@2.2",
        "libhidlbase",
    ],
    static_libs: [
@@ -71,6 +72,7 @@ cc_test {
    shared_libs: [
        "android.hardware.bluetooth.audio@2.0",
        "android.hardware.bluetooth.audio@2.1",
        "android.hardware.bluetooth.audio@2.2",
        "libcutils",
        "libfmq",
        "libhidlbase",
+1 −1
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ class A2dpTransport
    : public ::bluetooth::audio::IBluetoothSinkTransportInstance {
 public:
  A2dpTransport(SessionType sessionType)
      : IBluetoothSinkTransportInstance(sessionType, {}),
      : IBluetoothSinkTransportInstance(sessionType, (AudioConfiguration){}),
        total_bytes_read_(0),
        data_position_({}) {
    a2dp_pending_cmd_ = A2DP_CTRL_CMD_NONE;
Loading