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) | |
|
Tima Vaisburd
2015/10/02 00:44:32
I accidently deleted this check in the prior PS, r
| |
| 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()) { | |
|
Tima Vaisburd
2015/10/02 00:44:32
I changed the Start() semantic to follow StopAndRe
| |
| 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 base::TimeDelta duration = current_playback_time - start_time_; | |
| 57 | |
| 58 // Reset start time. | |
| 59 start_time_ = kNoTimestamp(); | |
| 60 | |
| 61 if (duration < base::TimeDelta::FromSeconds(kMinDurationInSeconds)) | |
| 62 return; // duration is too short. | |
| 63 | |
| 64 if (duration > base::TimeDelta::FromSeconds(kMaxDurationInSeconds)) | |
| 65 return; // duration is too long. | |
| 66 | |
| 67 Report(duration); | |
| 68 } | |
| 69 | |
| 70 void MediaStatistics::Clear() { | |
| 71 start_time_ = kNoTimestamp(); | |
| 72 audio_frame_stats_.Clear(); | |
| 73 video_frame_stats_.Clear(); | |
| 74 num_starvations_ = 0; | |
| 75 } | |
| 76 | |
| 77 void MediaStatistics::Report(base::TimeDelta duration) { | |
| 78 DVLOG(1) << __FUNCTION__ << " duration:" << duration | |
| 79 << " audio frames:" | |
| 80 << audio_frame_stats_.late << "/" << audio_frame_stats_.total | |
| 81 << " video frames:" | |
| 82 << video_frame_stats_.late << "/" << video_frame_stats_.total | |
| 83 << " starvations:" << num_starvations_; | |
| 84 | |
| 85 // Playback duration is the time interval between the moment playback starts | |
| 86 // and the moment it is interrupted either by stopping or by seeking, changing | |
| 87 // to full screen, minimizing the browser etc. The interval is measured by | |
| 88 // media time. | |
| 89 | |
| 90 UMA_HISTOGRAM_CUSTOM_TIMES( | |
| 91 "Media.MSE.PlaybackDuration", duration, | |
| 92 base::TimeDelta::FromSeconds(kMinDurationInSeconds), | |
| 93 base::TimeDelta::FromSeconds(kMaxDurationInSeconds), kNumDurationSlots); | |
| 94 | |
| 95 // Number of late frames per one million frames. | |
| 96 // We expect the ratios of the late frames to the total number of frames to be | |
| 97 // less than 1%, therefore after multiplying by one millon the range should be | |
| 98 // [0, 10000]. | |
| 99 | |
| 100 if (audio_frame_stats_.total) { | |
| 101 UMA_HISTOGRAM_COUNTS( | |
| 102 "Media.MSE.LateAudioFrames", | |
| 103 kOneMillion * audio_frame_stats_.late / audio_frame_stats_.total); | |
| 104 } | |
| 105 | |
| 106 if (video_frame_stats_.total) { | |
| 107 UMA_HISTOGRAM_COUNTS( | |
| 108 "Media.MSE.LateVideoFrames", | |
| 109 kOneMillion * video_frame_stats_.late / video_frame_stats_.total); | |
| 110 } | |
| 111 | |
| 112 // Number of starvations per one million frames. | |
| 113 | |
| 114 uint32_t total_frames = audio_frame_stats_.total ? audio_frame_stats_.total | |
| 115 : video_frame_stats_.total; | |
| 116 if (total_frames) { | |
| 117 UMA_HISTOGRAM_COUNTS("Media.MSE.Starvations", | |
| 118 kOneMillion * num_starvations_ / total_frames); | |
| 119 } | |
| 120 } | |
| 121 | |
| 122 } // namespace media | |
| OLD | NEW |