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:
@ -14,6 +14,7 @@
|
||||
#include <SLES/OpenSLES.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "api/ref_counted_base.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/thread_checker.h"
|
||||
@ -65,12 +66,12 @@ typedef ScopedSLObject<SLObjectItf, const SLObjectItf_*> ScopedSLObjectItf;
|
||||
// a reference to it. The engine object is only created at the first call
|
||||
// since OpenSL ES for Android only supports a single engine per application.
|
||||
// Subsequent calls returns the already created engine.
|
||||
// Note: This class must be used single threaded and this is enfored by a thread
|
||||
// checker.
|
||||
class OpenSLEngineManager {
|
||||
// Note: This class must be used single threaded and this is enforced by a
|
||||
// thread checker.
|
||||
class OpenSLEngineManager : public rtc::RefCountedBase {
|
||||
public:
|
||||
OpenSLEngineManager();
|
||||
~OpenSLEngineManager();
|
||||
~OpenSLEngineManager() override;
|
||||
SLObjectItf GetOpenSLEngine();
|
||||
|
||||
private:
|
||||
|
||||
@ -44,7 +44,7 @@ namespace jni {
|
||||
|
||||
OpenSLESPlayer::OpenSLESPlayer(
|
||||
const AudioParameters& audio_parameters,
|
||||
std::unique_ptr<OpenSLEngineManager> engine_manager)
|
||||
rtc::scoped_refptr<OpenSLEngineManager> engine_manager)
|
||||
: audio_parameters_(audio_parameters),
|
||||
audio_device_buffer_(nullptr),
|
||||
initialized_(false),
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/scoped_refptr.h"
|
||||
#include "modules/audio_device/audio_device_buffer.h"
|
||||
#include "modules/audio_device/fine_audio_buffer.h"
|
||||
#include "modules/audio_device/include/audio_device_defines.h"
|
||||
@ -60,7 +61,7 @@ class OpenSLESPlayer : public AudioOutput {
|
||||
static const int kNumOfOpenSLESBuffers = 2;
|
||||
|
||||
OpenSLESPlayer(const AudioParameters& audio_parameters,
|
||||
std::unique_ptr<OpenSLEngineManager> engine_manager);
|
||||
rtc::scoped_refptr<OpenSLEngineManager> engine_manager);
|
||||
~OpenSLESPlayer() override;
|
||||
|
||||
int Init() override;
|
||||
@ -159,7 +160,7 @@ class OpenSLESPlayer : public AudioOutput {
|
||||
// Example (kNumOfOpenSLESBuffers = 2): counts 0, 1, 0, 1, ...
|
||||
int buffer_index_;
|
||||
|
||||
std::unique_ptr<OpenSLEngineManager> engine_manager_;
|
||||
const rtc::scoped_refptr<OpenSLEngineManager> engine_manager_;
|
||||
// This interface exposes creation methods for all the OpenSL ES object types.
|
||||
// It is the OpenSL ES API entry point.
|
||||
SLEngineItf engine_;
|
||||
|
||||
@ -43,13 +43,14 @@ namespace webrtc {
|
||||
|
||||
namespace jni {
|
||||
|
||||
OpenSLESRecorder::OpenSLESRecorder(const AudioParameters& audio_parameters,
|
||||
OpenSLEngineManager* engine_manager)
|
||||
OpenSLESRecorder::OpenSLESRecorder(
|
||||
const AudioParameters& audio_parameters,
|
||||
rtc::scoped_refptr<OpenSLEngineManager> engine_manager)
|
||||
: audio_parameters_(audio_parameters),
|
||||
audio_device_buffer_(nullptr),
|
||||
initialized_(false),
|
||||
recording_(false),
|
||||
engine_manager_(engine_manager),
|
||||
engine_manager_(std::move(engine_manager)),
|
||||
engine_(nullptr),
|
||||
recorder_(nullptr),
|
||||
simple_buffer_queue_(nullptr),
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "api/scoped_refptr.h"
|
||||
#include "modules/audio_device/audio_device_buffer.h"
|
||||
#include "modules/audio_device/fine_audio_buffer.h"
|
||||
#include "modules/audio_device/include/audio_device_defines.h"
|
||||
@ -63,7 +64,7 @@ class OpenSLESRecorder : public AudioInput {
|
||||
static const int kNumOfOpenSLESBuffers = 2;
|
||||
|
||||
OpenSLESRecorder(const AudioParameters& audio_parameters,
|
||||
OpenSLEngineManager* engine_manager);
|
||||
rtc::scoped_refptr<OpenSLEngineManager> engine_manager);
|
||||
~OpenSLESRecorder() override;
|
||||
|
||||
int Init() override;
|
||||
@ -148,7 +149,7 @@ class OpenSLESRecorder : public AudioInput {
|
||||
bool initialized_;
|
||||
bool recording_;
|
||||
|
||||
OpenSLEngineManager* const engine_manager_;
|
||||
const rtc::scoped_refptr<OpenSLEngineManager> engine_manager_;
|
||||
// This interface exposes creation methods for all the OpenSL ES object types.
|
||||
// It is the OpenSL ES API entry point.
|
||||
SLEngineItf engine_;
|
||||
|
||||
Reference in New Issue
Block a user