Skip to content

Commit

Permalink
UI: Enable WHIP service in UI
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Sean-Der and kc5nra committed Jun 6, 2023
1 parent 63f9589 commit a6c84b2
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 13 deletions.
1 change: 1 addition & 0 deletions UI/data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion UI/window-basic-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
71 changes: 59 additions & 12 deletions UI/window-basic-settings-stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ extern QCefCookieManager *panel_cookies;
enum class ListOpt : int {
ShowAll = 1,
Custom,
WHIP,
};

enum class Section : int {
Expand All @@ -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);
Expand Down Expand Up @@ -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;

Expand All @@ -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();

Expand Down Expand Up @@ -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)
Expand All @@ -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();
Expand All @@ -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));
Expand Down Expand Up @@ -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);
Expand All @@ -262,7 +290,7 @@ void OBSBasicSettings::SaveStream1Settings()

void OBSBasicSettings::UpdateMoreInfoLink()
{
if (IsCustomService()) {
if (IsCustomService() || IsWHIP()) {
ui->moreInfoButton->hide();
return;
}
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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(
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions UI/window-basic-settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ class OBSBasicSettings : public QDialog {
/* stream */
void InitStreamPage();
inline bool IsCustomService() const;
inline bool IsWHIP() const;
void LoadServices(bool showAll);
void OnOAuthStreamKeyConnected();
void OnAuthConnected();
Expand Down

0 comments on commit a6c84b2

Please sign in to comment.