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

Commit 86b81be1 authored by En-Shuo Hsu's avatar En-Shuo Hsu Committed by Gerrit Code Review
Browse files

Merge "Floss: enable LC3 as a SW codec in HFP"

parents cab71645 dc9fadd7
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -138,6 +138,7 @@ struct CoreInterface {


  // codecs
  // codecs
  CodecInterface* msbcCodec;
  CodecInterface* msbcCodec;
  CodecInterface* lc3Codec;


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


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


  CoreInterface(const CoreInterface&) = delete;
  CoreInterface(const CoreInterface&) = delete;
+26 −1
Original line number Original line Diff line number Diff line
@@ -106,6 +106,8 @@
#include "stack/include/avdt_api.h"
#include "stack/include/avdt_api.h"
#include "stack/include/btm_api.h"
#include "stack/include/btm_api.h"
#include "stack/include/btu.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_decoder.h"
#include "stack/include/hfp_msbc_encoder.h"
#include "stack/include/hfp_msbc_encoder.h"
#include "stack/include/hidh_api.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 {
struct CoreInterfaceImpl : bluetooth::core::CoreInterface {
  using bluetooth::core::CoreInterface::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};
      .invoke_link_quality_report_cb = invoke_link_quality_report_cb};
  static auto configInterface = ConfigInterfaceImpl();
  static auto configInterface = ConfigInterfaceImpl();
  static auto msbcCodecInterface = MSBCCodec();
  static auto msbcCodecInterface = MSBCCodec();
  static auto lc3CodecInterface = LC3Codec();
  static auto profileInterface = bluetooth::core::HACK_ProfileInterface{
  static auto profileInterface = bluetooth::core::HACK_ProfileInterface{
      // HID
      // HID
      .btif_hh_connect = btif_hh_connect,
      .btif_hh_connect = btif_hh_connect,
@@ -352,7 +377,7 @@ static bluetooth::core::CoreInterface* CreateInterfaceToProfiles() {


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


+46 −0
Original line number Original line 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 Original line Diff line number Diff line
@@ -104,6 +104,7 @@ void SyspropsModule::parse_config(std::string file_path) {
      "bluetooth.core.le.vendor_capabilities.enabled",
      "bluetooth.core.le.vendor_capabilities.enabled",
      // SCO
      // SCO
      "bluetooth.sco.disable_enhanced_connection",
      "bluetooth.sco.disable_enhanced_connection",
      "bluetooth.sco.swb_supported",
      // Profile
      // Profile
      "persist.bluetooth.avrcpcontrolversion",
      "persist.bluetooth.avrcpcontrolversion",
  };
  };
+2 −2
Original line number Original line Diff line number Diff line
@@ -250,9 +250,9 @@
 * Initial SCO TX credit
 * Initial SCO TX credit
 ************************/
 ************************/
/* The size of buffer used for TX SCO data packets. The size should be divisible
/* 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
#ifndef BTM_SCO_DATA_SIZE_MAX
#define BTM_SCO_DATA_SIZE_MAX 240
#define BTM_SCO_DATA_SIZE_MAX 480
#endif
#endif


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