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