Chromium Code Reviews| 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..f2eea40007d53963a36dee72c6979ba6db52a7e3 |
| --- /dev/null |
| +++ b/media/base/android/media_statistics.cc |
| @@ -0,0 +1,111 @@ |
| +#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.
|
| + |
| +#include "base/logging.h" |
| +#include "base/metrics/histogram_macros.h" |
| +#include "media/base/android/demuxer_stream_player_params.h" |
| +#include "media/base/timestamp_constants.h" |
| + |
| +namespace media { |
| + |
| +namespace { |
| + |
| +// Minimum duration to report. |
| +const int kMinDurationInSeconds = 2; |
| + |
| +// Maximum duration to report. |
| +const int kMaxDurationInSeconds = 3600; |
| + |
| +// Number of slots in the histogram for duration. |
| +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.
|
| + |
| +} |
| + |
| +void FrameStatistics::AddLateFrame(base::TimeDelta delay) { |
| + // Do not collect the late frame if this is the first frame after start. |
| + // This simplifies the MediaSourcePlayer case. |
| + if (total == 1) |
| + return; |
| + |
| + DVLOG(1) << stream_type << " " << __FUNCTION__ << " delay:" << delay |
| + << " 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
|
| + ++late; |
| +} |
| + |
| +MediaStatistics::MediaStatistics() |
| + : start_time_(kNoTimestamp()), |
| + audio_frames_(DemuxerStream::AUDIO), |
| + video_frames_(DemuxerStream::VIDEO), |
| + 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.
|
| +} |
| + |
| +MediaStatistics::~MediaStatistics() {} |
| + |
| +void MediaStatistics::Start(base::TimeDelta current_playback_time) { |
| + DVLOG(1) << "MediaStatistics::" << __FUNCTION__; |
| + |
| + Clear(); |
| + start_time_ = current_playback_time; |
| +} |
| + |
| +void MediaStatistics::StopAndReport(base::TimeDelta current_playback_time) { |
| + DVLOG(1) << "MediaStatistics::" << __FUNCTION__; |
| + |
| + if (start_time_ == kNoTimestamp()) |
| + 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
|
| + |
| + 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) << "MediaStatistics::" << __FUNCTION__ << " duration:" << duration |
| + << " audio frames:" |
| + << audio_frames_.late << "/" << audio_frames_.total |
| + << " video frames:" |
| + << video_frames_.late << "/" << video_frames_.total; |
| + |
| + UMA_HISTOGRAM_CUSTOM_TIMES( |
| + "Media.MSE.Duration", duration, |
| + base::TimeDelta::FromSeconds(kMinDurationInSeconds), |
| + base::TimeDelta::FromSeconds(kMaxDurationInSeconds), kNumDurationSlots); |
| + |
| + // Number of late frames per one million frames. |
| + |
| + if (audio_frames_.total) { |
| + UMA_HISTOGRAM_COUNTS("Media.MSE.LateAudioFrames", |
| + 1000000 * audio_frames_.late / audio_frames_.total); |
| + } |
| + |
| + if (video_frames_.total) { |
| + UMA_HISTOGRAM_COUNTS("Media.MSE.LateVideoFrames", |
| + 1000000 * 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("Media.MSE.Starvations", |
| + 1000000 * num_starvations_ / total_frames); |
| + } |
| +} |
| + |
| +} // namespace media |