Chromium Code Reviews| Index: webrtc/media/engine/webrtcvideoengine2.cc |
| diff --git a/webrtc/media/engine/webrtcvideoengine2.cc b/webrtc/media/engine/webrtcvideoengine2.cc |
| index c6bdafee5a336666a4fd46f5aab78c0590525105..b8b2b5a3e5cf1c7af69193553084c5863224b6c4 100644 |
| --- a/webrtc/media/engine/webrtcvideoengine2.cc |
| +++ b/webrtc/media/engine/webrtcvideoengine2.cc |
| @@ -410,9 +410,8 @@ WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoStreams( |
| } |
| void* WebRtcVideoChannel2::WebRtcVideoSendStream::ConfigureVideoEncoderSettings( |
| - const VideoCodec& codec, |
| - const VideoOptions& options, |
| - bool is_screencast) { |
| + const VideoCodec& codec) { |
| + bool is_screencast = parameters_.options.is_screencast.value_or(false); |
| // No automatic resizing when using simulcast or screencast. |
| bool automatic_resize = |
| !is_screencast && parameters_.config.rtp.ssrcs.size() == 1; |
| @@ -423,8 +422,8 @@ void* WebRtcVideoChannel2::WebRtcVideoSendStream::ConfigureVideoEncoderSettings( |
| denoising = false; |
| } else { |
| // Use codec default if video_noise_reduction is unset. |
| - codec_default_denoising = !options.video_noise_reduction; |
| - denoising = options.video_noise_reduction.value_or(false); |
| + codec_default_denoising = !parameters_.options.video_noise_reduction; |
| + denoising = parameters_.options.video_noise_reduction.value_or(false); |
| } |
| if (CodecNamesEq(codec.name, kH264CodecName)) { |
| @@ -1528,7 +1527,7 @@ WebRtcVideoChannel2::WebRtcVideoSendStream::WebRtcVideoSendStream( |
| : webrtc::RtcpMode::kCompound; |
| if (codec_settings) { |
| - SetCodecAndOptions(*codec_settings, parameters_.options); |
| + SetCodecAndApplyOptions(*codec_settings); |
| } |
| } |
| @@ -1588,8 +1587,7 @@ void WebRtcVideoChannel2::WebRtcVideoSendStream::OnFrame( |
| last_frame_timestamp_ms_ = first_frame_timestamp_ms_ + frame_delta_ms; |
| video_frame.set_render_time_ms(last_frame_timestamp_ms_); |
| // Reconfigure codec if necessary. |
| - SetDimensions(video_frame.width(), video_frame.height(), |
| - capturer_->IsScreencast()); |
| + SetDimensions(video_frame.width(), video_frame.height()); |
| last_rotation_ = video_frame.rotation(); |
| stream_->Input()->IncomingCapturedFrame(video_frame); |
| @@ -1668,13 +1666,11 @@ WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const { |
| void WebRtcVideoChannel2::WebRtcVideoSendStream::SetOptions( |
| const VideoOptions& options) { |
| rtc::CritScope cs(&lock_); |
| - if (parameters_.codec_settings) { |
| - LOG(LS_INFO) << "SetCodecAndOptions because of SetOptions; options=" |
| - << options.ToString(); |
| - SetCodecAndOptions(*parameters_.codec_settings, options); |
| - } else { |
| - parameters_.options = options; |
| - } |
| + |
| + parameters_.options.SetAll(options); |
| + // Screencast flag may have changed. Reconfigure encoder |
| + // settings on the next frame or stream recreation. |
| + pending_encoder_reconfiguration_ = true; |
| } |
| webrtc::VideoCodecType CodecTypeFromName(const std::string& name) { |
| @@ -1731,9 +1727,8 @@ void WebRtcVideoChannel2::WebRtcVideoSendStream::DestroyVideoEncoder( |
| delete encoder->encoder; |
| } |
| -void WebRtcVideoChannel2::WebRtcVideoSendStream::SetCodecAndOptions( |
| - const VideoCodecSettings& codec_settings, |
| - const VideoOptions& options) { |
| +void WebRtcVideoChannel2::WebRtcVideoSendStream::SetCodecAndApplyOptions( |
| + const VideoCodecSettings& codec_settings) { |
| parameters_.encoder_config = |
| CreateVideoEncoderConfig(last_dimensions_, codec_settings.codec); |
| RTC_DCHECK(!parameters_.encoder_config.streams.empty()); |
| @@ -1765,15 +1760,15 @@ void WebRtcVideoChannel2::WebRtcVideoSendStream::SetCodecAndOptions( |
| HasNack(codec_settings.codec) ? kNackHistoryMs : 0; |
| parameters_.config.suspend_below_min_bitrate = |
| - options.suspend_below_min_bitrate.value_or(false); |
| + parameters_.options.suspend_below_min_bitrate.value_or(false); |
|
pbos-webrtc
2016/02/26 13:06:57
This one is now ignored through SetOptions current
nisse-webrtc
2016/02/26 14:36:46
If passed through SetOptions, parameters_.options.
|
| parameters_.codec_settings = |
| rtc::Optional<WebRtcVideoChannel2::VideoCodecSettings>(codec_settings); |
| - parameters_.options = options; |
| LOG(LS_INFO) |
| - << "RecreateWebRtcStream (send) because of SetCodecAndOptions; options=" |
| - << options.ToString(); |
| + << "RecreateWebRtcStream (send) because of " |
| + "SetCodecAndApplyOptions; options=" |
| + << parameters_.options.ToString(); |
| RecreateWebRtcStream(); |
| if (allocated_encoder_.encoder != new_encoder.encoder) { |
| DestroyVideoEncoder(&allocated_encoder_); |
| @@ -1810,21 +1805,20 @@ void WebRtcVideoChannel2::WebRtcVideoSendStream::SetSendParameters( |
| parameters_.conference_mode = *params.conference_mode; |
| } |
| // Set codecs and options. |
| + if (params.options) |
| + parameters_.options.SetAll(*params.options); |
| if (params.codec) { |
| - SetCodecAndOptions(*params.codec, |
| - params.options ? *params.options : parameters_.options); |
| + SetCodecAndApplyOptions(*params.codec); |
| return; |
| } else if (params.options) { |
| // Reconfigure if codecs are already set. |
| if (parameters_.codec_settings) { |
| - SetCodecAndOptions(*parameters_.codec_settings, *params.options); |
| + SetCodecAndApplyOptions(*parameters_.codec_settings); |
| return; |
| - } else { |
| - parameters_.options = *params.options; |
| } |
| } |
| else if (params.conference_mode && parameters_.codec_settings) { |
| - SetCodecAndOptions(*parameters_.codec_settings, parameters_.options); |
| + SetCodecAndApplyOptions(*parameters_.codec_settings); |
| return; |
| } |
| if (recreate_stream) { |
| @@ -1838,7 +1832,8 @@ WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig( |
| const Dimensions& dimensions, |
| const VideoCodec& codec) const { |
| webrtc::VideoEncoderConfig encoder_config; |
| - if (dimensions.is_screencast) { |
| + bool is_screencast = parameters_.options.is_screencast.value_or(false); |
| + if (is_screencast) { |
| encoder_config.min_transmit_bitrate_bps = |
| 1000 * parameters_.options.screencast_min_bitrate_kbps.value_or(0); |
| encoder_config.content_type = |
| @@ -1852,7 +1847,7 @@ WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig( |
| // Restrict dimensions according to codec max. |
| int width = dimensions.width; |
| int height = dimensions.height; |
| - if (!dimensions.is_screencast) { |
| + if (!is_screencast) { |
| if (codec.width < width) |
| width = codec.width; |
| if (codec.height < height) |
| @@ -1867,7 +1862,7 @@ WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig( |
| // number of negotiated ssrcs. But if the codec is blacklisted for simulcast |
| // or a screencast, only configure a single stream. |
| size_t stream_count = parameters_.config.rtp.ssrcs.size(); |
| - if (IsCodecBlacklistedForSimulcast(codec.name) || dimensions.is_screencast) { |
| + if (IsCodecBlacklistedForSimulcast(codec.name) || is_screencast) { |
| stream_count = 1; |
| } |
| @@ -1876,7 +1871,7 @@ WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig( |
| parameters_.max_bitrate_bps, stream_count); |
| // Conference mode screencast uses 2 temporal layers split at 100kbit. |
| - if (parameters_.conference_mode && dimensions.is_screencast && |
| + if (parameters_.conference_mode && is_screencast && |
| encoder_config.streams.size() == 1) { |
| ScreenshareLayerConfig config = ScreenshareLayerConfig::GetDefault(); |
| @@ -1895,20 +1890,15 @@ WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig( |
| void WebRtcVideoChannel2::WebRtcVideoSendStream::SetDimensions( |
| int width, |
| - int height, |
| - bool is_screencast) { |
| + int height) { |
| if (last_dimensions_.width == width && last_dimensions_.height == height && |
| - last_dimensions_.is_screencast == is_screencast && |
| !pending_encoder_reconfiguration_) { |
| // Configured using the same parameters, do not reconfigure. |
| return; |
| } |
| - LOG(LS_INFO) << "SetDimensions: " << width << "x" << height |
| - << (is_screencast ? " (screencast)" : " (not screencast)"); |
| last_dimensions_.width = width; |
| last_dimensions_.height = height; |
| - last_dimensions_.is_screencast = is_screencast; |
| RTC_DCHECK(!parameters_.encoder_config.streams.empty()); |
| @@ -1919,7 +1909,7 @@ void WebRtcVideoChannel2::WebRtcVideoSendStream::SetDimensions( |
| CreateVideoEncoderConfig(last_dimensions_, codec_settings.codec); |
| encoder_config.encoder_specific_settings = ConfigureVideoEncoderSettings( |
| - codec_settings.codec, parameters_.options, is_screencast); |
| + codec_settings.codec); |
| bool stream_reconfigured = stream_->ReconfigureVideoEncoder(encoder_config); |
| @@ -1927,8 +1917,6 @@ void WebRtcVideoChannel2::WebRtcVideoSendStream::SetDimensions( |
| pending_encoder_reconfiguration_ = false; |
| if (!stream_reconfigured) { |
| - LOG(LS_WARNING) << "Failed to reconfigure video encoder for dimensions: " |
| - << width << "x" << height; |
| return; |
| } |
| @@ -2067,11 +2055,12 @@ void WebRtcVideoChannel2::WebRtcVideoSendStream::RecreateWebRtcStream() { |
| } |
| RTC_CHECK(parameters_.codec_settings); |
| + RTC_DCHECK_EQ((parameters_.encoder_config.content_type == |
| + webrtc::VideoEncoderConfig::ContentType::kScreen), |
| + parameters_.options.is_screencast.value_or(false)) |
| + << "encoder content type inconsistent with screencast option"; |
| parameters_.encoder_config.encoder_specific_settings = |
| - ConfigureVideoEncoderSettings( |
| - parameters_.codec_settings->codec, parameters_.options, |
| - parameters_.encoder_config.content_type == |
| - webrtc::VideoEncoderConfig::ContentType::kScreen); |
| + ConfigureVideoEncoderSettings(parameters_.codec_settings->codec); |
| webrtc::VideoSendStream::Config config = parameters_.config; |
| if (!config.rtp.rtx.ssrcs.empty() && config.rtp.rtx.payload_type == -1) { |