From fbfbdcc41eaef418f6c3a2797c3db10c8bead7db Mon Sep 17 00:00:00 2001 From: Barry <870709864@qq.com> Date: Thu, 20 Jun 2019 14:33:20 +0800 Subject: [PATCH] =?UTF-8?q?add:=E5=A2=9E=E5=8A=A0=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E4=BD=BF=E7=94=A8forward=E7=9A=84=E9=80=89?= =?UTF-8?q?=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- QtScrcpy/device/device.cpp | 1 + QtScrcpy/device/device.h | 1 + QtScrcpy/device/server/server.cpp | 36 ++++++------- QtScrcpy/device/server/server.h | 3 +- QtScrcpy/dialog.cpp | 27 +--------- QtScrcpy/dialog.h | 4 -- QtScrcpy/dialog.ui | 87 +++++++++++++++++-------------- 7 files changed, 71 insertions(+), 88 deletions(-) diff --git a/QtScrcpy/device/device.cpp b/QtScrcpy/device/device.cpp index a8e1e0f..8e541f6 100644 --- a/QtScrcpy/device/device.cpp +++ b/QtScrcpy/device/device.cpp @@ -169,6 +169,7 @@ void Device::startServer() params.crop = "-"; params.sendFrameMeta = m_recorder ? true : false; params.control = true; + params.useReverse = m_params.useReverse; m_server->start(params); }); } diff --git a/QtScrcpy/device/device.h b/QtScrcpy/device/device.h index 1ea9bd2..034aeee 100644 --- a/QtScrcpy/device/device.h +++ b/QtScrcpy/device/device.h @@ -24,6 +24,7 @@ public: quint16 maxSize = 0; quint32 bitRate = 8000000; bool closeScreen = false; + bool useReverse = true; }; explicit Device(DeviceParams params, QObject *parent = nullptr); virtual ~Device(); diff --git a/QtScrcpy/device/server/server.cpp b/QtScrcpy/device/server/server.cpp index 04d68ad..0609eab 100644 --- a/QtScrcpy/device/server/server.cpp +++ b/QtScrcpy/device/server/server.cpp @@ -181,7 +181,18 @@ bool Server::connectTo() qWarning("video socket connect to server failed"); emit connectToResult(false, "", QSize()); return false; + } + + // control socket + m_controlSocket = new QTcpSocket(); + m_controlSocket->connectToHost(QHostAddress::LocalHost, m_params.localPort); + if (!m_controlSocket->waitForConnected(1000)) { + stop(); + qWarning("control socket connect to server failed"); + emit connectToResult(false, "", QSize()); + return false; } + if (QTcpSocket::ConnectedState == m_videoSocket->state()) { // connect will success even if devices offline, recv data is real connect success // because connect is to pc adb server @@ -200,17 +211,7 @@ bool Server::connectTo() success = false; } - // control socket - m_controlSocket = new QTcpSocket(); - m_controlSocket->connectToHost(QHostAddress::LocalHost, m_params.localPort); - if (!m_controlSocket->waitForConnected(1000)) { - stop(); - qWarning("control socket connect to server failed"); - emit connectToResult(false, "", QSize()); - return false; - } - - if (success) { + if (success) { // we don't need the adb tunnel anymore disableTunnelForward(); m_tunnelEnabled = false; @@ -358,13 +359,12 @@ void Server::onWorkProcessResult(AdbProcess::ADB_EXEC_RESULT processResult) switch (m_serverStartStep) { case SSS_PUSH: if (AdbProcess::AER_SUCCESS_EXEC == processResult) { -#if 1 - m_serverStartStep = SSS_ENABLE_TUNNEL_REVERSE; -#else - // test tunnelForward - m_tunnelForward = true; - m_serverStartStep = SSS_ENABLE_TUNNEL_FORWARD; -#endif + if (m_params.useReverse) { + m_serverStartStep = SSS_ENABLE_TUNNEL_REVERSE; + } else { + m_tunnelForward = true; + m_serverStartStep = SSS_ENABLE_TUNNEL_FORWARD; + } startServerByStep(); } else if (AdbProcess::AER_SUCCESS_START != processResult){ qCritical("adb push failed"); diff --git a/QtScrcpy/device/server/server.h b/QtScrcpy/device/server/server.h index 00d7a87..a760a67 100644 --- a/QtScrcpy/device/server/server.h +++ b/QtScrcpy/device/server/server.h @@ -25,11 +25,12 @@ public: struct ServerParams { QString serial = ""; quint16 localPort = 27183; - quint16 maxSize = 0; + quint16 maxSize = 750; quint32 bitRate = 8000000; QString crop = "-"; bool sendFrameMeta = false; bool control = true; + bool useReverse = true; }; explicit Server(QObject *parent = nullptr); diff --git a/QtScrcpy/dialog.cpp b/QtScrcpy/dialog.cpp index a74dfe9..3e90e39 100644 --- a/QtScrcpy/dialog.cpp +++ b/QtScrcpy/dialog.cpp @@ -123,6 +123,7 @@ void Dialog::on_startServerBtn_clicked() params.bitRate = bitRate; params.recordFileName = absFilePath; params.closeScreen = ui->closeScreenCheck->isChecked(); + params.useReverse = ui->useReverseCheck->isChecked(); m_device = new Device(params, this); if (ui->alwaysTopCheck->isChecked() && m_device->getVideoForm()) { m_device->getVideoForm()->staysOnTop(); @@ -243,32 +244,6 @@ void Dialog::on_recordPathEdt_textChanged(const QString &arg1) ui->recordPathEdt->setToolTip(arg1); } -void Dialog::on_alwaysTopCheck_stateChanged(int arg1) -{ - if (!m_device || m_device->getVideoForm()) { - return; - } - - if (Qt::Checked == arg1) { - m_device->getVideoForm()->staysOnTop(true); - } else { - m_device->getVideoForm()->staysOnTop(false); - } -} - -void Dialog::on_closeScreenCheck_stateChanged(int arg1) -{ - Q_UNUSED(arg1); - if (!m_device || m_device->getVideoForm()) { - return; - } - if (ui->closeScreenCheck->isChecked()) { - m_device->getController()->setScreenPowerMode(ControlMsg::SPM_OFF); - } else { - m_device->getController()->setScreenPowerMode(ControlMsg::SPM_NORMAL); - } -} - void Dialog::on_adbCommandBtn_clicked() { execAdbCmd(); diff --git a/QtScrcpy/dialog.h b/QtScrcpy/dialog.h index f2a8f03..6215c21 100644 --- a/QtScrcpy/dialog.h +++ b/QtScrcpy/dialog.h @@ -41,10 +41,6 @@ private slots: void on_recordPathEdt_textChanged(const QString &arg1); - void on_alwaysTopCheck_stateChanged(int arg1); - - void on_closeScreenCheck_stateChanged(int arg1); - void on_adbCommandBtn_clicked(); void on_stopAdbBtn_clicked(); diff --git a/QtScrcpy/dialog.ui b/QtScrcpy/dialog.ui index 5948860..5169335 100644 --- a/QtScrcpy/dialog.ui +++ b/QtScrcpy/dialog.ui @@ -116,36 +116,16 @@ - Config + Start Config - - - - + video size: - - - - - - - - - - - - - - - - - @@ -153,6 +133,19 @@ + + + + + + + + + + + + + @@ -163,14 +156,7 @@ - - - - true - - - - + select path @@ -180,13 +166,6 @@ - - - - record format: - - - @@ -197,7 +176,38 @@ - + + + + record format: + + + + + + + true + + + + + + + + + + + + + + use reverse + + + true + + + + close screen @@ -342,7 +352,6 @@ recordPathEdt selectRecordPathBtn alwaysTopCheck - closeScreenCheck serialBox startServerBtn stopServerBtn