From cfd57d2ca0bb058087f7dc90fcc3e8442b0288e1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 4 Oct 2022 10:03:17 +0200 Subject: Live supports object storage * Sync live files (segments, master playlist, resolution playlist, segment sha file) into object storage * Automatically delete them when the live ends * Segment sha file is now a file on disk, and not stored in memory anymore --- shared/server-commands/videos/live-command.ts | 60 ++++++++++++++++++---- .../videos/streaming-playlists-command.ts | 2 +- 2 files changed, 51 insertions(+), 11 deletions(-) (limited to 'shared/server-commands') diff --git a/shared/server-commands/videos/live-command.ts b/shared/server-commands/videos/live-command.ts index d804fd883..defae95fb 100644 --- a/shared/server-commands/videos/live-command.ts +++ b/shared/server-commands/videos/live-command.ts @@ -15,6 +15,7 @@ import { VideoState } from '@shared/models' import { unwrapBody } from '../requests' +import { ObjectStorageCommand } from '../server' import { AbstractCommand, OverrideCommandOptions } from '../shared' import { sendRTMPStream, testFfmpegStreamError } from './live' @@ -34,6 +35,8 @@ export class LiveCommand extends AbstractCommand { }) } + // --------------------------------------------------------------------------- + listSessions (options: OverrideCommandOptions & { videoId: number | string }) { @@ -70,6 +73,8 @@ export class LiveCommand extends AbstractCommand { }) } + // --------------------------------------------------------------------------- + update (options: OverrideCommandOptions & { videoId: number | string fields: LiveVideoUpdate @@ -110,6 +115,8 @@ export class LiveCommand extends AbstractCommand { return body.video } + // --------------------------------------------------------------------------- + async sendRTMPStreamInVideo (options: OverrideCommandOptions & { videoId: number | string fixtureName?: string @@ -130,6 +137,8 @@ export class LiveCommand extends AbstractCommand { return testFfmpegStreamError(command, options.shouldHaveError) } + // --------------------------------------------------------------------------- + waitUntilPublished (options: OverrideCommandOptions & { videoId: number | string }) { @@ -163,15 +172,34 @@ export class LiveCommand extends AbstractCommand { return this.server.servers.waitUntilLog(`${videoUUID}/${segmentName}`, totalSessions * 2, false) } - getSegment (options: OverrideCommandOptions & { + async waitUntilReplacedByReplay (options: OverrideCommandOptions & { + videoId: number | string + }) { + let video: VideoDetails + + do { + video = await this.server.videos.getWithToken({ token: options.token, id: options.videoId }) + + await wait(500) + } while (video.isLive === true || video.state.id !== VideoState.PUBLISHED) + } + + // --------------------------------------------------------------------------- + + getSegmentFile (options: OverrideCommandOptions & { videoUUID: string playlistNumber: number segment: number + objectStorage?: boolean // default false }) { - const { playlistNumber, segment, videoUUID } = options + const { playlistNumber, segment, videoUUID, objectStorage = false } = options const segmentName = `${playlistNumber}-00000${segment}.ts` - const url = `${this.server.url}/static/streaming-playlists/hls/${videoUUID}/${segmentName}` + const baseUrl = objectStorage + ? ObjectStorageCommand.getPlaylistBaseUrl() + : `${this.server.url}/static/streaming-playlists/hls` + + const url = `${baseUrl}/${videoUUID}/${segmentName}` return this.getRawRequest({ ...options, @@ -182,18 +210,30 @@ export class LiveCommand extends AbstractCommand { }) } - async waitUntilReplacedByReplay (options: OverrideCommandOptions & { - videoId: number | string + getPlaylistFile (options: OverrideCommandOptions & { + videoUUID: string + playlistName: string + objectStorage?: boolean // default false }) { - let video: VideoDetails + const { playlistName, videoUUID, objectStorage = false } = options - do { - video = await this.server.videos.getWithToken({ token: options.token, id: options.videoId }) + const baseUrl = objectStorage + ? ObjectStorageCommand.getPlaylistBaseUrl() + : `${this.server.url}/static/streaming-playlists/hls` - await wait(500) - } while (video.isLive === true || video.state.id !== VideoState.PUBLISHED) + const url = `${baseUrl}/${videoUUID}/${playlistName}` + + return this.getRawRequest({ + ...options, + + url, + implicitToken: false, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) } + // --------------------------------------------------------------------------- + async countPlaylists (options: OverrideCommandOptions & { videoUUID: string }) { diff --git a/shared/server-commands/videos/streaming-playlists-command.ts b/shared/server-commands/videos/streaming-playlists-command.ts index 5d40d35cb..7f923d001 100644 --- a/shared/server-commands/videos/streaming-playlists-command.ts +++ b/shared/server-commands/videos/streaming-playlists-command.ts @@ -16,7 +16,7 @@ export class StreamingPlaylistsCommand extends AbstractCommand { })) } - getSegment (options: OverrideCommandOptions & { + getFragmentedSegment (options: OverrideCommandOptions & { url: string range?: string }) { -- cgit v1.2.3