summaryrefslogtreecommitdiffstats
path: root/testing/talos/talos/tests/video/video_playback.html
blob: 99bec7c6c1f12c6d80c89d45431bbf5acd708b46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<!-- This Source Code Form is subject to the terms of the Mozilla Public
   - License, v. 2.0. If a copy of the MPL was not distributed with this file,
   - You can obtain one at http://mozilla.org/MPL/2.0/.  -->
<html>
<head>
<script src="resource://talos-powers/TalosPowersContent.js"></script>
<script src="resource://talos-powers/TalosContentProfiler.js"></script>
<script language="javascript" type="text/javascript">
const MEASUREMENT1_MS = 3000;
const MEASUREMENT2_MS = 2000;
const PLAYBACK_RATE = 5;
var vdo;
var start1 = 0;
var paintedFramesStart1 = 0;
var start2 = 0;
var paintedFramesStart2 = 0;
var testIndex = 0;
var test = [
  "testsrc.240p.120fps.mp4",
  "testsrc.480p.60fps.webm",
  "testsrc.1080p.60fps.mp4",
];
var viewModeIndex = 0;
// Remove fullscreen mode since it causes intermittent failures on try server. See bug 1192317.
var viewMode = [1, 1.1, 2];
var testResult = {names: [], values: []};

/* globals readyToStart:true */

function init() {
  TalosPowersContent.focus(content_focused);
}

function content_focused() {
  vdo = document.getElementById("vdo");
  vdo.addEventListener("loadeddata", prepare);
  document.addEventListener("fullscreenchange", fullscreen);
  document.addEventListener("mozfullscreenchange", fullscreen);
  runTest();
}

function fullscreen(event) {
  if ((document.fullscreenElement && document.fullscreenElement !== null) ||
      document.mozFullScreen) {
    startTest();
  } else {
    nextTest();
  }
}

function runTest() {
  // Windows XP cannot play mp4 clip due to the lack of gmp-eme-plugin, so skip it.
  if (window.navigator.oscpu == "Windows NT 5.1" && test[testIndex].includes("mp4")) {
    nextTest();
  }
  vdo.setAttribute("src", "clips/" + test[testIndex]);
  vdo.load();
}

function prepare() {
  if (viewMode[viewModeIndex] == "fullscreen") {
    // Fullscreen mode
    vdo.setAttribute("width", "100%");
    vdo.setAttribute("height", "100%");
    if (document.body.requestFullscreen) {
      document.body.requestFullscreen();
    } else if (document.body.mozRequestFullScreen) {
      document.body.mozRequestFullScreen();
    }
  } else {
    readyToStart = true;
    vdo.setAttribute("width", vdo.videoWidth * viewMode[viewModeIndex]);
    vdo.setAttribute("height", vdo.videoHeight * viewMode[viewModeIndex]);
    startTest();
  }
}

function startTest() {
  TalosContentProfiler.subtestStart("start test " + test[testIndex], true).then(() => {
    vdo.playbackRate = PLAYBACK_RATE;
    start1 = performance.now();
    paintedFramesStart1 = vdo.mozPaintedFrames;
    vdo.play();
    setTimeout(function() {
      start2 = performance.now();
      paintedFramesStart2 = vdo.mozPaintedFrames;
      setTimeout(measurementEnded, MEASUREMENT2_MS);
    }, MEASUREMENT1_MS);
  });
}

function measurementEnded() {
  vdo.pause();
  var end = performance.now();
  var paintedFramesEnd = vdo.mozPaintedFrames;
  var timePerFrame1 = (start2 - start1) / (paintedFramesStart2 - paintedFramesStart1);
  var timePerFrame2 = (end - start2) / (paintedFramesEnd - paintedFramesStart2);
  testResult.names.push(test[testIndex] + "_scale_" + viewMode[viewModeIndex] + "_startup");
  testResult.values.push(timePerFrame1);
  testResult.names.push(test[testIndex] + "_scale_" + viewMode[viewModeIndex] + "_inclip");
  testResult.values.push(timePerFrame2);

  TalosContentProfiler.subtestEnd("Test " + test[testIndex], true).then(() => {
    if (viewMode[viewModeIndex] == "fullscreen") {
      // Exit fullscreen mode
      if (document.exitFullscreen) {
        document.exitFullscreen();
      } else if (document.mozCancelFullScreen) {
        document.mozCancelFullScreen();
      }
    } else {
      nextTest();
    }
  });
}

function nextTest() {
  viewModeIndex++;
  if (viewModeIndex >= viewMode.length) {
    viewModeIndex = 0;
    testIndex++;
  }
  if (testIndex >= test.length) {
    // End the test
    reportResult();
  } else {
    runTest();
  }
}

function reportResult() {
  var msg = "";
  for (var i = 0; i < testResult.names.length; i++) {
    msg += testResult.names[i] + " = " + testResult.values[i] + " ms/frame\n\n";
  }

  dump(msg); // Put the readable report at talos run-log

  if (window.tpRecordTime) {
    // Within talos - report the results
    return tpRecordTime(testResult.values.join(","), 0, testResult.names.join(","));
  }
    // Local run in a plain browser, display the formatted report
    alert(msg);

  return undefined;
}
</script>

</head>
<body id="body" onload="init();">
<video id="vdo" width="100%" height="100%">
</video>
</body>
</html>