]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/live/live-manager.ts
Fix live max rate
[github/Chocobozzz/PeerTube.git] / server / lib / live / live-manager.ts
index 41f89a2a494ee4efefd103b7ca9be1402e8dcbe6..aadd8e30829e61b63aede0a8a00891e77f0013f3 100644 (file)
@@ -4,7 +4,7 @@ import { createServer, Server } from 'net'
 import { join } from 'path'
 import { createServer as createServerTLS, Server as ServerTLS } from 'tls'
 import {
-  computeLowerResolutionsToTranscode,
+  computeResolutionsToTranscode,
   ffprobePromise,
   getLiveSegmentTime,
   getVideoStreamBitrate,
@@ -26,6 +26,7 @@ import { federateVideoIfNeeded } from '../activitypub/videos'
 import { JobQueue } from '../job-queue'
 import { generateHLSMasterPlaylistFilename, generateHlsSha256SegmentsFilename, getLiveReplayBaseDirectory } from '../paths'
 import { PeerTubeSocket } from '../peertube-socket'
+import { Hooks } from '../plugins/hooks'
 import { LiveQuotaStore } from './live-quota-store'
 import { cleanupPermanentLive } from './live-utils'
 import { MuxingSession } from './shared'
@@ -242,7 +243,11 @@ class LiveManager {
       inputUrl, Date.now() - now, bitrate, fps, resolution, lTags(sessionId, video.uuid)
     )
 
-    const allResolutions = this.buildAllResolutionsToTranscode(resolution)
+    const allResolutions = await Hooks.wrapObject(
+      this.buildAllResolutionsToTranscode(resolution),
+      'filter:transcoding.auto.resolutions-to-transcode.result',
+      { video }
+    )
 
     logger.info(
       'Will mux/transcode live video of original resolution %d.', resolution,
@@ -403,7 +408,7 @@ class LiveManager {
         await liveSession.save()
       }
 
-      JobQueue.Instance.createJob({
+      JobQueue.Instance.createJobAsync({
         type: 'video-live-ending',
         payload: {
           videoId: fullVideo.id,
@@ -416,8 +421,12 @@ class LiveManager {
           streamingPlaylistId: fullVideo.getHLSPlaylist()?.id,
 
           publishedAt: fullVideo.publishedAt.toISOString()
-        }
-      }, { delay: cleanupNow ? 0 : VIDEO_LIVE.CLEANUP_DELAY })
+        },
+
+        delay: cleanupNow
+          ? 0
+          : VIDEO_LIVE.CLEANUP_DELAY
+      })
 
       fullVideo.state = live.permanentLive
         ? VideoState.WAITING_FOR_LIVE
@@ -451,11 +460,17 @@ class LiveManager {
   }
 
   private buildAllResolutionsToTranscode (originResolution: number) {
+    const includeInput = CONFIG.LIVE.TRANSCODING.ALWAYS_TRANSCODE_ORIGINAL_RESOLUTION
+
     const resolutionsEnabled = CONFIG.LIVE.TRANSCODING.ENABLED
-      ? computeLowerResolutionsToTranscode(originResolution, 'live')
+      ? computeResolutionsToTranscode({ input: originResolution, type: 'live', includeInput, strictLower: false })
       : []
 
-    return resolutionsEnabled.concat([ originResolution ])
+    if (resolutionsEnabled.length === 0) {
+      return [ originResolution ]
+    }
+
+    return resolutionsEnabled
   }
 
   private async createLivePlaylist (video: MVideo, allResolutions: number[]): Promise<MStreamingPlaylistVideo> {