From 2cb82bfd7ced6bf200663c4ffea4771b248edf63 Mon Sep 17 00:00:00 2001
From: Barry <870709864@qq.com>
Date: Thu, 20 Jun 2019 17:49:53 +0800
Subject: [PATCH] =?UTF-8?q?add:=E4=B8=8D=E6=98=BE=E7=A4=BA=EF=BC=8C?=
=?UTF-8?q?=E5=8F=AA=E5=90=8E=E5=8F=B0=E5=BD=95=E5=88=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
QtScrcpy/device/device.cpp | 49 ++++++++++++-------
QtScrcpy/device/device.h | 17 +++----
QtScrcpy/device/server/server.h | 16 +++----
QtScrcpy/dialog.cpp | 10 ++--
QtScrcpy/dialog.ui | 85 ++++++++++++++++++---------------
5 files changed, 102 insertions(+), 75 deletions(-)
diff --git a/QtScrcpy/device/device.cpp b/QtScrcpy/device/device.cpp
index 8e541f6..af4140f 100644
--- a/QtScrcpy/device/device.cpp
+++ b/QtScrcpy/device/device.cpp
@@ -14,25 +14,37 @@ Device::Device(DeviceParams params, QObject *parent)
: QObject(parent)
, m_params(params)
{
- m_vb = new VideoBuffer();
- m_vb->init();
- m_decoder = new Decoder(m_vb, this);
+ if (!params.display && m_params.recordFileName.trimmed().isEmpty()) {
+ qCritical("not display must be recorded");
+ deleteLater();
+ return;
+ }
+
+ if (params.display) {
+ m_vb = new VideoBuffer();
+ m_vb->init();
+ m_decoder = new Decoder(m_vb, this);
+ m_fileHandler = new FileHandler(this);
+ m_controller = new Controller(this);
+ m_videoForm = new VideoForm();
+ if (m_controller) {
+ m_videoForm->setController(m_controller);
+ }
+ if (m_fileHandler) {
+ m_videoForm->setFileHandler(m_fileHandler);
+ }
+ m_videoForm->show();
+ }
+
m_stream = new Stream(this);
- m_stream->setDecoder(m_decoder);
-
+ if (m_decoder) {
+ m_stream->setDecoder(m_decoder);
+ }
m_server = new Server(this);
- m_controller = new Controller(this);
- m_fileHandler = new FileHandler(this);
-
if (!m_params.recordFileName.trimmed().isEmpty()) {
m_recorder = new Recorder(m_params.recordFileName);
m_stream->setRecoder(m_recorder);
}
-
- m_videoForm = new VideoForm();
- m_videoForm->setController(m_controller);
- m_videoForm->show();
-
initSignals();
startServer();
}
@@ -71,7 +83,7 @@ Controller *Device::getController()
void Device::initSignals()
{
- if (m_videoForm) {
+ if (m_controller && m_videoForm) {
connect(m_controller, &Controller::grabCursor, m_videoForm, &VideoForm::onGrabCursor);
}
if (m_fileHandler) {
@@ -117,9 +129,12 @@ void Device::initSignals()
m_stream->startDecode();
// init controller
- m_controller->setControlSocket(m_server->getControlSocket());
+ if (m_controller) {
+ m_controller->setControlSocket(m_server->getControlSocket());
+ }
- if (m_params.closeScreen && m_controller) {
+ // 显示界面时才自动息屏(m_params.display)
+ if (m_params.closeScreen && m_params.display && m_controller) {
m_controller->setScreenPowerMode(ControlMsg::SPM_OFF);
}
}
@@ -137,7 +152,7 @@ void Device::initSignals()
});
}
- if (m_decoder) {
+ if (m_decoder && m_vb) {
// must be Qt::QueuedConnection, ui update must be main thread
connect(m_decoder, &Decoder::onNewFrame, this, [this](){
m_vb->lock();
diff --git a/QtScrcpy/device/device.h b/QtScrcpy/device/device.h
index 034aeee..afcef19 100644
--- a/QtScrcpy/device/device.h
+++ b/QtScrcpy/device/device.h
@@ -18,19 +18,20 @@ class Device : public QObject
Q_OBJECT
public:
struct DeviceParams {
- QString recordFileName = "";
- QString serial = "";
- quint16 localPort = 27183;
- quint16 maxSize = 0;
- quint32 bitRate = 8000000;
- bool closeScreen = false;
- bool useReverse = true;
+ QString recordFileName = ""; // 视频录制文件名
+ QString serial = ""; // 设备序列号
+ quint16 localPort = 27183; // reverse时本地监听端口
+ quint16 maxSize = 720; // 视频分辨率
+ quint32 bitRate = 8000000; // 视频比特率
+ bool closeScreen = false; // 启动时自动息屏
+ bool useReverse = true; // true:先使用adb reverse,失败后自动使用adb forward;false:直接使用adb forward
+ bool display = true; // 是否显示画面(或者仅仅后台录制)
};
explicit Device(DeviceParams params, QObject *parent = nullptr);
virtual ~Device();
VideoForm *getVideoForm();
- Controller* getController();
+ Controller *getController();
private:
void initSignals();
diff --git a/QtScrcpy/device/server/server.h b/QtScrcpy/device/server/server.h
index ec55fd7..6ccee1f 100644
--- a/QtScrcpy/device/server/server.h
+++ b/QtScrcpy/device/server/server.h
@@ -23,14 +23,14 @@ class Server : public QObject
};
public:
struct ServerParams {
- QString serial = "";
- quint16 localPort = 27183;
- quint16 maxSize = 750;
- quint32 bitRate = 8000000;
- QString crop = "-";
- bool sendFrameMeta = false;
- bool control = true;
- bool useReverse = true;
+ QString serial = ""; // 设备序列号
+ quint16 localPort = 27183; // reverse时本地监听端口
+ quint16 maxSize = 720; // 视频分辨率
+ quint32 bitRate = 8000000; // 视频比特率
+ QString crop = "-"; // 视频裁剪
+ bool sendFrameMeta = false; // 是否发送mp4帧数据
+ bool control = true; // 安卓端是否接收键鼠控制
+ bool useReverse = true; // true:先使用adb reverse,失败后自动使用adb forward;false:直接使用adb forward
};
explicit Server(QObject *parent = nullptr);
diff --git a/QtScrcpy/dialog.cpp b/QtScrcpy/dialog.cpp
index 3e90e39..36d6f02 100644
--- a/QtScrcpy/dialog.cpp
+++ b/QtScrcpy/dialog.cpp
@@ -103,6 +103,8 @@ void Dialog::on_updateDevice_clicked()
void Dialog::on_startServerBtn_clicked()
{
if (!m_device) {
+ outLog("start server...", false);
+
QString absFilePath;
QString fileDir(ui->recordPathEdt->text().trimmed());
if (!fileDir.isEmpty()) {
@@ -124,12 +126,11 @@ void Dialog::on_startServerBtn_clicked()
params.recordFileName = absFilePath;
params.closeScreen = ui->closeScreenCheck->isChecked();
params.useReverse = ui->useReverseCheck->isChecked();
+ params.display = !ui->notDisplayCheck->isChecked();
m_device = new Device(params, this);
if (ui->alwaysTopCheck->isChecked() && m_device->getVideoForm()) {
m_device->getVideoForm()->staysOnTop();
- }
-
- outLog("start server...", false);
+ }
}
}
@@ -241,7 +242,8 @@ void Dialog::on_selectRecordPathBtn_clicked()
void Dialog::on_recordPathEdt_textChanged(const QString &arg1)
{
- ui->recordPathEdt->setToolTip(arg1);
+ ui->recordPathEdt->setToolTip(arg1.trimmed());
+ ui->notDisplayCheck->setCheckable(!arg1.trimmed().isEmpty());
}
void Dialog::on_adbCommandBtn_clicked()
diff --git a/QtScrcpy/dialog.ui b/QtScrcpy/dialog.ui
index 5169335..cd74319 100644
--- a/QtScrcpy/dialog.ui
+++ b/QtScrcpy/dialog.ui
@@ -119,24 +119,17 @@
Start Config
- -
-
-
- video size:
+
-
+
+
+ true
- -
-
-
- bit rate:
-
-
-
- -
+
-
- -
+
-
@@ -146,17 +139,21 @@
- -
-
+
-
+
- record save path:
-
-
- recordPathEdt
+ record format:
- -
+
-
+
+
+
+
+
+
+ -
select path
@@ -166,7 +163,7 @@
- -
+
-
always top
@@ -176,28 +173,27 @@
- -
-
+
-
+
- record format:
+ not display
+
+
+ false
- -
-
-
- true
+
-
+
+
+ record save path:
+
+
+ recordPathEdt
- -
-
-
-
-
-
-
- -
+
-
use reverse
@@ -207,13 +203,27 @@
- -
+
-
close screen
+ -
+
+
+ bit rate:
+
+
+
+ -
+
+
+ video size:
+
+
+
@@ -351,7 +361,6 @@
formatBox
recordPathEdt
selectRecordPathBtn
- alwaysTopCheck
serialBox
startServerBtn
stopServerBtn