Make Frame buffer not drop frames unnecessary

Now VCMTiming::MaxWaitingTime will not clip negative values. Thus frame
buffer will be able to distinguish between late frames and when waiting
cycle was simply interrupted by a new inserted frame right before the
waiting timer would expire.

Bug: webrtc:8917
Change-Id: I6b253f459fcb3a346064a103cc92ee332b074e1b
Reviewed-on: https://webrtc-review.googlesource.com/57741
Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Reviewed-by: Philip Eliasson <philipel@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22210}
diff --git a/modules/video_coding/receiver.cc b/modules/video_coding/receiver.cc
index 157cb88..a1eeded 100644
--- a/modules/video_coding/receiver.cc
+++ b/modules/video_coding/receiver.cc
@@ -20,6 +20,7 @@
 #include "modules/video_coding/internal_defines.h"
 #include "modules/video_coding/media_opt_util.h"
 #include "rtc_base/logging.h"
+#include "rtc_base/numerics/safe_conversions.h"
 #include "rtc_base/trace_event.h"
 #include "system_wrappers/include/clock.h"
 
@@ -192,8 +193,8 @@
         static_cast<int32_t>(clock_->TimeInMilliseconds() - start_time_ms);
     uint16_t new_max_wait_time =
         static_cast<uint16_t>(VCM_MAX(available_wait_time, 0));
-    uint32_t wait_time_ms =
-        timing_->MaxWaitingTime(render_time_ms, clock_->TimeInMilliseconds());
+    uint32_t wait_time_ms = rtc::saturated_cast<uint32_t>(
+        timing_->MaxWaitingTime(render_time_ms, clock_->TimeInMilliseconds()));
     if (new_max_wait_time < wait_time_ms) {
       // We're not allowed to wait until the frame is supposed to be rendered,
       // waiting as long as we're allowed to avoid busy looping, and then return