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

Commit 920c847f authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

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

parents c18507ad 69b4ce60
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 =