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

Commit c474b971 authored by Cheney Ni's avatar Cheney Ni
Browse files

A2dpCodecs: encoder standalone APIs separating from codec config

Each A2DP peer has its own codec configurations, and there is a single
encoder instance used by the active peer. The interval and effective
frame size are used by the encoder, so moving those two APIs into the
encoder interface.

Bug: 195498246
Tag: #refactor
Test: 1. atest net_test_stack
      2. Switch A2DP codec manually
Change-Id: I3e97ff6c5811f620a8add88d3606cc7993851560
parent 6a3216b3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -277,7 +277,7 @@ bool a2dp_get_selected_hal_codec_config(CodecConfiguration* codec_config) {
  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 = a2dp_config->getEffectiveMtu();
  int effectiveMtu = bta_av_co_get_encoder_effective_frame_size();
  if (effectiveMtu > 0 && effectiveMtu < peer_param.peer_mtu) {
    codec_config->peerMtu = effectiveMtu;
  } else {
+7 −0
Original line number Diff line number Diff line
@@ -3043,6 +3043,13 @@ void bta_av_vendor_offload_start(tBTA_AV_SCB* p_scb,
  ARRAY_TO_STREAM(p_param, offload_start->codec_info,
                  (int8_t)sizeof(offload_start->codec_info));
  p_scb->offload_started = true;
  LOG_INFO(
      "codec: %#x, sample rate: %#x, bit depth: %#x, channel: %#x, bitrate: "
      "%#x, ACL: %#x, L2CAP: %#x, MTU: %#x",
      offload_start->codec_type, offload_start->sample_rate,
      offload_start->bits_per_sample, offload_start->ch_mode,
      offload_start->encoded_audio_bitrate, offload_start->acl_hdl,
      offload_start->l2c_rcid, offload_start->mtu);
  BTM_VendorSpecificCommand(HCI_CONTROLLER_A2DP, p_param - param,
                            param, offload_vendor_callback);
}
+17 −0
Original line number Diff line number Diff line
@@ -428,6 +428,13 @@ class BtaAvCo {
   */
  bool SetCodecAudioConfig(const btav_a2dp_codec_config_t& codec_audio_config);

  /**
   * Get the Source encoder maximum frame size for the current codec.
   *
   * @return the effective frame size for the current codec
   */
  int GetSourceEncoderEffectiveFrameSize();

  /**
   * Report the source codec state for a peer
   *
@@ -1642,6 +1649,12 @@ bool BtaAvCo::SetCodecAudioConfig(
  return true;
}

int BtaAvCo::GetSourceEncoderEffectiveFrameSize() {
  std::lock_guard<std::recursive_mutex> lock(codec_lock_);

  return A2DP_GetEecoderEffectiveFrameSize(codec_config_);
}

bool BtaAvCo::ReportSourceCodecState(BtaAvCoPeer* p_peer) {
  btav_a2dp_codec_config_t codec_config;
  std::vector<btav_a2dp_codec_config_t> codecs_local_capabilities;
@@ -2201,6 +2214,10 @@ bool bta_av_co_set_codec_audio_config(
  return bta_av_co_cb.SetCodecAudioConfig(codec_audio_config);
}

int bta_av_co_get_encoder_effective_frame_size() {
  return bta_av_co_cb.GetSourceEncoderEffectiveFrameSize();
}

btav_a2dp_scmst_info_t bta_av_co_get_scmst_info(
    const RawAddress& peer_address) {
  BtaAvCoPeer* p_peer = bta_av_co_cb.FindPeer(peer_address);
+4 −0
Original line number Diff line number Diff line
@@ -81,6 +81,10 @@ A2dpCodecConfig* bta_av_get_a2dp_current_codec(void);
A2dpCodecConfig* bta_av_get_a2dp_peer_current_codec(
    const RawAddress& peer_address);

// Gets the A2DP effective frame size from the current encoder.
// Returns the effective frame size if the encoder is configured, otherwise 0.
int bta_av_co_get_encoder_effective_frame_size();

// Dump A2DP codec debug-related information for the A2DP module.
// |fd| is the file descriptor to use for writing the ASCII formatted
// information.
+1 −10
Original line number Diff line number Diff line
@@ -117,6 +117,7 @@ static const tA2DP_ENCODER_INTERFACE a2dp_encoder_interface_aac = {
    a2dp_aac_feeding_reset,
    a2dp_aac_feeding_flush,
    a2dp_aac_get_encoder_interval_ms,
    a2dp_aac_get_effective_frame_size,
    a2dp_aac_send_frames,
    nullptr  // set_transmit_queue_length
};
@@ -1515,16 +1516,6 @@ bool A2dpCodecConfigAacSink::init() {
  return true;
}

uint64_t A2dpCodecConfigAacSink::encoderIntervalMs() const {
  // TODO: This method applies only to Source codecs
  return 0;
}

int A2dpCodecConfigAacSink::getEffectiveMtu() const {
  // TODO: This method applies only to Source codecs
  return 0;
}

bool A2dpCodecConfigAacSink::useRtpHeaderMarkerBit() const {
  // TODO: This method applies only to Source codecs
  return false;
Loading