Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
229 changes: 144 additions & 85 deletions UI/window-basic-settings-stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,29 +78,10 @@ void OBSBasicSettings::InitStreamPage()
ui->twitchAddonDropdown->addItem(
QTStr("Basic.Settings.Stream.TTVAddon.Both"));

connect(ui->service, SIGNAL(currentIndexChanged(int)), this,
SLOT(UpdateServerList()));
connect(ui->service, SIGNAL(currentIndexChanged(int)), this,
SLOT(UpdateKeyLink()));
connect(ui->service, SIGNAL(currentIndexChanged(int)), this,
SLOT(UpdateVodTrackSetting()));
connect(ui->service, SIGNAL(currentIndexChanged(int)), this,
SLOT(UpdateServiceRecommendations()));
connect(ui->service, SIGNAL(currentIndexChanged(int)), this,
SLOT(UpdateResFPSLimits()));
connect(ui->customServer, SIGNAL(textChanged(const QString &)), this,
SLOT(UpdateKeyLink()));
connect(ui->ignoreRecommended, SIGNAL(clicked(bool)), this,
SLOT(DisplayEnforceWarning(bool)));
connect(ui->ignoreRecommended, SIGNAL(toggled(bool)), this,
SLOT(UpdateResFPSLimits()));
connect(ui->service, SIGNAL(currentIndexChanged(int)), this,
SLOT(UpdateMoreInfoLink()));

connect(ui->service, SIGNAL(currentIndexChanged(int)), this,
SLOT(UpdateAdvNetworkGroup()));
connect(ui->customServer, SIGNAL(textChanged(const QString &)), this,
SLOT(UpdateAdvNetworkGroup()));
}

void OBSBasicSettings::LoadStream1Settings()
Expand All @@ -118,11 +99,13 @@ void OBSBasicSettings::LoadStream1Settings()
const char *service = obs_data_get_string(settings, "service");
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));

if (strcmp(type, "rtmp_custom") == 0) {
ui->service->setCurrentIndex(0);
ui->customServer->setText(server);
lastServiceIdx = 0;
lastCustomServer = ui->customServer->text();

bool use_auth = obs_data_get_bool(settings, "use_auth");
const char *username =
Expand Down Expand Up @@ -458,13 +441,46 @@ void OBSBasicSettings::UseStreamKeyAdvClicked()
ui->streamKeyWidget->setVisible(true);
}

void OBSBasicSettings::on_service_currentIndexChanged(int)
void OBSBasicSettings::on_service_currentIndexChanged(int idx)
{
bool showMore = ui->service->currentData().toInt() ==
(int)ListOpt::ShowAll;
if (showMore)
if (ui->service->currentData().toInt() == (int)ListOpt::ShowAll) {
LoadServices(true);
ui->service->showPopup();
return;
}

ServiceChanged();

UpdateMoreInfoLink();
UpdateServerList();
UpdateKeyLink();
UpdateServiceRecommendations();

UpdateVodTrackSetting();

protocol = FindProtocol();
UpdateAdvNetworkGroup();

if (ServiceSupportsCodecCheck() && UpdateResFPSLimits()) {
lastServiceIdx = idx;
if (idx == 0)
lastCustomServer = ui->customServer->text();
}
}

void OBSBasicSettings::on_customServer_textChanged(const QString &)
{
UpdateKeyLink();

protocol = FindProtocol();
UpdateAdvNetworkGroup();

if (ServiceSupportsCodecCheck())
lastCustomServer = ui->customServer->text();
}

void OBSBasicSettings::ServiceChanged()
{
std::string service = QT_TO_UTF8(ui->service->currentText());
bool custom = IsCustomService();

Expand Down Expand Up @@ -515,20 +531,49 @@ void OBSBasicSettings::on_service_currentIndexChanged(int)
}
}

void OBSBasicSettings::UpdateServerList()
QString OBSBasicSettings::FindProtocol()
{
QString serviceName = ui->service->currentText();
bool showMore = ui->service->currentData().toInt() ==
(int)ListOpt::ShowAll;
if (IsCustomService() && !ui->customServer->text().isEmpty()) {

QString server = ui->customServer->text();

if (server.startsWith("rtmps://"))
return QString("RTMPS");

if (server.startsWith("ftl://"))
return QString("FTL");

if (server.startsWith("srt://"))
return QString("SRT");

if (server.startsWith("rist://"))
return QString("RIST");

if (showMore) {
LoadServices(true);
ui->service->showPopup();
return;
} else {
lastService = serviceName;
obs_properties_t *props =
obs_get_service_properties("rtmp_common");
obs_property_t *services = obs_properties_get(props, "service");

OBSDataAutoRelease settings = obs_data_create();

obs_data_set_string(settings, "service",
QT_TO_UTF8(ui->service->currentText()));
obs_property_modified(services, settings);

obs_properties_destroy(props);

return QT_UTF8(obs_data_get_string(settings, "protocol"));
}

return QString("RTMP");
}

void OBSBasicSettings::UpdateServerList()
{
QString serviceName = ui->service->currentText();

lastService = serviceName;

obs_properties_t *props = obs_get_service_properties("rtmp_common");
obs_property_t *services = obs_properties_get(props, "service");

Expand Down Expand Up @@ -985,17 +1030,14 @@ extern void set_closest_res(int &cx, int &cy,
* which as of this writing, and hopefully for the foreseeable future, there is
* only one.
*/
void OBSBasicSettings::UpdateResFPSLimits()
bool OBSBasicSettings::UpdateResFPSLimits()
{
if (loading)
return;

if (!ServiceSupportsCodecCheck())
return;
return false;

int idx = ui->service->currentIndex();
if (idx == -1)
return;
return false;

bool ignoreRecommended = ui->ignoreRecommended->isChecked();
BPtr<obs_service_resolution> res_list;
Expand Down Expand Up @@ -1073,8 +1115,7 @@ void OBSBasicSettings::UpdateResFPSLimits()
ui->ignoreRecommended->setProperty("changed", true);
stream1Changed = true;
EnableApplyButton(true);
UpdateResFPSLimits();
return;
return UpdateResFPSLimits();
}

QMessageBox::StandardButton button;
Expand Down Expand Up @@ -1106,7 +1147,7 @@ void OBSBasicSettings::UpdateResFPSLimits()
"setChecked",
Qt::QueuedConnection,
Q_ARG(bool, true));
return;
return false;
}
}

Expand Down Expand Up @@ -1187,24 +1228,8 @@ void OBSBasicSettings::UpdateResFPSLimits()
/* ------------------------------------ */

lastIgnoreRecommended = (int)ignoreRecommended;
lastServiceIdx = idx;
}

bool OBSBasicSettings::IsServiceOutputHasNetworkFeatures()
{
if (IsCustomService())
return ui->customServer->text().startsWith("rtmp");

OBSServiceAutoRelease service = SpawnTempService();
const char *output = obs_service_get_output_type(service);

if (!output)
return true;

if (strcmp(output, "rtmp_output") == 0)
return true;

return false;
return true;
}

static bool service_supports_codec(const char **codecs, const char *codec)
Expand Down Expand Up @@ -1234,17 +1259,19 @@ static inline bool service_supports_encoder(const char **codecs,
return service_supports_codec(codecs, codec);
}

bool OBSBasicSettings::ServiceAndCodecCompatible()
static bool return_first_id(void *data, const char *id)
{
if (IsCustomService())
return true;
if (ui->service->currentData().toInt() == (int)ListOpt::ShowAll)
return true;
const char **output = (const char **)data;

*output = id;
return false;
}

bool OBSBasicSettings::ServiceAndCodecCompatible()
{
bool simple = (ui->outputMode->currentIndex() == 0);
bool ret;

OBSService service = SpawnTempService();
const char **codecs = obs_service_get_supported_video_codecs(service);
const char *codec;

if (simple) {
Expand All @@ -1257,7 +1284,29 @@ bool OBSBasicSettings::ServiceAndCodecCompatible()
codec = obs_get_encoder_codec(QT_TO_UTF8(encoder));
}

return service_supports_codec(codecs, codec);
OBSService service = SpawnTempService();
const char **codecs = obs_service_get_supported_video_codecs(service);

if (!codecs || IsCustomService()) {
const char *output;
char **output_codecs;

obs_enum_output_types_with_protocol(QT_TO_UTF8(protocol),
&output, return_first_id);

output_codecs = strlist_split(
obs_get_output_supported_video_codecs(output), ';',
false);

ret = service_supports_codec((const char **)output_codecs,
codec);

strlist_free(output_codecs);
} else {
ret = service_supports_codec(codecs, codec);
}

return ret;
}

/* we really need a way to find fallbacks in a less hardcoded way. maybe. */
Expand Down Expand Up @@ -1287,8 +1336,12 @@ static QString get_simple_fallback(const QString &enc)

bool OBSBasicSettings::ServiceSupportsCodecCheck()
{
if (loading)
return false;

if (ServiceAndCodecCompatible()) {
if (lastServiceIdx != ui->service->currentIndex())
if (lastServiceIdx != ui->service->currentIndex() ||
IsCustomService())
ResetEncoders(true);
return true;
}
Expand Down Expand Up @@ -1327,9 +1380,17 @@ bool OBSBasicSettings::ServiceSupportsCodecCheck()
#undef WARNING_VAL

if (button == QMessageBox::No) {
QMetaObject::invokeMethod(ui->service, "setCurrentIndex",
Qt::QueuedConnection,
Q_ARG(int, lastServiceIdx));
if (lastServiceIdx == 0 &&
lastServiceIdx == ui->service->currentIndex())
QMetaObject::invokeMethod(ui->customServer, "setText",
Qt::QueuedConnection,
Q_ARG(QString,
lastCustomServer));
else
QMetaObject::invokeMethod(ui->service,
"setCurrentIndex",
Qt::QueuedConnection,
Q_ARG(int, lastServiceIdx));
return false;
}

Expand All @@ -1347,8 +1408,20 @@ void OBSBasicSettings::ResetEncoders(bool streamOnly)
OBSService service = SpawnTempService();
const char **codecs = obs_service_get_supported_video_codecs(service);
const char *type;
BPtr<char *> output_codecs;
size_t idx = 0;

if (!codecs || IsCustomService()) {
const char *output;

obs_enum_output_types_with_protocol(QT_TO_UTF8(protocol),
&output, return_first_id);
output_codecs = strlist_split(
obs_get_output_supported_video_codecs(output), ';',
false);
codecs = (const char **)output_codecs.Get();
}

QSignalBlocker s1(ui->simpleOutStrEncoder);
QSignalBlocker s2(ui->advOutEncoder);

Expand All @@ -1374,27 +1447,13 @@ void OBSBasicSettings::ResetEncoders(bool streamOnly)
if (obs_get_encoder_type(type) != OBS_ENCODER_VIDEO)
continue;

const char *streaming_codecs[] = {
"h264",
#ifdef ENABLE_HEVC
"hevc",
#endif
};

bool is_streaming_codec = false;
for (const char *test_codec : streaming_codecs) {
if (strcmp(codec, test_codec) == 0) {
is_streaming_codec = true;
break;
}
}
if ((caps & ENCODER_HIDE_FLAGS) != 0)
continue;

QString qName = QT_UTF8(name);
QString qType = QT_UTF8(type);

if (is_streaming_codec && service_supports_codec(codecs, codec))
if (service_supports_codec(codecs, codec))
ui->advOutEncoder->addItem(qName, qType);
if (!streamOnly)
ui->advOutRecEncoder->addItem(qName, qType);
Expand Down
2 changes: 1 addition & 1 deletion UI/window-basic-settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5621,7 +5621,7 @@ void OBSBasicSettings::RecreateOutputResolutionWidget()

void OBSBasicSettings::UpdateAdvNetworkGroup()
{
bool enabled = IsServiceOutputHasNetworkFeatures();
bool enabled = protocol.contains("RTMP");

ui->advNetworkDisabled->setVisible(!enabled);

Expand Down
Loading