Index: media/base/android/media_statistics.h |
diff --git a/media/base/android/media_statistics.h b/media/base/android/media_statistics.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6d60babf6fcaac3565755e08ed8017eec12e93e4 |
--- /dev/null |
+++ b/media/base/android/media_statistics.h |
@@ -0,0 +1,86 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef MEDIA_BASE_ANDROID_MEDIA_STATISTICS_H_ |
+#define MEDIA_BASE_ANDROID_MEDIA_STATISTICS_H_ |
+ |
+#include <stdint.h> |
+#include "base/time/time.h" |
+#include "media/base/demuxer_stream.h" |
+ |
+namespace media { |
+ |
+// FrameStatistics struct deals with frames of one stream, i.e. either |
+// audio or video. |
+struct FrameStatistics { |
+ // Stream type that this statistics belong to (Audio or Video). |
+ DemuxerStream::Type stream_type; |
+ |
+ // Audio: total number of frame that has been rendered. |
Ilya Sherman
2015/10/01 07:19:20
nit: "has" -> "have"
Tima Vaisburd
2015/10/01 20:05:16
Done.
|
+ // Video: total amount of frames thatwere supposed to be rendered. Late video |
Ilya Sherman
2015/10/01 07:19:20
nit: "thatwere" -> "that were"
Tima Vaisburd
2015/10/01 20:05:16
Done.
|
+ // frames might be skipped, but are counted here. |
+ uint32_t total; |
+ |
+ // A number of late frames. Late frames are a subset of the total frames. |
xhwang
2015/09/30 21:02:58
What's the definition of being late?
Tima Vaisburd
2015/10/01 20:05:15
Copied the text from histogram.xml
|
+ uint32_t late; |
xhwang
2015/09/30 21:02:57
nit: consider using Non-Static Class Member Initia
Tima Vaisburd
2015/10/01 20:05:15
Done.
|
+ |
+ FrameStatistics(DemuxerStream::Type type) |
+ : stream_type(type), total(0), late(0) {} |
+ |
+ void Clear() { total = late = 0; } |
+ |
+ // Adds a frame to |total|. |
+ void AddFrame() { ++total; } |
+ |
+ // Adds a frame to |late|. For each AddLateFrame() call there should be |
+ // preceding AddFrame() call. |
+ void AddLateFrame(base::TimeDelta delay); |
+}; |
+ |
+// MediaStatistics class gathers and reports playback quality statistics to UMA. |
+// |
+// This class is not thread safe. The caller should guarantee that operations |
+// on FrameStatistics objects does not happen during Start() and |
+// StopAndReport(). The Start() and StopAndReport() methods need to be called |
+// sequantially. |
+ |
+class MediaStatistics { |
+ public: |
+ MediaStatistics(); |
+ ~MediaStatistics(); |
+ |
+ // Returns the frame statistics for audio frames. |
+ FrameStatistics& audio_frames() { return audio_frames_; } |
xhwang
2015/09/30 21:02:58
nit: s/audio_frame/audio_frame_statistic
Tima Vaisburd
2015/10/01 20:05:16
The only place in the code it is being called has
|
+ |
+ // Returns the frame statistics for video frames. |
+ FrameStatistics& video_frames() { return video_frames_; } |
xhwang
2015/09/30 21:02:58
ditto
Tima Vaisburd
2015/10/01 20:05:16
See above
|
+ |
+ // Starts gathering statistics. Can be called several times in the row, the |
+ // latest call takes effect. |
+ void Start(base::TimeDelta current_playback_time); |
+ |
+ // Stops gathering statistics, calculate and report results. Can be called |
+ // several times in a row, without a prior Start() this call is ignored. |
+ void StopAndReport(base::TimeDelta current_playback_time); |
xhwang
2015/09/30 21:02:58
When called in a row, will only the first call tak
Tima Vaisburd
2015/10/01 20:05:16
This is what I wanted to say. Changed the comment.
|
+ |
+ // Adds starvation event. |
+ void AddStarvation() { ++num_starvations_; } |
+ |
+ private: |
+ // Resets the data to the initial state. |
+ void Clear(); |
+ |
+ // Calculates relative data based on total frame numbers and reports it and |
+ // the duration to UMA. |
+ void Report(base::TimeDelta duration); |
+ |
+ base::TimeDelta start_time_; |
+ FrameStatistics audio_frames_; |
+ FrameStatistics video_frames_; |
+ uint32_t num_starvations_; |
+}; |
+ |
+} // namespace media |
+ |
+#endif // MEDIA_BASE_ANDROID_MEDIA_STATISTICS_H_ |