In android aaudio wrappers use threads through TaskQueue interface
Bug: webrtc:9702 Change-Id: I4686b8312a5e6705050ec89381938ea5da379d9b Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/274160 Reviewed-by: Henrik Andreassson <henrika@webrtc.org> Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Cr-Commit-Position: refs/heads/main@{#38010}
This commit is contained in:
committed by
WebRTC LUCI CQ
parent
dd1eb2e1ec
commit
fbfd81f61a
@ -192,7 +192,6 @@ rtc_library("audio_device_impl") {
|
|||||||
"../../api/task_queue",
|
"../../api/task_queue",
|
||||||
"../../common_audio",
|
"../../common_audio",
|
||||||
"../../common_audio:common_audio_c",
|
"../../common_audio:common_audio_c",
|
||||||
"../../rtc_base",
|
|
||||||
"../../rtc_base:buffer",
|
"../../rtc_base:buffer",
|
||||||
"../../rtc_base:checks",
|
"../../rtc_base:checks",
|
||||||
"../../rtc_base:logging",
|
"../../rtc_base:logging",
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "api/array_view.h"
|
#include "api/array_view.h"
|
||||||
|
#include "api/task_queue/task_queue_base.h"
|
||||||
#include "modules/audio_device/android/audio_manager.h"
|
#include "modules/audio_device/android/audio_manager.h"
|
||||||
#include "modules/audio_device/fine_audio_buffer.h"
|
#include "modules/audio_device/fine_audio_buffer.h"
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
@ -20,12 +21,8 @@
|
|||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
enum AudioDeviceMessageType : uint32_t {
|
|
||||||
kMessageOutputStreamDisconnected,
|
|
||||||
};
|
|
||||||
|
|
||||||
AAudioPlayer::AAudioPlayer(AudioManager* audio_manager)
|
AAudioPlayer::AAudioPlayer(AudioManager* audio_manager)
|
||||||
: main_thread_(rtc::Thread::Current()),
|
: main_thread_(TaskQueueBase::Current()),
|
||||||
aaudio_(audio_manager, AAUDIO_DIRECTION_OUTPUT, this) {
|
aaudio_(audio_manager, AAUDIO_DIRECTION_OUTPUT, this) {
|
||||||
RTC_LOG(LS_INFO) << "ctor";
|
RTC_LOG(LS_INFO) << "ctor";
|
||||||
thread_checker_aaudio_.Detach();
|
thread_checker_aaudio_.Detach();
|
||||||
@ -147,7 +144,7 @@ void AAudioPlayer::OnErrorCallback(aaudio_result_t error) {
|
|||||||
// from the callback, use another thread instead". A message is therefore
|
// from the callback, use another thread instead". A message is therefore
|
||||||
// sent to the main thread to do the restart operation.
|
// sent to the main thread to do the restart operation.
|
||||||
RTC_DCHECK(main_thread_);
|
RTC_DCHECK(main_thread_);
|
||||||
main_thread_->Post(RTC_FROM_HERE, this, kMessageOutputStreamDisconnected);
|
main_thread_->PostTask([this] { HandleStreamDisconnected(); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,15 +201,6 @@ aaudio_data_callback_result_t AAudioPlayer::OnDataCallback(void* audio_data,
|
|||||||
return AAUDIO_CALLBACK_RESULT_CONTINUE;
|
return AAUDIO_CALLBACK_RESULT_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AAudioPlayer::OnMessage(rtc::Message* msg) {
|
|
||||||
RTC_DCHECK_RUN_ON(&main_thread_checker_);
|
|
||||||
switch (msg->message_id) {
|
|
||||||
case kMessageOutputStreamDisconnected:
|
|
||||||
HandleStreamDisconnected();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AAudioPlayer::HandleStreamDisconnected() {
|
void AAudioPlayer::HandleStreamDisconnected() {
|
||||||
RTC_DCHECK_RUN_ON(&main_thread_checker_);
|
RTC_DCHECK_RUN_ON(&main_thread_checker_);
|
||||||
RTC_DLOG(LS_INFO) << "HandleStreamDisconnected";
|
RTC_DLOG(LS_INFO) << "HandleStreamDisconnected";
|
||||||
|
|||||||
@ -16,10 +16,9 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "api/sequence_checker.h"
|
#include "api/sequence_checker.h"
|
||||||
|
#include "api/task_queue/task_queue_base.h"
|
||||||
#include "modules/audio_device/android/aaudio_wrapper.h"
|
#include "modules/audio_device/android/aaudio_wrapper.h"
|
||||||
#include "modules/audio_device/include/audio_device_defines.h"
|
#include "modules/audio_device/include/audio_device_defines.h"
|
||||||
#include "rtc_base/message_handler.h"
|
|
||||||
#include "rtc_base/thread.h"
|
|
||||||
#include "rtc_base/thread_annotations.h"
|
#include "rtc_base/thread_annotations.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
@ -48,8 +47,7 @@ class AudioManager;
|
|||||||
// where the internal AAudio buffer can be increased when needed. It will
|
// where the internal AAudio buffer can be increased when needed. It will
|
||||||
// reduce the risk of underruns (~glitches) at the expense of an increased
|
// reduce the risk of underruns (~glitches) at the expense of an increased
|
||||||
// latency.
|
// latency.
|
||||||
class AAudioPlayer final : public AAudioObserverInterface,
|
class AAudioPlayer final : public AAudioObserverInterface {
|
||||||
public rtc::MessageHandler {
|
|
||||||
public:
|
public:
|
||||||
explicit AAudioPlayer(AudioManager* audio_manager);
|
explicit AAudioPlayer(AudioManager* audio_manager);
|
||||||
~AAudioPlayer();
|
~AAudioPlayer();
|
||||||
@ -85,10 +83,6 @@ class AAudioPlayer final : public AAudioObserverInterface,
|
|||||||
// Called on a real-time thread owned by AAudio.
|
// Called on a real-time thread owned by AAudio.
|
||||||
void OnErrorCallback(aaudio_result_t error) override;
|
void OnErrorCallback(aaudio_result_t error) override;
|
||||||
|
|
||||||
// rtc::MessageHandler used for restart messages from the error-callback
|
|
||||||
// thread to the main (creating) thread.
|
|
||||||
void OnMessage(rtc::Message* msg) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Closes the existing stream and starts a new stream.
|
// Closes the existing stream and starts a new stream.
|
||||||
void HandleStreamDisconnected();
|
void HandleStreamDisconnected();
|
||||||
@ -102,8 +96,8 @@ class AAudioPlayer final : public AAudioObserverInterface,
|
|||||||
// object.
|
// object.
|
||||||
SequenceChecker thread_checker_aaudio_;
|
SequenceChecker thread_checker_aaudio_;
|
||||||
|
|
||||||
// The thread on which this object is created on.
|
// The task queue on which this object is created on.
|
||||||
rtc::Thread* main_thread_;
|
TaskQueueBase* main_thread_;
|
||||||
|
|
||||||
// Wraps all AAudio resources. Contains an output stream using the default
|
// Wraps all AAudio resources. Contains an output stream using the default
|
||||||
// output audio device. Can be accessed on both the main thread and the
|
// output audio device. Can be accessed on both the main thread and the
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "api/array_view.h"
|
#include "api/array_view.h"
|
||||||
|
#include "api/task_queue/task_queue_base.h"
|
||||||
#include "modules/audio_device/android/audio_manager.h"
|
#include "modules/audio_device/android/audio_manager.h"
|
||||||
#include "modules/audio_device/fine_audio_buffer.h"
|
#include "modules/audio_device/fine_audio_buffer.h"
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
@ -21,12 +22,8 @@
|
|||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
enum AudioDeviceMessageType : uint32_t {
|
|
||||||
kMessageInputStreamDisconnected,
|
|
||||||
};
|
|
||||||
|
|
||||||
AAudioRecorder::AAudioRecorder(AudioManager* audio_manager)
|
AAudioRecorder::AAudioRecorder(AudioManager* audio_manager)
|
||||||
: main_thread_(rtc::Thread::Current()),
|
: main_thread_(TaskQueueBase::Current()),
|
||||||
aaudio_(audio_manager, AAUDIO_DIRECTION_INPUT, this) {
|
aaudio_(audio_manager, AAUDIO_DIRECTION_INPUT, this) {
|
||||||
RTC_LOG(LS_INFO) << "ctor";
|
RTC_LOG(LS_INFO) << "ctor";
|
||||||
thread_checker_aaudio_.Detach();
|
thread_checker_aaudio_.Detach();
|
||||||
@ -142,7 +139,7 @@ void AAudioRecorder::OnErrorCallback(aaudio_result_t error) {
|
|||||||
// from the callback, use another thread instead". A message is therefore
|
// from the callback, use another thread instead". A message is therefore
|
||||||
// sent to the main thread to do the restart operation.
|
// sent to the main thread to do the restart operation.
|
||||||
RTC_DCHECK(main_thread_);
|
RTC_DCHECK(main_thread_);
|
||||||
main_thread_->Post(RTC_FROM_HERE, this, kMessageInputStreamDisconnected);
|
main_thread_->PostTask([this] { HandleStreamDisconnected(); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,18 +187,6 @@ aaudio_data_callback_result_t AAudioRecorder::OnDataCallback(
|
|||||||
return AAUDIO_CALLBACK_RESULT_CONTINUE;
|
return AAUDIO_CALLBACK_RESULT_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AAudioRecorder::OnMessage(rtc::Message* msg) {
|
|
||||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
|
||||||
switch (msg->message_id) {
|
|
||||||
case kMessageInputStreamDisconnected:
|
|
||||||
HandleStreamDisconnected();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
RTC_LOG(LS_ERROR) << "Invalid message id: " << msg->message_id;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AAudioRecorder::HandleStreamDisconnected() {
|
void AAudioRecorder::HandleStreamDisconnected() {
|
||||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||||
RTC_LOG(LS_INFO) << "HandleStreamDisconnected";
|
RTC_LOG(LS_INFO) << "HandleStreamDisconnected";
|
||||||
|
|||||||
@ -16,10 +16,9 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "api/sequence_checker.h"
|
#include "api/sequence_checker.h"
|
||||||
|
#include "api/task_queue/task_queue_base.h"
|
||||||
#include "modules/audio_device/android/aaudio_wrapper.h"
|
#include "modules/audio_device/android/aaudio_wrapper.h"
|
||||||
#include "modules/audio_device/include/audio_device_defines.h"
|
#include "modules/audio_device/include/audio_device_defines.h"
|
||||||
#include "rtc_base/message_handler.h"
|
|
||||||
#include "rtc_base/thread.h"
|
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
@ -41,8 +40,7 @@ class AudioManager;
|
|||||||
//
|
//
|
||||||
// TODO(henrika): add comments about device changes and adaptive buffer
|
// TODO(henrika): add comments about device changes and adaptive buffer
|
||||||
// management.
|
// management.
|
||||||
class AAudioRecorder : public AAudioObserverInterface,
|
class AAudioRecorder : public AAudioObserverInterface {
|
||||||
public rtc::MessageHandler {
|
|
||||||
public:
|
public:
|
||||||
explicit AAudioRecorder(AudioManager* audio_manager);
|
explicit AAudioRecorder(AudioManager* audio_manager);
|
||||||
~AAudioRecorder();
|
~AAudioRecorder();
|
||||||
@ -79,9 +77,6 @@ class AAudioRecorder : public AAudioObserverInterface,
|
|||||||
// Called on a real-time thread owned by AAudio.
|
// Called on a real-time thread owned by AAudio.
|
||||||
void OnErrorCallback(aaudio_result_t error) override;
|
void OnErrorCallback(aaudio_result_t error) override;
|
||||||
|
|
||||||
// rtc::MessageHandler used for restart messages.
|
|
||||||
void OnMessage(rtc::Message* msg) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Closes the existing stream and starts a new stream.
|
// Closes the existing stream and starts a new stream.
|
||||||
void HandleStreamDisconnected();
|
void HandleStreamDisconnected();
|
||||||
@ -96,7 +91,7 @@ class AAudioRecorder : public AAudioObserverInterface,
|
|||||||
SequenceChecker thread_checker_aaudio_;
|
SequenceChecker thread_checker_aaudio_;
|
||||||
|
|
||||||
// The thread on which this object is created on.
|
// The thread on which this object is created on.
|
||||||
rtc::Thread* main_thread_;
|
TaskQueueBase* main_thread_;
|
||||||
|
|
||||||
// Wraps all AAudio resources. Contains an input stream using the default
|
// Wraps all AAudio resources. Contains an input stream using the default
|
||||||
// input audio device.
|
// input audio device.
|
||||||
|
|||||||
@ -1225,10 +1225,15 @@ if (current_os == "linux" || is_android) {
|
|||||||
":audio_device_module_base",
|
":audio_device_module_base",
|
||||||
":base_jni",
|
":base_jni",
|
||||||
"../../api:array_view",
|
"../../api:array_view",
|
||||||
|
"../../api:sequence_checker",
|
||||||
|
"../../api/task_queue",
|
||||||
"../../modules/audio_device",
|
"../../modules/audio_device",
|
||||||
"../../modules/audio_device:audio_device_buffer",
|
"../../modules/audio_device:audio_device_buffer",
|
||||||
"../../rtc_base",
|
|
||||||
"../../rtc_base:checks",
|
"../../rtc_base:checks",
|
||||||
|
"../../rtc_base:logging",
|
||||||
|
"../../rtc_base:macromagic",
|
||||||
|
"../../rtc_base:stringutils",
|
||||||
|
"../../rtc_base:timeutils",
|
||||||
"../../system_wrappers",
|
"../../system_wrappers",
|
||||||
]
|
]
|
||||||
absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
|
absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "api/array_view.h"
|
#include "api/array_view.h"
|
||||||
|
#include "api/task_queue/task_queue_base.h"
|
||||||
#include "modules/audio_device/fine_audio_buffer.h"
|
#include "modules/audio_device/fine_audio_buffer.h"
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
@ -21,12 +22,8 @@ namespace webrtc {
|
|||||||
|
|
||||||
namespace jni {
|
namespace jni {
|
||||||
|
|
||||||
enum AudioDeviceMessageType : uint32_t {
|
|
||||||
kMessageOutputStreamDisconnected,
|
|
||||||
};
|
|
||||||
|
|
||||||
AAudioPlayer::AAudioPlayer(const AudioParameters& audio_parameters)
|
AAudioPlayer::AAudioPlayer(const AudioParameters& audio_parameters)
|
||||||
: main_thread_(rtc::Thread::Current()),
|
: main_thread_(TaskQueueBase::Current()),
|
||||||
aaudio_(audio_parameters, AAUDIO_DIRECTION_OUTPUT, this) {
|
aaudio_(audio_parameters, AAUDIO_DIRECTION_OUTPUT, this) {
|
||||||
RTC_LOG(LS_INFO) << "ctor";
|
RTC_LOG(LS_INFO) << "ctor";
|
||||||
thread_checker_aaudio_.Detach();
|
thread_checker_aaudio_.Detach();
|
||||||
@ -163,7 +160,7 @@ void AAudioPlayer::OnErrorCallback(aaudio_result_t error) {
|
|||||||
// from the callback, use another thread instead". A message is therefore
|
// from the callback, use another thread instead". A message is therefore
|
||||||
// sent to the main thread to do the restart operation.
|
// sent to the main thread to do the restart operation.
|
||||||
RTC_DCHECK(main_thread_);
|
RTC_DCHECK(main_thread_);
|
||||||
main_thread_->Post(RTC_FROM_HERE, this, kMessageOutputStreamDisconnected);
|
main_thread_->PostTask([this] { HandleStreamDisconnected(); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,15 +217,6 @@ aaudio_data_callback_result_t AAudioPlayer::OnDataCallback(void* audio_data,
|
|||||||
return AAUDIO_CALLBACK_RESULT_CONTINUE;
|
return AAUDIO_CALLBACK_RESULT_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AAudioPlayer::OnMessage(rtc::Message* msg) {
|
|
||||||
RTC_DCHECK_RUN_ON(&main_thread_checker_);
|
|
||||||
switch (msg->message_id) {
|
|
||||||
case kMessageOutputStreamDisconnected:
|
|
||||||
HandleStreamDisconnected();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AAudioPlayer::HandleStreamDisconnected() {
|
void AAudioPlayer::HandleStreamDisconnected() {
|
||||||
RTC_DCHECK_RUN_ON(&main_thread_checker_);
|
RTC_DCHECK_RUN_ON(&main_thread_checker_);
|
||||||
RTC_DLOG(LS_INFO) << "HandleStreamDisconnected";
|
RTC_DLOG(LS_INFO) << "HandleStreamDisconnected";
|
||||||
|
|||||||
@ -17,10 +17,9 @@
|
|||||||
|
|
||||||
#include "absl/types/optional.h"
|
#include "absl/types/optional.h"
|
||||||
#include "api/sequence_checker.h"
|
#include "api/sequence_checker.h"
|
||||||
|
#include "api/task_queue/task_queue_base.h"
|
||||||
#include "modules/audio_device/audio_device_buffer.h"
|
#include "modules/audio_device/audio_device_buffer.h"
|
||||||
#include "modules/audio_device/include/audio_device_defines.h"
|
#include "modules/audio_device/include/audio_device_defines.h"
|
||||||
#include "rtc_base/message_handler.h"
|
|
||||||
#include "rtc_base/thread.h"
|
|
||||||
#include "rtc_base/thread_annotations.h"
|
#include "rtc_base/thread_annotations.h"
|
||||||
#include "sdk/android/src/jni/audio_device/aaudio_wrapper.h"
|
#include "sdk/android/src/jni/audio_device/aaudio_wrapper.h"
|
||||||
#include "sdk/android/src/jni/audio_device/audio_device_module.h"
|
#include "sdk/android/src/jni/audio_device/audio_device_module.h"
|
||||||
@ -52,9 +51,7 @@ namespace jni {
|
|||||||
// where the internal AAudio buffer can be increased when needed. It will
|
// where the internal AAudio buffer can be increased when needed. It will
|
||||||
// reduce the risk of underruns (~glitches) at the expense of an increased
|
// reduce the risk of underruns (~glitches) at the expense of an increased
|
||||||
// latency.
|
// latency.
|
||||||
class AAudioPlayer final : public AudioOutput,
|
class AAudioPlayer final : public AudioOutput, public AAudioObserverInterface {
|
||||||
public AAudioObserverInterface,
|
|
||||||
public rtc::MessageHandler {
|
|
||||||
public:
|
public:
|
||||||
explicit AAudioPlayer(const AudioParameters& audio_parameters);
|
explicit AAudioPlayer(const AudioParameters& audio_parameters);
|
||||||
~AAudioPlayer() override;
|
~AAudioPlayer() override;
|
||||||
@ -90,11 +87,10 @@ class AAudioPlayer final : public AudioOutput,
|
|||||||
// Called on a real-time thread owned by AAudio.
|
// Called on a real-time thread owned by AAudio.
|
||||||
void OnErrorCallback(aaudio_result_t error) override;
|
void OnErrorCallback(aaudio_result_t error) override;
|
||||||
|
|
||||||
// rtc::MessageHandler used for restart messages from the error-callback
|
|
||||||
// thread to the main (creating) thread.
|
|
||||||
void OnMessage(rtc::Message* msg) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// TODO(henrika): Implement.
|
||||||
|
int GetPlayoutUnderrunCount() override { return 0; }
|
||||||
|
|
||||||
// Closes the existing stream and starts a new stream.
|
// Closes the existing stream and starts a new stream.
|
||||||
void HandleStreamDisconnected();
|
void HandleStreamDisconnected();
|
||||||
|
|
||||||
@ -108,7 +104,7 @@ class AAudioPlayer final : public AudioOutput,
|
|||||||
SequenceChecker thread_checker_aaudio_;
|
SequenceChecker thread_checker_aaudio_;
|
||||||
|
|
||||||
// The thread on which this object is created on.
|
// The thread on which this object is created on.
|
||||||
rtc::Thread* main_thread_;
|
TaskQueueBase* main_thread_;
|
||||||
|
|
||||||
// Wraps all AAudio resources. Contains an output stream using the default
|
// Wraps all AAudio resources. Contains an output stream using the default
|
||||||
// output audio device. Can be accessed on both the main thread and the
|
// output audio device. Can be accessed on both the main thread and the
|
||||||
|
|||||||
@ -22,12 +22,8 @@ namespace webrtc {
|
|||||||
|
|
||||||
namespace jni {
|
namespace jni {
|
||||||
|
|
||||||
enum AudioDeviceMessageType : uint32_t {
|
|
||||||
kMessageInputStreamDisconnected,
|
|
||||||
};
|
|
||||||
|
|
||||||
AAudioRecorder::AAudioRecorder(const AudioParameters& audio_parameters)
|
AAudioRecorder::AAudioRecorder(const AudioParameters& audio_parameters)
|
||||||
: main_thread_(rtc::Thread::Current()),
|
: main_thread_(TaskQueueBase::Current()),
|
||||||
aaudio_(audio_parameters, AAUDIO_DIRECTION_INPUT, this) {
|
aaudio_(audio_parameters, AAUDIO_DIRECTION_INPUT, this) {
|
||||||
RTC_LOG(LS_INFO) << "ctor";
|
RTC_LOG(LS_INFO) << "ctor";
|
||||||
thread_checker_aaudio_.Detach();
|
thread_checker_aaudio_.Detach();
|
||||||
@ -153,7 +149,7 @@ void AAudioRecorder::OnErrorCallback(aaudio_result_t error) {
|
|||||||
// from the callback, use another thread instead". A message is therefore
|
// from the callback, use another thread instead". A message is therefore
|
||||||
// sent to the main thread to do the restart operation.
|
// sent to the main thread to do the restart operation.
|
||||||
RTC_DCHECK(main_thread_);
|
RTC_DCHECK(main_thread_);
|
||||||
main_thread_->Post(RTC_FROM_HERE, this, kMessageInputStreamDisconnected);
|
main_thread_->PostTask([this] { HandleStreamDisconnected(); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,18 +197,6 @@ aaudio_data_callback_result_t AAudioRecorder::OnDataCallback(
|
|||||||
return AAUDIO_CALLBACK_RESULT_CONTINUE;
|
return AAUDIO_CALLBACK_RESULT_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AAudioRecorder::OnMessage(rtc::Message* msg) {
|
|
||||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
|
||||||
switch (msg->message_id) {
|
|
||||||
case kMessageInputStreamDisconnected:
|
|
||||||
HandleStreamDisconnected();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
RTC_LOG(LS_ERROR) << "Invalid message id: " << msg->message_id;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AAudioRecorder::HandleStreamDisconnected() {
|
void AAudioRecorder::HandleStreamDisconnected() {
|
||||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||||
RTC_LOG(LS_INFO) << "HandleStreamDisconnected";
|
RTC_LOG(LS_INFO) << "HandleStreamDisconnected";
|
||||||
|
|||||||
@ -16,10 +16,9 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "api/sequence_checker.h"
|
#include "api/sequence_checker.h"
|
||||||
|
#include "api/task_queue/task_queue_base.h"
|
||||||
#include "modules/audio_device/audio_device_buffer.h"
|
#include "modules/audio_device/audio_device_buffer.h"
|
||||||
#include "modules/audio_device/include/audio_device_defines.h"
|
#include "modules/audio_device/include/audio_device_defines.h"
|
||||||
#include "rtc_base/message_handler.h"
|
|
||||||
#include "rtc_base/thread.h"
|
|
||||||
#include "sdk/android/src/jni/audio_device/aaudio_wrapper.h"
|
#include "sdk/android/src/jni/audio_device/aaudio_wrapper.h"
|
||||||
#include "sdk/android/src/jni/audio_device/audio_device_module.h"
|
#include "sdk/android/src/jni/audio_device/audio_device_module.h"
|
||||||
|
|
||||||
@ -44,9 +43,7 @@ namespace jni {
|
|||||||
//
|
//
|
||||||
// TODO(henrika): add comments about device changes and adaptive buffer
|
// TODO(henrika): add comments about device changes and adaptive buffer
|
||||||
// management.
|
// management.
|
||||||
class AAudioRecorder : public AudioInput,
|
class AAudioRecorder : public AudioInput, public AAudioObserverInterface {
|
||||||
public AAudioObserverInterface,
|
|
||||||
public rtc::MessageHandler {
|
|
||||||
public:
|
public:
|
||||||
explicit AAudioRecorder(const AudioParameters& audio_parameters);
|
explicit AAudioRecorder(const AudioParameters& audio_parameters);
|
||||||
~AAudioRecorder() override;
|
~AAudioRecorder() override;
|
||||||
@ -82,9 +79,6 @@ class AAudioRecorder : public AudioInput,
|
|||||||
// Called on a real-time thread owned by AAudio.
|
// Called on a real-time thread owned by AAudio.
|
||||||
void OnErrorCallback(aaudio_result_t error) override;
|
void OnErrorCallback(aaudio_result_t error) override;
|
||||||
|
|
||||||
// rtc::MessageHandler used for restart messages.
|
|
||||||
void OnMessage(rtc::Message* msg) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Closes the existing stream and starts a new stream.
|
// Closes the existing stream and starts a new stream.
|
||||||
void HandleStreamDisconnected();
|
void HandleStreamDisconnected();
|
||||||
@ -99,7 +93,7 @@ class AAudioRecorder : public AudioInput,
|
|||||||
SequenceChecker thread_checker_aaudio_;
|
SequenceChecker thread_checker_aaudio_;
|
||||||
|
|
||||||
// The thread on which this object is created on.
|
// The thread on which this object is created on.
|
||||||
rtc::Thread* main_thread_;
|
TaskQueueBase* main_thread_;
|
||||||
|
|
||||||
// Wraps all AAudio resources. Contains an input stream using the default
|
// Wraps all AAudio resources. Contains an input stream using the default
|
||||||
// input audio device.
|
// input audio device.
|
||||||
|
|||||||
Reference in New Issue
Block a user