From 416d2df3def1fc99ca30a2b405e91112d20a08a8 Mon Sep 17 00:00:00 2001 From: Matteo Baccan Date: Thu, 27 Jan 2022 11:38:14 +0100 Subject: [PATCH 01/14] Correct typo error Correct "unkonow" -> "unknown" --- ci/win/build_for_win.bat | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/win/build_for_win.bat b/ci/win/build_for_win.bat index 0e7e584ea..f5ce26546 100644 --- a/ci/win/build_for_win.bat +++ b/ci/win/build_for_win.bat @@ -44,7 +44,7 @@ if "%1"=="MinSizeRel" ( if "%1"=="RelWithDebInfo" ( goto build_mode_ok ) -echo error: unkonow build mode -- %1 +echo error: unknown build mode -- %1 goto return :build_mode_ok @@ -111,4 +111,4 @@ set errno=0 :return cd %old_cd% -exit /B %errno% \ No newline at end of file +exit /B %errno% From dbbe5297b06c3ee5a5128a400f0ca9f733ea1d04 Mon Sep 17 00:00:00 2001 From: Barry <870709864@qq.com> Date: Wed, 30 Mar 2022 19:21:50 +0800 Subject: [PATCH 02/14] refactor: stream and socket decoupling --- QtScrcpy/device/device.cpp | 10 ++++++++-- QtScrcpy/device/stream/stream.cpp | 22 +++++++++------------- QtScrcpy/device/stream/stream.h | 7 +++---- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/QtScrcpy/device/device.cpp b/QtScrcpy/device/device.cpp index 5ee2cdd8a..9980a7531 100644 --- a/QtScrcpy/device/device.cpp +++ b/QtScrcpy/device/device.cpp @@ -37,7 +37,14 @@ Device::Device(DeviceParams params, QObject *parent) : QObject(parent), m_params m_videoForm->setDevice(this); } - m_stream = new Stream(this); + m_stream = new Stream([this](quint8 *buf, qint32 bufSize) -> qint32 { + auto videoSocket = m_server->getVideoSocket(); + if (!videoSocket) { + return 0; + } + + return videoSocket->subThreadRecvData(buf, bufSize); + }, this); if (m_decoder) { m_stream->setDecoder(m_decoder); } @@ -245,7 +252,6 @@ void Device::initSignals() } // init decoder - m_stream->setVideoSocket(m_server->getVideoSocket()); m_stream->startDecode(); // init controller diff --git a/QtScrcpy/device/stream/stream.cpp b/QtScrcpy/device/stream/stream.cpp index 3eac3e4a7..4fe35ff29 100644 --- a/QtScrcpy/device/stream/stream.cpp +++ b/QtScrcpy/device/stream/stream.cpp @@ -13,7 +13,10 @@ typedef qint32 (*ReadPacketFunc)(void *, quint8 *, qint32); -Stream::Stream(QObject *parent) : QThread(parent) {} +Stream::Stream(std::function recvData, QObject *parent) + : QThread(parent) + , m_recvData(recvData) +{} Stream::~Stream() {} @@ -81,11 +84,6 @@ static quint64 bufferRead64be(quint8 *buf) return (static_cast(msb) << 32) | lsb; } -void Stream::setVideoSocket(VideoSocket *videoSocket) -{ - m_videoSocket = videoSocket; -} - void Stream::setRecoder(Recorder *recorder) { m_recorder = recorder; @@ -93,19 +91,17 @@ void Stream::setRecoder(Recorder *recorder) qint32 Stream::recvData(quint8 *buf, qint32 bufSize) { - if (!buf) { + if (!buf || !m_recvData) { return 0; } - if (m_videoSocket) { - qint32 len = m_videoSocket->subThreadRecvData(buf, bufSize); - return len; - } - return 0; + + qint32 len = m_recvData(buf, bufSize); + return len; } bool Stream::startDecode() { - if (!m_videoSocket) { + if (!m_recvData) { return false; } start(); diff --git a/QtScrcpy/device/stream/stream.h b/QtScrcpy/device/stream/stream.h index dc46c8792..839d04fda 100644 --- a/QtScrcpy/device/stream/stream.h +++ b/QtScrcpy/device/stream/stream.h @@ -17,7 +17,7 @@ class Stream : public QThread { Q_OBJECT public: - Stream(QObject *parent = Q_NULLPTR); + Stream(std::function recvData, QObject *parent = Q_NULLPTR); virtual ~Stream(); public: @@ -26,8 +26,6 @@ class Stream : public QThread void setDecoder(Decoder *decoder); void setRecoder(Recorder *recorder); - void setVideoSocket(VideoSocket *deviceSocket); - qint32 recvData(quint8 *buf, qint32 bufSize); bool startDecode(); void stopDecode(); @@ -41,9 +39,10 @@ class Stream : public QThread bool processConfigPacket(AVPacket *packet); bool parse(AVPacket *packet); bool processFrame(AVPacket *packet); + qint32 recvData(quint8 *buf, qint32 bufSize); private: - QPointer m_videoSocket; + std::function m_recvData = nullptr; // for recorder Recorder *m_recorder = Q_NULLPTR; Decoder *m_decoder = Q_NULLPTR; From 0b39bbc7191b57e38682eb81d2512b9940a5155d Mon Sep 17 00:00:00 2001 From: Barry <870709864@qq.com> Date: Wed, 6 Apr 2022 09:51:16 +0800 Subject: [PATCH 03/14] refactor: stream and decoder&recorder decoupling --- QtScrcpy/device/decoder/decoder.cpp | 21 ++++++---- QtScrcpy/device/decoder/decoder.h | 3 +- QtScrcpy/device/device.cpp | 43 ++++++++++++++++--- QtScrcpy/device/recorder/recorder.cpp | 9 +++- QtScrcpy/device/recorder/recorder.h | 2 +- QtScrcpy/device/stream/stream.cpp | 60 ++------------------------- QtScrcpy/device/stream/stream.h | 7 +--- 7 files changed, 66 insertions(+), 79 deletions(-) diff --git a/QtScrcpy/device/decoder/decoder.cpp b/QtScrcpy/device/decoder/decoder.cpp index c6d727e73..52188103a 100644 --- a/QtScrcpy/device/decoder/decoder.cpp +++ b/QtScrcpy/device/decoder/decoder.cpp @@ -8,8 +8,16 @@ Decoder::Decoder(VideoBuffer *vb, QObject *parent) : QObject(parent), m_vb(vb) { Decoder::~Decoder() {} -bool Decoder::open(const AVCodec *codec) +bool Decoder::open() { + // codec + AVCodec *codec = Q_NULLPTR; + codec = avcodec_find_decoder(AV_CODEC_ID_H264); + if (!codec) { + qCritical("H.264 decoder not found"); + return false; + } + // codec context m_codecCtx = avcodec_alloc_context3(codec); if (!m_codecCtx) { @@ -26,6 +34,10 @@ bool Decoder::open(const AVCodec *codec) void Decoder::close() { + if (m_vb) { + m_vb->interrupt(); + } + if (!m_codecCtx) { return; } @@ -98,13 +110,6 @@ bool Decoder::push(const AVPacket *packet) return true; } -void Decoder::interrupt() -{ - if (m_vb) { - m_vb->interrupt(); - } -} - void Decoder::pushFrame() { if (!m_vb) { diff --git a/QtScrcpy/device/decoder/decoder.h b/QtScrcpy/device/decoder/decoder.h index 5497a094d..cdde67c32 100644 --- a/QtScrcpy/device/decoder/decoder.h +++ b/QtScrcpy/device/decoder/decoder.h @@ -15,10 +15,9 @@ class Decoder : public QObject Decoder(VideoBuffer *vb, QObject *parent = Q_NULLPTR); virtual ~Decoder(); - bool open(const AVCodec *codec); + bool open(); void close(); bool push(const AVPacket *packet); - void interrupt(); signals: void onNewFrame(); diff --git a/QtScrcpy/device/device.cpp b/QtScrcpy/device/device.cpp index 9980a7531..664ea5dc3 100644 --- a/QtScrcpy/device/device.cpp +++ b/QtScrcpy/device/device.cpp @@ -45,13 +45,10 @@ Device::Device(DeviceParams params, QObject *parent) : QObject(parent), m_params return videoSocket->subThreadRecvData(buf, bufSize); }, this); - if (m_decoder) { - m_stream->setDecoder(m_decoder); - } + m_server = new Server(this); if (!m_params.recordFileName.trimmed().isEmpty()) { m_recorder = new Recorder(m_params.recordFileName); - m_stream->setRecoder(m_recorder); } initSignals(); startServer(); @@ -62,12 +59,22 @@ Device::~Device() if (m_server) { m_server->stop(); } - // server must stop before decoder, because decoder block main thread + if (m_stream) { m_stream->stopDecode(); } + // server must stop before decoder, because decoder block main thread + if (m_decoder) { + m_decoder->close(); + } + if (m_recorder) { + if (m_recorder->isRunning()) { + m_recorder->stopRecorder(); + m_recorder->wait(); + } + m_recorder->close(); delete m_recorder; } if (m_vb) { @@ -249,6 +256,18 @@ void Device::initSignals() // init recorder if (m_recorder) { m_recorder->setFrameSize(size); + if (!m_recorder->open()) { + qCritical("Could not open recorder"); + } + + if (!m_recorder->startRecorder()) { + qCritical("Could not start recorder"); + } + } + + // init decoder + if (m_decoder) { + m_decoder->open(); } // init decoder @@ -276,6 +295,20 @@ void Device::initSignals() deleteLater(); qDebug() << "stream thread stop"; }); + connect(m_stream, &Stream::getFrame, this, [this](AVPacket *packet) { + if (m_decoder && !m_decoder->push(packet)) { + qCritical("Could not send packet to decoder"); + } + + if (m_recorder && !m_recorder->push(packet)) { + qCritical("Could not send packet to recorder"); + } + }, Qt::DirectConnection); + connect(m_stream, &Stream::getConfigFrame, this, [this](AVPacket *packet) { + if (m_recorder && !m_recorder->push(packet)) { + qCritical("Could not send config packet to recorder"); + } + }, Qt::DirectConnection); } if (m_decoder && m_vb) { diff --git a/QtScrcpy/device/recorder/recorder.cpp b/QtScrcpy/device/recorder/recorder.cpp index a8130af41..41ac0956e 100644 --- a/QtScrcpy/device/recorder/recorder.cpp +++ b/QtScrcpy/device/recorder/recorder.cpp @@ -51,8 +51,15 @@ void Recorder::setFormat(Recorder::RecorderFormat format) m_format = format; } -bool Recorder::open(const AVCodec *inputCodec) +bool Recorder::open() { + // codec + AVCodec* inputCodec = avcodec_find_decoder(AV_CODEC_ID_H264); + if (!inputCodec) { + qCritical("H.264 decoder not found"); + return false; + } + QString formatName = recorderGetFormatName(m_format); Q_ASSERT(!formatName.isEmpty()); const AVOutputFormat *format = findMuxer(formatName.toUtf8()); diff --git a/QtScrcpy/device/recorder/recorder.h b/QtScrcpy/device/recorder/recorder.h index 1691f3867..db1c0b7be 100644 --- a/QtScrcpy/device/recorder/recorder.h +++ b/QtScrcpy/device/recorder/recorder.h @@ -28,7 +28,7 @@ class Recorder : public QThread void setFrameSize(const QSize &declaredFrameSize); void setFormat(Recorder::RecorderFormat format); - bool open(const AVCodec *inputCodec); + bool open(); void close(); bool write(AVPacket *packet); bool startRecorder(); diff --git a/QtScrcpy/device/stream/stream.cpp b/QtScrcpy/device/stream/stream.cpp index 4fe35ff29..3328c5e7a 100644 --- a/QtScrcpy/device/stream/stream.cpp +++ b/QtScrcpy/device/stream/stream.cpp @@ -67,11 +67,6 @@ void Stream::deInit() avformat_network_deinit(); // ignore failure } -void Stream::setDecoder(Decoder *decoder) -{ - m_decoder = decoder; -} - static quint32 bufferRead32be(quint8 *buf) { return static_cast((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]); @@ -84,11 +79,6 @@ static quint64 bufferRead64be(quint8 *buf) return (static_cast(msb) << 32) | lsb; } -void Stream::setRecoder(Recorder *recorder) -{ - m_recorder = recorder; -} - qint32 Stream::recvData(quint8 *buf, qint32 bufSize) { if (!buf || !m_recvData) { @@ -110,9 +100,6 @@ bool Stream::startDecode() void Stream::stopDecode() { - if (m_decoder) { - m_decoder->interrupt(); - } wait(); } @@ -136,23 +123,6 @@ void Stream::run() goto runQuit; } - if (m_decoder && !m_decoder->open(codec)) { - qCritical("Could not open m_decoder"); - goto runQuit; - } - - if (m_recorder) { - if (!m_recorder->open(codec)) { - qCritical("Could not open recorder"); - goto runQuit; - } - - if (!m_recorder->startRecorder()) { - qCritical("Could not start recorder"); - goto runQuit; - } - } - m_parser = av_parser_init(AV_CODEC_ID_H264); if (!m_parser) { qCritical("Could not initialize parser"); @@ -188,16 +158,6 @@ void Stream::run() av_parser_close(m_parser); runQuit: - if (m_recorder) { - if (m_recorder->isRunning()) { - m_recorder->stopRecorder(); - m_recorder->wait(); - } - m_recorder->close(); - } - if (m_decoder) { - m_decoder->close(); - } if (m_codecCtx) { avcodec_free_context(&m_codecCtx); } @@ -305,10 +265,7 @@ bool Stream::pushPacket(AVPacket *packet) bool Stream::processConfigPacket(AVPacket *packet) { - if (m_recorder && !m_recorder->push(packet)) { - qCritical("Could not send config packet to recorder"); - return false; - } + emit getConfigFrame(packet); return true; } @@ -340,18 +297,7 @@ bool Stream::parse(AVPacket *packet) bool Stream::processFrame(AVPacket *packet) { - if (m_decoder && !m_decoder->push(packet)) { - return false; - } - - if (m_recorder) { - packet->dts = packet->pts; - - if (!m_recorder->push(packet)) { - qCritical("Could not send packet to recorder"); - return false; - } - } - + packet->dts = packet->pts; + emit getFrame(packet); return true; } diff --git a/QtScrcpy/device/stream/stream.h b/QtScrcpy/device/stream/stream.h index 839d04fda..c58dac435 100644 --- a/QtScrcpy/device/stream/stream.h +++ b/QtScrcpy/device/stream/stream.h @@ -24,13 +24,13 @@ class Stream : public QThread static bool init(); static void deInit(); - void setDecoder(Decoder *decoder); - void setRecoder(Recorder *recorder); bool startDecode(); void stopDecode(); signals: void onStreamStop(); + void getFrame(AVPacket* packet); + void getConfigFrame(AVPacket* packet); protected: void run(); @@ -43,9 +43,6 @@ class Stream : public QThread private: std::function m_recvData = nullptr; - // for recorder - Recorder *m_recorder = Q_NULLPTR; - Decoder *m_decoder = Q_NULLPTR; AVCodecContext *m_codecCtx = Q_NULLPTR; AVCodecParserContext *m_parser = Q_NULLPTR; From d68d96b4eeeaaa25cf3842f436db11b662b57e85 Mon Sep 17 00:00:00 2001 From: Barry <870709864@qq.com> Date: Wed, 6 Apr 2022 11:47:49 +0800 Subject: [PATCH 04/14] fix: remove invalid quote --- QtScrcpy/device/stream/stream.cpp | 3 --- QtScrcpy/device/stream/stream.h | 3 --- config/userdata.ini.lock | 5 +++++ 3 files changed, 5 insertions(+), 6 deletions(-) create mode 100644 config/userdata.ini.lock diff --git a/QtScrcpy/device/stream/stream.cpp b/QtScrcpy/device/stream/stream.cpp index 3328c5e7a..d3188016c 100644 --- a/QtScrcpy/device/stream/stream.cpp +++ b/QtScrcpy/device/stream/stream.cpp @@ -2,10 +2,7 @@ #include #include "compat.h" -#include "decoder.h" -#include "recorder.h" #include "stream.h" -#include "videosocket.h" #define BUFSIZE 0x10000 #define HEADER_SIZE 12 diff --git a/QtScrcpy/device/stream/stream.h b/QtScrcpy/device/stream/stream.h index c58dac435..619c2d4bc 100644 --- a/QtScrcpy/device/stream/stream.h +++ b/QtScrcpy/device/stream/stream.h @@ -10,9 +10,6 @@ extern "C" #include "libavformat/avformat.h" } -class VideoSocket; -class Recorder; -class Decoder; class Stream : public QThread { Q_OBJECT diff --git a/config/userdata.ini.lock b/config/userdata.ini.lock new file mode 100644 index 000000000..de8018aad --- /dev/null +++ b/config/userdata.ini.lock @@ -0,0 +1,5 @@ +11952 +QtScrcpy +BARRY +ddd598cc-fb9f-4338-bb02-6c1cbf2b8914 + From 32cebd45aaa6e1d944872be235f55ee3d99ff6ee Mon Sep 17 00:00:00 2001 From: Barry <870709864@qq.com> Date: Wed, 6 Apr 2022 20:34:38 +0800 Subject: [PATCH 05/14] refactor: controller and socket decoupling --- QtScrcpy/device/controller/controller.cpp | 24 +++++++------- QtScrcpy/device/controller/controller.h | 8 +++-- .../device/controller/receiver/receiver.cpp | 30 +----------------- .../device/controller/receiver/receiver.h | 12 +------ QtScrcpy/device/device.cpp | 31 ++++++++++++++++--- 5 files changed, 46 insertions(+), 59 deletions(-) diff --git a/QtScrcpy/device/controller/controller.cpp b/QtScrcpy/device/controller/controller.cpp index b0faa82ca..014dc3edc 100644 --- a/QtScrcpy/device/controller/controller.cpp +++ b/QtScrcpy/device/controller/controller.cpp @@ -7,7 +7,9 @@ #include "receiver.h" #include "videosocket.h" -Controller::Controller(QString gameScript, QObject *parent) : QObject(parent) +Controller::Controller(std::function sendData, QString gameScript, QObject *parent) + : QObject(parent) + , m_sendData(sendData) { m_receiver = new Receiver(this); Q_ASSERT(m_receiver); @@ -17,20 +19,20 @@ Controller::Controller(QString gameScript, QObject *parent) : QObject(parent) Controller::~Controller() {} -void Controller::setControlSocket(QTcpSocket *controlSocket) +void Controller::postControlMsg(ControlMsg *controlMsg) { - if (m_controlSocket || !controlSocket) { - return; + if (controlMsg) { + QCoreApplication::postEvent(this, controlMsg); } - m_controlSocket = controlSocket; - m_receiver->setControlSocket(controlSocket); } -void Controller::postControlMsg(ControlMsg *controlMsg) +void Controller::recvDeviceMsg(DeviceMsg *deviceMsg) { - if (controlMsg) { - QCoreApplication::postEvent(this, controlMsg); + if (!m_receiver) { + return; } + + m_receiver->recvDeviceMsg(deviceMsg); } void Controller::test(QRect rc) @@ -236,8 +238,8 @@ bool Controller::sendControl(const QByteArray &buffer) return false; } qint32 len = 0; - if (m_controlSocket) { - len = static_cast(m_controlSocket->write(buffer.data(), buffer.length())); + if (m_sendData) { + len = static_cast(m_sendData(buffer)); } return len == buffer.length() ? true : false; } diff --git a/QtScrcpy/device/controller/controller.h b/QtScrcpy/device/controller/controller.h index 0b2d88685..1b50f73fd 100644 --- a/QtScrcpy/device/controller/controller.h +++ b/QtScrcpy/device/controller/controller.h @@ -1,3 +1,4 @@ + #ifndef CONTROLLER_H #define CONTROLLER_H @@ -9,15 +10,16 @@ class QTcpSocket; class Receiver; class InputConvertBase; +class DeviceMsg; class Controller : public QObject { Q_OBJECT public: - Controller(QString gameScript = "", QObject *parent = Q_NULLPTR); + Controller(std::function sendData, QString gameScript = "", QObject *parent = Q_NULLPTR); virtual ~Controller(); - void setControlSocket(QTcpSocket *controlSocket); void postControlMsg(ControlMsg *controlMsg); + void recvDeviceMsg(DeviceMsg *deviceMsg); void test(QRect rc); void updateScript(QString gameScript = ""); @@ -62,9 +64,9 @@ public slots: void postKeyCodeClick(AndroidKeycode keycode); private: - QPointer m_controlSocket; QPointer m_receiver; QPointer m_inputConvert; + std::function m_sendData = Q_NULLPTR; }; #endif // CONTROLLER_H diff --git a/QtScrcpy/device/controller/receiver/receiver.cpp b/QtScrcpy/device/controller/receiver/receiver.cpp index 32d819d3d..12f5b950c 100644 --- a/QtScrcpy/device/controller/receiver/receiver.cpp +++ b/QtScrcpy/device/controller/receiver/receiver.cpp @@ -1,6 +1,5 @@ #include #include -#include #include "devicemsg.h" #include "receiver.h" @@ -9,34 +8,7 @@ Receiver::Receiver(QObject *parent) : QObject(parent) {} Receiver::~Receiver() {} -void Receiver::setControlSocket(QTcpSocket *controlSocket) -{ - if (m_controlSocket || !controlSocket) { - return; - } - m_controlSocket = controlSocket; - connect(controlSocket, &QTcpSocket::readyRead, this, &Receiver::onReadyRead); -} - -void Receiver::onReadyRead() -{ - if (!m_controlSocket) { - return; - } - - while (m_controlSocket->bytesAvailable()) { - QByteArray byteArray = m_controlSocket->peek(m_controlSocket->bytesAvailable()); - DeviceMsg deviceMsg; - qint32 consume = deviceMsg.deserialize(byteArray); - if (0 >= consume) { - break; - } - m_controlSocket->read(consume); - processMsg(&deviceMsg); - } -} - -void Receiver::processMsg(DeviceMsg *deviceMsg) +void Receiver::recvDeviceMsg(DeviceMsg *deviceMsg) { switch (deviceMsg->type()) { case DeviceMsg::DMT_GET_CLIPBOARD: { diff --git a/QtScrcpy/device/controller/receiver/receiver.h b/QtScrcpy/device/controller/receiver/receiver.h index 13266ed68..a11d4dfb1 100644 --- a/QtScrcpy/device/controller/receiver/receiver.h +++ b/QtScrcpy/device/controller/receiver/receiver.h @@ -3,7 +3,6 @@ #include -class QTcpSocket; class DeviceMsg; class Receiver : public QObject { @@ -12,16 +11,7 @@ class Receiver : public QObject explicit Receiver(QObject *parent = Q_NULLPTR); virtual ~Receiver(); - void setControlSocket(QTcpSocket *controlSocket); - -public slots: - void onReadyRead(); - -protected: - void processMsg(DeviceMsg *deviceMsg); - -private: - QPointer m_controlSocket; + void recvDeviceMsg(DeviceMsg *deviceMsg); }; #endif // RECEIVER_H diff --git a/QtScrcpy/device/device.cpp b/QtScrcpy/device/device.cpp index 664ea5dc3..fabe6a289 100644 --- a/QtScrcpy/device/device.cpp +++ b/QtScrcpy/device/device.cpp @@ -5,6 +5,7 @@ #include "avframeconvert.h" #include "config.h" #include "controller.h" +#include "devicemsg.h" #include "decoder.h" #include "device.h" #include "filehandler.h" @@ -32,7 +33,13 @@ Device::Device(DeviceParams params, QObject *parent) : QObject(parent), m_params m_vb->init(params.renderExpiredFrames); m_decoder = new Decoder(m_vb, this); m_fileHandler = new FileHandler(this); - m_controller = new Controller(params.gameScript, this); + m_controller = new Controller([this](const QByteArray& buffer) -> qint64 { + if (!m_server || !m_server->getControlSocket()) { + return 0; + } + + return m_server->getControlSocket()->write(buffer.data(), buffer.length()); + }, params.gameScript, this); m_videoForm = new VideoForm(params.framelessWindow, Config::getInstance().getSkin()); m_videoForm->setDevice(this); } @@ -273,10 +280,24 @@ void Device::initSignals() // init decoder m_stream->startDecode(); - // init controller - if (m_controller) { - m_controller->setControlSocket(m_server->getControlSocket()); - } + // recv device msg + connect(m_server->getControlSocket(), &QTcpSocket::readyRead, this, [this](){ + if (!m_controller) { + return; + } + + auto controlSocket = m_server->getControlSocket(); + while (controlSocket->bytesAvailable()) { + QByteArray byteArray = controlSocket->peek(controlSocket->bytesAvailable()); + DeviceMsg deviceMsg; + qint32 consume = deviceMsg.deserialize(byteArray); + if (0 >= consume) { + break; + } + controlSocket->read(consume); + m_controller->recvDeviceMsg(&deviceMsg); + } + }); // 显示界面时才自动息屏(m_params.display) if (m_params.closeScreen && m_params.display && m_controller) { From b83c8cbe6fafffb7713748035937d420f691b425 Mon Sep 17 00:00:00 2001 From: Barry <870709864@qq.com> Date: Sat, 9 Apr 2022 10:12:34 +0800 Subject: [PATCH 06/14] refactor: move VideoBuffer to Decoder --- QtScrcpy/device/decoder/decoder.cpp | 36 +++++++++++- QtScrcpy/device/decoder/decoder.h | 12 +++- QtScrcpy/device/decoder/videobuffer.cpp | 65 +++++++++++++++++---- QtScrcpy/device/decoder/videobuffer.h | 14 +++-- QtScrcpy/device/device.cpp | 77 +++++-------------------- QtScrcpy/device/device.h | 3 +- QtScrcpy/device/ui/videoform.cpp | 8 +-- QtScrcpy/device/ui/videoform.h | 3 +- 8 files changed, 129 insertions(+), 89 deletions(-) diff --git a/QtScrcpy/device/decoder/decoder.cpp b/QtScrcpy/device/decoder/decoder.cpp index 52188103a..0a5bd4f18 100644 --- a/QtScrcpy/device/decoder/decoder.cpp +++ b/QtScrcpy/device/decoder/decoder.cpp @@ -4,9 +4,20 @@ #include "decoder.h" #include "videobuffer.h" -Decoder::Decoder(VideoBuffer *vb, QObject *parent) : QObject(parent), m_vb(vb) {} +Decoder::Decoder(std::function onFrame, QObject *parent) + : QObject(parent) + , m_vb(new VideoBuffer()) + , m_onFrame(onFrame) +{ + m_vb->init(); + connect(this, &Decoder::newFrame, this, &Decoder::onNewFrame, Qt::QueuedConnection); + connect(m_vb, &VideoBuffer::updateFPS, this, &Decoder::updateFPS); +} -Decoder::~Decoder() {} +Decoder::~Decoder() { + m_vb->deInit(); + delete m_vb; +} bool Decoder::open() { @@ -110,6 +121,14 @@ bool Decoder::push(const AVPacket *packet) return true; } +void Decoder::peekFrame(std::function onFrame) +{ + if (!m_vb) { + return; + } + m_vb->peekRenderedFrame(onFrame); +} + void Decoder::pushFrame() { if (!m_vb) { @@ -121,5 +140,16 @@ void Decoder::pushFrame() // the previous newFrame will consume this frame return; } - emit onNewFrame(); + emit newFrame(); +} + +void Decoder::onNewFrame() { + if (!m_onFrame) { + return; + } + + m_vb->lock(); + const AVFrame *frame = m_vb->consumeRenderedFrame(); + m_onFrame(frame->width, frame->height, frame->data[0], frame->data[1], frame->data[2], frame->linesize[0], frame->linesize[1], frame->linesize[2]); + m_vb->unLock(); } diff --git a/QtScrcpy/device/decoder/decoder.h b/QtScrcpy/device/decoder/decoder.h index cdde67c32..c372d6cdb 100644 --- a/QtScrcpy/device/decoder/decoder.h +++ b/QtScrcpy/device/decoder/decoder.h @@ -12,23 +12,31 @@ class Decoder : public QObject { Q_OBJECT public: - Decoder(VideoBuffer *vb, QObject *parent = Q_NULLPTR); + Decoder(std::function onFrame, QObject *parent = Q_NULLPTR); virtual ~Decoder(); bool open(); void close(); bool push(const AVPacket *packet); + void peekFrame(std::function onFrame); signals: + void updateFPS(quint32 fps); + +private slots: void onNewFrame(); -protected: +signals: + void newFrame(); + +private: void pushFrame(); private: VideoBuffer *m_vb = Q_NULLPTR; AVCodecContext *m_codecCtx = Q_NULLPTR; bool m_isCodecCtxOpen = false; + std::function m_onFrame = Q_NULLPTR; }; #endif // DECODER_H diff --git a/QtScrcpy/device/decoder/videobuffer.cpp b/QtScrcpy/device/decoder/videobuffer.cpp index f41e9226f..9ebb97951 100644 --- a/QtScrcpy/device/decoder/videobuffer.cpp +++ b/QtScrcpy/device/decoder/videobuffer.cpp @@ -1,17 +1,20 @@ #include "videobuffer.h" +#include "avframeconvert.h" extern "C" { #include "libavformat/avformat.h" #include "libavutil/avutil.h" +#include "libavutil/imgutils.h" } -VideoBuffer::VideoBuffer() {} +VideoBuffer::VideoBuffer(QObject *parent) : QObject(parent) { + connect(&m_fpsCounter, &FpsCounter::updateFPS, this, &VideoBuffer::updateFPS); +} VideoBuffer::~VideoBuffer() {} -bool VideoBuffer::init(bool renderExpiredFrames) +bool VideoBuffer::init() { - m_renderExpiredFrames = renderExpiredFrames; m_decodingFrame = av_frame_alloc(); if (!m_decodingFrame) { goto error; @@ -57,6 +60,11 @@ void VideoBuffer::unLock() m_mutex.unlock(); } +void VideoBuffer::setRenderExpiredFrames(bool renderExpiredFrames) +{ + m_renderExpiredFrames = renderExpiredFrames; +} + AVFrame *VideoBuffer::decodingFrame() { return m_decodingFrame; @@ -99,9 +107,51 @@ const AVFrame *VideoBuffer::consumeRenderedFrame() return m_renderingframe; } -const AVFrame *VideoBuffer::peekRenderedFrame() +void VideoBuffer::peekRenderedFrame(std::function onFrame) { - return m_renderingframe; + if (!onFrame) { + return; + } + + lock(); + auto frame = m_renderingframe; + int width = frame->width; + int height = frame->height; + + // create buffer + uint8_t* rgbBuffer = new uint8_t[width * height * 4]; + AVFrame *rgbFrame = av_frame_alloc(); + if (!rgbFrame) { + delete [] rgbBuffer; + return; + } + + // bind buffer to AVFrame + av_image_fill_arrays(rgbFrame->data, rgbFrame->linesize, rgbBuffer, AV_PIX_FMT_RGB32, width, height, 4); + + // convert + AVFrameConvert convert; + convert.setSrcFrameInfo(width, height, AV_PIX_FMT_YUV420P); + convert.setDstFrameInfo(width, height, AV_PIX_FMT_RGB32); + bool ret = false; + ret = convert.init(); + if (!ret) { + delete [] rgbBuffer; + av_free(rgbFrame); + return; + } + ret = convert.convert(frame, rgbFrame); + if (!ret) { + delete [] rgbBuffer; + av_free(rgbFrame); + return; + } + convert.deInit(); + av_free(rgbFrame); + unLock(); + + onFrame(width, height, rgbBuffer); + delete [] rgbBuffer; } void VideoBuffer::interrupt() @@ -115,11 +165,6 @@ void VideoBuffer::interrupt() } } -FpsCounter *VideoBuffer::getFPSCounter() -{ - return &m_fpsCounter; -} - void VideoBuffer::swap() { AVFrame *tmp = m_decodingFrame; diff --git a/QtScrcpy/device/decoder/videobuffer.h b/QtScrcpy/device/decoder/videobuffer.h index 908cbc63d..5c9704216 100644 --- a/QtScrcpy/device/decoder/videobuffer.h +++ b/QtScrcpy/device/decoder/videobuffer.h @@ -3,22 +3,25 @@ #include #include +#include #include "fpscounter.h" // forward declarations typedef struct AVFrame AVFrame; -class VideoBuffer +class VideoBuffer : public QObject { + Q_OBJECT public: - VideoBuffer(); + VideoBuffer(QObject *parent = Q_NULLPTR); virtual ~VideoBuffer(); - bool init(bool renderExpiredFrames = false); + bool init(); void deInit(); void lock(); void unLock(); + void setRenderExpiredFrames(bool renderExpiredFrames); AVFrame *decodingFrame(); // set the decoder frame as ready for rendering @@ -32,12 +35,13 @@ class VideoBuffer // unlocking m_mutex const AVFrame *consumeRenderedFrame(); - const AVFrame *peekRenderedFrame(); + void peekRenderedFrame(std::function onFrame); // wake up and avoid any blocking call void interrupt(); - FpsCounter *getFPSCounter(); +signals: + void updateFPS(quint32 fps); private: void swap(); diff --git a/QtScrcpy/device/device.cpp b/QtScrcpy/device/device.cpp index fabe6a289..8ec179e52 100644 --- a/QtScrcpy/device/device.cpp +++ b/QtScrcpy/device/device.cpp @@ -2,7 +2,6 @@ #include #include -#include "avframeconvert.h" #include "config.h" #include "controller.h" #include "devicemsg.h" @@ -13,12 +12,7 @@ #include "recorder.h" #include "server.h" #include "stream.h" -#include "videobuffer.h" #include "videoform.h" -extern "C" -{ -#include "libavutil/imgutils.h" -} Device::Device(DeviceParams params, QObject *parent) : QObject(parent), m_params(params) { @@ -29,9 +23,12 @@ Device::Device(DeviceParams params, QObject *parent) : QObject(parent), m_params } if (params.display) { - m_vb = new VideoBuffer(); - m_vb->init(params.renderExpiredFrames); - m_decoder = new Decoder(m_vb, this); + + m_decoder = new Decoder([this](int width, int height, uint8_t* dataY, uint8_t* dataU, uint8_t* dataV, int linesizeY, int linesizeU, int linesizeV) { + if (m_videoForm) { + m_videoForm->updateRender(width, height, dataY, dataU, dataV, linesizeY, linesizeU, linesizeV); + } + }, this); m_fileHandler = new FileHandler(this); m_controller = new Controller([this](const QByteArray& buffer) -> qint64 { if (!m_server || !m_server->getControlSocket()) { @@ -84,10 +81,6 @@ Device::~Device() m_recorder->close(); delete m_recorder; } - if (m_vb) { - m_vb->deInit(); - delete m_vb; - } if (m_videoForm) { m_videoForm->close(); delete m_videoForm; @@ -128,14 +121,14 @@ void Device::updateScript(QString script) void Device::onScreenshot() { - if (!m_vb) { + if (!m_decoder) { return; } - m_vb->lock(); // screenshot - saveFrame(m_vb->peekRenderedFrame()); - m_vb->unLock(); + m_decoder->peekFrame([this](int width, int height, uint8_t* dataRGB32) { + saveFrame(width, height, dataRGB32); + }); } void Device::onShowTouch(bool show) @@ -332,22 +325,8 @@ void Device::initSignals() }, Qt::DirectConnection); } - 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(); - const AVFrame *frame = m_vb->consumeRenderedFrame(); - if (m_videoForm) { - m_videoForm->updateRender(frame); - } - m_vb->unLock(); - }, - Qt::QueuedConnection); - connect(m_vb->getFPSCounter(), &::FpsCounter::updateFPS, m_videoForm, &VideoForm::updateFPS); + if (m_decoder) { + connect(m_decoder, &Decoder::updateFPS, m_videoForm, &VideoForm::updateFPS); } } @@ -412,37 +391,13 @@ bool Device::isCurrentCustomKeymap() return m_controller->isCurrentCustomKeymap(); } -bool Device::saveFrame(const AVFrame *frame) +bool Device::saveFrame(int width, int height, uint8_t* dataRGB32) { - if (!frame) { + if (!dataRGB32) { return false; } - // create buffer - QImage rgbImage(frame->width, frame->height, QImage::Format_RGB32); - AVFrame *rgbFrame = av_frame_alloc(); - if (!rgbFrame) { - return false; - } - - // bind buffer to AVFrame - av_image_fill_arrays(rgbFrame->data, rgbFrame->linesize, rgbImage.bits(), AV_PIX_FMT_RGB32, frame->width, frame->height, 4); - - // convert - AVFrameConvert convert; - convert.setSrcFrameInfo(frame->width, frame->height, AV_PIX_FMT_YUV420P); - convert.setDstFrameInfo(frame->width, frame->height, AV_PIX_FMT_RGB32); - bool ret = false; - ret = convert.init(); - if (!ret) { - return false; - } - ret = convert.convert(frame, rgbFrame); - if (!ret) { - return false; - } - convert.deInit(); - av_free(rgbFrame); + QImage rgbImage(dataRGB32, width, height, QImage::Format_RGB32); // save QString absFilePath; @@ -456,7 +411,7 @@ bool Device::saveFrame(const AVFrame *frame) fileName = Config::getInstance().getTitle() + fileName + ".png"; QDir dir(fileDir); absFilePath = dir.absoluteFilePath(fileName); - ret = rgbImage.save(absFilePath, "PNG", 100); + int ret = rgbImage.save(absFilePath, "PNG", 100); if (!ret) { return false; } diff --git a/QtScrcpy/device/device.h b/QtScrcpy/device/device.h index 2691348d9..063f518de 100644 --- a/QtScrcpy/device/device.h +++ b/QtScrcpy/device/device.h @@ -108,7 +108,7 @@ public slots: private: void initSignals(); void startServer(); - bool saveFrame(const AVFrame *frame); + bool saveFrame(int width, int height, uint8_t* dataRGB32); private: // server relevant @@ -117,7 +117,6 @@ public slots: QPointer m_controller; QPointer m_fileHandler; QPointer m_stream; - VideoBuffer *m_vb = Q_NULLPTR; Recorder *m_recorder = Q_NULLPTR; // ui diff --git a/QtScrcpy/device/ui/videoform.cpp b/QtScrcpy/device/ui/videoform.cpp index 9dc14ddda..295e65208 100644 --- a/QtScrcpy/device/ui/videoform.cpp +++ b/QtScrcpy/device/ui/videoform.cpp @@ -148,7 +148,7 @@ void VideoForm::showFPS(bool show) m_fpsLabel->setVisible(show); } -void VideoForm::updateRender(const AVFrame *frame) +void VideoForm::updateRender(int width, int height, uint8_t* dataY, uint8_t* dataU, uint8_t* dataV, int linesizeY, int linesizeU, int linesizeV) { if (m_videoWidget->isHidden()) { if (m_loadingWidget) { @@ -157,9 +157,9 @@ void VideoForm::updateRender(const AVFrame *frame) m_videoWidget->show(); } - updateShowSize(QSize(frame->width, frame->height)); - m_videoWidget->setFrameSize(QSize(frame->width, frame->height)); - m_videoWidget->updateTextures(frame->data[0], frame->data[1], frame->data[2], frame->linesize[0], frame->linesize[1], frame->linesize[2]); + updateShowSize(QSize(width, height)); + m_videoWidget->setFrameSize(QSize(width, height)); + m_videoWidget->updateTextures(dataY, dataU, dataV, linesizeY, linesizeU, linesizeV); } void VideoForm::showToolForm(bool show) diff --git a/QtScrcpy/device/ui/videoform.h b/QtScrcpy/device/ui/videoform.h index bda37a4ae..309cf7dae 100644 --- a/QtScrcpy/device/ui/videoform.h +++ b/QtScrcpy/device/ui/videoform.h @@ -9,7 +9,6 @@ namespace Ui class videoForm; } -struct AVFrame; class ToolForm; class Device; class FileHandler; @@ -24,7 +23,7 @@ class VideoForm : public QWidget void staysOnTop(bool top = true); void updateShowSize(const QSize &newSize); - void updateRender(const AVFrame *frame); + void updateRender(int width, int height, uint8_t* dataY, uint8_t* dataU, uint8_t* dataV, int linesizeY, int linesizeU, int linesizeV); void setDevice(Device *device); QRect getGrabCursorRect(); const QSize &frameSize(); From 2d235ee9a130154a4eba29dea49cd94fe5d1eef3 Mon Sep 17 00:00:00 2001 From: Barry <870709864@qq.com> Date: Sat, 9 Apr 2022 10:42:59 +0800 Subject: [PATCH 07/14] =?UTF-8?q?chore:=20=E7=A7=BB=E9=99=A4lock=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/userdata.ini.lock | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 config/userdata.ini.lock diff --git a/config/userdata.ini.lock b/config/userdata.ini.lock deleted file mode 100644 index de8018aad..000000000 --- a/config/userdata.ini.lock +++ /dev/null @@ -1,5 +0,0 @@ -11952 -QtScrcpy -BARRY -ddd598cc-fb9f-4338-bb02-6c1cbf2b8914 - From 8d360f62db07483e87d497674d0048161e0c74c3 Mon Sep 17 00:00:00 2001 From: Barry <870709864@qq.com> Date: Sat, 9 Apr 2022 12:10:06 +0800 Subject: [PATCH 08/14] fix: grab rect dpi error --- QtScrcpy/device/ui/videoform.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/QtScrcpy/device/ui/videoform.cpp b/QtScrcpy/device/ui/videoform.cpp index 295e65208..d6b68277d 100644 --- a/QtScrcpy/device/ui/videoform.cpp +++ b/QtScrcpy/device/ui/videoform.cpp @@ -90,8 +90,8 @@ QRect VideoForm::getGrabCursorRect() #if defined(Q_OS_WIN32) rc = QRect(ui->keepRatioWidget->mapToGlobal(m_videoWidget->pos()), m_videoWidget->size()); // high dpi support - rc.setTopLeft(rc.topLeft() * m_videoWidget->devicePixelRatio()); - rc.setBottomRight(rc.bottomRight() * m_videoWidget->devicePixelRatio()); + rc.setTopLeft(rc.topLeft() * m_videoWidget->devicePixelRatioF()); + rc.setBottomRight(rc.bottomRight() * m_videoWidget->devicePixelRatioF()); rc.setX(rc.x() + 10); rc.setY(rc.y() + 10); From 1be849aa220fb486cfcca912b1ce9edcf835dd7b Mon Sep 17 00:00:00 2001 From: Barry <870709864@qq.com> Date: Sat, 9 Apr 2022 13:31:52 +0800 Subject: [PATCH 09/14] feat: change ui --- QtScrcpy/dialog.cpp | 10 - QtScrcpy/dialog.ui | 1532 ++++++++++++++++++++++++------------------- 2 files changed, 870 insertions(+), 672 deletions(-) diff --git a/QtScrcpy/dialog.cpp b/QtScrcpy/dialog.cpp index 009a65c23..978f936e2 100644 --- a/QtScrcpy/dialog.cpp +++ b/QtScrcpy/dialog.cpp @@ -135,16 +135,6 @@ void Dialog::initUI() on_useSingleModeCheck_clicked(); on_updateDevice_clicked(); - -#ifdef Q_OS_OSX - // mac need more width - setFixedWidth(550); -#endif - -#ifdef Q_OS_LINUX - // linux need more width - setFixedWidth(520); -#endif } void Dialog::updateBootConfig(bool toView) diff --git a/QtScrcpy/dialog.ui b/QtScrcpy/dialog.ui index d99bafe9f..2575feafa 100644 --- a/QtScrcpy/dialog.ui +++ b/QtScrcpy/dialog.ui @@ -6,248 +6,214 @@ 0 0 - 500 - 749 + 1105 + 419 - - - 500 - 0 - - - - - 565 - 16777215 - - QtScrcpy - - - - - Use Simple Mode - - - false - - - + + + 0 + + + 0 + + + 0 + + + 0 + - - - Simple Mode - - - false + + + + 0 + 0 + - - - - - - - WIFI Connect - - - - - - - USB Connect - - - - - + - + + + + 0 + 0 + + - Double click to connect: + Use Simple Mode + + + false - + - + 0 0 - - - 0 - 100 - + + Simple Mode - - - 16777215 - 100 - + + false + + + + + + + + 0 + 0 + + + + WIFI Connect + + + + + + + + 0 + 0 + + + + USB Connect + + + + + + + + + + 0 + 0 + + + + Double click to connect: + + + + + + + + 0 + 0 + + + + + - - - - - - - Start Config - - - - 3 - - - 5 - - - 5 - - - 5 - - - 5 - - - + + + + 0 + 0 + + + + adb + + + + 3 + - 0 + 5 - 0 + 5 - 0 + 5 - 0 + 5 - + - + 0 0 - - - 60 - 0 - - - - - 0 - 16777215 - - - bit rate: + adb command: + + + adbCommandEdt - + - + 0 0 - - - 100 - 0 - - - - - 0 - 16777215 - - - 2 + devices - + - + 0 0 - - - 70 - 0 - - - - - 0 - 16777215 - - - - - - - Mbps + + execute - - - Mbps - - - - - Kbps - - - + - + 0 0 - - - 70 - 0 - - - - - 0 - 16777215 - - - max size: + terminate - - - + + + + 0 + 0 + + + + clear @@ -255,363 +221,814 @@ - - + + + + 0 + 0 + + + + Qt::ClickFocus + + + + + + true + + + + + + + + + + + 0 + 0 + + + + + + + + 0 + 0 + + + + Start Config + + + + 3 + - 0 + 5 - 0 + 5 - 0 + 5 - 0 + 5 - - - record format: + + + + 0 + 0 + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + bit rate: + + + + + + + + 0 + 0 + + + + 2 + + + + + + + + 0 + 0 + + + + + + + Mbps + + + + Mbps + + + + + Kbps + + + + + + + + + 0 + 0 + + + + max size: + + + + + + + + 0 + 0 + + + + + + + + - - - - - - lock orientation: + + + + 0 + 0 + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + record format: + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + lock orientation: + + + + + + + + 0 + 0 + + + + + - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - record save path: - - - recordPathEdt + + + + 0 + 0 + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + record save path: + + + recordPathEdt + + + + + + + + 0 + 0 + + + + true + + + + + + + + 0 + 0 + + + + select path + + + false + + + + - - - true + + + + 0 + 0 + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + refresh script + + + + + + + + 0 + 0 + + + + apply + + + + - - - select path - - - false + + + + 0 + 0 + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + screen-off + + + + + + + + 0 + 0 + + + + frameless + + + + + + + + 0 + 0 + + + + always on top + + + false + + + + + + + + 0 + 0 + + + + background record + + + false + + + + + + + + 0 + 0 + + + + reverse connection + + + true + + + + + + + + 0 + 0 + + + + record screen + + + + + + + + 0 + 0 + + + + show fps + + + + + + + + 0 + 0 + + + + stay awake + + + + - - - - 0 - - - 0 - - - 0 - - - 0 - + + + + 0 + 0 + + + + USB line + + - + + + + + + 0 + 0 + + + + device name: + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + update name + + + false + + + + + + + - + 0 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + device serial: + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + start server + + + false + + + + + + + + 0 + 0 + + + + stop server + + + false + + + + - - - refresh script - - - - - - - apply + + + + 0 + 0 + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + stop all server + + + + + + + + 0 + 0 + + + + refresh devices + + + false + + + + + + + + 0 + 0 + + + + get device IP + + + false + + + + + + + + 0 + 0 + + + + start adbd + + + false + + + + - - + + + + 0 + 0 + + + + Wireless + + + + 3 + - 0 + 5 - 0 + 5 - 0 + 5 - 0 + 5 - - + + - + 0 0 - screen-off + - - - - - - frameless + + 128 + + + 192.168.0.1 - - + + - + 0 0 - always on top - - - false + : - - + + - + 0 0 - background record + - - false + + 6 + + + 5555 - - + + - + 0 0 - reverse connection - - - true - - - - - - - record screen - - - - - - - show fps - - - - - - - stay awake - - - - - - - - - - - - - USB line - - - - - - - - - 110 - 0 - - - - device name: - - - - - - - - 16777215 - 16777215 - - - - - - - - update name - - - false - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 110 - 0 - - - - device serial: - - - - - - - - - - start server - - - false - - - - - - - stop server - - - false - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - stop all server - - - - - - - refresh devices + wireless connect false @@ -619,19 +1036,15 @@ - - - get device IP - - - false + + + + 0 + 0 + - - - - - start adbd + wireless disconnect false @@ -641,233 +1054,28 @@ - - - - - - - Wireless - - - - 3 - - - 5 - - - 5 - - - 5 - - - 5 - - - - - - - - 128 - - - 192.168.0.1 - - - - - - - - 5 - 0 - - - - - 5 - 16777215 - - - - : - - - - + - + 0 0 - + + Qt::Vertical + + - 60 - 16777215 + 20 + 40 - - - - - 6 - - - 5555 - - - - - - - - 0 - 0 - - - - wireless connect - - - false - - - - - - - - 0 - 0 - - - - wireless disconnect - - - false - - + - - - - adb - - - - 3 - - - 5 - - - 5 - - - 5 - - - 5 - - - - - adb command: - - - adbCommandEdt - - - - - - - devices - - - - - - - - 0 - 0 - - - - execute - - - - - - - - 0 - 0 - - - - terminate - - - - - - - - 0 - 0 - - - - clear - - - - - - - - - - - 0 - 0 - - - - - 0 - 120 - - - - - 16777215 - 120 - - - - Qt::ClickFocus - - - - - - true - - - From 393dc3fda6e2a7ddbe8daf5e79b72528c224b641 Mon Sep 17 00:00:00 2001 From: Barry <870709864@qq.com> Date: Sat, 9 Apr 2022 15:17:58 +0800 Subject: [PATCH 10/14] fix: grab rect dpi error on linux --- QtScrcpy/device/ui/videoform.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/QtScrcpy/device/ui/videoform.cpp b/QtScrcpy/device/ui/videoform.cpp index d6b68277d..7d74b2ce5 100644 --- a/QtScrcpy/device/ui/videoform.cpp +++ b/QtScrcpy/device/ui/videoform.cpp @@ -109,8 +109,8 @@ QRect VideoForm::getGrabCursorRect() #elif defined(Q_OS_LINUX) rc = QRect(ui->keepRatioWidget->mapToGlobal(m_videoWidget->pos()), m_videoWidget->size()); // high dpi support -- taken from the WIN32 section and untested - rc.setTopLeft(rc.topLeft() * m_videoWidget->devicePixelRatio()); - rc.setBottomRight(rc.bottomRight() * m_videoWidget->devicePixelRatio()); + rc.setTopLeft(rc.topLeft() * m_videoWidget->devicePixelRatioF()); + rc.setBottomRight(rc.bottomRight() * m_videoWidget->devicePixelRatioF()); rc.setX(rc.x() + 10); rc.setY(rc.y() + 10); From 6b792dcc1ce6a0b7294b97801304cdf705e6a59c Mon Sep 17 00:00:00 2001 From: Barry <870709864@qq.com> Date: Sat, 9 Apr 2022 15:18:08 +0800 Subject: [PATCH 11/14] docs: update readme --- README.md | 2 +- README_zh.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c9d109789..98713dfe7 100644 --- a/README.md +++ b/README.md @@ -171,7 +171,7 @@ Note: it is not necessary to keep you Android device connected via USB after you - Screen recording - Screenshot to png - Wireless connection -- Supports up to 16 device connections (the number can be higher if your PC performance allows. You need to compile it by yourself) +- Supports multiple device connections - Full-screen display - Display on the top - Install apk: drag and drop apk to the video window to install diff --git a/README_zh.md b/README_zh.md index d71e7e97e..eda914c8b 100644 --- a/README_zh.md +++ b/README_zh.md @@ -173,7 +173,7 @@ Mac OS平台,你可以直接使用我编译好的可执行程序: - 屏幕录制 - 截图为png - 无线连接 -- 最多支持16台设备连接(PC性能允许的情况下可以增加,需要自己编译) +- 支持多台设备连接 - 全屏显示 - 窗口置顶 - 安装apk:拖拽apk到视频窗口即可安装 From 7e781f46ae361803164003738ef72f1449f7e453 Mon Sep 17 00:00:00 2001 From: Barry <870709864@qq.com> Date: Sat, 9 Apr 2022 16:28:47 +0800 Subject: [PATCH 12/14] feat: good ui --- QtScrcpy/dialog.cpp | 12 +++--------- QtScrcpy/dialog.ui | 47 ++++++++++++++++++++++++--------------------- QtScrcpy/main.cpp | 1 + 3 files changed, 29 insertions(+), 31 deletions(-) diff --git a/QtScrcpy/dialog.cpp b/QtScrcpy/dialog.cpp index 978f936e2..1651e1f1e 100644 --- a/QtScrcpy/dialog.cpp +++ b/QtScrcpy/dialog.cpp @@ -593,19 +593,13 @@ void Dialog::on_updateNameBtn_clicked() void Dialog::on_useSingleModeCheck_clicked() { if (ui->useSingleModeCheck->isChecked()) { - ui->configGroupBox->hide(); - ui->adbGroupBox->hide(); - ui->wirelessGroupBox->hide(); - ui->usbGroupBox->hide(); + ui->rightWidget->hide(); } else { - ui->configGroupBox->show(); - ui->adbGroupBox->show(); - ui->wirelessGroupBox->show(); - ui->usbGroupBox->show(); + ui->rightWidget->show(); } QTimer::singleShot(0, this, [this]() { - resize(width(), layout()->sizeHint().height()); + resize(layout()->sizeHint().width(), height()); }); } diff --git a/QtScrcpy/dialog.ui b/QtScrcpy/dialog.ui index 2575feafa..1e5c8290f 100644 --- a/QtScrcpy/dialog.ui +++ b/QtScrcpy/dialog.ui @@ -6,7 +6,7 @@ 0 0 - 1105 + 1293 419 @@ -38,11 +38,14 @@ - + 0 0 + + + Use Simple Mode @@ -71,7 +74,7 @@ - + 0 0 @@ -84,7 +87,7 @@ - + 0 0 @@ -125,7 +128,7 @@ - + 0 0 @@ -152,7 +155,7 @@ - + 0 0 @@ -168,7 +171,7 @@ - + 0 0 @@ -181,7 +184,7 @@ - + 0 0 @@ -194,7 +197,7 @@ - + 0 0 @@ -207,7 +210,7 @@ - + 0 0 @@ -245,7 +248,7 @@ - + 0 0 @@ -302,7 +305,7 @@ - + 0 0 @@ -328,7 +331,7 @@ - + 0 0 @@ -354,7 +357,7 @@ - + 0 0 @@ -404,7 +407,7 @@ - + 0 0 @@ -427,7 +430,7 @@ - + 0 0 @@ -490,7 +493,7 @@ - + 0 0 @@ -543,7 +546,7 @@ - + 0 0 @@ -749,7 +752,7 @@ - + 0 0 @@ -971,7 +974,7 @@ - + 0 0 @@ -990,7 +993,7 @@ - + 0 0 @@ -1003,7 +1006,7 @@ - + 0 0 diff --git a/QtScrcpy/main.cpp b/QtScrcpy/main.cpp index 31b501d0e..f93fd1951 100644 --- a/QtScrcpy/main.cpp +++ b/QtScrcpy/main.cpp @@ -135,6 +135,7 @@ void installTranslator() case QLocale::English: default: languagePath += "en_US.qm"; + break; } translator.load(languagePath); From 3f15d1292df9fa558344e1d156c9078e39b50ba7 Mon Sep 17 00:00:00 2001 From: Barry <870709864@qq.com> Date: Sat, 9 Apr 2022 17:19:41 +0800 Subject: [PATCH 13/14] fix: cant not open screen bug --- QtScrcpy/device/ui/toolform.cpp | 9 +++++++++ QtScrcpy/device/ui/toolform.h | 2 ++ QtScrcpy/device/ui/toolform.ui | 10 ++++++++++ 3 files changed, 21 insertions(+) diff --git a/QtScrcpy/device/ui/toolform.cpp b/QtScrcpy/device/ui/toolform.cpp index 52c898cc5..31551294b 100644 --- a/QtScrcpy/device/ui/toolform.cpp +++ b/QtScrcpy/device/ui/toolform.cpp @@ -41,6 +41,7 @@ void ToolForm::initStyle() IconHelper::Instance()->SetIcon(ui->appSwitchBtn, QChar(0xf24d), 15); IconHelper::Instance()->SetIcon(ui->volumeUpBtn, QChar(0xf028), 15); IconHelper::Instance()->SetIcon(ui->volumeDownBtn, QChar(0xf027), 15); + IconHelper::Instance()->SetIcon(ui->openScreenBtn, QChar(0xf06e), 15); IconHelper::Instance()->SetIcon(ui->closeScreenBtn, QChar(0xf070), 15); IconHelper::Instance()->SetIcon(ui->powerBtn, QChar(0xf011), 15); IconHelper::Instance()->SetIcon(ui->expandNotifyBtn, QChar(0xf103), 15); @@ -220,3 +221,11 @@ void ToolForm::onControlStateChange(Device *device, Device::GroupControlState ol Q_UNUSED(newState) updateGroupControl(); } + +void ToolForm::on_openScreenBtn_clicked() +{ + if (!m_device) { + return; + } + emit m_device->setScreenPowerMode(ControlMsg::SPM_NORMAL); +} diff --git a/QtScrcpy/device/ui/toolform.h b/QtScrcpy/device/ui/toolform.h index 19164fed9..5762a3456 100644 --- a/QtScrcpy/device/ui/toolform.h +++ b/QtScrcpy/device/ui/toolform.h @@ -48,6 +48,8 @@ private slots: void onControlStateChange(Device *device, Device::GroupControlState oldState, Device::GroupControlState newState); + void on_openScreenBtn_clicked(); + private: void initStyle(); void updateGroupControl(); diff --git a/QtScrcpy/device/ui/toolform.ui b/QtScrcpy/device/ui/toolform.ui index 77a2a0ec3..cabb9e9b0 100644 --- a/QtScrcpy/device/ui/toolform.ui +++ b/QtScrcpy/device/ui/toolform.ui @@ -70,6 +70,16 @@ + + + + open screen + + + + + + From 816ae74672ee11dc4be0286a4372d3145e33bcc7 Mon Sep 17 00:00:00 2001 From: Barry <870709864@qq.com> Date: Sat, 9 Apr 2022 17:30:46 +0800 Subject: [PATCH 14/14] feat: update language --- QtScrcpy/res/i18n/en_US.qm | Bin 4507 -> 4577 bytes QtScrcpy/res/i18n/en_US.ts | 4 ++++ QtScrcpy/res/i18n/zh_CN.qm | Bin 3828 -> 3884 bytes QtScrcpy/res/i18n/zh_CN.ts | 4 ++++ docs/TODO.md | 5 +++-- 5 files changed, 11 insertions(+), 2 deletions(-) diff --git a/QtScrcpy/res/i18n/en_US.qm b/QtScrcpy/res/i18n/en_US.qm index aeb1d2f7a16183ea1df3d517bfc422377baa274a..65c81258e88d636dfcefe1dd3e5a5ec05f8bda0c 100644 GIT binary patch delta 117 zcmV-*0E+*cBjF>E9svlEA1?u*kxw214hNBMKMCOj!wR4P01qFLw{98^GY71VxBvhQ zc?aey;s5{(0|)Hqz5oCX$&)t$hXG=fzX2}+SCj7nGy$%&Bm&J12^Iiv0B`_h0B(~| X3Kt9uZ*XO9Aai4KWo2%&-w(V2Aetl{ delta 82 zcmV-Y0ImPwBby_T9svN6A1?u7kxw214at#jKMA7)!wR4P01n}iw{8**^#`ntxBvhQ oc?aey;s5{(1Cu`ihXEv$#{n+^8I$(`Gy!n4ECS69vo{c`0Xte5)c^nh diff --git a/QtScrcpy/res/i18n/en_US.ts b/QtScrcpy/res/i18n/en_US.ts index 432a4c3f3..213c7b0ef 100644 --- a/QtScrcpy/res/i18n/en_US.ts +++ b/QtScrcpy/res/i18n/en_US.ts @@ -376,6 +376,10 @@ You can download it at the following address: screen shot screen shot + + open screen + open screen + VideoForm diff --git a/QtScrcpy/res/i18n/zh_CN.qm b/QtScrcpy/res/i18n/zh_CN.qm index 3f1615160ad1a5e78e70e5a98807f7ea66584b4b..0e05298ed075ba96acd1d382fa72728e9ce3c1ba 100644 GIT binary patch delta 126 zcmew&yGCw;9HYQQc|9f`y@~$vj9Vw>+Y2T$A2?{mz`$9=e3)wi0|U>*iTm>k$J3Mscreen shot 截图 + + open screen + 打开屏幕 + VideoForm diff --git a/docs/TODO.md b/docs/TODO.md index 8447d77c9..fc090d6e5 100644 --- a/docs/TODO.md +++ b/docs/TODO.md @@ -1,5 +1,3 @@ -最后同步scrcpy 08baaf4b575aef7ee56d14683be3f4e3a86d39aa - # TODO ## 低优先级 - text转换 https://github.com/Genymobile/scrcpy/commit/c916af0984f72a60301d13fa8ef9a85112f54202?tdsourcetag=s_pctim_aiomsg @@ -24,6 +22,9 @@ ## ffmpeg [ffmpeg编译参数详解](https://www.cnblogs.com/wainiwann/p/4204230.html) +## fontawesome +[fontawesome 在线搜索](http://www.fontawesome.com.cn/cheatsheet/) + ## adb 以下是 ADB 和 Fastboot 的谷歌官方下载链接: