mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-08-03 06:08:39 +00:00
refactor: move config from server
This commit is contained in:
parent
2088c7f76f
commit
2acb11ac23
6 changed files with 27 additions and 21 deletions
|
@ -335,6 +335,8 @@ void Device::startServer()
|
||||||
// only one devices, serial can be null
|
// 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"
|
// mark: crop input format: "width:height:x:y" or "" for no crop, for example: "100:200:0:0"
|
||||||
Server::ServerParams params;
|
Server::ServerParams params;
|
||||||
|
params.serverLocalPath = m_params.serverLocalPath;
|
||||||
|
params.serverRemotePath = m_params.serverRemotePath;
|
||||||
params.serial = m_params.serial;
|
params.serial = m_params.serial;
|
||||||
params.localPort = m_params.localPort;
|
params.localPort = m_params.localPort;
|
||||||
params.maxSize = m_params.maxSize;
|
params.maxSize = m_params.maxSize;
|
||||||
|
|
|
@ -25,6 +25,8 @@ class Device : public QObject
|
||||||
public:
|
public:
|
||||||
struct DeviceParams
|
struct DeviceParams
|
||||||
{
|
{
|
||||||
|
QString serverLocalPath = ""; // 本地安卓server路径
|
||||||
|
QString serverRemotePath = ""; // 要推送到远端设备的server路径
|
||||||
QString recordFileName = ""; // 视频录制文件名
|
QString recordFileName = ""; // 视频录制文件名
|
||||||
QString recordPath = ""; // 视频保存路径
|
QString recordPath = ""; // 视频保存路径
|
||||||
QString serial = ""; // 设备序列号
|
QString serial = ""; // 设备序列号
|
||||||
|
|
|
@ -47,24 +47,12 @@ Server::Server(QObject *parent) : QObject(parent)
|
||||||
|
|
||||||
Server::~Server() {}
|
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()
|
bool Server::pushServer()
|
||||||
{
|
{
|
||||||
if (m_workProcess.isRuning()) {
|
if (m_workProcess.isRuning()) {
|
||||||
m_workProcess.kill();
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,12 +26,14 @@ class Server : public QObject
|
||||||
public:
|
public:
|
||||||
struct ServerParams
|
struct ServerParams
|
||||||
{
|
{
|
||||||
|
QString serverLocalPath = ""; // 本地安卓server路径
|
||||||
|
QString serverRemotePath = ""; // 要推送到远端设备的server路径
|
||||||
QString serial = ""; // 设备序列号
|
QString serial = ""; // 设备序列号
|
||||||
quint16 localPort = 27183; // reverse时本地监听端口
|
quint16 localPort = 27183; // reverse时本地监听端口
|
||||||
quint16 maxSize = 720; // 视频分辨率
|
quint16 maxSize = 720; // 视频分辨率
|
||||||
quint32 bitRate = 8000000; // 视频比特率
|
quint32 bitRate = 8000000; // 视频比特率
|
||||||
quint32 maxFps = 60; // 视频最大帧率
|
quint32 maxFps = 60; // 视频最大帧率
|
||||||
QString crop = ""; // 视频裁剪
|
QString crop = ""; // 视频裁剪
|
||||||
bool control = true; // 安卓端是否接收键鼠控制
|
bool control = true; // 安卓端是否接收键鼠控制
|
||||||
bool useReverse = true; // true:先使用adb reverse,失败后自动使用adb forward;false:直接使用adb forward
|
bool useReverse = true; // true:先使用adb reverse,失败后自动使用adb forward;false:直接使用adb forward
|
||||||
int lockVideoOrientation = -1; // 是否锁定视频方向
|
int lockVideoOrientation = -1; // 是否锁定视频方向
|
||||||
|
@ -42,15 +44,12 @@ public:
|
||||||
virtual ~Server();
|
virtual ~Server();
|
||||||
|
|
||||||
bool start(Server::ServerParams params);
|
bool start(Server::ServerParams params);
|
||||||
bool connectTo();
|
void stop();
|
||||||
bool isReverse();
|
bool isReverse();
|
||||||
Server::ServerParams getParams();
|
Server::ServerParams getParams();
|
||||||
|
|
||||||
VideoSocket *getVideoSocket();
|
VideoSocket *getVideoSocket();
|
||||||
QTcpSocket *getControlSocket();
|
QTcpSocket *getControlSocket();
|
||||||
|
|
||||||
void stop();
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void serverStarted(bool success, const QString &deviceName = "", const QSize &size = QSize());
|
void serverStarted(bool success, const QString &deviceName = "", const QSize &size = QSize());
|
||||||
void serverStoped();
|
void serverStoped();
|
||||||
|
@ -62,13 +61,13 @@ protected:
|
||||||
void timerEvent(QTimerEvent *event);
|
void timerEvent(QTimerEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const QString &getServerPath();
|
|
||||||
bool pushServer();
|
bool pushServer();
|
||||||
bool enableTunnelReverse();
|
bool enableTunnelReverse();
|
||||||
bool disableTunnelReverse();
|
bool disableTunnelReverse();
|
||||||
bool enableTunnelForward();
|
bool enableTunnelForward();
|
||||||
bool disableTunnelForward();
|
bool disableTunnelForward();
|
||||||
bool execute();
|
bool execute();
|
||||||
|
bool connectTo();
|
||||||
bool startServerByStep();
|
bool startServerByStep();
|
||||||
bool readInfo(VideoSocket *videoSocket, QString &deviceName, QSize &size);
|
bool readInfo(VideoSocket *videoSocket, QString &deviceName, QSize &size);
|
||||||
void startAcceptTimeoutTimer();
|
void startAcceptTimeoutTimer();
|
||||||
|
@ -78,7 +77,6 @@ private:
|
||||||
void onConnectTimer();
|
void onConnectTimer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_serverPath = "";
|
|
||||||
AdbProcess m_workProcess;
|
AdbProcess m_workProcess;
|
||||||
AdbProcess m_serverProcess;
|
AdbProcess m_serverProcess;
|
||||||
TcpServer m_serverSocket; // only used if !tunnel_forward
|
TcpServer m_serverSocket; // only used if !tunnel_forward
|
||||||
|
|
|
@ -292,6 +292,8 @@ void Dialog::on_startServerBtn_clicked()
|
||||||
params.stayAwake = ui->stayAwakeCheck->isChecked();
|
params.stayAwake = ui->stayAwakeCheck->isChecked();
|
||||||
params.framelessWindow = ui->framelessCheck->isChecked();
|
params.framelessWindow = ui->framelessCheck->isChecked();
|
||||||
params.recordPath = ui->recordPathEdt->text().trimmed();
|
params.recordPath = ui->recordPathEdt->text().trimmed();
|
||||||
|
params.serverLocalPath = getServerPath();
|
||||||
|
params.serverRemotePath = Config::getInstance().getServerPath();
|
||||||
|
|
||||||
m_deviceManage.connectDevice(params);
|
m_deviceManage.connectDevice(params);
|
||||||
|
|
||||||
|
@ -611,5 +613,18 @@ void Dialog::on_serialBox_currentIndexChanged(const QString &arg1)
|
||||||
quint32 Dialog::getBitRate()
|
quint32 Dialog::getBitRate()
|
||||||
{
|
{
|
||||||
return ui->bitRateEdit->text().trimmed().toUInt() *
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,7 @@ private:
|
||||||
void slotActivated(QSystemTrayIcon::ActivationReason reason);
|
void slotActivated(QSystemTrayIcon::ActivationReason reason);
|
||||||
int findDeviceFromeSerialBox(bool wifi);
|
int findDeviceFromeSerialBox(bool wifi);
|
||||||
quint32 getBitRate();
|
quint32 getBitRate();
|
||||||
|
const QString &getServerPath();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *event);
|
void closeEvent(QCloseEvent *event);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue