| Index: tools/perf/perf_tools/media_metrics.js
|
| diff --git a/tools/perf/perf_tools/media_metrics.js b/tools/perf/perf_tools/media_metrics.js
|
| index 8b0938b76faf351fc0876805471115c188afa53c..0bbec913e8de77911c91a0c407386bad8d9bdaf7 100644
|
| --- a/tools/perf/perf_tools/media_metrics.js
|
| +++ b/tools/perf/perf_tools/media_metrics.js
|
| @@ -1,4 +1,4 @@
|
| -// Copyright 2013 The Chromium Authors. All rights reserved.
|
| +// Copyright (c) 2013 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.
|
|
|
| @@ -13,10 +13,6 @@
|
| this.metrics = {};
|
| this.id = '';
|
| this.element = element;
|
| - // Listen to when a Telemetry 'Play' action gets called.
|
| - // TODO(shadi): Add event listeners for other media actions here.
|
| - if (this.element)
|
| - this.element.addEventListener('willPlay', this.onWillPlay, false);
|
| }
|
|
|
| MediaMetricBase.prototype.getMetrics = function() {
|
| @@ -30,10 +26,6 @@
|
| };
|
| };
|
|
|
| - MediaMetricBase.prototype.onWillPlay = function() {
|
| - this.playbackTimer = new Timer();
|
| - };
|
| -
|
| function HTMLMediaMetric(element) {
|
| MediaMetricBase.prototype.constructor.call(this, element);
|
| // Set the basic event handlers for HTML5 media element.
|
| @@ -54,10 +46,19 @@
|
| metric.onEnded(e);
|
| });
|
| this.setID();
|
| +
|
| + // Listen to when a Telemetry actions gets called.
|
| + this.element.addEventListener('willPlay', function (e) {
|
| + metric.onWillPlay(e);
|
| + }, false);
|
| + this.element.addEventListener('willSeek', function (e) {
|
| + metric.onWillSeek(e);
|
| + }, false);
|
| }
|
|
|
| HTMLMediaMetric.prototype = new MediaMetricBase();
|
| HTMLMediaMetric.prototype.constructor = HTMLMediaMetric;
|
| +
|
| HTMLMediaMetric.prototype.setID = function() {
|
| if (this.element.src)
|
| this.id = this.element.src.substring(this.element.src.lastIndexOf("/")+1);
|
| @@ -67,16 +68,29 @@
|
| this.id = 'media_' + window.__globalCounter++;
|
| };
|
|
|
| - HTMLMediaMetric.prototype.getMetrics = function() {
|
| - this.metrics['decoded_frame_count'] = this.element.webkitDecodedFrameCount;
|
| - this.metrics['dropped_frame_count'] = this.element.webkitDroppedFrameCount;
|
| - this.metrics['decoded_video_bytes'] =
|
| - this.element.webkitVideoDecodedByteCount;
|
| - this.metrics['decoded_audio_bytes'] =
|
| - this.element.webkitAudioDecodedByteCount;
|
| - return this.metrics;
|
| + HTMLMediaMetric.prototype.onWillPlay = function(e) {
|
| + this.playbackTimer = new Timer();
|
| };
|
|
|
| + HTMLMediaMetric.prototype.onWillSeek = function(e) {
|
| + var seekLabel = '';
|
| + if (e.seekLabel)
|
| + seekLabel = '_' + e.seekLabel;
|
| + var metric = this;
|
| + var onSeeked = function(e) {
|
| + metric.appendMetric('seek' + seekLabel, metric.seekTimer.stop())
|
| + e.target.removeEventListener('seeked', onSeeked);
|
| + };
|
| + this.seekTimer = new Timer();
|
| + this.element.addEventListener('seeked', onSeeked);
|
| + };
|
| +
|
| + HTMLMediaMetric.prototype.appendMetric = function(metric, value) {
|
| + if (!this.metrics[metric])
|
| + this.metrics[metric] = [];
|
| + this.metrics[metric].push(value);
|
| + }
|
| +
|
| HTMLMediaMetric.prototype.onPlaying = function(event) {
|
| // Playing event can fire more than once if seeking.
|
| if (!this.metrics['time_to_play'])
|
| @@ -87,6 +101,16 @@
|
| this.metrics['playback_time'] = this.playbackTimer.stop();
|
| };
|
|
|
| + HTMLMediaMetric.prototype.getMetrics = function() {
|
| + this.metrics['decoded_frame_count'] = this.element.webkitDecodedFrameCount;
|
| + this.metrics['dropped_frame_count'] = this.element.webkitDroppedFrameCount;
|
| + this.metrics['decoded_video_bytes'] =
|
| + this.element.webkitVideoDecodedByteCount;
|
| + this.metrics['decoded_audio_bytes'] =
|
| + this.element.webkitAudioDecodedByteCount;
|
| + return this.metrics;
|
| + };
|
| +
|
| function MediaMetric(element) {
|
| if (element instanceof HTMLMediaElement)
|
| return new HTMLMediaMetric(element);
|
|
|