yolobs-studio/UI/window-basic-auto-config.hpp

272 lines
5.1 KiB
C++
Raw Permalink Normal View History

2017-06-29 19:01:10 +00:00
#pragma once
#include <QWizard>
#include <QPointer>
#include <QFormLayout>
#include <QWizardPage>
#include <condition_variable>
#include <utility>
#include <thread>
2019-07-27 12:47:10 +00:00
#include <memory>
2017-06-29 19:01:10 +00:00
#include <vector>
#include <string>
#include <mutex>
class Ui_AutoConfigStartPage;
class Ui_AutoConfigVideoPage;
class Ui_AutoConfigStreamPage;
class Ui_AutoConfigTestPage;
2019-07-27 12:47:10 +00:00
class AutoConfigStreamPage;
class Auth;
2017-06-29 19:01:10 +00:00
class AutoConfig : public QWizard {
Q_OBJECT
friend class AutoConfigStartPage;
friend class AutoConfigVideoPage;
friend class AutoConfigStreamPage;
friend class AutoConfigTestPage;
enum class Type {
Invalid,
Streaming,
2019-09-22 21:19:10 +00:00
Recording,
2020-10-01 20:15:25 +00:00
VirtualCam,
2017-06-29 19:01:10 +00:00
};
enum class Service {
Twitch,
2018-02-19 19:54:37 +00:00
Smashcast,
2019-09-22 21:19:10 +00:00
Other,
2017-06-29 19:01:10 +00:00
};
enum class Encoder {
x264,
NVENC,
QSV,
AMD,
2019-09-22 21:19:10 +00:00
Stream,
2017-06-29 19:01:10 +00:00
};
enum class Quality {
Stream,
2019-09-22 21:19:10 +00:00
High,
2017-06-29 19:01:10 +00:00
};
enum class FPSType : int {
PreferHighFPS,
PreferHighRes,
UseCurrent,
fps30,
2019-09-22 21:19:10 +00:00
fps60,
2017-06-29 19:01:10 +00:00
};
static inline const char *GetEncoderId(Encoder enc);
2019-07-27 12:47:10 +00:00
AutoConfigStreamPage *streamPage = nullptr;
2017-06-29 19:01:10 +00:00
Service service = Service::Other;
Quality recordingQuality = Quality::Stream;
Encoder recordingEncoder = Encoder::Stream;
Encoder streamingEncoder = Encoder::x264;
Type type = Type::Streaming;
FPSType fpsType = FPSType::PreferHighFPS;
int idealBitrate = 2500;
int baseResolutionCX = 1920;
int baseResolutionCY = 1080;
int idealResolutionCX = 1280;
int idealResolutionCY = 720;
int idealFPSNum = 60;
int idealFPSDen = 1;
std::string serviceName;
std::string serverName;
std::string server;
std::string key;
bool hardwareEncodingAvailable = false;
bool nvencAvailable = false;
bool qsvAvailable = false;
bool vceAvailable = false;
int startingBitrate = 2500;
bool customServer = false;
bool bandwidthTest = false;
bool testRegions = true;
2018-02-19 19:54:37 +00:00
bool twitchAuto = false;
2017-06-29 19:01:10 +00:00
bool regionUS = true;
bool regionEU = true;
bool regionAsia = true;
bool regionOther = true;
bool preferHighFPS = false;
bool preferHardware = false;
int specificFPSNum = 0;
int specificFPSDen = 0;
void TestHardwareEncoding();
bool CanTestServer(const char *server);
virtual void done(int result) override;
void SaveStreamSettings();
void SaveSettings();
public:
AutoConfig(QWidget *parent);
~AutoConfig();
enum Page {
StartPage,
VideoPage,
StreamPage,
2019-09-22 21:19:10 +00:00
TestPage,
2017-06-29 19:01:10 +00:00
};
};
class AutoConfigStartPage : public QWizardPage {
Q_OBJECT
friend class AutoConfig;
Ui_AutoConfigStartPage *ui;
public:
AutoConfigStartPage(QWidget *parent = nullptr);
~AutoConfigStartPage();
virtual int nextId() const override;
public slots:
void on_prioritizeStreaming_clicked();
void on_prioritizeRecording_clicked();
2020-10-01 20:15:25 +00:00
void PrioritizeVCam();
2017-06-29 19:01:10 +00:00
};
class AutoConfigVideoPage : public QWizardPage {
Q_OBJECT
friend class AutoConfig;
Ui_AutoConfigVideoPage *ui;
public:
AutoConfigVideoPage(QWidget *parent = nullptr);
~AutoConfigVideoPage();
virtual int nextId() const override;
virtual bool validatePage() override;
};
class AutoConfigStreamPage : public QWizardPage {
Q_OBJECT
friend class AutoConfig;
2019-07-27 12:47:10 +00:00
enum class Section : int {
Connect,
StreamKey,
};
std::shared_ptr<Auth> auth;
2017-06-29 19:01:10 +00:00
Ui_AutoConfigStreamPage *ui;
QString lastService;
bool ready = false;
void LoadServices(bool showAll);
2020-03-25 08:07:22 +00:00
inline bool IsCustomService() const;
2017-06-29 19:01:10 +00:00
public:
AutoConfigStreamPage(QWidget *parent = nullptr);
~AutoConfigStreamPage();
virtual bool isComplete() const override;
virtual int nextId() const override;
virtual bool validatePage() override;
2019-07-27 12:47:10 +00:00
void OnAuthConnected();
void OnOAuthStreamKeyConnected();
2017-06-29 19:01:10 +00:00
public slots:
void on_show_clicked();
2019-07-27 12:47:10 +00:00
void on_connectAccount_clicked();
void on_disconnectAccount_clicked();
void on_useStreamKey_clicked();
2017-06-29 19:01:10 +00:00
void ServiceChanged();
void UpdateKeyLink();
2020-12-22 17:32:50 +00:00
void UpdateMoreInfoLink();
2017-06-29 19:01:10 +00:00
void UpdateServerList();
void UpdateCompleted();
};
class AutoConfigTestPage : public QWizardPage {
Q_OBJECT
friend class AutoConfig;
QPointer<QFormLayout> results;
Ui_AutoConfigTestPage *ui;
std::thread testThread;
std::condition_variable cv;
std::mutex m;
bool cancel = false;
bool started = false;
enum class Stage {
Starting,
BandwidthTest,
StreamEncoder,
RecordingEncoder,
2019-09-22 21:19:10 +00:00
Finished,
2017-06-29 19:01:10 +00:00
};
Stage stage = Stage::Starting;
bool softwareTested = false;
void StartBandwidthStage();
void StartStreamEncoderStage();
void StartRecordingEncoderStage();
void FindIdealHardwareResolution();
bool TestSoftwareEncoding();
void TestBandwidthThread();
void TestStreamEncoderThread();
void TestRecordingEncoderThread();
void FinalizeResults();
struct ServerInfo {
std::string name;
std::string address;
int bitrate = 0;
int ms = -1;
inline ServerInfo() {}
inline ServerInfo(const char *name_, const char *address_)
: name(name_), address(address_)
{
}
};
void GetServers(std::vector<ServerInfo> &servers);
public:
AutoConfigTestPage(QWidget *parent = nullptr);
~AutoConfigTestPage();
virtual void initializePage() override;
virtual void cleanupPage() override;
virtual bool isComplete() const override;
virtual int nextId() const override;
public slots:
void NextStage();
void UpdateMessage(QString message);
void Failure(QString message);
void Progress(int percentage);
};