Fix live buffering with small latency
This commit is contained in:
parent
73fb3dc535
commit
f967d8be4d
|
@ -96,7 +96,6 @@ export class HLSOptionsBuilder {
|
||||||
|
|
||||||
segmentValidator: segmentValidatorFactory({
|
segmentValidator: segmentValidatorFactory({
|
||||||
segmentsSha256Url: this.options.p2pMediaLoader.segmentsSha256Url,
|
segmentsSha256Url: this.options.p2pMediaLoader.segmentsSha256Url,
|
||||||
isLive: this.options.common.isLive,
|
|
||||||
authorizationHeader: this.options.common.authorizationHeader,
|
authorizationHeader: this.options.common.authorizationHeader,
|
||||||
requiresAuth: this.options.common.requiresAuth,
|
requiresAuth: this.options.common.requiresAuth,
|
||||||
serverUrl: this.options.common.serverUrl
|
serverUrl: this.options.common.serverUrl
|
||||||
|
@ -129,7 +128,7 @@ export class HLSOptionsBuilder {
|
||||||
...base,
|
...base,
|
||||||
|
|
||||||
useP2P: false,
|
useP2P: false,
|
||||||
httpDownloadProbability: 1
|
requiredSegmentsPriority: 10
|
||||||
}
|
}
|
||||||
|
|
||||||
case LiveVideoLatencyMode.HIGH_LATENCY:
|
case LiveVideoLatencyMode.HIGH_LATENCY:
|
||||||
|
|
|
@ -7,24 +7,20 @@ import { isSameOrigin } from '../common'
|
||||||
|
|
||||||
type SegmentsJSON = { [filename: string]: string | { [byterange: string]: string } }
|
type SegmentsJSON = { [filename: string]: string | { [byterange: string]: string } }
|
||||||
|
|
||||||
const maxRetries = 3
|
const maxRetries = 10
|
||||||
|
|
||||||
function segmentValidatorFactory (options: {
|
function segmentValidatorFactory (options: {
|
||||||
serverUrl: string
|
serverUrl: string
|
||||||
segmentsSha256Url: string
|
segmentsSha256Url: string
|
||||||
isLive: boolean
|
|
||||||
authorizationHeader: () => string
|
authorizationHeader: () => string
|
||||||
requiresAuth: boolean
|
requiresAuth: boolean
|
||||||
}) {
|
}) {
|
||||||
const { serverUrl, segmentsSha256Url, isLive, authorizationHeader, requiresAuth } = options
|
const { serverUrl, segmentsSha256Url, authorizationHeader, requiresAuth } = options
|
||||||
|
|
||||||
let segmentsJSON = fetchSha256Segments({ serverUrl, segmentsSha256Url, authorizationHeader, requiresAuth })
|
let segmentsJSON = fetchSha256Segments({ serverUrl, segmentsSha256Url, authorizationHeader, requiresAuth })
|
||||||
const regex = /bytes=(\d+)-(\d+)/
|
const regex = /bytes=(\d+)-(\d+)/
|
||||||
|
|
||||||
return async function segmentValidator (segment: Segment, _method: string, _peerId: string, retry = 1) {
|
return async function segmentValidator (segment: Segment, _method: string, _peerId: string, retry = 1) {
|
||||||
// Wait for hash generation from the server
|
|
||||||
if (isLive) await wait(1000)
|
|
||||||
|
|
||||||
const filename = basename(removeQueryParams(segment.url))
|
const filename = basename(removeQueryParams(segment.url))
|
||||||
|
|
||||||
const segmentValue = (await segmentsJSON)[filename]
|
const segmentValue = (await segmentsJSON)[filename]
|
||||||
|
@ -36,7 +32,7 @@ function segmentValidatorFactory (options: {
|
||||||
if (!segmentValue) {
|
if (!segmentValue) {
|
||||||
logger.info(`Refetching sha segments for ${filename}`)
|
logger.info(`Refetching sha segments for ${filename}`)
|
||||||
|
|
||||||
await wait(1000)
|
await wait(500)
|
||||||
|
|
||||||
segmentsJSON = fetchSha256Segments({ serverUrl, segmentsSha256Url, authorizationHeader, requiresAuth })
|
segmentsJSON = fetchSha256Segments({ serverUrl, segmentsSha256Url, authorizationHeader, requiresAuth })
|
||||||
await segmentValidator(segment, _method, _peerId, retry + 1)
|
await segmentValidator(segment, _method, _peerId, retry + 1)
|
||||||
|
|
Loading…
Reference in New Issue