]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Try to optimize sha segments fetching
authorChocobozzz <me@florianbigard.com>
Tue, 10 Nov 2020 13:21:26 +0000 (14:21 +0100)
committerChocobozzz <me@florianbigard.com>
Tue, 10 Nov 2020 13:21:26 +0000 (14:21 +0100)
client/src/app/+videos/+video-watch/video-watch.component.ts
client/src/assets/player/p2p-media-loader/segment-validator.ts
client/src/assets/player/peertube-player-manager.ts
client/src/standalone/videos/embed.ts

index 48623cae0d376573b0d5872264dac80a0281cfdc..66af9709dfcc8cfa5ceac2a2e606d77c5722c71d 100644 (file)
@@ -771,6 +771,8 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
           : null,
         embedUrl: video.embedUrl,
 
+        isLive: video.isLive,
+
         language: this.localeId,
 
         userWatching: user && user.videosHistoryEnabled === true ? {
index 9add3518459d0a5831584f69fabee2c654424c50..844956d6a6cb543ed441344af095dbfe91d9afb5 100644 (file)
@@ -6,11 +6,14 @@ type SegmentsJSON = { [filename: string]: string | { [byterange: string]: string
 
 const maxRetries = 3
 
-function segmentValidatorFactory (segmentsSha256Url: string) {
+function segmentValidatorFactory (segmentsSha256Url: string, isLive: boolean) {
   let segmentsJSON = fetchSha256Segments(segmentsSha256Url)
   const regex = /bytes=(\d+)-(\d+)/
 
   return async function segmentValidator (segment: Segment, retry = 1) {
+    // Wait for hash generation from the server
+    if (isLive) await wait(1000)
+
     const filename = basename(segment.url)
 
     const segmentValue = (await segmentsJSON)[filename]
@@ -20,10 +23,10 @@ function segmentValidatorFactory (segmentsSha256Url: string) {
     }
 
     if (!segmentValue) {
-      await wait(1000)
-
       console.log('Refetching sha segments for %s.', filename)
 
+      await wait(1000)
+
       segmentsJSON = fetchSha256Segments(segmentsSha256Url)
       await segmentValidator(segment, retry + 1)
 
index c1953043e354721fb53f843143ed7e94a23f1389..da23c59a749dad2a2a0b33b5018b7e47592c4850 100644 (file)
@@ -98,6 +98,8 @@ export interface CommonOptions extends CustomizationOptions {
   videoViewUrl: string
   embedUrl: string
 
+  isLive: boolean
+
   language?: string
 
   videoCaptions: VideoJSCaption[]
@@ -323,7 +325,7 @@ export class PeertubePlayerManager {
     const p2pMediaLoaderConfig = {
       loader: {
         trackerAnnounce,
-        segmentValidator: segmentValidatorFactory(options.p2pMediaLoader.segmentsSha256Url),
+        segmentValidator: segmentValidatorFactory(options.p2pMediaLoader.segmentsSha256Url, options.common.isLive),
         rtcConfig: getRtcConfig(),
         requiredSegmentsPriority: 1,
         segmentUrlBuilder: segmentUrlBuilderFactory(redundancyUrlManager),
index 9b07ef5e6684d8d54802be4c96272a65f73e7d20..66033158b6f63b8c7f6462550e240eff7dd6086f 100644 (file)
@@ -532,6 +532,8 @@ export class PeerTubeEmbed {
         inactivityTimeout: 2500,
         videoViewUrl: this.getVideoUrl(videoInfo.uuid) + '/views',
 
+        isLive: videoInfo.isLive,
+
         playerElement: this.playerElement,
         onPlayerElementChange: (element: HTMLVideoElement) => this.playerElement = element,