Bug 1254858: P5. Add h264 decoding gtest. r=kentuckyfriedtakahe
MozReview-Commit-ID: 7uD0X9kRjsf
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',