2016-03-03 05:57:11 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef MOZILLA_BENCHMARK_H
|
|
|
|
#define MOZILLA_BENCHMARK_H
|
|
|
|
|
2016-03-09 07:34:50 +03:00
|
|
|
#include "MediaDataDemuxer.h"
|
|
|
|
#include "PlatformDecoderModule.h"
|
2017-06-20 18:56:55 +03:00
|
|
|
#include "QueueObject.h"
|
2017-01-26 15:56:46 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2016-03-03 05:57:11 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
|
|
|
#include "mozilla/TimeStamp.h"
|
2019-07-10 08:24:54 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2016-03-09 07:34:50 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2016-03-03 05:57:11 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2016-05-24 11:48:26 +03:00
|
|
|
class TaskQueue;
|
2016-03-03 05:57:11 +03:00
|
|
|
class Benchmark;
|
|
|
|
|
2017-01-26 15:56:46 +03:00
|
|
|
class BenchmarkPlayback : public QueueObject {
|
2016-03-09 13:38:49 +03:00
|
|
|
friend class Benchmark;
|
2018-06-22 19:38:29 +03:00
|
|
|
BenchmarkPlayback(Benchmark* aGlobalState, MediaDataDemuxer* aDemuxer);
|
2016-03-09 07:34:50 +03:00
|
|
|
void DemuxSamples();
|
|
|
|
void DemuxNextSample();
|
2018-06-22 19:38:29 +03:00
|
|
|
void GlobalShutdown();
|
2019-07-10 08:24:54 +03:00
|
|
|
void InitDecoder(UniquePtr<TrackInfo>&& aInfo);
|
2016-03-03 05:57:11 +03:00
|
|
|
|
2018-11-09 18:45:31 +03:00
|
|
|
void Output(MediaDataDecoder::DecodedData&& aResults);
|
2018-03-29 23:11:06 +03:00
|
|
|
void Error(const MediaResult& aError);
|
2017-01-26 15:56:46 +03:00
|
|
|
void InputExhausted();
|
2016-03-03 05:57:11 +03:00
|
|
|
|
2018-03-29 23:11:06 +03:00
|
|
|
// Shutdown trackdemuxer and demuxer if any and shutdown the task queues.
|
|
|
|
void FinalizeShutdown();
|
|
|
|
|
2018-06-22 19:38:29 +03:00
|
|
|
Atomic<Benchmark*> mGlobalState;
|
2016-03-09 07:34:50 +03:00
|
|
|
|
2016-05-24 11:48:26 +03:00
|
|
|
RefPtr<TaskQueue> mDecoderTaskQueue;
|
2016-03-03 05:57:11 +03:00
|
|
|
RefPtr<MediaDataDecoder> mDecoder;
|
2016-03-09 07:34:50 +03:00
|
|
|
|
2016-03-09 10:49:22 +03:00
|
|
|
// Object only accessed on Thread()
|
2016-03-09 07:34:50 +03:00
|
|
|
RefPtr<MediaDataDemuxer> mDemuxer;
|
|
|
|
RefPtr<MediaTrackDemuxer> mTrackDemuxer;
|
2016-03-03 05:57:11 +03:00
|
|
|
nsTArray<RefPtr<MediaRawData>> mSamples;
|
2019-07-10 08:24:54 +03:00
|
|
|
UniquePtr<TrackInfo> mInfo;
|
2016-03-03 05:57:11 +03:00
|
|
|
size_t mSampleIndex;
|
2017-01-26 15:56:46 +03:00
|
|
|
Maybe<TimeStamp> mDecodeStartTime;
|
2016-03-03 05:57:11 +03:00
|
|
|
uint32_t mFrameCount;
|
|
|
|
bool mFinished;
|
2017-01-26 15:56:46 +03:00
|
|
|
bool mDrained;
|
2016-03-03 05:57:11 +03:00
|
|
|
};
|
|
|
|
|
2016-03-09 13:38:49 +03:00
|
|
|
// Init() must have been called at least once prior on the
|
|
|
|
// main thread.
|
2016-03-03 05:57:11 +03:00
|
|
|
class Benchmark : public QueueObject {
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(Benchmark)
|
|
|
|
|
2016-03-09 07:34:50 +03:00
|
|
|
struct Parameters {
|
|
|
|
Parameters()
|
2018-06-22 17:00:25 +03:00
|
|
|
: mFramesToMeasure(UINT32_MAX),
|
2016-03-09 07:34:50 +03:00
|
|
|
mStartupFrame(1),
|
2017-01-27 15:20:37 +03:00
|
|
|
mTimeout(TimeDuration::Forever()) {}
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2018-06-22 17:00:25 +03:00
|
|
|
Parameters(uint32_t aFramesToMeasure, uint32_t aStartupFrame,
|
2016-03-09 07:34:50 +03:00
|
|
|
uint32_t aStopAtFrame, const TimeDuration& aTimeout)
|
|
|
|
: mFramesToMeasure(aFramesToMeasure),
|
|
|
|
mStartupFrame(aStartupFrame),
|
|
|
|
mStopAtFrame(Some(aStopAtFrame)),
|
2017-01-27 15:20:37 +03:00
|
|
|
mTimeout(aTimeout) {}
|
2016-03-09 07:34:50 +03:00
|
|
|
|
2018-06-22 17:00:25 +03:00
|
|
|
const uint32_t mFramesToMeasure;
|
2016-03-09 07:34:50 +03:00
|
|
|
const uint32_t mStartupFrame;
|
2018-06-22 17:00:25 +03:00
|
|
|
const Maybe<uint32_t> mStopAtFrame;
|
2016-03-09 07:34:50 +03:00
|
|
|
const TimeDuration mTimeout;
|
|
|
|
};
|
|
|
|
|
2018-03-29 23:11:06 +03:00
|
|
|
typedef MozPromise<uint32_t, MediaResult, /* IsExclusive = */ true>
|
|
|
|
BenchmarkPromise;
|
2016-03-03 05:57:11 +03:00
|
|
|
|
2017-01-27 15:20:37 +03:00
|
|
|
explicit Benchmark(MediaDataDemuxer* aDemuxer,
|
|
|
|
const Parameters& aParameters = Parameters());
|
2016-03-09 07:34:50 +03:00
|
|
|
RefPtr<BenchmarkPromise> Run();
|
|
|
|
|
2018-06-22 17:00:25 +03:00
|
|
|
// Must be called on the main thread.
|
2016-03-09 13:38:49 +03:00
|
|
|
static void Init();
|
2016-03-03 05:57:11 +03:00
|
|
|
|
|
|
|
private:
|
2016-03-09 13:38:49 +03:00
|
|
|
friend class BenchmarkPlayback;
|
2016-03-09 07:34:50 +03:00
|
|
|
virtual ~Benchmark();
|
2016-03-09 13:38:49 +03:00
|
|
|
void ReturnResult(uint32_t aDecodeFps);
|
2018-03-29 23:11:06 +03:00
|
|
|
void ReturnError(const MediaResult& aError);
|
2016-03-09 13:38:49 +03:00
|
|
|
void Dispose();
|
|
|
|
const Parameters mParameters;
|
2016-03-03 05:57:11 +03:00
|
|
|
RefPtr<Benchmark> mKeepAliveUntilComplete;
|
|
|
|
BenchmarkPlayback mPlaybackState;
|
2016-03-09 07:34:50 +03:00
|
|
|
MozPromiseHolder<BenchmarkPromise> mPromise;
|
|
|
|
};
|
|
|
|
|
|
|
|
class VP9Benchmark {
|
|
|
|
public:
|
2018-07-03 19:32:09 +03:00
|
|
|
static bool IsVP9DecodeFast(bool aDefault = false);
|
2016-03-03 05:57:11 +03:00
|
|
|
static const char* sBenchmarkFpsPref;
|
2016-04-13 05:44:29 +03:00
|
|
|
static const char* sBenchmarkFpsVersionCheck;
|
|
|
|
static const uint32_t sBenchmarkVersionID;
|
2016-03-03 05:57:11 +03:00
|
|
|
static bool sHasRunTest;
|
2018-07-12 11:52:55 +03:00
|
|
|
// Return the value of media.benchmark.vp9.fps preference (which will be 0 if
|
|
|
|
// not known)
|
|
|
|
static uint32_t MediaBenchmarkVp9Fps();
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2018-07-12 11:52:55 +03:00
|
|
|
private:
|
|
|
|
static bool ShouldRun();
|
2016-03-03 05:57:11 +03:00
|
|
|
};
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|