Bug 1515548 - Fix potential divide by zero in DesktopCaptureImpl; r=jib, a=RyanVM
authorDan Minor <dminor@mozilla.com>
Thu, 20 Dec 2018 17:57:58 +0000
changeset 509246 b41ed6f2639aa4de0250294ed2643212ca411245
parent 509245 8230dc950f984a38a09c8272a4fa5b0acfb27688
child 509247 d85d79f64753dd634667e7398303abacf5ea13bc
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjib, RyanVM
bugs1515548, 1321221
milestone65.0
Bug 1515548 - Fix potential divide by zero in DesktopCaptureImpl; r=jib, a=RyanVM This clamps requests for FPS that are below 1 to 1. As far as I can tell, the getDisplayMedia specification does not provide any guidance on how to interpret negative or zero FPS constraints, so this seems like a reasonable limitation. I'm not adding a test here as there will be a wpt test that covers this as part of Bug 1321221. Differential Revision: https://phabricator.services.mozilla.com/D15105
dom/media/systemservices/video_engine/desktop_capture_impl.cc
--- a/dom/media/systemservices/video_engine/desktop_capture_impl.cc
+++ b/dom/media/systemservices/video_engine/desktop_capture_impl.cc
@@ -594,17 +594,19 @@ uint32_t DesktopCaptureImpl::CalculateFr
 
   return nrOfFrames;
 }
 
 int32_t DesktopCaptureImpl::StartCapture(
     const VideoCaptureCapability& capability) {
   _requestedCapability = capability;
 #if defined(_WIN32)
-  uint32_t maxFPSNeeded = 1000 / _requestedCapability.maxFPS;
+  uint32_t maxFPSNeeded = _requestedCapability.maxFPS > 0
+                              ? 1000 / _requestedCapability.maxFPS
+                              : 1000;
   capturer_thread_->RequestCallbackTimer(maxFPSNeeded);
 #endif
 
   if (started_) {
     return 0;
   }
 #if defined(WEBRTC_LINUX)
   // Lazily init capturer_thread_
@@ -665,16 +667,18 @@ void DesktopCaptureImpl::process() {
 
   desktop_capturer_cursor_composer_->CaptureFrame();
 
 #if !defined(_WIN32)
   const uint32_t processTime =
       ((uint32_t)(rtc::TimeNanos() - startProcessTime)) /
       rtc::kNumNanosecsPerMillisec;
   // Use at most x% CPU or limit framerate
-  const uint32_t maxFPSNeeded = 1000 / _requestedCapability.maxFPS;
+  const uint32_t maxFPSNeeded = _requestedCapability.maxFPS > 0
+                                    ? 1000 / _requestedCapability.maxFPS
+                                    : 1000;
   const float sleepTimeFactor = (100.0f / kMaxDesktopCaptureCpuUsage) - 1.0f;
   const uint32_t sleepTime = sleepTimeFactor * processTime;
   time_event_->Wait(std::max<uint32_t>(maxFPSNeeded, sleepTime));
 #endif
 }
 
 }  // namespace webrtc