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+ }
0 commit comments