Bug 1850460 - Removed file build/build-clang/revert-llvmorg-18-init-3787-gb6a1473f97d...
[gecko.git] / dom / media / Benchmark.h
blobb76942edc575d3edea01219c23bc10d15c313a46
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/. */
7 #ifndef MOZILLA_BENCHMARK_H
8 #define MOZILLA_BENCHMARK_H
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 "mozilla/UniquePtr.h"
17 #include "nsCOMPtr.h"
19 namespace mozilla {
21 class TaskQueue;
22 class Benchmark;
24 class BenchmarkPlayback : public QueueObject {
25 friend class Benchmark;
26 BenchmarkPlayback(Benchmark* aGlobalState, MediaDataDemuxer* aDemuxer);
27 void DemuxSamples();
28 void DemuxNextSample();
29 void GlobalShutdown();
30 void InitDecoder(UniquePtr<TrackInfo>&& aInfo);
32 void Output(MediaDataDecoder::DecodedData&& aResults);
33 void Error(const MediaResult& aError);
34 void InputExhausted();
36 // Shutdown trackdemuxer and demuxer if any and shutdown the task queues.
37 void FinalizeShutdown();
39 Atomic<Benchmark*> mGlobalState;
41 RefPtr<TaskQueue> mDecoderTaskQueue;
42 RefPtr<MediaDataDecoder> mDecoder;
44 // Object only accessed on Thread()
45 RefPtr<MediaDataDemuxer> mDemuxer;
46 RefPtr<MediaTrackDemuxer> mTrackDemuxer;
47 nsTArray<RefPtr<MediaRawData>> mSamples;
48 UniquePtr<TrackInfo> mInfo;
49 size_t mSampleIndex;
50 Maybe<TimeStamp> mDecodeStartTime;
51 uint32_t mFrameCount;
52 bool mFinished;
53 bool mDrained;
56 // Init() must have been called at least once prior on the
57 // main thread.
58 class Benchmark : public QueueObject {
59 public:
60 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(Benchmark)
62 struct Parameters {
63 Parameters()
64 : mFramesToMeasure(UINT32_MAX),
65 mStartupFrame(1),
66 mTimeout(TimeDuration::Forever()) {}
68 Parameters(uint32_t aFramesToMeasure, uint32_t aStartupFrame,
69 uint32_t aStopAtFrame, const TimeDuration& aTimeout)
70 : mFramesToMeasure(aFramesToMeasure),
71 mStartupFrame(aStartupFrame),
72 mStopAtFrame(Some(aStopAtFrame)),
73 mTimeout(aTimeout) {}
75 const uint32_t mFramesToMeasure;
76 const uint32_t mStartupFrame;
77 const Maybe<uint32_t> mStopAtFrame;
78 const TimeDuration mTimeout;
81 typedef MozPromise<uint32_t, MediaResult, /* IsExclusive = */ true>
82 BenchmarkPromise;
84 explicit Benchmark(MediaDataDemuxer* aDemuxer,
85 const Parameters& aParameters = Parameters());
86 RefPtr<BenchmarkPromise> Run();
88 // Must be called on the main thread.
89 static void Init();
91 private:
92 friend class BenchmarkPlayback;
93 virtual ~Benchmark();
94 void ReturnResult(uint32_t aDecodeFps);
95 void ReturnError(const MediaResult& aError);
96 void Dispose();
97 const Parameters mParameters;
98 RefPtr<Benchmark> mKeepAliveUntilComplete;
99 BenchmarkPlayback mPlaybackState;
100 MozPromiseHolder<BenchmarkPromise> mPromise;
103 class VP9Benchmark {
104 public:
105 static bool IsVP9DecodeFast(bool aDefault = false);
106 static const char* sBenchmarkFpsPref;
107 static const char* sBenchmarkFpsVersionCheck;
108 static const uint32_t sBenchmarkVersionID;
109 static bool sHasRunTest;
110 // Return the value of media.benchmark.vp9.fps preference (which will be 0 if
111 // not known)
112 static uint32_t MediaBenchmarkVp9Fps();
114 private:
115 static bool ShouldRun();
117 } // namespace mozilla
119 #endif