diff options
author | Chocobozzz <me@florianbigard.com> | 2020-11-17 12:09:25 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-11-17 14:05:15 +0100 |
commit | 6bff8ce23ac9a2de8c6ddcea9df5f7bd2b653156 (patch) | |
tree | 9a49590338dc84b360ae328be9685f6fc8006c03 /server | |
parent | f3081d6401b63da41b03376f9f952bf1cca8303d (diff) | |
download | PeerTube-6bff8ce23ac9a2de8c6ddcea9df5f7bd2b653156.tar.gz PeerTube-6bff8ce23ac9a2de8c6ddcea9df5f7bd2b653156.tar.zst PeerTube-6bff8ce23ac9a2de8c6ddcea9df5f7bd2b653156.zip |
Process remaining segment hashes on live ending
Diffstat (limited to 'server')
-rw-r--r-- | server/lib/live-manager.ts | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/server/lib/live-manager.ts b/server/lib/live-manager.ts index fe5b33322..feb6c5275 100644 --- a/server/lib/live-manager.ts +++ b/server/lib/live-manager.ts | |||
@@ -280,15 +280,21 @@ class LiveManager { | |||
280 | const segmentsToProcessPerPlaylist: { [playlistId: string]: string[] } = {} | 280 | const segmentsToProcessPerPlaylist: { [playlistId: string]: string[] } = {} |
281 | const playlistIdMatcher = /^([\d+])-/ | 281 | const playlistIdMatcher = /^([\d+])-/ |
282 | 282 | ||
283 | const addHandler = segmentPath => { | 283 | const processHashSegments = (segmentsToProcess: string[]) => { |
284 | const playlistId = basename(segmentPath).match(playlistIdMatcher)[0] | ||
285 | const segmentsToProcess = segmentsToProcessPerPlaylist[playlistId] || [] | ||
286 | |||
287 | // Add sha hash of previous segments, because ffmpeg should have finished generating them | 284 | // Add sha hash of previous segments, because ffmpeg should have finished generating them |
288 | for (const previousSegment of segmentsToProcess) { | 285 | for (const previousSegment of segmentsToProcess) { |
289 | this.addSegmentSha(videoUUID, previousSegment) | 286 | this.addSegmentSha(videoUUID, previousSegment) |
290 | .catch(err => logger.error('Cannot add sha segment of video %s -> %s.', videoUUID, previousSegment, { err })) | 287 | .catch(err => logger.error('Cannot add sha segment of video %s -> %s.', videoUUID, previousSegment, { err })) |
291 | } | 288 | } |
289 | } | ||
290 | |||
291 | const addHandler = segmentPath => { | ||
292 | logger.debug('Live add handler of %s.', segmentPath) | ||
293 | |||
294 | const playlistId = basename(segmentPath).match(playlistIdMatcher)[0] | ||
295 | |||
296 | const segmentsToProcess = segmentsToProcessPerPlaylist[playlistId] || [] | ||
297 | processHashSegments(segmentsToProcess) | ||
292 | 298 | ||
293 | segmentsToProcessPerPlaylist[playlistId] = [ segmentPath ] | 299 | segmentsToProcessPerPlaylist[playlistId] = [ segmentPath ] |
294 | 300 | ||
@@ -352,11 +358,21 @@ class LiveManager { | |||
352 | this.transSessions.delete(sessionId) | 358 | this.transSessions.delete(sessionId) |
353 | this.watchersPerVideo.delete(videoLive.videoId) | 359 | this.watchersPerVideo.delete(videoLive.videoId) |
354 | 360 | ||
355 | Promise.all([ tsWatcher.close(), masterWatcher.close() ]) | 361 | setTimeout(() => { |
356 | .catch(err => logger.error('Cannot close watchers of %s.', outPath, { err })) | 362 | // Wait latest segments generation, and close watchers |
357 | 363 | ||
358 | this.onEndTransmuxing(videoLive.Video.id) | 364 | Promise.all([ tsWatcher.close(), masterWatcher.close() ]) |
359 | .catch(err => logger.error('Error in closed transmuxing.', { err })) | 365 | .then(() => { |
366 | // Process remaining segments hash | ||
367 | for (const key of Object.keys(segmentsToProcessPerPlaylist)) { | ||
368 | processHashSegments(segmentsToProcessPerPlaylist[key]) | ||
369 | } | ||
370 | }) | ||
371 | .catch(err => logger.error('Cannot close watchers of %s or process remaining hash segments.', outPath, { err })) | ||
372 | |||
373 | this.onEndTransmuxing(videoLive.Video.id) | ||
374 | .catch(err => logger.error('Error in closed transmuxing.', { err })) | ||
375 | }, 1000) | ||
360 | } | 376 | } |
361 | 377 | ||
362 | ffmpegExec.on('error', (err, stdout, stderr) => { | 378 | ffmpegExec.on('error', (err, stdout, stderr) => { |