Bug 1296531 - Add gtest for encoding where suspend/resume timestamps happen in the middle of frame durations. r?jesup draft
authorAndreas Pehrson <pehrsons@gmail.com>
Mon, 30 Jan 2017 18:26:48 +0100
changeset 670301 83d01cf08f68b847bffb9e10df7f004b9b0196e8
parent 670300 ac4c1184f5979475ff22403925ce7cf1330e9ac5
child 670302 e9594fec3c49afccd438d7ab8567531466d95826
push id81598
push userbmo:apehrson@mozilla.com
push dateTue, 26 Sep 2017 09:13:19 +0000
reviewersjesup
bugs1296531
milestone58.0a1
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);