diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 6ee1ae141..720a97e4f 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2871,6 +2871,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "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_external_video_player" = "External video player"; +"ktg_settings_external_video_player_about" = "When this option is enabled, autoplay is force-disabled and system video player is used to play videos."; + "ktg_user_status_unaccessible" = "account inaccessible"; "ktg_settings_show_json_settings" = "Show settings file"; diff --git a/Telegram/Resources/langs/rewrites/en.json b/Telegram/Resources/langs/rewrites/en.json index d361f8c37..36fda5290 100644 --- a/Telegram/Resources/langs/rewrites/en.json +++ b/Telegram/Resources/langs/rewrites/en.json @@ -79,6 +79,10 @@ "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_external_video_player": "External video player", + "ktg_settings_external_video_player_about": "When this option is enabled, autoplay is force-disabled and system video player is used to play videos.", "ktg_settings_adaptive_bubbles": "Adaptive bubbles", "ktg_settings_disable_sound_from_tray": "Disable sound", "ktg_settings_enable_sound_from_tray": "Enable sound", diff --git a/Telegram/Resources/langs/rewrites/ru.json b/Telegram/Resources/langs/rewrites/ru.json index 13c86ed2a..be0032f10 100644 --- a/Telegram/Resources/langs/rewrites/ru.json +++ b/Telegram/Resources/langs/rewrites/ru.json @@ -79,6 +79,10 @@ "ktg_settings_call_confirm": "Подтверждение перед звонком", "ktg_call_sure": "Вы уверены, что хотите позвонить этому пользователю?", "ktg_call_button": "Позвонить", + "ktg_settings_ffmpeg_multithread": "Декодировать видео в несколько потоков", + "ktg_settings_ffmpeg_multithread_about": "Когда включено, расход ЦП и ОЗУ выше, видео декодируется быстрее. Когда выключено, расход ЦП и ОЗУ меньше, видео декодируется медленнее. Чем больше у вас ядер ЦП, тем больше расход ОЗУ, когда эта опция включена. Можно закрепить используемое число потоков в конфигурационном файле JSON.", + "ktg_settings_external_video_player": "Внешний видеоплеер", + "ktg_settings_external_video_player_about": "Когда эта опция включена, автовоспроизведение принудительно отключено и системный видеоплеер используется для проигрывания видео.", "ktg_settings_adaptive_bubbles": "Адаптивная ширина сообщений", "ktg_settings_disable_sound_from_tray": "Отключить звук", "ktg_settings_enable_sound_from_tray": "Включить звук", diff --git a/Telegram/SourceFiles/ffmpeg/ffmpeg_utility.cpp b/Telegram/SourceFiles/ffmpeg/ffmpeg_utility.cpp index ccaec6630..d13cd93f2 100644 --- a/Telegram/SourceFiles/ffmpeg/ffmpeg_utility.cpp +++ b/Telegram/SourceFiles/ffmpeg/ffmpeg_utility.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ffmpeg/ffmpeg_utility.h" #include "base/algorithm.h" +#include "kotato/settings.h" #include "logs.h" #include @@ -175,7 +176,13 @@ CodecPointer MakeCodecPointer(not_null stream) { return {}; } context->pkt_timebase = stream->time_base; - av_opt_set(context, "threads", "auto", 0); + if(cFFmpegMultithread()) { + if (cFFmpegThreadCount() > 0) { + av_opt_set(context, "threads", std::to_string(cFFmpegThreadCount()).c_str(), 0); + } else { + av_opt_set(context, "threads", "auto", 0); + } + } av_opt_set_int(context, "refcounted_frames", 1, 0); const auto codec = avcodec_find_decoder(context->codec_id); diff --git a/Telegram/SourceFiles/kotato/json_settings.cpp b/Telegram/SourceFiles/kotato/json_settings.cpp index 121cdc622..8cb3a0765 100644 --- a/Telegram/SourceFiles/kotato/json_settings.cpp +++ b/Telegram/SourceFiles/kotato/json_settings.cpp @@ -16,6 +16,7 @@ https://github.com/kotatogram/kotatogram-desktop/blob/dev/LEGAL #include "facades.h" #include "ui/widgets/input_fields.h" #include "data/data_chat_filters.h" +#include "platform/platform_file_utilities.h" #include #include @@ -371,6 +372,8 @@ QByteArray GenerateSettingsJson(bool areDefault = false) { settings.insert(qsl("disable_up_edit"), cDisableUpEdit()); settings.insert(qsl("auto_scroll_unfocused"), cAutoScrollUnfocused()); settings.insert(qsl("confirm_before_calls"), cConfirmBeforeCall()); + settings.insert(qsl("ffmpeg_multithread"), cFFmpegMultithread()); + settings.insert(qsl("ffmpeg_thread_count"), int(cFFmpegThreadCount())); settings.insert(qsl("native_decorations"), cUseNativeDecorations()); settings.insert(qsl("recent_stickers_limit"), RecentStickersLimit()); settings.insert(qsl("userpic_corner_type"), cUserpicCornersType()); @@ -609,6 +612,14 @@ bool Manager::readCustomFile() { cSetConfirmBeforeCall(v); }); + ReadBoolOption(settings, "ffmpeg_multithread", [&](auto v) { + cSetFFmpegMultithread(v); + }); + + ReadIntOption(settings, "ffmpeg_thread_count", [&](auto v) { + cSetFFmpegThreadCount(v); + }); + ReadBoolOption(settings, "native_decorations", [&](auto v) { cSetUseNativeDecorations(v); }); diff --git a/Telegram/SourceFiles/kotato/settings.cpp b/Telegram/SourceFiles/kotato/settings.cpp index 641c6ed2a..eb4c51db9 100644 --- a/Telegram/SourceFiles/kotato/settings.cpp +++ b/Telegram/SourceFiles/kotato/settings.cpp @@ -8,6 +8,7 @@ https://github.com/kotatogram/kotatogram-desktop/blob/dev/LEGAL #include "kotato/settings.h" #include "base/platform/base_platform_info.h" +#include "platform/platform_file_utilities.h" bool gKotatoFirstRun = true; @@ -127,6 +128,9 @@ bool AddCustomReplace(QString from, QString to) { bool gConfirmBeforeCall = true; +bool gFFmpegMultithread = true; +uint gFFmpegThreadCount = 0; + bool gUseNativeDecorations = false; bool UseNativeDecorations() { static const auto NativeDecorations = cUseNativeDecorations(); diff --git a/Telegram/SourceFiles/kotato/settings.h b/Telegram/SourceFiles/kotato/settings.h index 4cd27aaec..aaa5ca8e2 100644 --- a/Telegram/SourceFiles/kotato/settings.h +++ b/Telegram/SourceFiles/kotato/settings.h @@ -7,7 +7,15 @@ https://github.com/kotatogram/kotatogram-desktop/blob/dev/LEGAL */ #pragma once -#include "platform/platform_file_utilities.h" +#include + +namespace Platform { +namespace FileDialog { + +enum class ImplementationType; + +} // namespace FileDialog +} // namespace Platform #define DeclareReadSetting(Type, Name) extern Type g##Name; \ inline const Type &c##Name() { \ @@ -95,6 +103,9 @@ DeclareRefSetting(CustomReplacementsMap, CustomReplaces); bool AddCustomReplace(QString from, QString to); DeclareSetting(bool, ConfirmBeforeCall); +DeclareSetting(bool, FFmpegMultithread); +DeclareSetting(uint, FFmpegThreadCount); + DeclareSetting(bool, UseNativeDecorations); [[nodiscard]] bool UseNativeDecorations(); diff --git a/Telegram/SourceFiles/kotato/settings_menu.cpp b/Telegram/SourceFiles/kotato/settings_menu.cpp index 87ff3b82d..be71a8861 100644 --- a/Telegram/SourceFiles/kotato/settings_menu.cpp +++ b/Telegram/SourceFiles/kotato/settings_menu.cpp @@ -23,6 +23,7 @@ https://github.com/kotatogram/kotatogram-desktop/blob/dev/LEGAL #include "boxes/about_box.h" #include "boxes/confirm_box.h" #include "platform/platform_specific.h" +#include "platform/platform_file_utilities.h" #include "window/window_session_controller.h" #include "lang/lang_keys.h" #include "core/update_checker.h" @@ -657,8 +658,28 @@ void SetupKotatoOther(not_null container) { }); SettingsMenuCSwitch(ktg_settings_call_confirm, ConfirmBeforeCall); + SettingsMenuCSwitch(ktg_settings_ffmpeg_multithread, FFmpegMultithread); AddSkip(container); + AddDividerText(container, tr::ktg_settings_ffmpeg_multithread_about()); + AddSkip(container); + + AddButton( + container, + tr::ktg_settings_external_video_player(), + st::settingsButton + )->toggleOn( + rpl::single(cUseExternalVideoPlayer()) + )->toggledValue( + ) | rpl::filter([](bool enabled) { + return (enabled != cUseExternalVideoPlayer()); + }) | rpl::start_with_next([](bool enabled) { + cSetUseExternalVideoPlayer(enabled); + Core::App().saveSettingsDelayed(); + }, container->lifetime()); + + AddSkip(container); + AddDividerText(container, tr::ktg_settings_external_video_player_about()); } Kotato::Kotato( diff --git a/Telegram/SourceFiles/settings/settings_codes.cpp b/Telegram/SourceFiles/settings/settings_codes.cpp index d31b828a3..ebf5d4c18 100644 --- a/Telegram/SourceFiles/settings/settings_codes.cpp +++ b/Telegram/SourceFiles/settings/settings_codes.cpp @@ -81,17 +81,6 @@ auto GenerateCodes() { } }); }); - codes.emplace(qsl("videoplayer"), [](SessionController *window) { - if (!window) { - return; - } - auto text = cUseExternalVideoPlayer() ? qsl("Use internal video player?") : qsl("Use external video player?"); - Ui::show(Box(text, [=] { - cSetUseExternalVideoPlayer(!cUseExternalVideoPlayer()); - window->session().saveSettingsDelayed(); - Ui::hideLayer(); - })); - }); codes.emplace(qsl("endpoints"), [](SessionController *window) { if (!Core::App().domain().started()) { return;