Deprecating ThreadChecker specific interface.

All changes outside thread_checker.h are by:
s/CalledOnValidThread/IsCurrent/
s/DetachFromThread/Detach/

Bug: webrtc:9883
Change-Id: Idbb1086bff0817db58e770116acf4c9d60fae8b3
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/131023
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27494}
This commit is contained in:
Sebastian Jansson
2019-04-08 15:20:44 +02:00
committed by Commit Bot
parent e5b94160b5
commit c01367db40
78 changed files with 617 additions and 615 deletions

View File

@ -174,7 +174,7 @@ AndroidNetworkMonitor::AndroidNetworkMonitor(
AndroidNetworkMonitor::~AndroidNetworkMonitor() = default;
void AndroidNetworkMonitor::Start() {
RTC_CHECK(thread_checker_.CalledOnValidThread());
RTC_CHECK(thread_checker_.IsCurrent());
if (started_) {
return;
}
@ -191,7 +191,7 @@ void AndroidNetworkMonitor::Start() {
}
void AndroidNetworkMonitor::Stop() {
RTC_CHECK(thread_checker_.CalledOnValidThread());
RTC_CHECK(thread_checker_.IsCurrent());
if (!started_) {
return;
}
@ -216,7 +216,7 @@ void AndroidNetworkMonitor::Stop() {
rtc::NetworkBindingResult AndroidNetworkMonitor::BindSocketToNetwork(
int socket_fd,
const rtc::IPAddress& address) {
RTC_CHECK(thread_checker_.CalledOnValidThread());
RTC_CHECK(thread_checker_.IsCurrent());
// Android prior to Lollipop didn't have support for binding sockets to
// networks. This may also occur if there is no connectivity manager service.
@ -354,7 +354,7 @@ void AndroidNetworkMonitor::OnNetworkDisconnected_w(NetworkHandle handle) {
void AndroidNetworkMonitor::SetNetworkInfos(
const std::vector<NetworkInformation>& network_infos) {
RTC_CHECK(thread_checker_.CalledOnValidThread());
RTC_CHECK(thread_checker_.IsCurrent());
network_handle_by_address_.clear();
network_info_by_handle_.clear();
RTC_LOG(LS_INFO) << "Android network monitor found " << network_infos.size()

View File

@ -28,7 +28,7 @@ AAudioPlayer::AAudioPlayer(const AudioParameters& audio_parameters)
: main_thread_(rtc::Thread::Current()),
aaudio_(audio_parameters, AAUDIO_DIRECTION_OUTPUT, this) {
RTC_LOG(INFO) << "ctor";
thread_checker_aaudio_.DetachFromThread();
thread_checker_aaudio_.Detach();
}
AAudioPlayer::~AAudioPlayer() {
@ -102,7 +102,7 @@ int AAudioPlayer::StopPlayout() {
RTC_LOG(LS_ERROR) << "StopPlayout failed";
return -1;
}
thread_checker_aaudio_.DetachFromThread();
thread_checker_aaudio_.Detach();
initialized_ = false;
playing_ = false;
return 0;

View File

@ -31,19 +31,19 @@ AAudioRecorder::AAudioRecorder(const AudioParameters& audio_parameters)
: main_thread_(rtc::Thread::Current()),
aaudio_(audio_parameters, AAUDIO_DIRECTION_INPUT, this) {
RTC_LOG(INFO) << "ctor";
thread_checker_aaudio_.DetachFromThread();
thread_checker_aaudio_.Detach();
}
AAudioRecorder::~AAudioRecorder() {
RTC_LOG(INFO) << "dtor";
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
Terminate();
RTC_LOG(INFO) << "detected owerflows: " << overflow_count_;
}
int AAudioRecorder::Init() {
RTC_LOG(INFO) << "Init";
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
if (aaudio_.audio_parameters().channels() == 2) {
RTC_DLOG(LS_WARNING) << "Stereo mode is enabled";
}
@ -52,14 +52,14 @@ int AAudioRecorder::Init() {
int AAudioRecorder::Terminate() {
RTC_LOG(INFO) << "Terminate";
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
StopRecording();
return 0;
}
int AAudioRecorder::InitRecording() {
RTC_LOG(INFO) << "InitRecording";
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
RTC_DCHECK(!initialized_);
RTC_DCHECK(!recording_);
if (!aaudio_.Init()) {
@ -75,7 +75,7 @@ bool AAudioRecorder::RecordingIsInitialized() const {
int AAudioRecorder::StartRecording() {
RTC_LOG(INFO) << "StartRecording";
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
RTC_DCHECK(initialized_);
RTC_DCHECK(!recording_);
if (fine_audio_buffer_) {
@ -92,14 +92,14 @@ int AAudioRecorder::StartRecording() {
int AAudioRecorder::StopRecording() {
RTC_LOG(INFO) << "StopRecording";
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
if (!initialized_ || !recording_) {
return 0;
}
if (!aaudio_.Stop()) {
return -1;
}
thread_checker_aaudio_.DetachFromThread();
thread_checker_aaudio_.Detach();
initialized_ = false;
recording_ = false;
return 0;
@ -111,7 +111,7 @@ bool AAudioRecorder::Recording() const {
void AAudioRecorder::AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) {
RTC_LOG(INFO) << "AttachAudioBuffer";
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
audio_device_buffer_ = audioBuffer;
const AudioParameters audio_parameters = aaudio_.audio_parameters();
audio_device_buffer_->SetRecordingSampleRate(audio_parameters.sample_rate());
@ -145,7 +145,7 @@ int AAudioRecorder::EnableBuiltInNS(bool enable) {
void AAudioRecorder::OnErrorCallback(aaudio_result_t error) {
RTC_LOG(LS_ERROR) << "OnErrorCallback: " << AAudio_convertResultToText(error);
// RTC_DCHECK(thread_checker_aaudio_.CalledOnValidThread());
// RTC_DCHECK(thread_checker_aaudio_.IsCurrent());
if (aaudio_.stream_state() == AAUDIO_STREAM_STATE_DISCONNECTED) {
// The stream is disconnected and any attempt to use it will return
// AAUDIO_ERROR_DISCONNECTED..
@ -165,7 +165,7 @@ aaudio_data_callback_result_t AAudioRecorder::OnDataCallback(
void* audio_data,
int32_t num_frames) {
// TODO(henrika): figure out why we sometimes hit this one.
// RTC_DCHECK(thread_checker_aaudio_.CalledOnValidThread());
// RTC_DCHECK(thread_checker_aaudio_.IsCurrent());
// RTC_LOG(INFO) << "OnDataCallback: " << num_frames;
// Drain the input buffer at first callback to ensure that it does not
// contain any old data. Will also ensure that the lowest possible latency

View File

@ -139,19 +139,19 @@ AAudioWrapper::AAudioWrapper(const AudioParameters& audio_parameters,
observer_(observer) {
RTC_LOG(INFO) << "ctor";
RTC_DCHECK(observer_);
aaudio_thread_checker_.DetachFromThread();
aaudio_thread_checker_.Detach();
RTC_LOG(INFO) << audio_parameters_.ToString();
}
AAudioWrapper::~AAudioWrapper() {
RTC_LOG(INFO) << "dtor";
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
RTC_DCHECK(!stream_);
}
bool AAudioWrapper::Init() {
RTC_LOG(INFO) << "Init";
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
// Creates a stream builder which can be used to open an audio stream.
ScopedStreamBuilder builder;
// Configures the stream builder using audio parameters given at construction.
@ -175,7 +175,7 @@ bool AAudioWrapper::Init() {
bool AAudioWrapper::Start() {
RTC_LOG(INFO) << "Start";
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
// TODO(henrika): this state check might not be needed.
aaudio_stream_state_t current_state = AAudioStream_getState(stream_);
if (current_state != AAUDIO_STREAM_STATE_OPEN) {
@ -191,11 +191,11 @@ bool AAudioWrapper::Start() {
bool AAudioWrapper::Stop() {
RTC_LOG(INFO) << "Stop: " << DirectionToString(direction());
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
// Asynchronous request for the stream to stop.
RETURN_ON_ERROR(AAudioStream_requestStop(stream_), false);
CloseStream();
aaudio_thread_checker_.DetachFromThread();
aaudio_thread_checker_.Detach();
return true;
}
@ -242,7 +242,7 @@ double AAudioWrapper::EstimateLatencyMillis() const {
bool AAudioWrapper::IncreaseOutputBufferSize() {
RTC_LOG(INFO) << "IncreaseBufferSize";
RTC_DCHECK(stream_);
RTC_DCHECK(aaudio_thread_checker_.CalledOnValidThread());
RTC_DCHECK(aaudio_thread_checker_.IsCurrent());
RTC_DCHECK_EQ(direction(), AAUDIO_DIRECTION_OUTPUT);
aaudio_result_t buffer_size = AAudioStream_getBufferSizeInFrames(stream_);
// Try to increase size of buffer with one burst to reduce risk of underrun.
@ -270,7 +270,7 @@ bool AAudioWrapper::IncreaseOutputBufferSize() {
void AAudioWrapper::ClearInputStream(void* audio_data, int32_t num_frames) {
RTC_LOG(INFO) << "ClearInputStream";
RTC_DCHECK(stream_);
RTC_DCHECK(aaudio_thread_checker_.CalledOnValidThread());
RTC_DCHECK(aaudio_thread_checker_.IsCurrent());
RTC_DCHECK_EQ(direction(), AAUDIO_DIRECTION_INPUT);
aaudio_result_t cleared_frames = 0;
do {
@ -359,7 +359,7 @@ int64_t AAudioWrapper::frames_read() const {
void AAudioWrapper::SetStreamConfiguration(AAudioStreamBuilder* builder) {
RTC_LOG(INFO) << "SetStreamConfiguration";
RTC_DCHECK(builder);
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
// Request usage of default primary output/input device.
// TODO(henrika): verify that default device follows Java APIs.
// https://developer.android.com/reference/android/media/AudioDeviceInfo.html.

View File

@ -69,7 +69,7 @@ class AndroidAudioDeviceModule : public AudioDeviceModule {
RTC_CHECK(input_);
RTC_CHECK(output_);
RTC_LOG(INFO) << __FUNCTION__;
thread_checker_.DetachFromThread();
thread_checker_.Detach();
}
~AndroidAudioDeviceModule() override { RTC_LOG(INFO) << __FUNCTION__; }
@ -88,7 +88,7 @@ class AndroidAudioDeviceModule : public AudioDeviceModule {
int32_t Init() override {
RTC_LOG(INFO) << __FUNCTION__;
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
audio_device_buffer_ =
absl::make_unique<AudioDeviceBuffer>(&GlobalTaskQueueFactory());
AttachAudioBuffer();
@ -119,11 +119,11 @@ class AndroidAudioDeviceModule : public AudioDeviceModule {
RTC_LOG(INFO) << __FUNCTION__;
if (!initialized_)
return 0;
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
int32_t err = input_->Terminate();
err |= output_->Terminate();
initialized_ = false;
thread_checker_.DetachFromThread();
thread_checker_.Detach();
audio_device_buffer_.reset(nullptr);
RTC_DCHECK_EQ(err, 0);
return err;

View File

@ -74,34 +74,34 @@ AudioRecordJni::AudioRecordJni(JNIEnv* env,
jni::jlongFromPointer(this));
// Detach from this thread since construction is allowed to happen on a
// different thread.
thread_checker_.DetachFromThread();
thread_checker_java_.DetachFromThread();
thread_checker_.Detach();
thread_checker_java_.Detach();
}
AudioRecordJni::~AudioRecordJni() {
RTC_LOG(INFO) << "dtor";
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
Terminate();
}
int32_t AudioRecordJni::Init() {
RTC_LOG(INFO) << "Init";
env_ = AttachCurrentThreadIfNeeded();
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
return 0;
}
int32_t AudioRecordJni::Terminate() {
RTC_LOG(INFO) << "Terminate";
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
StopRecording();
thread_checker_.DetachFromThread();
thread_checker_.Detach();
return 0;
}
int32_t AudioRecordJni::InitRecording() {
RTC_LOG(INFO) << "InitRecording";
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
if (initialized_) {
// Already initialized.
return 0;
@ -133,7 +133,7 @@ bool AudioRecordJni::RecordingIsInitialized() const {
int32_t AudioRecordJni::StartRecording() {
RTC_LOG(INFO) << "StartRecording";
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
if (recording_) {
// Already recording.
return 0;
@ -154,7 +154,7 @@ int32_t AudioRecordJni::StartRecording() {
int32_t AudioRecordJni::StopRecording() {
RTC_LOG(INFO) << "StopRecording";
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
if (!initialized_ || !recording_) {
return 0;
}
@ -165,7 +165,7 @@ int32_t AudioRecordJni::StopRecording() {
// If we don't detach here, we will hit a RTC_DCHECK in OnDataIsRecorded()
// next time StartRecording() is called since it will create a new Java
// thread.
thread_checker_java_.DetachFromThread();
thread_checker_java_.Detach();
initialized_ = false;
recording_ = false;
direct_buffer_address_ = nullptr;
@ -178,7 +178,7 @@ bool AudioRecordJni::Recording() const {
void AudioRecordJni::AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) {
RTC_LOG(INFO) << "AttachAudioBuffer";
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
audio_device_buffer_ = audioBuffer;
const int sample_rate_hz = audio_parameters_.sample_rate();
RTC_LOG(INFO) << "SetRecordingSampleRate(" << sample_rate_hz << ")";
@ -189,20 +189,20 @@ void AudioRecordJni::AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) {
}
bool AudioRecordJni::IsAcousticEchoCancelerSupported() const {
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
return Java_WebRtcAudioRecord_isAcousticEchoCancelerSupported(
env_, j_audio_record_);
}
bool AudioRecordJni::IsNoiseSuppressorSupported() const {
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
return Java_WebRtcAudioRecord_isNoiseSuppressorSupported(env_,
j_audio_record_);
}
int32_t AudioRecordJni::EnableBuiltInAEC(bool enable) {
RTC_LOG(INFO) << "EnableBuiltInAEC(" << enable << ")";
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
return Java_WebRtcAudioRecord_enableBuiltInAEC(env_, j_audio_record_, enable)
? 0
: -1;
@ -210,7 +210,7 @@ int32_t AudioRecordJni::EnableBuiltInAEC(bool enable) {
int32_t AudioRecordJni::EnableBuiltInNS(bool enable) {
RTC_LOG(INFO) << "EnableBuiltInNS(" << enable << ")";
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
return Java_WebRtcAudioRecord_enableBuiltInNS(env_, j_audio_record_, enable)
? 0
: -1;
@ -221,7 +221,7 @@ void AudioRecordJni::CacheDirectBufferAddress(
const JavaParamRef<jobject>& j_caller,
const JavaParamRef<jobject>& byte_buffer) {
RTC_LOG(INFO) << "OnCacheDirectBufferAddress";
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
RTC_DCHECK(!direct_buffer_address_);
direct_buffer_address_ = env->GetDirectBufferAddress(byte_buffer.obj());
jlong capacity = env->GetDirectBufferCapacity(byte_buffer.obj());
@ -234,7 +234,7 @@ void AudioRecordJni::CacheDirectBufferAddress(
void AudioRecordJni::DataIsRecorded(JNIEnv* env,
const JavaParamRef<jobject>& j_caller,
int length) {
RTC_DCHECK(thread_checker_java_.CalledOnValidThread());
RTC_DCHECK(thread_checker_java_.IsCurrent());
if (!audio_device_buffer_) {
RTC_LOG(LS_ERROR) << "AttachAudioBuffer has not been called";
return;

View File

@ -48,34 +48,34 @@ AudioTrackJni::AudioTrackJni(JNIEnv* env,
jni::jlongFromPointer(this));
// Detach from this thread since construction is allowed to happen on a
// different thread.
thread_checker_.DetachFromThread();
thread_checker_java_.DetachFromThread();
thread_checker_.Detach();
thread_checker_java_.Detach();
}
AudioTrackJni::~AudioTrackJni() {
RTC_LOG(INFO) << "dtor";
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
Terminate();
}
int32_t AudioTrackJni::Init() {
RTC_LOG(INFO) << "Init";
env_ = AttachCurrentThreadIfNeeded();
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
return 0;
}
int32_t AudioTrackJni::Terminate() {
RTC_LOG(INFO) << "Terminate";
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
StopPlayout();
thread_checker_.DetachFromThread();
thread_checker_.Detach();
return 0;
}
int32_t AudioTrackJni::InitPlayout() {
RTC_LOG(INFO) << "InitPlayout";
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
if (initialized_) {
// Already initialized.
return 0;
@ -97,7 +97,7 @@ bool AudioTrackJni::PlayoutIsInitialized() const {
int32_t AudioTrackJni::StartPlayout() {
RTC_LOG(INFO) << "StartPlayout";
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
if (playing_) {
// Already playing.
return 0;
@ -117,7 +117,7 @@ int32_t AudioTrackJni::StartPlayout() {
int32_t AudioTrackJni::StopPlayout() {
RTC_LOG(INFO) << "StopPlayout";
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
if (!initialized_ || !playing_) {
return 0;
}
@ -127,7 +127,7 @@ int32_t AudioTrackJni::StopPlayout() {
}
// If we don't detach here, we will hit a RTC_DCHECK next time StartPlayout()
// is called since it will create a new Java thread.
thread_checker_java_.DetachFromThread();
thread_checker_java_.Detach();
initialized_ = false;
playing_ = false;
direct_buffer_address_ = nullptr;
@ -144,7 +144,7 @@ bool AudioTrackJni::SpeakerVolumeIsAvailable() {
int AudioTrackJni::SetSpeakerVolume(uint32_t volume) {
RTC_LOG(INFO) << "SetSpeakerVolume(" << volume << ")";
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
return Java_WebRtcAudioTrack_setStreamVolume(env_, j_audio_track_,
static_cast<int>(volume))
? 0
@ -152,17 +152,17 @@ int AudioTrackJni::SetSpeakerVolume(uint32_t volume) {
}
absl::optional<uint32_t> AudioTrackJni::MaxSpeakerVolume() const {
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
return Java_WebRtcAudioTrack_getStreamMaxVolume(env_, j_audio_track_);
}
absl::optional<uint32_t> AudioTrackJni::MinSpeakerVolume() const {
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
return 0;
}
absl::optional<uint32_t> AudioTrackJni::SpeakerVolume() const {
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
const uint32_t volume =
Java_WebRtcAudioTrack_getStreamVolume(env_, j_audio_track_);
RTC_LOG(INFO) << "SpeakerVolume: " << volume;
@ -172,7 +172,7 @@ absl::optional<uint32_t> AudioTrackJni::SpeakerVolume() const {
// TODO(henrika): possibly add stereo support.
void AudioTrackJni::AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) {
RTC_LOG(INFO) << "AttachAudioBuffer";
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
audio_device_buffer_ = audioBuffer;
const int sample_rate_hz = audio_parameters_.sample_rate();
RTC_LOG(INFO) << "SetPlayoutSampleRate(" << sample_rate_hz << ")";
@ -187,7 +187,7 @@ void AudioTrackJni::CacheDirectBufferAddress(
const JavaParamRef<jobject>&,
const JavaParamRef<jobject>& byte_buffer) {
RTC_LOG(INFO) << "OnCacheDirectBufferAddress";
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
RTC_DCHECK(!direct_buffer_address_);
direct_buffer_address_ = env->GetDirectBufferAddress(byte_buffer.obj());
jlong capacity = env->GetDirectBufferCapacity(byte_buffer.obj());
@ -203,7 +203,7 @@ void AudioTrackJni::CacheDirectBufferAddress(
void AudioTrackJni::GetPlayoutData(JNIEnv* env,
const JavaParamRef<jobject>&,
size_t length) {
RTC_DCHECK(thread_checker_java_.CalledOnValidThread());
RTC_DCHECK(thread_checker_java_.IsCurrent());
const size_t bytes_per_frame = audio_parameters_.channels() * sizeof(int16_t);
RTC_DCHECK_EQ(frames_per_buffer_, length / bytes_per_frame);
if (!audio_device_buffer_) {

View File

@ -103,14 +103,14 @@ SLDataFormat_PCM CreatePCMConfiguration(size_t channels,
}
OpenSLEngineManager::OpenSLEngineManager() {
thread_checker_.DetachFromThread();
thread_checker_.Detach();
}
OpenSLEngineManager::~OpenSLEngineManager() = default;
SLObjectItf OpenSLEngineManager::GetOpenSLEngine() {
RTC_LOG(INFO) << "GetOpenSLEngine";
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
// OpenSL ES for Android only supports a single engine per application.
// If one already has been created, return existing object instead of
// creating a new.

View File

@ -64,12 +64,12 @@ OpenSLESPlayer::OpenSLESPlayer(
audio_parameters_.bits_per_sample());
// Detach from this thread since we want to use the checker to verify calls
// from the internal audio thread.
thread_checker_opensles_.DetachFromThread();
thread_checker_opensles_.Detach();
}
OpenSLESPlayer::~OpenSLESPlayer() {
ALOGD("dtor[tid=%d]", rtc::CurrentThreadId());
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
Terminate();
DestroyAudioPlayer();
DestroyMix();
@ -83,7 +83,7 @@ OpenSLESPlayer::~OpenSLESPlayer() {
int OpenSLESPlayer::Init() {
ALOGD("Init[tid=%d]", rtc::CurrentThreadId());
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
if (audio_parameters_.channels() == 2) {
ALOGW("Stereo mode is enabled");
}
@ -92,14 +92,14 @@ int OpenSLESPlayer::Init() {
int OpenSLESPlayer::Terminate() {
ALOGD("Terminate[tid=%d]", rtc::CurrentThreadId());
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
StopPlayout();
return 0;
}
int OpenSLESPlayer::InitPlayout() {
ALOGD("InitPlayout[tid=%d]", rtc::CurrentThreadId());
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
RTC_DCHECK(!initialized_);
RTC_DCHECK(!playing_);
if (!ObtainEngineInterface()) {
@ -118,7 +118,7 @@ bool OpenSLESPlayer::PlayoutIsInitialized() const {
int OpenSLESPlayer::StartPlayout() {
ALOGD("StartPlayout[tid=%d]", rtc::CurrentThreadId());
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
RTC_DCHECK(initialized_);
RTC_DCHECK(!playing_);
if (fine_audio_buffer_) {
@ -146,7 +146,7 @@ int OpenSLESPlayer::StartPlayout() {
int OpenSLESPlayer::StopPlayout() {
ALOGD("StopPlayout[tid=%d]", rtc::CurrentThreadId());
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
if (!initialized_ || !playing_) {
return 0;
}
@ -164,7 +164,7 @@ int OpenSLESPlayer::StopPlayout() {
// The number of lower latency audio players is limited, hence we create the
// audio player in Start() and destroy it in Stop().
DestroyAudioPlayer();
thread_checker_opensles_.DetachFromThread();
thread_checker_opensles_.Detach();
initialized_ = false;
playing_ = false;
return 0;
@ -196,7 +196,7 @@ absl::optional<uint32_t> OpenSLESPlayer::MinSpeakerVolume() const {
void OpenSLESPlayer::AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) {
ALOGD("AttachAudioBuffer");
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
audio_device_buffer_ = audioBuffer;
const int sample_rate_hz = audio_parameters_.sample_rate();
ALOGD("SetPlayoutSampleRate(%d)", sample_rate_hz);
@ -210,7 +210,7 @@ void OpenSLESPlayer::AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) {
void OpenSLESPlayer::AllocateDataBuffers() {
ALOGD("AllocateDataBuffers");
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
RTC_DCHECK(!simple_buffer_queue_);
RTC_CHECK(audio_device_buffer_);
// Create a modified audio buffer class which allows us to ask for any number
@ -235,7 +235,7 @@ void OpenSLESPlayer::AllocateDataBuffers() {
bool OpenSLESPlayer::ObtainEngineInterface() {
ALOGD("ObtainEngineInterface");
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
if (engine_)
return true;
// Get access to (or create if not already existing) the global OpenSL Engine
@ -254,7 +254,7 @@ bool OpenSLESPlayer::ObtainEngineInterface() {
bool OpenSLESPlayer::CreateMix() {
ALOGD("CreateMix");
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
RTC_DCHECK(engine_);
if (output_mix_.Get())
return true;
@ -270,7 +270,7 @@ bool OpenSLESPlayer::CreateMix() {
void OpenSLESPlayer::DestroyMix() {
ALOGD("DestroyMix");
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
if (!output_mix_.Get())
return;
output_mix_.Reset();
@ -278,7 +278,7 @@ void OpenSLESPlayer::DestroyMix() {
bool OpenSLESPlayer::CreateAudioPlayer() {
ALOGD("CreateAudioPlayer");
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
RTC_DCHECK(output_mix_.Get());
if (player_object_.Get())
return true;
@ -362,7 +362,7 @@ bool OpenSLESPlayer::CreateAudioPlayer() {
void OpenSLESPlayer::DestroyAudioPlayer() {
ALOGD("DestroyAudioPlayer");
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
if (!player_object_.Get())
return;
(*simple_buffer_queue_)
@ -382,7 +382,7 @@ void OpenSLESPlayer::SimpleBufferQueueCallback(
}
void OpenSLESPlayer::FillBufferQueue() {
RTC_DCHECK(thread_checker_opensles_.CalledOnValidThread());
RTC_DCHECK(thread_checker_opensles_.IsCurrent());
SLuint32 state = GetPlayState();
if (state != SL_PLAYSTATE_PLAYING) {
ALOGW("Buffer callback in non-playing state!");
@ -404,13 +404,13 @@ void OpenSLESPlayer::EnqueuePlayoutData(bool silence) {
SLint8* audio_ptr8 =
reinterpret_cast<SLint8*>(audio_buffers_[buffer_index_].get());
if (silence) {
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
// Avoid acquiring real audio data from WebRTC and fill the buffer with
// zeros instead. Used to prime the buffer with silence and to avoid asking
// for audio data from two different threads.
memset(audio_ptr8, 0, audio_parameters_.GetBytesPerBuffer());
} else {
RTC_DCHECK(thread_checker_opensles_.CalledOnValidThread());
RTC_DCHECK(thread_checker_opensles_.IsCurrent());
// Read audio data from the WebRTC source using the FineAudioBuffer object
// to adjust for differences in buffer size between WebRTC (10ms) and native
// OpenSL ES. Use hardcoded delay estimate since OpenSL ES does not support

View File

@ -59,7 +59,7 @@ OpenSLESRecorder::OpenSLESRecorder(
ALOGD("ctor[tid=%d]", rtc::CurrentThreadId());
// Detach from this thread since we want to use the checker to verify calls
// from the internal audio thread.
thread_checker_opensles_.DetachFromThread();
thread_checker_opensles_.Detach();
// Use native audio output parameters provided by the audio manager and
// define the PCM format structure.
pcm_format_ = CreatePCMConfiguration(audio_parameters_.channels(),
@ -69,7 +69,7 @@ OpenSLESRecorder::OpenSLESRecorder(
OpenSLESRecorder::~OpenSLESRecorder() {
ALOGD("dtor[tid=%d]", rtc::CurrentThreadId());
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
Terminate();
DestroyAudioRecorder();
engine_ = nullptr;
@ -80,7 +80,7 @@ OpenSLESRecorder::~OpenSLESRecorder() {
int OpenSLESRecorder::Init() {
ALOGD("Init[tid=%d]", rtc::CurrentThreadId());
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
if (audio_parameters_.channels() == 2) {
ALOGD("Stereo mode is enabled");
}
@ -89,14 +89,14 @@ int OpenSLESRecorder::Init() {
int OpenSLESRecorder::Terminate() {
ALOGD("Terminate[tid=%d]", rtc::CurrentThreadId());
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
StopRecording();
return 0;
}
int OpenSLESRecorder::InitRecording() {
ALOGD("InitRecording[tid=%d]", rtc::CurrentThreadId());
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
RTC_DCHECK(!initialized_);
RTC_DCHECK(!recording_);
if (!ObtainEngineInterface()) {
@ -115,7 +115,7 @@ bool OpenSLESRecorder::RecordingIsInitialized() const {
int OpenSLESRecorder::StartRecording() {
ALOGD("StartRecording[tid=%d]", rtc::CurrentThreadId());
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
RTC_DCHECK(initialized_);
RTC_DCHECK(!recording_);
if (fine_audio_buffer_) {
@ -152,7 +152,7 @@ int OpenSLESRecorder::StartRecording() {
int OpenSLESRecorder::StopRecording() {
ALOGD("StopRecording[tid=%d]", rtc::CurrentThreadId());
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
if (!initialized_ || !recording_) {
return 0;
}
@ -165,7 +165,7 @@ int OpenSLESRecorder::StopRecording() {
if (LOG_ON_ERROR((*simple_buffer_queue_)->Clear(simple_buffer_queue_))) {
return -1;
}
thread_checker_opensles_.DetachFromThread();
thread_checker_opensles_.Detach();
initialized_ = false;
recording_ = false;
return 0;
@ -177,7 +177,7 @@ bool OpenSLESRecorder::Recording() const {
void OpenSLESRecorder::AttachAudioBuffer(AudioDeviceBuffer* audio_buffer) {
ALOGD("AttachAudioBuffer");
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
RTC_CHECK(audio_buffer);
audio_device_buffer_ = audio_buffer;
// Ensure that the audio device buffer is informed about the native sample
@ -204,21 +204,21 @@ bool OpenSLESRecorder::IsNoiseSuppressorSupported() const {
int OpenSLESRecorder::EnableBuiltInAEC(bool enable) {
ALOGD("EnableBuiltInAEC(%d)", enable);
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
ALOGE("Not implemented");
return 0;
}
int OpenSLESRecorder::EnableBuiltInNS(bool enable) {
ALOGD("EnableBuiltInNS(%d)", enable);
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
ALOGE("Not implemented");
return 0;
}
bool OpenSLESRecorder::ObtainEngineInterface() {
ALOGD("ObtainEngineInterface");
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
if (engine_)
return true;
// Get access to (or create if not already existing) the global OpenSL Engine
@ -239,7 +239,7 @@ bool OpenSLESRecorder::ObtainEngineInterface() {
bool OpenSLESRecorder::CreateAudioRecorder() {
ALOGD("CreateAudioRecorder");
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
if (recorder_object_.Get())
return true;
RTC_DCHECK(!recorder_);
@ -320,7 +320,7 @@ bool OpenSLESRecorder::CreateAudioRecorder() {
void OpenSLESRecorder::DestroyAudioRecorder() {
ALOGD("DestroyAudioRecorder");
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
if (!recorder_object_.Get())
return;
(*simple_buffer_queue_)
@ -339,7 +339,7 @@ void OpenSLESRecorder::SimpleBufferQueueCallback(
void OpenSLESRecorder::AllocateDataBuffers() {
ALOGD("AllocateDataBuffers");
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(thread_checker_.IsCurrent());
RTC_DCHECK(!simple_buffer_queue_);
RTC_CHECK(audio_device_buffer_);
// Create a modified audio buffer class which allows us to deliver any number
@ -364,7 +364,7 @@ void OpenSLESRecorder::AllocateDataBuffers() {
}
void OpenSLESRecorder::ReadBufferQueue() {
RTC_DCHECK(thread_checker_opensles_.CalledOnValidThread());
RTC_DCHECK(thread_checker_opensles_.IsCurrent());
SLuint32 state = GetRecordState();
if (state != SL_RECORDSTATE_RECORDING) {
ALOGW("Buffer callback in non-recording state!");

View File

@ -49,7 +49,7 @@ VideoDecoderWrapper::VideoDecoderWrapper(JNIEnv* jni,
// if the decoder provides frames.
{
decoder_thread_checker_.DetachFromThread();
decoder_thread_checker_.Detach();
}
VideoDecoderWrapper::~VideoDecoderWrapper() = default;
@ -141,7 +141,7 @@ int32_t VideoDecoderWrapper::Release() {
}
initialized_ = false;
// It is allowed to reinitialize the codec on a different thread.
decoder_thread_checker_.DetachFromThread();
decoder_thread_checker_.Detach();
return status;
}