AndroidVideoCapturer: Delegate framerate choice to VideoCapturerAndroid.java

webrtc::VideoSource resolves the kMaxFrameRate constraint by capping the desired framerate to kMaxFrameRate. That framerate is then passed into cricket::VideoCapturer::GetBestCaptureFormat(). The default implementation will choose a format from the supported formats list. Instead, we should override this function in AndroidVideoCapturer to give VideoCapturerAndroid.java the opportunity to choose a suitable framerate range.

BUG=webrtc:4938
R=glaznev@webrtc.org

Review URL: https://codereview.webrtc.org/1308953004 .

Cr-Commit-Position: refs/heads/master@{#9805}
diff --git a/talk/app/webrtc/androidvideocapturer.cc b/talk/app/webrtc/androidvideocapturer.cc
index e227022..cc78217 100644
--- a/talk/app/webrtc/androidvideocapturer.cc
+++ b/talk/app/webrtc/androidvideocapturer.cc
@@ -137,18 +137,17 @@
 
 cricket::CaptureState AndroidVideoCapturer::Start(
     const cricket::VideoFormat& capture_format) {
-  LOG(LS_INFO) << " AndroidVideoCapturer::Start w = " << capture_format.width
-               << " h = " << capture_format.height;
   CHECK(thread_checker_.CalledOnValidThread());
   CHECK(!running_);
+  const int fps = cricket::VideoFormat::IntervalToFps(capture_format.interval);
+  LOG(LS_INFO) << " AndroidVideoCapturer::Start " << capture_format.width << "x"
+               << capture_format.height << "@" << fps;
 
   frame_factory_ = new AndroidVideoCapturer::FrameFactory(delegate_.get());
   set_frame_factory(frame_factory_);
 
   running_ = true;
-  delegate_->Start(
-      capture_format.width, capture_format.height,
-      cricket::VideoFormat::IntervalToFps(capture_format.interval), this);
+  delegate_->Start(capture_format.width, capture_format.height, fps, this);
   SetCaptureFormat(&capture_format);
   current_state_ = cricket::CS_STARTING;
   return current_state_;
@@ -210,4 +209,12 @@
   video_adapter()->OnOutputFormatRequest(format);
 }
 
+bool AndroidVideoCapturer::GetBestCaptureFormat(
+    const cricket::VideoFormat& desired,
+    cricket::VideoFormat* best_format) {
+  // Delegate this choice to VideoCapturerAndroid.startCapture().
+  *best_format = desired;
+  return true;
+}
+
 }  // namespace webrtc
diff --git a/talk/app/webrtc/androidvideocapturer.h b/talk/app/webrtc/androidvideocapturer.h
index 78594f8..ad45004 100644
--- a/talk/app/webrtc/androidvideocapturer.h
+++ b/talk/app/webrtc/androidvideocapturer.h
@@ -76,6 +76,10 @@
 
   AndroidVideoCapturerDelegate* delegate() { return delegate_.get(); }
 
+  // cricket::VideoCapturer implementation.
+  bool GetBestCaptureFormat(const cricket::VideoFormat& desired,
+                            cricket::VideoFormat* best_format) override;
+
  private:
   // cricket::VideoCapturer implementation.
   // Video frames will be delivered using
diff --git a/talk/app/webrtc/videosource.cc b/talk/app/webrtc/videosource.cc
index d6e92b0..bb27b10 100644
--- a/talk/app/webrtc/videosource.cc
+++ b/talk/app/webrtc/videosource.cc
@@ -157,12 +157,9 @@
         value = 1;
       }
     }
-    if (value <= cricket::VideoFormat::IntervalToFps(format_in.interval)) {
+    if (value <= cricket::VideoFormat::IntervalToFps(format_in.interval))
       format_out->interval = cricket::VideoFormat::FpsToInterval(value);
-      return true;
-    } else {
-      return false;
-    }
+    return true;
   } else if (constraint.key == MediaConstraintsInterface::kMinAspectRatio) {
     double value = rtc::FromString<double>(constraint.value);
     // The aspect ratio in |constraint.value| has been converted to a string and