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

Commit dc9fadd7 authored by Jeremy Wu's avatar Jeremy Wu
Browse files

Floss: enable LC3 as a SW codec in HFP

In this CL, we enable LC3 SW path codec in HFP.

Note that this feature is not enabled in CrOS at the moment, and Android
does not use SW path as of now.

Bug: 269970706
Tag: #floss
Test: Build and verify
Change-Id: Idf426b36f775d23f510a90d1cf0cf868a25aaf9b
parent 9e9b9300
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -138,6 +138,7 @@ struct CoreInterface {

  // codecs
  CodecInterface* msbcCodec;
  CodecInterface* lc3Codec;

  // DO NOT add any more methods here
  HACK_ProfileInterface* profileSpecific_HACK;
@@ -150,10 +151,12 @@ struct CoreInterface {

  CoreInterface(EventCallbacks* eventCallbacks,
                ConfigInterface* configInterface, CodecInterface* msbcCodec,
                CodecInterface* lc3Codec,
                HACK_ProfileInterface* profileSpecific_HACK)
      : events{eventCallbacks},
        config{configInterface},
        msbcCodec{msbcCodec},
        lc3Codec{lc3Codec},
        profileSpecific_HACK{profileSpecific_HACK} {};

  CoreInterface(const CoreInterface&) = delete;
+26 −1
Original line number Diff line number Diff line
@@ -106,6 +106,8 @@
#include "stack/include/avdt_api.h"
#include "stack/include/btm_api.h"
#include "stack/include/btu.h"
#include "stack/include/hfp_lc3_decoder.h"
#include "stack/include/hfp_lc3_encoder.h"
#include "stack/include/hfp_msbc_decoder.h"
#include "stack/include/hfp_msbc_encoder.h"
#include "stack/include/hidh_api.h"
@@ -231,6 +233,28 @@ struct MSBCCodec : bluetooth::core::CodecInterface {
  }
};

struct LC3Codec : bluetooth::core::CodecInterface {
  LC3Codec() : bluetooth::core::CodecInterface(){};

  void initialize() override {
    hfp_lc3_decoder_init();
    hfp_lc3_encoder_init();
  }

  void cleanup() override {
    hfp_lc3_encoder_cleanup();
    hfp_lc3_decoder_cleanup();
  }

  uint32_t encodePacket(int16_t* input, uint8_t* output) {
    return hfp_lc3_encode_frames(input, output);
  }

  bool decodePacket(const uint8_t* i_buf, int16_t* o_buf, size_t out_len) {
    return hfp_lc3_decoder_decode_packet(i_buf, o_buf, out_len);
  }
};

struct CoreInterfaceImpl : bluetooth::core::CoreInterface {
  using bluetooth::core::CoreInterface::CoreInterface;

@@ -331,6 +355,7 @@ static bluetooth::core::CoreInterface* CreateInterfaceToProfiles() {
      .invoke_link_quality_report_cb = invoke_link_quality_report_cb};
  static auto configInterface = ConfigInterfaceImpl();
  static auto msbcCodecInterface = MSBCCodec();
  static auto lc3CodecInterface = LC3Codec();
  static auto profileInterface = bluetooth::core::HACK_ProfileInterface{
      // HID
      .btif_hh_connect = btif_hh_connect,
@@ -352,7 +377,7 @@ static bluetooth::core::CoreInterface* CreateInterfaceToProfiles() {

  static auto interfaceForCore =
      CoreInterfaceImpl(&eventCallbacks, &configInterface, &msbcCodecInterface,
                        &profileInterface);
                        &lc3CodecInterface, &profileInterface);
  return &interfaceForCore;
}

+46 −0
Original line number Diff line number Diff line
#
#  Copyright 2023 Google, Inc.
#
#  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.
#

static_library("liblc3") {
  cflags = [
    "-O3",
    "-ffast-math",
    "-Wmissing-braces",
    "-Wno-#warnings",
    "-Wuninitialized",
    "-Wno-self-assign",
    "-Wno-implicit-fallthrough",
  ]

  sources = [
    "src/attdet.c",
    "src/bits.c",
    "src/bwdet.c",
    "src/energy.c",
    "src/lc3.c",
    "src/ltpf.c",
    "src/mdct.c",
    "src/plc.c",
    "src/sns.c",
    "src/spec.c",
    "src/tables.c",
    "src/tns.c",
  ]

  include_dirs = [
    "include",
  ]
}
+1 −0
Original line number Diff line number Diff line
@@ -104,6 +104,7 @@ void SyspropsModule::parse_config(std::string file_path) {
      "bluetooth.core.le.vendor_capabilities.enabled",
      // SCO
      "bluetooth.sco.disable_enhanced_connection",
      "bluetooth.sco.swb_supported",
      // Profile
      "persist.bluetooth.avrcpcontrolversion",
  };
+2 −2
Original line number Diff line number Diff line
@@ -250,9 +250,9 @@
 * Initial SCO TX credit
 ************************/
/* The size of buffer used for TX SCO data packets. The size should be divisible
 * by BTM_MSBC_CODE_SIZE(240) */
 * by BTM_MSBC_CODE_SIZE(240) and BTM_LC3_CODE_SIZE(480). */
#ifndef BTM_SCO_DATA_SIZE_MAX
#define BTM_SCO_DATA_SIZE_MAX 240
#define BTM_SCO_DATA_SIZE_MAX 480
#endif

/* The size in bytes of the BTM inquiry database. */
Loading