From 102c6a61bc0b42dc0956d013530fc0213b7e881b Mon Sep 17 00:00:00 2001 From: kwiberg Date: Fri, 30 Oct 2015 02:47:38 -0700 Subject: [PATCH] Replace rtc::cricket::Settable with rtc::Maybe The former is very similar to the latter, but less general (mostly in naming). This CL, which is the first to use Maybe at scale, also removes the implicit conversion from T to Maybe, since it was agreed that the increased verbosity increased legibility. Review URL: https://codereview.webrtc.org/1430433004 Cr-Commit-Position: refs/heads/master@{#10461} --- talk/app/webrtc/localaudiosource.cc | 4 +- talk/app/webrtc/localaudiosource_unittest.cc | 40 +-- talk/app/webrtc/videosource.cc | 5 +- talk/app/webrtc/videosource_unittest.cc | 28 +- talk/app/webrtc/webrtcsession.cc | 31 +- talk/app/webrtc/webrtcsession_unittest.cc | 22 +- talk/media/base/mediachannel.h | 284 ++++++++---------- talk/media/base/videoengine_unittest.h | 14 +- talk/media/webrtc/webrtcvideoengine2.cc | 88 +++--- talk/media/webrtc/webrtcvideoengine2.h | 8 +- .../webrtc/webrtcvideoengine2_unittest.cc | 21 +- talk/media/webrtc/webrtcvoiceengine.cc | 248 ++++++++------- talk/media/webrtc/webrtcvoiceengine.h | 6 +- .../webrtc/webrtcvoiceengine_unittest.cc | 98 +++--- talk/session/media/channel.cc | 4 +- webrtc/base/maybe.h | 19 +- webrtc/base/maybe_unittest.cc | 54 ++-- .../audio_coding/main/acm2/rent_a_codec.cc | 7 +- .../audio_coding/main/acm2/rent_a_codec.h | 6 +- .../audio_processing/beamformer/array_util.cc | 6 +- 20 files changed, 450 insertions(+), 543 deletions(-) diff --git a/talk/app/webrtc/localaudiosource.cc b/talk/app/webrtc/localaudiosource.cc index 63c6f13a3d..8b4c25206b 100644 --- a/talk/app/webrtc/localaudiosource.cc +++ b/talk/app/webrtc/localaudiosource.cc @@ -49,7 +49,7 @@ void FromConstraints(const MediaConstraintsInterface::Constraints& constraints, // a different algorithm will be required. struct { const char* name; - cricket::Settable& value; + rtc::Maybe& value; } key_to_value[] = { {MediaConstraintsInterface::kGoogEchoCancellation, options->echo_cancellation}, @@ -78,7 +78,7 @@ void FromConstraints(const MediaConstraintsInterface::Constraints& constraints, for (auto& entry : key_to_value) { if (constraint.key.compare(entry.name) == 0) - entry.value.Set(value); + entry.value = rtc::Maybe(value); } } } diff --git a/talk/app/webrtc/localaudiosource_unittest.cc b/talk/app/webrtc/localaudiosource_unittest.cc index 8e05c18287..d36b7cd9c2 100644 --- a/talk/app/webrtc/localaudiosource_unittest.cc +++ b/talk/app/webrtc/localaudiosource_unittest.cc @@ -58,23 +58,14 @@ TEST(LocalAudioSourceTest, SetValidOptions) { LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(), &constraints); - bool value; - EXPECT_TRUE(source->options().echo_cancellation.Get(&value)); - EXPECT_FALSE(value); - EXPECT_TRUE(source->options().extended_filter_aec.Get(&value)); - EXPECT_TRUE(value); - EXPECT_TRUE(source->options().delay_agnostic_aec.Get(&value)); - EXPECT_TRUE(value); - EXPECT_TRUE(source->options().auto_gain_control.Get(&value)); - EXPECT_TRUE(value); - EXPECT_TRUE(source->options().experimental_agc.Get(&value)); - EXPECT_TRUE(value); - EXPECT_TRUE(source->options().noise_suppression.Get(&value)); - EXPECT_FALSE(value); - EXPECT_TRUE(source->options().highpass_filter.Get(&value)); - EXPECT_TRUE(value); - EXPECT_TRUE(source->options().aec_dump.Get(&value)); - EXPECT_TRUE(value); + EXPECT_EQ(rtc::Maybe(false), source->options().echo_cancellation); + EXPECT_EQ(rtc::Maybe(true), source->options().extended_filter_aec); + EXPECT_EQ(rtc::Maybe(true), source->options().delay_agnostic_aec); + EXPECT_EQ(rtc::Maybe(true), source->options().auto_gain_control); + EXPECT_EQ(rtc::Maybe(true), source->options().experimental_agc); + EXPECT_EQ(rtc::Maybe(false), source->options().noise_suppression); + EXPECT_EQ(rtc::Maybe(true), source->options().highpass_filter); + EXPECT_EQ(rtc::Maybe(true), source->options().aec_dump); } TEST(LocalAudioSourceTest, OptionNotSet) { @@ -82,8 +73,7 @@ TEST(LocalAudioSourceTest, OptionNotSet) { rtc::scoped_refptr source = LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(), &constraints); - bool value; - EXPECT_FALSE(source->options().highpass_filter.Get(&value)); + EXPECT_EQ(rtc::Maybe(), source->options().highpass_filter); } TEST(LocalAudioSourceTest, MandatoryOverridesOptional) { @@ -97,9 +87,7 @@ TEST(LocalAudioSourceTest, MandatoryOverridesOptional) { LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(), &constraints); - bool value; - EXPECT_TRUE(source->options().echo_cancellation.Get(&value)); - EXPECT_FALSE(value); + EXPECT_EQ(rtc::Maybe(false), source->options().echo_cancellation); } TEST(LocalAudioSourceTest, InvalidOptional) { @@ -112,9 +100,7 @@ TEST(LocalAudioSourceTest, InvalidOptional) { &constraints); EXPECT_EQ(MediaSourceInterface::kLive, source->state()); - bool value; - EXPECT_TRUE(source->options().highpass_filter.Get(&value)); - EXPECT_FALSE(value); + EXPECT_EQ(rtc::Maybe(false), source->options().highpass_filter); } TEST(LocalAudioSourceTest, InvalidMandatory) { @@ -127,7 +113,5 @@ TEST(LocalAudioSourceTest, InvalidMandatory) { &constraints); EXPECT_EQ(MediaSourceInterface::kLive, source->state()); - bool value; - EXPECT_TRUE(source->options().highpass_filter.Get(&value)); - EXPECT_FALSE(value); + EXPECT_EQ(rtc::Maybe(false), source->options().highpass_filter); } diff --git a/talk/app/webrtc/videosource.cc b/talk/app/webrtc/videosource.cc index b33f5f9e13..bed1be94db 100644 --- a/talk/app/webrtc/videosource.cc +++ b/talk/app/webrtc/videosource.cc @@ -267,11 +267,12 @@ const cricket::VideoFormat& GetBestCaptureFormat( // Set |option| to the highest-priority value of |key| in the constraints. // Return false if the key is mandatory, and the value is invalid. bool ExtractOption(const MediaConstraintsInterface* all_constraints, - const std::string& key, cricket::Settable* option) { + const std::string& key, + rtc::Maybe* option) { size_t mandatory = 0; bool value; if (FindConstraint(all_constraints, key, &value, &mandatory)) { - option->Set(value); + *option = rtc::Maybe(value); return true; } diff --git a/talk/app/webrtc/videosource_unittest.cc b/talk/app/webrtc/videosource_unittest.cc index 2efcc1d84e..f7dfe97542 100644 --- a/talk/app/webrtc/videosource_unittest.cc +++ b/talk/app/webrtc/videosource_unittest.cc @@ -392,16 +392,13 @@ TEST_F(VideoSourceTest, SetValidOptionValues) { CreateVideoSource(&constraints); - bool value = true; - EXPECT_TRUE(source_->options()->video_noise_reduction.Get(&value)); - EXPECT_FALSE(value); + EXPECT_EQ(rtc::Maybe(false), source_->options()->video_noise_reduction); } TEST_F(VideoSourceTest, OptionNotSet) { FakeConstraints constraints; CreateVideoSource(&constraints); - bool value; - EXPECT_FALSE(source_->options()->video_noise_reduction.Get(&value)); + EXPECT_EQ(rtc::Maybe(), source_->options()->video_noise_reduction); } TEST_F(VideoSourceTest, MandatoryOptionOverridesOptional) { @@ -413,9 +410,7 @@ TEST_F(VideoSourceTest, MandatoryOptionOverridesOptional) { CreateVideoSource(&constraints); - bool value = false; - EXPECT_TRUE(source_->options()->video_noise_reduction.Get(&value)); - EXPECT_TRUE(value); + EXPECT_EQ(rtc::Maybe(true), source_->options()->video_noise_reduction); } TEST_F(VideoSourceTest, InvalidOptionKeyOptional) { @@ -428,9 +423,7 @@ TEST_F(VideoSourceTest, InvalidOptionKeyOptional) { EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(), kMaxWaitMs); - bool value = true; - EXPECT_TRUE(source_->options()->video_noise_reduction.Get(&value)); - EXPECT_FALSE(value); + EXPECT_EQ(rtc::Maybe(false), source_->options()->video_noise_reduction); } TEST_F(VideoSourceTest, InvalidOptionKeyMandatory) { @@ -443,8 +436,7 @@ TEST_F(VideoSourceTest, InvalidOptionKeyMandatory) { EXPECT_EQ_WAIT(MediaSourceInterface::kEnded, state_observer_->state(), kMaxWaitMs); - bool value; - EXPECT_FALSE(source_->options()->video_noise_reduction.Get(&value)); + EXPECT_EQ(rtc::Maybe(), source_->options()->video_noise_reduction); } TEST_F(VideoSourceTest, InvalidOptionValueOptional) { @@ -456,8 +448,7 @@ TEST_F(VideoSourceTest, InvalidOptionValueOptional) { EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(), kMaxWaitMs); - bool value = false; - EXPECT_FALSE(source_->options()->video_noise_reduction.Get(&value)); + EXPECT_EQ(rtc::Maybe(), source_->options()->video_noise_reduction); } TEST_F(VideoSourceTest, InvalidOptionValueMandatory) { @@ -473,8 +464,7 @@ TEST_F(VideoSourceTest, InvalidOptionValueMandatory) { EXPECT_EQ_WAIT(MediaSourceInterface::kEnded, state_observer_->state(), kMaxWaitMs); - bool value; - EXPECT_FALSE(source_->options()->video_noise_reduction.Get(&value)); + EXPECT_EQ(rtc::Maybe(), source_->options()->video_noise_reduction); } TEST_F(VideoSourceTest, MixedOptionsAndConstraints) { @@ -497,9 +487,7 @@ TEST_F(VideoSourceTest, MixedOptionsAndConstraints) { EXPECT_EQ(288, format->height); EXPECT_EQ(30, format->framerate()); - bool value = true; - EXPECT_TRUE(source_->options()->video_noise_reduction.Get(&value)); - EXPECT_FALSE(value); + EXPECT_EQ(rtc::Maybe(false), source_->options()->video_noise_reduction); } // Tests that the source starts video with the default resolution for diff --git a/talk/app/webrtc/webrtcsession.cc b/talk/app/webrtc/webrtcsession.cc index 95abeab77a..5b58c24319 100644 --- a/talk/app/webrtc/webrtcsession.cc +++ b/talk/app/webrtc/webrtcsession.cc @@ -441,10 +441,11 @@ static std::string MakeTdErrorString(const std::string& desc) { // Set |option| to the highest-priority value of |key| in the optional // constraints if the key is found and has a valid value. -template +template static void SetOptionFromOptionalConstraint( const MediaConstraintsInterface* constraints, - const std::string& key, cricket::Settable* option) { + const std::string& key, + rtc::Maybe* option) { if (!constraints) { return; } @@ -452,7 +453,7 @@ static void SetOptionFromOptionalConstraint( T value; if (constraints->GetOptional().FindFirst(key, &string_value)) { if (rtc::FromString(string_value, &value)) { - option->Set(value); + *option = rtc::Maybe(value); } } } @@ -644,8 +645,8 @@ bool WebRtcSession::Initialize( constraints, MediaConstraintsInterface::kEnableDscp, &value, NULL)) { - audio_options_.dscp.Set(value); - video_options_.dscp.Set(value); + audio_options_.dscp = rtc::Maybe(value); + video_options_.dscp = rtc::Maybe(value); } // Find Suspend Below Min Bitrate constraint. @@ -654,7 +655,7 @@ bool WebRtcSession::Initialize( MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate, &value, NULL)) { - video_options_.suspend_below_min_bitrate.Set(value); + video_options_.suspend_below_min_bitrate = rtc::Maybe(value); } SetOptionFromOptionalConstraint(constraints, @@ -684,12 +685,10 @@ bool WebRtcSession::Initialize( SetOptionFromOptionalConstraint(constraints, MediaConstraintsInterface::kNumUnsignalledRecvStreams, &video_options_.unsignalled_recv_stream_limit); - if (video_options_.unsignalled_recv_stream_limit.IsSet()) { - int stream_limit; - video_options_.unsignalled_recv_stream_limit.Get(&stream_limit); - stream_limit = std::min(kMaxUnsignalledRecvStreams, stream_limit); - stream_limit = std::max(0, stream_limit); - video_options_.unsignalled_recv_stream_limit.Set(stream_limit); + if (video_options_.unsignalled_recv_stream_limit) { + video_options_.unsignalled_recv_stream_limit = rtc::Maybe( + std::max(0, std::min(kMaxUnsignalledRecvStreams, + *video_options_.unsignalled_recv_stream_limit))); } SetOptionFromOptionalConstraint(constraints, @@ -700,11 +699,11 @@ bool WebRtcSession::Initialize( MediaConstraintsInterface::kCombinedAudioVideoBwe, &audio_options_.combined_audio_video_bwe); - audio_options_.audio_jitter_buffer_max_packets.Set( - rtc_configuration.audio_jitter_buffer_max_packets); + audio_options_.audio_jitter_buffer_max_packets = + rtc::Maybe(rtc_configuration.audio_jitter_buffer_max_packets); - audio_options_.audio_jitter_buffer_fast_accelerate.Set( - rtc_configuration.audio_jitter_buffer_fast_accelerate); + audio_options_.audio_jitter_buffer_fast_accelerate = + rtc::Maybe(rtc_configuration.audio_jitter_buffer_fast_accelerate); const cricket::VideoCodec default_codec( JsepSessionDescription::kDefaultVideoCodecId, diff --git a/talk/app/webrtc/webrtcsession_unittest.cc b/talk/app/webrtc/webrtcsession_unittest.cc index 3eb46f1d3c..568f5fef89 100644 --- a/talk/app/webrtc/webrtcsession_unittest.cc +++ b/talk/app/webrtc/webrtcsession_unittest.cc @@ -789,7 +789,7 @@ class WebRtcSessionTest ASSERT_TRUE(video_channel_ != NULL); const cricket::VideoOptions& video_options = video_channel_->options(); EXPECT_EQ(value_expected, - video_options.unsignalled_recv_stream_limit.GetWithDefaultIfUnset(-1)); + video_options.unsignalled_recv_stream_limit.value_or(-1)); } void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1, @@ -3297,20 +3297,18 @@ TEST_F(WebRtcSessionTest, SetAudioSend) { EXPECT_FALSE(channel->IsStreamMuted(send_ssrc)); cricket::AudioOptions options; - options.echo_cancellation.Set(true); + options.echo_cancellation = rtc::Maybe(true); rtc::scoped_ptr renderer(new FakeAudioRenderer()); session_->SetAudioSend(send_ssrc, false, options, renderer.get()); EXPECT_TRUE(channel->IsStreamMuted(send_ssrc)); - EXPECT_FALSE(channel->options().echo_cancellation.IsSet()); + EXPECT_EQ(rtc::Maybe(), channel->options().echo_cancellation); EXPECT_TRUE(renderer->sink() != NULL); // This will trigger SetSink(NULL) to the |renderer|. session_->SetAudioSend(send_ssrc, true, options, NULL); EXPECT_FALSE(channel->IsStreamMuted(send_ssrc)); - bool value; - EXPECT_TRUE(channel->options().echo_cancellation.Get(&value)); - EXPECT_TRUE(value); + EXPECT_EQ(rtc::Maybe(true), channel->options().echo_cancellation); EXPECT_TRUE(renderer->sink() == NULL); } @@ -3993,10 +3991,8 @@ TEST_F(WebRtcSessionTest, TestDscpConstraint) { ASSERT_TRUE(voice_channel_ != NULL); const cricket::AudioOptions& audio_options = voice_channel_->options(); const cricket::VideoOptions& video_options = video_channel_->options(); - EXPECT_TRUE(audio_options.dscp.IsSet()); - EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false)); - EXPECT_TRUE(video_options.dscp.IsSet()); - EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false)); + EXPECT_EQ(rtc::Maybe(true), audio_options.dscp); + EXPECT_EQ(rtc::Maybe(true), video_options.dscp); } TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) { @@ -4014,8 +4010,7 @@ TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) { ASSERT_TRUE(video_channel_ != NULL); const cricket::VideoOptions& video_options = video_channel_->options(); - EXPECT_TRUE( - video_options.suspend_below_min_bitrate.GetWithDefaultIfUnset(false)); + EXPECT_EQ(rtc::Maybe(true), video_options.suspend_below_min_bitrate); } TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) { @@ -4042,8 +4037,7 @@ TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) { ASSERT_TRUE(voice_channel_ != NULL); const cricket::AudioOptions& audio_options = voice_channel_->options(); - EXPECT_TRUE( - audio_options.combined_audio_video_bwe.GetWithDefaultIfUnset(false)); + EXPECT_EQ(rtc::Maybe(true), audio_options.combined_audio_video_bwe); } // Tests that we can renegotiate new media content with ICE candidates in the diff --git a/talk/media/base/mediachannel.h b/talk/media/base/mediachannel.h index 14660847fa..9351420017 100644 --- a/talk/media/base/mediachannel.h +++ b/talk/media/base/mediachannel.h @@ -38,6 +38,7 @@ #include "webrtc/base/buffer.h" #include "webrtc/base/dscp.h" #include "webrtc/base/logging.h" +#include "webrtc/base/maybe.h" #include "webrtc/base/sigslot.h" #include "webrtc/base/socket.h" #include "webrtc/base/window.h" @@ -63,75 +64,13 @@ const int kMinRtpHeaderExtensionId = 1; const int kMaxRtpHeaderExtensionId = 255; const int kScreencastDefaultFps = 5; -// Used in AudioOptions and VideoOptions to signify "unset" values. template -class Settable { - public: - Settable() : set_(false), val_() {} - explicit Settable(T val) : set_(true), val_(val) {} - - bool IsSet() const { - return set_; - } - - bool Get(T* out) const { - *out = val_; - return set_; - } - - T GetWithDefaultIfUnset(const T& default_value) const { - return set_ ? val_ : default_value; - } - - void Set(T val) { - set_ = true; - val_ = val; - } - - void Clear() { - Set(T()); - set_ = false; - } - - void SetFrom(const Settable& o) { - // Set this value based on the value of o, iff o is set. If this value is - // set and o is unset, the current value will be unchanged. - T val; - if (o.Get(&val)) { - Set(val); - } - } - - std::string ToString() const { - return set_ ? rtc::ToString(val_) : ""; - } - - bool operator==(const Settable& o) const { - // Equal if both are unset with any value or both set with the same value. - return (set_ == o.set_) && (!set_ || (val_ == o.val_)); - } - - bool operator!=(const Settable& o) const { - return !operator==(o); - } - - protected: - void InitializeValue(const T &val) { - val_ = val; - } - - private: - bool set_; - T val_; -}; - -template -static std::string ToStringIfSet(const char* key, const Settable& val) { +static std::string ToStringIfSet(const char* key, const rtc::Maybe& val) { std::string str; - if (val.IsSet()) { + if (val) { str = key; str += ": "; - str += val.ToString(); + str += val ? rtc::ToString(*val) : ""; str += ", "; } return str; @@ -157,32 +96,32 @@ static std::string VectorToString(const std::vector& vals) { // but some things currently still use flags. struct AudioOptions { void SetAll(const AudioOptions& change) { - echo_cancellation.SetFrom(change.echo_cancellation); - auto_gain_control.SetFrom(change.auto_gain_control); - noise_suppression.SetFrom(change.noise_suppression); - highpass_filter.SetFrom(change.highpass_filter); - stereo_swapping.SetFrom(change.stereo_swapping); - audio_jitter_buffer_max_packets.SetFrom( - change.audio_jitter_buffer_max_packets); - audio_jitter_buffer_fast_accelerate.SetFrom( - change.audio_jitter_buffer_fast_accelerate); - typing_detection.SetFrom(change.typing_detection); - aecm_generate_comfort_noise.SetFrom(change.aecm_generate_comfort_noise); - conference_mode.SetFrom(change.conference_mode); - adjust_agc_delta.SetFrom(change.adjust_agc_delta); - experimental_agc.SetFrom(change.experimental_agc); - extended_filter_aec.SetFrom(change.extended_filter_aec); - delay_agnostic_aec.SetFrom(change.delay_agnostic_aec); - experimental_ns.SetFrom(change.experimental_ns); - aec_dump.SetFrom(change.aec_dump); - tx_agc_target_dbov.SetFrom(change.tx_agc_target_dbov); - tx_agc_digital_compression_gain.SetFrom( - change.tx_agc_digital_compression_gain); - tx_agc_limiter.SetFrom(change.tx_agc_limiter); - recording_sample_rate.SetFrom(change.recording_sample_rate); - playout_sample_rate.SetFrom(change.playout_sample_rate); - dscp.SetFrom(change.dscp); - combined_audio_video_bwe.SetFrom(change.combined_audio_video_bwe); + SetFrom(&echo_cancellation, change.echo_cancellation); + SetFrom(&auto_gain_control, change.auto_gain_control); + SetFrom(&noise_suppression, change.noise_suppression); + SetFrom(&highpass_filter, change.highpass_filter); + SetFrom(&stereo_swapping, change.stereo_swapping); + SetFrom(&audio_jitter_buffer_max_packets, + change.audio_jitter_buffer_max_packets); + SetFrom(&audio_jitter_buffer_fast_accelerate, + change.audio_jitter_buffer_fast_accelerate); + SetFrom(&typing_detection, change.typing_detection); + SetFrom(&aecm_generate_comfort_noise, change.aecm_generate_comfort_noise); + SetFrom(&conference_mode, change.conference_mode); + SetFrom(&adjust_agc_delta, change.adjust_agc_delta); + SetFrom(&experimental_agc, change.experimental_agc); + SetFrom(&extended_filter_aec, change.extended_filter_aec); + SetFrom(&delay_agnostic_aec, change.delay_agnostic_aec); + SetFrom(&experimental_ns, change.experimental_ns); + SetFrom(&aec_dump, change.aec_dump); + SetFrom(&tx_agc_target_dbov, change.tx_agc_target_dbov); + SetFrom(&tx_agc_digital_compression_gain, + change.tx_agc_digital_compression_gain); + SetFrom(&tx_agc_limiter, change.tx_agc_limiter); + SetFrom(&recording_sample_rate, change.recording_sample_rate); + SetFrom(&playout_sample_rate, change.playout_sample_rate); + SetFrom(&dscp, change.dscp); + SetFrom(&combined_audio_video_bwe, change.combined_audio_video_bwe); } bool operator==(const AudioOptions& o) const { @@ -247,39 +186,47 @@ struct AudioOptions { // Audio processing that attempts to filter away the output signal from // later inbound pickup. - Settable echo_cancellation; + rtc::Maybe echo_cancellation; // Audio processing to adjust the sensitivity of the local mic dynamically. - Settable auto_gain_control; + rtc::Maybe auto_gain_control; // Audio processing to filter out background noise. - Settable noise_suppression; + rtc::Maybe noise_suppression; // Audio processing to remove background noise of lower frequencies. - Settable highpass_filter; + rtc::Maybe highpass_filter; // Audio processing to swap the left and right channels. - Settable stereo_swapping; + rtc::Maybe stereo_swapping; // Audio receiver jitter buffer (NetEq) max capacity in number of packets. - Settable audio_jitter_buffer_max_packets; + rtc::Maybe audio_jitter_buffer_max_packets; // Audio receiver jitter buffer (NetEq) fast accelerate mode. - Settable audio_jitter_buffer_fast_accelerate; + rtc::Maybe audio_jitter_buffer_fast_accelerate; // Audio processing to detect typing. - Settable typing_detection; - Settable aecm_generate_comfort_noise; - Settable conference_mode; - Settable adjust_agc_delta; - Settable experimental_agc; - Settable extended_filter_aec; - Settable delay_agnostic_aec; - Settable experimental_ns; - Settable aec_dump; + rtc::Maybe typing_detection; + rtc::Maybe aecm_generate_comfort_noise; + rtc::Maybe conference_mode; + rtc::Maybe adjust_agc_delta; + rtc::Maybe experimental_agc; + rtc::Maybe extended_filter_aec; + rtc::Maybe delay_agnostic_aec; + rtc::Maybe experimental_ns; + rtc::Maybe aec_dump; // Note that tx_agc_* only applies to non-experimental AGC. - Settable tx_agc_target_dbov; - Settable tx_agc_digital_compression_gain; - Settable tx_agc_limiter; - Settable recording_sample_rate; - Settable playout_sample_rate; + rtc::Maybe tx_agc_target_dbov; + rtc::Maybe tx_agc_digital_compression_gain; + rtc::Maybe tx_agc_limiter; + rtc::Maybe recording_sample_rate; + rtc::Maybe playout_sample_rate; // Set DSCP value for packet sent from audio channel. - Settable dscp; + rtc::Maybe dscp; // Enable combined audio+bandwidth BWE. - Settable combined_audio_video_bwe; + rtc::Maybe combined_audio_video_bwe; + + private: + template + static void SetFrom(rtc::Maybe* s, const rtc::Maybe& o) { + if (o) { + *s = o; + } + } }; // Options that can be applied to a VideoMediaChannel or a VideoMediaEngine. @@ -287,38 +234,39 @@ struct AudioOptions { // We are moving all of the setting of options to structs like this, // but some things currently still use flags. struct VideoOptions { - VideoOptions() { - process_adaptation_threshhold.Set(kProcessCpuThreshold); - system_low_adaptation_threshhold.Set(kLowSystemCpuThreshold); - system_high_adaptation_threshhold.Set(kHighSystemCpuThreshold); - unsignalled_recv_stream_limit.Set(kNumDefaultUnsignalledVideoRecvStreams); - } + VideoOptions() + : process_adaptation_threshhold(kProcessCpuThreshold), + system_low_adaptation_threshhold(kLowSystemCpuThreshold), + system_high_adaptation_threshhold(kHighSystemCpuThreshold), + unsignalled_recv_stream_limit(kNumDefaultUnsignalledVideoRecvStreams) {} void SetAll(const VideoOptions& change) { - adapt_input_to_cpu_usage.SetFrom(change.adapt_input_to_cpu_usage); - adapt_cpu_with_smoothing.SetFrom(change.adapt_cpu_with_smoothing); - video_adapt_third.SetFrom(change.video_adapt_third); - video_noise_reduction.SetFrom(change.video_noise_reduction); - video_start_bitrate.SetFrom(change.video_start_bitrate); - cpu_overuse_detection.SetFrom(change.cpu_overuse_detection); - cpu_underuse_threshold.SetFrom(change.cpu_underuse_threshold); - cpu_overuse_threshold.SetFrom(change.cpu_overuse_threshold); - cpu_underuse_encode_rsd_threshold.SetFrom( - change.cpu_underuse_encode_rsd_threshold); - cpu_overuse_encode_rsd_threshold.SetFrom( - change.cpu_overuse_encode_rsd_threshold); - cpu_overuse_encode_usage.SetFrom(change.cpu_overuse_encode_usage); - conference_mode.SetFrom(change.conference_mode); - process_adaptation_threshhold.SetFrom(change.process_adaptation_threshhold); - system_low_adaptation_threshhold.SetFrom( - change.system_low_adaptation_threshhold); - system_high_adaptation_threshhold.SetFrom( - change.system_high_adaptation_threshhold); - dscp.SetFrom(change.dscp); - suspend_below_min_bitrate.SetFrom(change.suspend_below_min_bitrate); - unsignalled_recv_stream_limit.SetFrom(change.unsignalled_recv_stream_limit); - use_simulcast_adapter.SetFrom(change.use_simulcast_adapter); - screencast_min_bitrate.SetFrom(change.screencast_min_bitrate); + SetFrom(&adapt_input_to_cpu_usage, change.adapt_input_to_cpu_usage); + SetFrom(&adapt_cpu_with_smoothing, change.adapt_cpu_with_smoothing); + SetFrom(&video_adapt_third, change.video_adapt_third); + SetFrom(&video_noise_reduction, change.video_noise_reduction); + SetFrom(&video_start_bitrate, change.video_start_bitrate); + SetFrom(&cpu_overuse_detection, change.cpu_overuse_detection); + SetFrom(&cpu_underuse_threshold, change.cpu_underuse_threshold); + SetFrom(&cpu_overuse_threshold, change.cpu_overuse_threshold); + SetFrom(&cpu_underuse_encode_rsd_threshold, + change.cpu_underuse_encode_rsd_threshold); + SetFrom(&cpu_overuse_encode_rsd_threshold, + change.cpu_overuse_encode_rsd_threshold); + SetFrom(&cpu_overuse_encode_usage, change.cpu_overuse_encode_usage); + SetFrom(&conference_mode, change.conference_mode); + SetFrom(&process_adaptation_threshhold, + change.process_adaptation_threshhold); + SetFrom(&system_low_adaptation_threshhold, + change.system_low_adaptation_threshhold); + SetFrom(&system_high_adaptation_threshhold, + change.system_high_adaptation_threshhold); + SetFrom(&dscp, change.dscp); + SetFrom(&suspend_below_min_bitrate, change.suspend_below_min_bitrate); + SetFrom(&unsignalled_recv_stream_limit, + change.unsignalled_recv_stream_limit); + SetFrom(&use_simulcast_adapter, change.use_simulcast_adapter); + SetFrom(&screencast_min_bitrate, change.screencast_min_bitrate); } bool operator==(const VideoOptions& o) const { @@ -381,56 +329,64 @@ struct VideoOptions { } // Enable CPU adaptation? - Settable adapt_input_to_cpu_usage; + rtc::Maybe adapt_input_to_cpu_usage; // Enable CPU adaptation smoothing? - Settable adapt_cpu_with_smoothing; + rtc::Maybe adapt_cpu_with_smoothing; // Enable video adapt third? - Settable video_adapt_third; + rtc::Maybe video_adapt_third; // Enable denoising? - Settable video_noise_reduction; + rtc::Maybe video_noise_reduction; // Experimental: Enable WebRtc higher start bitrate? - Settable video_start_bitrate; + rtc::Maybe video_start_bitrate; // Enable WebRTC Cpu Overuse Detection, which is a new version of the CPU // adaptation algorithm. So this option will override the // |adapt_input_to_cpu_usage|. - Settable cpu_overuse_detection; + rtc::Maybe cpu_overuse_detection; // Low threshold (t1) for cpu overuse adaptation. (Adapt up) // Metric: encode usage (m1). m1 < t1 => underuse. - Settable cpu_underuse_threshold; + rtc::Maybe cpu_underuse_threshold; // High threshold (t1) for cpu overuse adaptation. (Adapt down) // Metric: encode usage (m1). m1 > t1 => overuse. - Settable cpu_overuse_threshold; + rtc::Maybe cpu_overuse_threshold; // Low threshold (t2) for cpu overuse adaptation. (Adapt up) // Metric: relative standard deviation of encode time (m2). // Optional threshold. If set, (m1 < t1 && m2 < t2) => underuse. // Note: t2 will have no effect if t1 is not set. - Settable cpu_underuse_encode_rsd_threshold; + rtc::Maybe cpu_underuse_encode_rsd_threshold; // High threshold (t2) for cpu overuse adaptation. (Adapt down) // Metric: relative standard deviation of encode time (m2). // Optional threshold. If set, (m1 > t1 || m2 > t2) => overuse. // Note: t2 will have no effect if t1 is not set. - Settable cpu_overuse_encode_rsd_threshold; + rtc::Maybe cpu_overuse_encode_rsd_threshold; // Use encode usage for cpu detection. - Settable cpu_overuse_encode_usage; + rtc::Maybe cpu_overuse_encode_usage; // Use conference mode? - Settable conference_mode; + rtc::Maybe conference_mode; // Threshhold for process cpu adaptation. (Process limit) - Settable process_adaptation_threshhold; + rtc::Maybe process_adaptation_threshhold; // Low threshhold for cpu adaptation. (Adapt up) - Settable system_low_adaptation_threshhold; + rtc::Maybe system_low_adaptation_threshhold; // High threshhold for cpu adaptation. (Adapt down) - Settable system_high_adaptation_threshhold; + rtc::Maybe system_high_adaptation_threshhold; // Set DSCP value for packet sent from video channel. - Settable dscp; + rtc::Maybe dscp; // Enable WebRTC suspension of video. No video frames will be sent when the // bitrate is below the configured minimum bitrate. - Settable suspend_below_min_bitrate; + rtc::Maybe suspend_below_min_bitrate; // Limit on the number of early receive channels that can be created. - Settable unsignalled_recv_stream_limit; + rtc::Maybe unsignalled_recv_stream_limit; // Enable use of simulcast adapter. - Settable use_simulcast_adapter; + rtc::Maybe use_simulcast_adapter; // Force screencast to use a minimum bitrate - Settable screencast_min_bitrate; + rtc::Maybe screencast_min_bitrate; + + private: + template + static void SetFrom(rtc::Maybe* s, const rtc::Maybe& o) { + if (o) { + *s = o; + } + } }; struct RtpHeaderExtension { diff --git a/talk/media/base/videoengine_unittest.h b/talk/media/base/videoengine_unittest.h index d89b3e6f43..539f4680db 100644 --- a/talk/media/base/videoengine_unittest.h +++ b/talk/media/base/videoengine_unittest.h @@ -875,7 +875,7 @@ class VideoMediaChannelTest : public testing::Test, EXPECT_TRUE(SetOneCodec(DefaultCodec())); cricket::VideoSendParameters parameters; parameters.codecs.push_back(DefaultCodec()); - parameters.options.conference_mode.Set(true); + parameters.options.conference_mode = rtc::Maybe(true); EXPECT_TRUE(channel_->SetSendParameters(parameters)); EXPECT_TRUE(SetSend(true)); EXPECT_TRUE(channel_->AddRecvStream( @@ -926,7 +926,7 @@ class VideoMediaChannelTest : public testing::Test, EXPECT_TRUE(SetOneCodec(DefaultCodec())); cricket::VideoSendParameters parameters; parameters.codecs.push_back(DefaultCodec()); - parameters.options.conference_mode.Set(true); + parameters.options.conference_mode = rtc::Maybe(true); EXPECT_TRUE(channel_->SetSendParameters(parameters)); EXPECT_TRUE(channel_->AddRecvStream( cricket::StreamParams::CreateLegacy(kSsrc))); @@ -1236,7 +1236,7 @@ class VideoMediaChannelTest : public testing::Test, EXPECT_TRUE(SetDefaultCodec()); cricket::VideoSendParameters parameters; parameters.codecs.push_back(DefaultCodec()); - parameters.options.conference_mode.Set(true); + parameters.options.conference_mode = rtc::Maybe(true); EXPECT_TRUE(channel_->SetSendParameters(parameters)); EXPECT_TRUE(SetSend(true)); EXPECT_TRUE(channel_->AddRecvStream( @@ -1746,8 +1746,8 @@ class VideoMediaChannelTest : public testing::Test, // Tests that we can send and receive frames with early receive. void TwoStreamsSendAndUnsignalledRecv(const cricket::VideoCodec& codec) { cricket::VideoSendParameters parameters; - parameters.options.conference_mode.Set(true); - parameters.options.unsignalled_recv_stream_limit.Set(1); + parameters.options.conference_mode = rtc::Maybe(true); + parameters.options.unsignalled_recv_stream_limit = rtc::Maybe(1); EXPECT_TRUE(channel_->SetSendParameters(parameters)); SetUpSecondStreamWithNoRecv(); // Test sending and receiving on first stream. @@ -1780,8 +1780,8 @@ class VideoMediaChannelTest : public testing::Test, void TwoStreamsAddAndRemoveUnsignalledRecv( const cricket::VideoCodec& codec) { cricket::VideoOptions vmo; - vmo.conference_mode.Set(true); - vmo.unsignalled_recv_stream_limit.Set(1); + vmo.conference_mode = rtc::Maybe(true); + vmo.unsignalled_recv_stream_limit = rtc::Maybe(1); EXPECT_TRUE(channel_->SetOptions(vmo)); SetUpSecondStreamWithNoRecv(); // Sending and receiving on first stream. diff --git a/talk/media/webrtc/webrtcvideoengine2.cc b/talk/media/webrtc/webrtcvideoengine2.cc index bcd513ee2d..c0c9a8f6b0 100644 --- a/talk/media/webrtc/webrtcvideoengine2.cc +++ b/talk/media/webrtc/webrtcvideoengine2.cc @@ -489,7 +489,8 @@ void* WebRtcVideoChannel2::WebRtcVideoSendStream::ConfigureVideoEncoderSettings( denoising = false; } else { // Use codec default if video_noise_reduction is unset. - codec_default_denoising = !options.video_noise_reduction.Get(&denoising); + codec_default_denoising = !options.video_noise_reduction; + denoising = options.video_noise_reduction.value_or(false); } if (CodecNamesEq(codec.name, kVp8CodecName)) { @@ -777,7 +778,8 @@ WebRtcVideoChannel2::WebRtcVideoChannel2( RTC_DCHECK(thread_checker_.CalledOnValidThread()); SetDefaultOptions(); options_.SetAll(options); - options_.cpu_overuse_detection.Get(&signal_cpu_adaptation_); + if (options_.cpu_overuse_detection) + signal_cpu_adaptation_ = *options_.cpu_overuse_detection; rtcp_receiver_report_ssrc_ = kDefaultRtcpReceiverReportSsrc; sending_ = false; default_send_ssrc_ = 0; @@ -785,10 +787,10 @@ WebRtcVideoChannel2::WebRtcVideoChannel2( } void WebRtcVideoChannel2::SetDefaultOptions() { - options_.cpu_overuse_detection.Set(true); - options_.dscp.Set(false); - options_.suspend_below_min_bitrate.Set(false); - options_.screencast_min_bitrate.Set(0); + options_.cpu_overuse_detection = rtc::Maybe(true); + options_.dscp = rtc::Maybe(false); + options_.suspend_below_min_bitrate = rtc::Maybe(false); + options_.screencast_min_bitrate = rtc::Maybe(0); } WebRtcVideoChannel2::~WebRtcVideoChannel2() { @@ -952,15 +954,15 @@ bool WebRtcVideoChannel2::SetSendCodecs(const std::vector& codecs) { LOG(LS_INFO) << "Using codec: " << supported_codecs.front().codec.ToString(); - VideoCodecSettings old_codec; - if (send_codec_.Get(&old_codec) && supported_codecs.front() == old_codec) { + if (send_codec_ && supported_codecs.front() == *send_codec_) { LOG(LS_INFO) << "Ignore call to SetSendCodecs because first supported " "codec hasn't changed."; // Using same codec, avoid reconfiguring. return true; } - send_codec_.Set(supported_codecs.front()); + send_codec_ = rtc::Maybe( + supported_codecs.front()); rtc::CritScope stream_lock(&stream_crit_); LOG(LS_INFO) << "Change the send codec because SetSendCodecs has a different " @@ -1006,12 +1008,11 @@ bool WebRtcVideoChannel2::SetSendCodecs(const std::vector& codecs) { } bool WebRtcVideoChannel2::GetSendCodec(VideoCodec* codec) { - VideoCodecSettings codec_settings; - if (!send_codec_.Get(&codec_settings)) { + if (!send_codec_) { LOG(LS_VERBOSE) << "GetSendCodec: No send codec set."; return false; } - *codec = codec_settings.codec; + *codec = send_codec_->codec; return true; } @@ -1028,7 +1029,7 @@ bool WebRtcVideoChannel2::SetSendStreamFormat(uint32_t ssrc, bool WebRtcVideoChannel2::SetSend(bool send) { LOG(LS_VERBOSE) << "SetSend: " << (send ? "true" : "false"); - if (send && !send_codec_.IsSet()) { + if (send && !send_codec_) { LOG(LS_ERROR) << "SetSend(true) called before setting codec."; return false; } @@ -1224,11 +1225,7 @@ bool WebRtcVideoChannel2::AddRecvStream(const StreamParams& sp, // Set up A/V sync group based on sync label. config.sync_group = sp.sync_label; - config.rtp.remb = false; - VideoCodecSettings send_codec; - if (send_codec_.Get(&send_codec)) { - config.rtp.remb = HasRemb(send_codec.codec); - } + config.rtp.remb = send_codec_ ? HasRemb(send_codec_->codec) : false; receive_streams_[ssrc] = new WebRtcVideoReceiveStream( call_, sp, config, external_decoder_factory_, default_stream, @@ -1612,11 +1609,11 @@ bool WebRtcVideoChannel2::SetOptions(const VideoOptions& options) { } { rtc::CritScope lock(&capturer_crit_); - options_.cpu_overuse_detection.Get(&signal_cpu_adaptation_); + if (options_.cpu_overuse_detection) + signal_cpu_adaptation_ = *options_.cpu_overuse_detection; } - rtc::DiffServCodePoint dscp = options_.dscp.GetWithDefaultIfUnset(false) - ? rtc::DSCP_AF41 - : rtc::DSCP_DEFAULT; + rtc::DiffServCodePoint dscp = + options_.dscp.value_or(false) ? rtc::DSCP_AF41 : rtc::DSCP_DEFAULT; MediaChannel::SetDscp(dscp); rtc::CritScope stream_lock(&stream_crit_); for (std::map::iterator it = @@ -1708,12 +1705,11 @@ WebRtcVideoChannel2::WebRtcVideoSendStream::VideoSendStreamParameters:: const webrtc::VideoSendStream::Config& config, const VideoOptions& options, int max_bitrate_bps, - const Settable& codec_settings) + const rtc::Maybe& codec_settings) : config(config), options(options), max_bitrate_bps(max_bitrate_bps), - codec_settings(codec_settings) { -} + codec_settings(codec_settings) {} WebRtcVideoChannel2::WebRtcVideoSendStream::AllocatedEncoder::AllocatedEncoder( webrtc::VideoEncoder* encoder, @@ -1737,7 +1733,7 @@ WebRtcVideoChannel2::WebRtcVideoSendStream::WebRtcVideoSendStream( WebRtcVideoEncoderFactory* external_encoder_factory, const VideoOptions& options, int max_bitrate_bps, - const Settable& codec_settings, + const rtc::Maybe& codec_settings, const std::vector& rtp_extensions) : ssrcs_(sp.ssrcs), ssrc_groups_(sp.ssrc_groups), @@ -1760,9 +1756,8 @@ WebRtcVideoChannel2::WebRtcVideoSendStream::WebRtcVideoSendStream( parameters_.config.rtp.c_name = sp.cname; parameters_.config.rtp.extensions = rtp_extensions; - VideoCodecSettings params; - if (codec_settings.Get(¶ms)) { - SetCodec(params); + if (codec_settings) { + SetCodec(*codec_settings); } } @@ -1940,11 +1935,10 @@ void WebRtcVideoChannel2::WebRtcVideoSendStream::SetApplyRotation( void WebRtcVideoChannel2::WebRtcVideoSendStream::SetOptions( const VideoOptions& options) { rtc::CritScope cs(&lock_); - VideoCodecSettings codec_settings; - if (parameters_.codec_settings.Get(&codec_settings)) { + if (parameters_.codec_settings) { LOG(LS_INFO) << "SetCodecAndOptions because of SetOptions; options=" << options.ToString(); - SetCodecAndOptions(codec_settings, options); + SetCodecAndOptions(*parameters_.codec_settings, options); } else { parameters_.options = options; } @@ -2049,10 +2043,12 @@ void WebRtcVideoChannel2::WebRtcVideoSendStream::SetCodecAndOptions( parameters_.config.rtp.nack.rtp_history_ms = HasNack(codec_settings.codec) ? kNackHistoryMs : 0; - options.suspend_below_min_bitrate.Get( - ¶meters_.config.suspend_below_min_bitrate); + RTC_CHECK(options.suspend_below_min_bitrate); + parameters_.config.suspend_below_min_bitrate = + *options.suspend_below_min_bitrate; - parameters_.codec_settings.Set(codec_settings); + parameters_.codec_settings = + rtc::Maybe(codec_settings); parameters_.options = options; LOG(LS_INFO) @@ -2081,11 +2077,9 @@ WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig( const VideoCodec& codec) const { webrtc::VideoEncoderConfig encoder_config; if (dimensions.is_screencast) { - int screencast_min_bitrate_kbps; - parameters_.options.screencast_min_bitrate.Get( - &screencast_min_bitrate_kbps); + RTC_CHECK(parameters_.options.screencast_min_bitrate); encoder_config.min_transmit_bitrate_bps = - screencast_min_bitrate_kbps * 1000; + *parameters_.options.screencast_min_bitrate * 1000; encoder_config.content_type = webrtc::VideoEncoderConfig::ContentType::kScreen; } else { @@ -2121,7 +2115,7 @@ WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig( parameters_.max_bitrate_bps, stream_count); // Conference mode screencast uses 2 temporal layers split at 100kbit. - if (parameters_.options.conference_mode.GetWithDefaultIfUnset(false) && + if (parameters_.options.conference_mode.value_or(false) && dimensions.is_screencast && encoder_config.streams.size() == 1) { ScreenshareLayerConfig config = ScreenshareLayerConfig::GetDefault(); @@ -2156,8 +2150,8 @@ void WebRtcVideoChannel2::WebRtcVideoSendStream::SetDimensions( RTC_DCHECK(!parameters_.encoder_config.streams.empty()); - VideoCodecSettings codec_settings; - parameters_.codec_settings.Get(&codec_settings); + RTC_CHECK(parameters_.codec_settings); + VideoCodecSettings codec_settings = *parameters_.codec_settings; webrtc::VideoEncoderConfig encoder_config = CreateVideoEncoderConfig(last_dimensions_, codec_settings.codec); @@ -2202,9 +2196,8 @@ WebRtcVideoChannel2::WebRtcVideoSendStream::GetVideoSenderInfo() { for (uint32_t ssrc : parameters_.config.rtp.ssrcs) info.add_ssrc(ssrc); - VideoCodecSettings codec_settings; - if (parameters_.codec_settings.Get(&codec_settings)) - info.codec_name = codec_settings.codec.name; + if (parameters_.codec_settings) + info.codec_name = parameters_.codec_settings->codec.name; for (size_t i = 0; i < parameters_.encoder_config.streams.size(); ++i) { if (i == parameters_.encoder_config.streams.size() - 1) { info.preferred_bitrate += @@ -2316,11 +2309,10 @@ void WebRtcVideoChannel2::WebRtcVideoSendStream::RecreateWebRtcStream() { call_->DestroyVideoSendStream(stream_); } - VideoCodecSettings codec_settings; - parameters_.codec_settings.Get(&codec_settings); + RTC_CHECK(parameters_.codec_settings); parameters_.encoder_config.encoder_specific_settings = ConfigureVideoEncoderSettings( - codec_settings.codec, parameters_.options, + parameters_.codec_settings->codec, parameters_.options, parameters_.encoder_config.content_type == webrtc::VideoEncoderConfig::ContentType::kScreen); diff --git a/talk/media/webrtc/webrtcvideoengine2.h b/talk/media/webrtc/webrtcvideoengine2.h index 7096135cdd..f64bcab34e 100644 --- a/talk/media/webrtc/webrtcvideoengine2.h +++ b/talk/media/webrtc/webrtcvideoengine2.h @@ -250,7 +250,7 @@ class WebRtcVideoChannel2 : public rtc::MessageHandler, WebRtcVideoEncoderFactory* external_encoder_factory, const VideoOptions& options, int max_bitrate_bps, - const Settable& codec_settings, + const rtc::Maybe& codec_settings, const std::vector& rtp_extensions); ~WebRtcVideoSendStream(); @@ -286,11 +286,11 @@ class WebRtcVideoChannel2 : public rtc::MessageHandler, const webrtc::VideoSendStream::Config& config, const VideoOptions& options, int max_bitrate_bps, - const Settable& codec_settings); + const rtc::Maybe& codec_settings); webrtc::VideoSendStream::Config config; VideoOptions options; int max_bitrate_bps; - Settable codec_settings; + rtc::Maybe codec_settings; // Sent resolutions + bitrates etc. by the underlying VideoSendStream, // typically changes when setting a new resolution or reconfiguring // bitrates. @@ -512,7 +512,7 @@ class WebRtcVideoChannel2 : public rtc::MessageHandler, std::set send_ssrcs_ GUARDED_BY(stream_crit_); std::set receive_ssrcs_ GUARDED_BY(stream_crit_); - Settable send_codec_; + rtc::Maybe send_codec_; std::vector send_rtp_extensions_; WebRtcVideoEncoderFactory* const external_encoder_factory_; diff --git a/talk/media/webrtc/webrtcvideoengine2_unittest.cc b/talk/media/webrtc/webrtcvideoengine2_unittest.cc index c0cd2ffa50..9f46f7c70e 100644 --- a/talk/media/webrtc/webrtcvideoengine2_unittest.cc +++ b/talk/media/webrtc/webrtcvideoengine2_unittest.cc @@ -1097,7 +1097,7 @@ class WebRtcVideoChannel2Test : public WebRtcVideoEngine2Test { FakeVideoSendStream* SetDenoisingOption( const cricket::VideoSendParameters& parameters, bool enabled) { cricket::VideoSendParameters params = parameters; - params.options.video_noise_reduction.Set(enabled); + params.options.video_noise_reduction = rtc::Maybe(enabled); channel_->SetSendParameters(params); return fake_call_->GetVideoSendStreams().back(); } @@ -1148,7 +1148,7 @@ TEST_F(WebRtcVideoChannel2Test, RecvStreamWithSimAndRtx) { parameters.codecs = engine_.codecs(); EXPECT_TRUE(channel_->SetSendParameters(parameters)); EXPECT_TRUE(channel_->SetSend(true)); - parameters.options.conference_mode.Set(true); + parameters.options.conference_mode = rtc::Maybe(true); EXPECT_TRUE(channel_->SetSendParameters(parameters)); // Send side. @@ -1558,7 +1558,8 @@ TEST_F(WebRtcVideoChannel2Test, UsesCorrectSettingsForScreencast) { cricket::VideoCodec codec = kVp8Codec360p; cricket::VideoSendParameters parameters; parameters.codecs.push_back(codec); - parameters.options.screencast_min_bitrate.Set(kScreenshareMinBitrateKbps); + parameters.options.screencast_min_bitrate = + rtc::Maybe(kScreenshareMinBitrateKbps); EXPECT_TRUE(channel_->SetSendParameters(parameters)); AddSendStream(); @@ -1612,7 +1613,7 @@ TEST_F(WebRtcVideoChannel2Test, ConferenceModeScreencastConfiguresTemporalLayer) { static const int kConferenceScreencastTemporalBitrateBps = ScreenshareLayerConfig::GetDefault().tl0_bitrate_kbps * 1000; - send_parameters_.options.conference_mode.Set(true); + send_parameters_.options.conference_mode = rtc::Maybe(true); channel_->SetSendParameters(send_parameters_); AddSendStream(); @@ -1659,13 +1660,13 @@ TEST_F(WebRtcVideoChannel2Test, SuspendBelowMinBitrateDisabledByDefault) { } TEST_F(WebRtcVideoChannel2Test, SetOptionsWithSuspendBelowMinBitrate) { - send_parameters_.options.suspend_below_min_bitrate.Set(true); + send_parameters_.options.suspend_below_min_bitrate = rtc::Maybe(true); channel_->SetSendParameters(send_parameters_); FakeVideoSendStream* stream = AddSendStream(); EXPECT_TRUE(stream->GetConfig().suspend_below_min_bitrate); - send_parameters_.options.suspend_below_min_bitrate.Set(false); + send_parameters_.options.suspend_below_min_bitrate = rtc::Maybe(false); channel_->SetSendParameters(send_parameters_); stream = fake_call_->GetVideoSendStreams()[0]; @@ -1853,7 +1854,7 @@ void WebRtcVideoChannel2Test::TestCpuAdaptation(bool enable_overuse, cricket::VideoSendParameters parameters; parameters.codecs.push_back(codec); if (!enable_overuse) { - parameters.options.cpu_overuse_detection.Set(false); + parameters.options.cpu_overuse_detection = rtc::Maybe(false); } EXPECT_TRUE(channel_->SetSendParameters(parameters)); @@ -2375,14 +2376,14 @@ TEST_F(WebRtcVideoChannel2Test, TestSetDscpOptions) { cricket::VideoSendParameters parameters = send_parameters_; EXPECT_TRUE(channel_->SetSendParameters(parameters)); EXPECT_EQ(rtc::DSCP_NO_CHANGE, network_interface->dscp()); - parameters.options.dscp.Set(true); + parameters.options.dscp = rtc::Maybe(true); EXPECT_TRUE(channel_->SetSendParameters(parameters)); EXPECT_EQ(rtc::DSCP_AF41, network_interface->dscp()); // Verify previous value is not modified if dscp option is not set. cricket::VideoSendParameters parameters1 = send_parameters_; EXPECT_TRUE(channel_->SetSendParameters(parameters1)); EXPECT_EQ(rtc::DSCP_AF41, network_interface->dscp()); - parameters1.options.dscp.Set(false); + parameters1.options.dscp = rtc::Maybe(false); EXPECT_TRUE(channel_->SetSendParameters(parameters1)); EXPECT_EQ(rtc::DSCP_DEFAULT, network_interface->dscp()); channel_->SetInterface(NULL); @@ -2460,7 +2461,7 @@ TEST_F(WebRtcVideoChannel2Test, GetStatsTracksAdaptationStats) { EXPECT_TRUE(channel_->SetSend(true)); // Verify that the CpuOveruseObserver is registered and trigger downgrade. - parameters.options.cpu_overuse_detection.Set(true); + parameters.options.cpu_overuse_detection = rtc::Maybe(true); EXPECT_TRUE(channel_->SetSendParameters(parameters)); // Trigger overuse. diff --git a/talk/media/webrtc/webrtcvoiceengine.cc b/talk/media/webrtc/webrtcvoiceengine.cc index 27ca1deb2d..a5c8089d10 100644 --- a/talk/media/webrtc/webrtcvoiceengine.cc +++ b/talk/media/webrtc/webrtcvoiceengine.cc @@ -368,20 +368,20 @@ void MaybeFixupG722(webrtc::CodecInst* voe_codec, int new_plfreq) { // ns, and highpass) and the rest hardcoded in InitInternal. AudioOptions GetDefaultEngineOptions() { AudioOptions options; - options.echo_cancellation.Set(true); - options.auto_gain_control.Set(true); - options.noise_suppression.Set(true); - options.highpass_filter.Set(true); - options.stereo_swapping.Set(false); - options.audio_jitter_buffer_max_packets.Set(50); - options.audio_jitter_buffer_fast_accelerate.Set(false); - options.typing_detection.Set(true); - options.adjust_agc_delta.Set(0); - options.experimental_agc.Set(false); - options.extended_filter_aec.Set(false); - options.delay_agnostic_aec.Set(false); - options.experimental_ns.Set(false); - options.aec_dump.Set(false); + options.echo_cancellation = rtc::Maybe(true); + options.auto_gain_control = rtc::Maybe(true); + options.noise_suppression = rtc::Maybe(true); + options.highpass_filter = rtc::Maybe(true); + options.stereo_swapping = rtc::Maybe(false); + options.audio_jitter_buffer_max_packets = rtc::Maybe(50); + options.audio_jitter_buffer_fast_accelerate = rtc::Maybe(false); + options.typing_detection = rtc::Maybe(true); + options.adjust_agc_delta = rtc::Maybe(0); + options.experimental_agc = rtc::Maybe(false); + options.extended_filter_aec = rtc::Maybe(false); + options.delay_agnostic_aec = rtc::Maybe(false); + options.experimental_ns = rtc::Maybe(false); + options.aec_dump = rtc::Maybe(false); return options; } @@ -619,16 +619,16 @@ bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) { webrtc::AecmModes aecm_mode = webrtc::kAecmSpeakerphone; webrtc::AgcModes agc_mode = webrtc::kAgcAdaptiveAnalog; webrtc::NsModes ns_mode = webrtc::kNsHighSuppression; - bool aecm_comfort_noise = false; - if (options.aecm_generate_comfort_noise.Get(&aecm_comfort_noise)) { + if (options.aecm_generate_comfort_noise) { LOG(LS_VERBOSE) << "Comfort noise explicitly set to " - << aecm_comfort_noise << " (default is false)."; + << *options.aecm_generate_comfort_noise + << " (default is false)."; } #if defined(IOS) // On iOS, VPIO provides built-in EC and AGC. - options.echo_cancellation.Set(false); - options.auto_gain_control.Set(false); + options.echo_cancellation = rtc::Maybe(false); + options.auto_gain_control = rtc::Maybe(false); LOG(LS_INFO) << "Always disable AEC and AGC on iOS. Use built-in instead."; #elif defined(ANDROID) ec_mode = webrtc::kEcAecm; @@ -638,20 +638,21 @@ bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) { // Set the AGC mode for iOS as well despite disabling it above, to avoid // unsupported configuration errors from webrtc. agc_mode = webrtc::kAgcFixedDigital; - options.typing_detection.Set(false); - options.experimental_agc.Set(false); - options.extended_filter_aec.Set(false); - options.experimental_ns.Set(false); + options.typing_detection = rtc::Maybe(false); + options.experimental_agc = rtc::Maybe(false); + options.extended_filter_aec = rtc::Maybe(false); + options.experimental_ns = rtc::Maybe(false); #endif // Delay Agnostic AEC automatically turns on EC if not set except on iOS // where the feature is not supported. bool use_delay_agnostic_aec = false; #if !defined(IOS) - if (options.delay_agnostic_aec.Get(&use_delay_agnostic_aec)) { + if (options.delay_agnostic_aec) { + use_delay_agnostic_aec = *options.delay_agnostic_aec; if (use_delay_agnostic_aec) { - options.echo_cancellation.Set(true); - options.extended_filter_aec.Set(true); + options.echo_cancellation = rtc::Maybe(true); + options.extended_filter_aec = rtc::Maybe(true); ec_mode = webrtc::kEcConference; } } @@ -659,8 +660,7 @@ bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) { webrtc::VoEAudioProcessing* voep = voe_wrapper_->processing(); - bool echo_cancellation = false; - if (options.echo_cancellation.Get(&echo_cancellation)) { + if (options.echo_cancellation) { // Check if platform supports built-in EC. Currently only supported on // Android and in combination with Java based audio layer. // TODO(henrika): investigate possibility to support built-in EC also @@ -671,63 +671,61 @@ bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) { // overriding it. Enable/Disable it according to the echo_cancellation // audio option. const bool enable_built_in_aec = - echo_cancellation && !use_delay_agnostic_aec; + *options.echo_cancellation && !use_delay_agnostic_aec; if (voe_wrapper_->hw()->EnableBuiltInAEC(enable_built_in_aec) == 0 && enable_built_in_aec) { // Disable internal software EC if built-in EC is enabled, // i.e., replace the software EC with the built-in EC. - options.echo_cancellation.Set(false); - echo_cancellation = false; + options.echo_cancellation = rtc::Maybe(false); LOG(LS_INFO) << "Disabling EC since built-in EC will be used instead"; } } - if (voep->SetEcStatus(echo_cancellation, ec_mode) == -1) { - LOG_RTCERR2(SetEcStatus, echo_cancellation, ec_mode); + if (voep->SetEcStatus(*options.echo_cancellation, ec_mode) == -1) { + LOG_RTCERR2(SetEcStatus, *options.echo_cancellation, ec_mode); return false; } else { - LOG(LS_INFO) << "Echo control set to " << echo_cancellation + LOG(LS_INFO) << "Echo control set to " << *options.echo_cancellation << " with mode " << ec_mode; } #if !defined(ANDROID) // TODO(ajm): Remove the error return on Android from webrtc. - if (voep->SetEcMetricsStatus(echo_cancellation) == -1) { - LOG_RTCERR1(SetEcMetricsStatus, echo_cancellation); + if (voep->SetEcMetricsStatus(*options.echo_cancellation) == -1) { + LOG_RTCERR1(SetEcMetricsStatus, *options.echo_cancellation); return false; } #endif if (ec_mode == webrtc::kEcAecm) { - if (voep->SetAecmMode(aecm_mode, aecm_comfort_noise) != 0) { - LOG_RTCERR2(SetAecmMode, aecm_mode, aecm_comfort_noise); + bool cn = options.aecm_generate_comfort_noise.value_or(false); + if (voep->SetAecmMode(aecm_mode, cn) != 0) { + LOG_RTCERR2(SetAecmMode, aecm_mode, cn); return false; } } } - bool auto_gain_control = false; - if (options.auto_gain_control.Get(&auto_gain_control)) { + if (options.auto_gain_control) { const bool built_in_agc = voe_wrapper_->hw()->BuiltInAGCIsAvailable(); if (built_in_agc) { - if (voe_wrapper_->hw()->EnableBuiltInAGC(auto_gain_control) == 0 && - auto_gain_control) { + if (voe_wrapper_->hw()->EnableBuiltInAGC(*options.auto_gain_control) == + 0 && + *options.auto_gain_control) { // Disable internal software AGC if built-in AGC is enabled, // i.e., replace the software AGC with the built-in AGC. - options.auto_gain_control.Set(false); - auto_gain_control = false; + options.auto_gain_control = rtc::Maybe(false); LOG(LS_INFO) << "Disabling AGC since built-in AGC will be used instead"; } } - if (voep->SetAgcStatus(auto_gain_control, agc_mode) == -1) { - LOG_RTCERR2(SetAgcStatus, auto_gain_control, agc_mode); + if (voep->SetAgcStatus(*options.auto_gain_control, agc_mode) == -1) { + LOG_RTCERR2(SetAgcStatus, *options.auto_gain_control, agc_mode); return false; } else { - LOG(LS_INFO) << "Auto gain set to " << auto_gain_control << " with mode " - << agc_mode; + LOG(LS_INFO) << "Auto gain set to " << *options.auto_gain_control + << " with mode " << agc_mode; } } - if (options.tx_agc_target_dbov.IsSet() || - options.tx_agc_digital_compression_gain.IsSet() || - options.tx_agc_limiter.IsSet()) { + if (options.tx_agc_target_dbov || options.tx_agc_digital_compression_gain || + options.tx_agc_limiter) { // Override default_agc_config_. Generally, an unset option means "leave // the VoE bits alone" in this function, so we want whatever is set to be // stored as the new "default". If we didn't, then setting e.g. @@ -736,15 +734,13 @@ bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) { // Also, if we don't update default_agc_config_, then adjust_agc_delta // would be an offset from the original values, and not whatever was set // explicitly. - default_agc_config_.targetLeveldBOv = - options.tx_agc_target_dbov.GetWithDefaultIfUnset( - default_agc_config_.targetLeveldBOv); + default_agc_config_.targetLeveldBOv = options.tx_agc_target_dbov.value_or( + default_agc_config_.targetLeveldBOv); default_agc_config_.digitalCompressionGaindB = - options.tx_agc_digital_compression_gain.GetWithDefaultIfUnset( + options.tx_agc_digital_compression_gain.value_or( default_agc_config_.digitalCompressionGaindB); default_agc_config_.limiterEnable = - options.tx_agc_limiter.GetWithDefaultIfUnset( - default_agc_config_.limiterEnable); + options.tx_agc_limiter.value_or(default_agc_config_.limiterEnable); if (voe_wrapper_->processing()->SetAgcConfig(default_agc_config_) == -1) { LOG_RTCERR3(SetAgcConfig, default_agc_config_.targetLeveldBOv, @@ -754,84 +750,79 @@ bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) { } } - bool noise_suppression = false; - if (options.noise_suppression.Get(&noise_suppression)) { + if (options.noise_suppression) { const bool built_in_ns = voe_wrapper_->hw()->BuiltInNSIsAvailable(); if (built_in_ns) { - if (voe_wrapper_->hw()->EnableBuiltInNS(noise_suppression) == 0 && - noise_suppression) { + if (voe_wrapper_->hw()->EnableBuiltInNS(*options.noise_suppression) == + 0 && + *options.noise_suppression) { // Disable internal software NS if built-in NS is enabled, // i.e., replace the software NS with the built-in NS. - options.noise_suppression.Set(false); - noise_suppression = false; + options.noise_suppression = rtc::Maybe(false); LOG(LS_INFO) << "Disabling NS since built-in NS will be used instead"; } } - if (voep->SetNsStatus(noise_suppression, ns_mode) == -1) { - LOG_RTCERR2(SetNsStatus, noise_suppression, ns_mode); + if (voep->SetNsStatus(*options.noise_suppression, ns_mode) == -1) { + LOG_RTCERR2(SetNsStatus, *options.noise_suppression, ns_mode); return false; } else { - LOG(LS_INFO) << "Noise suppression set to " << noise_suppression + LOG(LS_INFO) << "Noise suppression set to " << *options.noise_suppression << " with mode " << ns_mode; } } - bool highpass_filter; - if (options.highpass_filter.Get(&highpass_filter)) { - LOG(LS_INFO) << "High pass filter enabled? " << highpass_filter; - if (voep->EnableHighPassFilter(highpass_filter) == -1) { - LOG_RTCERR1(SetHighpassFilterStatus, highpass_filter); + if (options.highpass_filter) { + LOG(LS_INFO) << "High pass filter enabled? " << *options.highpass_filter; + if (voep->EnableHighPassFilter(*options.highpass_filter) == -1) { + LOG_RTCERR1(SetHighpassFilterStatus, *options.highpass_filter); return false; } } - bool stereo_swapping; - if (options.stereo_swapping.Get(&stereo_swapping)) { - LOG(LS_INFO) << "Stereo swapping enabled? " << stereo_swapping; - voep->EnableStereoChannelSwapping(stereo_swapping); - if (voep->IsStereoChannelSwappingEnabled() != stereo_swapping) { - LOG_RTCERR1(EnableStereoChannelSwapping, stereo_swapping); + if (options.stereo_swapping) { + LOG(LS_INFO) << "Stereo swapping enabled? " << *options.stereo_swapping; + voep->EnableStereoChannelSwapping(*options.stereo_swapping); + if (voep->IsStereoChannelSwappingEnabled() != *options.stereo_swapping) { + LOG_RTCERR1(EnableStereoChannelSwapping, *options.stereo_swapping); return false; } } - int audio_jitter_buffer_max_packets; - if (options.audio_jitter_buffer_max_packets.Get( - &audio_jitter_buffer_max_packets)) { - LOG(LS_INFO) << "NetEq capacity is " << audio_jitter_buffer_max_packets; + if (options.audio_jitter_buffer_max_packets) { + LOG(LS_INFO) << "NetEq capacity is " + << *options.audio_jitter_buffer_max_packets; voe_config_.Set( - new webrtc::NetEqCapacityConfig(audio_jitter_buffer_max_packets)); + new webrtc::NetEqCapacityConfig( + *options.audio_jitter_buffer_max_packets)); } - bool audio_jitter_buffer_fast_accelerate; - if (options.audio_jitter_buffer_fast_accelerate.Get( - &audio_jitter_buffer_fast_accelerate)) { - LOG(LS_INFO) << "NetEq fast mode? " << audio_jitter_buffer_fast_accelerate; + if (options.audio_jitter_buffer_fast_accelerate) { + LOG(LS_INFO) << "NetEq fast mode? " + << *options.audio_jitter_buffer_fast_accelerate; voe_config_.Set( - new webrtc::NetEqFastAccelerate(audio_jitter_buffer_fast_accelerate)); + new webrtc::NetEqFastAccelerate( + *options.audio_jitter_buffer_fast_accelerate)); } - bool typing_detection; - if (options.typing_detection.Get(&typing_detection)) { - LOG(LS_INFO) << "Typing detection is enabled? " << typing_detection; - if (voep->SetTypingDetectionStatus(typing_detection) == -1) { + if (options.typing_detection) { + LOG(LS_INFO) << "Typing detection is enabled? " + << *options.typing_detection; + if (voep->SetTypingDetectionStatus(*options.typing_detection) == -1) { // In case of error, log the info and continue - LOG_RTCERR1(SetTypingDetectionStatus, typing_detection); + LOG_RTCERR1(SetTypingDetectionStatus, *options.typing_detection); } } - int adjust_agc_delta; - if (options.adjust_agc_delta.Get(&adjust_agc_delta)) { - LOG(LS_INFO) << "Adjust agc delta is " << adjust_agc_delta; - if (!AdjustAgcLevel(adjust_agc_delta)) { + if (options.adjust_agc_delta) { + LOG(LS_INFO) << "Adjust agc delta is " << *options.adjust_agc_delta; + if (!AdjustAgcLevel(*options.adjust_agc_delta)) { return false; } } - bool aec_dump; - if (options.aec_dump.Get(&aec_dump)) { - LOG(LS_INFO) << "Aec dump is enabled? " << aec_dump; - if (aec_dump) + if (options.aec_dump) { + LOG(LS_INFO) << "Aec dump is enabled? " << *options.aec_dump; + if (*options.aec_dump) StartAecDump(kAecDumpByAudioOptionFilename); else StopAecDump(); @@ -839,28 +830,30 @@ bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) { webrtc::Config config; - delay_agnostic_aec_.SetFrom(options.delay_agnostic_aec); - bool delay_agnostic_aec; - if (delay_agnostic_aec_.Get(&delay_agnostic_aec)) { - LOG(LS_INFO) << "Delay agnostic aec is enabled? " << delay_agnostic_aec; + if (options.delay_agnostic_aec) + delay_agnostic_aec_ = options.delay_agnostic_aec; + if (delay_agnostic_aec_) { + LOG(LS_INFO) << "Delay agnostic aec is enabled? " << *delay_agnostic_aec_; config.Set( - new webrtc::DelayAgnostic(delay_agnostic_aec)); + new webrtc::DelayAgnostic(*delay_agnostic_aec_)); } - extended_filter_aec_.SetFrom(options.extended_filter_aec); - bool extended_filter; - if (extended_filter_aec_.Get(&extended_filter)) { - LOG(LS_INFO) << "Extended filter aec is enabled? " << extended_filter; + if (options.extended_filter_aec) { + extended_filter_aec_ = options.extended_filter_aec; + } + if (extended_filter_aec_) { + LOG(LS_INFO) << "Extended filter aec is enabled? " << *extended_filter_aec_; config.Set( - new webrtc::ExtendedFilter(extended_filter)); + new webrtc::ExtendedFilter(*extended_filter_aec_)); } - experimental_ns_.SetFrom(options.experimental_ns); - bool experimental_ns; - if (experimental_ns_.Get(&experimental_ns)) { - LOG(LS_INFO) << "Experimental ns is enabled? " << experimental_ns; + if (options.experimental_ns) { + experimental_ns_ = options.experimental_ns; + } + if (experimental_ns_) { + LOG(LS_INFO) << "Experimental ns is enabled? " << *experimental_ns_; config.Set( - new webrtc::ExperimentalNs(experimental_ns)); + new webrtc::ExperimentalNs(*experimental_ns_)); } // We check audioproc for the benefit of tests, since FakeWebRtcVoiceEngine @@ -870,19 +863,20 @@ bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) { audioproc->SetExtraOptions(config); } - uint32_t recording_sample_rate; - if (options.recording_sample_rate.Get(&recording_sample_rate)) { - LOG(LS_INFO) << "Recording sample rate is " << recording_sample_rate; - if (voe_wrapper_->hw()->SetRecordingSampleRate(recording_sample_rate)) { - LOG_RTCERR1(SetRecordingSampleRate, recording_sample_rate); + if (options.recording_sample_rate) { + LOG(LS_INFO) << "Recording sample rate is " + << *options.recording_sample_rate; + if (voe_wrapper_->hw()->SetRecordingSampleRate( + *options.recording_sample_rate)) { + LOG_RTCERR1(SetRecordingSampleRate, *options.recording_sample_rate); } } - uint32_t playout_sample_rate; - if (options.playout_sample_rate.Get(&playout_sample_rate)) { - LOG(LS_INFO) << "Playout sample rate is " << playout_sample_rate; - if (voe_wrapper_->hw()->SetPlayoutSampleRate(playout_sample_rate)) { - LOG_RTCERR1(SetPlayoutSampleRate, playout_sample_rate); + if (options.playout_sample_rate) { + LOG(LS_INFO) << "Playout sample rate is " << *options.playout_sample_rate; + if (voe_wrapper_->hw()->SetPlayoutSampleRate( + *options.playout_sample_rate)) { + LOG_RTCERR1(SetPlayoutSampleRate, *options.playout_sample_rate); } } @@ -1514,7 +1508,7 @@ bool WebRtcVoiceMediaChannel::SetOptions(const AudioOptions& options) { if (dscp_option_changed) { rtc::DiffServCodePoint dscp = rtc::DSCP_DEFAULT; - if (options_.dscp.GetWithDefaultIfUnset(false)) + if (options_.dscp.value_or(false)) dscp = kAudioDscpValue; if (MediaChannel::SetDscp(dscp) != 0) { LOG(LS_WARNING) << "Failed to set DSCP settings for audio channel"; @@ -2857,7 +2851,7 @@ void WebRtcVoiceMediaChannel::AddAudioReceiveStream(uint32_t ssrc) { // Only add RTP extensions if we support combined A/V BWE. config.rtp.extensions = recv_rtp_extensions_; config.combined_audio_video_bwe = - options_.combined_audio_video_bwe.GetWithDefaultIfUnset(false); + options_.combined_audio_video_bwe.value_or(false); config.voe_channel_id = stream->channel(); config.sync_group = receive_stream_params_[ssrc].sync_label; webrtc::AudioReceiveStream* s = call_->CreateAudioReceiveStream(config); diff --git a/talk/media/webrtc/webrtcvoiceengine.h b/talk/media/webrtc/webrtcvoiceengine.h index 1cf05e71a2..d9caf085be 100644 --- a/talk/media/webrtc/webrtcvoiceengine.h +++ b/talk/media/webrtc/webrtcvoiceengine.h @@ -171,9 +171,9 @@ class WebRtcVoiceEngine // values, and apply them in case they are missing in the audio options. We // need to do this because SetExtraOptions() will revert to defaults for // options which are not provided. - Settable extended_filter_aec_; - Settable delay_agnostic_aec_; - Settable experimental_ns_; + rtc::Maybe extended_filter_aec_; + rtc::Maybe delay_agnostic_aec_; + rtc::Maybe experimental_ns_; RTC_DISALLOW_COPY_AND_ASSIGN(WebRtcVoiceEngine); }; diff --git a/talk/media/webrtc/webrtcvoiceengine_unittest.cc b/talk/media/webrtc/webrtcvoiceengine_unittest.cc index ce5115cb10..f61641cb6d 100644 --- a/talk/media/webrtc/webrtcvoiceengine_unittest.cc +++ b/talk/media/webrtc/webrtcvoiceengine_unittest.cc @@ -97,7 +97,7 @@ class WebRtcVoiceEngineTestFake : public testing::Test { channel_(nullptr) { send_parameters_.codecs.push_back(kPcmuCodec); recv_parameters_.codecs.push_back(kPcmuCodec); - options_adjust_agc_.adjust_agc_delta.Set(-10); + options_adjust_agc_.adjust_agc_delta = rtc::Maybe(-10); } bool SetupEngine() { if (!engine_.Init(rtc::Thread::Current())) { @@ -2281,10 +2281,10 @@ TEST_F(WebRtcVoiceEngineTestFake, TxAgcConfigViaOptions) { EXPECT_EQ(0, agc_config.targetLeveldBOv); cricket::AudioOptions options; - options.tx_agc_target_dbov.Set(3); - options.tx_agc_digital_compression_gain.Set(9); - options.tx_agc_limiter.Set(true); - options.auto_gain_control.Set(true); + options.tx_agc_target_dbov = rtc::Maybe(3); + options.tx_agc_digital_compression_gain = rtc::Maybe(9); + options.tx_agc_limiter = rtc::Maybe(true); + options.auto_gain_control = rtc::Maybe(true); EXPECT_TRUE(engine_.SetOptions(options)); EXPECT_EQ(0, voe_.GetAgcConfig(agc_config)); @@ -2294,7 +2294,7 @@ TEST_F(WebRtcVoiceEngineTestFake, TxAgcConfigViaOptions) { // Check interaction with adjust_agc_delta. Both should be respected, for // backwards compatibility. - options.adjust_agc_delta.Set(-10); + options.adjust_agc_delta = rtc::Maybe(-10); EXPECT_TRUE(engine_.SetOptions(options)); EXPECT_EQ(0, voe_.GetAgcConfig(agc_config)); @@ -2304,8 +2304,8 @@ TEST_F(WebRtcVoiceEngineTestFake, TxAgcConfigViaOptions) { TEST_F(WebRtcVoiceEngineTestFake, SampleRatesViaOptions) { EXPECT_TRUE(SetupEngineWithSendStream()); cricket::AudioOptions options; - options.recording_sample_rate.Set(48000u); - options.playout_sample_rate.Set(44100u); + options.recording_sample_rate = rtc::Maybe(48000); + options.playout_sample_rate = rtc::Maybe(44100); EXPECT_TRUE(engine_.SetOptions(options)); unsigned int recording_sample_rate, playout_sample_rate; @@ -2630,14 +2630,14 @@ TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) { voe_.GetNetEqFastAccelerate()); // From GetDefaultEngineOptions(). // Turn echo cancellation off - options.echo_cancellation.Set(false); + options.echo_cancellation = rtc::Maybe(false); ASSERT_TRUE(engine_.SetOptions(options)); voe_.GetEcStatus(ec_enabled, ec_mode); EXPECT_FALSE(ec_enabled); // Turn echo cancellation back on, with settings, and make sure // nothing else changed. - options.echo_cancellation.Set(true); + options.echo_cancellation = rtc::Maybe(true); ASSERT_TRUE(engine_.SetOptions(options)); voe_.GetEcStatus(ec_enabled, ec_mode); voe_.GetAecmMode(aecm_mode, cng_enabled); @@ -2660,7 +2660,7 @@ TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) { // Turn on delay agnostic aec and make sure nothing change w.r.t. echo // control. - options.delay_agnostic_aec.Set(true); + options.delay_agnostic_aec = rtc::Maybe(true); ASSERT_TRUE(engine_.SetOptions(options)); voe_.GetEcStatus(ec_enabled, ec_mode); voe_.GetAecmMode(aecm_mode, cng_enabled); @@ -2669,14 +2669,14 @@ TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) { EXPECT_EQ(ec_mode, webrtc::kEcConference); // Turn off echo cancellation and delay agnostic aec. - options.delay_agnostic_aec.Set(false); - options.extended_filter_aec.Set(false); - options.echo_cancellation.Set(false); + options.delay_agnostic_aec = rtc::Maybe(false); + options.extended_filter_aec = rtc::Maybe(false); + options.echo_cancellation = rtc::Maybe(false); ASSERT_TRUE(engine_.SetOptions(options)); voe_.GetEcStatus(ec_enabled, ec_mode); EXPECT_FALSE(ec_enabled); // Turning delay agnostic aec back on should also turn on echo cancellation. - options.delay_agnostic_aec.Set(true); + options.delay_agnostic_aec = rtc::Maybe(true); ASSERT_TRUE(engine_.SetOptions(options)); voe_.GetEcStatus(ec_enabled, ec_mode); EXPECT_TRUE(ec_enabled); @@ -2684,14 +2684,14 @@ TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) { EXPECT_EQ(ec_mode, webrtc::kEcConference); // Turn off AGC - options.auto_gain_control.Set(false); + options.auto_gain_control = rtc::Maybe(false); ASSERT_TRUE(engine_.SetOptions(options)); voe_.GetAgcStatus(agc_enabled, agc_mode); EXPECT_FALSE(agc_enabled); // Turn AGC back on - options.auto_gain_control.Set(true); - options.adjust_agc_delta.Clear(); + options.auto_gain_control = rtc::Maybe(true); + options.adjust_agc_delta = rtc::Maybe(); ASSERT_TRUE(engine_.SetOptions(options)); voe_.GetAgcStatus(agc_enabled, agc_mode); EXPECT_TRUE(agc_enabled); @@ -2699,10 +2699,10 @@ TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) { EXPECT_EQ(0, agc_config.targetLeveldBOv); // Turn off other options (and stereo swapping on). - options.noise_suppression.Set(false); - options.highpass_filter.Set(false); - options.typing_detection.Set(false); - options.stereo_swapping.Set(true); + options.noise_suppression = rtc::Maybe(false); + options.highpass_filter = rtc::Maybe(false); + options.typing_detection = rtc::Maybe(false); + options.stereo_swapping = rtc::Maybe(true); ASSERT_TRUE(engine_.SetOptions(options)); voe_.GetNsStatus(ns_enabled, ns_mode); highpass_filter_enabled = voe_.IsHighPassFilterEnabled(); @@ -2785,9 +2785,9 @@ TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) { // AEC and AGC and NS cricket::AudioSendParameters parameters_options_all = send_parameters_; - parameters_options_all.options.echo_cancellation.Set(true); - parameters_options_all.options.auto_gain_control.Set(true); - parameters_options_all.options.noise_suppression.Set(true); + parameters_options_all.options.echo_cancellation = rtc::Maybe(true); + parameters_options_all.options.auto_gain_control = rtc::Maybe(true); + parameters_options_all.options.noise_suppression = rtc::Maybe(true); ASSERT_TRUE(channel1->SetSendParameters(parameters_options_all)); EXPECT_EQ(parameters_options_all.options, channel1->options()); ASSERT_TRUE(channel2->SetSendParameters(parameters_options_all)); @@ -2795,21 +2795,21 @@ TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) { // unset NS cricket::AudioSendParameters parameters_options_no_ns = send_parameters_; - parameters_options_no_ns.options.noise_suppression.Set(false); + parameters_options_no_ns.options.noise_suppression = rtc::Maybe(false); ASSERT_TRUE(channel1->SetSendParameters(parameters_options_no_ns)); cricket::AudioOptions expected_options = parameters_options_all.options; - expected_options.echo_cancellation.Set(true); - expected_options.auto_gain_control.Set(true); - expected_options.noise_suppression.Set(false); + expected_options.echo_cancellation = rtc::Maybe(true); + expected_options.auto_gain_control = rtc::Maybe(true); + expected_options.noise_suppression = rtc::Maybe(false); EXPECT_EQ(expected_options, channel1->options()); // unset AGC cricket::AudioSendParameters parameters_options_no_agc = send_parameters_; - parameters_options_no_agc.options.auto_gain_control.Set(false); + parameters_options_no_agc.options.auto_gain_control = rtc::Maybe(false); ASSERT_TRUE(channel2->SetSendParameters(parameters_options_no_agc)); - expected_options.echo_cancellation.Set(true); - expected_options.auto_gain_control.Set(false); - expected_options.noise_suppression.Set(true); + expected_options.echo_cancellation = rtc::Maybe(true); + expected_options.auto_gain_control = rtc::Maybe(false); + expected_options.noise_suppression = rtc::Maybe(true); EXPECT_EQ(expected_options, channel2->options()); ASSERT_TRUE(engine_.SetOptions(parameters_options_all.options)); @@ -2862,13 +2862,15 @@ TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) { ASSERT_TRUE(engine_.SetOptions(parameters_options_all.options)); cricket::AudioSendParameters parameters_options_no_agc_nor_ns = send_parameters_; - parameters_options_no_agc_nor_ns.options.auto_gain_control.Set(false); - parameters_options_no_agc_nor_ns.options.noise_suppression.Set(false); + parameters_options_no_agc_nor_ns.options.auto_gain_control = + rtc::Maybe(false); + parameters_options_no_agc_nor_ns.options.noise_suppression = + rtc::Maybe(false); channel2->SetSend(cricket::SEND_MICROPHONE); channel2->SetSendParameters(parameters_options_no_agc_nor_ns); - expected_options.echo_cancellation.Set(true); - expected_options.auto_gain_control.Set(false); - expected_options.noise_suppression.Set(false); + expected_options.echo_cancellation = rtc::Maybe(true); + expected_options.auto_gain_control = rtc::Maybe(false); + expected_options.noise_suppression = rtc::Maybe(false); EXPECT_EQ(expected_options, channel2->options()); voe_.GetEcStatus(ec_enabled, ec_mode); voe_.GetAgcStatus(agc_enabled, agc_mode); @@ -2887,13 +2889,13 @@ TEST_F(WebRtcVoiceEngineTestFake, TestSetDscpOptions) { new cricket::FakeNetworkInterface); channel->SetInterface(network_interface.get()); cricket::AudioSendParameters parameters = send_parameters_; - parameters.options.dscp.Set(true); + parameters.options.dscp = rtc::Maybe(true); EXPECT_TRUE(channel->SetSendParameters(parameters)); EXPECT_EQ(rtc::DSCP_EF, network_interface->dscp()); // Verify previous value is not modified if dscp option is not set. EXPECT_TRUE(channel->SetSendParameters(send_parameters_)); EXPECT_EQ(rtc::DSCP_EF, network_interface->dscp()); - parameters.options.dscp.Set(false); + parameters.options.dscp = rtc::Maybe(false); EXPECT_TRUE(channel->SetSendParameters(parameters)); EXPECT_EQ(rtc::DSCP_DEFAULT, network_interface->dscp()); } @@ -3002,7 +3004,7 @@ TEST_F(WebRtcVoiceEngineTestFake, CanChangeCombinedBweOption) { } // Enable combined BWE option - now it should be set up. - send_parameters_.options.combined_audio_video_bwe.Set(true); + send_parameters_.options.combined_audio_video_bwe = rtc::Maybe(true); EXPECT_TRUE(media_channel->SetSendParameters(send_parameters_)); for (uint32_t ssrc : ssrcs) { const auto* s = call_.GetAudioReceiveStream(ssrc); @@ -3011,7 +3013,7 @@ TEST_F(WebRtcVoiceEngineTestFake, CanChangeCombinedBweOption) { } // Disable combined BWE option - should be disabled again. - send_parameters_.options.combined_audio_video_bwe.Set(false); + send_parameters_.options.combined_audio_video_bwe = rtc::Maybe(false); EXPECT_TRUE(media_channel->SetSendParameters(send_parameters_)); for (uint32_t ssrc : ssrcs) { const auto* s = call_.GetAudioReceiveStream(ssrc); @@ -3028,7 +3030,7 @@ TEST_F(WebRtcVoiceEngineTestFake, ConfigureCombinedBweForNewRecvStreams) { EXPECT_TRUE(SetupEngineWithSendStream()); cricket::WebRtcVoiceMediaChannel* media_channel = static_cast(channel_); - send_parameters_.options.combined_audio_video_bwe.Set(true); + send_parameters_.options.combined_audio_video_bwe = rtc::Maybe(true); EXPECT_TRUE(media_channel->SetSendParameters(send_parameters_)); static const uint32_t kSsrcs[] = {1, 2, 3, 4}; @@ -3050,7 +3052,7 @@ TEST_F(WebRtcVoiceEngineTestFake, ConfiguresAudioReceiveStreamRtpExtensions) { EXPECT_TRUE(SetupEngineWithSendStream()); cricket::WebRtcVoiceMediaChannel* media_channel = static_cast(channel_); - send_parameters_.options.combined_audio_video_bwe.Set(true); + send_parameters_.options.combined_audio_video_bwe = rtc::Maybe(true); EXPECT_TRUE(media_channel->SetSendParameters(send_parameters_)); for (uint32_t ssrc : ssrcs) { EXPECT_TRUE(media_channel->AddRecvStream( @@ -3109,7 +3111,7 @@ TEST_F(WebRtcVoiceEngineTestFake, DeliverAudioPacket_Call) { EXPECT_TRUE(SetupEngineWithSendStream()); cricket::WebRtcVoiceMediaChannel* media_channel = static_cast(channel_); - send_parameters_.options.combined_audio_video_bwe.Set(true); + send_parameters_.options.combined_audio_video_bwe = rtc::Maybe(true); EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); EXPECT_TRUE(media_channel->AddRecvStream( cricket::StreamParams::CreateLegacy(kAudioSsrc))); @@ -3171,9 +3173,9 @@ TEST(WebRtcVoiceEngineTest, TestDefaultOptionsBeforeInit) { cricket::AudioOptions options = engine.GetOptions(); // The default options should have at least a few things set. We purposefully // don't check the option values here, though. - EXPECT_TRUE(options.echo_cancellation.IsSet()); - EXPECT_TRUE(options.auto_gain_control.IsSet()); - EXPECT_TRUE(options.noise_suppression.IsSet()); + EXPECT_TRUE(options.echo_cancellation); + EXPECT_TRUE(options.auto_gain_control); + EXPECT_TRUE(options.noise_suppression); } // Tests that the library initializes and shuts down properly. diff --git a/talk/session/media/channel.cc b/talk/session/media/channel.cc index 91a6d8cb5a..0e34cbfaac 100644 --- a/talk/session/media/channel.cc +++ b/talk/session/media/channel.cc @@ -1502,7 +1502,7 @@ bool VoiceChannel::SetRemoteContent_w(const MediaContentDescription* content, AudioSendParameters send_params = last_send_params_; RtpSendParametersFromMediaDescription(audio, &send_params); if (audio->agc_minus_10db()) { - send_params.options.adjust_agc_delta.Set(kAgcMinus10db); + send_params.options.adjust_agc_delta = rtc::Maybe(kAgcMinus10db); } if (!media_channel()->SetSendParameters(send_params)) { SafeSetError("Failed to set remote audio description send parameters.", @@ -1789,7 +1789,7 @@ bool VideoChannel::SetRemoteContent_w(const MediaContentDescription* content, VideoSendParameters send_params = last_send_params_; RtpSendParametersFromMediaDescription(video, &send_params); if (video->conference_mode()) { - send_params.options.conference_mode.Set(true); + send_params.options.conference_mode = rtc::Maybe(true); } if (!media_channel()->SetSendParameters(send_params)) { SafeSetError("Failed to set remote video description send parameters.", diff --git a/webrtc/base/maybe.h b/webrtc/base/maybe.h index df204366d5..1df94def3f 100644 --- a/webrtc/base/maybe.h +++ b/webrtc/base/maybe.h @@ -36,10 +36,9 @@ class Maybe final { // Construct an empty Maybe. Maybe() : has_value_(false) {} - // Construct a Maybe that contains a value. Note: These are non-explicit, so - // that a T will implicitly convert to Maybe. - Maybe(const T& val) : value_(val), has_value_(true) {} - Maybe(T&& val) : value_(static_cast(val)), has_value_(true) {} + // Construct a Maybe that contains a value. + explicit Maybe(const T& val) : value_(val), has_value_(true) {} + explicit Maybe(T&& val) : value_(static_cast(val)), has_value_(true) {} // Copy and move constructors. // TODO(kwiberg): =default the move constructor when MSVC supports it. @@ -47,7 +46,7 @@ class Maybe final { Maybe(Maybe&& m) : value_(static_cast(m.value_)), has_value_(m.has_value_) {} - // Assignment. Note that we allow assignment from either Maybe or plain T. + // Assignment. // TODO(kwiberg): =default the move assignment op when MSVC supports it. Maybe& operator=(const Maybe&) = default; Maybe& operator=(Maybe&& m) { @@ -55,16 +54,6 @@ class Maybe final { has_value_ = m.has_value_; return *this; } - Maybe& operator=(const T& val) { - value_ = val; - has_value_ = true; - return *this; - } - Maybe& operator=(T&& val) { - value_ = static_cast(val); - has_value_ = true; - return *this; - } friend void swap(Maybe& m1, Maybe& m2) { using std::swap; diff --git a/webrtc/base/maybe_unittest.cc b/webrtc/base/maybe_unittest.cc index 73fdc90873..f7707d1c81 100644 --- a/webrtc/base/maybe_unittest.cc +++ b/webrtc/base/maybe_unittest.cc @@ -144,7 +144,7 @@ TEST(MaybeTest, TestConstructCopyFull) { auto log = Logger::Setup(); { Logger a; - Maybe x = a; + Maybe x(a); EXPECT_TRUE(x); log->push_back("---"); auto y = x; @@ -173,7 +173,7 @@ TEST(MaybeTest, TestConstructMoveEmpty) { TEST(MaybeTest, TestConstructMoveFull) { auto log = Logger::Setup(); { - Maybe x = Logger(17); + Maybe x(Logger(17)); EXPECT_TRUE(x); log->push_back("---"); auto y = static_cast&&>(x); @@ -203,7 +203,7 @@ TEST(MaybeTest, TestCopyAssignToEmptyFromEmpty) { TEST(MaybeTest, TestCopyAssignToFullFromEmpty) { auto log = Logger::Setup(); { - Maybe x = Logger(17); + Maybe x(Logger(17)); Maybe y; log->push_back("---"); x = y; @@ -221,7 +221,7 @@ TEST(MaybeTest, TestCopyAssignToEmptyFromFull) { auto log = Logger::Setup(); { Maybe x; - Maybe y = Logger(17); + Maybe y(Logger(17)); log->push_back("---"); x = y; log->push_back("---"); @@ -236,8 +236,8 @@ TEST(MaybeTest, TestCopyAssignToEmptyFromFull) { TEST(MaybeTest, TestCopyAssignToFullFromFull) { auto log = Logger::Setup(); { - Maybe x = Logger(17); - Maybe y = Logger(42); + Maybe x(Logger(17)); + Maybe y(Logger(42)); log->push_back("---"); x = y; log->push_back("---"); @@ -257,29 +257,31 @@ TEST(MaybeTest, TestCopyAssignToEmptyFromT) { Maybe x; Logger y(17); log->push_back("---"); - x = y; + x = rtc::Maybe(y); log->push_back("---"); } EXPECT_EQ(V("0:0. default constructor", "1:17. explicit constructor", "---", - "0:17. operator= copy (from 1:17)", "---", "1:17. destructor", - "0:17. destructor"), + "2:17. copy constructor (from 1:17)", + "0:17. operator= move (from 2:17)", "2:17. destructor", "---", + "1:17. destructor", "0:17. destructor"), *log); } TEST(MaybeTest, TestCopyAssignToFullFromT) { auto log = Logger::Setup(); { - Maybe x = Logger(17); + Maybe x(Logger(17)); Logger y(42); log->push_back("---"); - x = y; + x = rtc::Maybe(y); log->push_back("---"); } EXPECT_EQ( V("0:17. explicit constructor", "1:17. move constructor (from 0:17)", "0:17. destructor", "2:42. explicit constructor", "---", - "1:42. operator= copy (from 2:42)", "---", "2:42. destructor", - "1:42. destructor"), + "3:42. copy constructor (from 2:42)", + "1:42. operator= move (from 3:42)", "3:42. destructor", "---", + "2:42. destructor", "1:42. destructor"), *log); } @@ -298,7 +300,7 @@ TEST(MaybeTest, TestMoveAssignToEmptyFromEmpty) { TEST(MaybeTest, TestMoveAssignToFullFromEmpty) { auto log = Logger::Setup(); { - Maybe x = Logger(17); + Maybe x(Logger(17)); Maybe y; log->push_back("---"); x = static_cast&&>(y); @@ -316,7 +318,7 @@ TEST(MaybeTest, TestMoveAssignToEmptyFromFull) { auto log = Logger::Setup(); { Maybe x; - Maybe y = Logger(17); + Maybe y(Logger(17)); log->push_back("---"); x = static_cast&&>(y); log->push_back("---"); @@ -331,8 +333,8 @@ TEST(MaybeTest, TestMoveAssignToEmptyFromFull) { TEST(MaybeTest, TestMoveAssignToFullFromFull) { auto log = Logger::Setup(); { - Maybe x = Logger(17); - Maybe y = Logger(42); + Maybe x(Logger(17)); + Maybe y(Logger(42)); log->push_back("---"); x = static_cast&&>(y); log->push_back("---"); @@ -352,36 +354,38 @@ TEST(MaybeTest, TestMoveAssignToEmptyFromT) { Maybe x; Logger y(17); log->push_back("---"); - x = static_cast(y); + x = rtc::Maybe(static_cast(y)); log->push_back("---"); } EXPECT_EQ(V("0:0. default constructor", "1:17. explicit constructor", "---", - "0:17. operator= move (from 1:17)", "---", "1:17. destructor", - "0:17. destructor"), + "2:17. move constructor (from 1:17)", + "0:17. operator= move (from 2:17)", "2:17. destructor", "---", + "1:17. destructor", "0:17. destructor"), *log); } TEST(MaybeTest, TestMoveAssignToFullFromT) { auto log = Logger::Setup(); { - Maybe x = Logger(17); + Maybe x(Logger(17)); Logger y(42); log->push_back("---"); - x = static_cast(y); + x = rtc::Maybe(static_cast(y)); log->push_back("---"); } EXPECT_EQ( V("0:17. explicit constructor", "1:17. move constructor (from 0:17)", "0:17. destructor", "2:42. explicit constructor", "---", - "1:42. operator= move (from 2:42)", "---", "2:42. destructor", - "1:42. destructor"), + "3:42. move constructor (from 2:42)", + "1:42. operator= move (from 3:42)", "3:42. destructor", "---", + "2:42. destructor", "1:42. destructor"), *log); } TEST(MaybeTest, TestDereference) { auto log = Logger::Setup(); { - Maybe x = Logger(42); + Maybe x(Logger(42)); const auto& y = x; log->push_back("---"); x->Foo(); diff --git a/webrtc/modules/audio_coding/main/acm2/rent_a_codec.cc b/webrtc/modules/audio_coding/main/acm2/rent_a_codec.cc index 42f0a4c7db..bee0275efe 100644 --- a/webrtc/modules/audio_coding/main/acm2/rent_a_codec.cc +++ b/webrtc/modules/audio_coding/main/acm2/rent_a_codec.cc @@ -61,9 +61,10 @@ rtc::Maybe RentACodec::NetEqDecoderFromCodecId(CodecId codec_id, if (!i) return rtc::Maybe(); const NetEqDecoder ned = ACMCodecDB::neteq_decoders_[*i]; - return (ned == NetEqDecoder::kDecoderOpus && num_channels == 2) - ? NetEqDecoder::kDecoderOpus_2ch - : ned; + return rtc::Maybe( + (ned == NetEqDecoder::kDecoderOpus && num_channels == 2) + ? NetEqDecoder::kDecoderOpus_2ch + : ned); } } // namespace acm2 diff --git a/webrtc/modules/audio_coding/main/acm2/rent_a_codec.h b/webrtc/modules/audio_coding/main/acm2/rent_a_codec.h index 55a5d0361a..02749f7423 100644 --- a/webrtc/modules/audio_coding/main/acm2/rent_a_codec.h +++ b/webrtc/modules/audio_coding/main/acm2/rent_a_codec.h @@ -133,12 +133,14 @@ class RentACodec { static inline rtc::Maybe CodecIndexFromId(CodecId codec_id) { const int i = static_cast(codec_id); - return i < static_cast(NumberOfCodecs()) ? i : rtc::Maybe(); + return i < static_cast(NumberOfCodecs()) ? rtc::Maybe(i) + : rtc::Maybe(); } static inline rtc::Maybe CodecIdFromIndex(int codec_index) { return static_cast(codec_index) < NumberOfCodecs() - ? static_cast(codec_index) + ? rtc::Maybe( + static_cast(codec_index)) : rtc::Maybe(); } diff --git a/webrtc/modules/audio_processing/beamformer/array_util.cc b/webrtc/modules/audio_processing/beamformer/array_util.cc index 8aaeee9f59..d97beea972 100644 --- a/webrtc/modules/audio_processing/beamformer/array_util.cc +++ b/webrtc/modules/audio_processing/beamformer/array_util.cc @@ -68,7 +68,7 @@ rtc::Maybe GetDirectionIfLinear( return rtc::Maybe(); } } - return first_pair_direction; + return rtc::Maybe(first_pair_direction); } rtc::Maybe GetNormalIfPlanar(const std::vector& array_geometry) { @@ -95,14 +95,14 @@ rtc::Maybe GetNormalIfPlanar(const std::vector& array_geometry) { return rtc::Maybe(); } } - return normal_direction; + return rtc::Maybe(normal_direction); } rtc::Maybe GetArrayNormalIfExists( const std::vector& array_geometry) { const rtc::Maybe direction = GetDirectionIfLinear(array_geometry); if (direction) { - return Point(direction->y(), -direction->x(), 0.f); + return rtc::Maybe(Point(direction->y(), -direction->x(), 0.f)); } const rtc::Maybe normal = GetNormalIfPlanar(array_geometry); if (normal && normal->z() < kMaxDotProduct) {