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..6b0b1933379cf037deab391a9cbcdf554bec7a7f |
--- /dev/null |
+++ b/media/base/android/media_statistics.h |
@@ -0,0 +1,87 @@ |
+// 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" |
+#include "media/base/timestamp_constants.h" |
+ |
+namespace media { |
+ |
+// FrameStatistics struct deals with frames of one stream, i.e. either |
+// audio or video. |
+struct FrameStatistics { |
+ // 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
|
+ // Video: total number of frames that were supposed to be rendered. Late video |
+ // frames might be skipped, but are counted here. |
+ uint32_t total = 0; |
+ |
+ // A number of late frames. Late frames are a subset of the total frames. |
+ // Audio: The frame is late if it might cause an underrun, i.e. comes from |
+ // decoder when audio buffer is already depleted. |
+ // Video: The frame is late if it missed its presentation time as determined |
+ // by PTS when it comes from decoder. The rendering policy (i.e. |
+ // render or skip) does not affect this number. |
+ uint32_t late = 0; |
+ |
+ void Clear() { total = late = 0; } |
+ |
+ // Adds a frame to |total|. |
+ 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
|
+ |
+ // Adds a frame to |late|. For each AddLateFrame() call there should be |
+ // preceding AddFrame() call. |
+ 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.
|
+}; |
+ |
+// 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/10/01 21:58:58
I would recommend to be as clear as possible. audi
Tima Vaisburd
2015/10/02 00:44:32
Done.
|
+ |
+ // Returns the frame statistics for video frames. |
+ FrameStatistics& video_frames() { return video_frames_; } |
+ |
+ // 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. When called |
+ // in a row only the firts call will take effect. |
+ void StopAndReport(base::TimeDelta current_playback_time); |
+ |
+ // Adds starvation event. Starvation happens when the player interrupts |
+ // the regular playback and asks for more data. |
+ 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_ = kNoTimestamp(); |
+ FrameStatistics audio_frames_; |
+ FrameStatistics video_frames_; |
+ uint32_t num_starvations_ = 0; |
+}; |
+ |
+} // namespace media |
+ |
+#endif // MEDIA_BASE_ANDROID_MEDIA_STATISTICS_H_ |