diff options
author | Chocobozzz <me@florianbigard.com> | 2022-06-24 09:34:56 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-06-24 09:35:30 +0200 |
commit | b6e2b5df73d3b67e275000f612907859c39d90d1 (patch) | |
tree | 0a95609e1eaeb33d18bf16d6328d25ed69d6d4d6 | |
parent | f2623febd8b7b818e47d995ae59f4f1d2f37961b (diff) | |
download | PeerTube-b6e2b5df73d3b67e275000f612907859c39d90d1.tar.gz PeerTube-b6e2b5df73d3b67e275000f612907859c39d90d1.tar.zst PeerTube-b6e2b5df73d3b67e275000f612907859c39d90d1.zip |
Fix removed sha segments on fast restream
-rw-r--r-- | server/initializers/constants.ts | 2 | ||||
-rw-r--r-- | server/lib/job-queue/handlers/video-live-ending.ts | 13 | ||||
-rw-r--r-- | server/lib/live/live-manager.ts | 5 | ||||
-rw-r--r-- | server/lib/live/live-utils.ts | 15 | ||||
-rw-r--r-- | server/tests/api/live/live-fast-restream.ts | 5 |
5 files changed, 19 insertions, 21 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 6c6628d28..88f370a9a 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -865,7 +865,7 @@ if (isTestInstance() === true) { | |||
865 | 865 | ||
866 | PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME = 5000 | 866 | PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME = 5000 |
867 | 867 | ||
868 | VIDEO_LIVE.CLEANUP_DELAY = getIntEnv('PEERTUBE_TEST_CONSTANTS.VIDEO_LIVE.CLEANUP_DELAY') ?? 5000 | 868 | VIDEO_LIVE.CLEANUP_DELAY = getIntEnv('PEERTUBE_TEST_CONSTANTS_VIDEO_LIVE_CLEANUP_DELAY') ?? 5000 |
869 | VIDEO_LIVE.SEGMENT_TIME_SECONDS.DEFAULT_LATENCY = 2 | 869 | VIDEO_LIVE.SEGMENT_TIME_SECONDS.DEFAULT_LATENCY = 2 |
870 | VIDEO_LIVE.SEGMENT_TIME_SECONDS.SMALL_LATENCY = 1 | 870 | VIDEO_LIVE.SEGMENT_TIME_SECONDS.SMALL_LATENCY = 1 |
871 | VIDEO_LIVE.EDGE_LIVE_DELAY_SEGMENTS_NOTIFICATION = 1 | 871 | VIDEO_LIVE.EDGE_LIVE_DELAY_SEGMENTS_NOTIFICATION = 1 |
diff --git a/server/lib/job-queue/handlers/video-live-ending.ts b/server/lib/job-queue/handlers/video-live-ending.ts index 450bda2fd..b2c42664a 100644 --- a/server/lib/job-queue/handlers/video-live-ending.ts +++ b/server/lib/job-queue/handlers/video-live-ending.ts | |||
@@ -4,13 +4,8 @@ import { join } from 'path' | |||
4 | import { ffprobePromise, getAudioStream, getVideoStreamDimensionsInfo, getVideoStreamDuration } from '@server/helpers/ffmpeg' | 4 | import { ffprobePromise, getAudioStream, getVideoStreamDimensionsInfo, getVideoStreamDuration } from '@server/helpers/ffmpeg' |
5 | import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url' | 5 | import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url' |
6 | import { federateVideoIfNeeded } from '@server/lib/activitypub/videos' | 6 | import { federateVideoIfNeeded } from '@server/lib/activitypub/videos' |
7 | import { cleanupUnsavedNormalLive, cleanupPermanentLive, cleanupTMPLiveFiles, LiveSegmentShaStore } from '@server/lib/live' | 7 | import { cleanupPermanentLive, cleanupTMPLiveFiles, cleanupUnsavedNormalLive } from '@server/lib/live' |
8 | import { | 8 | import { generateHLSMasterPlaylistFilename, generateHlsSha256SegmentsFilename, getLiveReplayBaseDirectory } from '@server/lib/paths' |
9 | generateHLSMasterPlaylistFilename, | ||
10 | generateHlsSha256SegmentsFilename, | ||
11 | getLiveDirectory, | ||
12 | getLiveReplayBaseDirectory | ||
13 | } from '@server/lib/paths' | ||
14 | import { generateVideoMiniature } from '@server/lib/thumbnail' | 9 | import { generateVideoMiniature } from '@server/lib/thumbnail' |
15 | import { generateHlsPlaylistResolutionFromTS } from '@server/lib/transcoding/transcoding' | 10 | import { generateHlsPlaylistResolutionFromTS } from '@server/lib/transcoding/transcoding' |
16 | import { moveToNextState } from '@server/lib/video-state' | 11 | import { moveToNextState } from '@server/lib/video-state' |
@@ -44,8 +39,6 @@ async function processVideoLiveEnding (job: Job) { | |||
44 | return | 39 | return |
45 | } | 40 | } |
46 | 41 | ||
47 | LiveSegmentShaStore.Instance.cleanupShaSegments(liveVideo.uuid) | ||
48 | |||
49 | if (live.saveReplay !== true) { | 42 | if (live.saveReplay !== true) { |
50 | return cleanupLiveAndFederate({ live, video: liveVideo, streamingPlaylistId: payload.streamingPlaylistId }) | 43 | return cleanupLiveAndFederate({ live, video: liveVideo, streamingPlaylistId: payload.streamingPlaylistId }) |
51 | } | 44 | } |
@@ -137,7 +130,7 @@ async function replaceLiveByReplay (options: { | |||
137 | }) { | 130 | }) { |
138 | const { liveVideo, liveSession, live, replayDirectory } = options | 131 | const { liveVideo, liveSession, live, replayDirectory } = options |
139 | 132 | ||
140 | await cleanupTMPLiveFiles(getLiveDirectory(liveVideo)) | 133 | await cleanupTMPLiveFiles(liveVideo) |
141 | 134 | ||
142 | await live.destroy() | 135 | await live.destroy() |
143 | 136 | ||
diff --git a/server/lib/live/live-manager.ts b/server/lib/live/live-manager.ts index f2f064b49..d499b4b1a 100644 --- a/server/lib/live/live-manager.ts +++ b/server/lib/live/live-manager.ts | |||
@@ -27,7 +27,6 @@ import { JobQueue } from '../job-queue' | |||
27 | import { generateHLSMasterPlaylistFilename, generateHlsSha256SegmentsFilename, getLiveReplayBaseDirectory } from '../paths' | 27 | import { generateHLSMasterPlaylistFilename, generateHlsSha256SegmentsFilename, getLiveReplayBaseDirectory } from '../paths' |
28 | import { PeerTubeSocket } from '../peertube-socket' | 28 | import { PeerTubeSocket } from '../peertube-socket' |
29 | import { LiveQuotaStore } from './live-quota-store' | 29 | import { LiveQuotaStore } from './live-quota-store' |
30 | import { LiveSegmentShaStore } from './live-segment-sha-store' | ||
31 | import { cleanupPermanentLive } from './live-utils' | 30 | import { cleanupPermanentLive } from './live-utils' |
32 | import { MuxingSession } from './shared' | 31 | import { MuxingSession } from './shared' |
33 | 32 | ||
@@ -219,9 +218,7 @@ class LiveManager { | |||
219 | return this.abortSession(sessionId) | 218 | return this.abortSession(sessionId) |
220 | } | 219 | } |
221 | 220 | ||
222 | // Cleanup old potential live files (could happen with a permanent live) | 221 | // Cleanup old potential live (could happen with a permanent live) |
223 | LiveSegmentShaStore.Instance.cleanupShaSegments(video.uuid) | ||
224 | |||
225 | const oldStreamingPlaylist = await VideoStreamingPlaylistModel.loadHLSPlaylistByVideo(video.id) | 222 | const oldStreamingPlaylist = await VideoStreamingPlaylistModel.loadHLSPlaylistByVideo(video.id) |
226 | if (oldStreamingPlaylist) { | 223 | if (oldStreamingPlaylist) { |
227 | if (!videoLive.permanentLive) throw new Error('Found previous session in a non permanent live: ' + video.uuid) | 224 | if (!videoLive.permanentLive) throw new Error('Found previous session in a non permanent live: ' + video.uuid) |
diff --git a/server/lib/live/live-utils.ts b/server/lib/live/live-utils.ts index 6305a97a8..bba876642 100644 --- a/server/lib/live/live-utils.ts +++ b/server/lib/live/live-utils.ts | |||
@@ -3,6 +3,7 @@ import { basename, join } from 'path' | |||
3 | import { logger } from '@server/helpers/logger' | 3 | import { logger } from '@server/helpers/logger' |
4 | import { MStreamingPlaylist, MVideo } from '@server/types/models' | 4 | import { MStreamingPlaylist, MVideo } from '@server/types/models' |
5 | import { getLiveDirectory } from '../paths' | 5 | import { getLiveDirectory } from '../paths' |
6 | import { LiveSegmentShaStore } from './live-segment-sha-store' | ||
6 | 7 | ||
7 | function buildConcatenatedName (segmentOrPlaylistPath: string) { | 8 | function buildConcatenatedName (segmentOrPlaylistPath: string) { |
8 | const num = basename(segmentOrPlaylistPath).match(/^(\d+)(-|\.)/) | 9 | const num = basename(segmentOrPlaylistPath).match(/^(\d+)(-|\.)/) |
@@ -11,9 +12,7 @@ function buildConcatenatedName (segmentOrPlaylistPath: string) { | |||
11 | } | 12 | } |
12 | 13 | ||
13 | async function cleanupPermanentLive (video: MVideo, streamingPlaylist: MStreamingPlaylist) { | 14 | async function cleanupPermanentLive (video: MVideo, streamingPlaylist: MStreamingPlaylist) { |
14 | const hlsDirectory = getLiveDirectory(video) | 15 | await cleanupTMPLiveFiles(video) |
15 | |||
16 | await cleanupTMPLiveFiles(hlsDirectory) | ||
17 | 16 | ||
18 | await streamingPlaylist.destroy() | 17 | await streamingPlaylist.destroy() |
19 | } | 18 | } |
@@ -24,11 +23,19 @@ async function cleanupUnsavedNormalLive (video: MVideo, streamingPlaylist: MStre | |||
24 | await remove(hlsDirectory) | 23 | await remove(hlsDirectory) |
25 | 24 | ||
26 | await streamingPlaylist.destroy() | 25 | await streamingPlaylist.destroy() |
26 | |||
27 | LiveSegmentShaStore.Instance.cleanupShaSegments(video.uuid) | ||
27 | } | 28 | } |
28 | 29 | ||
29 | async function cleanupTMPLiveFiles (hlsDirectory: string) { | 30 | async function cleanupTMPLiveFiles (video: MVideo) { |
31 | const hlsDirectory = getLiveDirectory(video) | ||
32 | |||
33 | LiveSegmentShaStore.Instance.cleanupShaSegments(video.uuid) | ||
34 | |||
30 | if (!await pathExists(hlsDirectory)) return | 35 | if (!await pathExists(hlsDirectory)) return |
31 | 36 | ||
37 | logger.info('Cleanup TMP live files of %s.', hlsDirectory) | ||
38 | |||
32 | const files = await readdir(hlsDirectory) | 39 | const files = await readdir(hlsDirectory) |
33 | 40 | ||
34 | for (const filename of files) { | 41 | for (const filename of files) { |
diff --git a/server/tests/api/live/live-fast-restream.ts b/server/tests/api/live/live-fast-restream.ts index 4b5d041ec..b524cbe7f 100644 --- a/server/tests/api/live/live-fast-restream.ts +++ b/server/tests/api/live/live-fast-restream.ts | |||
@@ -57,13 +57,14 @@ describe('Fast restream in live', function () { | |||
57 | } | 57 | } |
58 | 58 | ||
59 | async function ensureLastLiveWorks (liveId: string) { | 59 | async function ensureLastLiveWorks (liveId: string) { |
60 | // Equivalent to PEERTUBE_TEST_CONSTANTS.VIDEO_LIVE.CLEANUP_DELAY | 60 | // Equivalent to PEERTUBE_TEST_CONSTANTS_VIDEO_LIVE_CLEANUP_DELAY |
61 | for (let i = 0; i < 100; i++) { | 61 | for (let i = 0; i < 100; i++) { |
62 | const video = await server.videos.get({ id: liveId }) | 62 | const video = await server.videos.get({ id: liveId }) |
63 | expect(video.streamingPlaylists).to.have.lengthOf(1) | 63 | expect(video.streamingPlaylists).to.have.lengthOf(1) |
64 | 64 | ||
65 | await server.live.getSegment({ videoUUID: liveId, segment: 0, playlistNumber: 0 }) | 65 | await server.live.getSegment({ videoUUID: liveId, segment: 0, playlistNumber: 0 }) |
66 | await makeRawRequest(video.streamingPlaylists[0].playlistUrl, HttpStatusCode.OK_200) | 66 | await makeRawRequest(video.streamingPlaylists[0].playlistUrl, HttpStatusCode.OK_200) |
67 | await makeRawRequest(video.streamingPlaylists[0].segmentsSha256Url, HttpStatusCode.OK_200) | ||
67 | 68 | ||
68 | await wait(100) | 69 | await wait(100) |
69 | } | 70 | } |
@@ -101,7 +102,7 @@ describe('Fast restream in live', function () { | |||
101 | before(async function () { | 102 | before(async function () { |
102 | this.timeout(120000) | 103 | this.timeout(120000) |
103 | 104 | ||
104 | const env = { 'PEERTUBE_TEST_CONSTANTS.VIDEO_LIVE.CLEANUP_DELAY': '10000' } | 105 | const env = { 'PEERTUBE_TEST_CONSTANTS_VIDEO_LIVE_CLEANUP_DELAY': '10000' } |
105 | server = await createSingleServer(1, {}, { env }) | 106 | server = await createSingleServer(1, {}, { env }) |
106 | 107 | ||
107 | // Get the access tokens | 108 | // Get the access tokens |