diff options
Diffstat (limited to 'server/lib/live/live-manager.ts')
-rw-r--r-- | server/lib/live/live-manager.ts | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/server/lib/live/live-manager.ts b/server/lib/live/live-manager.ts index 6d51f4de7..68aa18443 100644 --- a/server/lib/live/live-manager.ts +++ b/server/lib/live/live-manager.ts | |||
@@ -4,7 +4,7 @@ import { join } from 'path' | |||
4 | import { createServer as createServerTLS, Server as ServerTLS } from 'tls' | 4 | import { createServer as createServerTLS, Server as ServerTLS } from 'tls' |
5 | import { logger, loggerTagsFactory } from '@server/helpers/logger' | 5 | import { logger, loggerTagsFactory } from '@server/helpers/logger' |
6 | import { CONFIG, registerConfigChangedHandler } from '@server/initializers/config' | 6 | import { CONFIG, registerConfigChangedHandler } from '@server/initializers/config' |
7 | import { VIDEO_LIVE } from '@server/initializers/constants' | 7 | import { VIDEO_LIVE, WEBSERVER } from '@server/initializers/constants' |
8 | import { sequelizeTypescript } from '@server/initializers/database' | 8 | import { sequelizeTypescript } from '@server/initializers/database' |
9 | import { RunnerJobModel } from '@server/models/runner/runner-job' | 9 | import { RunnerJobModel } from '@server/models/runner/runner-job' |
10 | import { UserModel } from '@server/models/user/user' | 10 | import { UserModel } from '@server/models/user/user' |
@@ -73,8 +73,10 @@ class LiveManager { | |||
73 | } | 73 | } |
74 | 74 | ||
75 | const session = this.getContext().sessions.get(sessionId) | 75 | const session = this.getContext().sessions.get(sessionId) |
76 | const inputLocalUrl = session.inputOriginLocalUrl + streamPath | ||
77 | const inputPublicUrl = session.inputOriginPublicUrl + streamPath | ||
76 | 78 | ||
77 | this.handleSession(sessionId, session.inputOriginUrl + streamPath, splittedPath[2]) | 79 | this.handleSession({ sessionId, inputPublicUrl, inputLocalUrl, streamKey: splittedPath[2] }) |
78 | .catch(err => logger.error('Cannot handle sessions.', { err, ...lTags(sessionId) })) | 80 | .catch(err => logger.error('Cannot handle sessions.', { err, ...lTags(sessionId) })) |
79 | }) | 81 | }) |
80 | 82 | ||
@@ -110,7 +112,8 @@ class LiveManager { | |||
110 | this.rtmpServer = createServer(socket => { | 112 | this.rtmpServer = createServer(socket => { |
111 | const session = new NodeRtmpSession(config, socket) | 113 | const session = new NodeRtmpSession(config, socket) |
112 | 114 | ||
113 | session.inputOriginUrl = 'rtmp://127.0.0.1:' + CONFIG.LIVE.RTMP.PORT | 115 | session.inputOriginLocalUrl = 'rtmp://127.0.0.1:' + CONFIG.LIVE.RTMP.PORT |
116 | session.inputOriginPublicUrl = WEBSERVER.RTMP_URL | ||
114 | session.run() | 117 | session.run() |
115 | }) | 118 | }) |
116 | 119 | ||
@@ -133,7 +136,8 @@ class LiveManager { | |||
133 | this.rtmpsServer = createServerTLS(serverOptions, socket => { | 136 | this.rtmpsServer = createServerTLS(serverOptions, socket => { |
134 | const session = new NodeRtmpSession(config, socket) | 137 | const session = new NodeRtmpSession(config, socket) |
135 | 138 | ||
136 | session.inputOriginUrl = 'rtmps://127.0.0.1:' + CONFIG.LIVE.RTMPS.PORT | 139 | session.inputOriginLocalUrl = 'rtmps://127.0.0.1:' + CONFIG.LIVE.RTMPS.PORT |
140 | session.inputOriginPublicUrl = WEBSERVER.RTMPS_URL | ||
137 | session.run() | 141 | session.run() |
138 | }) | 142 | }) |
139 | 143 | ||
@@ -210,7 +214,14 @@ class LiveManager { | |||
210 | } | 214 | } |
211 | } | 215 | } |
212 | 216 | ||
213 | private async handleSession (sessionId: string, inputUrl: string, streamKey: string) { | 217 | private async handleSession (options: { |
218 | sessionId: string | ||
219 | inputLocalUrl: string | ||
220 | inputPublicUrl: string | ||
221 | streamKey: string | ||
222 | }) { | ||
223 | const { inputLocalUrl, inputPublicUrl, sessionId, streamKey } = options | ||
224 | |||
214 | const videoLive = await VideoLiveModel.loadByStreamKey(streamKey) | 225 | const videoLive = await VideoLiveModel.loadByStreamKey(streamKey) |
215 | if (!videoLive) { | 226 | if (!videoLive) { |
216 | logger.warn('Unknown live video with stream key %s.', streamKey, lTags(sessionId)) | 227 | logger.warn('Unknown live video with stream key %s.', streamKey, lTags(sessionId)) |
@@ -239,18 +250,18 @@ class LiveManager { | |||
239 | this.videoSessions.set(video.uuid, sessionId) | 250 | this.videoSessions.set(video.uuid, sessionId) |
240 | 251 | ||
241 | const now = Date.now() | 252 | const now = Date.now() |
242 | const probe = await ffprobePromise(inputUrl) | 253 | const probe = await ffprobePromise(inputLocalUrl) |
243 | 254 | ||
244 | const [ { resolution, ratio }, fps, bitrate, hasAudio ] = await Promise.all([ | 255 | const [ { resolution, ratio }, fps, bitrate, hasAudio ] = await Promise.all([ |
245 | getVideoStreamDimensionsInfo(inputUrl, probe), | 256 | getVideoStreamDimensionsInfo(inputLocalUrl, probe), |
246 | getVideoStreamFPS(inputUrl, probe), | 257 | getVideoStreamFPS(inputLocalUrl, probe), |
247 | getVideoStreamBitrate(inputUrl, probe), | 258 | getVideoStreamBitrate(inputLocalUrl, probe), |
248 | hasAudioStream(inputUrl, probe) | 259 | hasAudioStream(inputLocalUrl, probe) |
249 | ]) | 260 | ]) |
250 | 261 | ||
251 | logger.info( | 262 | logger.info( |
252 | '%s probing took %d ms (bitrate: %d, fps: %d, resolution: %d)', | 263 | '%s probing took %d ms (bitrate: %d, fps: %d, resolution: %d)', |
253 | inputUrl, Date.now() - now, bitrate, fps, resolution, lTags(sessionId, video.uuid) | 264 | inputLocalUrl, Date.now() - now, bitrate, fps, resolution, lTags(sessionId, video.uuid) |
254 | ) | 265 | ) |
255 | 266 | ||
256 | const allResolutions = await Hooks.wrapObject( | 267 | const allResolutions = await Hooks.wrapObject( |
@@ -268,7 +279,8 @@ class LiveManager { | |||
268 | sessionId, | 279 | sessionId, |
269 | videoLive, | 280 | videoLive, |
270 | 281 | ||
271 | inputUrl, | 282 | inputLocalUrl, |
283 | inputPublicUrl, | ||
272 | fps, | 284 | fps, |
273 | bitrate, | 285 | bitrate, |
274 | ratio, | 286 | ratio, |
@@ -281,7 +293,9 @@ class LiveManager { | |||
281 | sessionId: string | 293 | sessionId: string |
282 | videoLive: MVideoLiveVideoWithSetting | 294 | videoLive: MVideoLiveVideoWithSetting |
283 | 295 | ||
284 | inputUrl: string | 296 | inputLocalUrl: string |
297 | inputPublicUrl: string | ||
298 | |||
285 | fps: number | 299 | fps: number |
286 | bitrate: number | 300 | bitrate: number |
287 | ratio: number | 301 | ratio: number |
@@ -303,7 +317,7 @@ class LiveManager { | |||
303 | videoLive, | 317 | videoLive, |
304 | user, | 318 | user, |
305 | 319 | ||
306 | ...pick(options, [ 'inputUrl', 'bitrate', 'ratio', 'fps', 'allResolutions', 'hasAudio' ]) | 320 | ...pick(options, [ 'inputLocalUrl', 'inputPublicUrl', 'bitrate', 'ratio', 'fps', 'allResolutions', 'hasAudio' ]) |
307 | }) | 321 | }) |
308 | 322 | ||
309 | muxingSession.on('live-ready', () => this.publishAndFederateLive(videoLive, localLTags)) | 323 | muxingSession.on('live-ready', () => this.publishAndFederateLive(videoLive, localLTags)) |