]>
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: { | |
8dd754c7 | 424 | '144p': resolutions.includes(144), |
65e6e260 C |
425 | '240p': resolutions.includes(240), |
426 | '360p': resolutions.includes(360), | |
427 | '480p': resolutions.includes(480), | |
428 | '720p': resolutions.includes(720), | |
429 | '1080p': resolutions.includes(1080), | |
430 | '2160p': resolutions.includes(2160) | |
431 | } | |
bd54ad19 C |
432 | } |
433 | } | |
434 | } | |
435 | }) | |
436 | } | |
437 | ||
438 | before(async function () { | |
439 | await updateConf([]) | |
440 | }) | |
af4ae64f C |
441 | |
442 | it('Should enable transcoding without additional resolutions', async function () { | |
d8fb3a2f | 443 | this.timeout(120000) |
bd54ad19 C |
444 | |
445 | liveVideoId = await createLiveWrapper(false) | |
446 | ||
4f219914 | 447 | const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId }) |
8ebf2a5d | 448 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) |
bd54ad19 | 449 | await waitJobs(servers) |
af4ae64f | 450 | |
bd54ad19 C |
451 | await testVideoResolutions(liveVideoId, [ 720 ]) |
452 | ||
4f219914 | 453 | await stopFfmpeg(ffmpegCommand) |
af4ae64f C |
454 | }) |
455 | ||
456 | it('Should enable transcoding with some resolutions', async function () { | |
d8fb3a2f | 457 | this.timeout(120000) |
bd54ad19 C |
458 | |
459 | const resolutions = [ 240, 480 ] | |
460 | await updateConf(resolutions) | |
461 | liveVideoId = await createLiveWrapper(false) | |
462 | ||
4f219914 | 463 | const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId }) |
8ebf2a5d | 464 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) |
bd54ad19 C |
465 | await waitJobs(servers) |
466 | ||
467 | await testVideoResolutions(liveVideoId, resolutions) | |
468 | ||
4f219914 | 469 | await stopFfmpeg(ffmpegCommand) |
af4ae64f C |
470 | }) |
471 | ||
c826f34a C |
472 | it('Should correctly set the appropriate bitrate depending on the input', async function () { |
473 | this.timeout(120000) | |
474 | ||
475 | liveVideoId = await createLiveWrapper(false) | |
476 | ||
477 | const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({ | |
478 | videoId: liveVideoId, | |
479 | fixtureName: 'video_short.mp4', | |
480 | copyCodecs: true | |
481 | }) | |
482 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) | |
483 | await waitJobs(servers) | |
484 | ||
485 | const video = await servers[0].videos.get({ id: liveVideoId }) | |
486 | ||
487 | const masterPlaylist = video.streamingPlaylists[0].playlistUrl | |
488 | const probe = await ffprobePromise(masterPlaylist) | |
489 | ||
490 | const bitrates = probe.streams.map(s => parseInt(s.tags.variant_bitrate)) | |
491 | for (const bitrate of bitrates) { | |
492 | expect(bitrate).to.exist | |
493 | expect(isNaN(bitrate)).to.be.false | |
494 | expect(bitrate).to.be.below(61_000_000) // video_short.mp4 bitrate | |
495 | } | |
496 | ||
497 | await stopFfmpeg(ffmpegCommand) | |
498 | }) | |
499 | ||
af4ae64f | 500 | it('Should enable transcoding with some resolutions and correctly save them', async function () { |
f42c2152 | 501 | this.timeout(200000) |
bd54ad19 C |
502 | |
503 | const resolutions = [ 240, 360, 720 ] | |
ca5c612b | 504 | |
bd54ad19 C |
505 | await updateConf(resolutions) |
506 | liveVideoId = await createLiveWrapper(true) | |
507 | ||
4f219914 | 508 | const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' }) |
8ebf2a5d | 509 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) |
bd54ad19 C |
510 | await waitJobs(servers) |
511 | ||
512 | await testVideoResolutions(liveVideoId, resolutions) | |
513 | ||
4f219914 | 514 | await stopFfmpeg(ffmpegCommand) |
04aed767 | 515 | await commands[0].waitUntilEnded({ videoId: liveVideoId }) |
34caef7f | 516 | |
bd54ad19 C |
517 | await waitJobs(servers) |
518 | ||
8ebf2a5d | 519 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) |
e0783718 | 520 | |
9f430a53 C |
521 | const maxBitrateLimits = { |
522 | 720: 6500 * 1000, // 60FPS | |
523 | 360: 1250 * 1000, | |
524 | 240: 700 * 1000 | |
525 | } | |
526 | ||
527 | const minBitrateLimits = { | |
528 | 720: 5500 * 1000, | |
529 | 360: 1000 * 1000, | |
530 | 240: 550 * 1000 | |
ca5c612b C |
531 | } |
532 | ||
bd54ad19 | 533 | for (const server of servers) { |
89d241a7 | 534 | const video = await server.videos.get({ id: liveVideoId }) |
bd54ad19 | 535 | |
e0783718 | 536 | expect(video.state.id).to.equal(VideoState.PUBLISHED) |
bd54ad19 C |
537 | expect(video.duration).to.be.greaterThan(1) |
538 | expect(video.files).to.have.lengthOf(0) | |
539 | ||
540 | const hlsPlaylist = video.streamingPlaylists.find(s => s.type === VideoStreamingPlaylistType.HLS) | |
f2eb23cd RK |
541 | await makeRawRequest(hlsPlaylist.playlistUrl, HttpStatusCode.OK_200) |
542 | await makeRawRequest(hlsPlaylist.segmentsSha256Url, HttpStatusCode.OK_200) | |
bd54ad19 | 543 | |
764b1a14 C |
544 | // We should have generated random filenames |
545 | expect(basename(hlsPlaylist.playlistUrl)).to.not.equal('master.m3u8') | |
546 | expect(basename(hlsPlaylist.segmentsSha256Url)).to.not.equal('segments-sha256.json') | |
547 | ||
bd54ad19 C |
548 | expect(hlsPlaylist.files).to.have.lengthOf(resolutions.length) |
549 | ||
550 | for (const resolution of resolutions) { | |
551 | const file = hlsPlaylist.files.find(f => f.resolution.id === resolution) | |
552 | ||
553 | expect(file).to.exist | |
bd54ad19 C |
554 | expect(file.size).to.be.greaterThan(1) |
555 | ||
884d2c39 C |
556 | if (resolution >= 720) { |
557 | expect(file.fps).to.be.approximately(60, 2) | |
558 | } else { | |
559 | expect(file.fps).to.be.approximately(30, 2) | |
560 | } | |
561 | ||
764b1a14 C |
562 | const filename = basename(file.fileUrl) |
563 | expect(filename).to.not.contain(video.uuid) | |
564 | ||
89d241a7 | 565 | const segmentPath = servers[0].servers.buildDirectory(join('streaming-playlists', 'hls', video.uuid, filename)) |
ca5c612b C |
566 | |
567 | const probe = await ffprobePromise(segmentPath) | |
568 | const videoStream = await getVideoStreamFromFile(segmentPath, probe) | |
6b67897e | 569 | |
9f430a53 C |
570 | expect(probe.format.bit_rate).to.be.below(maxBitrateLimits[videoStream.height]) |
571 | expect(probe.format.bit_rate).to.be.at.least(minBitrateLimits[videoStream.height]) | |
ca5c612b | 572 | |
f2eb23cd RK |
573 | await makeRawRequest(file.torrentUrl, HttpStatusCode.OK_200) |
574 | await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200) | |
bd54ad19 C |
575 | } |
576 | } | |
af4ae64f C |
577 | }) |
578 | ||
579 | it('Should correctly have cleaned up the live files', async function () { | |
bd54ad19 C |
580 | this.timeout(30000) |
581 | ||
764b1a14 | 582 | await checkLiveCleanupAfterSave(servers[0], liveVideoId, [ 240, 360, 720 ]) |
af4ae64f C |
583 | }) |
584 | }) | |
585 | ||
5c0904fc C |
586 | describe('After a server restart', function () { |
587 | let liveVideoId: string | |
588 | let liveVideoReplayId: string | |
589 | ||
590 | async function createLiveWrapper (saveReplay: boolean) { | |
591 | const liveAttributes = { | |
592 | name: 'live video', | |
89d241a7 | 593 | channelId: servers[0].store.channel.id, |
5c0904fc C |
594 | privacy: VideoPrivacy.PUBLIC, |
595 | saveReplay | |
596 | } | |
597 | ||
04aed767 | 598 | const { uuid } = await commands[0].create({ fields: liveAttributes }) |
4f219914 | 599 | return uuid |
5c0904fc C |
600 | } |
601 | ||
602 | before(async function () { | |
0d8de275 | 603 | this.timeout(120000) |
5c0904fc C |
604 | |
605 | liveVideoId = await createLiveWrapper(false) | |
606 | liveVideoReplayId = await createLiveWrapper(true) | |
607 | ||
608 | await Promise.all([ | |
4f219914 C |
609 | commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId }), |
610 | commands[0].sendRTMPStreamInVideo({ videoId: liveVideoReplayId }) | |
5c0904fc C |
611 | ]) |
612 | ||
613 | await Promise.all([ | |
04aed767 C |
614 | commands[0].waitUntilPublished({ videoId: liveVideoId }), |
615 | commands[0].waitUntilPublished({ videoId: liveVideoReplayId }) | |
5c0904fc C |
616 | ]) |
617 | ||
04aed767 C |
618 | await commands[0].waitUntilSegmentGeneration({ videoUUID: liveVideoId, resolution: 0, segment: 2 }) |
619 | await commands[0].waitUntilSegmentGeneration({ videoUUID: liveVideoReplayId, resolution: 0, segment: 2 }) | |
0d8de275 | 620 | |
9293139f | 621 | await killallServers([ servers[0] ]) |
254d3579 | 622 | await servers[0].run() |
5c0904fc C |
623 | |
624 | await wait(5000) | |
625 | }) | |
626 | ||
627 | it('Should cleanup lives', async function () { | |
628 | this.timeout(60000) | |
629 | ||
04aed767 | 630 | await commands[0].waitUntilEnded({ videoId: liveVideoId }) |
5c0904fc C |
631 | }) |
632 | ||
633 | it('Should save a live replay', async function () { | |
0d8de275 | 634 | this.timeout(120000) |
5c0904fc | 635 | |
04aed767 | 636 | await commands[0].waitUntilPublished({ videoId: liveVideoReplayId }) |
5c0904fc C |
637 | }) |
638 | }) | |
639 | ||
af4ae64f C |
640 | after(async function () { |
641 | await cleanupTests(servers) | |
642 | }) | |
643 | }) |