From 8ec568a9ff9b30dd7e8881a0c1bdbc418dc05ff4 Mon Sep 17 00:00:00 2001 From: eladalon Date: Fri, 8 Sep 2017 06:15:52 -0700 Subject: [PATCH] Make CreateRtcLogStreamConfig() return a std::unique_ptr This is done for two reasons: 1. This will be useful in an upcoming CL, when all logging will be done with one function that accepts a std::unique_ptr. 2. Ensure no unnecessary copies when the compiler fails to optimize. BUG=webrtc:8111 TBR=stefan@webrtc.org Review-Url: https://codereview.webrtc.org/3010273002 Cr-Commit-Position: refs/heads/master@{#19746} --- webrtc/call/call.cc | 66 ++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/webrtc/call/call.cc b/webrtc/call/call.cc index 343b3ef41f..e8b51f9bb1 100644 --- a/webrtc/call/call.cc +++ b/webrtc/call/call.cc @@ -93,59 +93,59 @@ const int* FindKeyByValue(const std::map& m, int v) { return nullptr; } -rtclog::StreamConfig CreateRtcLogStreamConfig( +std::unique_ptr CreateRtcLogStreamConfig( const VideoReceiveStream::Config& config) { - rtclog::StreamConfig rtclog_config; - rtclog_config.remote_ssrc = config.rtp.remote_ssrc; - rtclog_config.local_ssrc = config.rtp.local_ssrc; - rtclog_config.rtx_ssrc = config.rtp.rtx_ssrc; - rtclog_config.rtcp_mode = config.rtp.rtcp_mode; - rtclog_config.remb = config.rtp.remb; - rtclog_config.rtp_extensions = config.rtp.extensions; + auto rtclog_config = rtc::MakeUnique(); + rtclog_config->remote_ssrc = config.rtp.remote_ssrc; + rtclog_config->local_ssrc = config.rtp.local_ssrc; + rtclog_config->rtx_ssrc = config.rtp.rtx_ssrc; + rtclog_config->rtcp_mode = config.rtp.rtcp_mode; + rtclog_config->remb = config.rtp.remb; + rtclog_config->rtp_extensions = config.rtp.extensions; for (const auto& d : config.decoders) { const int* search = FindKeyByValue(config.rtp.rtx_associated_payload_types, d.payload_type); - rtclog_config.codecs.emplace_back(d.payload_name, d.payload_type, + rtclog_config->codecs.emplace_back(d.payload_name, d.payload_type, search ? *search : 0); } return rtclog_config; } -rtclog::StreamConfig CreateRtcLogStreamConfig( +std::unique_ptr CreateRtcLogStreamConfig( const VideoSendStream::Config& config, size_t ssrc_index) { - rtclog::StreamConfig rtclog_config; - rtclog_config.local_ssrc = config.rtp.ssrcs[ssrc_index]; + auto rtclog_config = rtc::MakeUnique(); + rtclog_config->local_ssrc = config.rtp.ssrcs[ssrc_index]; if (ssrc_index < config.rtp.rtx.ssrcs.size()) { - rtclog_config.rtx_ssrc = config.rtp.rtx.ssrcs[ssrc_index]; + rtclog_config->rtx_ssrc = config.rtp.rtx.ssrcs[ssrc_index]; } - rtclog_config.rtcp_mode = config.rtp.rtcp_mode; - rtclog_config.rtp_extensions = config.rtp.extensions; + rtclog_config->rtcp_mode = config.rtp.rtcp_mode; + rtclog_config->rtp_extensions = config.rtp.extensions; - rtclog_config.codecs.emplace_back(config.encoder_settings.payload_name, - config.encoder_settings.payload_type, - config.rtp.rtx.payload_type); + rtclog_config->codecs.emplace_back(config.encoder_settings.payload_name, + config.encoder_settings.payload_type, + config.rtp.rtx.payload_type); return rtclog_config; } -rtclog::StreamConfig CreateRtcLogStreamConfig( +std::unique_ptr CreateRtcLogStreamConfig( const AudioReceiveStream::Config& config) { - rtclog::StreamConfig rtclog_config; - rtclog_config.remote_ssrc = config.rtp.remote_ssrc; - rtclog_config.local_ssrc = config.rtp.local_ssrc; - rtclog_config.rtp_extensions = config.rtp.extensions; + auto rtclog_config = rtc::MakeUnique(); + rtclog_config->remote_ssrc = config.rtp.remote_ssrc; + rtclog_config->local_ssrc = config.rtp.local_ssrc; + rtclog_config->rtp_extensions = config.rtp.extensions; return rtclog_config; } -rtclog::StreamConfig CreateRtcLogStreamConfig( +std::unique_ptr CreateRtcLogStreamConfig( const AudioSendStream::Config& config) { - rtclog::StreamConfig rtclog_config; - rtclog_config.local_ssrc = config.rtp.ssrc; - rtclog_config.rtp_extensions = config.rtp.extensions; + auto rtclog_config = rtc::MakeUnique(); + rtclog_config->local_ssrc = config.rtp.ssrc; + rtclog_config->rtp_extensions = config.rtp.extensions; if (config.send_codec_spec) { - rtclog_config.codecs.emplace_back(config.send_codec_spec->format.name, - config.send_codec_spec->payload_type, 0); + rtclog_config->codecs.emplace_back(config.send_codec_spec->format.name, + config.send_codec_spec->payload_type, 0); } return rtclog_config; } @@ -605,7 +605,7 @@ webrtc::AudioSendStream* Call::CreateAudioSendStream( const webrtc::AudioSendStream::Config& config) { TRACE_EVENT0("webrtc", "Call::CreateAudioSendStream"); RTC_DCHECK_CALLED_SEQUENTIALLY(&configuration_sequence_checker_); - event_log_->LogAudioSendStreamConfig(CreateRtcLogStreamConfig(config)); + event_log_->LogAudioSendStreamConfig(*CreateRtcLogStreamConfig(config)); rtc::Optional suspended_rtp_state; { @@ -671,7 +671,7 @@ webrtc::AudioReceiveStream* Call::CreateAudioReceiveStream( const webrtc::AudioReceiveStream::Config& config) { TRACE_EVENT0("webrtc", "Call::CreateAudioReceiveStream"); RTC_DCHECK_CALLED_SEQUENTIALLY(&configuration_sequence_checker_); - event_log_->LogAudioReceiveStreamConfig(CreateRtcLogStreamConfig(config)); + event_log_->LogAudioReceiveStreamConfig(*CreateRtcLogStreamConfig(config)); AudioReceiveStream* receive_stream = new AudioReceiveStream( &audio_receiver_controller_, transport_send_->packet_router(), config, config_.audio_state, event_log_); @@ -732,7 +732,7 @@ webrtc::VideoSendStream* Call::CreateVideoSendStream( for (size_t ssrc_index = 0; ssrc_index < config.rtp.ssrcs.size(); ++ssrc_index) { event_log_->LogVideoSendStreamConfig( - CreateRtcLogStreamConfig(config, ssrc_index)); + *CreateRtcLogStreamConfig(config, ssrc_index)); } // TODO(mflodman): Base the start bitrate on a current bandwidth estimate, if @@ -822,7 +822,7 @@ webrtc::VideoReceiveStream* Call::CreateVideoReceiveStream( } receive_stream->SignalNetworkState(video_network_state_); UpdateAggregateNetworkState(); - event_log_->LogVideoReceiveStreamConfig(CreateRtcLogStreamConfig(config)); + event_log_->LogVideoReceiveStreamConfig(*CreateRtcLogStreamConfig(config)); return receive_stream; }