From dd392188b8f60ebc7e600ea803eda5304b4aebf9 Mon Sep 17 00:00:00 2001 From: Sean DuBois Date: Thu, 6 Apr 2023 21:52:13 -0400 Subject: [PATCH] UI: Enable WHIP service in UI This provides the UI glue to enable the WHIP service introduced in the obs-webrtc plugin. Co-authored-by: John Bradley Signed-off-by: pkv --- UI/data/locale/en-US.ini | 1 + UI/window-basic-main.cpp | 3 +- UI/window-basic-settings-stream.cpp | 71 ++++++++++++++++++++++++----- UI/window-basic-settings.hpp | 1 + 4 files changed, 63 insertions(+), 13 deletions(-) diff --git a/UI/data/locale/en-US.ini b/UI/data/locale/en-US.ini index f06ea1314..34e093deb 100644 --- a/UI/data/locale/en-US.ini +++ b/UI/data/locale/en-US.ini @@ -208,6 +208,7 @@ Basic.AutoConfig.StreamPage.Server="Server" Basic.AutoConfig.StreamPage.StreamKey="Stream Key" Basic.AutoConfig.StreamPage.StreamKey.ToolTip="RIST: enter the encryption passphrase.\nRTMP: enter the key provided by the service.\nSRT: enter the streamid if the service uses one." Basic.AutoConfig.StreamPage.EncoderKey="Encoder Key" +Basic.AutoConfig.StreamPage.BearerToken="Bearer Token" Basic.AutoConfig.StreamPage.ConnectedAccount="Connected account" Basic.AutoConfig.StreamPage.PerformBandwidthTest="Estimate bitrate with bandwidth test (may take a few minutes)" Basic.AutoConfig.StreamPage.PreferHardwareEncoding="Prefer hardware encoding" diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index 4b57ec240..b0ca8cac9 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -1369,7 +1369,8 @@ bool OBSBasic::LoadService() return false; /* Enforce Opus on FTL if needed */ - if (strcmp(obs_service_get_protocol(service), "FTL") == 0) { + if (strcmp(obs_service_get_protocol(service), "FTL") == 0 || + strcmp(obs_service_get_protocol(service), "WHIP") == 0) { const char *option = config_get_string( basicConfig, "SimpleOutput", "StreamAudioEncoder"); if (strcmp(option, "opus") != 0) diff --git a/UI/window-basic-settings-stream.cpp b/UI/window-basic-settings-stream.cpp index e167e31be..ee035f6a9 100644 --- a/UI/window-basic-settings-stream.cpp +++ b/UI/window-basic-settings-stream.cpp @@ -29,6 +29,7 @@ extern QCefCookieManager *panel_cookies; enum class ListOpt : int { ShowAll = 1, Custom, + WHIP, }; enum class Section : int { @@ -41,6 +42,11 @@ inline bool OBSBasicSettings::IsCustomService() const return ui->service->currentData().toInt() == (int)ListOpt::Custom; } +inline bool OBSBasicSettings::IsWHIP() const +{ + return ui->service->currentData().toInt() == (int)ListOpt::WHIP; +} + void OBSBasicSettings::InitStreamPage() { ui->connectAccount2->setVisible(false); @@ -91,6 +97,9 @@ void OBSBasicSettings::LoadStream1Settings() obs_service_t *service_obj = main->GetService(); const char *type = obs_service_get_type(service_obj); + bool is_rtmp_custom = (strcmp(type, "rtmp_custom") == 0); + bool is_rtmp_common = (strcmp(type, "rtmp_common") == 0); + bool is_whip = (strcmp(type, "whip_custom") == 0); loading = true; @@ -100,10 +109,14 @@ void OBSBasicSettings::LoadStream1Settings() const char *server = obs_data_get_string(settings, "server"); const char *key = obs_data_get_string(settings, "key"); protocol = QT_UTF8(obs_service_get_protocol(service_obj)); + const char *bearer_token = + obs_data_get_string(settings, "bearer_token"); - if (strcmp(type, "rtmp_custom") == 0) { - ui->service->setCurrentIndex(0); + if (is_rtmp_custom || is_whip) ui->customServer->setText(server); + + if (is_rtmp_custom) { + ui->service->setCurrentIndex(0); lastServiceIdx = 0; lastCustomServer = ui->customServer->text(); @@ -157,7 +170,7 @@ void OBSBasicSettings::LoadStream1Settings() UpdateServerList(); - if (strcmp(type, "rtmp_common") == 0) { + if (is_rtmp_common) { int idx = ui->server->findData(server); if (idx == -1) { if (server && *server) @@ -167,7 +180,10 @@ void OBSBasicSettings::LoadStream1Settings() ui->server->setCurrentIndex(idx); } - ui->key->setText(key); + if (is_whip) + ui->key->setText(bearer_token); + else + ui->key->setText(key); lastService.clear(); ServiceChanged(); @@ -191,14 +207,21 @@ void OBSBasicSettings::LoadStream1Settings() void OBSBasicSettings::SaveStream1Settings() { bool customServer = IsCustomService(); - const char *service_id = customServer ? "rtmp_custom" : "rtmp_common"; + bool whip = IsWHIP(); + const char *service_id = "rtmp_common"; + + if (customServer) { + service_id = "rtmp_custom"; + } else if (whip) { + service_id = "whip_custom"; + } obs_service_t *oldService = main->GetService(); OBSDataAutoRelease hotkeyData = obs_hotkeys_save_service(oldService); OBSDataAutoRelease settings = obs_data_create(); - if (!customServer) { + if (!customServer && !whip) { obs_data_set_string(settings, "service", QT_TO_UTF8(ui->service->currentText())); obs_data_set_string(settings, "protocol", QT_TO_UTF8(protocol)); @@ -239,7 +262,12 @@ void OBSBasicSettings::SaveStream1Settings() obs_data_set_bool(settings, "bwtest", false); } - obs_data_set_string(settings, "key", QT_TO_UTF8(ui->key->text())); + if (whip) + 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())); OBSServiceAutoRelease newService = obs_service_create( service_id, "default_service", settings, hotkeyData); @@ -262,7 +290,7 @@ void OBSBasicSettings::SaveStream1Settings() void OBSBasicSettings::UpdateMoreInfoLink() { - if (IsCustomService()) { + if (IsCustomService() || IsWHIP()) { ui->moreInfoButton->hide(); return; } @@ -312,6 +340,9 @@ void OBSBasicSettings::UpdateKeyLink() if (serviceName == "Dacast") { ui->streamKeyLabel->setText( QTStr("Basic.AutoConfig.StreamPage.EncoderKey")); + } else if (IsWHIP()) { + ui->streamKeyLabel->setText( + QTStr("Basic.AutoConfig.StreamPage.BearerToken")); } else if (!IsCustomService()) { ui->streamKeyLabel->setText( QTStr("Basic.AutoConfig.StreamPage.StreamKey")); @@ -356,6 +387,8 @@ void OBSBasicSettings::LoadServices(bool showAll) for (QString &name : names) ui->service->addItem(name); + ui->service->insertItem(0, QTStr("WHIP"), QVariant((int)ListOpt::WHIP)); + if (!showAll) { ui->service->addItem( QTStr("Basic.AutoConfig.StreamPage.Service.ShowAll"), @@ -484,6 +517,7 @@ void OBSBasicSettings::ServiceChanged() { std::string service = QT_TO_UTF8(ui->service->currentText()); bool custom = IsCustomService(); + bool whip = IsWHIP(); ui->disconnectAccount->setVisible(false); ui->bandwidthTestEnable->setVisible(false); @@ -500,7 +534,7 @@ void OBSBasicSettings::ServiceChanged() ui->authPwLabel->setVisible(custom); ui->authPwWidget->setVisible(custom); - if (custom) { + if (custom || whip) { ui->streamkeyPageLayout->insertRow(1, ui->serverLabel, ui->serverStackedWidget); @@ -625,11 +659,18 @@ void OBSBasicSettings::on_authPwShow_clicked() OBSService OBSBasicSettings::SpawnTempService() { bool custom = IsCustomService(); - const char *service_id = custom ? "rtmp_custom" : "rtmp_common"; + bool whip = IsWHIP(); + const char *service_id = "rtmp_common"; + + if (custom) { + service_id = "rtmp_custom"; + } else if (whip) { + service_id = "whip_custom"; + } OBSDataAutoRelease settings = obs_data_create(); - if (!custom) { + if (!custom && !whip) { obs_data_set_string(settings, "service", QT_TO_UTF8(ui->service->currentText())); obs_data_set_string( @@ -640,7 +681,13 @@ OBSService OBSBasicSettings::SpawnTempService() settings, "server", QT_TO_UTF8(ui->customServer->text().trimmed())); } - obs_data_set_string(settings, "key", QT_TO_UTF8(ui->key->text())); + + if (whip) + 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())); OBSServiceAutoRelease newService = obs_service_create( service_id, "temp_service", settings, nullptr); diff --git a/UI/window-basic-settings.hpp b/UI/window-basic-settings.hpp index 33b5b107c..ac99da9de 100644 --- a/UI/window-basic-settings.hpp +++ b/UI/window-basic-settings.hpp @@ -258,6 +258,7 @@ private: /* stream */ void InitStreamPage(); inline bool IsCustomService() const; + inline bool IsWHIP() const; void LoadServices(bool showAll); void OnOAuthStreamKeyConnected(); void OnAuthConnected();