aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-03-07 11:47:42 +0100
committerChocobozzz <me@florianbigard.com>2023-03-07 11:47:42 +0100
commitf967d8be4dd7bc806d9b9c2d848cdadbe6752c16 (patch)
treef3c65677107884a2f8687984096163c596497536 /client/src/assets
parent73fb3dc53571a6e94750a9d6cb5c2e949e1adcb9 (diff)
downloadPeerTube-f967d8be4dd7bc806d9b9c2d848cdadbe6752c16.tar.gz
PeerTube-f967d8be4dd7bc806d9b9c2d848cdadbe6752c16.tar.zst
PeerTube-f967d8be4dd7bc806d9b9c2d848cdadbe6752c16.zip
Fix live buffering with small latency
Diffstat (limited to 'client/src/assets')
-rw-r--r--client/src/assets/player/shared/manager-options/hls-options-builder.ts3
-rw-r--r--client/src/assets/player/shared/p2p-media-loader/segment-validator.ts10
2 files changed, 4 insertions, 9 deletions
diff --git a/client/src/assets/player/shared/manager-options/hls-options-builder.ts b/client/src/assets/player/shared/manager-options/hls-options-builder.ts
index 63e9fa8c8..194991fa4 100644
--- a/client/src/assets/player/shared/manager-options/hls-options-builder.ts
+++ b/client/src/assets/player/shared/manager-options/hls-options-builder.ts
@@ -96,7 +96,6 @@ export class HLSOptionsBuilder {
96 96
97 segmentValidator: segmentValidatorFactory({ 97 segmentValidator: segmentValidatorFactory({
98 segmentsSha256Url: this.options.p2pMediaLoader.segmentsSha256Url, 98 segmentsSha256Url: this.options.p2pMediaLoader.segmentsSha256Url,
99 isLive: this.options.common.isLive,
100 authorizationHeader: this.options.common.authorizationHeader, 99 authorizationHeader: this.options.common.authorizationHeader,
101 requiresAuth: this.options.common.requiresAuth, 100 requiresAuth: this.options.common.requiresAuth,
102 serverUrl: this.options.common.serverUrl 101 serverUrl: this.options.common.serverUrl
@@ -129,7 +128,7 @@ export class HLSOptionsBuilder {
129 ...base, 128 ...base,
130 129
131 useP2P: false, 130 useP2P: false,
132 httpDownloadProbability: 1 131 requiredSegmentsPriority: 10
133 } 132 }
134 133
135 case LiveVideoLatencyMode.HIGH_LATENCY: 134 case LiveVideoLatencyMode.HIGH_LATENCY:
diff --git a/client/src/assets/player/shared/p2p-media-loader/segment-validator.ts b/client/src/assets/player/shared/p2p-media-loader/segment-validator.ts
index 3c76d63f7..6e9bcf103 100644
--- a/client/src/assets/player/shared/p2p-media-loader/segment-validator.ts
+++ b/client/src/assets/player/shared/p2p-media-loader/segment-validator.ts
@@ -7,24 +7,20 @@ import { isSameOrigin } from '../common'
7 7
8type SegmentsJSON = { [filename: string]: string | { [byterange: string]: string } } 8type SegmentsJSON = { [filename: string]: string | { [byterange: string]: string } }
9 9
10const maxRetries = 3 10const maxRetries = 10
11 11
12function segmentValidatorFactory (options: { 12function segmentValidatorFactory (options: {
13 serverUrl: string 13 serverUrl: string
14 segmentsSha256Url: string 14 segmentsSha256Url: string
15 isLive: boolean
16 authorizationHeader: () => string 15 authorizationHeader: () => string
17 requiresAuth: boolean 16 requiresAuth: boolean
18}) { 17}) {
19 const { serverUrl, segmentsSha256Url, isLive, authorizationHeader, requiresAuth } = options 18 const { serverUrl, segmentsSha256Url, authorizationHeader, requiresAuth } = options
20 19
21 let segmentsJSON = fetchSha256Segments({ serverUrl, segmentsSha256Url, authorizationHeader, requiresAuth }) 20 let segmentsJSON = fetchSha256Segments({ serverUrl, segmentsSha256Url, authorizationHeader, requiresAuth })
22 const regex = /bytes=(\d+)-(\d+)/ 21 const regex = /bytes=(\d+)-(\d+)/
23 22
24 return async function segmentValidator (segment: Segment, _method: string, _peerId: string, retry = 1) { 23 return async function segmentValidator (segment: Segment, _method: string, _peerId: string, retry = 1) {
25 // Wait for hash generation from the server
26 if (isLive) await wait(1000)
27
28 const filename = basename(removeQueryParams(segment.url)) 24 const filename = basename(removeQueryParams(segment.url))
29 25
30 const segmentValue = (await segmentsJSON)[filename] 26 const segmentValue = (await segmentsJSON)[filename]
@@ -36,7 +32,7 @@ function segmentValidatorFactory (options: {
36 if (!segmentValue) { 32 if (!segmentValue) {
37 logger.info(`Refetching sha segments for ${filename}`) 33 logger.info(`Refetching sha segments for ${filename}`)
38 34
39 await wait(1000) 35 await wait(500)
40 36
41 segmentsJSON = fetchSha256Segments({ serverUrl, segmentsSha256Url, authorizationHeader, requiresAuth }) 37 segmentsJSON = fetchSha256Segments({ serverUrl, segmentsSha256Url, authorizationHeader, requiresAuth })
42 await segmentValidator(segment, _method, _peerId, retry + 1) 38 await segmentValidator(segment, _method, _peerId, retry + 1)