Просмотр исходного кода

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 <[email protected]>
Signed-off-by: pkv <[email protected]>
Sean DuBois 2 лет назад
Родитель
Сommit
dd392188b8

+ 1 - 0
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"

+ 2 - 1
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)

+ 59 - 12
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);

+ 1 - 0
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();