]>
Commit | Line | Data |
---|---|---|
af4ae64f C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
764b1a14 | 5 | import { basename, join } from 'path' |
679c12e6 | 6 | import { ffprobePromise, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils' |
af4ae64f | 7 | import { |
764b1a14 | 8 | checkLiveCleanupAfterSave, |
5c0904fc | 9 | checkLiveSegmentHash, |
bd54ad19 | 10 | checkResolutionsInMasterPlaylist, |
af4ae64f | 11 | cleanupTests, |
254d3579 | 12 | createMultipleServers, |
4c7e60bc | 13 | doubleFollow, |
5c0904fc | 14 | killallServers, |
4f219914 | 15 | LiveCommand, |
af4ae64f | 16 | makeRawRequest, |
254d3579 | 17 | PeerTubeServer, |
4c7e60bc | 18 | sendRTMPStream, |
af4ae64f C |
19 | setAccessTokensToServers, |
20 | setDefaultVideoChannel, | |
bd54ad19 | 21 | stopFfmpeg, |
97969c4e | 22 | testFfmpegStreamError, |
af4ae64f | 23 | testImage, |
e4bf7856 | 24 | wait, |
bd54ad19 | 25 | waitJobs, |
4f219914 | 26 | waitUntilLivePublishedOnAllServers |
d23dd9fb | 27 | } from '@shared/extra-utils' |
4c7e60bc C |
28 | import { |
29 | HttpStatusCode, | |
30 | LiveVideo, | |
31 | LiveVideoCreate, | |
32 | VideoDetails, | |
33 | VideoPrivacy, | |
34 | VideoState, | |
35 | VideoStreamingPlaylistType | |
36 | } from '@shared/models' | |
af4ae64f C |
37 | |
38 | const expect = chai.expect | |
39 | ||
40 | describe('Test live', function () { | |
254d3579 | 41 | let servers: PeerTubeServer[] = [] |
4f219914 | 42 | let commands: LiveCommand[] |
af4ae64f C |
43 | |
44 | before(async function () { | |
45 | this.timeout(120000) | |
46 | ||
254d3579 | 47 | servers = await createMultipleServers(2) |
af4ae64f C |
48 | |
49 | // Get the access tokens | |
50 | await setAccessTokensToServers(servers) | |
51 | await setDefaultVideoChannel(servers) | |
52 | ||
89d241a7 | 53 | await servers[0].config.updateCustomSubConfig({ |
65e6e260 C |
54 | newConfig: { |
55 | live: { | |
56 | enabled: true, | |
57 | allowReplay: true, | |
58 | transcoding: { | |
59 | enabled: false | |
60 | } | |
68e70a74 | 61 | } |
af4ae64f C |
62 | } |
63 | }) | |
64 | ||
65 | // Server 1 and server 2 follow each other | |
66 | await doubleFollow(servers[0], servers[1]) | |
4f219914 | 67 | |
89d241a7 | 68 | commands = servers.map(s => s.live) |
af4ae64f C |
69 | }) |
70 | ||
71 | describe('Live creation, update and delete', function () { | |
68e70a74 | 72 | let liveVideoUUID: string |
af4ae64f C |
73 | |
74 | it('Should create a live with the appropriate parameters', async function () { | |
75 | this.timeout(20000) | |
76 | ||
77 | const attributes: LiveVideoCreate = { | |
78 | category: 1, | |
79 | licence: 2, | |
80 | language: 'fr', | |
81 | description: 'super live description', | |
82 | support: 'support field', | |
89d241a7 | 83 | channelId: servers[0].store.channel.id, |
af4ae64f C |
84 | nsfw: false, |
85 | waitTranscoding: false, | |
86 | name: 'my super live', | |
87 | tags: [ 'tag1', 'tag2' ], | |
88 | commentsEnabled: false, | |
89 | downloadEnabled: false, | |
90 | saveReplay: true, | |
91 | privacy: VideoPrivacy.PUBLIC, | |
92 | previewfile: 'video_short1-preview.webm.jpg', | |
93 | thumbnailfile: 'video_short1.webm.jpg' | |
94 | } | |
95 | ||
04aed767 | 96 | const live = await commands[0].create({ fields: attributes }) |
4f219914 | 97 | liveVideoUUID = live.uuid |
af4ae64f C |
98 | |
99 | await waitJobs(servers) | |
100 | ||
101 | for (const server of servers) { | |
89d241a7 | 102 | const video = await server.videos.get({ id: liveVideoUUID }) |
af4ae64f C |
103 | |
104 | expect(video.category.id).to.equal(1) | |
105 | expect(video.licence.id).to.equal(2) | |
106 | expect(video.language.id).to.equal('fr') | |
107 | expect(video.description).to.equal('super live description') | |
108 | expect(video.support).to.equal('support field') | |
109 | ||
89d241a7 C |
110 | expect(video.channel.name).to.equal(servers[0].store.channel.name) |
111 | expect(video.channel.host).to.equal(servers[0].store.channel.host) | |
af4ae64f | 112 | |
1ab60243 C |
113 | expect(video.isLive).to.be.true |
114 | ||
af4ae64f C |
115 | expect(video.nsfw).to.be.false |
116 | expect(video.waitTranscoding).to.be.false | |
117 | expect(video.name).to.equal('my super live') | |
118 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2' ]) | |
119 | expect(video.commentsEnabled).to.be.false | |
120 | expect(video.downloadEnabled).to.be.false | |
121 | expect(video.privacy.id).to.equal(VideoPrivacy.PUBLIC) | |
122 | ||
123 | await testImage(server.url, 'video_short1-preview.webm', video.previewPath) | |
124 | await testImage(server.url, 'video_short1.webm', video.thumbnailPath) | |
125 | ||
89d241a7 | 126 | const live = await server.live.get({ videoId: liveVideoUUID }) |
af4ae64f C |
127 | |
128 | if (server.url === servers[0].url) { | |
c655c9ef | 129 | expect(live.rtmpUrl).to.equal('rtmp://' + server.hostname + ':' + servers[0].rtmpPort + '/live') |
af4ae64f C |
130 | expect(live.streamKey).to.not.be.empty |
131 | } else { | |
132 | expect(live.rtmpUrl).to.be.null | |
133 | expect(live.streamKey).to.be.null | |
134 | } | |
135 | ||
136 | expect(live.saveReplay).to.be.true | |
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 | ||
04aed767 | 181 | await commands[0].update({ videoId: liveVideoUUID, fields: { saveReplay: false } }) |
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 { | |
193 | expect(live.rtmpUrl).to.be.null | |
194 | expect(live.streamKey).to.be.null | |
195 | } | |
196 | ||
197 | expect(live.saveReplay).to.be.false | |
198 | } | |
199 | }) | |
200 | ||
201 | it('Delete the live', async function () { | |
202 | this.timeout(10000) | |
203 | ||
89d241a7 | 204 | await servers[0].videos.remove({ id: liveVideoUUID }) |
af4ae64f C |
205 | await waitJobs(servers) |
206 | }) | |
207 | ||
208 | it('Should have the live deleted', async function () { | |
209 | for (const server of servers) { | |
89d241a7 C |
210 | await server.videos.get({ id: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) |
211 | await server.live.get({ videoId: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) | |
af4ae64f C |
212 | } |
213 | }) | |
214 | }) | |
215 | ||
1fd61899 | 216 | describe('Live filters', function () { |
4f219914 | 217 | let ffmpegCommand: any |
1fd61899 C |
218 | let liveVideoId: string |
219 | let vodVideoId: string | |
220 | ||
221 | before(async function () { | |
222 | this.timeout(120000) | |
223 | ||
89d241a7 | 224 | vodVideoId = (await servers[0].videos.quickUpload({ name: 'vod video' })).uuid |
1fd61899 | 225 | |
89d241a7 | 226 | const liveOptions = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: servers[0].store.channel.id } |
04aed767 | 227 | const live = await commands[0].create({ fields: liveOptions }) |
4f219914 | 228 | liveVideoId = live.uuid |
1fd61899 | 229 | |
89d241a7 | 230 | ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoId }) |
8ebf2a5d | 231 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) |
1fd61899 C |
232 | await waitJobs(servers) |
233 | }) | |
234 | ||
235 | it('Should only display lives', async function () { | |
89d241a7 | 236 | const { data, total } = await servers[0].videos.list({ isLive: true }) |
1fd61899 | 237 | |
d23dd9fb C |
238 | expect(total).to.equal(1) |
239 | expect(data).to.have.lengthOf(1) | |
240 | expect(data[0].name).to.equal('live') | |
1fd61899 C |
241 | }) |
242 | ||
243 | it('Should not display lives', async function () { | |
89d241a7 | 244 | const { data, total } = await servers[0].videos.list({ isLive: false }) |
1fd61899 | 245 | |
d23dd9fb C |
246 | expect(total).to.equal(1) |
247 | expect(data).to.have.lengthOf(1) | |
248 | expect(data[0].name).to.equal('vod video') | |
1fd61899 C |
249 | }) |
250 | ||
251 | it('Should display my lives', async function () { | |
252 | this.timeout(60000) | |
253 | ||
4f219914 | 254 | await stopFfmpeg(ffmpegCommand) |
1fd61899 C |
255 | await waitJobs(servers) |
256 | ||
89d241a7 | 257 | const { data } = await servers[0].videos.listMyVideos({ isLive: true }) |
1fd61899 | 258 | |
d23dd9fb | 259 | const result = data.every(v => v.isLive) |
1fd61899 C |
260 | expect(result).to.be.true |
261 | }) | |
262 | ||
263 | it('Should not display my lives', async function () { | |
89d241a7 | 264 | const { data } = await servers[0].videos.listMyVideos({ isLive: false }) |
1fd61899 | 265 | |
d23dd9fb | 266 | const result = data.every(v => !v.isLive) |
1fd61899 C |
267 | expect(result).to.be.true |
268 | }) | |
269 | ||
270 | after(async function () { | |
89d241a7 C |
271 | await servers[0].videos.remove({ id: vodVideoId }) |
272 | await servers[0].videos.remove({ id: liveVideoId }) | |
1fd61899 C |
273 | }) |
274 | }) | |
275 | ||
68e70a74 C |
276 | describe('Stream checks', function () { |
277 | let liveVideo: LiveVideo & VideoDetails | |
278 | let rtmpUrl: string | |
279 | ||
280 | before(function () { | |
c655c9ef | 281 | rtmpUrl = 'rtmp://' + servers[0].hostname + ':' + servers[0].rtmpPort + '' |
68e70a74 | 282 | }) |
af4ae64f | 283 | |
68e70a74 | 284 | async function createLiveWrapper () { |
97969c4e C |
285 | const liveAttributes = { |
286 | name: 'user live', | |
89d241a7 | 287 | channelId: servers[0].store.channel.id, |
97969c4e | 288 | privacy: VideoPrivacy.PUBLIC, |
68e70a74 | 289 | saveReplay: false |
97969c4e C |
290 | } |
291 | ||
04aed767 | 292 | const { uuid } = await commands[0].create({ fields: liveAttributes }) |
97969c4e | 293 | |
04aed767 | 294 | const live = await commands[0].get({ videoId: uuid }) |
89d241a7 | 295 | const video = await servers[0].videos.get({ id: uuid }) |
97969c4e | 296 | |
d23dd9fb | 297 | return Object.assign(video, live) |
68e70a74 | 298 | } |
97969c4e | 299 | |
68e70a74 | 300 | it('Should not allow a stream without the appropriate path', async function () { |
2df6f943 | 301 | this.timeout(60000) |
97969c4e | 302 | |
68e70a74 | 303 | liveVideo = await createLiveWrapper() |
97969c4e | 304 | |
c826f34a | 305 | const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl + '/bad-live', streamKey: liveVideo.streamKey }) |
68e70a74 | 306 | await testFfmpegStreamError(command, true) |
af4ae64f C |
307 | }) |
308 | ||
68e70a74 | 309 | it('Should not allow a stream without the appropriate stream key', async function () { |
2df6f943 | 310 | this.timeout(60000) |
97969c4e | 311 | |
c826f34a | 312 | const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl + '/live', streamKey: 'bad-stream-key' }) |
68e70a74 | 313 | await testFfmpegStreamError(command, true) |
97969c4e C |
314 | }) |
315 | ||
68e70a74 | 316 | it('Should succeed with the correct params', async function () { |
2df6f943 | 317 | this.timeout(60000) |
97969c4e | 318 | |
c826f34a | 319 | const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl + '/live', streamKey: liveVideo.streamKey }) |
68e70a74 | 320 | await testFfmpegStreamError(command, false) |
af4ae64f C |
321 | }) |
322 | ||
1ab60243 C |
323 | it('Should list this live now someone stream into it', async function () { |
324 | for (const server of servers) { | |
89d241a7 | 325 | const { total, data } = await server.videos.list() |
1ab60243 | 326 | |
d23dd9fb C |
327 | expect(total).to.equal(1) |
328 | expect(data).to.have.lengthOf(1) | |
1ab60243 | 329 | |
d23dd9fb | 330 | const video = data[0] |
1ab60243 C |
331 | expect(video.name).to.equal('user live') |
332 | expect(video.isLive).to.be.true | |
333 | } | |
334 | }) | |
335 | ||
68e70a74 | 336 | it('Should not allow a stream on a live that was blacklisted', async function () { |
2df6f943 | 337 | this.timeout(60000) |
97969c4e | 338 | |
68e70a74 | 339 | liveVideo = await createLiveWrapper() |
af4ae64f | 340 | |
89d241a7 | 341 | await servers[0].blacklist.add({ videoId: liveVideo.uuid }) |
af4ae64f | 342 | |
c826f34a | 343 | const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl + '/live', streamKey: liveVideo.streamKey }) |
68e70a74 | 344 | await testFfmpegStreamError(command, true) |
af4ae64f C |
345 | }) |
346 | ||
68e70a74 | 347 | it('Should not allow a stream on a live that was deleted', async function () { |
2df6f943 | 348 | this.timeout(60000) |
af4ae64f | 349 | |
68e70a74 | 350 | liveVideo = await createLiveWrapper() |
af4ae64f | 351 | |
89d241a7 | 352 | await servers[0].videos.remove({ id: liveVideo.uuid }) |
af4ae64f | 353 | |
c826f34a | 354 | const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl + '/live', streamKey: liveVideo.streamKey }) |
68e70a74 | 355 | await testFfmpegStreamError(command, true) |
af4ae64f C |
356 | }) |
357 | }) | |
358 | ||
359 | describe('Live transcoding', function () { | |
bd54ad19 C |
360 | let liveVideoId: string |
361 | ||
362 | async function createLiveWrapper (saveReplay: boolean) { | |
363 | const liveAttributes = { | |
364 | name: 'live video', | |
89d241a7 | 365 | channelId: servers[0].store.channel.id, |
bd54ad19 C |
366 | privacy: VideoPrivacy.PUBLIC, |
367 | saveReplay | |
368 | } | |
369 | ||
04aed767 | 370 | const { uuid } = await commands[0].create({ fields: liveAttributes }) |
4f219914 | 371 | return uuid |
bd54ad19 C |
372 | } |
373 | ||
374 | async function testVideoResolutions (liveVideoId: string, resolutions: number[]) { | |
375 | for (const server of servers) { | |
89d241a7 | 376 | const { data } = await server.videos.list() |
d23dd9fb | 377 | expect(data.find(v => v.uuid === liveVideoId)).to.exist |
bd54ad19 | 378 | |
89d241a7 | 379 | const video = await server.videos.get({ id: liveVideoId }) |
bd54ad19 C |
380 | |
381 | expect(video.streamingPlaylists).to.have.lengthOf(1) | |
382 | ||
383 | const hlsPlaylist = video.streamingPlaylists.find(s => s.type === VideoStreamingPlaylistType.HLS) | |
384 | expect(hlsPlaylist).to.exist | |
385 | ||
386 | // Only finite files are displayed | |
387 | expect(hlsPlaylist.files).to.have.lengthOf(0) | |
388 | ||
57f879a5 | 389 | await checkResolutionsInMasterPlaylist({ server, playlistUrl: hlsPlaylist.playlistUrl, resolutions }) |
5c0904fc C |
390 | |
391 | for (let i = 0; i < resolutions.length; i++) { | |
a800dbf3 | 392 | const segmentNum = 3 |
0d8de275 | 393 | const segmentName = `${i}-00000${segmentNum}.ts` |
04aed767 | 394 | await commands[0].waitUntilSegmentGeneration({ videoUUID: video.uuid, resolution: i, segment: segmentNum }) |
5c0904fc | 395 | |
89d241a7 | 396 | const subPlaylist = await servers[0].streamingPlaylists.get({ |
57f879a5 C |
397 | url: `${servers[0].url}/static/streaming-playlists/hls/${video.uuid}/${i}.m3u8` |
398 | }) | |
5c0904fc C |
399 | |
400 | expect(subPlaylist).to.contain(segmentName) | |
401 | ||
402 | const baseUrlAndPath = servers[0].url + '/static/streaming-playlists/hls' | |
57f879a5 C |
403 | await checkLiveSegmentHash({ |
404 | server, | |
405 | baseUrlSegment: baseUrlAndPath, | |
406 | videoUUID: video.uuid, | |
407 | segmentName, | |
408 | hlsPlaylist | |
409 | }) | |
5c0904fc | 410 | } |
bd54ad19 C |
411 | } |
412 | } | |
413 | ||
414 | function updateConf (resolutions: number[]) { | |
89d241a7 | 415 | return servers[0].config.updateCustomSubConfig({ |
65e6e260 C |
416 | newConfig: { |
417 | live: { | |
bd54ad19 | 418 | enabled: true, |
65e6e260 C |
419 | allowReplay: true, |
420 | maxDuration: -1, | |
421 | transcoding: { | |
422 | enabled: true, | |
423 | resolutions: { | |
424 | '240p': resolutions.includes(240), | |
425 | '360p': resolutions.includes(360), | |
426 | '480p': resolutions.includes(480), | |
427 | '720p': resolutions.includes(720), | |
428 | '1080p': resolutions.includes(1080), | |
429 | '2160p': resolutions.includes(2160) | |
430 | } | |
bd54ad19 C |
431 | } |
432 | } | |
433 | } | |
434 | }) | |
435 | } | |
436 | ||
437 | before(async function () { | |
438 | await updateConf([]) | |
439 | }) | |
af4ae64f C |
440 | |
441 | it('Should enable transcoding without additional resolutions', async function () { | |
d8fb3a2f | 442 | this.timeout(120000) |
bd54ad19 C |
443 | |
444 | liveVideoId = await createLiveWrapper(false) | |
445 | ||
4f219914 | 446 | const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId }) |
8ebf2a5d | 447 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) |
bd54ad19 | 448 | await waitJobs(servers) |
af4ae64f | 449 | |
bd54ad19 C |
450 | await testVideoResolutions(liveVideoId, [ 720 ]) |
451 | ||
4f219914 | 452 | await stopFfmpeg(ffmpegCommand) |
af4ae64f C |
453 | }) |
454 | ||
455 | it('Should enable transcoding with some resolutions', async function () { | |
d8fb3a2f | 456 | this.timeout(120000) |
bd54ad19 C |
457 | |
458 | const resolutions = [ 240, 480 ] | |
459 | await updateConf(resolutions) | |
460 | liveVideoId = await createLiveWrapper(false) | |
461 | ||
4f219914 | 462 | const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId }) |
8ebf2a5d | 463 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) |
bd54ad19 C |
464 | await waitJobs(servers) |
465 | ||
466 | await testVideoResolutions(liveVideoId, resolutions) | |
467 | ||
4f219914 | 468 | await stopFfmpeg(ffmpegCommand) |
af4ae64f C |
469 | }) |
470 | ||
c826f34a C |
471 | it('Should correctly set the appropriate bitrate depending on the input', async function () { |
472 | this.timeout(120000) | |
473 | ||
474 | liveVideoId = await createLiveWrapper(false) | |
475 | ||
476 | const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({ | |
477 | videoId: liveVideoId, | |
478 | fixtureName: 'video_short.mp4', | |
479 | copyCodecs: true | |
480 | }) | |
481 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) | |
482 | await waitJobs(servers) | |
483 | ||
484 | const video = await servers[0].videos.get({ id: liveVideoId }) | |
485 | ||
486 | const masterPlaylist = video.streamingPlaylists[0].playlistUrl | |
487 | const probe = await ffprobePromise(masterPlaylist) | |
488 | ||
489 | const bitrates = probe.streams.map(s => parseInt(s.tags.variant_bitrate)) | |
490 | for (const bitrate of bitrates) { | |
491 | expect(bitrate).to.exist | |
492 | expect(isNaN(bitrate)).to.be.false | |
493 | expect(bitrate).to.be.below(61_000_000) // video_short.mp4 bitrate | |
494 | } | |
495 | ||
496 | await stopFfmpeg(ffmpegCommand) | |
497 | }) | |
498 | ||
af4ae64f | 499 | it('Should enable transcoding with some resolutions and correctly save them', async function () { |
f42c2152 | 500 | this.timeout(200000) |
bd54ad19 C |
501 | |
502 | const resolutions = [ 240, 360, 720 ] | |
ca5c612b | 503 | |
bd54ad19 C |
504 | await updateConf(resolutions) |
505 | liveVideoId = await createLiveWrapper(true) | |
506 | ||
4f219914 | 507 | const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) |
8ebf2a5d | 508 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) |
bd54ad19 C |
509 | await waitJobs(servers) |
510 | ||
511 | await testVideoResolutions(liveVideoId, resolutions) | |
512 | ||
4f219914 | 513 | await stopFfmpeg(ffmpegCommand) |
04aed767 | 514 | await commands[0].waitUntilEnded({ videoId: liveVideoId }) |
34caef7f | 515 | |
bd54ad19 C |
516 | await waitJobs(servers) |
517 | ||
8ebf2a5d | 518 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) |
e0783718 | 519 | |
9f430a53 C |
520 | const maxBitrateLimits = { |
521 | 720: 6500 * 1000, // 60FPS | |
522 | 360: 1250 * 1000, | |
523 | 240: 700 * 1000 | |
524 | } | |
525 | ||
526 | const minBitrateLimits = { | |
527 | 720: 5500 * 1000, | |
528 | 360: 1000 * 1000, | |
529 | 240: 550 * 1000 | |
ca5c612b C |
530 | } |
531 | ||
bd54ad19 | 532 | for (const server of servers) { |
89d241a7 | 533 | const video = await server.videos.get({ id: liveVideoId }) |
bd54ad19 | 534 | |
e0783718 | 535 | expect(video.state.id).to.equal(VideoState.PUBLISHED) |
bd54ad19 C |
536 | expect(video.duration).to.be.greaterThan(1) |
537 | expect(video.files).to.have.lengthOf(0) | |
538 | ||
539 | const hlsPlaylist = video.streamingPlaylists.find(s => s.type === VideoStreamingPlaylistType.HLS) | |
f2eb23cd RK |
540 | await makeRawRequest(hlsPlaylist.playlistUrl, HttpStatusCode.OK_200) |
541 | await makeRawRequest(hlsPlaylist.segmentsSha256Url, HttpStatusCode.OK_200) | |
bd54ad19 | 542 | |
764b1a14 C |
543 | // We should have generated random filenames |
544 | expect(basename(hlsPlaylist.playlistUrl)).to.not.equal('master.m3u8') | |
545 | expect(basename(hlsPlaylist.segmentsSha256Url)).to.not.equal('segments-sha256.json') | |
546 | ||
bd54ad19 C |
547 | expect(hlsPlaylist.files).to.have.lengthOf(resolutions.length) |
548 | ||
549 | for (const resolution of resolutions) { | |
550 | const file = hlsPlaylist.files.find(f => f.resolution.id === resolution) | |
551 | ||
552 | expect(file).to.exist | |
bd54ad19 C |
553 | expect(file.size).to.be.greaterThan(1) |
554 | ||
884d2c39 C |
555 | if (resolution >= 720) { |
556 | expect(file.fps).to.be.approximately(60, 2) | |
557 | } else { | |
558 | expect(file.fps).to.be.approximately(30, 2) | |
559 | } | |
560 | ||
764b1a14 C |
561 | const filename = basename(file.fileUrl) |
562 | expect(filename).to.not.contain(video.uuid) | |
563 | ||
89d241a7 | 564 | const segmentPath = servers[0].servers.buildDirectory(join('streaming-playlists', 'hls', video.uuid, filename)) |
ca5c612b C |
565 | |
566 | const probe = await ffprobePromise(segmentPath) | |
567 | const videoStream = await getVideoStreamFromFile(segmentPath, probe) | |
6b67897e | 568 | |
9f430a53 C |
569 | expect(probe.format.bit_rate).to.be.below(maxBitrateLimits[videoStream.height]) |
570 | expect(probe.format.bit_rate).to.be.at.least(minBitrateLimits[videoStream.height]) | |
ca5c612b | 571 | |
f2eb23cd RK |
572 | await makeRawRequest(file.torrentUrl, HttpStatusCode.OK_200) |
573 | await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200) | |
bd54ad19 C |
574 | } |
575 | } | |
af4ae64f C |
576 | }) |
577 | ||
578 | it('Should correctly have cleaned up the live files', async function () { | |
bd54ad19 C |
579 | this.timeout(30000) |
580 | ||
764b1a14 | 581 | await checkLiveCleanupAfterSave(servers[0], liveVideoId, [ 240, 360, 720 ]) |
af4ae64f C |
582 | }) |
583 | }) | |
584 | ||
5c0904fc C |
585 | describe('After a server restart', function () { |
586 | let liveVideoId: string | |
587 | let liveVideoReplayId: string | |
588 | ||
589 | async function createLiveWrapper (saveReplay: boolean) { | |
590 | const liveAttributes = { | |
591 | name: 'live video', | |
89d241a7 | 592 | channelId: servers[0].store.channel.id, |
5c0904fc C |
593 | privacy: VideoPrivacy.PUBLIC, |
594 | saveReplay | |
595 | } | |
596 | ||
04aed767 | 597 | const { uuid } = await commands[0].create({ fields: liveAttributes }) |
4f219914 | 598 | return uuid |
5c0904fc C |
599 | } |
600 | ||
601 | before(async function () { | |
0d8de275 | 602 | this.timeout(120000) |
5c0904fc C |
603 | |
604 | liveVideoId = await createLiveWrapper(false) | |
605 | liveVideoReplayId = await createLiveWrapper(true) | |
606 | ||
607 | await Promise.all([ | |
4f219914 C |
608 | commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId }), |
609 | commands[0].sendRTMPStreamInVideo({ videoId: liveVideoReplayId }) | |
5c0904fc C |
610 | ]) |
611 | ||
612 | await Promise.all([ | |
04aed767 C |
613 | commands[0].waitUntilPublished({ videoId: liveVideoId }), |
614 | commands[0].waitUntilPublished({ videoId: liveVideoReplayId }) | |
5c0904fc C |
615 | ]) |
616 | ||
04aed767 C |
617 | await commands[0].waitUntilSegmentGeneration({ videoUUID: liveVideoId, resolution: 0, segment: 2 }) |
618 | await commands[0].waitUntilSegmentGeneration({ videoUUID: liveVideoReplayId, resolution: 0, segment: 2 }) | |
0d8de275 | 619 | |
9293139f | 620 | await killallServers([ servers[0] ]) |
254d3579 | 621 | await servers[0].run() |
5c0904fc C |
622 | |
623 | await wait(5000) | |
624 | }) | |
625 | ||
626 | it('Should cleanup lives', async function () { | |
627 | this.timeout(60000) | |
628 | ||
04aed767 | 629 | await commands[0].waitUntilEnded({ videoId: liveVideoId }) |
5c0904fc C |
630 | }) |
631 | ||
632 | it('Should save a live replay', async function () { | |
0d8de275 | 633 | this.timeout(120000) |
5c0904fc | 634 | |
04aed767 | 635 | await commands[0].waitUntilPublished({ videoId: liveVideoReplayId }) |
5c0904fc C |
636 | }) |
637 | }) | |
638 | ||
af4ae64f C |
639 | after(async function () { |
640 | await cleanupTests(servers) | |
641 | }) | |
642 | }) |