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

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: rebase Created 5 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 | « 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 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 } 575 }
576 576
577 bool WebRtcVoiceEngine::SetOptions(const AudioOptions& options) { 577 bool WebRtcVoiceEngine::SetOptions(const AudioOptions& options) {
578 if (!ApplyOptions(options)) { 578 if (!ApplyOptions(options)) {
579 return false; 579 return false;
580 } 580 }
581 options_ = options; 581 options_ = options;
582 return true; 582 return true;
583 } 583 }
584 584
585 bool WebRtcVoiceEngine::SetOptionOverrides(const AudioOptions& overrides) {
586 LOG(LS_INFO) << "Setting option overrides: " << overrides.ToString();
587 if (!ApplyOptions(overrides)) {
588 return false;
589 }
590 option_overrides_ = overrides;
591 return true;
592 }
593
594 bool WebRtcVoiceEngine::ClearOptionOverrides() {
595 LOG(LS_INFO) << "Clearing option overrides.";
596 AudioOptions options = options_;
597 // Only call ApplyOptions if |options_overrides_| contains overrided options.
598 // ApplyOptions affects NS, AGC other options that is shared between
599 // all WebRtcVoiceEngineChannels.
600 if (option_overrides_ == AudioOptions()) {
601 return true;
602 }
603
604 if (!ApplyOptions(options)) {
605 return false;
606 }
607 option_overrides_ = AudioOptions();
608 return true;
609 }
610
611 // AudioOptions defaults are set in InitInternal (for options with corresponding 585 // AudioOptions defaults are set in InitInternal (for options with corresponding
612 // MediaEngineInterface flags) and in SetOptions(int) for flagless options. 586 // MediaEngineInterface flags) and in SetOptions(int) for flagless options.
613 bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) { 587 bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) {
614 LOG(LS_INFO) << "ApplyOptions: " << options_in.ToString(); 588 LOG(LS_INFO) << "ApplyOptions: " << options_in.ToString();
615 AudioOptions options = options_in; // The options are modified below. 589 AudioOptions options = options_in; // The options are modified below.
616 // kEcConference is AEC with high suppression. 590 // kEcConference is AEC with high suppression.
617 webrtc::EcModes ec_mode = webrtc::kEcConference; 591 webrtc::EcModes ec_mode = webrtc::kEcConference;
618 webrtc::AecmModes aecm_mode = webrtc::kAecmSpeakerphone; 592 webrtc::AecmModes aecm_mode = webrtc::kAecmSpeakerphone;
619 webrtc::AgcModes agc_mode = webrtc::kAgcAdaptiveAnalog; 593 webrtc::AgcModes agc_mode = webrtc::kAgcAdaptiveAnalog;
620 webrtc::NsModes ns_mode = webrtc::kNsHighSuppression; 594 webrtc::NsModes ns_mode = webrtc::kNsHighSuppression;
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
1238 RTC_DCHECK(ch != NULL); 1212 RTC_DCHECK(ch != NULL);
1239 if (ch->FindSsrc(channel_num, ssrc)) { 1213 if (ch->FindSsrc(channel_num, ssrc)) {
1240 *channel = ch; 1214 *channel = ch;
1241 return true; 1215 return true;
1242 } 1216 }
1243 } 1217 }
1244 1218
1245 return false; 1219 return false;
1246 } 1220 }
1247 1221
1248 void WebRtcVoiceEngine::RegisterChannel(WebRtcVoiceMediaChannel *channel) { 1222 void WebRtcVoiceEngine::RegisterChannel(WebRtcVoiceMediaChannel* channel) {
1249 rtc::CritScope lock(&channels_cs_); 1223 rtc::CritScope lock(&channels_cs_);
1250 channels_.push_back(channel); 1224 channels_.push_back(channel);
1251 } 1225 }
1252 1226
1253 void WebRtcVoiceEngine::UnregisterChannel(WebRtcVoiceMediaChannel *channel) { 1227 void WebRtcVoiceEngine::UnregisterChannel(WebRtcVoiceMediaChannel* channel) {
1254 rtc::CritScope lock(&channels_cs_); 1228 rtc::CritScope lock(&channels_cs_);
1255 ChannelList::iterator i = std::find(channels_.begin(), 1229 auto it = std::find(channels_.begin(), channels_.end(), channel);
1256 channels_.end(), 1230 if (it != channels_.end()) {
1257 channel); 1231 channels_.erase(it);
1258 if (i != channels_.end()) {
1259 channels_.erase(i);
1260 } 1232 }
1261 } 1233 }
1262 1234
1263 // Adjusts the default AGC target level by the specified delta. 1235 // Adjusts the default AGC target level by the specified delta.
1264 // NB: If we start messing with other config fields, we'll want 1236 // NB: If we start messing with other config fields, we'll want
1265 // to save the current webrtc::AgcConfig as well. 1237 // to save the current webrtc::AgcConfig as well.
1266 bool WebRtcVoiceEngine::AdjustAgcLevel(int delta) { 1238 bool WebRtcVoiceEngine::AdjustAgcLevel(int delta) {
1267 webrtc::AgcConfig config = default_agc_config_; 1239 webrtc::AgcConfig config = default_agc_config_;
1268 config.targetLeveldBOv -= delta; 1240 config.targetLeveldBOv -= delta;
1269 1241
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
1500 1472
1501 // TODO(xians): Add support to set different options for different send 1473 // TODO(xians): Add support to set different options for different send
1502 // streams after we support multiple APMs. 1474 // streams after we support multiple APMs.
1503 1475
1504 // We retain all of the existing options, and apply the given ones 1476 // We retain all of the existing options, and apply the given ones
1505 // on top. This means there is no way to "clear" options such that 1477 // on top. This means there is no way to "clear" options such that
1506 // they go back to the engine default. 1478 // they go back to the engine default.
1507 options_.SetAll(options); 1479 options_.SetAll(options);
1508 1480
1509 if (send_ != SEND_NOTHING) { 1481 if (send_ != SEND_NOTHING) {
1510 if (!engine()->SetOptionOverrides(options_)) { 1482 if (!engine()->ApplyOptions(options_)) {
1511 LOG(LS_WARNING) << 1483 LOG(LS_WARNING) <<
1512 "Failed to engine SetOptionOverrides during channel SetOptions."; 1484 "Failed to apply engine options during channel SetOptions.";
1513 return false; 1485 return false;
1514 } 1486 }
1515 } else {
1516 // Will be interpreted when appropriate.
1517 } 1487 }
1518 1488
1519 // Receiver-side auto gain control happens per channel, so set it here from 1489 // Receiver-side auto gain control happens per channel, so set it here from
1520 // options. Note that, like conference mode, setting it on the engine won't 1490 // options. Note that, like conference mode, setting it on the engine won't
1521 // have the desired effect, since voice channels don't inherit options from 1491 // have the desired effect, since voice channels don't inherit options from
1522 // the media engine when those options are applied per-channel. 1492 // the media engine when those options are applied per-channel.
1523 bool rx_auto_gain_control; 1493 bool rx_auto_gain_control;
1524 if (options.rx_auto_gain_control.Get(&rx_auto_gain_control)) { 1494 if (options.rx_auto_gain_control.Get(&rx_auto_gain_control)) {
1525 if (engine()->voe()->processing()->SetRxAgcStatus( 1495 if (engine()->voe()->processing()->SetRxAgcStatus(
1526 voe_channel(), rx_auto_gain_control, 1496 voe_channel(), rx_auto_gain_control,
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
2068 2038
2069 bool WebRtcVoiceMediaChannel::ResumeSend() { 2039 bool WebRtcVoiceMediaChannel::ResumeSend() {
2070 return ChangeSend(desired_send_); 2040 return ChangeSend(desired_send_);
2071 } 2041 }
2072 2042
2073 bool WebRtcVoiceMediaChannel::ChangeSend(SendFlags send) { 2043 bool WebRtcVoiceMediaChannel::ChangeSend(SendFlags send) {
2074 if (send_ == send) { 2044 if (send_ == send) {
2075 return true; 2045 return true;
2076 } 2046 }
2077 2047
2078 // Change the settings on each send channel. 2048 // Apply channel specific options.
2079 if (send == SEND_MICROPHONE) 2049 if (send == SEND_MICROPHONE) {
2080 engine()->SetOptionOverrides(options_); 2050 engine()->ApplyOptions(options_);
2051 }
2081 2052
2082 // Change the settings on each send channel. 2053 // Change the settings on each send channel.
2083 for (const auto& ch : send_channels_) { 2054 for (const auto& ch : send_channels_) {
2084 if (!ChangeSend(ch.second->channel(), send)) 2055 if (!ChangeSend(ch.second->channel(), send)) {
2085 return false; 2056 return false;
2057 }
2086 } 2058 }
2087 2059
2088 // Clear up the options after stopping sending. 2060 // Clear up the options after stopping sending. Since we may previously have
2089 if (send == SEND_NOTHING) 2061 // applied the channel specific options, now apply the original options stored
2090 engine()->ClearOptionOverrides(); 2062 // in WebRtcVoiceEngine.
2063 if (send == SEND_NOTHING) {
2064 engine()->ApplyOptions(engine()->GetOptions());
2065 }
2091 2066
2092 send_ = send; 2067 send_ = send;
2093 return true; 2068 return true;
2094 } 2069 }
2095 2070
2096 bool WebRtcVoiceMediaChannel::ChangeSend(int channel, SendFlags send) { 2071 bool WebRtcVoiceMediaChannel::ChangeSend(int channel, SendFlags send) {
2097 if (send == SEND_MICROPHONE) { 2072 if (send == SEND_MICROPHONE) {
2098 if (engine()->voe()->base()->StartSend(channel) == -1) { 2073 if (engine()->voe()->base()->StartSend(channel) == -1) {
2099 LOG_RTCERR1(StartSend, channel); 2074 LOG_RTCERR1(StartSend, channel);
2100 return false; 2075 return false;
(...skipping 1184 matching lines...) Expand 10 before | Expand all | Expand 10 after
3285 LOG(LS_WARNING) << "Unknown codec " << ToString(codec); 3260 LOG(LS_WARNING) << "Unknown codec " << ToString(codec);
3286 return false; 3261 return false;
3287 } 3262 }
3288 } 3263 }
3289 return true; 3264 return true;
3290 } 3265 }
3291 3266
3292 } // namespace cricket 3267 } // namespace cricket
3293 3268
3294 #endif // HAVE_WEBRTC_VOICE 3269 #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