diff options
author | Chocobozzz <me@florianbigard.com> | 2023-03-07 11:47:42 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-03-07 11:47:42 +0100 |
commit | f967d8be4dd7bc806d9b9c2d848cdadbe6752c16 (patch) | |
tree | f3c65677107884a2f8687984096163c596497536 /client/src/assets/player/shared/p2p-media-loader | |
parent | 73fb3dc53571a6e94750a9d6cb5c2e949e1adcb9 (diff) | |
download | PeerTube-f967d8be4dd7bc806d9b9c2d848cdadbe6752c16.tar.gz PeerTube-f967d8be4dd7bc806d9b9c2d848cdadbe6752c16.tar.zst PeerTube-f967d8be4dd7bc806d9b9c2d848cdadbe6752c16.zip |
Fix live buffering with small latency
Diffstat (limited to 'client/src/assets/player/shared/p2p-media-loader')
-rw-r--r-- | client/src/assets/player/shared/p2p-media-loader/segment-validator.ts | 10 |
1 files changed, 3 insertions, 7 deletions
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 | ||
8 | type SegmentsJSON = { [filename: string]: string | { [byterange: string]: string } } | 8 | type SegmentsJSON = { [filename: string]: string | { [byterange: string]: string } } |
9 | 9 | ||
10 | const maxRetries = 3 | 10 | const maxRetries = 10 |
11 | 11 | ||
12 | function segmentValidatorFactory (options: { | 12 | function 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) |