Chromium Code Reviews| 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 #include "media/base/android/media_statistics.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/metrics/histogram_macros.h" | |
| 9 #include "media/base/android/demuxer_stream_player_params.h" | |
| 10 | |
| 11 namespace media { | |
| 12 | |
| 13 // Minimum playback interval to report. | |
| 14 const int kMinDurationInSeconds = 2; | |
| 15 | |
| 16 // Maximum playback interval to report. | |
| 17 const int kMaxDurationInSeconds = 3600; | |
| 18 | |
| 19 // Number of slots in the histogram for playback interval. | |
| 20 const int kNumDurationSlots = 50; | |
| 21 | |
| 22 // For easier reading. | |
| 23 const int kOneMillion = 1000000; | |
| 24 | |
| 25 void FrameStatistics::IncrementLateFrameCount() { | |
| 26 // Do not collect the late frame if this is the first frame after the start. | |
| 27 // Right now we do not want to consider the late video frame which is the | |
| 28 // first after preroll, preroll may be inacurate in this respect. | |
| 29 // The first audio frame cannot be late by definition and by not considering | |
| 30 // it we can simplify audio decoder code. | |
| 31 if (total == 1) | |
| 32 return; | |
| 33 | |
| 34 ++late; | |
| 35 } | |
| 36 | |
| 37 MediaStatistics::MediaStatistics() {} | |
| 38 | |
| 39 MediaStatistics::~MediaStatistics() {} | |
| 40 | |
| 41 void MediaStatistics::Start(base::TimeDelta current_playback_time) { | |
| 42 DVLOG(1) << __FUNCTION__; | |
| 43 | |
| 44 if (start_time_ == kNoTimestamp) { | |
| 45 Clear(); | |
| 46 start_time_ = current_playback_time; | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 void MediaStatistics::StopAndReport(base::TimeDelta current_playback_time) { | |
| 51 DVLOG(1) << __FUNCTION__; | |
| 52 | |
| 53 if (start_time_ == kNoTimestamp) | |
| 54 return; // skip if there was no prior Start(). | |
| 55 | |
| 56 if (current_playback_time == kNoTimestamp) { | |
| 57 // Cancel the start event and skip if current time is unknown. | |
| 58 start_time_ = kNoTimestamp; | |
| 59 return; | |
| 60 } | |
| 61 | |
| 62 base::TimeDelta duration = current_playback_time - start_time_; | |
| 63 | |
| 64 // Reset start time. | |
| 65 start_time_ = kNoTimestamp; | |
| 66 | |
| 67 if (duration < base::TimeDelta::FromSeconds(kMinDurationInSeconds)) | |
| 68 return; // duration is too short. | |
| 69 | |
| 70 if (duration > base::TimeDelta::FromSeconds(kMaxDurationInSeconds)) | |
| 71 return; // duration is too long. | |
| 72 | |
| 73 Report(duration); | |
| 74 } | |
| 75 | |
| 76 void MediaStatistics::Clear() { | |
| 77 start_time_ = kNoTimestamp; | |
| 78 audio_frame_stats_.Clear(); | |
| 79 video_frame_stats_.Clear(); | |
| 80 num_starvations_ = 0; | |
| 81 } | |
| 82 | |
| 83 void MediaStatistics::Report(base::TimeDelta duration) { | |
| 84 DVLOG(1) << __FUNCTION__ << " duration:" << duration | |
| 85 << " audio frames:" | |
| 86 << audio_frame_stats_.late << "/" << audio_frame_stats_.total | |
| 87 << " video frames:" | |
| 88 << video_frame_stats_.late << "/" << video_frame_stats_.total | |
| 89 << " starvations:" << num_starvations_; | |
| 90 | |
| 91 // Playback duration is the time interval between the moment playback starts | |
| 92 // and the moment it is interrupted either by stopping or by seeking, changing | |
| 93 // to full screen, minimizing the browser etc. The interval is measured by | |
| 94 // media time. | |
| 95 | |
| 96 UMA_HISTOGRAM_CUSTOM_TIMES( | |
| 97 "Media.MSE.PlaybackDuration", duration, | |
|
wolenetz
2016/09/30 23:23:23
Deprecate this in histograms.xml?
DaleCurtis
2016/09/30 23:34:24
Done.
| |
| 98 base::TimeDelta::FromSeconds(kMinDurationInSeconds), | |
| 99 base::TimeDelta::FromSeconds(kMaxDurationInSeconds), kNumDurationSlots); | |
| 100 | |
| 101 // Number of late frames per one million frames. | |
| 102 | |
| 103 if (audio_frame_stats_.total) { | |
| 104 UMA_HISTOGRAM_COUNTS( | |
| 105 "Media.MSE.LateAudioFrames", | |
|
wolenetz
2016/09/30 23:23:23
ditto
DaleCurtis
2016/09/30 23:34:24
Done.
| |
| 106 kOneMillion * audio_frame_stats_.late / audio_frame_stats_.total); | |
| 107 } | |
| 108 | |
| 109 if (video_frame_stats_.total) { | |
| 110 UMA_HISTOGRAM_COUNTS( | |
| 111 "Media.MSE.LateVideoFrames", | |
|
wolenetz
2016/09/30 23:23:23
ditto
DaleCurtis
2016/09/30 23:34:24
Done.
| |
| 112 kOneMillion * video_frame_stats_.late / video_frame_stats_.total); | |
| 113 } | |
| 114 | |
| 115 // Number of starvations per one million frames. | |
| 116 | |
| 117 uint32_t total_frames = audio_frame_stats_.total ? audio_frame_stats_.total | |
| 118 : video_frame_stats_.total; | |
| 119 if (total_frames) { | |
| 120 UMA_HISTOGRAM_COUNTS("Media.MSE.Starvations", | |
|
wolenetz
2016/09/30 23:23:23
ditto
DaleCurtis
2016/09/30 23:34:24
Done.
| |
| 121 kOneMillion * num_starvations_ / total_frames); | |
| 122 } | |
| 123 } | |
| 124 | |
| 125 } // namespace media | |
| OLD | NEW |