aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player/peertube-player-manager.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/assets/player/peertube-player-manager.ts')
-rw-r--r--client/src/assets/player/peertube-player-manager.ts45
1 files changed, 36 insertions, 9 deletions
diff --git a/client/src/assets/player/peertube-player-manager.ts b/client/src/assets/player/peertube-player-manager.ts
index 766ad203e..c45e8f53e 100644
--- a/client/src/assets/player/peertube-player-manager.ts
+++ b/client/src/assets/player/peertube-player-manager.ts
@@ -22,6 +22,7 @@ import './videojs-components/settings-panel-child'
22import './videojs-components/theater-button' 22import './videojs-components/theater-button'
23import './playlist/playlist-plugin' 23import './playlist/playlist-plugin'
24import videojs from 'video.js' 24import videojs from 'video.js'
25import { HlsJsEngineSettings } from '@peertube/p2p-media-loader-hlsjs'
25import { PluginsManager } from '@root-helpers/plugins-manager' 26import { PluginsManager } from '@root-helpers/plugins-manager'
26import { buildVideoLink, decorateVideoLink } from '@shared/core-utils' 27import { buildVideoLink, decorateVideoLink } from '@shared/core-utils'
27import { isDefaultLocale } from '@shared/core-utils/i18n' 28import { isDefaultLocale } from '@shared/core-utils/i18n'
@@ -30,11 +31,12 @@ import { copyToClipboard } from '../../root-helpers/utils'
30import { RedundancyUrlManager } from './p2p-media-loader/redundancy-url-manager' 31import { RedundancyUrlManager } from './p2p-media-loader/redundancy-url-manager'
31import { segmentUrlBuilderFactory } from './p2p-media-loader/segment-url-builder' 32import { segmentUrlBuilderFactory } from './p2p-media-loader/segment-url-builder'
32import { segmentValidatorFactory } from './p2p-media-loader/segment-validator' 33import { segmentValidatorFactory } from './p2p-media-loader/segment-validator'
33import { getStoredP2PEnabled } from './peertube-player-local-storage' 34import { getAverageBandwidthInStore, getStoredP2PEnabled, saveAverageBandwidth } from './peertube-player-local-storage'
34import { 35import {
35 NextPreviousVideoButtonOptions, 36 NextPreviousVideoButtonOptions,
36 P2PMediaLoaderPluginOptions, 37 P2PMediaLoaderPluginOptions,
37 PeerTubeLinkButtonOptions, 38 PeerTubeLinkButtonOptions,
39 PlayerNetworkInfo,
38 PlaylistPluginOptions, 40 PlaylistPluginOptions,
39 UserWatching, 41 UserWatching,
40 VideoJSCaption, 42 VideoJSCaption,
@@ -148,7 +150,7 @@ export class PeertubePlayerManager {
148 if (mode === 'webtorrent') await import('./webtorrent/webtorrent-plugin') 150 if (mode === 'webtorrent') await import('./webtorrent/webtorrent-plugin')
149 if (mode === 'p2p-media-loader') { 151 if (mode === 'p2p-media-loader') {
150 [ p2pMediaLoader ] = await Promise.all([ 152 [ p2pMediaLoader ] = await Promise.all([
151 import('p2p-media-loader-hlsjs'), 153 import('@peertube/p2p-media-loader-hlsjs'),
152 import('./p2p-media-loader/p2p-media-loader-plugin') 154 import('./p2p-media-loader/p2p-media-loader-plugin')
153 ]) 155 ])
154 } 156 }
@@ -193,6 +195,12 @@ export class PeertubePlayerManager {
193 mode 195 mode
194 }) 196 })
195 197
198 player.on('p2pInfo', (_, data: PlayerNetworkInfo) => {
199 if (data.source !== 'p2p-media-loader' || isNaN(data.bandwidthEstimate)) return
200
201 saveAverageBandwidth(data.bandwidthEstimate)
202 })
203
196 return res(player) 204 return res(player)
197 }) 205 })
198 }) 206 })
@@ -359,12 +367,13 @@ export class PeertubePlayerManager {
359 consumeOnly = true 367 consumeOnly = true
360 } 368 }
361 369
362 const p2pMediaLoaderConfig = { 370 const p2pMediaLoaderConfig: HlsJsEngineSettings = {
363 loader: { 371 loader: {
364 trackerAnnounce, 372 trackerAnnounce,
365 segmentValidator: segmentValidatorFactory(options.p2pMediaLoader.segmentsSha256Url, options.common.isLive), 373 segmentValidator: segmentValidatorFactory(options.p2pMediaLoader.segmentsSha256Url, options.common.isLive),
366 rtcConfig: getRtcConfig(), 374 rtcConfig: getRtcConfig(),
367 requiredSegmentsPriority: 1, 375 requiredSegmentsPriority: 1,
376 simultaneousHttpDownloads: 1,
368 segmentUrlBuilder: segmentUrlBuilderFactory(redundancyUrlManager), 377 segmentUrlBuilder: segmentUrlBuilderFactory(redundancyUrlManager),
369 useP2P: getStoredP2PEnabled(), 378 useP2P: getStoredP2PEnabled(),
370 consumeOnly 379 consumeOnly
@@ -373,6 +382,7 @@ export class PeertubePlayerManager {
373 swarmId: p2pMediaLoaderOptions.playlistUrl 382 swarmId: p2pMediaLoaderOptions.playlistUrl
374 } 383 }
375 } 384 }
385
376 const hlsjs = { 386 const hlsjs = {
377 levelLabelHandler: (level: { height: number, width: number }) => { 387 levelLabelHandler: (level: { height: number, width: number }) => {
378 const resolution = Math.min(level.height || 0, level.width || 0) 388 const resolution = Math.min(level.height || 0, level.width || 0)
@@ -387,12 +397,7 @@ export class PeertubePlayerManager {
387 return label 397 return label
388 }, 398 },
389 html5: { 399 html5: {
390 hlsjsConfig: { 400 hlsjsConfig: this.getHLSOptions(p2pMediaLoaderModule, p2pMediaLoaderConfig)
391 capLevelToPlayerSize: true,
392 autoStartLoad: false,
393 liveSyncDurationCount: 5,
394 loader: new p2pMediaLoaderModule.Engine(p2pMediaLoaderConfig).createLoaderClass()
395 }
396 } 401 }
397 } 402 }
398 403
@@ -402,6 +407,28 @@ export class PeertubePlayerManager {
402 return toAssign 407 return toAssign
403 } 408 }
404 409
410 private static getHLSOptions (p2pMediaLoaderModule: any, p2pMediaLoaderConfig: HlsJsEngineSettings) {
411 const base = {
412 capLevelToPlayerSize: true,
413 autoStartLoad: false,
414 liveSyncDurationCount: 5,
415
416 loader: new p2pMediaLoaderModule.Engine(p2pMediaLoaderConfig).createLoaderClass()
417 }
418
419 const averageBandwidth = getAverageBandwidthInStore()
420 if (!averageBandwidth) return base
421
422 return {
423 ...base,
424
425 abrEwmaDefaultEstimate: averageBandwidth * 8, // We want bit/s
426 startLevel: -1,
427 testBandwidth: false,
428 debug: false
429 }
430 }
431
405 private static addWebTorrentOptions (plugins: VideoJSPluginOptions, options: PeertubePlayerManagerOptions) { 432 private static addWebTorrentOptions (plugins: VideoJSPluginOptions, options: PeertubePlayerManagerOptions) {
406 const commonOptions = options.common 433 const commonOptions = options.common
407 const webtorrentOptions = options.webtorrent 434 const webtorrentOptions = options.webtorrent