Skip to content

Commit

Permalink
Fix live ending when using remote runners
Browse files Browse the repository at this point in the history
  • Loading branch information
Chocobozzz committed Feb 11, 2025
1 parent 66023f9 commit ac0bf90
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
14 changes: 11 additions & 3 deletions apps/peertube-runner/src/server/process/shared/process-live.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down Expand Up @@ -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) {
Expand Down
17 changes: 0 additions & 17 deletions server/core/middlewares/validators/runners/jobs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { arrayify } from '@peertube/peertube-core-utils'
import {
HttpStatusCode,
RunnerJobLiveRTMPHLSTranscodingPrivatePayload,
RunnerJobState,
RunnerJobStateType,
RunnerJobSuccessBody,
Expand All @@ -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'
Expand Down Expand Up @@ -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()
}
]
Expand Down

0 comments on commit ac0bf90

Please sign in to comment.