OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2004 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 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
512 { kRedCodecName, 8000, 1, 127, false, { } }, | 512 { kRedCodecName, 8000, 1, 127, false, { } }, |
513 { kDtmfCodecName, 8000, 1, 126, false, { } }, | 513 { kDtmfCodecName, 8000, 1, 126, false, { } }, |
514 }; | 514 }; |
515 } // namespace { | 515 } // namespace { |
516 | 516 |
517 bool WebRtcVoiceEngine::ToCodecInst(const AudioCodec& in, | 517 bool WebRtcVoiceEngine::ToCodecInst(const AudioCodec& in, |
518 webrtc::CodecInst* out) { | 518 webrtc::CodecInst* out) { |
519 return WebRtcVoiceCodecs::ToCodecInst(in, out); | 519 return WebRtcVoiceCodecs::ToCodecInst(in, out); |
520 } | 520 } |
521 | 521 |
522 WebRtcVoiceEngine::WebRtcVoiceEngine() | 522 WebRtcVoiceEngine::WebRtcVoiceEngine(webrtc::AudioDeviceModule* adm) |
523 : voe_wrapper_(new VoEWrapper()), | 523 : WebRtcVoiceEngine(adm, new VoEWrapper()) { |
524 audio_state_(webrtc::AudioState::Create(MakeAudioStateConfig(voe()))) { | 524 audio_state_ = webrtc::AudioState::Create(MakeAudioStateConfig(voe())); |
525 Construct(); | |
526 } | 525 } |
527 | 526 |
528 WebRtcVoiceEngine::WebRtcVoiceEngine(VoEWrapper* voe_wrapper) | 527 WebRtcVoiceEngine::WebRtcVoiceEngine(webrtc::AudioDeviceModule* adm, |
528 VoEWrapper* voe_wrapper) | |
529 : voe_wrapper_(voe_wrapper) { | 529 : voe_wrapper_(voe_wrapper) { |
530 Construct(); | |
531 } | |
532 | |
533 void WebRtcVoiceEngine::Construct() { | |
534 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 530 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
535 LOG(LS_VERBOSE) << "WebRtcVoiceEngine::WebRtcVoiceEngine"; | 531 LOG(LS_VERBOSE) << "WebRtcVoiceEngine::WebRtcVoiceEngine"; |
536 | 532 |
537 signal_thread_checker_.DetachFromThread(); | 533 signal_thread_checker_.DetachFromThread(); |
534 webrtc::Trace::SetTraceCallback(this); | |
538 std::memset(&default_agc_config_, 0, sizeof(default_agc_config_)); | 535 std::memset(&default_agc_config_, 0, sizeof(default_agc_config_)); |
539 voe_config_.Set<webrtc::VoicePacing>(new webrtc::VoicePacing(true)); | 536 adm_ = adm; |
540 | 537 if (adm_) { |
541 webrtc::Trace::set_level_filter(kDefaultTraceFilter); | 538 adm_->AddRef(); |
pthatcher1
2016/03/25 23:23:21
Should we use a scoped_refptr for adm_?
Taylor Brandstetter
2016/03/29 00:49:23
+1
the sun
2016/03/29 21:46:40
Done.
the sun
2016/03/29 21:46:40
Done.
| |
542 webrtc::Trace::SetTraceCallback(this); | 539 } |
543 | |
544 // Load our audio codec list. | |
545 codecs_ = WebRtcVoiceCodecs::SupportedCodecs(); | |
546 } | 540 } |
547 | 541 |
548 WebRtcVoiceEngine::~WebRtcVoiceEngine() { | 542 WebRtcVoiceEngine::~WebRtcVoiceEngine() { |
549 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 543 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
550 LOG(LS_VERBOSE) << "WebRtcVoiceEngine::~WebRtcVoiceEngine"; | 544 LOG(LS_VERBOSE) << "WebRtcVoiceEngine::~WebRtcVoiceEngine"; |
551 if (adm_) { | 545 if (adm_) { |
552 voe_wrapper_.reset(); | |
Taylor Brandstetter
2016/03/29 00:49:23
Is there a reason this was called here, and if so,
the sun
2016/03/29 21:46:40
Looks like it wasn't needed; VoE's ADM reference s
| |
553 adm_->Release(); | 546 adm_->Release(); |
554 adm_ = NULL; | |
555 } | 547 } |
556 webrtc::Trace::SetTraceCallback(nullptr); | 548 webrtc::Trace::SetTraceCallback(nullptr); |
557 } | 549 } |
558 | 550 |
559 bool WebRtcVoiceEngine::Init(rtc::Thread* worker_thread) { | 551 bool WebRtcVoiceEngine::Init() { |
560 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 552 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
561 RTC_DCHECK(worker_thread == rtc::Thread::Current()); | |
562 LOG(LS_INFO) << "WebRtcVoiceEngine::Init"; | 553 LOG(LS_INFO) << "WebRtcVoiceEngine::Init"; |
563 bool res = InitInternal(); | 554 LOG(LS_INFO) << webrtc::VoiceEngine::GetVersionString(); |
564 if (res) { | |
565 LOG(LS_INFO) << "WebRtcVoiceEngine::Init Done!"; | |
566 } else { | |
567 LOG(LS_ERROR) << "WebRtcVoiceEngine::Init failed"; | |
568 Terminate(); | |
569 } | |
570 return res; | |
571 } | |
572 | 555 |
573 bool WebRtcVoiceEngine::InitInternal() { | 556 voe_config_.Set<webrtc::VoicePacing>(new webrtc::VoicePacing(true)); |
574 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 557 |
575 // Temporarily turn logging level up for the Init call. | 558 // Temporarily turn logging level up for the Init call. |
576 webrtc::Trace::set_level_filter(kElevatedTraceFilter); | 559 webrtc::Trace::set_level_filter(kElevatedTraceFilter); |
577 LOG(LS_INFO) << webrtc::VoiceEngine::GetVersionString(); | |
578 if (voe_wrapper_->base()->Init(adm_) == -1) { | 560 if (voe_wrapper_->base()->Init(adm_) == -1) { |
579 LOG_RTCERR0_EX(Init, voe_wrapper_->error()); | 561 LOG_RTCERR0_EX(Init, voe_wrapper_->error()); |
580 return false; | 562 return false; |
581 } | 563 } |
582 webrtc::Trace::set_level_filter(kDefaultTraceFilter); | 564 webrtc::Trace::set_level_filter(kDefaultTraceFilter); |
583 | 565 |
566 // No ADM supplied? Get the default one from VoE. | |
567 if (!adm_) { | |
568 adm_ = voe_wrapper_->base()->audio_device_module(); | |
569 adm_->AddRef(); | |
570 } | |
571 RTC_DCHECK(adm_); | |
572 | |
584 // Save the default AGC configuration settings. This must happen before | 573 // Save the default AGC configuration settings. This must happen before |
585 // calling ApplyOptions or the default will be overwritten. | 574 // calling ApplyOptions or the default will be overwritten. |
586 if (voe_wrapper_->processing()->GetAgcConfig(default_agc_config_) == -1) { | 575 if (voe_wrapper_->processing()->GetAgcConfig(default_agc_config_) == -1) { |
587 LOG_RTCERR0(GetAgcConfig); | 576 LOG_RTCERR0(GetAgcConfig); |
588 return false; | 577 return false; |
589 } | 578 } |
590 | 579 |
591 // Set default engine options. | 580 // Set default engine options. |
592 { | 581 { |
593 AudioOptions options; | 582 AudioOptions options; |
594 options.echo_cancellation = rtc::Optional<bool>(true); | 583 options.echo_cancellation = rtc::Optional<bool>(true); |
595 options.auto_gain_control = rtc::Optional<bool>(true); | 584 options.auto_gain_control = rtc::Optional<bool>(true); |
596 options.noise_suppression = rtc::Optional<bool>(true); | 585 options.noise_suppression = rtc::Optional<bool>(true); |
597 options.highpass_filter = rtc::Optional<bool>(true); | 586 options.highpass_filter = rtc::Optional<bool>(true); |
598 options.stereo_swapping = rtc::Optional<bool>(false); | 587 options.stereo_swapping = rtc::Optional<bool>(false); |
599 options.audio_jitter_buffer_max_packets = rtc::Optional<int>(50); | 588 options.audio_jitter_buffer_max_packets = rtc::Optional<int>(50); |
600 options.audio_jitter_buffer_fast_accelerate = rtc::Optional<bool>(false); | 589 options.audio_jitter_buffer_fast_accelerate = rtc::Optional<bool>(false); |
601 options.typing_detection = rtc::Optional<bool>(true); | 590 options.typing_detection = rtc::Optional<bool>(true); |
602 options.adjust_agc_delta = rtc::Optional<int>(0); | 591 options.adjust_agc_delta = rtc::Optional<int>(0); |
603 options.experimental_agc = rtc::Optional<bool>(false); | 592 options.experimental_agc = rtc::Optional<bool>(false); |
604 options.extended_filter_aec = rtc::Optional<bool>(false); | 593 options.extended_filter_aec = rtc::Optional<bool>(false); |
605 options.delay_agnostic_aec = rtc::Optional<bool>(false); | 594 options.delay_agnostic_aec = rtc::Optional<bool>(false); |
606 options.experimental_ns = rtc::Optional<bool>(false); | 595 options.experimental_ns = rtc::Optional<bool>(false); |
607 if (!ApplyOptions(options)) { | 596 if (!ApplyOptions(options)) { |
608 return false; | 597 return false; |
609 } | 598 } |
610 } | 599 } |
611 | 600 |
612 // Print our codec list again for the call diagnostic log. | 601 // Print our codec list again for the call diagnostic log. |
613 LOG(LS_INFO) << "WebRtc VoiceEngine codecs:"; | 602 LOG(LS_INFO) << "Supported codecs in order of preference:"; |
603 codecs_ = WebRtcVoiceCodecs::SupportedCodecs(); | |
614 for (const AudioCodec& codec : codecs_) { | 604 for (const AudioCodec& codec : codecs_) { |
615 LOG(LS_INFO) << ToString(codec); | 605 LOG(LS_INFO) << ToString(codec); |
616 } | 606 } |
617 | 607 |
618 SetDefaultDevices(); | 608 SetDefaultDevices(); |
619 | 609 |
620 initialized_ = true; | 610 LOG(LS_INFO) << "WebRtcVoiceEngine::Init Done!"; |
621 return true; | 611 return true; |
622 } | 612 } |
623 | 613 |
624 void WebRtcVoiceEngine::Terminate() { | 614 void WebRtcVoiceEngine::Terminate() { |
625 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 615 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
626 LOG(LS_INFO) << "WebRtcVoiceEngine::Terminate"; | 616 LOG(LS_INFO) << "WebRtcVoiceEngine::Terminate"; |
627 initialized_ = false; | |
628 | |
629 StopAecDump(); | 617 StopAecDump(); |
630 | |
631 voe_wrapper_->base()->Terminate(); | 618 voe_wrapper_->base()->Terminate(); |
632 } | 619 } |
633 | 620 |
634 rtc::scoped_refptr<webrtc::AudioState> | 621 rtc::scoped_refptr<webrtc::AudioState> |
635 WebRtcVoiceEngine::GetAudioState() const { | 622 WebRtcVoiceEngine::GetAudioState() const { |
636 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 623 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
637 return audio_state_; | 624 return audio_state_; |
638 } | 625 } |
639 | 626 |
640 VoiceMediaChannel* WebRtcVoiceEngine::CreateChannel( | 627 VoiceMediaChannel* WebRtcVoiceEngine::CreateChannel( |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1045 << default_agc_config_.targetLeveldBOv << "dB to -" | 1032 << default_agc_config_.targetLeveldBOv << "dB to -" |
1046 << config.targetLeveldBOv << "dB"; | 1033 << config.targetLeveldBOv << "dB"; |
1047 | 1034 |
1048 if (voe_wrapper_->processing()->SetAgcConfig(config) == -1) { | 1035 if (voe_wrapper_->processing()->SetAgcConfig(config) == -1) { |
1049 LOG_RTCERR1(SetAgcConfig, config.targetLeveldBOv); | 1036 LOG_RTCERR1(SetAgcConfig, config.targetLeveldBOv); |
1050 return false; | 1037 return false; |
1051 } | 1038 } |
1052 return true; | 1039 return true; |
1053 } | 1040 } |
1054 | 1041 |
1055 bool WebRtcVoiceEngine::SetAudioDeviceModule(webrtc::AudioDeviceModule* adm) { | |
1056 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | |
1057 if (initialized_) { | |
1058 LOG(LS_WARNING) << "SetAudioDeviceModule can not be called after Init."; | |
1059 return false; | |
1060 } | |
1061 if (adm_) { | |
1062 adm_->Release(); | |
1063 adm_ = NULL; | |
1064 } | |
1065 if (adm) { | |
1066 adm_ = adm; | |
1067 adm_->AddRef(); | |
1068 } | |
1069 return true; | |
1070 } | |
1071 | |
1072 bool WebRtcVoiceEngine::StartAecDump(rtc::PlatformFile file, | 1042 bool WebRtcVoiceEngine::StartAecDump(rtc::PlatformFile file, |
1073 int64_t max_size_bytes) { | 1043 int64_t max_size_bytes) { |
1074 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1044 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
1075 FILE* aec_dump_file_stream = rtc::FdopenPlatformFileForWriting(file); | 1045 FILE* aec_dump_file_stream = rtc::FdopenPlatformFileForWriting(file); |
1076 if (!aec_dump_file_stream) { | 1046 if (!aec_dump_file_stream) { |
1077 LOG(LS_ERROR) << "Could not open AEC dump file stream."; | 1047 LOG(LS_ERROR) << "Could not open AEC dump file stream."; |
1078 if (!rtc::ClosePlatformFile(file)) | 1048 if (!rtc::ClosePlatformFile(file)) |
1079 LOG(LS_WARNING) << "Could not close file."; | 1049 LOG(LS_WARNING) << "Could not close file."; |
1080 return false; | 1050 return false; |
1081 } | 1051 } |
(...skipping 1466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2548 } | 2518 } |
2549 } else { | 2519 } else { |
2550 LOG(LS_INFO) << "Stopping playout for channel #" << channel; | 2520 LOG(LS_INFO) << "Stopping playout for channel #" << channel; |
2551 engine()->voe()->base()->StopPlayout(channel); | 2521 engine()->voe()->base()->StopPlayout(channel); |
2552 } | 2522 } |
2553 return true; | 2523 return true; |
2554 } | 2524 } |
2555 } // namespace cricket | 2525 } // namespace cricket |
2556 | 2526 |
2557 #endif // HAVE_WEBRTC_VOICE | 2527 #endif // HAVE_WEBRTC_VOICE |
OLD | NEW |