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