Returning errors if any of the Init() settings in VoE fail.

There's no reason to try to continue if these simple settings fail; better to know about it immediately.

Also, readjusting the indentation to avoid breaking strings over several lines. This bends GStyle a bit, but it's well worth it to avoid the common "forgot to add a space" error.
Review URL: http://webrtc-codereview.appspot.com/173003

git-svn-id: http://webrtc.googlecode.com/svn/trunk@676 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
andrew@webrtc.org 2011-10-03 15:22:28 +00:00
parent 5b91464edf
commit f458916145
2 changed files with 65 additions and 90 deletions

View File

@ -342,8 +342,7 @@ int VoEBaseImpl::DeRegisterVoiceEngineObserver()
if (!_voiceEngineObserverPtr) if (!_voiceEngineObserverPtr)
{ {
_engineStatistics.SetLastError(VE_INVALID_OPERATION, kTraceError, _engineStatistics.SetLastError(VE_INVALID_OPERATION, kTraceError,
"DeRegisterVoiceEngineObserver() " "DeRegisterVoiceEngineObserver() observer already disabled");
" observer already disabled");
return 0; return 0;
} }
@ -379,8 +378,7 @@ int VoEBaseImpl::Init(AudioDeviceModule* external_adm)
if (_moduleProcessThreadPtr->Start() != 0) if (_moduleProcessThreadPtr->Start() != 0)
{ {
_engineStatistics.SetLastError(VE_THREAD_ERROR, kTraceError, _engineStatistics.SetLastError(VE_THREAD_ERROR, kTraceError,
"Init() failed to start module " "Init() failed to start module process thread");
"process thread");
return -1; return -1;
} }
} }
@ -394,8 +392,7 @@ int VoEBaseImpl::Init(AudioDeviceModule* external_adm)
if (_audioProcessingModulePtr == NULL) if (_audioProcessingModulePtr == NULL)
{ {
_engineStatistics.SetLastError(VE_NO_MEMORY, kTraceCritical, _engineStatistics.SetLastError(VE_NO_MEMORY, kTraceCritical,
"Init() failed to create the AP " "Init() failed to create the AP module");
"module");
return -1; return -1;
} }
voe::Utility::TraceModuleVersion(VoEId(_instanceId, -1), voe::Utility::TraceModuleVersion(VoEId(_instanceId, -1),
@ -409,111 +406,103 @@ int VoEBaseImpl::Init(AudioDeviceModule* external_adm)
set_device_sample_rate_hz( set_device_sample_rate_hz(
kVoiceEngineAudioProcessingDeviceSampleRateHz)) kVoiceEngineAudioProcessingDeviceSampleRateHz))
{ {
_engineStatistics.SetLastError(VE_APM_ERROR, kTraceWarning, _engineStatistics.SetLastError(VE_APM_ERROR, kTraceError,
"Init() failed to set the device " "Init() failed to set the device sample rate to 48K for AP "
"sample rate to " " module");
"48K for AP module"); return -1;
} }
// Using 8 kHz as inital Fs. Might be changed already at first call. // Using 8 kHz as inital Fs. Might be changed already at first call.
if (_audioProcessingModulePtr->set_sample_rate_hz(8000)) if (_audioProcessingModulePtr->set_sample_rate_hz(8000))
{ {
_engineStatistics.SetLastError(VE_APM_ERROR, kTraceWarning, _engineStatistics.SetLastError(VE_APM_ERROR, kTraceError,
"Init() failed to set the sample " "Init() failed to set the sample rate to 8K for AP module");
"rate to 8K for AP" return -1;
"module");
} }
if (_audioProcessingModulePtr->set_num_channels(1, 1) != 0) if (_audioProcessingModulePtr->set_num_channels(1, 1) != 0)
{ {
_engineStatistics.SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning, _engineStatistics.SetLastError(VE_SOUNDCARD_ERROR, kTraceError,
"Init() failed to set channels for " "Init() failed to set channels for the primary audio stream");
"the primary audio" return -1;
"stream");
} }
if (_audioProcessingModulePtr->set_num_reverse_channels(1) != 0) if (_audioProcessingModulePtr->set_num_reverse_channels(1) != 0)
{ {
_engineStatistics.SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning, _engineStatistics.SetLastError(VE_SOUNDCARD_ERROR, kTraceError,
"Init() failed to set channels for " "Init() failed to set channels for the primary audio stream");
"the primary audio" return -1;
"stream");
} }
// high-pass filter // high-pass filter
if (_audioProcessingModulePtr->high_pass_filter()->Enable( if (_audioProcessingModulePtr->high_pass_filter()->Enable(
WEBRTC_VOICE_ENGINE_HP_DEFAULT_STATE) != 0) WEBRTC_VOICE_ENGINE_HP_DEFAULT_STATE) != 0)
{ {
_engineStatistics.SetLastError(VE_APM_ERROR, kTraceWarning, _engineStatistics.SetLastError(VE_APM_ERROR, kTraceError,
"Init() failed to set the high-pass " "Init() failed to set the high-pass filter for AP module");
"filter for AP" return -1;
" module");
} }
// Echo Cancellation // Echo Cancellation
if (_audioProcessingModulePtr->echo_cancellation()-> if (_audioProcessingModulePtr->echo_cancellation()->
enable_drift_compensation(false) != 0) enable_drift_compensation(false) != 0)
{ {
_engineStatistics.SetLastError(VE_APM_ERROR, kTraceWarning, _engineStatistics.SetLastError(VE_APM_ERROR, kTraceError,
"Init() failed to set drift " "Init() failed to set drift compensation for AP module");
"compensation for AP module"); return -1;
} }
if (_audioProcessingModulePtr->echo_cancellation()->Enable( if (_audioProcessingModulePtr->echo_cancellation()->Enable(
WEBRTC_VOICE_ENGINE_EC_DEFAULT_STATE)) WEBRTC_VOICE_ENGINE_EC_DEFAULT_STATE))
{ {
_engineStatistics.SetLastError(VE_APM_ERROR, kTraceWarning, _engineStatistics.SetLastError(VE_APM_ERROR, kTraceError,
"Init() failed to set echo " "Init() failed to set echo cancellation state for AP module");
"cancellation state for AP" return -1;
" module");
} }
// Noise Reduction // Noise Reduction
if (_audioProcessingModulePtr->noise_suppression()->set_level( if (_audioProcessingModulePtr->noise_suppression()->set_level(
(NoiseSuppression::Level) WEBRTC_VOICE_ENGINE_NS_DEFAULT_MODE) (NoiseSuppression::Level) WEBRTC_VOICE_ENGINE_NS_DEFAULT_MODE)
!= 0) != 0)
{ {
_engineStatistics.SetLastError(VE_APM_ERROR, kTraceWarning, _engineStatistics.SetLastError(VE_APM_ERROR, kTraceError,
"Init() failed to set noise " "Init() failed to set noise reduction level for AP module");
"reduction level for VP" return -1;
"module");
} }
if (_audioProcessingModulePtr->noise_suppression()->Enable( if (_audioProcessingModulePtr->noise_suppression()->Enable(
WEBRTC_VOICE_ENGINE_NS_DEFAULT_STATE) != 0) WEBRTC_VOICE_ENGINE_NS_DEFAULT_STATE) != 0)
{ {
_engineStatistics.SetLastError(VE_APM_ERROR, kTraceWarning, _engineStatistics.SetLastError(VE_APM_ERROR, kTraceError,
"Init() failed to set noise " "Init() failed to set noise reduction state for AP module");
"reduction state for AP" return -1;
"module");
} }
// Automatic Gain control // Automatic Gain control
if (_audioProcessingModulePtr->gain_control()->set_analog_level_limits( if (_audioProcessingModulePtr->gain_control()->set_analog_level_limits(
kMinVolumeLevel,kMaxVolumeLevel) != 0) kMinVolumeLevel,kMaxVolumeLevel) != 0)
{ {
_engineStatistics.SetLastError(VE_APM_ERROR, kTraceWarning, _engineStatistics.SetLastError(VE_APM_ERROR, kTraceError,
"Init() failed to set AGC analog " "Init() failed to set AGC analog level for AP module");
"level for AP module"); return -1;
} }
if (_audioProcessingModulePtr->gain_control()->set_mode( if (_audioProcessingModulePtr->gain_control()->set_mode(
(GainControl::Mode) WEBRTC_VOICE_ENGINE_AGC_DEFAULT_MODE) (GainControl::Mode) WEBRTC_VOICE_ENGINE_AGC_DEFAULT_MODE)
!= 0) != 0)
{ {
_engineStatistics.SetLastError(VE_APM_ERROR, kTraceWarning, _engineStatistics.SetLastError(VE_APM_ERROR, kTraceError,
"Init() failed to set AGC mode for " "Init() failed to set AGC mode for AP module");
"AP module"); return -1;
} }
if (_audioProcessingModulePtr->gain_control()->Enable( if (_audioProcessingModulePtr->gain_control()->Enable(
WEBRTC_VOICE_ENGINE_AGC_DEFAULT_STATE) WEBRTC_VOICE_ENGINE_AGC_DEFAULT_STATE)
!= 0) != 0)
{ {
_engineStatistics.SetLastError(VE_APM_ERROR, kTraceWarning, _engineStatistics.SetLastError(VE_APM_ERROR, kTraceError,
"Init() failed to set AGC state for " "Init() failed to set AGC state for AP module");
"AP module"); return -1;
} }
// VAD // VAD
if (_audioProcessingModulePtr->voice_detection()->Enable( if (_audioProcessingModulePtr->voice_detection()->Enable(
WEBRTC_VOICE_ENGINE_VAD_DEFAULT_STATE) WEBRTC_VOICE_ENGINE_VAD_DEFAULT_STATE)
!= 0) != 0)
{ {
_engineStatistics.SetLastError(VE_APM_ERROR, kTraceWarning, _engineStatistics.SetLastError(VE_APM_ERROR, kTraceError,
"Init() failed to set Level " "Init() failed to set VAD state for AP module");
"Estimator state for AP" return -1;
"module");
} }
} }
@ -524,7 +513,7 @@ int VoEBaseImpl::Init(AudioDeviceModule* external_adm)
// Create the internal ADM implementation. // Create the internal ADM implementation.
_audioDevicePtr = AudioDeviceModuleImpl::Create( _audioDevicePtr = AudioDeviceModuleImpl::Create(
VoEId(_instanceId, -1), _audioDeviceLayer); VoEId(_instanceId, -1), _audioDeviceLayer);
if (_audioDevicePtr == NULL) if (_audioDevicePtr == NULL)
{ {
_engineStatistics.SetLastError(VE_NO_MEMORY, kTraceCritical, _engineStatistics.SetLastError(VE_NO_MEMORY, kTraceCritical,
@ -577,33 +566,25 @@ int VoEBaseImpl::Init(AudioDeviceModule* external_adm)
if (_audioDevicePtr->SetPlayoutDevice(WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE) if (_audioDevicePtr->SetPlayoutDevice(WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE)
!= 0) != 0)
{ {
_engineStatistics.SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, _engineStatistics.SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceInfo,
kTraceInfo, "Init() failed to set the default output device");
"Init() failed to set the default "
"output device");
} }
if (_audioDevicePtr->SpeakerIsAvailable(&available) != 0) if (_audioDevicePtr->SpeakerIsAvailable(&available) != 0)
{ {
_engineStatistics.SetLastError(VE_CANNOT_ACCESS_SPEAKER_VOL, _engineStatistics.SetLastError(VE_CANNOT_ACCESS_SPEAKER_VOL, kTraceInfo,
kTraceInfo, "Init() failed to check speaker availability, trying to "
"Init() failed to check speaker " "initialize speaker anyway");
"availability, trying"
" to initialize speaker anyway");
} }
else if (!available) else if (!available)
{ {
_engineStatistics.SetLastError(VE_CANNOT_ACCESS_SPEAKER_VOL, _engineStatistics.SetLastError(VE_CANNOT_ACCESS_SPEAKER_VOL, kTraceInfo,
kTraceInfo, "Init() speaker not available, trying to initialize speaker "
"Init() speaker not available, " "anyway");
"trying to initialize"
"speaker anyway");
} }
if (_audioDevicePtr->InitSpeaker() != 0) if (_audioDevicePtr->InitSpeaker() != 0)
{ {
_engineStatistics.SetLastError(VE_CANNOT_ACCESS_SPEAKER_VOL, _engineStatistics.SetLastError(VE_CANNOT_ACCESS_SPEAKER_VOL, kTraceInfo,
kTraceInfo, "Init() failed to initialize the speaker");
"Init() failed to initialize the "
"speaker");
} }
// Initialize the default microphone // Initialize the default microphone
@ -611,28 +592,24 @@ int VoEBaseImpl::Init(AudioDeviceModule* external_adm)
!= 0) != 0)
{ {
_engineStatistics.SetLastError(VE_SOUNDCARD_ERROR, kTraceInfo, _engineStatistics.SetLastError(VE_SOUNDCARD_ERROR, kTraceInfo,
"Init() failed to set the default " "Init() failed to set the default input device");
"input device");
} }
if (_audioDevicePtr->MicrophoneIsAvailable(&available) != 0) if (_audioDevicePtr->MicrophoneIsAvailable(&available) != 0)
{ {
_engineStatistics.SetLastError(VE_CANNOT_ACCESS_MIC_VOL, kTraceInfo, _engineStatistics.SetLastError(VE_CANNOT_ACCESS_MIC_VOL, kTraceInfo,
"Init() failed to check microphone " "Init() failed to check microphone availability, trying to "
"availability, trying" "initialize microphone anyway");
"to initialize microphone anyway");
} }
else if (!available) else if (!available)
{ {
_engineStatistics.SetLastError(VE_CANNOT_ACCESS_MIC_VOL, kTraceInfo, _engineStatistics.SetLastError(VE_CANNOT_ACCESS_MIC_VOL, kTraceInfo,
"Init() microphone not available, " "Init() microphone not available, trying to initialize "
"trying to initialize" "microphone anyway");
"microphone anyway");
} }
if (_audioDevicePtr->InitMicrophone() != 0) if (_audioDevicePtr->InitMicrophone() != 0)
{ {
_engineStatistics.SetLastError(VE_CANNOT_ACCESS_MIC_VOL, kTraceInfo, _engineStatistics.SetLastError(VE_CANNOT_ACCESS_MIC_VOL, kTraceInfo,
"Init() failed to initialize the " "Init() failed to initialize the microphone");
"microphone");
} }
// Set default AGC mode for the ADM // Set default AGC mode for the ADM
@ -646,9 +623,7 @@ int VoEBaseImpl::Init(AudioDeviceModule* external_adm)
if (_audioDevicePtr->SetAGC(enable) != 0) if (_audioDevicePtr->SetAGC(enable) != 0)
{ {
_engineStatistics.SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, _engineStatistics.SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR,
kTraceWarning, kTraceError, "Init() failed to set default AGC mode in ADM 0");
"Init() failed to set default AGC "
"mode in ADM 0");
} }
} }
#endif #endif
@ -657,15 +632,13 @@ int VoEBaseImpl::Init(AudioDeviceModule* external_adm)
if (_audioDevicePtr->SetStereoPlayout(available ? true : false) != 0) if (_audioDevicePtr->SetStereoPlayout(available ? true : false) != 0)
{ {
_engineStatistics.SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning, _engineStatistics.SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning,
"Init() failed to set stereo playout " "Init() failed to set stereo playout mode");
"mode");
} }
_audioDevicePtr->StereoRecordingIsAvailable(&available); _audioDevicePtr->StereoRecordingIsAvailable(&available);
if (_audioDevicePtr->SetStereoRecording(available ? true : false) != 0) if (_audioDevicePtr->SetStereoRecording(available ? true : false) != 0)
{ {
_engineStatistics.SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning, _engineStatistics.SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning,
"Init() failed to set mono recording " "Init() failed to set mono recording mode");
"mode");
} }
return _engineStatistics.SetInitialized(); return _engineStatistics.SetInitialized();

View File

@ -129,6 +129,8 @@ enum { kVoiceEngineMaxRtpExtensionId = 14 };
} // namespace webrtc } // namespace webrtc
// TODO(andrew): we shouldn't be using the precompiler for this.
// Use enums or bools as appropriate.
#define WEBRTC_AUDIO_PROCESSING_OFF false #define WEBRTC_AUDIO_PROCESSING_OFF false
#define WEBRTC_VOICE_ENGINE_HP_DEFAULT_STATE true #define WEBRTC_VOICE_ENGINE_HP_DEFAULT_STATE true