From cb7d92c0ed742ea1b21ccd87224b7d83d553ab40 Mon Sep 17 00:00:00 2001 From: Emil Santurio Date: Thu, 11 Dec 2025 17:15:20 +0100 Subject: [PATCH 1/5] frontend: Auto-discovery of registered services --- frontend/settings/OBSBasicSettings.hpp | 35 ++++ frontend/settings/OBSBasicSettings_Stream.cpp | 188 +++++++++++++++--- 2 files changed, 195 insertions(+), 28 deletions(-) diff --git a/frontend/settings/OBSBasicSettings.hpp b/frontend/settings/OBSBasicSettings.hpp index 092288030b9fd9..daa60c2d21541f 100644 --- a/frontend/settings/OBSBasicSettings.hpp +++ b/frontend/settings/OBSBasicSettings.hpp @@ -37,6 +37,39 @@ struct OBSTheme; std::string DeserializeConfigText(const char *value); +// Structured data for service dropdown items +struct ServiceItemData { + enum class Type { + Custom, // rtmp_custom service + ShowAll, // "Show All" option in dropdown + RtmpCommon, // Standard rtmp_common service (Twitch, YouTube, etc.) + CustomServiceType // Custom service types (WHIP, MoQ, etc.) + }; + + Type type; + QString serviceId; // Service ID: for RtmpCommon this is the service name, + // for CustomServiceType this is the service type ID (e.g., "whip_custom") + QString displayName; // Human-readable display name + + ServiceItemData() : type(Type::Custom) {} + + ServiceItemData(Type t, const QString &id = QString(), const QString &name = QString()) + : type(t), + serviceId(id), + displayName(name) + { + } + + // Helper methods for easy type checking + bool isCustom() const { return type == Type::Custom; } + bool isShowAll() const { return type == Type::ShowAll; } + bool isRtmpCommon() const { return type == Type::RtmpCommon; } + bool isCustomServiceType() const { return type == Type::CustomServiceType; } +}; + +// Register with Qt's meta-type system so it can be stored in QVariant +Q_DECLARE_METATYPE(ServiceItemData) + class OBSBasicSettings : public QDialog { Q_OBJECT Q_PROPERTY(QIcon generalIcon READ GetGeneralIcon WRITE SetGeneralIcon DESIGNABLE true) @@ -204,6 +237,8 @@ class OBSBasicSettings : public QDialog { /* stream */ void InitStreamPage(); bool IsCustomService() const; + inline bool IsCustomServiceType() const; + inline QString GetCustomServiceTypeId() const; inline bool IsWHIP() const; void LoadServices(bool showAll); void OnOAuthStreamKeyConnected(); diff --git a/frontend/settings/OBSBasicSettings_Stream.cpp b/frontend/settings/OBSBasicSettings_Stream.cpp index 1307e267ce9f95..eb12bb493b78d3 100644 --- a/frontend/settings/OBSBasicSettings_Stream.cpp +++ b/frontend/settings/OBSBasicSettings_Stream.cpp @@ -39,12 +39,45 @@ enum class Section : int { bool OBSBasicSettings::IsCustomService() const { - return ui->service->currentData().toInt() == (int)ListOpt::Custom; + QVariant data = ui->service->currentData(); + if (data.canConvert()) { + ServiceItemData serviceData = data.value(); + return serviceData.isCustom(); + } + // Fallback for backward compatibility during migration + return data.toInt() == (int)ListOpt::Custom; +} + +inline bool OBSBasicSettings::IsCustomServiceType() const +{ + QVariant data = ui->service->currentData(); + if (data.canConvert()) { + ServiceItemData serviceData = data.value(); + return serviceData.isCustomServiceType(); + } + // Fallback for backward compatibility during migration + return data.canConvert() && !data.toString().isEmpty(); +} + +inline QString OBSBasicSettings::GetCustomServiceTypeId() const +{ + QVariant data = ui->service->currentData(); + if (data.canConvert()) { + ServiceItemData serviceData = data.value(); + if (serviceData.isCustomServiceType()) { + return serviceData.serviceId; + } + } + // Fallback for backward compatibility during migration + if (data.canConvert()) { + return data.toString(); + } + return QString(); } inline bool OBSBasicSettings::IsWHIP() const { - return ui->service->currentData().toInt() == (int)ListOpt::WHIP; + return GetCustomServiceTypeId() == "whip_custom"; } void OBSBasicSettings::InitStreamPage() @@ -114,13 +147,28 @@ void OBSBasicSettings::LoadStream1Settings() protocol = QT_UTF8(obs_service_get_protocol(service_obj)); const char *bearer_token = obs_data_get_string(settings, "bearer_token"); - if (is_rtmp_custom || is_whip) { + if (!is_rtmp_common) { ui->customServer->setText(server); } if (is_rtmp_custom) { - ui->service->setCurrentIndex(0); - lastServiceIdx = 0; + // Find the "Custom" option by looking for ServiceItemData with Type::Custom + int idx = -1; + for (int i = 0; i < ui->service->count(); i++) { + QVariant data = ui->service->itemData(i); + if (data.canConvert()) { + ServiceItemData serviceData = data.value(); + if (serviceData.isCustom()) { + idx = i; + break; + } + } + } + if (idx == -1) { + idx = 0; + } + ui->service->setCurrentIndex(idx); + lastServiceIdx = idx; lastCustomServer = ui->customServer->text(); bool use_auth = obs_data_get_bool(settings, "use_auth"); @@ -129,11 +177,25 @@ void OBSBasicSettings::LoadStream1Settings() ui->authUsername->setText(QT_UTF8(username)); ui->authPw->setText(QT_UTF8(password)); ui->useAuth->setChecked(use_auth); - } else { - int idx = ui->service->findText(service); + } else if (is_rtmp_common) { + // For rtmp_common services, find by service ID in ServiceItemData + int idx = -1; + for (int i = 0; i < ui->service->count(); i++) { + QVariant data = ui->service->itemData(i); + if (data.canConvert()) { + ServiceItemData serviceData = data.value(); + if (serviceData.isRtmpCommon() && serviceData.serviceId == service) { + idx = i; + break; + } + } + } + if (idx == -1) { + // Service not found, add it if (service && *service) { - ui->service->insertItem(1, service); + ServiceItemData newService(ServiceItemData::Type::RtmpCommon, service, service); + ui->service->insertItem(1, service, QVariant::fromValue(newService)); } idx = 1; } @@ -145,6 +207,34 @@ void OBSBasicSettings::LoadStream1Settings() idx = config_get_int(main->Config(), "Twitch", "AddonChoice"); ui->twitchAddonDropdown->setCurrentIndex(idx); + } else { + // For custom service types (WHIP, MoQ, etc.), find by service type ID in ServiceItemData + int idx = -1; + for (int i = 0; i < ui->service->count(); i++) { + QVariant data = ui->service->itemData(i); + if (data.canConvert()) { + ServiceItemData serviceData = data.value(); + if (serviceData.isCustomServiceType() && serviceData.serviceId == type) { + idx = i; + break; + } + } + } + + if (idx == -1) { + // Service type not found in dropdown, try to add it + const char *display_name = obs_service_get_display_name(type); + if (!display_name) { + display_name = type; + } + ServiceItemData newService(ServiceItemData::Type::CustomServiceType, QString(type), + QT_UTF8(display_name)); + ui->service->insertItem(1, QT_UTF8(display_name), QVariant::fromValue(newService)); + idx = 1; + } + + ui->service->setCurrentIndex(idx); + lastServiceIdx = idx; } ui->enableMultitrackVideo->setChecked(config_get_bool(main->Config(), "Stream1", "EnableMultitrackVideo")); @@ -267,13 +357,15 @@ void OBSBasicSettings::SwapMultiTrack(const char *protocol) void OBSBasicSettings::SaveStream1Settings() { bool customServer = IsCustomService(); - bool whip = IsWHIP(); + QString customServiceTypeId = GetCustomServiceTypeId(); const char *service_id = "rtmp_common"; + QByteArray serviceIdUtf8; if (customServer) { service_id = "rtmp_custom"; - } else if (whip) { - service_id = "whip_custom"; + } else if (!customServiceTypeId.isEmpty()) { + serviceIdUtf8 = customServiceTypeId.toUtf8(); + service_id = serviceIdUtf8.constData(); } obs_service_t *oldService = main->GetService(); @@ -281,7 +373,7 @@ void OBSBasicSettings::SaveStream1Settings() OBSDataAutoRelease settings = obs_data_create(); - if (!customServer && !whip) { + if (!customServer && customServiceTypeId.isEmpty()) { obs_data_set_string(settings, "service", QT_TO_UTF8(ui->service->currentText())); obs_data_set_string(settings, "protocol", QT_TO_UTF8(protocol)); if (ui->server->currentData() == CustomServerUUID()) { @@ -316,8 +408,7 @@ void OBSBasicSettings::SaveStream1Settings() obs_data_set_bool(settings, "bwtest", false); } - if (whip) { - obs_data_set_string(settings, "service", "WHIP"); + if (IsWHIP()) { obs_data_set_string(settings, "bearer_token", QT_TO_UTF8(ui->key->text())); } else { obs_data_set_string(settings, "key", QT_TO_UTF8(ui->key->text())); @@ -382,7 +473,7 @@ void OBSBasicSettings::SaveStream1Settings() void OBSBasicSettings::UpdateMoreInfoLink() { - if (IsCustomService() || IsWHIP()) { + if (IsCustomService() || IsCustomServiceType()) { ui->moreInfoButton->hide(); return; } @@ -487,20 +578,49 @@ void OBSBasicSettings::LoadServices(bool showAll) names.sort(Qt::CaseInsensitive); } + // Add rtmp_common services with ServiceItemData for (QString &name : names) { - ui->service->addItem(name); + ServiceItemData data(ServiceItemData::Type::RtmpCommon, name, name); + ui->service->addItem(name, QVariant::fromValue(data)); } - if (obs_is_output_protocol_registered("WHIP")) { - ui->service->addItem(QTStr("WHIP"), QVariant((int)ListOpt::WHIP)); + // Enumerate all available service types loaded in OBS + size_t idx = 0; + const char *service_id; + while (obs_enum_service_types(idx++, &service_id)) { + // Skip rtmp_common and rtmp_custom as they're handled separately + if (strcmp(service_id, "rtmp_common") == 0 || strcmp(service_id, "rtmp_custom") == 0) { + continue; + } + + // Get the display name for the service + const char *display_name = obs_service_get_display_name(service_id); + if (!display_name) { + display_name = service_id; + } + + // Check if the service has a registered protocol + OBSServiceAutoRelease temp_service = obs_service_create(service_id, "temp", nullptr, nullptr); + if (temp_service) { + const char *protocol = obs_service_get_protocol(temp_service); + if (protocol && obs_is_output_protocol_registered(protocol)) { + // Add the service to the dropdown with ServiceItemData + ServiceItemData data(ServiceItemData::Type::CustomServiceType, QString(service_id), + QT_UTF8(display_name)); + ui->service->addItem(QT_UTF8(display_name), QVariant::fromValue(data)); + } + } } if (!showAll) { + ServiceItemData showAllData(ServiceItemData::Type::ShowAll); ui->service->addItem(QTStr("Basic.AutoConfig.StreamPage.Service.ShowAll"), - QVariant((int)ListOpt::ShowAll)); + QVariant::fromValue(showAllData)); } - ui->service->insertItem(0, QTStr("Basic.AutoConfig.StreamPage.Service.Custom"), QVariant((int)ListOpt::Custom)); + ServiceItemData customData(ServiceItemData::Type::Custom); + ui->service->insertItem(0, QTStr("Basic.AutoConfig.StreamPage.Service.Custom"), + QVariant::fromValue(customData)); if (!lastService.isEmpty()) { int idx = ui->service->findText(lastService); @@ -576,7 +696,17 @@ void OBSBasicSettings::UseStreamKeyAdvClicked() void OBSBasicSettings::on_service_currentIndexChanged(int idx) { - if (ui->service->currentData().toInt() == (int)ListOpt::ShowAll) { + // Check if "Show All" was selected + QVariant data = ui->service->currentData(); + if (data.canConvert()) { + ServiceItemData serviceData = data.value(); + if (serviceData.isShowAll()) { + LoadServices(true); + ui->service->showPopup(); + return; + } + } else if (data.toInt() == (int)ListOpt::ShowAll) { + // Fallback for backward compatibility LoadServices(true); ui->service->showPopup(); return; @@ -634,7 +764,7 @@ void OBSBasicSettings::ServiceChanged(bool resetFields) { std::string service = ui->service->currentText().toStdString(); bool custom = IsCustomService(); - bool whip = IsWHIP(); + bool customServiceType = IsCustomServiceType(); ui->disconnectAccount->setVisible(false); ui->bandwidthTestEnable->setVisible(false); @@ -655,7 +785,7 @@ void OBSBasicSettings::ServiceChanged(bool resetFields) ui->authPwLabel->setVisible(custom); ui->authPwWidget->setVisible(custom); - if (custom || whip) { + if (custom || customServiceType) { ui->destinationLayout->insertRow(1, ui->serverLabel, ui->serverStackedWidget); ui->serverStackedWidget->setCurrentIndex(1); @@ -778,25 +908,27 @@ void OBSBasicSettings::on_authPwShow_clicked() OBSService OBSBasicSettings::SpawnTempService() { bool custom = IsCustomService(); - bool whip = IsWHIP(); + QString customServiceTypeId = GetCustomServiceTypeId(); const char *service_id = "rtmp_common"; + QByteArray serviceIdUtf8; if (custom) { service_id = "rtmp_custom"; - } else if (whip) { - service_id = "whip_custom"; + } else if (!customServiceTypeId.isEmpty()) { + serviceIdUtf8 = customServiceTypeId.toUtf8(); + service_id = serviceIdUtf8.constData(); } OBSDataAutoRelease settings = obs_data_create(); - if (!custom && !whip) { + if (!custom && customServiceTypeId.isEmpty()) { obs_data_set_string(settings, "service", QT_TO_UTF8(ui->service->currentText())); obs_data_set_string(settings, "server", QT_TO_UTF8(ui->server->currentData().toString())); } else { obs_data_set_string(settings, "server", QT_TO_UTF8(ui->customServer->text().trimmed())); } - if (whip) { + if (IsWHIP()) { obs_data_set_string(settings, "bearer_token", QT_TO_UTF8(ui->key->text())); } else { obs_data_set_string(settings, "key", QT_TO_UTF8(ui->key->text())); From 1cb7a2c011e6c95441c29dfd72e1830105fc236f Mon Sep 17 00:00:00 2001 From: Emil Santurio Date: Wed, 14 Jan 2026 19:41:38 +0100 Subject: [PATCH 2/5] frontend: Remove ListOpt and refactor duplicated code OBSBasicSettings --- frontend/settings/OBSBasicSettings.hpp | 5 +- frontend/settings/OBSBasicSettings_Stream.cpp | 108 ++++++------------ 2 files changed, 35 insertions(+), 78 deletions(-) diff --git a/frontend/settings/OBSBasicSettings.hpp b/frontend/settings/OBSBasicSettings.hpp index daa60c2d21541f..de4420cf81b713 100644 --- a/frontend/settings/OBSBasicSettings.hpp +++ b/frontend/settings/OBSBasicSettings.hpp @@ -237,9 +237,10 @@ class OBSBasicSettings : public QDialog { /* stream */ void InitStreamPage(); bool IsCustomService() const; - inline bool IsCustomServiceType() const; - inline QString GetCustomServiceTypeId() const; + bool IsCustomServiceType() const; + QString GetCustomServiceTypeId() const; inline bool IsWHIP() const; + int FindService(const std::function &predicate); void LoadServices(bool showAll); void OnOAuthStreamKeyConnected(); void OnAuthConnected(); diff --git a/frontend/settings/OBSBasicSettings_Stream.cpp b/frontend/settings/OBSBasicSettings_Stream.cpp index eb12bb493b78d3..71eead5d910fa5 100644 --- a/frontend/settings/OBSBasicSettings_Stream.cpp +++ b/frontend/settings/OBSBasicSettings_Stream.cpp @@ -26,12 +26,6 @@ extern QCef *cef; extern QCefCookieManager *panel_cookies; extern bool cef_js_avail; -enum class ListOpt : int { - ShowAll = 1, - Custom, - WHIP, -}; - enum class Section : int { Connect, StreamKey, @@ -40,37 +34,23 @@ enum class Section : int { bool OBSBasicSettings::IsCustomService() const { QVariant data = ui->service->currentData(); - if (data.canConvert()) { - ServiceItemData serviceData = data.value(); - return serviceData.isCustom(); - } - // Fallback for backward compatibility during migration - return data.toInt() == (int)ListOpt::Custom; + ServiceItemData serviceData = data.value(); + return serviceData.isCustom(); } -inline bool OBSBasicSettings::IsCustomServiceType() const +bool OBSBasicSettings::IsCustomServiceType() const { QVariant data = ui->service->currentData(); - if (data.canConvert()) { - ServiceItemData serviceData = data.value(); - return serviceData.isCustomServiceType(); - } - // Fallback for backward compatibility during migration - return data.canConvert() && !data.toString().isEmpty(); + ServiceItemData serviceData = data.value(); + return serviceData.isCustomServiceType(); } -inline QString OBSBasicSettings::GetCustomServiceTypeId() const +QString OBSBasicSettings::GetCustomServiceTypeId() const { QVariant data = ui->service->currentData(); - if (data.canConvert()) { - ServiceItemData serviceData = data.value(); - if (serviceData.isCustomServiceType()) { - return serviceData.serviceId; - } - } - // Fallback for backward compatibility during migration - if (data.canConvert()) { - return data.toString(); + ServiceItemData serviceData = data.value(); + if (serviceData.isCustomServiceType()) { + return serviceData.serviceId; } return QString(); } @@ -80,6 +60,20 @@ inline bool OBSBasicSettings::IsWHIP() const return GetCustomServiceTypeId() == "whip_custom"; } +int OBSBasicSettings::FindService(const std::function &predicate) +{ + for (int i = 0; i < ui->service->count(); i++) { + QVariant data = ui->service->itemData(i); + if (data.canConvert()) { + ServiceItemData serviceData = data.value(); + if (predicate(serviceData)) { + return i; + } + } + } + return -1; +} + void OBSBasicSettings::InitStreamPage() { ui->connectAccount2->setVisible(false); @@ -152,18 +146,7 @@ void OBSBasicSettings::LoadStream1Settings() } if (is_rtmp_custom) { - // Find the "Custom" option by looking for ServiceItemData with Type::Custom - int idx = -1; - for (int i = 0; i < ui->service->count(); i++) { - QVariant data = ui->service->itemData(i); - if (data.canConvert()) { - ServiceItemData serviceData = data.value(); - if (serviceData.isCustom()) { - idx = i; - break; - } - } - } + auto idx = FindService([](const ServiceItemData &serviceData) { return serviceData.isCustom(); }); if (idx == -1) { idx = 0; } @@ -178,21 +161,11 @@ void OBSBasicSettings::LoadStream1Settings() ui->authPw->setText(QT_UTF8(password)); ui->useAuth->setChecked(use_auth); } else if (is_rtmp_common) { - // For rtmp_common services, find by service ID in ServiceItemData - int idx = -1; - for (int i = 0; i < ui->service->count(); i++) { - QVariant data = ui->service->itemData(i); - if (data.canConvert()) { - ServiceItemData serviceData = data.value(); - if (serviceData.isRtmpCommon() && serviceData.serviceId == service) { - idx = i; - break; - } - } - } + auto idx = FindService([&](const ServiceItemData &serviceData) { + return serviceData.isRtmpCommon() && serviceData.serviceId == service; + }); if (idx == -1) { - // Service not found, add it if (service && *service) { ServiceItemData newService(ServiceItemData::Type::RtmpCommon, service, service); ui->service->insertItem(1, service, QVariant::fromValue(newService)); @@ -208,21 +181,11 @@ void OBSBasicSettings::LoadStream1Settings() idx = config_get_int(main->Config(), "Twitch", "AddonChoice"); ui->twitchAddonDropdown->setCurrentIndex(idx); } else { - // For custom service types (WHIP, MoQ, etc.), find by service type ID in ServiceItemData - int idx = -1; - for (int i = 0; i < ui->service->count(); i++) { - QVariant data = ui->service->itemData(i); - if (data.canConvert()) { - ServiceItemData serviceData = data.value(); - if (serviceData.isCustomServiceType() && serviceData.serviceId == type) { - idx = i; - break; - } - } - } + auto idx = FindService([&](const ServiceItemData &serviceData) { + return serviceData.isCustomServiceType() && serviceData.serviceId == type; + }); if (idx == -1) { - // Service type not found in dropdown, try to add it const char *display_name = obs_service_get_display_name(type); if (!display_name) { display_name = type; @@ -698,15 +661,8 @@ void OBSBasicSettings::on_service_currentIndexChanged(int idx) { // Check if "Show All" was selected QVariant data = ui->service->currentData(); - if (data.canConvert()) { - ServiceItemData serviceData = data.value(); - if (serviceData.isShowAll()) { - LoadServices(true); - ui->service->showPopup(); - return; - } - } else if (data.toInt() == (int)ListOpt::ShowAll) { - // Fallback for backward compatibility + ServiceItemData serviceData = data.value(); + if (serviceData.isShowAll()) { LoadServices(true); ui->service->showPopup(); return; From ed19d08b3529dd628b26291729600d95439fa628 Mon Sep 17 00:00:00 2001 From: Gaston Bogarin Date: Thu, 29 Oct 2026 14:11:08 -0300 Subject: [PATCH 3/5] frontend: Show service properties on Stream page Add a "Service Options" group to the Stream settings page that renders a service's own properties, so that a plugin can expose its settings without requiring frontend changes. #12911 makes a plugin's service appear in the services dropdown, but the Stream page could still only configure Server and Stream Key. A service with settings of its own had nowhere to put them in the UI, leaving plugins with the problem #12911 solves for discovery: editing OBSBasicSettings_Stream.cpp to hardcode new fields. The group is only shown for a plugin-provided service that declares at least one property the Stream page does not already own. Properties named after keys the page writes itself are removed, so that they cannot appear twice or overwrite what the page saves. On save, the property values are written to the service settings together with their defaults, as explicit values. This is needed because, unlike outputs, services do not have get_defaults applied on creation, so the plugin would otherwise receive empty fields in create(). The trade-off is that defaults are frozen once the user saves: changing a default in a later version of a plugin does not reach users who already have settings stored. --- docs/sphinx/reference-services.rst | 10 ++ frontend/data/locale/en-US.ini | 1 + frontend/forms/OBSBasicSettings.ui | 21 ++++ frontend/settings/OBSBasicSettings.hpp | 8 +- frontend/settings/OBSBasicSettings_Stream.cpp | 119 ++++++++++++++++++ 5 files changed, 158 insertions(+), 1 deletion(-) diff --git a/docs/sphinx/reference-services.rst b/docs/sphinx/reference-services.rst index 3ed58b5d985ab3..9485b41fd14850 100644 --- a/docs/sphinx/reference-services.rst +++ b/docs/sphinx/reference-services.rst @@ -71,6 +71,16 @@ Service Definition Structure :return: The properties of the service + The frontend displays these properties in the *Service Options* group + of the Stream settings page. In that context ``get_properties`` is + called with *data* set to ``NULL`` and ``get_properties2`` is not + used. Properties named after settings owned by the Stream page + (``server``, ``key``, ``bearer_token``, ``use_auth``, ``username``, + ``password``, ``service``, ``protocol``, ``using_custom_server`` and + ``bwtest``) are removed before the group is displayed. The remaining + values are saved along with their defaults as explicit values, as + services do not have their defaults applied on creation. + .. member:: void (*obs_service_info.update)(void *data, obs_data_t *settings) Updates the settings for this service. diff --git a/frontend/data/locale/en-US.ini b/frontend/data/locale/en-US.ini index 3046ec3ca9f99d..7f12828c62c4de 100644 --- a/frontend/data/locale/en-US.ini +++ b/frontend/data/locale/en-US.ini @@ -1042,6 +1042,7 @@ Basic.Settings.Stream.WHIPSimulcastLabel="Simulcast" Basic.Settings.Stream.WHIPSimulcastInfo="Simulcast allows you to encode and send multiple video qualities. Learn More" Basic.Settings.Stream.WHIPSimulcastTotalLayers="Total Layers" Basic.Settings.Stream.AdvancedOptions="Advanced Options" +Basic.Settings.Stream.ServiceOptions="Service Options" # basic mode 'output' settings Basic.Settings.Output="Output" diff --git a/frontend/forms/OBSBasicSettings.ui b/frontend/forms/OBSBasicSettings.ui index f0e191ce8b973b..4bc753a7b1cd43 100644 --- a/frontend/forms/OBSBasicSettings.ui +++ b/frontend/forms/OBSBasicSettings.ui @@ -1848,6 +1848,27 @@ + + + + Basic.Settings.Stream.ServiceOptions + + + + 8 + + + 2 + + + 8 + + + 8 + + + + diff --git a/frontend/settings/OBSBasicSettings.hpp b/frontend/settings/OBSBasicSettings.hpp index de4420cf81b713..1e9756fed60c1c 100644 --- a/frontend/settings/OBSBasicSettings.hpp +++ b/frontend/settings/OBSBasicSettings.hpp @@ -120,7 +120,9 @@ class OBSBasicSettings : public QDialog { std::vector formats; - OBSPropertiesView *streamProperties = nullptr; + OBSPropertiesView *servicePropertiesView = nullptr; + QString servicePropertiesId; + OBSPropertiesView *streamEncoderProps = nullptr; OBSPropertiesView *recordEncoderProps = nullptr; @@ -242,6 +244,10 @@ class OBSBasicSettings : public QDialog { inline bool IsWHIP() const; int FindService(const std::function &predicate); void LoadServices(bool showAll); + void LoadServicePropertiesView(); + void ClearServicePropertiesView(); + OBSData SeedServicePropertiesSettings(const char *serviceId) const; + void MergeServiceProperties(obs_data_t *settings); void OnOAuthStreamKeyConnected(); void OnAuthConnected(); QString lastService; diff --git a/frontend/settings/OBSBasicSettings_Stream.cpp b/frontend/settings/OBSBasicSettings_Stream.cpp index 71eead5d910fa5..0fe82033dc533b 100644 --- a/frontend/settings/OBSBasicSettings_Stream.cpp +++ b/frontend/settings/OBSBasicSettings_Stream.cpp @@ -9,10 +9,13 @@ #endif #include +#include #include #include +#include + static const QUuid &CustomServerUUID() { static const QUuid uuid = QUuid::fromString(QT_UTF8("{241da255-70f2-4bbb-bef7-509695bf8e65}")); @@ -86,6 +89,8 @@ void OBSBasicSettings::InitStreamPage() ui->connectedAccountLabel->setVisible(false); ui->connectedAccountText->setVisible(false); + ui->servicePropertiesGroupBox->setVisible(false); + int vertSpacing = ui->topStreamLayout->verticalSpacing(); QMargins m = ui->topStreamLayout->contentsMargins(); @@ -280,6 +285,8 @@ void OBSBasicSettings::LoadStream1Settings() ServiceChanged(true); + LoadServicePropertiesView(); + UpdateKeyLink(); UpdateMoreInfoLink(); UpdateVodTrackSetting(); @@ -336,6 +343,8 @@ void OBSBasicSettings::SaveStream1Settings() OBSDataAutoRelease settings = obs_data_create(); + MergeServiceProperties(settings); + if (!customServer && customServiceTypeId.isEmpty()) { obs_data_set_string(settings, "service", QT_TO_UTF8(ui->service->currentText())); obs_data_set_string(settings, "protocol", QT_TO_UTF8(protocol)); @@ -595,6 +604,112 @@ void OBSBasicSettings::LoadServices(bool showAll) ui->service->blockSignals(false); } +namespace { + +// Mandatory keys, cannot be re-declared or overwritten by custom service props +constexpr std::array kFrontendOwnedServiceKeys{"server", "key", "bearer_token", + "use_auth", "username", "password", + "service", "protocol", "using_custom_server", + "bwtest"}; + +obs_properties_t *createFilteredServiceProperties(const char *serviceId) +{ + obs_properties_t *props = obs_get_service_properties(serviceId); + + for (const char *name : kFrontendOwnedServiceKeys) { + obs_properties_remove_by_name(props, name); + } + + return props; +} + +// Reload callback for OBSPropertiesView, which passes the service type id back as its opaque object +obs_properties_t *getServiceCustomProperties(void *typeData) +{ + return createFilteredServiceProperties(static_cast(typeData)); +} + +bool serviceHasCustomProperties(const char *serviceId) +{ + OBSProperties props = createFilteredServiceProperties(serviceId); + return obs_properties_first(props) != nullptr; +} + +} // namespace + +void OBSBasicSettings::LoadServicePropertiesView() +{ + ClearServicePropertiesView(); + + if (!IsCustomServiceType()) { + return; + } + + const QString serviceId = GetCustomServiceTypeId(); + const QByteArray serviceIdUtf8 = serviceId.toUtf8(); + + if (!serviceHasCustomProperties(serviceIdUtf8.constData())) { + return; + } + + OBSData settings = SeedServicePropertiesSettings(serviceIdUtf8.constData()); + + servicePropertiesView = + new OBSPropertiesView(settings, serviceIdUtf8.constData(), getServiceCustomProperties, 170); + + servicePropertiesView->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); + servicePropertiesView->setScrolling(false); + servicePropertiesId = serviceId; + + connect(servicePropertiesView, &OBSPropertiesView::Changed, this, &OBSBasicSettings::Stream1Changed); + + ui->servicePropertiesLayout->addWidget(servicePropertiesView); + ui->servicePropertiesGroupBox->setVisible(true); +} + +void OBSBasicSettings::ClearServicePropertiesView() +{ + delete servicePropertiesView; + servicePropertiesView = nullptr; + servicePropertiesId.clear(); + ui->servicePropertiesGroupBox->setVisible(false); +} + +OBSData OBSBasicSettings::SeedServicePropertiesSettings(const char *serviceId) const +{ + OBSDataAutoRelease settings = obs_service_defaults(serviceId); + if (!settings) { + settings = obs_data_create(); + } + + obs_service_t *activeService = main->GetService(); + const char *activeServiceId = activeService ? obs_service_get_type(activeService) : nullptr; + if (activeServiceId && strcmp(serviceId, activeServiceId) == 0) { + OBSDataAutoRelease activeSettings = obs_service_get_settings(activeService); + obs_data_apply(settings, activeSettings); + } + + for (const char *name : kFrontendOwnedServiceKeys) { + obs_data_erase(settings, name); + } + + return settings.Get(); +} + +void OBSBasicSettings::MergeServiceProperties(obs_data_t *settings) +{ + if (!servicePropertiesView || servicePropertiesId.isEmpty() || + servicePropertiesId != GetCustomServiceTypeId()) { + return; + } + + obs_data_t *props = servicePropertiesView->GetSettings(); + + OBSDataAutoRelease defaults = obs_data_get_defaults(props); + obs_data_apply(settings, defaults); + obs_data_apply(settings, props); +} + static inline bool is_auth_service(const std::string &service) { return Auth::AuthType(service) != Auth::Type::None; @@ -670,6 +785,8 @@ void OBSBasicSettings::on_service_currentIndexChanged(int idx) ServiceChanged(); + LoadServicePropertiesView(); + UpdateMoreInfoLink(); UpdateServerList(); UpdateKeyLink(); @@ -877,6 +994,8 @@ OBSService OBSBasicSettings::SpawnTempService() OBSDataAutoRelease settings = obs_data_create(); + MergeServiceProperties(settings); + if (!custom && customServiceTypeId.isEmpty()) { obs_data_set_string(settings, "service", QT_TO_UTF8(ui->service->currentText())); obs_data_set_string(settings, "server", QT_TO_UTF8(ui->server->currentData().toString())); From 6f2bf6273581cea731b38bf4754978a8f657bf02 Mon Sep 17 00:00:00 2001 From: Gaston Bogarin Date: Thu, 20 Aug 2026 15:40:51 -0300 Subject: [PATCH 4/5] libobs: Add OBS_OUTPUT_NO_INTERLEAVE capability flag --- docs/sphinx/reference-outputs.rst | 16 ++++++++++++++++ libobs/obs-output.c | 18 ++++++++++++++++-- libobs/obs-output.h | 1 + 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/docs/sphinx/reference-outputs.rst b/docs/sphinx/reference-outputs.rst index dcfe16b620779f..c3687e6406ee56 100644 --- a/docs/sphinx/reference-outputs.rst +++ b/docs/sphinx/reference-outputs.rst @@ -74,6 +74,22 @@ Output Definition Structure (obs_output_info) frame. Audio data will be correctly truncated down to the exact audio sample according to that video frame timing. + - **OBS_OUTPUT_NO_INTERLEAVE** - Output does not want A/V interleaving. + + When this capability flag is used, encoded packets are delivered as + soon as each encoder produces them, instead of being held until a + packet of the opposing type establishes a monotonic muxed order. + This is intended for transports that carry each elementary stream + independently and whose receiver synchronises from media + timestamps; a muxed container should not use it. + + The output must then handle two things itself: video is no longer + gated on the first keyframe, so the first video packet may be a + delta frame, and packets arrive per encoder with no cross-type + ordering or timestamp offset normalisation. + + Ignored unless both video and audio are present. + .. member:: const char *(*obs_output_info.get_name)(void *type_data) Get the translated name of the output type. diff --git a/libobs/obs-output.c b/libobs/obs-output.c index 3e915917a77ecc..a7cb006bafcf5f 100644 --- a/libobs/obs-output.c +++ b/libobs/obs-output.c @@ -97,6 +97,11 @@ static inline bool flag_audio(const struct obs_output *output) return (output->info.flags & OBS_OUTPUT_AUDIO) != 0; } +static inline bool flag_no_interleave(const struct obs_output *output) +{ + return (output->info.flags & OBS_OUTPUT_NO_INTERLEAVE) != 0; +} + static inline bool log_flag_audio(const struct obs_output *output, const char *func_name) { bool ret = flag_audio(output); @@ -2326,6 +2331,15 @@ static void default_encoded_callback(void *param, struct encoder_packet *packet, obs_encoder_packet_release(packet); } +static inline encoded_callback_t choose_encoded_callback(const struct obs_output *output, bool has_video, + bool has_audio) +{ + if (!has_video || !has_audio || flag_no_interleave(output)) + return default_encoded_callback; + + return interleave_packets; +} + static void default_raw_video_callback(void *param, struct video_data *frame) { struct obs_output *output = param; @@ -2512,7 +2526,7 @@ static void hook_data_capture(struct obs_output *output) reset_packet_data(output); pthread_mutex_unlock(&output->interleaved_mutex); - encoded_callback = (has_video && has_audio) ? interleave_packets : default_encoded_callback; + encoded_callback = choose_encoded_callback(output, has_video, has_audio); if (output->delay_sec) { output->active_delay_ns = (uint64_t)output->delay_sec * 1000000000ULL; @@ -2865,7 +2879,7 @@ static void *end_data_capture_thread(void *data) if (output->active_delay_ns) encoded_callback = process_delay; else - encoded_callback = (has_video && has_audio) ? interleave_packets : default_encoded_callback; + encoded_callback = choose_encoded_callback(output, has_video, has_audio); if (has_video) stop_video_encoders(output, encoded_callback); diff --git a/libobs/obs-output.h b/libobs/obs-output.h index d765e35e9e0b6d..2eacc953df9ca7 100644 --- a/libobs/obs-output.h +++ b/libobs/obs-output.h @@ -32,6 +32,7 @@ extern "C" { #define OBS_OUTPUT_MULTI_TRACK_AUDIO OBS_OUTPUT_MULTI_TRACK #define OBS_OUTPUT_MULTI_TRACK_VIDEO (1 << 6) #define OBS_OUTPUT_MULTI_TRACK_AV (OBS_OUTPUT_MULTI_TRACK_AUDIO | OBS_OUTPUT_MULTI_TRACK_VIDEO) +#define OBS_OUTPUT_NO_INTERLEAVE (1 << 7) #define MAX_OUTPUT_AUDIO_ENCODERS 6 #define MAX_OUTPUT_VIDEO_ENCODERS 10 From 105b85c04cf4695f07da0e6ab293ece691d7887c Mon Sep 17 00:00:00 2001 From: Gaston Bogarin Date: Fri, 28 Aug 2026 15:53:42 -0300 Subject: [PATCH 5/5] mac-videotoolbox: Add low latency rate control Add a "low_latency" encoder setting, not exposed in the UI, that services can enable through apply_encoder_settings for real-time protocols. On hardware H.264/HEVC encoders it creates the session with EnableLowLatencyRateControl, which selects the low latency (.rtvc) encoder, and sets RealTime. CBR falls back to ABR and Spatial AQ is skipped, as neither is supported in this mode. Other encoders ignore the setting and encode normally. --- plugins/mac-videotoolbox/encoder.c | 115 +++++++++++++++++++++++------ 1 file changed, 94 insertions(+), 21 deletions(-) diff --git a/plugins/mac-videotoolbox/encoder.c b/plugins/mac-videotoolbox/encoder.c index ca084ac6e568dc..6f796b7cd3a5db 100644 --- a/plugins/mac-videotoolbox/encoder.c +++ b/plugins/mac-videotoolbox/encoder.c @@ -64,6 +64,7 @@ struct vt_encoder { CMVideoCodecType codec_type; bool bframes; bool spatial_aq; + bool low_latency; int vt_pix_fmt; enum video_colorspace colorspace; @@ -273,7 +274,8 @@ static OSStatus session_set_prop(VTCompressionSessionRef session, CFStringRef ke } static OSStatus session_set_bitrate(VTCompressionSessionRef session, const char *rate_control, int new_bitrate, - float quality, bool limit_bitrate, int max_bitrate, double max_bitrate_window) + float quality, bool limit_bitrate, int max_bitrate, double max_bitrate_window, + bool low_latency) { OSStatus code; @@ -284,7 +286,11 @@ static OSStatus session_set_bitrate(VTCompressionSessionRef session, const char compressionPropertyKey = kVTCompressionPropertyKey_AverageBitRate; can_limit_bitrate = true; - if (__builtin_available(macOS 13.0, *)) { + if (low_latency) { + VT_LOG(LOG_WARNING, + "CBR is not supported with low latency rate control. Will use ABR instead."); + can_limit_bitrate = false; + } else if (__builtin_available(macOS 13.0, *)) { if (is_apple_silicon) { compressionPropertyKey = kVTCompressionPropertyKey_ConstantBitRate; can_limit_bitrate = false; @@ -422,15 +428,39 @@ void sample_encoded_callback(void *data, void *source, OSStatus status, VTEncode CFRelease(pixbuf); } -static inline CFDictionaryRef create_encoder_spec(const char *vt_encoder_id) +static char *copy_low_latency_encoder_id(struct vt_encoder *enc) { - CFStringRef id = CFStringCreateWithFileSystemRepresentation(NULL, vt_encoder_id); + CFTypeRef keys[1] = {kVTVideoEncoderSpecification_EnableLowLatencyRateControl}; + CFTypeRef values[1] = {kCFBooleanTrue}; + CFDictionaryRef spec = CFDictionaryCreate(kCFAllocatorDefault, keys, values, 1, &kCFTypeDictionaryKeyCallBacks, + &kCFTypeDictionaryValueCallBacks); - CFTypeRef keys[1] = {kVTVideoEncoderSpecification_EncoderID}; - CFTypeRef values[1] = {id}; + CFStringRef id = NULL; + OSStatus code = VTCopySupportedPropertyDictionaryForEncoder((int32_t)enc->width, (int32_t)enc->height, + enc->codec_type, spec, &id, NULL); + CFRelease(spec); - CFDictionaryRef encoder_spec = CFDictionaryCreate( - kCFAllocatorDefault, keys, values, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); + if (code != noErr || id == NULL) + return NULL; + + char *str = cfstr_copy_cstr(id, kCFStringEncodingUTF8); + CFRelease(id); + + return str; +} + +static inline CFDictionaryRef create_encoder_spec(const char *vt_encoder_id, const char *low_latency_id) +{ + const bool low_latency = low_latency_id != NULL; + CFStringRef id = CFStringCreateWithFileSystemRepresentation(NULL, low_latency ? low_latency_id : vt_encoder_id); + + CFTypeRef keys[2] = {kVTVideoEncoderSpecification_EncoderID, + kVTVideoEncoderSpecification_EnableLowLatencyRateControl}; + CFTypeRef values[2] = {id, kCFBooleanTrue}; + + CFDictionaryRef encoder_spec = CFDictionaryCreate(kCFAllocatorDefault, keys, values, low_latency ? 2 : 1, + &kCFTypeDictionaryKeyCallBacks, + &kCFTypeDictionaryValueCallBacks); CFRelease(id); @@ -494,12 +524,28 @@ static OSStatus create_encoder(struct vt_encoder *enc) const char *codec_name = obs_encoder_get_codec(enc->encoder); CFDictionaryRef encoder_spec; + char *low_latency_id = NULL; if (strcmp(codec_name, "prores") == 0) { struct vt_encoder_type_data *type_data = (struct vt_encoder_type_data *)obs_encoder_get_type_data(enc->encoder); encoder_spec = create_prores_encoder_spec(enc->codec_type, type_data->hardware_accelerated); } else { - encoder_spec = create_encoder_spec(enc->vt_encoder_id); + if (enc->low_latency) { + // Low latency rate control is only offered by dedicated encoders + // (e.g. "com.apple.videotoolbox.videoencoder.h264.rtvc"), so the + // selected encoder is swapped for the low latency one of the same codec. + low_latency_id = copy_low_latency_encoder_id(enc); + if (low_latency_id != NULL) { + VT_BLOG(LOG_INFO, "low latency: encoding with '%s' in place of '%s'", low_latency_id, + enc->vt_encoder_id); + } else { + VT_BLOG(LOG_WARNING, "no low latency encoder for %.4s at %ux%u, encoding normally", + codec_type_to_print_fmt(enc->codec_type), enc->width, enc->height); + enc->low_latency = false; + } + } + + encoder_spec = create_encoder_spec(enc->vt_encoder_id, low_latency_id); } CFDictionaryRef pixbuf_spec = create_pixbuf_spec(enc); @@ -513,6 +559,7 @@ static OSStatus create_encoder(struct vt_encoder *enc) CFRelease(encoder_spec); CFRelease(pixbuf_spec); + bfree(low_latency_id); CFBooleanRef b = NULL; code = VTSessionCopyProperty(s, kVTCompressionPropertyKey_UsingHardwareAcceleratedVideoEncoder, NULL, &b); @@ -572,28 +619,36 @@ static OSStatus create_encoder(struct vt_encoder *enc) } code = session_set_bitrate(s, enc->rate_control, enc->bitrate, enc->quality, enc->limit_bitrate, - enc->rc_max_bitrate, enc->rc_max_bitrate_window); + enc->rc_max_bitrate, enc->rc_max_bitrate_window, enc->low_latency); if (code != noErr) { return code; } - if (__builtin_available(macOS 15.0, *)) { - int spatial_aq = enc->spatial_aq ? kVTQPModulationLevel_Default : kVTQPModulationLevel_Disable; - CFNumberRef spatialAQ = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &spatial_aq); + // The low latency encoder rejects Spatial AQ with kVTPropertyNotSupportedErr, so skip it + if (!enc->low_latency) { + if (__builtin_available(macOS 15.0, *)) { + int spatial_aq = enc->spatial_aq ? kVTQPModulationLevel_Default + : kVTQPModulationLevel_Disable; + CFNumberRef spatialAQ = + CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &spatial_aq); - code = VTSessionSetProperty(s, kVTCompressionPropertyKey_SpatialAdaptiveQPLevel, spatialAQ); + code = VTSessionSetProperty(s, kVTCompressionPropertyKey_SpatialAdaptiveQPLevel, + spatialAQ); - if (code != noErr) { - log_osstatus(LOG_WARNING, enc, - "setting kVTCompressionPropertyKey_SpatialAdaptiveQPLevel failed", code); - } + if (code != noErr) { + log_osstatus(LOG_WARNING, enc, + "setting kVTCompressionPropertyKey_SpatialAdaptiveQPLevel failed", + code); + } - CFRelease(spatialAQ); + CFRelease(spatialAQ); + } } } // This can fail depending on hardware configuration - code = session_set_prop(s, kVTCompressionPropertyKey_RealTime, kCFBooleanFalse); + code = session_set_prop(s, kVTCompressionPropertyKey_RealTime, + enc->low_latency ? kCFBooleanTrue : kCFBooleanFalse); if (code != noErr) log_osstatus(LOG_WARNING, enc, "setting kVTCompressionPropertyKey_RealTime failed, " @@ -648,11 +703,13 @@ static void dump_encoder_info(struct vt_encoder *enc) "\trc_max_bitrate_window: %f (s)\n" "\thw_enc: %s\n" "\tspatial_aq: %s\n" + "\tlow_latency: %s\n" "\tprofile: %s\n" "\tcodec_type: %.4s\n", enc->vt_encoder_id, enc->rate_control, enc->bitrate, enc->quality, enc->fps_num, enc->fps_den, enc->width, enc->height, enc->keyint, enc->limit_bitrate ? "on" : "off", enc->rc_max_bitrate, enc->rc_max_bitrate_window, enc->hw_enc ? "on" : "off", enc->spatial_aq ? "on" : "off", + enc->low_latency ? "on" : "off", (enc->profile != NULL && !!strlen(enc->profile)) ? enc->profile : "default", codec_type_to_print_fmt(enc->codec_type)); } @@ -772,7 +829,8 @@ static bool vt_update(void *data, obs_data_t *settings) return true; OSStatus code = session_set_bitrate(enc->session, enc->rate_control, enc->bitrate, enc->quality, - enc->limit_bitrate, enc->rc_max_bitrate, enc->rc_max_bitrate_window); + enc->limit_bitrate, enc->rc_max_bitrate, enc->rc_max_bitrate_window, + enc->low_latency); if (code != noErr) VT_BLOG(LOG_WARNING, "Failed to set bitrate to session"); @@ -792,6 +850,21 @@ static void *vt_create(obs_data_t *settings, obs_encoder_t *encoder) if (!update_params(enc, settings)) goto fail; + // Low latency is part of the encoder specification and cannot change once + // the session exists, so it is decided here instead of in update_params(), + // which also runs on every vt_update(). + if (obs_data_get_bool(settings, "low_latency")) { + struct vt_encoder_type_data *type_data = + (struct vt_encoder_type_data *)obs_encoder_get_type_data(enc->encoder); + + if (type_data->hardware_accelerated && + (enc->codec_type == kCMVideoCodecType_H264 || enc->codec_type == kCMVideoCodecType_HEVC)) + enc->low_latency = true; + else + VT_BLOG(LOG_INFO, + "low latency was requested but this encoder does not support it, encoding normally"); + } + code = CMSimpleQueueCreate(NULL, 100, &enc->queue); if (code != noErr) { goto fail;