Bug 1570337 - p4: test initializing encoder both w/ and w/o specific parameters. r?jya draft
authorpulselistener
Wed, 28 Aug 2019 23:14:46 +0000
changeset 2245290 6e0724afea1a89ba6ff43e399dc891e30a347793
parent 2245289 2bc7ce5a2c2e7aceefeacd130877b47dca91507d
child 2245291 ff2cca29efd77820db0fdc4e5add4a7eea955065
push id413423
push userreviewbot
push dateWed, 28 Aug 2019 23:15:31 +0000
treeherdertry@5f11893726ee [default view] [failures only]
reviewersjya
bugs1570337
milestone70.0a1
Bug 1570337 - p4: test initializing encoder both w/ and w/o specific parameters. r?jya Differential Revision: https://phabricator.services.mozilla.com/D43688 Differential Diff: PHID-DIFF-wxgbr4egjetjm74zkquz
dom/media/gtest/TestMediaDataEncoder.cpp
--- a/dom/media/gtest/TestMediaDataEncoder.cpp
+++ b/dom/media/gtest/TestMediaDataEncoder.cpp
@@ -27,17 +27,18 @@
   } while (0)
 
 #define BLOCK_SIZE 64
 #define WIDTH 640
 #define HEIGHT 480
 #define NUM_FRAMES 150UL
 #define FRAME_RATE 30
 #define FRAME_DURATION (1000000 / FRAME_RATE)
-#define BIT_RATE (1000 * 1000)  // 1Mbps
+#define BIT_RATE (1000 * 1000)        // 1Mbps
+#define KEYFRAME_INTERVAL FRAME_RATE  // 1 keyframe per second
 
 using namespace mozilla;
 
 static gfx::IntSize kImageSize(WIDTH, HEIGHT);
 
 class MediaDataEncoderTest : public testing::Test {
  protected:
   void SetUp() override { mData.Init(kImageSize); }
@@ -128,32 +129,44 @@ class MediaDataEncoderTest : public test
     }
   };
 
  public:
   FrameSource mData;
 };
 
 static already_AddRefed<MediaDataEncoder> CreateH264Encoder(
-    MediaDataEncoder::Usage aUsage,
-    MediaDataEncoder::PixelFormat aPixelFormat) {
+    MediaDataEncoder::Usage aUsage, MediaDataEncoder::PixelFormat aPixelFormat,
+    const Maybe<MediaDataEncoder::H264Specific>& aSpecific =
+        Some(MediaDataEncoder::H264Specific(
+            KEYFRAME_INTERVAL,
+            MediaDataEncoder::H264Specific::ProfileLevel::BaselineAutoLevel))) {
   RefPtr<PEMFactory> f(new PEMFactory());
 
   if (!f->SupportsMimeType(NS_LITERAL_CSTRING(VIDEO_MP4))) {
     return nullptr;
   }
 
   VideoInfo videoInfo(WIDTH, HEIGHT);
   videoInfo.mMimeType = NS_LITERAL_CSTRING(VIDEO_MP4);
   const RefPtr<TaskQueue> taskQueue(
       new TaskQueue(GetMediaThreadPool(MediaThreadType::PLAYBACK)));
-  CreateEncoderParams c(videoInfo /* track info */, aUsage, taskQueue,
-                        aPixelFormat, FRAME_RATE /* FPS */,
-                        BIT_RATE /* bitrate */);
-  return f->CreateEncoder(c);
+
+  RefPtr<MediaDataEncoder> e;
+  if (aSpecific) {
+    e = f->CreateEncoder(CreateEncoderParams(
+        videoInfo /* track info */, aUsage, taskQueue, aPixelFormat,
+        FRAME_RATE /* FPS */, BIT_RATE /* bitrate */, aSpecific.value()));
+  } else {
+    e = f->CreateEncoder(CreateEncoderParams(
+        videoInfo /* track info */, aUsage, taskQueue, aPixelFormat,
+        FRAME_RATE /* FPS */, BIT_RATE /* bitrate */));
+  }
+
+  return e.forget();
 }
 
 void WaitForShutdown(RefPtr<MediaDataEncoder> aEncoder) {
   MOZ_ASSERT(aEncoder);
 
   Maybe<bool> result;
   // media::Await() supports exclusive promises only, but ShutdownPromise is
   // not.
@@ -193,16 +206,32 @@ static bool EnsureInit(RefPtr<MediaDataE
       [&succeeded](TrackInfo::TrackType t) {
         EXPECT_EQ(TrackInfo::TrackType::kVideoTrack, t);
         succeeded = true;
       },
       [&succeeded](MediaResult r) { succeeded = false; });
   return succeeded;
 }
 
+TEST_F(MediaDataEncoderTest, H264InitWithoutSpecific) {
+  SKIP_IF_NOT_SUPPORTED(VIDEO_MP4);
+
+  RefPtr<MediaDataEncoder> e =
+      CreateH264Encoder(MediaDataEncoder::Usage::Realtime,
+                        MediaDataEncoder::PixelFormat::YUV420P, Nothing());
+
+#if defined(MOZ_WIDGET_ANDROID)  // Android encoder requires I-frame interval
+  EXPECT_FALSE(EnsureInit(e));
+#else
+  EXPECT_TRUE(EnsureInit(e));
+#endif
+
+  WaitForShutdown(e);
+}
+
 TEST_F(MediaDataEncoderTest, H264Init) {
   SKIP_IF_NOT_SUPPORTED(VIDEO_MP4);
 
   RefPtr<MediaDataEncoder> e =
       CreateH264Encoder(MediaDataEncoder::Usage::Realtime,
                         MediaDataEncoder::PixelFormat::YUV420P);
 
   EXPECT_TRUE(EnsureInit(e));
@@ -300,9 +329,9 @@ TEST_F(MediaDataEncoderTest, EncodeMulti
   MediaDataEncoder::EncodedData output = Encode(e, NUM_FRAMES, mData);
   EXPECT_EQ(output.Length(), NUM_FRAMES);
   AnnexB::IsAVCC(output[0]);  // Only 1st frame has extra data.
   for (auto frame : output) {
     EXPECT_FALSE(AnnexB::IsAnnexB(frame));
   }
 
   WaitForShutdown(e);
-}
\ No newline at end of file
+}