| OLD | NEW |
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2004 Google Inc. | 3 * Copyright 2004 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 static std::string GetEnableString(bool enable) { | 362 static std::string GetEnableString(bool enable) { |
| 363 return enable ? "enable" : "disable"; | 363 return enable ? "enable" : "disable"; |
| 364 } | 364 } |
| 365 | 365 |
| 366 WebRtcVoiceEngine::WebRtcVoiceEngine() | 366 WebRtcVoiceEngine::WebRtcVoiceEngine() |
| 367 : voe_wrapper_(new VoEWrapper()), | 367 : voe_wrapper_(new VoEWrapper()), |
| 368 tracing_(new VoETraceWrapper()), | 368 tracing_(new VoETraceWrapper()), |
| 369 adm_(NULL), | 369 adm_(NULL), |
| 370 log_filter_(SeverityToFilter(kDefaultLogSeverity)), | 370 log_filter_(SeverityToFilter(kDefaultLogSeverity)), |
| 371 is_dumping_aec_(false), | 371 is_dumping_aec_(false), |
| 372 desired_local_monitor_enable_(false), | |
| 373 tx_processor_ssrc_(0), | 372 tx_processor_ssrc_(0), |
| 374 rx_processor_ssrc_(0) { | 373 rx_processor_ssrc_(0) { |
| 375 Construct(); | 374 Construct(); |
| 376 } | 375 } |
| 377 | 376 |
| 378 WebRtcVoiceEngine::WebRtcVoiceEngine(VoEWrapper* voe_wrapper, | 377 WebRtcVoiceEngine::WebRtcVoiceEngine(VoEWrapper* voe_wrapper, |
| 379 VoETraceWrapper* tracing) | 378 VoETraceWrapper* tracing) |
| 380 : voe_wrapper_(voe_wrapper), | 379 : voe_wrapper_(voe_wrapper), |
| 381 tracing_(tracing), | 380 tracing_(tracing), |
| 382 adm_(NULL), | 381 adm_(NULL), |
| 383 log_filter_(SeverityToFilter(kDefaultLogSeverity)), | 382 log_filter_(SeverityToFilter(kDefaultLogSeverity)), |
| 384 is_dumping_aec_(false), | 383 is_dumping_aec_(false), |
| 385 desired_local_monitor_enable_(false), | |
| 386 tx_processor_ssrc_(0), | 384 tx_processor_ssrc_(0), |
| 387 rx_processor_ssrc_(0) { | 385 rx_processor_ssrc_(0) { |
| 388 Construct(); | 386 Construct(); |
| 389 } | 387 } |
| 390 | 388 |
| 391 void WebRtcVoiceEngine::Construct() { | 389 void WebRtcVoiceEngine::Construct() { |
| 392 SetTraceFilter(log_filter_); | 390 SetTraceFilter(log_filter_); |
| 393 initialized_ = false; | 391 initialized_ = false; |
| 394 LOG(LS_VERBOSE) << "WebRtcVoiceEngine::WebRtcVoiceEngine"; | 392 LOG(LS_VERBOSE) << "WebRtcVoiceEngine::WebRtcVoiceEngine"; |
| 395 SetTraceOptions(""); | 393 SetTraceOptions(""); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 return true; | 563 return true; |
| 566 } | 564 } |
| 567 | 565 |
| 568 void WebRtcVoiceEngine::Terminate() { | 566 void WebRtcVoiceEngine::Terminate() { |
| 569 LOG(LS_INFO) << "WebRtcVoiceEngine::Terminate"; | 567 LOG(LS_INFO) << "WebRtcVoiceEngine::Terminate"; |
| 570 initialized_ = false; | 568 initialized_ = false; |
| 571 | 569 |
| 572 StopAecDump(); | 570 StopAecDump(); |
| 573 | 571 |
| 574 voe_wrapper_->base()->Terminate(); | 572 voe_wrapper_->base()->Terminate(); |
| 575 desired_local_monitor_enable_ = false; | |
| 576 } | 573 } |
| 577 | 574 |
| 578 int WebRtcVoiceEngine::GetCapabilities() { | 575 int WebRtcVoiceEngine::GetCapabilities() { |
| 579 return AUDIO_SEND | AUDIO_RECV; | 576 return AUDIO_SEND | AUDIO_RECV; |
| 580 } | 577 } |
| 581 | 578 |
| 582 VoiceMediaChannel* WebRtcVoiceEngine::CreateChannel(webrtc::Call* call, | 579 VoiceMediaChannel* WebRtcVoiceEngine::CreateChannel(webrtc::Call* call, |
| 583 const AudioOptions& options) { | 580 const AudioOptions& options) { |
| 584 WebRtcVoiceMediaChannel* ch = | 581 WebRtcVoiceMediaChannel* ch = |
| 585 new WebRtcVoiceMediaChannel(this, options, call); | 582 new WebRtcVoiceMediaChannel(this, options, call); |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 926 #endif | 923 #endif |
| 927 | 924 |
| 928 std::string in_name = (in_id != kDefaultAudioDeviceId) ? | 925 std::string in_name = (in_id != kDefaultAudioDeviceId) ? |
| 929 in_device->name : "Default device"; | 926 in_device->name : "Default device"; |
| 930 std::string out_name = (out_id != kDefaultAudioDeviceId) ? | 927 std::string out_name = (out_id != kDefaultAudioDeviceId) ? |
| 931 out_device->name : "Default device"; | 928 out_device->name : "Default device"; |
| 932 LOG(LS_INFO) << "Setting microphone to (id=" << in_id << ", name=" << in_name | 929 LOG(LS_INFO) << "Setting microphone to (id=" << in_id << ", name=" << in_name |
| 933 << ") and speaker to (id=" << out_id << ", name=" << out_name | 930 << ") and speaker to (id=" << out_id << ", name=" << out_name |
| 934 << ")"; | 931 << ")"; |
| 935 | 932 |
| 936 // If we're running the local monitor, we need to stop it first. | 933 // Must also pause all audio playback and capture. |
| 937 bool ret = true; | 934 bool ret = true; |
| 938 if (!PauseLocalMonitor()) { | |
| 939 LOG(LS_WARNING) << "Failed to pause local monitor"; | |
| 940 ret = false; | |
| 941 } | |
| 942 | |
| 943 // Must also pause all audio playback and capture. | |
| 944 for (WebRtcVoiceMediaChannel* channel : channels_) { | 935 for (WebRtcVoiceMediaChannel* channel : channels_) { |
| 945 if (!channel->PausePlayout()) { | 936 if (!channel->PausePlayout()) { |
| 946 LOG(LS_WARNING) << "Failed to pause playout"; | 937 LOG(LS_WARNING) << "Failed to pause playout"; |
| 947 ret = false; | 938 ret = false; |
| 948 } | 939 } |
| 949 if (!channel->PauseSend()) { | 940 if (!channel->PauseSend()) { |
| 950 LOG(LS_WARNING) << "Failed to pause send"; | 941 LOG(LS_WARNING) << "Failed to pause send"; |
| 951 ret = false; | 942 ret = false; |
| 952 } | 943 } |
| 953 } | 944 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 983 if (!channel->ResumePlayout()) { | 974 if (!channel->ResumePlayout()) { |
| 984 LOG(LS_WARNING) << "Failed to resume playout"; | 975 LOG(LS_WARNING) << "Failed to resume playout"; |
| 985 ret = false; | 976 ret = false; |
| 986 } | 977 } |
| 987 if (!channel->ResumeSend()) { | 978 if (!channel->ResumeSend()) { |
| 988 LOG(LS_WARNING) << "Failed to resume send"; | 979 LOG(LS_WARNING) << "Failed to resume send"; |
| 989 ret = false; | 980 ret = false; |
| 990 } | 981 } |
| 991 } | 982 } |
| 992 | 983 |
| 993 // Resume local monitor. | |
| 994 if (!ResumeLocalMonitor()) { | |
| 995 LOG(LS_WARNING) << "Failed to resume local monitor"; | |
| 996 ret = false; | |
| 997 } | |
| 998 | |
| 999 if (ret) { | 984 if (ret) { |
| 1000 LOG(LS_INFO) << "Set microphone to (id=" << in_id <<" name=" << in_name | 985 LOG(LS_INFO) << "Set microphone to (id=" << in_id <<" name=" << in_name |
| 1001 << ") and speaker to (id="<< out_id << " name=" << out_name | 986 << ") and speaker to (id="<< out_id << " name=" << out_name |
| 1002 << ")"; | 987 << ")"; |
| 1003 } | 988 } |
| 1004 | 989 |
| 1005 return ret; | 990 return ret; |
| 1006 #else | 991 #else |
| 1007 return true; | 992 return true; |
| 1008 #endif // !IOS | 993 #endif // !IOS |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1076 } | 1061 } |
| 1077 return true; | 1062 return true; |
| 1078 } | 1063 } |
| 1079 | 1064 |
| 1080 int WebRtcVoiceEngine::GetInputLevel() { | 1065 int WebRtcVoiceEngine::GetInputLevel() { |
| 1081 unsigned int ulevel; | 1066 unsigned int ulevel; |
| 1082 return (voe_wrapper_->volume()->GetSpeechInputLevel(ulevel) != -1) ? | 1067 return (voe_wrapper_->volume()->GetSpeechInputLevel(ulevel) != -1) ? |
| 1083 static_cast<int>(ulevel) : -1; | 1068 static_cast<int>(ulevel) : -1; |
| 1084 } | 1069 } |
| 1085 | 1070 |
| 1086 bool WebRtcVoiceEngine::SetLocalMonitor(bool enable) { | |
| 1087 desired_local_monitor_enable_ = enable; | |
| 1088 return ChangeLocalMonitor(desired_local_monitor_enable_); | |
| 1089 } | |
| 1090 | |
| 1091 bool WebRtcVoiceEngine::ChangeLocalMonitor(bool enable) { | |
| 1092 // The voe file api is not available in chrome. | |
| 1093 if (!voe_wrapper_->file()) { | |
| 1094 return false; | |
| 1095 } | |
| 1096 if (enable && !monitor_) { | |
| 1097 monitor_.reset(new WebRtcMonitorStream); | |
| 1098 if (voe_wrapper_->file()->StartRecordingMicrophone(monitor_.get()) == -1) { | |
| 1099 LOG_RTCERR1(StartRecordingMicrophone, monitor_.get()); | |
| 1100 // Must call Stop() because there are some cases where Start will report | |
| 1101 // failure but still change the state, and if we leave VE in the on state | |
| 1102 // then it could crash later when trying to invoke methods on our monitor. | |
| 1103 voe_wrapper_->file()->StopRecordingMicrophone(); | |
| 1104 monitor_.reset(); | |
| 1105 return false; | |
| 1106 } | |
| 1107 } else if (!enable && monitor_) { | |
| 1108 voe_wrapper_->file()->StopRecordingMicrophone(); | |
| 1109 monitor_.reset(); | |
| 1110 } | |
| 1111 return true; | |
| 1112 } | |
| 1113 | |
| 1114 bool WebRtcVoiceEngine::PauseLocalMonitor() { | |
| 1115 return ChangeLocalMonitor(false); | |
| 1116 } | |
| 1117 | |
| 1118 bool WebRtcVoiceEngine::ResumeLocalMonitor() { | |
| 1119 return ChangeLocalMonitor(desired_local_monitor_enable_); | |
| 1120 } | |
| 1121 | |
| 1122 const std::vector<AudioCodec>& WebRtcVoiceEngine::codecs() { | 1071 const std::vector<AudioCodec>& WebRtcVoiceEngine::codecs() { |
| 1123 return codecs_; | 1072 return codecs_; |
| 1124 } | 1073 } |
| 1125 | 1074 |
| 1126 bool WebRtcVoiceEngine::FindCodec(const AudioCodec& in) { | 1075 bool WebRtcVoiceEngine::FindCodec(const AudioCodec& in) { |
| 1127 return FindWebRtcCodec(in, NULL); | 1076 return FindWebRtcCodec(in, NULL); |
| 1128 } | 1077 } |
| 1129 | 1078 |
| 1130 // Get the VoiceEngine codec that matches |in|, with the supplied settings. | 1079 // Get the VoiceEngine codec that matches |in|, with the supplied settings. |
| 1131 bool WebRtcVoiceEngine::FindWebRtcCodec(const AudioCodec& in, | 1080 bool WebRtcVoiceEngine::FindWebRtcCodec(const AudioCodec& in, |
| (...skipping 2418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3550 LOG(LS_WARNING) << "Unknown codec " << ToString(codec); | 3499 LOG(LS_WARNING) << "Unknown codec " << ToString(codec); |
| 3551 return false; | 3500 return false; |
| 3552 } | 3501 } |
| 3553 } | 3502 } |
| 3554 return true; | 3503 return true; |
| 3555 } | 3504 } |
| 3556 | 3505 |
| 3557 } // namespace cricket | 3506 } // namespace cricket |
| 3558 | 3507 |
| 3559 #endif // HAVE_WEBRTC_VOICE | 3508 #endif // HAVE_WEBRTC_VOICE |
| OLD | NEW |