Adding an error callback to AudioDeviceModuleIOS.

This adds an optional callback closure and an enum representing the error.

Bug: webrtc:390314937
Change-Id: If9a22dd6d90d5c4d94175e021511766ea49acec2
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/374420
Commit-Queue: Peter Hanspers <peterhanspers@webrtc.org>
Reviewed-by: Jakob Ivarsson‎ <jakobi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43780}
This commit is contained in:
Peter Hanspers 2025-01-21 14:54:51 +01:00 committed by WebRTC LUCI CQ
parent 32f3c6cef1
commit 3fef8b27db
6 changed files with 214 additions and 23 deletions

View File

@ -231,6 +231,7 @@ if (is_ios || is_mac) {
deps = [ deps = [
":audio_device", ":audio_device",
":audio_device_module_error_handler",
"../api:make_ref_counted", "../api:make_ref_counted",
"../api/audio:audio_device", "../api/audio:audio_device",
"../modules/audio_device:audio_device_generic", "../modules/audio_device:audio_device_generic",
@ -290,6 +291,7 @@ if (is_ios || is_mac) {
] ]
deps = [ deps = [
":audio_device_module_error_handler",
":audio_objc", ":audio_objc",
":audio_session_observer", ":audio_session_observer",
":base_objc", ":base_objc",
@ -507,6 +509,16 @@ if (is_ios || is_mac) {
} }
} }
rtc_source_set("audio_device_module_error_handler") {
visibility = [ ":*" ]
sources = [ "objc/native/api/audio_device_module_error_handler.h" ]
public_configs = [ ":common_config_objc" ]
deps = []
}
rtc_library("objc_audio_device_module") { rtc_library("objc_audio_device_module") {
visibility = [ "*" ] visibility = [ "*" ]
allow_poison = [ "environment_construction" ] allow_poison = [ "environment_construction" ]

View File

@ -14,6 +14,7 @@
#include <memory> #include <memory>
#include "api/audio/audio_device.h" #include "api/audio/audio_device.h"
#include "sdk/objc/native/api/audio_device_module_error_handler.h"
namespace webrtc { namespace webrtc {
@ -31,6 +32,15 @@ rtc::scoped_refptr<AudioDeviceModule> CreateMutedDetectAudioDeviceModule(
AudioDeviceModule::MutedSpeechEventHandler muted_speech_event_handler, AudioDeviceModule::MutedSpeechEventHandler muted_speech_event_handler,
bool bypass_voice_processing = false); bool bypass_voice_processing = false);
// If `muted_speech_event_handler` is exist, audio unit will catch speech
// activity while muted.
// Provide `error_handler` to receive callbacks on errors such as microphone
// init failed or playout start failied.
rtc::scoped_refptr<AudioDeviceModule> CreateMutedDetectAudioDeviceModule(
AudioDeviceModule::MutedSpeechEventHandler muted_speech_event_handler,
ADMErrorHandler error_handler,
bool bypass_voice_processing = false);
} // namespace webrtc } // namespace webrtc
#endif // SDK_OBJC_NATIVE_API_AUDIO_DEVICE_MODULE_H_ #endif // SDK_OBJC_NATIVE_API_AUDIO_DEVICE_MODULE_H_

View File

@ -22,7 +22,9 @@ rtc::scoped_refptr<AudioDeviceModule> CreateAudioDeviceModule(
RTC_DLOG(LS_INFO) << __FUNCTION__; RTC_DLOG(LS_INFO) << __FUNCTION__;
#if defined(WEBRTC_IOS) #if defined(WEBRTC_IOS)
return rtc::make_ref_counted<ios_adm::AudioDeviceModuleIOS>( return rtc::make_ref_counted<ios_adm::AudioDeviceModuleIOS>(
bypass_voice_processing, nullptr); bypass_voice_processing,
/*muted_speech_event_handler=*/nullptr,
/*error_handler=*/nullptr);
#else #else
RTC_LOG(LS_ERROR) RTC_LOG(LS_ERROR)
<< "current platform is not supported => this module will self destruct!"; << "current platform is not supported => this module will self destruct!";
@ -31,12 +33,22 @@ rtc::scoped_refptr<AudioDeviceModule> CreateAudioDeviceModule(
} }
rtc::scoped_refptr<AudioDeviceModule> CreateMutedDetectAudioDeviceModule( rtc::scoped_refptr<AudioDeviceModule> CreateMutedDetectAudioDeviceModule(
AudioDeviceModule::MutedSpeechEventHandler handler, AudioDeviceModule::MutedSpeechEventHandler muted_speech_event_handler,
bool bypass_voice_processing) {
RTC_DLOG(LS_INFO) << __FUNCTION__;
return CreateMutedDetectAudioDeviceModule(muted_speech_event_handler,
/*error_handler=*/nullptr,
bypass_voice_processing);
}
rtc::scoped_refptr<AudioDeviceModule> CreateMutedDetectAudioDeviceModule(
AudioDeviceModule::MutedSpeechEventHandler muted_speech_event_handler,
ADMErrorHandler error_handler,
bool bypass_voice_processing) { bool bypass_voice_processing) {
RTC_DLOG(LS_INFO) << __FUNCTION__; RTC_DLOG(LS_INFO) << __FUNCTION__;
#if defined(WEBRTC_IOS) #if defined(WEBRTC_IOS)
return rtc::make_ref_counted<ios_adm::AudioDeviceModuleIOS>( return rtc::make_ref_counted<ios_adm::AudioDeviceModuleIOS>(
bypass_voice_processing, handler); bypass_voice_processing, muted_speech_event_handler, error_handler);
#else #else
RTC_LOG(LS_ERROR) RTC_LOG(LS_ERROR)
<< "current platform is not supported => this module will self destruct!"; << "current platform is not supported => this module will self destruct!";

View File

@ -0,0 +1,54 @@
/*
* Copyright (c) 2025 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef SDK_OBJC_NATIVE_API_AUDIO_DEVICE_MODULE_ERROR_HANDLER_H
#define SDK_OBJC_NATIVE_API_AUDIO_DEVICE_MODULE_ERROR_HANDLER_H
namespace webrtc {
enum ADMError : uint8_t {
// Generic.
kNotInitialized,
kInitializationFailed,
kTerminateFailed,
// Playout / speaker errors.
kInitSpeakerFailed,
kPlayoutInitFailed,
kPlayoutStartFailed,
kPlayoutFailed,
kPlayoutDeviceFailed,
kPlayoutDelayFailed,
kPlayoutDeviceNameFailed,
kStereoPlayoutFailed,
kSpeakerMuteFailed,
kSpeakerVolumeFailed,
// Recording / microphone errors.
kInitMicrophoneFailed,
kRecordingInitFailed,
kRecordingStartFailed,
kRecordingFailed,
kRecordingDeviceFailed,
kRecordingDeviceNameFailed,
kStereoRecordingFailed,
kMicrophoneMuteFailed,
kMicrophoneVolumeFailed,
// Others.
kNoActiveAudioLayer,
kRegisterAudioCallbackFailed,
kEnableBuiltInAECFailed,
kEnableBuiltInAGCFailed,
kEnableBuiltInNSFailed,
};
typedef void (^ADMErrorHandler)(ADMError error);
} // namespace webrtc
#endif // SDK_OBJC_NATIVE_API_AUDIO_DEVICE_MODULE_ERROR_HANDLER_H

View File

@ -18,6 +18,7 @@
#include "audio_device_ios.h" #include "audio_device_ios.h"
#include "modules/audio_device/audio_device_buffer.h" #include "modules/audio_device/audio_device_buffer.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "sdk/objc/native/api/audio_device_module_error_handler.h"
namespace webrtc { namespace webrtc {
@ -31,7 +32,8 @@ class AudioDeviceModuleIOS : public AudioDeviceModule {
explicit AudioDeviceModuleIOS( explicit AudioDeviceModuleIOS(
bool bypass_voice_processing, bool bypass_voice_processing,
MutedSpeechEventHandler muted_speech_event_handler); MutedSpeechEventHandler muted_speech_event_handler,
ADMErrorHandler error_handler);
~AudioDeviceModuleIOS() override; ~AudioDeviceModuleIOS() override;
// Retrieve the currently utilized audio layer // Retrieve the currently utilized audio layer
@ -134,8 +136,10 @@ class AudioDeviceModuleIOS : public AudioDeviceModule {
int GetRecordAudioParameters(AudioParameters* params) const override; int GetRecordAudioParameters(AudioParameters* params) const override;
#endif // WEBRTC_IOS #endif // WEBRTC_IOS
private: private:
void ReportError(ADMError error) const;
const bool bypass_voice_processing_; const bool bypass_voice_processing_;
MutedSpeechEventHandler muted_speech_event_handler_; MutedSpeechEventHandler muted_speech_event_handler_;
ADMErrorHandler error_handler_;
bool initialized_ = false; bool initialized_ = false;
const std::unique_ptr<TaskQueueFactory> task_queue_factory_; const std::unique_ptr<TaskQueueFactory> task_queue_factory_;
std::unique_ptr<AudioDeviceIOS> audio_device_; std::unique_ptr<AudioDeviceIOS> audio_device_;

View File

@ -25,6 +25,7 @@
#define CHECKinitialized_() \ #define CHECKinitialized_() \
{ \ { \
if (!initialized_) { \ if (!initialized_) { \
ReportError(kNotInitialized); \
return -1; \ return -1; \
}; \ }; \
} }
@ -32,6 +33,7 @@
#define CHECKinitialized__BOOL() \ #define CHECKinitialized__BOOL() \
{ \ { \
if (!initialized_) { \ if (!initialized_) { \
ReportError(kNotInitialized); \
return false; \ return false; \
}; \ }; \
} }
@ -41,9 +43,11 @@ namespace ios_adm {
AudioDeviceModuleIOS::AudioDeviceModuleIOS( AudioDeviceModuleIOS::AudioDeviceModuleIOS(
bool bypass_voice_processing, bool bypass_voice_processing,
MutedSpeechEventHandler muted_speech_event_handler) MutedSpeechEventHandler muted_speech_event_handler,
ADMErrorHandler error_handler)
: bypass_voice_processing_(bypass_voice_processing), : bypass_voice_processing_(bypass_voice_processing),
muted_speech_event_handler_(muted_speech_event_handler), muted_speech_event_handler_(muted_speech_event_handler),
error_handler_(error_handler),
task_queue_factory_(CreateDefaultTaskQueueFactory()) { task_queue_factory_(CreateDefaultTaskQueueFactory()) {
RTC_LOG(LS_INFO) << "current platform is IOS"; RTC_LOG(LS_INFO) << "current platform is IOS";
RTC_LOG(LS_INFO) << "iPhone Audio APIs will be utilized."; RTC_LOG(LS_INFO) << "iPhone Audio APIs will be utilized.";
@ -59,10 +63,17 @@ AudioDeviceModuleIOS::~AudioDeviceModuleIOS() {
RTC_DLOG(LS_INFO) << __FUNCTION__; RTC_DLOG(LS_INFO) << __FUNCTION__;
} }
void AudioDeviceModuleIOS::ReportError(ADMError error) const {
if (error_handler_) {
error_handler_(error);
}
}
int32_t AudioDeviceModuleIOS::ActiveAudioLayer(AudioLayer* audioLayer) const { int32_t AudioDeviceModuleIOS::ActiveAudioLayer(AudioLayer* audioLayer) const {
RTC_DLOG(LS_INFO) << __FUNCTION__; RTC_DLOG(LS_INFO) << __FUNCTION__;
AudioLayer activeAudio; AudioLayer activeAudio;
if (audio_device_->ActiveAudioLayer(activeAudio) == -1) { if (audio_device_->ActiveAudioLayer(activeAudio) == -1) {
ReportError(kNoActiveAudioLayer);
return -1; return -1;
} }
*audioLayer = activeAudio; *audioLayer = activeAudio;
@ -88,6 +99,7 @@ int32_t AudioDeviceModuleIOS::Init() {
static_cast<int>(AudioDeviceGeneric::InitStatus::NUM_STATUSES)); static_cast<int>(AudioDeviceGeneric::InitStatus::NUM_STATUSES));
if (status != AudioDeviceGeneric::InitStatus::OK) { if (status != AudioDeviceGeneric::InitStatus::OK) {
RTC_LOG(LS_ERROR) << "Audio device initialization failed."; RTC_LOG(LS_ERROR) << "Audio device initialization failed.";
ReportError(kInitializationFailed);
return -1; return -1;
} }
initialized_ = true; initialized_ = true;
@ -98,6 +110,7 @@ int32_t AudioDeviceModuleIOS::Terminate() {
RTC_DLOG(LS_INFO) << __FUNCTION__; RTC_DLOG(LS_INFO) << __FUNCTION__;
if (!initialized_) return 0; if (!initialized_) return 0;
if (audio_device_->Terminate() == -1) { if (audio_device_->Terminate() == -1) {
ReportError(kTerminateFailed);
return -1; return -1;
} }
initialized_ = false; initialized_ = false;
@ -112,13 +125,21 @@ bool AudioDeviceModuleIOS::Initialized() const {
int32_t AudioDeviceModuleIOS::InitSpeaker() { int32_t AudioDeviceModuleIOS::InitSpeaker() {
RTC_DLOG(LS_INFO) << __FUNCTION__; RTC_DLOG(LS_INFO) << __FUNCTION__;
CHECKinitialized_(); CHECKinitialized_();
return audio_device_->InitSpeaker(); int32_t result = audio_device_->InitSpeaker();
if (result != 0) {
ReportError(kInitSpeakerFailed);
}
return result;
} }
int32_t AudioDeviceModuleIOS::InitMicrophone() { int32_t AudioDeviceModuleIOS::InitMicrophone() {
RTC_DLOG(LS_INFO) << __FUNCTION__; RTC_DLOG(LS_INFO) << __FUNCTION__;
CHECKinitialized_(); CHECKinitialized_();
return audio_device_->InitMicrophone(); int32_t result = audio_device_->InitMicrophone();
if (result != 0) {
ReportError(kInitMicrophoneFailed);
}
return result;
} }
int32_t AudioDeviceModuleIOS::SpeakerVolumeIsAvailable(bool* available) { int32_t AudioDeviceModuleIOS::SpeakerVolumeIsAvailable(bool* available) {
@ -126,6 +147,7 @@ int32_t AudioDeviceModuleIOS::SpeakerVolumeIsAvailable(bool* available) {
CHECKinitialized_(); CHECKinitialized_();
bool isAvailable = false; bool isAvailable = false;
if (audio_device_->SpeakerVolumeIsAvailable(isAvailable) == -1) { if (audio_device_->SpeakerVolumeIsAvailable(isAvailable) == -1) {
ReportError(kSpeakerVolumeFailed);
return -1; return -1;
} }
*available = isAvailable; *available = isAvailable;
@ -136,7 +158,11 @@ int32_t AudioDeviceModuleIOS::SpeakerVolumeIsAvailable(bool* available) {
int32_t AudioDeviceModuleIOS::SetSpeakerVolume(uint32_t volume) { int32_t AudioDeviceModuleIOS::SetSpeakerVolume(uint32_t volume) {
RTC_DLOG(LS_INFO) << __FUNCTION__ << "(" << volume << ")"; RTC_DLOG(LS_INFO) << __FUNCTION__ << "(" << volume << ")";
CHECKinitialized_(); CHECKinitialized_();
return audio_device_->SetSpeakerVolume(volume); int32_t result = audio_device_->SetSpeakerVolume(volume);
if (result != 0) {
ReportError(kSpeakerVolumeFailed);
}
return result;
} }
int32_t AudioDeviceModuleIOS::SpeakerVolume(uint32_t* volume) const { int32_t AudioDeviceModuleIOS::SpeakerVolume(uint32_t* volume) const {
@ -144,6 +170,7 @@ int32_t AudioDeviceModuleIOS::SpeakerVolume(uint32_t* volume) const {
CHECKinitialized_(); CHECKinitialized_();
uint32_t level = 0; uint32_t level = 0;
if (audio_device_->SpeakerVolume(level) == -1) { if (audio_device_->SpeakerVolume(level) == -1) {
ReportError(kSpeakerVolumeFailed);
return -1; return -1;
} }
*volume = level; *volume = level;
@ -171,6 +198,7 @@ int32_t AudioDeviceModuleIOS::MaxSpeakerVolume(uint32_t* maxVolume) const {
CHECKinitialized_(); CHECKinitialized_();
uint32_t maxVol = 0; uint32_t maxVol = 0;
if (audio_device_->MaxSpeakerVolume(maxVol) == -1) { if (audio_device_->MaxSpeakerVolume(maxVol) == -1) {
ReportError(kSpeakerVolumeFailed);
return -1; return -1;
} }
*maxVolume = maxVol; *maxVolume = maxVol;
@ -181,6 +209,7 @@ int32_t AudioDeviceModuleIOS::MinSpeakerVolume(uint32_t* minVolume) const {
CHECKinitialized_(); CHECKinitialized_();
uint32_t minVol = 0; uint32_t minVol = 0;
if (audio_device_->MinSpeakerVolume(minVol) == -1) { if (audio_device_->MinSpeakerVolume(minVol) == -1) {
ReportError(kSpeakerVolumeFailed);
return -1; return -1;
} }
*minVolume = minVol; *minVolume = minVol;
@ -192,6 +221,7 @@ int32_t AudioDeviceModuleIOS::SpeakerMuteIsAvailable(bool* available) {
CHECKinitialized_(); CHECKinitialized_();
bool isAvailable = false; bool isAvailable = false;
if (audio_device_->SpeakerMuteIsAvailable(isAvailable) == -1) { if (audio_device_->SpeakerMuteIsAvailable(isAvailable) == -1) {
ReportError(kSpeakerMuteFailed);
return -1; return -1;
} }
*available = isAvailable; *available = isAvailable;
@ -202,7 +232,11 @@ int32_t AudioDeviceModuleIOS::SpeakerMuteIsAvailable(bool* available) {
int32_t AudioDeviceModuleIOS::SetSpeakerMute(bool enable) { int32_t AudioDeviceModuleIOS::SetSpeakerMute(bool enable) {
RTC_DLOG(LS_INFO) << __FUNCTION__ << "(" << enable << ")"; RTC_DLOG(LS_INFO) << __FUNCTION__ << "(" << enable << ")";
CHECKinitialized_(); CHECKinitialized_();
return audio_device_->SetSpeakerMute(enable); int32_t result = audio_device_->SetSpeakerMute(enable);
if (result != 0) {
ReportError(kSpeakerMuteFailed);
}
return result;
} }
int32_t AudioDeviceModuleIOS::SpeakerMute(bool* enabled) const { int32_t AudioDeviceModuleIOS::SpeakerMute(bool* enabled) const {
@ -210,6 +244,7 @@ int32_t AudioDeviceModuleIOS::SpeakerMute(bool* enabled) const {
CHECKinitialized_(); CHECKinitialized_();
bool muted = false; bool muted = false;
if (audio_device_->SpeakerMute(muted) == -1) { if (audio_device_->SpeakerMute(muted) == -1) {
ReportError(kSpeakerMuteFailed);
return -1; return -1;
} }
*enabled = muted; *enabled = muted;
@ -222,6 +257,7 @@ int32_t AudioDeviceModuleIOS::MicrophoneMuteIsAvailable(bool* available) {
CHECKinitialized_(); CHECKinitialized_();
bool isAvailable = false; bool isAvailable = false;
if (audio_device_->MicrophoneMuteIsAvailable(isAvailable) == -1) { if (audio_device_->MicrophoneMuteIsAvailable(isAvailable) == -1) {
ReportError(kMicrophoneMuteFailed);
return -1; return -1;
} }
*available = isAvailable; *available = isAvailable;
@ -232,7 +268,11 @@ int32_t AudioDeviceModuleIOS::MicrophoneMuteIsAvailable(bool* available) {
int32_t AudioDeviceModuleIOS::SetMicrophoneMute(bool enable) { int32_t AudioDeviceModuleIOS::SetMicrophoneMute(bool enable) {
RTC_DLOG(LS_INFO) << __FUNCTION__ << "(" << enable << ")"; RTC_DLOG(LS_INFO) << __FUNCTION__ << "(" << enable << ")";
CHECKinitialized_(); CHECKinitialized_();
return (audio_device_->SetMicrophoneMute(enable)); int32_t result = audio_device_->SetMicrophoneMute(enable);
if (result != 0) {
ReportError(kMicrophoneMuteFailed);
}
return result;
} }
int32_t AudioDeviceModuleIOS::MicrophoneMute(bool* enabled) const { int32_t AudioDeviceModuleIOS::MicrophoneMute(bool* enabled) const {
@ -240,6 +280,7 @@ int32_t AudioDeviceModuleIOS::MicrophoneMute(bool* enabled) const {
CHECKinitialized_(); CHECKinitialized_();
bool muted = false; bool muted = false;
if (audio_device_->MicrophoneMute(muted) == -1) { if (audio_device_->MicrophoneMute(muted) == -1) {
ReportError(kMicrophoneMuteFailed);
return -1; return -1;
} }
*enabled = muted; *enabled = muted;
@ -252,6 +293,7 @@ int32_t AudioDeviceModuleIOS::MicrophoneVolumeIsAvailable(bool* available) {
CHECKinitialized_(); CHECKinitialized_();
bool isAvailable = false; bool isAvailable = false;
if (audio_device_->MicrophoneVolumeIsAvailable(isAvailable) == -1) { if (audio_device_->MicrophoneVolumeIsAvailable(isAvailable) == -1) {
ReportError(kMicrophoneVolumeFailed);
return -1; return -1;
} }
*available = isAvailable; *available = isAvailable;
@ -270,6 +312,7 @@ int32_t AudioDeviceModuleIOS::MicrophoneVolume(uint32_t* volume) const {
CHECKinitialized_(); CHECKinitialized_();
uint32_t level = 0; uint32_t level = 0;
if (audio_device_->MicrophoneVolume(level) == -1) { if (audio_device_->MicrophoneVolume(level) == -1) {
ReportError(kMicrophoneVolumeFailed);
return -1; return -1;
} }
*volume = level; *volume = level;
@ -283,6 +326,7 @@ int32_t AudioDeviceModuleIOS::StereoRecordingIsAvailable(
CHECKinitialized_(); CHECKinitialized_();
bool isAvailable = false; bool isAvailable = false;
if (audio_device_->StereoRecordingIsAvailable(isAvailable) == -1) { if (audio_device_->StereoRecordingIsAvailable(isAvailable) == -1) {
ReportError(kStereoRecordingFailed);
return -1; return -1;
} }
*available = isAvailable; *available = isAvailable;
@ -296,6 +340,7 @@ int32_t AudioDeviceModuleIOS::SetStereoRecording(bool enable) {
if (enable) { if (enable) {
RTC_LOG(LS_WARNING) << "recording in stereo is not supported"; RTC_LOG(LS_WARNING) << "recording in stereo is not supported";
} }
ReportError(kStereoRecordingFailed);
return -1; return -1;
} }
@ -304,6 +349,7 @@ int32_t AudioDeviceModuleIOS::StereoRecording(bool* enabled) const {
CHECKinitialized_(); CHECKinitialized_();
bool stereo = false; bool stereo = false;
if (audio_device_->StereoRecording(stereo) == -1) { if (audio_device_->StereoRecording(stereo) == -1) {
ReportError(kStereoRecordingFailed);
return -1; return -1;
} }
*enabled = stereo; *enabled = stereo;
@ -316,6 +362,7 @@ int32_t AudioDeviceModuleIOS::StereoPlayoutIsAvailable(bool* available) const {
CHECKinitialized_(); CHECKinitialized_();
bool isAvailable = false; bool isAvailable = false;
if (audio_device_->StereoPlayoutIsAvailable(isAvailable) == -1) { if (audio_device_->StereoPlayoutIsAvailable(isAvailable) == -1) {
ReportError(kStereoPlayoutFailed);
return -1; return -1;
} }
*available = isAvailable; *available = isAvailable;
@ -329,10 +376,12 @@ int32_t AudioDeviceModuleIOS::SetStereoPlayout(bool enable) {
if (audio_device_->PlayoutIsInitialized()) { if (audio_device_->PlayoutIsInitialized()) {
RTC_LOG(LS_ERROR) RTC_LOG(LS_ERROR)
<< "unable to set stereo mode while playing side is initialized"; << "unable to set stereo mode while playing side is initialized";
ReportError(kStereoPlayoutFailed);
return -1; return -1;
} }
if (audio_device_->SetStereoPlayout(enable)) { if (audio_device_->SetStereoPlayout(enable)) {
RTC_LOG(LS_WARNING) << "stereo playout is not supported"; RTC_LOG(LS_WARNING) << "stereo playout is not supported";
ReportError(kStereoPlayoutFailed);
return -1; return -1;
} }
int8_t nChannels(1); int8_t nChannels(1);
@ -348,6 +397,7 @@ int32_t AudioDeviceModuleIOS::StereoPlayout(bool* enabled) const {
CHECKinitialized_(); CHECKinitialized_();
bool stereo = false; bool stereo = false;
if (audio_device_->StereoPlayout(stereo) == -1) { if (audio_device_->StereoPlayout(stereo) == -1) {
ReportError(kStereoPlayoutFailed);
return -1; return -1;
} }
*enabled = stereo; *enabled = stereo;
@ -360,6 +410,7 @@ int32_t AudioDeviceModuleIOS::PlayoutIsAvailable(bool* available) {
CHECKinitialized_(); CHECKinitialized_();
bool isAvailable = false; bool isAvailable = false;
if (audio_device_->PlayoutIsAvailable(isAvailable) == -1) { if (audio_device_->PlayoutIsAvailable(isAvailable) == -1) {
ReportError(kPlayoutFailed);
return -1; return -1;
} }
*available = isAvailable; *available = isAvailable;
@ -372,6 +423,7 @@ int32_t AudioDeviceModuleIOS::RecordingIsAvailable(bool* available) {
CHECKinitialized_(); CHECKinitialized_();
bool isAvailable = false; bool isAvailable = false;
if (audio_device_->RecordingIsAvailable(isAvailable) == -1) { if (audio_device_->RecordingIsAvailable(isAvailable) == -1) {
ReportError(kRecordingFailed);
return -1; return -1;
} }
*available = isAvailable; *available = isAvailable;
@ -383,6 +435,7 @@ int32_t AudioDeviceModuleIOS::MaxMicrophoneVolume(uint32_t* maxVolume) const {
CHECKinitialized_(); CHECKinitialized_();
uint32_t maxVol(0); uint32_t maxVol(0);
if (audio_device_->MaxMicrophoneVolume(maxVol) == -1) { if (audio_device_->MaxMicrophoneVolume(maxVol) == -1) {
ReportError(kMicrophoneVolumeFailed);
return -1; return -1;
} }
*maxVolume = maxVol; *maxVolume = maxVol;
@ -393,6 +446,7 @@ int32_t AudioDeviceModuleIOS::MinMicrophoneVolume(uint32_t* minVolume) const {
CHECKinitialized_(); CHECKinitialized_();
uint32_t minVol(0); uint32_t minVol(0);
if (audio_device_->MinMicrophoneVolume(minVol) == -1) { if (audio_device_->MinMicrophoneVolume(minVol) == -1) {
ReportError(kMicrophoneVolumeFailed);
return -1; return -1;
} }
*minVolume = minVol; *minVolume = minVol;
@ -416,7 +470,11 @@ int32_t AudioDeviceModuleIOS::SetPlayoutDevice(uint16_t index) {
int32_t AudioDeviceModuleIOS::SetPlayoutDevice(WindowsDeviceType device) { int32_t AudioDeviceModuleIOS::SetPlayoutDevice(WindowsDeviceType device) {
RTC_DLOG(LS_INFO) << __FUNCTION__; RTC_DLOG(LS_INFO) << __FUNCTION__;
CHECKinitialized_(); CHECKinitialized_();
return audio_device_->SetPlayoutDevice(device); int32_t result = audio_device_->SetPlayoutDevice(device);
if (result != 0) {
ReportError(kPlayoutDeviceFailed);
}
return result;
} }
int32_t AudioDeviceModuleIOS::PlayoutDeviceName( int32_t AudioDeviceModuleIOS::PlayoutDeviceName(
@ -426,9 +484,11 @@ int32_t AudioDeviceModuleIOS::PlayoutDeviceName(
RTC_DLOG(LS_INFO) << __FUNCTION__ << "(" << index << ", ...)"; RTC_DLOG(LS_INFO) << __FUNCTION__ << "(" << index << ", ...)";
CHECKinitialized_(); CHECKinitialized_();
if (name == NULL) { if (name == NULL) {
ReportError(kPlayoutDeviceNameFailed);
return -1; return -1;
} }
if (audio_device_->PlayoutDeviceName(index, name, guid) == -1) { if (audio_device_->PlayoutDeviceName(index, name, guid) == -1) {
ReportError(kPlayoutDeviceNameFailed);
return -1; return -1;
} }
if (name != NULL) { if (name != NULL) {
@ -447,9 +507,11 @@ int32_t AudioDeviceModuleIOS::RecordingDeviceName(
RTC_DLOG(LS_INFO) << __FUNCTION__ << "(" << index << ", ...)"; RTC_DLOG(LS_INFO) << __FUNCTION__ << "(" << index << ", ...)";
CHECKinitialized_(); CHECKinitialized_();
if (name == NULL) { if (name == NULL) {
ReportError(kRecordingDeviceNameFailed);
return -1; return -1;
} }
if (audio_device_->RecordingDeviceName(index, name, guid) == -1) { if (audio_device_->RecordingDeviceName(index, name, guid) == -1) {
ReportError(kRecordingDeviceNameFailed);
return -1; return -1;
} }
if (name != NULL) { if (name != NULL) {
@ -478,7 +540,11 @@ int32_t AudioDeviceModuleIOS::SetRecordingDevice(uint16_t index) {
int32_t AudioDeviceModuleIOS::SetRecordingDevice(WindowsDeviceType device) { int32_t AudioDeviceModuleIOS::SetRecordingDevice(WindowsDeviceType device) {
RTC_DLOG(LS_INFO) << __FUNCTION__; RTC_DLOG(LS_INFO) << __FUNCTION__;
CHECKinitialized_(); CHECKinitialized_();
return audio_device_->SetRecordingDevice(device); int32_t result = audio_device_->SetRecordingDevice(device);
if (result < 0) {
ReportError(kRecordingDeviceFailed);
}
return result;
} }
int32_t AudioDeviceModuleIOS::InitPlayout() { int32_t AudioDeviceModuleIOS::InitPlayout() {
@ -488,6 +554,9 @@ int32_t AudioDeviceModuleIOS::InitPlayout() {
return 0; return 0;
} }
int32_t result = audio_device_->InitPlayout(); int32_t result = audio_device_->InitPlayout();
if (result < 0) {
ReportError(kPlayoutInitFailed);
}
RTC_DLOG(LS_INFO) << "output: " << result; RTC_DLOG(LS_INFO) << "output: " << result;
RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitPlayoutSuccess", RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitPlayoutSuccess",
static_cast<int>(result == 0)); static_cast<int>(result == 0));
@ -501,6 +570,9 @@ int32_t AudioDeviceModuleIOS::InitRecording() {
return 0; return 0;
} }
int32_t result = audio_device_->InitRecording(); int32_t result = audio_device_->InitRecording();
if (result < 0) {
ReportError(kRecordingInitFailed);
}
RTC_DLOG(LS_INFO) << "output: " << result; RTC_DLOG(LS_INFO) << "output: " << result;
RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitRecordingSuccess", RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.InitRecordingSuccess",
static_cast<int>(result == 0)); static_cast<int>(result == 0));
@ -527,6 +599,9 @@ int32_t AudioDeviceModuleIOS::StartPlayout() {
} }
audio_device_buffer_.get()->StartPlayout(); audio_device_buffer_.get()->StartPlayout();
int32_t result = audio_device_->StartPlayout(); int32_t result = audio_device_->StartPlayout();
if (result < 0) {
ReportError(kPlayoutStartFailed);
}
RTC_DLOG(LS_INFO) << "output: " << result; RTC_DLOG(LS_INFO) << "output: " << result;
RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartPlayoutSuccess", RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartPlayoutSuccess",
static_cast<int>(result == 0)); static_cast<int>(result == 0));
@ -538,6 +613,9 @@ int32_t AudioDeviceModuleIOS::StopPlayout() {
CHECKinitialized_(); CHECKinitialized_();
int32_t result = audio_device_->StopPlayout(); int32_t result = audio_device_->StopPlayout();
audio_device_buffer_.get()->StopPlayout(); audio_device_buffer_.get()->StopPlayout();
if (result < 0) {
ReportError(kPlayoutFailed);
}
RTC_DLOG(LS_INFO) << "output: " << result; RTC_DLOG(LS_INFO) << "output: " << result;
RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopPlayoutSuccess", RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopPlayoutSuccess",
static_cast<int>(result == 0)); static_cast<int>(result == 0));
@ -558,6 +636,9 @@ int32_t AudioDeviceModuleIOS::StartRecording() {
} }
audio_device_buffer_.get()->StartRecording(); audio_device_buffer_.get()->StartRecording();
int32_t result = audio_device_->StartRecording(); int32_t result = audio_device_->StartRecording();
if (result < 0) {
ReportError(kRecordingStartFailed);
}
RTC_DLOG(LS_INFO) << "output: " << result; RTC_DLOG(LS_INFO) << "output: " << result;
RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartRecordingSuccess", RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StartRecordingSuccess",
static_cast<int>(result == 0)); static_cast<int>(result == 0));
@ -569,6 +650,9 @@ int32_t AudioDeviceModuleIOS::StopRecording() {
CHECKinitialized_(); CHECKinitialized_();
int32_t result = audio_device_->StopRecording(); int32_t result = audio_device_->StopRecording();
audio_device_buffer_.get()->StopRecording(); audio_device_buffer_.get()->StopRecording();
if (result < 0) {
ReportError(kRecordingFailed);
}
RTC_DLOG(LS_INFO) << "output: " << result; RTC_DLOG(LS_INFO) << "output: " << result;
RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopRecordingSuccess", RTC_HISTOGRAM_BOOLEAN("WebRTC.Audio.StopRecordingSuccess",
static_cast<int>(result == 0)); static_cast<int>(result == 0));
@ -584,13 +668,19 @@ bool AudioDeviceModuleIOS::Recording() const {
int32_t AudioDeviceModuleIOS::RegisterAudioCallback( int32_t AudioDeviceModuleIOS::RegisterAudioCallback(
AudioTransport* audioCallback) { AudioTransport* audioCallback) {
RTC_DLOG(LS_INFO) << __FUNCTION__; RTC_DLOG(LS_INFO) << __FUNCTION__;
return audio_device_buffer_.get()->RegisterAudioCallback(audioCallback); int32_t result =
audio_device_buffer_.get()->RegisterAudioCallback(audioCallback);
if (result < 0) {
ReportError(kRegisterAudioCallbackFailed);
}
return result;
} }
int32_t AudioDeviceModuleIOS::PlayoutDelay(uint16_t* delayMS) const { int32_t AudioDeviceModuleIOS::PlayoutDelay(uint16_t* delayMS) const {
CHECKinitialized_(); CHECKinitialized_();
uint16_t delay = 0; uint16_t delay = 0;
if (audio_device_->PlayoutDelay(delay) == -1) { if (audio_device_->PlayoutDelay(delay) == -1) {
ReportError(kPlayoutDelayFailed);
RTC_LOG(LS_ERROR) << "failed to retrieve the playout delay"; RTC_LOG(LS_ERROR) << "failed to retrieve the playout delay";
return -1; return -1;
} }
@ -610,6 +700,9 @@ int32_t AudioDeviceModuleIOS::EnableBuiltInAEC(bool enable) {
RTC_DLOG(LS_INFO) << __FUNCTION__ << "(" << enable << ")"; RTC_DLOG(LS_INFO) << __FUNCTION__ << "(" << enable << ")";
CHECKinitialized_(); CHECKinitialized_();
int32_t ok = audio_device_->EnableBuiltInAEC(enable); int32_t ok = audio_device_->EnableBuiltInAEC(enable);
if (ok < 0) {
ReportError(kEnableBuiltInAECFailed);
}
RTC_DLOG(LS_INFO) << "output: " << ok; RTC_DLOG(LS_INFO) << "output: " << ok;
return ok; return ok;
} }
@ -626,6 +719,9 @@ int32_t AudioDeviceModuleIOS::EnableBuiltInAGC(bool enable) {
RTC_DLOG(LS_INFO) << __FUNCTION__ << "(" << enable << ")"; RTC_DLOG(LS_INFO) << __FUNCTION__ << "(" << enable << ")";
CHECKinitialized_(); CHECKinitialized_();
int32_t ok = audio_device_->EnableBuiltInAGC(enable); int32_t ok = audio_device_->EnableBuiltInAGC(enable);
if (ok < 0) {
ReportError(kEnableBuiltInAGCFailed);
}
RTC_DLOG(LS_INFO) << "output: " << ok; RTC_DLOG(LS_INFO) << "output: " << ok;
return ok; return ok;
} }
@ -642,6 +738,9 @@ int32_t AudioDeviceModuleIOS::EnableBuiltInNS(bool enable) {
RTC_DLOG(LS_INFO) << __FUNCTION__ << "(" << enable << ")"; RTC_DLOG(LS_INFO) << __FUNCTION__ << "(" << enable << ")";
CHECKinitialized_(); CHECKinitialized_();
int32_t ok = audio_device_->EnableBuiltInNS(enable); int32_t ok = audio_device_->EnableBuiltInNS(enable);
if (ok < 0) {
ReportError(kEnableBuiltInNSFailed);
}
RTC_DLOG(LS_INFO) << "output: " << ok; RTC_DLOG(LS_INFO) << "output: " << ok;
return ok; return ok;
} }