summaryrefslogtreecommitdiffstats
path: root/media/test/data/eme_player_js/fps_observer.js
diff options
context:
space:
mode:
authorshadi@chromium.org <shadi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-12 04:47:40 +0000
committershadi@chromium.org <shadi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-12 04:47:40 +0000
commit073a22b657722868df4069d680646b7481ff9802 (patch)
treecaca993eb5a4c569624e0f9ae5722c8cbc5e7759 /media/test/data/eme_player_js/fps_observer.js
parent2ca7594cad9b497998b2b5102be086e51dc00d08 (diff)
downloadchromium_src-073a22b657722868df4069d680646b7481ff9802.zip
chromium_src-073a22b657722868df4069d680646b7481ff9802.tar.gz
chromium_src-073a22b657722868df4069d680646b7481ff9802.tar.bz2
Have media content and chrome browser tests load data from media/test/data
With media files copied over to media/test/data, this CL makes media related content browser tests and chrome browser tests load test data from one location. The location is common with media unit tests data forder; managed in one place in media/base/test_data_util.h BUG=379314 Review URL: https://codereview.chromium.org/357413002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282795 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/test/data/eme_player_js/fps_observer.js')
-rw-r--r--media/test/data/eme_player_js/fps_observer.js67
1 files changed, 67 insertions, 0 deletions
diff --git a/media/test/data/eme_player_js/fps_observer.js b/media/test/data/eme_player_js/fps_observer.js
new file mode 100644
index 0000000..8226df8
--- /dev/null
+++ b/media/test/data/eme_player_js/fps_observer.js
@@ -0,0 +1,67 @@
+// Copyright 2014 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.
+
+// FPSObserver observes a <video> and reports decoded FPS, dropped FPS, and
+// total dropped frames during the video playback.
+var FPSObserver = new function() {
+ this.video_ = null;
+ this.decodedFrames_ = 0;
+ this.droppedFrames_ = 0;
+ this.startTime_ = 0;
+ this.intID_ = null;
+}
+
+FPSObserver.observe = function(video) {
+ this.video_ = video;
+ var observer = this;
+ this.video_.addEventListener('playing', function() {
+ observer.onVideoPlaying();
+ });
+
+ this.video_.addEventListener('error', function() {
+ observer.endTest();
+ });
+
+ this.video_.addEventListener('ended', function() {
+ observer.endTest();
+ });
+};
+
+FPSObserver.onVideoPlaying = function() {
+ this.decodedFrames_ = 0;
+ this.droppedFrames_ = 0;
+ this.startTime_ = window.performance.now();
+ this.endTest(true);
+ var observer = this;
+ this.intID_ = window.setInterval(function() {
+ observer.calculateStats();}, 1000);
+};
+
+FPSObserver.calculateStats = function() {
+ if (this.video_.readyState <= HTMLMediaElement.HAVE_CURRENT_DATA ||
+ this.video_.paused || this.video_.ended)
+ return;
+ var currentTime = window.performance.now();
+ var deltaTime = (currentTime - this.startTime_) / 1000;
+ this.startTime_ = currentTime;
+
+ // Calculate decoded frames per sec.
+ var fps = (this.video_.webkitDecodedFrameCount - this.decodedFrames_) /
+ deltaTime;
+ this.decodedFrames_ = this.video_.webkitDecodedFrameCount;
+ fps = fps.toFixed(2);
+ decodedFPSElement.innerHTML = fps;
+
+ // Calculate dropped frames per sec.
+ fps = (this.video_.webkitDroppedFrameCount - this.droppedFrames_) / deltaTime;
+ this.droppedFrames_ = this.video_.webkitDroppedFrameCount;
+ fps = fps.toFixed(2);
+ droppedFPSElement.innerHTML = fps;
+
+ droppedFramesElement.innerHTML = this.droppedFrames_;
+};
+
+FPSObserver.endTest = function() {
+ window.clearInterval(this.intID_);
+};