Bug 1254858: P5. Add h264 decoding gtest. r=kentuckyfriedtakahe
authorJean-Yves Avenard <jyavenard@mozilla.com>
Wed, 09 Mar 2016 21:31:52 +1100
changeset 288105 e7900dcbea03e17ccaea804899143675d705c5b6
parent 288104 81269ce3999d02be196a04778b7da33c788a94ec
child 288106 ebb100508cf86790b126eb61f67d16d8bc6984df
push id30075
push usercbook@mozilla.com
push dateFri, 11 Mar 2016 15:51:11 +0000
treeherdermozilla-central@f907faa919be [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskentuckyfriedtakahe
bugs1254858
milestone48.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 1254858: P5. Add h264 decoding gtest. r=kentuckyfriedtakahe 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',