/work/obj-fuzz/dist/include/FrameStatistics.h
Line | Count | Source (jump to first uncovered line) |
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 | | FrameStatisticsData() = default; |
42 | | FrameStatisticsData(uint64_t aParsed, |
43 | | uint64_t aDecoded, |
44 | | uint64_t aDropped, |
45 | | uint64_t aPresented) |
46 | | : mParsedFrames(aParsed) |
47 | | , mDecodedFrames(aDecoded) |
48 | | , mPresentedFrames(aPresented) |
49 | | , mDroppedFrames(aDropped) |
50 | | { |
51 | | } |
52 | | |
53 | | void |
54 | | Accumulate(const FrameStatisticsData& aStats) |
55 | | { |
56 | | mParsedFrames += aStats.mParsedFrames; |
57 | | mDecodedFrames += aStats.mDecodedFrames; |
58 | | mPresentedFrames += aStats.mPresentedFrames; |
59 | | mDroppedFrames += aStats.mDroppedFrames; |
60 | | mInterKeyframeSum_us += aStats.mInterKeyframeSum_us; |
61 | | mInterKeyframeCount += aStats.mInterKeyframeCount; |
62 | | // It doesn't make sense to add max numbers, instead keep the bigger one. |
63 | | if (mInterKeyFrameMax_us < aStats.mInterKeyFrameMax_us) { |
64 | | mInterKeyFrameMax_us = aStats.mInterKeyFrameMax_us; |
65 | | } |
66 | | } |
67 | | }; |
68 | | |
69 | | // Frame decoding/painting related performance counters. |
70 | | // Threadsafe. |
71 | | class FrameStatistics |
72 | | { |
73 | | public: |
74 | | NS_INLINE_DECL_THREADSAFE_REFCOUNTING(FrameStatistics); |
75 | | |
76 | | FrameStatistics() |
77 | | : mReentrantMonitor("FrameStats") |
78 | | {} |
79 | | |
80 | | // Returns a copy of all frame statistics data. |
81 | | // Can be called on any thread. |
82 | | FrameStatisticsData GetFrameStatisticsData() const |
83 | | { |
84 | | ReentrantMonitorAutoEnter mon(mReentrantMonitor); |
85 | | return mFrameStatisticsData; |
86 | | } |
87 | | |
88 | | // Returns number of frames which have been parsed from the media. |
89 | | // Can be called on any thread. |
90 | | uint64_t GetParsedFrames() const |
91 | | { |
92 | | ReentrantMonitorAutoEnter mon(mReentrantMonitor); |
93 | | return mFrameStatisticsData.mParsedFrames; |
94 | | } |
95 | | |
96 | | // Returns the number of parsed frames which have been decoded. |
97 | | // Can be called on any thread. |
98 | | uint64_t GetDecodedFrames() const |
99 | | { |
100 | | ReentrantMonitorAutoEnter mon(mReentrantMonitor); |
101 | | return mFrameStatisticsData.mDecodedFrames; |
102 | | } |
103 | | |
104 | | // Returns the number of decoded frames which have been sent to the rendering |
105 | | // pipeline for painting ("presented"). |
106 | | // Can be called on any thread. |
107 | | uint64_t GetPresentedFrames() const |
108 | | { |
109 | | ReentrantMonitorAutoEnter mon(mReentrantMonitor); |
110 | | return mFrameStatisticsData.mPresentedFrames; |
111 | | } |
112 | | |
113 | | // Returns the number of frames that have been skipped because they have |
114 | | // missed their composition deadline. |
115 | | uint64_t GetDroppedFrames() const |
116 | | { |
117 | | ReentrantMonitorAutoEnter mon(mReentrantMonitor); |
118 | | return mFrameStatisticsData.mDroppedFrames; |
119 | | } |
120 | | |
121 | | // Increments the parsed and decoded frame counters by the passed in counts. |
122 | | // Can be called on any thread. |
123 | | void Accumulate(const FrameStatisticsData& aStats) |
124 | | { |
125 | | ReentrantMonitorAutoEnter mon(mReentrantMonitor); |
126 | | mFrameStatisticsData.Accumulate(aStats); |
127 | | } |
128 | | |
129 | | // Increments the presented frame counters. |
130 | | // Can be called on any thread. |
131 | | void NotifyPresentedFrame() |
132 | 0 | { |
133 | 0 | ReentrantMonitorAutoEnter mon(mReentrantMonitor); |
134 | 0 | ++mFrameStatisticsData.mPresentedFrames; |
135 | 0 | } |
136 | | |
137 | | // Stack based class to assist in notifying the frame statistics of |
138 | | // parsed and decoded frames. Use inside video demux & decode functions |
139 | | // to ensure all parsed and decoded frames are reported on all return paths. |
140 | | class AutoNotifyDecoded |
141 | | { |
142 | | public: |
143 | | explicit AutoNotifyDecoded(FrameStatistics* aFrameStats) |
144 | | : mFrameStats(aFrameStats) |
145 | | { |
146 | | } |
147 | | ~AutoNotifyDecoded() |
148 | | { |
149 | | if (mFrameStats) { |
150 | | mFrameStats->Accumulate(mStats); |
151 | | } |
152 | | } |
153 | | |
154 | | FrameStatisticsData mStats; |
155 | | |
156 | | private: |
157 | | FrameStatistics* mFrameStats; |
158 | | }; |
159 | | |
160 | | private: |
161 | | ~FrameStatistics() {} |
162 | | |
163 | | // ReentrantMonitor to protect access of playback statistics. |
164 | | mutable ReentrantMonitor mReentrantMonitor; |
165 | | |
166 | | FrameStatisticsData mFrameStatisticsData; |
167 | | }; |
168 | | |
169 | | } // namespace mozilla |
170 | | |
171 | | #endif // FrameStatistics_h_ |