aboutsummaryrefslogtreecommitdiffhomepage
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/src/assets/player/peertube-videojs-plugin.ts36
1 files changed, 25 insertions, 11 deletions
diff --git a/client/src/assets/player/peertube-videojs-plugin.ts b/client/src/assets/player/peertube-videojs-plugin.ts
index 84a5e7f13..2eddcb1d8 100644
--- a/client/src/assets/player/peertube-videojs-plugin.ts
+++ b/client/src/assets/player/peertube-videojs-plugin.ts
@@ -44,19 +44,23 @@ class PeerTubePlugin extends Plugin {
44 INFO_SCHEDULER: 1000, // Don't change this 44 INFO_SCHEDULER: 1000, // Don't change this
45 AUTO_QUALITY_SCHEDULER: 3000, // Check quality every 3 seconds 45 AUTO_QUALITY_SCHEDULER: 3000, // Check quality every 3 seconds
46 AUTO_QUALITY_THRESHOLD_PERCENT: 30, // Bandwidth should be 30% more important than a resolution bitrate to change to it 46 AUTO_QUALITY_THRESHOLD_PERCENT: 30, // Bandwidth should be 30% more important than a resolution bitrate to change to it
47 AUTO_QUALITY_OBSERVATION_TIME: 10000, // Wait 10 seconds before potentially changing the definition 47 AUTO_QUALITY_OBSERVATION_TIME: 10000, // Wait 10 seconds after having change the resolution before another check
48 AUTO_QUALITY_UPPER_RESOLUTION_DELAY: 5000, // Buffer upper resolution during 5 seconds 48 AUTO_QUALITY_HIGHER_RESOLUTION_DELAY: 5000, // Buffering higher resolution during 5 seconds
49 BANDWIDTH_AVERAGE_NUMBER_OF_VALUES: 5 // Last 5 seconds to build average bandwidth 49 BANDWIDTH_AVERAGE_NUMBER_OF_VALUES: 5 // Last 5 seconds to build average bandwidth
50 } 50 }
51 51
52 private player: any 52 private player: any
53 private currentVideoFile: VideoFile 53 private currentVideoFile: VideoFile
54 private torrent: WebTorrent.Torrent 54 private torrent: WebTorrent.Torrent
55 private autoResolution = true
56 private isAutoResolutionObservation = false
57
55 private videoViewInterval 58 private videoViewInterval
56 private torrentInfoInterval 59 private torrentInfoInterval
57 private autoQualityInterval 60 private autoQualityInterval
58 private autoResolution = true 61 private addTorrentDelay
59 private isAutoResolutionObservation = false 62 private qualityObservationTimer
63 private runAutoQualitySchedulerTimer
60 64
61 private downloadSpeeds: number[] = [] 65 private downloadSpeeds: number[] = []
62 66
@@ -91,7 +95,9 @@ class PeerTubePlugin extends Plugin {
91 95
92 this.player.one('play', () => { 96 this.player.one('play', () => {
93 // Don't run immediately scheduler, wait some seconds the TCP connections are maid 97 // Don't run immediately scheduler, wait some seconds the TCP connections are maid
94 setTimeout(() => this.runAutoQualityScheduler(), this.CONSTANTS.AUTO_QUALITY_SCHEDULER) 98 this.runAutoQualitySchedulerTimer = setTimeout(() => {
99 this.runAutoQualityScheduler()
100 }, this.CONSTANTS.AUTO_QUALITY_SCHEDULER)
95 }) 101 })
96 }) 102 })
97 103
@@ -102,6 +108,10 @@ class PeerTubePlugin extends Plugin {
102 } 108 }
103 109
104 dispose () { 110 dispose () {
111 clearTimeout(this.addTorrentDelay)
112 clearTimeout(this.qualityObservationTimer)
113 clearTimeout(this.runAutoQualitySchedulerTimer)
114
105 clearInterval(this.videoViewInterval) 115 clearInterval(this.videoViewInterval)
106 clearInterval(this.torrentInfoInterval) 116 clearInterval(this.torrentInfoInterval)
107 clearInterval(this.autoQualityInterval) 117 clearInterval(this.autoQualityInterval)
@@ -167,7 +177,7 @@ class PeerTubePlugin extends Plugin {
167 oldTorrent.removePeer(oldTorrent['ws']) 177 oldTorrent.removePeer(oldTorrent['ws'])
168 } 178 }
169 179
170 setTimeout(() => { 180 this.addTorrentDelay = setTimeout(() => {
171 this.flushVideoFile(previousVideoFile) 181 this.flushVideoFile(previousVideoFile)
172 182
173 const options = { autoplay: true, controls: true } 183 const options = { autoplay: true, controls: true }
@@ -265,7 +275,7 @@ class PeerTubePlugin extends Plugin {
265 const fileBitrate = (f.size / this.videoDuration) 275 const fileBitrate = (f.size / this.videoDuration)
266 let threshold = fileBitrate 276 let threshold = fileBitrate
267 277
268 // If this is for a higher resolution, or an initial load -> add a upper margin 278 // If this is for a higher resolution or an initial load: add a margin
269 if (!this.currentVideoFile || f.resolution.id > this.currentVideoFile.resolution.id) { 279 if (!this.currentVideoFile || f.resolution.id > this.currentVideoFile.resolution.id) {
270 threshold += ((fileBitrate * this.CONSTANTS.AUTO_QUALITY_THRESHOLD_PERCENT) / 100) 280 threshold += ((fileBitrate * this.CONSTANTS.AUTO_QUALITY_THRESHOLD_PERCENT) / 100)
271 } 281 }
@@ -313,6 +323,7 @@ class PeerTubePlugin extends Plugin {
313 323
314 private runAutoQualityScheduler () { 324 private runAutoQualityScheduler () {
315 this.autoQualityInterval = setInterval(() => { 325 this.autoQualityInterval = setInterval(() => {
326
316 // Not initialized or in HTTP fallback 327 // Not initialized or in HTTP fallback
317 if (this.torrent === undefined || this.torrent === null) return 328 if (this.torrent === undefined || this.torrent === null) return
318 if (this.isAutoResolutionOn() === false) return 329 if (this.isAutoResolutionOn() === false) return
@@ -326,10 +337,10 @@ class PeerTubePlugin extends Plugin {
326 if (this.isPlayerWaiting() && file.resolution.id < this.currentVideoFile.resolution.id) { 337 if (this.isPlayerWaiting() && file.resolution.id < this.currentVideoFile.resolution.id) {
327 console.log('Downgrading automatically the resolution to: %s', file.resolution.label) 338 console.log('Downgrading automatically the resolution to: %s', file.resolution.label)
328 changeResolution = true 339 changeResolution = true
329 } else if (file.resolution.id > this.currentVideoFile.resolution.id) { // Greater resolution 340 } else if (file.resolution.id > this.currentVideoFile.resolution.id) { // Higher resolution
330 console.log('Upgrading automatically the resolution to: %s', file.resolution.label) 341 console.log('Upgrading automatically the resolution to: %s', file.resolution.label)
331 changeResolution = true 342 changeResolution = true
332 changeResolutionDelay = this.CONSTANTS.AUTO_QUALITY_UPPER_RESOLUTION_DELAY 343 changeResolutionDelay = this.CONSTANTS.AUTO_QUALITY_HIGHER_RESOLUTION_DELAY
333 } 344 }
334 345
335 if (changeResolution === true) { 346 if (changeResolution === true) {
@@ -337,13 +348,16 @@ class PeerTubePlugin extends Plugin {
337 348
338 // Wait some seconds in observation of our new resolution 349 // Wait some seconds in observation of our new resolution
339 this.isAutoResolutionObservation = true 350 this.isAutoResolutionObservation = true
340 setTimeout(() => this.isAutoResolutionObservation = false, this.CONSTANTS.AUTO_QUALITY_OBSERVATION_TIME) 351
352 this.qualityObservationTimer = setTimeout(() => {
353 this.isAutoResolutionObservation = false
354 }, this.CONSTANTS.AUTO_QUALITY_OBSERVATION_TIME)
341 } 355 }
342 }, this.CONSTANTS.AUTO_QUALITY_SCHEDULER) 356 }, this.CONSTANTS.AUTO_QUALITY_SCHEDULER)
343 } 357 }
344 358
345 private isPlayerWaiting () { 359 private isPlayerWaiting () {
346 return this.player.hasClass('vjs-waiting') 360 return this.player && this.player.hasClass('vjs-waiting')
347 } 361 }
348 362
349 private runTorrentInfoScheduler () { 363 private runTorrentInfoScheduler () {