Skip to content
Snippets Groups Projects
Commit 7ba89ded 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: 67c8895e

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

Change-Id: I565d669873cbe242d6988e9611387ee5116aaa1d
parents ccb10c9c 67c8895e
No related branches found
No related tags found
No related merge requests found
......@@ -27,6 +27,8 @@
#include <time.h>
#include <unistd.h>
#include <memory>
#include "BluetoothAudioSession.h"
#include "stream_apis.h"
#include "utils.h"
......@@ -697,7 +699,7 @@ int adev_open_output_stream(struct audio_hw_device* dev,
struct audio_stream_out** stream_out,
const char* address __unused) {
*stream_out = nullptr;
auto* out = new BluetoothStreamOut{};
auto out = std::make_unique<BluetoothStreamOut>();
if (::aidl::android::hardware::bluetooth::audio::BluetoothAudioSession::
IsAidlAvailable()) {
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)) {
out->bluetooth_output_ = nullptr;
LOG(ERROR) << __func__ << ": cannot init HAL";
delete out;
return -EINVAL;
}
LOG(VERBOSE) << __func__ << ": device=" << StringPrintf("%#x", devices);
......@@ -782,18 +783,21 @@ int adev_open_output_stream(struct audio_hw_device* dev,
out->frames_rendered_ = 0;
out->frames_presented_ = 0;
BluetoothStreamOut* out_ptr = out.release();
{
auto* bluetooth_device = reinterpret_cast<BluetoothAudioDevice*>(dev);
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()
<< ", sample_rate=" << out->sample_rate_
<< ", channels=" << StringPrintf("%#x", out->channel_mask_)
<< ", format=" << out->format_ << ", preferred_data_interval_us="
<< out->preferred_data_interval_us
<< ", frames=" << out->frames_count_;
*stream_out = &out_ptr->stream_out_;
LOG(INFO) << __func__ << ": state=" << out_ptr->bluetooth_output_->GetState()
<< ", sample_rate=" << out_ptr->sample_rate_
<< ", channels=" << StringPrintf("%#x", out_ptr->channel_mask_)
<< ", format=" << out_ptr->format_
<< ", preferred_data_interval_us="
<< out_ptr->preferred_data_interval_us
<< ", frames=" << out_ptr->frames_count_;
return 0;
}
......@@ -1203,7 +1207,7 @@ int adev_open_input_stream(struct audio_hw_device* dev,
const char* address __unused,
audio_source_t source __unused) {
*stream_in = nullptr;
auto* in = new BluetoothStreamIn{};
auto in = std::make_unique<BluetoothStreamIn>();
if (::aidl::android::hardware::bluetooth::audio::BluetoothAudioSession::
IsAidlAvailable()) {
in->bluetooth_input_ = std::make_unique<
......@@ -1217,7 +1221,6 @@ int adev_open_input_stream(struct audio_hw_device* dev,
if (!in->bluetooth_input_->SetUp(devices)) {
in->bluetooth_input_ = nullptr;
LOG(ERROR) << __func__ << ": cannot init HAL";
delete in;
return -EINVAL;
}
......@@ -1273,13 +1276,14 @@ int adev_open_input_stream(struct audio_hw_device* dev,
frame_count(in->preferred_data_interval_us, in->sample_rate_);
in->frames_presented_ = 0;
*stream_in = &in->stream_in_;
LOG(INFO) << __func__ << ": state=" << in->bluetooth_input_->GetState()
<< ", sample_rate=" << in->sample_rate_
<< ", channels=" << StringPrintf("%#x", in->channel_mask_)
<< ", format=" << in->format_
<< ", preferred_data_interval_us=" << in->preferred_data_interval_us
<< ", frames=" << in->frames_count_;
BluetoothStreamIn* in_ptr = in.release();
*stream_in = &in_ptr->stream_in_;
LOG(INFO) << __func__ << ": state=" << in_ptr->bluetooth_input_->GetState()
<< ", sample_rate=" << in_ptr->sample_rate_
<< ", channels=" << StringPrintf("%#x", in_ptr->channel_mask_)
<< ", format=" << in_ptr->format_ << ", preferred_data_interval_us="
<< in_ptr->preferred_data_interval_us
<< ", frames=" << in_ptr->frames_count_;
return 0;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment