From 25140bfd29b5f541c4fd6993248953e1a4e3cee6 Mon Sep 17 00:00:00 2001 From: Exeldro Date: Mon, 29 Jul 2024 16:13:22 +0200 Subject: [PATCH] Cache video encoder descriptions --- config-dialog.cpp | 13 +++++++++++-- config-dialog.hpp | 2 -- multistream.cpp | 19 ++++++++++++------- multistream.hpp | 1 - 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/config-dialog.cpp b/config-dialog.cpp index e459ce6..db7e657 100644 --- a/config-dialog.cpp +++ b/config-dialog.cpp @@ -559,9 +559,18 @@ void OBSBasicSettings::AddServer(QFormLayout *outputsLayout, obs_data_t *setting videoEncoder->setCurrentIndex(0); videoPageLayout->addRow(QString::fromUtf8(obs_module_text("VideoEncoder")), videoEncoder); + bool allEmpty = false; auto videoEncoderIndex = new QComboBox; for (int i = 0; i < MAX_OUTPUT_VIDEO_ENCODERS; i++) { - videoEncoderIndex->addItem(QString::number(i + 1) + " " + mainEncoderDescriptions[i]); + QString settingName = QString::fromUtf8("video_encoder_description") + QString::number(i); + auto description = obs_data_get_string(this->settings, settingName.toUtf8().constData()); + if (!description || description[0] == '\0') { + if (i != 0 && !allEmpty) { + break; + } + allEmpty = true; + } + videoEncoderIndex->addItem(QString::number(i + 1) + " " + description); } videoEncoderIndex->setCurrentIndex(obs_data_get_int(settings, "video_encoder_index")); connect(videoEncoderIndex, &QComboBox::currentIndexChanged, [videoEncoderIndex, settings] { @@ -733,7 +742,7 @@ void OBSBasicSettings::AddServer(QFormLayout *outputsLayout, obs_data_t *setting if (strcmp(type, current_type) == 0) videoEncoder->setCurrentIndex(videoEncoder->count() - 1); } - if (!advanced || videoEncoder->currentIndex() <= 0) + if (videoEncoder->currentIndex() <= 0) videoEncoderGroup->setVisible(false); auto audioEncoder = new QComboBox; diff --git a/config-dialog.hpp b/config-dialog.hpp index cfc148b..96b4c0c 100644 --- a/config-dialog.hpp +++ b/config-dialog.hpp @@ -80,7 +80,5 @@ public: void LoadOutputStats(std::vector *oldVideos); void SetNewerVersion(QString newer_version_available); - QStringList mainEncoderDescriptions = QStringList(MAX_OUTPUT_VIDEO_ENCODERS); - public slots: }; diff --git a/multistream.cpp b/multistream.cpp index d3062a6..9f75f1e 100644 --- a/multistream.cpp +++ b/multistream.cpp @@ -284,7 +284,6 @@ MultistreamDock::MultistreamDock(QWidget *parent) : QFrame(parent) QPushButton::connect(configButton, &QPushButton::clicked, [this] { if (!configDialog) configDialog = new OBSBasicSettings((QMainWindow *)obs_frontend_get_main_window()); - configDialog->mainEncoderDescriptions = mainEncoderDescriptions; auto settings = obs_data_create(); if (current_config) obs_data_apply(settings, current_config); @@ -929,6 +928,8 @@ void MultistreamDock::LoadVerticalOutputs(bool firstLoad) void MultistreamDock::storeMainStreamEncoders() { + if (!current_config) + return; struct obs_video_info ovi = {0}; obs_get_video_info(&ovi); double fps = ovi.fps_den > 0 ? (double)ovi.fps_num / (double)ovi.fps_den : 0.0; @@ -936,24 +937,28 @@ void MultistreamDock::storeMainStreamEncoders() bool found = false; for (auto i = 0; i < MAX_OUTPUT_VIDEO_ENCODERS; i++) { auto encoder = obs_output_get_video_encoder2(output, i); + QString settingName = QString::fromUtf8("video_encoder_description") + QString::number(i); if (encoder) { found = true; - mainEncoderDescriptions[i] = QString::number(obs_encoder_get_width(encoder)) + "x" + - QString::number(obs_encoder_get_height(encoder)); + auto mainEncoderDescription = QString::number(obs_encoder_get_width(encoder)) + "x" + + QString::number(obs_encoder_get_height(encoder)); auto divisor = obs_encoder_get_frame_rate_divisor(encoder); if (divisor > 0) - mainEncoderDescriptions[i] += + mainEncoderDescription += QString::fromUtf8(" ") + QString::number(fps / divisor, 'g', 4) + QString::fromUtf8("fps"); auto settings = obs_encoder_get_settings(encoder); auto bitrate = settings ? obs_data_get_int(settings, "bitrate") : 0; if (bitrate > 0) - mainEncoderDescriptions[i] += + mainEncoderDescription += QString::fromUtf8(" ") + QString::number(bitrate) + QString::fromUtf8("Kbps"); obs_data_release(settings); - } else if (found && !mainEncoderDescriptions[i].isEmpty()) { - mainEncoderDescriptions[i] = ""; + obs_data_set_string(current_config, settingName.toUtf8().constData(), + mainEncoderDescription.toUtf8().constData()); + + } else if (found && obs_data_has_user_value(current_config, settingName.toUtf8().constData())) { + obs_data_unset_user_value(current_config, settingName.toUtf8().constData()); } } obs_output_release(output); diff --git a/multistream.hpp b/multistream.hpp index a543d42..0cac932 100644 --- a/multistream.hpp +++ b/multistream.hpp @@ -46,7 +46,6 @@ private: void outputButtonStyle(QPushButton *button); void storeMainStreamEncoders(); - QStringList mainEncoderDescriptions = QStringList(MAX_OUTPUT_VIDEO_ENCODERS); QIcon streamActiveIcon = QIcon(":/aitum/media/streaming.svg"); QIcon streamInactiveIcon = QIcon(":/aitum/media/stream.svg");