X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Flive%2Flive-manager.ts;h=9ea9831198435c4c90256f1eb4c5373e3195daf5;hb=54db8e3d5c09fedc82d8421529c81255760a5ac2;hp=1410889a2dc1ba31f7419d4630c124911d573a70;hpb=5e2afe4290103bf0d54ae7b3e62781f2a00487c9;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/live/live-manager.ts b/server/lib/live/live-manager.ts index 1410889a2..9ea983119 100644 --- a/server/lib/live/live-manager.ts +++ b/server/lib/live/live-manager.ts @@ -1,4 +1,3 @@ - import { readdir, readFile } from 'fs-extra' import { createServer, Server } from 'net' import { join } from 'path' @@ -9,7 +8,8 @@ import { getLiveSegmentTime, getVideoStreamBitrate, getVideoStreamDimensionsInfo, - getVideoStreamFPS + getVideoStreamFPS, + hasAudioStream } from '@server/helpers/ffmpeg' import { logger, loggerTagsFactory } from '@server/helpers/logger' import { CONFIG, registerConfigChangedHandler } from '@server/initializers/config' @@ -20,15 +20,15 @@ import { VideoLiveModel } from '@server/models/video/video-live' import { VideoLiveSessionModel } from '@server/models/video/video-live-session' import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist' import { MStreamingPlaylistVideo, MVideo, MVideoLiveSession, MVideoLiveVideo } from '@server/types/models' -import { wait } from '@shared/core-utils' -import { LiveVideoError, VideoState, VideoStreamingPlaylistType } from '@shared/models' +import { pick, wait } from '@shared/core-utils' +import { LiveVideoError, VideoState, VideoStorage, VideoStreamingPlaylistType } from '@shared/models' 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 { cleanupAndDestroyPermanentLive } from './live-utils' import { MuxingSession } from './shared' const NodeRtmpSession = require('node-media-server/src/node_rtmp_session') @@ -224,7 +224,7 @@ class LiveManager { if (oldStreamingPlaylist) { if (!videoLive.permanentLive) throw new Error('Found previous session in a non permanent live: ' + video.uuid) - await cleanupPermanentLive(video, oldStreamingPlaylist) + await cleanupAndDestroyPermanentLive(video, oldStreamingPlaylist) } this.videoSessions.set(video.id, sessionId) @@ -232,10 +232,11 @@ class LiveManager { const now = Date.now() const probe = await ffprobePromise(inputUrl) - const [ { resolution, ratio }, fps, bitrate ] = await Promise.all([ + const [ { resolution, ratio }, fps, bitrate, hasAudio ] = await Promise.all([ getVideoStreamDimensionsInfo(inputUrl, probe), getVideoStreamFPS(inputUrl, probe), - getVideoStreamBitrate(inputUrl, probe) + getVideoStreamBitrate(inputUrl, probe), + hasAudioStream(inputUrl, probe) ]) logger.info( @@ -244,7 +245,7 @@ class LiveManager { ) const allResolutions = await Hooks.wrapObject( - this.buildAllResolutionsToTranscode(resolution), + this.buildAllResolutionsToTranscode(resolution, hasAudio), 'filter:transcoding.auto.resolutions-to-transcode.result', { video } ) @@ -259,26 +260,30 @@ class LiveManager { return this.runMuxingSession({ sessionId, videoLive, + streamingPlaylist, inputUrl, fps, bitrate, ratio, - allResolutions + allResolutions, + hasAudio }) } private async runMuxingSession (options: { sessionId: string videoLive: MVideoLiveVideo + streamingPlaylist: MStreamingPlaylistVideo inputUrl: string fps: number bitrate: number ratio: number allResolutions: number[] + hasAudio: boolean }) { - const { sessionId, videoLive, streamingPlaylist, allResolutions, fps, bitrate, ratio, inputUrl } = options + const { sessionId, videoLive } = options const videoUUID = videoLive.Video.uuid const localLTags = lTags(sessionId, videoUUID) @@ -289,18 +294,14 @@ class LiveManager { const muxingSession = new MuxingSession({ context: this.getContext(), - user, sessionId, videoLive, - streamingPlaylist, - inputUrl, - bitrate, - ratio, - fps, - allResolutions + user, + + ...pick(options, [ 'streamingPlaylist', 'inputUrl', 'bitrate', 'ratio', 'fps', 'allResolutions', 'hasAudio' ]) }) - muxingSession.on('master-playlist-created', () => this.publishAndFederateLive(videoLive, localLTags)) + muxingSession.on('live-ready', () => this.publishAndFederateLive(videoLive, localLTags)) muxingSession.on('bad-socket-health', ({ videoId }) => { logger.error( @@ -408,7 +409,7 @@ class LiveManager { await liveSession.save() } - JobQueue.Instance.createJob({ + JobQueue.Instance.createJobAsync({ type: 'video-live-ending', payload: { videoId: fullVideo.id, @@ -421,8 +422,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 @@ -455,11 +460,11 @@ class LiveManager { return join(directory, files.sort().reverse()[0]) } - private buildAllResolutionsToTranscode (originResolution: number) { + private buildAllResolutionsToTranscode (originResolution: number, hasAudio: boolean) { const includeInput = CONFIG.LIVE.TRANSCODING.ALWAYS_TRANSCODE_ORIGINAL_RESOLUTION const resolutionsEnabled = CONFIG.LIVE.TRANSCODING.ENABLED - ? computeResolutionsToTranscode({ input: originResolution, type: 'live', includeInput, strictLower: false }) + ? computeResolutionsToTranscode({ input: originResolution, type: 'live', includeInput, strictLower: false, hasAudio }) : [] if (resolutionsEnabled.length === 0) { @@ -478,6 +483,10 @@ class LiveManager { playlist.p2pMediaLoaderPeerVersion = P2P_MEDIA_LOADER_PEER_VERSION playlist.type = VideoStreamingPlaylistType.HLS + playlist.storage = CONFIG.OBJECT_STORAGE.ENABLED + ? VideoStorage.OBJECT_STORAGE + : VideoStorage.FILE_SYSTEM + playlist.assignP2PMediaLoaderInfoHashes(video, allResolutions) return playlist.save()