From f443a74649174b2f9347c158e30f8ac7aa3e958a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 4 Mar 2022 13:40:02 +0100 Subject: Add latency setting support --- server/initializers/checker-before-init.ts | 4 +-- server/initializers/config.ts | 6 +++- server/initializers/constants.ts | 10 +++++-- .../migrations/0690-live-latency-mode.ts | 35 ++++++++++++++++++++++ 4 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 server/initializers/migrations/0690-live-latency-mode.ts (limited to 'server/initializers') diff --git a/server/initializers/checker-before-init.ts b/server/initializers/checker-before-init.ts index 10dd98f43..fa311f708 100644 --- a/server/initializers/checker-before-init.ts +++ b/server/initializers/checker-before-init.ts @@ -49,8 +49,8 @@ function checkMissedConfig () { 'peertube.check_latest_version.enabled', 'peertube.check_latest_version.url', 'search.remote_uri.users', 'search.remote_uri.anonymous', 'search.search_index.enabled', 'search.search_index.url', 'search.search_index.disable_local_search', 'search.search_index.is_default_search', - 'live.enabled', 'live.allow_replay', 'live.max_duration', 'live.max_user_lives', 'live.max_instance_lives', - 'live.rtmp.enabled', 'live.rtmp.port', 'live.rtmp.hostname', + 'live.enabled', 'live.allow_replay', 'live.latency_setting.enabled', 'live.max_duration', + 'live.max_user_lives', 'live.max_instance_lives', 'live.rtmp.enabled', 'live.rtmp.port', 'live.rtmp.hostname', 'live.rtmps.enabled', 'live.rtmps.port', 'live.rtmps.hostname', 'live.rtmps.key_file', 'live.rtmps.cert_file', 'live.transcoding.enabled', 'live.transcoding.threads', 'live.transcoding.profile', 'live.transcoding.resolutions.144p', 'live.transcoding.resolutions.240p', 'live.transcoding.resolutions.360p', diff --git a/server/initializers/config.ts b/server/initializers/config.ts index 7a13a1368..6dcca9b67 100644 --- a/server/initializers/config.ts +++ b/server/initializers/config.ts @@ -4,9 +4,9 @@ import { dirname, join } from 'path' import { decacheModule } from '@server/helpers/decache' import { VideoRedundancyConfigFilter } from '@shared/models/redundancy/video-redundancy-config-filter.type' import { BroadcastMessageLevel } from '@shared/models/server' +import { buildPath, root } from '../../shared/core-utils' import { VideoPrivacy, VideosRedundancyStrategy } from '../../shared/models' import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type' -import { buildPath, root } from '../../shared/core-utils' import { parseBytes, parseDurationToMs } from '../helpers/core-utils' // Use a variable to reload the configuration if we need @@ -296,6 +296,10 @@ const CONFIG = { get ALLOW_REPLAY () { return config.get('live.allow_replay') }, + LATENCY_SETTING: { + get ENABLED () { return config.get('live.latency_setting.enabled') } + }, + RTMP: { get ENABLED () { return config.get('live.rtmp.enabled') }, get PORT () { return config.get('live.rtmp.port') }, diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 7bc2877aa..1c849b561 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -24,7 +24,7 @@ import { CONFIG, registerConfigChangedHandler } from './config' // --------------------------------------------------------------------------- -const LAST_MIGRATION_VERSION = 685 +const LAST_MIGRATION_VERSION = 690 // --------------------------------------------------------------------------- @@ -700,7 +700,10 @@ const RESUMABLE_UPLOAD_SESSION_LIFETIME = SCHEDULER_INTERVALS_MS.REMOVE_DANGLING const VIDEO_LIVE = { EXTENSION: '.ts', CLEANUP_DELAY: 1000 * 60 * 5, // 5 minutes - SEGMENT_TIME_SECONDS: 4, // 4 seconds + SEGMENT_TIME_SECONDS: { + DEFAULT_LATENCY: 4, // 4 seconds + SMALL_LATENCY: 2 // 2 seconds + }, SEGMENTS_LIST_SIZE: 15, // 15 maximum segments in live playlist REPLAY_DIRECTORY: 'replay', EDGE_LIVE_DELAY_SEGMENTS_NOTIFICATION: 4, @@ -842,7 +845,8 @@ if (isTestInstance() === true) { PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME = 5000 VIDEO_LIVE.CLEANUP_DELAY = 5000 - VIDEO_LIVE.SEGMENT_TIME_SECONDS = 2 + VIDEO_LIVE.SEGMENT_TIME_SECONDS.DEFAULT_LATENCY = 2 + VIDEO_LIVE.SEGMENT_TIME_SECONDS.SMALL_LATENCY = 1 VIDEO_LIVE.EDGE_LIVE_DELAY_SEGMENTS_NOTIFICATION = 1 } diff --git a/server/initializers/migrations/0690-live-latency-mode.ts b/server/initializers/migrations/0690-live-latency-mode.ts new file mode 100644 index 000000000..c31a61364 --- /dev/null +++ b/server/initializers/migrations/0690-live-latency-mode.ts @@ -0,0 +1,35 @@ +import { LiveVideoLatencyMode } from '@shared/models' +import * as Sequelize from 'sequelize' + +async function up (utils: { + transaction: Sequelize.Transaction + queryInterface: Sequelize.QueryInterface + sequelize: Sequelize.Sequelize + db: any +}): Promise { + await utils.queryInterface.addColumn('videoLive', 'latencyMode', { + type: Sequelize.INTEGER, + defaultValue: null, + allowNull: true + }, { transaction: utils.transaction }) + + { + const query = `UPDATE "videoLive" SET "latencyMode" = ${LiveVideoLatencyMode.DEFAULT}` + await utils.sequelize.query(query, { type: Sequelize.QueryTypes.UPDATE, transaction: utils.transaction }) + } + + await utils.queryInterface.changeColumn('videoLive', 'latencyMode', { + type: Sequelize.INTEGER, + defaultValue: null, + allowNull: false + }, { transaction: utils.transaction }) +} + +function down () { + throw new Error('Not implemented.') +} + +export { + up, + down +} -- cgit v1.2.3