Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: voice_engine/voe_base_impl.cc

Issue 3020473002: Remove voe::Statistics. (Closed)
Patch Set: rebase Created 3 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « voice_engine/voe_base_impl.h ('k') | voice_engine/voe_base_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 24 matching lines...) Expand all
35 } 35 }
36 36
37 VoEBaseImpl::VoEBaseImpl(voe::SharedData* shared) 37 VoEBaseImpl::VoEBaseImpl(voe::SharedData* shared)
38 : shared_(shared) {} 38 : shared_(shared) {}
39 39
40 VoEBaseImpl::~VoEBaseImpl() { 40 VoEBaseImpl::~VoEBaseImpl() {
41 TerminateInternal(); 41 TerminateInternal();
42 } 42 }
43 43
44 void VoEBaseImpl::OnErrorIsReported(const ErrorCode error) { 44 void VoEBaseImpl::OnErrorIsReported(const ErrorCode error) {
45 rtc::CritScope cs(&callbackCritSect_);
46 if (error == AudioDeviceObserver::kRecordingError) { 45 if (error == AudioDeviceObserver::kRecordingError) {
47 LOG_F(LS_ERROR) << "VE_RUNTIME_REC_ERROR"; 46 LOG_F(LS_ERROR) << "VE_RUNTIME_REC_ERROR";
48 } else if (error == AudioDeviceObserver::kPlayoutError) { 47 } else if (error == AudioDeviceObserver::kPlayoutError) {
49 LOG_F(LS_ERROR) << "VE_RUNTIME_PLAY_ERROR"; 48 LOG_F(LS_ERROR) << "VE_RUNTIME_PLAY_ERROR";
50 } 49 }
51 } 50 }
52 51
53 void VoEBaseImpl::OnWarningIsReported(const WarningCode warning) { 52 void VoEBaseImpl::OnWarningIsReported(const WarningCode warning) {
54 rtc::CritScope cs(&callbackCritSect_);
55 if (warning == AudioDeviceObserver::kRecordingWarning) { 53 if (warning == AudioDeviceObserver::kRecordingWarning) {
56 LOG_F(LS_WARNING) << "VE_RUNTIME_REC_WARNING"; 54 LOG_F(LS_WARNING) << "VE_RUNTIME_REC_WARNING";
57 } else if (warning == AudioDeviceObserver::kPlayoutWarning) { 55 } else if (warning == AudioDeviceObserver::kPlayoutWarning) {
58 LOG_F(LS_WARNING) << "VE_RUNTIME_PLAY_WARNING"; 56 LOG_F(LS_WARNING) << "VE_RUNTIME_PLAY_WARNING";
59 } 57 }
60 } 58 }
61 59
62 int32_t VoEBaseImpl::RecordedDataIsAvailable( 60 int32_t VoEBaseImpl::RecordedDataIsAvailable(
63 const void* audio_data, 61 const void* audio_data,
64 const size_t number_of_frames, 62 const size_t number_of_frames,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 RTC_NOTREACHED(); 158 RTC_NOTREACHED();
161 } 159 }
162 160
163 int VoEBaseImpl::Init( 161 int VoEBaseImpl::Init(
164 AudioDeviceModule* external_adm, 162 AudioDeviceModule* external_adm,
165 AudioProcessing* audio_processing, 163 AudioProcessing* audio_processing,
166 const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory) { 164 const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory) {
167 RTC_DCHECK(audio_processing); 165 RTC_DCHECK(audio_processing);
168 rtc::CritScope cs(shared_->crit_sec()); 166 rtc::CritScope cs(shared_->crit_sec());
169 WebRtcSpl_Init(); 167 WebRtcSpl_Init();
170 if (shared_->statistics().Initialized()) {
171 return 0;
172 }
173 if (shared_->process_thread()) { 168 if (shared_->process_thread()) {
174 shared_->process_thread()->Start(); 169 shared_->process_thread()->Start();
175 } 170 }
176 171
177 // Create an internal ADM if the user has not added an external 172 // Create an internal ADM if the user has not added an external
178 // ADM implementation as input to Init(). 173 // ADM implementation as input to Init().
179 if (external_adm == nullptr) { 174 if (external_adm == nullptr) {
180 #if !defined(WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE) 175 #if !defined(WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE)
181 return -1; 176 return -1;
182 #else 177 #else
183 // Create the internal ADM implementation. 178 // Create the internal ADM implementation.
184 shared_->set_audio_device(AudioDeviceModule::Create( 179 shared_->set_audio_device(AudioDeviceModule::Create(
185 VoEId(shared_->instance_id(), -1), 180 VoEId(shared_->instance_id(), -1),
186 AudioDeviceModule::kPlatformDefaultAudio)); 181 AudioDeviceModule::kPlatformDefaultAudio));
187 if (shared_->audio_device() == nullptr) { 182 if (shared_->audio_device() == nullptr) {
188 shared_->SetLastError(VE_NO_MEMORY, kTraceCritical, 183 LOG(LS_ERROR) << "Init() failed to create the ADM";
189 "Init() failed to create the ADM");
190 return -1; 184 return -1;
191 } 185 }
192 #endif // WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE 186 #endif // WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE
193 } else { 187 } else {
194 // Use the already existing external ADM implementation. 188 // Use the already existing external ADM implementation.
195 shared_->set_audio_device(external_adm); 189 shared_->set_audio_device(external_adm);
196 LOG_F(LS_INFO) 190 LOG_F(LS_INFO)
197 << "An external ADM implementation will be used in VoiceEngine"; 191 << "An external ADM implementation will be used in VoiceEngine";
198 } 192 }
199 193
200 // Register the ADM to the process thread, which will drive the error 194 // Register the ADM to the process thread, which will drive the error
201 // callback mechanism 195 // callback mechanism
202 if (shared_->process_thread()) { 196 if (shared_->process_thread()) {
203 shared_->process_thread()->RegisterModule(shared_->audio_device(), 197 shared_->process_thread()->RegisterModule(shared_->audio_device(),
204 RTC_FROM_HERE); 198 RTC_FROM_HERE);
205 } 199 }
206 200
207 bool available = false; 201 bool available = false;
208 202
209 // -------------------- 203 // --------------------
210 // Reinitialize the ADM 204 // Reinitialize the ADM
211 205
212 // Register the AudioObserver implementation 206 // Register the AudioObserver implementation
213 if (shared_->audio_device()->RegisterEventObserver(this) != 0) { 207 if (shared_->audio_device()->RegisterEventObserver(this) != 0) {
214 shared_->SetLastError( 208 LOG(LS_ERROR) << "Init() failed to register event observer for the ADM";
215 VE_AUDIO_DEVICE_MODULE_ERROR, kTraceWarning,
216 "Init() failed to register event observer for the ADM");
217 } 209 }
218 210
219 // Register the AudioTransport implementation 211 // Register the AudioTransport implementation
220 if (shared_->audio_device()->RegisterAudioCallback(this) != 0) { 212 if (shared_->audio_device()->RegisterAudioCallback(this) != 0) {
221 shared_->SetLastError( 213 LOG(LS_ERROR) << "Init() failed to register audio callback for the ADM";
222 VE_AUDIO_DEVICE_MODULE_ERROR, kTraceWarning,
223 "Init() failed to register audio callback for the ADM");
224 } 214 }
225 215
226 // ADM initialization 216 // ADM initialization
227 if (shared_->audio_device()->Init() != 0) { 217 if (shared_->audio_device()->Init() != 0) {
228 shared_->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError, 218 LOG(LS_ERROR) << "Init() failed to initialize the ADM";
229 "Init() failed to initialize the ADM");
230 return -1; 219 return -1;
231 } 220 }
232 221
233 // Initialize the default speaker 222 // Initialize the default speaker
234 if (shared_->audio_device()->SetPlayoutDevice( 223 if (shared_->audio_device()->SetPlayoutDevice(
235 WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE) != 0) { 224 WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE) != 0) {
236 shared_->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceInfo, 225 LOG(LS_ERROR) << "Init() failed to set the default output device";
237 "Init() failed to set the default output device");
238 } 226 }
239 if (shared_->audio_device()->InitSpeaker() != 0) { 227 if (shared_->audio_device()->InitSpeaker() != 0) {
240 shared_->SetLastError(VE_CANNOT_ACCESS_SPEAKER_VOL, kTraceInfo, 228 LOG(LS_ERROR) << "Init() failed to initialize the speaker";
241 "Init() failed to initialize the speaker");
242 } 229 }
243 230
244 // Initialize the default microphone 231 // Initialize the default microphone
245 if (shared_->audio_device()->SetRecordingDevice( 232 if (shared_->audio_device()->SetRecordingDevice(
246 WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE) != 0) { 233 WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE) != 0) {
247 shared_->SetLastError(VE_SOUNDCARD_ERROR, kTraceInfo, 234 LOG(LS_ERROR) << "Init() failed to set the default input device";
248 "Init() failed to set the default input device");
249 } 235 }
250 if (shared_->audio_device()->InitMicrophone() != 0) { 236 if (shared_->audio_device()->InitMicrophone() != 0) {
251 shared_->SetLastError(VE_CANNOT_ACCESS_MIC_VOL, kTraceInfo, 237 LOG(LS_ERROR) << "Init() failed to initialize the microphone";
252 "Init() failed to initialize the microphone");
253 } 238 }
254 239
255 // Set number of channels 240 // Set number of channels
256 if (shared_->audio_device()->StereoPlayoutIsAvailable(&available) != 0) { 241 if (shared_->audio_device()->StereoPlayoutIsAvailable(&available) != 0) {
257 shared_->SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning, 242 LOG(LS_ERROR) << "Init() failed to query stereo playout mode";
258 "Init() failed to query stereo playout mode");
259 } 243 }
260 if (shared_->audio_device()->SetStereoPlayout(available) != 0) { 244 if (shared_->audio_device()->SetStereoPlayout(available) != 0) {
261 shared_->SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning, 245 LOG(LS_ERROR) << "Init() failed to set mono/stereo playout mode";
262 "Init() failed to set mono/stereo playout mode");
263 } 246 }
264 247
265 // TODO(andrew): These functions don't tell us whether stereo recording 248 // TODO(andrew): These functions don't tell us whether stereo recording
266 // is truly available. We simply set the AudioProcessing input to stereo 249 // is truly available. We simply set the AudioProcessing input to stereo
267 // here, because we have to wait until receiving the first frame to 250 // here, because we have to wait until receiving the first frame to
268 // determine the actual number of channels anyway. 251 // determine the actual number of channels anyway.
269 // 252 //
270 // These functions may be changed; tracked here: 253 // These functions may be changed; tracked here:
271 // http://code.google.com/p/webrtc/issues/detail?id=204 254 // http://code.google.com/p/webrtc/issues/detail?id=204
272 shared_->audio_device()->StereoRecordingIsAvailable(&available); 255 shared_->audio_device()->StereoRecordingIsAvailable(&available);
273 if (shared_->audio_device()->SetStereoRecording(available) != 0) { 256 if (shared_->audio_device()->SetStereoRecording(available) != 0) {
274 shared_->SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning, 257 LOG(LS_ERROR) << "Init() failed to set mono/stereo recording mode";
275 "Init() failed to set mono/stereo recording mode");
276 } 258 }
277 259
278 shared_->set_audio_processing(audio_processing); 260 shared_->set_audio_processing(audio_processing);
279 261
280 // Set the error state for any failures in this block.
281 shared_->SetLastError(VE_APM_ERROR);
282 // Configure AudioProcessing components. 262 // Configure AudioProcessing components.
283 // TODO(peah): Move this initialization to webrtcvoiceengine.cc. 263 // TODO(peah): Move this initialization to webrtcvoiceengine.cc.
284 if (audio_processing->high_pass_filter()->Enable(true) != 0) { 264 if (audio_processing->high_pass_filter()->Enable(true) != 0) {
285 LOG_F(LS_ERROR) << "Failed to enable high pass filter."; 265 LOG_F(LS_ERROR) << "Failed to enable high pass filter.";
286 return -1; 266 return -1;
287 } 267 }
288 if (audio_processing->echo_cancellation()->enable_drift_compensation(false) != 268 if (audio_processing->echo_cancellation()->enable_drift_compensation(false) !=
289 0) { 269 0) {
290 LOG_F(LS_ERROR) << "Failed to disable drift compensation."; 270 LOG_F(LS_ERROR) << "Failed to disable drift compensation.";
291 return -1; 271 return -1;
(...skipping 10 matching lines...) Expand all
302 return -1; 282 return -1;
303 } 283 }
304 if (agc->set_mode(kDefaultAgcMode) != 0) { 284 if (agc->set_mode(kDefaultAgcMode) != 0) {
305 LOG_F(LS_ERROR) << "Failed to set mode: " << kDefaultAgcMode; 285 LOG_F(LS_ERROR) << "Failed to set mode: " << kDefaultAgcMode;
306 return -1; 286 return -1;
307 } 287 }
308 if (agc->Enable(kDefaultAgcState) != 0) { 288 if (agc->Enable(kDefaultAgcState) != 0) {
309 LOG_F(LS_ERROR) << "Failed to set agc state: " << kDefaultAgcState; 289 LOG_F(LS_ERROR) << "Failed to set agc state: " << kDefaultAgcState;
310 return -1; 290 return -1;
311 } 291 }
312 shared_->SetLastError(0); // Clear error state.
313 292
314 #ifdef WEBRTC_VOICE_ENGINE_AGC 293 #ifdef WEBRTC_VOICE_ENGINE_AGC
315 bool agc_enabled = 294 bool agc_enabled =
316 agc->mode() == GainControl::kAdaptiveAnalog && agc->is_enabled(); 295 agc->mode() == GainControl::kAdaptiveAnalog && agc->is_enabled();
317 if (shared_->audio_device()->SetAGC(agc_enabled) != 0) { 296 if (shared_->audio_device()->SetAGC(agc_enabled) != 0) {
318 LOG_F(LS_ERROR) << "Failed to set agc to enabled: " << agc_enabled; 297 LOG_F(LS_ERROR) << "Failed to set agc to enabled: " << agc_enabled;
319 shared_->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR);
320 // TODO(ajm): No error return here due to 298 // TODO(ajm): No error return here due to
321 // https://code.google.com/p/webrtc/issues/detail?id=1464 299 // https://code.google.com/p/webrtc/issues/detail?id=1464
322 } 300 }
323 #endif 301 #endif
324 302
325 if (decoder_factory) 303 if (decoder_factory)
326 decoder_factory_ = decoder_factory; 304 decoder_factory_ = decoder_factory;
327 else 305 else
328 decoder_factory_ = CreateBuiltinAudioDecoderFactory(); 306 decoder_factory_ = CreateBuiltinAudioDecoderFactory();
329 307
330 return shared_->statistics().SetInitialized(); 308 return 0;
331 } 309 }
332 310
333 int VoEBaseImpl::Terminate() { 311 int VoEBaseImpl::Terminate() {
334 rtc::CritScope cs(shared_->crit_sec()); 312 rtc::CritScope cs(shared_->crit_sec());
335 return TerminateInternal(); 313 return TerminateInternal();
336 } 314 }
337 315
338 int VoEBaseImpl::CreateChannel() { 316 int VoEBaseImpl::CreateChannel() {
339 return CreateChannel(ChannelConfig()); 317 return CreateChannel(ChannelConfig());
340 } 318 }
341 319
342 int VoEBaseImpl::CreateChannel(const ChannelConfig& config) { 320 int VoEBaseImpl::CreateChannel(const ChannelConfig& config) {
343 rtc::CritScope cs(shared_->crit_sec()); 321 rtc::CritScope cs(shared_->crit_sec());
344 if (!shared_->statistics().Initialized()) {
345 shared_->SetLastError(VE_NOT_INITED, kTraceError);
346 return -1;
347 }
348
349 ChannelConfig config_copy(config); 322 ChannelConfig config_copy(config);
350 config_copy.acm_config.decoder_factory = decoder_factory_; 323 config_copy.acm_config.decoder_factory = decoder_factory_;
351 voe::ChannelOwner channel_owner = 324 voe::ChannelOwner channel_owner =
352 shared_->channel_manager().CreateChannel(config_copy); 325 shared_->channel_manager().CreateChannel(config_copy);
353 return InitializeChannel(&channel_owner); 326 return InitializeChannel(&channel_owner);
354 } 327 }
355 328
356 int VoEBaseImpl::InitializeChannel(voe::ChannelOwner* channel_owner) { 329 int VoEBaseImpl::InitializeChannel(voe::ChannelOwner* channel_owner) {
357 if (channel_owner->channel()->SetEngineInformation( 330 if (channel_owner->channel()->SetEngineInformation(
358 shared_->statistics(),
359 *shared_->process_thread(), *shared_->audio_device(), 331 *shared_->process_thread(), *shared_->audio_device(),
360 &callbackCritSect_, shared_->encoder_queue()) != 0) { 332 shared_->encoder_queue()) != 0) {
361 shared_->SetLastError( 333 LOG(LS_ERROR) << "CreateChannel() failed to associate engine and channel."
362 VE_CHANNEL_NOT_CREATED, kTraceError, 334 " Destroying channel.";
363 "CreateChannel() failed to associate engine and channel."
364 " Destroying channel.");
365 shared_->channel_manager().DestroyChannel( 335 shared_->channel_manager().DestroyChannel(
366 channel_owner->channel()->ChannelId()); 336 channel_owner->channel()->ChannelId());
367 return -1; 337 return -1;
368 } else if (channel_owner->channel()->Init() != 0) { 338 } else if (channel_owner->channel()->Init() != 0) {
369 shared_->SetLastError( 339 LOG(LS_ERROR) << "CreateChannel() failed to initialize channel. Destroying"
370 VE_CHANNEL_NOT_CREATED, kTraceError, 340 " channel.";
371 "CreateChannel() failed to initialize channel. Destroying"
372 " channel.");
373 shared_->channel_manager().DestroyChannel( 341 shared_->channel_manager().DestroyChannel(
374 channel_owner->channel()->ChannelId()); 342 channel_owner->channel()->ChannelId());
375 return -1; 343 return -1;
376 } 344 }
377 return channel_owner->channel()->ChannelId(); 345 return channel_owner->channel()->ChannelId();
378 } 346 }
379 347
380 int VoEBaseImpl::DeleteChannel(int channel) { 348 int VoEBaseImpl::DeleteChannel(int channel) {
381 rtc::CritScope cs(shared_->crit_sec()); 349 rtc::CritScope cs(shared_->crit_sec());
382 if (!shared_->statistics().Initialized()) {
383 shared_->SetLastError(VE_NOT_INITED, kTraceError);
384 return -1;
385 }
386
387 { 350 {
388 voe::ChannelOwner ch = shared_->channel_manager().GetChannel(channel); 351 voe::ChannelOwner ch = shared_->channel_manager().GetChannel(channel);
389 voe::Channel* channelPtr = ch.channel(); 352 voe::Channel* channelPtr = ch.channel();
390 if (channelPtr == nullptr) { 353 if (channelPtr == nullptr) {
391 shared_->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, 354 LOG(LS_ERROR) << "DeleteChannel() failed to locate channel";
392 "DeleteChannel() failed to locate channel");
393 return -1; 355 return -1;
394 } 356 }
395 } 357 }
396 358
397 shared_->channel_manager().DestroyChannel(channel); 359 shared_->channel_manager().DestroyChannel(channel);
398 if (StopSend() != 0) { 360 if (StopSend() != 0) {
399 return -1; 361 return -1;
400 } 362 }
401 if (StopPlayout() != 0) { 363 if (StopPlayout() != 0) {
402 return -1; 364 return -1;
403 } 365 }
404 return 0; 366 return 0;
405 } 367 }
406 368
407 int VoEBaseImpl::StartPlayout(int channel) { 369 int VoEBaseImpl::StartPlayout(int channel) {
408 rtc::CritScope cs(shared_->crit_sec()); 370 rtc::CritScope cs(shared_->crit_sec());
409 if (!shared_->statistics().Initialized()) {
410 shared_->SetLastError(VE_NOT_INITED, kTraceError);
411 return -1;
412 }
413 voe::ChannelOwner ch = shared_->channel_manager().GetChannel(channel); 371 voe::ChannelOwner ch = shared_->channel_manager().GetChannel(channel);
414 voe::Channel* channelPtr = ch.channel(); 372 voe::Channel* channelPtr = ch.channel();
415 if (channelPtr == nullptr) { 373 if (channelPtr == nullptr) {
416 shared_->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, 374 LOG(LS_ERROR) << "StartPlayout() failed to locate channel";
417 "StartPlayout() failed to locate channel");
418 return -1; 375 return -1;
419 } 376 }
420 if (channelPtr->Playing()) { 377 if (channelPtr->Playing()) {
421 return 0; 378 return 0;
422 } 379 }
423 if (StartPlayout() != 0) { 380 if (StartPlayout() != 0) {
424 shared_->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError, 381 LOG(LS_ERROR) << "StartPlayout() failed to start playout";
425 "StartPlayout() failed to start playout");
426 return -1; 382 return -1;
427 } 383 }
428 return channelPtr->StartPlayout(); 384 return channelPtr->StartPlayout();
429 } 385 }
430 386
431 int VoEBaseImpl::StopPlayout(int channel) { 387 int VoEBaseImpl::StopPlayout(int channel) {
432 rtc::CritScope cs(shared_->crit_sec()); 388 rtc::CritScope cs(shared_->crit_sec());
433 if (!shared_->statistics().Initialized()) {
434 shared_->SetLastError(VE_NOT_INITED, kTraceError);
435 return -1;
436 }
437 voe::ChannelOwner ch = shared_->channel_manager().GetChannel(channel); 389 voe::ChannelOwner ch = shared_->channel_manager().GetChannel(channel);
438 voe::Channel* channelPtr = ch.channel(); 390 voe::Channel* channelPtr = ch.channel();
439 if (channelPtr == nullptr) { 391 if (channelPtr == nullptr) {
440 shared_->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, 392 LOG(LS_ERROR) << "StopPlayout() failed to locate channel";
441 "StopPlayout() failed to locate channel");
442 return -1; 393 return -1;
443 } 394 }
444 if (channelPtr->StopPlayout() != 0) { 395 if (channelPtr->StopPlayout() != 0) {
445 LOG_F(LS_WARNING) << "StopPlayout() failed to stop playout for channel " 396 LOG_F(LS_WARNING) << "StopPlayout() failed to stop playout for channel "
446 << channel; 397 << channel;
447 } 398 }
448 return StopPlayout(); 399 return StopPlayout();
449 } 400 }
450 401
451 int VoEBaseImpl::StartSend(int channel) { 402 int VoEBaseImpl::StartSend(int channel) {
452 rtc::CritScope cs(shared_->crit_sec()); 403 rtc::CritScope cs(shared_->crit_sec());
453 if (!shared_->statistics().Initialized()) {
454 shared_->SetLastError(VE_NOT_INITED, kTraceError);
455 return -1;
456 }
457 voe::ChannelOwner ch = shared_->channel_manager().GetChannel(channel); 404 voe::ChannelOwner ch = shared_->channel_manager().GetChannel(channel);
458 voe::Channel* channelPtr = ch.channel(); 405 voe::Channel* channelPtr = ch.channel();
459 if (channelPtr == nullptr) { 406 if (channelPtr == nullptr) {
460 shared_->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, 407 LOG(LS_ERROR) << "StartSend() failed to locate channel";
461 "StartSend() failed to locate channel");
462 return -1; 408 return -1;
463 } 409 }
464 if (channelPtr->Sending()) { 410 if (channelPtr->Sending()) {
465 return 0; 411 return 0;
466 } 412 }
467 if (StartSend() != 0) { 413 if (StartSend() != 0) {
468 shared_->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError, 414 LOG(LS_ERROR) << "StartSend() failed to start recording";
469 "StartSend() failed to start recording");
470 return -1; 415 return -1;
471 } 416 }
472 return channelPtr->StartSend(); 417 return channelPtr->StartSend();
473 } 418 }
474 419
475 int VoEBaseImpl::StopSend(int channel) { 420 int VoEBaseImpl::StopSend(int channel) {
476 rtc::CritScope cs(shared_->crit_sec()); 421 rtc::CritScope cs(shared_->crit_sec());
477 if (!shared_->statistics().Initialized()) {
478 shared_->SetLastError(VE_NOT_INITED, kTraceError);
479 return -1;
480 }
481 voe::ChannelOwner ch = shared_->channel_manager().GetChannel(channel); 422 voe::ChannelOwner ch = shared_->channel_manager().GetChannel(channel);
482 voe::Channel* channelPtr = ch.channel(); 423 voe::Channel* channelPtr = ch.channel();
483 if (channelPtr == nullptr) { 424 if (channelPtr == nullptr) {
484 shared_->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, 425 LOG(LS_ERROR) << "StopSend() failed to locate channel";
485 "StopSend() failed to locate channel");
486 return -1; 426 return -1;
487 } 427 }
488 channelPtr->StopSend(); 428 channelPtr->StopSend();
489 return StopSend(); 429 return StopSend();
490 } 430 }
491 431
492 int32_t VoEBaseImpl::StartPlayout() { 432 int32_t VoEBaseImpl::StartPlayout() {
493 if (!shared_->audio_device()->Playing()) { 433 if (!shared_->audio_device()->Playing()) {
494 if (shared_->audio_device()->InitPlayout() != 0) { 434 if (shared_->audio_device()->InitPlayout() != 0) {
495 LOG_F(LS_ERROR) << "Failed to initialize playout"; 435 LOG_F(LS_ERROR) << "Failed to initialize playout";
496 return -1; 436 return -1;
497 } 437 }
498 if (shared_->audio_device()->StartPlayout() != 0) { 438 if (shared_->audio_device()->StartPlayout() != 0) {
499 LOG_F(LS_ERROR) << "Failed to start playout"; 439 LOG_F(LS_ERROR) << "Failed to start playout";
500 return -1; 440 return -1;
501 } 441 }
502 } 442 }
503 return 0; 443 return 0;
504 } 444 }
505 445
506 int32_t VoEBaseImpl::StopPlayout() { 446 int32_t VoEBaseImpl::StopPlayout() {
507 // Stop audio-device playing if no channel is playing out 447 // Stop audio-device playing if no channel is playing out
508 if (shared_->NumOfPlayingChannels() == 0) { 448 if (shared_->NumOfPlayingChannels() == 0) {
509 if (shared_->audio_device()->StopPlayout() != 0) { 449 if (shared_->audio_device()->StopPlayout() != 0) {
510 shared_->SetLastError(VE_CANNOT_STOP_PLAYOUT, kTraceError, 450 LOG(LS_ERROR) << "StopPlayout() failed to stop playout";
511 "StopPlayout() failed to stop playout");
512 return -1; 451 return -1;
513 } 452 }
514 } 453 }
515 return 0; 454 return 0;
516 } 455 }
517 456
518 int32_t VoEBaseImpl::StartSend() { 457 int32_t VoEBaseImpl::StartSend() {
519 if (!shared_->audio_device()->RecordingIsInitialized() && 458 if (!shared_->audio_device()->RecordingIsInitialized() &&
520 !shared_->audio_device()->Recording()) { 459 !shared_->audio_device()->Recording()) {
521 if (shared_->audio_device()->InitRecording() != 0) { 460 if (shared_->audio_device()->InitRecording() != 0) {
522 LOG_F(LS_ERROR) << "Failed to initialize recording"; 461 LOG_F(LS_ERROR) << "Failed to initialize recording";
523 return -1; 462 return -1;
524 } 463 }
525 } 464 }
526 if (!shared_->audio_device()->Recording()) { 465 if (!shared_->audio_device()->Recording()) {
527 if (shared_->audio_device()->StartRecording() != 0) { 466 if (shared_->audio_device()->StartRecording() != 0) {
528 LOG_F(LS_ERROR) << "Failed to start recording"; 467 LOG_F(LS_ERROR) << "Failed to start recording";
529 return -1; 468 return -1;
530 } 469 }
531 } 470 }
532 return 0; 471 return 0;
533 } 472 }
534 473
535 int32_t VoEBaseImpl::StopSend() { 474 int32_t VoEBaseImpl::StopSend() {
536 if (shared_->NumOfSendingChannels() == 0) { 475 if (shared_->NumOfSendingChannels() == 0) {
537 // Stop audio-device recording if no channel is recording 476 // Stop audio-device recording if no channel is recording
538 if (shared_->audio_device()->StopRecording() != 0) { 477 if (shared_->audio_device()->StopRecording() != 0) {
539 shared_->SetLastError(VE_CANNOT_STOP_RECORDING, kTraceError, 478 LOG(LS_ERROR) << "StopSend() failed to stop recording";
540 "StopSend() failed to stop recording");
541 return -1; 479 return -1;
542 } 480 }
543 shared_->transmit_mixer()->StopSend(); 481 shared_->transmit_mixer()->StopSend();
544 } 482 }
545 483
546 return 0; 484 return 0;
547 } 485 }
548 486
549 int32_t VoEBaseImpl::TerminateInternal() { 487 int32_t VoEBaseImpl::TerminateInternal() {
550 // Delete any remaining channel objects 488 // Delete any remaining channel objects
551 shared_->channel_manager().DestroyAllChannels(); 489 shared_->channel_manager().DestroyAllChannels();
552 490
553 if (shared_->process_thread()) { 491 if (shared_->process_thread()) {
554 if (shared_->audio_device()) { 492 if (shared_->audio_device()) {
555 shared_->process_thread()->DeRegisterModule(shared_->audio_device()); 493 shared_->process_thread()->DeRegisterModule(shared_->audio_device());
556 } 494 }
557 shared_->process_thread()->Stop(); 495 shared_->process_thread()->Stop();
558 } 496 }
559 497
560 if (shared_->audio_device()) { 498 if (shared_->audio_device()) {
561 if (shared_->audio_device()->StopPlayout() != 0) { 499 if (shared_->audio_device()->StopPlayout() != 0) {
562 shared_->SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning, 500 LOG(LS_ERROR) << "TerminateInternal() failed to stop playout";
563 "TerminateInternal() failed to stop playout");
564 } 501 }
565 if (shared_->audio_device()->StopRecording() != 0) { 502 if (shared_->audio_device()->StopRecording() != 0) {
566 shared_->SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning, 503 LOG(LS_ERROR) << "TerminateInternal() failed to stop recording";
567 "TerminateInternal() failed to stop recording");
568 } 504 }
569 if (shared_->audio_device()->RegisterEventObserver(nullptr) != 0) { 505 if (shared_->audio_device()->RegisterEventObserver(nullptr) != 0) {
570 shared_->SetLastError( 506 LOG(LS_ERROR) << "TerminateInternal() failed to de-register event "
571 VE_AUDIO_DEVICE_MODULE_ERROR, kTraceWarning, 507 "observer for the ADM";
572 "TerminateInternal() failed to de-register event observer "
573 "for the ADM");
574 } 508 }
575 if (shared_->audio_device()->RegisterAudioCallback(nullptr) != 0) { 509 if (shared_->audio_device()->RegisterAudioCallback(nullptr) != 0) {
576 shared_->SetLastError( 510 LOG(LS_ERROR) << "TerminateInternal() failed to de-register audio "
577 VE_AUDIO_DEVICE_MODULE_ERROR, kTraceWarning, 511 "callback for the ADM";
578 "TerminateInternal() failed to de-register audio callback "
579 "for the ADM");
580 } 512 }
581 if (shared_->audio_device()->Terminate() != 0) { 513 if (shared_->audio_device()->Terminate() != 0) {
582 shared_->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError, 514 LOG(LS_ERROR) << "TerminateInternal() failed to terminate the ADM";
583 "TerminateInternal() failed to terminate the ADM");
584 } 515 }
585 shared_->set_audio_device(nullptr); 516 shared_->set_audio_device(nullptr);
586 } 517 }
587 518
588 shared_->set_audio_processing(nullptr); 519 shared_->set_audio_processing(nullptr);
589 520
590 return shared_->statistics().SetUnInitialized(); 521 return 0;
591 } 522 }
592 } // namespace webrtc 523 } // namespace webrtc
OLDNEW
« no previous file with comments | « voice_engine/voe_base_impl.h ('k') | voice_engine/voe_base_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698