diff options
author | Cheney Ni <cheneyni@google.com> | 2021-08-26 02:21:38 +0800 |
---|---|---|
committer | Cheney Ni <cheneyni@google.com> | 2021-09-06 11:42:42 +0800 |
commit | d7bc913745003f10d2aa845ce8f987b5ba73dccf (patch) | |
tree | 250af9943bf13e5095449d29a36cc48aad796350 | |
parent | 9182d02bf0d63871e4ded22f8ed9701bc86b7852 (diff) | |
download | bt-d7bc913745003f10d2aa845ce8f987b5ba73dccf.tar.gz |
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
29 files changed, 156 insertions, 119 deletions
diff --git a/audio_hal_interface/a2dp_encoding.cc b/audio_hal_interface/a2dp_encoding.cc index 44a4828fc..6eb78c92e 100644 --- a/audio_hal_interface/a2dp_encoding.cc +++ b/audio_hal_interface/a2dp_encoding.cc @@ -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 { diff --git a/bta/av/bta_av_aact.cc b/bta/av/bta_av_aact.cc index 5c78afb67..700d44e9e 100644 --- a/bta/av/bta_av_aact.cc +++ b/bta/av/bta_av_aact.cc @@ -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); } diff --git a/btif/co/bta_av_co.cc b/btif/co/bta_av_co.cc index b10831603..f2909a0d2 100644 --- a/btif/co/bta_av_co.cc +++ b/btif/co/bta_av_co.cc @@ -429,6 +429,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 * * @param p_peer the peer to report @@ -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); diff --git a/btif/include/btif_av_co.h b/btif/include/btif_av_co.h index 01b3b2fd0..f9c2ed857 100644 --- a/btif/include/btif_av_co.h +++ b/btif/include/btif_av_co.h @@ -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. diff --git a/stack/a2dp/a2dp_aac.cc b/stack/a2dp/a2dp_aac.cc index e58d7bdf2..bdd998651 100644 --- a/stack/a2dp/a2dp_aac.cc +++ b/stack/a2dp/a2dp_aac.cc @@ -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; diff --git a/stack/a2dp/a2dp_aac_encoder.cc b/stack/a2dp/a2dp_aac_encoder.cc index 3f2d4d648..80b1b4e7d 100644 --- a/stack/a2dp/a2dp_aac_encoder.cc +++ b/stack/a2dp/a2dp_aac_encoder.cc @@ -523,6 +523,10 @@ uint64_t a2dp_aac_get_encoder_interval_ms(void) { return a2dp_aac_encoder_interval_ms; } +int a2dp_aac_get_effective_frame_size() { + return a2dp_aac_encoder_cb.TxAaMtuSize; +} + void a2dp_aac_send_frames(uint64_t timestamp_us) { uint8_t nb_frame = 0; uint8_t nb_iterations = 0; @@ -728,14 +732,6 @@ static bool a2dp_aac_read_feeding(uint8_t* read_buffer, uint32_t* bytes_read) { return true; } -uint64_t A2dpCodecConfigAacSource::encoderIntervalMs() const { - return a2dp_aac_get_encoder_interval_ms(); -} - -int A2dpCodecConfigAacSource::getEffectiveMtu() const { - return a2dp_aac_encoder_cb.TxAaMtuSize; -} - void A2dpCodecConfigAacSource::debug_codec_dump(int fd) { a2dp_aac_encoder_stats_t* stats = &a2dp_aac_encoder_cb.stats; @@ -749,6 +745,9 @@ void A2dpCodecConfigAacSource::debug_codec_dump(int fd) { ((codec_specific_1 & ~A2DP_AAC_VARIABLE_BIT_RATE_MASK) == 0 ? "Constant" : "Variable"), codec_specific_1); + dprintf(fd, " Encoder interval (ms): %" PRIu64 "\n", + a2dp_aac_get_encoder_interval_ms()); + dprintf(fd, " Effective MTU: %d\n", a2dp_aac_get_effective_frame_size()); dprintf(fd, " Packet counts (expected/dropped) : %zu / " "%zu\n", diff --git a/stack/a2dp/a2dp_codec_config.cc b/stack/a2dp/a2dp_codec_config.cc index a90c88108..1f8c62d4b 100644 --- a/stack/a2dp/a2dp_codec_config.cc +++ b/stack/a2dp/a2dp_codec_config.cc @@ -519,8 +519,6 @@ void A2dpCodecConfig::debug_codec_dump(int fd) { std::string result; dprintf(fd, "\nA2DP %s State:\n", name().c_str()); dprintf(fd, " Priority: %d\n", codecPriority()); - dprintf(fd, " Encoder interval (ms): %" PRIu64 "\n", encoderIntervalMs()); - dprintf(fd, " Effective MTU: %d\n", getEffectiveMtu()); result = codecConfig2Str(getCodecConfig()); dprintf(fd, " Config: %s\n", result.c_str()); @@ -1555,3 +1553,28 @@ std::string A2DP_CodecInfoString(const uint8_t* p_codec_info) { return "Unsupported codec type: " + loghex(codec_type); } + +int A2DP_GetEecoderEffectiveFrameSize(const uint8_t* p_codec_info) { + tA2DP_CODEC_TYPE codec_type = A2DP_GetCodecType(p_codec_info); + + const tA2DP_ENCODER_INTERFACE* a2dp_encoder_interface = nullptr; + switch (codec_type) { + case A2DP_MEDIA_CT_SBC: + a2dp_encoder_interface = A2DP_GetEncoderInterfaceSbc(p_codec_info); + break; +#if !defined(EXCLUDE_NONSTANDARD_CODECS) + case A2DP_MEDIA_CT_AAC: + a2dp_encoder_interface = A2DP_GetEncoderInterfaceAac(p_codec_info); + break; + case A2DP_MEDIA_CT_NON_A2DP: + a2dp_encoder_interface = A2DP_VendorGetEncoderInterface(p_codec_info); + break; +#endif + default: + break; + } + if (a2dp_encoder_interface == nullptr) { + return 0; + } + return a2dp_encoder_interface->get_effective_frame_size(); +} diff --git a/stack/a2dp/a2dp_sbc.cc b/stack/a2dp/a2dp_sbc.cc index adf9cc5b3..18e6a1231 100644 --- a/stack/a2dp/a2dp_sbc.cc +++ b/stack/a2dp/a2dp_sbc.cc @@ -98,6 +98,7 @@ static const tA2DP_ENCODER_INTERFACE a2dp_encoder_interface_sbc = { a2dp_sbc_feeding_reset, a2dp_sbc_feeding_flush, a2dp_sbc_get_encoder_interval_ms, + a2dp_sbc_get_effective_frame_size, a2dp_sbc_send_frames, nullptr // set_transmit_queue_length }; @@ -1569,13 +1570,3 @@ bool A2dpCodecConfigSbcSink::updateEncoderUserConfig( // TODO: This method applies only to Source codecs return false; } - -uint64_t A2dpCodecConfigSbcSink::encoderIntervalMs() const { - // TODO: This method applies only to Source codecs - return 0; -} - -int A2dpCodecConfigSbcSink::getEffectiveMtu() const { - // TODO: This method applies only to Source codecs - return 0; -} diff --git a/stack/a2dp/a2dp_sbc_encoder.cc b/stack/a2dp/a2dp_sbc_encoder.cc index 2de3fad42..9b4fa5e16 100644 --- a/stack/a2dp/a2dp_sbc_encoder.cc +++ b/stack/a2dp/a2dp_sbc_encoder.cc @@ -396,6 +396,10 @@ uint64_t a2dp_sbc_get_encoder_interval_ms(void) { return A2DP_SBC_ENCODER_INTERVAL_MS; } +int a2dp_sbc_get_effective_frame_size() { + return a2dp_sbc_encoder_cb.TxAaMtuSize; +} + void a2dp_sbc_send_frames(uint64_t timestamp_us) { uint8_t nb_frame = 0; uint8_t nb_iterations = 0; @@ -890,14 +894,6 @@ uint32_t a2dp_sbc_get_bitrate() { return p_encoder_params->u16BitRate * 1000; } -uint64_t A2dpCodecConfigSbcSource::encoderIntervalMs() const { - return a2dp_sbc_get_encoder_interval_ms(); -} - -int A2dpCodecConfigSbcSource::getEffectiveMtu() const { - return a2dp_sbc_encoder_cb.TxAaMtuSize; -} - void A2dpCodecConfigSbcSource::debug_codec_dump(int fd) { a2dp_sbc_encoder_stats_t* stats = &a2dp_sbc_encoder_cb.stats; @@ -906,20 +902,23 @@ void A2dpCodecConfigSbcSource::debug_codec_dump(int fd) { uint8_t codec_info[AVDT_CODEC_SIZE]; if (copyOutOtaCodecConfig(codec_info)) { dprintf(fd, - " Block length : %d\n", + " SBC Block length : %d\n", A2DP_GetNumberOfBlocksSbc(codec_info)); dprintf(fd, - " Number of subbands : %d\n", + " SBC Number of subbands : %d\n", A2DP_GetNumberOfSubbandsSbc(codec_info)); dprintf(fd, - " Allocation method : %d\n", + " SBC Allocation method : %d\n", A2DP_GetAllocationMethodCodeSbc(codec_info)); dprintf( fd, - " Bitpool (min/max) : %d / %d\n", + " SBC Bitpool (min/max) : %d / %d\n", A2DP_GetMinBitpoolSbc(codec_info), A2DP_GetMaxBitpoolSbc(codec_info)); } + dprintf(fd, " Encoder interval (ms): %" PRIu64 "\n", + a2dp_sbc_get_encoder_interval_ms()); + dprintf(fd, " Effective MTU: %d\n", a2dp_sbc_get_effective_frame_size()); dprintf(fd, " Packet counts (expected/dropped) : %zu / " "%zu\n", diff --git a/stack/a2dp/a2dp_vendor_aptx.cc b/stack/a2dp/a2dp_vendor_aptx.cc index d256b76a0..976ed7e7b 100644 --- a/stack/a2dp/a2dp_vendor_aptx.cc +++ b/stack/a2dp/a2dp_vendor_aptx.cc @@ -76,6 +76,7 @@ static const tA2DP_ENCODER_INTERFACE a2dp_encoder_interface_aptx = { a2dp_vendor_aptx_feeding_reset, a2dp_vendor_aptx_feeding_flush, a2dp_vendor_aptx_get_encoder_interval_ms, + a2dp_vendor_aptx_get_effective_frame_size, a2dp_vendor_aptx_send_frames, nullptr // set_transmit_queue_length }; diff --git a/stack/a2dp/a2dp_vendor_aptx_encoder.cc b/stack/a2dp/a2dp_vendor_aptx_encoder.cc index bc8752117..dc3accafa 100644 --- a/stack/a2dp/a2dp_vendor_aptx_encoder.cc +++ b/stack/a2dp/a2dp_vendor_aptx_encoder.cc @@ -371,6 +371,10 @@ uint64_t a2dp_vendor_aptx_get_encoder_interval_ms(void) { return a2dp_aptx_encoder_cb.framing_params.sleep_time_ns / (1000 * 1000); } +int a2dp_vendor_aptx_get_effective_frame_size() { + return a2dp_aptx_encoder_cb.peer_mtu; +} + void a2dp_vendor_aptx_send_frames(uint64_t timestamp_us) { tAPTX_FRAMING_PARAMS* framing_params = &a2dp_aptx_encoder_cb.framing_params; @@ -476,19 +480,15 @@ static size_t aptx_encode_16bit(tAPTX_FRAMING_PARAMS* framing_params, return pcm_bytes_encoded; } -uint64_t A2dpCodecConfigAptx::encoderIntervalMs() const { - return a2dp_vendor_aptx_get_encoder_interval_ms(); -} - -int A2dpCodecConfigAptx::getEffectiveMtu() const { - return a2dp_aptx_encoder_cb.peer_mtu; -} - void A2dpCodecConfigAptx::debug_codec_dump(int fd) { a2dp_aptx_encoder_stats_t* stats = &a2dp_aptx_encoder_cb.stats; A2dpCodecConfig::debug_codec_dump(fd); + dprintf(fd, " Encoder interval (ms): %" PRIu64 "\n", + a2dp_vendor_aptx_get_encoder_interval_ms()); + dprintf(fd, " Effective MTU: %d\n", + a2dp_vendor_aptx_get_effective_frame_size()); dprintf(fd, " Packet counts (expected/dropped) : %zu / " "%zu\n", diff --git a/stack/a2dp/a2dp_vendor_aptx_hd.cc b/stack/a2dp/a2dp_vendor_aptx_hd.cc index 0b5916b5d..35becb1b8 100644 --- a/stack/a2dp/a2dp_vendor_aptx_hd.cc +++ b/stack/a2dp/a2dp_vendor_aptx_hd.cc @@ -83,6 +83,7 @@ static const tA2DP_ENCODER_INTERFACE a2dp_encoder_interface_aptx_hd = { a2dp_vendor_aptx_hd_feeding_reset, a2dp_vendor_aptx_hd_feeding_flush, a2dp_vendor_aptx_hd_get_encoder_interval_ms, + a2dp_vendor_aptx_hd_get_effective_frame_size, a2dp_vendor_aptx_hd_send_frames, nullptr // set_transmit_queue_length }; diff --git a/stack/a2dp/a2dp_vendor_aptx_hd_encoder.cc b/stack/a2dp/a2dp_vendor_aptx_hd_encoder.cc index 5856e0827..9f05925a5 100644 --- a/stack/a2dp/a2dp_vendor_aptx_hd_encoder.cc +++ b/stack/a2dp/a2dp_vendor_aptx_hd_encoder.cc @@ -355,6 +355,10 @@ uint64_t a2dp_vendor_aptx_hd_get_encoder_interval_ms(void) { return a2dp_aptx_hd_encoder_cb.framing_params.sleep_time_ns / (1000 * 1000); } +int a2dp_vendor_aptx_hd_get_effective_frame_size() { + return a2dp_aptx_hd_encoder_cb.peer_mtu; +} + void a2dp_vendor_aptx_hd_send_frames(uint64_t timestamp_us) { tAPTX_HD_FRAMING_PARAMS* framing_params = &a2dp_aptx_hd_encoder_cb.framing_params; @@ -473,19 +477,15 @@ static size_t aptx_hd_encode_24bit(tAPTX_HD_FRAMING_PARAMS* framing_params, return pcm_bytes_encoded; } -uint64_t A2dpCodecConfigAptxHd::encoderIntervalMs() const { - return a2dp_vendor_aptx_hd_get_encoder_interval_ms(); -} - -int A2dpCodecConfigAptxHd::getEffectiveMtu() const { - return a2dp_aptx_hd_encoder_cb.peer_mtu; -} - void A2dpCodecConfigAptxHd::debug_codec_dump(int fd) { a2dp_aptx_hd_encoder_stats_t* stats = &a2dp_aptx_hd_encoder_cb.stats; A2dpCodecConfig::debug_codec_dump(fd); + dprintf(fd, " Encoder interval (ms): %" PRIu64 "\n", + a2dp_vendor_aptx_hd_get_encoder_interval_ms()); + dprintf(fd, " Effective MTU: %d\n", + a2dp_vendor_aptx_hd_get_effective_frame_size()); dprintf(fd, " Packet counts (expected/dropped) : %zu / " "%zu\n", diff --git a/stack/a2dp/a2dp_vendor_ldac.cc b/stack/a2dp/a2dp_vendor_ldac.cc index b9e5f5a21..8edca5240 100644 --- a/stack/a2dp/a2dp_vendor_ldac.cc +++ b/stack/a2dp/a2dp_vendor_ldac.cc @@ -90,6 +90,7 @@ static const tA2DP_ENCODER_INTERFACE a2dp_encoder_interface_ldac = { a2dp_vendor_ldac_feeding_reset, a2dp_vendor_ldac_feeding_flush, a2dp_vendor_ldac_get_encoder_interval_ms, + a2dp_vendor_ldac_get_effective_frame_size, a2dp_vendor_ldac_send_frames, a2dp_vendor_ldac_set_transmit_queue_length}; @@ -1422,16 +1423,6 @@ bool A2dpCodecConfigLdacSink::init() { return true; } -uint64_t A2dpCodecConfigLdacSink::encoderIntervalMs() const { - // TODO: This method applies only to Source codecs - return 0; -} - -int A2dpCodecConfigLdacSink::getEffectiveMtu() const { - // TODO: This method applies only to Source codecs - return 0; -} - bool A2dpCodecConfigLdacSink::useRtpHeaderMarkerBit() const { // TODO: This method applies only to Source codecs return false; diff --git a/stack/a2dp/a2dp_vendor_ldac_encoder.cc b/stack/a2dp/a2dp_vendor_ldac_encoder.cc index 62d2d9e43..89d0e6a88 100644 --- a/stack/a2dp/a2dp_vendor_ldac_encoder.cc +++ b/stack/a2dp/a2dp_vendor_ldac_encoder.cc @@ -535,6 +535,10 @@ uint64_t a2dp_vendor_ldac_get_encoder_interval_ms(void) { return A2DP_LDAC_ENCODER_INTERVAL_MS; } +int a2dp_vendor_ldac_get_effective_frame_size() { + return a2dp_ldac_encoder_cb.TxAaMtuSize; +} + void a2dp_vendor_ldac_send_frames(uint64_t timestamp_us) { uint8_t nb_frame = 0; uint8_t nb_iterations = 0; @@ -756,14 +760,6 @@ void a2dp_vendor_ldac_set_transmit_queue_length(size_t transmit_queue_length) { a2dp_ldac_encoder_cb.TxQueueLength = transmit_queue_length; } -uint64_t A2dpCodecConfigLdacSource::encoderIntervalMs() const { - return a2dp_vendor_ldac_get_encoder_interval_ms(); -} - -int A2dpCodecConfigLdacSource::getEffectiveMtu() const { - return a2dp_ldac_encoder_cb.TxAaMtuSize; -} - void A2dpCodecConfigLdacSource::debug_codec_dump(int fd) { a2dp_ldac_encoder_stats_t* stats = &a2dp_ldac_encoder_cb.stats; tA2DP_LDAC_ENCODER_PARAMS* p_encoder_params = @@ -771,24 +767,6 @@ void A2dpCodecConfigLdacSource::debug_codec_dump(int fd) { A2dpCodecConfig::debug_codec_dump(fd); - dprintf(fd, - " Packet counts (expected/dropped) : %zu / " - "%zu\n", - stats->media_read_total_expected_packets, - stats->media_read_total_dropped_packets); - - dprintf(fd, - " PCM read counts (expected/actual) : %zu / " - "%zu\n", - stats->media_read_total_expected_reads_count, - stats->media_read_total_actual_reads_count); - - dprintf(fd, - " PCM read bytes (expected/actual) : %zu / " - "%zu\n", - stats->media_read_total_expected_read_bytes, - stats->media_read_total_actual_read_bytes); - dprintf( fd, " LDAC quality mode : %s\n", quality_mode_index_to_name(p_encoder_params->quality_mode_index).c_str()); @@ -808,4 +786,25 @@ void A2dpCodecConfigLdacSource::debug_codec_dump(int fd) { " LDAC adaptive bit rate adjustments : %zu\n", a2dp_ldac_encoder_cb.ldac_abr_adjustments); } + dprintf(fd, " Encoder interval (ms): %" PRIu64 "\n", + a2dp_vendor_ldac_get_encoder_interval_ms()); + dprintf(fd, " Effective MTU: %d\n", + a2dp_vendor_ldac_get_effective_frame_size()); + dprintf(fd, + " Packet counts (expected/dropped) : %zu / " + "%zu\n", + stats->media_read_total_expected_packets, + stats->media_read_total_dropped_packets); + + dprintf(fd, + " PCM read counts (expected/actual) : %zu / " + "%zu\n", + stats->media_read_total_expected_reads_count, + stats->media_read_total_actual_reads_count); + + dprintf(fd, + " PCM read bytes (expected/actual) : %zu / " + "%zu\n", + stats->media_read_total_expected_read_bytes, + stats->media_read_total_actual_read_bytes); } diff --git a/stack/include/a2dp_aac.h b/stack/include/a2dp_aac.h index 94ba730f5..1fe84627b 100644 --- a/stack/include/a2dp_aac.h +++ b/stack/include/a2dp_aac.h @@ -48,8 +48,6 @@ class A2dpCodecConfigAacSource : public A2dpCodecConfigAacBase { virtual ~A2dpCodecConfigAacSource(); bool init() override; - uint64_t encoderIntervalMs() const override; - int getEffectiveMtu() const override; private: bool useRtpHeaderMarkerBit() const override; @@ -66,8 +64,6 @@ class A2dpCodecConfigAacSink : public A2dpCodecConfigAacBase { virtual ~A2dpCodecConfigAacSink(); bool init() override; - uint64_t encoderIntervalMs() const override; - int getEffectiveMtu() const override; private: bool useRtpHeaderMarkerBit() const override; diff --git a/stack/include/a2dp_aac_encoder.h b/stack/include/a2dp_aac_encoder.h index 5e909d8b4..4503f4669 100644 --- a/stack/include/a2dp_aac_encoder.h +++ b/stack/include/a2dp_aac_encoder.h @@ -73,6 +73,9 @@ void a2dp_aac_feeding_flush(void); // Get the A2DP AAC encoder interval (in milliseconds). uint64_t a2dp_aac_get_encoder_interval_ms(void); +// Get the A2DP AAC encoded maximum frame size +int a2dp_aac_get_effective_frame_size(); + // Prepare and send A2DP AAC encoded frames. // |timestamp_us| is the current timestamp (in microseconds). void a2dp_aac_send_frames(uint64_t timestamp_us); diff --git a/stack/include/a2dp_codec_api.h b/stack/include/a2dp_codec_api.h index 3297c5c78..1e335cc97 100644 --- a/stack/include/a2dp_codec_api.h +++ b/stack/include/a2dp_codec_api.h @@ -124,11 +124,6 @@ class A2dpCodecConfig { // the Marker bit in the header is set according to RFC 6416. virtual bool useRtpHeaderMarkerBit() const = 0; - // Gets the effective MTU for the A2DP codec. - // Returns the effective MTU of current codec configuration, or 0 if not - // configured. - virtual int getEffectiveMtu() const = 0; - // Checks whether |codec_config| is empty and contains no configuration. // Returns true if |codec_config| is empty, otherwise false. static bool isCodecConfigEmpty(const btav_a2dp_codec_config_t& codec_config); @@ -215,9 +210,6 @@ class A2dpCodecConfig { // Checks whether the internal state is valid virtual bool isValid() const; - // Returns the encoder's periodic interval (in milliseconds). - virtual uint64_t encoderIntervalMs() const = 0; - // Checks whether the A2DP Codec Configuration is valid. // Returns true if A2DP Codec Configuration stored in |codec_config| // is valid, otherwise false. @@ -532,6 +524,9 @@ typedef struct { // Get the A2DP encoder interval (in milliseconds). uint64_t (*get_encoder_interval_ms)(void); + // Get the A2DP encoded maximum frame size (similar to MTU). + int (*get_effective_frame_size)(void); + // Prepare and send A2DP encoded frames. // |timestamp_us| is the current timestamp (in microseconds). void (*send_frames)(uint64_t timestamp_us); @@ -727,6 +722,13 @@ const char* A2DP_CodecIndexStr(btav_a2dp_codec_index_t codec_index); bool A2DP_InitCodecConfig(btav_a2dp_codec_index_t codec_index, AvdtpSepConfig* p_cfg); +// Gets the A2DP effective frame size that each encoded media frame should not +// exceed this value. +// |p_codec_info| contains the codec information. +// Returns the effective frame size if the encoder is configured with this +// |p_codec_info|, otherwise 0. +int A2DP_GetEecoderEffectiveFrameSize(const uint8_t* p_codec_info); + // Decodes A2DP codec info into a human readable string. // |p_codec_info| is a pointer to the codec_info to decode. // Returns a string describing the codec information. diff --git a/stack/include/a2dp_sbc.h b/stack/include/a2dp_sbc.h index 5f7b0aad4..f17c6b574 100644 --- a/stack/include/a2dp_sbc.h +++ b/stack/include/a2dp_sbc.h @@ -48,8 +48,6 @@ class A2dpCodecConfigSbcSource : public A2dpCodecConfigSbcBase { virtual ~A2dpCodecConfigSbcSource(); bool init() override; - uint64_t encoderIntervalMs() const override; - int getEffectiveMtu() const override; private: bool useRtpHeaderMarkerBit() const override; @@ -66,8 +64,6 @@ class A2dpCodecConfigSbcSink : public A2dpCodecConfigSbcBase { virtual ~A2dpCodecConfigSbcSink(); bool init() override; - uint64_t encoderIntervalMs() const override; - int getEffectiveMtu() const override; private: bool useRtpHeaderMarkerBit() const override; diff --git a/stack/include/a2dp_sbc_encoder.h b/stack/include/a2dp_sbc_encoder.h index 0acf16f05..b40537b40 100644 --- a/stack/include/a2dp_sbc_encoder.h +++ b/stack/include/a2dp_sbc_encoder.h @@ -55,6 +55,9 @@ void a2dp_sbc_feeding_flush(void); // Get the A2DP SBC encoder interval (in milliseconds). uint64_t a2dp_sbc_get_encoder_interval_ms(void); +// Get the A2DP SBC encoded maximum frame size +int a2dp_sbc_get_effective_frame_size(); + // Prepare and send A2DP SBC encoded frames. // |timestamp_us| is the current timestamp (in microseconds). void a2dp_sbc_send_frames(uint64_t timestamp_us); diff --git a/stack/include/a2dp_vendor_aptx.h b/stack/include/a2dp_vendor_aptx.h index bf4ebf09b..3f860c1fe 100644 --- a/stack/include/a2dp_vendor_aptx.h +++ b/stack/include/a2dp_vendor_aptx.h @@ -31,8 +31,6 @@ class A2dpCodecConfigAptx : public A2dpCodecConfig { virtual ~A2dpCodecConfigAptx(); bool init() override; - uint64_t encoderIntervalMs() const override; - int getEffectiveMtu() const override; bool setCodecConfig(const uint8_t* p_peer_codec_info, bool is_capability, uint8_t* p_result_codec_config) override; bool setPeerCodecCapabilities( diff --git a/stack/include/a2dp_vendor_aptx_encoder.h b/stack/include/a2dp_vendor_aptx_encoder.h index c0954fada..aaafc6eff 100644 --- a/stack/include/a2dp_vendor_aptx_encoder.h +++ b/stack/include/a2dp_vendor_aptx_encoder.h @@ -53,6 +53,9 @@ void a2dp_vendor_aptx_feeding_flush(void); // Get the A2DP aptX encoder interval (in milliseconds). uint64_t a2dp_vendor_aptx_get_encoder_interval_ms(void); +// Get the A2DP aptX encoded maximum frame size +int a2dp_vendor_aptx_get_effective_frame_size(); + // Prepare and send A2DP aptX encoded frames. // |timestamp_us| is the current timestamp (in microseconds). void a2dp_vendor_aptx_send_frames(uint64_t timestamp_us); diff --git a/stack/include/a2dp_vendor_aptx_hd.h b/stack/include/a2dp_vendor_aptx_hd.h index 8efe8c6f8..53e806782 100644 --- a/stack/include/a2dp_vendor_aptx_hd.h +++ b/stack/include/a2dp_vendor_aptx_hd.h @@ -31,8 +31,6 @@ class A2dpCodecConfigAptxHd : public A2dpCodecConfig { virtual ~A2dpCodecConfigAptxHd(); bool init() override; - uint64_t encoderIntervalMs() const override; - int getEffectiveMtu() const override; bool setCodecConfig(const uint8_t* p_peer_codec_info, bool is_capability, uint8_t* p_result_codec_config) override; bool setPeerCodecCapabilities( diff --git a/stack/include/a2dp_vendor_aptx_hd_encoder.h b/stack/include/a2dp_vendor_aptx_hd_encoder.h index 84ef8a035..dbaad01ec 100644 --- a/stack/include/a2dp_vendor_aptx_hd_encoder.h +++ b/stack/include/a2dp_vendor_aptx_hd_encoder.h @@ -53,6 +53,9 @@ void a2dp_vendor_aptx_hd_feeding_flush(void); // Get the A2DP aptX-HD encoder interval (in milliseconds). uint64_t a2dp_vendor_aptx_hd_get_encoder_interval_ms(void); +// Get the A2DP aptX-HD encoded maximum frame size +int a2dp_vendor_aptx_hd_get_effective_frame_size(); + // Prepare and send A2DP aptX-HD encoded frames. // |timestamp_us| is the current timestamp (in microseconds). void a2dp_vendor_aptx_hd_send_frames(uint64_t timestamp_us); diff --git a/stack/include/a2dp_vendor_ldac.h b/stack/include/a2dp_vendor_ldac.h index 9b1958f6d..fae574de1 100644 --- a/stack/include/a2dp_vendor_ldac.h +++ b/stack/include/a2dp_vendor_ldac.h @@ -48,8 +48,6 @@ class A2dpCodecConfigLdacSource : public A2dpCodecConfigLdacBase { virtual ~A2dpCodecConfigLdacSource(); bool init() override; - uint64_t encoderIntervalMs() const override; - int getEffectiveMtu() const override; private: bool useRtpHeaderMarkerBit() const override; @@ -66,8 +64,6 @@ class A2dpCodecConfigLdacSink : public A2dpCodecConfigLdacBase { virtual ~A2dpCodecConfigLdacSink(); bool init() override; - uint64_t encoderIntervalMs() const override; - int getEffectiveMtu() const override; private: bool useRtpHeaderMarkerBit() const override; diff --git a/stack/include/a2dp_vendor_ldac_encoder.h b/stack/include/a2dp_vendor_ldac_encoder.h index f5e320aa8..fbd87152f 100644 --- a/stack/include/a2dp_vendor_ldac_encoder.h +++ b/stack/include/a2dp_vendor_ldac_encoder.h @@ -53,6 +53,9 @@ void a2dp_vendor_ldac_feeding_flush(void); // Get the A2DP LDAC encoder interval (in milliseconds). uint64_t a2dp_vendor_ldac_get_encoder_interval_ms(void); +// Get the A2DP LDAC encoded maximum frame size +int a2dp_vendor_ldac_get_effective_frame_size(); + // Prepare and send A2DP LDAC encoded frames. // |timestamp_us| is the current timestamp (in microseconds). void a2dp_vendor_ldac_send_frames(uint64_t timestamp_us); diff --git a/stack/test/fuzzers/a2dp/codec/a2dpCodecInfoFuzzFunctions.h b/stack/test/fuzzers/a2dp/codec/a2dpCodecInfoFuzzFunctions.h index 187b474d7..5f8f91663 100644 --- a/stack/test/fuzzers/a2dp/codec/a2dpCodecInfoFuzzFunctions.h +++ b/stack/test/fuzzers/a2dp/codec/a2dpCodecInfoFuzzFunctions.h @@ -207,6 +207,11 @@ std::vector<std::function<void(FuzzedDataProvider*, uint8_t*)>> A2DP_InitCodecConfig(getArbitraryBtavCodecIndex(fdp), &cfg_retval); }, + // A2DP_GetEecoderEffectiveFrameSize + [](FuzzedDataProvider* fdp, uint8_t* codec_info) -> void { + A2DP_GetEecoderEffectiveFrameSize(codec_info); + }, + // A2DP_CodecInfoString [](FuzzedDataProvider* fdp, uint8_t* codec_info) -> void { A2DP_CodecInfoString(codec_info); diff --git a/test/mock/mock_a2dp_codec_config.cc b/test/mock/mock_a2dp_codec_config.cc index 8d0132826..b3b7cfaf2 100644 --- a/test/mock/mock_a2dp_codec_config.cc +++ b/test/mock/mock_a2dp_codec_config.cc @@ -97,6 +97,10 @@ bool A2DP_InitCodecConfig(btav_a2dp_codec_index_t codec_index, mock_function_count_map[__func__]++; return false; } +int A2DP_GetEecoderEffectiveFrameSize(const uint8_t* p_codec_info) { + mock_function_count_map[__func__]++; + return 0; +} bool A2DP_IsPeerSinkCodecValid(const uint8_t* p_codec_info) { mock_function_count_map[__func__]++; return false; diff --git a/test/mock/mock_stack_a2dp_codec_config.cc b/test/mock/mock_stack_a2dp_codec_config.cc index 8d0132826..b3b7cfaf2 100644 --- a/test/mock/mock_stack_a2dp_codec_config.cc +++ b/test/mock/mock_stack_a2dp_codec_config.cc @@ -97,6 +97,10 @@ bool A2DP_InitCodecConfig(btav_a2dp_codec_index_t codec_index, mock_function_count_map[__func__]++; return false; } +int A2DP_GetEecoderEffectiveFrameSize(const uint8_t* p_codec_info) { + mock_function_count_map[__func__]++; + return 0; +} bool A2DP_IsPeerSinkCodecValid(const uint8_t* p_codec_info) { mock_function_count_map[__func__]++; return false; |