Bug 1570673 - Update last frame's time on same-frame-ticks. r=bwc a=RyanVM
authorAndreas Pehrson <apehrson@mozilla.com>
Wed, 07 Aug 2019 15:11:00 +0000
changeset 545061 1b6a325b60bae842ccd150ba96c02ce7349a7666
parent 545060 c63aa7985beb8f697ef2442b28f236593cf67107
child 545062 48cb377f63cf6de0221656201a1f867ad5ba5440
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbwc, RyanVM
bugs1570673
milestone69.0
Bug 1570673 - Update last frame's time on same-frame-ticks. r=bwc a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D40599
dom/media/VideoFrameConverter.h
dom/media/gtest/TestVideoFrameConverter.cpp
--- a/dom/media/VideoFrameConverter.h
+++ b/dom/media/VideoFrameConverter.h
@@ -220,16 +220,18 @@ class VideoFrameConverter {
     MOZ_ASSERT(aClosure);
     VideoFrameConverter* self = static_cast<VideoFrameConverter*>(aClosure);
     MOZ_ASSERT(self->mTaskQueue->IsCurrentThreadIn());
 
     if (!self->mLastFrameConverted) {
       return;
     }
 
+    self->mLastFrameConverted->set_timestamp_us(
+        webrtc::Clock::GetRealTimeClock()->TimeInMicroseconds());
     for (RefPtr<VideoConverterListener>& listener : self->mListeners) {
       listener->OnVideoFrameConverted(*self->mLastFrameConverted);
     }
   }
 
   void VideoFrameConverted(const webrtc::VideoFrame& aVideoFrame) {
     MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
 
--- a/dom/media/gtest/TestVideoFrameConverter.cpp
+++ b/dom/media/gtest/TestVideoFrameConverter.cpp
@@ -50,16 +50,17 @@ class VideoFrameConverterTest : public :
     std::vector<FrameType> v(mConvertedFrames.begin(),
                              mConvertedFrames.begin() + aN);
     return v;
   }
 
  public:
   void OnVideoFrameConverted(const webrtc::VideoFrame& aVideoFrame) {
     MonitorAutoLock lock(mMonitor);
+    EXPECT_NE(aVideoFrame.timestamp_us(), 0);
     mConvertedFrames.push_back(MakePair(aVideoFrame, TimeStamp::Now()));
     mMonitor.Notify();
   }
 };
 
 FrameListener::FrameListener(VideoFrameConverterTest* aTest) : mTest(aTest) {}
 void FrameListener::OnVideoFrameConverted(
     const webrtc::VideoFrame& aVideoFrame) {
@@ -134,16 +135,20 @@ TEST_F(VideoFrameConverterTest, Duplicat
   EXPECT_GT(TimeStamp::Now(), now + TimeDuration::FromMilliseconds(1100));
   ASSERT_EQ(frames.size(), 2U);
   EXPECT_EQ(frames[0].first().width(), 640);
   EXPECT_EQ(frames[0].first().height(), 480);
   EXPECT_GT(frames[0].second(), future1);
   EXPECT_EQ(frames[1].first().width(), 640);
   EXPECT_EQ(frames[1].first().height(), 480);
   EXPECT_GT(frames[1].second(), now + TimeDuration::FromMilliseconds(1100));
+  // Check that the second frame comes between 1s and 2s after the first.
+  EXPECT_NEAR(frames[1].first().timestamp_us(),
+              frames[0].first().timestamp_us() + ((PR_USEC_PER_SEC * 3) / 2),
+              PR_USEC_PER_SEC / 2);
 }
 
 TEST_F(VideoFrameConverterTest, DropsOld) {
   TimeStamp now = TimeStamp::Now();
   TimeStamp future1 = now + TimeDuration::FromMilliseconds(1000);
   TimeStamp future2 = now + TimeDuration::FromMilliseconds(100);
   mConverter->SetActive(true);
   mConverter->QueueVideoChunk(GenerateChunk(800, 600, future1), false);
@@ -173,16 +178,20 @@ TEST_F(VideoFrameConverterTest, BlackOnD
   EXPECT_GT(TimeStamp::Now(), now + TimeDuration::FromMilliseconds(1100));
   ASSERT_EQ(frames.size(), 2U);
   EXPECT_EQ(frames[0].first().width(), 640);
   EXPECT_EQ(frames[0].first().height(), 480);
   EXPECT_GT(frames[0].second(), future1);
   EXPECT_EQ(frames[1].first().width(), 640);
   EXPECT_EQ(frames[1].first().height(), 480);
   EXPECT_GT(frames[1].second(), now + TimeDuration::FromMilliseconds(1100));
+  // Check that the second frame comes between 1s and 2s after the first.
+  EXPECT_NEAR(frames[1].first().timestamp_us(),
+              frames[0].first().timestamp_us() + ((PR_USEC_PER_SEC * 3) / 2),
+              PR_USEC_PER_SEC / 2);
 }
 
 TEST_F(VideoFrameConverterTest, ClearFutureFramesOnJumpingBack) {
   TimeStamp start = TimeStamp::Now();
   TimeStamp future1 = start + TimeDuration::FromMilliseconds(100);
 
   mConverter->SetActive(true);
   mConverter->QueueVideoChunk(GenerateChunk(640, 480, future1), false);