Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Fix live ending when using remote runners

Chocobozzzac0bf9075871
diff --git a/apps/peertube-runner/src/server/process/shared/process-live.ts b/apps/peertube-runner/src/server/process/shared/process-live.ts
index d3272b346c..7cf4f76567 100644
--- a/apps/peertube-runner/src/server/process/shared/process-live.ts
+++ b/apps/peertube-runner/src/server/process/shared/process-live.ts
@@ -223,11 +223,13 @@ export class ProcessLiveRTMPHLSTranscoding {
private async onFFmpegEnded () {
if (this.ended) return
- this.ended = true
logger.info('FFmpeg ended, sending success to server')
// Wait last ffmpeg chunks generation
await wait(1500)
+ await this.sendPendingChunks()
+
+ this.ended = true
this.sendSuccess()
.catch(err => logger.error({ err }, 'Cannot send success'))
@@ -360,11 +362,17 @@ export class ProcessLiveRTMPHLSTranscoding {
private async updatePlaylistContent (playlistName: string, latestChunkFilename: string) {
const m3u8Path = join(this.outputPath, playlistName)
- const playlistContent = await readFile(m3u8Path, 'utf-8')
+ let playlistContent = await readFile(m3u8Path, 'utf-8')
+
+ if (!playlistContent.includes('#EXT-X-ENDLIST')) {
+ playlistContent = playlistContent.substring(
+ 0,
+ playlistContent.lastIndexOf(latestChunkFilename) + latestChunkFilename.length
+ ) + '\n'
+ }
// Remove new chunk references, that will be processed later
this.latestFilteredPlaylistContent[playlistName] = playlistContent
- .substring(0, playlistContent.lastIndexOf(latestChunkFilename) + latestChunkFilename.length) + '\n'
}
private buildPlaylistFileParam (playlistName: string) {
diff --git a/server/core/middlewares/validators/runners/jobs.ts b/server/core/middlewares/validators/runners/jobs.ts
index 9110fce39c..8d95e516ff 100644
--- a/server/core/middlewares/validators/runners/jobs.ts
+++ b/server/core/middlewares/validators/runners/jobs.ts
@@ -1,7 +1,6 @@
import { arrayify } from '@peertube/peertube-core-utils'
import {
HttpStatusCode,
- RunnerJobLiveRTMPHLSTranscodingPrivatePayload,
RunnerJobState,
RunnerJobStateType,
RunnerJobSuccessBody,
@@ -20,7 +19,6 @@ import {
} from '@server/helpers/custom-validators/runners/jobs.js'
import { isRunnerTokenValid } from '@server/helpers/custom-validators/runners/runners.js'
import { cleanUpReqFiles } from '@server/helpers/express-utils.js'
-import { LiveManager } from '@server/lib/live/index.js'
import { runnerJobCanBeCancelled } from '@server/lib/runners/index.js'
import { RunnerJobModel } from '@server/models/runner/runner-job.js'
import express from 'express'
@@ -72,21 +70,6 @@ export const updateRunnerJobValidator = [
})
}
- if (res.locals.runnerJob.type === 'live-rtmp-hls-transcoding') {
- const privatePayload = job.privatePayload as RunnerJobLiveRTMPHLSTranscodingPrivatePayload
-
- if (!LiveManager.Instance.hasSession(privatePayload.sessionId)) {
- cleanUpReqFiles(req)
-
- return res.fail({
- status: HttpStatusCode.BAD_REQUEST_400,
- type: ServerErrorCode.RUNNER_JOB_NOT_IN_PROCESSING_STATE,
- message: 'Session of this live ended',
- tags
- })
- }
- }
-
return next()
}
]