Bug 1332585 - Add gtest for encoding a single frame. r=jesup
authorAndreas Pehrson <pehrsons@gmail.com>
Fri, 20 Jan 2017 12:24:36 +0100
changeset 377778 60d77d6c0becd0eb74d6474e70782e4e92d61501
parent 377777 76f2c83d048c379d19dbb2170db9f9f200df0804
child 377779 d7538cc4bf1e65ac89713e686c6144995d32bbf4
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs1332585
milestone53.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 1332585 - Add gtest for encoding a single frame. r=jesup MozReview-Commit-ID: DAEG4hO34G6
dom/media/gtest/TestVideoTrackEncoder.cpp
--- a/dom/media/gtest/TestVideoTrackEncoder.cpp
+++ b/dom/media/gtest/TestVideoTrackEncoder.cpp
@@ -290,16 +290,56 @@ TEST(VP8VideoTrackEncoder, FrameEncode)
   // track change notification.
   encoder.SetCurrentFrames(segment);
 
   // 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.SetCurrentFrames(segment);
+
+  // End the track.
+  segment.Clear();
+  encoder.NotifyQueuedTrackChanges(nullptr, 0, 0, TrackEventCommand::TRACK_EVENT_ENDED, segment);
+
+  EncodedFrameContainer container;
+  ASSERT_TRUE(NS_SUCCEEDED(encoder.GetEncodedTrack(container)));
+
+  EXPECT_TRUE(encoder.IsEncodingComplete());
+
+  // Read out encoded data, and verify.
+  const nsTArray<RefPtr<EncodedFrame>>& frames = container.GetEncodedFrames();
+  const size_t oneElement = 1;
+  ASSERT_EQ(oneElement, frames.Length());
+
+  EXPECT_EQ(EncodedFrame::VP8_I_FRAME, frames[0]->GetFrameType()) <<
+    "We only have one frame, so it should be a keyframe";
+
+  const uint64_t halfSecond = PR_USEC_PER_SEC / 2;
+  EXPECT_EQ(halfSecond, frames[0]->GetDuration());
+}
+
 // EOS test
 TEST(VP8VideoTrackEncoder, EncodeComplete)
 {
   // Initiate VP8 encoder
   TestVP8TrackEncoder encoder;
   InitParam param = {true, 640, 480};
   encoder.TestInit(param);