Optional: Use nullopt and implicit construction in /audio

Changes places where we explicitly construct an Optional to instead use
nullopt or the requisite value type only.

This CL was uploaded by git cl split.

R=solenberg@webrtc.org

Bug: None
Change-Id: I03562600978bdedb9dc93a34aeb0561c66f54aae
Reviewed-on: https://webrtc-review.googlesource.com/23617
Reviewed-by: Fredrik Solenberg <solenberg@webrtc.org>
Commit-Queue: Oskar Sundbom <ossu@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20731}
This commit is contained in:
Oskar Sundbom 2017-11-16 10:57:35 +01:00 committed by Commit Bot
parent c296255c7e
commit 2707fb2782
6 changed files with 52 additions and 58 deletions

View File

@ -180,7 +180,7 @@ webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats() const {
stats.capture_start_ntp_time_ms = call_stats.capture_start_ntp_time_ms_;
if (codec_inst.pltype != -1) {
stats.codec_name = codec_inst.plname;
stats.codec_payload_type = rtc::Optional<int>(codec_inst.pltype);
stats.codec_payload_type = codec_inst.pltype;
}
stats.ext_seqnum = call_stats.extendedMax;
if (codec_inst.plfreq / 1000 > 0) {
@ -272,18 +272,18 @@ rtc::Optional<Syncable::Info> AudioReceiveStream::GetInfo() const {
if (!rtp_receiver->GetLatestTimestamps(
&info.latest_received_capture_timestamp,
&info.latest_receive_time_ms)) {
return rtc::Optional<Syncable::Info>();
return rtc::nullopt;
}
if (rtp_rtcp->RemoteNTP(&info.capture_time_ntp_secs,
&info.capture_time_ntp_frac,
nullptr,
nullptr,
&info.capture_time_source_clock) != 0) {
return rtc::Optional<Syncable::Info>();
return rtc::nullopt;
}
info.current_delay_ms = channel_proxy_->GetDelayEstimate();
return rtc::Optional<Syncable::Info>(info);
return info;
}
uint32_t AudioReceiveStream::GetPlayoutTimestamp() const {

View File

@ -296,7 +296,7 @@ webrtc::AudioSendStream::Stats AudioSendStream::GetStats() const {
if (config_.send_codec_spec) {
const auto& spec = *config_.send_codec_spec;
stats.codec_name = spec.format.name;
stats.codec_payload_type = rtc::Optional<int>(spec.payload_type);
stats.codec_payload_type = spec.payload_type;
// Get data from the last remote RTCP report.
for (const auto& block : channel_proxy_->GetRemoteRTCPReportBlocks()) {

View File

@ -115,14 +115,15 @@ rtc::scoped_refptr<MockAudioEncoderFactory> SetupEncoderFactoryMock() {
.WillByDefault(Return(std::vector<AudioCodecSpec>(
std::begin(kCodecSpecs), std::end(kCodecSpecs))));
ON_CALL(*factory.get(), QueryAudioEncoder(_))
.WillByDefault(Invoke([](const SdpAudioFormat& format) {
for (const auto& spec : kCodecSpecs) {
if (format == spec.format) {
return rtc::Optional<AudioCodecInfo>(spec.info);
}
}
return rtc::Optional<AudioCodecInfo>();
}));
.WillByDefault(Invoke(
[](const SdpAudioFormat& format) -> rtc::Optional<AudioCodecInfo> {
for (const auto& spec : kCodecSpecs) {
if (format == spec.format) {
return spec.info;
}
}
return rtc::nullopt;
}));
ON_CALL(*factory.get(), MakeAudioEncoderMock(_, _, _))
.WillByDefault(Invoke([](int payload_type, const SdpAudioFormat& format,
std::unique_ptr<AudioEncoder>* return_value) {
@ -168,8 +169,7 @@ struct ConfigHelper {
// Use ISAC as default codec so as to prevent unnecessary |voice_engine_|
// calls from the default ctor behavior.
stream_config_.send_codec_spec =
rtc::Optional<AudioSendStream::Config::SendCodecSpec>(
{kIsacPayloadType, kIsacFormat});
AudioSendStream::Config::SendCodecSpec(kIsacPayloadType, kIsacFormat);
stream_config_.voe_channel_id = kChannelId;
stream_config_.rtp.ssrc = kSsrc;
stream_config_.rtp.nack.rtp_history_ms = 200;
@ -358,11 +358,10 @@ TEST(AudioSendStreamTest, ConfigToString) {
config.min_bitrate_bps = 12000;
config.max_bitrate_bps = 34000;
config.send_codec_spec =
rtc::Optional<AudioSendStream::Config::SendCodecSpec>(
{kIsacPayloadType, kIsacFormat});
AudioSendStream::Config::SendCodecSpec(kIsacPayloadType, kIsacFormat);
config.send_codec_spec->nack_enabled = true;
config.send_codec_spec->transport_cc_enabled = false;
config.send_codec_spec->cng_payload_type = rtc::Optional<int>(42);
config.send_codec_spec->cng_payload_type = 42;
config.encoder_factory = MockAudioEncoderFactory::CreateUnusedFactory();
config.rtp.extensions.push_back(
RtpExtension(RtpExtension::kAudioLevelUri, kAudioLevelId));
@ -383,7 +382,7 @@ TEST(AudioSendStreamTest, ConstructDestruct) {
internal::AudioSendStream send_stream(
helper.config(), helper.audio_state(), helper.worker_queue(),
helper.transport(), helper.bitrate_allocator(), helper.event_log(),
helper.rtcp_rtt_stats(), rtc::Optional<RtpState>());
helper.rtcp_rtt_stats(), rtc::nullopt);
}
TEST(AudioSendStreamTest, SendTelephoneEvent) {
@ -391,7 +390,7 @@ TEST(AudioSendStreamTest, SendTelephoneEvent) {
internal::AudioSendStream send_stream(
helper.config(), helper.audio_state(), helper.worker_queue(),
helper.transport(), helper.bitrate_allocator(), helper.event_log(),
helper.rtcp_rtt_stats(), rtc::Optional<RtpState>());
helper.rtcp_rtt_stats(), rtc::nullopt);
helper.SetupMockForSendTelephoneEvent();
EXPECT_TRUE(send_stream.SendTelephoneEvent(kTelephoneEventPayloadType,
kTelephoneEventPayloadFrequency, kTelephoneEventCode,
@ -403,7 +402,7 @@ TEST(AudioSendStreamTest, SetMuted) {
internal::AudioSendStream send_stream(
helper.config(), helper.audio_state(), helper.worker_queue(),
helper.transport(), helper.bitrate_allocator(), helper.event_log(),
helper.rtcp_rtt_stats(), rtc::Optional<RtpState>());
helper.rtcp_rtt_stats(), rtc::nullopt);
EXPECT_CALL(*helper.channel_proxy(), SetInputMute(true));
send_stream.SetMuted(true);
}
@ -413,7 +412,7 @@ TEST(AudioSendStreamTest, AudioBweCorrectObjectsOnChannelProxy) {
internal::AudioSendStream send_stream(
helper.config(), helper.audio_state(), helper.worker_queue(),
helper.transport(), helper.bitrate_allocator(), helper.event_log(),
helper.rtcp_rtt_stats(), rtc::Optional<RtpState>());
helper.rtcp_rtt_stats(), rtc::nullopt);
}
TEST(AudioSendStreamTest, NoAudioBweCorrectObjectsOnChannelProxy) {
@ -421,7 +420,7 @@ TEST(AudioSendStreamTest, NoAudioBweCorrectObjectsOnChannelProxy) {
internal::AudioSendStream send_stream(
helper.config(), helper.audio_state(), helper.worker_queue(),
helper.transport(), helper.bitrate_allocator(), helper.event_log(),
helper.rtcp_rtt_stats(), rtc::Optional<RtpState>());
helper.rtcp_rtt_stats(), rtc::nullopt);
}
TEST(AudioSendStreamTest, GetStats) {
@ -429,7 +428,7 @@ TEST(AudioSendStreamTest, GetStats) {
internal::AudioSendStream send_stream(
helper.config(), helper.audio_state(), helper.worker_queue(),
helper.transport(), helper.bitrate_allocator(), helper.event_log(),
helper.rtcp_rtt_stats(), rtc::Optional<RtpState>());
helper.rtcp_rtt_stats(), rtc::nullopt);
helper.SetupMockForGetStats();
AudioSendStream::Stats stats = send_stream.GetStats();
EXPECT_EQ(kSsrc, stats.local_ssrc);
@ -461,12 +460,11 @@ TEST(AudioSendStreamTest, SendCodecAppliesAudioNetworkAdaptor) {
ConfigHelper helper(false, true);
auto stream_config = helper.config();
stream_config.send_codec_spec =
rtc::Optional<AudioSendStream::Config::SendCodecSpec>({0, kOpusFormat});
AudioSendStream::Config::SendCodecSpec(0, kOpusFormat);
const std::string kAnaConfigString = "abcde";
const std::string kAnaReconfigString = "12345";
stream_config.audio_network_adaptor_config =
rtc::Optional<std::string>(kAnaConfigString);
stream_config.audio_network_adaptor_config = kAnaConfigString;
EXPECT_CALL(helper.mock_encoder_factory(), MakeAudioEncoderMock(_, _, _))
.WillOnce(Invoke([&kAnaConfigString, &kAnaReconfigString](
@ -485,10 +483,9 @@ TEST(AudioSendStreamTest, SendCodecAppliesAudioNetworkAdaptor) {
internal::AudioSendStream send_stream(
stream_config, helper.audio_state(), helper.worker_queue(),
helper.transport(), helper.bitrate_allocator(), helper.event_log(),
helper.rtcp_rtt_stats(), rtc::Optional<RtpState>());
helper.rtcp_rtt_stats(), rtc::nullopt);
stream_config.audio_network_adaptor_config =
rtc::Optional<std::string>(kAnaReconfigString);
stream_config.audio_network_adaptor_config = kAnaReconfigString;
helper.SetupMockForModifyEncoder();
send_stream.Reconfigure(stream_config);
@ -500,8 +497,8 @@ TEST(AudioSendStreamTest, SendCodecCanApplyVad) {
ConfigHelper helper(false, false);
auto stream_config = helper.config();
stream_config.send_codec_spec =
rtc::Optional<AudioSendStream::Config::SendCodecSpec>({9, kG722Format});
stream_config.send_codec_spec->cng_payload_type = rtc::Optional<int>(105);
AudioSendStream::Config::SendCodecSpec(9, kG722Format);
stream_config.send_codec_spec->cng_payload_type = 105;
using ::testing::Invoke;
std::unique_ptr<AudioEncoder> stolen_encoder;
EXPECT_CALL(*helper.channel_proxy(), SetEncoderForMock(_, _))
@ -515,7 +512,7 @@ TEST(AudioSendStreamTest, SendCodecCanApplyVad) {
internal::AudioSendStream send_stream(
stream_config, helper.audio_state(), helper.worker_queue(),
helper.transport(), helper.bitrate_allocator(), helper.event_log(),
helper.rtcp_rtt_stats(), rtc::Optional<RtpState>());
helper.rtcp_rtt_stats(), rtc::nullopt);
// We cannot truly determine if the encoder created is an AudioEncoderCng. It
// is the only reasonable implementation that will return something from
@ -529,7 +526,7 @@ TEST(AudioSendStreamTest, DoesNotPassHigherBitrateThanMaxBitrate) {
internal::AudioSendStream send_stream(
helper.config(), helper.audio_state(), helper.worker_queue(),
helper.transport(), helper.bitrate_allocator(), helper.event_log(),
helper.rtcp_rtt_stats(), rtc::Optional<RtpState>());
helper.rtcp_rtt_stats(), rtc::nullopt);
EXPECT_CALL(*helper.channel_proxy(),
SetBitrate(helper.config().max_bitrate_bps, _));
send_stream.OnBitrateUpdated(helper.config().max_bitrate_bps + 5000, 0.0, 50,
@ -541,7 +538,7 @@ TEST(AudioSendStreamTest, ProbingIntervalOnBitrateUpdated) {
internal::AudioSendStream send_stream(
helper.config(), helper.audio_state(), helper.worker_queue(),
helper.transport(), helper.bitrate_allocator(), helper.event_log(),
helper.rtcp_rtt_stats(), rtc::Optional<RtpState>());
helper.rtcp_rtt_stats(), rtc::nullopt);
EXPECT_CALL(*helper.channel_proxy(), SetBitrate(_, 5000));
send_stream.OnBitrateUpdated(50000, 0.0, 50, 5000);
}
@ -559,12 +556,12 @@ TEST(AudioSendStreamTest, DontRecreateEncoder) {
auto stream_config = helper.config();
stream_config.send_codec_spec =
rtc::Optional<AudioSendStream::Config::SendCodecSpec>({9, kG722Format});
stream_config.send_codec_spec->cng_payload_type = rtc::Optional<int>(105);
AudioSendStream::Config::SendCodecSpec(9, kG722Format);
stream_config.send_codec_spec->cng_payload_type = 105;
internal::AudioSendStream send_stream(
stream_config, helper.audio_state(), helper.worker_queue(),
helper.transport(), helper.bitrate_allocator(), helper.event_log(),
helper.rtcp_rtt_stats(), rtc::Optional<RtpState>());
helper.rtcp_rtt_stats(), rtc::nullopt);
send_stream.Reconfigure(stream_config);
}
@ -573,7 +570,7 @@ TEST(AudioSendStreamTest, ReconfigureTransportCcResetsFirst) {
internal::AudioSendStream send_stream(
helper.config(), helper.audio_state(), helper.worker_queue(),
helper.transport(), helper.bitrate_allocator(), helper.event_log(),
helper.rtcp_rtt_stats(), rtc::Optional<RtpState>());
helper.rtcp_rtt_stats(), rtc::nullopt);
auto new_config = helper.config();
ConfigHelper::AddBweToConfig(&new_config);
EXPECT_CALL(*helper.channel_proxy(),

View File

@ -92,13 +92,12 @@ class NoBandwidthDropAfterDtx : public AudioBweTest {
void ModifyAudioConfigs(
AudioSendStream::Config* send_config,
std::vector<AudioReceiveStream::Config>* receive_configs) override {
send_config->send_codec_spec =
rtc::Optional<AudioSendStream::Config::SendCodecSpec>(
{test::CallTest::kAudioSendPayloadType,
{"OPUS",
48000,
2,
{{"ptime", "60"}, {"usedtx", "1"}, {"stereo", "1"}}}});
send_config->send_codec_spec = AudioSendStream::Config::SendCodecSpec(
test::CallTest::kAudioSendPayloadType,
{"OPUS",
48000,
2,
{{"ptime", "60"}, {"usedtx", "1"}, {"stereo", "1"}}});
send_config->min_bitrate_bps = 6000;
send_config->max_bitrate_bps = 100000;

View File

@ -80,9 +80,8 @@ void AudioEndToEndTest::ModifyAudioConfigs(
// Large bitrate by default.
const webrtc::SdpAudioFormat kDefaultFormat("opus", 48000, 2,
{{"stereo", "1"}});
send_config->send_codec_spec =
rtc::Optional<AudioSendStream::Config::SendCodecSpec>(
{test::CallTest::kAudioSendPayloadType, kDefaultFormat});
send_config->send_codec_spec = AudioSendStream::Config::SendCodecSpec(
test::CallTest::kAudioSendPayloadType, kDefaultFormat);
}
void AudioEndToEndTest::OnAudioStreamsCreated(

View File

@ -77,15 +77,14 @@ class AudioQualityTest : public AudioEndToEndTest {
class Mobile2GNetworkTest : public AudioQualityTest {
void ModifyAudioConfigs(AudioSendStream::Config* send_config,
std::vector<AudioReceiveStream::Config>* receive_configs) override {
send_config->send_codec_spec =
rtc::Optional<AudioSendStream::Config::SendCodecSpec>(
{test::CallTest::kAudioSendPayloadType,
{"OPUS",
48000,
2,
{{"maxaveragebitrate", "6000"},
{"ptime", "60"},
{"stereo", "1"}}}});
send_config->send_codec_spec = AudioSendStream::Config::SendCodecSpec(
test::CallTest::kAudioSendPayloadType,
{"OPUS",
48000,
2,
{{"maxaveragebitrate", "6000"},
{"ptime", "60"},
{"stereo", "1"}}});
}
FakeNetworkPipe::Config GetNetworkPipeConfig() const override {