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

Commit cf968e9a authored by Jakub Pawłowski's avatar Jakub Pawłowski Committed by Automerger Merge Worker
Browse files

Merge "stream_apis: use a unique_ptr to avoid memory leaks" am: 73569d29 am:...

Merge "stream_apis: use a unique_ptr to avoid memory leaks" am: 73569d29 am: 67c8895e am: 7ba89ded am: c4c4f922

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

Change-Id: I3fda782875b039d0cf1c1e2800c727d13c7881aa
parents 80331757 c4c4f922
Loading
Loading
Loading
Loading
+23 −19
Original line number Original line Diff line number Diff line
@@ -27,6 +27,8 @@
#include <time.h>
#include <time.h>
#include <unistd.h>
#include <unistd.h>


#include <memory>

#include "BluetoothAudioSession.h"
#include "BluetoothAudioSession.h"
#include "stream_apis.h"
#include "stream_apis.h"
#include "utils.h"
#include "utils.h"
@@ -697,7 +699,7 @@ int adev_open_output_stream(struct audio_hw_device* dev,
                            struct audio_stream_out** stream_out,
                            struct audio_stream_out** stream_out,
                            const char* address __unused) {
                            const char* address __unused) {
  *stream_out = nullptr;
  *stream_out = nullptr;
  auto* out = new BluetoothStreamOut{};
  auto out = std::make_unique<BluetoothStreamOut>();
  if (::aidl::android::hardware::bluetooth::audio::BluetoothAudioSession::
  if (::aidl::android::hardware::bluetooth::audio::BluetoothAudioSession::
          IsAidlAvailable()) {
          IsAidlAvailable()) {
    out->bluetooth_output_ = std::make_unique<
    out->bluetooth_output_ = std::make_unique<
@@ -711,7 +713,6 @@ int adev_open_output_stream(struct audio_hw_device* dev,
  if (!out->bluetooth_output_->SetUp(devices)) {
  if (!out->bluetooth_output_->SetUp(devices)) {
    out->bluetooth_output_ = nullptr;
    out->bluetooth_output_ = nullptr;
    LOG(ERROR) << __func__ << ": cannot init HAL";
    LOG(ERROR) << __func__ << ": cannot init HAL";
    delete out;
    return -EINVAL;
    return -EINVAL;
  }
  }
  LOG(VERBOSE) << __func__ << ": device=" << StringPrintf("%#x", devices);
  LOG(VERBOSE) << __func__ << ": device=" << StringPrintf("%#x", devices);
@@ -783,18 +784,21 @@ int adev_open_output_stream(struct audio_hw_device* dev,
  out->frames_rendered_ = 0;
  out->frames_rendered_ = 0;
  out->frames_presented_ = 0;
  out->frames_presented_ = 0;


  BluetoothStreamOut* out_ptr = out.release();
  {
  {
    auto* bluetooth_device = reinterpret_cast<BluetoothAudioDevice*>(dev);
    auto* bluetooth_device = reinterpret_cast<BluetoothAudioDevice*>(dev);
    std::lock_guard<std::mutex> guard(bluetooth_device->mutex_);
    std::lock_guard<std::mutex> guard(bluetooth_device->mutex_);
    bluetooth_device->opened_stream_outs_.push_back(out);
    bluetooth_device->opened_stream_outs_.push_back(out_ptr);
  }
  }
  *stream_out = &out->stream_out_;

  LOG(INFO) << __func__ << ": state=" << out->bluetooth_output_->GetState()
  *stream_out = &out_ptr->stream_out_;
            << ", sample_rate=" << out->sample_rate_
  LOG(INFO) << __func__ << ": state=" << out_ptr->bluetooth_output_->GetState()
            << ", channels=" << StringPrintf("%#x", out->channel_mask_)
            << ", sample_rate=" << out_ptr->sample_rate_
            << ", format=" << out->format_ << ", preferred_data_interval_us="
            << ", channels=" << StringPrintf("%#x", out_ptr->channel_mask_)
            << out->preferred_data_interval_us
            << ", format=" << out_ptr->format_
            << ", frames=" << out->frames_count_;
            << ", preferred_data_interval_us="
            << out_ptr->preferred_data_interval_us
            << ", frames=" << out_ptr->frames_count_;
  return 0;
  return 0;
}
}


@@ -1204,7 +1208,7 @@ int adev_open_input_stream(struct audio_hw_device* dev,
                           const char* address __unused,
                           const char* address __unused,
                           audio_source_t source __unused) {
                           audio_source_t source __unused) {
  *stream_in = nullptr;
  *stream_in = nullptr;
  auto* in = new BluetoothStreamIn{};
  auto in = std::make_unique<BluetoothStreamIn>();
  if (::aidl::android::hardware::bluetooth::audio::BluetoothAudioSession::
  if (::aidl::android::hardware::bluetooth::audio::BluetoothAudioSession::
          IsAidlAvailable()) {
          IsAidlAvailable()) {
    in->bluetooth_input_ = std::make_unique<
    in->bluetooth_input_ = std::make_unique<
@@ -1218,7 +1222,6 @@ int adev_open_input_stream(struct audio_hw_device* dev,
  if (!in->bluetooth_input_->SetUp(devices)) {
  if (!in->bluetooth_input_->SetUp(devices)) {
    in->bluetooth_input_ = nullptr;
    in->bluetooth_input_ = nullptr;
    LOG(ERROR) << __func__ << ": cannot init HAL";
    LOG(ERROR) << __func__ << ": cannot init HAL";
    delete in;
    return -EINVAL;
    return -EINVAL;
  }
  }


@@ -1274,13 +1277,14 @@ int adev_open_input_stream(struct audio_hw_device* dev,
      frame_count(in->preferred_data_interval_us, in->sample_rate_);
      frame_count(in->preferred_data_interval_us, in->sample_rate_);
  in->frames_presented_ = 0;
  in->frames_presented_ = 0;


  *stream_in = &in->stream_in_;
  BluetoothStreamIn* in_ptr = in.release();
  LOG(INFO) << __func__ << ": state=" << in->bluetooth_input_->GetState()
  *stream_in = &in_ptr->stream_in_;
            << ", sample_rate=" << in->sample_rate_
  LOG(INFO) << __func__ << ": state=" << in_ptr->bluetooth_input_->GetState()
            << ", channels=" << StringPrintf("%#x", in->channel_mask_)
            << ", sample_rate=" << in_ptr->sample_rate_
            << ", format=" << in->format_
            << ", channels=" << StringPrintf("%#x", in_ptr->channel_mask_)
            << ", preferred_data_interval_us=" << in->preferred_data_interval_us
            << ", format=" << in_ptr->format_ << ", preferred_data_interval_us="
            << ", frames=" << in->frames_count_;
            << in_ptr->preferred_data_interval_us
            << ", frames=" << in_ptr->frames_count_;


  return 0;
  return 0;
}
}