window-basic-settings-stream.cpp 49 KB

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