Use scoped_refptr to share the instance of OpenSLEngineManager

Use rtc::scoped_refptr instead of std::unique_ptr to hold the instance
of OpenSLEngineManager; this makes it safe to share it between
OpenSLESRecorder and OpenSLESPlayer.

Bug: webrtc:10436
Change-Id: Ibd0717e5410020c89a40bfdb05953a02378a6a4b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/128651
Commit-Queue: Lu Liu <lliuu@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Henrik Andreassson <henrika@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27253}
This commit is contained in:
Lu Liu
2019-03-22 12:40:05 -07:00
committed by Commit Bot
parent b947fe1218
commit c771c805f1
8 changed files with 29 additions and 16 deletions

View File

@ -14,6 +14,7 @@
#include <utility>
#include "absl/memory/memory.h"
#include "api/scoped_refptr.h"
#include "rtc_base/logging.h"
#include "rtc_base/ref_count.h"
#include "rtc_base/ref_counted_object.h"
@ -109,9 +110,10 @@ rtc::scoped_refptr<AudioDeviceModule> CreateOpenSLESAudioDeviceModule(
GetDefaultAudioParameters(env, application_context, &input_parameters,
&output_parameters);
// Create ADM from OpenSLESRecorder and OpenSLESPlayer.
auto engine_manager = absl::make_unique<jni::OpenSLEngineManager>();
auto audio_input = absl::make_unique<jni::OpenSLESRecorder>(
input_parameters, engine_manager.get());
rtc::scoped_refptr<jni::OpenSLEngineManager> engine_manager(
new jni::OpenSLEngineManager());
auto audio_input = absl::make_unique<jni::OpenSLESRecorder>(input_parameters,
engine_manager);
auto audio_output = absl::make_unique<jni::OpenSLESPlayer>(
output_parameters, std::move(engine_manager));
return CreateAudioDeviceModuleFromInputAndOutput(
@ -138,8 +140,11 @@ CreateJavaInputAndOpenSLESOutputAudioDeviceModule(JNIEnv* env,
env, input_parameters, jni::kLowLatencyModeDelayEstimateInMilliseconds,
jni::AudioRecordJni::CreateJavaWebRtcAudioRecord(env, j_context,
j_audio_manager));
rtc::scoped_refptr<jni::OpenSLEngineManager> engine_manager(
new jni::OpenSLEngineManager());
auto audio_output = absl::make_unique<jni::OpenSLESPlayer>(
output_parameters, absl::make_unique<jni::OpenSLEngineManager>());
output_parameters, std::move(engine_manager));
return CreateAudioDeviceModuleFromInputAndOutput(
AudioDeviceModule::kAndroidJavaInputAndOpenSLESOutputAudio,
false /* use_stereo_input */, false /* use_stereo_output */,