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

Side by Side Diff: talk/media/webrtc/webrtcvoiceengine.cc

Issue 1364753002: Simplify handling of options in WebRtcVoiceMediaEngine. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 3 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 | « talk/media/webrtc/webrtcvoiceengine.h ('k') | no next file » | 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 * 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 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 } 579 }
580 580
581 bool WebRtcVoiceEngine::SetOptions(const AudioOptions& options) { 581 bool WebRtcVoiceEngine::SetOptions(const AudioOptions& options) {
582 if (!ApplyOptions(options)) { 582 if (!ApplyOptions(options)) {
583 return false; 583 return false;
584 } 584 }
585 options_ = options; 585 options_ = options;
586 return true; 586 return true;
587 } 587 }
588 588
589 bool WebRtcVoiceEngine::SetOptionOverrides(const AudioOptions& overrides) {
590 LOG(LS_INFO) << "Setting option overrides: " << overrides.ToString();
591 if (!ApplyOptions(overrides)) {
592 return false;
593 }
594 option_overrides_ = overrides;
595 return true;
596 }
597
598 bool WebRtcVoiceEngine::ClearOptionOverrides() {
599 LOG(LS_INFO) << "Clearing option overrides.";
600 AudioOptions options = options_;
601 // Only call ApplyOptions if |options_overrides_| contains overrided options.
602 // ApplyOptions affects NS, AGC other options that is shared between
603 // all WebRtcVoiceEngineChannels.
604 if (option_overrides_ == AudioOptions()) {
605 return true;
606 }
607
608 if (!ApplyOptions(options)) {
609 return false;
610 }
611 option_overrides_ = AudioOptions();
612 return true;
613 }
614
615 // AudioOptions defaults are set in InitInternal (for options with corresponding 589 // AudioOptions defaults are set in InitInternal (for options with corresponding
616 // MediaEngineInterface flags) and in SetOptions(int) for flagless options. 590 // MediaEngineInterface flags) and in SetOptions(int) for flagless options.
617 bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) { 591 bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) {
618 AudioOptions options = options_in; // The options are modified below. 592 AudioOptions options = options_in; // The options are modified below.
619 // kEcConference is AEC with high suppression. 593 // kEcConference is AEC with high suppression.
620 webrtc::EcModes ec_mode = webrtc::kEcConference; 594 webrtc::EcModes ec_mode = webrtc::kEcConference;
621 webrtc::AecmModes aecm_mode = webrtc::kAecmSpeakerphone; 595 webrtc::AecmModes aecm_mode = webrtc::kAecmSpeakerphone;
622 webrtc::AgcModes agc_mode = webrtc::kAgcAdaptiveAnalog; 596 webrtc::AgcModes agc_mode = webrtc::kAgcAdaptiveAnalog;
623 webrtc::NsModes ns_mode = webrtc::kNsHighSuppression; 597 webrtc::NsModes ns_mode = webrtc::kNsHighSuppression;
624 bool aecm_comfort_noise = false; 598 bool aecm_comfort_noise = false;
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after
1238 return false; 1212 return false;
1239 } 1213 }
1240 1214
1241 void WebRtcVoiceEngine::RegisterChannel(WebRtcVoiceMediaChannel *channel) { 1215 void WebRtcVoiceEngine::RegisterChannel(WebRtcVoiceMediaChannel *channel) {
1242 rtc::CritScope lock(&channels_cs_); 1216 rtc::CritScope lock(&channels_cs_);
1243 channels_.push_back(channel); 1217 channels_.push_back(channel);
1244 } 1218 }
1245 1219
1246 void WebRtcVoiceEngine::UnregisterChannel(WebRtcVoiceMediaChannel *channel) { 1220 void WebRtcVoiceEngine::UnregisterChannel(WebRtcVoiceMediaChannel *channel) {
1247 rtc::CritScope lock(&channels_cs_); 1221 rtc::CritScope lock(&channels_cs_);
1248 ChannelList::iterator i = std::find(channels_.begin(), 1222 auto i = std::find(channels_.begin(), channels_.end(), channel);
pbos-webrtc 2015/09/23 13:41:34 s/i/it/
the sun 2015/09/23 15:11:28 Done.
1249 channels_.end(),
1250 channel);
1251 if (i != channels_.end()) { 1223 if (i != channels_.end()) {
1252 channels_.erase(i); 1224 channels_.erase(i);
1253 } 1225 }
1254 } 1226 }
1255 1227
1256 // Adjusts the default AGC target level by the specified delta. 1228 // Adjusts the default AGC target level by the specified delta.
1257 // NB: If we start messing with other config fields, we'll want 1229 // NB: If we start messing with other config fields, we'll want
1258 // to save the current webrtc::AgcConfig as well. 1230 // to save the current webrtc::AgcConfig as well.
1259 bool WebRtcVoiceEngine::AdjustAgcLevel(int delta) { 1231 bool WebRtcVoiceEngine::AdjustAgcLevel(int delta) {
1260 webrtc::AgcConfig config = default_agc_config_; 1232 webrtc::AgcConfig config = default_agc_config_;
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1493 1465
1494 // TODO(xians): Add support to set different options for different send 1466 // TODO(xians): Add support to set different options for different send
1495 // streams after we support multiple APMs. 1467 // streams after we support multiple APMs.
1496 1468
1497 // We retain all of the existing options, and apply the given ones 1469 // We retain all of the existing options, and apply the given ones
1498 // on top. This means there is no way to "clear" options such that 1470 // on top. This means there is no way to "clear" options such that
1499 // they go back to the engine default. 1471 // they go back to the engine default.
1500 options_.SetAll(options); 1472 options_.SetAll(options);
1501 1473
1502 if (send_ != SEND_NOTHING) { 1474 if (send_ != SEND_NOTHING) {
1503 if (!engine()->SetOptionOverrides(options_)) { 1475 if (!engine()->ApplyOptions(options_)) {
1504 LOG(LS_WARNING) <<
1505 "Failed to engine SetOptionOverrides during channel SetOptions.";
1506 return false; 1476 return false;
1507 } 1477 }
1508 } else {
1509 // Will be interpreted when appropriate.
1510 } 1478 }
1511 1479
1512 // Receiver-side auto gain control happens per channel, so set it here from 1480 // Receiver-side auto gain control happens per channel, so set it here from
1513 // options. Note that, like conference mode, setting it on the engine won't 1481 // options. Note that, like conference mode, setting it on the engine won't
1514 // have the desired effect, since voice channels don't inherit options from 1482 // have the desired effect, since voice channels don't inherit options from
1515 // the media engine when those options are applied per-channel. 1483 // the media engine when those options are applied per-channel.
1516 bool rx_auto_gain_control; 1484 bool rx_auto_gain_control;
1517 if (options.rx_auto_gain_control.Get(&rx_auto_gain_control)) { 1485 if (options.rx_auto_gain_control.Get(&rx_auto_gain_control)) {
1518 if (engine()->voe()->processing()->SetRxAgcStatus( 1486 if (engine()->voe()->processing()->SetRxAgcStatus(
1519 voe_channel(), rx_auto_gain_control, 1487 voe_channel(), rx_auto_gain_control,
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
2062 bool WebRtcVoiceMediaChannel::ResumeSend() { 2030 bool WebRtcVoiceMediaChannel::ResumeSend() {
2063 return ChangeSend(desired_send_); 2031 return ChangeSend(desired_send_);
2064 } 2032 }
2065 2033
2066 bool WebRtcVoiceMediaChannel::ChangeSend(SendFlags send) { 2034 bool WebRtcVoiceMediaChannel::ChangeSend(SendFlags send) {
2067 if (send_ == send) { 2035 if (send_ == send) {
2068 return true; 2036 return true;
2069 } 2037 }
2070 2038
2071 // Change the settings on each send channel. 2039 // Change the settings on each send channel.
2072 if (send == SEND_MICROPHONE) 2040 if (send == SEND_MICROPHONE) {
2073 engine()->SetOptionOverrides(options_); 2041 engine()->ApplyOptions(options_);
2042 }
2074 2043
2075 // Change the settings on each send channel. 2044 // Change the settings on each send channel.
2076 for (const auto& ch : send_channels_) { 2045 for (const auto& ch : send_channels_) {
2077 if (!ChangeSend(ch.second->channel(), send)) 2046 if (!ChangeSend(ch.second->channel(), send)) {
2078 return false; 2047 return false;
2048 }
2079 } 2049 }
2080 2050
2081 // Clear up the options after stopping sending. 2051 // Clear up the options after stopping sending.
2082 if (send == SEND_NOTHING) 2052 if (send == SEND_NOTHING) {
2083 engine()->ClearOptionOverrides(); 2053 engine()->ApplyOptions(engine()->GetOptions());
pbos-webrtc 2015/09/23 13:41:34 Why is this not a no-op?
the sun 2015/09/23 15:11:28 Because the engine options_ can be different from
pbos-webrtc 2015/09/23 15:13:14 But you're applying engine's GetOptions to engine?
2054 }
2084 2055
2085 send_ = send; 2056 send_ = send;
2086 return true; 2057 return true;
2087 } 2058 }
2088 2059
2089 bool WebRtcVoiceMediaChannel::ChangeSend(int channel, SendFlags send) { 2060 bool WebRtcVoiceMediaChannel::ChangeSend(int channel, SendFlags send) {
2090 if (send == SEND_MICROPHONE) { 2061 if (send == SEND_MICROPHONE) {
2091 if (engine()->voe()->base()->StartSend(channel) == -1) { 2062 if (engine()->voe()->base()->StartSend(channel) == -1) {
2092 LOG_RTCERR1(StartSend, channel); 2063 LOG_RTCERR1(StartSend, channel);
2093 return false; 2064 return false;
(...skipping 1184 matching lines...) Expand 10 before | Expand all | Expand 10 after
3278 LOG(LS_WARNING) << "Unknown codec " << ToString(codec); 3249 LOG(LS_WARNING) << "Unknown codec " << ToString(codec);
3279 return false; 3250 return false;
3280 } 3251 }
3281 } 3252 }
3282 return true; 3253 return true;
3283 } 3254 }
3284 3255
3285 } // namespace cricket 3256 } // namespace cricket
3286 3257
3287 #endif // HAVE_WEBRTC_VOICE 3258 #endif // HAVE_WEBRTC_VOICE
OLDNEW
« no previous file with comments | « talk/media/webrtc/webrtcvoiceengine.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698