Bug 1296531 - Add gtest for encoding where suspend/resume timestamps happen in the middle of frame durations. r=jesup
authorAndreas Pehrson <pehrsons@gmail.com>
Mon, 30 Jan 2017 18:26:48 +0100
changeset 383031 9ff34ff8a7459f77831c464a7c48eb836f8f4324
parent 383030 81c3fc64fe9f32ff38a10632f273104724cf7919
child 383032 ff830ca6e0d241cdf0226bb5887a7e6214b7ab8f
push id32582
push userkwierso@gmail.com
push dateWed, 27 Sep 2017 00:11:27 +0000
treeherdermozilla-central@70158e4e215d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs1296531
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1296531 - Add gtest for encoding where suspend/resume timestamps happen in the middle of frame durations. r=jesup MozReview-Commit-ID: H2UPEC2OTxQ
dom/media/gtest/TestVideoTrackEncoder.cpp
--- a/dom/media/gtest/TestVideoTrackEncoder.cpp
+++ b/dom/media/gtest/TestVideoTrackEncoder.cpp
@@ -786,16 +786,73 @@ TEST(VP8VideoTrackEncoder, SuspendedBegi
   uint64_t totalDuration = 0;
   for (auto& frame : container.GetEncodedFrames()) {
     totalDuration += frame->GetDuration();
   }
   const uint64_t oneAndAHalf = PR_USEC_PER_SEC / 2 * 3;
   EXPECT_EQ(oneAndAHalf, totalDuration);
 }
 
+// Test that suspending and resuming in the middle of already pushed data
+// works.
+TEST(VP8VideoTrackEncoder, SuspendedOverlap)
+{
+  // Initiate VP8 encoder
+  TestVP8TrackEncoder encoder;
+  InitParam param = {true, 640, 480};
+  encoder.TestInit(param);
+
+  // Pass a 1s frame and suspend after 0.5s.
+  YUVBufferGenerator generator;
+  generator.Init(mozilla::gfx::IntSize(640, 480));
+  TimeStamp now = TimeStamp::Now();
+  VideoSegment segment;
+  segment.AppendFrame(generator.GenerateI420Image(),
+                      mozilla::StreamTime(90000), // 1s
+                      generator.GetSize(),
+                      PRINCIPAL_HANDLE_NONE,
+                      false,
+                      now);
+
+  encoder.AppendVideoSegment(Move(segment));
+
+  encoder.NotifyCurrentTime(45000);
+  encoder.Suspend();
+
+  // Pass another 1s frame and resume after 0.3 of this new frame.
+  segment.AppendFrame(generator.GenerateI420Image(),
+                      mozilla::StreamTime(90000), // 1s
+                      generator.GetSize(),
+                      PRINCIPAL_HANDLE_NONE,
+                      false,
+                      now + TimeDuration::FromSeconds(1));
+  encoder.AppendVideoSegment(Move(segment));
+  encoder.NotifyCurrentTime(117000);
+  encoder.Resume();
+  encoder.NotifyCurrentTime(180000);
+
+  encoder.NotifyEndOfStream();
+
+  EncodedFrameContainer container;
+  ASSERT_TRUE(NS_SUCCEEDED(encoder.GetEncodedTrack(container)));
+
+  EXPECT_TRUE(encoder.IsEncodingComplete());
+
+  // Verify that we have two encoded frames and a total duration of 0.1s.
+  const uint64_t two= 2;
+  EXPECT_EQ(two, container.GetEncodedFrames().Length());
+
+  uint64_t totalDuration = 0;
+  for (auto& frame : container.GetEncodedFrames()) {
+    totalDuration += frame->GetDuration();
+  }
+  const uint64_t onePointTwo = (PR_USEC_PER_SEC / 10) * 12;
+  EXPECT_EQ(onePointTwo, totalDuration);
+}
+
 // EOS test
 TEST(VP8VideoTrackEncoder, EncodeComplete)
 {
   // Initiate VP8 encoder
   TestVP8TrackEncoder encoder;
   InitParam param = {true, 640, 480};
   encoder.TestInit(param);