window-basic-settings-stream.cpp 50 KB

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