]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/assets/player/p2p-media-loader/hls-plugin.ts
Fast forward on HLS decode error
[github/Chocobozzz/PeerTube.git] / client / src / assets / player / p2p-media-loader / hls-plugin.ts
index 2aa691f05fa05361a4908d5e188908d25d921f4d..ae31bcfe176fc78ece41142170c7c36c9df4843a 100644 (file)
@@ -89,6 +89,8 @@ class Html5Hlsjs {
   private readonly source: videojs.Tech.SourceObject
   private readonly vjs: typeof videojs
 
+  private maxNetworkErrorRecovery = 5
+
   private hls: Hlsjs
   private hlsjsConfig: Partial<HlsConfig & { cueHandler: any }> = null
 
@@ -146,6 +148,7 @@ class Html5Hlsjs {
   }
 
   duration () {
+    if (this._duration === Infinity) return Infinity
     if (!isNaN(this.videoElement.duration)) return this.videoElement.duration
 
     return this._duration || 0
@@ -171,6 +174,12 @@ class Html5Hlsjs {
   dispose () {
     this.videoElement.removeEventListener('play', this.handlers.play)
 
+    // FIXME: https://github.com/video-dev/hls.js/issues/4092
+    const untypedHLS = this.hls as any
+    untypedHLS.log = untypedHLS.warn = () => {
+      // empty
+    }
+
     this.hls.destroy()
   }
 
@@ -224,7 +233,7 @@ class Html5Hlsjs {
   }
 
   private _handleNetworkError (error: any) {
-    if (this.errorCounts[Hlsjs.ErrorTypes.NETWORK_ERROR] <= 5) {
+    if (this.errorCounts[Hlsjs.ErrorTypes.NETWORK_ERROR] <= this.maxNetworkErrorRecovery) {
       console.info('trying to recover network error')
 
       // Wait 1 second and retry
@@ -370,6 +379,9 @@ class Html5Hlsjs {
       this.dvrDuration = data.details.totalduration
 
       this._duration = this.isLive ? Infinity : data.details.totalduration
+
+      // Increase network error recovery for lives since they can be broken (server restart, stream interruption etc)
+      if (this.isLive) this.maxNetworkErrorRecovery = 300
     })
 
     this.hls.once(Hlsjs.Events.FRAG_LOADED, () => {