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"
|
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-03 05:57:11 +03:00
|
|
|
{
|
2016-03-09 13:38:49 +03:00
|
|
|
friend class Benchmark;
|
2017-01-27 15:20:37 +03:00
|
|
|
BenchmarkPlayback(Benchmark* aMainThreadState, MediaDataDemuxer* aDemuxer);
|
2016-03-09 07:34:50 +03:00
|
|
|
void DemuxSamples();
|
|
|
|
void DemuxNextSample();
|
2016-03-03 05:57:11 +03:00
|
|
|
void MainThreadShutdown();
|
2016-03-09 07:34:50 +03:00
|
|
|
void InitDecoder(TrackInfo&& aInfo);
|
2016-03-03 05:57:11 +03:00
|
|
|
|
2017-01-26 15:56:46 +03:00
|
|
|
void Output(const MediaDataDecoder::DecodedData& aResults);
|
|
|
|
void InputExhausted();
|
2016-03-03 05:57:11 +03:00
|
|
|
|
2016-03-09 07:34:50 +03:00
|
|
|
Atomic<Benchmark*> mMainThreadState;
|
|
|
|
|
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;
|
|
|
|
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()
|
|
|
|
: mFramesToMeasure(-1)
|
|
|
|
, mStartupFrame(1)
|
2017-01-27 15:20:37 +03:00
|
|
|
, mTimeout(TimeDuration::Forever())
|
|
|
|
{
|
|
|
|
}
|
2016-03-09 07:34:50 +03:00
|
|
|
|
|
|
|
Parameters(int32_t aFramesToMeasure,
|
|
|
|
uint32_t aStartupFrame,
|
|
|
|
int32_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
|
|
|
|
|
|
|
const int32_t mFramesToMeasure;
|
|
|
|
const uint32_t mStartupFrame;
|
|
|
|
const Maybe<int32_t> mStopAtFrame;
|
|
|
|
const TimeDuration mTimeout;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef MozPromise<uint32_t, bool, /* 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();
|
|
|
|
|
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);
|
|
|
|
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:
|
|
|
|
static bool IsVP9DecodeFast();
|
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;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|