/src/mozilla-central/dom/media/Benchmark.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim:set ts=2 sw=2 sts=2 et cindent: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef MOZILLA_BENCHMARK_H |
8 | | #define MOZILLA_BENCHMARK_H |
9 | | |
10 | | #include "MediaDataDemuxer.h" |
11 | | #include "PlatformDecoderModule.h" |
12 | | #include "QueueObject.h" |
13 | | #include "mozilla/Maybe.h" |
14 | | #include "mozilla/RefPtr.h" |
15 | | #include "mozilla/TimeStamp.h" |
16 | | #include "nsCOMPtr.h" |
17 | | |
18 | | namespace mozilla { |
19 | | |
20 | | class TaskQueue; |
21 | | class Benchmark; |
22 | | |
23 | | class BenchmarkPlayback : public QueueObject |
24 | | { |
25 | | friend class Benchmark; |
26 | | BenchmarkPlayback(Benchmark* aGlobalState, MediaDataDemuxer* aDemuxer); |
27 | | void DemuxSamples(); |
28 | | void DemuxNextSample(); |
29 | | void GlobalShutdown(); |
30 | | void InitDecoder(TrackInfo&& aInfo); |
31 | | |
32 | | void Output(const MediaDataDecoder::DecodedData& aResults); |
33 | | void Error(const MediaResult& aError); |
34 | | void InputExhausted(); |
35 | | |
36 | | // Shutdown trackdemuxer and demuxer if any and shutdown the task queues. |
37 | | void FinalizeShutdown(); |
38 | | |
39 | | Atomic<Benchmark*> mGlobalState; |
40 | | |
41 | | RefPtr<TaskQueue> mDecoderTaskQueue; |
42 | | RefPtr<MediaDataDecoder> mDecoder; |
43 | | |
44 | | // Object only accessed on Thread() |
45 | | RefPtr<MediaDataDemuxer> mDemuxer; |
46 | | RefPtr<MediaTrackDemuxer> mTrackDemuxer; |
47 | | nsTArray<RefPtr<MediaRawData>> mSamples; |
48 | | size_t mSampleIndex; |
49 | | Maybe<TimeStamp> mDecodeStartTime; |
50 | | uint32_t mFrameCount; |
51 | | bool mFinished; |
52 | | bool mDrained; |
53 | | }; |
54 | | |
55 | | // Init() must have been called at least once prior on the |
56 | | // main thread. |
57 | | class Benchmark : public QueueObject |
58 | | { |
59 | | public: |
60 | | NS_INLINE_DECL_THREADSAFE_REFCOUNTING(Benchmark) |
61 | | |
62 | | struct Parameters |
63 | | { |
64 | | Parameters() |
65 | | : mFramesToMeasure(UINT32_MAX) |
66 | | , mStartupFrame(1) |
67 | | , mTimeout(TimeDuration::Forever()) |
68 | 0 | { |
69 | 0 | } |
70 | | |
71 | | Parameters(uint32_t aFramesToMeasure, |
72 | | uint32_t aStartupFrame, |
73 | | uint32_t aStopAtFrame, |
74 | | const TimeDuration& aTimeout) |
75 | | : mFramesToMeasure(aFramesToMeasure) |
76 | | , mStartupFrame(aStartupFrame) |
77 | | , mStopAtFrame(Some(aStopAtFrame)) |
78 | | , mTimeout(aTimeout) |
79 | 0 | { |
80 | 0 | } |
81 | | |
82 | | const uint32_t mFramesToMeasure; |
83 | | const uint32_t mStartupFrame; |
84 | | const Maybe<uint32_t> mStopAtFrame; |
85 | | const TimeDuration mTimeout; |
86 | | }; |
87 | | |
88 | | typedef MozPromise<uint32_t, MediaResult, /* IsExclusive = */ true> BenchmarkPromise; |
89 | | |
90 | | explicit Benchmark(MediaDataDemuxer* aDemuxer, |
91 | | const Parameters& aParameters = Parameters()); |
92 | | RefPtr<BenchmarkPromise> Run(); |
93 | | |
94 | | // Must be called on the main thread. |
95 | | static void Init(); |
96 | | |
97 | | private: |
98 | | friend class BenchmarkPlayback; |
99 | | virtual ~Benchmark(); |
100 | | void ReturnResult(uint32_t aDecodeFps); |
101 | | void ReturnError(const MediaResult& aError); |
102 | | void Dispose(); |
103 | | const Parameters mParameters; |
104 | | RefPtr<Benchmark> mKeepAliveUntilComplete; |
105 | | BenchmarkPlayback mPlaybackState; |
106 | | MozPromiseHolder<BenchmarkPromise> mPromise; |
107 | | }; |
108 | | |
109 | | class VP9Benchmark |
110 | | { |
111 | | public: |
112 | | static bool IsVP9DecodeFast(bool aDefault = false); |
113 | | static const char* sBenchmarkFpsPref; |
114 | | static const char* sBenchmarkFpsVersionCheck; |
115 | | static const uint32_t sBenchmarkVersionID; |
116 | | static bool sHasRunTest; |
117 | | // Return the value of media.benchmark.vp9.fps preference (which will be 0 if |
118 | | // not known) |
119 | | static uint32_t MediaBenchmarkVp9Fps(); |
120 | | private: |
121 | | static bool ShouldRun(); |
122 | | }; |
123 | | } |
124 | | |
125 | | #endif |