mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-07-29 12:18:39 +00:00
add:多台控制
This commit is contained in:
parent
49013aa414
commit
ee787ee200
10 changed files with 180 additions and 38 deletions
|
@ -41,6 +41,7 @@ include ($$PWD/uibase/uibase.pri)
|
||||||
include ($$PWD/fontawesome/fontawesome.pri)
|
include ($$PWD/fontawesome/fontawesome.pri)
|
||||||
include ($$PWD/util/util.pri)
|
include ($$PWD/util/util.pri)
|
||||||
include ($$PWD/device/device.pri)
|
include ($$PWD/device/device.pri)
|
||||||
|
include ($$PWD/devicemanage/devicemanage.pri)
|
||||||
|
|
||||||
# 附加包含路径
|
# 附加包含路径
|
||||||
INCLUDEPATH += \
|
INCLUDEPATH += \
|
||||||
|
@ -48,7 +49,8 @@ INCLUDEPATH += \
|
||||||
$$PWD/adb \
|
$$PWD/adb \
|
||||||
$$PWD/uibase \
|
$$PWD/uibase \
|
||||||
$$PWD/util \
|
$$PWD/util \
|
||||||
$$PWD/device \
|
$$PWD/device \
|
||||||
|
$$PWD/devicemanage \
|
||||||
$$PWD/fontawesome
|
$$PWD/fontawesome
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "filehandler.h"
|
#include "filehandler.h"
|
||||||
#include "stream.h"
|
#include "stream.h"
|
||||||
#include "videoform.h"
|
#include "videoform.h"
|
||||||
|
#include "controller.h"
|
||||||
|
|
||||||
Device::Device(DeviceParams params, QObject *parent)
|
Device::Device(DeviceParams params, QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
|
@ -69,6 +70,7 @@ Device::~Device()
|
||||||
if (m_videoForm) {
|
if (m_videoForm) {
|
||||||
delete m_videoForm;
|
delete m_videoForm;
|
||||||
}
|
}
|
||||||
|
emit deviceDisconnect(m_params.serial);
|
||||||
}
|
}
|
||||||
|
|
||||||
VideoForm *Device::getVideoForm()
|
VideoForm *Device::getVideoForm()
|
||||||
|
@ -81,6 +83,11 @@ Controller *Device::getController()
|
||||||
return m_controller;
|
return m_controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Server *Device::getServer()
|
||||||
|
{
|
||||||
|
return m_server;
|
||||||
|
}
|
||||||
|
|
||||||
void Device::initSignals()
|
void Device::initSignals()
|
||||||
{
|
{
|
||||||
if (m_controller && m_videoForm) {
|
if (m_controller && m_videoForm) {
|
||||||
|
|
|
@ -4,8 +4,6 @@
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
|
|
||||||
#include "controller.h"
|
|
||||||
|
|
||||||
class Recorder;
|
class Recorder;
|
||||||
class Server;
|
class Server;
|
||||||
class VideoBuffer;
|
class VideoBuffer;
|
||||||
|
@ -13,6 +11,7 @@ class Decoder;
|
||||||
class FileHandler;
|
class FileHandler;
|
||||||
class Stream;
|
class Stream;
|
||||||
class VideoForm;
|
class VideoForm;
|
||||||
|
class Controller;
|
||||||
class Device : public QObject
|
class Device : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -32,6 +31,10 @@ public:
|
||||||
|
|
||||||
VideoForm *getVideoForm();
|
VideoForm *getVideoForm();
|
||||||
Controller *getController();
|
Controller *getController();
|
||||||
|
Server *getServer();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void deviceDisconnect(QString serial);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initSignals();
|
void initSignals();
|
||||||
|
|
|
@ -168,6 +168,16 @@ bool Server::connectTo()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Server::isReverse()
|
||||||
|
{
|
||||||
|
return !m_tunnelForward;
|
||||||
|
}
|
||||||
|
|
||||||
|
Server::ServerParams Server::getParams()
|
||||||
|
{
|
||||||
|
return m_params;
|
||||||
|
}
|
||||||
|
|
||||||
void Server::timerEvent(QTimerEvent *event)
|
void Server::timerEvent(QTimerEvent *event)
|
||||||
{
|
{
|
||||||
if (event && m_acceptTimeoutTimer == event->timerId()) {
|
if (event && m_acceptTimeoutTimer == event->timerId()) {
|
||||||
|
|
|
@ -38,6 +38,8 @@ public:
|
||||||
|
|
||||||
bool start(Server::ServerParams params);
|
bool start(Server::ServerParams params);
|
||||||
bool connectTo();
|
bool connectTo();
|
||||||
|
bool isReverse();
|
||||||
|
Server::ServerParams getParams();
|
||||||
|
|
||||||
VideoSocket* getVideoSocket();
|
VideoSocket* getVideoSocket();
|
||||||
QTcpSocket* getControlSocket();
|
QTcpSocket* getControlSocket();
|
||||||
|
|
87
QtScrcpy/devicemanage/devicemanage.cpp
Normal file
87
QtScrcpy/devicemanage/devicemanage.cpp
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "devicemanage.h"
|
||||||
|
#include "server.h"
|
||||||
|
|
||||||
|
#define DM_MAX_DEVICES_NUM 16
|
||||||
|
|
||||||
|
DeviceManage::DeviceManage(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceManage::~DeviceManage()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DeviceManage::connectDevice(Device::DeviceParams params)
|
||||||
|
{
|
||||||
|
if (params.serial.trimmed().isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (m_devices.contains(params.serial)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (DM_MAX_DEVICES_NUM < m_devices.size()) {
|
||||||
|
qInfo("over the maximum number of connections");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
quint16 port = 0;
|
||||||
|
if (params.useReverse) {
|
||||||
|
port = getFreePort();
|
||||||
|
if (0 == port) {
|
||||||
|
qInfo("no port available, automatically switch to forward");
|
||||||
|
params.useReverse = false;
|
||||||
|
} else {
|
||||||
|
qInfo("free port %d", port);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Device *device = new Device(params);
|
||||||
|
connect(device, &Device::deviceDisconnect, this, &DeviceManage::onDeviceDisconnect);
|
||||||
|
m_devices[params.serial] = device;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DeviceManage::disconnectDevice(const QString &serial)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
if (!serial.isEmpty() && m_devices.contains(serial)) {
|
||||||
|
auto it = m_devices.find(serial);
|
||||||
|
if (it->data()) {
|
||||||
|
it->data()->deleteLater();
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceManage::onDeviceDisconnect(QString serial)
|
||||||
|
{
|
||||||
|
if (!serial.isEmpty() && m_devices.contains(serial)) {
|
||||||
|
m_devices.remove(serial);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
quint16 DeviceManage::getFreePort()
|
||||||
|
{
|
||||||
|
quint16 port = m_localPortStart;
|
||||||
|
QMapIterator<QString, QPointer<Device>> i(m_devices);
|
||||||
|
while (port < m_localPortStart + DM_MAX_DEVICES_NUM) {
|
||||||
|
bool used = false;
|
||||||
|
while (i.hasNext()) {
|
||||||
|
i.next();
|
||||||
|
auto device = i.value();
|
||||||
|
if (device && device->getServer()
|
||||||
|
&& device->getServer()->isReverse()
|
||||||
|
&& port == device->getServer()->getParams().localPort) {
|
||||||
|
used = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!used) {
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
30
QtScrcpy/devicemanage/devicemanage.h
Normal file
30
QtScrcpy/devicemanage/devicemanage.h
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#ifndef DEVICEMANAGE_H
|
||||||
|
#define DEVICEMANAGE_H
|
||||||
|
|
||||||
|
#include <QPointer>
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
|
#include "device.h"
|
||||||
|
|
||||||
|
class DeviceManage : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit DeviceManage(QObject *parent = nullptr);
|
||||||
|
virtual ~DeviceManage();
|
||||||
|
|
||||||
|
bool connectDevice(Device::DeviceParams params);
|
||||||
|
bool disconnectDevice(const QString &serial);
|
||||||
|
|
||||||
|
protected slots:
|
||||||
|
void onDeviceDisconnect(QString serial);
|
||||||
|
|
||||||
|
private:
|
||||||
|
quint16 getFreePort();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QMap<QString, QPointer<Device>> m_devices;
|
||||||
|
quint16 m_localPortStart = 27183;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DEVICEMANAGE_H
|
5
QtScrcpy/devicemanage/devicemanage.pri
Normal file
5
QtScrcpy/devicemanage/devicemanage.pri
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
HEADERS += \
|
||||||
|
$$PWD/devicemanage.h
|
||||||
|
|
||||||
|
SOURCES += \
|
||||||
|
$$PWD/devicemanage.cpp
|
|
@ -102,42 +102,42 @@ void Dialog::on_updateDevice_clicked()
|
||||||
|
|
||||||
void Dialog::on_startServerBtn_clicked()
|
void Dialog::on_startServerBtn_clicked()
|
||||||
{
|
{
|
||||||
if (!m_device) {
|
outLog("start server...", false);
|
||||||
outLog("start server...", false);
|
|
||||||
|
|
||||||
QString absFilePath;
|
QString absFilePath;
|
||||||
QString fileDir(ui->recordPathEdt->text().trimmed());
|
QString fileDir(ui->recordPathEdt->text().trimmed());
|
||||||
if (!fileDir.isEmpty()) {
|
if (!fileDir.isEmpty()) {
|
||||||
QDateTime dateTime = QDateTime::currentDateTime();
|
QDateTime dateTime = QDateTime::currentDateTime();
|
||||||
QString fileName = dateTime.toString("_yyyyMMdd_hhmmss_zzz");
|
QString fileName = dateTime.toString("_yyyyMMdd_hhmmss_zzz");
|
||||||
QString ext = ui->formatBox->currentText().trimmed();
|
QString ext = ui->formatBox->currentText().trimmed();
|
||||||
fileName = windowTitle() + fileName + "." + ext;
|
fileName = windowTitle() + fileName + "." + ext;
|
||||||
QDir dir(fileDir);
|
QDir dir(fileDir);
|
||||||
absFilePath = dir.absoluteFilePath(fileName);
|
absFilePath = dir.absoluteFilePath(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 bitRate = ui->bitRateBox->currentText().trimmed().toUInt();
|
quint32 bitRate = ui->bitRateBox->currentText().trimmed().toUInt();
|
||||||
// this is ok that "native" toUshort is 0
|
// this is ok that "native" toUshort is 0
|
||||||
quint16 videoSize = ui->videoSizeBox->currentText().trimmed().toUShort();
|
quint16 videoSize = ui->videoSizeBox->currentText().trimmed().toUShort();
|
||||||
Device::DeviceParams params;
|
Device::DeviceParams params;
|
||||||
params.serial = ui->serialBox->currentText().trimmed();
|
params.serial = ui->serialBox->currentText().trimmed();
|
||||||
params.maxSize = videoSize;
|
params.maxSize = videoSize;
|
||||||
params.bitRate = bitRate;
|
params.bitRate = bitRate;
|
||||||
params.recordFileName = absFilePath;
|
params.recordFileName = absFilePath;
|
||||||
params.closeScreen = ui->closeScreenCheck->isChecked();
|
params.closeScreen = ui->closeScreenCheck->isChecked();
|
||||||
params.useReverse = ui->useReverseCheck->isChecked();
|
params.useReverse = ui->useReverseCheck->isChecked();
|
||||||
params.display = !ui->notDisplayCheck->isChecked();
|
params.display = !ui->notDisplayCheck->isChecked();
|
||||||
m_device = new Device(params, this);
|
m_deviceManage.connectDevice(params);
|
||||||
|
|
||||||
|
/*
|
||||||
if (ui->alwaysTopCheck->isChecked() && m_device->getVideoForm()) {
|
if (ui->alwaysTopCheck->isChecked() && m_device->getVideoForm()) {
|
||||||
m_device->getVideoForm()->staysOnTop();
|
m_device->getVideoForm()->staysOnTop();
|
||||||
}
|
}
|
||||||
}
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dialog::on_stopServerBtn_clicked()
|
void Dialog::on_stopServerBtn_clicked()
|
||||||
{
|
{
|
||||||
if (m_device) {
|
if (m_deviceManage.disconnectDevice(ui->serialBox->currentText().trimmed())) {
|
||||||
m_device->deleteLater();
|
|
||||||
outLog("stop server");
|
outLog("stop server");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -257,10 +257,6 @@ void Dialog::on_stopAdbBtn_clicked()
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dialog::on_clearOut_clicked()
|
void Dialog::on_clearOut_clicked()
|
||||||
{
|
{
|
||||||
static bool show = true;
|
|
||||||
m_adb.setShowTouchesEnabled("", show);
|
|
||||||
show = !show;
|
|
||||||
|
|
||||||
ui->outEdit->clear();
|
ui->outEdit->clear();
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,12 @@
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
|
||||||
#include "adbprocess.h"
|
#include "adbprocess.h"
|
||||||
|
#include "devicemanage.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class Dialog;
|
class Dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Device;
|
|
||||||
class QYUVOpenGLWidget;
|
class QYUVOpenGLWidget;
|
||||||
class Dialog : public QDialog
|
class Dialog : public QDialog
|
||||||
{
|
{
|
||||||
|
@ -55,7 +55,7 @@ private:
|
||||||
private:
|
private:
|
||||||
Ui::Dialog *ui;
|
Ui::Dialog *ui;
|
||||||
AdbProcess m_adb;
|
AdbProcess m_adb;
|
||||||
QPointer<Device> m_device;
|
DeviceManage m_deviceManage;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DIALOG_H
|
#endif // DIALOG_H
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue