Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
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/. */
6 :
7 : #ifndef FrameStatistics_h_
8 : #define FrameStatistics_h_
9 :
10 : #include "mozilla/ReentrantMonitor.h"
11 :
12 : namespace mozilla {
13 :
14 : struct FrameStatisticsData
15 : {
16 : // Number of frames parsed and demuxed from media.
17 : // Access protected by mReentrantMonitor.
18 : uint64_t mParsedFrames = 0;
19 :
20 : // Number of parsed frames which were actually decoded.
21 : // Access protected by mReentrantMonitor.
22 : uint64_t mDecodedFrames = 0;
23 :
24 : // Number of decoded frames which were actually sent down the rendering
25 : // pipeline to be painted ("presented"). Access protected by mReentrantMonitor.
26 : uint64_t mPresentedFrames = 0;
27 :
28 : // Number of frames that have been skipped because they have missed their
29 : // composition deadline.
30 : uint64_t mDroppedFrames = 0;
31 :
32 : // Sum of all inter-keyframe segment durations, in microseconds.
33 : // Dividing by count will give the average inter-keyframe time.
34 : uint64_t mInterKeyframeSum_us = 0;
35 : // Number of inter-keyframe segments summed so far.
36 : size_t mInterKeyframeCount = 0;
37 :
38 : // Maximum inter-keyframe segment duration, in microseconds.
39 : uint64_t mInterKeyFrameMax_us = 0;
40 :
41 0 : FrameStatisticsData() = default;
42 0 : FrameStatisticsData(uint64_t aParsed, uint64_t aDecoded, uint64_t aDropped)
43 0 : : mParsedFrames(aParsed)
44 : , mDecodedFrames(aDecoded)
45 0 : , mDroppedFrames(aDropped)
46 0 : {}
47 :
48 : void
49 0 : Accumulate(const FrameStatisticsData& aStats)
50 : {
51 0 : mParsedFrames += aStats.mParsedFrames;
52 0 : mDecodedFrames += aStats.mDecodedFrames;
53 0 : mPresentedFrames += aStats.mPresentedFrames;
54 0 : mDroppedFrames += aStats.mDroppedFrames;
55 0 : mInterKeyframeSum_us += aStats.mInterKeyframeSum_us;
56 0 : mInterKeyframeCount += aStats.mInterKeyframeCount;
57 : // It doesn't make sense to add max numbers, instead keep the bigger one.
58 0 : if (mInterKeyFrameMax_us < aStats.mInterKeyFrameMax_us) {
59 0 : mInterKeyFrameMax_us = aStats.mInterKeyFrameMax_us;
60 : }
61 0 : }
62 : };
63 :
64 : // Frame decoding/painting related performance counters.
65 : // Threadsafe.
66 : class FrameStatistics
67 : {
68 : public:
69 0 : NS_INLINE_DECL_THREADSAFE_REFCOUNTING(FrameStatistics);
70 :
71 0 : FrameStatistics()
72 0 : : mReentrantMonitor("FrameStats")
73 0 : {}
74 :
75 : // Returns a copy of all frame statistics data.
76 : // Can be called on any thread.
77 0 : FrameStatisticsData GetFrameStatisticsData() const
78 : {
79 0 : ReentrantMonitorAutoEnter mon(mReentrantMonitor);
80 0 : return mFrameStatisticsData;
81 : }
82 :
83 : // Returns number of frames which have been parsed from the media.
84 : // Can be called on any thread.
85 0 : uint64_t GetParsedFrames() const
86 : {
87 0 : ReentrantMonitorAutoEnter mon(mReentrantMonitor);
88 0 : return mFrameStatisticsData.mParsedFrames;
89 : }
90 :
91 : // Returns the number of parsed frames which have been decoded.
92 : // Can be called on any thread.
93 0 : uint64_t GetDecodedFrames() const
94 : {
95 0 : ReentrantMonitorAutoEnter mon(mReentrantMonitor);
96 0 : return mFrameStatisticsData.mDecodedFrames;
97 : }
98 :
99 : // Returns the number of decoded frames which have been sent to the rendering
100 : // pipeline for painting ("presented").
101 : // Can be called on any thread.
102 0 : uint64_t GetPresentedFrames() const
103 : {
104 0 : ReentrantMonitorAutoEnter mon(mReentrantMonitor);
105 0 : return mFrameStatisticsData.mPresentedFrames;
106 : }
107 :
108 : // Returns the number of frames that have been skipped because they have
109 : // missed their composition deadline.
110 : uint64_t GetDroppedFrames() const
111 : {
112 : ReentrantMonitorAutoEnter mon(mReentrantMonitor);
113 : return mFrameStatisticsData.mDroppedFrames;
114 : }
115 :
116 : // Increments the parsed and decoded frame counters by the passed in counts.
117 : // Can be called on any thread.
118 0 : void NotifyDecodedFrames(const FrameStatisticsData& aStats)
119 : {
120 0 : ReentrantMonitorAutoEnter mon(mReentrantMonitor);
121 0 : mFrameStatisticsData.Accumulate(aStats);
122 0 : }
123 :
124 : // Increments the presented frame counters.
125 : // Can be called on any thread.
126 0 : void NotifyPresentedFrame()
127 : {
128 0 : ReentrantMonitorAutoEnter mon(mReentrantMonitor);
129 0 : ++mFrameStatisticsData.mPresentedFrames;
130 0 : }
131 :
132 : private:
133 0 : ~FrameStatistics() {}
134 :
135 : // ReentrantMonitor to protect access of playback statistics.
136 : mutable ReentrantMonitor mReentrantMonitor;
137 :
138 : FrameStatisticsData mFrameStatisticsData;
139 : };
140 :
141 : } // namespace mozilla
142 :
143 : #endif // FrameStatistics_h_
|