Index: media/base/android/media_statistics.cc |
diff --git a/media/base/android/media_statistics.cc b/media/base/android/media_statistics.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e5b637e5d77ab162eadf0c8a83b745c7ee04faa9 |
--- /dev/null |
+++ b/media/base/android/media_statistics.cc |
@@ -0,0 +1,115 @@ |
+// 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. |
+ |
+#include "media/base/android/media_statistics.h" |
+ |
+#include "base/logging.h" |
+#include "base/metrics/histogram_macros.h" |
+#include "media/base/android/demuxer_stream_player_params.h" |
+ |
+// Limit the value by 9999. Since we multiply |a| by one million before, this |
+// bound means that |a| will never exceed 1%. |
+#define LIMIT_10000(a) std::min(a, 9999U) |
Tima Vaisburd
2015/10/02 00:44:32
The Widevine testing on Shaka player shows up to 7
|
+ |
+namespace media { |
+ |
+namespace { |
xhwang
2015/10/01 21:58:58
nit: no need to have anonymous namespace here. nam
Tima Vaisburd
2015/10/02 00:44:32
Done.
|
+ |
+// Minimum playback interval to report. |
+const int kMinDurationInSeconds = 2; |
+ |
+// Maximum playback interval to report. |
+const int kMaxDurationInSeconds = 3600; |
+ |
+// Number of slots in the histogram for playback interval. |
+const int kNumDurationSlots = 50; |
+ |
+// For easier reading. |
+const int kOneMillion = 1000000; |
+} |
+ |
+MediaStatistics::MediaStatistics() {} |
+ |
+MediaStatistics::~MediaStatistics() {} |
+ |
+void MediaStatistics::Start(base::TimeDelta current_playback_time) { |
+ DVLOG(1) << __FUNCTION__; |
+ |
+ Clear(); |
+ start_time_ = current_playback_time; |
+} |
+ |
+void MediaStatistics::StopAndReport(base::TimeDelta current_playback_time) { |
+ DVLOG(1) << __FUNCTION__; |
+ |
+ if (start_time_ == kNoTimestamp()) |
+ return; // skip if there was no prior Start(). |
+ |
+ base::TimeDelta duration = current_playback_time - start_time_; |
+ |
+ // Reset start time. |
+ start_time_ = kNoTimestamp(); |
+ |
+ if (duration < base::TimeDelta::FromSeconds(kMinDurationInSeconds)) |
+ return; // duration is too short. |
+ |
+ if (duration > base::TimeDelta::FromSeconds(kMaxDurationInSeconds)) |
+ return; // duration is too long. |
+ |
+ Report(duration); |
+} |
+ |
+void MediaStatistics::Clear() { |
+ start_time_ = kNoTimestamp(); |
+ audio_frames_.Clear(); |
+ video_frames_.Clear(); |
+ num_starvations_ = 0; |
+} |
+ |
+void MediaStatistics::Report(base::TimeDelta duration) { |
+ DVLOG(1) << __FUNCTION__ << " duration:" << duration |
+ << " audio frames:" |
+ << audio_frames_.late << "/" << audio_frames_.total |
+ << " video frames:" |
+ << video_frames_.late << "/" << video_frames_.total; |
+ |
+ // Playback duration is the time interval between the moment playback starts |
+ // and the moment it is interrupted either by stopping or by seeking, changing |
+ // to full screen, minimizing the browser etc. The interval is measured by |
+ // media time. |
+ |
+ UMA_HISTOGRAM_CUSTOM_TIMES( |
+ "Media.MSE.PlaybackDuration", duration, |
+ base::TimeDelta::FromSeconds(kMinDurationInSeconds), |
+ base::TimeDelta::FromSeconds(kMaxDurationInSeconds), kNumDurationSlots); |
+ |
+ // Number of late frames per one million frames. |
+ // We expect the ratios of the late frames to the total number of frames to be |
+ // less than 1%, therefore after multiplying by one millon the range should be |
+ // [0, 10000]. |
+ |
+ if (audio_frames_.total) { |
+ UMA_HISTOGRAM_COUNTS_10000( |
+ "Media.MSE.LateAudioFrames", |
+ LIMIT_10000(kOneMillion * audio_frames_.late / audio_frames_.total)); |
+ } |
+ |
+ if (video_frames_.total) { |
+ UMA_HISTOGRAM_COUNTS_10000( |
+ "Media.MSE.LateVideoFrames", |
+ LIMIT_10000(kOneMillion * video_frames_.late / video_frames_.total)); |
+ } |
+ |
+ // Number of starvations per one million frames. |
+ |
+ uint32_t total_frames = |
+ audio_frames_.total ? audio_frames_.total : video_frames_.total; |
+ if (total_frames) { |
+ UMA_HISTOGRAM_COUNTS_10000( |
+ "Media.MSE.Starvations", |
+ LIMIT_10000(kOneMillion * num_starvations_ / total_frames)); |
+ } |
+} |
+ |
+} // namespace media |