Bug 1254858: P5. Add h264 decoding gtest. r=kentuckyfriedtakahe a=ritu
authorJean-Yves Avenard <jyavenard@mozilla.com>
Wed, 09 Mar 2016 21:31:52 +1100
changeset 323721 15393c275f93da2f176d60e4bd3d2dc4b9f38254
parent 323720 78260f138a89defebc4902aec2dab773f5ffc9bf
child 323722 ed3b972887c065357ea93ce31fa21d5de013579c
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskentuckyfriedtakahe, ritu
bugs1254858
milestone47.0a2
Bug 1254858: P5. Add h264 decoding gtest. r=kentuckyfriedtakahe a=ritu MozReview-Commit-ID: 7uD0X9kRjsf
dom/media/gtest/TestMediaDataDecoder.cpp
dom/media/gtest/moz.build
new file mode 100644
--- /dev/null
+++ b/dom/media/gtest/TestMediaDataDecoder.cpp
@@ -0,0 +1,55 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "gtest/gtest.h"
+#include "Benchmark.h"
+#include "MockMediaResource.h"
+#include "DecoderTraits.h"
+#include "MP4Demuxer.h"
+
+using namespace mozilla;
+
+class BenchmarkRunner
+{
+public:
+  explicit BenchmarkRunner(Benchmark* aBenchmark)
+    : mBenchmark(aBenchmark) {}
+
+  uint32_t Run()
+  {
+    bool done = false;
+    uint32_t result = 0;
+
+    mBenchmark->Init();
+    mBenchmark->Run()->Then(
+      AbstractThread::MainThread(), __func__,
+      [&](uint32_t aDecodeFps) { result = aDecodeFps; done = true; },
+      [&]() { done = true; });
+
+    // Wait until benchmark completes.
+    while (!done) {
+      NS_ProcessNextEvent();
+    }
+    return result;
+  }
+
+private:
+  RefPtr<Benchmark> mBenchmark;
+};
+
+TEST(MediaDataDecoder, H264)
+{
+  if (!DecoderTraits::IsMP4TypeAndEnabled(NS_LITERAL_CSTRING("video/mp4"))) {
+    EXPECT_TRUE(true);
+  } else {
+    RefPtr<MediaResource> resource =
+      new MockMediaResource("gizmo.mp4", NS_LITERAL_CSTRING("video/mp4"));
+    nsresult rv = resource->Open(nullptr);
+    EXPECT_TRUE(NS_SUCCEEDED(rv));
+
+    BenchmarkRunner runner(new Benchmark(new MP4Demuxer(resource)));
+    EXPECT_GT(runner.Run(), 0u);
+  }
+}
--- a/dom/media/gtest/moz.build
+++ b/dom/media/gtest/moz.build
@@ -6,16 +6,17 @@
 
 UNIFIED_SOURCES += [
     'MockMediaResource.cpp',
     'TestAudioCompactor.cpp',
     'TestGMPCrossOrigin.cpp',
     'TestGMPRemoveAndDelete.cpp',
     'TestGMPUtils.cpp',
     'TestIntervalSet.cpp',
+    'TestMediaDataDecoder.cpp',
     'TestMediaEventSource.cpp',
     'TestMediaFormatReader.cpp',
     'TestMozPromise.cpp',
     'TestMP3Demuxer.cpp',
     'TestMP4Demuxer.cpp',
     # 'TestMP4Reader.cpp', disabled so we can turn check tests back on (bug 1175752)
     'TestTrackEncoder.cpp',
     'TestVideoSegment.cpp',