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

Commit 1b076537 authored by Chisato Kenmochi's avatar Chisato Kenmochi Committed by Pavlin Radoslavov
Browse files

Add support for A2DP LDAC Sink function



Note: The LDAC decoder source code is needed to run with this patch.

Bug: 112839060
Test: Manual
Change-Id: Idce0070dcce4d6b83cfd08213b846d957d694d26
Signed-off-by: default avatarChisato Kenmochi <Chisato.Kenmochi@sony.com>
parent f82ec2bf
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -85,6 +85,9 @@ tA2DP_SAMPLE_RATE btif_a2dp_sink_get_sample_rate(void);
// Get the audio channel count for the A2DP Sink module.
tA2DP_CHANNEL_COUNT btif_a2dp_sink_get_channel_count(void);

// Get the audio bits per sample for the A2DP Sink module.
tA2DP_BITS_PER_SAMPLE btif_a2dp_sink_get_bits_per_sample(void);

// Update the decoder for the A2DP Sink module.
// |p_codec_info| contains the new codec information.
void btif_a2dp_sink_update_decoder(const uint8_t* p_codec_info);
+2 −1
Original line number Diff line number Diff line
@@ -35,7 +35,8 @@
 * should eventually be
 * deleted using BtifAvrcpAudioTrackDelete (see below).
 */
void* BtifAvrcpAudioTrackCreate(int trackFreq, int channelType);
void* BtifAvrcpAudioTrackCreate(int trackFreq, int bits_per_sample,
                                int channelType);

/**
 * Starts the audio track.
+13 −1
Original line number Diff line number Diff line
@@ -113,6 +113,7 @@ class BtifA2dpSinkControlBlock {
  bool rx_flush; /* discards any incoming data when true */
  alarm_t* decode_alarm;
  tA2DP_SAMPLE_RATE sample_rate;
  tA2DP_BITS_PER_SAMPLE bits_per_sample;
  tA2DP_CHANNEL_COUNT channel_count;
  btif_a2dp_sink_focus_state_t rx_focus_state; /* audio focus state */
  void* audio_track;
@@ -320,6 +321,11 @@ tA2DP_SAMPLE_RATE btif_a2dp_sink_get_sample_rate() {
  return btif_a2dp_sink_cb.sample_rate;
}

tA2DP_BITS_PER_SAMPLE btif_a2dp_sink_get_bits_per_sample() {
  LockGuard lock(g_mutex);
  return btif_a2dp_sink_cb.bits_per_sample;
}

tA2DP_CHANNEL_COUNT btif_a2dp_sink_get_channel_count() {
  LockGuard lock(g_mutex);
  return btif_a2dp_sink_cb.channel_count;
@@ -539,6 +545,11 @@ static void btif_a2dp_sink_decoder_update_event(
    LOG_ERROR(LOG_TAG, "%s: cannot get the track frequency", __func__);
    return;
  }
  int bits_per_sample = A2DP_GetTrackBitsPerSample(p_buf->codec_info);
  if (bits_per_sample == -1) {
    LOG_ERROR(LOG_TAG, "%s: cannot get the bits per sample", __func__);
    return;
  }
  int channel_count = A2DP_GetTrackChannelCount(p_buf->codec_info);
  if (channel_count == -1) {
    LOG_ERROR(LOG_TAG, "%s: cannot get the channel count", __func__);
@@ -550,6 +561,7 @@ static void btif_a2dp_sink_decoder_update_event(
    return;
  }
  btif_a2dp_sink_cb.sample_rate = sample_rate;
  btif_a2dp_sink_cb.bits_per_sample = bits_per_sample;
  btif_a2dp_sink_cb.channel_count = channel_count;

  btif_a2dp_sink_cb.rx_flush = false;
@@ -571,7 +583,7 @@ static void btif_a2dp_sink_decoder_update_event(
  APPL_TRACE_DEBUG("%s: create audio track", __func__);
  btif_a2dp_sink_cb.audio_track =
#ifndef OS_GENERIC
      BtifAvrcpAudioTrackCreate(sample_rate, channel_type);
      BtifAvrcpAudioTrackCreate(sample_rate, bits_per_sample, channel_type);
#else
      NULL;
#endif
+19 −4
Original line number Diff line number Diff line
@@ -35,11 +35,26 @@ FILE* outputPcmSampleFile;
char outputFilename[50] = "/data/misc/bluedroid/output_sample.pcm";
#endif

void* BtifAvrcpAudioTrackCreate(int trackFreq, int channelType) {
  LOG_VERBOSE(LOG_TAG, "%s Track.cpp: btCreateTrack freq %d  channel %d ",
              __func__, trackFreq, channelType);
void* BtifAvrcpAudioTrackCreate(int trackFreq, int bits_per_sample,
                                int channelType) {
  audio_format_t format;
  switch (bits_per_sample) {
    default:
    case 16:
      format = AUDIO_FORMAT_PCM_16_BIT;
      break;
    case 24:
      format = AUDIO_FORMAT_PCM_24_BIT_PACKED;
      break;
    case 32:
      format = AUDIO_FORMAT_PCM_32_BIT;
      break;
  }
  LOG_VERBOSE(LOG_TAG,
              "%s Track.cpp: btCreateTrack freq %d format 0x%x channel %d ",
              __func__, trackFreq, format, channelType);
  sp<android::AudioTrack> track = new android::AudioTrack(
      AUDIO_STREAM_MUSIC, trackFreq, AUDIO_FORMAT_PCM_16_BIT, channelType,
      AUDIO_STREAM_MUSIC, trackFreq, format, channelType,
      (size_t)0 /*frameCount*/, (audio_output_flags_t)AUDIO_OUTPUT_FLAG_FAST,
      NULL /*callback_t*/, NULL /*void* user*/, 0 /*notificationFrames*/,
      AUDIO_SESSION_ALLOCATE, android::AudioTrack::TRANSFER_SYNC);
+4 −0
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ typedef enum {
  // Add an entry for each sink codec here
  BTAV_A2DP_CODEC_INDEX_SINK_SBC = BTAV_A2DP_CODEC_INDEX_SINK_MIN,
  BTAV_A2DP_CODEC_INDEX_SINK_AAC,
  BTAV_A2DP_CODEC_INDEX_SINK_LDAC,

  BTAV_A2DP_CODEC_INDEX_SINK_MAX,

@@ -154,6 +155,9 @@ typedef struct {
      case BTAV_A2DP_CODEC_INDEX_SINK_AAC:
        codec_name_str = "AAC (Sink)";
        break;
      case BTAV_A2DP_CODEC_INDEX_SINK_LDAC:
        codec_name_str = "LDAC (Sink)";
        break;
      case BTAV_A2DP_CODEC_INDEX_MAX:
        codec_name_str = "Unknown(CODEC_INDEX_MAX)";
        break;
Loading