Calculate NtpCaptureStartMs using clock, not the frame rtp timestamp

If the first frame rtp timestamp got corrupted somehow, the introduced
error would stay there for the duration of the call. Using realtime
clock to calculate elapsed time instead of rtp timestamps resolves that
problem. The error will go away once ntp time would be estimated
correctly from the correct timestamps.

Bug: webrtc:9698
Change-Id: Ifa4c3f55f280fae8ec9f1826a89c251ec61b965e
Reviewed-on: https://webrtc-review.googlesource.com/97101
Reviewed-by: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Stefan Holmer <stefan@webrtc.org>
Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24726}
diff --git a/media/engine/webrtcvideoengine_unittest.cc b/media/engine/webrtcvideoengine_unittest.cc
index 4a45494..d825078 100644
--- a/media/engine/webrtcvideoengine_unittest.cc
+++ b/media/engine/webrtcvideoengine_unittest.cc
@@ -40,6 +40,7 @@
 #include "media/engine/webrtcvoiceengine.h"
 #include "modules/rtp_rtcp/include/rtp_header_parser.h"
 #include "rtc_base/arraysize.h"
+#include "rtc_base/fakeclock.h"
 #include "rtc_base/gunit.h"
 #include "rtc_base/numerics/safe_conversions.h"
 #include "rtc_base/stringutils.h"
@@ -210,7 +211,11 @@
         engine_(std::unique_ptr<cricket::FakeWebRtcVideoEncoderFactory>(
                     encoder_factory_),
                 std::unique_ptr<cricket::FakeWebRtcVideoDecoderFactory>(
-                    decoder_factory_)) {}
+                    decoder_factory_)) {
+    // Ensure fake clock doesn't return 0, which will cause some initializations
+    // fail inside RTP senders.
+    fake_clock_.AdvanceTimeMicros(1);
+  }
 
  protected:
   void AssignDefaultAptRtxTypes();
@@ -231,6 +236,9 @@
 
   void TestExtendedEncoderOveruse(bool use_external_encoder);
 
+  // Has to be the first one, so it is initialized before the call or there is a
+  // race condition in the clock access.
+  rtc::ScopedFakeClock fake_clock_;
   webrtc::test::ScopedFieldTrials override_field_trials_;
   webrtc::RtcEventLogNullImpl event_log_;
   // Used in WebRtcVideoEngineVoiceTest, but defined here so it's properly
@@ -3480,6 +3488,7 @@
   // This timestamp is kInitialTimestamp (-1) + kFrameOffsetMs * 90, which
   // triggers a constant-overflow warning, hence we're calculating it explicitly
   // here.
+  fake_clock_.AdvanceTimeMicros(kFrameOffsetMs * rtc::kNumMicrosecsPerMillisec);
   video_frame.set_timestamp(kFrameOffsetMs * 90 - 1);
   video_frame.set_ntp_time_ms(kInitialNtpTimeMs + kFrameOffsetMs);
   stream->InjectFrame(video_frame);