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 <vector>
  19. #include <memory>
  20. #include "window-main.hpp"
  21. #include "window-basic-interaction.hpp"
  22. #include "window-basic-properties.hpp"
  23. #include "window-basic-transform.hpp"
  24. #include "window-basic-adv-audio.hpp"
  25. #include "window-basic-filters.hpp"
  26. #include <util/platform.h>
  27. #include <util/util.hpp>
  28. #include <QPointer>
  29. class QListWidgetItem;
  30. class VolControl;
  31. class QNetworkReply;
  32. #include "ui_OBSBasic.h"
  33. #define DESKTOP_AUDIO_1 Str("DesktopAudioDevice1")
  34. #define DESKTOP_AUDIO_2 Str("DesktopAudioDevice2")
  35. #define AUX_AUDIO_1 Str("AuxAudioDevice1")
  36. #define AUX_AUDIO_2 Str("AuxAudioDevice2")
  37. #define AUX_AUDIO_3 Str("AuxAudioDevice3")
  38. #define SIMPLE_ENCODER_X264 "x264"
  39. #define SIMPLE_ENCODER_X264_LOWCPU "x264_lowcpu"
  40. struct BasicOutputHandler;
  41. enum class QtDataRole {
  42. OBSRef = Qt::UserRole,
  43. OBSSignals,
  44. };
  45. class OBSBasic : public OBSMainWindow {
  46. Q_OBJECT
  47. friend class OBSBasicPreview;
  48. friend class OBSBasicStatusBar;
  49. enum class MoveDir {
  50. Up,
  51. Down,
  52. Left,
  53. Right
  54. };
  55. private:
  56. std::vector<VolControl*> volumes;
  57. std::vector<OBSSignal> signalHandlers;
  58. bool loaded = false;
  59. long disableSaving = 1;
  60. bool projectChanged = false;
  61. QPointer<QThread> updateCheckThread;
  62. QPointer<QThread> logUploadThread;
  63. QPointer<OBSBasicInteraction> interaction;
  64. QPointer<OBSBasicProperties> properties;
  65. QPointer<OBSBasicTransform> transformWindow;
  66. QPointer<OBSBasicAdvAudio> advAudioWindow;
  67. QPointer<OBSBasicFilters> filters;
  68. QPointer<QTimer> cpuUsageTimer;
  69. os_cpu_usage_info_t *cpuUsageInfo = nullptr;
  70. OBSService service;
  71. std::unique_ptr<BasicOutputHandler> outputHandler;
  72. gs_vertbuffer_t *box = nullptr;
  73. gs_vertbuffer_t *circle = nullptr;
  74. bool sceneChanging = false;
  75. bool ignoreSelectionUpdate = false;
  76. int previewX = 0, previewY = 0;
  77. int previewCX = 0, previewCY = 0;
  78. float previewScale = 0.0f;
  79. ConfigFile basicConfig;
  80. QPointer<QWidget> projectors[10];
  81. QPointer<QMenu> startStreamMenu;
  82. void DrawBackdrop(float cx, float cy);
  83. void SetupEncoders();
  84. void CreateFirstRunSources();
  85. void CreateDefaultScene(bool firstStart);
  86. void ClearVolumeControls();
  87. void UploadLog(const char *file);
  88. void Save(const char *file);
  89. void Load(const char *file);
  90. void InitHotkeys();
  91. void CreateHotkeys();
  92. void ClearHotkeys();
  93. bool InitService();
  94. bool InitBasicConfigDefaults();
  95. bool InitBasicConfig();
  96. void InitOBSCallbacks();
  97. void InitPrimitives();
  98. OBSSceneItem GetSceneItem(QListWidgetItem *item);
  99. OBSSceneItem GetCurrentSceneItem();
  100. bool QueryRemoveSource(obs_source_t *source);
  101. void TimedCheckForUpdates();
  102. void CheckForUpdates();
  103. void GetFPSCommon(uint32_t &num, uint32_t &den) const;
  104. void GetFPSInteger(uint32_t &num, uint32_t &den) const;
  105. void GetFPSFraction(uint32_t &num, uint32_t &den) const;
  106. void GetFPSNanoseconds(uint32_t &num, uint32_t &den) const;
  107. void GetConfigFPS(uint32_t &num, uint32_t &den) const;
  108. void UpdateSources(OBSScene scene);
  109. void InsertSceneItem(obs_sceneitem_t *item);
  110. void LoadSceneListOrder(obs_data_array_t *array);
  111. obs_data_array_t *SaveSceneListOrder();
  112. void ChangeSceneIndex(bool relative, int idx, int invalidIdx);
  113. void TempFileOutput(const char *path, int vBitrate, int aBitrate);
  114. void TempStreamOutput(const char *url, const char *key,
  115. int vBitrate, int aBitrate);
  116. void CreateInteractionWindow(obs_source_t *source);
  117. void CreatePropertiesWindow(obs_source_t *source);
  118. void CreateFiltersWindow(obs_source_t *source);
  119. void CloseDialogs();
  120. void ClearSceneData();
  121. void Nudge(int dist, MoveDir dir);
  122. void OpenProjector(obs_source_t *source, int monitor);
  123. void GetAudioSourceFilters();
  124. void GetAudioSourceProperties();
  125. void VolControlContextMenu();
  126. void AddSceneCollection(bool create_new);
  127. void RefreshSceneCollections();
  128. void ChangeSceneCollection();
  129. void LoadProfile();
  130. void ResetProfileData();
  131. bool AddProfile(bool create_new, const char *title, const char *text,
  132. const char *init_text = nullptr);
  133. void DeleteProfile(const char *profile_name, const char *profile_dir);
  134. void RefreshProfiles();
  135. void ChangeProfile();
  136. void SaveProjectNow();
  137. obs_hotkey_pair_id streamingHotkeys, recordingHotkeys;
  138. obs_hotkey_id forceStreamingStopHotkey;
  139. public slots:
  140. void StartStreaming();
  141. void StopStreaming();
  142. void ForceStopStreaming();
  143. void StreamDelayStarting(int sec);
  144. void StreamDelayStopping(int sec);
  145. void StreamingStart();
  146. void StreamingStop(int errorcode);
  147. void StartRecording();
  148. void StopRecording();
  149. void RecordingStart();
  150. void RecordingStop(int code);
  151. void SaveProjectDeferred();
  152. void SaveProject();
  153. private slots:
  154. void AddSceneItem(OBSSceneItem item);
  155. void RemoveSceneItem(OBSSceneItem item);
  156. void AddScene(OBSSource source);
  157. void RemoveScene(OBSSource source);
  158. void UpdateSceneSelection(OBSSource source);
  159. void RenameSources(QString newName, QString prevName);
  160. void SelectSceneItem(OBSScene scene, OBSSceneItem item, bool select);
  161. void ActivateAudioSource(OBSSource source);
  162. void DeactivateAudioSource(OBSSource source);
  163. void DuplicateSelectedScene();
  164. void RemoveSelectedScene();
  165. void RemoveSelectedSceneItem();
  166. void ReorderSources(OBSScene scene);
  167. void ProcessHotkey(obs_hotkey_id id, bool pressed);
  168. private:
  169. /* OBS Callbacks */
  170. static void SceneReordered(void *data, calldata_t *params);
  171. static void SceneItemAdded(void *data, calldata_t *params);
  172. static void SceneItemRemoved(void *data, calldata_t *params);
  173. static void SceneItemSelected(void *data, calldata_t *params);
  174. static void SceneItemDeselected(void *data, calldata_t *params);
  175. static void SourceLoaded(void *data, calldata_t *params);
  176. static void SourceRemoved(void *data, calldata_t *params);
  177. static void SourceActivated(void *data, calldata_t *params);
  178. static void SourceDeactivated(void *data, calldata_t *params);
  179. static void SourceRenamed(void *data, calldata_t *params);
  180. static void ChannelChanged(void *data, calldata_t *params);
  181. static void RenderMain(void *data, uint32_t cx, uint32_t cy);
  182. void ResizePreview(uint32_t cx, uint32_t cy);
  183. void AddSource(const char *id);
  184. QMenu *CreateAddSourcePopupMenu();
  185. void AddSourcePopupMenu(const QPoint &pos);
  186. void copyActionsDynamicProperties();
  187. static void HotkeyTriggered(void *data, obs_hotkey_id id, bool pressed);
  188. public:
  189. OBSScene GetCurrentScene();
  190. inline OBSSource GetCurrentSceneSource()
  191. {
  192. OBSScene curScene = GetCurrentScene();
  193. return OBSSource(obs_scene_get_source(curScene));
  194. }
  195. obs_service_t *GetService();
  196. void SetService(obs_service_t *service);
  197. bool StreamingActive();
  198. int ResetVideo();
  199. bool ResetAudio();
  200. void ResetOutputs();
  201. void ResetAudioDevice(const char *sourceId, const char *deviceId,
  202. const char *deviceDesc, int channel);
  203. void NewProject();
  204. void LoadProject();
  205. inline void GetDisplayRect(int &x, int &y, int &cx, int &cy)
  206. {
  207. x = previewX;
  208. y = previewY;
  209. cx = previewCX;
  210. cy = previewCY;
  211. }
  212. inline double GetCPUUsage() const
  213. {
  214. return os_cpu_usage_info_query(cpuUsageInfo);
  215. }
  216. void SaveService();
  217. bool LoadService();
  218. void ReorderSceneItem(obs_sceneitem_t *item, size_t idx);
  219. void CreateSourcePopupMenu(QListWidgetItem *item, bool preview);
  220. void UpdateTitleBar();
  221. protected:
  222. virtual void closeEvent(QCloseEvent *event) override;
  223. virtual void changeEvent(QEvent *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. };