2015-09-15 17:57:20 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* 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 FrameStatistics_h_
|
|
|
|
#define FrameStatistics_h_
|
|
|
|
|
2016-07-18 03:41:40 +03:00
|
|
|
#include "mozilla/ReentrantMonitor.h"
|
|
|
|
|
2015-09-15 17:57:20 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
2016-07-18 02:51:25 +03:00
|
|
|
struct FrameStatisticsData {
|
|
|
|
// Number of frames parsed and demuxed from media.
|
|
|
|
// Access protected by mReentrantMonitor.
|
2016-07-18 03:51:30 +03:00
|
|
|
uint64_t mParsedFrames = 0;
|
2016-07-18 02:51:25 +03:00
|
|
|
|
|
|
|
// Number of parsed frames which were actually decoded.
|
|
|
|
// Access protected by mReentrantMonitor.
|
2016-07-18 03:51:30 +03:00
|
|
|
uint64_t mDecodedFrames = 0;
|
2016-07-18 02:51:25 +03:00
|
|
|
|
2019-04-16 14:50:38 +03:00
|
|
|
// Number of parsed frames which were dropped in the decoder.
|
|
|
|
// Access protected by mReentrantMonitor.
|
|
|
|
uint64_t mDroppedDecodedFrames = 0;
|
|
|
|
|
|
|
|
// Number of decoded frames which were dropped in the sink
|
|
|
|
// Access protected by mReentrantMonitor.
|
|
|
|
uint64_t mDroppedSinkFrames = 0;
|
|
|
|
|
|
|
|
// Number of sinked frames which were dropped in the compositor
|
|
|
|
// Access protected by mReentrantMonitor.
|
|
|
|
uint64_t mDroppedCompositorFrames = 0;
|
|
|
|
|
2016-07-18 02:51:25 +03:00
|
|
|
// Number of decoded frames which were actually sent down the rendering
|
|
|
|
// pipeline to be painted ("presented"). Access protected by
|
|
|
|
// mReentrantMonitor.
|
2016-07-18 03:51:30 +03:00
|
|
|
uint64_t mPresentedFrames = 0;
|
2016-07-18 02:51:25 +03:00
|
|
|
|
2016-07-26 02:36:55 +03:00
|
|
|
// Sum of all inter-keyframe segment durations, in microseconds.
|
|
|
|
// Dividing by count will give the average inter-keyframe time.
|
|
|
|
uint64_t mInterKeyframeSum_us = 0;
|
|
|
|
// Number of inter-keyframe segments summed so far.
|
|
|
|
size_t mInterKeyframeCount = 0;
|
|
|
|
|
|
|
|
// Maximum inter-keyframe segment duration, in microseconds.
|
|
|
|
uint64_t mInterKeyFrameMax_us = 0;
|
|
|
|
|
2016-07-18 03:41:40 +03:00
|
|
|
FrameStatisticsData() = default;
|
2019-04-16 14:50:38 +03:00
|
|
|
FrameStatisticsData(uint64_t aParsed, uint64_t aDecoded, uint64_t aPresented,
|
|
|
|
uint64_t aDroppedDecodedFrames,
|
|
|
|
uint64_t aDroppedSinkFrames,
|
|
|
|
uint64_t aDroppedCompositorFrames)
|
2016-07-18 03:41:40 +03:00
|
|
|
: mParsedFrames(aParsed),
|
|
|
|
mDecodedFrames(aDecoded),
|
2019-04-16 14:50:38 +03:00
|
|
|
mDroppedDecodedFrames(aDroppedDecodedFrames),
|
|
|
|
mDroppedSinkFrames(aDroppedSinkFrames),
|
|
|
|
mDroppedCompositorFrames(aDroppedCompositorFrames),
|
|
|
|
mPresentedFrames(aPresented) {}
|
2016-07-18 03:41:40 +03:00
|
|
|
|
|
|
|
void Accumulate(const FrameStatisticsData& aStats) {
|
|
|
|
mParsedFrames += aStats.mParsedFrames;
|
|
|
|
mDecodedFrames += aStats.mDecodedFrames;
|
|
|
|
mPresentedFrames += aStats.mPresentedFrames;
|
2019-04-16 14:50:38 +03:00
|
|
|
mDroppedDecodedFrames += aStats.mDroppedDecodedFrames;
|
|
|
|
mDroppedSinkFrames += aStats.mDroppedSinkFrames;
|
|
|
|
mDroppedCompositorFrames += aStats.mDroppedCompositorFrames;
|
2016-07-26 02:36:55 +03:00
|
|
|
mInterKeyframeSum_us += aStats.mInterKeyframeSum_us;
|
|
|
|
mInterKeyframeCount += aStats.mInterKeyframeCount;
|
|
|
|
// It doesn't make sense to add max numbers, instead keep the bigger one.
|
|
|
|
if (mInterKeyFrameMax_us < aStats.mInterKeyFrameMax_us) {
|
|
|
|
mInterKeyFrameMax_us = aStats.mInterKeyFrameMax_us;
|
|
|
|
}
|
2016-07-18 03:41:40 +03:00
|
|
|
}
|
2016-07-18 02:51:25 +03:00
|
|
|
};
|
|
|
|
|
2015-09-15 17:57:20 +03:00
|
|
|
// Frame decoding/painting related performance counters.
|
|
|
|
// Threadsafe.
|
2016-07-15 09:48:56 +03:00
|
|
|
class FrameStatistics {
|
2015-09-15 17:57:20 +03:00
|
|
|
public:
|
2015-12-03 10:59:30 +03:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(FrameStatistics);
|
|
|
|
|
2016-07-15 09:48:56 +03:00
|
|
|
FrameStatistics() : mReentrantMonitor("FrameStats") {}
|
2015-09-15 17:57:20 +03:00
|
|
|
|
2016-07-18 02:51:25 +03:00
|
|
|
// Returns a copy of all frame statistics data.
|
|
|
|
// Can be called on any thread.
|
|
|
|
FrameStatisticsData GetFrameStatisticsData() const {
|
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
|
|
|
return mFrameStatisticsData;
|
|
|
|
}
|
|
|
|
|
2015-09-15 17:57:20 +03:00
|
|
|
// Returns number of frames which have been parsed from the media.
|
|
|
|
// Can be called on any thread.
|
2016-07-18 03:51:30 +03:00
|
|
|
uint64_t GetParsedFrames() const {
|
2015-09-15 17:57:20 +03:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2016-07-18 02:51:25 +03:00
|
|
|
return mFrameStatisticsData.mParsedFrames;
|
2015-09-15 17:57:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the number of parsed frames which have been decoded.
|
|
|
|
// Can be called on any thread.
|
2016-07-18 03:51:30 +03:00
|
|
|
uint64_t GetDecodedFrames() const {
|
2015-09-15 17:57:20 +03:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2016-07-18 02:51:25 +03:00
|
|
|
return mFrameStatisticsData.mDecodedFrames;
|
2015-09-15 17:57:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the number of decoded frames which have been sent to the rendering
|
|
|
|
// pipeline for painting ("presented").
|
|
|
|
// Can be called on any thread.
|
2016-07-18 03:51:30 +03:00
|
|
|
uint64_t GetPresentedFrames() const {
|
2015-09-15 17:57:20 +03:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2016-07-18 02:51:25 +03:00
|
|
|
return mFrameStatisticsData.mPresentedFrames;
|
2015-09-15 17:57:20 +03:00
|
|
|
}
|
|
|
|
|
2019-04-16 14:50:38 +03:00
|
|
|
// Returns the number of presented and dropped frames
|
|
|
|
// Can be called on any thread.
|
|
|
|
uint64_t GetTotalFrames() const {
|
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
|
|
|
return mFrameStatisticsData.mPresentedFrames + GetDroppedFrames();
|
|
|
|
}
|
|
|
|
|
2016-07-15 09:48:56 +03:00
|
|
|
// Returns the number of frames that have been skipped because they have
|
|
|
|
// missed their composition deadline.
|
2016-07-18 03:51:30 +03:00
|
|
|
uint64_t GetDroppedFrames() const {
|
2015-09-15 17:57:20 +03:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2019-04-16 14:50:38 +03:00
|
|
|
return mFrameStatisticsData.mDroppedDecodedFrames +
|
|
|
|
mFrameStatisticsData.mDroppedSinkFrames +
|
|
|
|
mFrameStatisticsData.mDroppedCompositorFrames;
|
2015-09-15 17:57:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Increments the parsed and decoded frame counters by the passed in counts.
|
|
|
|
// Can be called on any thread.
|
2018-08-27 13:27:19 +03:00
|
|
|
void Accumulate(const FrameStatisticsData& aStats) {
|
2015-09-15 17:57:20 +03:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2016-07-18 03:41:40 +03:00
|
|
|
mFrameStatisticsData.Accumulate(aStats);
|
2015-09-15 17:57:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Increments the presented frame counters.
|
|
|
|
// Can be called on any thread.
|
2016-07-15 09:48:56 +03:00
|
|
|
void NotifyPresentedFrame() {
|
2015-09-15 17:57:20 +03:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2016-07-18 02:51:25 +03:00
|
|
|
++mFrameStatisticsData.mPresentedFrames;
|
2015-09-15 17:57:20 +03:00
|
|
|
}
|
|
|
|
|
2017-07-13 10:17:25 +03:00
|
|
|
// Stack based class to assist in notifying the frame statistics of
|
|
|
|
// parsed and decoded frames. Use inside video demux & decode functions
|
|
|
|
// to ensure all parsed and decoded frames are reported on all return paths.
|
|
|
|
class AutoNotifyDecoded {
|
|
|
|
public:
|
|
|
|
explicit AutoNotifyDecoded(FrameStatistics* aFrameStats)
|
|
|
|
: mFrameStats(aFrameStats) {}
|
|
|
|
~AutoNotifyDecoded() {
|
|
|
|
if (mFrameStats) {
|
2018-08-27 13:27:19 +03:00
|
|
|
mFrameStats->Accumulate(mStats);
|
2017-07-13 10:17:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FrameStatisticsData mStats;
|
|
|
|
|
|
|
|
private:
|
|
|
|
FrameStatistics* mFrameStats;
|
|
|
|
};
|
|
|
|
|
2015-09-15 17:57:20 +03:00
|
|
|
private:
|
2015-12-03 10:59:30 +03:00
|
|
|
~FrameStatistics() {}
|
2015-09-15 17:57:20 +03:00
|
|
|
|
|
|
|
// ReentrantMonitor to protect access of playback statistics.
|
2016-07-15 09:48:56 +03:00
|
|
|
mutable ReentrantMonitor mReentrantMonitor;
|
2015-09-15 17:57:20 +03:00
|
|
|
|
2016-07-18 02:51:25 +03:00
|
|
|
FrameStatisticsData mFrameStatisticsData;
|
2015-09-15 17:57:20 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2016-07-15 09:48:56 +03:00
|
|
|
#endif // FrameStatistics_h_
|