window-basic-settings-stream.cpp 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894
  1. #include <QMessageBox>
  2. #include <QUrl>
  3. #include <QUuid>
  4. #include "window-basic-settings.hpp"
  5. #include "obs-frontend-api.h"
  6. #include "obs-app.hpp"
  7. #include "window-basic-main.hpp"
  8. #include "qt-wrappers.hpp"
  9. #include "url-push-button.hpp"
  10. #ifdef BROWSER_AVAILABLE
  11. #include <browser-panel.hpp>
  12. #endif
  13. #include "auth-oauth.hpp"
  14. #include "ui-config.h"
  15. #ifdef YOUTUBE_ENABLED
  16. #include "youtube-api-wrappers.hpp"
  17. #endif
  18. static const QUuid &CustomServerUUID()
  19. {
  20. static const QUuid uuid = QUuid::fromString(
  21. QT_UTF8("{241da255-70f2-4bbb-bef7-509695bf8e65}"));
  22. return uuid;
  23. }
  24. struct QCef;
  25. struct QCefCookieManager;
  26. extern QCef *cef;
  27. extern QCefCookieManager *panel_cookies;
  28. enum class ListOpt : int {
  29. ShowAll = 1,
  30. Custom,
  31. WHIP,
  32. };
  33. enum class Section : int {
  34. Connect,
  35. StreamKey,
  36. };
  37. inline bool OBSBasicSettings::IsCustomService() const
  38. {
  39. return ui->service->currentData().toInt() == (int)ListOpt::Custom;
  40. }
  41. inline bool OBSBasicSettings::IsWHIP() const
  42. {
  43. return ui->service->currentData().toInt() == (int)ListOpt::WHIP;
  44. }
  45. void OBSBasicSettings::InitStreamPage()
  46. {
  47. ui->connectAccount2->setVisible(false);
  48. ui->disconnectAccount->setVisible(false);
  49. ui->bandwidthTestEnable->setVisible(false);
  50. ui->twitchAddonDropdown->setVisible(false);
  51. ui->twitchAddonLabel->setVisible(false);
  52. ui->connectedAccountLabel->setVisible(false);
  53. ui->connectedAccountText->setVisible(false);
  54. int vertSpacing = ui->topStreamLayout->verticalSpacing();
  55. QMargins m = ui->topStreamLayout->contentsMargins();
  56. m.setBottom(vertSpacing / 2);
  57. ui->topStreamLayout->setContentsMargins(m);
  58. m = ui->loginPageLayout->contentsMargins();
  59. m.setTop(vertSpacing / 2);
  60. ui->loginPageLayout->setContentsMargins(m);
  61. m = ui->streamkeyPageLayout->contentsMargins();
  62. m.setTop(vertSpacing / 2);
  63. ui->streamkeyPageLayout->setContentsMargins(m);
  64. LoadServices(false);
  65. ui->twitchAddonDropdown->addItem(
  66. QTStr("Basic.Settings.Stream.TTVAddon.None"));
  67. ui->twitchAddonDropdown->addItem(
  68. QTStr("Basic.Settings.Stream.TTVAddon.BTTV"));
  69. ui->twitchAddonDropdown->addItem(
  70. QTStr("Basic.Settings.Stream.TTVAddon.FFZ"));
  71. ui->twitchAddonDropdown->addItem(
  72. QTStr("Basic.Settings.Stream.TTVAddon.Both"));
  73. connect(ui->ignoreRecommended, &QCheckBox::clicked, this,
  74. &OBSBasicSettings::DisplayEnforceWarning);
  75. connect(ui->ignoreRecommended, &QCheckBox::toggled, this,
  76. &OBSBasicSettings::UpdateResFPSLimits);
  77. }
  78. void OBSBasicSettings::LoadStream1Settings()
  79. {
  80. bool ignoreRecommended =
  81. config_get_bool(main->Config(), "Stream1", "IgnoreRecommended");
  82. obs_service_t *service_obj = main->GetService();
  83. const char *type = obs_service_get_type(service_obj);
  84. bool is_rtmp_custom = (strcmp(type, "rtmp_custom") == 0);
  85. bool is_rtmp_common = (strcmp(type, "rtmp_common") == 0);
  86. bool is_whip = (strcmp(type, "whip_custom") == 0);
  87. loading = true;
  88. OBSDataAutoRelease settings = obs_service_get_settings(service_obj);
  89. const char *service = obs_data_get_string(settings, "service");
  90. const char *server = obs_data_get_string(settings, "server");
  91. const char *key = obs_data_get_string(settings, "key");
  92. bool use_custom_server =
  93. obs_data_get_bool(settings, "using_custom_server");
  94. protocol = QT_UTF8(obs_service_get_protocol(service_obj));
  95. const char *bearer_token =
  96. obs_data_get_string(settings, "bearer_token");
  97. if (is_rtmp_custom || is_whip)
  98. ui->customServer->setText(server);
  99. if (is_rtmp_custom) {
  100. ui->service->setCurrentIndex(0);
  101. lastServiceIdx = 0;
  102. lastCustomServer = ui->customServer->text();
  103. bool use_auth = obs_data_get_bool(settings, "use_auth");
  104. const char *username =
  105. obs_data_get_string(settings, "username");
  106. const char *password =
  107. obs_data_get_string(settings, "password");
  108. ui->authUsername->setText(QT_UTF8(username));
  109. ui->authPw->setText(QT_UTF8(password));
  110. ui->useAuth->setChecked(use_auth);
  111. } else {
  112. int idx = ui->service->findText(service);
  113. if (idx == -1) {
  114. if (service && *service)
  115. ui->service->insertItem(1, service);
  116. idx = 1;
  117. }
  118. ui->service->setCurrentIndex(idx);
  119. lastServiceIdx = idx;
  120. bool bw_test = obs_data_get_bool(settings, "bwtest");
  121. ui->bandwidthTestEnable->setChecked(bw_test);
  122. idx = config_get_int(main->Config(), "Twitch", "AddonChoice");
  123. ui->twitchAddonDropdown->setCurrentIndex(idx);
  124. }
  125. UpdateServerList();
  126. if (is_rtmp_common) {
  127. int idx = -1;
  128. if (use_custom_server) {
  129. idx = ui->server->findData(CustomServerUUID());
  130. } else {
  131. idx = ui->server->findData(QString::fromUtf8(server));
  132. }
  133. if (idx == -1) {
  134. if (server && *server)
  135. ui->server->insertItem(0, server, server);
  136. idx = 0;
  137. }
  138. ui->server->setCurrentIndex(idx);
  139. }
  140. if (use_custom_server)
  141. ui->serviceCustomServer->setText(server);
  142. if (is_whip)
  143. ui->key->setText(bearer_token);
  144. else
  145. ui->key->setText(key);
  146. ServiceChanged(true);
  147. UpdateKeyLink();
  148. UpdateMoreInfoLink();
  149. UpdateVodTrackSetting();
  150. UpdateServiceRecommendations();
  151. bool streamActive = obs_frontend_streaming_active();
  152. ui->streamPage->setEnabled(!streamActive);
  153. ui->ignoreRecommended->setChecked(ignoreRecommended);
  154. loading = false;
  155. QMetaObject::invokeMethod(this, "UpdateResFPSLimits",
  156. Qt::QueuedConnection);
  157. }
  158. #define SRT_PROTOCOL "srt"
  159. #define RIST_PROTOCOL "rist"
  160. bool OBSBasicSettings::AllowsMultiTrack(const char *protocol)
  161. {
  162. return astrcmpi_n(protocol, SRT_PROTOCOL, strlen(SRT_PROTOCOL)) == 0 ||
  163. astrcmpi_n(protocol, RIST_PROTOCOL, strlen(RIST_PROTOCOL)) == 0;
  164. }
  165. void OBSBasicSettings::SwapMultiTrack(const char *protocol)
  166. {
  167. if (protocol) {
  168. if (AllowsMultiTrack(protocol)) {
  169. ui->advStreamTrackWidget->setCurrentWidget(
  170. ui->streamMultiTracks);
  171. } else {
  172. ui->advStreamTrackWidget->setCurrentWidget(
  173. ui->streamSingleTracks);
  174. }
  175. }
  176. }
  177. void OBSBasicSettings::SaveStream1Settings()
  178. {
  179. bool customServer = IsCustomService();
  180. bool whip = IsWHIP();
  181. const char *service_id = "rtmp_common";
  182. if (customServer) {
  183. service_id = "rtmp_custom";
  184. } else if (whip) {
  185. service_id = "whip_custom";
  186. }
  187. obs_service_t *oldService = main->GetService();
  188. OBSDataAutoRelease hotkeyData = obs_hotkeys_save_service(oldService);
  189. OBSDataAutoRelease settings = obs_data_create();
  190. if (!customServer && !whip) {
  191. obs_data_set_string(settings, "service",
  192. QT_TO_UTF8(ui->service->currentText()));
  193. obs_data_set_string(settings, "protocol", QT_TO_UTF8(protocol));
  194. if (ui->server->currentData() == CustomServerUUID()) {
  195. obs_data_set_bool(settings, "using_custom_server",
  196. true);
  197. obs_data_set_string(
  198. settings, "server",
  199. QT_TO_UTF8(ui->serviceCustomServer->text()));
  200. } else {
  201. obs_data_set_string(
  202. settings, "server",
  203. QT_TO_UTF8(
  204. ui->server->currentData().toString()));
  205. }
  206. } else {
  207. obs_data_set_string(
  208. settings, "server",
  209. QT_TO_UTF8(ui->customServer->text().trimmed()));
  210. obs_data_set_bool(settings, "use_auth",
  211. ui->useAuth->isChecked());
  212. if (ui->useAuth->isChecked()) {
  213. obs_data_set_string(
  214. settings, "username",
  215. QT_TO_UTF8(ui->authUsername->text()));
  216. obs_data_set_string(settings, "password",
  217. QT_TO_UTF8(ui->authPw->text()));
  218. }
  219. }
  220. if (!!auth && strcmp(auth->service(), "Twitch") == 0) {
  221. bool choiceExists = config_has_user_value(
  222. main->Config(), "Twitch", "AddonChoice");
  223. int currentChoice =
  224. config_get_int(main->Config(), "Twitch", "AddonChoice");
  225. int newChoice = ui->twitchAddonDropdown->currentIndex();
  226. config_set_int(main->Config(), "Twitch", "AddonChoice",
  227. newChoice);
  228. if (choiceExists && currentChoice != newChoice)
  229. forceAuthReload = true;
  230. obs_data_set_bool(settings, "bwtest",
  231. ui->bandwidthTestEnable->isChecked());
  232. } else {
  233. obs_data_set_bool(settings, "bwtest", false);
  234. }
  235. if (whip) {
  236. obs_data_set_string(settings, "service", "WHIP");
  237. obs_data_set_string(settings, "bearer_token",
  238. QT_TO_UTF8(ui->key->text()));
  239. } else {
  240. obs_data_set_string(settings, "key",
  241. QT_TO_UTF8(ui->key->text()));
  242. }
  243. OBSServiceAutoRelease newService = obs_service_create(
  244. service_id, "default_service", settings, hotkeyData);
  245. if (!newService)
  246. return;
  247. main->SetService(newService);
  248. main->SaveService();
  249. main->auth = auth;
  250. if (!!main->auth) {
  251. main->auth->LoadUI();
  252. main->SetBroadcastFlowEnabled(main->auth->broadcastFlow());
  253. } else {
  254. main->SetBroadcastFlowEnabled(false);
  255. }
  256. SaveCheckBox(ui->ignoreRecommended, "Stream1", "IgnoreRecommended");
  257. SwapMultiTrack(QT_TO_UTF8(protocol));
  258. }
  259. void OBSBasicSettings::UpdateMoreInfoLink()
  260. {
  261. if (IsCustomService() || IsWHIP()) {
  262. ui->moreInfoButton->hide();
  263. return;
  264. }
  265. QString serviceName = ui->service->currentText();
  266. obs_properties_t *props = obs_get_service_properties("rtmp_common");
  267. obs_property_t *services = obs_properties_get(props, "service");
  268. OBSDataAutoRelease settings = obs_data_create();
  269. obs_data_set_string(settings, "service", QT_TO_UTF8(serviceName));
  270. obs_property_modified(services, settings);
  271. const char *more_info_link =
  272. obs_data_get_string(settings, "more_info_link");
  273. if (!more_info_link || (*more_info_link == '\0')) {
  274. ui->moreInfoButton->hide();
  275. } else {
  276. ui->moreInfoButton->setTargetUrl(QUrl(more_info_link));
  277. ui->moreInfoButton->show();
  278. }
  279. obs_properties_destroy(props);
  280. }
  281. void OBSBasicSettings::UpdateKeyLink()
  282. {
  283. QString serviceName = ui->service->currentText();
  284. QString customServer = ui->customServer->text().trimmed();
  285. QString streamKeyLink;
  286. obs_properties_t *props = obs_get_service_properties("rtmp_common");
  287. obs_property_t *services = obs_properties_get(props, "service");
  288. OBSDataAutoRelease settings = obs_data_create();
  289. obs_data_set_string(settings, "service", QT_TO_UTF8(serviceName));
  290. obs_property_modified(services, settings);
  291. streamKeyLink = obs_data_get_string(settings, "stream_key_link");
  292. if (customServer.contains("fbcdn.net") && IsCustomService()) {
  293. streamKeyLink =
  294. "https://www.facebook.com/live/producer?ref=OBS";
  295. }
  296. if (serviceName == "Dacast") {
  297. ui->streamKeyLabel->setText(
  298. QTStr("Basic.AutoConfig.StreamPage.EncoderKey"));
  299. ui->streamKeyLabel->setToolTip("");
  300. } else if (IsWHIP()) {
  301. ui->streamKeyLabel->setText(
  302. QTStr("Basic.AutoConfig.StreamPage.BearerToken"));
  303. ui->streamKeyLabel->setToolTip("");
  304. } else if (!IsCustomService()) {
  305. ui->streamKeyLabel->setText(
  306. QTStr("Basic.AutoConfig.StreamPage.StreamKey"));
  307. ui->streamKeyLabel->setToolTip("");
  308. } else {
  309. /* add tooltips for stream key, user, password fields */
  310. QString file = !App()->IsThemeDark()
  311. ? ":/res/images/help.svg"
  312. : ":/res/images/help_light.svg";
  313. QString lStr = "<html>%1 <img src='%2' style=' \
  314. vertical-align: bottom; \
  315. ' /></html>";
  316. ui->streamKeyLabel->setText(lStr.arg(
  317. QTStr("Basic.AutoConfig.StreamPage.StreamKey"), file));
  318. ui->streamKeyLabel->setToolTip(
  319. QTStr("Basic.AutoConfig.StreamPage.StreamKey.ToolTip"));
  320. ui->authUsernameLabel->setText(lStr.arg(
  321. QTStr("Basic.Settings.Stream.Custom.Username"), file));
  322. ui->authUsernameLabel->setToolTip(
  323. QTStr("Basic.Settings.Stream.Custom.Username.ToolTip"));
  324. ui->authPwLabel->setText(lStr.arg(
  325. QTStr("Basic.Settings.Stream.Custom.Password"), file));
  326. ui->authPwLabel->setToolTip(
  327. QTStr("Basic.Settings.Stream.Custom.Password.ToolTip"));
  328. }
  329. if (QString(streamKeyLink).isNull() ||
  330. QString(streamKeyLink).isEmpty()) {
  331. ui->getStreamKeyButton->hide();
  332. } else {
  333. ui->getStreamKeyButton->setTargetUrl(QUrl(streamKeyLink));
  334. ui->getStreamKeyButton->show();
  335. }
  336. obs_properties_destroy(props);
  337. }
  338. void OBSBasicSettings::LoadServices(bool showAll)
  339. {
  340. obs_properties_t *props = obs_get_service_properties("rtmp_common");
  341. OBSDataAutoRelease settings = obs_data_create();
  342. obs_data_set_bool(settings, "show_all", showAll);
  343. obs_property_t *prop = obs_properties_get(props, "show_all");
  344. obs_property_modified(prop, settings);
  345. ui->service->blockSignals(true);
  346. ui->service->clear();
  347. QStringList names;
  348. obs_property_t *services = obs_properties_get(props, "service");
  349. size_t services_count = obs_property_list_item_count(services);
  350. for (size_t i = 0; i < services_count; i++) {
  351. const char *name = obs_property_list_item_string(services, i);
  352. names.push_back(name);
  353. }
  354. if (showAll)
  355. names.sort(Qt::CaseInsensitive);
  356. for (QString &name : names)
  357. ui->service->addItem(name);
  358. if (obs_is_output_protocol_registered("WHIP")) {
  359. ui->service->addItem(QTStr("WHIP"),
  360. QVariant((int)ListOpt::WHIP));
  361. }
  362. if (!showAll) {
  363. ui->service->addItem(
  364. QTStr("Basic.AutoConfig.StreamPage.Service.ShowAll"),
  365. QVariant((int)ListOpt::ShowAll));
  366. }
  367. ui->service->insertItem(
  368. 0, QTStr("Basic.AutoConfig.StreamPage.Service.Custom"),
  369. QVariant((int)ListOpt::Custom));
  370. if (!lastService.isEmpty()) {
  371. int idx = ui->service->findText(lastService);
  372. if (idx != -1)
  373. ui->service->setCurrentIndex(idx);
  374. }
  375. obs_properties_destroy(props);
  376. ui->service->blockSignals(false);
  377. }
  378. static inline bool is_auth_service(const std::string &service)
  379. {
  380. return Auth::AuthType(service) != Auth::Type::None;
  381. }
  382. static inline bool is_external_oauth(const std::string &service)
  383. {
  384. return Auth::External(service);
  385. }
  386. static void reset_service_ui_fields(Ui::OBSBasicSettings *ui,
  387. std::string &service, bool loading)
  388. {
  389. bool external_oauth = is_external_oauth(service);
  390. if (external_oauth) {
  391. ui->streamKeyWidget->setVisible(false);
  392. ui->streamKeyLabel->setVisible(false);
  393. ui->connectAccount2->setVisible(true);
  394. ui->useStreamKeyAdv->setVisible(true);
  395. ui->streamStackWidget->setCurrentIndex((int)Section::StreamKey);
  396. } else if (cef) {
  397. QString key = ui->key->text();
  398. bool can_auth = is_auth_service(service);
  399. int page = can_auth && (!loading || key.isEmpty())
  400. ? (int)Section::Connect
  401. : (int)Section::StreamKey;
  402. ui->streamStackWidget->setCurrentIndex(page);
  403. ui->streamKeyWidget->setVisible(true);
  404. ui->streamKeyLabel->setVisible(true);
  405. ui->connectAccount2->setVisible(can_auth);
  406. ui->useStreamKeyAdv->setVisible(false);
  407. } else {
  408. ui->connectAccount2->setVisible(false);
  409. ui->useStreamKeyAdv->setVisible(false);
  410. ui->streamStackWidget->setCurrentIndex((int)Section::StreamKey);
  411. }
  412. ui->connectedAccountLabel->setVisible(false);
  413. ui->connectedAccountText->setVisible(false);
  414. ui->disconnectAccount->setVisible(false);
  415. }
  416. #ifdef YOUTUBE_ENABLED
  417. static void get_yt_ch_title(Ui::OBSBasicSettings *ui)
  418. {
  419. const char *name = config_get_string(OBSBasic::Get()->Config(),
  420. "YouTube", "ChannelName");
  421. if (name) {
  422. ui->connectedAccountText->setText(name);
  423. } else {
  424. // if we still not changed the service page
  425. if (IsYouTubeService(QT_TO_UTF8(ui->service->currentText()))) {
  426. ui->connectedAccountText->setText(
  427. QTStr("Auth.LoadingChannel.Error"));
  428. }
  429. }
  430. }
  431. #endif
  432. void OBSBasicSettings::UseStreamKeyAdvClicked()
  433. {
  434. ui->streamKeyWidget->setVisible(true);
  435. ui->streamKeyLabel->setVisible(true);
  436. ui->useStreamKeyAdv->setVisible(false);
  437. }
  438. void OBSBasicSettings::on_service_currentIndexChanged(int idx)
  439. {
  440. if (ui->service->currentData().toInt() == (int)ListOpt::ShowAll) {
  441. LoadServices(true);
  442. ui->service->showPopup();
  443. return;
  444. }
  445. ServiceChanged();
  446. UpdateMoreInfoLink();
  447. UpdateServerList();
  448. UpdateKeyLink();
  449. UpdateServiceRecommendations();
  450. UpdateVodTrackSetting();
  451. protocol = FindProtocol();
  452. UpdateAdvNetworkGroup();
  453. if (ServiceSupportsCodecCheck() && UpdateResFPSLimits()) {
  454. lastServiceIdx = idx;
  455. if (idx == 0)
  456. lastCustomServer = ui->customServer->text();
  457. }
  458. if (!IsCustomService()) {
  459. ui->advStreamTrackWidget->setCurrentWidget(
  460. ui->streamSingleTracks);
  461. } else {
  462. SwapMultiTrack(QT_TO_UTF8(protocol));
  463. }
  464. }
  465. void OBSBasicSettings::on_customServer_textChanged(const QString &)
  466. {
  467. UpdateKeyLink();
  468. protocol = FindProtocol();
  469. UpdateAdvNetworkGroup();
  470. if (ServiceSupportsCodecCheck())
  471. lastCustomServer = ui->customServer->text();
  472. SwapMultiTrack(QT_TO_UTF8(protocol));
  473. }
  474. void OBSBasicSettings::ServiceChanged(bool resetFields)
  475. {
  476. std::string service = QT_TO_UTF8(ui->service->currentText());
  477. bool custom = IsCustomService();
  478. bool whip = IsWHIP();
  479. ui->disconnectAccount->setVisible(false);
  480. ui->bandwidthTestEnable->setVisible(false);
  481. ui->twitchAddonDropdown->setVisible(false);
  482. ui->twitchAddonLabel->setVisible(false);
  483. if (resetFields || lastService != service.c_str()) {
  484. reset_service_ui_fields(ui.get(), service, loading);
  485. }
  486. ui->useAuth->setVisible(custom);
  487. ui->authUsernameLabel->setVisible(custom);
  488. ui->authUsername->setVisible(custom);
  489. ui->authPwLabel->setVisible(custom);
  490. ui->authPwWidget->setVisible(custom);
  491. if (custom || whip) {
  492. ui->streamkeyPageLayout->insertRow(1, ui->serverLabel,
  493. ui->serverStackedWidget);
  494. ui->serverStackedWidget->setCurrentIndex(1);
  495. ui->serverStackedWidget->setVisible(true);
  496. ui->serverLabel->setVisible(true);
  497. on_useAuth_toggled();
  498. } else {
  499. ui->serverStackedWidget->setCurrentIndex(0);
  500. }
  501. auth.reset();
  502. if (!main->auth) {
  503. return;
  504. }
  505. auto system_auth_service = main->auth->service();
  506. bool service_check = service.find(system_auth_service) !=
  507. std::string::npos;
  508. #ifdef YOUTUBE_ENABLED
  509. service_check = service_check ? service_check
  510. : IsYouTubeService(system_auth_service) &&
  511. IsYouTubeService(service);
  512. #endif
  513. if (service_check) {
  514. auth = main->auth;
  515. OnAuthConnected();
  516. }
  517. }
  518. QString OBSBasicSettings::FindProtocol()
  519. {
  520. if (IsCustomService()) {
  521. if (ui->customServer->text().isEmpty())
  522. return QString("RTMP");
  523. QString server = ui->customServer->text();
  524. if (obs_is_output_protocol_registered("RTMPS") &&
  525. server.startsWith("rtmps://"))
  526. return QString("RTMPS");
  527. if (server.startsWith("ftl://"))
  528. return QString("FTL");
  529. if (server.startsWith("srt://"))
  530. return QString("SRT");
  531. if (server.startsWith("rist://"))
  532. return QString("RIST");
  533. } else {
  534. obs_properties_t *props =
  535. obs_get_service_properties("rtmp_common");
  536. obs_property_t *services = obs_properties_get(props, "service");
  537. OBSDataAutoRelease settings = obs_data_create();
  538. obs_data_set_string(settings, "service",
  539. QT_TO_UTF8(ui->service->currentText()));
  540. obs_property_modified(services, settings);
  541. obs_properties_destroy(props);
  542. const char *protocol =
  543. obs_data_get_string(settings, "protocol");
  544. if (protocol && *protocol)
  545. return QT_UTF8(protocol);
  546. }
  547. return QString("RTMP");
  548. }
  549. void OBSBasicSettings::UpdateServerList()
  550. {
  551. QString serviceName = ui->service->currentText();
  552. lastService = serviceName;
  553. obs_properties_t *props = obs_get_service_properties("rtmp_common");
  554. obs_property_t *services = obs_properties_get(props, "service");
  555. OBSDataAutoRelease settings = obs_data_create();
  556. obs_data_set_string(settings, "service", QT_TO_UTF8(serviceName));
  557. obs_property_modified(services, settings);
  558. obs_property_t *servers = obs_properties_get(props, "server");
  559. ui->server->clear();
  560. size_t servers_count = obs_property_list_item_count(servers);
  561. for (size_t i = 0; i < servers_count; i++) {
  562. const char *name = obs_property_list_item_name(servers, i);
  563. const char *server = obs_property_list_item_string(servers, i);
  564. ui->server->addItem(name, server);
  565. }
  566. if (serviceName == "Twitch") {
  567. ui->server->addItem(
  568. QTStr("Basic.Settings.Stream.SpecifyCustomServer"),
  569. CustomServerUUID());
  570. }
  571. obs_properties_destroy(props);
  572. }
  573. void OBSBasicSettings::on_show_clicked()
  574. {
  575. if (ui->key->echoMode() == QLineEdit::Password) {
  576. ui->key->setEchoMode(QLineEdit::Normal);
  577. ui->show->setText(QTStr("Hide"));
  578. } else {
  579. ui->key->setEchoMode(QLineEdit::Password);
  580. ui->show->setText(QTStr("Show"));
  581. }
  582. }
  583. void OBSBasicSettings::on_authPwShow_clicked()
  584. {
  585. if (ui->authPw->echoMode() == QLineEdit::Password) {
  586. ui->authPw->setEchoMode(QLineEdit::Normal);
  587. ui->authPwShow->setText(QTStr("Hide"));
  588. } else {
  589. ui->authPw->setEchoMode(QLineEdit::Password);
  590. ui->authPwShow->setText(QTStr("Show"));
  591. }
  592. }
  593. OBSService OBSBasicSettings::SpawnTempService()
  594. {
  595. bool custom = IsCustomService();
  596. bool whip = IsWHIP();
  597. const char *service_id = "rtmp_common";
  598. if (custom) {
  599. service_id = "rtmp_custom";
  600. } else if (whip) {
  601. service_id = "whip_custom";
  602. }
  603. OBSDataAutoRelease settings = obs_data_create();
  604. if (!custom && !whip) {
  605. obs_data_set_string(settings, "service",
  606. QT_TO_UTF8(ui->service->currentText()));
  607. obs_data_set_string(
  608. settings, "server",
  609. QT_TO_UTF8(ui->server->currentData().toString()));
  610. } else {
  611. obs_data_set_string(
  612. settings, "server",
  613. QT_TO_UTF8(ui->customServer->text().trimmed()));
  614. }
  615. if (whip)
  616. obs_data_set_string(settings, "bearer_token",
  617. QT_TO_UTF8(ui->key->text()));
  618. else
  619. obs_data_set_string(settings, "key",
  620. QT_TO_UTF8(ui->key->text()));
  621. OBSServiceAutoRelease newService = obs_service_create(
  622. service_id, "temp_service", settings, nullptr);
  623. return newService.Get();
  624. }
  625. void OBSBasicSettings::OnOAuthStreamKeyConnected()
  626. {
  627. OAuthStreamKey *a = reinterpret_cast<OAuthStreamKey *>(auth.get());
  628. if (a) {
  629. bool validKey = !a->key().empty();
  630. if (validKey)
  631. ui->key->setText(QT_UTF8(a->key().c_str()));
  632. ui->streamKeyWidget->setVisible(false);
  633. ui->streamKeyLabel->setVisible(false);
  634. ui->connectAccount2->setVisible(false);
  635. ui->disconnectAccount->setVisible(true);
  636. ui->useStreamKeyAdv->setVisible(false);
  637. ui->connectedAccountLabel->setVisible(false);
  638. ui->connectedAccountText->setVisible(false);
  639. if (strcmp(a->service(), "Twitch") == 0) {
  640. ui->bandwidthTestEnable->setVisible(true);
  641. ui->twitchAddonLabel->setVisible(true);
  642. ui->twitchAddonDropdown->setVisible(true);
  643. } else {
  644. ui->bandwidthTestEnable->setChecked(false);
  645. }
  646. #ifdef YOUTUBE_ENABLED
  647. if (IsYouTubeService(a->service())) {
  648. ui->key->clear();
  649. ui->connectedAccountLabel->setVisible(true);
  650. ui->connectedAccountText->setVisible(true);
  651. ui->connectedAccountText->setText(
  652. QTStr("Auth.LoadingChannel.Title"));
  653. get_yt_ch_title(ui.get());
  654. }
  655. #endif
  656. }
  657. ui->streamStackWidget->setCurrentIndex((int)Section::StreamKey);
  658. }
  659. void OBSBasicSettings::OnAuthConnected()
  660. {
  661. std::string service = QT_TO_UTF8(ui->service->currentText());
  662. Auth::Type type = Auth::AuthType(service);
  663. if (type == Auth::Type::OAuth_StreamKey ||
  664. type == Auth::Type::OAuth_LinkedAccount) {
  665. OnOAuthStreamKeyConnected();
  666. }
  667. if (!loading) {
  668. stream1Changed = true;
  669. EnableApplyButton(true);
  670. }
  671. }
  672. void OBSBasicSettings::on_connectAccount_clicked()
  673. {
  674. std::string service = QT_TO_UTF8(ui->service->currentText());
  675. OAuth::DeleteCookies(service);
  676. auth = OAuthStreamKey::Login(this, service);
  677. if (!!auth) {
  678. OnAuthConnected();
  679. #ifdef YOUTUBE_ENABLED
  680. if (cef_js_avail && IsYouTubeService(service)) {
  681. if (!main->GetYouTubeAppDock()) {
  682. main->NewYouTubeAppDock();
  683. }
  684. main->GetYouTubeAppDock()->AccountConnected();
  685. }
  686. #endif
  687. ui->useStreamKeyAdv->setVisible(false);
  688. }
  689. }
  690. #define DISCONNECT_COMFIRM_TITLE \
  691. "Basic.AutoConfig.StreamPage.DisconnectAccount.Confirm.Title"
  692. #define DISCONNECT_COMFIRM_TEXT \
  693. "Basic.AutoConfig.StreamPage.DisconnectAccount.Confirm.Text"
  694. void OBSBasicSettings::on_disconnectAccount_clicked()
  695. {
  696. QMessageBox::StandardButton button;
  697. button = OBSMessageBox::question(this, QTStr(DISCONNECT_COMFIRM_TITLE),
  698. QTStr(DISCONNECT_COMFIRM_TEXT));
  699. if (button == QMessageBox::No) {
  700. return;
  701. }
  702. main->auth.reset();
  703. auth.reset();
  704. main->SetBroadcastFlowEnabled(false);
  705. std::string service = QT_TO_UTF8(ui->service->currentText());
  706. #ifdef BROWSER_AVAILABLE
  707. OAuth::DeleteCookies(service);
  708. #endif
  709. ui->bandwidthTestEnable->setChecked(false);
  710. reset_service_ui_fields(ui.get(), service, loading);
  711. ui->bandwidthTestEnable->setVisible(false);
  712. ui->twitchAddonDropdown->setVisible(false);
  713. ui->twitchAddonLabel->setVisible(false);
  714. ui->key->setText("");
  715. ui->connectedAccountLabel->setVisible(false);
  716. ui->connectedAccountText->setVisible(false);
  717. #ifdef YOUTUBE_ENABLED
  718. if (cef_js_avail && IsYouTubeService(service)) {
  719. if (!main->GetYouTubeAppDock()) {
  720. main->NewYouTubeAppDock();
  721. }
  722. main->GetYouTubeAppDock()->AccountDisconnected();
  723. main->GetYouTubeAppDock()->Update();
  724. }
  725. #endif
  726. }
  727. void OBSBasicSettings::on_useStreamKey_clicked()
  728. {
  729. ui->streamStackWidget->setCurrentIndex((int)Section::StreamKey);
  730. }
  731. void OBSBasicSettings::on_useAuth_toggled()
  732. {
  733. if (!IsCustomService())
  734. return;
  735. bool use_auth = ui->useAuth->isChecked();
  736. ui->authUsernameLabel->setVisible(use_auth);
  737. ui->authUsername->setVisible(use_auth);
  738. ui->authPwLabel->setVisible(use_auth);
  739. ui->authPwWidget->setVisible(use_auth);
  740. }
  741. bool OBSBasicSettings::IsCustomServer()
  742. {
  743. return ui->server->currentData() == QVariant{CustomServerUUID()};
  744. }
  745. void OBSBasicSettings::on_server_currentIndexChanged(int /*index*/)
  746. {
  747. auto server_is_custom = IsCustomServer();
  748. ui->serviceCustomServerLabel->setVisible(server_is_custom);
  749. ui->serviceCustomServer->setVisible(server_is_custom);
  750. }
  751. void OBSBasicSettings::UpdateVodTrackSetting()
  752. {
  753. bool enableForCustomServer = config_get_bool(
  754. GetGlobalConfig(), "General", "EnableCustomServerVodTrack");
  755. bool enableVodTrack = ui->service->currentText() == "Twitch";
  756. bool wasEnabled = !!vodTrackCheckbox;
  757. if (enableForCustomServer && IsCustomService())
  758. enableVodTrack = true;
  759. if (enableVodTrack == wasEnabled)
  760. return;
  761. if (!enableVodTrack) {
  762. delete vodTrackCheckbox;
  763. delete vodTrackContainer;
  764. delete simpleVodTrack;
  765. return;
  766. }
  767. /* -------------------------------------- */
  768. /* simple output mode vod track widgets */
  769. bool simpleAdv = ui->simpleOutAdvanced->isChecked();
  770. bool vodTrackEnabled = config_get_bool(main->Config(), "SimpleOutput",
  771. "VodTrackEnabled");
  772. simpleVodTrack = new QCheckBox(this);
  773. simpleVodTrack->setText(
  774. QTStr("Basic.Settings.Output.Simple.TwitchVodTrack"));
  775. simpleVodTrack->setVisible(simpleAdv);
  776. simpleVodTrack->setChecked(vodTrackEnabled);
  777. int pos;
  778. ui->simpleStreamingLayout->getWidgetPosition(ui->simpleOutAdvanced,
  779. &pos, nullptr);
  780. ui->simpleStreamingLayout->insertRow(pos + 1, nullptr, simpleVodTrack);
  781. HookWidget(simpleVodTrack.data(), &QCheckBox::clicked,
  782. &OBSBasicSettings::OutputsChanged);
  783. connect(ui->simpleOutAdvanced, &QCheckBox::toggled,
  784. simpleVodTrack.data(), &QCheckBox::setVisible);
  785. /* -------------------------------------- */
  786. /* advanced output mode vod track widgets */
  787. vodTrackCheckbox = new QCheckBox(this);
  788. vodTrackCheckbox->setText(
  789. QTStr("Basic.Settings.Output.Adv.TwitchVodTrack"));
  790. vodTrackCheckbox->setLayoutDirection(Qt::RightToLeft);
  791. vodTrackContainer = new QWidget(this);
  792. QHBoxLayout *vodTrackLayout = new QHBoxLayout();
  793. for (int i = 0; i < MAX_AUDIO_MIXES; i++) {
  794. vodTrack[i] = new QRadioButton(QString::number(i + 1));
  795. vodTrackLayout->addWidget(vodTrack[i]);
  796. HookWidget(vodTrack[i].data(), &QRadioButton::clicked,
  797. &OBSBasicSettings::OutputsChanged);
  798. }
  799. HookWidget(vodTrackCheckbox.data(), &QCheckBox::clicked,
  800. &OBSBasicSettings::OutputsChanged);
  801. vodTrackLayout->addStretch();
  802. vodTrackLayout->setContentsMargins(0, 0, 0, 0);
  803. vodTrackContainer->setLayout(vodTrackLayout);
  804. ui->advOutTopLayout->insertRow(2, vodTrackCheckbox, vodTrackContainer);
  805. vodTrackEnabled =
  806. config_get_bool(main->Config(), "AdvOut", "VodTrackEnabled");
  807. vodTrackCheckbox->setChecked(vodTrackEnabled);
  808. vodTrackContainer->setEnabled(vodTrackEnabled);
  809. connect(vodTrackCheckbox, &QCheckBox::clicked, vodTrackContainer,
  810. &QWidget::setEnabled);
  811. int trackIndex =
  812. config_get_int(main->Config(), "AdvOut", "VodTrackIndex");
  813. for (int i = 0; i < MAX_AUDIO_MIXES; i++) {
  814. vodTrack[i]->setChecked((i + 1) == trackIndex);
  815. }
  816. }
  817. OBSService OBSBasicSettings::GetStream1Service()
  818. {
  819. return stream1Changed ? SpawnTempService()
  820. : OBSService(main->GetService());
  821. }
  822. void OBSBasicSettings::UpdateServiceRecommendations()
  823. {
  824. bool customServer = IsCustomService();
  825. ui->ignoreRecommended->setVisible(!customServer);
  826. ui->enforceSettingsLabel->setVisible(!customServer);
  827. OBSService service = GetStream1Service();
  828. int vbitrate, abitrate;
  829. BPtr<obs_service_resolution> res_list;
  830. size_t res_count;
  831. int fps;
  832. obs_service_get_max_bitrate(service, &vbitrate, &abitrate);
  833. obs_service_get_supported_resolutions(service, &res_list, &res_count);
  834. obs_service_get_max_fps(service, &fps);
  835. QString text;
  836. #define ENFORCE_TEXT(x) QTStr("Basic.Settings.Stream.Recommended." x)
  837. if (vbitrate)
  838. text += ENFORCE_TEXT("MaxVideoBitrate")
  839. .arg(QString::number(vbitrate));
  840. if (abitrate) {
  841. if (!text.isEmpty())
  842. text += "<br>";
  843. text += ENFORCE_TEXT("MaxAudioBitrate")
  844. .arg(QString::number(abitrate));
  845. }
  846. if (res_count) {
  847. if (!text.isEmpty())
  848. text += "<br>";
  849. obs_service_resolution best_res = {};
  850. int best_res_pixels = 0;
  851. for (size_t i = 0; i < res_count; i++) {
  852. obs_service_resolution res = res_list[i];
  853. int res_pixels = res.cx + res.cy;
  854. if (res_pixels > best_res_pixels) {
  855. best_res = res;
  856. best_res_pixels = res_pixels;
  857. }
  858. }
  859. QString res_str =
  860. QString("%1x%2").arg(QString::number(best_res.cx),
  861. QString::number(best_res.cy));
  862. text += ENFORCE_TEXT("MaxResolution").arg(res_str);
  863. }
  864. if (fps) {
  865. if (!text.isEmpty())
  866. text += "<br>";
  867. text += ENFORCE_TEXT("MaxFPS").arg(QString::number(fps));
  868. }
  869. #undef ENFORCE_TEXT
  870. #ifdef YOUTUBE_ENABLED
  871. if (IsYouTubeService(QT_TO_UTF8(ui->service->currentText()))) {
  872. if (!text.isEmpty())
  873. text += "<br><br>";
  874. text += "<a href=\"https://www.youtube.com/t/terms\">"
  875. "YouTube Terms of Service</a><br>"
  876. "<a href=\"http://www.google.com/policies/privacy\">"
  877. "Google Privacy Policy</a><br>"
  878. "<a href=\"https://security.google.com/settings/security/permissions\">"
  879. "Google Third-Party Permissions</a>";
  880. }
  881. #endif
  882. ui->enforceSettingsLabel->setText(text);
  883. }
  884. void OBSBasicSettings::DisplayEnforceWarning(bool checked)
  885. {
  886. if (IsCustomService())
  887. return;
  888. if (!checked) {
  889. SimpleRecordingEncoderChanged();
  890. return;
  891. }
  892. QMessageBox::StandardButton button;
  893. #define ENFORCE_WARNING(x) \
  894. QTStr("Basic.Settings.Stream.IgnoreRecommended.Warn." x)
  895. button = OBSMessageBox::question(this, ENFORCE_WARNING("Title"),
  896. ENFORCE_WARNING("Text"));
  897. #undef ENFORCE_WARNING
  898. if (button == QMessageBox::No) {
  899. QMetaObject::invokeMethod(ui->ignoreRecommended, "setChecked",
  900. Qt::QueuedConnection,
  901. Q_ARG(bool, false));
  902. return;
  903. }
  904. SimpleRecordingEncoderChanged();
  905. }
  906. bool OBSBasicSettings::ResFPSValid(obs_service_resolution *res_list,
  907. size_t res_count, int max_fps)
  908. {
  909. if (!res_count && !max_fps)
  910. return true;
  911. if (res_count) {
  912. QString res = ui->outputResolution->currentText();
  913. bool found_res = false;
  914. int cx, cy;
  915. if (sscanf(QT_TO_UTF8(res), "%dx%d", &cx, &cy) != 2)
  916. return false;
  917. for (size_t i = 0; i < res_count; i++) {
  918. if (res_list[i].cx == cx && res_list[i].cy == cy) {
  919. found_res = true;
  920. break;
  921. }
  922. }
  923. if (!found_res)
  924. return false;
  925. }
  926. if (max_fps) {
  927. int fpsType = ui->fpsType->currentIndex();
  928. if (fpsType != 0)
  929. return false;
  930. std::string fps_str = QT_TO_UTF8(ui->fpsCommon->currentText());
  931. float fps;
  932. sscanf(fps_str.c_str(), "%f", &fps);
  933. if (fps > (float)max_fps)
  934. return false;
  935. }
  936. return true;
  937. }
  938. extern void set_closest_res(int &cx, int &cy,
  939. struct obs_service_resolution *res_list,
  940. size_t count);
  941. /* Checks for and updates the resolution and FPS limits of a service, if any.
  942. *
  943. * If the service has a resolution and/or FPS limit, this will enforce those
  944. * limitations in the UI itself, preventing the user from selecting a
  945. * resolution or FPS that's not supported.
  946. *
  947. * This is an unpleasant thing to have to do to users, but there is no other
  948. * way to ensure that a service's restricted resolution/framerate values are
  949. * properly enforced, otherwise users will just be confused when things aren't
  950. * working correctly. The user can turn it off if they're partner (or if they
  951. * want to risk getting in trouble with their service) by selecting the "Ignore
  952. * recommended settings" option in the stream section of settings.
  953. *
  954. * This only affects services that have a resolution and/or framerate limit, of
  955. * which as of this writing, and hopefully for the foreseeable future, there is
  956. * only one.
  957. */
  958. bool OBSBasicSettings::UpdateResFPSLimits()
  959. {
  960. if (loading)
  961. return false;
  962. int idx = ui->service->currentIndex();
  963. if (idx == -1)
  964. return false;
  965. bool ignoreRecommended = ui->ignoreRecommended->isChecked();
  966. BPtr<obs_service_resolution> res_list;
  967. size_t res_count = 0;
  968. int max_fps = 0;
  969. if (!IsCustomService() && !ignoreRecommended) {
  970. OBSService service = GetStream1Service();
  971. obs_service_get_supported_resolutions(service, &res_list,
  972. &res_count);
  973. obs_service_get_max_fps(service, &max_fps);
  974. }
  975. /* ------------------------------------ */
  976. /* Check for enforced res/FPS */
  977. QString res = ui->outputResolution->currentText();
  978. QString fps_str;
  979. int cx = 0, cy = 0;
  980. double max_fpsd = (double)max_fps;
  981. int closest_fps_index = -1;
  982. double fpsd;
  983. sscanf(QT_TO_UTF8(res), "%dx%d", &cx, &cy);
  984. if (res_count)
  985. set_closest_res(cx, cy, res_list, res_count);
  986. if (max_fps) {
  987. int fpsType = ui->fpsType->currentIndex();
  988. if (fpsType == 1) { //Integer
  989. fpsd = (double)ui->fpsInteger->value();
  990. } else if (fpsType == 2) { //Fractional
  991. fpsd = (double)ui->fpsNumerator->value() /
  992. (double)ui->fpsDenominator->value();
  993. } else { //Common
  994. sscanf(QT_TO_UTF8(ui->fpsCommon->currentText()), "%lf",
  995. &fpsd);
  996. }
  997. double closest_diff = 1000000000000.0;
  998. for (int i = 0; i < ui->fpsCommon->count(); i++) {
  999. double com_fpsd;
  1000. sscanf(QT_TO_UTF8(ui->fpsCommon->itemText(i)), "%lf",
  1001. &com_fpsd);
  1002. if (com_fpsd > max_fpsd) {
  1003. continue;
  1004. }
  1005. double diff = fabs(com_fpsd - fpsd);
  1006. if (diff < closest_diff) {
  1007. closest_diff = diff;
  1008. closest_fps_index = i;
  1009. fps_str = ui->fpsCommon->itemText(i);
  1010. }
  1011. }
  1012. }
  1013. QString res_str =
  1014. QString("%1x%2").arg(QString::number(cx), QString::number(cy));
  1015. /* ------------------------------------ */
  1016. /* Display message box if res/FPS bad */
  1017. bool valid = ResFPSValid(res_list, res_count, max_fps);
  1018. if (!valid) {
  1019. /* if the user was already on facebook with an incompatible
  1020. * resolution, assume it's an upgrade */
  1021. if (lastServiceIdx == -1 && lastIgnoreRecommended == -1) {
  1022. ui->ignoreRecommended->setChecked(true);
  1023. ui->ignoreRecommended->setProperty("changed", true);
  1024. stream1Changed = true;
  1025. EnableApplyButton(true);
  1026. return UpdateResFPSLimits();
  1027. }
  1028. QMessageBox::StandardButton button;
  1029. #define WARNING_VAL(x) \
  1030. QTStr("Basic.Settings.Output.Warn.EnforceResolutionFPS." x)
  1031. QString str;
  1032. if (res_count)
  1033. str += WARNING_VAL("Resolution").arg(res_str);
  1034. if (max_fps) {
  1035. if (!str.isEmpty())
  1036. str += "\n";
  1037. str += WARNING_VAL("FPS").arg(fps_str);
  1038. }
  1039. button = OBSMessageBox::question(this, WARNING_VAL("Title"),
  1040. WARNING_VAL("Msg").arg(str));
  1041. #undef WARNING_VAL
  1042. if (button == QMessageBox::No) {
  1043. if (idx != lastServiceIdx)
  1044. QMetaObject::invokeMethod(
  1045. ui->service, "setCurrentIndex",
  1046. Qt::QueuedConnection,
  1047. Q_ARG(int, lastServiceIdx));
  1048. else
  1049. QMetaObject::invokeMethod(ui->ignoreRecommended,
  1050. "setChecked",
  1051. Qt::QueuedConnection,
  1052. Q_ARG(bool, true));
  1053. return false;
  1054. }
  1055. }
  1056. /* ------------------------------------ */
  1057. /* Update widgets/values if switching */
  1058. /* to/from enforced resolution/FPS */
  1059. ui->outputResolution->blockSignals(true);
  1060. if (res_count) {
  1061. ui->outputResolution->clear();
  1062. ui->outputResolution->setEditable(false);
  1063. HookWidget(ui->outputResolution,
  1064. &QComboBox::currentIndexChanged,
  1065. &OBSBasicSettings::VideoChangedResolution);
  1066. int new_res_index = -1;
  1067. for (size_t i = 0; i < res_count; i++) {
  1068. obs_service_resolution val = res_list[i];
  1069. QString str =
  1070. QString("%1x%2").arg(QString::number(val.cx),
  1071. QString::number(val.cy));
  1072. ui->outputResolution->addItem(str);
  1073. if (val.cx == cx && val.cy == cy)
  1074. new_res_index = (int)i;
  1075. }
  1076. ui->outputResolution->setCurrentIndex(new_res_index);
  1077. if (!valid) {
  1078. ui->outputResolution->setProperty("changed", true);
  1079. videoChanged = true;
  1080. EnableApplyButton(true);
  1081. }
  1082. } else {
  1083. QString baseRes = ui->baseResolution->currentText();
  1084. int baseCX, baseCY;
  1085. sscanf(QT_TO_UTF8(baseRes), "%dx%d", &baseCX, &baseCY);
  1086. if (!ui->outputResolution->isEditable()) {
  1087. RecreateOutputResolutionWidget();
  1088. ui->outputResolution->blockSignals(true);
  1089. ResetDownscales((uint32_t)baseCX, (uint32_t)baseCY,
  1090. true);
  1091. ui->outputResolution->setCurrentText(res);
  1092. }
  1093. }
  1094. ui->outputResolution->blockSignals(false);
  1095. if (max_fps) {
  1096. for (int i = 0; i < ui->fpsCommon->count(); i++) {
  1097. double com_fpsd;
  1098. sscanf(QT_TO_UTF8(ui->fpsCommon->itemText(i)), "%lf",
  1099. &com_fpsd);
  1100. if (com_fpsd > max_fpsd) {
  1101. SetComboItemEnabled(ui->fpsCommon, i, false);
  1102. continue;
  1103. }
  1104. }
  1105. ui->fpsType->setCurrentIndex(0);
  1106. ui->fpsCommon->setCurrentIndex(closest_fps_index);
  1107. if (!valid) {
  1108. ui->fpsType->setProperty("changed", true);
  1109. ui->fpsCommon->setProperty("changed", true);
  1110. videoChanged = true;
  1111. EnableApplyButton(true);
  1112. }
  1113. } else {
  1114. for (int i = 0; i < ui->fpsCommon->count(); i++)
  1115. SetComboItemEnabled(ui->fpsCommon, i, true);
  1116. }
  1117. SetComboItemEnabled(ui->fpsType, 1, !max_fps);
  1118. SetComboItemEnabled(ui->fpsType, 2, !max_fps);
  1119. /* ------------------------------------ */
  1120. lastIgnoreRecommended = (int)ignoreRecommended;
  1121. return true;
  1122. }
  1123. static bool service_supports_codec(const char **codecs, const char *codec)
  1124. {
  1125. if (!codecs)
  1126. return true;
  1127. while (*codecs) {
  1128. if (strcmp(*codecs, codec) == 0)
  1129. return true;
  1130. codecs++;
  1131. }
  1132. return false;
  1133. }
  1134. extern bool EncoderAvailable(const char *encoder);
  1135. extern const char *get_simple_output_encoder(const char *name);
  1136. static inline bool service_supports_encoder(const char **codecs,
  1137. const char *encoder)
  1138. {
  1139. if (!EncoderAvailable(encoder))
  1140. return false;
  1141. const char *codec = obs_get_encoder_codec(encoder);
  1142. return service_supports_codec(codecs, codec);
  1143. }
  1144. static bool return_first_id(void *data, const char *id)
  1145. {
  1146. const char **output = (const char **)data;
  1147. *output = id;
  1148. return false;
  1149. }
  1150. bool OBSBasicSettings::ServiceAndVCodecCompatible()
  1151. {
  1152. bool simple = (ui->outputMode->currentIndex() == 0);
  1153. bool ret;
  1154. const char *codec;
  1155. if (simple) {
  1156. QString encoder =
  1157. ui->simpleOutStrEncoder->currentData().toString();
  1158. const char *id = get_simple_output_encoder(QT_TO_UTF8(encoder));
  1159. codec = obs_get_encoder_codec(id);
  1160. } else {
  1161. QString encoder = ui->advOutEncoder->currentData().toString();
  1162. codec = obs_get_encoder_codec(QT_TO_UTF8(encoder));
  1163. }
  1164. OBSService service = SpawnTempService();
  1165. const char **codecs = obs_service_get_supported_video_codecs(service);
  1166. if (!codecs || IsCustomService()) {
  1167. const char *output;
  1168. char **output_codecs;
  1169. obs_enum_output_types_with_protocol(QT_TO_UTF8(protocol),
  1170. &output, return_first_id);
  1171. output_codecs = strlist_split(
  1172. obs_get_output_supported_video_codecs(output), ';',
  1173. false);
  1174. ret = service_supports_codec((const char **)output_codecs,
  1175. codec);
  1176. strlist_free(output_codecs);
  1177. } else {
  1178. ret = service_supports_codec(codecs, codec);
  1179. }
  1180. return ret;
  1181. }
  1182. bool OBSBasicSettings::ServiceAndACodecCompatible()
  1183. {
  1184. bool simple = (ui->outputMode->currentIndex() == 0);
  1185. bool ret;
  1186. QString codec;
  1187. if (simple) {
  1188. codec = ui->simpleOutStrAEncoder->currentData().toString();
  1189. } else {
  1190. QString encoder = ui->advOutAEncoder->currentData().toString();
  1191. codec = obs_get_encoder_codec(QT_TO_UTF8(encoder));
  1192. }
  1193. OBSService service = SpawnTempService();
  1194. const char **codecs = obs_service_get_supported_audio_codecs(service);
  1195. if (!codecs || IsCustomService()) {
  1196. const char *output;
  1197. char **output_codecs;
  1198. obs_enum_output_types_with_protocol(QT_TO_UTF8(protocol),
  1199. &output, return_first_id);
  1200. output_codecs = strlist_split(
  1201. obs_get_output_supported_audio_codecs(output), ';',
  1202. false);
  1203. ret = service_supports_codec((const char **)output_codecs,
  1204. QT_TO_UTF8(codec));
  1205. strlist_free(output_codecs);
  1206. } else {
  1207. ret = service_supports_codec(codecs, QT_TO_UTF8(codec));
  1208. }
  1209. return ret;
  1210. }
  1211. /* we really need a way to find fallbacks in a less hardcoded way. maybe. */
  1212. static QString get_adv_fallback(const QString &enc)
  1213. {
  1214. if (enc == "jim_hevc_nvenc" || enc == "jim_av1_nvenc")
  1215. return "jim_nvenc";
  1216. if (enc == "h265_texture_amf" || enc == "av1_texture_amf")
  1217. return "h264_texture_amf";
  1218. if (enc == "com.apple.videotoolbox.videoencoder.ave.hevc")
  1219. return "com.apple.videotoolbox.videoencoder.ave.avc";
  1220. if (enc == "obs_qsv11_av1")
  1221. return "obs_qsv11";
  1222. return "obs_x264";
  1223. }
  1224. static QString get_adv_audio_fallback(const QString &enc)
  1225. {
  1226. const char *codec = obs_get_encoder_codec(QT_TO_UTF8(enc));
  1227. if (codec && strcmp(codec, "aac") == 0)
  1228. return "ffmpeg_opus";
  1229. QString aac_default = "ffmpeg_aac";
  1230. if (EncoderAvailable("CoreAudio_AAC"))
  1231. aac_default = "CoreAudio_AAC";
  1232. else if (EncoderAvailable("libfdk_aac"))
  1233. aac_default = "libfdk_aac";
  1234. return aac_default;
  1235. }
  1236. static QString get_simple_fallback(const QString &enc)
  1237. {
  1238. if (enc == SIMPLE_ENCODER_NVENC_HEVC || enc == SIMPLE_ENCODER_NVENC_AV1)
  1239. return SIMPLE_ENCODER_NVENC;
  1240. if (enc == SIMPLE_ENCODER_AMD_HEVC || enc == SIMPLE_ENCODER_AMD_AV1)
  1241. return SIMPLE_ENCODER_AMD;
  1242. if (enc == SIMPLE_ENCODER_APPLE_HEVC)
  1243. return SIMPLE_ENCODER_APPLE_H264;
  1244. if (enc == SIMPLE_ENCODER_QSV_AV1)
  1245. return SIMPLE_ENCODER_QSV;
  1246. return SIMPLE_ENCODER_X264;
  1247. }
  1248. bool OBSBasicSettings::ServiceSupportsCodecCheck()
  1249. {
  1250. if (loading)
  1251. return false;
  1252. bool vcodec_compat = ServiceAndVCodecCompatible();
  1253. bool acodec_compat = ServiceAndACodecCompatible();
  1254. if (vcodec_compat && acodec_compat) {
  1255. if (lastServiceIdx != ui->service->currentIndex() ||
  1256. IsCustomService())
  1257. ResetEncoders(true);
  1258. return true;
  1259. }
  1260. QString service = ui->service->currentText();
  1261. QString cur_video_name;
  1262. QString fb_video_name;
  1263. QString cur_audio_name;
  1264. QString fb_audio_name;
  1265. bool simple = (ui->outputMode->currentIndex() == 0);
  1266. /* ------------------------------------------------- */
  1267. /* get current codec */
  1268. if (simple) {
  1269. QString cur_enc =
  1270. ui->simpleOutStrEncoder->currentData().toString();
  1271. QString fb_enc = get_simple_fallback(cur_enc);
  1272. int cur_idx = ui->simpleOutStrEncoder->findData(cur_enc);
  1273. int fb_idx = ui->simpleOutStrEncoder->findData(fb_enc);
  1274. cur_video_name = ui->simpleOutStrEncoder->itemText(cur_idx);
  1275. fb_video_name = ui->simpleOutStrEncoder->itemText(fb_idx);
  1276. cur_enc = ui->simpleOutStrAEncoder->currentData().toString();
  1277. fb_enc = (cur_enc == "opus") ? "aac" : "opus";
  1278. cur_audio_name = ui->simpleOutStrAEncoder->itemText(
  1279. ui->simpleOutStrAEncoder->findData(cur_enc));
  1280. fb_audio_name =
  1281. (cur_enc == "opus")
  1282. ? QTStr("Basic.Settings.Output.Simple.Codec.AAC")
  1283. : QTStr("Basic.Settings.Output.Simple.Codec.Opus");
  1284. } else {
  1285. QString cur_enc = ui->advOutEncoder->currentData().toString();
  1286. QString fb_enc = get_adv_fallback(cur_enc);
  1287. cur_video_name =
  1288. obs_encoder_get_display_name(QT_TO_UTF8(cur_enc));
  1289. fb_video_name =
  1290. obs_encoder_get_display_name(QT_TO_UTF8(fb_enc));
  1291. cur_enc = ui->advOutAEncoder->currentData().toString();
  1292. fb_enc = get_adv_audio_fallback(cur_enc);
  1293. cur_audio_name =
  1294. obs_encoder_get_display_name(QT_TO_UTF8(cur_enc));
  1295. fb_audio_name =
  1296. obs_encoder_get_display_name(QT_TO_UTF8(fb_enc));
  1297. }
  1298. #define WARNING_VAL(x) \
  1299. QTStr("Basic.Settings.Output.Warn.ServiceCodecCompatibility." x)
  1300. QString msg = WARNING_VAL("Msg").arg(
  1301. service, vcodec_compat ? cur_audio_name : cur_video_name,
  1302. vcodec_compat ? fb_audio_name : fb_video_name);
  1303. if (!vcodec_compat && !acodec_compat)
  1304. msg = WARNING_VAL("Msg2").arg(service, cur_video_name,
  1305. cur_audio_name, fb_video_name,
  1306. fb_audio_name);
  1307. auto button = OBSMessageBox::question(this, WARNING_VAL("Title"), msg);
  1308. #undef WARNING_VAL
  1309. if (button == QMessageBox::No) {
  1310. if (lastServiceIdx == 0 &&
  1311. lastServiceIdx == ui->service->currentIndex())
  1312. QMetaObject::invokeMethod(ui->customServer, "setText",
  1313. Qt::QueuedConnection,
  1314. Q_ARG(QString,
  1315. lastCustomServer));
  1316. else
  1317. QMetaObject::invokeMethod(ui->service,
  1318. "setCurrentIndex",
  1319. Qt::QueuedConnection,
  1320. Q_ARG(int, lastServiceIdx));
  1321. return false;
  1322. }
  1323. ResetEncoders(true);
  1324. return true;
  1325. }
  1326. #define TEXT_USE_STREAM_ENC \
  1327. QTStr("Basic.Settings.Output.Adv.Recording.UseStreamEncoder")
  1328. void OBSBasicSettings::ResetEncoders(bool streamOnly)
  1329. {
  1330. QString lastAdvVideoEnc = ui->advOutEncoder->currentData().toString();
  1331. QString lastVideoEnc =
  1332. ui->simpleOutStrEncoder->currentData().toString();
  1333. QString lastAdvAudioEnc = ui->advOutAEncoder->currentData().toString();
  1334. QString lastAudioEnc =
  1335. ui->simpleOutStrAEncoder->currentData().toString();
  1336. OBSService service = SpawnTempService();
  1337. const char **vcodecs = obs_service_get_supported_video_codecs(service);
  1338. const char **acodecs = obs_service_get_supported_audio_codecs(service);
  1339. const char *type;
  1340. BPtr<char *> output_vcodecs;
  1341. BPtr<char *> output_acodecs;
  1342. size_t idx = 0;
  1343. if (!vcodecs || IsCustomService()) {
  1344. const char *output;
  1345. obs_enum_output_types_with_protocol(QT_TO_UTF8(protocol),
  1346. &output, return_first_id);
  1347. output_vcodecs = strlist_split(
  1348. obs_get_output_supported_video_codecs(output), ';',
  1349. false);
  1350. vcodecs = (const char **)output_vcodecs.Get();
  1351. }
  1352. if (!acodecs || IsCustomService()) {
  1353. const char *output;
  1354. obs_enum_output_types_with_protocol(QT_TO_UTF8(protocol),
  1355. &output, return_first_id);
  1356. output_acodecs = strlist_split(
  1357. obs_get_output_supported_audio_codecs(output), ';',
  1358. false);
  1359. acodecs = (const char **)output_acodecs.Get();
  1360. }
  1361. QSignalBlocker s1(ui->simpleOutStrEncoder);
  1362. QSignalBlocker s2(ui->advOutEncoder);
  1363. QSignalBlocker s3(ui->simpleOutStrAEncoder);
  1364. QSignalBlocker s4(ui->advOutAEncoder);
  1365. /* ------------------------------------------------- */
  1366. /* clear encoder lists */
  1367. ui->simpleOutStrEncoder->clear();
  1368. ui->advOutEncoder->clear();
  1369. ui->simpleOutStrAEncoder->clear();
  1370. ui->advOutAEncoder->clear();
  1371. if (!streamOnly) {
  1372. ui->advOutRecEncoder->clear();
  1373. ui->advOutRecAEncoder->clear();
  1374. }
  1375. /* ------------------------------------------------- */
  1376. /* load advanced stream/recording encoders */
  1377. while (obs_enum_encoder_types(idx++, &type)) {
  1378. const char *name = obs_encoder_get_display_name(type);
  1379. const char *codec = obs_get_encoder_codec(type);
  1380. uint32_t caps = obs_get_encoder_caps(type);
  1381. QString qName = QT_UTF8(name);
  1382. QString qType = QT_UTF8(type);
  1383. if (obs_get_encoder_type(type) == OBS_ENCODER_VIDEO) {
  1384. if ((caps & ENCODER_HIDE_FLAGS) != 0)
  1385. continue;
  1386. if (service_supports_codec(vcodecs, codec))
  1387. ui->advOutEncoder->addItem(qName, qType);
  1388. if (!streamOnly)
  1389. ui->advOutRecEncoder->addItem(qName, qType);
  1390. }
  1391. if (obs_get_encoder_type(type) == OBS_ENCODER_AUDIO) {
  1392. if (service_supports_codec(acodecs, codec))
  1393. ui->advOutAEncoder->addItem(qName, qType);
  1394. if (!streamOnly)
  1395. ui->advOutRecAEncoder->addItem(qName, qType);
  1396. }
  1397. }
  1398. ui->advOutEncoder->model()->sort(0);
  1399. ui->advOutAEncoder->model()->sort(0);
  1400. if (!streamOnly) {
  1401. ui->advOutRecEncoder->model()->sort(0);
  1402. ui->advOutRecEncoder->insertItem(0, TEXT_USE_STREAM_ENC,
  1403. "none");
  1404. ui->advOutRecAEncoder->model()->sort(0);
  1405. ui->advOutRecAEncoder->insertItem(0, TEXT_USE_STREAM_ENC,
  1406. "none");
  1407. }
  1408. /* ------------------------------------------------- */
  1409. /* load simple stream encoders */
  1410. #define ENCODER_STR(str) QTStr("Basic.Settings.Output.Simple.Encoder." str)
  1411. ui->simpleOutStrEncoder->addItem(ENCODER_STR("Software"),
  1412. QString(SIMPLE_ENCODER_X264));
  1413. #ifdef _WIN32
  1414. if (service_supports_encoder(vcodecs, "obs_qsv11"))
  1415. ui->simpleOutStrEncoder->addItem(
  1416. ENCODER_STR("Hardware.QSV.H264"),
  1417. QString(SIMPLE_ENCODER_QSV));
  1418. if (service_supports_encoder(vcodecs, "obs_qsv11_av1"))
  1419. ui->simpleOutStrEncoder->addItem(
  1420. ENCODER_STR("Hardware.QSV.AV1"),
  1421. QString(SIMPLE_ENCODER_QSV_AV1));
  1422. #endif
  1423. if (service_supports_encoder(vcodecs, "ffmpeg_nvenc"))
  1424. ui->simpleOutStrEncoder->addItem(
  1425. ENCODER_STR("Hardware.NVENC.H264"),
  1426. QString(SIMPLE_ENCODER_NVENC));
  1427. if (service_supports_encoder(vcodecs, "jim_av1_nvenc"))
  1428. ui->simpleOutStrEncoder->addItem(
  1429. ENCODER_STR("Hardware.NVENC.AV1"),
  1430. QString(SIMPLE_ENCODER_NVENC_AV1));
  1431. #ifdef ENABLE_HEVC
  1432. if (service_supports_encoder(vcodecs, "h265_texture_amf"))
  1433. ui->simpleOutStrEncoder->addItem(
  1434. ENCODER_STR("Hardware.AMD.HEVC"),
  1435. QString(SIMPLE_ENCODER_AMD_HEVC));
  1436. if (service_supports_encoder(vcodecs, "ffmpeg_hevc_nvenc"))
  1437. ui->simpleOutStrEncoder->addItem(
  1438. ENCODER_STR("Hardware.NVENC.HEVC"),
  1439. QString(SIMPLE_ENCODER_NVENC_HEVC));
  1440. #endif
  1441. if (service_supports_encoder(vcodecs, "h264_texture_amf"))
  1442. ui->simpleOutStrEncoder->addItem(
  1443. ENCODER_STR("Hardware.AMD.H264"),
  1444. QString(SIMPLE_ENCODER_AMD));
  1445. if (service_supports_encoder(vcodecs, "av1_texture_amf"))
  1446. ui->simpleOutStrEncoder->addItem(
  1447. ENCODER_STR("Hardware.AMD.AV1"),
  1448. QString(SIMPLE_ENCODER_AMD_AV1));
  1449. /* Preprocessor guard required for the macOS version check */
  1450. #ifdef __APPLE__
  1451. if (service_supports_encoder(
  1452. vcodecs, "com.apple.videotoolbox.videoencoder.ave.avc")
  1453. #ifndef __aarch64__
  1454. && os_get_emulation_status() == true
  1455. #endif
  1456. ) {
  1457. if (__builtin_available(macOS 13.0, *)) {
  1458. ui->simpleOutStrEncoder->addItem(
  1459. ENCODER_STR("Hardware.Apple.H264"),
  1460. QString(SIMPLE_ENCODER_APPLE_H264));
  1461. }
  1462. }
  1463. #ifdef ENABLE_HEVC
  1464. if (service_supports_encoder(
  1465. vcodecs, "com.apple.videotoolbox.videoencoder.ave.hevc")
  1466. #ifndef __aarch64__
  1467. && os_get_emulation_status() == true
  1468. #endif
  1469. ) {
  1470. if (__builtin_available(macOS 13.0, *)) {
  1471. ui->simpleOutStrEncoder->addItem(
  1472. ENCODER_STR("Hardware.Apple.HEVC"),
  1473. QString(SIMPLE_ENCODER_APPLE_HEVC));
  1474. }
  1475. }
  1476. #endif
  1477. #endif
  1478. if (service_supports_encoder(acodecs, "CoreAudio_AAC") ||
  1479. service_supports_encoder(acodecs, "libfdk_aac") ||
  1480. service_supports_encoder(acodecs, "ffmpeg_aac"))
  1481. ui->simpleOutStrAEncoder->addItem(
  1482. QTStr("Basic.Settings.Output.Simple.Codec.AAC.Default"),
  1483. "aac");
  1484. if (service_supports_encoder(acodecs, "ffmpeg_opus"))
  1485. ui->simpleOutStrAEncoder->addItem(
  1486. QTStr("Basic.Settings.Output.Simple.Codec.Opus"),
  1487. "opus");
  1488. #undef ENCODER_STR
  1489. /* ------------------------------------------------- */
  1490. /* Find fallback encoders */
  1491. if (!lastAdvVideoEnc.isEmpty()) {
  1492. int idx = ui->advOutEncoder->findData(lastAdvVideoEnc);
  1493. if (idx == -1) {
  1494. lastAdvVideoEnc = get_adv_fallback(lastAdvVideoEnc);
  1495. ui->advOutEncoder->setProperty("changed",
  1496. QVariant(true));
  1497. OutputsChanged();
  1498. }
  1499. idx = ui->advOutEncoder->findData(lastAdvVideoEnc);
  1500. s2.unblock();
  1501. ui->advOutEncoder->setCurrentIndex(idx);
  1502. }
  1503. if (!lastAdvAudioEnc.isEmpty()) {
  1504. int idx = ui->advOutAEncoder->findData(lastAdvAudioEnc);
  1505. if (idx == -1) {
  1506. lastAdvAudioEnc =
  1507. get_adv_audio_fallback(lastAdvAudioEnc);
  1508. ui->advOutAEncoder->setProperty("changed",
  1509. QVariant(true));
  1510. OutputsChanged();
  1511. }
  1512. idx = ui->advOutAEncoder->findData(lastAdvAudioEnc);
  1513. s4.unblock();
  1514. ui->advOutAEncoder->setCurrentIndex(idx);
  1515. }
  1516. if (!lastVideoEnc.isEmpty()) {
  1517. int idx = ui->simpleOutStrEncoder->findData(lastVideoEnc);
  1518. if (idx == -1) {
  1519. lastVideoEnc = get_simple_fallback(lastVideoEnc);
  1520. ui->simpleOutStrEncoder->setProperty("changed",
  1521. QVariant(true));
  1522. OutputsChanged();
  1523. }
  1524. idx = ui->simpleOutStrEncoder->findData(lastVideoEnc);
  1525. s1.unblock();
  1526. ui->simpleOutStrEncoder->setCurrentIndex(idx);
  1527. }
  1528. if (!lastAudioEnc.isEmpty()) {
  1529. int idx = ui->simpleOutStrAEncoder->findData(lastAudioEnc);
  1530. if (idx == -1) {
  1531. lastAudioEnc = (lastAudioEnc == "opus") ? "aac"
  1532. : "opus";
  1533. ui->simpleOutStrAEncoder->setProperty("changed",
  1534. QVariant(true));
  1535. OutputsChanged();
  1536. }
  1537. idx = ui->simpleOutStrAEncoder->findData(lastAudioEnc);
  1538. s3.unblock();
  1539. ui->simpleOutStrAEncoder->setCurrentIndex(idx);
  1540. }
  1541. }