window-basic-settings-stream.cpp 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447
  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. #if 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. };
  25. enum class Section : int {
  26. Connect,
  27. StreamKey,
  28. };
  29. inline bool OBSBasicSettings::IsCustomService() const
  30. {
  31. return ui->service->currentData().toInt() == (int)ListOpt::Custom;
  32. }
  33. void OBSBasicSettings::InitStreamPage()
  34. {
  35. ui->connectAccount2->setVisible(false);
  36. ui->disconnectAccount->setVisible(false);
  37. ui->bandwidthTestEnable->setVisible(false);
  38. ui->twitchAddonDropdown->setVisible(false);
  39. ui->twitchAddonLabel->setVisible(false);
  40. ui->connectedAccountLabel->setVisible(false);
  41. ui->connectedAccountText->setVisible(false);
  42. int vertSpacing = ui->topStreamLayout->verticalSpacing();
  43. QMargins m = ui->topStreamLayout->contentsMargins();
  44. m.setBottom(vertSpacing / 2);
  45. ui->topStreamLayout->setContentsMargins(m);
  46. m = ui->loginPageLayout->contentsMargins();
  47. m.setTop(vertSpacing / 2);
  48. ui->loginPageLayout->setContentsMargins(m);
  49. m = ui->streamkeyPageLayout->contentsMargins();
  50. m.setTop(vertSpacing / 2);
  51. ui->streamkeyPageLayout->setContentsMargins(m);
  52. LoadServices(false);
  53. ui->twitchAddonDropdown->addItem(
  54. QTStr("Basic.Settings.Stream.TTVAddon.None"));
  55. ui->twitchAddonDropdown->addItem(
  56. QTStr("Basic.Settings.Stream.TTVAddon.BTTV"));
  57. ui->twitchAddonDropdown->addItem(
  58. QTStr("Basic.Settings.Stream.TTVAddon.FFZ"));
  59. ui->twitchAddonDropdown->addItem(
  60. QTStr("Basic.Settings.Stream.TTVAddon.Both"));
  61. connect(ui->service, SIGNAL(currentIndexChanged(int)), this,
  62. SLOT(UpdateServerList()));
  63. connect(ui->service, SIGNAL(currentIndexChanged(int)), this,
  64. SLOT(UpdateKeyLink()));
  65. connect(ui->service, SIGNAL(currentIndexChanged(int)), this,
  66. SLOT(UpdateVodTrackSetting()));
  67. connect(ui->service, SIGNAL(currentIndexChanged(int)), this,
  68. SLOT(UpdateServiceRecommendations()));
  69. connect(ui->service, SIGNAL(currentIndexChanged(int)), this,
  70. SLOT(UpdateResFPSLimits()));
  71. connect(ui->customServer, SIGNAL(textChanged(const QString &)), this,
  72. SLOT(UpdateKeyLink()));
  73. connect(ui->ignoreRecommended, SIGNAL(clicked(bool)), this,
  74. SLOT(DisplayEnforceWarning(bool)));
  75. connect(ui->ignoreRecommended, SIGNAL(toggled(bool)), this,
  76. SLOT(UpdateResFPSLimits()));
  77. connect(ui->service, SIGNAL(currentIndexChanged(int)), this,
  78. SLOT(UpdateMoreInfoLink()));
  79. connect(ui->service, SIGNAL(currentIndexChanged(int)), this,
  80. SLOT(UpdateAdvNetworkGroup()));
  81. connect(ui->customServer, SIGNAL(textChanged(const QString &)), this,
  82. SLOT(UpdateAdvNetworkGroup()));
  83. }
  84. void OBSBasicSettings::LoadStream1Settings()
  85. {
  86. bool ignoreRecommended =
  87. config_get_bool(main->Config(), "Stream1", "IgnoreRecommended");
  88. obs_service_t *service_obj = main->GetService();
  89. const char *type = obs_service_get_type(service_obj);
  90. loading = true;
  91. OBSDataAutoRelease settings = obs_service_get_settings(service_obj);
  92. const char *service = obs_data_get_string(settings, "service");
  93. const char *server = obs_data_get_string(settings, "server");
  94. const char *key = obs_data_get_string(settings, "key");
  95. if (strcmp(type, "rtmp_custom") == 0) {
  96. ui->service->setCurrentIndex(0);
  97. ui->customServer->setText(server);
  98. lastServiceIdx = 0;
  99. bool use_auth = obs_data_get_bool(settings, "use_auth");
  100. const char *username =
  101. obs_data_get_string(settings, "username");
  102. const char *password =
  103. obs_data_get_string(settings, "password");
  104. ui->authUsername->setText(QT_UTF8(username));
  105. ui->authPw->setText(QT_UTF8(password));
  106. ui->useAuth->setChecked(use_auth);
  107. } else {
  108. int idx = ui->service->findText(service);
  109. if (idx == -1) {
  110. if (service && *service)
  111. ui->service->insertItem(1, service);
  112. idx = 1;
  113. }
  114. ui->service->setCurrentIndex(idx);
  115. lastServiceIdx = idx;
  116. bool bw_test = obs_data_get_bool(settings, "bwtest");
  117. ui->bandwidthTestEnable->setChecked(bw_test);
  118. idx = config_get_int(main->Config(), "Twitch", "AddonChoice");
  119. ui->twitchAddonDropdown->setCurrentIndex(idx);
  120. }
  121. UpdateServerList();
  122. if (strcmp(type, "rtmp_common") == 0) {
  123. int idx = ui->server->findData(server);
  124. if (idx == -1) {
  125. if (server && *server)
  126. ui->server->insertItem(0, server, server);
  127. idx = 0;
  128. }
  129. ui->server->setCurrentIndex(idx);
  130. }
  131. ui->key->setText(key);
  132. lastService.clear();
  133. on_service_currentIndexChanged(0);
  134. UpdateKeyLink();
  135. UpdateMoreInfoLink();
  136. UpdateVodTrackSetting();
  137. UpdateServiceRecommendations();
  138. bool streamActive = obs_frontend_streaming_active();
  139. ui->streamPage->setEnabled(!streamActive);
  140. ui->ignoreRecommended->setChecked(ignoreRecommended);
  141. loading = false;
  142. QMetaObject::invokeMethod(this, "UpdateResFPSLimits",
  143. Qt::QueuedConnection);
  144. }
  145. void OBSBasicSettings::SaveStream1Settings()
  146. {
  147. bool customServer = IsCustomService();
  148. const char *service_id = customServer ? "rtmp_custom" : "rtmp_common";
  149. obs_service_t *oldService = main->GetService();
  150. OBSDataAutoRelease hotkeyData = obs_hotkeys_save_service(oldService);
  151. OBSDataAutoRelease settings = obs_data_create();
  152. if (!customServer) {
  153. obs_data_set_string(settings, "service",
  154. QT_TO_UTF8(ui->service->currentText()));
  155. obs_data_set_string(
  156. settings, "server",
  157. QT_TO_UTF8(ui->server->currentData().toString()));
  158. } else {
  159. obs_data_set_string(
  160. settings, "server",
  161. QT_TO_UTF8(ui->customServer->text().trimmed()));
  162. obs_data_set_bool(settings, "use_auth",
  163. ui->useAuth->isChecked());
  164. if (ui->useAuth->isChecked()) {
  165. obs_data_set_string(
  166. settings, "username",
  167. QT_TO_UTF8(ui->authUsername->text()));
  168. obs_data_set_string(settings, "password",
  169. QT_TO_UTF8(ui->authPw->text()));
  170. }
  171. }
  172. if (!!auth && strcmp(auth->service(), "Twitch") == 0) {
  173. bool choiceExists = config_has_user_value(
  174. main->Config(), "Twitch", "AddonChoice");
  175. int currentChoice =
  176. config_get_int(main->Config(), "Twitch", "AddonChoice");
  177. int newChoice = ui->twitchAddonDropdown->currentIndex();
  178. config_set_int(main->Config(), "Twitch", "AddonChoice",
  179. newChoice);
  180. if (choiceExists && currentChoice != newChoice)
  181. forceAuthReload = true;
  182. obs_data_set_bool(settings, "bwtest",
  183. ui->bandwidthTestEnable->isChecked());
  184. } else {
  185. obs_data_set_bool(settings, "bwtest", false);
  186. }
  187. obs_data_set_string(settings, "key", QT_TO_UTF8(ui->key->text()));
  188. OBSServiceAutoRelease newService = obs_service_create(
  189. service_id, "default_service", settings, hotkeyData);
  190. if (!newService)
  191. return;
  192. main->SetService(newService);
  193. main->SaveService();
  194. main->auth = auth;
  195. if (!!main->auth) {
  196. main->auth->LoadUI();
  197. main->SetBroadcastFlowEnabled(main->auth->broadcastFlow());
  198. } else {
  199. main->SetBroadcastFlowEnabled(false);
  200. }
  201. SaveCheckBox(ui->ignoreRecommended, "Stream1", "IgnoreRecommended");
  202. }
  203. void OBSBasicSettings::UpdateMoreInfoLink()
  204. {
  205. if (IsCustomService()) {
  206. ui->moreInfoButton->hide();
  207. return;
  208. }
  209. QString serviceName = ui->service->currentText();
  210. obs_properties_t *props = obs_get_service_properties("rtmp_common");
  211. obs_property_t *services = obs_properties_get(props, "service");
  212. OBSDataAutoRelease settings = obs_data_create();
  213. obs_data_set_string(settings, "service", QT_TO_UTF8(serviceName));
  214. obs_property_modified(services, settings);
  215. const char *more_info_link =
  216. obs_data_get_string(settings, "more_info_link");
  217. if (!more_info_link || (*more_info_link == '\0')) {
  218. ui->moreInfoButton->hide();
  219. } else {
  220. ui->moreInfoButton->setTargetUrl(QUrl(more_info_link));
  221. ui->moreInfoButton->show();
  222. }
  223. obs_properties_destroy(props);
  224. }
  225. void OBSBasicSettings::UpdateKeyLink()
  226. {
  227. QString serviceName = ui->service->currentText();
  228. QString customServer = ui->customServer->text().trimmed();
  229. QString streamKeyLink;
  230. obs_properties_t *props = obs_get_service_properties("rtmp_common");
  231. obs_property_t *services = obs_properties_get(props, "service");
  232. OBSDataAutoRelease settings = obs_data_create();
  233. obs_data_set_string(settings, "service", QT_TO_UTF8(serviceName));
  234. obs_property_modified(services, settings);
  235. streamKeyLink = obs_data_get_string(settings, "stream_key_link");
  236. if (customServer.contains("fbcdn.net") && IsCustomService()) {
  237. streamKeyLink =
  238. "https://www.facebook.com/live/producer?ref=OBS";
  239. }
  240. if (serviceName == "Dacast") {
  241. ui->streamKeyLabel->setText(
  242. QTStr("Basic.AutoConfig.StreamPage.EncoderKey"));
  243. } else {
  244. ui->streamKeyLabel->setText(
  245. QTStr("Basic.AutoConfig.StreamPage.StreamKey"));
  246. }
  247. if (QString(streamKeyLink).isNull() ||
  248. QString(streamKeyLink).isEmpty()) {
  249. ui->getStreamKeyButton->hide();
  250. } else {
  251. ui->getStreamKeyButton->setTargetUrl(QUrl(streamKeyLink));
  252. ui->getStreamKeyButton->show();
  253. }
  254. obs_properties_destroy(props);
  255. }
  256. void OBSBasicSettings::LoadServices(bool showAll)
  257. {
  258. obs_properties_t *props = obs_get_service_properties("rtmp_common");
  259. OBSDataAutoRelease settings = obs_data_create();
  260. obs_data_set_bool(settings, "show_all", showAll);
  261. obs_property_t *prop = obs_properties_get(props, "show_all");
  262. obs_property_modified(prop, settings);
  263. ui->service->blockSignals(true);
  264. ui->service->clear();
  265. QStringList names;
  266. obs_property_t *services = obs_properties_get(props, "service");
  267. size_t services_count = obs_property_list_item_count(services);
  268. for (size_t i = 0; i < services_count; i++) {
  269. const char *name = obs_property_list_item_string(services, i);
  270. names.push_back(name);
  271. }
  272. if (showAll)
  273. names.sort(Qt::CaseInsensitive);
  274. for (QString &name : names)
  275. ui->service->addItem(name);
  276. if (!showAll) {
  277. ui->service->addItem(
  278. QTStr("Basic.AutoConfig.StreamPage.Service.ShowAll"),
  279. QVariant((int)ListOpt::ShowAll));
  280. }
  281. ui->service->insertItem(
  282. 0, QTStr("Basic.AutoConfig.StreamPage.Service.Custom"),
  283. QVariant((int)ListOpt::Custom));
  284. if (!lastService.isEmpty()) {
  285. int idx = ui->service->findText(lastService);
  286. if (idx != -1)
  287. ui->service->setCurrentIndex(idx);
  288. }
  289. obs_properties_destroy(props);
  290. ui->service->blockSignals(false);
  291. }
  292. static inline bool is_auth_service(const std::string &service)
  293. {
  294. return Auth::AuthType(service) != Auth::Type::None;
  295. }
  296. static inline bool is_external_oauth(const std::string &service)
  297. {
  298. return Auth::External(service);
  299. }
  300. static void reset_service_ui_fields(Ui::OBSBasicSettings *ui,
  301. std::string &service, bool loading)
  302. {
  303. bool external_oauth = is_external_oauth(service);
  304. if (external_oauth) {
  305. ui->streamKeyWidget->setVisible(false);
  306. ui->streamKeyLabel->setVisible(false);
  307. ui->connectAccount2->setVisible(true);
  308. ui->useStreamKeyAdv->setVisible(true);
  309. ui->streamStackWidget->setCurrentIndex((int)Section::StreamKey);
  310. } else if (cef) {
  311. QString key = ui->key->text();
  312. bool can_auth = is_auth_service(service);
  313. int page = can_auth && (!loading || key.isEmpty())
  314. ? (int)Section::Connect
  315. : (int)Section::StreamKey;
  316. ui->streamStackWidget->setCurrentIndex(page);
  317. ui->streamKeyWidget->setVisible(true);
  318. ui->streamKeyLabel->setVisible(true);
  319. ui->connectAccount2->setVisible(can_auth);
  320. ui->useStreamKeyAdv->setVisible(false);
  321. } else {
  322. ui->connectAccount2->setVisible(false);
  323. ui->useStreamKeyAdv->setVisible(false);
  324. }
  325. ui->connectedAccountLabel->setVisible(false);
  326. ui->connectedAccountText->setVisible(false);
  327. ui->disconnectAccount->setVisible(false);
  328. }
  329. #if YOUTUBE_ENABLED
  330. static void get_yt_ch_title(Ui::OBSBasicSettings *ui)
  331. {
  332. const char *name = config_get_string(OBSBasic::Get()->Config(),
  333. "YouTube", "ChannelName");
  334. if (name) {
  335. ui->connectedAccountText->setText(name);
  336. } else {
  337. // if we still not changed the service page
  338. if (IsYouTubeService(QT_TO_UTF8(ui->service->currentText()))) {
  339. ui->connectedAccountText->setText(
  340. QTStr("Auth.LoadingChannel.Error"));
  341. }
  342. }
  343. }
  344. #endif
  345. void OBSBasicSettings::UseStreamKeyAdvClicked()
  346. {
  347. ui->streamKeyWidget->setVisible(true);
  348. }
  349. void OBSBasicSettings::on_service_currentIndexChanged(int)
  350. {
  351. bool showMore = ui->service->currentData().toInt() ==
  352. (int)ListOpt::ShowAll;
  353. if (showMore)
  354. return;
  355. std::string service = QT_TO_UTF8(ui->service->currentText());
  356. bool custom = IsCustomService();
  357. ui->disconnectAccount->setVisible(false);
  358. ui->bandwidthTestEnable->setVisible(false);
  359. ui->twitchAddonDropdown->setVisible(false);
  360. ui->twitchAddonLabel->setVisible(false);
  361. if (lastService != service.c_str()) {
  362. reset_service_ui_fields(ui.get(), service, loading);
  363. }
  364. ui->useAuth->setVisible(custom);
  365. ui->authUsernameLabel->setVisible(custom);
  366. ui->authUsername->setVisible(custom);
  367. ui->authPwLabel->setVisible(custom);
  368. ui->authPwWidget->setVisible(custom);
  369. if (custom) {
  370. ui->streamkeyPageLayout->insertRow(1, ui->serverLabel,
  371. ui->serverStackedWidget);
  372. ui->serverStackedWidget->setCurrentIndex(1);
  373. ui->serverStackedWidget->setVisible(true);
  374. ui->serverLabel->setVisible(true);
  375. on_useAuth_toggled();
  376. } else {
  377. ui->serverStackedWidget->setCurrentIndex(0);
  378. }
  379. auth.reset();
  380. if (!main->auth) {
  381. return;
  382. }
  383. auto system_auth_service = main->auth->service();
  384. bool service_check = service.find(system_auth_service) !=
  385. std::string::npos;
  386. #if YOUTUBE_ENABLED
  387. service_check = service_check ? service_check
  388. : IsYouTubeService(system_auth_service) &&
  389. IsYouTubeService(service);
  390. #endif
  391. if (service_check) {
  392. auth = main->auth;
  393. OnAuthConnected();
  394. }
  395. }
  396. void OBSBasicSettings::UpdateServerList()
  397. {
  398. QString serviceName = ui->service->currentText();
  399. bool showMore = ui->service->currentData().toInt() ==
  400. (int)ListOpt::ShowAll;
  401. if (showMore) {
  402. LoadServices(true);
  403. ui->service->showPopup();
  404. return;
  405. } else {
  406. lastService = serviceName;
  407. }
  408. obs_properties_t *props = obs_get_service_properties("rtmp_common");
  409. obs_property_t *services = obs_properties_get(props, "service");
  410. OBSDataAutoRelease settings = obs_data_create();
  411. obs_data_set_string(settings, "service", QT_TO_UTF8(serviceName));
  412. obs_property_modified(services, settings);
  413. obs_property_t *servers = obs_properties_get(props, "server");
  414. ui->server->clear();
  415. size_t servers_count = obs_property_list_item_count(servers);
  416. for (size_t i = 0; i < servers_count; i++) {
  417. const char *name = obs_property_list_item_name(servers, i);
  418. const char *server = obs_property_list_item_string(servers, i);
  419. ui->server->addItem(name, server);
  420. }
  421. obs_properties_destroy(props);
  422. }
  423. void OBSBasicSettings::on_show_clicked()
  424. {
  425. if (ui->key->echoMode() == QLineEdit::Password) {
  426. ui->key->setEchoMode(QLineEdit::Normal);
  427. ui->show->setText(QTStr("Hide"));
  428. } else {
  429. ui->key->setEchoMode(QLineEdit::Password);
  430. ui->show->setText(QTStr("Show"));
  431. }
  432. }
  433. void OBSBasicSettings::on_authPwShow_clicked()
  434. {
  435. if (ui->authPw->echoMode() == QLineEdit::Password) {
  436. ui->authPw->setEchoMode(QLineEdit::Normal);
  437. ui->authPwShow->setText(QTStr("Hide"));
  438. } else {
  439. ui->authPw->setEchoMode(QLineEdit::Password);
  440. ui->authPwShow->setText(QTStr("Show"));
  441. }
  442. }
  443. OBSService OBSBasicSettings::SpawnTempService()
  444. {
  445. bool custom = IsCustomService();
  446. const char *service_id = custom ? "rtmp_custom" : "rtmp_common";
  447. OBSDataAutoRelease settings = obs_data_create();
  448. if (!custom) {
  449. obs_data_set_string(settings, "service",
  450. QT_TO_UTF8(ui->service->currentText()));
  451. obs_data_set_string(
  452. settings, "server",
  453. QT_TO_UTF8(ui->server->currentData().toString()));
  454. } else {
  455. obs_data_set_string(
  456. settings, "server",
  457. QT_TO_UTF8(ui->customServer->text().trimmed()));
  458. }
  459. obs_data_set_string(settings, "key", QT_TO_UTF8(ui->key->text()));
  460. OBSServiceAutoRelease newService = obs_service_create(
  461. service_id, "temp_service", settings, nullptr);
  462. return newService.Get();
  463. }
  464. void OBSBasicSettings::OnOAuthStreamKeyConnected()
  465. {
  466. OAuthStreamKey *a = reinterpret_cast<OAuthStreamKey *>(auth.get());
  467. if (a) {
  468. bool validKey = !a->key().empty();
  469. if (validKey)
  470. ui->key->setText(QT_UTF8(a->key().c_str()));
  471. ui->streamKeyWidget->setVisible(false);
  472. ui->streamKeyLabel->setVisible(false);
  473. ui->connectAccount2->setVisible(false);
  474. ui->disconnectAccount->setVisible(true);
  475. ui->useStreamKeyAdv->setVisible(false);
  476. ui->connectedAccountLabel->setVisible(false);
  477. ui->connectedAccountText->setVisible(false);
  478. if (strcmp(a->service(), "Twitch") == 0) {
  479. ui->bandwidthTestEnable->setVisible(true);
  480. ui->twitchAddonLabel->setVisible(true);
  481. ui->twitchAddonDropdown->setVisible(true);
  482. } else {
  483. ui->bandwidthTestEnable->setChecked(false);
  484. }
  485. #if YOUTUBE_ENABLED
  486. if (IsYouTubeService(a->service())) {
  487. ui->key->clear();
  488. ui->connectedAccountLabel->setVisible(true);
  489. ui->connectedAccountText->setVisible(true);
  490. ui->connectedAccountText->setText(
  491. QTStr("Auth.LoadingChannel.Title"));
  492. get_yt_ch_title(ui.get());
  493. }
  494. #endif
  495. }
  496. ui->streamStackWidget->setCurrentIndex((int)Section::StreamKey);
  497. }
  498. void OBSBasicSettings::OnAuthConnected()
  499. {
  500. std::string service = QT_TO_UTF8(ui->service->currentText());
  501. Auth::Type type = Auth::AuthType(service);
  502. if (type == Auth::Type::OAuth_StreamKey ||
  503. type == Auth::Type::OAuth_LinkedAccount) {
  504. OnOAuthStreamKeyConnected();
  505. }
  506. if (!loading) {
  507. stream1Changed = true;
  508. EnableApplyButton(true);
  509. }
  510. }
  511. void OBSBasicSettings::on_connectAccount_clicked()
  512. {
  513. std::string service = QT_TO_UTF8(ui->service->currentText());
  514. OAuth::DeleteCookies(service);
  515. auth = OAuthStreamKey::Login(this, service);
  516. if (!!auth) {
  517. OnAuthConnected();
  518. ui->useStreamKeyAdv->setVisible(false);
  519. }
  520. }
  521. #define DISCONNECT_COMFIRM_TITLE \
  522. "Basic.AutoConfig.StreamPage.DisconnectAccount.Confirm.Title"
  523. #define DISCONNECT_COMFIRM_TEXT \
  524. "Basic.AutoConfig.StreamPage.DisconnectAccount.Confirm.Text"
  525. void OBSBasicSettings::on_disconnectAccount_clicked()
  526. {
  527. QMessageBox::StandardButton button;
  528. button = OBSMessageBox::question(this, QTStr(DISCONNECT_COMFIRM_TITLE),
  529. QTStr(DISCONNECT_COMFIRM_TEXT));
  530. if (button == QMessageBox::No) {
  531. return;
  532. }
  533. main->auth.reset();
  534. auth.reset();
  535. main->SetBroadcastFlowEnabled(false);
  536. std::string service = QT_TO_UTF8(ui->service->currentText());
  537. #ifdef BROWSER_AVAILABLE
  538. OAuth::DeleteCookies(service);
  539. #endif
  540. ui->bandwidthTestEnable->setChecked(false);
  541. reset_service_ui_fields(ui.get(), service, loading);
  542. ui->bandwidthTestEnable->setVisible(false);
  543. ui->twitchAddonDropdown->setVisible(false);
  544. ui->twitchAddonLabel->setVisible(false);
  545. ui->key->setText("");
  546. ui->connectedAccountLabel->setVisible(false);
  547. ui->connectedAccountText->setVisible(false);
  548. }
  549. void OBSBasicSettings::on_useStreamKey_clicked()
  550. {
  551. ui->streamStackWidget->setCurrentIndex((int)Section::StreamKey);
  552. }
  553. void OBSBasicSettings::on_useAuth_toggled()
  554. {
  555. if (!IsCustomService())
  556. return;
  557. bool use_auth = ui->useAuth->isChecked();
  558. ui->authUsernameLabel->setVisible(use_auth);
  559. ui->authUsername->setVisible(use_auth);
  560. ui->authPwLabel->setVisible(use_auth);
  561. ui->authPwWidget->setVisible(use_auth);
  562. }
  563. void OBSBasicSettings::UpdateVodTrackSetting()
  564. {
  565. bool enableForCustomServer = config_get_bool(
  566. GetGlobalConfig(), "General", "EnableCustomServerVodTrack");
  567. bool enableVodTrack = ui->service->currentText() == "Twitch";
  568. bool wasEnabled = !!vodTrackCheckbox;
  569. if (enableForCustomServer && IsCustomService())
  570. enableVodTrack = true;
  571. if (enableVodTrack == wasEnabled)
  572. return;
  573. if (!enableVodTrack) {
  574. delete vodTrackCheckbox;
  575. delete vodTrackContainer;
  576. delete simpleVodTrack;
  577. return;
  578. }
  579. /* -------------------------------------- */
  580. /* simple output mode vod track widgets */
  581. bool simpleAdv = ui->simpleOutAdvanced->isChecked();
  582. bool vodTrackEnabled = config_get_bool(main->Config(), "SimpleOutput",
  583. "VodTrackEnabled");
  584. simpleVodTrack = new QCheckBox(this);
  585. simpleVodTrack->setText(
  586. QTStr("Basic.Settings.Output.Simple.TwitchVodTrack"));
  587. simpleVodTrack->setVisible(simpleAdv);
  588. simpleVodTrack->setChecked(vodTrackEnabled);
  589. int pos;
  590. ui->simpleStreamingLayout->getWidgetPosition(ui->simpleOutAdvanced,
  591. &pos, nullptr);
  592. ui->simpleStreamingLayout->insertRow(pos + 1, nullptr, simpleVodTrack);
  593. HookWidget(simpleVodTrack, SIGNAL(clicked(bool)),
  594. SLOT(OutputsChanged()));
  595. connect(ui->simpleOutAdvanced, SIGNAL(toggled(bool)),
  596. simpleVodTrack.data(), SLOT(setVisible(bool)));
  597. /* -------------------------------------- */
  598. /* advanced output mode vod track widgets */
  599. vodTrackCheckbox = new QCheckBox(this);
  600. vodTrackCheckbox->setText(
  601. QTStr("Basic.Settings.Output.Adv.TwitchVodTrack"));
  602. vodTrackCheckbox->setLayoutDirection(Qt::RightToLeft);
  603. vodTrackContainer = new QWidget(this);
  604. QHBoxLayout *vodTrackLayout = new QHBoxLayout();
  605. for (int i = 0; i < MAX_AUDIO_MIXES; i++) {
  606. vodTrack[i] = new QRadioButton(QString::number(i + 1));
  607. vodTrackLayout->addWidget(vodTrack[i]);
  608. HookWidget(vodTrack[i], SIGNAL(clicked(bool)),
  609. SLOT(OutputsChanged()));
  610. }
  611. HookWidget(vodTrackCheckbox, SIGNAL(clicked(bool)),
  612. SLOT(OutputsChanged()));
  613. vodTrackLayout->addStretch();
  614. vodTrackLayout->setContentsMargins(0, 0, 0, 0);
  615. vodTrackContainer->setLayout(vodTrackLayout);
  616. ui->advOutTopLayout->insertRow(2, vodTrackCheckbox, vodTrackContainer);
  617. vodTrackEnabled =
  618. config_get_bool(main->Config(), "AdvOut", "VodTrackEnabled");
  619. vodTrackCheckbox->setChecked(vodTrackEnabled);
  620. vodTrackContainer->setEnabled(vodTrackEnabled);
  621. connect(vodTrackCheckbox, SIGNAL(clicked(bool)), vodTrackContainer,
  622. SLOT(setEnabled(bool)));
  623. int trackIndex =
  624. config_get_int(main->Config(), "AdvOut", "VodTrackIndex");
  625. for (int i = 0; i < MAX_AUDIO_MIXES; i++) {
  626. vodTrack[i]->setChecked((i + 1) == trackIndex);
  627. }
  628. }
  629. OBSService OBSBasicSettings::GetStream1Service()
  630. {
  631. return stream1Changed ? SpawnTempService()
  632. : OBSService(main->GetService());
  633. }
  634. void OBSBasicSettings::UpdateServiceRecommendations()
  635. {
  636. bool customServer = IsCustomService();
  637. ui->ignoreRecommended->setVisible(!customServer);
  638. ui->enforceSettingsLabel->setVisible(!customServer);
  639. OBSService service = GetStream1Service();
  640. int vbitrate, abitrate;
  641. BPtr<obs_service_resolution> res_list;
  642. size_t res_count;
  643. int fps;
  644. obs_service_get_max_bitrate(service, &vbitrate, &abitrate);
  645. obs_service_get_supported_resolutions(service, &res_list, &res_count);
  646. obs_service_get_max_fps(service, &fps);
  647. QString text;
  648. #define ENFORCE_TEXT(x) QTStr("Basic.Settings.Stream.Recommended." x)
  649. if (vbitrate)
  650. text += ENFORCE_TEXT("MaxVideoBitrate")
  651. .arg(QString::number(vbitrate));
  652. if (abitrate) {
  653. if (!text.isEmpty())
  654. text += "<br>";
  655. text += ENFORCE_TEXT("MaxAudioBitrate")
  656. .arg(QString::number(abitrate));
  657. }
  658. if (res_count) {
  659. if (!text.isEmpty())
  660. text += "<br>";
  661. obs_service_resolution best_res = {};
  662. int best_res_pixels = 0;
  663. for (size_t i = 0; i < res_count; i++) {
  664. obs_service_resolution res = res_list[i];
  665. int res_pixels = res.cx + res.cy;
  666. if (res_pixels > best_res_pixels) {
  667. best_res = res;
  668. best_res_pixels = res_pixels;
  669. }
  670. }
  671. QString res_str =
  672. QString("%1x%2").arg(QString::number(best_res.cx),
  673. QString::number(best_res.cy));
  674. text += ENFORCE_TEXT("MaxResolution").arg(res_str);
  675. }
  676. if (fps) {
  677. if (!text.isEmpty())
  678. text += "<br>";
  679. text += ENFORCE_TEXT("MaxFPS").arg(QString::number(fps));
  680. }
  681. #undef ENFORCE_TEXT
  682. #if YOUTUBE_ENABLED
  683. if (IsYouTubeService(QT_TO_UTF8(ui->service->currentText()))) {
  684. if (!text.isEmpty())
  685. text += "<br><br>";
  686. text += "<a href=\"https://www.youtube.com/t/terms\">"
  687. "YouTube Terms of Service</a><br>"
  688. "<a href=\"http://www.google.com/policies/privacy\">"
  689. "Google Privacy Policy</a><br>"
  690. "<a href=\"https://security.google.com/settings/security/permissions\">"
  691. "Google Third-Party Permissions</a>";
  692. }
  693. #endif
  694. ui->enforceSettingsLabel->setText(text);
  695. }
  696. void OBSBasicSettings::DisplayEnforceWarning(bool checked)
  697. {
  698. if (IsCustomService())
  699. return;
  700. if (!checked) {
  701. SimpleRecordingEncoderChanged();
  702. return;
  703. }
  704. QMessageBox::StandardButton button;
  705. #define ENFORCE_WARNING(x) \
  706. QTStr("Basic.Settings.Stream.IgnoreRecommended.Warn." x)
  707. button = OBSMessageBox::question(this, ENFORCE_WARNING("Title"),
  708. ENFORCE_WARNING("Text"));
  709. #undef ENFORCE_WARNING
  710. if (button == QMessageBox::No) {
  711. QMetaObject::invokeMethod(ui->ignoreRecommended, "setChecked",
  712. Qt::QueuedConnection,
  713. Q_ARG(bool, false));
  714. return;
  715. }
  716. SimpleRecordingEncoderChanged();
  717. }
  718. bool OBSBasicSettings::ResFPSValid(obs_service_resolution *res_list,
  719. size_t res_count, int max_fps)
  720. {
  721. if (!res_count && !max_fps)
  722. return true;
  723. if (res_count) {
  724. QString res = ui->outputResolution->currentText();
  725. bool found_res = false;
  726. int cx, cy;
  727. if (sscanf(QT_TO_UTF8(res), "%dx%d", &cx, &cy) != 2)
  728. return false;
  729. for (size_t i = 0; i < res_count; i++) {
  730. if (res_list[i].cx == cx && res_list[i].cy == cy) {
  731. found_res = true;
  732. break;
  733. }
  734. }
  735. if (!found_res)
  736. return false;
  737. }
  738. if (max_fps) {
  739. int fpsType = ui->fpsType->currentIndex();
  740. if (fpsType != 0)
  741. return false;
  742. std::string fps_str = QT_TO_UTF8(ui->fpsCommon->currentText());
  743. float fps;
  744. sscanf(fps_str.c_str(), "%f", &fps);
  745. if (fps > (float)max_fps)
  746. return false;
  747. }
  748. return true;
  749. }
  750. extern void set_closest_res(int &cx, int &cy,
  751. struct obs_service_resolution *res_list,
  752. size_t count);
  753. /* Checks for and updates the resolution and FPS limits of a service, if any.
  754. *
  755. * If the service has a resolution and/or FPS limit, this will enforce those
  756. * limitations in the UI itself, preventing the user from selecting a
  757. * resolution or FPS that's not supported.
  758. *
  759. * This is an unpleasant thing to have to do to users, but there is no other
  760. * way to ensure that a service's restricted resolution/framerate values are
  761. * properly enforced, otherwise users will just be confused when things aren't
  762. * working correctly. The user can turn it off if they're partner (or if they
  763. * want to risk getting in trouble with their service) by selecting the "Ignore
  764. * recommended settings" option in the stream section of settings.
  765. *
  766. * This only affects services that have a resolution and/or framerate limit, of
  767. * which as of this writing, and hopefully for the foreseeable future, there is
  768. * only one.
  769. */
  770. void OBSBasicSettings::UpdateResFPSLimits()
  771. {
  772. if (loading)
  773. return;
  774. if (!ServiceSupportsCodecCheck())
  775. return;
  776. int idx = ui->service->currentIndex();
  777. if (idx == -1)
  778. return;
  779. bool ignoreRecommended = ui->ignoreRecommended->isChecked();
  780. BPtr<obs_service_resolution> res_list;
  781. size_t res_count = 0;
  782. int max_fps = 0;
  783. if (!IsCustomService() && !ignoreRecommended) {
  784. OBSService service = GetStream1Service();
  785. obs_service_get_supported_resolutions(service, &res_list,
  786. &res_count);
  787. obs_service_get_max_fps(service, &max_fps);
  788. }
  789. /* ------------------------------------ */
  790. /* Check for enforced res/FPS */
  791. QString res = ui->outputResolution->currentText();
  792. QString fps_str;
  793. int cx = 0, cy = 0;
  794. double max_fpsd = (double)max_fps;
  795. int closest_fps_index = -1;
  796. double fpsd;
  797. sscanf(QT_TO_UTF8(res), "%dx%d", &cx, &cy);
  798. if (res_count)
  799. set_closest_res(cx, cy, res_list, res_count);
  800. if (max_fps) {
  801. int fpsType = ui->fpsType->currentIndex();
  802. if (fpsType == 1) { //Integer
  803. fpsd = (double)ui->fpsInteger->value();
  804. } else if (fpsType == 2) { //Fractional
  805. fpsd = (double)ui->fpsNumerator->value() /
  806. (double)ui->fpsDenominator->value();
  807. } else { //Common
  808. sscanf(QT_TO_UTF8(ui->fpsCommon->currentText()), "%lf",
  809. &fpsd);
  810. }
  811. double closest_diff = 1000000000000.0;
  812. for (int i = 0; i < ui->fpsCommon->count(); i++) {
  813. double com_fpsd;
  814. sscanf(QT_TO_UTF8(ui->fpsCommon->itemText(i)), "%lf",
  815. &com_fpsd);
  816. if (com_fpsd > max_fpsd) {
  817. continue;
  818. }
  819. double diff = fabs(com_fpsd - fpsd);
  820. if (diff < closest_diff) {
  821. closest_diff = diff;
  822. closest_fps_index = i;
  823. fps_str = ui->fpsCommon->itemText(i);
  824. }
  825. }
  826. }
  827. QString res_str =
  828. QString("%1x%2").arg(QString::number(cx), QString::number(cy));
  829. /* ------------------------------------ */
  830. /* Display message box if res/FPS bad */
  831. bool valid = ResFPSValid(res_list, res_count, max_fps);
  832. if (!valid) {
  833. /* if the user was already on facebook with an incompatible
  834. * resolution, assume it's an upgrade */
  835. if (lastServiceIdx == -1 && lastIgnoreRecommended == -1) {
  836. ui->ignoreRecommended->setChecked(true);
  837. ui->ignoreRecommended->setProperty("changed", true);
  838. stream1Changed = true;
  839. EnableApplyButton(true);
  840. UpdateResFPSLimits();
  841. return;
  842. }
  843. QMessageBox::StandardButton button;
  844. #define WARNING_VAL(x) \
  845. QTStr("Basic.Settings.Output.Warn.EnforceResolutionFPS." x)
  846. QString str;
  847. if (res_count)
  848. str += WARNING_VAL("Resolution").arg(res_str);
  849. if (max_fps) {
  850. if (!str.isEmpty())
  851. str += "\n";
  852. str += WARNING_VAL("FPS").arg(fps_str);
  853. }
  854. button = OBSMessageBox::question(this, WARNING_VAL("Title"),
  855. WARNING_VAL("Msg").arg(str));
  856. #undef WARNING_VAL
  857. if (button == QMessageBox::No) {
  858. if (idx != lastServiceIdx)
  859. QMetaObject::invokeMethod(
  860. ui->service, "setCurrentIndex",
  861. Qt::QueuedConnection,
  862. Q_ARG(int, lastServiceIdx));
  863. else
  864. QMetaObject::invokeMethod(ui->ignoreRecommended,
  865. "setChecked",
  866. Qt::QueuedConnection,
  867. Q_ARG(bool, true));
  868. return;
  869. }
  870. }
  871. /* ------------------------------------ */
  872. /* Update widgets/values if switching */
  873. /* to/from enforced resolution/FPS */
  874. ui->outputResolution->blockSignals(true);
  875. if (res_count) {
  876. ui->outputResolution->clear();
  877. ui->outputResolution->setEditable(false);
  878. HookWidget(ui->outputResolution,
  879. SIGNAL(currentIndexChanged(int)),
  880. SLOT(VideoChangedResolution()));
  881. int new_res_index = -1;
  882. for (size_t i = 0; i < res_count; i++) {
  883. obs_service_resolution val = res_list[i];
  884. QString str =
  885. QString("%1x%2").arg(QString::number(val.cx),
  886. QString::number(val.cy));
  887. ui->outputResolution->addItem(str);
  888. if (val.cx == cx && val.cy == cy)
  889. new_res_index = (int)i;
  890. }
  891. ui->outputResolution->setCurrentIndex(new_res_index);
  892. if (!valid) {
  893. ui->outputResolution->setProperty("changed", true);
  894. videoChanged = true;
  895. EnableApplyButton(true);
  896. }
  897. } else {
  898. QString baseRes = ui->baseResolution->currentText();
  899. int baseCX, baseCY;
  900. sscanf(QT_TO_UTF8(baseRes), "%dx%d", &baseCX, &baseCY);
  901. if (!ui->outputResolution->isEditable()) {
  902. RecreateOutputResolutionWidget();
  903. ui->outputResolution->blockSignals(true);
  904. ResetDownscales((uint32_t)baseCX, (uint32_t)baseCY,
  905. true);
  906. ui->outputResolution->setCurrentText(res);
  907. }
  908. }
  909. ui->outputResolution->blockSignals(false);
  910. if (max_fps) {
  911. for (int i = 0; i < ui->fpsCommon->count(); i++) {
  912. double com_fpsd;
  913. sscanf(QT_TO_UTF8(ui->fpsCommon->itemText(i)), "%lf",
  914. &com_fpsd);
  915. if (com_fpsd > max_fpsd) {
  916. SetComboItemEnabled(ui->fpsCommon, i, false);
  917. continue;
  918. }
  919. }
  920. ui->fpsType->setCurrentIndex(0);
  921. ui->fpsCommon->setCurrentIndex(closest_fps_index);
  922. if (!valid) {
  923. ui->fpsType->setProperty("changed", true);
  924. ui->fpsCommon->setProperty("changed", true);
  925. videoChanged = true;
  926. EnableApplyButton(true);
  927. }
  928. } else {
  929. for (int i = 0; i < ui->fpsCommon->count(); i++)
  930. SetComboItemEnabled(ui->fpsCommon, i, true);
  931. }
  932. SetComboItemEnabled(ui->fpsType, 1, !max_fps);
  933. SetComboItemEnabled(ui->fpsType, 2, !max_fps);
  934. /* ------------------------------------ */
  935. lastIgnoreRecommended = (int)ignoreRecommended;
  936. lastServiceIdx = idx;
  937. }
  938. bool OBSBasicSettings::IsServiceOutputHasNetworkFeatures()
  939. {
  940. if (IsCustomService())
  941. return ui->customServer->text().startsWith("rtmp");
  942. OBSServiceAutoRelease service = SpawnTempService();
  943. const char *output = obs_service_get_output_type(service);
  944. if (!output)
  945. return true;
  946. if (strcmp(output, "rtmp_output") == 0)
  947. return true;
  948. return false;
  949. }
  950. static bool service_supports_codec(const char **codecs, const char *codec)
  951. {
  952. if (!codecs)
  953. return true;
  954. while (*codecs) {
  955. if (strcmp(*codecs, codec) == 0)
  956. return true;
  957. codecs++;
  958. }
  959. return false;
  960. }
  961. extern bool EncoderAvailable(const char *encoder);
  962. extern const char *get_simple_output_encoder(const char *name);
  963. static inline bool service_supports_encoder(const char **codecs,
  964. const char *encoder)
  965. {
  966. if (!EncoderAvailable(encoder))
  967. return false;
  968. const char *codec = obs_get_encoder_codec(encoder);
  969. return service_supports_codec(codecs, codec);
  970. }
  971. bool OBSBasicSettings::ServiceAndCodecCompatible()
  972. {
  973. if (IsCustomService())
  974. return true;
  975. if (ui->service->currentData().toInt() == (int)ListOpt::ShowAll)
  976. return true;
  977. bool simple = (ui->outputMode->currentIndex() == 0);
  978. OBSService service = SpawnTempService();
  979. const char **codecs = obs_service_get_supported_video_codecs(service);
  980. const char *codec;
  981. if (simple) {
  982. QString encoder =
  983. ui->simpleOutStrEncoder->currentData().toString();
  984. const char *id = get_simple_output_encoder(QT_TO_UTF8(encoder));
  985. codec = obs_get_encoder_codec(id);
  986. } else {
  987. QString encoder = ui->advOutEncoder->currentData().toString();
  988. codec = obs_get_encoder_codec(QT_TO_UTF8(encoder));
  989. }
  990. return service_supports_codec(codecs, codec);
  991. }
  992. /* we really need a way to find fallbacks in a less hardcoded way. maybe. */
  993. static QString get_adv_fallback(const QString &enc)
  994. {
  995. if (enc == "jim_hevc_nvenc")
  996. return "jim_nvenc";
  997. if (enc == "h265_texture_amf")
  998. return "h264_texture_amf";
  999. return "obs_x264";
  1000. }
  1001. static QString get_simple_fallback(const QString &enc)
  1002. {
  1003. if (enc == SIMPLE_ENCODER_NVENC_HEVC)
  1004. return SIMPLE_ENCODER_NVENC;
  1005. if (enc == SIMPLE_ENCODER_AMD_HEVC)
  1006. return SIMPLE_ENCODER_AMD;
  1007. return SIMPLE_ENCODER_X264;
  1008. }
  1009. bool OBSBasicSettings::ServiceSupportsCodecCheck()
  1010. {
  1011. if (ServiceAndCodecCompatible()) {
  1012. if (lastServiceIdx != ui->service->currentIndex())
  1013. ResetEncoders(true);
  1014. return true;
  1015. }
  1016. QString service = ui->service->currentText();
  1017. QString cur_name;
  1018. QString fb_name;
  1019. bool simple = (ui->outputMode->currentIndex() == 0);
  1020. /* ------------------------------------------------- */
  1021. /* get current codec */
  1022. if (simple) {
  1023. QString cur_enc =
  1024. ui->simpleOutStrEncoder->currentData().toString();
  1025. QString fb_enc = get_simple_fallback(cur_enc);
  1026. int cur_idx = ui->simpleOutStrEncoder->findData(cur_enc);
  1027. int fb_idx = ui->simpleOutStrEncoder->findData(fb_enc);
  1028. cur_name = ui->simpleOutStrEncoder->itemText(cur_idx);
  1029. fb_name = ui->simpleOutStrEncoder->itemText(fb_idx);
  1030. } else {
  1031. QString cur_enc = ui->advOutEncoder->currentData().toString();
  1032. QString fb_enc = get_adv_fallback(cur_enc);
  1033. cur_name = obs_encoder_get_display_name(QT_TO_UTF8(cur_enc));
  1034. fb_name = obs_encoder_get_display_name(QT_TO_UTF8(fb_enc));
  1035. }
  1036. #define WARNING_VAL(x) \
  1037. QTStr("Basic.Settings.Output.Warn.ServiceCodecCompatibility." x)
  1038. QString msg = WARNING_VAL("Msg").arg(service, cur_name, fb_name);
  1039. auto button = OBSMessageBox::question(this, WARNING_VAL("Title"), msg);
  1040. #undef WARNING_VAL
  1041. if (button == QMessageBox::No) {
  1042. QMetaObject::invokeMethod(ui->service, "setCurrentIndex",
  1043. Qt::QueuedConnection,
  1044. Q_ARG(int, lastServiceIdx));
  1045. return false;
  1046. }
  1047. ResetEncoders(true);
  1048. return true;
  1049. }
  1050. #define TEXT_USE_STREAM_ENC \
  1051. QTStr("Basic.Settings.Output.Adv.Recording.UseStreamEncoder")
  1052. void OBSBasicSettings::ResetEncoders(bool streamOnly)
  1053. {
  1054. QString lastAdvEnc = ui->advOutRecEncoder->currentData().toString();
  1055. QString lastEnc = ui->simpleOutStrEncoder->currentData().toString();
  1056. OBSService service = SpawnTempService();
  1057. const char **codecs = obs_service_get_supported_video_codecs(service);
  1058. const char *type;
  1059. size_t idx = 0;
  1060. QSignalBlocker s1(ui->simpleOutStrEncoder);
  1061. QSignalBlocker s2(ui->advOutEncoder);
  1062. /* ------------------------------------------------- */
  1063. /* clear encoder lists */
  1064. ui->simpleOutStrEncoder->clear();
  1065. ui->advOutEncoder->clear();
  1066. if (!streamOnly) {
  1067. ui->advOutRecEncoder->clear();
  1068. ui->advOutRecEncoder->addItem(TEXT_USE_STREAM_ENC, "none");
  1069. }
  1070. /* ------------------------------------------------- */
  1071. /* load advanced stream/recording encoders */
  1072. while (obs_enum_encoder_types(idx++, &type)) {
  1073. const char *name = obs_encoder_get_display_name(type);
  1074. const char *codec = obs_get_encoder_codec(type);
  1075. uint32_t caps = obs_get_encoder_caps(type);
  1076. if (obs_get_encoder_type(type) != OBS_ENCODER_VIDEO)
  1077. continue;
  1078. const char *streaming_codecs[] = {
  1079. "h264",
  1080. #ifdef ENABLE_HEVC
  1081. "hevc",
  1082. #endif
  1083. };
  1084. bool is_streaming_codec = false;
  1085. for (const char *test_codec : streaming_codecs) {
  1086. if (strcmp(codec, test_codec) == 0) {
  1087. is_streaming_codec = true;
  1088. break;
  1089. }
  1090. }
  1091. if ((caps & ENCODER_HIDE_FLAGS) != 0)
  1092. continue;
  1093. QString qName = QT_UTF8(name);
  1094. QString qType = QT_UTF8(type);
  1095. if (is_streaming_codec && service_supports_codec(codecs, codec))
  1096. ui->advOutEncoder->addItem(qName, qType);
  1097. if (!streamOnly)
  1098. ui->advOutRecEncoder->addItem(qName, qType);
  1099. }
  1100. /* ------------------------------------------------- */
  1101. /* load simple stream encoders */
  1102. #define ENCODER_STR(str) QTStr("Basic.Settings.Output.Simple.Encoder." str)
  1103. ui->simpleOutStrEncoder->addItem(ENCODER_STR("Software"),
  1104. QString(SIMPLE_ENCODER_X264));
  1105. if (service_supports_encoder(codecs, "obs_qsv11"))
  1106. ui->simpleOutStrEncoder->addItem(
  1107. ENCODER_STR("Hardware.QSV.H264"),
  1108. QString(SIMPLE_ENCODER_QSV));
  1109. if (service_supports_encoder(codecs, "ffmpeg_nvenc"))
  1110. ui->simpleOutStrEncoder->addItem(
  1111. ENCODER_STR("Hardware.NVENC.H264"),
  1112. QString(SIMPLE_ENCODER_NVENC));
  1113. #ifdef ENABLE_HEVC
  1114. if (service_supports_encoder(codecs, "h265_texture_amf"))
  1115. ui->simpleOutStrEncoder->addItem(
  1116. ENCODER_STR("Hardware.AMD.HEVC"),
  1117. QString(SIMPLE_ENCODER_AMD_HEVC));
  1118. if (service_supports_encoder(codecs, "ffmpeg_hevc_nvenc"))
  1119. ui->simpleOutStrEncoder->addItem(
  1120. ENCODER_STR("Hardware.NVENC.HEVC"),
  1121. QString(SIMPLE_ENCODER_NVENC_HEVC));
  1122. #endif
  1123. if (service_supports_encoder(codecs, "h264_texture_amf"))
  1124. ui->simpleOutStrEncoder->addItem(
  1125. ENCODER_STR("Hardware.AMD.H264"),
  1126. QString(SIMPLE_ENCODER_AMD));
  1127. /* Preprocessor guard required for the macOS version check */
  1128. #ifdef __APPLE__
  1129. if (service_supports_encoder(
  1130. codecs, "com.apple.videotoolbox.videoencoder.ave.avc")
  1131. #ifndef __aarch64__
  1132. && os_get_emulation_status() == true
  1133. #endif
  1134. ) {
  1135. if (__builtin_available(macOS 13.0, *)) {
  1136. ui->simpleOutStrEncoder->addItem(
  1137. ENCODER_STR("Hardware.Apple.H264"),
  1138. QString(SIMPLE_ENCODER_APPLE_H264));
  1139. }
  1140. }
  1141. #endif
  1142. #undef ENCODER_STR
  1143. /* ------------------------------------------------- */
  1144. /* Find fallback encoders */
  1145. if (!lastAdvEnc.isEmpty()) {
  1146. int idx = ui->advOutEncoder->findData(lastAdvEnc);
  1147. if (idx == -1) {
  1148. lastAdvEnc = get_adv_fallback(lastAdvEnc);
  1149. ui->advOutEncoder->setProperty("changed",
  1150. QVariant(true));
  1151. OutputsChanged();
  1152. }
  1153. idx = ui->advOutEncoder->findData(lastAdvEnc);
  1154. ui->advOutEncoder->setCurrentIndex(idx);
  1155. }
  1156. if (!lastEnc.isEmpty()) {
  1157. int idx = ui->simpleOutStrEncoder->findData(lastEnc);
  1158. if (idx == -1) {
  1159. lastEnc = get_simple_fallback(lastEnc);
  1160. ui->simpleOutStrEncoder->setProperty("changed",
  1161. QVariant(true));
  1162. OutputsChanged();
  1163. }
  1164. idx = ui->simpleOutStrEncoder->findData(lastEnc);
  1165. ui->simpleOutStrEncoder->setCurrentIndex(idx);
  1166. }
  1167. }