window-basic-main.hpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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 <obs.hpp>
  18. #include <unordered_map>
  19. #include <vector>
  20. #include <memory>
  21. #include "window-main.hpp"
  22. #include "window-basic-interaction.hpp"
  23. #include "window-basic-properties.hpp"
  24. #include "window-basic-transform.hpp"
  25. #include "window-basic-adv-audio.hpp"
  26. #include "window-basic-filters.hpp"
  27. #include <util/platform.h>
  28. #include <util/util.hpp>
  29. #include <QPointer>
  30. class QListWidgetItem;
  31. class VolControl;
  32. class QNetworkReply;
  33. #include "ui_OBSBasic.h"
  34. #define DESKTOP_AUDIO_1 Str("DesktopAudioDevice1")
  35. #define DESKTOP_AUDIO_2 Str("DesktopAudioDevice2")
  36. #define AUX_AUDIO_1 Str("AuxAudioDevice1")
  37. #define AUX_AUDIO_2 Str("AuxAudioDevice2")
  38. #define AUX_AUDIO_3 Str("AuxAudioDevice3")
  39. #define SIMPLE_ENCODER_X264 "x264"
  40. #define SIMPLE_ENCODER_X264_LOWCPU "x264_lowcpu"
  41. struct BasicOutputHandler;
  42. enum class QtDataRole {
  43. OBSRef = Qt::UserRole,
  44. OBSSignals,
  45. };
  46. class OBSBasic : public OBSMainWindow {
  47. Q_OBJECT
  48. friend class OBSBasicPreview;
  49. friend class OBSBasicStatusBar;
  50. enum class MoveDir {
  51. Up,
  52. Down,
  53. Left,
  54. Right
  55. };
  56. private:
  57. std::unordered_map<obs_source_t*, int> sourceSceneRefs;
  58. std::vector<VolControl*> volumes;
  59. std::vector<OBSSignal> signalHandlers;
  60. bool loaded = false;
  61. long disableSaving = 1;
  62. bool projectChanged = false;
  63. QPointer<QThread> updateCheckThread;
  64. QPointer<QThread> logUploadThread;
  65. QPointer<OBSBasicInteraction> interaction;
  66. QPointer<OBSBasicProperties> properties;
  67. QPointer<OBSBasicTransform> transformWindow;
  68. QPointer<OBSBasicAdvAudio> advAudioWindow;
  69. QPointer<OBSBasicFilters> filters;
  70. QPointer<QTimer> cpuUsageTimer;
  71. os_cpu_usage_info_t *cpuUsageInfo = nullptr;
  72. os_inhibit_t *sleepInhibitor = nullptr;
  73. OBSService service;
  74. std::unique_ptr<BasicOutputHandler> outputHandler;
  75. gs_vertbuffer_t *box = nullptr;
  76. gs_vertbuffer_t *circle = nullptr;
  77. bool sceneChanging = false;
  78. bool ignoreSelectionUpdate = false;
  79. int previewX = 0, previewY = 0;
  80. int previewCX = 0, previewCY = 0;
  81. float previewScale = 0.0f;
  82. ConfigFile basicConfig;
  83. QPointer<QWidget> projectors[10];
  84. QPointer<QMenu> startStreamMenu;
  85. void DrawBackdrop(float cx, float cy);
  86. void SetupEncoders();
  87. void CreateFirstRunSources();
  88. void CreateDefaultScene(bool firstStart);
  89. void ClearVolumeControls();
  90. void UploadLog(const char *file);
  91. void Save(const char *file);
  92. void Load(const char *file);
  93. void InitHotkeys();
  94. void CreateHotkeys();
  95. void ClearHotkeys();
  96. bool InitService();
  97. bool InitBasicConfigDefaults();
  98. bool InitBasicConfig();
  99. void InitOBSCallbacks();
  100. void InitPrimitives();
  101. OBSSceneItem GetSceneItem(QListWidgetItem *item);
  102. OBSSceneItem GetCurrentSceneItem();
  103. bool QueryRemoveSource(obs_source_t *source);
  104. void TimedCheckForUpdates();
  105. void CheckForUpdates();
  106. void GetFPSCommon(uint32_t &num, uint32_t &den) const;
  107. void GetFPSInteger(uint32_t &num, uint32_t &den) const;
  108. void GetFPSFraction(uint32_t &num, uint32_t &den) const;
  109. void GetFPSNanoseconds(uint32_t &num, uint32_t &den) const;
  110. void GetConfigFPS(uint32_t &num, uint32_t &den) const;
  111. void UpdateSources(OBSScene scene);
  112. void InsertSceneItem(obs_sceneitem_t *item);
  113. void LoadSceneListOrder(obs_data_array_t *array);
  114. obs_data_array_t *SaveSceneListOrder();
  115. void ChangeSceneIndex(bool relative, int idx, int invalidIdx);
  116. void TempFileOutput(const char *path, int vBitrate, int aBitrate);
  117. void TempStreamOutput(const char *url, const char *key,
  118. int vBitrate, int aBitrate);
  119. void CreateInteractionWindow(obs_source_t *source);
  120. void CreatePropertiesWindow(obs_source_t *source);
  121. void CreateFiltersWindow(obs_source_t *source);
  122. void CloseDialogs();
  123. void ClearSceneData();
  124. void CleanupUnusedSources();
  125. void Nudge(int dist, MoveDir dir);
  126. void OpenProjector(obs_source_t *source, int monitor);
  127. void GetAudioSourceFilters();
  128. void GetAudioSourceProperties();
  129. void VolControlContextMenu();
  130. void AddSceneCollection(bool create_new);
  131. void RefreshSceneCollections();
  132. void ChangeSceneCollection();
  133. void LoadProfile();
  134. void ResetProfileData();
  135. bool AddProfile(bool create_new, const char *title, const char *text,
  136. const char *init_text = nullptr);
  137. void DeleteProfile(const char *profile_name, const char *profile_dir);
  138. void RefreshProfiles();
  139. void ChangeProfile();
  140. void SaveProjectNow();
  141. obs_hotkey_pair_id streamingHotkeys, recordingHotkeys;
  142. obs_hotkey_id forceStreamingStopHotkey;
  143. public slots:
  144. void StartStreaming();
  145. void StopStreaming();
  146. void ForceStopStreaming();
  147. void StreamDelayStarting(int sec);
  148. void StreamDelayStopping(int sec);
  149. void StreamingStart();
  150. void StreamingStop(int errorcode);
  151. void StartRecording();
  152. void StopRecording();
  153. void RecordingStart();
  154. void RecordingStop(int code);
  155. void SaveProjectDeferred();
  156. void SaveProject();
  157. private slots:
  158. void AddSceneItem(OBSSceneItem item);
  159. void RemoveSceneItem(OBSSceneItem item);
  160. void AddScene(OBSSource source);
  161. void RemoveScene(OBSSource source);
  162. void UpdateSceneSelection(OBSSource source);
  163. void RenameSources(QString newName, QString prevName);
  164. void SelectSceneItem(OBSScene scene, OBSSceneItem item, bool select);
  165. void ActivateAudioSource(OBSSource source);
  166. void DeactivateAudioSource(OBSSource source);
  167. void DuplicateSelectedScene();
  168. void RemoveSelectedScene();
  169. void RemoveSelectedSceneItem();
  170. void ReorderSources(OBSScene scene);
  171. void ProcessHotkey(obs_hotkey_id id, bool pressed);
  172. private:
  173. /* OBS Callbacks */
  174. static void SceneReordered(void *data, calldata_t *params);
  175. static void SceneItemAdded(void *data, calldata_t *params);
  176. static void SceneItemRemoved(void *data, calldata_t *params);
  177. static void SceneItemSelected(void *data, calldata_t *params);
  178. static void SceneItemDeselected(void *data, calldata_t *params);
  179. static void SourceAdded(void *data, calldata_t *params);
  180. static void SourceRemoved(void *data, calldata_t *params);
  181. static void SourceActivated(void *data, calldata_t *params);
  182. static void SourceDeactivated(void *data, calldata_t *params);
  183. static void SourceRenamed(void *data, calldata_t *params);
  184. static void ChannelChanged(void *data, calldata_t *params);
  185. static void RenderMain(void *data, uint32_t cx, uint32_t cy);
  186. void ResizePreview(uint32_t cx, uint32_t cy);
  187. void AddSource(const char *id);
  188. QMenu *CreateAddSourcePopupMenu();
  189. void AddSourcePopupMenu(const QPoint &pos);
  190. void copyActionsDynamicProperties();
  191. static void HotkeyTriggered(void *data, obs_hotkey_id id, bool pressed);
  192. public:
  193. OBSScene GetCurrentScene();
  194. obs_service_t *GetService();
  195. void SetService(obs_service_t *service);
  196. bool StreamingActive();
  197. int ResetVideo();
  198. bool ResetAudio();
  199. void ResetOutputs();
  200. void ResetAudioDevice(const char *sourceId, const char *deviceId,
  201. const char *deviceDesc, int channel);
  202. void NewProject();
  203. void LoadProject();
  204. inline void GetDisplayRect(int &x, int &y, int &cx, int &cy)
  205. {
  206. x = previewX;
  207. y = previewY;
  208. cx = previewCX;
  209. cy = previewCY;
  210. }
  211. inline double GetCPUUsage() const
  212. {
  213. return os_cpu_usage_info_query(cpuUsageInfo);
  214. }
  215. void SaveService();
  216. bool LoadService();
  217. void ReorderSceneItem(obs_sceneitem_t *item, size_t idx);
  218. void CreateSourcePopupMenu(QListWidgetItem *item, bool preview);
  219. void UpdateTitleBar();
  220. protected:
  221. virtual void closeEvent(QCloseEvent *event) override;
  222. virtual void changeEvent(QEvent *event) override;
  223. virtual void resizeEvent(QResizeEvent *event) override;
  224. private slots:
  225. void on_actionShow_Recordings_triggered();
  226. void on_actionRemux_triggered();
  227. void on_action_Settings_triggered();
  228. void on_actionAdvAudioProperties_triggered();
  229. void on_advAudioProps_clicked();
  230. void on_advAudioProps_destroyed();
  231. void on_actionShowLogs_triggered();
  232. void on_actionUploadCurrentLog_triggered();
  233. void on_actionUploadLastLog_triggered();
  234. void on_actionViewCurrentLog_triggered();
  235. void on_actionCheckForUpdates_triggered();
  236. void on_actionEditTransform_triggered();
  237. void on_actionResetTransform_triggered();
  238. void on_actionRotate90CW_triggered();
  239. void on_actionRotate90CCW_triggered();
  240. void on_actionRotate180_triggered();
  241. void on_actionFlipHorizontal_triggered();
  242. void on_actionFlipVertical_triggered();
  243. void on_actionFitToScreen_triggered();
  244. void on_actionStretchToScreen_triggered();
  245. void on_actionCenterToScreen_triggered();
  246. void on_scenes_currentItemChanged(QListWidgetItem *current,
  247. QListWidgetItem *prev);
  248. void on_scenes_customContextMenuRequested(const QPoint &pos);
  249. void on_actionAddScene_triggered();
  250. void on_actionRemoveScene_triggered();
  251. void on_actionSceneUp_triggered();
  252. void on_actionSceneDown_triggered();
  253. void on_sources_itemSelectionChanged();
  254. void on_sources_customContextMenuRequested(const QPoint &pos);
  255. void on_sources_itemDoubleClicked(QListWidgetItem *item);
  256. void on_actionAddSource_triggered();
  257. void on_actionRemoveSource_triggered();
  258. void on_actionInteract_triggered();
  259. void on_actionSourceProperties_triggered();
  260. void on_actionSourceUp_triggered();
  261. void on_actionSourceDown_triggered();
  262. void on_actionMoveUp_triggered();
  263. void on_actionMoveDown_triggered();
  264. void on_actionMoveToTop_triggered();
  265. void on_actionMoveToBottom_triggered();
  266. void on_streamButton_clicked();
  267. void on_recordButton_clicked();
  268. void on_settingsButton_clicked();
  269. void on_actionWebsite_triggered();
  270. void on_preview_customContextMenuRequested(const QPoint &pos);
  271. void on_previewDisabledLabel_customContextMenuRequested(
  272. const QPoint &pos);
  273. void on_actionNewSceneCollection_triggered();
  274. void on_actionDupSceneCollection_triggered();
  275. void on_actionRenameSceneCollection_triggered();
  276. void on_actionRemoveSceneCollection_triggered();
  277. void on_actionNewProfile_triggered();
  278. void on_actionDupProfile_triggered();
  279. void on_actionRenameProfile_triggered();
  280. void on_actionRemoveProfile_triggered();
  281. void on_actionShowSettingsFolder_triggered();
  282. void on_actionShowProfileFolder_triggered();
  283. void logUploadFinished(const QString &text, const QString &error);
  284. void updateFileFinished(const QString &text, const QString &error);
  285. void AddSourceFromAction();
  286. void MoveSceneToTop();
  287. void MoveSceneToBottom();
  288. void EditSceneName();
  289. void EditSceneItemName();
  290. void SceneNameEdited(QWidget *editor,
  291. QAbstractItemDelegate::EndEditHint endHint);
  292. void SceneItemNameEdited(QWidget *editor,
  293. QAbstractItemDelegate::EndEditHint endHint);
  294. void OpenSceneFilters();
  295. void OpenFilters();
  296. void TogglePreview();
  297. void NudgeUp();
  298. void NudgeDown();
  299. void NudgeLeft();
  300. void NudgeRight();
  301. void OpenPreviewProjector();
  302. void OpenSourceProjector();
  303. void OpenSceneProjector();
  304. public:
  305. explicit OBSBasic(QWidget *parent = 0);
  306. virtual ~OBSBasic();
  307. virtual void OBSInit() override;
  308. virtual config_t *Config() const override;
  309. virtual int GetProfilePath(char *path, size_t size, const char *file)
  310. const override;
  311. private:
  312. std::unique_ptr<Ui::OBSBasic> ui;
  313. };