window-basic-main.hpp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227
  1. /******************************************************************************
  2. Copyright (C) 2013-2014 by Hugh Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #pragma once
  15. #include <QBuffer>
  16. #include <QAction>
  17. #include <QThread>
  18. #include <QWidgetAction>
  19. #include <QSystemTrayIcon>
  20. #include <QStyledItemDelegate>
  21. #include <obs.hpp>
  22. #include <vector>
  23. #include <memory>
  24. #include "window-main.hpp"
  25. #include "window-basic-interaction.hpp"
  26. #include "window-basic-properties.hpp"
  27. #include "window-basic-transform.hpp"
  28. #include "window-basic-adv-audio.hpp"
  29. #include "window-basic-filters.hpp"
  30. #include "window-missing-files.hpp"
  31. #include "window-projector.hpp"
  32. #include "window-basic-about.hpp"
  33. #include "auth-base.hpp"
  34. #include "log-viewer.hpp"
  35. #include "undo-stack-obs.hpp"
  36. #include <obs-frontend-internal.hpp>
  37. #include <util/platform.h>
  38. #include <util/threading.h>
  39. #include <util/util.hpp>
  40. #include <QPointer>
  41. class QMessageBox;
  42. class QListWidgetItem;
  43. class VolControl;
  44. class OBSBasicStats;
  45. #include "ui_OBSBasic.h"
  46. #include "ui_ColorSelect.h"
  47. #define DESKTOP_AUDIO_1 Str("DesktopAudioDevice1")
  48. #define DESKTOP_AUDIO_2 Str("DesktopAudioDevice2")
  49. #define AUX_AUDIO_1 Str("AuxAudioDevice1")
  50. #define AUX_AUDIO_2 Str("AuxAudioDevice2")
  51. #define AUX_AUDIO_3 Str("AuxAudioDevice3")
  52. #define AUX_AUDIO_4 Str("AuxAudioDevice4")
  53. #define SIMPLE_ENCODER_X264 "x264"
  54. #define SIMPLE_ENCODER_X264_LOWCPU "x264_lowcpu"
  55. #define SIMPLE_ENCODER_QSV "qsv"
  56. #define SIMPLE_ENCODER_QSV_AV1 "qsv_av1"
  57. #define SIMPLE_ENCODER_NVENC "nvenc"
  58. #define SIMPLE_ENCODER_NVENC_AV1 "nvenc_av1"
  59. #define SIMPLE_ENCODER_NVENC_HEVC "nvenc_hevc"
  60. #define SIMPLE_ENCODER_AMD "amd"
  61. #define SIMPLE_ENCODER_AMD_HEVC "amd_hevc"
  62. #define SIMPLE_ENCODER_AMD_AV1 "amd_av1"
  63. #define SIMPLE_ENCODER_APPLE_H264 "apple_h264"
  64. #define SIMPLE_ENCODER_APPLE_HEVC "apple_hevc"
  65. #define PREVIEW_EDGE_SIZE 10
  66. struct BasicOutputHandler;
  67. enum class QtDataRole {
  68. OBSRef = Qt::UserRole,
  69. OBSSignals,
  70. };
  71. struct SavedProjectorInfo {
  72. ProjectorType type;
  73. int monitor;
  74. std::string geometry;
  75. std::string name;
  76. bool alwaysOnTop;
  77. bool alwaysOnTopOverridden;
  78. };
  79. struct SourceCopyInfo {
  80. OBSWeakSource weak_source;
  81. bool visible;
  82. obs_sceneitem_crop crop;
  83. obs_transform_info transform;
  84. obs_blending_method blend_method;
  85. obs_blending_type blend_mode;
  86. };
  87. struct QuickTransition {
  88. QPushButton *button = nullptr;
  89. OBSSource source;
  90. obs_hotkey_id hotkey = OBS_INVALID_HOTKEY_ID;
  91. int duration = 0;
  92. int id = 0;
  93. bool fadeToBlack = false;
  94. inline QuickTransition() {}
  95. inline QuickTransition(OBSSource source_, int duration_, int id_,
  96. bool fadeToBlack_ = false)
  97. : source(source_),
  98. duration(duration_),
  99. id(id_),
  100. fadeToBlack(fadeToBlack_),
  101. renamedSignal(std::make_shared<OBSSignal>(
  102. obs_source_get_signal_handler(source), "rename",
  103. SourceRenamed, this))
  104. {
  105. }
  106. private:
  107. static void SourceRenamed(void *param, calldata_t *data);
  108. std::shared_ptr<OBSSignal> renamedSignal;
  109. };
  110. class ColorSelect : public QWidget {
  111. public:
  112. explicit ColorSelect(QWidget *parent = 0);
  113. private:
  114. std::unique_ptr<Ui::ColorSelect> ui;
  115. };
  116. class OBSBasic : public OBSMainWindow {
  117. Q_OBJECT
  118. Q_PROPERTY(QIcon imageIcon READ GetImageIcon WRITE SetImageIcon
  119. DESIGNABLE true)
  120. Q_PROPERTY(QIcon colorIcon READ GetColorIcon WRITE SetColorIcon
  121. DESIGNABLE true)
  122. Q_PROPERTY(QIcon slideshowIcon READ GetSlideshowIcon WRITE
  123. SetSlideshowIcon DESIGNABLE true)
  124. Q_PROPERTY(QIcon audioInputIcon READ GetAudioInputIcon WRITE
  125. SetAudioInputIcon DESIGNABLE true)
  126. Q_PROPERTY(QIcon audioOutputIcon READ GetAudioOutputIcon WRITE
  127. SetAudioOutputIcon DESIGNABLE true)
  128. Q_PROPERTY(QIcon desktopCapIcon READ GetDesktopCapIcon WRITE
  129. SetDesktopCapIcon DESIGNABLE true)
  130. Q_PROPERTY(QIcon windowCapIcon READ GetWindowCapIcon WRITE
  131. SetWindowCapIcon DESIGNABLE true)
  132. Q_PROPERTY(QIcon gameCapIcon READ GetGameCapIcon WRITE SetGameCapIcon
  133. DESIGNABLE true)
  134. Q_PROPERTY(QIcon cameraIcon READ GetCameraIcon WRITE SetCameraIcon
  135. DESIGNABLE true)
  136. Q_PROPERTY(QIcon textIcon READ GetTextIcon WRITE SetTextIcon
  137. DESIGNABLE true)
  138. Q_PROPERTY(QIcon mediaIcon READ GetMediaIcon WRITE SetMediaIcon
  139. DESIGNABLE true)
  140. Q_PROPERTY(QIcon browserIcon READ GetBrowserIcon WRITE SetBrowserIcon
  141. DESIGNABLE true)
  142. Q_PROPERTY(QIcon groupIcon READ GetGroupIcon WRITE SetGroupIcon
  143. DESIGNABLE true)
  144. Q_PROPERTY(QIcon sceneIcon READ GetSceneIcon WRITE SetSceneIcon
  145. DESIGNABLE true)
  146. Q_PROPERTY(QIcon defaultIcon READ GetDefaultIcon WRITE SetDefaultIcon
  147. DESIGNABLE true)
  148. Q_PROPERTY(QIcon audioProcessOutputIcon READ GetAudioProcessOutputIcon
  149. WRITE SetAudioProcessOutputIcon DESIGNABLE true)
  150. friend class OBSAbout;
  151. friend class OBSBasicPreview;
  152. friend class OBSBasicStatusBar;
  153. friend class OBSBasicSourceSelect;
  154. friend class OBSBasicTransform;
  155. friend class OBSBasicSettings;
  156. friend class Auth;
  157. friend class AutoConfig;
  158. friend class AutoConfigStreamPage;
  159. friend class RecordButton;
  160. friend class ControlsSplitButton;
  161. friend class ExtraBrowsersModel;
  162. friend class ExtraBrowsersDelegate;
  163. friend class DeviceCaptureToolbar;
  164. friend class DeviceToolbarPropertiesThread;
  165. friend class OBSBasicSourceSelect;
  166. friend class OBSYoutubeActions;
  167. friend class OBSPermissions;
  168. friend struct BasicOutputHandler;
  169. friend struct OBSStudioAPI;
  170. friend class ScreenshotObj;
  171. enum class MoveDir { Up, Down, Left, Right };
  172. enum DropType {
  173. DropType_RawText,
  174. DropType_Text,
  175. DropType_Image,
  176. DropType_Media,
  177. DropType_Html,
  178. DropType_Url,
  179. };
  180. enum ContextBarSize {
  181. ContextBarSize_Minimized,
  182. ContextBarSize_Reduced,
  183. ContextBarSize_Normal
  184. };
  185. enum class CenterType {
  186. Scene,
  187. Vertical,
  188. Horizontal,
  189. };
  190. private:
  191. obs_frontend_callbacks *api = nullptr;
  192. std::shared_ptr<Auth> auth;
  193. std::vector<VolControl *> volumes;
  194. std::vector<OBSSignal> signalHandlers;
  195. QList<QPointer<QDockWidget>> extraDocks;
  196. bool loaded = false;
  197. long disableSaving = 1;
  198. bool projectChanged = false;
  199. bool previewEnabled = true;
  200. ContextBarSize contextBarSize = ContextBarSize_Normal;
  201. std::deque<SourceCopyInfo> clipboard;
  202. OBSWeakSourceAutoRelease copyFiltersSource;
  203. bool copyVisible = true;
  204. obs_transform_info copiedTransformInfo;
  205. obs_sceneitem_crop copiedCropInfo;
  206. bool hasCopiedTransform = false;
  207. OBSWeakSourceAutoRelease copySourceTransition;
  208. bool closing = false;
  209. QScopedPointer<QThread> devicePropertiesThread;
  210. QScopedPointer<QThread> whatsNewInitThread;
  211. QScopedPointer<QThread> updateCheckThread;
  212. QScopedPointer<QThread> introCheckThread;
  213. QScopedPointer<QThread> logUploadThread;
  214. QPointer<OBSBasicInteraction> interaction;
  215. QPointer<OBSBasicProperties> properties;
  216. QPointer<OBSBasicTransform> transformWindow;
  217. QPointer<OBSBasicAdvAudio> advAudioWindow;
  218. QPointer<OBSBasicFilters> filters;
  219. QPointer<QDockWidget> statsDock;
  220. QPointer<OBSAbout> about;
  221. QPointer<OBSMissingFiles> missDialog;
  222. QPointer<OBSLogViewer> logView;
  223. QPointer<QTimer> cpuUsageTimer;
  224. QPointer<QTimer> diskFullTimer;
  225. QPointer<QTimer> nudge_timer;
  226. bool recent_nudge = false;
  227. os_cpu_usage_info_t *cpuUsageInfo = nullptr;
  228. OBSService service;
  229. std::unique_ptr<BasicOutputHandler> outputHandler;
  230. bool streamingStopping = false;
  231. bool recordingStopping = false;
  232. bool replayBufferStopping = false;
  233. gs_vertbuffer_t *box = nullptr;
  234. gs_vertbuffer_t *boxLeft = nullptr;
  235. gs_vertbuffer_t *boxTop = nullptr;
  236. gs_vertbuffer_t *boxRight = nullptr;
  237. gs_vertbuffer_t *boxBottom = nullptr;
  238. gs_vertbuffer_t *circle = nullptr;
  239. gs_vertbuffer_t *actionSafeMargin = nullptr;
  240. gs_vertbuffer_t *graphicsSafeMargin = nullptr;
  241. gs_vertbuffer_t *fourByThreeSafeMargin = nullptr;
  242. gs_vertbuffer_t *leftLine = nullptr;
  243. gs_vertbuffer_t *topLine = nullptr;
  244. gs_vertbuffer_t *rightLine = nullptr;
  245. int previewX = 0, previewY = 0;
  246. int previewCX = 0, previewCY = 0;
  247. float previewScale = 0.0f;
  248. ConfigFile basicConfig;
  249. std::vector<SavedProjectorInfo *> savedProjectorsArray;
  250. std::vector<OBSProjector *> projectors;
  251. QPointer<QWidget> stats;
  252. QPointer<QWidget> remux;
  253. QPointer<QWidget> extraBrowsers;
  254. QPointer<QWidget> importer;
  255. QPointer<QMenu> startStreamMenu;
  256. QPointer<QPushButton> transitionButton;
  257. QPointer<ControlsSplitButton> replayBufferButton;
  258. QScopedPointer<QPushButton> pause;
  259. QPointer<ControlsSplitButton> vcamButton;
  260. bool vcamEnabled = false;
  261. QScopedPointer<QSystemTrayIcon> trayIcon;
  262. QPointer<QAction> sysTrayStream;
  263. QPointer<QAction> sysTrayRecord;
  264. QPointer<QAction> sysTrayReplayBuffer;
  265. QPointer<QAction> sysTrayVirtualCam;
  266. QPointer<QAction> showHide;
  267. QPointer<QAction> exit;
  268. QPointer<QMenu> trayMenu;
  269. QPointer<QMenu> previewProjector;
  270. QPointer<QMenu> studioProgramProjector;
  271. QPointer<QMenu> previewProjectorSource;
  272. QPointer<QMenu> previewProjectorMain;
  273. QPointer<QMenu> sceneProjectorMenu;
  274. QPointer<QMenu> sourceProjector;
  275. QPointer<QMenu> scaleFilteringMenu;
  276. QPointer<QMenu> blendingMethodMenu;
  277. QPointer<QMenu> blendingModeMenu;
  278. QPointer<QMenu> colorMenu;
  279. QPointer<QWidgetAction> colorWidgetAction;
  280. QPointer<ColorSelect> colorSelect;
  281. QPointer<QMenu> deinterlaceMenu;
  282. QPointer<QMenu> perSceneTransitionMenu;
  283. QPointer<QObject> shortcutFilter;
  284. QPointer<QAction> renameScene;
  285. QPointer<QAction> renameSource;
  286. QPointer<QWidget> programWidget;
  287. QPointer<QVBoxLayout> programLayout;
  288. QPointer<QLabel> programLabel;
  289. QScopedPointer<QThread> patronJsonThread;
  290. std::string patronJson;
  291. std::atomic<obs_scene_t *> currentScene = nullptr;
  292. void UpdateMultiviewProjectorMenu();
  293. void DrawBackdrop(float cx, float cy);
  294. void SetupEncoders();
  295. void CreateFirstRunSources();
  296. void CreateDefaultScene(bool firstStart);
  297. void UpdateVolumeControlsDecayRate();
  298. void UpdateVolumeControlsPeakMeterType();
  299. void ClearVolumeControls();
  300. void UploadLog(const char *subdir, const char *file, const bool crash);
  301. void Save(const char *file);
  302. void LoadData(obs_data_t *data, const char *file);
  303. void Load(const char *file);
  304. void InitHotkeys();
  305. void CreateHotkeys();
  306. void ClearHotkeys();
  307. bool InitService();
  308. bool InitBasicConfigDefaults();
  309. void InitBasicConfigDefaults2();
  310. bool InitBasicConfig();
  311. void InitOBSCallbacks();
  312. void InitPrimitives();
  313. void OnFirstLoad();
  314. OBSSceneItem GetSceneItem(QListWidgetItem *item);
  315. OBSSceneItem GetCurrentSceneItem();
  316. bool QueryRemoveSource(obs_source_t *source);
  317. void TimedCheckForUpdates();
  318. void CheckForUpdates(bool manualUpdate);
  319. void GetFPSCommon(uint32_t &num, uint32_t &den) const;
  320. void GetFPSInteger(uint32_t &num, uint32_t &den) const;
  321. void GetFPSFraction(uint32_t &num, uint32_t &den) const;
  322. void GetFPSNanoseconds(uint32_t &num, uint32_t &den) const;
  323. void GetConfigFPS(uint32_t &num, uint32_t &den) const;
  324. void UpdatePreviewScalingMenu();
  325. void LoadSceneListOrder(obs_data_array_t *array);
  326. obs_data_array_t *SaveSceneListOrder();
  327. void ChangeSceneIndex(bool relative, int idx, int invalidIdx);
  328. void TempFileOutput(const char *path, int vBitrate, int aBitrate);
  329. void TempStreamOutput(const char *url, const char *key, int vBitrate,
  330. int aBitrate);
  331. void CloseDialogs();
  332. void ClearSceneData();
  333. void ClearProjectors();
  334. void Nudge(int dist, MoveDir dir);
  335. OBSProjector *OpenProjector(obs_source_t *source, int monitor,
  336. ProjectorType type);
  337. void GetAudioSourceFilters();
  338. void GetAudioSourceProperties();
  339. void VolControlContextMenu();
  340. void ToggleVolControlLayout();
  341. void ToggleMixerLayout(bool vertical);
  342. void RefreshSceneCollections();
  343. void ChangeSceneCollection();
  344. void LogScenes();
  345. void ResetProfileData();
  346. bool AddProfile(bool create_new, const char *title, const char *text,
  347. const char *init_text = nullptr, bool rename = false);
  348. bool CreateProfile(const std::string &newName, bool create_new,
  349. bool showWizardChecked, bool rename = false);
  350. void DeleteProfile(const char *profile_name, const char *profile_dir);
  351. void RefreshProfiles();
  352. void ChangeProfile();
  353. void CheckForSimpleModeX264Fallback();
  354. void SaveProjectNow();
  355. int GetTopSelectedSourceItem();
  356. QModelIndexList GetAllSelectedSourceItems();
  357. obs_hotkey_pair_id streamingHotkeys, recordingHotkeys, pauseHotkeys,
  358. replayBufHotkeys, vcamHotkeys, togglePreviewHotkeys,
  359. contextBarHotkeys;
  360. obs_hotkey_id forceStreamingStopHotkey, splitFileHotkey;
  361. void InitDefaultTransitions();
  362. void InitTransition(obs_source_t *transition);
  363. obs_source_t *FindTransition(const char *name);
  364. OBSSource GetCurrentTransition();
  365. obs_data_array_t *SaveTransitions();
  366. void LoadTransitions(obs_data_array_t *transitions,
  367. obs_load_source_cb cb, void *private_data);
  368. obs_source_t *fadeTransition;
  369. obs_source_t *cutTransition;
  370. void CreateProgramDisplay();
  371. void CreateProgramOptions();
  372. void AddQuickTransitionId(int id);
  373. void AddQuickTransition();
  374. void AddQuickTransitionHotkey(QuickTransition *qt);
  375. void RemoveQuickTransitionHotkey(QuickTransition *qt);
  376. void LoadQuickTransitions(obs_data_array_t *array);
  377. obs_data_array_t *SaveQuickTransitions();
  378. void ClearQuickTransitionWidgets();
  379. void RefreshQuickTransitions();
  380. void DisableQuickTransitionWidgets();
  381. void EnableTransitionWidgets(bool enable);
  382. void CreateDefaultQuickTransitions();
  383. void PasteShowHideTransition(obs_sceneitem_t *item, bool show,
  384. obs_source_t *tr);
  385. QMenu *CreatePerSceneTransitionMenu();
  386. QMenu *CreateVisibilityTransitionMenu(bool visible);
  387. QuickTransition *GetQuickTransition(int id);
  388. int GetQuickTransitionIdx(int id);
  389. QMenu *CreateTransitionMenu(QWidget *parent, QuickTransition *qt);
  390. void ClearQuickTransitions();
  391. void QuickTransitionClicked();
  392. void QuickTransitionChange();
  393. void QuickTransitionChangeDuration(int value);
  394. void QuickTransitionRemoveClicked();
  395. void SetPreviewProgramMode(bool enabled);
  396. void ResizeProgram(uint32_t cx, uint32_t cy);
  397. void SetCurrentScene(obs_scene_t *scene, bool force = false);
  398. static void RenderProgram(void *data, uint32_t cx, uint32_t cy);
  399. std::vector<QuickTransition> quickTransitions;
  400. QPointer<QWidget> programOptions;
  401. QPointer<OBSQTDisplay> program;
  402. OBSWeakSource lastScene;
  403. OBSWeakSource swapScene;
  404. OBSWeakSource programScene;
  405. bool editPropertiesMode = false;
  406. bool sceneDuplicationMode = true;
  407. bool swapScenesMode = true;
  408. volatile bool previewProgramMode = false;
  409. obs_hotkey_id togglePreviewProgramHotkey = 0;
  410. obs_hotkey_id transitionHotkey = 0;
  411. obs_hotkey_id statsHotkey = 0;
  412. obs_hotkey_id screenshotHotkey = 0;
  413. obs_hotkey_id sourceScreenshotHotkey = 0;
  414. int quickTransitionIdCounter = 1;
  415. bool overridingTransition = false;
  416. int programX = 0, programY = 0;
  417. int programCX = 0, programCY = 0;
  418. float programScale = 0.0f;
  419. int disableOutputsRef = 0;
  420. inline void OnActivate(bool force = false);
  421. inline void OnDeactivate();
  422. void AddDropSource(const char *file, DropType image);
  423. void AddDropURL(const char *url, QString &name, obs_data_t *settings,
  424. const obs_video_info &ovi);
  425. void ConfirmDropUrl(const QString &url);
  426. void dragEnterEvent(QDragEnterEvent *event) override;
  427. void dragLeaveEvent(QDragLeaveEvent *event) override;
  428. void dragMoveEvent(QDragMoveEvent *event) override;
  429. void dropEvent(QDropEvent *event) override;
  430. void ReplayBufferClicked();
  431. bool sysTrayMinimizeToTray();
  432. void EnumDialogs();
  433. QList<QDialog *> visDialogs;
  434. QList<QDialog *> modalDialogs;
  435. QList<QMessageBox *> visMsgBoxes;
  436. QList<QPoint> visDlgPositions;
  437. QByteArray startingDockLayout;
  438. obs_data_array_t *SaveProjectors();
  439. void LoadSavedProjectors(obs_data_array_t *savedProjectors);
  440. void ReceivedIntroJson(const QString &text);
  441. void ShowWhatsNew(const QString &url);
  442. void UpdatePreviewProgramIndicators();
  443. #ifdef BROWSER_AVAILABLE
  444. QList<QSharedPointer<QDockWidget>> extraBrowserDocks;
  445. QList<QSharedPointer<QAction>> extraBrowserDockActions;
  446. QStringList extraBrowserDockTargets;
  447. void ClearExtraBrowserDocks();
  448. void LoadExtraBrowserDocks();
  449. void SaveExtraBrowserDocks();
  450. void ManageExtraBrowserDocks();
  451. void AddExtraBrowserDock(const QString &title, const QString &url,
  452. const QString &uuid, bool firstCreate);
  453. #endif
  454. QIcon imageIcon;
  455. QIcon colorIcon;
  456. QIcon slideshowIcon;
  457. QIcon audioInputIcon;
  458. QIcon audioOutputIcon;
  459. QIcon desktopCapIcon;
  460. QIcon windowCapIcon;
  461. QIcon gameCapIcon;
  462. QIcon cameraIcon;
  463. QIcon textIcon;
  464. QIcon mediaIcon;
  465. QIcon browserIcon;
  466. QIcon groupIcon;
  467. QIcon sceneIcon;
  468. QIcon defaultIcon;
  469. QIcon audioProcessOutputIcon;
  470. QIcon GetImageIcon() const;
  471. QIcon GetColorIcon() const;
  472. QIcon GetSlideshowIcon() const;
  473. QIcon GetAudioInputIcon() const;
  474. QIcon GetAudioOutputIcon() const;
  475. QIcon GetDesktopCapIcon() const;
  476. QIcon GetWindowCapIcon() const;
  477. QIcon GetGameCapIcon() const;
  478. QIcon GetCameraIcon() const;
  479. QIcon GetTextIcon() const;
  480. QIcon GetMediaIcon() const;
  481. QIcon GetBrowserIcon() const;
  482. QIcon GetDefaultIcon() const;
  483. QIcon GetAudioProcessOutputIcon() const;
  484. QSlider *tBar;
  485. bool tBarActive = false;
  486. OBSSource GetOverrideTransition(OBSSource source);
  487. int GetOverrideTransitionDuration(OBSSource source);
  488. void UpdateProjectorHideCursor();
  489. void UpdateProjectorAlwaysOnTop(bool top);
  490. void ResetProjectors();
  491. QPointer<QObject> screenshotData;
  492. void MoveSceneItem(enum obs_order_movement movement,
  493. const QString &action_name);
  494. bool autoStartBroadcast = true;
  495. bool autoStopBroadcast = true;
  496. bool broadcastActive = false;
  497. bool broadcastReady = false;
  498. QPointer<QThread> youtubeStreamCheckThread;
  499. #if YOUTUBE_ENABLED
  500. void YoutubeStreamCheck(const std::string &key);
  501. void ShowYouTubeAutoStartWarning();
  502. void YouTubeActionDialogOk(const QString &id, const QString &key,
  503. bool autostart, bool autostop,
  504. bool start_now);
  505. #endif
  506. void BroadcastButtonClicked();
  507. void SetBroadcastFlowEnabled(bool enabled);
  508. void UpdatePreviewSafeAreas();
  509. bool drawSafeAreas = false;
  510. void CenterSelectedSceneItems(const CenterType &centerType);
  511. void ShowMissingFilesDialog(obs_missing_files_t *files);
  512. QColor selectionColor;
  513. QColor cropColor;
  514. QColor hoverColor;
  515. QColor GetCropColor() const;
  516. QColor GetHoverColor() const;
  517. void UpdatePreviewSpacingHelpers();
  518. bool drawSpacingHelpers = true;
  519. float GetDevicePixelRatio();
  520. void SourceToolBarActionsSetEnabled();
  521. std::string lastScreenshot;
  522. std::string lastReplay;
  523. void UpdatePreviewOverflowSettings();
  524. public slots:
  525. void DeferSaveBegin();
  526. void DeferSaveEnd();
  527. void DisplayStreamStartError();
  528. void SetupBroadcast();
  529. void StartStreaming();
  530. void StopStreaming();
  531. void ForceStopStreaming();
  532. void StreamDelayStarting(int sec);
  533. void StreamDelayStopping(int sec);
  534. void StreamingStart();
  535. void StreamStopping();
  536. void StreamingStop(int errorcode, QString last_error);
  537. void StartRecording();
  538. void StopRecording();
  539. void RecordingStart();
  540. void RecordStopping();
  541. void RecordingStop(int code, QString last_error);
  542. void RecordingFileChanged(QString lastRecordingPath);
  543. void ShowReplayBufferPauseWarning();
  544. void StartReplayBuffer();
  545. void StopReplayBuffer();
  546. void ReplayBufferStart();
  547. void ReplayBufferSave();
  548. void ReplayBufferSaved();
  549. void ReplayBufferStopping();
  550. void ReplayBufferStop(int code);
  551. void StartVirtualCam();
  552. void StopVirtualCam();
  553. void OnVirtualCamStart();
  554. void OnVirtualCamStop(int code);
  555. void SaveProjectDeferred();
  556. void SaveProject();
  557. void SetTransition(OBSSource transition);
  558. void OverrideTransition(OBSSource transition);
  559. void TransitionToScene(OBSScene scene, bool force = false);
  560. void TransitionToScene(OBSSource scene, bool force = false,
  561. bool quickTransition = false,
  562. int quickDuration = 0, bool black = false,
  563. bool manual = false);
  564. void SetCurrentScene(OBSSource scene, bool force = false);
  565. bool AddSceneCollection(bool create_new,
  566. const QString &name = QString());
  567. bool NewProfile(const QString &name);
  568. bool DuplicateProfile(const QString &name);
  569. void DeleteProfile(const QString &profileName);
  570. void UpdatePatronJson(const QString &text, const QString &error);
  571. void ShowContextBar();
  572. void HideContextBar();
  573. void PauseRecording();
  574. void UnpauseRecording();
  575. private slots:
  576. void on_actionMainUndo_triggered();
  577. void on_actionMainRedo_triggered();
  578. void AddSceneItem(OBSSceneItem item);
  579. void AddScene(OBSSource source);
  580. void RemoveScene(OBSSource source);
  581. void RenameSources(OBSSource source, QString newName, QString prevName);
  582. void ActivateAudioSource(OBSSource source);
  583. void DeactivateAudioSource(OBSSource source);
  584. void DuplicateSelectedScene();
  585. void RemoveSelectedScene();
  586. void ToggleAlwaysOnTop();
  587. void ReorderSources(OBSScene scene);
  588. void RefreshSources(OBSScene scene);
  589. void ProcessHotkey(obs_hotkey_id id, bool pressed);
  590. void AddTransition();
  591. void RenameTransition();
  592. void TransitionClicked();
  593. void TransitionStopped();
  594. void TransitionFullyStopped();
  595. void TriggerQuickTransition(int id);
  596. void SetDeinterlacingMode();
  597. void SetDeinterlacingOrder();
  598. void SetScaleFilter();
  599. void SetBlendingMethod();
  600. void SetBlendingMode();
  601. void IconActivated(QSystemTrayIcon::ActivationReason reason);
  602. void SetShowing(bool showing);
  603. void ToggleShowHide();
  604. void HideAudioControl();
  605. void UnhideAllAudioControls();
  606. void ToggleHideMixer();
  607. void MixerRenameSource();
  608. void on_vMixerScrollArea_customContextMenuRequested();
  609. void on_hMixerScrollArea_customContextMenuRequested();
  610. void on_actionCopySource_triggered();
  611. void on_actionPasteRef_triggered();
  612. void on_actionPasteDup_triggered();
  613. void on_actionCopyFilters_triggered();
  614. void on_actionPasteFilters_triggered();
  615. void ColorChange();
  616. SourceTreeItem *GetItemWidgetFromSceneItem(obs_sceneitem_t *sceneItem);
  617. void on_actionShowAbout_triggered();
  618. void AudioMixerCopyFilters();
  619. void AudioMixerPasteFilters();
  620. void EnablePreview();
  621. void DisablePreview();
  622. void SceneCopyFilters();
  623. void ScenePasteFilters();
  624. void CheckDiskSpaceRemaining();
  625. void OpenSavedProjector(SavedProjectorInfo *info);
  626. void ScenesReordered();
  627. void ResetStatsHotkey();
  628. void SetImageIcon(const QIcon &icon);
  629. void SetColorIcon(const QIcon &icon);
  630. void SetSlideshowIcon(const QIcon &icon);
  631. void SetAudioInputIcon(const QIcon &icon);
  632. void SetAudioOutputIcon(const QIcon &icon);
  633. void SetDesktopCapIcon(const QIcon &icon);
  634. void SetWindowCapIcon(const QIcon &icon);
  635. void SetGameCapIcon(const QIcon &icon);
  636. void SetCameraIcon(const QIcon &icon);
  637. void SetTextIcon(const QIcon &icon);
  638. void SetMediaIcon(const QIcon &icon);
  639. void SetBrowserIcon(const QIcon &icon);
  640. void SetGroupIcon(const QIcon &icon);
  641. void SetSceneIcon(const QIcon &icon);
  642. void SetDefaultIcon(const QIcon &icon);
  643. void SetAudioProcessOutputIcon(const QIcon &icon);
  644. void TBarChanged(int value);
  645. void TBarReleased();
  646. void LockVolumeControl(bool lock);
  647. void ResetProxyStyleSliders();
  648. private:
  649. /* OBS Callbacks */
  650. static void SceneReordered(void *data, calldata_t *params);
  651. static void SceneRefreshed(void *data, calldata_t *params);
  652. static void SceneItemAdded(void *data, calldata_t *params);
  653. static void SourceCreated(void *data, calldata_t *params);
  654. static void SourceRemoved(void *data, calldata_t *params);
  655. static void SourceActivated(void *data, calldata_t *params);
  656. static void SourceDeactivated(void *data, calldata_t *params);
  657. static void SourceAudioActivated(void *data, calldata_t *params);
  658. static void SourceAudioDeactivated(void *data, calldata_t *params);
  659. static void SourceRenamed(void *data, calldata_t *params);
  660. static void RenderMain(void *data, uint32_t cx, uint32_t cy);
  661. void ResizePreview(uint32_t cx, uint32_t cy);
  662. void AddSource(const char *id);
  663. QMenu *CreateAddSourcePopupMenu();
  664. void AddSourcePopupMenu(const QPoint &pos);
  665. void copyActionsDynamicProperties();
  666. static void HotkeyTriggered(void *data, obs_hotkey_id id, bool pressed);
  667. void AutoRemux(QString input, bool no_show = false);
  668. void UpdatePause(bool activate = true);
  669. void UpdateReplayBuffer(bool activate = true);
  670. bool OutputPathValid();
  671. void OutputPathInvalidMessage();
  672. bool LowDiskSpace();
  673. void DiskSpaceMessage();
  674. OBSSource prevFTBSource = nullptr;
  675. float dpi = 1.0;
  676. public:
  677. OBSSource GetProgramSource();
  678. OBSScene GetCurrentScene();
  679. void SysTrayNotify(const QString &text, QSystemTrayIcon::MessageIcon n);
  680. inline OBSSource GetCurrentSceneSource()
  681. {
  682. OBSScene curScene = GetCurrentScene();
  683. return OBSSource(obs_scene_get_source(curScene));
  684. }
  685. obs_service_t *GetService();
  686. void SetService(obs_service_t *service);
  687. int GetTransitionDuration();
  688. int GetTbarPosition();
  689. inline bool IsPreviewProgramMode() const
  690. {
  691. return os_atomic_load_bool(&previewProgramMode);
  692. }
  693. inline bool VCamEnabled() const { return vcamEnabled; }
  694. bool Active() const;
  695. void ResetUI();
  696. int ResetVideo();
  697. bool ResetAudio();
  698. void AddVCamButton();
  699. void ResetOutputs();
  700. void RefreshVolumeColors();
  701. void ResetAudioDevice(const char *sourceId, const char *deviceId,
  702. const char *deviceDesc, int channel);
  703. void NewProject();
  704. void LoadProject();
  705. inline void GetDisplayRect(int &x, int &y, int &cx, int &cy)
  706. {
  707. x = previewX;
  708. y = previewY;
  709. cx = previewCX;
  710. cy = previewCY;
  711. }
  712. inline bool SavingDisabled() const { return disableSaving; }
  713. inline double GetCPUUsage() const
  714. {
  715. return os_cpu_usage_info_query(cpuUsageInfo);
  716. }
  717. void SaveService();
  718. bool LoadService();
  719. inline Auth *GetAuth() { return auth.get(); }
  720. inline void EnableOutputs(bool enable)
  721. {
  722. if (enable) {
  723. if (--disableOutputsRef < 0)
  724. disableOutputsRef = 0;
  725. } else {
  726. disableOutputsRef++;
  727. }
  728. }
  729. QMenu *AddDeinterlacingMenu(QMenu *menu, obs_source_t *source);
  730. QMenu *AddScaleFilteringMenu(QMenu *menu, obs_sceneitem_t *item);
  731. QMenu *AddBlendingMethodMenu(QMenu *menu, obs_sceneitem_t *item);
  732. QMenu *AddBlendingModeMenu(QMenu *menu, obs_sceneitem_t *item);
  733. QMenu *AddBackgroundColorMenu(QMenu *menu, QWidgetAction *widgetAction,
  734. ColorSelect *select,
  735. obs_sceneitem_t *item);
  736. void CreateSourcePopupMenu(int idx, bool preview);
  737. void UpdateTitleBar();
  738. void SystemTrayInit();
  739. void SystemTray(bool firstStarted);
  740. void OpenSavedProjectors();
  741. void CreateInteractionWindow(obs_source_t *source);
  742. void CreatePropertiesWindow(obs_source_t *source);
  743. void CreateFiltersWindow(obs_source_t *source);
  744. void CreateEditTransformWindow(obs_sceneitem_t *item);
  745. QAction *AddDockWidget(QDockWidget *dock);
  746. static OBSBasic *Get();
  747. const char *GetCurrentOutputPath();
  748. void DeleteProjector(OBSProjector *projector);
  749. void AddProjectorMenuMonitors(QMenu *parent, QObject *target,
  750. const char *slot);
  751. QIcon GetSourceIcon(const char *id) const;
  752. QIcon GetGroupIcon() const;
  753. QIcon GetSceneIcon() const;
  754. OBSWeakSource copyFilter;
  755. void ShowStatusBarMessage(const QString &message);
  756. static OBSData
  757. BackupScene(obs_scene_t *scene,
  758. std::vector<obs_source_t *> *sources = nullptr);
  759. void CreateSceneUndoRedoAction(const QString &action_name,
  760. OBSData undo_data, OBSData redo_data);
  761. static inline OBSData
  762. BackupScene(obs_source_t *scene_source,
  763. std::vector<obs_source_t *> *sources = nullptr)
  764. {
  765. obs_scene_t *scene = obs_scene_from_source(scene_source);
  766. return BackupScene(scene, sources);
  767. }
  768. void CreateFilterPasteUndoRedoAction(const QString &text,
  769. obs_source_t *source,
  770. obs_data_array_t *undo_array,
  771. obs_data_array_t *redo_array);
  772. void UpdateEditMenu();
  773. void SetDisplayAffinity(QWindow *window);
  774. QColor GetSelectionColor() const;
  775. protected:
  776. virtual void closeEvent(QCloseEvent *event) override;
  777. #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
  778. virtual bool nativeEvent(const QByteArray &eventType, void *message,
  779. qintptr *result) override;
  780. #else
  781. virtual bool nativeEvent(const QByteArray &eventType, void *message,
  782. long *result) override;
  783. #endif
  784. virtual void changeEvent(QEvent *event) override;
  785. private slots:
  786. void on_actionFullscreenInterface_triggered();
  787. void on_actionShow_Recordings_triggered();
  788. void on_actionRemux_triggered();
  789. void on_action_Settings_triggered();
  790. void on_actionShowMacPermissions_triggered();
  791. void on_actionShowMissingFiles_triggered();
  792. void on_actionAdvAudioProperties_triggered();
  793. void on_actionMixerToolbarAdvAudio_triggered();
  794. void on_actionMixerToolbarMenu_triggered();
  795. void on_actionShowLogs_triggered();
  796. void on_actionUploadCurrentLog_triggered();
  797. void on_actionUploadLastLog_triggered();
  798. void on_actionViewCurrentLog_triggered();
  799. void on_actionCheckForUpdates_triggered();
  800. void on_actionRepair_triggered();
  801. void on_actionShowCrashLogs_triggered();
  802. void on_actionUploadLastCrashLog_triggered();
  803. void on_actionEditTransform_triggered();
  804. void on_actionCopyTransform_triggered();
  805. void on_actionPasteTransform_triggered();
  806. void on_actionRotate90CW_triggered();
  807. void on_actionRotate90CCW_triggered();
  808. void on_actionRotate180_triggered();
  809. void on_actionFlipHorizontal_triggered();
  810. void on_actionFlipVertical_triggered();
  811. void on_actionFitToScreen_triggered();
  812. void on_actionStretchToScreen_triggered();
  813. void on_actionCenterToScreen_triggered();
  814. void on_actionVerticalCenter_triggered();
  815. void on_actionHorizontalCenter_triggered();
  816. void on_actionSceneFilters_triggered();
  817. void on_OBSBasic_customContextMenuRequested(const QPoint &pos);
  818. void on_scenes_currentItemChanged(QListWidgetItem *current,
  819. QListWidgetItem *prev);
  820. void on_scenes_customContextMenuRequested(const QPoint &pos);
  821. void GridActionClicked();
  822. void on_actionAddScene_triggered();
  823. void on_actionRemoveScene_triggered();
  824. void on_actionSceneUp_triggered();
  825. void on_actionSceneDown_triggered();
  826. void on_sources_customContextMenuRequested(const QPoint &pos);
  827. void on_scenes_itemDoubleClicked(QListWidgetItem *item);
  828. void on_actionAddSource_triggered();
  829. void on_actionRemoveSource_triggered();
  830. void on_actionInteract_triggered();
  831. void on_actionSourceProperties_triggered();
  832. void on_actionSourceUp_triggered();
  833. void on_actionSourceDown_triggered();
  834. void on_actionMoveUp_triggered();
  835. void on_actionMoveDown_triggered();
  836. void on_actionMoveToTop_triggered();
  837. void on_actionMoveToBottom_triggered();
  838. void on_actionLockPreview_triggered();
  839. void on_scalingMenu_aboutToShow();
  840. void on_actionScaleWindow_triggered();
  841. void on_actionScaleCanvas_triggered();
  842. void on_actionScaleOutput_triggered();
  843. void on_streamButton_clicked();
  844. void on_recordButton_clicked();
  845. void VCamButtonClicked();
  846. void VCamConfigButtonClicked();
  847. void on_settingsButton_clicked();
  848. void Screenshot(OBSSource source_ = nullptr);
  849. void ScreenshotSelectedSource();
  850. void ScreenshotProgram();
  851. void ScreenshotScene();
  852. void on_actionHelpPortal_triggered();
  853. void on_actionWebsite_triggered();
  854. void on_actionDiscord_triggered();
  855. void on_preview_customContextMenuRequested(const QPoint &pos);
  856. void ProgramViewContextMenuRequested(const QPoint &pos);
  857. void PreviewDisabledMenu(const QPoint &pos);
  858. void on_actionNewSceneCollection_triggered();
  859. void on_actionDupSceneCollection_triggered();
  860. void on_actionRenameSceneCollection_triggered();
  861. void on_actionRemoveSceneCollection_triggered();
  862. void on_actionImportSceneCollection_triggered();
  863. void on_actionExportSceneCollection_triggered();
  864. void on_actionNewProfile_triggered();
  865. void on_actionDupProfile_triggered();
  866. void on_actionRenameProfile_triggered();
  867. void on_actionRemoveProfile_triggered(bool skipConfirmation = false);
  868. void on_actionImportProfile_triggered();
  869. void on_actionExportProfile_triggered();
  870. void on_actionShowSettingsFolder_triggered();
  871. void on_actionShowProfileFolder_triggered();
  872. void on_actionAlwaysOnTop_triggered();
  873. void on_toggleListboxToolbars_toggled(bool visible);
  874. void on_toggleContextBar_toggled(bool visible);
  875. void on_toggleStatusBar_toggled(bool visible);
  876. void on_toggleSourceIcons_toggled(bool visible);
  877. void on_transitions_currentIndexChanged(int index);
  878. void on_transitionAdd_clicked();
  879. void on_transitionRemove_clicked();
  880. void on_transitionProps_clicked();
  881. void on_transitionDuration_valueChanged(int value);
  882. void on_tbar_position_valueChanged(int value);
  883. void ShowTransitionProperties();
  884. void HideTransitionProperties();
  885. void on_modeSwitch_clicked();
  886. // Source Context Buttons
  887. void on_sourcePropertiesButton_clicked();
  888. void on_sourceFiltersButton_clicked();
  889. void on_sourceInteractButton_clicked();
  890. void on_autoConfigure_triggered();
  891. void on_stats_triggered();
  892. void on_resetUI_triggered();
  893. void on_resetDocks_triggered(bool force = false);
  894. void on_lockDocks_toggled(bool lock);
  895. void on_multiviewProjectorWindowed_triggered();
  896. void PauseToggled();
  897. void logUploadFinished(const QString &text, const QString &error);
  898. void crashUploadFinished(const QString &text, const QString &error);
  899. void openLogDialog(const QString &text, const bool crash);
  900. void updateCheckFinished();
  901. void AddSourceFromAction();
  902. void MoveSceneToTop();
  903. void MoveSceneToBottom();
  904. void EditSceneName();
  905. void EditSceneItemName();
  906. void SceneNameEdited(QWidget *editor,
  907. QAbstractItemDelegate::EndEditHint endHint);
  908. void OpenSceneFilters();
  909. void OpenFilters(OBSSource source = nullptr);
  910. void OpenProperties(OBSSource source = nullptr);
  911. void OpenInteraction(OBSSource source = nullptr);
  912. void OpenEditTransform(OBSSceneItem item = nullptr);
  913. void EnablePreviewDisplay(bool enable);
  914. void TogglePreview();
  915. void OpenStudioProgramProjector();
  916. void OpenPreviewProjector();
  917. void OpenSourceProjector();
  918. void OpenMultiviewProjector();
  919. void OpenSceneProjector();
  920. void OpenStudioProgramWindow();
  921. void OpenPreviewWindow();
  922. void OpenSourceWindow();
  923. void OpenSceneWindow();
  924. void StackedMixerAreaContextMenuRequested();
  925. void ResizeOutputSizeOfSource();
  926. public slots:
  927. void on_actionResetTransform_triggered();
  928. bool StreamingActive();
  929. bool RecordingActive();
  930. bool ReplayBufferActive();
  931. bool VirtualCamActive();
  932. void ClearContextBar();
  933. void UpdateContextBar(bool force = false);
  934. void UpdateContextBarDeferred(bool force = false);
  935. void UpdateContextBarVisibility();
  936. private:
  937. std::unique_ptr<Ui::OBSBasic> ui;
  938. public:
  939. /* `undo_s` needs to be declared after `ui` to prevent an uninitialized
  940. * warning for `ui` while initializing `undo_s`. */
  941. undo_stack undo_s;
  942. explicit OBSBasic(QWidget *parent = 0);
  943. virtual ~OBSBasic();
  944. virtual void OBSInit() override;
  945. virtual config_t *Config() const override;
  946. virtual int GetProfilePath(char *path, size_t size,
  947. const char *file) const override;
  948. static void InitBrowserPanelSafeBlock();
  949. };
  950. class SceneRenameDelegate : public QStyledItemDelegate {
  951. Q_OBJECT
  952. public:
  953. SceneRenameDelegate(QObject *parent);
  954. virtual void setEditorData(QWidget *editor,
  955. const QModelIndex &index) const override;
  956. protected:
  957. virtual bool eventFilter(QObject *editor, QEvent *event) override;
  958. };