(Auto)update libjingle 79104430-> 79104922

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7602 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/talk/media/webrtc/webrtcvideoengine.cc b/talk/media/webrtc/webrtcvideoengine.cc
index 451b84c..04092f3 100644
--- a/talk/media/webrtc/webrtcvideoengine.cc
+++ b/talk/media/webrtc/webrtcvideoengine.cc
@@ -3879,47 +3879,22 @@
   // 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<int>(frame.width);
-  int frame_height = static_cast<int>(frame.height);
   VideoFormat max = send_channel->adapt_format();
+  size_t max_width = static_cast<size_t>(max.width);
+  size_t max_height = static_cast<size_t>(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 @@
   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<int>(last_captured_frame_info.width);
+  codec.height = static_cast<int>(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 26b0453..cc81ee9 100644
--- a/talk/media/webrtc/webrtcvideoengine.h
+++ b/talk/media/webrtc/webrtcvideoengine.h
@@ -336,6 +336,18 @@
     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(