Bug 1296531 - Add gtest for an encoding that is suspended in the beginning. r?jesup draft
authorAndreas Pehrson <pehrsons@gmail.com>
Mon, 30 Jan 2017 18:26:08 +0100
changeset 670300 ac4c1184f5979475ff22403925ce7cf1330e9ac5
parent 670299 1609452c43f657e6ea36311cc69592a87d349fdb
child 670301 83d01cf08f68b847bffb9e10df7f004b9b0196e8
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 an encoding that is suspended in the beginning. r?jesup MozReview-Commit-ID: HZeQW4Z01CR
dom/media/gtest/TestVideoTrackEncoder.cpp
--- a/dom/media/gtest/TestVideoTrackEncoder.cpp
+++ b/dom/media/gtest/TestVideoTrackEncoder.cpp
@@ -731,16 +731,71 @@ TEST(VP8VideoTrackEncoder, AlwaysSuspend
 
   EXPECT_TRUE(encoder.IsEncodingComplete());
 
   // Verify that we have one encoded frames and a total duration of 0.1s.
   const uint64_t none = 0;
   EXPECT_EQ(none, container.GetEncodedFrames().Length());
 }
 
+// Test that encoding a track that is suspended in the beginning works.
+TEST(VP8VideoTrackEncoder, SuspendedBeginning)
+{
+  // Initiate VP8 encoder
+  TestVP8TrackEncoder encoder;
+  InitParam param = {true, 640, 480};
+  encoder.TestInit(param);
+
+  // Suspend and pass a frame with duration 1.5s. Then resume and pass one more.
+  encoder.Suspend();
+
+  YUVBufferGenerator generator;
+  generator.Init(mozilla::gfx::IntSize(640, 480));
+  TimeStamp now = TimeStamp::Now();
+  VideoSegment segment;
+  segment.AppendFrame(generator.GenerateI420Image(),
+                      mozilla::StreamTime(135000), // 1.5s
+                      generator.GetSize(),
+                      PRINCIPAL_HANDLE_NONE,
+                      false,
+                      now);
+
+  encoder.AppendVideoSegment(Move(segment));
+  encoder.NotifyCurrentTime(135000);
+
+  encoder.Resume();
+
+  segment.AppendFrame(generator.GenerateI420Image(),
+                      mozilla::StreamTime(135000), // 1.5s
+                      generator.GetSize(),
+                      PRINCIPAL_HANDLE_NONE,
+                      false,
+                      now + TimeDuration::FromSeconds(1.5));
+  encoder.AppendVideoSegment(Move(segment));
+  encoder.NotifyCurrentTime(270000);
+
+  encoder.NotifyEndOfStream();
+
+  EncodedFrameContainer container;
+  ASSERT_TRUE(NS_SUCCEEDED(encoder.GetEncodedTrack(container)));
+
+  EXPECT_TRUE(encoder.IsEncodingComplete());
+
+  // Verify that we have one encoded frames and a total duration of 0.1s.
+  const uint64_t one = 1;
+  EXPECT_EQ(one, container.GetEncodedFrames().Length());
+
+  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);
+}
+
 // EOS test
 TEST(VP8VideoTrackEncoder, EncodeComplete)
 {
   // Initiate VP8 encoder
   TestVP8TrackEncoder encoder;
   InitParam param = {true, 640, 480};
   encoder.TestInit(param);