1
0

window-basic-auto-config.hpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. #pragma once
  2. #include <QWizard>
  3. #include <QPointer>
  4. #include <QFormLayout>
  5. #include <QWizardPage>
  6. #include <condition_variable>
  7. #include <utility>
  8. #include <thread>
  9. #include <memory>
  10. #include <vector>
  11. #include <string>
  12. #include <mutex>
  13. class Ui_AutoConfigStartPage;
  14. class Ui_AutoConfigVideoPage;
  15. class Ui_AutoConfigStreamPage;
  16. class Ui_AutoConfigTestPage;
  17. class AutoConfigStreamPage;
  18. class Auth;
  19. class AutoConfig : public QWizard {
  20. Q_OBJECT
  21. friend class AutoConfigStartPage;
  22. friend class AutoConfigVideoPage;
  23. friend class AutoConfigStreamPage;
  24. friend class AutoConfigTestPage;
  25. enum class Type {
  26. Invalid,
  27. Streaming,
  28. Recording
  29. };
  30. enum class Service {
  31. Twitch,
  32. Smashcast,
  33. Other
  34. };
  35. enum class Encoder {
  36. x264,
  37. NVENC,
  38. QSV,
  39. AMD,
  40. Stream
  41. };
  42. enum class Quality {
  43. Stream,
  44. High
  45. };
  46. enum class FPSType : int {
  47. PreferHighFPS,
  48. PreferHighRes,
  49. UseCurrent,
  50. fps30,
  51. fps60
  52. };
  53. static inline const char *GetEncoderId(Encoder enc);
  54. AutoConfigStreamPage *streamPage = nullptr;
  55. Service service = Service::Other;
  56. Quality recordingQuality = Quality::Stream;
  57. Encoder recordingEncoder = Encoder::Stream;
  58. Encoder streamingEncoder = Encoder::x264;
  59. Type type = Type::Streaming;
  60. FPSType fpsType = FPSType::PreferHighFPS;
  61. int idealBitrate = 2500;
  62. int baseResolutionCX = 1920;
  63. int baseResolutionCY = 1080;
  64. int idealResolutionCX = 1280;
  65. int idealResolutionCY = 720;
  66. int idealFPSNum = 60;
  67. int idealFPSDen = 1;
  68. std::string serviceName;
  69. std::string serverName;
  70. std::string server;
  71. std::string key;
  72. bool hardwareEncodingAvailable = false;
  73. bool nvencAvailable = false;
  74. bool qsvAvailable = false;
  75. bool vceAvailable = false;
  76. int startingBitrate = 2500;
  77. bool customServer = false;
  78. bool bandwidthTest = false;
  79. bool testRegions = true;
  80. bool twitchAuto = false;
  81. bool regionUS = true;
  82. bool regionEU = true;
  83. bool regionAsia = true;
  84. bool regionOther = true;
  85. bool preferHighFPS = false;
  86. bool preferHardware = false;
  87. int specificFPSNum = 0;
  88. int specificFPSDen = 0;
  89. void TestHardwareEncoding();
  90. bool CanTestServer(const char *server);
  91. virtual void done(int result) override;
  92. void SaveStreamSettings();
  93. void SaveSettings();
  94. public:
  95. AutoConfig(QWidget *parent);
  96. ~AutoConfig();
  97. enum Page {
  98. StartPage,
  99. VideoPage,
  100. StreamPage,
  101. TestPage
  102. };
  103. };
  104. class AutoConfigStartPage : public QWizardPage {
  105. Q_OBJECT
  106. friend class AutoConfig;
  107. Ui_AutoConfigStartPage *ui;
  108. public:
  109. AutoConfigStartPage(QWidget *parent = nullptr);
  110. ~AutoConfigStartPage();
  111. virtual int nextId() const override;
  112. public slots:
  113. void on_prioritizeStreaming_clicked();
  114. void on_prioritizeRecording_clicked();
  115. };
  116. class AutoConfigVideoPage : public QWizardPage {
  117. Q_OBJECT
  118. friend class AutoConfig;
  119. Ui_AutoConfigVideoPage *ui;
  120. public:
  121. AutoConfigVideoPage(QWidget *parent = nullptr);
  122. ~AutoConfigVideoPage();
  123. virtual int nextId() const override;
  124. virtual bool validatePage() override;
  125. };
  126. class AutoConfigStreamPage : public QWizardPage {
  127. Q_OBJECT
  128. friend class AutoConfig;
  129. enum class Section : int {
  130. Connect,
  131. StreamKey,
  132. };
  133. std::shared_ptr<Auth> auth;
  134. Ui_AutoConfigStreamPage *ui;
  135. QString lastService;
  136. bool ready = false;
  137. void LoadServices(bool showAll);
  138. inline bool IsCustom() const;
  139. public:
  140. AutoConfigStreamPage(QWidget *parent = nullptr);
  141. ~AutoConfigStreamPage();
  142. virtual bool isComplete() const override;
  143. virtual int nextId() const override;
  144. virtual bool validatePage() override;
  145. void OnAuthConnected();
  146. void OnOAuthStreamKeyConnected();
  147. public slots:
  148. void on_show_clicked();
  149. void on_connectAccount_clicked();
  150. void on_disconnectAccount_clicked();
  151. void on_useStreamKey_clicked();
  152. void ServiceChanged();
  153. void UpdateKeyLink();
  154. void UpdateServerList();
  155. void UpdateCompleted();
  156. };
  157. class AutoConfigTestPage : public QWizardPage {
  158. Q_OBJECT
  159. friend class AutoConfig;
  160. QPointer<QFormLayout> results;
  161. Ui_AutoConfigTestPage *ui;
  162. std::thread testThread;
  163. std::condition_variable cv;
  164. std::mutex m;
  165. bool cancel = false;
  166. bool started = false;
  167. enum class Stage {
  168. Starting,
  169. BandwidthTest,
  170. StreamEncoder,
  171. RecordingEncoder,
  172. Finished
  173. };
  174. Stage stage = Stage::Starting;
  175. bool softwareTested = false;
  176. void StartBandwidthStage();
  177. void StartStreamEncoderStage();
  178. void StartRecordingEncoderStage();
  179. void FindIdealHardwareResolution();
  180. bool TestSoftwareEncoding();
  181. void TestBandwidthThread();
  182. void TestStreamEncoderThread();
  183. void TestRecordingEncoderThread();
  184. void FinalizeResults();
  185. struct ServerInfo {
  186. std::string name;
  187. std::string address;
  188. int bitrate = 0;
  189. int ms = -1;
  190. inline ServerInfo() {}
  191. inline ServerInfo(const char *name_, const char *address_)
  192. : name(name_), address(address_)
  193. {
  194. }
  195. };
  196. void GetServers(std::vector<ServerInfo> &servers);
  197. public:
  198. AutoConfigTestPage(QWidget *parent = nullptr);
  199. ~AutoConfigTestPage();
  200. virtual void initializePage() override;
  201. virtual void cleanupPage() override;
  202. virtual bool isComplete() const override;
  203. virtual int nextId() const override;
  204. public slots:
  205. void NextStage();
  206. void UpdateMessage(QString message);
  207. void Failure(QString message);
  208. void Progress(int percentage);
  209. };