From 5ab14ad07a135ba189fefd9b0793e8431c87c0df Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Fri, 17 Mar 2023 09:50:09 -0700 Subject: [PATCH] video-setup: add print-config Signed-off-by: Varun Patil --- lib/Command/VideoSetup.php | 9 +++ lib/Controller/VideoController.php | 95 ++++++++++++++++-------------- 2 files changed, 61 insertions(+), 43 deletions(-) diff --git a/lib/Command/VideoSetup.php b/lib/Command/VideoSetup.php index 6e3c087c..2830779b 100644 --- a/lib/Command/VideoSetup.php +++ b/lib/Command/VideoSetup.php @@ -47,6 +47,7 @@ class VideoSetup extends Command $this ->setName('memories:video-setup') ->setDescription('Setup video streaming') + ->addOption('print-config', null, null, 'Print the current go-vod configuration JSON') ; } @@ -54,6 +55,14 @@ class VideoSetup extends Command { $this->output = $output; + // Check if we just need the config + if ($input->getOption('print-config')) { + $conf = \OCA\Memories\Controller\VideoController::getGoVodConfig(\OC::$server->get(IConfig::class)); + $output->writeln(json_encode($conf, JSON_PRETTY_PRINT)); + + return 0; + } + // Preset executables $ffmpegPath = $this->config->getSystemValue('memories.vod.ffmpeg', 'ffmpeg'); if ('ffmpeg' === $ffmpegPath) { diff --git a/lib/Controller/VideoController.php b/lib/Controller/VideoController.php index ddb80049..8bbee125 100644 --- a/lib/Controller/VideoController.php +++ b/lib/Controller/VideoController.php @@ -278,6 +278,55 @@ class VideoController extends ApiBase return "http://{$connect}/{$client}{$path}/{$profile}"; } + /** + * Get the goVod config JSON. + */ + public static function getGoVodConfig(\OCP\IConfig $config): array + { + // Migrate legacy config: remove in 2024 + self::migrateLegacyConfig($config); + + // Get temp directory + $defaultTmp = sys_get_temp_dir().'/go-vod/'; + $tmpPath = $config->getSystemValue('memories.vod.tempdir', $defaultTmp); + + // Make sure path ends with slash + if ('/' !== substr($tmpPath, -1)) { + $tmpPath .= '/'; + } + + // Add instance ID to path + $tmpPath .= $config->getSystemValue('instanceid', 'default'); + + // (Re-)create temp dir + shell_exec("rm -rf '{$tmpPath}' && mkdir -p '{$tmpPath}' && chmod 755 '{$tmpPath}'"); + + // Check temp directory exists + if (!is_dir($tmpPath)) { + throw new \Exception("Temp directory could not be created ({$tmpPath})"); + } + + // Check temp directory is writable + if (!is_writable($tmpPath)) { + throw new \Exception("Temp directory is not writable ({$tmpPath})"); + } + + // Get config from system values + return [ + 'bind' => $config->getSystemValue('memories.vod.bind', '127.0.0.1:47788'), + 'ffmpeg' => $config->getSystemValue('memories.vod.ffmpeg', 'ffmpeg'), + 'ffprobe' => $config->getSystemValue('memories.vod.ffprobe', 'ffprobe'), + 'tempdir' => $tmpPath, + + 'vaapi' => $config->getSystemValue('memories.vod.vaapi', false), + 'vaapiLowPower' => $config->getSystemValue('memories.vod.vaapi.low_power', false), + + 'nvenc' => $config->getSystemValue('memories.vod.nvenc', false), + 'nvencTemporalAQ' => $config->getSystemValue('memories.vod.nvenc.temporal_aq', false), + 'nvencScale' => $config->getSystemValue('memories.vod.nvenc.scale', 'npp'), + ]; + } + private function getUpstream(string $client, string $path, string $profile) { $returnCode = $this->getUpstreamInternal($client, $path, $profile); @@ -359,54 +408,14 @@ class VideoController extends ApiBase } /** - * Construct the goVod config JSON. + * Construct the goVod config JSON and put it to a file. * * @return array [config file, log file] */ private static function makeGoVodConfig(\OCP\IConfig $config): array { - // Migrate legacy config: remove in 2024 - self::migrateLegacyConfig($config); - - // Get temp directory - $defaultTmp = sys_get_temp_dir().'/go-vod/'; - $tmpPath = $config->getSystemValue('memories.vod.tempdir', $defaultTmp); - - // Make sure path ends with slash - if ('/' !== substr($tmpPath, -1)) { - $tmpPath .= '/'; - } - - // Add instance ID to path - $tmpPath .= $config->getSystemValue('instanceid', 'default'); - - // (Re-)create temp dir - shell_exec("rm -rf '{$tmpPath}' && mkdir -p '{$tmpPath}' && chmod 755 '{$tmpPath}'"); - - // Check temp directory exists - if (!is_dir($tmpPath)) { - throw new \Exception("Temp directory could not be created ({$tmpPath})"); - } - - // Check temp directory is writable - if (!is_writable($tmpPath)) { - throw new \Exception("Temp directory is not writable ({$tmpPath})"); - } - - // Get config from system values - $env = [ - 'bind' => $config->getSystemValue('memories.vod.bind', '127.0.0.1:47788'), - 'ffmpeg' => $config->getSystemValue('memories.vod.ffmpeg', 'ffmpeg'), - 'ffprobe' => $config->getSystemValue('memories.vod.ffprobe', 'ffprobe'), - 'tempdir' => $tmpPath, - - 'vaapi' => $config->getSystemValue('memories.vod.vaapi', false), - 'vaapiLowPower' => $config->getSystemValue('memories.vod.vaapi.low_power', false), - - 'nvenc' => $config->getSystemValue('memories.vod.nvenc', false), - 'nvencTemporalAQ' => $config->getSystemValue('memories.vod.nvenc.temporal_aq', false), - 'nvencScale' => $config->getSystemValue('memories.vod.nvenc.scale', 'npp'), - ]; + $env = self::getGoVodConfig($config); + $tmpPath = $env['tempdir']; // Write config to file $logFile = $tmpPath.'.log';