Simplify handling of options in WebRtcVoiceMediaEngine.

Also removes unnecessary typedef ChannelList.

BUG=webrtc:4690

Review URL: https://codereview.webrtc.org/1364753002

Cr-Commit-Position: refs/heads/master@{#10107}
This commit is contained in:
solenberg
2015-09-29 06:06:31 -07:00
committed by Commit bot
parent 86fd9ed6f9
commit 63b345441a
2 changed files with 25 additions and 73 deletions

View File

@ -582,32 +582,6 @@ bool WebRtcVoiceEngine::SetOptions(const AudioOptions& options) {
return true; return true;
} }
bool WebRtcVoiceEngine::SetOptionOverrides(const AudioOptions& overrides) {
LOG(LS_INFO) << "Setting option overrides: " << overrides.ToString();
if (!ApplyOptions(overrides)) {
return false;
}
option_overrides_ = overrides;
return true;
}
bool WebRtcVoiceEngine::ClearOptionOverrides() {
LOG(LS_INFO) << "Clearing option overrides.";
AudioOptions options = options_;
// Only call ApplyOptions if |options_overrides_| contains overrided options.
// ApplyOptions affects NS, AGC other options that is shared between
// all WebRtcVoiceEngineChannels.
if (option_overrides_ == AudioOptions()) {
return true;
}
if (!ApplyOptions(options)) {
return false;
}
option_overrides_ = AudioOptions();
return true;
}
// AudioOptions defaults are set in InitInternal (for options with corresponding // AudioOptions defaults are set in InitInternal (for options with corresponding
// MediaEngineInterface flags) and in SetOptions(int) for flagless options. // MediaEngineInterface flags) and in SetOptions(int) for flagless options.
bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) { bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) {
@ -1245,18 +1219,16 @@ bool WebRtcVoiceEngine::FindChannelAndSsrc(
return false; return false;
} }
void WebRtcVoiceEngine::RegisterChannel(WebRtcVoiceMediaChannel *channel) { void WebRtcVoiceEngine::RegisterChannel(WebRtcVoiceMediaChannel* channel) {
rtc::CritScope lock(&channels_cs_); rtc::CritScope lock(&channels_cs_);
channels_.push_back(channel); channels_.push_back(channel);
} }
void WebRtcVoiceEngine::UnregisterChannel(WebRtcVoiceMediaChannel *channel) { void WebRtcVoiceEngine::UnregisterChannel(WebRtcVoiceMediaChannel* channel) {
rtc::CritScope lock(&channels_cs_); rtc::CritScope lock(&channels_cs_);
ChannelList::iterator i = std::find(channels_.begin(), auto it = std::find(channels_.begin(), channels_.end(), channel);
channels_.end(), if (it != channels_.end()) {
channel); channels_.erase(it);
if (i != channels_.end()) {
channels_.erase(i);
} }
} }
@ -1507,13 +1479,11 @@ bool WebRtcVoiceMediaChannel::SetOptions(const AudioOptions& options) {
options_.SetAll(options); options_.SetAll(options);
if (send_ != SEND_NOTHING) { if (send_ != SEND_NOTHING) {
if (!engine()->SetOptionOverrides(options_)) { if (!engine()->ApplyOptions(options_)) {
LOG(LS_WARNING) << LOG(LS_WARNING) <<
"Failed to engine SetOptionOverrides during channel SetOptions."; "Failed to apply engine options during channel SetOptions.";
return false; return false;
} }
} else {
// Will be interpreted when appropriate.
} }
// Receiver-side auto gain control happens per channel, so set it here from // Receiver-side auto gain control happens per channel, so set it here from
@ -2075,19 +2045,24 @@ bool WebRtcVoiceMediaChannel::ChangeSend(SendFlags send) {
return true; return true;
} }
// Change the settings on each send channel. // Apply channel specific options.
if (send == SEND_MICROPHONE) if (send == SEND_MICROPHONE) {
engine()->SetOptionOverrides(options_); engine()->ApplyOptions(options_);
}
// Change the settings on each send channel. // Change the settings on each send channel.
for (const auto& ch : send_channels_) { for (const auto& ch : send_channels_) {
if (!ChangeSend(ch.second->channel(), send)) if (!ChangeSend(ch.second->channel(), send)) {
return false; return false;
}
} }
// Clear up the options after stopping sending. // Clear up the options after stopping sending. Since we may previously have
if (send == SEND_NOTHING) // applied the channel specific options, now apply the original options stored
engine()->ClearOptionOverrides(); // in WebRtcVoiceEngine.
if (send == SEND_NOTHING) {
engine()->ApplyOptions(engine()->GetOptions());
}
send_ = send; send_ = send;
return true; return true;

View File

@ -92,8 +92,8 @@ class WebRtcVoiceEngine
// For tracking WebRtc channels. Needed because we have to pause them // For tracking WebRtc channels. Needed because we have to pause them
// all when switching devices. // all when switching devices.
// May only be called by WebRtcVoiceMediaChannel. // May only be called by WebRtcVoiceMediaChannel.
void RegisterChannel(WebRtcVoiceMediaChannel *channel); void RegisterChannel(WebRtcVoiceMediaChannel* channel);
void UnregisterChannel(WebRtcVoiceMediaChannel *channel); void UnregisterChannel(WebRtcVoiceMediaChannel* channel);
// Called by WebRtcVoiceMediaChannel to set a gain offset from // Called by WebRtcVoiceMediaChannel to set a gain offset from
// the default AGC target level. // the default AGC target level.
@ -112,32 +112,16 @@ class WebRtcVoiceEngine
int CreateMediaVoiceChannel(); int CreateMediaVoiceChannel();
private: private:
typedef std::vector<WebRtcVoiceMediaChannel*> ChannelList;
void Construct(); void Construct();
void ConstructCodecs(); void ConstructCodecs();
bool GetVoeCodec(int index, webrtc::CodecInst* codec); bool GetVoeCodec(int index, webrtc::CodecInst* codec);
bool InitInternal(); bool InitInternal();
void SetTraceFilter(int filter); void SetTraceFilter(int filter);
void SetTraceOptions(const std::string& options); void SetTraceOptions(const std::string& options);
// Applies either options or overrides. Every option that is "set" // Every option that is "set" will be applied. Every option not "set" will be
// will be applied. Every option not "set" will be ignored. This // ignored. This allows us to selectively turn on and off different options
// allows us to selectively turn on and off different options easily // easily at any time.
// at any time.
bool ApplyOptions(const AudioOptions& options); bool ApplyOptions(const AudioOptions& options);
// Overrides, when set, take precedence over the options on a
// per-option basis. For example, if AGC is set in options and AEC
// is set in overrides, AGC and AEC will be both be set. Overrides
// can also turn off options. For example, if AGC is set to "on" in
// options and AGC is set to "off" in overrides, the result is that
// AGC will be off until different overrides are applied or until
// the overrides are cleared. Only one set of overrides is present
// at a time (they do not "stack"). And when the overrides are
// cleared, the media engine's state reverts back to the options set
// via SetOptions. This allows us to have both "persistent options"
// (the normal options) and "temporary options" (overrides).
bool SetOptionOverrides(const AudioOptions& options);
bool ClearOptionOverrides();
// webrtc::TraceCallback: // webrtc::TraceCallback:
void Print(webrtc::TraceLevel level, const char* trace, int length) override; void Print(webrtc::TraceLevel level, const char* trace, int length) override;
@ -169,7 +153,7 @@ class WebRtcVoiceEngine
bool is_dumping_aec_; bool is_dumping_aec_;
std::vector<AudioCodec> codecs_; std::vector<AudioCodec> codecs_;
std::vector<RtpHeaderExtension> rtp_header_extensions_; std::vector<RtpHeaderExtension> rtp_header_extensions_;
ChannelList channels_; std::vector<WebRtcVoiceMediaChannel*> channels_;
// channels_ can be read from WebRtc callback thread. We need a lock on that // channels_ can be read from WebRtc callback thread. We need a lock on that
// callback as well as the RegisterChannel/UnregisterChannel. // callback as well as the RegisterChannel/UnregisterChannel.
rtc::CriticalSection channels_cs_; rtc::CriticalSection channels_cs_;
@ -178,14 +162,7 @@ class WebRtcVoiceEngine
webrtc::Config voe_config_; webrtc::Config voe_config_;
bool initialized_; bool initialized_;
// See SetOptions and SetOptionOverrides for a description of the
// difference between options and overrides.
// options_ are the base options, which combined with the
// option_overrides_, create the current options being used.
// options_ is stored so that when option_overrides_ is cleared, we
// can restore the options_ without the option_overrides.
AudioOptions options_; AudioOptions options_;
AudioOptions option_overrides_;
// Cache received extended_filter_aec, delay_agnostic_aec and experimental_ns // Cache received extended_filter_aec, delay_agnostic_aec and experimental_ns
// values, and apply them in case they are missing in the audio options. We // values, and apply them in case they are missing in the audio options. We