mirror of https://github.com/Chocobozzz/PeerTube
Fix concurrency issues when sendin chunks
parent
0ac25c0531
commit
c5255e784c
|
@ -268,41 +268,51 @@ export class ProcessLiveRTMPHLSTranscoding {
|
||||||
private async sendPendingChunks (): Promise<any> {
|
private async sendPendingChunks (): Promise<any> {
|
||||||
if (this.ended) return Promise.resolve()
|
if (this.ended) return Promise.resolve()
|
||||||
|
|
||||||
const promises: Promise<any>[] = []
|
const parallelPromises: Promise<any>[] = []
|
||||||
|
|
||||||
for (const playlist of this.pendingChunksPerPlaylist.keys()) {
|
for (const playlist of this.pendingChunksPerPlaylist.keys()) {
|
||||||
|
let sequentialPromises: Promise<any>
|
||||||
|
|
||||||
for (const chunk of this.pendingChunksPerPlaylist.get(playlist)) {
|
for (const chunk of this.pendingChunksPerPlaylist.get(playlist)) {
|
||||||
logger.debug(`Sending added live chunk ${chunk} update`)
|
logger.debug(`Sending added live chunk ${chunk} update`)
|
||||||
|
|
||||||
const videoChunkFilename = basename(chunk)
|
const videoChunkFilename = basename(chunk)
|
||||||
|
|
||||||
let payload: CustomLiveRTMPHLSTranscodingUpdatePayload = {
|
const payloadBuilder = async () => {
|
||||||
type: 'add-chunk',
|
let payload: CustomLiveRTMPHLSTranscodingUpdatePayload = {
|
||||||
videoChunkFilename,
|
type: 'add-chunk',
|
||||||
videoChunkFile: chunk
|
videoChunkFilename,
|
||||||
}
|
videoChunkFile: chunk
|
||||||
|
|
||||||
if (this.allPlaylistsCreated) {
|
|
||||||
const playlistName = this.getPlaylistName(videoChunkFilename)
|
|
||||||
|
|
||||||
await this.updatePlaylistContent(playlistName, videoChunkFilename)
|
|
||||||
|
|
||||||
payload = {
|
|
||||||
...payload,
|
|
||||||
|
|
||||||
masterPlaylistFile: join(this.outputPath, 'master.m3u8'),
|
|
||||||
resolutionPlaylistFilename: playlistName,
|
|
||||||
resolutionPlaylistFile: this.buildPlaylistFileParam(playlistName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.allPlaylistsCreated) {
|
||||||
|
const playlistName = this.getPlaylistName(videoChunkFilename)
|
||||||
|
|
||||||
|
await this.updatePlaylistContent(playlistName, videoChunkFilename)
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
...payload,
|
||||||
|
|
||||||
|
masterPlaylistFile: join(this.outputPath, 'master.m3u8'),
|
||||||
|
resolutionPlaylistFilename: playlistName,
|
||||||
|
resolutionPlaylistFile: this.buildPlaylistFileParam(playlistName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return payload
|
||||||
}
|
}
|
||||||
|
|
||||||
promises.push(this.updateWithRetry(payload))
|
const p = payloadBuilder().then(p => this.updateWithRetry(p))
|
||||||
|
|
||||||
|
if (!sequentialPromises) sequentialPromises = p
|
||||||
|
else sequentialPromises = sequentialPromises.then(() => p)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parallelPromises.push(sequentialPromises)
|
||||||
this.pendingChunksPerPlaylist.set(playlist, [])
|
this.pendingChunksPerPlaylist.set(playlist, [])
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all(promises)
|
await Promise.all(parallelPromises)
|
||||||
}
|
}
|
||||||
|
|
||||||
private async updateWithRetry (payload: CustomLiveRTMPHLSTranscodingUpdatePayload, currentTry = 1): Promise<any> {
|
private async updateWithRetry (payload: CustomLiveRTMPHLSTranscodingUpdatePayload, currentTry = 1): Promise<any> {
|
||||||
|
|
Loading…
Reference in New Issue