window-basic-settings-stream.cpp 40 KB

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