(Auto)update libjingle 63777286-> 63837929

git-svn-id: http://webrtc.googlecode.com/svn/trunk@5797 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/talk/app/webrtc/mediaconstraintsinterface.cc b/talk/app/webrtc/mediaconstraintsinterface.cc
index 732cdcd..72c5ffc 100644
--- a/talk/app/webrtc/mediaconstraintsinterface.cc
+++ b/talk/app/webrtc/mediaconstraintsinterface.cc
@@ -69,13 +69,6 @@
 const char MediaConstraintsInterface::kLeakyBucket[] = "googLeakyBucket";
 const char MediaConstraintsInterface::kTemporalLayeredScreencast[] =
     "googTemporalLayeredScreencast";
-// TODO(ronghuawu): Remove once cpu overuse detection is stable.
-const char MediaConstraintsInterface::kCpuOveruseDetection[] =
-    "googCpuOveruseDetection";
-const char MediaConstraintsInterface::kCpuUnderuseThreshold[] =
-    "googCpuUnderuseThreshold";
-const char MediaConstraintsInterface::kCpuOveruseThreshold[] =
-    "googCpuOveruseThreshold";
 
 // Google-specific PeerConnection constraint keys.
 const char MediaConstraintsInterface::kImprovedWifiBwe[] =
@@ -84,6 +77,15 @@
     "googScreencastMinBitrate";
 const char MediaConstraintsInterface::kSkipEncodingUnusedStreams[] =
     "googSkipEncodingUnusedStreams";
+// TODO(ronghuawu): Remove once cpu overuse detection is stable.
+const char MediaConstraintsInterface::kCpuOveruseDetection[] =
+    "googCpuOveruseDetection";
+const char MediaConstraintsInterface::kCpuUnderuseThreshold[] =
+    "googCpuUnderuseThreshold";
+const char MediaConstraintsInterface::kCpuOveruseThreshold[] =
+    "googCpuOveruseThreshold";
+const char MediaConstraintsInterface::kCpuOveruseEncodeUsage[] =
+    "googCpuOveruseEncodeUsage";
 
 // Constraint keys for CreateOffer / CreateAnswer defined in W3C specification.
 const char MediaConstraintsInterface::kOfferToReceiveAudio[] =
diff --git a/talk/app/webrtc/mediaconstraintsinterface.h b/talk/app/webrtc/mediaconstraintsinterface.h
index d4e4ba5..8c1ba17 100644
--- a/talk/app/webrtc/mediaconstraintsinterface.h
+++ b/talk/app/webrtc/mediaconstraintsinterface.h
@@ -90,15 +90,16 @@
 
   // googTemporalLayeredScreencast
   static const char kTemporalLayeredScreencast[];
-  static const char kCpuOveruseDetection[];
-  static const char kCpuUnderuseThreshold[];
-  static const char kCpuOveruseThreshold[];
 
   // Google-specific PeerConnection constraint keys.
   static const char kImprovedWifiBwe[];  // googImprovedWifiBwe
   static const char kScreencastMinBitrate[];  // googScreencastMinBitrate
   static const char kSkipEncodingUnusedStreams[];
     // googSkipEncodingUnusedStreams
+  static const char kCpuOveruseDetection[];
+  static const char kCpuUnderuseThreshold[];
+  static const char kCpuOveruseThreshold[];
+  static const char kCpuOveruseEncodeUsage[];
 
   // Constraint keys for CreateOffer / CreateAnswer
   // Specified by the W3C PeerConnection spec
diff --git a/talk/app/webrtc/videosource.cc b/talk/app/webrtc/videosource.cc
index 4057318..eb4ab97 100644
--- a/talk/app/webrtc/videosource.cc
+++ b/talk/app/webrtc/videosource.cc
@@ -181,13 +181,7 @@
   } else if (constraint.key == MediaConstraintsInterface::kNoiseReduction ||
              constraint.key == MediaConstraintsInterface::kLeakyBucket ||
              constraint.key ==
-                 MediaConstraintsInterface::kTemporalLayeredScreencast ||
-             constraint.key ==
-                 MediaConstraintsInterface::kCpuOveruseDetection ||
-             constraint.key ==
-                 MediaConstraintsInterface::kCpuUnderuseThreshold ||
-             constraint.key ==
-                 MediaConstraintsInterface::kCpuOveruseThreshold) {
+                 MediaConstraintsInterface::kTemporalLayeredScreencast) {
     // These are actually options, not constraints, so they can be satisfied
     // regardless of the format.
     return true;
@@ -271,22 +265,6 @@
   return *best_it;
 }
 
-// Set |option| to the highest-priority value of |key| in the optional
-// constraints if the key is found and has a valid value.
-void ExtractOptionalOption(const MediaConstraintsInterface* all_constraints,
-    const std::string& key, cricket::Settable<int>* option) {
-  if (!all_constraints) {
-    return;
-  }
-  std::string string_value;
-  int value;
-  if (all_constraints->GetOptional().FindFirst(key, &string_value)) {
-    if (talk_base::FromString(string_value, &value)) {
-      option->Set(value);
-    }
-  }
-}
-
 // Set |option| to the highest-priority value of |key| in the constraints.
 // Return false if the key is mandatory, and the value is invalid.
 bool ExtractOption(const MediaConstraintsInterface* all_constraints,
@@ -317,15 +295,6 @@
   all_valid &= ExtractOption(all_constraints,
       MediaConstraintsInterface::kTemporalLayeredScreencast,
       &(options->video_temporal_layer_screencast));
-  all_valid &= ExtractOption(all_constraints,
-      MediaConstraintsInterface::kCpuOveruseDetection,
-      &(options->cpu_overuse_detection));
-  ExtractOptionalOption(all_constraints,
-      MediaConstraintsInterface::kCpuUnderuseThreshold,
-      &(options->cpu_underuse_threshold));
-  ExtractOptionalOption(all_constraints,
-      MediaConstraintsInterface::kCpuOveruseThreshold,
-      &(options->cpu_overuse_threshold));
 
   return all_valid;
 }
diff --git a/talk/app/webrtc/videosource_unittest.cc b/talk/app/webrtc/videosource_unittest.cc
index 309104e..4381176 100644
--- a/talk/app/webrtc/videosource_unittest.cc
+++ b/talk/app/webrtc/videosource_unittest.cc
@@ -370,12 +370,6 @@
       MediaConstraintsInterface::kTemporalLayeredScreencast, "false");
   constraints.AddOptional(
       MediaConstraintsInterface::kLeakyBucket, "true");
-  constraints.AddOptional(
-      MediaConstraintsInterface::kCpuOveruseDetection, "true");
-  constraints.AddOptional(
-      MediaConstraintsInterface::kCpuUnderuseThreshold, 12);
-  constraints.AddOptional(
-      MediaConstraintsInterface::kCpuOveruseThreshold, 22);
 
   CreateVideoSource(&constraints);
 
@@ -387,12 +381,6 @@
   EXPECT_FALSE(value);
   EXPECT_TRUE(source_->options()->video_leaky_bucket.Get(&value));
   EXPECT_TRUE(value);
-  EXPECT_TRUE(source_->options()->
-      cpu_overuse_detection.GetWithDefaultIfUnset(false));
-  EXPECT_EQ(12, source_->options()->
-      cpu_underuse_threshold.GetWithDefaultIfUnset(23));
-  EXPECT_EQ(22, source_->options()->
-      cpu_overuse_threshold.GetWithDefaultIfUnset(23));
 }
 
 TEST_F(VideoSourceTest, OptionNotSet) {
@@ -400,10 +388,6 @@
   CreateVideoSource(&constraints);
   bool value;
   EXPECT_FALSE(source_->options()->video_noise_reduction.Get(&value));
-  EXPECT_FALSE(source_->options()->cpu_overuse_detection.Get(&value));
-  int int_value;
-  EXPECT_FALSE(source_->options()->cpu_underuse_threshold.Get(&int_value));
-  EXPECT_FALSE(source_->options()->cpu_overuse_threshold.Get(&int_value));
 }
 
 TEST_F(VideoSourceTest, MandatoryOptionOverridesOptional) {
@@ -456,10 +440,6 @@
       MediaConstraintsInterface::kNoiseReduction, "true");
   constraints.AddOptional(
       MediaConstraintsInterface::kLeakyBucket, "not boolean");
-  constraints.AddOptional(
-      MediaConstraintsInterface::kCpuUnderuseThreshold, "12");
-  constraints.AddOptional(
-      MediaConstraintsInterface::kCpuOveruseThreshold, "not int");
 
   CreateVideoSource(&constraints);
 
@@ -469,10 +449,6 @@
   EXPECT_TRUE(source_->options()->video_noise_reduction.Get(&value));
   EXPECT_TRUE(value);
   EXPECT_FALSE(source_->options()->video_leaky_bucket.Get(&value));
-  int int_value = 0;
-  EXPECT_TRUE(source_->options()->cpu_underuse_threshold.Get(&int_value));
-  EXPECT_EQ(12, int_value);
-  EXPECT_FALSE(source_->options()->cpu_overuse_threshold.Get(&int_value));
 }
 
 TEST_F(VideoSourceTest, InvalidOptionValueMandatory) {
diff --git a/talk/app/webrtc/webrtcsession.cc b/talk/app/webrtc/webrtcsession.cc
index f987993..af9d205 100644
--- a/talk/app/webrtc/webrtcsession.cc
+++ b/talk/app/webrtc/webrtcsession.cc
@@ -359,6 +359,23 @@
   return MakeErrorString(kPushDownTDFailed, desc);
 }
 
+// Set |option| to the highest-priority value of |key| in the optional
+// constraints if the key is found and has a valid value.
+static void SetOptionFromOptionalConstraint(
+    const MediaConstraintsInterface* constraints,
+    const std::string& key, cricket::Settable<int>* option) {
+  if (!constraints) {
+    return;
+  }
+  std::string string_value;
+  int value;
+  if (constraints->GetOptional().FindFirst(key, &string_value)) {
+    if (talk_base::FromString(string_value, &value)) {
+      option->Set(value);
+    }
+  }
+}
+
 // Help class used to remember if a a remote peer has requested ice restart by
 // by sending a description with new ice ufrag and password.
 class IceRestartAnswerLatch {
@@ -525,15 +542,31 @@
     video_options_.skip_encoding_unused_streams.Set(value);
   }
 
-  std::string string_value;
-  if (constraints &&
-      constraints->GetOptional().FindFirst(
-        MediaConstraintsInterface::kScreencastMinBitrate,
-        &string_value)) {
-    int bitrate;
-    if (talk_base::FromString(string_value, &bitrate)) {
-      video_options_.screencast_min_bitrate.Set(bitrate);
-    }
+  SetOptionFromOptionalConstraint(constraints,
+      MediaConstraintsInterface::kScreencastMinBitrate,
+      &video_options_.screencast_min_bitrate);
+
+  // Find constraints for cpu overuse detection.
+  SetOptionFromOptionalConstraint(constraints,
+      MediaConstraintsInterface::kCpuUnderuseThreshold,
+      &video_options_.cpu_underuse_threshold);
+  SetOptionFromOptionalConstraint(constraints,
+      MediaConstraintsInterface::kCpuOveruseThreshold,
+      &video_options_.cpu_overuse_threshold);
+
+  if (FindConstraint(
+      constraints,
+      MediaConstraintsInterface::kCpuOveruseDetection,
+      &value,
+      NULL)) {
+    video_options_.cpu_overuse_detection.Set(value);
+  }
+  if (FindConstraint(
+      constraints,
+      MediaConstraintsInterface::kCpuOveruseEncodeUsage,
+      &value,
+      NULL)) {
+    video_options_.cpu_overuse_encode_usage.Set(value);
   }
 
   // Find improved wifi bwe constraint.
diff --git a/talk/app/webrtc/webrtcsession.h b/talk/app/webrtc/webrtcsession.h
index 98effa6..1b8dac8 100644
--- a/talk/app/webrtc/webrtcsession.h
+++ b/talk/app/webrtc/webrtcsession.h
@@ -42,6 +42,7 @@
 #include "talk/session/media/mediasession.h"
 
 namespace cricket {
+
 class BaseChannel;
 class ChannelManager;
 class DataChannel;
@@ -50,6 +51,7 @@
 class VideoCapturer;
 class VideoChannel;
 class VoiceChannel;
+
 }  // namespace cricket
 
 namespace webrtc {
diff --git a/talk/base/win32toolhelp_unittest.cc b/talk/base/win32toolhelp_unittest.cc
index 529bef9..e740345 100644
--- a/talk/base/win32toolhelp_unittest.cc
+++ b/talk/base/win32toolhelp_unittest.cc
@@ -267,7 +267,6 @@
 }
 
 TEST_F(Win32ToolhelpTest, TestCurrentProcess) {
-  int size = MAX_PATH;
   WCHAR buf[MAX_PATH];
   GetModuleFileName(NULL, buf, ARRAY_SIZE(buf));
   std::wstring name = ToUtf16(Pathname(ToUtf8(buf)).filename());
diff --git a/talk/media/base/mediachannel.h b/talk/media/base/mediachannel.h
index a069d07..873c1ff 100644
--- a/talk/media/base/mediachannel.h
+++ b/talk/media/base/mediachannel.h
@@ -317,6 +317,7 @@
     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_overuse_encode_usage.SetFrom(change.cpu_overuse_encode_usage);
     conference_mode.SetFrom(change.conference_mode);
     process_adaptation_threshhold.SetFrom(change.process_adaptation_threshhold);
     system_low_adaptation_threshhold.SetFrom(
@@ -352,6 +353,7 @@
         cpu_overuse_detection == o.cpu_overuse_detection &&
         cpu_underuse_threshold == o.cpu_underuse_threshold &&
         cpu_overuse_threshold == o.cpu_overuse_threshold &&
+        cpu_overuse_encode_usage == o.cpu_overuse_encode_usage &&
         conference_mode == o.conference_mode &&
         process_adaptation_threshhold == o.process_adaptation_threshhold &&
         system_low_adaptation_threshhold ==
@@ -391,6 +393,8 @@
     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 overuse encode usage",
+                         cpu_overuse_encode_usage);
     ost << ToStringIfSet("conference mode", conference_mode);
     ost << ToStringIfSet("process", process_adaptation_threshhold);
     ost << ToStringIfSet("low", system_low_adaptation_threshhold);
@@ -446,6 +450,8 @@
   Settable<int> cpu_underuse_threshold;
   // High threshold for cpu overuse adaptation in ms.  (Adapt down)
   Settable<int> cpu_overuse_threshold;
+  // Use encode usage for cpu detection.
+  Settable<bool> cpu_overuse_encode_usage;
   // Use conference mode?
   Settable<bool> conference_mode;
   // Threshhold for process cpu adaptation.  (Process limit)
diff --git a/talk/media/webrtc/fakewebrtcvideoengine.h b/talk/media/webrtc/fakewebrtcvideoengine.h
index 1d4f19a..4096ff1 100644
--- a/talk/media/webrtc/fakewebrtcvideoengine.h
+++ b/talk/media/webrtc/fakewebrtcvideoengine.h
@@ -300,6 +300,9 @@
           overuse_observer_(NULL) {
       ssrcs_[0] = 0;  // default ssrc.
       memset(&send_codec, 0, sizeof(send_codec));
+#ifdef USE_WEBRTC_DEV_BRANCH
+      memset(&overuse_options_, 0, sizeof(overuse_options_));
+#endif
     }
     int capture_id_;
     int original_channel_id_;
@@ -338,6 +341,9 @@
     unsigned int receive_bandwidth_;
     bool suspend_below_min_bitrate_;
     webrtc::CpuOveruseObserver* overuse_observer_;
+#ifdef USE_WEBRTC_DEV_BRANCH
+    webrtc::CpuOveruseOptions overuse_options_;
+#endif
   };
   class Capturer : public webrtc::ViEExternalCapture {
    public:
@@ -539,6 +545,12 @@
     WEBRTC_ASSERT_CHANNEL(channel);
     return channels_.find(channel)->second->overuse_observer_;
   }
+#ifdef USE_WEBRTC_DEV_BRANCH
+  webrtc::CpuOveruseOptions GetCpuOveruseOptions(int channel) const {
+    WEBRTC_ASSERT_CHANNEL(channel);
+    return channels_.find(channel)->second->overuse_options_;
+  }
+#endif
   int GetRtxSsrc(int channel, int simulcast_idx) const {
     WEBRTC_ASSERT_CHANNEL(channel);
     if (channels_.find(channel)->second->rtx_ssrcs_.find(simulcast_idx) ==
@@ -666,6 +678,14 @@
     return 0;
   }
   WEBRTC_STUB(CpuOveruseMeasures, (int, int*, int*, int*, int*));
+#ifdef USE_WEBRTC_DEV_BRANCH
+  WEBRTC_FUNC(SetCpuOveruseOptions,
+      (int channel, const webrtc::CpuOveruseOptions& options)) {
+    WEBRTC_CHECK_CHANNEL(channel);
+    channels_[channel]->overuse_options_ = options;
+    return 0;
+  }
+#endif
   WEBRTC_STUB(ConnectAudioChannel, (const int, const int));
   WEBRTC_STUB(DisconnectAudioChannel, (const int));
   WEBRTC_FUNC(StartSend, (const int channel)) {
diff --git a/talk/media/webrtc/webrtcvideoengine.cc b/talk/media/webrtc/webrtcvideoengine.cc
index 169bad5..f48596a 100644
--- a/talk/media/webrtc/webrtcvideoengine.cc
+++ b/talk/media/webrtc/webrtcvideoengine.cc
@@ -842,6 +842,38 @@
       video_format.interval);
 }
 
+#ifdef USE_WEBRTC_DEV_BRANCH
+static bool GetCpuOveruseOptions(const VideoOptions& options,
+                                 webrtc::CpuOveruseOptions* overuse_options) {
+  int underuse_threshold = 0;
+  int overuse_threshold = 0;
+  if (!options.cpu_underuse_threshold.Get(&underuse_threshold) ||
+      !options.cpu_overuse_threshold.Get(&overuse_threshold)) {
+    return false;
+  }
+  if (underuse_threshold <= 0 || overuse_threshold <= 0) {
+    return false;
+  }
+  // Valid thresholds.
+  bool encode_usage =
+      options.cpu_overuse_encode_usage.GetWithDefaultIfUnset(false);
+  overuse_options->enable_capture_jitter_method = !encode_usage;
+  overuse_options->enable_encode_usage_method = encode_usage;
+  if (encode_usage) {
+    // Use method based on encode usage.
+    overuse_options->low_encode_usage_threshold_percent = underuse_threshold;
+    overuse_options->high_encode_usage_threshold_percent = overuse_threshold;
+  } else {
+    // Use default method based on capture jitter.
+    overuse_options->low_capture_jitter_threshold_ms =
+        static_cast<float>(underuse_threshold);
+    overuse_options->high_capture_jitter_threshold_ms =
+        static_cast<float>(overuse_threshold);
+  }
+  return true;
+}
+#endif
+
 WebRtcVideoEngine::WebRtcVideoEngine() {
   Construct(new ViEWrapper(), new ViETraceWrapper(), NULL,
       new talk_base::CpuMonitor(NULL));
@@ -2981,6 +3013,16 @@
           it->second->channel_id(), config);
     }
   }
+  webrtc::CpuOveruseOptions overuse_options;
+  if (GetCpuOveruseOptions(options_, &overuse_options)) {
+    for (SendChannelMap::iterator it = send_channels_.begin();
+         it != send_channels_.end(); ++it) {
+      if (engine()->vie()->base()->SetCpuOveruseOptions(
+          it->second->channel_id(), overuse_options) != 0) {
+        LOG_RTCERR1(SetCpuOveruseOptions, it->second->channel_id());
+      }
+    }
+  }
 #endif
   return true;
 }
@@ -3414,6 +3456,16 @@
     send_channel->SetCpuOveruseDetection(true);
   }
 
+#ifdef USE_WEBRTC_DEV_BRANCH
+  webrtc::CpuOveruseOptions overuse_options;
+  if (GetCpuOveruseOptions(options_, &overuse_options)) {
+    if (engine()->vie()->base()->SetCpuOveruseOptions(channel_id,
+                                                      overuse_options) != 0) {
+      LOG_RTCERR1(SetCpuOveruseOptions, channel_id);
+    }
+  }
+#endif
+
   // Register encoder observer for outgoing framerate and bitrate.
   if (engine()->vie()->codec()->RegisterEncoderObserver(
       channel_id, *send_channel->encoder_observer()) != 0) {
diff --git a/talk/media/webrtc/webrtcvideoengine_unittest.cc b/talk/media/webrtc/webrtcvideoengine_unittest.cc
index c9663c5..a61b8d8 100644
--- a/talk/media/webrtc/webrtcvideoengine_unittest.cc
+++ b/talk/media/webrtc/webrtcvideoengine_unittest.cc
@@ -920,6 +920,120 @@
   EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(first_send_channel));
 }
 
+#ifdef USE_WEBRTC_DEV_BRANCH
+TEST_F(WebRtcVideoEngineTestFake, SetCpuOveruseOptionsWithCaptureJitterMethod) {
+  EXPECT_TRUE(SetupEngine());
+
+  // Verify this is off by default.
+  EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
+  int first_send_channel = vie_.GetLastChannel();
+  webrtc::CpuOveruseOptions cpu_option =
+      vie_.GetCpuOveruseOptions(first_send_channel);
+  EXPECT_EQ(0, cpu_option.low_capture_jitter_threshold_ms);
+  EXPECT_EQ(0, cpu_option.high_capture_jitter_threshold_ms);
+  EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
+  EXPECT_FALSE(cpu_option.enable_encode_usage_method);
+
+  // Set low and high threshold and verify that cpu options are set.
+  cricket::VideoOptions options;
+  options.conference_mode.Set(true);
+  options.cpu_underuse_threshold.Set(10);
+  options.cpu_overuse_threshold.Set(20);
+  EXPECT_TRUE(channel_->SetOptions(options));
+  cpu_option = vie_.GetCpuOveruseOptions(first_send_channel);
+  EXPECT_EQ(10, cpu_option.low_capture_jitter_threshold_ms);
+  EXPECT_EQ(20, cpu_option.high_capture_jitter_threshold_ms);
+  EXPECT_TRUE(cpu_option.enable_capture_jitter_method);
+  EXPECT_FALSE(cpu_option.enable_encode_usage_method);
+
+  // Add a receive channel and verify that cpu options are not set.
+  EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
+  int recv_channel_num = vie_.GetLastChannel();
+  EXPECT_NE(first_send_channel, recv_channel_num);
+  cpu_option = vie_.GetCpuOveruseOptions(recv_channel_num);
+  EXPECT_EQ(0, cpu_option.low_capture_jitter_threshold_ms);
+  EXPECT_EQ(0, cpu_option.high_capture_jitter_threshold_ms);
+  EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
+  EXPECT_FALSE(cpu_option.enable_encode_usage_method);
+
+  // 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_capture_jitter_threshold_ms);
+  EXPECT_EQ(20, cpu_option.high_capture_jitter_threshold_ms);
+  EXPECT_TRUE(cpu_option.enable_capture_jitter_method);
+  EXPECT_FALSE(cpu_option.enable_encode_usage_method);
+}
+
+TEST_F(WebRtcVideoEngineTestFake, SetInvalidCpuOveruseThresholds) {
+  EXPECT_TRUE(SetupEngine());
+  EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
+  int channel_num = vie_.GetLastChannel();
+
+  // Only low threshold set. Verify that cpu options are not set.
+  cricket::VideoOptions options;
+  options.conference_mode.Set(true);
+  options.cpu_underuse_threshold.Set(10);
+  EXPECT_TRUE(channel_->SetOptions(options));
+  webrtc::CpuOveruseOptions cpu_option = vie_.GetCpuOveruseOptions(channel_num);
+  EXPECT_EQ(0, cpu_option.low_capture_jitter_threshold_ms);
+  EXPECT_EQ(0, cpu_option.high_capture_jitter_threshold_ms);
+  EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
+  EXPECT_FALSE(cpu_option.enable_encode_usage_method);
+
+  // Set high threshold to a negative value. Verify that options are not set.
+  options.cpu_overuse_threshold.Set(-1);
+  EXPECT_TRUE(channel_->SetOptions(options));
+  cpu_option = vie_.GetCpuOveruseOptions(channel_num);
+  EXPECT_EQ(0, cpu_option.low_capture_jitter_threshold_ms);
+  EXPECT_EQ(0, cpu_option.high_capture_jitter_threshold_ms);
+  EXPECT_FALSE(cpu_option.enable_capture_jitter_method);
+  EXPECT_FALSE(cpu_option.enable_encode_usage_method);
+
+  // Low and high threshold valid. Verify that cpu options are set.
+  options.cpu_overuse_threshold.Set(20);
+  EXPECT_TRUE(channel_->SetOptions(options));
+  cpu_option = vie_.GetCpuOveruseOptions(channel_num);
+  EXPECT_EQ(10, cpu_option.low_capture_jitter_threshold_ms);
+  EXPECT_EQ(20, cpu_option.high_capture_jitter_threshold_ms);
+  EXPECT_TRUE(cpu_option.enable_capture_jitter_method);
+  EXPECT_FALSE(cpu_option.enable_encode_usage_method);
+}
+
+TEST_F(WebRtcVideoEngineTestFake, SetCpuOveruseOptionsWithEncodeUsageMethod) {
+  EXPECT_TRUE(SetupEngine());
+  EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1)));
+  int first_send_channel = vie_.GetLastChannel();
+
+  // Set low and high threshold and enable encode usage method.
+  // Verify that cpu options are set.
+  cricket::VideoOptions options;
+  options.conference_mode.Set(true);
+  options.cpu_underuse_threshold.Set(10);
+  options.cpu_overuse_threshold.Set(20);
+  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);
+
+  // 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);
+}
+#endif
+
 // Test that AddRecvStream doesn't create new channel for 1:1 call.
 TEST_F(WebRtcVideoEngineTestFake, AddRecvStream1On1) {
   EXPECT_TRUE(SetupEngine());