File: getdisplaymedia-framerate.https.html

package info (click to toggle)
firefox 145.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,653,344 kB
  • sloc: cpp: 7,594,932; javascript: 6,459,612; ansic: 3,752,905; python: 1,403,433; xml: 629,811; asm: 438,677; java: 186,421; sh: 67,287; makefile: 19,169; objc: 13,086; perl: 12,982; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (42 lines) | stat: -rw-r--r-- 1,647 bytes parent folder | download | duplicates (17)
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
<!doctype html>
<meta charset=utf-8>
<title>getDisplayMedia</title>
<meta name="timeout" content="long">
<button id="button">User gesture</button>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<video id="display"></video>
<script>
  'use strict';

const stopTracks = stream => stream.getTracks().forEach(track => track.stop());

async function getDisplayMedia(constraints) {
  const p = new Promise(r => button.onclick = r);
  await test_driver.click(button);
  await p;
  return navigator.mediaDevices.getDisplayMedia(constraints);
}

promise_test( async t => {
  const v = document.getElementById('display');
  v.autoplay = true;
  // work around firefox bug 1586505, orthogonal to what's being tested
  const frames = () => v.mozPaintedFrames ?? v.getVideoPlaybackQuality()?.totalVideoFrames;
  const target_rate = 5;
  const stream = await getDisplayMedia({video: {width:160, frameRate: target_rate}});
  t.add_cleanup(() => stopTracks(stream));
  v.srcObject = stream;
  const intitial_time = v.currentTime;
  const initial_frame_count = frames();
  await new Promise(r => t.step_timeout(r, 10000));
  const total_elapsed_frames = frames() - initial_frame_count;
  const total_elapsed_time = v.currentTime - intitial_time;
  const average_fps = total_elapsed_frames / total_elapsed_time;
  assert_greater_than_equal(average_fps, target_rate * 0.50);
  assert_less_than_equal(average_fps, target_rate * 1.75);
}, "getDisplayMedia() must adhere to frameRate if set");

</script>