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 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 RTC_CHECK_EQ(0, voe_wrapper_->base()->Init(adm_.get(), nullptr, | 546 RTC_CHECK_EQ(0, voe_wrapper_->base()->Init(adm_.get(), nullptr, |
547 decoder_factory_)); | 547 decoder_factory_)); |
548 webrtc::Trace::set_level_filter(kDefaultTraceFilter); | 548 webrtc::Trace::set_level_filter(kDefaultTraceFilter); |
549 | 549 |
550 // No ADM supplied? Get the default one from VoE. | 550 // No ADM supplied? Get the default one from VoE. |
551 if (!adm_) { | 551 if (!adm_) { |
552 adm_ = voe_wrapper_->base()->audio_device_module(); | 552 adm_ = voe_wrapper_->base()->audio_device_module(); |
553 } | 553 } |
554 RTC_DCHECK(adm_); | 554 RTC_DCHECK(adm_); |
555 | 555 |
| 556 apm_ = voe_wrapper_->base()->audio_processing(); |
| 557 RTC_DCHECK(apm_); |
| 558 |
556 // Save the default AGC configuration settings. This must happen before | 559 // Save the default AGC configuration settings. This must happen before |
557 // calling ApplyOptions or the default will be overwritten. | 560 // calling ApplyOptions or the default will be overwritten. |
558 int error = voe_wrapper_->processing()->GetAgcConfig(default_agc_config_); | 561 int error = voe_wrapper_->processing()->GetAgcConfig(default_agc_config_); |
559 RTC_DCHECK_EQ(0, error); | 562 RTC_DCHECK_EQ(0, error); |
560 | 563 |
561 // Set default engine options. | 564 // Set default engine options. |
562 { | 565 { |
563 AudioOptions options; | 566 AudioOptions options; |
564 options.echo_cancellation = rtc::Optional<bool>(true); | 567 options.echo_cancellation = rtc::Optional<bool>(true); |
565 options.auto_gain_control = rtc::Optional<bool>(true); | 568 options.auto_gain_control = rtc::Optional<bool>(true); |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 << (!!level_control_ ? *level_control_ : -1); | 873 << (!!level_control_ ? *level_control_ : -1); |
871 webrtc::AudioProcessing::Config apm_config; | 874 webrtc::AudioProcessing::Config apm_config; |
872 if (level_control_) { | 875 if (level_control_) { |
873 apm_config.level_controller.enabled = *level_control_; | 876 apm_config.level_controller.enabled = *level_control_; |
874 if (options.level_control_initial_peak_level_dbfs) { | 877 if (options.level_control_initial_peak_level_dbfs) { |
875 apm_config.level_controller.initial_peak_level_dbfs = | 878 apm_config.level_controller.initial_peak_level_dbfs = |
876 *options.level_control_initial_peak_level_dbfs; | 879 *options.level_control_initial_peak_level_dbfs; |
877 } | 880 } |
878 } | 881 } |
879 | 882 |
880 // We check audioproc for the benefit of tests, since FakeWebRtcVoiceEngine | 883 apm()->SetExtraOptions(config); |
881 // returns NULL on audio_processing(). | 884 apm()->ApplyConfig(apm_config); |
882 webrtc::AudioProcessing* audioproc = voe_wrapper_->base()->audio_processing(); | |
883 if (audioproc) { | |
884 audioproc->SetExtraOptions(config); | |
885 audioproc->ApplyConfig(apm_config); | |
886 } | |
887 | 885 |
888 if (options.recording_sample_rate) { | 886 if (options.recording_sample_rate) { |
889 LOG(LS_INFO) << "Recording sample rate is " | 887 LOG(LS_INFO) << "Recording sample rate is " |
890 << *options.recording_sample_rate; | 888 << *options.recording_sample_rate; |
891 if (adm()->SetRecordingSampleRate(*options.recording_sample_rate)) { | 889 if (adm()->SetRecordingSampleRate(*options.recording_sample_rate)) { |
892 LOG_RTCERR1(SetRecordingSampleRate, *options.recording_sample_rate); | 890 LOG_RTCERR1(SetRecordingSampleRate, *options.recording_sample_rate); |
893 } | 891 } |
894 } | 892 } |
895 | 893 |
896 if (options.playout_sample_rate) { | 894 if (options.playout_sample_rate) { |
(...skipping 12 matching lines...) Expand all Loading... |
909 int in_id = kDefaultAudioDeviceId; | 907 int in_id = kDefaultAudioDeviceId; |
910 int out_id = kDefaultAudioDeviceId; | 908 int out_id = kDefaultAudioDeviceId; |
911 LOG(LS_INFO) << "Setting microphone to (id=" << in_id | 909 LOG(LS_INFO) << "Setting microphone to (id=" << in_id |
912 << ") and speaker to (id=" << out_id << ")"; | 910 << ") and speaker to (id=" << out_id << ")"; |
913 | 911 |
914 bool ret = true; | 912 bool ret = true; |
915 if (voe_wrapper_->hw()->SetRecordingDevice(in_id) == -1) { | 913 if (voe_wrapper_->hw()->SetRecordingDevice(in_id) == -1) { |
916 LOG_RTCERR1(SetRecordingDevice, in_id); | 914 LOG_RTCERR1(SetRecordingDevice, in_id); |
917 ret = false; | 915 ret = false; |
918 } | 916 } |
919 webrtc::AudioProcessing* ap = voe()->base()->audio_processing(); | 917 |
920 if (ap) { | 918 apm()->Initialize(); |
921 ap->Initialize(); | |
922 } | |
923 | 919 |
924 if (voe_wrapper_->hw()->SetPlayoutDevice(out_id) == -1) { | 920 if (voe_wrapper_->hw()->SetPlayoutDevice(out_id) == -1) { |
925 LOG_RTCERR1(SetPlayoutDevice, out_id); | 921 LOG_RTCERR1(SetPlayoutDevice, out_id); |
926 ret = false; | 922 ret = false; |
927 } | 923 } |
928 | 924 |
929 if (ret) { | 925 if (ret) { |
930 LOG(LS_INFO) << "Set microphone to (id=" << in_id | 926 LOG(LS_INFO) << "Set microphone to (id=" << in_id |
931 << ") and speaker to (id=" << out_id << ")"; | 927 << ") and speaker to (id=" << out_id << ")"; |
932 } | 928 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 int64_t max_size_bytes) { | 1029 int64_t max_size_bytes) { |
1034 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1030 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
1035 FILE* aec_dump_file_stream = rtc::FdopenPlatformFileForWriting(file); | 1031 FILE* aec_dump_file_stream = rtc::FdopenPlatformFileForWriting(file); |
1036 if (!aec_dump_file_stream) { | 1032 if (!aec_dump_file_stream) { |
1037 LOG(LS_ERROR) << "Could not open AEC dump file stream."; | 1033 LOG(LS_ERROR) << "Could not open AEC dump file stream."; |
1038 if (!rtc::ClosePlatformFile(file)) | 1034 if (!rtc::ClosePlatformFile(file)) |
1039 LOG(LS_WARNING) << "Could not close file."; | 1035 LOG(LS_WARNING) << "Could not close file."; |
1040 return false; | 1036 return false; |
1041 } | 1037 } |
1042 StopAecDump(); | 1038 StopAecDump(); |
1043 if (voe_wrapper_->base()->audio_processing()->StartDebugRecording( | 1039 if (apm()->StartDebugRecording(aec_dump_file_stream, max_size_bytes) != |
1044 aec_dump_file_stream, max_size_bytes) != | |
1045 webrtc::AudioProcessing::kNoError) { | 1040 webrtc::AudioProcessing::kNoError) { |
1046 LOG_RTCERR0(StartDebugRecording); | 1041 LOG_RTCERR0(StartDebugRecording); |
1047 fclose(aec_dump_file_stream); | 1042 fclose(aec_dump_file_stream); |
1048 return false; | 1043 return false; |
1049 } | 1044 } |
1050 is_dumping_aec_ = true; | 1045 is_dumping_aec_ = true; |
1051 return true; | 1046 return true; |
1052 } | 1047 } |
1053 | 1048 |
1054 void WebRtcVoiceEngine::StartAecDump(const std::string& filename) { | 1049 void WebRtcVoiceEngine::StartAecDump(const std::string& filename) { |
1055 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1050 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
1056 if (!is_dumping_aec_) { | 1051 if (!is_dumping_aec_) { |
1057 // Start dumping AEC when we are not dumping. | 1052 // Start dumping AEC when we are not dumping. |
1058 if (voe_wrapper_->base()->audio_processing()->StartDebugRecording( | 1053 if (apm()->StartDebugRecording(filename.c_str(), -1) != |
1059 filename.c_str(), -1) != webrtc::AudioProcessing::kNoError) { | 1054 webrtc::AudioProcessing::kNoError) { |
1060 LOG_RTCERR1(StartDebugRecording, filename.c_str()); | 1055 LOG_RTCERR1(StartDebugRecording, filename.c_str()); |
1061 } else { | 1056 } else { |
1062 is_dumping_aec_ = true; | 1057 is_dumping_aec_ = true; |
1063 } | 1058 } |
1064 } | 1059 } |
1065 } | 1060 } |
1066 | 1061 |
1067 void WebRtcVoiceEngine::StopAecDump() { | 1062 void WebRtcVoiceEngine::StopAecDump() { |
1068 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1063 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
1069 if (is_dumping_aec_) { | 1064 if (is_dumping_aec_) { |
1070 // Stop dumping AEC when we are dumping. | 1065 // Stop dumping AEC when we are dumping. |
1071 if (voe_wrapper_->base()->audio_processing()->StopDebugRecording() != | 1066 if (apm()->StopDebugRecording() != webrtc::AudioProcessing::kNoError) { |
1072 webrtc::AudioProcessing::kNoError) { | |
1073 LOG_RTCERR0(StopDebugRecording); | 1067 LOG_RTCERR0(StopDebugRecording); |
1074 } | 1068 } |
1075 is_dumping_aec_ = false; | 1069 is_dumping_aec_ = false; |
1076 } | 1070 } |
1077 } | 1071 } |
1078 | 1072 |
1079 int WebRtcVoiceEngine::CreateVoEChannel() { | 1073 int WebRtcVoiceEngine::CreateVoEChannel() { |
1080 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1074 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
1081 return voe_wrapper_->base()->CreateChannel(channel_config_); | 1075 return voe_wrapper_->base()->CreateChannel(channel_config_); |
1082 } | 1076 } |
1083 | 1077 |
1084 webrtc::AudioDeviceModule* WebRtcVoiceEngine::adm() { | 1078 webrtc::AudioDeviceModule* WebRtcVoiceEngine::adm() { |
1085 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1079 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
1086 RTC_DCHECK(adm_); | 1080 RTC_DCHECK(adm_); |
1087 return adm_; | 1081 return adm_; |
1088 } | 1082 } |
1089 | 1083 |
| 1084 webrtc::AudioProcessing* WebRtcVoiceEngine::apm() { |
| 1085 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 1086 RTC_DCHECK(apm_); |
| 1087 return apm_; |
| 1088 } |
| 1089 |
1090 AudioCodecs WebRtcVoiceEngine::CollectRecvCodecs() const { | 1090 AudioCodecs WebRtcVoiceEngine::CollectRecvCodecs() const { |
1091 PayloadTypeMapper mapper; | 1091 PayloadTypeMapper mapper; |
1092 AudioCodecs out; | 1092 AudioCodecs out; |
1093 const std::vector<webrtc::AudioCodecSpec>& specs = | 1093 const std::vector<webrtc::AudioCodecSpec>& specs = |
1094 decoder_factory_->GetSupportedDecoders(); | 1094 decoder_factory_->GetSupportedDecoders(); |
1095 | 1095 |
1096 // Only generate CN payload types for these clockrates | 1096 // Only generate CN payload types for these clockrates |
1097 std::map<int, bool, std::greater<int>> generate_cn = {{ 8000, false }, | 1097 std::map<int, bool, std::greater<int>> generate_cn = {{ 8000, false }, |
1098 { 16000, false }, | 1098 { 16000, false }, |
1099 { 32000, false }}; | 1099 { 32000, false }}; |
(...skipping 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2371 | 2371 |
2372 // TODO(solenberg): | 2372 // TODO(solenberg): |
2373 // We set the AGC to mute state only when all the channels are muted. | 2373 // We set the AGC to mute state only when all the channels are muted. |
2374 // This implementation is not ideal, instead we should signal the AGC when | 2374 // This implementation is not ideal, instead we should signal the AGC when |
2375 // the mic channel is muted/unmuted. We can't do it today because there | 2375 // the mic channel is muted/unmuted. We can't do it today because there |
2376 // is no good way to know which stream is mapping to the mic channel. | 2376 // is no good way to know which stream is mapping to the mic channel. |
2377 bool all_muted = muted; | 2377 bool all_muted = muted; |
2378 for (const auto& kv : send_streams_) { | 2378 for (const auto& kv : send_streams_) { |
2379 all_muted = all_muted && kv.second->muted(); | 2379 all_muted = all_muted && kv.second->muted(); |
2380 } | 2380 } |
| 2381 engine()->apm()->set_output_will_be_muted(all_muted); |
2381 | 2382 |
2382 webrtc::AudioProcessing* ap = engine()->voe()->base()->audio_processing(); | |
2383 if (ap) { | |
2384 ap->set_output_will_be_muted(all_muted); | |
2385 } | |
2386 return true; | 2383 return true; |
2387 } | 2384 } |
2388 | 2385 |
2389 bool WebRtcVoiceMediaChannel::SetMaxSendBitrate(int bps) { | 2386 bool WebRtcVoiceMediaChannel::SetMaxSendBitrate(int bps) { |
2390 LOG(LS_INFO) << "WebRtcVoiceMediaChannel::SetMaxSendBitrate."; | 2387 LOG(LS_INFO) << "WebRtcVoiceMediaChannel::SetMaxSendBitrate."; |
2391 max_send_bitrate_bps_ = bps; | 2388 max_send_bitrate_bps_ = bps; |
2392 bool success = true; | 2389 bool success = true; |
2393 for (const auto& kv : send_streams_) { | 2390 for (const auto& kv : send_streams_) { |
2394 if (!kv.second->SetMaxSendBitrate(max_send_bitrate_bps_)) { | 2391 if (!kv.second->SetMaxSendBitrate(max_send_bitrate_bps_)) { |
2395 success = false; | 2392 success = false; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2515 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 2512 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
2516 const auto it = send_streams_.find(ssrc); | 2513 const auto it = send_streams_.find(ssrc); |
2517 if (it != send_streams_.end()) { | 2514 if (it != send_streams_.end()) { |
2518 return it->second->channel(); | 2515 return it->second->channel(); |
2519 } | 2516 } |
2520 return -1; | 2517 return -1; |
2521 } | 2518 } |
2522 } // namespace cricket | 2519 } // namespace cricket |
2523 | 2520 |
2524 #endif // HAVE_WEBRTC_VOICE | 2521 #endif // HAVE_WEBRTC_VOICE |
OLD | NEW |