diff --git a/modules/audio_device/audio_device_buffer.cc b/modules/audio_device/audio_device_buffer.cc index 779cb06a07..3d7d9bc85b 100644 --- a/modules/audio_device/audio_device_buffer.cc +++ b/modules/audio_device/audio_device_buffer.cc @@ -68,6 +68,7 @@ AudioDeviceBuffer::AudioDeviceBuffer() phase_ = 0.0; LOG(WARNING) << "AUDIO_DEVICE_PLAYS_SINUS_TONE is defined!"; #endif + WebRtcSpl_Init(); playout_thread_checker_.DetachFromThread(); recording_thread_checker_.DetachFromThread(); } diff --git a/modules/audio_device/audio_device_impl.cc b/modules/audio_device/audio_device_impl.cc index 1296ddb73e..c37e6184ed 100644 --- a/modules/audio_device/audio_device_impl.cc +++ b/modules/audio_device/audio_device_impl.cc @@ -9,19 +9,15 @@ */ #include "modules/audio_device/audio_device_impl.h" -#include "common_audio/signal_processing/include/signal_processing_library.h" + #include "modules/audio_device/audio_device_config.h" #include "modules/audio_device/audio_device_generic.h" #include "rtc_base/checks.h" #include "rtc_base/logging.h" #include "rtc_base/refcount.h" #include "rtc_base/refcountedobject.h" -#include "rtc_base/timeutils.h" #include "system_wrappers/include/metrics.h" -#include -#include - #if defined(_WIN32) #if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD) #include "audio_device_core_win.h" @@ -46,43 +42,34 @@ #elif defined(WEBRTC_MAC) #include "audio_device_mac.h" #endif - #if defined(WEBRTC_DUMMY_FILE_DEVICES) #include "modules/audio_device/dummy/file_audio_device_factory.h" #endif - #include "modules/audio_device/dummy/audio_device_dummy.h" #include "modules/audio_device/dummy/file_audio_device.h" -#define CHECK_INITIALIZED() \ +#define CHECKinitialized_() \ { \ - if (!_initialized) { \ + if (!initialized_) { \ return -1; \ }; \ } -#define CHECK_INITIALIZED_BOOL() \ +#define CHECKinitialized__BOOL() \ { \ - if (!_initialized) { \ + if (!initialized_) { \ return false; \ }; \ } namespace webrtc { -// ============================================================================ -// Static methods -// ============================================================================ - -// ---------------------------------------------------------------------------- -// AudioDeviceModule::Create() -// ---------------------------------------------------------------------------- - +// static rtc::scoped_refptr AudioDeviceModule::Create( const int32_t id, const AudioLayer audio_layer) { LOG(INFO) << __FUNCTION__; - // Create the generic ref counted (platform independent) implementation. + // Create the generic reference counted (platform independent) implementation. rtc::scoped_refptr audioDevice( new rtc::RefCountedObject(id, audio_layer)); @@ -96,47 +83,25 @@ rtc::scoped_refptr AudioDeviceModule::Create( return nullptr; } - // Ensure that the generic audio buffer can communicate with the - // platform-specific parts. + // Ensure that the generic audio buffer can communicate with the platform + // specific parts. if (audioDevice->AttachAudioBuffer() == -1) { return nullptr; } - WebRtcSpl_Init(); - return audioDevice; } -// ============================================================================ -// Construction & Destruction -// ============================================================================ - -// ---------------------------------------------------------------------------- -// AudioDeviceModuleImpl - ctor -// ---------------------------------------------------------------------------- - AudioDeviceModuleImpl::AudioDeviceModuleImpl(const int32_t id, const AudioLayer audioLayer) - : _ptrAudioDevice(NULL), - _id(id), - _platformAudioLayer(audioLayer), - _platformType(kPlatformNotSupported), - _initialized(false), - _lastError(kAdmErrNone) { + : id_(id), audio_layer_(audioLayer) { LOG(INFO) << __FUNCTION__; } -// ---------------------------------------------------------------------------- -// CheckPlatform -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::CheckPlatform() { LOG(INFO) << __FUNCTION__; - // Ensure that the current platform is supported - // PlatformType platform(kPlatformNotSupported); - #if defined(_WIN32) platform = kPlatformWin32; LOG(INFO) << "current platform is Win32"; @@ -153,54 +118,41 @@ int32_t AudioDeviceModuleImpl::CheckPlatform() { platform = kPlatformMac; LOG(INFO) << "current platform is Mac"; #endif - if (platform == kPlatformNotSupported) { LOG(LERROR) << "current platform is not supported => this module will self " "destruct!"; return -1; } - - // Store valid output results - // - _platformType = platform; - + platform_type_ = platform; return 0; } -// ---------------------------------------------------------------------------- -// CreatePlatformSpecificObjects -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::CreatePlatformSpecificObjects() { LOG(INFO) << __FUNCTION__; - - AudioDeviceGeneric* ptrAudioDevice(NULL); - +// Dummy ADM implementations if build flags are set. #if defined(WEBRTC_DUMMY_AUDIO_BUILD) - ptrAudioDevice = new AudioDeviceDummy(Id()); + audio_device_.reset(new AudioDeviceDummy(Id())); LOG(INFO) << "Dummy Audio APIs will be utilized"; #elif defined(WEBRTC_DUMMY_FILE_DEVICES) - ptrAudioDevice = FileAudioDeviceFactory::CreateFileAudioDevice(Id()); - if (ptrAudioDevice) { + audio_device_.reset(FileAudioDeviceFactory::CreateFileAudioDevice(Id())); + if (audio_device_) { LOG(INFO) << "Will use file-playing dummy device."; } else { // Create a dummy device instead. - ptrAudioDevice = new AudioDeviceDummy(Id()); + audio_device_.reset(new AudioDeviceDummy(Id())); LOG(INFO) << "Dummy Audio APIs will be utilized"; } + +// Real (non-dummy) ADM implementations. #else - AudioLayer audioLayer(PlatformAudioLayer()); - -// Create the *Windows* implementation of the Audio Device -// + AudioLayer audio_layer(PlatformAudioLayer()); +// Windows ADM implementation. #if defined(WEBRTC_WINDOWS_CORE_AUDIO_BUILD) - if ((audioLayer == kWindowsCoreAudio) || - (audioLayer == kPlatformDefaultAudio)) { - LOG(INFO) << "attempting to use the Windows Core Audio APIs..."; - + if ((audio_layer == kWindowsCoreAudio) || + (audio_layer == kPlatformDefaultAudio)) { + LOG(INFO) << "Attempting to use the Windows Core Audio APIs..."; if (AudioDeviceWindowsCore::CoreAudioIsSupported()) { - // create *Windows Core Audio* implementation - ptrAudioDevice = new AudioDeviceWindowsCore(); + audio_device_.reset(new AudioDeviceWindowsCore()); LOG(INFO) << "Windows Core Audio APIs will be utilized"; } } @@ -208,194 +160,145 @@ int32_t AudioDeviceModuleImpl::CreatePlatformSpecificObjects() { #if defined(WEBRTC_ANDROID) // Create an Android audio manager. - _audioManagerAndroid.reset(new AudioManager()); + audio_manager_android_.reset(new AudioManager()); // Select best possible combination of audio layers. - if (audioLayer == kPlatformDefaultAudio) { - if (_audioManagerAndroid->IsLowLatencyPlayoutSupported() && - _audioManagerAndroid->IsLowLatencyRecordSupported()) { + if (audio_layer == kPlatformDefaultAudio) { + if (audio_manager_android_->IsLowLatencyPlayoutSupported() && + audio_manager_android_->IsLowLatencyRecordSupported()) { // Use OpenSL ES for both playout and recording. - audioLayer = kAndroidOpenSLESAudio; - } else if (_audioManagerAndroid->IsLowLatencyPlayoutSupported() && - !_audioManagerAndroid->IsLowLatencyRecordSupported()) { + audio_layer = kAndroidOpenSLESAudio; + } else if (audio_manager_android_->IsLowLatencyPlayoutSupported() && + !audio_manager_android_->IsLowLatencyRecordSupported()) { // Use OpenSL ES for output on devices that only supports the // low-latency output audio path. - audioLayer = kAndroidJavaInputAndOpenSLESOutputAudio; + audio_layer = kAndroidJavaInputAndOpenSLESOutputAudio; } else { // Use Java-based audio in both directions when low-latency output is // not supported. - audioLayer = kAndroidJavaAudio; + audio_layer = kAndroidJavaAudio; } } - AudioManager* audio_manager = _audioManagerAndroid.get(); - if (audioLayer == kAndroidJavaAudio) { + AudioManager* audio_manager = audio_manager_android_.get(); + if (audio_layer == kAndroidJavaAudio) { // Java audio for both input and output audio. - ptrAudioDevice = new AudioDeviceTemplate( - audioLayer, audio_manager); - } else if (audioLayer == kAndroidOpenSLESAudio) { + audio_device_.reset(new AudioDeviceTemplate( + audio_layer, audio_manager)); + } else if (audio_layer == kAndroidOpenSLESAudio) { // OpenSL ES based audio for both input and output audio. - ptrAudioDevice = new AudioDeviceTemplate( - audioLayer, audio_manager); - } else if (audioLayer == kAndroidJavaInputAndOpenSLESOutputAudio) { + audio_device_.reset( + new AudioDeviceTemplate( + audio_layer, audio_manager)); + } else if (audio_layer == kAndroidJavaInputAndOpenSLESOutputAudio) { // Java audio for input and OpenSL ES for output audio (i.e. mixed APIs). // This combination provides low-latency output audio and at the same // time support for HW AEC using the AudioRecord Java API. - ptrAudioDevice = new AudioDeviceTemplate( - audioLayer, audio_manager); + audio_device_.reset(new AudioDeviceTemplate( + audio_layer, audio_manager)); } else { // Invalid audio layer. - ptrAudioDevice = nullptr; + audio_device_.reset(nullptr); } // END #if defined(WEBRTC_ANDROID) -// Create the *Linux* implementation of the Audio Device -// +// Linux ADM implementation. #elif defined(WEBRTC_LINUX) - if ((audioLayer == kLinuxPulseAudio) || - (audioLayer == kPlatformDefaultAudio)) { + if ((audio_layer == kLinuxPulseAudio) || + (audio_layer == kPlatformDefaultAudio)) { #if defined(LINUX_PULSE) - LOG(INFO) << "attempting to use the Linux PulseAudio APIs..."; - - // create *Linux PulseAudio* implementation - AudioDeviceLinuxPulse* pulseDevice = new AudioDeviceLinuxPulse(); - if (pulseDevice->Init() == AudioDeviceGeneric::InitStatus::OK) { - ptrAudioDevice = pulseDevice; + LOG(INFO) << "Attempting to use Linux PulseAudio APIs..."; + // Linux PulseAudio implementation. + audio_device_.reset(new AudioDeviceLinuxPulse()); + if (audio_device_->Init() == AudioDeviceGeneric::InitStatus::OK) { LOG(INFO) << "Linux PulseAudio APIs will be utilized"; } else { - delete pulseDevice; + LOG(WARNING) << "Failed to initialize Linux PulseAudio " + "implementation."; + audio_device_.reset(nullptr); #endif #if defined(LINUX_ALSA) - // create *Linux ALSA Audio* implementation - ptrAudioDevice = new AudioDeviceLinuxALSA(); - if (ptrAudioDevice != NULL) { - // Pulse Audio was not supported => revert to ALSA instead - _platformAudioLayer = - kLinuxAlsaAudio; // modify the state set at construction - LOG(WARNING) << "Linux PulseAudio is *not* supported => ALSA APIs will " - "be utilized instead"; - } + // Revert to Linux ALSA implementation instead. + audio_device_.reset(new AudioDeviceLinuxALSA()); + audio_layer_ = kLinuxAlsaAudio; + LOG(WARNING) << "Linux PulseAudio is not supported => ALSA APIs will " + "be utilized instead."; #endif #if defined(LINUX_PULSE) } #endif - } else if (audioLayer == kLinuxAlsaAudio) { + } else if (audio_layer == kLinuxAlsaAudio) { #if defined(LINUX_ALSA) - // create *Linux ALSA Audio* implementation - ptrAudioDevice = new AudioDeviceLinuxALSA(); - LOG(INFO) << "Linux ALSA APIs will be utilized"; + // Linux ALSA implementation. + audio_device_.reset(new AudioDeviceLinuxALSA()); + LOG(INFO) << "Linux ALSA APIs will be utilized."; #endif } #endif // #if defined(WEBRTC_LINUX) -// Create the *iPhone* implementation of the Audio Device -// +// iOS ADM implementation. #if defined(WEBRTC_IOS) - if (audioLayer == kPlatformDefaultAudio) { - // Create iOS Audio Device implementation. - ptrAudioDevice = new AudioDeviceIOS(); - LOG(INFO) << "iPhone Audio APIs will be utilized"; + if (audio_layer == kPlatformDefaultAudio) { + audio_device_.reset(new AudioDeviceIOS()); + LOG(INFO) << "iPhone Audio APIs will be utilized."; } // END #if defined(WEBRTC_IOS) -// Create the *Mac* implementation of the Audio Device -// +// Mac OS X ADM implementation. #elif defined(WEBRTC_MAC) - if (audioLayer == kPlatformDefaultAudio) { - // Create *Mac Audio* implementation - ptrAudioDevice = new AudioDeviceMac(); - LOG(INFO) << "Mac OS X Audio APIs will be utilized"; + if (audio_layer == kPlatformDefaultAudio) { + audio_device_.reset(new AudioDeviceMac()); + LOG(INFO) << "Mac OS X Audio APIs will be utilized."; } #endif // WEBRTC_MAC - // Create the *Dummy* implementation of the Audio Device - // Available for all platforms - // - if (audioLayer == kDummyAudio) { - // Create *Dummy Audio* implementation - assert(!ptrAudioDevice); - ptrAudioDevice = new AudioDeviceDummy(Id()); - LOG(INFO) << "Dummy Audio APIs will be utilized"; + // Dummy ADM implementation. + if (audio_layer == kDummyAudio) { + audio_device_.reset(new AudioDeviceDummy(Id())); + LOG(INFO) << "Dummy Audio APIs will be utilized."; } #endif // if defined(WEBRTC_DUMMY_AUDIO_BUILD) - if (ptrAudioDevice == NULL) { - LOG(LERROR) - << "unable to create the platform specific audio device implementation"; + if (!audio_device_) { + LOG(LS_ERROR) + << "Failed to create the platform specific ADM implementation."; return -1; } - - // Store valid output pointers - // - _ptrAudioDevice = ptrAudioDevice; - return 0; } -// ---------------------------------------------------------------------------- -// AttachAudioBuffer -// -// Install "bridge" between the platform implemetation and the generic -// implementation. The "child" shall set the native sampling rate and the -// number of channels in this function call. -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::AttachAudioBuffer() { LOG(INFO) << __FUNCTION__; - - _audioDeviceBuffer.SetId(_id); - _ptrAudioDevice->AttachAudioBuffer(&_audioDeviceBuffer); + audio_device_buffer_.SetId(id_); + audio_device_->AttachAudioBuffer(&audio_device_buffer_); return 0; } -// ---------------------------------------------------------------------------- -// ~AudioDeviceModuleImpl - dtor -// ---------------------------------------------------------------------------- - AudioDeviceModuleImpl::~AudioDeviceModuleImpl() { LOG(INFO) << __FUNCTION__; - if (_ptrAudioDevice) { - delete _ptrAudioDevice; - _ptrAudioDevice = NULL; - } } -// ============================================================================ -// Public API -// ============================================================================ - -// ---------------------------------------------------------------------------- -// ActiveAudioLayer -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::ActiveAudioLayer(AudioLayer* audioLayer) const { LOG(INFO) << __FUNCTION__; AudioLayer activeAudio; - if (_ptrAudioDevice->ActiveAudioLayer(activeAudio) == -1) { + if (audio_device_->ActiveAudioLayer(activeAudio) == -1) { return -1; } *audioLayer = activeAudio; return 0; } -// ---------------------------------------------------------------------------- -// LastError -// ---------------------------------------------------------------------------- - +// TODO(henrika): remove this API. AudioDeviceModule::ErrorCode AudioDeviceModuleImpl::LastError() const { LOG(INFO) << __FUNCTION__; - return _lastError; + LOG(WARNING) << "Not supported"; + return kAdmErrNone; } -// ---------------------------------------------------------------------------- -// Init -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::Init() { LOG(INFO) << __FUNCTION__; - if (_initialized) + if (initialized_) return 0; - RTC_CHECK(_ptrAudioDevice); - - AudioDeviceGeneric::InitStatus status = _ptrAudioDevice->Init(); + RTC_CHECK(audio_device_); + AudioDeviceGeneric::InitStatus status = audio_device_->Init(); RTC_HISTOGRAM_ENUMERATION( "WebRTC.Audio.InitializationResult", static_cast(status), static_cast(AudioDeviceGeneric::InitStatus::NUM_STATUSES)); @@ -403,379 +306,238 @@ int32_t AudioDeviceModuleImpl::Init() { LOG(LS_ERROR) << "Audio device initialization failed."; return -1; } - - _initialized = true; + initialized_ = true; return 0; } -// ---------------------------------------------------------------------------- -// Terminate -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::Terminate() { LOG(INFO) << __FUNCTION__; - if (!_initialized) + if (!initialized_) return 0; - - if (_ptrAudioDevice->Terminate() == -1) { + if (audio_device_->Terminate() == -1) { return -1; } - - _initialized = false; + initialized_ = false; return 0; } -// ---------------------------------------------------------------------------- -// Initialized -// ---------------------------------------------------------------------------- - bool AudioDeviceModuleImpl::Initialized() const { - LOG(INFO) << __FUNCTION__ << ": " << _initialized; - return (_initialized); + LOG(INFO) << __FUNCTION__ << ": " << initialized_; + return initialized_; } -// ---------------------------------------------------------------------------- -// InitSpeaker -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::InitSpeaker() { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED(); - return (_ptrAudioDevice->InitSpeaker()); + CHECKinitialized_(); + return audio_device_->InitSpeaker(); } -// ---------------------------------------------------------------------------- -// InitMicrophone -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::InitMicrophone() { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED(); - return (_ptrAudioDevice->InitMicrophone()); + CHECKinitialized_(); + return audio_device_->InitMicrophone(); } -// ---------------------------------------------------------------------------- -// SpeakerVolumeIsAvailable -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::SpeakerVolumeIsAvailable(bool* available) { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED(); - - bool isAvailable(0); - - if (_ptrAudioDevice->SpeakerVolumeIsAvailable(isAvailable) == -1) { + CHECKinitialized_(); + bool isAvailable = false; + if (audio_device_->SpeakerVolumeIsAvailable(isAvailable) == -1) { return -1; } - *available = isAvailable; LOG(INFO) << "output: " << isAvailable; - return (0); + return 0; } -// ---------------------------------------------------------------------------- -// SetSpeakerVolume -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::SetSpeakerVolume(uint32_t volume) { LOG(INFO) << __FUNCTION__ << "(" << volume << ")"; - CHECK_INITIALIZED(); - return (_ptrAudioDevice->SetSpeakerVolume(volume)); + CHECKinitialized_(); + return audio_device_->SetSpeakerVolume(volume); } -// ---------------------------------------------------------------------------- -// SpeakerVolume -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::SpeakerVolume(uint32_t* volume) const { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED(); - - uint32_t level(0); - - if (_ptrAudioDevice->SpeakerVolume(level) == -1) { + CHECKinitialized_(); + uint32_t level = 0; + if (audio_device_->SpeakerVolume(level) == -1) { return -1; } - *volume = level; LOG(INFO) << "output: " << *volume; - return (0); + return 0; } -// ---------------------------------------------------------------------------- -// SpeakerIsInitialized -// ---------------------------------------------------------------------------- - bool AudioDeviceModuleImpl::SpeakerIsInitialized() const { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED_BOOL(); - - bool isInitialized = _ptrAudioDevice->SpeakerIsInitialized(); + CHECKinitialized__BOOL(); + bool isInitialized = audio_device_->SpeakerIsInitialized(); LOG(INFO) << "output: " << isInitialized; - return (isInitialized); + return isInitialized; } -// ---------------------------------------------------------------------------- -// MicrophoneIsInitialized -// ---------------------------------------------------------------------------- - bool AudioDeviceModuleImpl::MicrophoneIsInitialized() const { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED_BOOL(); - - bool isInitialized = _ptrAudioDevice->MicrophoneIsInitialized(); + CHECKinitialized__BOOL(); + bool isInitialized = audio_device_->MicrophoneIsInitialized(); LOG(INFO) << "output: " << isInitialized; - return (isInitialized); + return isInitialized; } -// ---------------------------------------------------------------------------- -// MaxSpeakerVolume -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::MaxSpeakerVolume(uint32_t* maxVolume) const { - CHECK_INITIALIZED(); - - uint32_t maxVol(0); - - if (_ptrAudioDevice->MaxSpeakerVolume(maxVol) == -1) { + CHECKinitialized_(); + uint32_t maxVol = 0; + if (audio_device_->MaxSpeakerVolume(maxVol) == -1) { return -1; } - *maxVolume = maxVol; - return (0); + return 0; } -// ---------------------------------------------------------------------------- -// MinSpeakerVolume -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::MinSpeakerVolume(uint32_t* minVolume) const { - CHECK_INITIALIZED(); - - uint32_t minVol(0); - - if (_ptrAudioDevice->MinSpeakerVolume(minVol) == -1) { + CHECKinitialized_(); + uint32_t minVol = 0; + if (audio_device_->MinSpeakerVolume(minVol) == -1) { return -1; } - *minVolume = minVol; - return (0); + return 0; } -// ---------------------------------------------------------------------------- -// SpeakerMuteIsAvailable -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::SpeakerMuteIsAvailable(bool* available) { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED(); - - bool isAvailable(0); - - if (_ptrAudioDevice->SpeakerMuteIsAvailable(isAvailable) == -1) { + CHECKinitialized_(); + bool isAvailable = false; + if (audio_device_->SpeakerMuteIsAvailable(isAvailable) == -1) { return -1; } - *available = isAvailable; LOG(INFO) << "output: " << isAvailable; - return (0); + return 0; } -// ---------------------------------------------------------------------------- -// SetSpeakerMute -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::SetSpeakerMute(bool enable) { LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; - CHECK_INITIALIZED(); - return (_ptrAudioDevice->SetSpeakerMute(enable)); + CHECKinitialized_(); + return audio_device_->SetSpeakerMute(enable); } -// ---------------------------------------------------------------------------- -// SpeakerMute -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::SpeakerMute(bool* enabled) const { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED(); - - bool muted(false); - - if (_ptrAudioDevice->SpeakerMute(muted) == -1) { + CHECKinitialized_(); + bool muted = false; + if (audio_device_->SpeakerMute(muted) == -1) { return -1; } - *enabled = muted; LOG(INFO) << "output: " << muted; - return (0); + return 0; } -// ---------------------------------------------------------------------------- -// MicrophoneMuteIsAvailable -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::MicrophoneMuteIsAvailable(bool* available) { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED(); - - bool isAvailable(0); - - if (_ptrAudioDevice->MicrophoneMuteIsAvailable(isAvailable) == -1) { + CHECKinitialized_(); + bool isAvailable = false; + if (audio_device_->MicrophoneMuteIsAvailable(isAvailable) == -1) { return -1; } - *available = isAvailable; LOG(INFO) << "output: " << isAvailable; - return (0); + return 0; } -// ---------------------------------------------------------------------------- -// SetMicrophoneMute -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::SetMicrophoneMute(bool enable) { LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; - CHECK_INITIALIZED(); - return (_ptrAudioDevice->SetMicrophoneMute(enable)); + CHECKinitialized_(); + return (audio_device_->SetMicrophoneMute(enable)); } -// ---------------------------------------------------------------------------- -// MicrophoneMute -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::MicrophoneMute(bool* enabled) const { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED(); - - bool muted(false); - - if (_ptrAudioDevice->MicrophoneMute(muted) == -1) { + CHECKinitialized_(); + bool muted = false; + if (audio_device_->MicrophoneMute(muted) == -1) { return -1; } - *enabled = muted; LOG(INFO) << "output: " << muted; - return (0); + return 0; } -// ---------------------------------------------------------------------------- -// MicrophoneVolumeIsAvailable -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::MicrophoneVolumeIsAvailable(bool* available) { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED(); - - bool isAvailable(0); - - if (_ptrAudioDevice->MicrophoneVolumeIsAvailable(isAvailable) == -1) { + CHECKinitialized_(); + bool isAvailable = false; + if (audio_device_->MicrophoneVolumeIsAvailable(isAvailable) == -1) { return -1; } - *available = isAvailable; LOG(INFO) << "output: " << isAvailable; - return (0); + return 0; } -// ---------------------------------------------------------------------------- -// SetMicrophoneVolume -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::SetMicrophoneVolume(uint32_t volume) { LOG(INFO) << __FUNCTION__ << "(" << volume << ")"; - CHECK_INITIALIZED(); - return (_ptrAudioDevice->SetMicrophoneVolume(volume)); + CHECKinitialized_(); + return (audio_device_->SetMicrophoneVolume(volume)); } -// ---------------------------------------------------------------------------- -// MicrophoneVolume -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::MicrophoneVolume(uint32_t* volume) const { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED(); - - uint32_t level(0); - - if (_ptrAudioDevice->MicrophoneVolume(level) == -1) { + CHECKinitialized_(); + uint32_t level = 0; + if (audio_device_->MicrophoneVolume(level) == -1) { return -1; } - *volume = level; LOG(INFO) << "output: " << *volume; - return (0); + return 0; } -// ---------------------------------------------------------------------------- -// StereoRecordingIsAvailable -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::StereoRecordingIsAvailable( bool* available) const { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED(); - - bool isAvailable(0); - - if (_ptrAudioDevice->StereoRecordingIsAvailable(isAvailable) == -1) { + CHECKinitialized_(); + bool isAvailable = false; + if (audio_device_->StereoRecordingIsAvailable(isAvailable) == -1) { return -1; } - *available = isAvailable; LOG(INFO) << "output: " << isAvailable; - return (0); + return 0; } -// ---------------------------------------------------------------------------- -// SetStereoRecording -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::SetStereoRecording(bool enable) { LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; - CHECK_INITIALIZED(); - - if (_ptrAudioDevice->RecordingIsInitialized()) { + CHECKinitialized_(); + if (audio_device_->RecordingIsInitialized()) { LOG(WARNING) << "recording in stereo is not supported"; return -1; } - - if (_ptrAudioDevice->SetStereoRecording(enable) == -1) { + if (audio_device_->SetStereoRecording(enable) == -1) { LOG(WARNING) << "failed to change stereo recording"; return -1; } - int8_t nChannels(1); if (enable) { nChannels = 2; } - _audioDeviceBuffer.SetRecordingChannels(nChannels); - + audio_device_buffer_.SetRecordingChannels(nChannels); return 0; } -// ---------------------------------------------------------------------------- -// StereoRecording -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::StereoRecording(bool* enabled) const { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED(); - - bool stereo(false); - - if (_ptrAudioDevice->StereoRecording(stereo) == -1) { + CHECKinitialized_(); + bool stereo = false; + if (audio_device_->StereoRecording(stereo) == -1) { return -1; } - *enabled = stereo; LOG(INFO) << "output: " << stereo; - return (0); + return 0; } -// ---------------------------------------------------------------------------- -// SetRecordingChannel -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel) { if (channel == kChannelBoth) { LOG(INFO) << __FUNCTION__ << "(both)"; @@ -784,32 +546,22 @@ int32_t AudioDeviceModuleImpl::SetRecordingChannel(const ChannelType channel) { } else { LOG(INFO) << __FUNCTION__ << "(right)"; } - CHECK_INITIALIZED(); - - bool stereo(false); - - if (_ptrAudioDevice->StereoRecording(stereo) == -1) { + CHECKinitialized_(); + bool stereo = false; + if (audio_device_->StereoRecording(stereo) == -1) { LOG(WARNING) << "recording in stereo is not supported"; return -1; } - - return (_audioDeviceBuffer.SetRecordingChannel(channel)); + return audio_device_buffer_.SetRecordingChannel(channel); } -// ---------------------------------------------------------------------------- -// RecordingChannel -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED(); - + CHECKinitialized_(); ChannelType chType; - - if (_audioDeviceBuffer.RecordingChannel(chType) == -1) { + if (audio_device_buffer_.RecordingChannel(chType) == -1) { return -1; } - *channel = chType; if (*channel == kChannelBoth) { LOG(INFO) << "output: both"; @@ -818,582 +570,383 @@ int32_t AudioDeviceModuleImpl::RecordingChannel(ChannelType* channel) const { } else { LOG(INFO) << "output: right"; } - return (0); + return 0; } -// ---------------------------------------------------------------------------- -// StereoPlayoutIsAvailable -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::StereoPlayoutIsAvailable(bool* available) const { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED(); - - bool isAvailable(0); - - if (_ptrAudioDevice->StereoPlayoutIsAvailable(isAvailable) == -1) { + CHECKinitialized_(); + bool isAvailable = false; + if (audio_device_->StereoPlayoutIsAvailable(isAvailable) == -1) { return -1; } - *available = isAvailable; LOG(INFO) << "output: " << isAvailable; - return (0); + return 0; } -// ---------------------------------------------------------------------------- -// SetStereoPlayout -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::SetStereoPlayout(bool enable) { LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; - CHECK_INITIALIZED(); - - if (_ptrAudioDevice->PlayoutIsInitialized()) { + CHECKinitialized_(); + if (audio_device_->PlayoutIsInitialized()) { LOG(LERROR) << "unable to set stereo mode while playing side is initialized"; return -1; } - - if (_ptrAudioDevice->SetStereoPlayout(enable)) { + if (audio_device_->SetStereoPlayout(enable)) { LOG(WARNING) << "stereo playout is not supported"; return -1; } - int8_t nChannels(1); if (enable) { nChannels = 2; } - _audioDeviceBuffer.SetPlayoutChannels(nChannels); - + audio_device_buffer_.SetPlayoutChannels(nChannels); return 0; } -// ---------------------------------------------------------------------------- -// StereoPlayout -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::StereoPlayout(bool* enabled) const { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED(); - - bool stereo(false); - - if (_ptrAudioDevice->StereoPlayout(stereo) == -1) { + CHECKinitialized_(); + bool stereo = false; + if (audio_device_->StereoPlayout(stereo) == -1) { return -1; } - *enabled = stereo; LOG(INFO) << "output: " << stereo; - return (0); + return 0; } -// ---------------------------------------------------------------------------- -// SetAGC -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::SetAGC(bool enable) { LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; - CHECK_INITIALIZED(); - return (_ptrAudioDevice->SetAGC(enable)); + CHECKinitialized_(); + return (audio_device_->SetAGC(enable)); } -// ---------------------------------------------------------------------------- -// AGC -// ---------------------------------------------------------------------------- - bool AudioDeviceModuleImpl::AGC() const { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED_BOOL(); - return (_ptrAudioDevice->AGC()); + CHECKinitialized__BOOL(); + return audio_device_->AGC(); } -// ---------------------------------------------------------------------------- -// PlayoutIsAvailable -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::PlayoutIsAvailable(bool* available) { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED(); - - bool isAvailable(0); - - if (_ptrAudioDevice->PlayoutIsAvailable(isAvailable) == -1) { + CHECKinitialized_(); + bool isAvailable = false; + if (audio_device_->PlayoutIsAvailable(isAvailable) == -1) { return -1; } - *available = isAvailable; LOG(INFO) << "output: " << isAvailable; - return (0); + return 0; } -// ---------------------------------------------------------------------------- -// RecordingIsAvailable -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::RecordingIsAvailable(bool* available) { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED(); - - bool isAvailable(0); - - if (_ptrAudioDevice->RecordingIsAvailable(isAvailable) == -1) { + CHECKinitialized_(); + bool isAvailable = false; + if (audio_device_->RecordingIsAvailable(isAvailable) == -1) { return -1; } - *available = isAvailable; LOG(INFO) << "output: " << isAvailable; - return (0); + return 0; } -// ---------------------------------------------------------------------------- -// MaxMicrophoneVolume -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::MaxMicrophoneVolume(uint32_t* maxVolume) const { - CHECK_INITIALIZED(); - + CHECKinitialized_(); uint32_t maxVol(0); - - if (_ptrAudioDevice->MaxMicrophoneVolume(maxVol) == -1) { + if (audio_device_->MaxMicrophoneVolume(maxVol) == -1) { return -1; } - *maxVolume = maxVol; - return (0); + return 0; } -// ---------------------------------------------------------------------------- -// MinMicrophoneVolume -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::MinMicrophoneVolume(uint32_t* minVolume) const { - CHECK_INITIALIZED(); - + CHECKinitialized_(); uint32_t minVol(0); - - if (_ptrAudioDevice->MinMicrophoneVolume(minVol) == -1) { + if (audio_device_->MinMicrophoneVolume(minVol) == -1) { return -1; } - *minVolume = minVol; - return (0); + return 0; } -// ---------------------------------------------------------------------------- -// PlayoutDevices -// ---------------------------------------------------------------------------- - int16_t AudioDeviceModuleImpl::PlayoutDevices() { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED(); - - uint16_t nPlayoutDevices = _ptrAudioDevice->PlayoutDevices(); + CHECKinitialized_(); + uint16_t nPlayoutDevices = audio_device_->PlayoutDevices(); LOG(INFO) << "output: " << nPlayoutDevices; - return ((int16_t)(nPlayoutDevices)); + return (int16_t)(nPlayoutDevices); } -// ---------------------------------------------------------------------------- -// SetPlayoutDevice I (II) -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::SetPlayoutDevice(uint16_t index) { LOG(INFO) << __FUNCTION__ << "(" << index << ")"; - CHECK_INITIALIZED(); - return (_ptrAudioDevice->SetPlayoutDevice(index)); + CHECKinitialized_(); + return audio_device_->SetPlayoutDevice(index); } -// ---------------------------------------------------------------------------- -// SetPlayoutDevice II (II) -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::SetPlayoutDevice(WindowsDeviceType device) { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED(); - - return (_ptrAudioDevice->SetPlayoutDevice(device)); + CHECKinitialized_(); + return audio_device_->SetPlayoutDevice(device); } -// ---------------------------------------------------------------------------- -// PlayoutDeviceName -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::PlayoutDeviceName( uint16_t index, char name[kAdmMaxDeviceNameSize], char guid[kAdmMaxGuidSize]) { LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)"; - CHECK_INITIALIZED(); - + CHECKinitialized_(); if (name == NULL) { - _lastError = kAdmErrArgument; return -1; } - - if (_ptrAudioDevice->PlayoutDeviceName(index, name, guid) == -1) { + if (audio_device_->PlayoutDeviceName(index, name, guid) == -1) { return -1; } - if (name != NULL) { LOG(INFO) << "output: name = " << name; } if (guid != NULL) { LOG(INFO) << "output: guid = " << guid; } - - return (0); + return 0; } -// ---------------------------------------------------------------------------- -// RecordingDeviceName -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::RecordingDeviceName( uint16_t index, char name[kAdmMaxDeviceNameSize], char guid[kAdmMaxGuidSize]) { LOG(INFO) << __FUNCTION__ << "(" << index << ", ...)"; - CHECK_INITIALIZED(); - + CHECKinitialized_(); if (name == NULL) { - _lastError = kAdmErrArgument; return -1; } - - if (_ptrAudioDevice->RecordingDeviceName(index, name, guid) == -1) { + if (audio_device_->RecordingDeviceName(index, name, guid) == -1) { return -1; } - if (name != NULL) { LOG(INFO) << "output: name = " << name; } if (guid != NULL) { LOG(INFO) << "output: guid = " << guid; } - - return (0); + return 0; } -// ---------------------------------------------------------------------------- -// RecordingDevices -// ---------------------------------------------------------------------------- - int16_t AudioDeviceModuleImpl::RecordingDevices() { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED(); - - uint16_t nRecordingDevices = _ptrAudioDevice->RecordingDevices(); - + CHECKinitialized_(); + uint16_t nRecordingDevices = audio_device_->RecordingDevices(); LOG(INFO) << "output: " << nRecordingDevices; - return ((int16_t)nRecordingDevices); + return (int16_t)nRecordingDevices; } -// ---------------------------------------------------------------------------- -// SetRecordingDevice I (II) -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::SetRecordingDevice(uint16_t index) { LOG(INFO) << __FUNCTION__ << "(" << index << ")"; - CHECK_INITIALIZED(); - return (_ptrAudioDevice->SetRecordingDevice(index)); + CHECKinitialized_(); + return audio_device_->SetRecordingDevice(index); } -// ---------------------------------------------------------------------------- -// SetRecordingDevice II (II) -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::SetRecordingDevice(WindowsDeviceType device) { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED(); - - return (_ptrAudioDevice->SetRecordingDevice(device)); + CHECKinitialized_(); + return audio_device_->SetRecordingDevice(device); } -// ---------------------------------------------------------------------------- -// InitPlayout -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::InitPlayout() { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED(); + CHECKinitialized_(); if (PlayoutIsInitialized()) { return 0; } - int32_t result = _ptrAudioDevice->InitPlayout(); + int32_t result = audio_device_->InitPlayout(); LOG(INFO) << "output: " << result; RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitPlayoutSuccess", static_cast(result == 0)); return result; } -// ---------------------------------------------------------------------------- -// InitRecording -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::InitRecording() { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED(); + CHECKinitialized_(); if (RecordingIsInitialized()) { return 0; } - int32_t result = _ptrAudioDevice->InitRecording(); + int32_t result = audio_device_->InitRecording(); LOG(INFO) << "output: " << result; RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitRecordingSuccess", static_cast(result == 0)); return result; } -// ---------------------------------------------------------------------------- -// PlayoutIsInitialized -// ---------------------------------------------------------------------------- - bool AudioDeviceModuleImpl::PlayoutIsInitialized() const { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED_BOOL(); - return (_ptrAudioDevice->PlayoutIsInitialized()); + CHECKinitialized__BOOL(); + return audio_device_->PlayoutIsInitialized(); } -// ---------------------------------------------------------------------------- -// RecordingIsInitialized -// ---------------------------------------------------------------------------- - bool AudioDeviceModuleImpl::RecordingIsInitialized() const { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED_BOOL(); - return (_ptrAudioDevice->RecordingIsInitialized()); + CHECKinitialized__BOOL(); + return audio_device_->RecordingIsInitialized(); } -// ---------------------------------------------------------------------------- -// StartPlayout -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::StartPlayout() { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED(); + CHECKinitialized_(); if (Playing()) { return 0; } - _audioDeviceBuffer.StartPlayout(); - int32_t result = _ptrAudioDevice->StartPlayout(); + audio_device_buffer_.StartPlayout(); + int32_t result = audio_device_->StartPlayout(); LOG(INFO) << "output: " << result; RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartPlayoutSuccess", static_cast(result == 0)); return result; } -// ---------------------------------------------------------------------------- -// StopPlayout -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::StopPlayout() { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED(); - int32_t result = _ptrAudioDevice->StopPlayout(); - _audioDeviceBuffer.StopPlayout(); + CHECKinitialized_(); + int32_t result = audio_device_->StopPlayout(); + audio_device_buffer_.StopPlayout(); LOG(INFO) << "output: " << result; RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopPlayoutSuccess", static_cast(result == 0)); return result; } -// ---------------------------------------------------------------------------- -// Playing -// ---------------------------------------------------------------------------- - bool AudioDeviceModuleImpl::Playing() const { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED_BOOL(); - return (_ptrAudioDevice->Playing()); + CHECKinitialized__BOOL(); + return audio_device_->Playing(); } -// ---------------------------------------------------------------------------- -// StartRecording -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::StartRecording() { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED(); + CHECKinitialized_(); if (Recording()) { return 0; } - _audioDeviceBuffer.StartRecording(); - int32_t result = _ptrAudioDevice->StartRecording(); + audio_device_buffer_.StartRecording(); + int32_t result = audio_device_->StartRecording(); LOG(INFO) << "output: " << result; RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartRecordingSuccess", static_cast(result == 0)); return result; } -// ---------------------------------------------------------------------------- -// StopRecording -// ---------------------------------------------------------------------------- int32_t AudioDeviceModuleImpl::StopRecording() { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED(); - int32_t result = _ptrAudioDevice->StopRecording(); - _audioDeviceBuffer.StopRecording(); + CHECKinitialized_(); + int32_t result = audio_device_->StopRecording(); + audio_device_buffer_.StopRecording(); LOG(INFO) << "output: " << result; RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopRecordingSuccess", static_cast(result == 0)); return result; } -// ---------------------------------------------------------------------------- -// Recording -// ---------------------------------------------------------------------------- - bool AudioDeviceModuleImpl::Recording() const { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED_BOOL(); - return (_ptrAudioDevice->Recording()); + CHECKinitialized__BOOL(); + return audio_device_->Recording(); } -// ---------------------------------------------------------------------------- -// RegisterAudioCallback -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::RegisterAudioCallback( AudioTransport* audioCallback) { LOG(INFO) << __FUNCTION__; - rtc::CritScope lock(&_critSectAudioCb); - return _audioDeviceBuffer.RegisterAudioCallback(audioCallback); + return audio_device_buffer_.RegisterAudioCallback(audioCallback); } -// ---------------------------------------------------------------------------- -// PlayoutDelay -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::PlayoutDelay(uint16_t* delayMS) const { - CHECK_INITIALIZED(); - - uint16_t delay(0); - - if (_ptrAudioDevice->PlayoutDelay(delay) == -1) { + CHECKinitialized_(); + uint16_t delay = 0; + if (audio_device_->PlayoutDelay(delay) == -1) { LOG(LERROR) << "failed to retrieve the playout delay"; return -1; } - *delayMS = delay; - return (0); + return 0; } -// ---------------------------------------------------------------------------- -// RecordingDelay -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::RecordingDelay(uint16_t* delayMS) const { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED(); - - uint16_t delay(0); - - if (_ptrAudioDevice->RecordingDelay(delay) == -1) { + CHECKinitialized_(); + uint16_t delay = 0; + if (audio_device_->RecordingDelay(delay) == -1) { LOG(LERROR) << "failed to retrieve the recording delay"; return -1; } - *delayMS = delay; LOG(INFO) << "output: " << *delayMS; - return (0); + return 0; } -// ---------------------------------------------------------------------------- -// SetRecordingSampleRate -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::SetRecordingSampleRate( const uint32_t samplesPerSec) { LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")"; - CHECK_INITIALIZED(); - - if (_ptrAudioDevice->SetRecordingSampleRate(samplesPerSec) != 0) { + CHECKinitialized_(); + if (audio_device_->SetRecordingSampleRate(samplesPerSec) != 0) { return -1; } - - return (0); + return 0; } -// ---------------------------------------------------------------------------- -// RecordingSampleRate -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::RecordingSampleRate( uint32_t* samplesPerSec) const { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED(); - - int32_t sampleRate = _audioDeviceBuffer.RecordingSampleRate(); - + CHECKinitialized_(); + int32_t sampleRate = audio_device_buffer_.RecordingSampleRate(); if (sampleRate == -1) { LOG(LERROR) << "failed to retrieve the sample rate"; return -1; } - *samplesPerSec = sampleRate; LOG(INFO) << "output: " << *samplesPerSec; - return (0); + return 0; } -// ---------------------------------------------------------------------------- -// SetPlayoutSampleRate -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::SetPlayoutSampleRate( const uint32_t samplesPerSec) { LOG(INFO) << __FUNCTION__ << "(" << samplesPerSec << ")"; - CHECK_INITIALIZED(); - - if (_ptrAudioDevice->SetPlayoutSampleRate(samplesPerSec) != 0) { + CHECKinitialized_(); + if (audio_device_->SetPlayoutSampleRate(samplesPerSec) != 0) { return -1; } - - return (0); + return 0; } -// ---------------------------------------------------------------------------- -// PlayoutSampleRate -// ---------------------------------------------------------------------------- - int32_t AudioDeviceModuleImpl::PlayoutSampleRate( uint32_t* samplesPerSec) const { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED(); - - int32_t sampleRate = _audioDeviceBuffer.PlayoutSampleRate(); - + CHECKinitialized_(); + int32_t sampleRate = audio_device_buffer_.PlayoutSampleRate(); if (sampleRate == -1) { LOG(LERROR) << "failed to retrieve the sample rate"; return -1; } - *samplesPerSec = sampleRate; LOG(INFO) << "output: " << *samplesPerSec; - return (0); -} - -// ---------------------------------------------------------------------------- -// SetLoudspeakerStatus -// ---------------------------------------------------------------------------- - -int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable) { - LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; - CHECK_INITIALIZED(); - - if (_ptrAudioDevice->SetLoudspeakerStatus(enable) != 0) { - return -1; - } - return 0; } -// ---------------------------------------------------------------------------- -// GetLoudspeakerStatus -// ---------------------------------------------------------------------------- +int32_t AudioDeviceModuleImpl::SetLoudspeakerStatus(bool enable) { + LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; + CHECKinitialized_(); + if (audio_device_->SetLoudspeakerStatus(enable) != 0) { + return -1; + } + return 0; +} int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED(); + CHECKinitialized_(); int32_t ok = 0; - if (_ptrAudioDevice->GetLoudspeakerStatus(*enabled) != 0) { + if (audio_device_->GetLoudspeakerStatus(*enabled) != 0) { ok = -1; } LOG(INFO) << "output: " << ok; @@ -1402,48 +955,48 @@ int32_t AudioDeviceModuleImpl::GetLoudspeakerStatus(bool* enabled) const { bool AudioDeviceModuleImpl::BuiltInAECIsAvailable() const { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED_BOOL(); - bool isAvailable = _ptrAudioDevice->BuiltInAECIsAvailable(); + CHECKinitialized__BOOL(); + bool isAvailable = audio_device_->BuiltInAECIsAvailable(); LOG(INFO) << "output: " << isAvailable; return isAvailable; } int32_t AudioDeviceModuleImpl::EnableBuiltInAEC(bool enable) { LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; - CHECK_INITIALIZED(); - int32_t ok = _ptrAudioDevice->EnableBuiltInAEC(enable); + CHECKinitialized_(); + int32_t ok = audio_device_->EnableBuiltInAEC(enable); LOG(INFO) << "output: " << ok; return ok; } bool AudioDeviceModuleImpl::BuiltInAGCIsAvailable() const { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED_BOOL(); - bool isAvailable = _ptrAudioDevice->BuiltInAGCIsAvailable(); + CHECKinitialized__BOOL(); + bool isAvailable = audio_device_->BuiltInAGCIsAvailable(); LOG(INFO) << "output: " << isAvailable; return isAvailable; } int32_t AudioDeviceModuleImpl::EnableBuiltInAGC(bool enable) { LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; - CHECK_INITIALIZED(); - int32_t ok = _ptrAudioDevice->EnableBuiltInAGC(enable); + CHECKinitialized_(); + int32_t ok = audio_device_->EnableBuiltInAGC(enable); LOG(INFO) << "output: " << ok; return ok; } bool AudioDeviceModuleImpl::BuiltInNSIsAvailable() const { LOG(INFO) << __FUNCTION__; - CHECK_INITIALIZED_BOOL(); - bool isAvailable = _ptrAudioDevice->BuiltInNSIsAvailable(); + CHECKinitialized__BOOL(); + bool isAvailable = audio_device_->BuiltInNSIsAvailable(); LOG(INFO) << "output: " << isAvailable; return isAvailable; } int32_t AudioDeviceModuleImpl::EnableBuiltInNS(bool enable) { LOG(INFO) << __FUNCTION__ << "(" << enable << ")"; - CHECK_INITIALIZED(); - int32_t ok = _ptrAudioDevice->EnableBuiltInNS(enable); + CHECKinitialized_(); + int32_t ok = audio_device_->EnableBuiltInNS(enable); LOG(INFO) << "output: " << ok; return ok; } @@ -1452,7 +1005,7 @@ int32_t AudioDeviceModuleImpl::EnableBuiltInNS(bool enable) { int AudioDeviceModuleImpl::GetPlayoutAudioParameters( AudioParameters* params) const { LOG(INFO) << __FUNCTION__; - int r = _ptrAudioDevice->GetPlayoutAudioParameters(params); + int r = audio_device_->GetPlayoutAudioParameters(params); LOG(INFO) << "output: " << r; return r; } @@ -1460,33 +1013,21 @@ int AudioDeviceModuleImpl::GetPlayoutAudioParameters( int AudioDeviceModuleImpl::GetRecordAudioParameters( AudioParameters* params) const { LOG(INFO) << __FUNCTION__; - int r = _ptrAudioDevice->GetRecordAudioParameters(params); + int r = audio_device_->GetRecordAudioParameters(params); LOG(INFO) << "output: " << r; return r; } #endif // WEBRTC_IOS -// ============================================================================ -// Private Methods -// ============================================================================ - -// ---------------------------------------------------------------------------- -// Platform -// ---------------------------------------------------------------------------- - AudioDeviceModuleImpl::PlatformType AudioDeviceModuleImpl::Platform() const { LOG(INFO) << __FUNCTION__; - return _platformType; + return platform_type_; } -// ---------------------------------------------------------------------------- -// PlatformAudioLayer -// ---------------------------------------------------------------------------- - AudioDeviceModule::AudioLayer AudioDeviceModuleImpl::PlatformAudioLayer() const { LOG(INFO) << __FUNCTION__; - return _platformAudioLayer; + return audio_layer_; } } // namespace webrtc diff --git a/modules/audio_device/audio_device_impl.h b/modules/audio_device/audio_device_impl.h index 864ab48833..b59f19b920 100644 --- a/modules/audio_device/audio_device_impl.h +++ b/modules/audio_device/audio_device_impl.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef AUDIO_DEVICE_AUDIO_DEVICE_IMPL_H_ -#define AUDIO_DEVICE_AUDIO_DEVICE_IMPL_H_ +#ifndef MODULES_AUDIO_DEVICE_AUDIO_DEVICE_IMPL_H_ +#define MODULES_AUDIO_DEVICE_AUDIO_DEVICE_IMPL_H_ #if defined(WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE) @@ -160,37 +160,33 @@ class AudioDeviceModuleImpl : public AudioDeviceModule { int GetRecordAudioParameters(AudioParameters* params) const override; #endif // WEBRTC_IOS - int32_t Id() { return _id; } + int32_t Id() const { return id_; } #if defined(WEBRTC_ANDROID) // Only use this acccessor for test purposes on Android. AudioManager* GetAndroidAudioManagerForTest() { - return _audioManagerAndroid.get(); + return audio_manager_android_.get(); } #endif - AudioDeviceBuffer* GetAudioDeviceBuffer() { return &_audioDeviceBuffer; } + AudioDeviceBuffer* GetAudioDeviceBuffer() { return &audio_device_buffer_; } private: PlatformType Platform() const; AudioLayer PlatformAudioLayer() const; - rtc::CriticalSection _critSect; - rtc::CriticalSection _critSectAudioCb; - - AudioDeviceGeneric* _ptrAudioDevice; - - AudioDeviceBuffer _audioDeviceBuffer; + const int32_t id_; + AudioLayer audio_layer_; + PlatformType platform_type_ = kPlatformNotSupported; + bool initialized_ = false; #if defined(WEBRTC_ANDROID) - std::unique_ptr _audioManagerAndroid; + // Should be declared first to ensure that it outlives other resources. + std::unique_ptr audio_manager_android_; #endif - int32_t _id; - AudioLayer _platformAudioLayer; - PlatformType _platformType; - bool _initialized; - mutable ErrorCode _lastError; + AudioDeviceBuffer audio_device_buffer_; + std::unique_ptr audio_device_; }; } // namespace webrtc #endif // defined(WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE) -#endif // MODULES_INTERFACE_AUDIO_DEVICE_IMPL_H_ +#endif // MODULES_AUDIO_DEVICE_AUDIO_DEVICE_IMPL_H_