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

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

Merge "floss: Add HFP hal"

parents 87c96961 1667430d
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -136,6 +136,7 @@ cc_library_static {
        "acl/btm_pm.cc",
        "acl/btm_pm.cc",
        "btm/btm_sco.cc",
        "btm/btm_sco.cc",
        "btm/btm_sco_hci.cc",
        "btm/btm_sco_hci.cc",
        "btm/btm_sco_hfp_hal.cc",
        "btm/btm_iso.cc",
        "btm/btm_iso.cc",
        "btm/btm_sec.cc",
        "btm/btm_sec.cc",
        "btm/btm_scn.cc",
        "btm/btm_scn.cc",
@@ -819,6 +820,7 @@ cc_test {
        "btm/btm_main.cc",
        "btm/btm_main.cc",
        "btm/btm_sco.cc",
        "btm/btm_sco.cc",
        "btm/btm_sco_hci.cc",
        "btm/btm_sco_hci.cc",
        "btm/btm_sco_hfp_hal.cc",
        "btm/btm_scn.cc",
        "btm/btm_scn.cc",
        "btm/btm_sec.cc",
        "btm/btm_sec.cc",
        "metrics/stack_metrics_logging.cc",
        "metrics/stack_metrics_logging.cc",
+1 −0
Original line number Original line Diff line number Diff line
@@ -122,6 +122,7 @@ source_set("stack") {
    "btm/btm_scn.cc",
    "btm/btm_scn.cc",
    "btm/btm_sco.cc",
    "btm/btm_sco.cc",
    "btm/btm_sco_hci.cc",
    "btm/btm_sco_hci.cc",
    "btm/btm_sco_hfp_hal_linux.cc",
    "btm/btm_sec.cc",
    "btm/btm_sec.cc",
    "btu/btu_hcif.cc",
    "btu/btu_hcif.cc",
    "btu/btu_task.cc",
    "btu/btu_task.cc",
+2 −0
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@
#include <cstdint>
#include <cstdint>
#include <string>
#include <string>


#include "btm_sco_hfp_hal.h"
#include "device/include/esco_parameters.h"
#include "device/include/esco_parameters.h"
#include "stack/include/btm_api_types.h"
#include "stack/include/btm_api_types.h"


@@ -137,6 +138,7 @@ typedef struct {


  void Init() {
  void Init() {
    def_esco_parms = esco_parameters_for_codec(ESCO_CODEC_CVSD_S3);
    def_esco_parms = esco_parameters_for_codec(ESCO_CODEC_CVSD_S3);
    hfp_hal_interface::init();
  }
  }


  void Free() { bluetooth::audio::sco::cleanup(); }
  void Free() { bluetooth::audio::sco::cleanup(); }
+90 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "btm_sco_hfp_hal.h"

#include <vector>

#include "device/include/esco_parameters.h"

namespace hfp_hal_interface {
namespace {
bool offload_supported = true;
bool offload_enabled = true;
std::vector<bt_codec> cached_codecs;
}  // namespace

// Android implementation only has consts. Initialize CVSD and MSBC to PCM
// offloaded defaults.
void init() {
  bt_codec cvsd = {
      .codec = codec::CVSD,
      .data_path = ESCO_DATA_PATH_PCM,
  };

  bt_codec msbc = {
      .codec = codec::MSBC,
      .data_path = ESCO_DATA_PATH_PCM,
  };

  cached_codecs.clear();
  cached_codecs.emplace_back(cvsd);
  cached_codecs.emplace_back(msbc);
}

// Android statically compiles WBS support.
bool get_wbs_supported() { return !DISABLE_WBS; }

// Checks the supported codecs
bt_codecs get_codec_capabilities(uint64_t codecs) {
  bt_codecs codec_list = {.offload_capable = offload_supported};

  for (auto c : cached_codecs) {
    if (c.codec & codecs) {
      codec_list.codecs.push_back(c);
    }
  }

  return codec_list;
}

// Check if hardware offload is supported
bool get_offload_supported() { return offload_supported; }

// Check if hardware offload is enabled
bool get_offload_enabled() { return offload_supported && offload_enabled; }

// Set offload enable/disable
bool enable_offload(bool enable) {
  if (!offload_supported) {
    return false;
  }
  offload_enabled = enable;
  return true;
}

// Notify the codec datapath to lower layer for offload mode.
bool set_codec_datapath(int codec) { return true; }

// No packet size limits on Android since it will be offloaded.
int get_packet_size(int codec) { return kDefaultPacketSize; }

void notify_sco_connection_change(RawAddress device, bool is_connected,
                                  int codec) {
  // Do nothing since this is handled by Android's audio hidl.
}

}  // namespace hfp_hal_interface
+80 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <stdint.h>

#include <vector>

#include "bt_target.h"
#include "raw_address.h"

// Used by the Bluetooth stack to get WBS supported and codec, or notify SCO
// connection change to lower layer (kernel) when SCO-over-HCI is used. So far
// ChromeOS uses SCO-over-HCI; usually Android phone uses hardware SCO route so
// it doesn't apply here.
namespace hfp_hal_interface {
enum codec : uint64_t {
  CVSD = 1 << 0,
  MSBC_TRANSPARENT = 1 << 1,
  MSBC = 1 << 2,
};

struct bt_codec {
  codec codec;
  uint8_t data_path;
  std::vector<uint8_t> data;
};

struct bt_codecs {
  bool offload_capable;
  std::vector<bt_codec> codecs;
};

// Use default packet size for codec if this value is given.
constexpr int kDefaultPacketSize = 0;

// Initialize the SCO HFP HAL module
void init();

// Check if wideband speech is supported on local device.
bool get_wbs_supported();

// Checks the details of the codecs (specified as a bitmask of enum codec).
bt_codecs get_codec_capabilities(uint64_t codecs);

// Check if hardware offload is supported.
bool get_offload_supported();

// Check if hardware offload is enabled.
bool get_offload_enabled();

// Set offload enable/disable.
bool enable_offload(bool enable);

// Notify the codec datapath to lower layer for offload mode.
// TODO - This api may become unnecessary depending on how this is integrated.
bool set_codec_datapath(int codec);

// Get the maximum supported packet size from the lower layer.
int get_packet_size(int codec);

// Notify the lower layer about SCO connection change.
void notify_sco_connection_change(RawAddress device, bool is_connected,
                                  int codec);

}  // namespace hfp_hal_interface
Loading