diff options
author | Chocobozzz <me@florianbigard.com> | 2022-10-04 10:03:17 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-10-04 10:03:17 +0200 |
commit | cfd57d2ca0bb058087f7dc90fcc3e8442b0288e1 (patch) | |
tree | dc899a1504ecac588e5580553e02571e0f5d7e4b /server/lib/job-queue/handlers | |
parent | 9c0cdc5047918b959ebd5e075ddad81eb7fb93f0 (diff) | |
download | PeerTube-cfd57d2ca0bb058087f7dc90fcc3e8442b0288e1.tar.gz PeerTube-cfd57d2ca0bb058087f7dc90fcc3e8442b0288e1.tar.zst PeerTube-cfd57d2ca0bb058087f7dc90fcc3e8442b0288e1.zip |
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
Diffstat (limited to 'server/lib/job-queue/handlers')
-rw-r--r-- | server/lib/job-queue/handlers/move-to-object-storage.ts | 10 | ||||
-rw-r--r-- | server/lib/job-queue/handlers/video-live-ending.ts | 23 |
2 files changed, 16 insertions, 17 deletions
diff --git a/server/lib/job-queue/handlers/move-to-object-storage.ts b/server/lib/job-queue/handlers/move-to-object-storage.ts index 25bdebeea..28c3d325d 100644 --- a/server/lib/job-queue/handlers/move-to-object-storage.ts +++ b/server/lib/job-queue/handlers/move-to-object-storage.ts | |||
@@ -5,7 +5,7 @@ import { logger, loggerTagsFactory } from '@server/helpers/logger' | |||
5 | import { updateTorrentMetadata } from '@server/helpers/webtorrent' | 5 | import { updateTorrentMetadata } from '@server/helpers/webtorrent' |
6 | import { CONFIG } from '@server/initializers/config' | 6 | import { CONFIG } from '@server/initializers/config' |
7 | import { P2P_MEDIA_LOADER_PEER_VERSION } from '@server/initializers/constants' | 7 | import { P2P_MEDIA_LOADER_PEER_VERSION } from '@server/initializers/constants' |
8 | import { storeHLSFile, storeWebTorrentFile } from '@server/lib/object-storage' | 8 | import { storeHLSFileFromFilename, storeWebTorrentFile } from '@server/lib/object-storage' |
9 | import { getHLSDirectory, getHlsResolutionPlaylistFilename } from '@server/lib/paths' | 9 | import { getHLSDirectory, getHlsResolutionPlaylistFilename } from '@server/lib/paths' |
10 | import { moveToFailedMoveToObjectStorageState, moveToNextState } from '@server/lib/video-state' | 10 | import { moveToFailedMoveToObjectStorageState, moveToNextState } from '@server/lib/video-state' |
11 | import { VideoModel } from '@server/models/video/video' | 11 | import { VideoModel } from '@server/models/video/video' |
@@ -88,10 +88,10 @@ async function moveHLSFiles (video: MVideoWithAllFiles) { | |||
88 | 88 | ||
89 | // Resolution playlist | 89 | // Resolution playlist |
90 | const playlistFilename = getHlsResolutionPlaylistFilename(file.filename) | 90 | const playlistFilename = getHlsResolutionPlaylistFilename(file.filename) |
91 | await storeHLSFile(playlistWithVideo, playlistFilename) | 91 | await storeHLSFileFromFilename(playlistWithVideo, playlistFilename) |
92 | 92 | ||
93 | // Resolution fragmented file | 93 | // Resolution fragmented file |
94 | const fileUrl = await storeHLSFile(playlistWithVideo, file.filename) | 94 | const fileUrl = await storeHLSFileFromFilename(playlistWithVideo, file.filename) |
95 | 95 | ||
96 | const oldPath = join(getHLSDirectory(video), file.filename) | 96 | const oldPath = join(getHLSDirectory(video), file.filename) |
97 | 97 | ||
@@ -113,9 +113,9 @@ async function doAfterLastJob (options: { | |||
113 | const playlistWithVideo = playlist.withVideo(video) | 113 | const playlistWithVideo = playlist.withVideo(video) |
114 | 114 | ||
115 | // Master playlist | 115 | // Master playlist |
116 | playlist.playlistUrl = await storeHLSFile(playlistWithVideo, playlist.playlistFilename) | 116 | playlist.playlistUrl = await storeHLSFileFromFilename(playlistWithVideo, playlist.playlistFilename) |
117 | // Sha256 segments file | 117 | // Sha256 segments file |
118 | playlist.segmentsSha256Url = await storeHLSFile(playlistWithVideo, playlist.segmentsSha256Filename) | 118 | playlist.segmentsSha256Url = await storeHLSFileFromFilename(playlistWithVideo, playlist.segmentsSha256Filename) |
119 | 119 | ||
120 | playlist.storage = VideoStorage.OBJECT_STORAGE | 120 | playlist.storage = VideoStorage.OBJECT_STORAGE |
121 | 121 | ||
diff --git a/server/lib/job-queue/handlers/video-live-ending.ts b/server/lib/job-queue/handlers/video-live-ending.ts index 8a3ee09a2..abfaf1cd7 100644 --- a/server/lib/job-queue/handlers/video-live-ending.ts +++ b/server/lib/job-queue/handlers/video-live-ending.ts | |||
@@ -4,7 +4,7 @@ import { join } from 'path' | |||
4 | import { ffprobePromise, getAudioStream, getVideoStreamDimensionsInfo } from '@server/helpers/ffmpeg' | 4 | import { ffprobePromise, getAudioStream, getVideoStreamDimensionsInfo } from '@server/helpers/ffmpeg' |
5 | import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url' | 5 | import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url' |
6 | import { federateVideoIfNeeded } from '@server/lib/activitypub/videos' | 6 | import { federateVideoIfNeeded } from '@server/lib/activitypub/videos' |
7 | import { cleanupPermanentLive, cleanupTMPLiveFiles, cleanupUnsavedNormalLive } from '@server/lib/live' | 7 | import { cleanupAndDestroyPermanentLive, cleanupTMPLiveFiles, cleanupUnsavedNormalLive } from '@server/lib/live' |
8 | import { generateHLSMasterPlaylistFilename, generateHlsSha256SegmentsFilename, getLiveReplayBaseDirectory } from '@server/lib/paths' | 8 | import { generateHLSMasterPlaylistFilename, generateHlsSha256SegmentsFilename, getLiveReplayBaseDirectory } from '@server/lib/paths' |
9 | import { generateVideoMiniature } from '@server/lib/thumbnail' | 9 | import { generateVideoMiniature } from '@server/lib/thumbnail' |
10 | import { generateHlsPlaylistResolutionFromTS } from '@server/lib/transcoding/transcoding' | 10 | import { generateHlsPlaylistResolutionFromTS } from '@server/lib/transcoding/transcoding' |
@@ -141,23 +141,22 @@ async function replaceLiveByReplay (options: { | |||
141 | }) { | 141 | }) { |
142 | const { video, liveSession, live, permanentLive, replayDirectory } = options | 142 | const { video, liveSession, live, permanentLive, replayDirectory } = options |
143 | 143 | ||
144 | await cleanupTMPLiveFiles(video) | 144 | const videoWithFiles = await VideoModel.loadFull(video.id) |
145 | const hlsPlaylist = videoWithFiles.getHLSPlaylist() | ||
146 | |||
147 | await cleanupTMPLiveFiles(videoWithFiles, hlsPlaylist) | ||
145 | 148 | ||
146 | await live.destroy() | 149 | await live.destroy() |
147 | 150 | ||
148 | video.isLive = false | 151 | videoWithFiles.isLive = false |
149 | video.waitTranscoding = true | 152 | videoWithFiles.waitTranscoding = true |
150 | video.state = VideoState.TO_TRANSCODE | 153 | videoWithFiles.state = VideoState.TO_TRANSCODE |
151 | 154 | ||
152 | await video.save() | 155 | await videoWithFiles.save() |
153 | 156 | ||
154 | liveSession.replayVideoId = video.id | 157 | liveSession.replayVideoId = videoWithFiles.id |
155 | await liveSession.save() | 158 | await liveSession.save() |
156 | 159 | ||
157 | // Remove old HLS playlist video files | ||
158 | const videoWithFiles = await VideoModel.loadFull(video.id) | ||
159 | |||
160 | const hlsPlaylist = videoWithFiles.getHLSPlaylist() | ||
161 | await VideoFileModel.removeHLSFilesOfVideoId(hlsPlaylist.id) | 160 | await VideoFileModel.removeHLSFilesOfVideoId(hlsPlaylist.id) |
162 | 161 | ||
163 | // Reset playlist | 162 | // Reset playlist |
@@ -234,7 +233,7 @@ async function cleanupLiveAndFederate (options: { | |||
234 | 233 | ||
235 | if (streamingPlaylist) { | 234 | if (streamingPlaylist) { |
236 | if (permanentLive) { | 235 | if (permanentLive) { |
237 | await cleanupPermanentLive(video, streamingPlaylist) | 236 | await cleanupAndDestroyPermanentLive(video, streamingPlaylist) |
238 | } else { | 237 | } else { |
239 | await cleanupUnsavedNormalLive(video, streamingPlaylist) | 238 | await cleanupUnsavedNormalLive(video, streamingPlaylist) |
240 | } | 239 | } |