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

Commit 3083e1a2 authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Jakub Pawłowski
Browse files

Fix the stereo microphone cache issue

Without this patch, we would not wipe the microphone cache after audio
is passed to audio framework. We would later use old cached data again.
This means we were sending data to audio framework too often causing
alsa mixer crashes.

Test: make a mono phone call, make stereo phone call, drop connection
during phone call, ensure no crashes and good audio quality
Bug: 209004829
Bug: 150670922
Change-Id: I07511439cb60ac8a772f523411fbca018cd3f995
parent fb35baa9
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -2119,6 +2119,12 @@ class LeAudioClientImpl : public LeAudioClient {
    }
  }

  void CleanCachedMicrophoneData() {
    cached_channel_data_.clear();
    cached_channel_timestamp_ = 0;
    cached_channel_is_left_ = false;
  }

  void SendAudioData(uint8_t* data, uint16_t size, uint16_t cis_conn_hdl,
                     uint32_t timestamp) {
    /* Get only one channel for MONO microphone */
@@ -2211,9 +2217,9 @@ class LeAudioClientImpl : public LeAudioClient {
                        &pcm_data_decoded, nullptr);
      return;
    }

    /* both devices are connected */
    if (cached_channel_timestamp_ == 0) {

    if (cached_channel_timestamp_ == 0 && cached_channel_data_.empty()) {
      /* First packet received, cache it. We need both channel data to send it
       * to AF. */
      cached_channel_data_ = pcm_data_decoded;
@@ -2237,7 +2243,7 @@ class LeAudioClientImpl : public LeAudioClient {
                            &pcm_data_decoded, &cached_channel_data_);
        }

        cached_channel_timestamp_ = 0;
        CleanCachedMicrophoneData();
        return;
      }

@@ -2401,7 +2407,8 @@ class LeAudioClientImpl : public LeAudioClient {
    uint16_t remote_delay_ms =
        group->GetRemoteDelay(le_audio::types::kLeAudioDirectionSource);

    cached_channel_timestamp_ = 0;
    CleanCachedMicrophoneData();

    if (CodecManager::GetInstance()->GetCodecLocation() ==
        le_audio::types::CodecLocation::HOST) {
      if (lc3_decoder_left_mem) {