aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/assets')
-rw-r--r--client/src/assets/player/webtorrent/webtorrent-plugin.ts40
1 files changed, 22 insertions, 18 deletions
diff --git a/client/src/assets/player/webtorrent/webtorrent-plugin.ts b/client/src/assets/player/webtorrent/webtorrent-plugin.ts
index 85636c5be..f9c050b84 100644
--- a/client/src/assets/player/webtorrent/webtorrent-plugin.ts
+++ b/client/src/assets/player/webtorrent/webtorrent-plugin.ts
@@ -362,45 +362,49 @@ class WebTorrentPlugin extends Plugin {
362 } 362 }
363 363
364 private getAppropriateFile (averageDownloadSpeed?: number): VideoFile { 364 private getAppropriateFile (averageDownloadSpeed?: number): VideoFile {
365 if (this.videoFiles === undefined || this.videoFiles.length === 0) return undefined 365 if (this.videoFiles === undefined) return undefined
366 if (this.videoFiles.length === 1) return this.videoFiles[0] 366
367 const files = this.videoFiles.filter(f => f.resolution.id !== 0)
368
369 if (files.length === 0) return undefined
370 if (files.length === 1) return files[0]
367 371
368 // Don't change the torrent is the play was ended 372 // Don't change the torrent is the play was ended
369 if (this.torrent && this.torrent.progress === 1 && this.player.ended()) return this.currentVideoFile 373 if (this.torrent && this.torrent.progress === 1 && this.player.ended()) return this.currentVideoFile
370 374
371 if (!averageDownloadSpeed) averageDownloadSpeed = this.getAndSaveActualDownloadSpeed() 375 if (!averageDownloadSpeed) averageDownloadSpeed = this.getAndSaveActualDownloadSpeed()
376 averageDownloadSpeed = 0
372 377
373 // Limit resolution according to player height 378 // Limit resolution according to player height
374 const playerHeight = this.playerElement.offsetHeight 379 const playerHeight = this.playerElement.offsetHeight
375 380
376 // We take the first resolution just above the player height 381 // We take the first resolution just above the player height
377 // Example: player height is 530px, we want the 720p file instead of 480p 382 // Example: player height is 530px, we want the 720p file instead of 480p
378 let maxResolution = this.videoFiles[0].resolution.id 383 let maxResolution = files[0].resolution.id
379 for (let i = this.videoFiles.length - 1; i >= 0; i--) { 384 for (let i = files.length - 1; i >= 0; i--) {
380 const resolutionId = this.videoFiles[i].resolution.id 385 const resolutionId = files[i].resolution.id
381 if (resolutionId >= playerHeight) { 386 if (resolutionId !== 0 && resolutionId >= playerHeight) {
382 maxResolution = resolutionId 387 maxResolution = resolutionId
383 break 388 break
384 } 389 }
385 } 390 }
386 391
387 // Filter videos we can play according to our screen resolution and bandwidth 392 // Filter videos we can play according to our screen resolution and bandwidth
388 const filteredFiles = this.videoFiles 393 const filteredFiles = files.filter(f => f.resolution.id <= maxResolution)
389 .filter(f => f.resolution.id <= maxResolution) 394 .filter(f => {
390 .filter(f => { 395 const fileBitrate = (f.size / this.videoDuration)
391 const fileBitrate = (f.size / this.videoDuration) 396 let threshold = fileBitrate
392 let threshold = fileBitrate
393 397
394 // If this is for a higher resolution or an initial load: add a margin 398 // If this is for a higher resolution or an initial load: add a margin
395 if (!this.currentVideoFile || f.resolution.id > this.currentVideoFile.resolution.id) { 399 if (!this.currentVideoFile || f.resolution.id > this.currentVideoFile.resolution.id) {
396 threshold += ((fileBitrate * this.CONSTANTS.AUTO_QUALITY_THRESHOLD_PERCENT) / 100) 400 threshold += ((fileBitrate * this.CONSTANTS.AUTO_QUALITY_THRESHOLD_PERCENT) / 100)
397 } 401 }
398 402
399 return averageDownloadSpeed > threshold 403 return averageDownloadSpeed > threshold
400 }) 404 })
401 405
402 // If the download speed is too bad, return the lowest resolution we have 406 // If the download speed is too bad, return the lowest resolution we have
403 if (filteredFiles.length === 0) return videoFileMinByResolution(this.videoFiles) 407 if (filteredFiles.length === 0) return videoFileMinByResolution(files)
404 408
405 return videoFileMaxByResolution(filteredFiles) 409 return videoFileMaxByResolution(filteredFiles)
406 } 410 }