From 30d5f6d7f7701d5df8d966ce74337218dd4f5e32 Mon Sep 17 00:00:00 2001 From: Paulina Hensman Date: Wed, 11 Apr 2018 10:30:42 +0200 Subject: [PATCH] Small cleanup in sdk/android ADM Mainly remove CHECKinitialized_ macro and AGC functionality. Also make actual behavior clearer in some functions. Bug: webrtc:7452 Change-Id: I1eac86f4eaff7b14820d3e4192b15c20ab6acb45 Reviewed-on: https://webrtc-review.googlesource.com/69161 Reviewed-by: Magnus Jedvert Commit-Queue: Paulina Hensman Cr-Commit-Position: refs/heads/master@{#22820} --- .../src/jni/audio_device/aaudio_recorder.cc | 6 - .../src/jni/audio_device/aaudio_recorder.h | 1 - .../jni/audio_device/audio_device_module.cc | 148 ++++++------------ .../jni/audio_device/audio_device_module.h | 1 - .../src/jni/audio_device/audio_record_jni.cc | 8 +- .../src/jni/audio_device/audio_record_jni.h | 1 - .../src/jni/audio_device/audio_track_jni.cc | 5 +- .../src/jni/audio_device/opensles_recorder.cc | 7 - .../src/jni/audio_device/opensles_recorder.h | 1 - 9 files changed, 51 insertions(+), 127 deletions(-) diff --git a/sdk/android/src/jni/audio_device/aaudio_recorder.cc b/sdk/android/src/jni/audio_device/aaudio_recorder.cc index a52affcb5d..f77348feb3 100644 --- a/sdk/android/src/jni/audio_device/aaudio_recorder.cc +++ b/sdk/android/src/jni/audio_device/aaudio_recorder.cc @@ -136,12 +136,6 @@ int AAudioRecorder::EnableBuiltInAEC(bool enable) { return -1; } -int AAudioRecorder::EnableBuiltInAGC(bool enable) { - RTC_LOG(INFO) << "EnableBuiltInAGC: " << enable; - RTC_LOG(LS_ERROR) << "Not implemented"; - return -1; -} - int AAudioRecorder::EnableBuiltInNS(bool enable) { RTC_LOG(INFO) << "EnableBuiltInNS: " << enable; RTC_LOG(LS_ERROR) << "Not implemented"; diff --git a/sdk/android/src/jni/audio_device/aaudio_recorder.h b/sdk/android/src/jni/audio_device/aaudio_recorder.h index 8f92c4e181..32f2aea647 100644 --- a/sdk/android/src/jni/audio_device/aaudio_recorder.h +++ b/sdk/android/src/jni/audio_device/aaudio_recorder.h @@ -66,7 +66,6 @@ class AAudioRecorder : public AudioInput, bool IsAcousticEchoCancelerSupported() const override; bool IsNoiseSuppressorSupported() const override; int EnableBuiltInAEC(bool enable) override; - int EnableBuiltInAGC(bool enable) override; int EnableBuiltInNS(bool enable) override; protected: diff --git a/sdk/android/src/jni/audio_device/audio_device_module.cc b/sdk/android/src/jni/audio_device/audio_device_module.cc index 1375cba02e..555086cefa 100644 --- a/sdk/android/src/jni/audio_device/audio_device_module.cc +++ b/sdk/android/src/jni/audio_device/audio_device_module.cc @@ -19,20 +19,6 @@ #include "sdk/android/generated_audio_device_base_jni/jni/WebRtcAudioManager_jni.h" #include "system_wrappers/include/metrics.h" -#define CHECKinitialized_() \ - { \ - if (!initialized_) { \ - return -1; \ - } \ - } - -#define CHECKinitialized__BOOL() \ - { \ - if (!initialized_) { \ - return false; \ - } \ - } - namespace webrtc { namespace android_adm { @@ -136,7 +122,6 @@ class AndroidAudioDeviceModule : public AudioDeviceModule { bool Initialized() const override { RTC_LOG(INFO) << __FUNCTION__ << ":" << initialized_; - RTC_DCHECK(thread_checker_.CalledOnValidThread()); // not done in _impl return initialized_; } @@ -201,7 +186,8 @@ class AndroidAudioDeviceModule : public AudioDeviceModule { int32_t InitPlayout() override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized_(); + if (!initialized_) + return -1; if (PlayoutIsInitialized()) { return 0; } @@ -214,7 +200,6 @@ class AndroidAudioDeviceModule : public AudioDeviceModule { bool PlayoutIsInitialized() const override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized__BOOL(); return output_->PlayoutIsInitialized(); } @@ -227,7 +212,8 @@ class AndroidAudioDeviceModule : public AudioDeviceModule { int32_t InitRecording() override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized_(); + if (!initialized_) + return -1; if (RecordingIsInitialized()) { return 0; } @@ -240,13 +226,13 @@ class AndroidAudioDeviceModule : public AudioDeviceModule { bool RecordingIsInitialized() const override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized__BOOL(); return input_->RecordingIsInitialized(); } int32_t StartPlayout() override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized_(); + if (!initialized_) + return -1; if (Playing()) { return 0; } @@ -260,7 +246,8 @@ class AndroidAudioDeviceModule : public AudioDeviceModule { int32_t StopPlayout() override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized_(); + if (!initialized_) + return -1; if (!Playing()) return 0; RTC_LOG(INFO) << __FUNCTION__; @@ -274,13 +261,13 @@ class AndroidAudioDeviceModule : public AudioDeviceModule { bool Playing() const override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized__BOOL(); return output_->Playing(); } int32_t StartRecording() override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized_(); + if (!initialized_) + return -1; if (Recording()) { return 0; } @@ -294,8 +281,8 @@ class AndroidAudioDeviceModule : public AudioDeviceModule { int32_t StopRecording() override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized_(); - // Avoid using audio manger (JNI/Java cost) if recording was inactive. + if (!initialized_) + return -1; if (!Recording()) return 0; audio_device_buffer_->StopRecording(); @@ -308,39 +295,33 @@ class AndroidAudioDeviceModule : public AudioDeviceModule { bool Recording() const override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized__BOOL(); return input_->Recording(); } int32_t InitSpeaker() override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized_(); - return 0; + return initialized_ ? 0 : -1; } bool SpeakerIsInitialized() const override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized__BOOL(); - RTC_LOG(INFO) << "output: " << true; - return true; + return initialized_; } int32_t InitMicrophone() override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized_(); - return 0; + return initialized_ ? 0 : -1; } bool MicrophoneIsInitialized() const override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized__BOOL(); - RTC_LOG(INFO) << "output: " << true; - return true; + return initialized_; } int32_t SpeakerVolumeIsAvailable(bool* available) override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized_(); + if (!initialized_) + return -1; *available = output_->SpeakerVolumeIsAvailable(); RTC_LOG(INFO) << "output: " << *available; return 0; @@ -348,13 +329,15 @@ class AndroidAudioDeviceModule : public AudioDeviceModule { int32_t SetSpeakerVolume(uint32_t volume) override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized_(); + if (!initialized_) + return -1; return output_->SetSpeakerVolume(volume); } int32_t SpeakerVolume(uint32_t* output_volume) const override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized_(); + if (!initialized_) + return -1; rtc::Optional volume = output_->SpeakerVolume(); if (!volume) return -1; @@ -365,7 +348,8 @@ class AndroidAudioDeviceModule : public AudioDeviceModule { int32_t MaxSpeakerVolume(uint32_t* output_max_volume) const override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized_(); + if (!initialized_) + return -1; rtc::Optional max_volume = output_->MaxSpeakerVolume(); if (!max_volume) return -1; @@ -375,7 +359,8 @@ class AndroidAudioDeviceModule : public AudioDeviceModule { int32_t MinSpeakerVolume(uint32_t* output_min_volume) const override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized_(); + if (!initialized_) + return -1; rtc::Optional min_volume = output_->MinSpeakerVolume(); if (!min_volume) return -1; @@ -385,7 +370,6 @@ class AndroidAudioDeviceModule : public AudioDeviceModule { int32_t MicrophoneVolumeIsAvailable(bool* available) override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized_(); *available = false; RTC_LOG(INFO) << "output: " << *available; return -1; @@ -393,77 +377,66 @@ class AndroidAudioDeviceModule : public AudioDeviceModule { int32_t SetMicrophoneVolume(uint32_t volume) override { RTC_LOG(INFO) << __FUNCTION__ << "(" << volume << ")"; - CHECKinitialized_(); FATAL() << "Should never be called"; return -1; } int32_t MicrophoneVolume(uint32_t* volume) const override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized_(); FATAL() << "Should never be called"; return -1; } int32_t MaxMicrophoneVolume(uint32_t* maxVolume) const override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized_(); FATAL() << "Should never be called"; return -1; } int32_t MinMicrophoneVolume(uint32_t* minVolume) const override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized_(); FATAL() << "Should never be called"; return -1; } int32_t SpeakerMuteIsAvailable(bool* available) override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized_(); FATAL() << "Should never be called"; return -1; } int32_t SetSpeakerMute(bool enable) override { RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; - CHECKinitialized_(); FATAL() << "Should never be called"; return -1; } int32_t SpeakerMute(bool* enabled) const override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized_(); FATAL() << "Should never be called"; return -1; } int32_t MicrophoneMuteIsAvailable(bool* available) override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized_(); FATAL() << "Not implemented"; return -1; } int32_t SetMicrophoneMute(bool enable) override { RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; - CHECKinitialized_(); FATAL() << "Not implemented"; return -1; } int32_t MicrophoneMute(bool* enabled) const override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized_(); FATAL() << "Not implemented"; return -1; } int32_t StereoPlayoutIsAvailable(bool* available) const override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized_(); *available = is_stereo_playout_supported_; RTC_LOG(INFO) << "output: " << *available; return 0; @@ -471,29 +444,19 @@ class AndroidAudioDeviceModule : public AudioDeviceModule { int32_t SetStereoPlayout(bool enable) override { RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; - CHECKinitialized_(); - if (PlayoutIsInitialized()) { - RTC_LOG(WARNING) << "recording in stereo is not supported"; - return -1; - } + // Android does not support changes between mono and stero on the fly. The + // use of stereo or mono is determined by the audio layer. It is allowed + // to call this method if that same state is not modified. bool available = is_stereo_playout_supported_; - // Android does not support changes between mono and stero on the fly. It is - // allowed to call this method if that same state is not modified. if (enable != available) { - RTC_LOG(WARNING) << "failed to change stereo recording"; + RTC_LOG(WARNING) << "changing stereo playout not supported"; return -1; } - int8_t nChannels(1); - if (enable) { - nChannels = 2; - } - audio_device_buffer_->SetPlayoutChannels(nChannels); return 0; } int32_t StereoPlayout(bool* enabled) const override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized_(); *enabled = is_stereo_playout_supported_; RTC_LOG(INFO) << "output: " << *enabled; return 0; @@ -501,7 +464,6 @@ class AndroidAudioDeviceModule : public AudioDeviceModule { int32_t StereoRecordingIsAvailable(bool* available) const override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized_(); *available = is_stereo_record_supported_; RTC_LOG(INFO) << "output: " << *available; return 0; @@ -509,36 +471,25 @@ class AndroidAudioDeviceModule : public AudioDeviceModule { int32_t SetStereoRecording(bool enable) override { RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; - CHECKinitialized_(); - if (RecordingIsInitialized()) { - RTC_LOG(WARNING) << "recording in stereo is not supported"; - return -1; - } + // Android does not support changes between mono and stero on the fly. The + // use of stereo or mono is determined by the audio layer. It is allowed + // to call this method if that same state is not modified. bool available = is_stereo_record_supported_; - // Android does not support changes between mono and stero on the fly. It is - // allowed to call this method if that same state is not modified. if (enable != available) { - RTC_LOG(WARNING) << "failed to change stereo recording"; + RTC_LOG(WARNING) << "changing stereo recording not supported"; return -1; } - int8_t nChannels(1); - if (enable) { - nChannels = 2; - } - audio_device_buffer_->SetRecordingChannels(nChannels); return 0; } int32_t StereoRecording(bool* enabled) const override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized_(); *enabled = is_stereo_record_supported_; RTC_LOG(INFO) << "output: " << *enabled; return 0; } int32_t PlayoutDelay(uint16_t* delay_ms) const override { - CHECKinitialized_(); // Best guess we can do is to use half of the estimated total delay. *delay_ms = playout_delay_ms_; RTC_DCHECK_GT(*delay_ms, 0); @@ -559,22 +510,18 @@ class AndroidAudioDeviceModule : public AudioDeviceModule { // until I have added full support for audio effects based on OpenSL ES APIs. bool BuiltInAECIsAvailable() const override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized__BOOL(); + if (!initialized_) + return false; bool isAvailable = input_->IsAcousticEchoCancelerSupported(); RTC_LOG(INFO) << "output: " << isAvailable; return isAvailable; } - // Returns true if the device both supports built in AGC and the device - // is not blacklisted. - // TODO(henrika): add implementation for OpenSL ES based audio as well. - // In addition, see comments for BuiltInAECIsAvailable(). + // Not implemented for any input device on Android. bool BuiltInAGCIsAvailable() const override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized__BOOL(); - bool isAvailable = false; - RTC_LOG(INFO) << "output: " << isAvailable; - return isAvailable; + RTC_LOG(INFO) << "output: " << false; + return false; } // Returns true if the device both supports built in NS and the device @@ -583,7 +530,8 @@ class AndroidAudioDeviceModule : public AudioDeviceModule { // In addition, see comments for BuiltInAECIsAvailable(). bool BuiltInNSIsAvailable() const override { RTC_LOG(INFO) << __FUNCTION__; - CHECKinitialized__BOOL(); + if (!initialized_) + return false; bool isAvailable = input_->IsNoiseSuppressorSupported(); RTC_LOG(INFO) << "output: " << isAvailable; return isAvailable; @@ -592,27 +540,25 @@ class AndroidAudioDeviceModule : public AudioDeviceModule { // TODO(henrika): add implementation for OpenSL ES based audio as well. int32_t EnableBuiltInAEC(bool enable) override { RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; - CHECKinitialized_(); + if (!initialized_) + return -1; RTC_CHECK(BuiltInAECIsAvailable()) << "HW AEC is not available"; int32_t result = input_->EnableBuiltInAEC(enable); RTC_LOG(INFO) << "output: " << result; return result; } - // TODO(henrika): add implementation for OpenSL ES based audio as well. int32_t EnableBuiltInAGC(bool enable) override { RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; - CHECKinitialized_(); - RTC_CHECK(BuiltInAGCIsAvailable()) << "HW AGC is not available"; - int32_t result = input_->EnableBuiltInAGC(enable); - RTC_LOG(INFO) << "output: " << result; - return result; + FATAL() << "HW AGC is not available"; + return -1; } // TODO(henrika): add implementation for OpenSL ES based audio as well. int32_t EnableBuiltInNS(bool enable) override { RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; - CHECKinitialized_(); + if (!initialized_) + return -1; RTC_CHECK(BuiltInNSIsAvailable()) << "HW NS is not available"; int32_t result = input_->EnableBuiltInNS(enable); RTC_LOG(INFO) << "output: " << result; diff --git a/sdk/android/src/jni/audio_device/audio_device_module.h b/sdk/android/src/jni/audio_device/audio_device_module.h index b797040c02..27de3a0fcc 100644 --- a/sdk/android/src/jni/audio_device/audio_device_module.h +++ b/sdk/android/src/jni/audio_device/audio_device_module.h @@ -43,7 +43,6 @@ class AudioInput { virtual bool IsNoiseSuppressorSupported() const = 0; virtual int32_t EnableBuiltInAEC(bool enable) = 0; - virtual int32_t EnableBuiltInAGC(bool enable) = 0; virtual int32_t EnableBuiltInNS(bool enable) = 0; }; diff --git a/sdk/android/src/jni/audio_device/audio_record_jni.cc b/sdk/android/src/jni/audio_device/audio_record_jni.cc index 4008c9bd48..9b1d5f8982 100644 --- a/sdk/android/src/jni/audio_device/audio_record_jni.cc +++ b/sdk/android/src/jni/audio_device/audio_record_jni.cc @@ -182,11 +182,13 @@ void AudioRecordJni::AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) { } bool AudioRecordJni::IsAcousticEchoCancelerSupported() const { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); return Java_WebRtcAudioRecord_isAcousticEchoCancelerSupported( env_, j_audio_record_); } bool AudioRecordJni::IsNoiseSuppressorSupported() const { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); return Java_WebRtcAudioRecord_isNoiseSuppressorSupported(env_, j_audio_record_); } @@ -199,12 +201,6 @@ int32_t AudioRecordJni::EnableBuiltInAEC(bool enable) { : -1; } -int32_t AudioRecordJni::EnableBuiltInAGC(bool enable) { - // TODO(henrika): possibly remove when no longer used by any client. - FATAL() << "Should never be called"; - return -1; -} - int32_t AudioRecordJni::EnableBuiltInNS(bool enable) { RTC_LOG(INFO) << "EnableBuiltInNS(" << enable << ")"; RTC_DCHECK(thread_checker_.CalledOnValidThread()); diff --git a/sdk/android/src/jni/audio_device/audio_record_jni.h b/sdk/android/src/jni/audio_device/audio_record_jni.h index fa70fe347b..23ae51b93f 100644 --- a/sdk/android/src/jni/audio_device/audio_record_jni.h +++ b/sdk/android/src/jni/audio_device/audio_record_jni.h @@ -70,7 +70,6 @@ class AudioRecordJni : public AudioInput { bool IsNoiseSuppressorSupported() const override; int32_t EnableBuiltInAEC(bool enable) override; - int32_t EnableBuiltInAGC(bool enable) override; int32_t EnableBuiltInNS(bool enable) override; // Called from Java side so we can cache the address of the Java-manged diff --git a/sdk/android/src/jni/audio_device/audio_track_jni.cc b/sdk/android/src/jni/audio_device/audio_track_jni.cc index 4544cecb0b..0e6c554ae9 100644 --- a/sdk/android/src/jni/audio_device/audio_track_jni.cc +++ b/sdk/android/src/jni/audio_device/audio_track_jni.cc @@ -118,9 +118,8 @@ int32_t AudioTrackJni::StopPlayout() { RTC_LOG(LS_ERROR) << "StopPlayout failed"; return -1; } - // 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. + // 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(); initialized_ = false; playing_ = false; diff --git a/sdk/android/src/jni/audio_device/opensles_recorder.cc b/sdk/android/src/jni/audio_device/opensles_recorder.cc index f80e486c93..b3af25bcfb 100644 --- a/sdk/android/src/jni/audio_device/opensles_recorder.cc +++ b/sdk/android/src/jni/audio_device/opensles_recorder.cc @@ -209,13 +209,6 @@ int OpenSLESRecorder::EnableBuiltInAEC(bool enable) { return 0; } -int OpenSLESRecorder::EnableBuiltInAGC(bool enable) { - ALOGD("EnableBuiltInAGC(%d)", enable); - RTC_DCHECK(thread_checker_.CalledOnValidThread()); - ALOGE("Not implemented"); - return 0; -} - int OpenSLESRecorder::EnableBuiltInNS(bool enable) { ALOGD("EnableBuiltInNS(%d)", enable); RTC_DCHECK(thread_checker_.CalledOnValidThread()); diff --git a/sdk/android/src/jni/audio_device/opensles_recorder.h b/sdk/android/src/jni/audio_device/opensles_recorder.h index 731f958d3b..2f6bd6a03f 100644 --- a/sdk/android/src/jni/audio_device/opensles_recorder.h +++ b/sdk/android/src/jni/audio_device/opensles_recorder.h @@ -82,7 +82,6 @@ class OpenSLESRecorder : public AudioInput { bool IsAcousticEchoCancelerSupported() const override; bool IsNoiseSuppressorSupported() const override; int EnableBuiltInAEC(bool enable) override; - int EnableBuiltInAGC(bool enable) override; int EnableBuiltInNS(bool enable) override; private: