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

Commit 397dcfdf authored by Pavlin Radoslavov's avatar Pavlin Radoslavov
Browse files

BTIF A2DP Source and Sink refactor and cleanup

* Moved bta/av/bta_av_sbc.c to stack/a2dp/a2d_sbc_up_sample.c
  and renamed the corresponding bta_av_sbc_up_sample_* functions to
  a2d_sbc_up_sample_*
  Also, renamed bta_av_sbc_init_up_sample() to a2d_sbc_init_up_sample()
* Moved A2DP SBC Encoder-related tasks, state and constants from
  btif_a2dp_source.cc to a2d_sbc_encoder.c
* Introduced A2DP encoder callbacks interface tA2D_ENCODER_INTERFACE,
  and added A2D_GetEncoderInterface() to acccess the interface for a codec.
* Updated a2d_sbc_encoder_init() to specify callbacks:
  - a2d_source_read_callback_t - a callback to read audio data for encoding
  - a2d_source_enqueue_callback_t - a callback to enqueue A2DP source
    packets for transmission
* Removed BTIF_MEDIA_TRSCD_* - the encoding is always PCM
* Removed conditionally defined constants and replaced them by
  local definitions:
  - BTIF_MEDIA_BITRATE_STEP -> A2D_SBC_BITRATE_STEP
  - BTIF_A2DP_DEFAULT_BITRATE -> A2D_SBC_DEFAULT_BITRATE
  - BTIF_A2DP_NON_EDR_MAX_RATE -> A2D_SBC_NON_EDR_MAX_RATE
* Hard-coded the read data timeout period A2DP_DATA_READ_POLL_MS to 10ms
* Merged the UNDERRUN read errors into the UNDERFLOW errors.
* Removed the following statistics, because they are not very useful:
  - media_read_total_limited_frames
  - media_read_max_limited_frames
  - media_read_limited_count
  - media_read_total_expected_frames
  - media_read_max_expected_frames
  - media_read_expected_count
* Updated the implementation of buffer_overruns_max_count to
  use the (new) counter tx_queue_max_dropped_messages instead of
  media_read_max_expected_frames
* Replaced usage of LOG_DEBUG() in stack/a2d/ with LOG_VERBOSE():
  the former is enabled by default on some of the builds.
* Renamed:
  - btif_a2dp_sink_audio_focus_state_t -> btif_a2dp_sink_focus_state_t
  - btif_a2dp_sink_set_audio_focus_state_req() ->
    btif_a2dp_sink_set_focus_state_req()
  - tBTIF_A2DP_SINK_CB.RxSbcQ -> rx_audio_queue
  - btif_a2dp_source_start_aa_req() -> btif_a2dp_source_start_audio_req()
  - btif_a2dp_source_stop_aa_req() -> btif_a2dp_source_stop_audio_req()
  - btif_a2dp_source_aa_readbuf() -> btif_a2dp_source_audio_readbuf()
  - tBTIF_A2DP_SOURCE_CB.TxAaQ -> tx_audio_queue
  - BTIF_A2DP_SOURCE_MEDIA_TIMER_MS -> A2D_SBC_ENCODER_INTERVAL_MS
  - tA2D_AV_MEDIA_FEEDINGS -> tA2D_FEEDING_PARAMS
  - tBTIF_A2DP_SOURCE_INIT_AUDIO -> tA2D_ENCODER_INIT_PARAMS
  - tBTIF_A2DP_SOURCE_UPDATE_AUDIO -> tA2D_ENCODER_UPDATE_PARAMS
  - tBTIF_A2DP_SOURCE_INIT_AUDIO_FEEDING -> tBTIF_A2DP_SOURCE_INIT_FEEDING

Bug: 30958229
Test: TestTracker/65192
Change-Id: Iba0a9694bda3dba73f211f1bde25821497fa6a06
parent a8cee4f3
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -79,7 +79,6 @@ LOCAL_SRC_FILES:= \
    ./av/bta_av_main.c \
    ./av/bta_av_cfg.c \
    ./av/bta_av_ssm.c \
    ./av/bta_av_sbc.c \
    ./ar/bta_ar.c \
    ./hl/bta_hl_act.c \
    ./hl/bta_hl_api.c \
+0 −1
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@ static_library("bta") {
    "av/bta_av_cfg.c",
    "av/bta_av_ci.c",
    "av/bta_av_main.c",
    "av/bta_av_sbc.c",
    "av/bta_av_ssm.c",
    "closure/bta_closure.cc",
    "dm/bta_dm_act.cc",
+31 −14
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
 *
 ******************************************************************************/

#include <assert.h>
#include <string.h>
#include "a2d_api.h"
#include "bt_target.h"
@@ -765,7 +766,7 @@ void* bta_av_co_audio_src_data_path(const uint8_t *p_codec_info,

    APPL_TRACE_DEBUG("%s: codec: %s", __func__, A2D_CodecName(p_codec_info));

    p_buf = btif_a2dp_source_aa_readbuf();
    p_buf = btif_a2dp_source_audio_readbuf();
    if (p_buf == NULL)
        return NULL;

@@ -1069,11 +1070,11 @@ static void bta_av_co_audio_codec_reset(void)
 ** Returns          true if successful, false otherwise
 **
 *******************************************************************************/
bool bta_av_co_audio_set_codec(const tA2D_AV_MEDIA_FEEDINGS *p_feeding)
bool bta_av_co_audio_set_codec(const tA2D_FEEDING_PARAMS *p_feeding_params)
{
    uint8_t new_cfg[AVDT_CODEC_SIZE];

    if (!A2D_SetCodec(p_feeding, new_cfg))
    if (!A2D_SetCodec(p_feeding_params, new_cfg))
        return false;

    /* The new config was correctly built */
@@ -1083,11 +1084,12 @@ bool bta_av_co_audio_set_codec(const tA2D_AV_MEDIA_FEEDINGS *p_feeding)
    return bta_av_co_audio_codec_supported();
}

void bta_av_co_audio_encoder_init(tBTIF_A2DP_SOURCE_INIT_AUDIO *msg)
void bta_av_co_audio_encoder_init(tA2D_ENCODER_INIT_PARAMS *p_init_params)
{
    uint16_t min_mtu = 0xFFFF;

    APPL_TRACE_DEBUG("%s", __func__);
    assert(p_init_params != nullptr);

    /* Protect access to bta_av_co_cb.codec_cfg */
    mutex_global_lock();
@@ -1102,22 +1104,23 @@ void bta_av_co_audio_encoder_init(tBTIF_A2DP_SOURCE_INIT_AUDIO *msg)
    }

    const uint8_t *p_codec_info = bta_av_co_cb.codec_cfg;
    msg->NumOfSubBands = A2D_GetNumberOfSubbands(p_codec_info);
    msg->NumOfBlocks = A2D_GetNumberOfBlocks(p_codec_info);
    msg->AllocationMethod = A2D_GetAllocationMethodCode(p_codec_info);
    msg->ChannelMode = A2D_GetChannelModeCode(p_codec_info);
    msg->SamplingFreq = A2D_GetSamplingFrequencyCode(p_codec_info);
    msg->MtuSize = min_mtu;
    p_init_params->NumOfSubBands = A2D_GetNumberOfSubbands(p_codec_info);
    p_init_params->NumOfBlocks = A2D_GetNumberOfBlocks(p_codec_info);
    p_init_params->AllocationMethod = A2D_GetAllocationMethodCode(p_codec_info);
    p_init_params->ChannelMode = A2D_GetChannelModeCode(p_codec_info);
    p_init_params->SamplingFreq = A2D_GetSamplingFrequencyCode(p_codec_info);
    p_init_params->MtuSize = min_mtu;

    /* Protect access to bta_av_co_cb.codec_cfg */
    mutex_global_unlock();
}

void bta_av_co_audio_encoder_update(tBTIF_A2DP_SOURCE_UPDATE_AUDIO *msg)
void bta_av_co_audio_encoder_update(tA2D_ENCODER_UPDATE_PARAMS *p_update_params)
{
    uint16_t min_mtu = 0xFFFF;

    APPL_TRACE_DEBUG("%s", __func__);
    assert(p_update_params != nullptr);

    /* Protect access to bta_av_co_cb.codec_cfg */
    mutex_global_lock();
@@ -1186,9 +1189,23 @@ void bta_av_co_audio_encoder_update(tBTIF_A2DP_SOURCE_UPDATE_AUDIO *msg)
        return;
    }

    msg->MinMtuSize = min_mtu;
    msg->MinBitPool = min_bitpool;
    msg->MaxBitPool = max_bitpool;
    p_update_params->MinMtuSize = min_mtu;
    p_update_params->MinBitPool = min_bitpool;
    p_update_params->MaxBitPool = max_bitpool;
}

const tA2D_ENCODER_INTERFACE *bta_av_co_get_encoder_interface(void)
{
    /* Protect access to bta_av_co_cb.codec_cfg */
    mutex_global_lock();

    const tA2D_ENCODER_INTERFACE *encoder_interface =
        A2D_GetEncoderInterface(bta_av_co_cb.codec_cfg);

    /* Protect access to bta_av_co_cb.codec_cfg */
    mutex_global_unlock();

    return encoder_interface;
}

/*******************************************************************************
+0 −8
Original line number Diff line number Diff line
@@ -28,14 +28,6 @@
extern "C" {
#endif

//
// |MAX_PCM_FRAME_NUM_PER_TICK| controls how many buffers we can hold in
// the A2DP buffer queues during temporary link congestion.
//
#ifndef MAX_PCM_FRAME_NUM_PER_TICK
#define MAX_PCM_FRAME_NUM_PER_TICK     14
#endif

// Process 'idle' request from the BTIF state machine during initialization.
void btif_a2dp_on_idle(void);

+3 −3
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ extern "C" {
typedef enum {
  BTIF_A2DP_SINK_FOCUS_NOT_GRANTED = 0,
  BTIF_A2DP_SINK_FOCUS_GRANTED = 1
} btif_a2dp_sink_audio_focus_state_t;
} btif_a2dp_sink_focus_state_t;

// Initialize and startup the A2DP Sink module.
// This function should be called by the BTIF state machine prior to using the
@@ -97,9 +97,9 @@ void btif_a2dp_sink_debug_dump(int fd);
void btif_a2dp_sink_update_metrics(void);

// Create a request to set the audio focus state for the audio track.
// |state| is the new state value - see |btif_a2dp_sink_audio_focus_state_t|
// |state| is the new state value - see |btif_a2dp_sink_focus_state_t|
// for valid values.
void btif_a2dp_sink_set_audio_focus_state_req(btif_a2dp_sink_audio_focus_state_t state);
void btif_a2dp_sink_set_focus_state_req(btif_a2dp_sink_focus_state_t state);

// Set the audio track gain for the audio track.
// |gain| is the audio track gain value to use.
Loading