aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player/peertube-player-options-builder.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/assets/player/peertube-player-options-builder.ts')
-rw-r--r--client/src/assets/player/peertube-player-options-builder.ts99
1 files changed, 80 insertions, 19 deletions
diff --git a/client/src/assets/player/peertube-player-options-builder.ts b/client/src/assets/player/peertube-player-options-builder.ts
index 7a82b128d..c9cbbbf4d 100644
--- a/client/src/assets/player/peertube-player-options-builder.ts
+++ b/client/src/assets/player/peertube-player-options-builder.ts
@@ -1,9 +1,10 @@
1import videojs from 'video.js' 1import videojs from 'video.js'
2import { HybridLoaderSettings } from '@peertube/p2p-media-loader-core'
2import { HlsJsEngineSettings } from '@peertube/p2p-media-loader-hlsjs' 3import { HlsJsEngineSettings } from '@peertube/p2p-media-loader-hlsjs'
3import { PluginsManager } from '@root-helpers/plugins-manager' 4import { PluginsManager } from '@root-helpers/plugins-manager'
4import { buildVideoLink, decorateVideoLink } from '@shared/core-utils' 5import { buildVideoLink, decorateVideoLink } from '@shared/core-utils'
5import { isDefaultLocale } from '@shared/core-utils/i18n' 6import { isDefaultLocale } from '@shared/core-utils/i18n'
6import { VideoFile } from '@shared/models' 7import { LiveVideoLatencyMode, VideoFile } from '@shared/models'
7import { copyToClipboard } from '../../root-helpers/utils' 8import { copyToClipboard } from '../../root-helpers/utils'
8import { RedundancyUrlManager } from './p2p-media-loader/redundancy-url-manager' 9import { RedundancyUrlManager } from './p2p-media-loader/redundancy-url-manager'
9import { segmentUrlBuilderFactory } from './p2p-media-loader/segment-url-builder' 10import { segmentUrlBuilderFactory } from './p2p-media-loader/segment-url-builder'
@@ -19,7 +20,6 @@ import {
19 VideoJSPluginOptions 20 VideoJSPluginOptions
20} from './peertube-videojs-typings' 21} from './peertube-videojs-typings'
21import { buildVideoOrPlaylistEmbed, getRtcConfig, isIOS, isSafari } from './utils' 22import { buildVideoOrPlaylistEmbed, getRtcConfig, isIOS, isSafari } from './utils'
22import { HybridLoaderSettings } from '@peertube/p2p-media-loader-core'
23 23
24export type PlayerMode = 'webtorrent' | 'p2p-media-loader' 24export type PlayerMode = 'webtorrent' | 'p2p-media-loader'
25 25
@@ -76,6 +76,9 @@ export interface CommonOptions extends CustomizationOptions {
76 embedTitle: string 76 embedTitle: string
77 77
78 isLive: boolean 78 isLive: boolean
79 liveOptions?: {
80 latencyMode: LiveVideoLatencyMode
81 }
79 82
80 language?: string 83 language?: string
81 84
@@ -250,21 +253,8 @@ export class PeertubePlayerOptionsBuilder {
250 .filter(t => t.startsWith('ws')) 253 .filter(t => t.startsWith('ws'))
251 254
252 const specificLiveOrVODOptions = this.options.common.isLive 255 const specificLiveOrVODOptions = this.options.common.isLive
253 ? { // Live 256 ? this.getP2PMediaLoaderLiveOptions()
254 requiredSegmentsPriority: 1 257 : this.getP2PMediaLoaderVODOptions()
255 }
256 : { // VOD
257 requiredSegmentsPriority: 3,
258
259 cachedSegmentExpiration: 86400000,
260 cachedSegmentsCount: 100,
261
262 httpDownloadMaxPriority: 9,
263 httpDownloadProbability: 0.06,
264 httpDownloadProbabilitySkipIfNoPeers: true,
265
266 p2pDownloadMaxPriority: 50
267 }
268 258
269 return { 259 return {
270 trackerAnnounce, 260 trackerAnnounce,
@@ -283,13 +273,57 @@ export class PeertubePlayerOptionsBuilder {
283 } 273 }
284 } 274 }
285 275
276 private getP2PMediaLoaderLiveOptions (): Partial<HybridLoaderSettings> {
277 const base = {
278 requiredSegmentsPriority: 1
279 }
280
281 const latencyMode = this.options.common.liveOptions.latencyMode
282
283 switch (latencyMode) {
284 case LiveVideoLatencyMode.SMALL_LATENCY:
285 return {
286 ...base,
287
288 useP2P: false,
289 httpDownloadProbability: 1
290 }
291
292 case LiveVideoLatencyMode.HIGH_LATENCY:
293 return base
294
295 default:
296 return base
297 }
298 }
299
300 private getP2PMediaLoaderVODOptions (): Partial<HybridLoaderSettings> {
301 return {
302 requiredSegmentsPriority: 3,
303
304 cachedSegmentExpiration: 86400000,
305 cachedSegmentsCount: 100,
306
307 httpDownloadMaxPriority: 9,
308 httpDownloadProbability: 0.06,
309 httpDownloadProbabilitySkipIfNoPeers: true,
310
311 p2pDownloadMaxPriority: 50
312 }
313 }
314
286 private getHLSOptions (p2pMediaLoaderConfig: HlsJsEngineSettings) { 315 private getHLSOptions (p2pMediaLoaderConfig: HlsJsEngineSettings) {
316 const specificLiveOrVODOptions = this.options.common.isLive
317 ? this.getHLSLiveOptions()
318 : this.getHLSVODOptions()
319
287 const base = { 320 const base = {
288 capLevelToPlayerSize: true, 321 capLevelToPlayerSize: true,
289 autoStartLoad: false, 322 autoStartLoad: false,
290 liveSyncDurationCount: 5,
291 323
292 loader: new this.p2pMediaLoaderModule.Engine(p2pMediaLoaderConfig).createLoaderClass() 324 loader: new this.p2pMediaLoaderModule.Engine(p2pMediaLoaderConfig).createLoaderClass(),
325
326 ...specificLiveOrVODOptions
293 } 327 }
294 328
295 const averageBandwidth = getAverageBandwidthInStore() 329 const averageBandwidth = getAverageBandwidthInStore()
@@ -305,6 +339,33 @@ export class PeertubePlayerOptionsBuilder {
305 } 339 }
306 } 340 }
307 341
342 private getHLSLiveOptions () {
343 const latencyMode = this.options.common.liveOptions.latencyMode
344
345 switch (latencyMode) {
346 case LiveVideoLatencyMode.SMALL_LATENCY:
347 return {
348 liveSyncDurationCount: 2
349 }
350
351 case LiveVideoLatencyMode.HIGH_LATENCY:
352 return {
353 liveSyncDurationCount: 10
354 }
355
356 default:
357 return {
358 liveSyncDurationCount: 5
359 }
360 }
361 }
362
363 private getHLSVODOptions () {
364 return {
365 liveSyncDurationCount: 5
366 }
367 }
368
308 private addWebTorrentOptions (plugins: VideoJSPluginOptions, alreadyPlayed: boolean) { 369 private addWebTorrentOptions (plugins: VideoJSPluginOptions, alreadyPlayed: boolean) {
309 const commonOptions = this.options.common 370 const commonOptions = this.options.common
310 const webtorrentOptions = this.options.webtorrent 371 const webtorrentOptions = this.options.webtorrent