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

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

Merge "audio_hal_interface: Pass effective peer mtu as parameter to setup_codec" into main

parents 01f0ab1f 5246a610
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -70,11 +70,11 @@ void cleanup() {
}

// Set up the codec into BluetoothAudio HAL
bool setup_codec(A2dpCodecConfig* a2dp_config) {
bool setup_codec(A2dpCodecConfig* a2dp_config, uint16_t peer_mtu) {
  if (HalVersionManager::GetHalTransport() == BluetoothAudioHalTransport::HIDL) {
    return hidl::a2dp::setup_codec(a2dp_config);
    return hidl::a2dp::setup_codec(a2dp_config, peer_mtu);
  }
  return aidl::a2dp::setup_codec(a2dp_config);
  return aidl::a2dp::setup_codec(a2dp_config, peer_mtu);
}

// Send command to the BluetoothAudio HAL: StartSession, EndSession,
+1 −1
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ bool init(bluetooth::common::MessageLoopThread* message_loop);
void cleanup();

// Set up the codec into BluetoothAudio HAL
bool setup_codec(A2dpCodecConfig* a2dp_config);
bool setup_codec(A2dpCodecConfig* a2dp_config, uint16_t peer_mtu);

// Set low latency buffer mode allowed or disallowed
void set_audio_low_latency_mode_allowed(bool allowed);
+1 −1
Original line number Diff line number Diff line
@@ -248,7 +248,7 @@ void cleanup() {
}

// Set up the codec into BluetoothAudio HAL
bool setup_codec(A2dpCodecConfig* /*a2dp_config*/) {
bool setup_codec(A2dpCodecConfig* /*a2dp_config*/, uint16_t /*peer_mtu*/) {
  // TODO: setup codec
  return true;
}
+5 −53
Original line number Diff line number Diff line
@@ -256,39 +256,7 @@ static BluetoothAudioCtrlAck a2dp_ack_to_bt_audio_ctrl_ack(BluetoothAudioStatus
  }
}

/// Return the MTU for the active peer audio connection.
static uint16_t a2dp_get_peer_mtu(btav_a2dp_codec_index_t codec_index, uint8_t const* codec_info) {
  RawAddress peer_addr = btif_av_source_active_peer();
  tA2DP_ENCODER_INIT_PEER_PARAMS peer_params;
  bta_av_co_get_peer_params(peer_addr, &peer_params);
  uint16_t peer_mtu = peer_params.peer_mtu;
  uint16_t effective_mtu = bta_av_co_get_encoder_effective_frame_size(peer_addr);

  if (effective_mtu > 0 && effective_mtu < peer_mtu) {
    peer_mtu = effective_mtu;
  }

  // b/188020925
  // When SBC headsets report middle quality bitpool under a larger MTU, we
  // reduce the packet size to prevent the hardware encoder from putting too
  // many frames in one packet.
  if (codec_index == BTAV_A2DP_CODEC_INDEX_SOURCE_SBC &&
      codec_info[2] /* maxBitpool */ <= A2DP_SBC_BITPOOL_MIDDLE_QUALITY) {
    peer_mtu = MAX_2MBPS_AVDTP_MTU;
  }

  // b/177205770
  // Fix the MTU value not to be greater than an AVDTP packet, so the data
  // encoded by A2DP hardware encoder can be fitted into one AVDTP packet
  // without fragmented
  if (peer_mtu > MAX_3MBPS_AVDTP_MTU) {
    peer_mtu = MAX_3MBPS_AVDTP_MTU;
  }

  return peer_mtu;
}

bool a2dp_get_selected_hal_codec_config(A2dpCodecConfig* a2dp_config,
bool a2dp_get_selected_hal_codec_config(A2dpCodecConfig* a2dp_config, uint16_t peer_mtu,
                                        CodecConfiguration* codec_config) {
  btav_a2dp_codec_config_t current_codec = a2dp_config->getCodecConfig();
  switch (current_codec.codec_type) {
@@ -335,23 +303,7 @@ bool a2dp_get_selected_hal_codec_config(A2dpCodecConfig* a2dp_config,
      return false;
  }
  codec_config->encodedAudioBitrate = a2dp_config->getTrackBitRate();
  // Obtain the MTU
  RawAddress peer_addr = btif_av_source_active_peer();
  tA2DP_ENCODER_INIT_PEER_PARAMS peer_param;
  bta_av_co_get_peer_params(peer_addr, &peer_param);
  int effectiveMtu = bta_av_co_get_encoder_effective_frame_size(peer_addr);
  if (effectiveMtu > 0 && effectiveMtu < peer_param.peer_mtu) {
    codec_config->peerMtu = effectiveMtu;
  } else {
    codec_config->peerMtu = peer_param.peer_mtu;
  }
  if (current_codec.codec_type == BTAV_A2DP_CODEC_INDEX_SOURCE_SBC &&
      codec_config->config.get<CodecConfiguration::CodecSpecific::sbcConfig>().maxBitpool <=
              A2DP_SBC_BITPOOL_MIDDLE_QUALITY) {
    codec_config->peerMtu = MAX_2MBPS_AVDTP_MTU;
  } else if (codec_config->peerMtu > MAX_3MBPS_AVDTP_MTU) {
    codec_config->peerMtu = MAX_3MBPS_AVDTP_MTU;
  }
  codec_config->peerMtu = peer_mtu;
  log::info("CodecConfiguration={}", codec_config->toString());
  return true;
}
@@ -505,7 +457,7 @@ void cleanup() {
}

// Set up the codec into BluetoothAudio HAL
bool setup_codec(A2dpCodecConfig* a2dp_config) {
bool setup_codec(A2dpCodecConfig* a2dp_config, uint16_t peer_mtu) {
  log::assert_that(a2dp_config != nullptr, "received invalid codec configuration");

  if (!is_hal_enabled()) {
@@ -522,7 +474,7 @@ bool setup_codec(A2dpCodecConfig* a2dp_config) {
    A2dpStreamConfiguration a2dp_stream_configuration;

    a2dp_config->copyOutOtaCodecConfig(codec_info);
    a2dp_stream_configuration.peerMtu = a2dp_get_peer_mtu(a2dp_config->codecIndex(), codec_info);
    a2dp_stream_configuration.peerMtu = peer_mtu;
    a2dp_stream_configuration.codecId =
            provider_info->GetCodec(a2dp_config->codecIndex()).value()->id;

@@ -556,7 +508,7 @@ bool setup_codec(A2dpCodecConfig* a2dp_config) {
  // Fallback to legacy offloading path.
  CodecConfiguration codec_config{};

  if (!a2dp_get_selected_hal_codec_config(a2dp_config, &codec_config)) {
  if (!a2dp_get_selected_hal_codec_config(a2dp_config, peer_mtu, &codec_config)) {
    log::error("Failed to get CodecConfiguration");
    return false;
  }
+1 −1
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ void cleanup();
/***
 * Set up the codec into BluetoothAudio HAL
 ***/
bool setup_codec(A2dpCodecConfig* a2dp_config);
bool setup_codec(A2dpCodecConfig* a2dp_config, uint16_t peer_mtu);

/***
 * Send command to the BluetoothAudio HAL: StartSession, EndSession,
Loading