} from '@server/helpers/ffmpeg'
import { logger, loggerTagsFactory } from '@server/helpers/logger'
import { CONFIG, registerConfigChangedHandler } from '@server/initializers/config'
-import { P2P_MEDIA_LOADER_PEER_VERSION, VIDEO_LIVE } from '@server/initializers/constants'
+import { VIDEO_LIVE } from '@server/initializers/constants'
import { UserModel } from '@server/models/user/user'
import { VideoModel } from '@server/models/video/video'
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 { MVideo, MVideoLiveSession, MVideoLiveVideo } from '@server/types/models'
import { pick, wait } from '@shared/core-utils'
-import { LiveVideoError, VideoState, VideoStreamingPlaylistType } from '@shared/models'
+import { LiveVideoError, VideoState } from '@shared/models'
import { federateVideoIfNeeded } from '../activitypub/videos'
import { JobQueue } from '../job-queue'
-import { generateHLSMasterPlaylistFilename, generateHlsSha256SegmentsFilename, getLiveReplayBaseDirectory } from '../paths'
+import { 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')
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)
)
const allResolutions = await Hooks.wrapObject(
- this.buildAllResolutionsToTranscode(resolution),
+ this.buildAllResolutionsToTranscode(resolution, hasAudio),
'filter:transcoding.auto.resolutions-to-transcode.result',
{ video }
)
{ allResolutions, ...lTags(sessionId, video.uuid) }
)
- const streamingPlaylist = await this.createLivePlaylist(video, allResolutions)
-
return this.runMuxingSession({
sessionId,
videoLive,
- streamingPlaylist,
inputUrl,
fps,
bitrate,
sessionId: string
videoLive: MVideoLiveVideo
- streamingPlaylist: MStreamingPlaylistVideo
inputUrl: string
fps: number
bitrate: number
videoLive,
user,
- ...pick(options, [ 'streamingPlaylist', 'inputUrl', 'bitrate', 'ratio', 'fps', 'allResolutions', 'hasAudio' ])
+ ...pick(options, [ '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(
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) {
return resolutionsEnabled
}
- private async createLivePlaylist (video: MVideo, allResolutions: number[]): Promise<MStreamingPlaylistVideo> {
- const playlist = await VideoStreamingPlaylistModel.loadOrGenerate(video)
-
- playlist.playlistFilename = generateHLSMasterPlaylistFilename(true)
- playlist.segmentsSha256Filename = generateHlsSha256SegmentsFilename(true)
-
- playlist.p2pMediaLoaderPeerVersion = P2P_MEDIA_LOADER_PEER_VERSION
- playlist.type = VideoStreamingPlaylistType.HLS
-
- playlist.assignP2PMediaLoaderInfoHashes(video, allResolutions)
-
- return playlist.save()
- }
-
private saveStartingSession (videoLive: MVideoLiveVideo) {
const liveSession = new VideoLiveSessionModel({
startDate: new Date(),