Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #include "media/base/android/media_statistics.h" | |
|
xhwang
2015/09/30 21:02:57
Add license header
Tima Vaisburd
2015/10/01 20:05:15
Done.
| |
| 2 | |
| 3 #include "base/logging.h" | |
| 4 #include "base/metrics/histogram_macros.h" | |
| 5 #include "media/base/android/demuxer_stream_player_params.h" | |
| 6 #include "media/base/timestamp_constants.h" | |
| 7 | |
| 8 namespace media { | |
| 9 | |
| 10 namespace { | |
| 11 | |
| 12 // Minimum duration to report. | |
| 13 const int kMinDurationInSeconds = 2; | |
| 14 | |
| 15 // Maximum duration to report. | |
| 16 const int kMaxDurationInSeconds = 3600; | |
| 17 | |
| 18 // Number of slots in the histogram for duration. | |
| 19 const int kNumDurationSlots = 60; | |
|
Ilya Sherman
2015/10/01 07:19:20
Please keep in mind that histogram buckets are siz
Tima Vaisburd
2015/10/01 20:05:15
Wow, that's great! Changed to 50.
| |
| 20 | |
| 21 } | |
| 22 | |
| 23 void FrameStatistics::AddLateFrame(base::TimeDelta delay) { | |
| 24 // Do not collect the late frame if this is the first frame after start. | |
| 25 // This simplifies the MediaSourcePlayer case. | |
| 26 if (total == 1) | |
| 27 return; | |
| 28 | |
| 29 DVLOG(1) << stream_type << " " << __FUNCTION__ << " delay:" << delay | |
| 30 << " total:" << total; | |
|
xhwang
2015/09/30 21:02:57
This seems to be the only place to use |stream_typ
Tima Vaisburd
2015/10/01 20:05:15
It would be in 4 places instead of one though: aud
| |
| 31 ++late; | |
| 32 } | |
| 33 | |
| 34 MediaStatistics::MediaStatistics() | |
| 35 : start_time_(kNoTimestamp()), | |
| 36 audio_frames_(DemuxerStream::AUDIO), | |
| 37 video_frames_(DemuxerStream::VIDEO), | |
| 38 num_starvations_(0) { | |
|
xhwang
2015/09/30 21:02:57
nit: consider using Non-Static Class Member Initia
Tima Vaisburd
2015/10/01 20:05:15
Done.
| |
| 39 } | |
| 40 | |
| 41 MediaStatistics::~MediaStatistics() {} | |
| 42 | |
| 43 void MediaStatistics::Start(base::TimeDelta current_playback_time) { | |
| 44 DVLOG(1) << "MediaStatistics::" << __FUNCTION__; | |
| 45 | |
| 46 Clear(); | |
| 47 start_time_ = current_playback_time; | |
| 48 } | |
| 49 | |
| 50 void MediaStatistics::StopAndReport(base::TimeDelta current_playback_time) { | |
| 51 DVLOG(1) << "MediaStatistics::" << __FUNCTION__; | |
| 52 | |
| 53 if (start_time_ == kNoTimestamp()) | |
| 54 return; // skip if there was no prior Start(). | |
|
xhwang
2015/09/30 21:02:57
Should this ever happen?
Tima Vaisburd
2015/10/01 20:05:15
Yes, in MediaCodecPlayer this method is called fro
| |
| 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_frames_.Clear(); | |
| 73 video_frames_.Clear(); | |
| 74 num_starvations_ = 0; | |
| 75 } | |
| 76 | |
| 77 void MediaStatistics::Report(base::TimeDelta duration) { | |
| 78 DVLOG(1) << "MediaStatistics::" << __FUNCTION__ << " duration:" << duration | |
| 79 << " audio frames:" | |
| 80 << audio_frames_.late << "/" << audio_frames_.total | |
| 81 << " video frames:" | |
| 82 << video_frames_.late << "/" << video_frames_.total; | |
| 83 | |
| 84 UMA_HISTOGRAM_CUSTOM_TIMES( | |
| 85 "Media.MSE.Duration", duration, | |
| 86 base::TimeDelta::FromSeconds(kMinDurationInSeconds), | |
| 87 base::TimeDelta::FromSeconds(kMaxDurationInSeconds), kNumDurationSlots); | |
| 88 | |
| 89 // Number of late frames per one million frames. | |
| 90 | |
| 91 if (audio_frames_.total) { | |
| 92 UMA_HISTOGRAM_COUNTS("Media.MSE.LateAudioFrames", | |
| 93 1000000 * audio_frames_.late / audio_frames_.total); | |
| 94 } | |
| 95 | |
| 96 if (video_frames_.total) { | |
| 97 UMA_HISTOGRAM_COUNTS("Media.MSE.LateVideoFrames", | |
| 98 1000000 * video_frames_.late / video_frames_.total); | |
| 99 } | |
| 100 | |
| 101 // Number of starvations per one million frames. | |
| 102 | |
| 103 uint32_t total_frames = | |
| 104 audio_frames_.total ? audio_frames_.total : video_frames_.total; | |
| 105 if (total_frames) { | |
| 106 UMA_HISTOGRAM_COUNTS("Media.MSE.Starvations", | |
| 107 1000000 * num_starvations_ / total_frames); | |
| 108 } | |
| 109 } | |
| 110 | |
| 111 } // namespace media | |
| OLD | NEW |