]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import { expect } from 'chai' | |
4 | import { basename, join } from 'path' | |
5 | import { SQLCommand, testImage, testLiveVideoResolutions } from '@server/tests/shared' | |
6 | import { getAllFiles, wait } from '@shared/core-utils' | |
7 | import { ffprobePromise, getVideoStream } from '@shared/ffmpeg' | |
8 | import { | |
9 | HttpStatusCode, | |
10 | LiveVideo, | |
11 | LiveVideoCreate, | |
12 | LiveVideoLatencyMode, | |
13 | VideoDetails, | |
14 | VideoPrivacy, | |
15 | VideoState, | |
16 | VideoStreamingPlaylistType | |
17 | } from '@shared/models' | |
18 | import { | |
19 | cleanupTests, | |
20 | createMultipleServers, | |
21 | doubleFollow, | |
22 | killallServers, | |
23 | LiveCommand, | |
24 | makeGetRequest, | |
25 | makeRawRequest, | |
26 | PeerTubeServer, | |
27 | sendRTMPStream, | |
28 | setAccessTokensToServers, | |
29 | setDefaultVideoChannel, | |
30 | stopFfmpeg, | |
31 | testFfmpegStreamError, | |
32 | waitJobs, | |
33 | waitUntilLivePublishedOnAllServers | |
34 | } from '@shared/server-commands' | |
35 | ||
36 | describe('Test live', function () { | |
37 | let servers: PeerTubeServer[] = [] | |
38 | let commands: LiveCommand[] | |
39 | ||
40 | before(async function () { | |
41 | this.timeout(120000) | |
42 | ||
43 | servers = await createMultipleServers(2) | |
44 | ||
45 | // Get the access tokens | |
46 | await setAccessTokensToServers(servers) | |
47 | await setDefaultVideoChannel(servers) | |
48 | ||
49 | await servers[0].config.updateCustomSubConfig({ | |
50 | newConfig: { | |
51 | live: { | |
52 | enabled: true, | |
53 | allowReplay: true, | |
54 | latencySetting: { | |
55 | enabled: true | |
56 | }, | |
57 | transcoding: { | |
58 | enabled: false | |
59 | } | |
60 | } | |
61 | } | |
62 | }) | |
63 | ||
64 | // Server 1 and server 2 follow each other | |
65 | await doubleFollow(servers[0], servers[1]) | |
66 | ||
67 | commands = servers.map(s => s.live) | |
68 | }) | |
69 | ||
70 | describe('Live creation, update and delete', function () { | |
71 | let liveVideoUUID: string | |
72 | ||
73 | it('Should create a live with the appropriate parameters', async function () { | |
74 | this.timeout(20000) | |
75 | ||
76 | const attributes: LiveVideoCreate = { | |
77 | category: 1, | |
78 | licence: 2, | |
79 | language: 'fr', | |
80 | description: 'super live description', | |
81 | support: 'support field', | |
82 | channelId: servers[0].store.channel.id, | |
83 | nsfw: false, | |
84 | waitTranscoding: false, | |
85 | name: 'my super live', | |
86 | tags: [ 'tag1', 'tag2' ], | |
87 | commentsEnabled: false, | |
88 | downloadEnabled: false, | |
89 | saveReplay: true, | |
90 | replaySettings: { privacy: VideoPrivacy.PUBLIC }, | |
91 | latencyMode: LiveVideoLatencyMode.SMALL_LATENCY, | |
92 | privacy: VideoPrivacy.PUBLIC, | |
93 | previewfile: 'video_short1-preview.webm.jpg', | |
94 | thumbnailfile: 'video_short1.webm.jpg' | |
95 | } | |
96 | ||
97 | const live = await commands[0].create({ fields: attributes }) | |
98 | liveVideoUUID = live.uuid | |
99 | ||
100 | await waitJobs(servers) | |
101 | ||
102 | for (const server of servers) { | |
103 | const video = await server.videos.get({ id: liveVideoUUID }) | |
104 | ||
105 | expect(video.category.id).to.equal(1) | |
106 | expect(video.licence.id).to.equal(2) | |
107 | expect(video.language.id).to.equal('fr') | |
108 | expect(video.description).to.equal('super live description') | |
109 | expect(video.support).to.equal('support field') | |
110 | ||
111 | expect(video.channel.name).to.equal(servers[0].store.channel.name) | |
112 | expect(video.channel.host).to.equal(servers[0].store.channel.host) | |
113 | ||
114 | expect(video.isLive).to.be.true | |
115 | ||
116 | expect(video.nsfw).to.be.false | |
117 | expect(video.waitTranscoding).to.be.false | |
118 | expect(video.name).to.equal('my super live') | |
119 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2' ]) | |
120 | expect(video.commentsEnabled).to.be.false | |
121 | expect(video.downloadEnabled).to.be.false | |
122 | expect(video.privacy.id).to.equal(VideoPrivacy.PUBLIC) | |
123 | ||
124 | await testImage(server.url, 'video_short1-preview.webm', video.previewPath) | |
125 | await testImage(server.url, 'video_short1.webm', video.thumbnailPath) | |
126 | ||
127 | const live = await server.live.get({ videoId: liveVideoUUID }) | |
128 | ||
129 | if (server.url === servers[0].url) { | |
130 | expect(live.rtmpUrl).to.equal('rtmp://' + server.hostname + ':' + servers[0].rtmpPort + '/live') | |
131 | expect(live.streamKey).to.not.be.empty | |
132 | ||
133 | expect(live.replaySettings).to.exist | |
134 | expect(live.replaySettings.privacy).to.equal(VideoPrivacy.PUBLIC) | |
135 | } else { | |
136 | expect(live.rtmpUrl).to.not.exist | |
137 | expect(live.streamKey).to.not.exist | |
138 | } | |
139 | ||
140 | expect(live.saveReplay).to.be.true | |
141 | expect(live.latencyMode).to.equal(LiveVideoLatencyMode.SMALL_LATENCY) | |
142 | } | |
143 | }) | |
144 | ||
145 | it('Should have a default preview and thumbnail', async function () { | |
146 | this.timeout(20000) | |
147 | ||
148 | const attributes: LiveVideoCreate = { | |
149 | name: 'default live thumbnail', | |
150 | channelId: servers[0].store.channel.id, | |
151 | privacy: VideoPrivacy.UNLISTED, | |
152 | nsfw: true | |
153 | } | |
154 | ||
155 | const live = await commands[0].create({ fields: attributes }) | |
156 | const videoId = live.uuid | |
157 | ||
158 | await waitJobs(servers) | |
159 | ||
160 | for (const server of servers) { | |
161 | const video = await server.videos.get({ id: videoId }) | |
162 | expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED) | |
163 | expect(video.nsfw).to.be.true | |
164 | ||
165 | await makeGetRequest({ url: server.url, path: video.thumbnailPath, expectedStatus: HttpStatusCode.OK_200 }) | |
166 | await makeGetRequest({ url: server.url, path: video.previewPath, expectedStatus: HttpStatusCode.OK_200 }) | |
167 | } | |
168 | }) | |
169 | ||
170 | it('Should not have the live listed since nobody streams into', async function () { | |
171 | for (const server of servers) { | |
172 | const { total, data } = await server.videos.list() | |
173 | ||
174 | expect(total).to.equal(0) | |
175 | expect(data).to.have.lengthOf(0) | |
176 | } | |
177 | }) | |
178 | ||
179 | it('Should not be able to update a live of another server', async function () { | |
180 | await commands[1].update({ videoId: liveVideoUUID, fields: { saveReplay: false }, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) | |
181 | }) | |
182 | ||
183 | it('Should update the live', async function () { | |
184 | await commands[0].update({ videoId: liveVideoUUID, fields: { saveReplay: false, latencyMode: LiveVideoLatencyMode.DEFAULT } }) | |
185 | await waitJobs(servers) | |
186 | }) | |
187 | ||
188 | it('Have the live updated', async function () { | |
189 | for (const server of servers) { | |
190 | const live = await server.live.get({ videoId: liveVideoUUID }) | |
191 | ||
192 | if (server.url === servers[0].url) { | |
193 | expect(live.rtmpUrl).to.equal('rtmp://' + server.hostname + ':' + servers[0].rtmpPort + '/live') | |
194 | expect(live.streamKey).to.not.be.empty | |
195 | } else { | |
196 | expect(live.rtmpUrl).to.not.exist | |
197 | expect(live.streamKey).to.not.exist | |
198 | } | |
199 | ||
200 | expect(live.saveReplay).to.be.false | |
201 | expect(live.replaySettings).to.not.exist | |
202 | expect(live.latencyMode).to.equal(LiveVideoLatencyMode.DEFAULT) | |
203 | } | |
204 | }) | |
205 | ||
206 | it('Delete the live', async function () { | |
207 | await servers[0].videos.remove({ id: liveVideoUUID }) | |
208 | await waitJobs(servers) | |
209 | }) | |
210 | ||
211 | it('Should have the live deleted', async function () { | |
212 | for (const server of servers) { | |
213 | await server.videos.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) | |
214 | await server.live.get({ videoId: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) | |
215 | } | |
216 | }) | |
217 | }) | |
218 | ||
219 | describe('Live filters', function () { | |
220 | let ffmpegCommand: any | |
221 | let liveVideoId: string | |
222 | let vodVideoId: string | |
223 | ||
224 | before(async function () { | |
225 | this.timeout(240000) | |
226 | ||
227 | vodVideoId = (await servers[0].videos.quickUpload({ name: 'vod video' })).uuid | |
228 | ||
229 | const liveOptions = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: servers[0].store.channel.id } | |
230 | const live = await commands[0].create({ fields: liveOptions }) | |
231 | liveVideoId = live.uuid | |
232 | ||
233 | ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoId }) | |
234 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) | |
235 | await waitJobs(servers) | |
236 | }) | |
237 | ||
238 | it('Should only display lives', async function () { | |
239 | const { data, total } = await servers[0].videos.list({ isLive: true }) | |
240 | ||
241 | expect(total).to.equal(1) | |
242 | expect(data).to.have.lengthOf(1) | |
243 | expect(data[0].name).to.equal('live') | |
244 | }) | |
245 | ||
246 | it('Should not display lives', async function () { | |
247 | const { data, total } = await servers[0].videos.list({ isLive: false }) | |
248 | ||
249 | expect(total).to.equal(1) | |
250 | expect(data).to.have.lengthOf(1) | |
251 | expect(data[0].name).to.equal('vod video') | |
252 | }) | |
253 | ||
254 | it('Should display my lives', async function () { | |
255 | this.timeout(60000) | |
256 | ||
257 | await stopFfmpeg(ffmpegCommand) | |
258 | await waitJobs(servers) | |
259 | ||
260 | const { data } = await servers[0].videos.listMyVideos({ isLive: true }) | |
261 | ||
262 | const result = data.every(v => v.isLive) | |
263 | expect(result).to.be.true | |
264 | }) | |
265 | ||
266 | it('Should not display my lives', async function () { | |
267 | const { data } = await servers[0].videos.listMyVideos({ isLive: false }) | |
268 | ||
269 | const result = data.every(v => !v.isLive) | |
270 | expect(result).to.be.true | |
271 | }) | |
272 | ||
273 | after(async function () { | |
274 | await servers[0].videos.remove({ id: vodVideoId }) | |
275 | await servers[0].videos.remove({ id: liveVideoId }) | |
276 | }) | |
277 | }) | |
278 | ||
279 | describe('Stream checks', function () { | |
280 | let liveVideo: LiveVideo & VideoDetails | |
281 | let rtmpUrl: string | |
282 | ||
283 | before(function () { | |
284 | rtmpUrl = 'rtmp://' + servers[0].hostname + ':' + servers[0].rtmpPort + '' | |
285 | }) | |
286 | ||
287 | async function createLiveWrapper () { | |
288 | const liveAttributes = { | |
289 | name: 'user live', | |
290 | channelId: servers[0].store.channel.id, | |
291 | privacy: VideoPrivacy.PUBLIC, | |
292 | saveReplay: false | |
293 | } | |
294 | ||
295 | const { uuid } = await commands[0].create({ fields: liveAttributes }) | |
296 | ||
297 | const live = await commands[0].get({ videoId: uuid }) | |
298 | const video = await servers[0].videos.get({ id: uuid }) | |
299 | ||
300 | return Object.assign(video, live) | |
301 | } | |
302 | ||
303 | it('Should not allow a stream without the appropriate path', async function () { | |
304 | this.timeout(60000) | |
305 | ||
306 | liveVideo = await createLiveWrapper() | |
307 | ||
308 | const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl + '/bad-live', streamKey: liveVideo.streamKey }) | |
309 | await testFfmpegStreamError(command, true) | |
310 | }) | |
311 | ||
312 | it('Should not allow a stream without the appropriate stream key', async function () { | |
313 | this.timeout(60000) | |
314 | ||
315 | const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl + '/live', streamKey: 'bad-stream-key' }) | |
316 | await testFfmpegStreamError(command, true) | |
317 | }) | |
318 | ||
319 | it('Should succeed with the correct params', async function () { | |
320 | this.timeout(60000) | |
321 | ||
322 | const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl + '/live', streamKey: liveVideo.streamKey }) | |
323 | await testFfmpegStreamError(command, false) | |
324 | }) | |
325 | ||
326 | it('Should list this live now someone stream into it', async function () { | |
327 | for (const server of servers) { | |
328 | const { total, data } = await server.videos.list() | |
329 | ||
330 | expect(total).to.equal(1) | |
331 | expect(data).to.have.lengthOf(1) | |
332 | ||
333 | const video = data[0] | |
334 | expect(video.name).to.equal('user live') | |
335 | expect(video.isLive).to.be.true | |
336 | } | |
337 | }) | |
338 | ||
339 | it('Should not allow a stream on a live that was blacklisted', async function () { | |
340 | this.timeout(60000) | |
341 | ||
342 | liveVideo = await createLiveWrapper() | |
343 | ||
344 | await servers[0].blacklist.add({ videoId: liveVideo.uuid }) | |
345 | ||
346 | const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl + '/live', streamKey: liveVideo.streamKey }) | |
347 | await testFfmpegStreamError(command, true) | |
348 | }) | |
349 | ||
350 | it('Should not allow a stream on a live that was deleted', async function () { | |
351 | this.timeout(60000) | |
352 | ||
353 | liveVideo = await createLiveWrapper() | |
354 | ||
355 | await servers[0].videos.remove({ id: liveVideo.uuid }) | |
356 | ||
357 | const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl + '/live', streamKey: liveVideo.streamKey }) | |
358 | await testFfmpegStreamError(command, true) | |
359 | }) | |
360 | }) | |
361 | ||
362 | describe('Live transcoding', function () { | |
363 | let liveVideoId: string | |
364 | let sqlCommandServer1: SQLCommand | |
365 | ||
366 | async function createLiveWrapper (saveReplay: boolean) { | |
367 | const liveAttributes = { | |
368 | name: 'live video', | |
369 | channelId: servers[0].store.channel.id, | |
370 | privacy: VideoPrivacy.PUBLIC, | |
371 | saveReplay, | |
372 | replaySettings: saveReplay | |
373 | ? { privacy: VideoPrivacy.PUBLIC } | |
374 | : undefined | |
375 | } | |
376 | ||
377 | const { uuid } = await commands[0].create({ fields: liveAttributes }) | |
378 | return uuid | |
379 | } | |
380 | ||
381 | function updateConf (resolutions: number[]) { | |
382 | return servers[0].config.updateCustomSubConfig({ | |
383 | newConfig: { | |
384 | live: { | |
385 | enabled: true, | |
386 | allowReplay: true, | |
387 | maxDuration: -1, | |
388 | transcoding: { | |
389 | enabled: true, | |
390 | resolutions: { | |
391 | '144p': resolutions.includes(144), | |
392 | '240p': resolutions.includes(240), | |
393 | '360p': resolutions.includes(360), | |
394 | '480p': resolutions.includes(480), | |
395 | '720p': resolutions.includes(720), | |
396 | '1080p': resolutions.includes(1080), | |
397 | '2160p': resolutions.includes(2160) | |
398 | } | |
399 | } | |
400 | } | |
401 | } | |
402 | }) | |
403 | } | |
404 | ||
405 | before(async function () { | |
406 | await updateConf([]) | |
407 | ||
408 | sqlCommandServer1 = new SQLCommand(servers[0]) | |
409 | }) | |
410 | ||
411 | it('Should enable transcoding without additional resolutions', async function () { | |
412 | this.timeout(120000) | |
413 | ||
414 | liveVideoId = await createLiveWrapper(false) | |
415 | ||
416 | const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId }) | |
417 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) | |
418 | await waitJobs(servers) | |
419 | ||
420 | await testLiveVideoResolutions({ | |
421 | originServer: servers[0], | |
422 | sqlCommand: sqlCommandServer1, | |
423 | servers, | |
424 | liveVideoId, | |
425 | resolutions: [ 720 ], | |
426 | objectStorage: false, | |
427 | transcoded: true | |
428 | }) | |
429 | ||
430 | await stopFfmpeg(ffmpegCommand) | |
431 | }) | |
432 | ||
433 | it('Should transcode audio only RTMP stream', async function () { | |
434 | this.timeout(120000) | |
435 | ||
436 | liveVideoId = await createLiveWrapper(false) | |
437 | ||
438 | const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short_no_audio.mp4' }) | |
439 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) | |
440 | await waitJobs(servers) | |
441 | ||
442 | await stopFfmpeg(ffmpegCommand) | |
443 | }) | |
444 | ||
445 | it('Should enable transcoding with some resolutions', async function () { | |
446 | this.timeout(240000) | |
447 | ||
448 | const resolutions = [ 240, 480 ] | |
449 | await updateConf(resolutions) | |
450 | liveVideoId = await createLiveWrapper(false) | |
451 | ||
452 | const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId }) | |
453 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) | |
454 | await waitJobs(servers) | |
455 | ||
456 | await testLiveVideoResolutions({ | |
457 | originServer: servers[0], | |
458 | sqlCommand: sqlCommandServer1, | |
459 | servers, | |
460 | liveVideoId, | |
461 | resolutions: resolutions.concat([ 720 ]), | |
462 | objectStorage: false, | |
463 | transcoded: true | |
464 | }) | |
465 | ||
466 | await stopFfmpeg(ffmpegCommand) | |
467 | }) | |
468 | ||
469 | it('Should correctly set the appropriate bitrate depending on the input', async function () { | |
470 | this.timeout(120000) | |
471 | ||
472 | liveVideoId = await createLiveWrapper(false) | |
473 | ||
474 | const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({ | |
475 | videoId: liveVideoId, | |
476 | fixtureName: 'video_short.mp4', | |
477 | copyCodecs: true | |
478 | }) | |
479 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) | |
480 | await waitJobs(servers) | |
481 | ||
482 | const video = await servers[0].videos.get({ id: liveVideoId }) | |
483 | ||
484 | const masterPlaylist = video.streamingPlaylists[0].playlistUrl | |
485 | const probe = await ffprobePromise(masterPlaylist) | |
486 | ||
487 | const bitrates = probe.streams.map(s => parseInt(s.tags.variant_bitrate)) | |
488 | for (const bitrate of bitrates) { | |
489 | expect(bitrate).to.exist | |
490 | expect(isNaN(bitrate)).to.be.false | |
491 | expect(bitrate).to.be.below(61_000_000) // video_short.mp4 bitrate | |
492 | } | |
493 | ||
494 | await stopFfmpeg(ffmpegCommand) | |
495 | }) | |
496 | ||
497 | it('Should enable transcoding with some resolutions and correctly save them', async function () { | |
498 | this.timeout(500_000) | |
499 | ||
500 | const resolutions = [ 240, 360, 720 ] | |
501 | ||
502 | await updateConf(resolutions) | |
503 | liveVideoId = await createLiveWrapper(true) | |
504 | ||
505 | const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) | |
506 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) | |
507 | await waitJobs(servers) | |
508 | ||
509 | await testLiveVideoResolutions({ | |
510 | originServer: servers[0], | |
511 | sqlCommand: sqlCommandServer1, | |
512 | servers, | |
513 | liveVideoId, | |
514 | resolutions, | |
515 | objectStorage: false, | |
516 | transcoded: true | |
517 | }) | |
518 | ||
519 | await stopFfmpeg(ffmpegCommand) | |
520 | await commands[0].waitUntilEnded({ videoId: liveVideoId }) | |
521 | ||
522 | await waitJobs(servers) | |
523 | ||
524 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) | |
525 | ||
526 | const maxBitrateLimits = { | |
527 | 720: 6500 * 1000, // 60FPS | |
528 | 360: 1250 * 1000, | |
529 | 240: 700 * 1000 | |
530 | } | |
531 | ||
532 | const minBitrateLimits = { | |
533 | 720: 4800 * 1000, | |
534 | 360: 1000 * 1000, | |
535 | 240: 550 * 1000 | |
536 | } | |
537 | ||
538 | for (const server of servers) { | |
539 | const video = await server.videos.get({ id: liveVideoId }) | |
540 | ||
541 | expect(video.state.id).to.equal(VideoState.PUBLISHED) | |
542 | expect(video.duration).to.be.greaterThan(1) | |
543 | expect(video.files).to.have.lengthOf(0) | |
544 | ||
545 | const hlsPlaylist = video.streamingPlaylists.find(s => s.type === VideoStreamingPlaylistType.HLS) | |
546 | await makeRawRequest({ url: hlsPlaylist.playlistUrl, expectedStatus: HttpStatusCode.OK_200 }) | |
547 | await makeRawRequest({ url: hlsPlaylist.segmentsSha256Url, expectedStatus: HttpStatusCode.OK_200 }) | |
548 | ||
549 | // We should have generated random filenames | |
550 | expect(basename(hlsPlaylist.playlistUrl)).to.not.equal('master.m3u8') | |
551 | expect(basename(hlsPlaylist.segmentsSha256Url)).to.not.equal('segments-sha256.json') | |
552 | ||
553 | expect(hlsPlaylist.files).to.have.lengthOf(resolutions.length) | |
554 | ||
555 | for (const resolution of resolutions) { | |
556 | const file = hlsPlaylist.files.find(f => f.resolution.id === resolution) | |
557 | ||
558 | expect(file).to.exist | |
559 | expect(file.size).to.be.greaterThan(1) | |
560 | ||
561 | if (resolution >= 720) { | |
562 | expect(file.fps).to.be.approximately(60, 10) | |
563 | } else { | |
564 | expect(file.fps).to.be.approximately(30, 3) | |
565 | } | |
566 | ||
567 | const filename = basename(file.fileUrl) | |
568 | expect(filename).to.not.contain(video.uuid) | |
569 | ||
570 | const segmentPath = servers[0].servers.buildDirectory(join('streaming-playlists', 'hls', video.uuid, filename)) | |
571 | ||
572 | const probe = await ffprobePromise(segmentPath) | |
573 | const videoStream = await getVideoStream(segmentPath, probe) | |
574 | ||
575 | expect(probe.format.bit_rate).to.be.below(maxBitrateLimits[videoStream.height]) | |
576 | expect(probe.format.bit_rate).to.be.at.least(minBitrateLimits[videoStream.height]) | |
577 | ||
578 | await makeRawRequest({ url: file.torrentUrl, expectedStatus: HttpStatusCode.OK_200 }) | |
579 | await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 }) | |
580 | } | |
581 | } | |
582 | }) | |
583 | ||
584 | it('Should not generate an upper resolution than original file', async function () { | |
585 | this.timeout(500_000) | |
586 | ||
587 | const resolutions = [ 240, 480 ] | |
588 | await updateConf(resolutions) | |
589 | ||
590 | await servers[0].config.updateExistingSubConfig({ | |
591 | newConfig: { | |
592 | live: { | |
593 | transcoding: { | |
594 | alwaysTranscodeOriginalResolution: false | |
595 | } | |
596 | } | |
597 | } | |
598 | }) | |
599 | ||
600 | liveVideoId = await createLiveWrapper(true) | |
601 | ||
602 | const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) | |
603 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) | |
604 | await waitJobs(servers) | |
605 | ||
606 | await testLiveVideoResolutions({ | |
607 | originServer: servers[0], | |
608 | sqlCommand: sqlCommandServer1, | |
609 | servers, | |
610 | liveVideoId, | |
611 | resolutions, | |
612 | objectStorage: false, | |
613 | transcoded: true | |
614 | }) | |
615 | ||
616 | await stopFfmpeg(ffmpegCommand) | |
617 | await commands[0].waitUntilEnded({ videoId: liveVideoId }) | |
618 | ||
619 | await waitJobs(servers) | |
620 | ||
621 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) | |
622 | ||
623 | const video = await servers[0].videos.get({ id: liveVideoId }) | |
624 | const hlsFiles = video.streamingPlaylists[0].files | |
625 | ||
626 | expect(video.files).to.have.lengthOf(0) | |
627 | expect(hlsFiles).to.have.lengthOf(resolutions.length) | |
628 | ||
629 | // eslint-disable-next-line @typescript-eslint/require-array-sort-compare | |
630 | expect(getAllFiles(video).map(f => f.resolution.id).sort()).to.deep.equal(resolutions) | |
631 | }) | |
632 | ||
633 | it('Should only keep the original resolution if all resolutions are disabled', async function () { | |
634 | this.timeout(600_000) | |
635 | ||
636 | await updateConf([]) | |
637 | liveVideoId = await createLiveWrapper(true) | |
638 | ||
639 | const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) | |
640 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) | |
641 | await waitJobs(servers) | |
642 | ||
643 | await testLiveVideoResolutions({ | |
644 | originServer: servers[0], | |
645 | sqlCommand: sqlCommandServer1, | |
646 | servers, | |
647 | liveVideoId, | |
648 | resolutions: [ 720 ], | |
649 | objectStorage: false, | |
650 | transcoded: true | |
651 | }) | |
652 | ||
653 | await stopFfmpeg(ffmpegCommand) | |
654 | await commands[0].waitUntilEnded({ videoId: liveVideoId }) | |
655 | ||
656 | await waitJobs(servers) | |
657 | ||
658 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) | |
659 | ||
660 | const video = await servers[0].videos.get({ id: liveVideoId }) | |
661 | const hlsFiles = video.streamingPlaylists[0].files | |
662 | ||
663 | expect(video.files).to.have.lengthOf(0) | |
664 | expect(hlsFiles).to.have.lengthOf(1) | |
665 | ||
666 | expect(hlsFiles[0].resolution.id).to.equal(720) | |
667 | }) | |
668 | ||
669 | after(async function () { | |
670 | await sqlCommandServer1.cleanup() | |
671 | }) | |
672 | }) | |
673 | ||
674 | describe('After a server restart', function () { | |
675 | let liveVideoId: string | |
676 | let liveVideoReplayId: string | |
677 | let permanentLiveVideoReplayId: string | |
678 | ||
679 | let permanentLiveReplayName: string | |
680 | ||
681 | let beforeServerRestart: Date | |
682 | ||
683 | async function createLiveWrapper (options: { saveReplay: boolean, permanent: boolean }) { | |
684 | const liveAttributes: LiveVideoCreate = { | |
685 | name: 'live video', | |
686 | channelId: servers[0].store.channel.id, | |
687 | privacy: VideoPrivacy.PUBLIC, | |
688 | saveReplay: options.saveReplay, | |
689 | replaySettings: options.saveReplay | |
690 | ? { privacy: VideoPrivacy.PUBLIC } | |
691 | : undefined, | |
692 | permanentLive: options.permanent | |
693 | } | |
694 | ||
695 | const { uuid } = await commands[0].create({ fields: liveAttributes }) | |
696 | return uuid | |
697 | } | |
698 | ||
699 | before(async function () { | |
700 | this.timeout(600_000) | |
701 | ||
702 | liveVideoId = await createLiveWrapper({ saveReplay: false, permanent: false }) | |
703 | liveVideoReplayId = await createLiveWrapper({ saveReplay: true, permanent: false }) | |
704 | permanentLiveVideoReplayId = await createLiveWrapper({ saveReplay: true, permanent: true }) | |
705 | ||
706 | await Promise.all([ | |
707 | commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId }), | |
708 | commands[0].sendRTMPStreamInVideo({ videoId: permanentLiveVideoReplayId }), | |
709 | commands[0].sendRTMPStreamInVideo({ videoId: liveVideoReplayId }) | |
710 | ]) | |
711 | ||
712 | await Promise.all([ | |
713 | commands[0].waitUntilPublished({ videoId: liveVideoId }), | |
714 | commands[0].waitUntilPublished({ videoId: permanentLiveVideoReplayId }), | |
715 | commands[0].waitUntilPublished({ videoId: liveVideoReplayId }) | |
716 | ]) | |
717 | ||
718 | for (const videoUUID of [ liveVideoId, liveVideoReplayId, permanentLiveVideoReplayId ]) { | |
719 | await commands[0].waitUntilSegmentGeneration({ | |
720 | server: servers[0], | |
721 | videoUUID, | |
722 | playlistNumber: 0, | |
723 | segment: 2, | |
724 | objectStorage: false | |
725 | }) | |
726 | } | |
727 | ||
728 | { | |
729 | const video = await servers[0].videos.get({ id: permanentLiveVideoReplayId }) | |
730 | permanentLiveReplayName = video.name + ' - ' + new Date(video.publishedAt).toLocaleString() | |
731 | } | |
732 | ||
733 | await killallServers([ servers[0] ]) | |
734 | ||
735 | beforeServerRestart = new Date() | |
736 | await servers[0].run() | |
737 | ||
738 | await wait(5000) | |
739 | await waitJobs(servers) | |
740 | }) | |
741 | ||
742 | it('Should cleanup lives', async function () { | |
743 | this.timeout(60000) | |
744 | ||
745 | await commands[0].waitUntilEnded({ videoId: liveVideoId }) | |
746 | await commands[0].waitUntilWaiting({ videoId: permanentLiveVideoReplayId }) | |
747 | }) | |
748 | ||
749 | it('Should save a non permanent live replay', async function () { | |
750 | this.timeout(240000) | |
751 | ||
752 | await commands[0].waitUntilPublished({ videoId: liveVideoReplayId }) | |
753 | ||
754 | const session = await commands[0].getReplaySession({ videoId: liveVideoReplayId }) | |
755 | expect(session.endDate).to.exist | |
756 | expect(new Date(session.endDate)).to.be.above(beforeServerRestart) | |
757 | }) | |
758 | ||
759 | it('Should have saved a permanent live replay', async function () { | |
760 | this.timeout(120000) | |
761 | ||
762 | const { data } = await servers[0].videos.listMyVideos({ sort: '-publishedAt' }) | |
763 | expect(data.find(v => v.name === permanentLiveReplayName)).to.exist | |
764 | }) | |
765 | }) | |
766 | ||
767 | after(async function () { | |
768 | await cleanupTests(servers) | |
769 | }) | |
770 | }) |