diff --git a/talk/media/webrtc/webrtcvideoengine.cc b/talk/media/webrtc/webrtcvideoengine.cc index 451b84c61..04092f329 100644 --- a/talk/media/webrtc/webrtcvideoengine.cc +++ b/talk/media/webrtc/webrtcvideoengine.cc @@ -3879,47 +3879,22 @@ bool WebRtcVideoMediaChannel::SetSendParams( // only needed because some unit tests bypass the VideoAdapter, and // others expect behavior from the adapter different than what it // actually does. We should fix the tests and remove this block. - int frame_width = static_cast(frame.width); - int frame_height = static_cast(frame.height); VideoFormat max = send_channel->adapt_format(); + size_t max_width = static_cast(max.width); + size_t max_height = static_cast(max.height); if (!send_channel->last_captured_frame_info().IsSet() || (!frame.screencast && - (frame_width > max.width || frame_height > max.height))) { - frame_width = max.width; - frame_height = max.height; + (frame.width > max_width || frame.height > max_height))) { + frame.width = max_width; + frame.height = max_height; } - // Set the new codec on vie. - webrtc::VideoCodec codec = send_params.codec; - - // Settings for both screencast and non-screencast - codec.width = frame_width; - codec.height = frame_height; + webrtc::VideoCodec codec; + ConfigureVieCodecFromSendParams(channel_id, send_params, frame, &codec); + // TODO(pthatcher): Figure out a clean way to configure the max + // framerate and sanitize the bitrates inside of + // ConfigureVieCodecFromSendParams. codec.maxFramerate = max.framerate(); - codec.targetBitrate = 0; - if (codec.codecType == webrtc::kVideoCodecVP8) { - codec.codecSpecific.VP8.numberOfTemporalLayers = - kDefaultNumberOfTemporalLayers; - codec.codecSpecific.VP8.resilience = webrtc::kResilienceOff; - } - if (frame.screencast) { - // Settings for screencast - codec.mode = webrtc::kScreensharing; - if (codec.codecType == webrtc::kVideoCodecVP8) { - codec.codecSpecific.VP8.denoisingOn = false; - codec.codecSpecific.VP8.automaticResizeOn = false; - codec.codecSpecific.VP8.frameDroppingOn = false; - } - } else { - // Settings for non-screencast - codec.mode = webrtc::kRealtimeVideo; - if (codec.codecType == webrtc::kVideoCodecVP8) { - codec.codecSpecific.VP8.denoisingOn = - options_.video_noise_reduction.GetWithDefaultIfUnset(true); - codec.codecSpecific.VP8.automaticResizeOn = true; - codec.codecSpecific.VP8.frameDroppingOn = true; - } - } SanitizeBitrates(channel_id, &codec); // Get current vie codec. @@ -3958,6 +3933,44 @@ bool WebRtcVideoMediaChannel::SetSendParams( return true; } +bool WebRtcVideoMediaChannel::ConfigureVieCodecFromSendParams( + int channel_id, + const VideoSendParams& send_params, + const CapturedFrameInfo& last_captured_frame_info, + webrtc::VideoCodec* codec_out) { + webrtc::VideoCodec codec = send_params.codec; + + codec.width = static_cast(last_captured_frame_info.width); + codec.height = static_cast(last_captured_frame_info.height); + codec.targetBitrate = 0; + if (codec.codecType == webrtc::kVideoCodecVP8) { + codec.codecSpecific.VP8.numberOfTemporalLayers = + kDefaultNumberOfTemporalLayers; + codec.codecSpecific.VP8.resilience = webrtc::kResilienceOff; + } + + if (last_captured_frame_info.screencast) { + codec.mode = webrtc::kScreensharing; + if (codec.codecType == webrtc::kVideoCodecVP8) { + codec.codecSpecific.VP8.denoisingOn = false; + codec.codecSpecific.VP8.automaticResizeOn = false; + codec.codecSpecific.VP8.frameDroppingOn = false; + } + } else { + codec.mode = webrtc::kRealtimeVideo; + if (codec.codecType == webrtc::kVideoCodecVP8) { + // TODO(pthatcher): Pass in options in VideoSendParams. + codec.codecSpecific.VP8.denoisingOn = + options_.video_noise_reduction.GetWithDefaultIfUnset(true); + codec.codecSpecific.VP8.automaticResizeOn = true; + codec.codecSpecific.VP8.frameDroppingOn = true; + } + } + + *codec_out = codec; + return true; +} + void WebRtcVideoMediaChannel::SanitizeBitrates( int channel_id, webrtc::VideoCodec* codec) { codec->minBitrate = GetBitrate(codec->minBitrate, kMinVideoBitrate); diff --git a/talk/media/webrtc/webrtcvideoengine.h b/talk/media/webrtc/webrtcvideoengine.h index 26b0453b0..cc81ee9d6 100644 --- a/talk/media/webrtc/webrtcvideoengine.h +++ b/talk/media/webrtc/webrtcvideoengine.h @@ -336,6 +336,18 @@ class WebRtcVideoMediaChannel : public rtc::MessageHandler, return options_.conference_mode.GetWithDefaultIfUnset(false); } + // We take lots of things as input from applications (packaged in + // params), but ViE wants lots of those packed instead as a + // webrtc::VideoCodec. This is where we convert between the inputs + // we get from the applications and the input to give to ViE. We + // also configure the codec differently depending on the latest + // frame that we have received (in particular, depending on the + // resolution and whether the it was a screencast frame or not). + virtual bool ConfigureVieCodecFromSendParams( + int channel_id, + const VideoSendParams& send_params, + const CapturedFrameInfo& last_captured_frame_info, + webrtc::VideoCodec* codec); // Checks the current bitrate estimate and modifies the bitrates // accordingly, including converting kAutoBandwidth to the correct defaults. virtual void SanitizeBitrates(