]> 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 17b9aba97ff40f84c3f505ba8d66c1728905022a..ae31bcfe176fc78ece41142170c7c36c9df4843a 100644 (file)
@@ -68,10 +68,6 @@ function hlsjsConfigHandler (this: videojs.Player, options: HlsjsConfigHandlerOp
     player.srOptions_.hlsjsConfig = options.hlsjsConfig
   }
 
-  if (!player.srOptions_.captionConfig) {
-    player.srOptions_.captionConfig = options.captionConfig
-  }
-
   if (options.levelLabelHandler && !player.srOptions_.levelLabelHandler) {
     player.srOptions_.levelLabelHandler = options.levelLabelHandler
   }
@@ -93,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
 
@@ -150,7 +148,10 @@ class Html5Hlsjs {
   }
 
   duration () {
-    return this._duration || this.videoElement.duration || 0
+    if (this._duration === Infinity) return Infinity
+    if (!isNaN(this.videoElement.duration)) return this.videoElement.duration
+
+    return this._duration || 0
   }
 
   seekable () {
@@ -173,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()
   }
 
@@ -226,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,7 +377,11 @@ class Html5Hlsjs {
 
       this.isLive = data.details.live
       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, () => {