OLD | NEW |
| (Empty) |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef MEDIA_BASE_ANDROID_MEDIA_STATISTICS_H_ | |
6 #define MEDIA_BASE_ANDROID_MEDIA_STATISTICS_H_ | |
7 | |
8 #include <stdint.h> | |
9 #include "base/time/time.h" | |
10 #include "media/base/demuxer_stream.h" | |
11 #include "media/base/timestamp_constants.h" | |
12 | |
13 namespace media { | |
14 | |
15 // FrameStatistics struct deals with frames of one stream, i.e. either | |
16 // audio or video. | |
17 struct FrameStatistics { | |
18 // Audio: total number of frames that have been rendered. | |
19 // Video: total number of frames that were supposed to be rendered. Late video | |
20 // frames might be skipped, but are counted here. | |
21 uint32_t total = 0; | |
22 | |
23 // A number of late frames. Late frames are a subset of the total frames. | |
24 // Audio: The frame is late if it might cause an underrun, i.e. comes from | |
25 // decoder when audio buffer is already depleted. | |
26 // Video: The frame is late if it missed its presentation time as determined | |
27 // by PTS when it comes from decoder. The rendering policy (i.e. | |
28 // render or skip) does not affect this number. | |
29 uint32_t late = 0; | |
30 | |
31 void Clear() { total = late = 0; } | |
32 | |
33 // Increments |total| frame count. | |
34 void IncrementFrameCount() { ++total; } | |
35 | |
36 // Increments |late| frame count except it is the first frame after start. | |
37 // For each IncrementLateFrameCount() call there should be preceding | |
38 // IncrementFrameCount() call. | |
39 void IncrementLateFrameCount(); | |
40 }; | |
41 | |
42 // MediaStatistics class gathers and reports playback quality statistics to UMA. | |
43 // | |
44 // This class is not thread safe. The caller should guarantee that operations | |
45 // on FrameStatistics objects does not happen during Start() and | |
46 // StopAndReport(). The Start() and StopAndReport() methods need to be called | |
47 // sequentially. | |
48 | |
49 class MediaStatistics { | |
50 public: | |
51 MediaStatistics(); | |
52 ~MediaStatistics(); | |
53 | |
54 // Returns the frame statistics for audio frames. | |
55 FrameStatistics& audio_frame_stats() { return audio_frame_stats_; } | |
56 | |
57 // Returns the frame statistics for video frames. | |
58 FrameStatistics& video_frame_stats() { return video_frame_stats_; } | |
59 | |
60 // Starts gathering statistics. When called in a row only the first call will | |
61 // take effect. | |
62 void Start(base::TimeDelta current_playback_time); | |
63 | |
64 // Stops gathering statistics, calculate and report results. When called | |
65 // in a row only the first call will take effect. | |
66 void StopAndReport(base::TimeDelta current_playback_time); | |
67 | |
68 // Adds starvation event. Starvation happens when the player interrupts | |
69 // the regular playback and asks for more data. | |
70 void AddStarvation() { ++num_starvations_; } | |
71 | |
72 private: | |
73 // Resets the data to the initial state. | |
74 void Clear(); | |
75 | |
76 // Calculates relative data based on total frame numbers and reports it and | |
77 // the duration to UMA. | |
78 void Report(base::TimeDelta duration); | |
79 | |
80 base::TimeDelta start_time_ = kNoTimestamp; | |
81 FrameStatistics audio_frame_stats_; | |
82 FrameStatistics video_frame_stats_; | |
83 uint32_t num_starvations_ = 0; | |
84 }; | |
85 | |
86 } // namespace media | |
87 | |
88 #endif // MEDIA_BASE_ANDROID_MEDIA_STATISTICS_H_ | |
OLD | NEW |