diff options
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) => { |