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"
24 class BenchmarkPlayback
: public QueueObject
{
25 friend class Benchmark
;
26 BenchmarkPlayback(Benchmark
* aGlobalState
, MediaDataDemuxer
* aDemuxer
);
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
;
50 Maybe
<TimeStamp
> mDecodeStartTime
;
56 // Init() must have been called at least once prior on the
58 class Benchmark
: public QueueObject
{
60 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(Benchmark
)
64 : mFramesToMeasure(UINT32_MAX
),
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
)),
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>
84 explicit Benchmark(MediaDataDemuxer
* aDemuxer
,
85 const Parameters
& aParameters
= Parameters());
86 RefPtr
<BenchmarkPromise
> Run();
88 // Must be called on the main thread.
92 friend class BenchmarkPlayback
;
94 void ReturnResult(uint32_t aDecodeFps
);
95 void ReturnError(const MediaResult
& aError
);
97 const Parameters mParameters
;
98 RefPtr
<Benchmark
> mKeepAliveUntilComplete
;
99 BenchmarkPlayback mPlaybackState
;
100 MozPromiseHolder
<BenchmarkPromise
> mPromise
;
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
112 static uint32_t MediaBenchmarkVp9Fps();
115 static bool ShouldRun();
117 } // namespace mozilla