]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/live/live-utils.ts
Implement remote runner jobs in server
[github/Chocobozzz/PeerTube.git] / server / lib / live / live-utils.ts
index d2b8e3a55b8c1469f2e84b1c0f137e92f6a18da7..3fb3ce1cee998886f96f8f3dce6d0888b678f0dc 100644 (file)
@@ -1,9 +1,10 @@
 import { pathExists, readdir, remove } from 'fs-extra'
 import { basename, join } from 'path'
 import { logger } from '@server/helpers/logger'
+import { VIDEO_LIVE } from '@server/initializers/constants'
 import { MStreamingPlaylist, MStreamingPlaylistVideo, MVideo } from '@server/types/models'
-import { VideoStorage } from '@shared/models'
-import { listHLSFileKeysOf, removeHLSFileObjectStorage, removeHLSObjectStorage } from '../object-storage'
+import { LiveVideoLatencyMode, VideoStorage } from '@shared/models'
+import { listHLSFileKeysOf, removeHLSFileObjectStorageByFullKey, removeHLSObjectStorage } from '../object-storage'
 import { getLiveDirectory } from '../paths'
 
 function buildConcatenatedName (segmentOrPlaylistPath: string) {
@@ -37,10 +38,19 @@ async function cleanupTMPLiveFiles (video: MVideo, streamingPlaylist: MStreaming
   await cleanupTMPLiveFilesFromFilesystem(video)
 }
 
+function getLiveSegmentTime (latencyMode: LiveVideoLatencyMode) {
+  if (latencyMode === LiveVideoLatencyMode.SMALL_LATENCY) {
+    return VIDEO_LIVE.SEGMENT_TIME_SECONDS.SMALL_LATENCY
+  }
+
+  return VIDEO_LIVE.SEGMENT_TIME_SECONDS.DEFAULT_LATENCY
+}
+
 export {
   cleanupAndDestroyPermanentLive,
   cleanupUnsavedNormalLive,
   cleanupTMPLiveFiles,
+  getLiveSegmentTime,
   buildConcatenatedName
 }
 
@@ -77,11 +87,13 @@ async function cleanupTMPLiveFilesFromFilesystem (video: MVideo) {
 async function cleanupTMPLiveFilesFromObjectStorage (streamingPlaylist: MStreamingPlaylistVideo) {
   if (streamingPlaylist.storage !== VideoStorage.OBJECT_STORAGE) return
 
+  logger.info('Cleanup TMP live files from object storage for %s.', streamingPlaylist.Video.uuid)
+
   const keys = await listHLSFileKeysOf(streamingPlaylist)
 
   for (const key of keys) {
     if (isTMPLiveFile(key)) {
-      await removeHLSFileObjectStorage(streamingPlaylist, key)
+      await removeHLSFileObjectStorageByFullKey(key)
     }
   }
 }