Skip to content

Commit 72a2075

Browse files
committed
Add requestVideoFrameCallback polyfill
1 parent 022dece commit 72a2075

3 files changed

Lines changed: 42 additions & 2 deletions

File tree

static/js/rvfc-polyfill.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// From https://github.com/ThaUnknown/rvfc-polyfill
2+
// Released under GNU General Public License v3.0
3+
4+
if (typeof HTMLVideoElement !== 'undefined' && !('requestVideoFrameCallback' in HTMLVideoElement.prototype) && 'getVideoPlaybackQuality' in HTMLVideoElement.prototype) {
5+
HTMLVideoElement.prototype._rvfcpolyfillmap = {}
6+
HTMLVideoElement.prototype.requestVideoFrameCallback = function (callback) {
7+
const handle = performance.now()
8+
const quality = this.getVideoPlaybackQuality()
9+
const baseline = this.mozPresentedFrames || this.mozPaintedFrames || quality.totalVideoFrames - quality.droppedVideoFrames
10+
11+
const check = (old, now) => {
12+
const newquality = this.getVideoPlaybackQuality()
13+
const presentedFrames = this.mozPresentedFrames || this.mozPaintedFrames || newquality.totalVideoFrames - newquality.droppedVideoFrames
14+
if (presentedFrames > baseline) {
15+
const processingDuration = this.mozFrameDelay || (newquality.totalFrameDelay - quality.totalFrameDelay) || 0
16+
const timediff = now - old // HighRes diff
17+
callback(now, {
18+
presentationTime: now + processingDuration * 1000,
19+
expectedDisplayTime: now + timediff,
20+
width: this.videoWidth,
21+
height: this.videoHeight,
22+
mediaTime: Math.max(0, this.currentTime || 0) + timediff / 1000,
23+
presentedFrames,
24+
processingDuration
25+
})
26+
delete this._rvfcpolyfillmap[handle]
27+
} else {
28+
this._rvfcpolyfillmap[handle] = requestAnimationFrame(newer => check(now, newer))
29+
}
30+
}
31+
this._rvfcpolyfillmap[handle] = requestAnimationFrame(newer => check(handle, newer))
32+
return handle
33+
}
34+
35+
HTMLVideoElement.prototype.cancelVideoFrameCallback = function (handle) {
36+
cancelAnimationFrame(this._rvfcpolyfillmap[handle])
37+
delete this._rvfcpolyfillmap[handle]
38+
}
39+
}

static/js/videolog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ function send_to_renderer(){
274274
setTimeout(function() {document.getElementById("talkid").classList.add('invalid')}, 100)
275275
valid = false
276276
}
277-
277+
278278
if (valid) {
279279
// All good - send video for processing!
280280
var xhttp = new XMLHttpRequest();

templates/log.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{% include 'head.html' %}
22
<script src="{{url_for('static', filename='js/videolog.js')}}"></script>
3+
<script src="{{url_for('static', filename='js/rvfc-polyfill.js')}}"></script>
34
<link rel="stylesheet" href="{{url_for('static', filename='css/log.css')}}">
45
</head>
56
<body>
@@ -75,7 +76,7 @@
7576
<!--<input type="submit" value="Send to Renderer"/>-->
7677
<button type="button" onclick="get_shuttle()">Connect to Shuttle controller</button><br/>
7778
</div>
78-
79+
7980
</div>
8081
</div>
8182
</form>

0 commit comments

Comments
 (0)