From cee7e3f149f0118f2b098d1f01439e25379e1ccf Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Tue, 30 Aug 2022 13:55:07 +0300 Subject: [PATCH] [Option][GUI/JSON] Multithreaded video decoding --- Telegram/Resources/langs/rewrites/en.json | 2 ++ Telegram/SourceFiles/ffmpeg/ffmpeg_utility.cpp | 9 ++++++++- Telegram/SourceFiles/kotato/kotato_settings.cpp | 7 +++++++ Telegram/SourceFiles/kotato/kotato_settings_menu.cpp | 4 ++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Telegram/Resources/langs/rewrites/en.json b/Telegram/Resources/langs/rewrites/en.json index f68b897f8..3279d583b 100644 --- a/Telegram/Resources/langs/rewrites/en.json +++ b/Telegram/Resources/langs/rewrites/en.json @@ -61,6 +61,8 @@ "ktg_profile_group_id": "Group ID", "ktg_profile_supergroup_id": "Supergroup ID", "ktg_profile_channel_id": "Channel ID", + "ktg_settings_ffmpeg_multithread": "Multithread video decoding", + "ktg_settings_ffmpeg_multithread_about": "When enabled, CPU and RAM consumption is higher, video decodes faster. When disabled, CPU and RAM consumption is lower, video decodes slower. The more CPU cores you have, the more RAM consumption you have when this option is enabled. You can set exact number of threads in the JSON configuration file.", "ktg_settings_adaptive_bubbles": "Adaptive bubbles", "ktg_settings_filters": "Folders", "ktg_settings_messages": "Messages", diff --git a/Telegram/SourceFiles/ffmpeg/ffmpeg_utility.cpp b/Telegram/SourceFiles/ffmpeg/ffmpeg_utility.cpp index 95cefeffc..f202cdd81 100644 --- a/Telegram/SourceFiles/ffmpeg/ffmpeg_utility.cpp +++ b/Telegram/SourceFiles/ffmpeg/ffmpeg_utility.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "ffmpeg/ffmpeg_utility.h" +#include "kotato/kotato_settings.h" #include "base/algorithm.h" #include "logs.h" @@ -328,7 +329,13 @@ CodecPointer MakeCodecPointer(CodecDescriptor descriptor) { return {}; } context->pkt_timebase = stream->time_base; - av_opt_set(context, "threads", "auto", 0); + if(::Kotato::JsonSettings::GetBool("ffmpeg_multithread")) { + if (::Kotato::JsonSettings::GetInt("ffmpeg_thread_count") > 0) { + av_opt_set(context, "threads", std::to_string(::Kotato::JsonSettings::GetInt("ffmpeg_thread_count")).c_str(), 0); + } else { + av_opt_set(context, "threads", "auto", 0); + } + } av_opt_set_int(context, "refcounted_frames", 1, 0); const auto codec = FindDecoder(context); diff --git a/Telegram/SourceFiles/kotato/kotato_settings.cpp b/Telegram/SourceFiles/kotato/kotato_settings.cpp index c1617f753..44f5cd6fe 100644 --- a/Telegram/SourceFiles/kotato/kotato_settings.cpp +++ b/Telegram/SourceFiles/kotato/kotato_settings.cpp @@ -322,6 +322,13 @@ const std::map> DefinitionMap { { "replaces", { .type = SettingType::QJsonArraySetting, .limitHandler = ReplacesLimit(), }}, + { "ffmpeg_multithread", { + .type = SettingType::BoolSetting, + .defaultValue = true, }}, + { "ffmpeg_thread_count", { + .type = SettingType::IntSetting, + .defaultValue = 0, + .limitHandler = IntLimitMin(0) }}, }; using OldOptionKey = QString; diff --git a/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp b/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp index fc921de0b..9a0330831 100644 --- a/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp +++ b/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp @@ -330,6 +330,10 @@ void SetupKotatoOther( })); }); + SettingsMenuJsonSwitch(ktg_settings_ffmpeg_multithread, ffmpeg_multithread); + + Ui::AddSkip(container); + Ui::AddDividerText(container, rktr("ktg_settings_ffmpeg_multithread_about")); Ui::AddSkip(container); }