From 17ecdf61ce1d374cc8ba17601b93c9bda08112b2 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 22 May 2023 13:44:22 +0200 Subject: Force stop remote live transcoding --- server/lib/live/live-manager.ts | 4 ++++ server/lib/live/shared/muxing-session.ts | 1 + .../abstract-transcoding-wrapper.ts | 3 +++ .../remote-transcoding-wrapper.ts | 1 + .../live-rtmp-hls-transcoding-job-handler.ts | 4 +++- server/middlewares/validators/runners/jobs.ts | 27 ++++++++++++++++++++-- server/tests/api/live/live-constraints.ts | 2 +- server/tests/api/search/search-videos.ts | 2 +- 8 files changed, 39 insertions(+), 5 deletions(-) (limited to 'server') diff --git a/server/lib/live/live-manager.ts b/server/lib/live/live-manager.ts index 68aa18443..f062e2fd3 100644 --- a/server/lib/live/live-manager.ts +++ b/server/lib/live/live-manager.ts @@ -178,6 +178,10 @@ class LiveManager { return !!this.rtmpServer } + hasSession (sessionId: string) { + return this.getContext().sessions.has(sessionId) + } + stopSessionOf (videoUUID: string, error: LiveVideoError | null) { const sessionId = this.videoSessions.get(videoUUID) if (!sessionId) { diff --git a/server/lib/live/shared/muxing-session.ts b/server/lib/live/shared/muxing-session.ts index 6632499ff..c672ec4d6 100644 --- a/server/lib/live/shared/muxing-session.ts +++ b/server/lib/live/shared/muxing-session.ts @@ -477,6 +477,7 @@ class MuxingSession extends EventEmitter { lTags: this.lTags, + sessionId: this.sessionId, inputLocalUrl: this.inputLocalUrl, inputPublicUrl: this.inputPublicUrl, diff --git a/server/lib/live/shared/transcoding-wrapper/abstract-transcoding-wrapper.ts b/server/lib/live/shared/transcoding-wrapper/abstract-transcoding-wrapper.ts index ee61d7690..95168745d 100644 --- a/server/lib/live/shared/transcoding-wrapper/abstract-transcoding-wrapper.ts +++ b/server/lib/live/shared/transcoding-wrapper/abstract-transcoding-wrapper.ts @@ -25,6 +25,7 @@ interface AbstractTranscodingWrapperOptions { lTags: LoggerTagsFn + sessionId: string inputLocalUrl: string inputPublicUrl: string @@ -52,6 +53,7 @@ abstract class AbstractTranscodingWrapper extends EventEmitter { fps: number }[] + protected readonly sessionId: string protected readonly inputLocalUrl: string protected readonly inputPublicUrl: string @@ -80,6 +82,7 @@ abstract class AbstractTranscodingWrapper extends EventEmitter { this.videoUUID = options.videoLive.Video.uuid this.streamingPlaylist = options.streamingPlaylist + this.sessionId = options.sessionId this.inputLocalUrl = options.inputLocalUrl this.inputPublicUrl = options.inputPublicUrl diff --git a/server/lib/live/shared/transcoding-wrapper/remote-transcoding-wrapper.ts b/server/lib/live/shared/transcoding-wrapper/remote-transcoding-wrapper.ts index 6770a5e6f..2aeeb31fb 100644 --- a/server/lib/live/shared/transcoding-wrapper/remote-transcoding-wrapper.ts +++ b/server/lib/live/shared/transcoding-wrapper/remote-transcoding-wrapper.ts @@ -5,6 +5,7 @@ export class RemoteTranscodingWrapper extends AbstractTranscodingWrapper { async run () { await new LiveRTMPHLSTranscodingJobHandler().create({ rtmpUrl: this.inputPublicUrl, + sessionId: this.sessionId, toTranscode: this.toTranscode, video: this.videoLive.Video, outputDirectory: this.outDirectory, diff --git a/server/lib/runners/job-handlers/live-rtmp-hls-transcoding-job-handler.ts b/server/lib/runners/job-handlers/live-rtmp-hls-transcoding-job-handler.ts index 87b6f0702..6b2894f8c 100644 --- a/server/lib/runners/job-handlers/live-rtmp-hls-transcoding-job-handler.ts +++ b/server/lib/runners/job-handlers/live-rtmp-hls-transcoding-job-handler.ts @@ -20,6 +20,7 @@ type CreateOptions = { video: MVideo playlist: MStreamingPlaylist + sessionId: string rtmpUrl: string toTranscode: { @@ -37,7 +38,7 @@ type CreateOptions = { export class LiveRTMPHLSTranscodingJobHandler extends AbstractJobHandler { async create (options: CreateOptions) { - const { video, rtmpUrl, toTranscode, playlist, segmentDuration, segmentListSize, outputDirectory } = options + const { video, rtmpUrl, toTranscode, playlist, segmentDuration, segmentListSize, outputDirectory, sessionId } = options const jobUUID = buildUUID() const payload: RunnerJobLiveRTMPHLSTranscodingPayload = { @@ -54,6 +55,7 @@ export class LiveRTMPHLSTranscodingJobHandler extends AbstractJobHandler