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. | |
xhwang
2015/10/01 21:58:58
How about late frames, as described in l.24.
Tima Vaisburd
2015/10/02 00:44:32
Late frames are also rendered. I'm not sure I got
| |
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 // Adds a frame to |total|. | |
34 void AddFrame() { ++total; } | |
xhwang
2015/10/01 21:58:58
To be accurate, all Add*() functions should really
Tima Vaisburd
2015/10/02 00:44:32
Renamed to IncrementFrameCount() and IncrementLate
| |
35 | |
36 // Adds a frame to |late|. For each AddLateFrame() call there should be | |
37 // preceding AddFrame() call. | |
38 void AddLateFrame(base::TimeDelta /* delay */) { ++late; } | |
xhwang
2015/10/01 21:58:58
Why do you still pass in |delay| here?
Tima Vaisburd
2015/10/02 00:44:32
Sorry, removed.
| |
39 }; | |
40 | |
41 // MediaStatistics class gathers and reports playback quality statistics to UMA. | |
42 // | |
43 // This class is not thread safe. The caller should guarantee that operations | |
44 // on FrameStatistics objects does not happen during Start() and | |
45 // StopAndReport(). The Start() and StopAndReport() methods need to be called | |
46 // sequantially. | |
47 | |
48 class MediaStatistics { | |
49 public: | |
50 MediaStatistics(); | |
51 ~MediaStatistics(); | |
52 | |
53 // Returns the frame statistics for audio frames. | |
54 FrameStatistics& audio_frames() { return audio_frames_; } | |
xhwang
2015/10/01 21:58:58
I would recommend to be as clear as possible. audi
Tima Vaisburd
2015/10/02 00:44:32
Done.
| |
55 | |
56 // Returns the frame statistics for video frames. | |
57 FrameStatistics& video_frames() { return video_frames_; } | |
58 | |
59 // Starts gathering statistics. Can be called several times in the row, the | |
60 // latest call takes effect. | |
61 void Start(base::TimeDelta current_playback_time); | |
62 | |
63 // Stops gathering statistics, calculate and report results. When called | |
64 // in a row only the firts call will take effect. | |
65 void StopAndReport(base::TimeDelta current_playback_time); | |
66 | |
67 // Adds starvation event. Starvation happens when the player interrupts | |
68 // the regular playback and asks for more data. | |
69 void AddStarvation() { ++num_starvations_; } | |
70 | |
71 private: | |
72 // Resets the data to the initial state. | |
73 void Clear(); | |
74 | |
75 // Calculates relative data based on total frame numbers and reports it and | |
76 // the duration to UMA. | |
77 void Report(base::TimeDelta duration); | |
78 | |
79 base::TimeDelta start_time_ = kNoTimestamp(); | |
80 FrameStatistics audio_frames_; | |
81 FrameStatistics video_frames_; | |
82 uint32_t num_starvations_ = 0; | |
83 }; | |
84 | |
85 } // namespace media | |
86 | |
87 #endif // MEDIA_BASE_ANDROID_MEDIA_STATISTICS_H_ | |
OLD | NEW |