]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/extra-utils/videos/live.ts
Optimize torrent URL update
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / videos / live.ts
index 92cb9104c4a5b828a2800c89bc579c7634ad480c..29f99ed6d0bfec68bc48263f8e542126aaa9253a 100644 (file)
@@ -4,19 +4,32 @@ import { expect } from 'chai'
 import * as ffmpeg from 'fluent-ffmpeg'
 import { pathExists, readdir } from 'fs-extra'
 import { join } from 'path'
-import { buildAbsoluteFixturePath, buildServerDirectory, wait } from '../miscs/miscs'
-import { ServerInfo } from '../server/servers'
+import { buildAbsoluteFixturePath, wait } from '../miscs'
+import { PeerTubeServer } from '../server/server'
+
+function sendRTMPStream (options: {
+  rtmpBaseUrl: string
+  streamKey: string
+  fixtureName?: string // default video_short.mp4
+  copyCodecs?: boolean // default false
+}) {
+  const { rtmpBaseUrl, streamKey, fixtureName = 'video_short.mp4', copyCodecs = false } = options
 
-function sendRTMPStream (rtmpBaseUrl: string, streamKey: string, fixtureName = 'video_short.mp4') {
   const fixture = buildAbsoluteFixturePath(fixtureName)
 
   const command = ffmpeg(fixture)
   command.inputOption('-stream_loop -1')
   command.inputOption('-re')
-  command.outputOption('-c:v libx264')
-  command.outputOption('-g 50')
-  command.outputOption('-keyint_min 2')
-  command.outputOption('-r 60')
+
+  if (copyCodecs) {
+    command.outputOption('-c copy')
+  } else {
+    command.outputOption('-c:v libx264')
+    command.outputOption('-g 50')
+    command.outputOption('-keyint_min 2')
+    command.outputOption('-r 60')
+  }
+
   command.outputOption('-f flv')
 
   const rtmpUrl = rtmpBaseUrl + '/' + streamKey
@@ -70,14 +83,20 @@ async function stopFfmpeg (command: ffmpeg.FfmpegCommand) {
   await wait(500)
 }
 
-async function waitUntilLivePublishedOnAllServers (servers: ServerInfo[], videoId: string) {
+async function waitUntilLivePublishedOnAllServers (servers: PeerTubeServer[], videoId: string) {
+  for (const server of servers) {
+    await server.live.waitUntilPublished({ videoId })
+  }
+}
+
+async function waitUntilLiveSavedOnAllServers (servers: PeerTubeServer[], videoId: string) {
   for (const server of servers) {
-    await server.liveCommand.waitUntilPublished({ videoId })
+    await server.live.waitUntilSaved({ videoId })
   }
 }
 
-async function checkLiveCleanup (server: ServerInfo, videoUUID: string, resolutions: number[] = []) {
-  const basePath = buildServerDirectory(server, 'streaming-playlists')
+async function checkLiveCleanupAfterSave (server: PeerTubeServer, videoUUID: string, resolutions: number[] = []) {
+  const basePath = server.servers.buildDirectory('streaming-playlists')
   const hlsPath = join(basePath, 'hls', videoUUID)
 
   if (resolutions.length === 0) {
@@ -93,12 +112,18 @@ async function checkLiveCleanup (server: ServerInfo, videoUUID: string, resoluti
   expect(files).to.have.lengthOf(resolutions.length * 2 + 2)
 
   for (const resolution of resolutions) {
-    expect(files).to.contain(`${videoUUID}-${resolution}-fragmented.mp4`)
-    expect(files).to.contain(`${resolution}.m3u8`)
+    const fragmentedFile = files.find(f => f.endsWith(`-${resolution}-fragmented.mp4`))
+    expect(fragmentedFile).to.exist
+
+    const playlistFile = files.find(f => f.endsWith(`${resolution}.m3u8`))
+    expect(playlistFile).to.exist
   }
 
-  expect(files).to.contain('master.m3u8')
-  expect(files).to.contain('segments-sha256.json')
+  const masterPlaylistFile = files.find(f => f.endsWith('-master.m3u8'))
+  expect(masterPlaylistFile).to.exist
+
+  const shaFile = files.find(f => f.endsWith('-segments-sha256.json'))
+  expect(shaFile).to.exist
 }
 
 export {
@@ -107,5 +132,6 @@ export {
   testFfmpegStreamError,
   stopFfmpeg,
   waitUntilLivePublishedOnAllServers,
-  checkLiveCleanup
+  waitUntilLiveSavedOnAllServers,
+  checkLiveCleanupAfterSave
 }