diff options
author | Chocobozzz <me@florianbigard.com> | 2020-11-10 14:21:26 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-11-10 14:21:26 +0100 |
commit | 25b7c847249c2b7f7b309b14eecb03dd024db649 (patch) | |
tree | bad822d4a10f902a23ad29ca5569e4f8b824446f /client/src | |
parent | 210856a7be4631540791bad027fb3ef0f7a51f14 (diff) | |
download | PeerTube-25b7c847249c2b7f7b309b14eecb03dd024db649.tar.gz PeerTube-25b7c847249c2b7f7b309b14eecb03dd024db649.tar.zst PeerTube-25b7c847249c2b7f7b309b14eecb03dd024db649.zip |
Try to optimize sha segments fetching
Diffstat (limited to 'client/src')
4 files changed, 13 insertions, 4 deletions
diff --git a/client/src/app/+videos/+video-watch/video-watch.component.ts b/client/src/app/+videos/+video-watch/video-watch.component.ts index 48623cae0..66af9709d 100644 --- a/client/src/app/+videos/+video-watch/video-watch.component.ts +++ b/client/src/app/+videos/+video-watch/video-watch.component.ts | |||
@@ -771,6 +771,8 @@ export class VideoWatchComponent implements OnInit, OnDestroy { | |||
771 | : null, | 771 | : null, |
772 | embedUrl: video.embedUrl, | 772 | embedUrl: video.embedUrl, |
773 | 773 | ||
774 | isLive: video.isLive, | ||
775 | |||
774 | language: this.localeId, | 776 | language: this.localeId, |
775 | 777 | ||
776 | userWatching: user && user.videosHistoryEnabled === true ? { | 778 | userWatching: user && user.videosHistoryEnabled === true ? { |
diff --git a/client/src/assets/player/p2p-media-loader/segment-validator.ts b/client/src/assets/player/p2p-media-loader/segment-validator.ts index 9add35184..844956d6a 100644 --- a/client/src/assets/player/p2p-media-loader/segment-validator.ts +++ b/client/src/assets/player/p2p-media-loader/segment-validator.ts | |||
@@ -6,11 +6,14 @@ type SegmentsJSON = { [filename: string]: string | { [byterange: string]: string | |||
6 | 6 | ||
7 | const maxRetries = 3 | 7 | const maxRetries = 3 |
8 | 8 | ||
9 | function segmentValidatorFactory (segmentsSha256Url: string) { | 9 | function segmentValidatorFactory (segmentsSha256Url: string, isLive: boolean) { |
10 | let segmentsJSON = fetchSha256Segments(segmentsSha256Url) | 10 | let segmentsJSON = fetchSha256Segments(segmentsSha256Url) |
11 | const regex = /bytes=(\d+)-(\d+)/ | 11 | const regex = /bytes=(\d+)-(\d+)/ |
12 | 12 | ||
13 | return async function segmentValidator (segment: Segment, retry = 1) { | 13 | return async function segmentValidator (segment: Segment, retry = 1) { |
14 | // Wait for hash generation from the server | ||
15 | if (isLive) await wait(1000) | ||
16 | |||
14 | const filename = basename(segment.url) | 17 | const filename = basename(segment.url) |
15 | 18 | ||
16 | const segmentValue = (await segmentsJSON)[filename] | 19 | const segmentValue = (await segmentsJSON)[filename] |
@@ -20,10 +23,10 @@ function segmentValidatorFactory (segmentsSha256Url: string) { | |||
20 | } | 23 | } |
21 | 24 | ||
22 | if (!segmentValue) { | 25 | if (!segmentValue) { |
23 | await wait(1000) | ||
24 | |||
25 | console.log('Refetching sha segments for %s.', filename) | 26 | console.log('Refetching sha segments for %s.', filename) |
26 | 27 | ||
28 | await wait(1000) | ||
29 | |||
27 | segmentsJSON = fetchSha256Segments(segmentsSha256Url) | 30 | segmentsJSON = fetchSha256Segments(segmentsSha256Url) |
28 | await segmentValidator(segment, retry + 1) | 31 | await segmentValidator(segment, retry + 1) |
29 | 32 | ||
diff --git a/client/src/assets/player/peertube-player-manager.ts b/client/src/assets/player/peertube-player-manager.ts index c1953043e..da23c59a7 100644 --- a/client/src/assets/player/peertube-player-manager.ts +++ b/client/src/assets/player/peertube-player-manager.ts | |||
@@ -98,6 +98,8 @@ export interface CommonOptions extends CustomizationOptions { | |||
98 | videoViewUrl: string | 98 | videoViewUrl: string |
99 | embedUrl: string | 99 | embedUrl: string |
100 | 100 | ||
101 | isLive: boolean | ||
102 | |||
101 | language?: string | 103 | language?: string |
102 | 104 | ||
103 | videoCaptions: VideoJSCaption[] | 105 | videoCaptions: VideoJSCaption[] |
@@ -323,7 +325,7 @@ export class PeertubePlayerManager { | |||
323 | const p2pMediaLoaderConfig = { | 325 | const p2pMediaLoaderConfig = { |
324 | loader: { | 326 | loader: { |
325 | trackerAnnounce, | 327 | trackerAnnounce, |
326 | segmentValidator: segmentValidatorFactory(options.p2pMediaLoader.segmentsSha256Url), | 328 | segmentValidator: segmentValidatorFactory(options.p2pMediaLoader.segmentsSha256Url, options.common.isLive), |
327 | rtcConfig: getRtcConfig(), | 329 | rtcConfig: getRtcConfig(), |
328 | requiredSegmentsPriority: 1, | 330 | requiredSegmentsPriority: 1, |
329 | segmentUrlBuilder: segmentUrlBuilderFactory(redundancyUrlManager), | 331 | segmentUrlBuilder: segmentUrlBuilderFactory(redundancyUrlManager), |
diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts index 9b07ef5e6..66033158b 100644 --- a/client/src/standalone/videos/embed.ts +++ b/client/src/standalone/videos/embed.ts | |||
@@ -532,6 +532,8 @@ export class PeerTubeEmbed { | |||
532 | inactivityTimeout: 2500, | 532 | inactivityTimeout: 2500, |
533 | videoViewUrl: this.getVideoUrl(videoInfo.uuid) + '/views', | 533 | videoViewUrl: this.getVideoUrl(videoInfo.uuid) + '/views', |
534 | 534 | ||
535 | isLive: videoInfo.isLive, | ||
536 | |||
535 | playerElement: this.playerElement, | 537 | playerElement: this.playerElement, |
536 | onPlayerElementChange: (element: HTMLVideoElement) => this.playerElement = element, | 538 | onPlayerElementChange: (element: HTMLVideoElement) => this.playerElement = element, |
537 | 539 | ||