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

Commit e330c19a authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Bluetooth audio HAL: several fixes on buffer duration calculation" am:...

Merge "Bluetooth audio HAL: several fixes on buffer duration calculation" am: 920c847f am: 6891145e

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/1961302

Change-Id: Ie8e51e25038d0b0f445132d2241e0cc59397aaa2
parents 35738bd6 6891145e
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -506,7 +506,7 @@ static ssize_t out_write(struct audio_stream_out* stream, const void* buffer,
        // drop data for cases of A2dpSuspended=true / closing=true
        totalWritten = bytes;
      }
      usleep(kBluetoothDefaultOutputBufferMs * 1000);
      usleep(out->preferred_data_interval_us);
      return totalWritten;
    }
    lock.lock();
@@ -743,6 +743,17 @@ int adev_open_output_stream(struct audio_hw_device* dev,
    out->preferred_data_interval_us = kBluetoothDefaultOutputBufferMs * 1000;
  }

  // Ensure minimum buffer duration for spatialized output
  if (flags == (AUDIO_OUTPUT_FLAG_FAST | AUDIO_OUTPUT_FLAG_DEEP_BUFFER) &&
      out->preferred_data_interval_us <
          kBluetoothSpatializerOutputBufferMs * 1000) {
    out->preferred_data_interval_us =
        kBluetoothSpatializerOutputBufferMs * 1000;
    LOG(INFO) << __func__
              << ": adjusting to minimum buffer duration for spatializer: "
              << StringPrintf("%zu", out->preferred_data_interval_us);
  }

  out->frames_count_ =
      frame_count(out->preferred_data_interval_us, out->sample_rate_);

@@ -1208,13 +1219,13 @@ int adev_open_input_stream(struct audio_hw_device* dev,
  in->format_ = config->format;
  // frame is number of samples per channel

  size_t preferred_data_interval_us = kBluetoothDefaultOutputBufferMs * 1000;
  size_t preferred_data_interval_us = kBluetoothDefaultInputBufferMs * 1000;
  if (in->bluetooth_input_.GetPreferredDataIntervalUs(
          &preferred_data_interval_us) &&
      preferred_data_interval_us != 0) {
    in->preferred_data_interval_us = preferred_data_interval_us;
  } else {
    in->preferred_data_interval_us = kBluetoothDefaultOutputBufferMs * 1000;
    in->preferred_data_interval_us = kBluetoothDefaultInputBufferMs * 1000;
  }

  in->frames_count_ =
+2 −0
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@ constexpr unsigned int kBluetoothDefaultInputBufferMs = 20;
constexpr unsigned int kBluetoothDefaultInputStateTimeoutMs = 20;

constexpr unsigned int kBluetoothDefaultOutputBufferMs = 2;
constexpr unsigned int kBluetoothSpatializerOutputBufferMs = 10;

constexpr audio_channel_mask_t kBluetoothDefaultOutputChannelModeMask =
    AUDIO_CHANNEL_OUT_STEREO;
constexpr audio_channel_mask_t kBluetoothDefaultInputChannelModeMask =