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