(Auto)update libjingle 69278008-> 69291002

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6448 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/talk/app/webrtc/mediaconstraintsinterface.cc b/talk/app/webrtc/mediaconstraintsinterface.cc
index c4f9306..b19604b 100644
--- a/talk/app/webrtc/mediaconstraintsinterface.cc
+++ b/talk/app/webrtc/mediaconstraintsinterface.cc
@@ -106,6 +106,10 @@
     "googCpuUnderuseThreshold";
 const char MediaConstraintsInterface::kCpuOveruseThreshold[] =
     "googCpuOveruseThreshold";
+const char MediaConstraintsInterface::kCpuUnderuseEncodeRsdThreshold[] =
+    "googCpuUnderuseEncodeRsdThreshold";
+const char MediaConstraintsInterface::kCpuOveruseEncodeRsdThreshold[] =
+    "googCpuOveruseEncodeRsdThreshold";
 const char MediaConstraintsInterface::kCpuOveruseEncodeUsage[] =
     "googCpuOveruseEncodeUsage";
 const char MediaConstraintsInterface::kHighStartBitrate[] =
diff --git a/talk/app/webrtc/mediaconstraintsinterface.h b/talk/app/webrtc/mediaconstraintsinterface.h
index 63b749c..36cf20d 100644
--- a/talk/app/webrtc/mediaconstraintsinterface.h
+++ b/talk/app/webrtc/mediaconstraintsinterface.h
@@ -122,6 +122,12 @@
   static const char kCpuOveruseDetection[];  // googCpuOveruseDetection
   static const char kCpuUnderuseThreshold[];  // googCpuUnderuseThreshold
   static const char kCpuOveruseThreshold[];  // googCpuOveruseThreshold
+  // Low cpu adaptation threshold for relative standard deviation of encode
+  // time.
+  static const char kCpuUnderuseEncodeRsdThreshold[];
+  // High cpu adaptation threshold for relative standard deviation of encode
+  // time.
+  static const char kCpuOveruseEncodeRsdThreshold[];
   static const char kCpuOveruseEncodeUsage[];  // googCpuOveruseEncodeUsage
   static const char kHighStartBitrate[];  // googHighStartBitrate
   static const char kHighBitrate[];  // googHighBitrate
diff --git a/talk/app/webrtc/webrtcsession.cc b/talk/app/webrtc/webrtcsession.cc
index 887aa4f..17177bd 100644
--- a/talk/app/webrtc/webrtcsession.cc
+++ b/talk/app/webrtc/webrtcsession.cc
@@ -564,6 +564,12 @@
   SetOptionFromOptionalConstraint(constraints,
       MediaConstraintsInterface::kCpuOveruseThreshold,
       &video_options_.cpu_overuse_threshold);
+  SetOptionFromOptionalConstraint(constraints,
+      MediaConstraintsInterface::kCpuUnderuseEncodeRsdThreshold,
+      &video_options_.cpu_underuse_encode_rsd_threshold);
+  SetOptionFromOptionalConstraint(constraints,
+      MediaConstraintsInterface::kCpuOveruseEncodeRsdThreshold,
+      &video_options_.cpu_overuse_encode_rsd_threshold);
 
   if (FindConstraint(
       constraints,
diff --git a/talk/media/base/mediachannel.h b/talk/media/base/mediachannel.h
index 078c073..49902ee 100644
--- a/talk/media/base/mediachannel.h
+++ b/talk/media/base/mediachannel.h
@@ -314,6 +314,10 @@
     cpu_overuse_detection.SetFrom(change.cpu_overuse_detection);
     cpu_underuse_threshold.SetFrom(change.cpu_underuse_threshold);
     cpu_overuse_threshold.SetFrom(change.cpu_overuse_threshold);
+    cpu_underuse_encode_rsd_threshold.SetFrom(
+        change.cpu_underuse_encode_rsd_threshold);
+    cpu_overuse_encode_rsd_threshold.SetFrom(
+        change.cpu_overuse_encode_rsd_threshold);
     cpu_overuse_encode_usage.SetFrom(change.cpu_overuse_encode_usage);
     conference_mode.SetFrom(change.conference_mode);
     process_adaptation_threshhold.SetFrom(change.process_adaptation_threshhold);
@@ -350,6 +354,10 @@
         cpu_overuse_detection == o.cpu_overuse_detection &&
         cpu_underuse_threshold == o.cpu_underuse_threshold &&
         cpu_overuse_threshold == o.cpu_overuse_threshold &&
+        cpu_underuse_encode_rsd_threshold ==
+            o.cpu_underuse_encode_rsd_threshold &&
+        cpu_overuse_encode_rsd_threshold ==
+            o.cpu_overuse_encode_rsd_threshold &&
         cpu_overuse_encode_usage == o.cpu_overuse_encode_usage &&
         conference_mode == o.conference_mode &&
         process_adaptation_threshhold == o.process_adaptation_threshhold &&
@@ -390,6 +398,10 @@
     ost << ToStringIfSet("cpu overuse detection", cpu_overuse_detection);
     ost << ToStringIfSet("cpu underuse threshold", cpu_underuse_threshold);
     ost << ToStringIfSet("cpu overuse threshold", cpu_overuse_threshold);
+    ost << ToStringIfSet("cpu underuse encode rsd threshold",
+                         cpu_underuse_encode_rsd_threshold);
+    ost << ToStringIfSet("cpu overuse encode rsd threshold",
+                         cpu_overuse_encode_rsd_threshold);
     ost << ToStringIfSet("cpu overuse encode usage",
                          cpu_overuse_encode_usage);
     ost << ToStringIfSet("conference mode", conference_mode);
@@ -443,10 +455,22 @@
   // adaptation algorithm. So this option will override the
   // |adapt_input_to_cpu_usage|.
   Settable<bool> cpu_overuse_detection;
-  // Low threshold for cpu overuse adaptation in ms.  (Adapt up)
+  // Low threshold (t1) for cpu overuse adaptation.  (Adapt up)
+  // Metric: encode usage (m1). m1 < t1 => underuse.
   Settable<int> cpu_underuse_threshold;
-  // High threshold for cpu overuse adaptation in ms.  (Adapt down)
+  // High threshold (t1) for cpu overuse adaptation.  (Adapt down)
+  // Metric: encode usage (m1). m1 > t1 => overuse.
   Settable<int> cpu_overuse_threshold;
+  // Low threshold (t2) for cpu overuse adaptation. (Adapt up)
+  // Metric: relative standard deviation of encode time (m2).
+  // Optional threshold. If set, (m1 < t1 && m2 < t2) => underuse.
+  // Note: t2 will have no effect if t1 is not set.
+  Settable<int> cpu_underuse_encode_rsd_threshold;
+  // High threshold (t2) for cpu overuse adaptation. (Adapt down)
+  // Metric: relative standard deviation of encode time (m2).
+  // Optional threshold. If set, (m1 > t1 || m2 > t2) => overuse.
+  // Note: t2 will have no effect if t1 is not set.
+  Settable<int> cpu_overuse_encode_rsd_threshold;
   // Use encode usage for cpu detection.
   Settable<bool> cpu_overuse_encode_usage;
   // Use conference mode?
diff --git a/talk/media/webrtc/webrtcvideoengine.cc b/talk/media/webrtc/webrtcvideoengine.cc
index 0dfa9d0..f1810bf 100644
--- a/talk/media/webrtc/webrtcvideoengine.cc
+++ b/talk/media/webrtc/webrtcvideoengine.cc
@@ -886,6 +886,18 @@
     // Use method based on encode usage.
     overuse_options->low_encode_usage_threshold_percent = underuse_threshold;
     overuse_options->high_encode_usage_threshold_percent = overuse_threshold;
+#ifdef USE_WEBRTC_DEV_BRANCH
+    // Set optional thresholds, if configured.
+    int underuse_rsd_threshold = 0;
+    if (options.cpu_underuse_encode_rsd_threshold.Get(
+        &underuse_rsd_threshold)) {
+      overuse_options->low_encode_time_rsd_threshold = underuse_rsd_threshold;
+    }
+    int overuse_rsd_threshold = 0;
+    if (options.cpu_overuse_encode_rsd_threshold.Get(&overuse_rsd_threshold)) {
+      overuse_options->high_encode_time_rsd_threshold = overuse_rsd_threshold;
+    }
+#endif
   } else {
     // Use default method based on capture jitter.
     overuse_options->low_capture_jitter_threshold_ms =
diff --git a/talk/media/webrtc/webrtcvideoengine_unittest.cc b/talk/media/webrtc/webrtcvideoengine_unittest.cc
index 91a994c..307e594 100644
--- a/talk/media/webrtc/webrtcvideoengine_unittest.cc
+++ b/talk/media/webrtc/webrtcvideoengine_unittest.cc
@@ -1186,6 +1186,11 @@
   EXPECT_EQ(20, cpu_option.high_encode_usage_threshold_percent);
   EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
   EXPECT_TRUE(cpu_option.enable_encode_usage_method);
+#ifdef USE_WEBRTC_DEV_BRANCH
+  // Verify that optional encode rsd thresholds are not set.
+  EXPECT_EQ(-1, cpu_option.low_encode_time_rsd_threshold);
+  EXPECT_EQ(-1, cpu_option.high_encode_time_rsd_threshold);
+#endif
 
   // Add a new send stream and verify that cpu options are set from start.
   EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
@@ -1196,6 +1201,51 @@
   EXPECT_EQ(20, cpu_option.high_encode_usage_threshold_percent);
   EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
   EXPECT_TRUE(cpu_option.enable_encode_usage_method);
+#ifdef USE_WEBRTC_DEV_BRANCH
+  // Verify that optional encode rsd thresholds are not set.
+  EXPECT_EQ(-1, cpu_option.low_encode_time_rsd_threshold);
+  EXPECT_EQ(-1, cpu_option.high_encode_time_rsd_threshold);
+#endif
+}
+
+TEST_F(WebRtcVideoEngineTestFake, SetCpuOveruseOptionsWithEncodeRsdThresholds) {
+  EXPECT_TRUE(SetupEngine());
+  EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
+  int first_send_channel = vie_.GetLastChannel();
+
+  // Set optional encode rsd thresholds and verify cpu options.
+  cricket::VideoOptions options;
+  options.conference_mode.Set(true);
+  options.cpu_underuse_threshold.Set(10);
+  options.cpu_overuse_threshold.Set(20);
+  options.cpu_underuse_encode_rsd_threshold.Set(30);
+  options.cpu_overuse_encode_rsd_threshold.Set(40);
+  options.cpu_overuse_encode_usage.Set(true);
+  EXPECT_TRUE(channel_->SetOptions(options));
+  webrtc::CpuOveruseOptions cpu_option =
+      vie_.GetCpuOveruseOptions(first_send_channel);
+  EXPECT_EQ(10, cpu_option.low_encode_usage_threshold_percent);
+  EXPECT_EQ(20, cpu_option.high_encode_usage_threshold_percent);
+  EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
+  EXPECT_TRUE(cpu_option.enable_encode_usage_method);
+#ifdef USE_WEBRTC_DEV_BRANCH
+  EXPECT_EQ(30, cpu_option.low_encode_time_rsd_threshold);
+  EXPECT_EQ(40, cpu_option.high_encode_time_rsd_threshold);
+#endif
+
+  // Add a new send stream and verify that cpu options are set from start.
+  EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
+  int second_send_channel = vie_.GetLastChannel();
+  EXPECT_NE(first_send_channel, second_send_channel);
+  cpu_option = vie_.GetCpuOveruseOptions(second_send_channel);
+  EXPECT_EQ(10, cpu_option.low_encode_usage_threshold_percent);
+  EXPECT_EQ(20, cpu_option.high_encode_usage_threshold_percent);
+  EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
+  EXPECT_TRUE(cpu_option.enable_encode_usage_method);
+#ifdef USE_WEBRTC_DEV_BRANCH
+  EXPECT_EQ(30, cpu_option.low_encode_time_rsd_threshold);
+  EXPECT_EQ(40, cpu_option.high_encode_time_rsd_threshold);
+#endif
 }
 
 // Test that AddRecvStream doesn't create new channel for 1:1 call.