refactor: move config from server

This commit is contained in:
Barry 2022-04-09 20:57:10 +08:00
parent 2088c7f76f
commit 2acb11ac23
6 changed files with 27 additions and 21 deletions

View file

@ -335,6 +335,8 @@ void Device::startServer()
// only one devices, serial can be null
// mark: crop input format: "width:height:x:y" or "" for no crop, for example: "100:200:0:0"
Server::ServerParams params;
params.serverLocalPath = m_params.serverLocalPath;
params.serverRemotePath = m_params.serverRemotePath;
params.serial = m_params.serial;
params.localPort = m_params.localPort;
params.maxSize = m_params.maxSize;

View file

@ -25,6 +25,8 @@ class Device : public QObject
public:
struct DeviceParams
{
QString serverLocalPath = ""; // 本地安卓server路径
QString serverRemotePath = ""; // 要推送到远端设备的server路径
QString recordFileName = ""; // 视频录制文件名
QString recordPath = ""; // 视频保存路径
QString serial = ""; // 设备序列号

View file

@ -47,24 +47,12 @@ Server::Server(QObject *parent) : QObject(parent)
Server::~Server() {}
const QString &Server::getServerPath()
{
if (m_serverPath.isEmpty()) {
m_serverPath = QString::fromLocal8Bit(qgetenv("QTSCRCPY_SERVER_PATH"));
QFileInfo fileInfo(m_serverPath);
if (m_serverPath.isEmpty() || !fileInfo.isFile()) {
m_serverPath = QCoreApplication::applicationDirPath() + "/scrcpy-server";
}
}
return m_serverPath;
}
bool Server::pushServer()
{
if (m_workProcess.isRuning()) {
m_workProcess.kill();
}
m_workProcess.push(m_params.serial, getServerPath(), Config::getInstance().getServerPath());
m_workProcess.push(m_params.serial, m_params.serverLocalPath, m_params.serverRemotePath);
return true;
}

View file

@ -26,12 +26,14 @@ class Server : public QObject
public:
struct ServerParams
{
QString serverLocalPath = ""; // 本地安卓server路径
QString serverRemotePath = ""; // 要推送到远端设备的server路径
QString serial = ""; // 设备序列号
quint16 localPort = 27183; // reverse时本地监听端口
quint16 maxSize = 720; // 视频分辨率
quint32 bitRate = 8000000; // 视频比特率
quint32 maxFps = 60; // 视频最大帧率
QString crop = ""; // 视频裁剪
QString crop = ""; // 视频裁剪
bool control = true; // 安卓端是否接收键鼠控制
bool useReverse = true; // true:先使用adb reverse失败后自动使用adb forwardfalse:直接使用adb forward
int lockVideoOrientation = -1; // 是否锁定视频方向
@ -42,15 +44,12 @@ public:
virtual ~Server();
bool start(Server::ServerParams params);
bool connectTo();
void stop();
bool isReverse();
Server::ServerParams getParams();
VideoSocket *getVideoSocket();
QTcpSocket *getControlSocket();
void stop();
signals:
void serverStarted(bool success, const QString &deviceName = "", const QSize &size = QSize());
void serverStoped();
@ -62,13 +61,13 @@ protected:
void timerEvent(QTimerEvent *event);
private:
const QString &getServerPath();
bool pushServer();
bool enableTunnelReverse();
bool disableTunnelReverse();
bool enableTunnelForward();
bool disableTunnelForward();
bool execute();
bool connectTo();
bool startServerByStep();
bool readInfo(VideoSocket *videoSocket, QString &deviceName, QSize &size);
void startAcceptTimeoutTimer();
@ -78,7 +77,6 @@ private:
void onConnectTimer();
private:
QString m_serverPath = "";
AdbProcess m_workProcess;
AdbProcess m_serverProcess;
TcpServer m_serverSocket; // only used if !tunnel_forward

View file

@ -292,6 +292,8 @@ void Dialog::on_startServerBtn_clicked()
params.stayAwake = ui->stayAwakeCheck->isChecked();
params.framelessWindow = ui->framelessCheck->isChecked();
params.recordPath = ui->recordPathEdt->text().trimmed();
params.serverLocalPath = getServerPath();
params.serverRemotePath = Config::getInstance().getServerPath();
m_deviceManage.connectDevice(params);
@ -611,5 +613,18 @@ void Dialog::on_serialBox_currentIndexChanged(const QString &arg1)
quint32 Dialog::getBitRate()
{
return ui->bitRateEdit->text().trimmed().toUInt() *
(ui->bitRateBox->currentText() == QString("Mbps") ? 1000000 : 1000);
(ui->bitRateBox->currentText() == QString("Mbps") ? 1000000 : 1000);
}
const QString &Dialog::getServerPath()
{
static QString serverPath;
if (serverPath.isEmpty()) {
serverPath = QString::fromLocal8Bit(qgetenv("QTSCRCPY_SERVER_PATH"));
QFileInfo fileInfo(serverPath);
if (serverPath.isEmpty() || !fileInfo.isFile()) {
serverPath = QCoreApplication::applicationDirPath() + "/scrcpy-server";
}
}
return serverPath;
}

View file

@ -65,6 +65,7 @@ private:
void slotActivated(QSystemTrayIcon::ActivationReason reason);
int findDeviceFromeSerialBox(bool wifi);
quint32 getBitRate();
const QString &getServerPath();
protected:
void closeEvent(QCloseEvent *event);