From be57983f4bd875c39a229bab5112b32dad004057 Mon Sep 17 00:00:00 2001 From: Karl Wiberg Date: Tue, 10 Nov 2015 22:34:18 +0100 Subject: [PATCH] Rename Maybe to Optional And add examples of good and bad usage to the documentation. R=aluebs@webrtc.org, henrik.lundin@webrtc.org, pthatcher@webrtc.org Review URL: https://codereview.webrtc.org/1432553007 . Cr-Commit-Position: refs/heads/master@{#10588} --- talk/app/webrtc/localaudiosource.cc | 4 +- talk/app/webrtc/localaudiosource_unittest.cc | 24 ++-- talk/app/webrtc/videosource.cc | 4 +- talk/app/webrtc/videosource_unittest.cc | 20 +-- talk/app/webrtc/webrtcsession.cc | 18 +-- talk/app/webrtc/webrtcsession_unittest.cc | 14 +- talk/media/base/mediachannel.h | 94 ++++++------- talk/media/base/videoengine_unittest.h | 14 +- talk/media/webrtc/webrtcvideoengine2.cc | 16 +-- talk/media/webrtc/webrtcvideoengine2.h | 8 +- .../webrtc/webrtcvideoengine2_unittest.cc | 22 +-- talk/media/webrtc/webrtcvoiceengine.cc | 50 +++---- talk/media/webrtc/webrtcvoiceengine.h | 6 +- .../webrtc/webrtcvoiceengine_unittest.cc | 93 ++++++------ talk/session/media/channel.cc | 4 +- webrtc/base/BUILD.gn | 2 +- webrtc/base/base.gyp | 2 +- webrtc/base/base_tests.gyp | 2 +- webrtc/base/{maybe.h => optional.h} | 66 ++++++--- ...maybe_unittest.cc => optional_unittest.cc} | 132 +++++++++--------- .../audio_coding/main/acm2/acm_receiver.cc | 4 +- .../main/acm2/audio_coding_module.cc | 9 +- .../main/acm2/audio_coding_module_impl.cc | 2 +- .../main/acm2/audio_coding_module_impl.h | 2 +- .../audio_coding/main/acm2/codec_manager.cc | 6 +- .../audio_coding/main/acm2/codec_manager.h | 4 +- .../audio_coding/main/acm2/rent_a_codec.cc | 45 +++--- .../audio_coding/main/acm2/rent_a_codec.h | 39 +++--- .../main/include/audio_coding_module.h | 4 +- .../modules/audio_coding/main/test/APITest.cc | 2 +- .../audio_processing/beamformer/array_util.cc | 25 ++-- .../audio_processing/beamformer/array_util.h | 9 +- .../beamformer/nonlinear_beamformer.h | 2 +- 33 files changed, 397 insertions(+), 351 deletions(-) rename webrtc/base/{maybe.h => optional.h} (54%) rename webrtc/base/{maybe_unittest.cc => optional_unittest.cc} (82%) diff --git a/talk/app/webrtc/localaudiosource.cc b/talk/app/webrtc/localaudiosource.cc index 8b4c25206b..591877aa8b 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; - rtc::Maybe& value; + rtc::Optional& 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 = rtc::Maybe(value); + entry.value = rtc::Optional(value); } } } diff --git a/talk/app/webrtc/localaudiosource_unittest.cc b/talk/app/webrtc/localaudiosource_unittest.cc index d36b7cd9c2..75d0c35462 100644 --- a/talk/app/webrtc/localaudiosource_unittest.cc +++ b/talk/app/webrtc/localaudiosource_unittest.cc @@ -58,14 +58,14 @@ TEST(LocalAudioSourceTest, SetValidOptions) { LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(), &constraints); - 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); + EXPECT_EQ(rtc::Optional(false), source->options().echo_cancellation); + EXPECT_EQ(rtc::Optional(true), source->options().extended_filter_aec); + EXPECT_EQ(rtc::Optional(true), source->options().delay_agnostic_aec); + EXPECT_EQ(rtc::Optional(true), source->options().auto_gain_control); + EXPECT_EQ(rtc::Optional(true), source->options().experimental_agc); + EXPECT_EQ(rtc::Optional(false), source->options().noise_suppression); + EXPECT_EQ(rtc::Optional(true), source->options().highpass_filter); + EXPECT_EQ(rtc::Optional(true), source->options().aec_dump); } TEST(LocalAudioSourceTest, OptionNotSet) { @@ -73,7 +73,7 @@ TEST(LocalAudioSourceTest, OptionNotSet) { rtc::scoped_refptr source = LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(), &constraints); - EXPECT_EQ(rtc::Maybe(), source->options().highpass_filter); + EXPECT_EQ(rtc::Optional(), source->options().highpass_filter); } TEST(LocalAudioSourceTest, MandatoryOverridesOptional) { @@ -87,7 +87,7 @@ TEST(LocalAudioSourceTest, MandatoryOverridesOptional) { LocalAudioSource::Create(PeerConnectionFactoryInterface::Options(), &constraints); - EXPECT_EQ(rtc::Maybe(false), source->options().echo_cancellation); + EXPECT_EQ(rtc::Optional(false), source->options().echo_cancellation); } TEST(LocalAudioSourceTest, InvalidOptional) { @@ -100,7 +100,7 @@ TEST(LocalAudioSourceTest, InvalidOptional) { &constraints); EXPECT_EQ(MediaSourceInterface::kLive, source->state()); - EXPECT_EQ(rtc::Maybe(false), source->options().highpass_filter); + EXPECT_EQ(rtc::Optional(false), source->options().highpass_filter); } TEST(LocalAudioSourceTest, InvalidMandatory) { @@ -113,5 +113,5 @@ TEST(LocalAudioSourceTest, InvalidMandatory) { &constraints); EXPECT_EQ(MediaSourceInterface::kLive, source->state()); - EXPECT_EQ(rtc::Maybe(false), source->options().highpass_filter); + EXPECT_EQ(rtc::Optional(false), source->options().highpass_filter); } diff --git a/talk/app/webrtc/videosource.cc b/talk/app/webrtc/videosource.cc index bed1be94db..7331e0e7a4 100644 --- a/talk/app/webrtc/videosource.cc +++ b/talk/app/webrtc/videosource.cc @@ -268,11 +268,11 @@ const cricket::VideoFormat& GetBestCaptureFormat( // Return false if the key is mandatory, and the value is invalid. bool ExtractOption(const MediaConstraintsInterface* all_constraints, const std::string& key, - rtc::Maybe* option) { + rtc::Optional* option) { size_t mandatory = 0; bool value; if (FindConstraint(all_constraints, key, &value, &mandatory)) { - *option = rtc::Maybe(value); + *option = rtc::Optional(value); return true; } diff --git a/talk/app/webrtc/videosource_unittest.cc b/talk/app/webrtc/videosource_unittest.cc index f7dfe97542..8d6d6ac9bf 100644 --- a/talk/app/webrtc/videosource_unittest.cc +++ b/talk/app/webrtc/videosource_unittest.cc @@ -392,13 +392,14 @@ TEST_F(VideoSourceTest, SetValidOptionValues) { CreateVideoSource(&constraints); - EXPECT_EQ(rtc::Maybe(false), source_->options()->video_noise_reduction); + EXPECT_EQ(rtc::Optional(false), + source_->options()->video_noise_reduction); } TEST_F(VideoSourceTest, OptionNotSet) { FakeConstraints constraints; CreateVideoSource(&constraints); - EXPECT_EQ(rtc::Maybe(), source_->options()->video_noise_reduction); + EXPECT_EQ(rtc::Optional(), source_->options()->video_noise_reduction); } TEST_F(VideoSourceTest, MandatoryOptionOverridesOptional) { @@ -410,7 +411,8 @@ TEST_F(VideoSourceTest, MandatoryOptionOverridesOptional) { CreateVideoSource(&constraints); - EXPECT_EQ(rtc::Maybe(true), source_->options()->video_noise_reduction); + EXPECT_EQ(rtc::Optional(true), + source_->options()->video_noise_reduction); } TEST_F(VideoSourceTest, InvalidOptionKeyOptional) { @@ -423,7 +425,8 @@ TEST_F(VideoSourceTest, InvalidOptionKeyOptional) { EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(), kMaxWaitMs); - EXPECT_EQ(rtc::Maybe(false), source_->options()->video_noise_reduction); + EXPECT_EQ(rtc::Optional(false), + source_->options()->video_noise_reduction); } TEST_F(VideoSourceTest, InvalidOptionKeyMandatory) { @@ -436,7 +439,7 @@ TEST_F(VideoSourceTest, InvalidOptionKeyMandatory) { EXPECT_EQ_WAIT(MediaSourceInterface::kEnded, state_observer_->state(), kMaxWaitMs); - EXPECT_EQ(rtc::Maybe(), source_->options()->video_noise_reduction); + EXPECT_EQ(rtc::Optional(), source_->options()->video_noise_reduction); } TEST_F(VideoSourceTest, InvalidOptionValueOptional) { @@ -448,7 +451,7 @@ TEST_F(VideoSourceTest, InvalidOptionValueOptional) { EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(), kMaxWaitMs); - EXPECT_EQ(rtc::Maybe(), source_->options()->video_noise_reduction); + EXPECT_EQ(rtc::Optional(), source_->options()->video_noise_reduction); } TEST_F(VideoSourceTest, InvalidOptionValueMandatory) { @@ -464,7 +467,7 @@ TEST_F(VideoSourceTest, InvalidOptionValueMandatory) { EXPECT_EQ_WAIT(MediaSourceInterface::kEnded, state_observer_->state(), kMaxWaitMs); - EXPECT_EQ(rtc::Maybe(), source_->options()->video_noise_reduction); + EXPECT_EQ(rtc::Optional(), source_->options()->video_noise_reduction); } TEST_F(VideoSourceTest, MixedOptionsAndConstraints) { @@ -487,7 +490,8 @@ TEST_F(VideoSourceTest, MixedOptionsAndConstraints) { EXPECT_EQ(288, format->height); EXPECT_EQ(30, format->framerate()); - EXPECT_EQ(rtc::Maybe(false), source_->options()->video_noise_reduction); + EXPECT_EQ(rtc::Optional(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 5b58c24319..11b2d602a2 100644 --- a/talk/app/webrtc/webrtcsession.cc +++ b/talk/app/webrtc/webrtcsession.cc @@ -445,7 +445,7 @@ template static void SetOptionFromOptionalConstraint( const MediaConstraintsInterface* constraints, const std::string& key, - rtc::Maybe* option) { + rtc::Optional* option) { if (!constraints) { return; } @@ -453,7 +453,7 @@ static void SetOptionFromOptionalConstraint( T value; if (constraints->GetOptional().FindFirst(key, &string_value)) { if (rtc::FromString(string_value, &value)) { - *option = rtc::Maybe(value); + *option = rtc::Optional(value); } } } @@ -645,8 +645,8 @@ bool WebRtcSession::Initialize( constraints, MediaConstraintsInterface::kEnableDscp, &value, NULL)) { - audio_options_.dscp = rtc::Maybe(value); - video_options_.dscp = rtc::Maybe(value); + audio_options_.dscp = rtc::Optional(value); + video_options_.dscp = rtc::Optional(value); } // Find Suspend Below Min Bitrate constraint. @@ -655,7 +655,7 @@ bool WebRtcSession::Initialize( MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate, &value, NULL)) { - video_options_.suspend_below_min_bitrate = rtc::Maybe(value); + video_options_.suspend_below_min_bitrate = rtc::Optional(value); } SetOptionFromOptionalConstraint(constraints, @@ -686,7 +686,7 @@ bool WebRtcSession::Initialize( MediaConstraintsInterface::kNumUnsignalledRecvStreams, &video_options_.unsignalled_recv_stream_limit); if (video_options_.unsignalled_recv_stream_limit) { - video_options_.unsignalled_recv_stream_limit = rtc::Maybe( + video_options_.unsignalled_recv_stream_limit = rtc::Optional( std::max(0, std::min(kMaxUnsignalledRecvStreams, *video_options_.unsignalled_recv_stream_limit))); } @@ -700,10 +700,10 @@ bool WebRtcSession::Initialize( &audio_options_.combined_audio_video_bwe); audio_options_.audio_jitter_buffer_max_packets = - rtc::Maybe(rtc_configuration.audio_jitter_buffer_max_packets); + rtc::Optional(rtc_configuration.audio_jitter_buffer_max_packets); - audio_options_.audio_jitter_buffer_fast_accelerate = - rtc::Maybe(rtc_configuration.audio_jitter_buffer_fast_accelerate); + audio_options_.audio_jitter_buffer_fast_accelerate = rtc::Optional( + 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 568f5fef89..3ce8c7a418 100644 --- a/talk/app/webrtc/webrtcsession_unittest.cc +++ b/talk/app/webrtc/webrtcsession_unittest.cc @@ -3297,18 +3297,18 @@ TEST_F(WebRtcSessionTest, SetAudioSend) { EXPECT_FALSE(channel->IsStreamMuted(send_ssrc)); cricket::AudioOptions options; - options.echo_cancellation = rtc::Maybe(true); + options.echo_cancellation = rtc::Optional(true); rtc::scoped_ptr renderer(new FakeAudioRenderer()); session_->SetAudioSend(send_ssrc, false, options, renderer.get()); EXPECT_TRUE(channel->IsStreamMuted(send_ssrc)); - EXPECT_EQ(rtc::Maybe(), channel->options().echo_cancellation); + EXPECT_EQ(rtc::Optional(), 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)); - EXPECT_EQ(rtc::Maybe(true), channel->options().echo_cancellation); + EXPECT_EQ(rtc::Optional(true), channel->options().echo_cancellation); EXPECT_TRUE(renderer->sink() == NULL); } @@ -3991,8 +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_EQ(rtc::Maybe(true), audio_options.dscp); - EXPECT_EQ(rtc::Maybe(true), video_options.dscp); + EXPECT_EQ(rtc::Optional(true), audio_options.dscp); + EXPECT_EQ(rtc::Optional(true), video_options.dscp); } TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) { @@ -4010,7 +4010,7 @@ TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) { ASSERT_TRUE(video_channel_ != NULL); const cricket::VideoOptions& video_options = video_channel_->options(); - EXPECT_EQ(rtc::Maybe(true), video_options.suspend_below_min_bitrate); + EXPECT_EQ(rtc::Optional(true), video_options.suspend_below_min_bitrate); } TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) { @@ -4037,7 +4037,7 @@ TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) { ASSERT_TRUE(voice_channel_ != NULL); const cricket::AudioOptions& audio_options = voice_channel_->options(); - EXPECT_EQ(rtc::Maybe(true), audio_options.combined_audio_video_bwe); + EXPECT_EQ(rtc::Optional(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 9351420017..fb828ef6c6 100644 --- a/talk/media/base/mediachannel.h +++ b/talk/media/base/mediachannel.h @@ -38,7 +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/optional.h" #include "webrtc/base/sigslot.h" #include "webrtc/base/socket.h" #include "webrtc/base/window.h" @@ -65,7 +65,7 @@ const int kMaxRtpHeaderExtensionId = 255; const int kScreencastDefaultFps = 5; template -static std::string ToStringIfSet(const char* key, const rtc::Maybe& val) { +static std::string ToStringIfSet(const char* key, const rtc::Optional& val) { std::string str; if (val) { str = key; @@ -186,43 +186,43 @@ struct AudioOptions { // Audio processing that attempts to filter away the output signal from // later inbound pickup. - rtc::Maybe echo_cancellation; + rtc::Optional echo_cancellation; // Audio processing to adjust the sensitivity of the local mic dynamically. - rtc::Maybe auto_gain_control; + rtc::Optional auto_gain_control; // Audio processing to filter out background noise. - rtc::Maybe noise_suppression; + rtc::Optional noise_suppression; // Audio processing to remove background noise of lower frequencies. - rtc::Maybe highpass_filter; + rtc::Optional highpass_filter; // Audio processing to swap the left and right channels. - rtc::Maybe stereo_swapping; + rtc::Optional stereo_swapping; // Audio receiver jitter buffer (NetEq) max capacity in number of packets. - rtc::Maybe audio_jitter_buffer_max_packets; + rtc::Optional audio_jitter_buffer_max_packets; // Audio receiver jitter buffer (NetEq) fast accelerate mode. - rtc::Maybe audio_jitter_buffer_fast_accelerate; + rtc::Optional audio_jitter_buffer_fast_accelerate; // Audio processing to detect typing. - 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; + rtc::Optional typing_detection; + rtc::Optional aecm_generate_comfort_noise; + rtc::Optional conference_mode; + rtc::Optional adjust_agc_delta; + rtc::Optional experimental_agc; + rtc::Optional extended_filter_aec; + rtc::Optional delay_agnostic_aec; + rtc::Optional experimental_ns; + rtc::Optional aec_dump; // Note that tx_agc_* only applies to non-experimental AGC. - 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; + rtc::Optional tx_agc_target_dbov; + rtc::Optional tx_agc_digital_compression_gain; + rtc::Optional tx_agc_limiter; + rtc::Optional recording_sample_rate; + rtc::Optional playout_sample_rate; // Set DSCP value for packet sent from audio channel. - rtc::Maybe dscp; + rtc::Optional dscp; // Enable combined audio+bandwidth BWE. - rtc::Maybe combined_audio_video_bwe; + rtc::Optional combined_audio_video_bwe; private: template - static void SetFrom(rtc::Maybe* s, const rtc::Maybe& o) { + static void SetFrom(rtc::Optional* s, const rtc::Optional& o) { if (o) { *s = o; } @@ -329,60 +329,60 @@ struct VideoOptions { } // Enable CPU adaptation? - rtc::Maybe adapt_input_to_cpu_usage; + rtc::Optional adapt_input_to_cpu_usage; // Enable CPU adaptation smoothing? - rtc::Maybe adapt_cpu_with_smoothing; + rtc::Optional adapt_cpu_with_smoothing; // Enable video adapt third? - rtc::Maybe video_adapt_third; + rtc::Optional video_adapt_third; // Enable denoising? - rtc::Maybe video_noise_reduction; + rtc::Optional video_noise_reduction; // Experimental: Enable WebRtc higher start bitrate? - rtc::Maybe video_start_bitrate; + rtc::Optional 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|. - rtc::Maybe cpu_overuse_detection; + rtc::Optional cpu_overuse_detection; // Low threshold (t1) for cpu overuse adaptation. (Adapt up) // Metric: encode usage (m1). m1 < t1 => underuse. - rtc::Maybe cpu_underuse_threshold; + rtc::Optional cpu_underuse_threshold; // High threshold (t1) for cpu overuse adaptation. (Adapt down) // Metric: encode usage (m1). m1 > t1 => overuse. - rtc::Maybe cpu_overuse_threshold; + rtc::Optional 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. - rtc::Maybe cpu_underuse_encode_rsd_threshold; + rtc::Optional 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. - rtc::Maybe cpu_overuse_encode_rsd_threshold; + rtc::Optional cpu_overuse_encode_rsd_threshold; // Use encode usage for cpu detection. - rtc::Maybe cpu_overuse_encode_usage; + rtc::Optional cpu_overuse_encode_usage; // Use conference mode? - rtc::Maybe conference_mode; + rtc::Optional conference_mode; // Threshhold for process cpu adaptation. (Process limit) - rtc::Maybe process_adaptation_threshhold; + rtc::Optional process_adaptation_threshhold; // Low threshhold for cpu adaptation. (Adapt up) - rtc::Maybe system_low_adaptation_threshhold; + rtc::Optional system_low_adaptation_threshhold; // High threshhold for cpu adaptation. (Adapt down) - rtc::Maybe system_high_adaptation_threshhold; + rtc::Optional system_high_adaptation_threshhold; // Set DSCP value for packet sent from video channel. - rtc::Maybe dscp; + rtc::Optional dscp; // Enable WebRTC suspension of video. No video frames will be sent when the // bitrate is below the configured minimum bitrate. - rtc::Maybe suspend_below_min_bitrate; + rtc::Optional suspend_below_min_bitrate; // Limit on the number of early receive channels that can be created. - rtc::Maybe unsignalled_recv_stream_limit; + rtc::Optional unsignalled_recv_stream_limit; // Enable use of simulcast adapter. - rtc::Maybe use_simulcast_adapter; + rtc::Optional use_simulcast_adapter; // Force screencast to use a minimum bitrate - rtc::Maybe screencast_min_bitrate; + rtc::Optional screencast_min_bitrate; private: template - static void SetFrom(rtc::Maybe* s, const rtc::Maybe& o) { + static void SetFrom(rtc::Optional* s, const rtc::Optional& o) { if (o) { *s = o; } diff --git a/talk/media/base/videoengine_unittest.h b/talk/media/base/videoengine_unittest.h index 539f4680db..ef579cc961 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 = rtc::Maybe(true); + parameters.options.conference_mode = rtc::Optional(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 = rtc::Maybe(true); + parameters.options.conference_mode = rtc::Optional(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 = rtc::Maybe(true); + parameters.options.conference_mode = rtc::Optional(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 = rtc::Maybe(true); - parameters.options.unsignalled_recv_stream_limit = rtc::Maybe(1); + parameters.options.conference_mode = rtc::Optional(true); + parameters.options.unsignalled_recv_stream_limit = rtc::Optional(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 = rtc::Maybe(true); - vmo.unsignalled_recv_stream_limit = rtc::Maybe(1); + vmo.conference_mode = rtc::Optional(true); + vmo.unsignalled_recv_stream_limit = rtc::Optional(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 0c19a4114e..101ed15bdd 100644 --- a/talk/media/webrtc/webrtcvideoengine2.cc +++ b/talk/media/webrtc/webrtcvideoengine2.cc @@ -786,10 +786,10 @@ WebRtcVideoChannel2::WebRtcVideoChannel2( } void WebRtcVideoChannel2::SetDefaultOptions() { - 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); + options_.cpu_overuse_detection = rtc::Optional(true); + options_.dscp = rtc::Optional(false); + options_.suspend_below_min_bitrate = rtc::Optional(false); + options_.screencast_min_bitrate = rtc::Optional(0); } WebRtcVideoChannel2::~WebRtcVideoChannel2() { @@ -960,7 +960,7 @@ bool WebRtcVideoChannel2::SetSendCodecs(const std::vector& codecs) { return true; } - send_codec_ = rtc::Maybe( + send_codec_ = rtc::Optional( supported_codecs.front()); rtc::CritScope stream_lock(&stream_crit_); @@ -1704,7 +1704,7 @@ WebRtcVideoChannel2::WebRtcVideoSendStream::VideoSendStreamParameters:: const webrtc::VideoSendStream::Config& config, const VideoOptions& options, int max_bitrate_bps, - const rtc::Maybe& codec_settings) + const rtc::Optional& codec_settings) : config(config), options(options), max_bitrate_bps(max_bitrate_bps), @@ -1732,7 +1732,7 @@ WebRtcVideoChannel2::WebRtcVideoSendStream::WebRtcVideoSendStream( WebRtcVideoEncoderFactory* external_encoder_factory, const VideoOptions& options, int max_bitrate_bps, - const rtc::Maybe& codec_settings, + const rtc::Optional& codec_settings, const std::vector& rtp_extensions) : ssrcs_(sp.ssrcs), ssrc_groups_(sp.ssrc_groups), @@ -2047,7 +2047,7 @@ void WebRtcVideoChannel2::WebRtcVideoSendStream::SetCodecAndOptions( *options.suspend_below_min_bitrate; parameters_.codec_settings = - rtc::Maybe(codec_settings); + rtc::Optional(codec_settings); parameters_.options = options; LOG(LS_INFO) diff --git a/talk/media/webrtc/webrtcvideoengine2.h b/talk/media/webrtc/webrtcvideoengine2.h index f64bcab34e..05f73d1358 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 rtc::Maybe& codec_settings, + const rtc::Optional& 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 rtc::Maybe& codec_settings); + const rtc::Optional& codec_settings); webrtc::VideoSendStream::Config config; VideoOptions options; int max_bitrate_bps; - rtc::Maybe codec_settings; + rtc::Optional 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_); - rtc::Maybe send_codec_; + rtc::Optional 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 9f46f7c70e..87a0ac81a9 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 = rtc::Maybe(enabled); + params.options.video_noise_reduction = rtc::Optional(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 = rtc::Maybe(true); + parameters.options.conference_mode = rtc::Optional(true); EXPECT_TRUE(channel_->SetSendParameters(parameters)); // Send side. @@ -1559,7 +1559,7 @@ TEST_F(WebRtcVideoChannel2Test, UsesCorrectSettingsForScreencast) { cricket::VideoSendParameters parameters; parameters.codecs.push_back(codec); parameters.options.screencast_min_bitrate = - rtc::Maybe(kScreenshareMinBitrateKbps); + rtc::Optional(kScreenshareMinBitrateKbps); EXPECT_TRUE(channel_->SetSendParameters(parameters)); AddSendStream(); @@ -1613,7 +1613,7 @@ TEST_F(WebRtcVideoChannel2Test, ConferenceModeScreencastConfiguresTemporalLayer) { static const int kConferenceScreencastTemporalBitrateBps = ScreenshareLayerConfig::GetDefault().tl0_bitrate_kbps * 1000; - send_parameters_.options.conference_mode = rtc::Maybe(true); + send_parameters_.options.conference_mode = rtc::Optional(true); channel_->SetSendParameters(send_parameters_); AddSendStream(); @@ -1660,13 +1660,15 @@ TEST_F(WebRtcVideoChannel2Test, SuspendBelowMinBitrateDisabledByDefault) { } TEST_F(WebRtcVideoChannel2Test, SetOptionsWithSuspendBelowMinBitrate) { - send_parameters_.options.suspend_below_min_bitrate = rtc::Maybe(true); + send_parameters_.options.suspend_below_min_bitrate = + rtc::Optional(true); channel_->SetSendParameters(send_parameters_); FakeVideoSendStream* stream = AddSendStream(); EXPECT_TRUE(stream->GetConfig().suspend_below_min_bitrate); - send_parameters_.options.suspend_below_min_bitrate = rtc::Maybe(false); + send_parameters_.options.suspend_below_min_bitrate = + rtc::Optional(false); channel_->SetSendParameters(send_parameters_); stream = fake_call_->GetVideoSendStreams()[0]; @@ -1854,7 +1856,7 @@ void WebRtcVideoChannel2Test::TestCpuAdaptation(bool enable_overuse, cricket::VideoSendParameters parameters; parameters.codecs.push_back(codec); if (!enable_overuse) { - parameters.options.cpu_overuse_detection = rtc::Maybe(false); + parameters.options.cpu_overuse_detection = rtc::Optional(false); } EXPECT_TRUE(channel_->SetSendParameters(parameters)); @@ -2376,14 +2378,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 = rtc::Maybe(true); + parameters.options.dscp = rtc::Optional(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 = rtc::Maybe(false); + parameters1.options.dscp = rtc::Optional(false); EXPECT_TRUE(channel_->SetSendParameters(parameters1)); EXPECT_EQ(rtc::DSCP_DEFAULT, network_interface->dscp()); channel_->SetInterface(NULL); @@ -2461,7 +2463,7 @@ TEST_F(WebRtcVideoChannel2Test, GetStatsTracksAdaptationStats) { EXPECT_TRUE(channel_->SetSend(true)); // Verify that the CpuOveruseObserver is registered and trigger downgrade. - parameters.options.cpu_overuse_detection = rtc::Maybe(true); + parameters.options.cpu_overuse_detection = rtc::Optional(true); EXPECT_TRUE(channel_->SetSendParameters(parameters)); // Trigger overuse. diff --git a/talk/media/webrtc/webrtcvoiceengine.cc b/talk/media/webrtc/webrtcvoiceengine.cc index 37df244f4f..ba6408fbec 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 = 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); + options.echo_cancellation = rtc::Optional(true); + options.auto_gain_control = rtc::Optional(true); + options.noise_suppression = rtc::Optional(true); + options.highpass_filter = rtc::Optional(true); + options.stereo_swapping = rtc::Optional(false); + options.audio_jitter_buffer_max_packets = rtc::Optional(50); + options.audio_jitter_buffer_fast_accelerate = rtc::Optional(false); + options.typing_detection = rtc::Optional(true); + options.adjust_agc_delta = rtc::Optional(0); + options.experimental_agc = rtc::Optional(false); + options.extended_filter_aec = rtc::Optional(false); + options.delay_agnostic_aec = rtc::Optional(false); + options.experimental_ns = rtc::Optional(false); + options.aec_dump = rtc::Optional(false); return options; } @@ -640,8 +640,8 @@ bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) { #if defined(IOS) // On iOS, VPIO provides built-in EC and AGC. - options.echo_cancellation = rtc::Maybe(false); - options.auto_gain_control = rtc::Maybe(false); + options.echo_cancellation = rtc::Optional(false); + options.auto_gain_control = rtc::Optional(false); LOG(LS_INFO) << "Always disable AEC and AGC on iOS. Use built-in instead."; #elif defined(ANDROID) ec_mode = webrtc::kEcAecm; @@ -651,10 +651,10 @@ 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 = rtc::Maybe(false); - options.experimental_agc = rtc::Maybe(false); - options.extended_filter_aec = rtc::Maybe(false); - options.experimental_ns = rtc::Maybe(false); + options.typing_detection = rtc::Optional(false); + options.experimental_agc = rtc::Optional(false); + options.extended_filter_aec = rtc::Optional(false); + options.experimental_ns = rtc::Optional(false); #endif // Delay Agnostic AEC automatically turns on EC if not set except on iOS @@ -664,8 +664,8 @@ bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) { if (options.delay_agnostic_aec) { use_delay_agnostic_aec = *options.delay_agnostic_aec; if (use_delay_agnostic_aec) { - options.echo_cancellation = rtc::Maybe(true); - options.extended_filter_aec = rtc::Maybe(true); + options.echo_cancellation = rtc::Optional(true); + options.extended_filter_aec = rtc::Optional(true); ec_mode = webrtc::kEcConference; } } @@ -689,7 +689,7 @@ bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) { 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 = rtc::Maybe(false); + options.echo_cancellation = rtc::Optional(false); LOG(LS_INFO) << "Disabling EC since built-in EC will be used instead"; } } @@ -724,7 +724,7 @@ bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) { *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 = rtc::Maybe(false); + options.auto_gain_control = rtc::Optional(false); LOG(LS_INFO) << "Disabling AGC since built-in AGC will be used instead"; } } @@ -771,7 +771,7 @@ bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) { *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 = rtc::Maybe(false); + options.noise_suppression = rtc::Optional(false); LOG(LS_INFO) << "Disabling NS since built-in NS will be used instead"; } } diff --git a/talk/media/webrtc/webrtcvoiceengine.h b/talk/media/webrtc/webrtcvoiceengine.h index b9b50bb93d..33524dbf53 100644 --- a/talk/media/webrtc/webrtcvoiceengine.h +++ b/talk/media/webrtc/webrtcvoiceengine.h @@ -168,9 +168,9 @@ class WebRtcVoiceEngine final : public webrtc::TraceCallback { // 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. - rtc::Maybe extended_filter_aec_; - rtc::Maybe delay_agnostic_aec_; - rtc::Maybe experimental_ns_; + rtc::Optional extended_filter_aec_; + rtc::Optional delay_agnostic_aec_; + rtc::Optional 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 efa195d204..3f63fd7c08 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 = rtc::Maybe(-10); + options_adjust_agc_.adjust_agc_delta = rtc::Optional(-10); } bool SetupEngine() { if (!engine_.Init(rtc::Thread::Current())) { @@ -2282,10 +2282,10 @@ TEST_F(WebRtcVoiceEngineTestFake, TxAgcConfigViaOptions) { EXPECT_EQ(0, agc_config.targetLeveldBOv); cricket::AudioOptions options; - 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); + options.tx_agc_target_dbov = rtc::Optional(3); + options.tx_agc_digital_compression_gain = rtc::Optional(9); + options.tx_agc_limiter = rtc::Optional(true); + options.auto_gain_control = rtc::Optional(true); EXPECT_TRUE(engine_.SetOptions(options)); EXPECT_EQ(0, voe_.GetAgcConfig(agc_config)); @@ -2295,7 +2295,7 @@ TEST_F(WebRtcVoiceEngineTestFake, TxAgcConfigViaOptions) { // Check interaction with adjust_agc_delta. Both should be respected, for // backwards compatibility. - options.adjust_agc_delta = rtc::Maybe(-10); + options.adjust_agc_delta = rtc::Optional(-10); EXPECT_TRUE(engine_.SetOptions(options)); EXPECT_EQ(0, voe_.GetAgcConfig(agc_config)); @@ -2305,8 +2305,8 @@ TEST_F(WebRtcVoiceEngineTestFake, TxAgcConfigViaOptions) { TEST_F(WebRtcVoiceEngineTestFake, SampleRatesViaOptions) { EXPECT_TRUE(SetupEngineWithSendStream()); cricket::AudioOptions options; - options.recording_sample_rate = rtc::Maybe(48000); - options.playout_sample_rate = rtc::Maybe(44100); + options.recording_sample_rate = rtc::Optional(48000); + options.playout_sample_rate = rtc::Optional(44100); EXPECT_TRUE(engine_.SetOptions(options)); unsigned int recording_sample_rate, playout_sample_rate; @@ -2639,14 +2639,14 @@ TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) { voe_.GetNetEqFastAccelerate()); // From GetDefaultEngineOptions(). // Turn echo cancellation off - options.echo_cancellation = rtc::Maybe(false); + options.echo_cancellation = rtc::Optional(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 = rtc::Maybe(true); + options.echo_cancellation = rtc::Optional(true); ASSERT_TRUE(engine_.SetOptions(options)); voe_.GetEcStatus(ec_enabled, ec_mode); voe_.GetAecmMode(aecm_mode, cng_enabled); @@ -2669,7 +2669,7 @@ TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) { // Turn on delay agnostic aec and make sure nothing change w.r.t. echo // control. - options.delay_agnostic_aec = rtc::Maybe(true); + options.delay_agnostic_aec = rtc::Optional(true); ASSERT_TRUE(engine_.SetOptions(options)); voe_.GetEcStatus(ec_enabled, ec_mode); voe_.GetAecmMode(aecm_mode, cng_enabled); @@ -2678,14 +2678,14 @@ TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) { EXPECT_EQ(ec_mode, webrtc::kEcConference); // Turn off echo cancellation and delay agnostic aec. - options.delay_agnostic_aec = rtc::Maybe(false); - options.extended_filter_aec = rtc::Maybe(false); - options.echo_cancellation = rtc::Maybe(false); + options.delay_agnostic_aec = rtc::Optional(false); + options.extended_filter_aec = rtc::Optional(false); + options.echo_cancellation = rtc::Optional(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 = rtc::Maybe(true); + options.delay_agnostic_aec = rtc::Optional(true); ASSERT_TRUE(engine_.SetOptions(options)); voe_.GetEcStatus(ec_enabled, ec_mode); EXPECT_TRUE(ec_enabled); @@ -2693,14 +2693,14 @@ TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) { EXPECT_EQ(ec_mode, webrtc::kEcConference); // Turn off AGC - options.auto_gain_control = rtc::Maybe(false); + options.auto_gain_control = rtc::Optional(false); ASSERT_TRUE(engine_.SetOptions(options)); voe_.GetAgcStatus(agc_enabled, agc_mode); EXPECT_FALSE(agc_enabled); // Turn AGC back on - options.auto_gain_control = rtc::Maybe(true); - options.adjust_agc_delta = rtc::Maybe(); + options.auto_gain_control = rtc::Optional(true); + options.adjust_agc_delta = rtc::Optional(); ASSERT_TRUE(engine_.SetOptions(options)); voe_.GetAgcStatus(agc_enabled, agc_mode); EXPECT_TRUE(agc_enabled); @@ -2708,10 +2708,10 @@ TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) { EXPECT_EQ(0, agc_config.targetLeveldBOv); // Turn off other options (and stereo swapping on). - options.noise_suppression = rtc::Maybe(false); - options.highpass_filter = rtc::Maybe(false); - options.typing_detection = rtc::Maybe(false); - options.stereo_swapping = rtc::Maybe(true); + options.noise_suppression = rtc::Optional(false); + options.highpass_filter = rtc::Optional(false); + options.typing_detection = rtc::Optional(false); + options.stereo_swapping = rtc::Optional(true); ASSERT_TRUE(engine_.SetOptions(options)); voe_.GetNsStatus(ns_enabled, ns_mode); highpass_filter_enabled = voe_.IsHighPassFilterEnabled(); @@ -2794,9 +2794,9 @@ TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) { // AEC and AGC and NS cricket::AudioSendParameters parameters_options_all = send_parameters_; - 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); + parameters_options_all.options.echo_cancellation = rtc::Optional(true); + parameters_options_all.options.auto_gain_control = rtc::Optional(true); + parameters_options_all.options.noise_suppression = rtc::Optional(true); ASSERT_TRUE(channel1->SetSendParameters(parameters_options_all)); EXPECT_EQ(parameters_options_all.options, channel1->options()); ASSERT_TRUE(channel2->SetSendParameters(parameters_options_all)); @@ -2804,21 +2804,23 @@ TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) { // unset NS cricket::AudioSendParameters parameters_options_no_ns = send_parameters_; - parameters_options_no_ns.options.noise_suppression = rtc::Maybe(false); + parameters_options_no_ns.options.noise_suppression = + rtc::Optional(false); ASSERT_TRUE(channel1->SetSendParameters(parameters_options_no_ns)); cricket::AudioOptions expected_options = parameters_options_all.options; - expected_options.echo_cancellation = rtc::Maybe(true); - expected_options.auto_gain_control = rtc::Maybe(true); - expected_options.noise_suppression = rtc::Maybe(false); + expected_options.echo_cancellation = rtc::Optional(true); + expected_options.auto_gain_control = rtc::Optional(true); + expected_options.noise_suppression = rtc::Optional(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 = rtc::Maybe(false); + parameters_options_no_agc.options.auto_gain_control = + rtc::Optional(false); ASSERT_TRUE(channel2->SetSendParameters(parameters_options_no_agc)); - expected_options.echo_cancellation = rtc::Maybe(true); - expected_options.auto_gain_control = rtc::Maybe(false); - expected_options.noise_suppression = rtc::Maybe(true); + expected_options.echo_cancellation = rtc::Optional(true); + expected_options.auto_gain_control = rtc::Optional(false); + expected_options.noise_suppression = rtc::Optional(true); EXPECT_EQ(expected_options, channel2->options()); ASSERT_TRUE(engine_.SetOptions(parameters_options_all.options)); @@ -2872,14 +2874,14 @@ TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) { cricket::AudioSendParameters parameters_options_no_agc_nor_ns = send_parameters_; parameters_options_no_agc_nor_ns.options.auto_gain_control = - rtc::Maybe(false); + rtc::Optional(false); parameters_options_no_agc_nor_ns.options.noise_suppression = - rtc::Maybe(false); + rtc::Optional(false); channel2->SetSend(cricket::SEND_MICROPHONE); channel2->SetSendParameters(parameters_options_no_agc_nor_ns); - expected_options.echo_cancellation = rtc::Maybe(true); - expected_options.auto_gain_control = rtc::Maybe(false); - expected_options.noise_suppression = rtc::Maybe(false); + expected_options.echo_cancellation = rtc::Optional(true); + expected_options.auto_gain_control = rtc::Optional(false); + expected_options.noise_suppression = rtc::Optional(false); EXPECT_EQ(expected_options, channel2->options()); voe_.GetEcStatus(ec_enabled, ec_mode); voe_.GetAgcStatus(agc_enabled, agc_mode); @@ -2898,13 +2900,13 @@ TEST_F(WebRtcVoiceEngineTestFake, TestSetDscpOptions) { new cricket::FakeNetworkInterface); channel->SetInterface(network_interface.get()); cricket::AudioSendParameters parameters = send_parameters_; - parameters.options.dscp = rtc::Maybe(true); + parameters.options.dscp = rtc::Optional(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 = rtc::Maybe(false); + parameters.options.dscp = rtc::Optional(false); EXPECT_TRUE(channel->SetSendParameters(parameters)); EXPECT_EQ(rtc::DSCP_DEFAULT, network_interface->dscp()); } @@ -3013,7 +3015,7 @@ TEST_F(WebRtcVoiceEngineTestFake, CanChangeCombinedBweOption) { } // Enable combined BWE option - now it should be set up. - send_parameters_.options.combined_audio_video_bwe = rtc::Maybe(true); + send_parameters_.options.combined_audio_video_bwe = rtc::Optional(true); EXPECT_TRUE(media_channel->SetSendParameters(send_parameters_)); for (uint32_t ssrc : ssrcs) { const auto* s = call_.GetAudioReceiveStream(ssrc); @@ -3022,7 +3024,8 @@ TEST_F(WebRtcVoiceEngineTestFake, CanChangeCombinedBweOption) { } // Disable combined BWE option - should be disabled again. - send_parameters_.options.combined_audio_video_bwe = rtc::Maybe(false); + send_parameters_.options.combined_audio_video_bwe = + rtc::Optional(false); EXPECT_TRUE(media_channel->SetSendParameters(send_parameters_)); for (uint32_t ssrc : ssrcs) { const auto* s = call_.GetAudioReceiveStream(ssrc); @@ -3039,7 +3042,7 @@ TEST_F(WebRtcVoiceEngineTestFake, ConfigureCombinedBweForNewRecvStreams) { EXPECT_TRUE(SetupEngineWithSendStream()); cricket::WebRtcVoiceMediaChannel* media_channel = static_cast(channel_); - send_parameters_.options.combined_audio_video_bwe = rtc::Maybe(true); + send_parameters_.options.combined_audio_video_bwe = rtc::Optional(true); EXPECT_TRUE(media_channel->SetSendParameters(send_parameters_)); static const uint32_t kSsrcs[] = {1, 2, 3, 4}; @@ -3061,7 +3064,7 @@ TEST_F(WebRtcVoiceEngineTestFake, ConfiguresAudioReceiveStreamRtpExtensions) { EXPECT_TRUE(SetupEngineWithSendStream()); cricket::WebRtcVoiceMediaChannel* media_channel = static_cast(channel_); - send_parameters_.options.combined_audio_video_bwe = rtc::Maybe(true); + send_parameters_.options.combined_audio_video_bwe = rtc::Optional(true); EXPECT_TRUE(media_channel->SetSendParameters(send_parameters_)); for (uint32_t ssrc : ssrcs) { EXPECT_TRUE(media_channel->AddRecvStream( @@ -3120,7 +3123,7 @@ TEST_F(WebRtcVoiceEngineTestFake, DeliverAudioPacket_Call) { EXPECT_TRUE(SetupEngineWithSendStream()); cricket::WebRtcVoiceMediaChannel* media_channel = static_cast(channel_); - send_parameters_.options.combined_audio_video_bwe = rtc::Maybe(true); + send_parameters_.options.combined_audio_video_bwe = rtc::Optional(true); EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); EXPECT_TRUE(media_channel->AddRecvStream( cricket::StreamParams::CreateLegacy(kAudioSsrc))); diff --git a/talk/session/media/channel.cc b/talk/session/media/channel.cc index 0e34cbfaac..ae27e332f8 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 = rtc::Maybe(kAgcMinus10db); + send_params.options.adjust_agc_delta = rtc::Optional(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 = rtc::Maybe(true); + send_params.options.conference_mode = rtc::Optional(true); } if (!media_channel()->SetSendParameters(send_params)) { SafeSetError("Failed to set remote video description send parameters.", diff --git a/webrtc/base/BUILD.gn b/webrtc/base/BUILD.gn index 11a26646be..ca79a3819f 100644 --- a/webrtc/base/BUILD.gn +++ b/webrtc/base/BUILD.gn @@ -115,11 +115,11 @@ static_library("rtc_base_approved") { "event_tracer.h", "exp_filter.cc", "exp_filter.h", - "maybe.h", "md5.cc", "md5.h", "md5digest.cc", "md5digest.h", + "optional.h", "platform_file.cc", "platform_file.h", "platform_thread.cc", diff --git a/webrtc/base/base.gyp b/webrtc/base/base.gyp index 4b6ad85362..80bd652719 100644 --- a/webrtc/base/base.gyp +++ b/webrtc/base/base.gyp @@ -54,11 +54,11 @@ 'exp_filter.h', 'logging.cc', 'logging.h', - 'maybe.h', 'md5.cc', 'md5.h', 'md5digest.cc', 'md5digest.h', + 'optional.h', 'platform_file.cc', 'platform_file.h', 'platform_thread.cc', diff --git a/webrtc/base/base_tests.gyp b/webrtc/base/base_tests.gyp index ee371f4a62..a6dd3d13d8 100644 --- a/webrtc/base/base_tests.gyp +++ b/webrtc/base/base_tests.gyp @@ -71,13 +71,13 @@ 'httpserver_unittest.cc', 'ipaddress_unittest.cc', 'logging_unittest.cc', - 'maybe_unittest.cc', 'md5digest_unittest.cc', 'messagedigest_unittest.cc', 'messagequeue_unittest.cc', 'multipart_unittest.cc', 'nat_unittest.cc', 'network_unittest.cc', + 'optional_unittest.cc', 'optionsfile_unittest.cc', 'pathutils_unittest.cc', 'profiler_unittest.cc', diff --git a/webrtc/base/maybe.h b/webrtc/base/optional.h similarity index 54% rename from webrtc/base/maybe.h rename to webrtc/base/optional.h index 1df94def3f..6e7535b446 100644 --- a/webrtc/base/maybe.h +++ b/webrtc/base/optional.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef WEBRTC_BASE_MAYBE_H_ -#define WEBRTC_BASE_MAYBE_H_ +#ifndef WEBRTC_BASE_OPTIONAL_H_ +#define WEBRTC_BASE_OPTIONAL_H_ #include #include @@ -24,38 +24,67 @@ namespace rtc { // contain a value; use e.g. rtc::scoped_ptr instead if that's too // expensive. // -// A moved-from Maybe may only be destroyed, and assigned to if T allows +// A moved-from Optional may only be destroyed, and assigned to if T allows // being assigned to after having been moved from. Specifically, you may not // assume that it just doesn't contain a value anymore. // +// Examples of good places to use Optional: +// +// - As a class or struct member, when the member doesn't always have a value: +// struct Prisoner { +// std::string name; +// Optional cell_number; // Empty if not currently incarcerated. +// }; +// +// - As a return value for functions that may fail to return a value on all +// allowed inputs. For example, a function that searches an array might +// return an Optional (the index where it found the element, or +// nothing if it didn't find it); and a function that parses numbers might +// return Optional (the parsed number, or nothing if parsing failed). +// +// Examples of bad places to use Optional: +// +// - As a return value for functions that may fail because of disallowed +// inputs. For example, a string length function should not return +// Optional so that it can return nothing in case the caller passed +// it a null pointer; the function should probably use RTC_[D]CHECK instead, +// and return plain size_t. +// +// - As a return value for functions that may fail to return a value on all +// allowed inputs, but need to tell the caller what went wrong. Returning +// Optional when parsing a single number as in the example above +// might make sense, but any larger parse job is probably going to need to +// tell the caller what the problem was, not just that there was one. +// // TODO(kwiberg): Get rid of this class when the standard library has // std::optional (and we're allowed to use it). template -class Maybe final { +class Optional final { public: - // Construct an empty Maybe. - Maybe() : has_value_(false) {} + // Construct an empty Optional. + Optional() : has_value_(false) {} - // 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) {} + // Construct an Optional that contains a value. + explicit Optional(const T& val) : value_(val), has_value_(true) {} + explicit Optional(T&& val) + : value_(static_cast(val)), has_value_(true) {} // Copy and move constructors. // TODO(kwiberg): =default the move constructor when MSVC supports it. - Maybe(const Maybe&) = default; - Maybe(Maybe&& m) + Optional(const Optional&) = default; + Optional(Optional&& m) : value_(static_cast(m.value_)), has_value_(m.has_value_) {} // Assignment. // TODO(kwiberg): =default the move assignment op when MSVC supports it. - Maybe& operator=(const Maybe&) = default; - Maybe& operator=(Maybe&& m) { + Optional& operator=(const Optional&) = default; + Optional& operator=(Optional&& m) { value_ = static_cast(m.value_); has_value_ = m.has_value_; return *this; } - friend void swap(Maybe& m1, Maybe& m2) { + friend void swap(Optional& m1, Optional& m2) { using std::swap; swap(m1.value_, m2.value_); swap(m1.has_value_, m2.has_value_); @@ -87,13 +116,14 @@ class Maybe final { return has_value_ ? value_ : default_val; } - // Equality tests. Two Maybes are equal if they contain equivalent values, or + // Equality tests. Two Optionals are equal if they contain equivalent values, + // or // if they're both empty. - friend bool operator==(const Maybe& m1, const Maybe& m2) { + friend bool operator==(const Optional& m1, const Optional& m2) { return m1.has_value_ && m2.has_value_ ? m1.value_ == m2.value_ : m1.has_value_ == m2.has_value_; } - friend bool operator!=(const Maybe& m1, const Maybe& m2) { + friend bool operator!=(const Optional& m1, const Optional& m2) { return m1.has_value_ && m2.has_value_ ? m1.value_ != m2.value_ : m1.has_value_ != m2.has_value_; } @@ -107,4 +137,4 @@ class Maybe final { } // namespace rtc -#endif // WEBRTC_BASE_MAYBE_H_ +#endif // WEBRTC_BASE_OPTIONAL_H_ diff --git a/webrtc/base/maybe_unittest.cc b/webrtc/base/optional_unittest.cc similarity index 82% rename from webrtc/base/maybe_unittest.cc rename to webrtc/base/optional_unittest.cc index f7707d1c81..5483314f49 100644 --- a/webrtc/base/maybe_unittest.cc +++ b/webrtc/base/optional_unittest.cc @@ -14,7 +14,7 @@ #include #include "webrtc/base/gunit.h" -#include "webrtc/base/maybe.h" +#include "webrtc/base/optional.h" namespace rtc { @@ -118,19 +118,19 @@ std::vector V(Ts... es) { } // namespace -TEST(MaybeTest, TestConstructDefault) { +TEST(OptionalTest, TestConstructDefault) { auto log = Logger::Setup(); { - Maybe x; + Optional x; EXPECT_FALSE(x); } EXPECT_EQ(V("0:0. default constructor", "0:0. destructor"), *log); } -TEST(MaybeTest, TestConstructCopyEmpty) { +TEST(OptionalTest, TestConstructCopyEmpty) { auto log = Logger::Setup(); { - Maybe x; + Optional x; EXPECT_FALSE(x); auto y = x; EXPECT_FALSE(y); @@ -140,11 +140,11 @@ TEST(MaybeTest, TestConstructCopyEmpty) { *log); } -TEST(MaybeTest, TestConstructCopyFull) { +TEST(OptionalTest, TestConstructCopyFull) { auto log = Logger::Setup(); { Logger a; - Maybe x(a); + Optional x(a); EXPECT_TRUE(x); log->push_back("---"); auto y = x; @@ -157,12 +157,12 @@ TEST(MaybeTest, TestConstructCopyFull) { *log); } -TEST(MaybeTest, TestConstructMoveEmpty) { +TEST(OptionalTest, TestConstructMoveEmpty) { auto log = Logger::Setup(); { - Maybe x; + Optional x; EXPECT_FALSE(x); - auto y = static_cast&&>(x); + auto y = static_cast&&>(x); EXPECT_FALSE(y); } EXPECT_EQ(V("0:0. default constructor", "1:0. move constructor (from 0:0)", @@ -170,13 +170,13 @@ TEST(MaybeTest, TestConstructMoveEmpty) { *log); } -TEST(MaybeTest, TestConstructMoveFull) { +TEST(OptionalTest, TestConstructMoveFull) { auto log = Logger::Setup(); { - Maybe x(Logger(17)); + Optional x(Logger(17)); EXPECT_TRUE(x); log->push_back("---"); - auto y = static_cast&&>(x); + auto y = static_cast&&>(x); EXPECT_TRUE(x); EXPECT_TRUE(y); log->push_back("---"); @@ -188,10 +188,10 @@ TEST(MaybeTest, TestConstructMoveFull) { *log); } -TEST(MaybeTest, TestCopyAssignToEmptyFromEmpty) { +TEST(OptionalTest, TestCopyAssignToEmptyFromEmpty) { auto log = Logger::Setup(); { - Maybe x, y; + Optional x, y; x = y; } EXPECT_EQ( @@ -200,11 +200,11 @@ TEST(MaybeTest, TestCopyAssignToEmptyFromEmpty) { *log); } -TEST(MaybeTest, TestCopyAssignToFullFromEmpty) { +TEST(OptionalTest, TestCopyAssignToFullFromEmpty) { auto log = Logger::Setup(); { - Maybe x(Logger(17)); - Maybe y; + Optional x(Logger(17)); + Optional y; log->push_back("---"); x = y; log->push_back("---"); @@ -217,11 +217,11 @@ TEST(MaybeTest, TestCopyAssignToFullFromEmpty) { *log); } -TEST(MaybeTest, TestCopyAssignToEmptyFromFull) { +TEST(OptionalTest, TestCopyAssignToEmptyFromFull) { auto log = Logger::Setup(); { - Maybe x; - Maybe y(Logger(17)); + Optional x; + Optional y(Logger(17)); log->push_back("---"); x = y; log->push_back("---"); @@ -233,11 +233,11 @@ TEST(MaybeTest, TestCopyAssignToEmptyFromFull) { *log); } -TEST(MaybeTest, TestCopyAssignToFullFromFull) { +TEST(OptionalTest, TestCopyAssignToFullFromFull) { auto log = Logger::Setup(); { - Maybe x(Logger(17)); - Maybe y(Logger(42)); + Optional x(Logger(17)); + Optional y(Logger(42)); log->push_back("---"); x = y; log->push_back("---"); @@ -251,13 +251,13 @@ TEST(MaybeTest, TestCopyAssignToFullFromFull) { *log); } -TEST(MaybeTest, TestCopyAssignToEmptyFromT) { +TEST(OptionalTest, TestCopyAssignToEmptyFromT) { auto log = Logger::Setup(); { - Maybe x; + Optional x; Logger y(17); log->push_back("---"); - x = rtc::Maybe(y); + x = Optional(y); log->push_back("---"); } EXPECT_EQ(V("0:0. default constructor", "1:17. explicit constructor", "---", @@ -267,13 +267,13 @@ TEST(MaybeTest, TestCopyAssignToEmptyFromT) { *log); } -TEST(MaybeTest, TestCopyAssignToFullFromT) { +TEST(OptionalTest, TestCopyAssignToFullFromT) { auto log = Logger::Setup(); { - Maybe x(Logger(17)); + Optional x(Logger(17)); Logger y(42); log->push_back("---"); - x = rtc::Maybe(y); + x = Optional(y); log->push_back("---"); } EXPECT_EQ( @@ -285,11 +285,11 @@ TEST(MaybeTest, TestCopyAssignToFullFromT) { *log); } -TEST(MaybeTest, TestMoveAssignToEmptyFromEmpty) { +TEST(OptionalTest, TestMoveAssignToEmptyFromEmpty) { auto log = Logger::Setup(); { - Maybe x, y; - x = static_cast&&>(y); + Optional x, y; + x = static_cast&&>(y); } EXPECT_EQ( V("0:0. default constructor", "1:1. default constructor", @@ -297,13 +297,13 @@ TEST(MaybeTest, TestMoveAssignToEmptyFromEmpty) { *log); } -TEST(MaybeTest, TestMoveAssignToFullFromEmpty) { +TEST(OptionalTest, TestMoveAssignToFullFromEmpty) { auto log = Logger::Setup(); { - Maybe x(Logger(17)); - Maybe y; + Optional x(Logger(17)); + Optional y; log->push_back("---"); - x = static_cast&&>(y); + x = static_cast&&>(y); log->push_back("---"); } EXPECT_EQ( @@ -314,13 +314,13 @@ TEST(MaybeTest, TestMoveAssignToFullFromEmpty) { *log); } -TEST(MaybeTest, TestMoveAssignToEmptyFromFull) { +TEST(OptionalTest, TestMoveAssignToEmptyFromFull) { auto log = Logger::Setup(); { - Maybe x; - Maybe y(Logger(17)); + Optional x; + Optional y(Logger(17)); log->push_back("---"); - x = static_cast&&>(y); + x = static_cast&&>(y); log->push_back("---"); } EXPECT_EQ(V("0:0. default constructor", "1:17. explicit constructor", @@ -330,13 +330,13 @@ TEST(MaybeTest, TestMoveAssignToEmptyFromFull) { *log); } -TEST(MaybeTest, TestMoveAssignToFullFromFull) { +TEST(OptionalTest, TestMoveAssignToFullFromFull) { auto log = Logger::Setup(); { - Maybe x(Logger(17)); - Maybe y(Logger(42)); + Optional x(Logger(17)); + Optional y(Logger(42)); log->push_back("---"); - x = static_cast&&>(y); + x = static_cast&&>(y); log->push_back("---"); } EXPECT_EQ( @@ -348,13 +348,13 @@ TEST(MaybeTest, TestMoveAssignToFullFromFull) { *log); } -TEST(MaybeTest, TestMoveAssignToEmptyFromT) { +TEST(OptionalTest, TestMoveAssignToEmptyFromT) { auto log = Logger::Setup(); { - Maybe x; + Optional x; Logger y(17); log->push_back("---"); - x = rtc::Maybe(static_cast(y)); + x = Optional(static_cast(y)); log->push_back("---"); } EXPECT_EQ(V("0:0. default constructor", "1:17. explicit constructor", "---", @@ -364,13 +364,13 @@ TEST(MaybeTest, TestMoveAssignToEmptyFromT) { *log); } -TEST(MaybeTest, TestMoveAssignToFullFromT) { +TEST(OptionalTest, TestMoveAssignToFullFromT) { auto log = Logger::Setup(); { - Maybe x(Logger(17)); + Optional x(Logger(17)); Logger y(42); log->push_back("---"); - x = rtc::Maybe(static_cast(y)); + x = Optional(static_cast(y)); log->push_back("---"); } EXPECT_EQ( @@ -382,21 +382,21 @@ TEST(MaybeTest, TestMoveAssignToFullFromT) { *log); } -TEST(MaybeTest, TestDereference) { +TEST(OptionalTest, TestDereference) { auto log = Logger::Setup(); { - Maybe x(Logger(42)); + Optional x(Logger(42)); const auto& y = x; log->push_back("---"); x->Foo(); y->Foo(); - static_cast&&>(x)->Foo(); - static_cast&&>(y)->Foo(); + static_cast&&>(x)->Foo(); + static_cast&&>(y)->Foo(); log->push_back("---"); (*x).Foo(); (*y).Foo(); - (*static_cast&&>(x)).Foo(); - (*static_cast&&>(y)).Foo(); + (*static_cast&&>(x)).Foo(); + (*static_cast&&>(y)).Foo(); log->push_back("---"); } EXPECT_EQ(V("0:42. explicit constructor", @@ -407,20 +407,20 @@ TEST(MaybeTest, TestDereference) { *log); } -TEST(MaybeTest, TestDereferenceWithDefault) { +TEST(OptionalTest, TestDereferenceWithDefault) { auto log = Logger::Setup(); { const Logger a(17), b(42); - Maybe x(a); - Maybe y; + Optional x(a); + Optional y; log->push_back("-1-"); EXPECT_EQ(a, x.value_or(Logger(42))); log->push_back("-2-"); EXPECT_EQ(b, y.value_or(Logger(42))); log->push_back("-3-"); - EXPECT_EQ(a, Maybe(Logger(17)).value_or(b)); + EXPECT_EQ(a, Optional(Logger(17)).value_or(b)); log->push_back("-4-"); - EXPECT_EQ(b, Maybe().value_or(b)); + EXPECT_EQ(b, Optional().value_or(b)); log->push_back("-5-"); } EXPECT_EQ( @@ -437,11 +437,11 @@ TEST(MaybeTest, TestDereferenceWithDefault) { *log); } -TEST(MaybeTest, TestEquality) { +TEST(OptionalTest, TestEquality) { auto log = Logger::Setup(); { Logger a(17), b(42); - Maybe ma1(a), ma2(a), mb(b), me1, me2; + Optional ma1(a), ma2(a), mb(b), me1, me2; log->push_back("---"); EXPECT_EQ(ma1, ma1); EXPECT_EQ(ma1, ma2); @@ -463,11 +463,11 @@ TEST(MaybeTest, TestEquality) { *log); } -TEST(MaybeTest, TestSwap) { +TEST(OptionalTest, TestSwap) { auto log = Logger::Setup(); { Logger a(17), b(42); - Maybe x1(a), x2(b), y1(a), y2, z1, z2; + Optional x1(a), x2(b), y1(a), y2, z1, z2; log->push_back("---"); swap(x1, x2); // Swap full <-> full. swap(y1, y2); // Swap full <-> empty. diff --git a/webrtc/modules/audio_coding/main/acm2/acm_receiver.cc b/webrtc/modules/audio_coding/main/acm2/acm_receiver.cc index 34726ccb20..4e1977636a 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_receiver.cc +++ b/webrtc/modules/audio_coding/main/acm2/acm_receiver.cc @@ -313,10 +313,10 @@ int32_t AcmReceiver::AddCodec(int acm_codec_id, const auto neteq_decoder = [acm_codec_id, channels]() -> NetEqDecoder { if (acm_codec_id == -1) return NetEqDecoder::kDecoderArbitrary; // External decoder. - const rtc::Maybe cid = + const rtc::Optional cid = RentACodec::CodecIdFromIndex(acm_codec_id); RTC_DCHECK(cid) << "Invalid codec index: " << acm_codec_id; - const rtc::Maybe ned = + const rtc::Optional ned = RentACodec::NetEqDecoderFromCodecId(*cid, channels); RTC_DCHECK(ned) << "Invalid codec ID: " << static_cast(*cid); return *ned; diff --git a/webrtc/modules/audio_coding/main/acm2/audio_coding_module.cc b/webrtc/modules/audio_coding/main/acm2/audio_coding_module.cc index 77ee0f2789..889d62092a 100644 --- a/webrtc/modules/audio_coding/main/acm2/audio_coding_module.cc +++ b/webrtc/modules/audio_coding/main/acm2/audio_coding_module.cc @@ -57,7 +57,7 @@ int AudioCodingModule::Codec(const char* payload_name, CodecInst* codec, int sampling_freq_hz, int channels) { - rtc::Maybe ci = acm2::RentACodec::CodecInstByParams( + rtc::Optional ci = acm2::RentACodec::CodecInstByParams( payload_name, sampling_freq_hz, channels); if (ci) { *codec = *ci; @@ -77,11 +77,12 @@ int AudioCodingModule::Codec(const char* payload_name, int AudioCodingModule::Codec(const char* payload_name, int sampling_freq_hz, int channels) { - rtc::Maybe ci = acm2::RentACodec::CodecIdByParams( - payload_name, sampling_freq_hz, channels); + rtc::Optional ci = + acm2::RentACodec::CodecIdByParams(payload_name, sampling_freq_hz, + channels); if (!ci) return -1; - rtc::Maybe i = acm2::RentACodec::CodecIndexFromId(*ci); + rtc::Optional i = acm2::RentACodec::CodecIndexFromId(*ci); return i ? *i : -1; } diff --git a/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.cc b/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.cc index 3b8b14015a..aaf204b6a8 100644 --- a/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.cc +++ b/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.cc @@ -208,7 +208,7 @@ void AudioCodingModuleImpl::RegisterExternalSendCodec( } // Get current send codec. -rtc::Maybe AudioCodingModuleImpl::SendCodec() const { +rtc::Optional AudioCodingModuleImpl::SendCodec() const { CriticalSectionScoped lock(acm_crit_sect_.get()); return codec_manager_.GetCodecInst(); } diff --git a/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.h b/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.h index d6c077a4c9..c04ccf9c2f 100644 --- a/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.h +++ b/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.h @@ -47,7 +47,7 @@ class AudioCodingModuleImpl final : public AudioCodingModule { AudioEncoder* external_speech_encoder) override; // Get current send codec. - rtc::Maybe SendCodec() const override; + rtc::Optional SendCodec() const override; // Get current send frequency. int SendFrequency() const override; diff --git a/webrtc/modules/audio_coding/main/acm2/codec_manager.cc b/webrtc/modules/audio_coding/main/acm2/codec_manager.cc index 6a33886192..e4070c76ae 100644 --- a/webrtc/modules/audio_coding/main/acm2/codec_manager.cc +++ b/webrtc/modules/audio_coding/main/acm2/codec_manager.cc @@ -328,7 +328,7 @@ void CodecManager::RegisterEncoder(AudioEncoder* external_speech_encoder) { codec_owner_.SetEncoders(external_speech_encoder, cng_pt, vad_mode_, red_pt); } -rtc::Maybe CodecManager::GetCodecInst() const { +rtc::Optional CodecManager::GetCodecInst() const { int dummy_id = 0; WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, dummy_id, "SendCodec()"); @@ -336,9 +336,9 @@ rtc::Maybe CodecManager::GetCodecInst() const { if (!codec_owner_.Encoder()) { WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, dummy_id, "SendCodec Failed, no codec is registered"); - return rtc::Maybe(); + return rtc::Optional(); } - return rtc::Maybe(send_codec_inst_); + return rtc::Optional(send_codec_inst_); } bool CodecManager::SetCopyRed(bool enable) { diff --git a/webrtc/modules/audio_coding/main/acm2/codec_manager.h b/webrtc/modules/audio_coding/main/acm2/codec_manager.h index 395e88f7f1..37018d345b 100644 --- a/webrtc/modules/audio_coding/main/acm2/codec_manager.h +++ b/webrtc/modules/audio_coding/main/acm2/codec_manager.h @@ -12,7 +12,7 @@ #define WEBRTC_MODULES_AUDIO_CODING_MAIN_ACM2_CODEC_MANAGER_H_ #include "webrtc/base/constructormagic.h" -#include "webrtc/base/maybe.h" +#include "webrtc/base/optional.h" #include "webrtc/base/scoped_ptr.h" #include "webrtc/base/thread_checker.h" #include "webrtc/modules/audio_coding/main/acm2/codec_owner.h" @@ -36,7 +36,7 @@ class CodecManager final { void RegisterEncoder(AudioEncoder* external_speech_encoder); - rtc::Maybe GetCodecInst() const; + rtc::Optional GetCodecInst() const; bool SetCopyRed(bool enable); 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 a056f78e0b..2ee953c1dd 100644 --- a/webrtc/modules/audio_coding/main/acm2/rent_a_codec.cc +++ b/webrtc/modules/audio_coding/main/acm2/rent_a_codec.cc @@ -36,7 +36,7 @@ namespace webrtc { namespace acm2 { -rtc::Maybe RentACodec::CodecIdByParams( +rtc::Optional RentACodec::CodecIdByParams( const char* payload_name, int sampling_freq_hz, int channels) { @@ -44,24 +44,25 @@ rtc::Maybe RentACodec::CodecIdByParams( ACMCodecDB::CodecId(payload_name, sampling_freq_hz, channels)); } -rtc::Maybe RentACodec::CodecInstById(CodecId codec_id) { - rtc::Maybe mi = CodecIndexFromId(codec_id); - return mi ? rtc::Maybe(Database()[*mi]) : rtc::Maybe(); +rtc::Optional RentACodec::CodecInstById(CodecId codec_id) { + rtc::Optional mi = CodecIndexFromId(codec_id); + return mi ? rtc::Optional(Database()[*mi]) + : rtc::Optional(); } -rtc::Maybe RentACodec::CodecIdByInst( +rtc::Optional RentACodec::CodecIdByInst( const CodecInst& codec_inst) { return CodecIdFromIndex(ACMCodecDB::CodecNumber(codec_inst)); } -rtc::Maybe RentACodec::CodecInstByParams(const char* payload_name, - int sampling_freq_hz, - int channels) { - rtc::Maybe codec_id = +rtc::Optional RentACodec::CodecInstByParams(const char* payload_name, + int sampling_freq_hz, + int channels) { + rtc::Optional codec_id = CodecIdByParams(payload_name, sampling_freq_hz, channels); if (!codec_id) - return rtc::Maybe(); - rtc::Maybe ci = CodecInstById(*codec_id); + return rtc::Optional(); + rtc::Optional ci = CodecInstById(*codec_id); RTC_DCHECK(ci); // Keep the number of channels from the function call. For most codecs it @@ -75,12 +76,13 @@ bool RentACodec::IsCodecValid(const CodecInst& codec_inst) { return ACMCodecDB::CodecNumber(codec_inst) >= 0; } -rtc::Maybe RentACodec::IsSupportedNumChannels(CodecId codec_id, - int num_channels) { +rtc::Optional RentACodec::IsSupportedNumChannels(CodecId codec_id, + int num_channels) { auto i = CodecIndexFromId(codec_id); - return i ? rtc::Maybe(ACMCodecDB::codec_settings_[*i].channel_support >= - num_channels) - : rtc::Maybe(); + return i ? rtc::Optional( + ACMCodecDB::codec_settings_[*i].channel_support >= + num_channels) + : rtc::Optional(); } rtc::ArrayView RentACodec::Database() { @@ -88,13 +90,14 @@ rtc::ArrayView RentACodec::Database() { NumberOfCodecs()); } -rtc::Maybe RentACodec::NetEqDecoderFromCodecId(CodecId codec_id, - int num_channels) { - rtc::Maybe i = CodecIndexFromId(codec_id); +rtc::Optional RentACodec::NetEqDecoderFromCodecId( + CodecId codec_id, + int num_channels) { + rtc::Optional i = CodecIndexFromId(codec_id); if (!i) - return rtc::Maybe(); + return rtc::Optional(); const NetEqDecoder ned = ACMCodecDB::neteq_decoders_[*i]; - return rtc::Maybe( + return rtc::Optional( (ned == NetEqDecoder::kDecoderOpus && num_channels == 2) ? NetEqDecoder::kDecoderOpus_2ch : ned); 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 e74ad08996..4daac6ad7e 100644 --- a/webrtc/modules/audio_coding/main/acm2/rent_a_codec.h +++ b/webrtc/modules/audio_coding/main/acm2/rent_a_codec.h @@ -15,7 +15,7 @@ #include "webrtc/base/array_view.h" #include "webrtc/base/constructormagic.h" -#include "webrtc/base/maybe.h" +#include "webrtc/base/optional.h" #include "webrtc/base/scoped_ptr.h" #include "webrtc/typedefs.h" #include "webrtc/modules/audio_coding/codecs/audio_encoder.h" @@ -144,27 +144,28 @@ class RentACodec { return static_cast(CodecId::kNumCodecs); } - static inline rtc::Maybe CodecIndexFromId(CodecId codec_id) { + static inline rtc::Optional CodecIndexFromId(CodecId codec_id) { const int i = static_cast(codec_id); - return i >= 0 && i < static_cast(NumberOfCodecs()) ? rtc::Maybe(i) - : rtc::Maybe(); + return i >= 0 && i < static_cast(NumberOfCodecs()) + ? rtc::Optional(i) + : rtc::Optional(); } - static inline rtc::Maybe CodecIdFromIndex(int codec_index) { + static inline rtc::Optional CodecIdFromIndex(int codec_index) { return static_cast(codec_index) < NumberOfCodecs() - ? rtc::Maybe( + ? rtc::Optional( static_cast(codec_index)) - : rtc::Maybe(); + : rtc::Optional(); } - static rtc::Maybe CodecIdByParams(const char* payload_name, - int sampling_freq_hz, - int channels); - static rtc::Maybe CodecInstById(CodecId codec_id); - static rtc::Maybe CodecIdByInst(const CodecInst& codec_inst); - static rtc::Maybe CodecInstByParams(const char* payload_name, - int sampling_freq_hz, - int channels); + static rtc::Optional CodecIdByParams(const char* payload_name, + int sampling_freq_hz, + int channels); + static rtc::Optional CodecInstById(CodecId codec_id); + static rtc::Optional CodecIdByInst(const CodecInst& codec_inst); + static rtc::Optional CodecInstByParams(const char* payload_name, + int sampling_freq_hz, + int channels); static bool IsCodecValid(const CodecInst& codec_inst); static inline bool IsPayloadTypeValid(int payload_type) { @@ -173,11 +174,11 @@ class RentACodec { static rtc::ArrayView Database(); - static rtc::Maybe IsSupportedNumChannels(CodecId codec_id, - int num_channels); + static rtc::Optional IsSupportedNumChannels(CodecId codec_id, + int num_channels); - static rtc::Maybe NetEqDecoderFromCodecId(CodecId codec_id, - int num_channels); + static rtc::Optional NetEqDecoderFromCodecId(CodecId codec_id, + int num_channels); RentACodec(); ~RentACodec(); diff --git a/webrtc/modules/audio_coding/main/include/audio_coding_module.h b/webrtc/modules/audio_coding/main/include/audio_coding_module.h index 9924d0c349..fc3ddd5486 100644 --- a/webrtc/modules/audio_coding/main/include/audio_coding_module.h +++ b/webrtc/modules/audio_coding/main/include/audio_coding_module.h @@ -13,7 +13,7 @@ #include -#include "webrtc/base/maybe.h" +#include "webrtc/base/optional.h" #include "webrtc/common_types.h" #include "webrtc/modules/audio_coding/main/include/audio_coding_module_typedefs.h" #include "webrtc/modules/audio_coding/neteq/include/neteq.h" @@ -213,7 +213,7 @@ class AudioCodingModule { // Return value: // The send codec, or nothing if we don't have one // - virtual rtc::Maybe SendCodec() const = 0; + virtual rtc::Optional SendCodec() const = 0; /////////////////////////////////////////////////////////////////////////// // int32_t SendFrequency() diff --git a/webrtc/modules/audio_coding/main/test/APITest.cc b/webrtc/modules/audio_coding/main/test/APITest.cc index 81880bee1f..dec14738df 100644 --- a/webrtc/modules/audio_coding/main/test/APITest.cc +++ b/webrtc/modules/audio_coding/main/test/APITest.cc @@ -827,7 +827,7 @@ void APITest::TestRegisteration(char sendSide) { if (!myCodec) { CodecInst ci; AudioCodingModule::Codec(_codecCntrA, &ci); - myCodec = rtc::Maybe(ci); + myCodec = rtc::Optional(ci); } if (!_randomTest) { diff --git a/webrtc/modules/audio_processing/beamformer/array_util.cc b/webrtc/modules/audio_processing/beamformer/array_util.cc index d97beea972..6b1c474269 100644 --- a/webrtc/modules/audio_processing/beamformer/array_util.cc +++ b/webrtc/modules/audio_processing/beamformer/array_util.cc @@ -56,7 +56,7 @@ bool ArePerpendicular(const Point& a, const Point& b) { return std::abs(DotProduct(a, b)) < kMaxDotProduct; } -rtc::Maybe GetDirectionIfLinear( +rtc::Optional GetDirectionIfLinear( const std::vector& array_geometry) { RTC_DCHECK_GT(array_geometry.size(), 1u); const Point first_pair_direction = @@ -65,13 +65,14 @@ rtc::Maybe GetDirectionIfLinear( const Point pair_direction = PairDirection(array_geometry[i - 1], array_geometry[i]); if (!AreParallel(first_pair_direction, pair_direction)) { - return rtc::Maybe(); + return rtc::Optional(); } } - return rtc::Maybe(first_pair_direction); + return rtc::Optional(first_pair_direction); } -rtc::Maybe GetNormalIfPlanar(const std::vector& array_geometry) { +rtc::Optional GetNormalIfPlanar( + const std::vector& array_geometry) { RTC_DCHECK_GT(array_geometry.size(), 1u); const Point first_pair_direction = PairDirection(array_geometry[0], array_geometry[1]); @@ -85,30 +86,30 @@ rtc::Maybe GetNormalIfPlanar(const std::vector& array_geometry) { } } if (is_linear) { - return rtc::Maybe(); + return rtc::Optional(); } const Point normal_direction = CrossProduct(first_pair_direction, pair_direction); for (; i < array_geometry.size(); ++i) { pair_direction = PairDirection(array_geometry[i - 1], array_geometry[i]); if (!ArePerpendicular(normal_direction, pair_direction)) { - return rtc::Maybe(); + return rtc::Optional(); } } - return rtc::Maybe(normal_direction); + return rtc::Optional(normal_direction); } -rtc::Maybe GetArrayNormalIfExists( +rtc::Optional GetArrayNormalIfExists( const std::vector& array_geometry) { - const rtc::Maybe direction = GetDirectionIfLinear(array_geometry); + const rtc::Optional direction = GetDirectionIfLinear(array_geometry); if (direction) { - return rtc::Maybe(Point(direction->y(), -direction->x(), 0.f)); + return rtc::Optional(Point(direction->y(), -direction->x(), 0.f)); } - const rtc::Maybe normal = GetNormalIfPlanar(array_geometry); + const rtc::Optional normal = GetNormalIfPlanar(array_geometry); if (normal && normal->z() < kMaxDotProduct) { return normal; } - return rtc::Maybe(); + return rtc::Optional(); } Point AzimuthToPoint(float azimuth) { diff --git a/webrtc/modules/audio_processing/beamformer/array_util.h b/webrtc/modules/audio_processing/beamformer/array_util.h index 7fff9735a1..f86ad5dee6 100644 --- a/webrtc/modules/audio_processing/beamformer/array_util.h +++ b/webrtc/modules/audio_processing/beamformer/array_util.h @@ -14,7 +14,7 @@ #include #include -#include "webrtc/base/maybe.h" +#include "webrtc/base/optional.h" namespace webrtc { @@ -59,15 +59,16 @@ float GetMinimumSpacing(const std::vector& array_geometry); // If the given array geometry is linear it returns the direction without // normalizing. -rtc::Maybe GetDirectionIfLinear( +rtc::Optional GetDirectionIfLinear( const std::vector& array_geometry); // If the given array geometry is planar it returns the normal without // normalizing. -rtc::Maybe GetNormalIfPlanar(const std::vector& array_geometry); +rtc::Optional GetNormalIfPlanar( + const std::vector& array_geometry); // Returns the normal of an array if it has one and it is in the xy-plane. -rtc::Maybe GetArrayNormalIfExists( +rtc::Optional GetArrayNormalIfExists( const std::vector& array_geometry); // The resulting Point will be in the xy-plane. diff --git a/webrtc/modules/audio_processing/beamformer/nonlinear_beamformer.h b/webrtc/modules/audio_processing/beamformer/nonlinear_beamformer.h index 565c1f349f..b20d9389b7 100644 --- a/webrtc/modules/audio_processing/beamformer/nonlinear_beamformer.h +++ b/webrtc/modules/audio_processing/beamformer/nonlinear_beamformer.h @@ -134,7 +134,7 @@ class NonlinearBeamformer const std::vector array_geometry_; // The normal direction of the array if it has one and it is in the xy-plane. - const rtc::Maybe array_normal_; + const rtc::Optional array_normal_; // Minimum spacing between microphone pairs. const float min_mic_spacing_;