window-basic-settings-stream.cpp 47 KB

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