window-basic-settings-stream.cpp 41 KB

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