window-basic-settings-stream.cpp 41 KB

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