/src/mozilla-central/dom/media/gtest/TestMediaDataDecoder.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | | |
6 | | #include "gtest/gtest.h" |
7 | | #include "Benchmark.h" |
8 | | #include "MockMediaResource.h" |
9 | | #include "DecoderTraits.h" |
10 | | #include "MediaContainerType.h" |
11 | | #include "MP4Demuxer.h" |
12 | | #include "WebMDecoder.h" |
13 | | #include "WebMDemuxer.h" |
14 | | #include "mozilla/AbstractThread.h" |
15 | | #include "nsMimeTypes.h" |
16 | | |
17 | | using namespace mozilla; |
18 | | |
19 | | class BenchmarkRunner |
20 | | { |
21 | | public: |
22 | | explicit BenchmarkRunner(Benchmark* aBenchmark) |
23 | 0 | : mBenchmark(aBenchmark) {} |
24 | | |
25 | | uint32_t Run() |
26 | 0 | { |
27 | 0 | bool done = false; |
28 | 0 | uint32_t result = 0; |
29 | 0 |
|
30 | 0 | mBenchmark->Init(); |
31 | 0 | mBenchmark->Run()->Then( |
32 | 0 | // Non DocGroup-version of AbstractThread::MainThread() is fine for testing. |
33 | 0 | AbstractThread::MainThread(), __func__, |
34 | 0 | [&](uint32_t aDecodeFps) { result = aDecodeFps; done = true; }, |
35 | 0 | [&]() { done = true; }); |
36 | 0 |
|
37 | 0 | // Wait until benchmark completes. |
38 | 0 | SpinEventLoopUntil([&]() { return done; }); |
39 | 0 | return result; |
40 | 0 | } |
41 | | |
42 | | private: |
43 | | RefPtr<Benchmark> mBenchmark; |
44 | | }; |
45 | | |
46 | | TEST(MediaDataDecoder, H264) |
47 | 0 | { |
48 | 0 | if (!DecoderTraits::IsMP4SupportedType( |
49 | 0 | MediaContainerType(MEDIAMIMETYPE(VIDEO_MP4)), |
50 | 0 | /* DecoderDoctorDiagnostics* */ nullptr)) { |
51 | 0 | EXPECT_TRUE(true); |
52 | 0 | } else { |
53 | 0 | RefPtr<MockMediaResource> resource = new MockMediaResource("gizmo.mp4"); |
54 | 0 | nsresult rv = resource->Open(); |
55 | 0 | EXPECT_TRUE(NS_SUCCEEDED(rv)); |
56 | 0 |
|
57 | 0 | BenchmarkRunner runner(new Benchmark(new MP4Demuxer(resource))); |
58 | 0 | EXPECT_GT(runner.Run(), 0u); |
59 | 0 | } |
60 | 0 | } |
61 | | |
62 | | TEST(MediaDataDecoder, VP9) |
63 | 0 | { |
64 | 0 | if (!WebMDecoder::IsSupportedType(MediaContainerType(MEDIAMIMETYPE(VIDEO_WEBM)))) { |
65 | 0 | EXPECT_TRUE(true); |
66 | 0 | } else { |
67 | 0 | RefPtr<MockMediaResource> resource = new MockMediaResource("vp9cake.webm"); |
68 | 0 | nsresult rv = resource->Open(); |
69 | 0 | EXPECT_TRUE(NS_SUCCEEDED(rv)); |
70 | 0 |
|
71 | 0 | BenchmarkRunner runner(new Benchmark(new WebMDemuxer(resource))); |
72 | 0 | EXPECT_GT(runner.Run(), 0u); |
73 | 0 | } |
74 | 0 | } |