diff --git a/Telegram/Resources/langs/rewrites/en.json b/Telegram/Resources/langs/rewrites/en.json index 24606ae3f..fc45c52c4 100644 --- a/Telegram/Resources/langs/rewrites/en.json +++ b/Telegram/Resources/langs/rewrites/en.json @@ -66,6 +66,8 @@ "ktg_settings_call_confirm": "Confirm before calling", "ktg_call_sure": "Are you sure you want to call this user?", "ktg_call_button": "Call", + "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 2335e181e..ff8cf4314 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" @@ -287,7 +288,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 de28699fa..9eaca3c33 100644 --- a/Telegram/SourceFiles/kotato/kotato_settings.cpp +++ b/Telegram/SourceFiles/kotato/kotato_settings.cpp @@ -352,6 +352,13 @@ const std::map> DefinitionMap { { "confirm_before_calls", { .type = SettingType::BoolSetting, .defaultValue = true, }}, + { "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 eba47c38c..1a7da3e2d 100644 --- a/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp +++ b/Telegram/SourceFiles/kotato/kotato_settings_menu.cpp @@ -357,6 +357,11 @@ void SetupKotatoOther( }); SettingsMenuJsonSwitch(ktg_settings_call_confirm, confirm_before_calls); + SettingsMenuJsonSwitch(ktg_settings_ffmpeg_multithread, ffmpeg_multithread); + + AddSkip(container); + AddDividerText(container, rktr("ktg_settings_ffmpeg_multithread_about")); + AddSkip(container); } Kotato::Kotato(