From d95a1fb5d7cf50286b6a89de2941f6cd0dd1983d Mon Sep 17 00:00:00 2001 From: Barry <870709864@qq.com> Date: Thu, 22 Nov 2018 23:08:09 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A1=AE=E4=BF=9DDeviceSocket=20subThreadRecvD?= =?UTF-8?q?ata=E4=B8=8D=E5=9C=A8=E4=B8=BB=E7=BA=BF=E7=A8=8B=E8=B0=83?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- QtScrcpy/decoder/decoder.cpp | 2 +- QtScrcpy/server/devicesocket.cpp | 5 ++++- QtScrcpy/server/devicesocket.h | 8 +++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/QtScrcpy/decoder/decoder.cpp b/QtScrcpy/decoder/decoder.cpp index aabd391..29912fd 100644 --- a/QtScrcpy/decoder/decoder.cpp +++ b/QtScrcpy/decoder/decoder.cpp @@ -57,7 +57,7 @@ qint32 Decoder::recvData(quint8* buf, qint32 bufSize) return 0; } if (m_deviceSocket) { - qint32 len = m_deviceSocket->recvData(buf, bufSize); + qint32 len = m_deviceSocket->subThreadRecvData(buf, bufSize); if (len == -1) { return AVERROR(errno); } diff --git a/QtScrcpy/server/devicesocket.cpp b/QtScrcpy/server/devicesocket.cpp index ebc3518..cac5bd4 100644 --- a/QtScrcpy/server/devicesocket.cpp +++ b/QtScrcpy/server/devicesocket.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "qscrcpyevent.h" @@ -16,8 +17,10 @@ DeviceSocket::~DeviceSocket() quitNotify(); } -qint32 DeviceSocket::recvData(quint8 *buf, qint32 bufSize) +qint32 DeviceSocket::subThreadRecvData(quint8 *buf, qint32 bufSize) { + // this function cant call in main thread + Q_ASSERT(QCoreApplication::instance()->thread() != QThread::currentThread()); if (m_quit) { return 0; } diff --git a/QtScrcpy/server/devicesocket.h b/QtScrcpy/server/devicesocket.h index 87dcd2d..b7a303c 100644 --- a/QtScrcpy/server/devicesocket.h +++ b/QtScrcpy/server/devicesocket.h @@ -13,16 +13,14 @@ public: explicit DeviceSocket(QObject *parent = nullptr); virtual ~DeviceSocket(); - qint32 recvData(quint8* buf, qint32 bufSize); + qint32 subThreadRecvData(quint8* buf, qint32 bufSize); protected: bool event(QEvent *event); -public slots: - void quitNotify(); - protected slots: - void onReadyRead(); + void onReadyRead(); + void quitNotify(); private: QMutex m_mutex;