window-basic-auto-config.hpp 4.6 KB

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