diff options
author | Chocobozzz <me@florianbigard.com> | 2022-03-04 13:40:02 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2022-03-09 09:23:10 +0100 |
commit | f443a74649174b2f9347c158e30f8ac7aa3e958a (patch) | |
tree | e423bc4e2307477bda4341037b7fa04ad10adae6 /client/src/assets/player/peertube-player-options-builder.ts | |
parent | 01dd04cd5ab7b55d2a9af7d0ebf405bee9579b09 (diff) | |
download | PeerTube-f443a74649174b2f9347c158e30f8ac7aa3e958a.tar.gz PeerTube-f443a74649174b2f9347c158e30f8ac7aa3e958a.tar.zst PeerTube-f443a74649174b2f9347c158e30f8ac7aa3e958a.zip |
Add latency setting support
Diffstat (limited to 'client/src/assets/player/peertube-player-options-builder.ts')
-rw-r--r-- | client/src/assets/player/peertube-player-options-builder.ts | 99 |
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 @@ | |||
1 | import videojs from 'video.js' | 1 | import videojs from 'video.js' |
2 | import { HybridLoaderSettings } from '@peertube/p2p-media-loader-core' | ||
2 | import { HlsJsEngineSettings } from '@peertube/p2p-media-loader-hlsjs' | 3 | import { HlsJsEngineSettings } from '@peertube/p2p-media-loader-hlsjs' |
3 | import { PluginsManager } from '@root-helpers/plugins-manager' | 4 | import { PluginsManager } from '@root-helpers/plugins-manager' |
4 | import { buildVideoLink, decorateVideoLink } from '@shared/core-utils' | 5 | import { buildVideoLink, decorateVideoLink } from '@shared/core-utils' |
5 | import { isDefaultLocale } from '@shared/core-utils/i18n' | 6 | import { isDefaultLocale } from '@shared/core-utils/i18n' |
6 | import { VideoFile } from '@shared/models' | 7 | import { LiveVideoLatencyMode, VideoFile } from '@shared/models' |
7 | import { copyToClipboard } from '../../root-helpers/utils' | 8 | import { copyToClipboard } from '../../root-helpers/utils' |
8 | import { RedundancyUrlManager } from './p2p-media-loader/redundancy-url-manager' | 9 | import { RedundancyUrlManager } from './p2p-media-loader/redundancy-url-manager' |
9 | import { segmentUrlBuilderFactory } from './p2p-media-loader/segment-url-builder' | 10 | import { 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' |
21 | import { buildVideoOrPlaylistEmbed, getRtcConfig, isIOS, isSafari } from './utils' | 22 | import { buildVideoOrPlaylistEmbed, getRtcConfig, isIOS, isSafari } from './utils' |
22 | import { HybridLoaderSettings } from '@peertube/p2p-media-loader-core' | ||
23 | 23 | ||
24 | export type PlayerMode = 'webtorrent' | 'p2p-media-loader' | 24 | export 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 |