OBSBasic.cpp 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018
  1. /******************************************************************************
  2. Copyright (C) 2023 by Lain Bailey <[email protected]>
  3. Zachary Lund <[email protected]>
  4. Philippe Groarke <[email protected]>
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ******************************************************************************/
  16. #include "OBSBasic.hpp"
  17. #include "ui-config.h"
  18. #include "ColorSelect.hpp"
  19. #include "OBSBasicControls.hpp"
  20. #include "OBSBasicStats.hpp"
  21. #include "VolControl.hpp"
  22. #ifdef YOUTUBE_ENABLED
  23. #include <docks/YouTubeAppDock.hpp>
  24. #endif
  25. #include <dialogs/NameDialog.hpp>
  26. #include <dialogs/OBSAbout.hpp>
  27. #include <dialogs/OBSBasicAdvAudio.hpp>
  28. #include <dialogs/OBSBasicFilters.hpp>
  29. #include <dialogs/OBSBasicInteraction.hpp>
  30. #include <dialogs/OBSBasicProperties.hpp>
  31. #include <dialogs/OBSBasicTransform.hpp>
  32. #include <models/SceneCollection.hpp>
  33. #include <settings/OBSBasicSettings.hpp>
  34. #include <utility/QuickTransition.hpp>
  35. #include <utility/SceneRenameDelegate.hpp>
  36. #if defined(_WIN32) || defined(WHATSNEW_ENABLED)
  37. #include <utility/WhatsNewInfoThread.hpp>
  38. #endif
  39. #include <widgets/OBSProjector.hpp>
  40. #include <OBSStudioAPI.hpp>
  41. #ifdef BROWSER_AVAILABLE
  42. #include <browser-panel.hpp>
  43. #endif
  44. #ifdef ENABLE_WAYLAND
  45. #include <obs-nix-platform.h>
  46. #endif
  47. #include <qt-wrappers.hpp>
  48. #include <QActionGroup>
  49. #include <QThread>
  50. #include <QWidgetAction>
  51. #ifdef _WIN32
  52. #include <sstream>
  53. #endif
  54. #include <string>
  55. #include <unordered_set>
  56. #ifdef _WIN32
  57. #define WIN32_LEAN_AND_MEAN
  58. #include "Windows.h"
  59. #endif
  60. #include "moc_OBSBasic.cpp"
  61. using namespace std;
  62. extern bool portable_mode;
  63. extern bool disable_3p_plugins;
  64. extern bool opt_studio_mode;
  65. extern bool opt_always_on_top;
  66. extern bool opt_minimize_tray;
  67. extern std::string opt_starting_profile;
  68. extern std::string opt_starting_collection;
  69. extern bool safe_mode;
  70. extern bool opt_start_recording;
  71. extern bool opt_start_replaybuffer;
  72. extern bool opt_start_virtualcam;
  73. extern volatile long insideEventLoop;
  74. extern bool restart;
  75. extern bool EncoderAvailable(const char *encoder);
  76. extern void RegisterTwitchAuth();
  77. extern void RegisterRestreamAuth();
  78. #ifdef YOUTUBE_ENABLED
  79. extern void RegisterYoutubeAuth();
  80. #endif
  81. struct QCef;
  82. extern QCef *cef;
  83. extern bool cef_js_avail;
  84. extern void DestroyPanelCookieManager();
  85. extern void CheckExistingCookieId();
  86. static void AddExtraModulePaths()
  87. {
  88. string plugins_path, plugins_data_path;
  89. char *s;
  90. s = getenv("OBS_PLUGINS_PATH");
  91. if (s)
  92. plugins_path = s;
  93. s = getenv("OBS_PLUGINS_DATA_PATH");
  94. if (s)
  95. plugins_data_path = s;
  96. if (!plugins_path.empty() && !plugins_data_path.empty()) {
  97. #if defined(__APPLE__)
  98. plugins_path += "/%module%.plugin/Contents/MacOS";
  99. plugins_data_path += "/%module%.plugin/Contents/Resources";
  100. obs_add_module_path(plugins_path.c_str(), plugins_data_path.c_str());
  101. #else
  102. string data_path_with_module_suffix;
  103. data_path_with_module_suffix += plugins_data_path;
  104. data_path_with_module_suffix += "/%module%";
  105. obs_add_module_path(plugins_path.c_str(), data_path_with_module_suffix.c_str());
  106. #endif
  107. }
  108. if (portable_mode)
  109. return;
  110. char base_module_dir[512];
  111. #if defined(_WIN32)
  112. int ret = GetProgramDataPath(base_module_dir, sizeof(base_module_dir), "obs-studio/plugins/%module%");
  113. #elif defined(__APPLE__)
  114. int ret = GetAppConfigPath(base_module_dir, sizeof(base_module_dir), "obs-studio/plugins/%module%.plugin");
  115. #else
  116. int ret = GetAppConfigPath(base_module_dir, sizeof(base_module_dir), "obs-studio/plugins/%module%");
  117. #endif
  118. if (ret <= 0)
  119. return;
  120. string path = base_module_dir;
  121. #if defined(__APPLE__)
  122. /* User Application Support Search Path */
  123. obs_add_module_path((path + "/Contents/MacOS").c_str(), (path + "/Contents/Resources").c_str());
  124. #ifndef __aarch64__
  125. /* Legacy System Library Search Path */
  126. char system_legacy_module_dir[PATH_MAX];
  127. GetProgramDataPath(system_legacy_module_dir, sizeof(system_legacy_module_dir), "obs-studio/plugins/%module%");
  128. std::string path_system_legacy = system_legacy_module_dir;
  129. obs_add_module_path((path_system_legacy + "/bin").c_str(), (path_system_legacy + "/data").c_str());
  130. /* Legacy User Application Support Search Path */
  131. char user_legacy_module_dir[PATH_MAX];
  132. GetAppConfigPath(user_legacy_module_dir, sizeof(user_legacy_module_dir), "obs-studio/plugins/%module%");
  133. std::string path_user_legacy = user_legacy_module_dir;
  134. obs_add_module_path((path_user_legacy + "/bin").c_str(), (path_user_legacy + "/data").c_str());
  135. #endif
  136. #else
  137. #if ARCH_BITS == 64
  138. obs_add_module_path((path + "/bin/64bit").c_str(), (path + "/data").c_str());
  139. #else
  140. obs_add_module_path((path + "/bin/32bit").c_str(), (path + "/data").c_str());
  141. #endif
  142. #endif
  143. }
  144. /* First-party modules considered to be potentially unsafe to load in Safe Mode
  145. * due to them allowing external code (e.g. scripts) to modify OBS's state. */
  146. static const unordered_set<string> unsafe_modules = {
  147. "frontend-tools", // Scripting
  148. "obs-websocket", // Allows outside modifications
  149. };
  150. static void SetSafeModuleNames()
  151. {
  152. #ifndef SAFE_MODULES
  153. return;
  154. #else
  155. string module;
  156. stringstream modules(SAFE_MODULES);
  157. while (getline(modules, module, '|')) {
  158. /* When only disallowing third-party plugins, still add
  159. * "unsafe" bundled modules to the safe list. */
  160. if (disable_3p_plugins || !unsafe_modules.count(module))
  161. obs_add_safe_module(module.c_str());
  162. }
  163. #endif
  164. }
  165. extern void setupDockAction(QDockWidget *dock);
  166. OBSBasic::OBSBasic(QWidget *parent) : OBSMainWindow(parent), undo_s(ui), ui(new Ui::OBSBasic)
  167. {
  168. collections = {};
  169. setAttribute(Qt::WA_NativeWindow);
  170. #ifdef TWITCH_ENABLED
  171. RegisterTwitchAuth();
  172. #endif
  173. #ifdef RESTREAM_ENABLED
  174. RegisterRestreamAuth();
  175. #endif
  176. #ifdef YOUTUBE_ENABLED
  177. RegisterYoutubeAuth();
  178. #endif
  179. setAcceptDrops(true);
  180. setContextMenuPolicy(Qt::CustomContextMenu);
  181. QEvent::registerEventType(QEvent::User + QEvent::Close);
  182. api = InitializeAPIInterface(this);
  183. ui->setupUi(this);
  184. ui->previewDisabledWidget->setVisible(false);
  185. /* Set up streaming connections */
  186. connect(
  187. this, &OBSBasic::StreamingStarting, this, [this] { this->streamingStarting = true; },
  188. Qt::DirectConnection);
  189. connect(
  190. this, &OBSBasic::StreamingStarted, this, [this] { this->streamingStarting = false; },
  191. Qt::DirectConnection);
  192. connect(
  193. this, &OBSBasic::StreamingStopped, this, [this] { this->streamingStarting = false; },
  194. Qt::DirectConnection);
  195. /* Set up recording connections */
  196. connect(
  197. this, &OBSBasic::RecordingStarted, this,
  198. [this]() {
  199. this->recordingStarted = true;
  200. this->recordingPaused = false;
  201. },
  202. Qt::DirectConnection);
  203. connect(
  204. this, &OBSBasic::RecordingPaused, this, [this]() { this->recordingPaused = true; },
  205. Qt::DirectConnection);
  206. connect(
  207. this, &OBSBasic::RecordingUnpaused, this, [this]() { this->recordingPaused = false; },
  208. Qt::DirectConnection);
  209. connect(
  210. this, &OBSBasic::RecordingStopped, this,
  211. [this]() {
  212. this->recordingStarted = false;
  213. this->recordingPaused = false;
  214. },
  215. Qt::DirectConnection);
  216. /* Add controls dock */
  217. OBSBasicControls *controls = new OBSBasicControls(this);
  218. controlsDock = new OBSDock(this);
  219. controlsDock->setObjectName(QString::fromUtf8("controlsDock"));
  220. controlsDock->setWindowTitle(QTStr("Basic.Main.Controls"));
  221. /* Parenting is done there so controls will be deleted alongside controlsDock */
  222. controlsDock->setWidget(controls);
  223. addDockWidget(Qt::BottomDockWidgetArea, controlsDock);
  224. connect(controls, &OBSBasicControls::StreamButtonClicked, this, &OBSBasic::StreamActionTriggered);
  225. connect(controls, &OBSBasicControls::StartStreamMenuActionClicked, this, &OBSBasic::StartStreaming);
  226. connect(controls, &OBSBasicControls::StopStreamMenuActionClicked, this, &OBSBasic::StopStreaming);
  227. connect(controls, &OBSBasicControls::ForceStopStreamMenuActionClicked, this, &OBSBasic::ForceStopStreaming);
  228. connect(controls, &OBSBasicControls::BroadcastButtonClicked, this, &OBSBasic::BroadcastButtonClicked);
  229. connect(controls, &OBSBasicControls::RecordButtonClicked, this, &OBSBasic::RecordActionTriggered);
  230. connect(controls, &OBSBasicControls::PauseRecordButtonClicked, this, &OBSBasic::RecordPauseToggled);
  231. connect(controls, &OBSBasicControls::ReplayBufferButtonClicked, this, &OBSBasic::ReplayBufferActionTriggered);
  232. connect(controls, &OBSBasicControls::SaveReplayBufferButtonClicked, this, &OBSBasic::ReplayBufferSave);
  233. connect(controls, &OBSBasicControls::VirtualCamButtonClicked, this, &OBSBasic::VirtualCamActionTriggered);
  234. connect(controls, &OBSBasicControls::VirtualCamConfigButtonClicked, this, &OBSBasic::OpenVirtualCamConfig);
  235. connect(controls, &OBSBasicControls::StudioModeButtonClicked, this, &OBSBasic::TogglePreviewProgramMode);
  236. connect(controls, &OBSBasicControls::SettingsButtonClicked, this, &OBSBasic::on_action_Settings_triggered);
  237. startingDockLayout = saveState();
  238. statsDock = new OBSDock();
  239. statsDock->setObjectName(QStringLiteral("statsDock"));
  240. statsDock->setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable |
  241. QDockWidget::DockWidgetFloatable);
  242. statsDock->setWindowTitle(QTStr("Basic.Stats"));
  243. addDockWidget(Qt::BottomDockWidgetArea, statsDock);
  244. statsDock->setVisible(false);
  245. statsDock->setFloating(true);
  246. statsDock->resize(700, 200);
  247. copyActionsDynamicProperties();
  248. qRegisterMetaType<int64_t>("int64_t");
  249. qRegisterMetaType<uint32_t>("uint32_t");
  250. qRegisterMetaType<OBSScene>("OBSScene");
  251. qRegisterMetaType<OBSSceneItem>("OBSSceneItem");
  252. qRegisterMetaType<OBSSource>("OBSSource");
  253. qRegisterMetaType<obs_hotkey_id>("obs_hotkey_id");
  254. qRegisterMetaType<SavedProjectorInfo *>("SavedProjectorInfo *");
  255. ui->scenes->setAttribute(Qt::WA_MacShowFocusRect, false);
  256. ui->sources->setAttribute(Qt::WA_MacShowFocusRect, false);
  257. bool sceneGrid = config_get_bool(App()->GetUserConfig(), "BasicWindow", "gridMode");
  258. ui->scenes->SetGridMode(sceneGrid);
  259. if (sceneGrid)
  260. ui->actionSceneGridMode->setChecked(true);
  261. else
  262. ui->actionSceneListMode->setChecked(true);
  263. ui->scenes->setItemDelegate(new SceneRenameDelegate(ui->scenes));
  264. auto displayResize = [this]() {
  265. struct obs_video_info ovi;
  266. if (obs_get_video_info(&ovi))
  267. ResizePreview(ovi.base_width, ovi.base_height);
  268. UpdateContextBarVisibility();
  269. UpdatePreviewControls();
  270. dpi = devicePixelRatioF();
  271. };
  272. dpi = devicePixelRatioF();
  273. connect(windowHandle(), &QWindow::screenChanged, displayResize);
  274. connect(ui->preview, &OBSQTDisplay::DisplayResized, displayResize);
  275. /* TODO: Move these into window-basic-preview */
  276. /* Preview Scaling label */
  277. connect(ui->preview, &OBSBasicPreview::scalingChanged, ui->previewScalePercent,
  278. &OBSPreviewScalingLabel::PreviewScaleChanged);
  279. /* Preview Scaling dropdown */
  280. connect(ui->preview, &OBSBasicPreview::scalingChanged, ui->previewScalingMode,
  281. &OBSPreviewScalingComboBox::PreviewScaleChanged);
  282. connect(ui->preview, &OBSBasicPreview::fixedScalingChanged, ui->previewScalingMode,
  283. &OBSPreviewScalingComboBox::PreviewFixedScalingChanged);
  284. connect(ui->previewScalingMode, &OBSPreviewScalingComboBox::currentIndexChanged, this,
  285. &OBSBasic::PreviewScalingModeChanged);
  286. /* Preview Controls */
  287. connect(ui->previewXScrollBar, &QScrollBar::sliderMoved, ui->preview, &OBSBasicPreview::xScrollBarChanged);
  288. connect(ui->previewYScrollBar, &QScrollBar::valueChanged, ui->preview, &OBSBasicPreview::yScrollBarChanged);
  289. connect(ui->previewZoomInButton, &QPushButton::clicked, ui->preview, &OBSBasicPreview::increaseScalingLevel);
  290. connect(ui->previewZoomOutButton, &QPushButton::clicked, ui->preview, &OBSBasicPreview::decreaseScalingLevel);
  291. /* Preview Actions */
  292. connect(ui->actionScaleWindow, &QAction::triggered, this, &OBSBasic::setPreviewScalingWindow);
  293. connect(ui->actionScaleCanvas, &QAction::triggered, this, &OBSBasic::setPreviewScalingCanvas);
  294. connect(ui->actionScaleOutput, &QAction::triggered, this, &OBSBasic::setPreviewScalingOutput);
  295. connect(ui->actionPreviewZoomIn, &QAction::triggered, ui->preview, &OBSBasicPreview::increaseScalingLevel);
  296. connect(ui->actionPreviewZoomOut, &QAction::triggered, ui->preview, &OBSBasicPreview::decreaseScalingLevel);
  297. connect(ui->actionPreviewResetZoom, &QAction::triggered, ui->preview, &OBSBasicPreview::resetScalingLevel);
  298. connect(this, &OBSBasic::CanvasResized, ui->previewScalingMode, &OBSPreviewScalingComboBox::CanvasResized);
  299. connect(this, &OBSBasic::OutputResized, ui->previewScalingMode, &OBSPreviewScalingComboBox::OutputResized);
  300. delete shortcutFilter;
  301. shortcutFilter = CreateShortcutFilter();
  302. installEventFilter(shortcutFilter);
  303. stringstream name;
  304. name << "OBS " << App()->GetVersionString();
  305. blog(LOG_INFO, "%s", name.str().c_str());
  306. blog(LOG_INFO, "---------------------------------");
  307. UpdateTitleBar();
  308. connect(ui->scenes->itemDelegate(), &QAbstractItemDelegate::closeEditor, this, &OBSBasic::SceneNameEdited);
  309. cpuUsageInfo = os_cpu_usage_info_start();
  310. cpuUsageTimer = new QTimer(this);
  311. connect(cpuUsageTimer.data(), &QTimer::timeout, ui->statusbar, &OBSBasicStatusBar::UpdateCPUUsage);
  312. cpuUsageTimer->start(3000);
  313. diskFullTimer = new QTimer(this);
  314. connect(diskFullTimer, &QTimer::timeout, this, &OBSBasic::CheckDiskSpaceRemaining);
  315. renameScene = new QAction(QTStr("Rename"), ui->scenesDock);
  316. renameScene->setShortcutContext(Qt::WidgetWithChildrenShortcut);
  317. connect(renameScene, &QAction::triggered, this, &OBSBasic::EditSceneName);
  318. ui->scenesDock->addAction(renameScene);
  319. renameSource = new QAction(QTStr("Rename"), ui->sourcesDock);
  320. renameSource->setShortcutContext(Qt::WidgetWithChildrenShortcut);
  321. connect(renameSource, &QAction::triggered, this, &OBSBasic::EditSceneItemName);
  322. ui->sourcesDock->addAction(renameSource);
  323. #ifdef __APPLE__
  324. renameScene->setShortcut({Qt::Key_Return});
  325. renameSource->setShortcut({Qt::Key_Return});
  326. ui->actionRemoveSource->setShortcuts({Qt::Key_Backspace});
  327. ui->actionRemoveScene->setShortcuts({Qt::Key_Backspace});
  328. ui->actionCheckForUpdates->setMenuRole(QAction::AboutQtRole);
  329. ui->action_Settings->setMenuRole(QAction::PreferencesRole);
  330. ui->actionShowMacPermissions->setMenuRole(QAction::ApplicationSpecificRole);
  331. ui->actionE_xit->setMenuRole(QAction::QuitRole);
  332. #else
  333. renameScene->setShortcut({Qt::Key_F2});
  334. renameSource->setShortcut({Qt::Key_F2});
  335. #endif
  336. #ifdef __linux__
  337. ui->actionE_xit->setShortcut(Qt::CTRL | Qt::Key_Q);
  338. #endif
  339. auto addNudge = [this](const QKeySequence &seq, MoveDir direction, int distance) {
  340. QAction *nudge = new QAction(ui->preview);
  341. nudge->setShortcut(seq);
  342. nudge->setShortcutContext(Qt::WidgetShortcut);
  343. ui->preview->addAction(nudge);
  344. connect(nudge, &QAction::triggered, [this, distance, direction]() { Nudge(distance, direction); });
  345. };
  346. addNudge(Qt::Key_Up, MoveDir::Up, 1);
  347. addNudge(Qt::Key_Down, MoveDir::Down, 1);
  348. addNudge(Qt::Key_Left, MoveDir::Left, 1);
  349. addNudge(Qt::Key_Right, MoveDir::Right, 1);
  350. addNudge(Qt::SHIFT | Qt::Key_Up, MoveDir::Up, 10);
  351. addNudge(Qt::SHIFT | Qt::Key_Down, MoveDir::Down, 10);
  352. addNudge(Qt::SHIFT | Qt::Key_Left, MoveDir::Left, 10);
  353. addNudge(Qt::SHIFT | Qt::Key_Right, MoveDir::Right, 10);
  354. /* Setup dock toggle action
  355. * And hide all docks before restoring parent geometry */
  356. #define SETUP_DOCK(dock) \
  357. setupDockAction(dock); \
  358. ui->menuDocks->addAction(dock->toggleViewAction()); \
  359. dock->setVisible(false);
  360. SETUP_DOCK(ui->scenesDock);
  361. SETUP_DOCK(ui->sourcesDock);
  362. SETUP_DOCK(ui->mixerDock);
  363. SETUP_DOCK(ui->transitionsDock);
  364. SETUP_DOCK(controlsDock);
  365. SETUP_DOCK(statsDock);
  366. #undef SETUP_DOCK
  367. // Register shortcuts for Undo/Redo
  368. ui->actionMainUndo->setShortcut(Qt::CTRL | Qt::Key_Z);
  369. QList<QKeySequence> shrt;
  370. shrt << QKeySequence((Qt::CTRL | Qt::SHIFT) | Qt::Key_Z) << QKeySequence(Qt::CTRL | Qt::Key_Y);
  371. ui->actionMainRedo->setShortcuts(shrt);
  372. ui->actionMainUndo->setShortcutContext(Qt::ApplicationShortcut);
  373. ui->actionMainRedo->setShortcutContext(Qt::ApplicationShortcut);
  374. QPoint curPos;
  375. //restore parent window geometry
  376. const char *geometry = config_get_string(App()->GetUserConfig(), "BasicWindow", "geometry");
  377. if (geometry != NULL) {
  378. QByteArray byteArray = QByteArray::fromBase64(QByteArray(geometry));
  379. restoreGeometry(byteArray);
  380. QRect windowGeometry = normalGeometry();
  381. if (!WindowPositionValid(windowGeometry)) {
  382. QRect rect = QGuiApplication::primaryScreen()->geometry();
  383. setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, size(), rect));
  384. }
  385. curPos = pos();
  386. } else {
  387. QRect desktopRect = QGuiApplication::primaryScreen()->geometry();
  388. QSize adjSize = desktopRect.size() / 2 - size() / 2;
  389. curPos = QPoint(adjSize.width(), adjSize.height());
  390. }
  391. QPoint curSize(width(), height());
  392. QPoint statsDockSize(statsDock->width(), statsDock->height());
  393. QPoint statsDockPos = curSize / 2 - statsDockSize / 2;
  394. QPoint newPos = curPos + statsDockPos;
  395. statsDock->move(newPos);
  396. ui->actionReleaseNotes->setVisible(true);
  397. ui->previewDisabledWidget->setContextMenuPolicy(Qt::CustomContextMenu);
  398. connect(ui->enablePreviewButton, &QPushButton::clicked, this, &OBSBasic::TogglePreview);
  399. connect(ui->scenes, &SceneTree::scenesReordered, []() { OBSProjector::UpdateMultiviewProjectors(); });
  400. connect(App(), &OBSApp::StyleChanged, this, [this]() { OnEvent(OBS_FRONTEND_EVENT_THEME_CHANGED); });
  401. QActionGroup *actionGroup = new QActionGroup(this);
  402. actionGroup->addAction(ui->actionSceneListMode);
  403. actionGroup->addAction(ui->actionSceneGridMode);
  404. UpdatePreviewSafeAreas();
  405. UpdatePreviewSpacingHelpers();
  406. UpdatePreviewOverflowSettings();
  407. }
  408. static const double scaled_vals[] = {1.0, 1.25, (1.0 / 0.75), 1.5, (1.0 / 0.6), 1.75, 2.0, 2.25, 2.5, 2.75, 3.0, 0.0};
  409. #ifdef __APPLE__
  410. #define DEFAULT_CONTAINER "fragmented_mov"
  411. #elif OBS_RELEASE_CANDIDATE == 0 && OBS_BETA == 0
  412. #define DEFAULT_CONTAINER "mkv"
  413. #else
  414. #define DEFAULT_CONTAINER "hybrid_mp4"
  415. #endif
  416. bool OBSBasic::InitBasicConfigDefaults()
  417. {
  418. QList<QScreen *> screens = QGuiApplication::screens();
  419. if (!screens.size()) {
  420. OBSErrorBox(NULL, "There appears to be no monitors. Er, this "
  421. "technically shouldn't be possible.");
  422. return false;
  423. }
  424. QScreen *primaryScreen = QGuiApplication::primaryScreen();
  425. uint32_t cx = primaryScreen->size().width();
  426. uint32_t cy = primaryScreen->size().height();
  427. cx *= devicePixelRatioF();
  428. cy *= devicePixelRatioF();
  429. bool oldResolutionDefaults = config_get_bool(App()->GetUserConfig(), "General", "Pre19Defaults");
  430. /* use 1920x1080 for new default base res if main monitor is above
  431. * 1920x1080, but don't apply for people from older builds -- only to
  432. * new users */
  433. if (!oldResolutionDefaults && (cx * cy) > (1920 * 1080)) {
  434. cx = 1920;
  435. cy = 1080;
  436. }
  437. bool changed = false;
  438. /* ----------------------------------------------------- */
  439. /* move over old FFmpeg track settings */
  440. if (config_has_user_value(activeConfiguration, "AdvOut", "FFAudioTrack") &&
  441. !config_has_user_value(activeConfiguration, "AdvOut", "Pre22.1Settings")) {
  442. int track = (int)config_get_int(activeConfiguration, "AdvOut", "FFAudioTrack");
  443. config_set_int(activeConfiguration, "AdvOut", "FFAudioMixes", 1LL << (track - 1));
  444. config_set_bool(activeConfiguration, "AdvOut", "Pre22.1Settings", true);
  445. changed = true;
  446. }
  447. /* ----------------------------------------------------- */
  448. /* move over mixer values in advanced if older config */
  449. if (config_has_user_value(activeConfiguration, "AdvOut", "RecTrackIndex") &&
  450. !config_has_user_value(activeConfiguration, "AdvOut", "RecTracks")) {
  451. uint64_t track = config_get_uint(activeConfiguration, "AdvOut", "RecTrackIndex");
  452. track = 1ULL << (track - 1);
  453. config_set_uint(activeConfiguration, "AdvOut", "RecTracks", track);
  454. config_remove_value(activeConfiguration, "AdvOut", "RecTrackIndex");
  455. changed = true;
  456. }
  457. /* ----------------------------------------------------- */
  458. /* set twitch chat extensions to "both" if prev version */
  459. /* is under 24.1 */
  460. if (config_get_bool(App()->GetUserConfig(), "General", "Pre24.1Defaults") &&
  461. !config_has_user_value(activeConfiguration, "Twitch", "AddonChoice")) {
  462. config_set_int(activeConfiguration, "Twitch", "AddonChoice", 3);
  463. changed = true;
  464. }
  465. /* ----------------------------------------------------- */
  466. /* move bitrate enforcement setting to new value */
  467. if (config_has_user_value(activeConfiguration, "SimpleOutput", "EnforceBitrate") &&
  468. !config_has_user_value(activeConfiguration, "Stream1", "IgnoreRecommended") &&
  469. !config_has_user_value(activeConfiguration, "Stream1", "MovedOldEnforce")) {
  470. bool enforce = config_get_bool(activeConfiguration, "SimpleOutput", "EnforceBitrate");
  471. config_set_bool(activeConfiguration, "Stream1", "IgnoreRecommended", !enforce);
  472. config_set_bool(activeConfiguration, "Stream1", "MovedOldEnforce", true);
  473. changed = true;
  474. }
  475. /* ----------------------------------------------------- */
  476. /* enforce minimum retry delay of 1 second prior to 27.1 */
  477. if (config_has_user_value(activeConfiguration, "Output", "RetryDelay")) {
  478. int retryDelay = config_get_uint(activeConfiguration, "Output", "RetryDelay");
  479. if (retryDelay < 1) {
  480. config_set_uint(activeConfiguration, "Output", "RetryDelay", 1);
  481. changed = true;
  482. }
  483. }
  484. /* ----------------------------------------------------- */
  485. /* Migrate old container selection (if any) to new key. */
  486. auto MigrateFormat = [&](const char *section) {
  487. bool has_old_key = config_has_user_value(activeConfiguration, section, "RecFormat");
  488. bool has_new_key = config_has_user_value(activeConfiguration, section, "RecFormat2");
  489. if (!has_new_key && !has_old_key)
  490. return;
  491. string old_format =
  492. config_get_string(activeConfiguration, section, has_new_key ? "RecFormat2" : "RecFormat");
  493. string new_format = old_format;
  494. if (old_format == "ts")
  495. new_format = "mpegts";
  496. else if (old_format == "m3u8")
  497. new_format = "hls";
  498. else if (old_format == "fmp4")
  499. new_format = "fragmented_mp4";
  500. else if (old_format == "fmov")
  501. new_format = "fragmented_mov";
  502. if (new_format != old_format || !has_new_key) {
  503. config_set_string(activeConfiguration, section, "RecFormat2", new_format.c_str());
  504. changed = true;
  505. }
  506. };
  507. MigrateFormat("AdvOut");
  508. MigrateFormat("SimpleOutput");
  509. /* ----------------------------------------------------- */
  510. /* Migrate output scale setting to GPU scaling options. */
  511. if (config_get_bool(activeConfiguration, "AdvOut", "Rescale") &&
  512. !config_has_user_value(activeConfiguration, "AdvOut", "RescaleFilter")) {
  513. config_set_int(activeConfiguration, "AdvOut", "RescaleFilter", OBS_SCALE_BILINEAR);
  514. }
  515. if (config_get_bool(activeConfiguration, "AdvOut", "RecRescale") &&
  516. !config_has_user_value(activeConfiguration, "AdvOut", "RecRescaleFilter")) {
  517. config_set_int(activeConfiguration, "AdvOut", "RecRescaleFilter", OBS_SCALE_BILINEAR);
  518. }
  519. /* ----------------------------------------------------- */
  520. if (changed) {
  521. activeConfiguration.SaveSafe("tmp");
  522. }
  523. /* ----------------------------------------------------- */
  524. config_set_default_string(activeConfiguration, "Output", "Mode", "Simple");
  525. config_set_default_bool(activeConfiguration, "Stream1", "IgnoreRecommended", false);
  526. config_set_default_bool(activeConfiguration, "Stream1", "EnableMultitrackVideo", false);
  527. config_set_default_bool(activeConfiguration, "Stream1", "MultitrackVideoMaximumAggregateBitrateAuto", true);
  528. config_set_default_bool(activeConfiguration, "Stream1", "MultitrackVideoMaximumVideoTracksAuto", true);
  529. config_set_default_string(activeConfiguration, "SimpleOutput", "FilePath", GetDefaultVideoSavePath().c_str());
  530. config_set_default_string(activeConfiguration, "SimpleOutput", "RecFormat2", DEFAULT_CONTAINER);
  531. config_set_default_uint(activeConfiguration, "SimpleOutput", "VBitrate", 2500);
  532. config_set_default_uint(activeConfiguration, "SimpleOutput", "ABitrate", 160);
  533. config_set_default_bool(activeConfiguration, "SimpleOutput", "UseAdvanced", false);
  534. config_set_default_string(activeConfiguration, "SimpleOutput", "Preset", "veryfast");
  535. config_set_default_string(activeConfiguration, "SimpleOutput", "NVENCPreset2", "p5");
  536. config_set_default_string(activeConfiguration, "SimpleOutput", "RecQuality", "Stream");
  537. config_set_default_bool(activeConfiguration, "SimpleOutput", "RecRB", false);
  538. config_set_default_int(activeConfiguration, "SimpleOutput", "RecRBTime", 20);
  539. config_set_default_int(activeConfiguration, "SimpleOutput", "RecRBSize", 512);
  540. config_set_default_string(activeConfiguration, "SimpleOutput", "RecRBPrefix", "Replay");
  541. config_set_default_string(activeConfiguration, "SimpleOutput", "StreamAudioEncoder", "aac");
  542. config_set_default_string(activeConfiguration, "SimpleOutput", "RecAudioEncoder", "aac");
  543. config_set_default_uint(activeConfiguration, "SimpleOutput", "RecTracks", (1 << 0));
  544. config_set_default_bool(activeConfiguration, "AdvOut", "ApplyServiceSettings", true);
  545. config_set_default_bool(activeConfiguration, "AdvOut", "UseRescale", false);
  546. config_set_default_uint(activeConfiguration, "AdvOut", "TrackIndex", 1);
  547. config_set_default_uint(activeConfiguration, "AdvOut", "VodTrackIndex", 2);
  548. config_set_default_string(activeConfiguration, "AdvOut", "Encoder", "obs_x264");
  549. config_set_default_string(activeConfiguration, "AdvOut", "RecType", "Standard");
  550. config_set_default_string(activeConfiguration, "AdvOut", "RecFilePath", GetDefaultVideoSavePath().c_str());
  551. config_set_default_string(activeConfiguration, "AdvOut", "RecFormat2", DEFAULT_CONTAINER);
  552. config_set_default_bool(activeConfiguration, "AdvOut", "RecUseRescale", false);
  553. config_set_default_uint(activeConfiguration, "AdvOut", "RecTracks", (1 << 0));
  554. config_set_default_string(activeConfiguration, "AdvOut", "RecEncoder", "none");
  555. config_set_default_uint(activeConfiguration, "AdvOut", "FLVTrack", 1);
  556. config_set_default_uint(activeConfiguration, "AdvOut", "StreamMultiTrackAudioMixes", 1);
  557. config_set_default_bool(activeConfiguration, "AdvOut", "FFOutputToFile", true);
  558. config_set_default_string(activeConfiguration, "AdvOut", "FFFilePath", GetDefaultVideoSavePath().c_str());
  559. config_set_default_string(activeConfiguration, "AdvOut", "FFExtension", "mp4");
  560. config_set_default_uint(activeConfiguration, "AdvOut", "FFVBitrate", 2500);
  561. config_set_default_uint(activeConfiguration, "AdvOut", "FFVGOPSize", 250);
  562. config_set_default_bool(activeConfiguration, "AdvOut", "FFUseRescale", false);
  563. config_set_default_bool(activeConfiguration, "AdvOut", "FFIgnoreCompat", false);
  564. config_set_default_uint(activeConfiguration, "AdvOut", "FFABitrate", 160);
  565. config_set_default_uint(activeConfiguration, "AdvOut", "FFAudioMixes", 1);
  566. config_set_default_uint(activeConfiguration, "AdvOut", "Track1Bitrate", 160);
  567. config_set_default_uint(activeConfiguration, "AdvOut", "Track2Bitrate", 160);
  568. config_set_default_uint(activeConfiguration, "AdvOut", "Track3Bitrate", 160);
  569. config_set_default_uint(activeConfiguration, "AdvOut", "Track4Bitrate", 160);
  570. config_set_default_uint(activeConfiguration, "AdvOut", "Track5Bitrate", 160);
  571. config_set_default_uint(activeConfiguration, "AdvOut", "Track6Bitrate", 160);
  572. config_set_default_uint(activeConfiguration, "AdvOut", "RecSplitFileTime", 15);
  573. config_set_default_uint(activeConfiguration, "AdvOut", "RecSplitFileSize", 2048);
  574. config_set_default_bool(activeConfiguration, "AdvOut", "RecRB", false);
  575. config_set_default_uint(activeConfiguration, "AdvOut", "RecRBTime", 20);
  576. config_set_default_int(activeConfiguration, "AdvOut", "RecRBSize", 512);
  577. config_set_default_uint(activeConfiguration, "Video", "BaseCX", cx);
  578. config_set_default_uint(activeConfiguration, "Video", "BaseCY", cy);
  579. /* don't allow BaseCX/BaseCY to be susceptible to defaults changing */
  580. if (!config_has_user_value(activeConfiguration, "Video", "BaseCX") ||
  581. !config_has_user_value(activeConfiguration, "Video", "BaseCY")) {
  582. config_set_uint(activeConfiguration, "Video", "BaseCX", cx);
  583. config_set_uint(activeConfiguration, "Video", "BaseCY", cy);
  584. config_save_safe(activeConfiguration, "tmp", nullptr);
  585. }
  586. config_set_default_string(activeConfiguration, "Output", "FilenameFormatting", "%CCYY-%MM-%DD %hh-%mm-%ss");
  587. config_set_default_bool(activeConfiguration, "Output", "DelayEnable", false);
  588. config_set_default_uint(activeConfiguration, "Output", "DelaySec", 20);
  589. config_set_default_bool(activeConfiguration, "Output", "DelayPreserve", true);
  590. config_set_default_bool(activeConfiguration, "Output", "Reconnect", true);
  591. config_set_default_uint(activeConfiguration, "Output", "RetryDelay", 2);
  592. config_set_default_uint(activeConfiguration, "Output", "MaxRetries", 25);
  593. config_set_default_string(activeConfiguration, "Output", "BindIP", "default");
  594. config_set_default_string(activeConfiguration, "Output", "IPFamily", "IPv4+IPv6");
  595. config_set_default_bool(activeConfiguration, "Output", "NewSocketLoopEnable", false);
  596. config_set_default_bool(activeConfiguration, "Output", "LowLatencyEnable", false);
  597. int i = 0;
  598. uint32_t scale_cx = cx;
  599. uint32_t scale_cy = cy;
  600. /* use a default scaled resolution that has a pixel count no higher
  601. * than 1280x720 */
  602. while (((scale_cx * scale_cy) > (1280 * 720)) && scaled_vals[i] > 0.0) {
  603. double scale = scaled_vals[i++];
  604. scale_cx = uint32_t(double(cx) / scale);
  605. scale_cy = uint32_t(double(cy) / scale);
  606. }
  607. config_set_default_uint(activeConfiguration, "Video", "OutputCX", scale_cx);
  608. config_set_default_uint(activeConfiguration, "Video", "OutputCY", scale_cy);
  609. /* don't allow OutputCX/OutputCY to be susceptible to defaults
  610. * changing */
  611. if (!config_has_user_value(activeConfiguration, "Video", "OutputCX") ||
  612. !config_has_user_value(activeConfiguration, "Video", "OutputCY")) {
  613. config_set_uint(activeConfiguration, "Video", "OutputCX", scale_cx);
  614. config_set_uint(activeConfiguration, "Video", "OutputCY", scale_cy);
  615. config_save_safe(activeConfiguration, "tmp", nullptr);
  616. }
  617. config_set_default_uint(activeConfiguration, "Video", "FPSType", 0);
  618. config_set_default_string(activeConfiguration, "Video", "FPSCommon", "30");
  619. config_set_default_uint(activeConfiguration, "Video", "FPSInt", 30);
  620. config_set_default_uint(activeConfiguration, "Video", "FPSNum", 30);
  621. config_set_default_uint(activeConfiguration, "Video", "FPSDen", 1);
  622. config_set_default_string(activeConfiguration, "Video", "ScaleType", "bicubic");
  623. config_set_default_string(activeConfiguration, "Video", "ColorFormat", "NV12");
  624. config_set_default_string(activeConfiguration, "Video", "ColorSpace", "709");
  625. config_set_default_string(activeConfiguration, "Video", "ColorRange", "Partial");
  626. config_set_default_uint(activeConfiguration, "Video", "SdrWhiteLevel", 300);
  627. config_set_default_uint(activeConfiguration, "Video", "HdrNominalPeakLevel", 1000);
  628. config_set_default_string(activeConfiguration, "Audio", "MonitoringDeviceId", "default");
  629. config_set_default_string(activeConfiguration, "Audio", "MonitoringDeviceName",
  630. Str("Basic.Settings.Advanced.Audio.MonitoringDevice"
  631. ".Default"));
  632. config_set_default_uint(activeConfiguration, "Audio", "SampleRate", 48000);
  633. config_set_default_string(activeConfiguration, "Audio", "ChannelSetup", "Stereo");
  634. config_set_default_double(activeConfiguration, "Audio", "MeterDecayRate", VOLUME_METER_DECAY_FAST);
  635. config_set_default_uint(activeConfiguration, "Audio", "PeakMeterType", 0);
  636. CheckExistingCookieId();
  637. return true;
  638. }
  639. void OBSBasic::InitBasicConfigDefaults2()
  640. {
  641. bool oldEncDefaults = config_get_bool(App()->GetUserConfig(), "General", "Pre23Defaults");
  642. bool useNV = EncoderAvailable("ffmpeg_nvenc") && !oldEncDefaults;
  643. config_set_default_string(activeConfiguration, "SimpleOutput", "StreamEncoder",
  644. useNV ? SIMPLE_ENCODER_NVENC : SIMPLE_ENCODER_X264);
  645. config_set_default_string(activeConfiguration, "SimpleOutput", "RecEncoder",
  646. useNV ? SIMPLE_ENCODER_NVENC : SIMPLE_ENCODER_X264);
  647. const char *aac_default = "ffmpeg_aac";
  648. if (EncoderAvailable("CoreAudio_AAC"))
  649. aac_default = "CoreAudio_AAC";
  650. else if (EncoderAvailable("libfdk_aac"))
  651. aac_default = "libfdk_aac";
  652. config_set_default_string(activeConfiguration, "AdvOut", "AudioEncoder", aac_default);
  653. config_set_default_string(activeConfiguration, "AdvOut", "RecAudioEncoder", aac_default);
  654. }
  655. bool OBSBasic::InitBasicConfig()
  656. {
  657. ProfileScope("OBSBasic::InitBasicConfig");
  658. RefreshProfiles(true);
  659. const std::string currentProfileName{config_get_string(App()->GetUserConfig(), "Basic", "Profile")};
  660. const std::optional<OBSProfile> currentProfile = GetProfileByName(currentProfileName);
  661. const std::optional<OBSProfile> foundProfile = GetProfileByName(opt_starting_profile);
  662. try {
  663. if (foundProfile) {
  664. ActivateProfile(foundProfile.value());
  665. } else if (currentProfile) {
  666. ActivateProfile(currentProfile.value());
  667. } else {
  668. const OBSProfile &newProfile = CreateProfile(currentProfileName);
  669. ActivateProfile(newProfile);
  670. }
  671. } catch (const std::logic_error &) {
  672. OBSErrorBox(NULL, "Failed to open basic.ini: %d", -1);
  673. return false;
  674. }
  675. return true;
  676. }
  677. void OBSBasic::InitOBSCallbacks()
  678. {
  679. ProfileScope("OBSBasic::InitOBSCallbacks");
  680. signalHandlers.reserve(signalHandlers.size() + 9);
  681. signalHandlers.emplace_back(obs_get_signal_handler(), "source_create", OBSBasic::SourceCreated, this);
  682. signalHandlers.emplace_back(obs_get_signal_handler(), "source_remove", OBSBasic::SourceRemoved, this);
  683. signalHandlers.emplace_back(obs_get_signal_handler(), "source_activate", OBSBasic::SourceActivated, this);
  684. signalHandlers.emplace_back(obs_get_signal_handler(), "source_deactivate", OBSBasic::SourceDeactivated, this);
  685. signalHandlers.emplace_back(obs_get_signal_handler(), "source_audio_activate", OBSBasic::SourceAudioActivated,
  686. this);
  687. signalHandlers.emplace_back(obs_get_signal_handler(), "source_audio_deactivate",
  688. OBSBasic::SourceAudioDeactivated, this);
  689. signalHandlers.emplace_back(obs_get_signal_handler(), "source_rename", OBSBasic::SourceRenamed, this);
  690. signalHandlers.emplace_back(
  691. obs_get_signal_handler(), "source_filter_add",
  692. [](void *data, calldata_t *) {
  693. QMetaObject::invokeMethod(static_cast<OBSBasic *>(data), "UpdateEditMenu",
  694. Qt::QueuedConnection);
  695. },
  696. this);
  697. signalHandlers.emplace_back(
  698. obs_get_signal_handler(), "source_filter_remove",
  699. [](void *data, calldata_t *) {
  700. QMetaObject::invokeMethod(static_cast<OBSBasic *>(data), "UpdateEditMenu",
  701. Qt::QueuedConnection);
  702. },
  703. this);
  704. }
  705. #define STARTUP_SEPARATOR "==== Startup complete ==============================================="
  706. #define SHUTDOWN_SEPARATOR "==== Shutting down =================================================="
  707. #define UNSUPPORTED_ERROR \
  708. "Failed to initialize video:\n\nRequired graphics API functionality " \
  709. "not found. Your GPU may not be supported."
  710. #define UNKNOWN_ERROR \
  711. "Failed to initialize video. Your GPU may not be supported, " \
  712. "or your graphics drivers may need to be updated."
  713. static inline void LogEncoders()
  714. {
  715. constexpr uint32_t hide_flags = OBS_ENCODER_CAP_DEPRECATED | OBS_ENCODER_CAP_INTERNAL;
  716. auto list_encoders = [](obs_encoder_type type) {
  717. size_t idx = 0;
  718. const char *encoder_type;
  719. while (obs_enum_encoder_types(idx++, &encoder_type)) {
  720. if (obs_get_encoder_caps(encoder_type) & hide_flags ||
  721. obs_get_encoder_type(encoder_type) != type) {
  722. continue;
  723. }
  724. blog(LOG_INFO, "\t- %s (%s)", encoder_type, obs_encoder_get_display_name(encoder_type));
  725. }
  726. };
  727. blog(LOG_INFO, "---------------------------------");
  728. blog(LOG_INFO, "Available Encoders:");
  729. blog(LOG_INFO, " Video Encoders:");
  730. list_encoders(OBS_ENCODER_VIDEO);
  731. blog(LOG_INFO, " Audio Encoders:");
  732. list_encoders(OBS_ENCODER_AUDIO);
  733. }
  734. void OBSBasic::OBSInit()
  735. {
  736. ProfileScope("OBSBasic::OBSInit");
  737. if (!InitBasicConfig())
  738. throw "Failed to load basic.ini";
  739. if (!ResetAudio())
  740. throw "Failed to initialize audio";
  741. int ret = 0;
  742. ret = ResetVideo();
  743. switch (ret) {
  744. case OBS_VIDEO_MODULE_NOT_FOUND:
  745. throw "Failed to initialize video: Graphics module not found";
  746. case OBS_VIDEO_NOT_SUPPORTED:
  747. throw UNSUPPORTED_ERROR;
  748. case OBS_VIDEO_INVALID_PARAM:
  749. throw "Failed to initialize video: Invalid parameters";
  750. default:
  751. if (ret != OBS_VIDEO_SUCCESS)
  752. throw UNKNOWN_ERROR;
  753. }
  754. /* load audio monitoring */
  755. if (obs_audio_monitoring_available()) {
  756. const char *device_name = config_get_string(activeConfiguration, "Audio", "MonitoringDeviceName");
  757. const char *device_id = config_get_string(activeConfiguration, "Audio", "MonitoringDeviceId");
  758. obs_set_audio_monitoring_device(device_name, device_id);
  759. blog(LOG_INFO, "Audio monitoring device:\n\tname: %s\n\tid: %s", device_name, device_id);
  760. }
  761. InitOBSCallbacks();
  762. InitHotkeys();
  763. ui->preview->Init();
  764. /* hack to prevent elgato from loading its own QtNetwork that it tries
  765. * to ship with */
  766. #if defined(_WIN32) && !defined(_DEBUG)
  767. LoadLibraryW(L"Qt6Network");
  768. #endif
  769. struct obs_module_failure_info mfi;
  770. /* Safe Mode disables third-party plugins so we don't need to add earch
  771. * paths outside the OBS bundle/installation. */
  772. if (safe_mode || disable_3p_plugins) {
  773. SetSafeModuleNames();
  774. } else {
  775. AddExtraModulePaths();
  776. }
  777. /* Modules can access frontend information (i.e. profile and scene collection data) during their initialization, and some modules (e.g. obs-websockets) are known to use the filesystem location of the current profile in their own code.
  778. Thus the profile and scene collection discovery needs to happen before any access to that information (but after intializing global settings) to ensure legacy code gets valid path information.
  779. */
  780. RefreshSceneCollections(true);
  781. blog(LOG_INFO, "---------------------------------");
  782. obs_load_all_modules2(&mfi);
  783. blog(LOG_INFO, "---------------------------------");
  784. obs_log_loaded_modules();
  785. blog(LOG_INFO, "---------------------------------");
  786. obs_post_load_modules();
  787. BPtr<char *> failed_modules = mfi.failed_modules;
  788. #ifdef BROWSER_AVAILABLE
  789. cef = obs_browser_init_panel();
  790. cef_js_avail = cef && obs_browser_qcef_version() >= 3;
  791. #endif
  792. vcamEnabled = (obs_get_output_flags(VIRTUAL_CAM_ID) & OBS_OUTPUT_VIDEO) != 0;
  793. if (vcamEnabled) {
  794. emit VirtualCamEnabled();
  795. }
  796. UpdateProfileEncoders();
  797. LogEncoders();
  798. blog(LOG_INFO, STARTUP_SEPARATOR);
  799. if (!InitService())
  800. throw "Failed to initialize service";
  801. ResetOutputs();
  802. CreateHotkeys();
  803. InitPrimitives();
  804. sceneDuplicationMode = config_get_bool(App()->GetUserConfig(), "BasicWindow", "SceneDuplicationMode");
  805. swapScenesMode = config_get_bool(App()->GetUserConfig(), "BasicWindow", "SwapScenesMode");
  806. editPropertiesMode = config_get_bool(App()->GetUserConfig(), "BasicWindow", "EditPropertiesMode");
  807. if (!opt_studio_mode) {
  808. SetPreviewProgramMode(config_get_bool(App()->GetUserConfig(), "BasicWindow", "PreviewProgramMode"));
  809. } else {
  810. SetPreviewProgramMode(true);
  811. opt_studio_mode = false;
  812. }
  813. #define SET_VISIBILITY(name, control) \
  814. do { \
  815. if (config_has_user_value(App()->GetUserConfig(), "BasicWindow", name)) { \
  816. bool visible = config_get_bool(App()->GetUserConfig(), "BasicWindow", name); \
  817. ui->control->setChecked(visible); \
  818. } \
  819. } while (false)
  820. SET_VISIBILITY("ShowListboxToolbars", toggleListboxToolbars);
  821. SET_VISIBILITY("ShowStatusBar", toggleStatusBar);
  822. #undef SET_VISIBILITY
  823. bool sourceIconsVisible = config_get_bool(App()->GetUserConfig(), "BasicWindow", "ShowSourceIcons");
  824. ui->toggleSourceIcons->setChecked(sourceIconsVisible);
  825. bool contextVisible = config_get_bool(App()->GetUserConfig(), "BasicWindow", "ShowContextToolbars");
  826. ui->toggleContextBar->setChecked(contextVisible);
  827. ui->contextContainer->setVisible(contextVisible);
  828. if (contextVisible)
  829. UpdateContextBar(true);
  830. UpdateEditMenu();
  831. {
  832. ProfileScope("OBSBasic::Load");
  833. const std::string sceneCollectionName{
  834. config_get_string(App()->GetUserConfig(), "Basic", "SceneCollection")};
  835. std::optional<OBS::SceneCollection> configuredCollection =
  836. GetSceneCollectionByName(sceneCollectionName);
  837. std::optional<OBS::SceneCollection> foundCollection = GetSceneCollectionByName(opt_starting_collection);
  838. if (foundCollection) {
  839. ActivateSceneCollection(foundCollection.value());
  840. } else if (configuredCollection) {
  841. ActivateSceneCollection(configuredCollection.value());
  842. } else {
  843. disableSaving--;
  844. SetupNewSceneCollection(sceneCollectionName);
  845. disableSaving++;
  846. }
  847. if (foundCollection || configuredCollection) {
  848. disableSaving--;
  849. OnEvent(OBS_FRONTEND_EVENT_SCENE_COLLECTION_LIST_CHANGED);
  850. OnEvent(OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGED);
  851. OnEvent(OBS_FRONTEND_EVENT_SCENE_CHANGED);
  852. OnEvent(OBS_FRONTEND_EVENT_PREVIEW_SCENE_CHANGED);
  853. disableSaving++;
  854. }
  855. }
  856. loaded = true;
  857. previewEnabled = config_get_bool(App()->GetUserConfig(), "BasicWindow", "PreviewEnabled");
  858. if (!previewEnabled && !IsPreviewProgramMode())
  859. QMetaObject::invokeMethod(this, "EnablePreviewDisplay", Qt::QueuedConnection,
  860. Q_ARG(bool, previewEnabled));
  861. else if (!previewEnabled && IsPreviewProgramMode())
  862. QMetaObject::invokeMethod(this, "EnablePreviewDisplay", Qt::QueuedConnection, Q_ARG(bool, true));
  863. disableSaving--;
  864. auto addDisplay = [this](OBSQTDisplay *window) {
  865. obs_display_add_draw_callback(window->GetDisplay(), OBSBasic::RenderMain, this);
  866. struct obs_video_info ovi;
  867. if (obs_get_video_info(&ovi))
  868. ResizePreview(ovi.base_width, ovi.base_height);
  869. };
  870. connect(ui->preview, &OBSQTDisplay::DisplayCreated, addDisplay);
  871. /* Show the main window, unless the tray icon isn't available
  872. * or neither the setting nor flag for starting minimized is set. */
  873. bool sysTrayEnabled = config_get_bool(App()->GetUserConfig(), "BasicWindow", "SysTrayEnabled");
  874. bool sysTrayWhenStarted = config_get_bool(App()->GetUserConfig(), "BasicWindow", "SysTrayWhenStarted");
  875. bool hideWindowOnStart = QSystemTrayIcon::isSystemTrayAvailable() && sysTrayEnabled &&
  876. (opt_minimize_tray || sysTrayWhenStarted);
  877. #ifdef _WIN32
  878. SetWin32DropStyle(this);
  879. if (!hideWindowOnStart)
  880. show();
  881. #endif
  882. bool alwaysOnTop = config_get_bool(App()->GetUserConfig(), "BasicWindow", "AlwaysOnTop");
  883. #ifdef ENABLE_WAYLAND
  884. bool isWayland = obs_get_nix_platform() == OBS_NIX_PLATFORM_WAYLAND;
  885. #else
  886. bool isWayland = false;
  887. #endif
  888. if (!isWayland && (alwaysOnTop || opt_always_on_top)) {
  889. SetAlwaysOnTop(this, true);
  890. ui->actionAlwaysOnTop->setChecked(true);
  891. } else if (isWayland) {
  892. if (opt_always_on_top)
  893. blog(LOG_INFO, "Always On Top not available on Wayland, ignoring.");
  894. ui->actionAlwaysOnTop->setEnabled(false);
  895. ui->actionAlwaysOnTop->setVisible(false);
  896. }
  897. #ifndef _WIN32
  898. if (!hideWindowOnStart)
  899. show();
  900. #endif
  901. /* setup stats dock */
  902. OBSBasicStats *statsDlg = new OBSBasicStats(statsDock, false);
  903. statsDock->setWidget(statsDlg);
  904. /* ----------------------------- */
  905. /* add custom browser docks */
  906. #if defined(BROWSER_AVAILABLE) && defined(YOUTUBE_ENABLED)
  907. YouTubeAppDock::CleanupYouTubeUrls();
  908. #endif
  909. #ifdef BROWSER_AVAILABLE
  910. if (cef) {
  911. QAction *action = new QAction(QTStr("Basic.MainMenu.Docks."
  912. "CustomBrowserDocks"),
  913. this);
  914. ui->menuDocks->insertAction(ui->scenesDock->toggleViewAction(), action);
  915. connect(action, &QAction::triggered, this, &OBSBasic::ManageExtraBrowserDocks);
  916. ui->menuDocks->insertSeparator(ui->scenesDock->toggleViewAction());
  917. LoadExtraBrowserDocks();
  918. }
  919. #endif
  920. #ifdef YOUTUBE_ENABLED
  921. /* setup YouTube app dock */
  922. if (YouTubeAppDock::IsYTServiceSelected())
  923. NewYouTubeAppDock();
  924. #endif
  925. const char *dockStateStr = config_get_string(App()->GetUserConfig(), "BasicWindow", "DockState");
  926. if (!dockStateStr) {
  927. on_resetDocks_triggered(true);
  928. } else {
  929. QByteArray dockState = QByteArray::fromBase64(QByteArray(dockStateStr));
  930. if (!restoreState(dockState))
  931. on_resetDocks_triggered(true);
  932. }
  933. bool pre23Defaults = config_get_bool(App()->GetUserConfig(), "General", "Pre23Defaults");
  934. if (pre23Defaults) {
  935. bool resetDockLock23 = config_get_bool(App()->GetUserConfig(), "General", "ResetDockLock23");
  936. if (!resetDockLock23) {
  937. config_set_bool(App()->GetUserConfig(), "General", "ResetDockLock23", true);
  938. config_remove_value(App()->GetUserConfig(), "BasicWindow", "DocksLocked");
  939. config_save_safe(App()->GetUserConfig(), "tmp", nullptr);
  940. }
  941. }
  942. bool docksLocked = config_get_bool(App()->GetUserConfig(), "BasicWindow", "DocksLocked");
  943. on_lockDocks_toggled(docksLocked);
  944. ui->lockDocks->blockSignals(true);
  945. ui->lockDocks->setChecked(docksLocked);
  946. ui->lockDocks->blockSignals(false);
  947. bool sideDocks = config_get_bool(App()->GetUserConfig(), "BasicWindow", "SideDocks");
  948. on_sideDocks_toggled(sideDocks);
  949. ui->sideDocks->blockSignals(true);
  950. ui->sideDocks->setChecked(sideDocks);
  951. ui->sideDocks->blockSignals(false);
  952. SystemTray(true);
  953. TaskbarOverlayInit();
  954. #ifdef __APPLE__
  955. disableColorSpaceConversion(this);
  956. #endif
  957. bool has_last_version = config_has_user_value(App()->GetAppConfig(), "General", "LastVersion");
  958. bool first_run = config_get_bool(App()->GetUserConfig(), "General", "FirstRun");
  959. if (!first_run) {
  960. config_set_bool(App()->GetUserConfig(), "General", "FirstRun", true);
  961. config_save_safe(App()->GetUserConfig(), "tmp", nullptr);
  962. }
  963. if (!first_run && !has_last_version && !Active())
  964. QMetaObject::invokeMethod(this, "on_autoConfigure_triggered", Qt::QueuedConnection);
  965. #if (defined(_WIN32) || defined(__APPLE__)) && (OBS_RELEASE_CANDIDATE > 0 || OBS_BETA > 0)
  966. /* Automatically set branch to "beta" the first time a pre-release build is run. */
  967. if (!config_get_bool(App()->GetAppConfig(), "General", "AutoBetaOptIn")) {
  968. config_set_string(App()->GetAppConfig(), "General", "UpdateBranch", "beta");
  969. config_set_bool(App()->GetAppConfig(), "General", "AutoBetaOptIn", true);
  970. config_save_safe(App()->GetAppConfig(), "tmp", nullptr);
  971. }
  972. #endif
  973. TimedCheckForUpdates();
  974. ToggleMixerLayout(config_get_bool(App()->GetUserConfig(), "BasicWindow", "VerticalVolControl"));
  975. if (config_get_bool(activeConfiguration, "General", "OpenStatsOnStartup"))
  976. on_stats_triggered();
  977. OBSBasicStats::InitializeValues();
  978. /* ----------------------- */
  979. /* Add multiview menu */
  980. ui->viewMenu->addSeparator();
  981. connect(ui->viewMenu->menuAction(), &QAction::hovered, this, &OBSBasic::updateMultiviewProjectorMenu);
  982. OBSBasic::updateMultiviewProjectorMenu();
  983. ui->sources->UpdateIcons();
  984. #if !defined(_WIN32)
  985. delete ui->actionShowCrashLogs;
  986. delete ui->actionUploadLastCrashLog;
  987. delete ui->menuCrashLogs;
  988. delete ui->actionRepair;
  989. ui->actionShowCrashLogs = nullptr;
  990. ui->actionUploadLastCrashLog = nullptr;
  991. ui->menuCrashLogs = nullptr;
  992. ui->actionRepair = nullptr;
  993. #if !defined(__APPLE__)
  994. delete ui->actionCheckForUpdates;
  995. ui->actionCheckForUpdates = nullptr;
  996. #endif
  997. #endif
  998. #ifdef __APPLE__
  999. /* Remove OBS' Fullscreen Interface menu in favor of the one macOS adds by default */
  1000. delete ui->actionFullscreenInterface;
  1001. ui->actionFullscreenInterface = nullptr;
  1002. #else
  1003. /* Don't show menu to raise macOS-only permissions dialog */
  1004. delete ui->actionShowMacPermissions;
  1005. ui->actionShowMacPermissions = nullptr;
  1006. #endif
  1007. #if defined(_WIN32) || defined(__APPLE__)
  1008. if (App()->IsUpdaterDisabled()) {
  1009. ui->actionCheckForUpdates->setEnabled(false);
  1010. #if defined(_WIN32)
  1011. ui->actionRepair->setEnabled(false);
  1012. #endif
  1013. }
  1014. #endif
  1015. #ifndef WHATSNEW_ENABLED
  1016. delete ui->actionShowWhatsNew;
  1017. ui->actionShowWhatsNew = nullptr;
  1018. #endif
  1019. if (safe_mode) {
  1020. ui->actionRestartSafe->setText(QTStr("Basic.MainMenu.Help.RestartNormal"));
  1021. }
  1022. UpdatePreviewProgramIndicators();
  1023. OnFirstLoad();
  1024. if (!hideWindowOnStart)
  1025. activateWindow();
  1026. /* ------------------------------------------- */
  1027. /* display warning message for failed modules */
  1028. if (mfi.count) {
  1029. QString failed_plugins;
  1030. char **plugin = mfi.failed_modules;
  1031. while (*plugin) {
  1032. failed_plugins += *plugin;
  1033. failed_plugins += "\n";
  1034. plugin++;
  1035. }
  1036. QString failed_msg = QTStr("PluginsFailedToLoad.Text").arg(failed_plugins);
  1037. OBSMessageBox::warning(this, QTStr("PluginsFailedToLoad.Title"), failed_msg);
  1038. }
  1039. }
  1040. void OBSBasic::OnFirstLoad()
  1041. {
  1042. OnEvent(OBS_FRONTEND_EVENT_FINISHED_LOADING);
  1043. #ifdef WHATSNEW_ENABLED
  1044. /* Attempt to load init screen if available */
  1045. if (cef) {
  1046. WhatsNewInfoThread *wnit = new WhatsNewInfoThread();
  1047. connect(wnit, &WhatsNewInfoThread::Result, this, &OBSBasic::ReceivedIntroJson, Qt::QueuedConnection);
  1048. introCheckThread.reset(wnit);
  1049. introCheckThread->start();
  1050. }
  1051. #endif
  1052. Auth::Load();
  1053. bool showLogViewerOnStartup = config_get_bool(App()->GetUserConfig(), "LogViewer", "ShowLogStartup");
  1054. if (showLogViewerOnStartup)
  1055. on_actionViewCurrentLog_triggered();
  1056. }
  1057. OBSBasic::~OBSBasic()
  1058. {
  1059. /* clear out UI event queue */
  1060. QApplication::sendPostedEvents(nullptr);
  1061. QApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
  1062. if (updateCheckThread && updateCheckThread->isRunning())
  1063. updateCheckThread->wait();
  1064. if (patronJsonThread && patronJsonThread->isRunning())
  1065. patronJsonThread->wait();
  1066. delete screenshotData;
  1067. delete previewProjector;
  1068. delete studioProgramProjector;
  1069. delete previewProjectorSource;
  1070. delete previewProjectorMain;
  1071. delete sourceProjector;
  1072. delete sceneProjectorMenu;
  1073. delete scaleFilteringMenu;
  1074. delete blendingModeMenu;
  1075. delete colorMenu;
  1076. delete colorWidgetAction;
  1077. delete colorSelect;
  1078. delete deinterlaceMenu;
  1079. delete perSceneTransitionMenu;
  1080. delete shortcutFilter;
  1081. delete trayMenu;
  1082. delete programOptions;
  1083. delete program;
  1084. /* XXX: any obs data must be released before calling obs_shutdown.
  1085. * currently, we can't automate this with C++ RAII because of the
  1086. * delicate nature of obs_shutdown needing to be freed before the UI
  1087. * can be freed, and we have no control over the destruction order of
  1088. * the Qt UI stuff, so we have to manually clear any references to
  1089. * libobs. */
  1090. delete cpuUsageTimer;
  1091. os_cpu_usage_info_destroy(cpuUsageInfo);
  1092. obs_hotkey_set_callback_routing_func(nullptr, nullptr);
  1093. ClearHotkeys();
  1094. service = nullptr;
  1095. outputHandler.reset();
  1096. delete interaction;
  1097. delete properties;
  1098. delete filters;
  1099. delete transformWindow;
  1100. delete advAudioWindow;
  1101. delete about;
  1102. delete remux;
  1103. obs_display_remove_draw_callback(ui->preview->GetDisplay(), OBSBasic::RenderMain, this);
  1104. obs_enter_graphics();
  1105. gs_vertexbuffer_destroy(box);
  1106. gs_vertexbuffer_destroy(boxLeft);
  1107. gs_vertexbuffer_destroy(boxTop);
  1108. gs_vertexbuffer_destroy(boxRight);
  1109. gs_vertexbuffer_destroy(boxBottom);
  1110. gs_vertexbuffer_destroy(circle);
  1111. gs_vertexbuffer_destroy(actionSafeMargin);
  1112. gs_vertexbuffer_destroy(graphicsSafeMargin);
  1113. gs_vertexbuffer_destroy(fourByThreeSafeMargin);
  1114. gs_vertexbuffer_destroy(leftLine);
  1115. gs_vertexbuffer_destroy(topLine);
  1116. gs_vertexbuffer_destroy(rightLine);
  1117. obs_leave_graphics();
  1118. /* When shutting down, sometimes source references can get in to the
  1119. * event queue, and if we don't forcibly process those events they
  1120. * won't get processed until after obs_shutdown has been called. I
  1121. * really wish there were a more elegant way to deal with this via C++,
  1122. * but Qt doesn't use C++ in a normal way, so you can't really rely on
  1123. * normal C++ behavior for your data to be freed in the order that you
  1124. * expect or want it to. */
  1125. QApplication::sendPostedEvents(nullptr);
  1126. config_set_int(App()->GetAppConfig(), "General", "LastVersion", LIBOBS_API_VER);
  1127. config_save_safe(App()->GetAppConfig(), "tmp", nullptr);
  1128. config_set_bool(App()->GetUserConfig(), "BasicWindow", "PreviewEnabled", previewEnabled);
  1129. config_set_bool(App()->GetUserConfig(), "BasicWindow", "AlwaysOnTop", ui->actionAlwaysOnTop->isChecked());
  1130. config_set_bool(App()->GetUserConfig(), "BasicWindow", "SceneDuplicationMode", sceneDuplicationMode);
  1131. config_set_bool(App()->GetUserConfig(), "BasicWindow", "SwapScenesMode", swapScenesMode);
  1132. config_set_bool(App()->GetUserConfig(), "BasicWindow", "EditPropertiesMode", editPropertiesMode);
  1133. config_set_bool(App()->GetUserConfig(), "BasicWindow", "PreviewProgramMode", IsPreviewProgramMode());
  1134. config_set_bool(App()->GetUserConfig(), "BasicWindow", "DocksLocked", ui->lockDocks->isChecked());
  1135. config_set_bool(App()->GetUserConfig(), "BasicWindow", "SideDocks", ui->sideDocks->isChecked());
  1136. config_save_safe(App()->GetUserConfig(), "tmp", nullptr);
  1137. #ifdef BROWSER_AVAILABLE
  1138. DestroyPanelCookieManager();
  1139. delete cef;
  1140. cef = nullptr;
  1141. #endif
  1142. }
  1143. static inline int AttemptToResetVideo(struct obs_video_info *ovi)
  1144. {
  1145. return obs_reset_video(ovi);
  1146. }
  1147. static inline enum obs_scale_type GetScaleType(ConfigFile &activeConfiguration)
  1148. {
  1149. const char *scaleTypeStr = config_get_string(activeConfiguration, "Video", "ScaleType");
  1150. if (astrcmpi(scaleTypeStr, "bilinear") == 0)
  1151. return OBS_SCALE_BILINEAR;
  1152. else if (astrcmpi(scaleTypeStr, "lanczos") == 0)
  1153. return OBS_SCALE_LANCZOS;
  1154. else if (astrcmpi(scaleTypeStr, "area") == 0)
  1155. return OBS_SCALE_AREA;
  1156. else
  1157. return OBS_SCALE_BICUBIC;
  1158. }
  1159. static inline enum video_format GetVideoFormatFromName(const char *name)
  1160. {
  1161. if (astrcmpi(name, "I420") == 0)
  1162. return VIDEO_FORMAT_I420;
  1163. else if (astrcmpi(name, "NV12") == 0)
  1164. return VIDEO_FORMAT_NV12;
  1165. else if (astrcmpi(name, "I444") == 0)
  1166. return VIDEO_FORMAT_I444;
  1167. else if (astrcmpi(name, "I010") == 0)
  1168. return VIDEO_FORMAT_I010;
  1169. else if (astrcmpi(name, "P010") == 0)
  1170. return VIDEO_FORMAT_P010;
  1171. else if (astrcmpi(name, "P216") == 0)
  1172. return VIDEO_FORMAT_P216;
  1173. else if (astrcmpi(name, "P416") == 0)
  1174. return VIDEO_FORMAT_P416;
  1175. #if 0 //currently unsupported
  1176. else if (astrcmpi(name, "YVYU") == 0)
  1177. return VIDEO_FORMAT_YVYU;
  1178. else if (astrcmpi(name, "YUY2") == 0)
  1179. return VIDEO_FORMAT_YUY2;
  1180. else if (astrcmpi(name, "UYVY") == 0)
  1181. return VIDEO_FORMAT_UYVY;
  1182. #endif
  1183. else
  1184. return VIDEO_FORMAT_BGRA;
  1185. }
  1186. static inline enum video_colorspace GetVideoColorSpaceFromName(const char *name)
  1187. {
  1188. enum video_colorspace colorspace = VIDEO_CS_SRGB;
  1189. if (strcmp(name, "601") == 0)
  1190. colorspace = VIDEO_CS_601;
  1191. else if (strcmp(name, "709") == 0)
  1192. colorspace = VIDEO_CS_709;
  1193. else if (strcmp(name, "2100PQ") == 0)
  1194. colorspace = VIDEO_CS_2100_PQ;
  1195. else if (strcmp(name, "2100HLG") == 0)
  1196. colorspace = VIDEO_CS_2100_HLG;
  1197. return colorspace;
  1198. }
  1199. int OBSBasic::ResetVideo()
  1200. {
  1201. if (outputHandler && outputHandler->Active())
  1202. return OBS_VIDEO_CURRENTLY_ACTIVE;
  1203. ProfileScope("OBSBasic::ResetVideo");
  1204. struct obs_video_info ovi;
  1205. int ret;
  1206. GetConfigFPS(ovi.fps_num, ovi.fps_den);
  1207. const char *colorFormat = config_get_string(activeConfiguration, "Video", "ColorFormat");
  1208. const char *colorSpace = config_get_string(activeConfiguration, "Video", "ColorSpace");
  1209. const char *colorRange = config_get_string(activeConfiguration, "Video", "ColorRange");
  1210. ovi.graphics_module = App()->GetRenderModule();
  1211. ovi.base_width = (uint32_t)config_get_uint(activeConfiguration, "Video", "BaseCX");
  1212. ovi.base_height = (uint32_t)config_get_uint(activeConfiguration, "Video", "BaseCY");
  1213. ovi.output_width = (uint32_t)config_get_uint(activeConfiguration, "Video", "OutputCX");
  1214. ovi.output_height = (uint32_t)config_get_uint(activeConfiguration, "Video", "OutputCY");
  1215. ovi.output_format = GetVideoFormatFromName(colorFormat);
  1216. ovi.colorspace = GetVideoColorSpaceFromName(colorSpace);
  1217. ovi.range = astrcmpi(colorRange, "Full") == 0 ? VIDEO_RANGE_FULL : VIDEO_RANGE_PARTIAL;
  1218. ovi.adapter = config_get_uint(App()->GetUserConfig(), "Video", "AdapterIdx");
  1219. ovi.gpu_conversion = true;
  1220. ovi.scale_type = GetScaleType(activeConfiguration);
  1221. if (ovi.base_width < 32 || ovi.base_height < 32) {
  1222. ovi.base_width = 1920;
  1223. ovi.base_height = 1080;
  1224. config_set_uint(activeConfiguration, "Video", "BaseCX", 1920);
  1225. config_set_uint(activeConfiguration, "Video", "BaseCY", 1080);
  1226. }
  1227. if (ovi.output_width < 32 || ovi.output_height < 32) {
  1228. ovi.output_width = ovi.base_width;
  1229. ovi.output_height = ovi.base_height;
  1230. config_set_uint(activeConfiguration, "Video", "OutputCX", ovi.base_width);
  1231. config_set_uint(activeConfiguration, "Video", "OutputCY", ovi.base_height);
  1232. }
  1233. ret = AttemptToResetVideo(&ovi);
  1234. if (ret == OBS_VIDEO_CURRENTLY_ACTIVE) {
  1235. blog(LOG_WARNING, "Tried to reset when already active");
  1236. return ret;
  1237. }
  1238. if (ret == OBS_VIDEO_SUCCESS) {
  1239. ResizePreview(ovi.base_width, ovi.base_height);
  1240. if (program)
  1241. ResizeProgram(ovi.base_width, ovi.base_height);
  1242. const float sdr_white_level = (float)config_get_uint(activeConfiguration, "Video", "SdrWhiteLevel");
  1243. const float hdr_nominal_peak_level =
  1244. (float)config_get_uint(activeConfiguration, "Video", "HdrNominalPeakLevel");
  1245. obs_set_video_levels(sdr_white_level, hdr_nominal_peak_level);
  1246. OBSBasicStats::InitializeValues();
  1247. OBSProjector::UpdateMultiviewProjectors();
  1248. if (!collections.empty()) {
  1249. const OBS::SceneCollection currentSceneCollection = OBSBasic::GetCurrentSceneCollection();
  1250. bool usingAbsoluteCoordinates = currentSceneCollection.getCoordinateMode() ==
  1251. OBS::SceneCoordinateMode::Absolute;
  1252. OBS::Rect migrationResolution = currentSceneCollection.getMigrationResolution();
  1253. OBS::Rect videoResolution = OBS::Rect(ovi.base_width, ovi.base_height);
  1254. bool canMigrate = usingAbsoluteCoordinates ||
  1255. (!migrationResolution.isZero() && migrationResolution != videoResolution);
  1256. ui->actionRemigrateSceneCollection->setEnabled(canMigrate);
  1257. } else {
  1258. ui->actionRemigrateSceneCollection->setEnabled(false);
  1259. }
  1260. emit CanvasResized(ovi.base_width, ovi.base_height);
  1261. emit OutputResized(ovi.output_width, ovi.output_height);
  1262. }
  1263. return ret;
  1264. }
  1265. bool OBSBasic::ResetAudio()
  1266. {
  1267. ProfileScope("OBSBasic::ResetAudio");
  1268. struct obs_audio_info2 ai = {};
  1269. ai.samples_per_sec = config_get_uint(activeConfiguration, "Audio", "SampleRate");
  1270. const char *channelSetupStr = config_get_string(activeConfiguration, "Audio", "ChannelSetup");
  1271. if (strcmp(channelSetupStr, "Mono") == 0)
  1272. ai.speakers = SPEAKERS_MONO;
  1273. else if (strcmp(channelSetupStr, "2.1") == 0)
  1274. ai.speakers = SPEAKERS_2POINT1;
  1275. else if (strcmp(channelSetupStr, "4.0") == 0)
  1276. ai.speakers = SPEAKERS_4POINT0;
  1277. else if (strcmp(channelSetupStr, "4.1") == 0)
  1278. ai.speakers = SPEAKERS_4POINT1;
  1279. else if (strcmp(channelSetupStr, "5.1") == 0)
  1280. ai.speakers = SPEAKERS_5POINT1;
  1281. else if (strcmp(channelSetupStr, "7.1") == 0)
  1282. ai.speakers = SPEAKERS_7POINT1;
  1283. else
  1284. ai.speakers = SPEAKERS_STEREO;
  1285. bool lowLatencyAudioBuffering = config_get_bool(App()->GetUserConfig(), "Audio", "LowLatencyAudioBuffering");
  1286. if (lowLatencyAudioBuffering) {
  1287. ai.max_buffering_ms = 20;
  1288. ai.fixed_buffering = true;
  1289. }
  1290. return obs_reset_audio2(&ai);
  1291. }
  1292. void OBSBasic::closeEvent(QCloseEvent *event)
  1293. {
  1294. /* Wait for multitrack video stream to start/finish processing in the background */
  1295. if (setupStreamingGuard.valid() &&
  1296. setupStreamingGuard.wait_for(std::chrono::seconds{0}) != std::future_status::ready) {
  1297. QTimer::singleShot(1000, this, &OBSBasic::close);
  1298. event->ignore();
  1299. return;
  1300. }
  1301. /* Do not close window if inside of a temporary event loop because we
  1302. * could be inside of an Auth::LoadUI call. Keep trying once per
  1303. * second until we've exit any known sub-loops. */
  1304. if (os_atomic_load_long(&insideEventLoop) != 0) {
  1305. QTimer::singleShot(1000, this, &OBSBasic::close);
  1306. event->ignore();
  1307. return;
  1308. }
  1309. #ifdef YOUTUBE_ENABLED
  1310. /* Also don't close the window if the youtube stream check is active */
  1311. if (youtubeStreamCheckThread) {
  1312. QTimer::singleShot(1000, this, &OBSBasic::close);
  1313. event->ignore();
  1314. return;
  1315. }
  1316. #endif
  1317. if (isVisible())
  1318. config_set_string(App()->GetUserConfig(), "BasicWindow", "geometry",
  1319. saveGeometry().toBase64().constData());
  1320. bool confirmOnExit = config_get_bool(App()->GetUserConfig(), "General", "ConfirmOnExit");
  1321. if (confirmOnExit && outputHandler && outputHandler->Active() && !clearingFailed) {
  1322. SetShowing(true);
  1323. QMessageBox::StandardButton button =
  1324. OBSMessageBox::question(this, QTStr("ConfirmExit.Title"), QTStr("ConfirmExit.Text"));
  1325. if (button == QMessageBox::No) {
  1326. event->ignore();
  1327. restart = false;
  1328. return;
  1329. }
  1330. }
  1331. if (remux && !remux->close()) {
  1332. event->ignore();
  1333. restart = false;
  1334. return;
  1335. }
  1336. QWidget::closeEvent(event);
  1337. if (!event->isAccepted())
  1338. return;
  1339. blog(LOG_INFO, SHUTDOWN_SEPARATOR);
  1340. closing = true;
  1341. /* While closing, a resize event to OBSQTDisplay could be triggered.
  1342. * The graphics thread on macOS dispatches a lambda function to be
  1343. * executed asynchronously in the main thread. However, the display is
  1344. * sometimes deleted before the lambda function is actually executed.
  1345. * To avoid such a case, destroy displays earlier than others such as
  1346. * deleting browser docks. */
  1347. ui->preview->DestroyDisplay();
  1348. if (program)
  1349. program->DestroyDisplay();
  1350. if (outputHandler->VirtualCamActive())
  1351. outputHandler->StopVirtualCam();
  1352. if (introCheckThread)
  1353. introCheckThread->wait();
  1354. if (whatsNewInitThread)
  1355. whatsNewInitThread->wait();
  1356. if (updateCheckThread)
  1357. updateCheckThread->wait();
  1358. if (logUploadThread)
  1359. logUploadThread->wait();
  1360. if (devicePropertiesThread && devicePropertiesThread->isRunning()) {
  1361. devicePropertiesThread->wait();
  1362. devicePropertiesThread.reset();
  1363. }
  1364. QApplication::sendPostedEvents(nullptr);
  1365. signalHandlers.clear();
  1366. Auth::Save();
  1367. SaveProjectNow();
  1368. auth.reset();
  1369. delete extraBrowsers;
  1370. config_set_string(App()->GetUserConfig(), "BasicWindow", "DockState", saveState().toBase64().constData());
  1371. #ifdef BROWSER_AVAILABLE
  1372. if (cef)
  1373. SaveExtraBrowserDocks();
  1374. ClearExtraBrowserDocks();
  1375. #endif
  1376. OnEvent(OBS_FRONTEND_EVENT_SCRIPTING_SHUTDOWN);
  1377. disableSaving++;
  1378. /* Clear all scene data (dialogs, widgets, widget sub-items, scenes,
  1379. * sources, etc) so that all references are released before shutdown */
  1380. ClearSceneData();
  1381. OnEvent(OBS_FRONTEND_EVENT_EXIT);
  1382. // Destroys the frontend API so plugins can't continue calling it
  1383. obs_frontend_set_callbacks_internal(nullptr);
  1384. api = nullptr;
  1385. QMetaObject::invokeMethod(App(), "quit", Qt::QueuedConnection);
  1386. }
  1387. bool OBSBasic::nativeEvent(const QByteArray &, void *message, qintptr *)
  1388. {
  1389. #ifdef _WIN32
  1390. const MSG &msg = *static_cast<MSG *>(message);
  1391. switch (msg.message) {
  1392. case WM_MOVE:
  1393. for (OBSQTDisplay *const display : findChildren<OBSQTDisplay *>()) {
  1394. display->OnMove();
  1395. }
  1396. break;
  1397. case WM_DISPLAYCHANGE:
  1398. for (OBSQTDisplay *const display : findChildren<OBSQTDisplay *>()) {
  1399. display->OnDisplayChange();
  1400. }
  1401. }
  1402. #else
  1403. UNUSED_PARAMETER(message);
  1404. #endif
  1405. return false;
  1406. }
  1407. void OBSBasic::changeEvent(QEvent *event)
  1408. {
  1409. if (event->type() == QEvent::WindowStateChange) {
  1410. QWindowStateChangeEvent *stateEvent = (QWindowStateChangeEvent *)event;
  1411. if (isMinimized()) {
  1412. if (trayIcon && trayIcon->isVisible() && sysTrayMinimizeToTray()) {
  1413. ToggleShowHide();
  1414. return;
  1415. }
  1416. if (previewEnabled)
  1417. EnablePreviewDisplay(false);
  1418. } else if (stateEvent->oldState() & Qt::WindowMinimized && isVisible()) {
  1419. if (previewEnabled)
  1420. EnablePreviewDisplay(true);
  1421. }
  1422. }
  1423. }
  1424. void OBSBasic::GetFPSCommon(uint32_t &num, uint32_t &den) const
  1425. {
  1426. const char *val = config_get_string(activeConfiguration, "Video", "FPSCommon");
  1427. if (strcmp(val, "10") == 0) {
  1428. num = 10;
  1429. den = 1;
  1430. } else if (strcmp(val, "20") == 0) {
  1431. num = 20;
  1432. den = 1;
  1433. } else if (strcmp(val, "24 NTSC") == 0) {
  1434. num = 24000;
  1435. den = 1001;
  1436. } else if (strcmp(val, "25 PAL") == 0) {
  1437. num = 25;
  1438. den = 1;
  1439. } else if (strcmp(val, "29.97") == 0) {
  1440. num = 30000;
  1441. den = 1001;
  1442. } else if (strcmp(val, "48") == 0) {
  1443. num = 48;
  1444. den = 1;
  1445. } else if (strcmp(val, "50 PAL") == 0) {
  1446. num = 50;
  1447. den = 1;
  1448. } else if (strcmp(val, "59.94") == 0) {
  1449. num = 60000;
  1450. den = 1001;
  1451. } else if (strcmp(val, "60") == 0) {
  1452. num = 60;
  1453. den = 1;
  1454. } else {
  1455. num = 30;
  1456. den = 1;
  1457. }
  1458. }
  1459. void OBSBasic::GetFPSInteger(uint32_t &num, uint32_t &den) const
  1460. {
  1461. num = (uint32_t)config_get_uint(activeConfiguration, "Video", "FPSInt");
  1462. den = 1;
  1463. }
  1464. void OBSBasic::GetFPSFraction(uint32_t &num, uint32_t &den) const
  1465. {
  1466. num = (uint32_t)config_get_uint(activeConfiguration, "Video", "FPSNum");
  1467. den = (uint32_t)config_get_uint(activeConfiguration, "Video", "FPSDen");
  1468. }
  1469. void OBSBasic::GetFPSNanoseconds(uint32_t &num, uint32_t &den) const
  1470. {
  1471. num = 1000000000;
  1472. den = (uint32_t)config_get_uint(activeConfiguration, "Video", "FPSNS");
  1473. }
  1474. void OBSBasic::GetConfigFPS(uint32_t &num, uint32_t &den) const
  1475. {
  1476. uint32_t type = config_get_uint(activeConfiguration, "Video", "FPSType");
  1477. if (type == 1) //"Integer"
  1478. GetFPSInteger(num, den);
  1479. else if (type == 2) //"Fraction"
  1480. GetFPSFraction(num, den);
  1481. /*
  1482. * else if (false) //"Nanoseconds", currently not implemented
  1483. * GetFPSNanoseconds(num, den);
  1484. */
  1485. else
  1486. GetFPSCommon(num, den);
  1487. }
  1488. config_t *OBSBasic::Config() const
  1489. {
  1490. return activeConfiguration;
  1491. }
  1492. void OBSBasic::UpdateEditMenu()
  1493. {
  1494. QModelIndexList items = GetAllSelectedSourceItems();
  1495. int totalCount = items.count();
  1496. size_t filter_count = 0;
  1497. if (totalCount == 1) {
  1498. OBSSceneItem sceneItem = ui->sources->Get(GetTopSelectedSourceItem());
  1499. OBSSource source = obs_sceneitem_get_source(sceneItem);
  1500. filter_count = obs_source_filter_count(source);
  1501. }
  1502. bool allowPastingDuplicate = !!clipboard.size();
  1503. for (size_t i = clipboard.size(); i > 0; i--) {
  1504. const size_t idx = i - 1;
  1505. OBSWeakSource &weak = clipboard[idx].weak_source;
  1506. if (obs_weak_source_expired(weak)) {
  1507. clipboard.erase(clipboard.begin() + idx);
  1508. continue;
  1509. }
  1510. OBSSourceAutoRelease strong = obs_weak_source_get_source(weak.Get());
  1511. if (allowPastingDuplicate && obs_source_get_output_flags(strong) & OBS_SOURCE_DO_NOT_DUPLICATE)
  1512. allowPastingDuplicate = false;
  1513. }
  1514. int videoCount = 0;
  1515. bool canTransformMultiple = false;
  1516. for (int i = 0; i < totalCount; i++) {
  1517. OBSSceneItem item = ui->sources->Get(items.value(i).row());
  1518. OBSSource source = obs_sceneitem_get_source(item);
  1519. const uint32_t flags = obs_source_get_output_flags(source);
  1520. const bool hasVideo = (flags & OBS_SOURCE_VIDEO) != 0;
  1521. if (hasVideo && !obs_sceneitem_locked(item))
  1522. canTransformMultiple = true;
  1523. if (hasVideo)
  1524. videoCount++;
  1525. }
  1526. const bool canTransformSingle = videoCount == 1 && totalCount == 1;
  1527. OBSSceneItem curItem = GetCurrentSceneItem();
  1528. bool locked = curItem && obs_sceneitem_locked(curItem);
  1529. ui->actionCopySource->setEnabled(totalCount > 0);
  1530. ui->actionEditTransform->setEnabled(canTransformSingle && !locked);
  1531. ui->actionCopyTransform->setEnabled(canTransformSingle);
  1532. ui->actionPasteTransform->setEnabled(canTransformMultiple && hasCopiedTransform && videoCount > 0);
  1533. ui->actionCopyFilters->setEnabled(filter_count > 0);
  1534. ui->actionPasteFilters->setEnabled(!obs_weak_source_expired(copyFiltersSource) && totalCount > 0);
  1535. ui->actionPasteRef->setEnabled(!!clipboard.size());
  1536. ui->actionPasteDup->setEnabled(allowPastingDuplicate);
  1537. ui->actionMoveUp->setEnabled(totalCount > 0);
  1538. ui->actionMoveDown->setEnabled(totalCount > 0);
  1539. ui->actionMoveToTop->setEnabled(totalCount > 0);
  1540. ui->actionMoveToBottom->setEnabled(totalCount > 0);
  1541. ui->actionResetTransform->setEnabled(canTransformMultiple);
  1542. ui->actionRotate90CW->setEnabled(canTransformMultiple);
  1543. ui->actionRotate90CCW->setEnabled(canTransformMultiple);
  1544. ui->actionRotate180->setEnabled(canTransformMultiple);
  1545. ui->actionFlipHorizontal->setEnabled(canTransformMultiple);
  1546. ui->actionFlipVertical->setEnabled(canTransformMultiple);
  1547. ui->actionFitToScreen->setEnabled(canTransformMultiple);
  1548. ui->actionStretchToScreen->setEnabled(canTransformMultiple);
  1549. ui->actionCenterToScreen->setEnabled(canTransformMultiple);
  1550. ui->actionVerticalCenter->setEnabled(canTransformMultiple);
  1551. ui->actionHorizontalCenter->setEnabled(canTransformMultiple);
  1552. }
  1553. void OBSBasic::UpdateTitleBar()
  1554. {
  1555. stringstream name;
  1556. const char *profile = config_get_string(App()->GetUserConfig(), "Basic", "Profile");
  1557. const char *sceneCollection = config_get_string(App()->GetUserConfig(), "Basic", "SceneCollection");
  1558. name << "OBS ";
  1559. if (previewProgramMode)
  1560. name << "Studio ";
  1561. name << App()->GetVersionString(false);
  1562. if (safe_mode)
  1563. name << " (" << Str("TitleBar.SafeMode") << ")";
  1564. if (App()->IsPortableMode())
  1565. name << " - " << Str("TitleBar.PortableMode");
  1566. name << " - " << Str("TitleBar.Profile") << ": " << profile;
  1567. name << " - " << Str("TitleBar.Scenes") << ": " << sceneCollection;
  1568. setWindowTitle(QT_UTF8(name.str().c_str()));
  1569. }
  1570. OBSBasic *OBSBasic::Get()
  1571. {
  1572. return reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
  1573. }
  1574. void OBSBasic::UpdatePatronJson(const QString &text, const QString &error)
  1575. {
  1576. if (!error.isEmpty())
  1577. return;
  1578. patronJson = QT_TO_UTF8(text);
  1579. }
  1580. void OBSBasic::SetDisplayAffinity(QWindow *window)
  1581. {
  1582. if (!SetDisplayAffinitySupported())
  1583. return;
  1584. bool hideFromCapture = config_get_bool(App()->GetUserConfig(), "BasicWindow", "HideOBSWindowsFromCapture");
  1585. // Don't hide projectors, those are designed to be visible / captured
  1586. if (window->property("isOBSProjectorWindow") == true)
  1587. return;
  1588. #ifdef _WIN32
  1589. HWND hwnd = (HWND)window->winId();
  1590. DWORD curAffinity;
  1591. if (GetWindowDisplayAffinity(hwnd, &curAffinity)) {
  1592. if (hideFromCapture && curAffinity != WDA_EXCLUDEFROMCAPTURE)
  1593. SetWindowDisplayAffinity(hwnd, WDA_EXCLUDEFROMCAPTURE);
  1594. else if (!hideFromCapture && curAffinity != WDA_NONE)
  1595. SetWindowDisplayAffinity(hwnd, WDA_NONE);
  1596. }
  1597. #else
  1598. // TODO: Implement for other platforms if possible. Don't forget to
  1599. // implement SetDisplayAffinitySupported too!
  1600. UNUSED_PARAMETER(hideFromCapture);
  1601. #endif
  1602. }
  1603. void OBSBasic::OnEvent(enum obs_frontend_event event)
  1604. {
  1605. if (api)
  1606. api->on_event(event);
  1607. }
  1608. OBSPromptResult OBSBasic::PromptForName(const OBSPromptRequest &request, const OBSPromptCallback &callback)
  1609. {
  1610. OBSPromptResult result;
  1611. for (;;) {
  1612. result.success = false;
  1613. if (request.withOption && !request.optionPrompt.empty()) {
  1614. result.optionValue = request.optionValue;
  1615. result.success = NameDialog::AskForNameWithOption(
  1616. this, request.title.c_str(), request.prompt.c_str(), result.promptValue,
  1617. request.optionPrompt.c_str(), result.optionValue,
  1618. (request.promptValue.empty() ? nullptr : request.promptValue.c_str()));
  1619. } else {
  1620. result.success = NameDialog::AskForName(
  1621. this, request.title.c_str(), request.prompt.c_str(), result.promptValue,
  1622. (request.promptValue.empty() ? nullptr : request.promptValue.c_str()));
  1623. }
  1624. if (!result.success) {
  1625. break;
  1626. }
  1627. if (result.promptValue.empty()) {
  1628. OBSMessageBox::warning(this, QTStr("NoNameEntered.Title"), QTStr("NoNameEntered.Text"));
  1629. continue;
  1630. }
  1631. if (!callback(result)) {
  1632. OBSMessageBox::warning(this, QTStr("NameExists.Title"), QTStr("NameExists.Text"));
  1633. continue;
  1634. }
  1635. break;
  1636. }
  1637. return result;
  1638. }