Bug 1296531 - Change track encoder gtests to better mimic Gecko usage. r=jesup
authorAndreas Pehrson <pehrsons@gmail.com>
Tue, 16 May 2017 13:29:43 +0200
changeset 433802 9fb91aa67681f291a0693ecbccc6ec0462b6cdfb
parent 433801 2f254c86634764e86890b3a163f5eb6e3b872240
child 433803 fbb794b4ab77eb66d7c20f04fc895403d4b54132
push id8114
push userjlorenzo@mozilla.com
push dateThu, 02 Nov 2017 16:33:21 +0000
treeherdermozilla-beta@73e0d89a540f [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 - Change track encoder gtests to better mimic Gecko usage. r=jesup MozReview-Commit-ID: 3VwqUBip33u
dom/media/gtest/TestAudioTrackEncoder.cpp
dom/media/gtest/TestVideoTrackEncoder.cpp
--- a/dom/media/gtest/TestAudioTrackEncoder.cpp
+++ b/dom/media/gtest/TestAudioTrackEncoder.cpp
@@ -226,16 +226,17 @@ TEST(OpusAudioTrackEncoder, FrameEncode)
   EXPECT_TRUE(encoder.TestOpusRawCreation(channels, sampleRate));
 
   // Generate five seconds of raw audio data.
   AudioGenerator generator(channels, sampleRate);
   AudioSegment segment;
   const int32_t samples = sampleRate * 5;
   generator.Generate(segment, samples);
 
+  encoder.SetStartOffset(0);
   encoder.AppendAudioSegment(Move(segment));
   encoder.AdvanceCurrentTime(samples);
 
   EncodedFrameContainer container;
   EXPECT_TRUE(NS_SUCCEEDED(encoder.GetEncodedTrack(container)));
 
   // Verify that encoded data is 5 seconds long.
   uint64_t totalDuration = 0;
--- a/dom/media/gtest/TestVideoTrackEncoder.cpp
+++ b/dom/media/gtest/TestVideoTrackEncoder.cpp
@@ -255,20 +255,17 @@ TEST(VP8VideoTrackEncoder, FetchMetaData
     EXPECT_TRUE(vp8Meta->mWidth == params[i].mWidth);
     EXPECT_TRUE(vp8Meta->mHeight == params[i].mHeight);
   }
 }
 
 // Encode test
 TEST(VP8VideoTrackEncoder, FrameEncode)
 {
-  // Initiate VP8 encoder
   TestVP8TrackEncoder encoder;
-  InitParam param = {true, 640, 480};
-  encoder.TestInit(param);
 
   // Create YUV images as source.
   nsTArray<RefPtr<Image>> images;
   YUVBufferGenerator generator;
   generator.Init(mozilla::gfx::IntSize(640, 480));
   images.AppendElement(generator.GenerateI420Image());
   images.AppendElement(generator.GenerateNV12Image());
   images.AppendElement(generator.GenerateNV21Image());
@@ -283,41 +280,40 @@ TEST(VP8VideoTrackEncoder, FrameEncode)
     segment.AppendFrame(image.forget(),
                         mozilla::StreamTime(90000),
                         generator.GetSize(),
                         PRINCIPAL_HANDLE_NONE,
                         false,
                         now + TimeDuration::FromSeconds(i));
   }
 
+  encoder.SetStartOffset(0);
   encoder.AppendVideoSegment(Move(segment));
   encoder.AdvanceCurrentTime(images.Length() * 90000);
 
   // Pull Encoded Data back from encoder.
   EncodedFrameContainer container;
   EXPECT_TRUE(NS_SUCCEEDED(encoder.GetEncodedTrack(container)));
 }
 
 // Test that encoding a single frame gives useful output.
 TEST(VP8VideoTrackEncoder, SingleFrameEncode)
 {
-  // Initiate VP8 encoder
   TestVP8TrackEncoder encoder;
-  InitParam param = {true, 640, 480};
-  encoder.TestInit(param);
 
   // Pass a half-second frame to the encoder.
   YUVBufferGenerator generator;
   generator.Init(mozilla::gfx::IntSize(640, 480));
   VideoSegment segment;
   segment.AppendFrame(generator.GenerateI420Image(),
                       mozilla::StreamTime(45000), // 1/2 second
                       generator.GetSize(),
                       PRINCIPAL_HANDLE_NONE);
 
+  encoder.SetStartOffset(0);
   encoder.AppendVideoSegment(Move(segment));
   encoder.AdvanceCurrentTime(45000);
   encoder.NotifyEndOfStream();
 
   EncodedFrameContainer container;
   ASSERT_TRUE(NS_SUCCEEDED(encoder.GetEncodedTrack(container)));
 
   EXPECT_TRUE(encoder.IsEncodingComplete());
@@ -332,36 +328,34 @@ TEST(VP8VideoTrackEncoder, SingleFrameEn
 
   const uint64_t halfSecond = PR_USEC_PER_SEC / 2;
   EXPECT_EQ(halfSecond, frames[0]->GetDuration());
 }
 
 // Test that encoding a couple of identical images gives useful output.
 TEST(VP8VideoTrackEncoder, SameFrameEncode)
 {
-  // Initiate VP8 encoder
   TestVP8TrackEncoder encoder;
-  InitParam param = {true, 640, 480};
-  encoder.TestInit(param);
 
   // Pass 15 100ms frames to the encoder.
   YUVBufferGenerator generator;
   generator.Init(mozilla::gfx::IntSize(640, 480));
   RefPtr<Image> image = generator.GenerateI420Image();
   TimeStamp now = TimeStamp::Now();
   VideoSegment segment;
   for (uint32_t i = 0; i < 15; ++i) {
     segment.AppendFrame(do_AddRef(image),
                         mozilla::StreamTime(9000), // 100ms
                         generator.GetSize(),
                         PRINCIPAL_HANDLE_NONE,
                         false,
                         now + TimeDuration::FromSeconds(i * 0.1));
   }
 
+  encoder.SetStartOffset(0);
   encoder.AppendVideoSegment(Move(segment));
   encoder.AdvanceCurrentTime(15 * 9000);
   encoder.NotifyEndOfStream();
 
   EncodedFrameContainer container;
   ASSERT_TRUE(NS_SUCCEEDED(encoder.GetEncodedTrack(container)));
 
   EXPECT_TRUE(encoder.IsEncodingComplete());
@@ -373,20 +367,17 @@ TEST(VP8VideoTrackEncoder, SameFrameEnco
   }
   const uint64_t oneAndAHalf = (PR_USEC_PER_SEC / 2) * 3;
   EXPECT_EQ(oneAndAHalf, totalDuration);
 }
 
 // Test encoding a track that starts with null data
 TEST(VP8VideoTrackEncoder, NullFrameFirst)
 {
-  // Initiate VP8 encoder
   TestVP8TrackEncoder encoder;
-  InitParam param = {true, 640, 480};
-  encoder.TestInit(param);
   YUVBufferGenerator generator;
   generator.Init(mozilla::gfx::IntSize(640, 480));
   RefPtr<Image> image = generator.GenerateI420Image();
   TimeStamp now = TimeStamp::Now();
   VideoSegment segment;
 
   // Pass 2 100ms null frames to the encoder.
   for (uint32_t i = 0; i < 2; ++i) {
@@ -401,16 +392,17 @@ TEST(VP8VideoTrackEncoder, NullFrameFirs
   // Pass a real 100ms frame to the encoder.
   segment.AppendFrame(image.forget(),
                       mozilla::StreamTime(9000), // 100ms
                       generator.GetSize(),
                       PRINCIPAL_HANDLE_NONE,
                       false,
                       now + TimeDuration::FromSeconds(0.3));
 
+  encoder.SetStartOffset(0);
   encoder.AppendVideoSegment(Move(segment));
   encoder.AdvanceCurrentTime(3 * 9000);
   encoder.NotifyEndOfStream();
 
   EncodedFrameContainer container;
   ASSERT_TRUE(NS_SUCCEEDED(encoder.GetEncodedTrack(container)));
 
   EXPECT_TRUE(encoder.IsEncodingComplete());
@@ -422,36 +414,34 @@ TEST(VP8VideoTrackEncoder, NullFrameFirs
   }
   const uint64_t pointThree = (PR_USEC_PER_SEC / 10) * 3;
   EXPECT_EQ(pointThree, totalDuration);
 }
 
 // Test encoding a track that has to skip frames.
 TEST(VP8VideoTrackEncoder, SkippedFrames)
 {
-  // Initiate VP8 encoder
   TestVP8TrackEncoder encoder;
-  InitParam param = {true, 640, 480};
-  encoder.TestInit(param);
   YUVBufferGenerator generator;
   generator.Init(mozilla::gfx::IntSize(640, 480));
   TimeStamp now = TimeStamp::Now();
   VideoSegment segment;
 
   // Pass 100 frames of the shortest possible duration where we don't get
   // rounding errors between input/output rate.
   for (uint32_t i = 0; i < 100; ++i) {
     segment.AppendFrame(generator.GenerateI420Image(),
                         mozilla::StreamTime(90), // 1ms
                         generator.GetSize(),
                         PRINCIPAL_HANDLE_NONE,
                         false,
                         now + TimeDuration::FromMilliseconds(i));
   }
 
+  encoder.SetStartOffset(0);
   encoder.AppendVideoSegment(Move(segment));
   encoder.AdvanceCurrentTime(100 * 90);
   encoder.NotifyEndOfStream();
 
   EncodedFrameContainer container;
   ASSERT_TRUE(NS_SUCCEEDED(encoder.GetEncodedTrack(container)));
 
   EXPECT_TRUE(encoder.IsEncodingComplete());
@@ -463,20 +453,17 @@ TEST(VP8VideoTrackEncoder, SkippedFrames
   }
   const uint64_t hundredMillis = PR_USEC_PER_SEC / 10;
   EXPECT_EQ(hundredMillis, totalDuration);
 }
 
 // Test encoding a track with frames subject to rounding errors.
 TEST(VP8VideoTrackEncoder, RoundingErrorFramesEncode)
 {
-  // Initiate VP8 encoder
   TestVP8TrackEncoder encoder;
-  InitParam param = {true, 640, 480};
-  encoder.TestInit(param);
   YUVBufferGenerator generator;
   generator.Init(mozilla::gfx::IntSize(640, 480));
   TimeStamp now = TimeStamp::Now();
   VideoSegment segment;
 
   // Pass nine frames with timestamps not expressable in 90kHz sample rate,
   // then one frame to make the total duration one second.
   uint32_t usPerFrame = 99999; //99.999ms
@@ -492,16 +479,17 @@ TEST(VP8VideoTrackEncoder, RoundingError
   // This last frame has timestamp start + 0.9s and duration 0.1s.
   segment.AppendFrame(generator.GenerateI420Image(),
                       mozilla::StreamTime(9000), // 100ms
                       generator.GetSize(),
                       PRINCIPAL_HANDLE_NONE,
                       false,
                       now + TimeDuration::FromSeconds(0.9));
 
+  encoder.SetStartOffset(0);
   encoder.AppendVideoSegment(Move(segment));
   encoder.AdvanceCurrentTime(10 * 9000);
   encoder.NotifyEndOfStream();
 
   EncodedFrameContainer container;
   ASSERT_TRUE(NS_SUCCEEDED(encoder.GetEncodedTrack(container)));
 
   EXPECT_TRUE(encoder.IsEncodingComplete());
@@ -513,20 +501,17 @@ TEST(VP8VideoTrackEncoder, RoundingError
   }
   const uint64_t oneSecond= PR_USEC_PER_SEC;
   EXPECT_EQ(oneSecond, totalDuration);
 }
 
 // Test that we're encoding timestamps rather than durations.
 TEST(VP8VideoTrackEncoder, TimestampFrameEncode)
 {
-  // Initiate VP8 encoder
   TestVP8TrackEncoder encoder;
-  InitParam param = {true, 640, 480};
-  encoder.TestInit(param);
 
   // Pass 3 frames with duration 0.1s, but varying timestamps to the encoder.
   // Total duration of the segment should be the same for both.
   YUVBufferGenerator generator;
   generator.Init(mozilla::gfx::IntSize(640, 480));
   TimeStamp now = TimeStamp::Now();
   VideoSegment segment;
   segment.AppendFrame(generator.GenerateI420Image(),
@@ -543,16 +528,17 @@ TEST(VP8VideoTrackEncoder, TimestampFram
                       now + TimeDuration::FromSeconds(0.05));
   segment.AppendFrame(generator.GenerateI420Image(),
                       mozilla::StreamTime(9000), // 0.1s
                       generator.GetSize(),
                       PRINCIPAL_HANDLE_NONE,
                       false,
                       now + TimeDuration::FromSeconds(0.2));
 
+  encoder.SetStartOffset(0);
   encoder.AppendVideoSegment(Move(segment));
   encoder.AdvanceCurrentTime(3 * 9000);
   encoder.NotifyEndOfStream();
 
   EncodedFrameContainer container;
   ASSERT_TRUE(NS_SUCCEEDED(encoder.GetEncodedTrack(container)));
 
   EXPECT_TRUE(encoder.IsEncodingComplete());
@@ -569,34 +555,32 @@ TEST(VP8VideoTrackEncoder, TimestampFram
   }
   const uint64_t pointThree = (PR_USEC_PER_SEC / 10) * 3;
   EXPECT_EQ(pointThree, totalDuration);
 }
 
 // Test that suspending an encoding works.
 TEST(VP8VideoTrackEncoder, Suspended)
 {
-  // Initiate VP8 encoder
   TestVP8TrackEncoder encoder;
-  InitParam param = {true, 640, 480};
-  encoder.TestInit(param);
 
   // Pass 3 frames with duration 0.1s. We suspend before and resume after the
   // second frame.
   YUVBufferGenerator generator;
   generator.Init(mozilla::gfx::IntSize(640, 480));
   TimeStamp now = TimeStamp::Now();
   VideoSegment segment;
   segment.AppendFrame(generator.GenerateI420Image(),
                       mozilla::StreamTime(9000), // 0.1s
                       generator.GetSize(),
                       PRINCIPAL_HANDLE_NONE,
                       false,
                       now);
 
+  encoder.SetStartOffset(0);
   encoder.AppendVideoSegment(Move(segment));
   encoder.AdvanceCurrentTime(9000);
 
   encoder.Suspend(now + TimeDuration::FromSeconds(0.1));
 
   segment.AppendFrame(generator.GenerateI420Image(),
                       mozilla::StreamTime(9000), // 0.1s
                       generator.GetSize(),
@@ -634,33 +618,31 @@ TEST(VP8VideoTrackEncoder, Suspended)
   }
   const uint64_t pointTwo = (PR_USEC_PER_SEC / 10) * 2;
   EXPECT_EQ(pointTwo, totalDuration);
 }
 
 // Test that ending a track while the video track encoder is suspended works.
 TEST(VP8VideoTrackEncoder, SuspendedUntilEnd)
 {
-  // Initiate VP8 encoder
   TestVP8TrackEncoder encoder;
-  InitParam param = {true, 640, 480};
-  encoder.TestInit(param);
 
   // Pass 2 frames with duration 0.1s. We suspend before the second frame.
   YUVBufferGenerator generator;
   generator.Init(mozilla::gfx::IntSize(640, 480));
   TimeStamp now = TimeStamp::Now();
   VideoSegment segment;
   segment.AppendFrame(generator.GenerateI420Image(),
                       mozilla::StreamTime(9000), // 0.1s
                       generator.GetSize(),
                       PRINCIPAL_HANDLE_NONE,
                       false,
                       now);
 
+  encoder.SetStartOffset(0);
   encoder.AppendVideoSegment(Move(segment));
   encoder.AdvanceCurrentTime(9000);
 
   encoder.Suspend(now + TimeDuration::FromSeconds(0.1));
 
   segment.AppendFrame(generator.GenerateI420Image(),
                       mozilla::StreamTime(9000), // 0.1s
                       generator.GetSize(),
@@ -687,20 +669,17 @@ TEST(VP8VideoTrackEncoder, SuspendedUnti
   }
   const uint64_t pointOne = PR_USEC_PER_SEC / 10;
   EXPECT_EQ(pointOne, totalDuration);
 }
 
 // Test that ending a track that was always suspended works.
 TEST(VP8VideoTrackEncoder, AlwaysSuspended)
 {
-  // Initiate VP8 encoder
   TestVP8TrackEncoder encoder;
-  InitParam param = {true, 640, 480};
-  encoder.TestInit(param);
 
   // Suspend and then pass a frame with duration 2s.
   YUVBufferGenerator generator;
   generator.Init(mozilla::gfx::IntSize(640, 480));
 
   TimeStamp now = TimeStamp::Now();
 
   encoder.Suspend(now);
@@ -708,16 +687,17 @@ TEST(VP8VideoTrackEncoder, AlwaysSuspend
   VideoSegment segment;
   segment.AppendFrame(generator.GenerateI420Image(),
                       mozilla::StreamTime(180000), // 2s
                       generator.GetSize(),
                       PRINCIPAL_HANDLE_NONE,
                       false,
                       now);
 
+  encoder.SetStartOffset(0);
   encoder.AppendVideoSegment(Move(segment));
   encoder.AdvanceCurrentTime(180000);
 
   encoder.NotifyEndOfStream();
 
   EncodedFrameContainer container;
   ASSERT_TRUE(NS_SUCCEEDED(encoder.GetEncodedTrack(container)));
 
@@ -726,35 +706,33 @@ TEST(VP8VideoTrackEncoder, AlwaysSuspend
   // 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);
   TimeStamp now = TimeStamp::Now();
 
   // Suspend and pass a frame with duration 0.5s. Then resume and pass one more.
   encoder.Suspend(now);
 
   YUVBufferGenerator generator;
   generator.Init(mozilla::gfx::IntSize(640, 480));
   VideoSegment segment;
   segment.AppendFrame(generator.GenerateI420Image(),
                       mozilla::StreamTime(45000), // 0.5s
                       generator.GetSize(),
                       PRINCIPAL_HANDLE_NONE,
                       false,
                       now);
 
+  encoder.SetStartOffset(0);
   encoder.AppendVideoSegment(Move(segment));
   encoder.AdvanceCurrentTime(45000);
 
   encoder.Resume(now + TimeDuration::FromSeconds(0.5));
 
   segment.AppendFrame(generator.GenerateI420Image(),
                       mozilla::StreamTime(45000), // 0.5s
                       generator.GetSize(),
@@ -782,33 +760,31 @@ TEST(VP8VideoTrackEncoder, SuspendedBegi
   const uint64_t half = PR_USEC_PER_SEC / 2;
   EXPECT_EQ(half, 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.SetStartOffset(0);
   encoder.AppendVideoSegment(Move(segment));
 
   encoder.AdvanceCurrentTime(45000);
   encoder.Suspend(now + TimeDuration::FromSeconds(0.5));
 
   // Pass another 1s frame and resume after 0.3 of this new frame.
   segment.AppendFrame(generator.GenerateI420Image(),
                       mozilla::StreamTime(90000), // 1s
@@ -838,33 +814,31 @@ TEST(VP8VideoTrackEncoder, SuspendedOver
   }
   const uint64_t onePointTwo = (PR_USEC_PER_SEC / 10) * 12;
   EXPECT_EQ(onePointTwo, totalDuration);
 }
 
 // Test that ending a track in the middle of already pushed data works.
 TEST(VP8VideoTrackEncoder, PrematureEnding)
 {
-  // Initiate VP8 encoder
   TestVP8TrackEncoder encoder;
-  InitParam param = {true, 640, 480};
-  encoder.TestInit(param);
 
   // Pass a 1s frame and end the track 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.SetStartOffset(0);
   encoder.AppendVideoSegment(Move(segment));
   encoder.AdvanceCurrentTime(45000);
   encoder.NotifyEndOfStream();
 
   EncodedFrameContainer container;
   ASSERT_TRUE(NS_SUCCEEDED(encoder.GetEncodedTrack(container)));
 
   EXPECT_TRUE(encoder.IsEncodingComplete());
@@ -875,20 +849,17 @@ TEST(VP8VideoTrackEncoder, PrematureEndi
   }
   const uint64_t half = PR_USEC_PER_SEC / 2;
   EXPECT_EQ(half, totalDuration);
 }
 
 // EOS test
 TEST(VP8VideoTrackEncoder, EncodeComplete)
 {
-  // Initiate VP8 encoder
   TestVP8TrackEncoder encoder;
-  InitParam param = {true, 640, 480};
-  encoder.TestInit(param);
 
   // track end notification.
   encoder.NotifyEndOfStream();
 
   // Pull Encoded Data back from encoder. Since we have sent
   // EOS to encoder, encoder.GetEncodedTrack should return
   // NS_OK immidiately.
   EncodedFrameContainer container;