mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-04-20 03:25:02 +00:00
解决decoder退出
This commit is contained in:
parent
54e3e0d4eb
commit
effb3387ea
4 changed files with 37 additions and 8 deletions
|
@ -44,16 +44,37 @@ qint32 Decoder::recvData(quint8* buf, qint32 bufSize)
|
|||
return 0;
|
||||
}
|
||||
if (m_deviceSocket) {
|
||||
while (m_deviceSocket->bytesAvailable() < bufSize) {
|
||||
m_deviceSocket->waitForReadyRead();
|
||||
while (!m_quit && m_deviceSocket->bytesAvailable() < bufSize) {
|
||||
if (!m_deviceSocket->waitForReadyRead(300)
|
||||
&& QTcpSocket::SocketTimeoutError != m_deviceSocket->error()) {
|
||||
break;
|
||||
}
|
||||
if (QTcpSocket::SocketTimeoutError == m_deviceSocket->error()) {
|
||||
qDebug() << "QTcpSocket::SocketTimeoutError";
|
||||
}
|
||||
}
|
||||
qint64 a = m_deviceSocket->read((char*)buf, bufSize);
|
||||
qDebug() << "++++++++++recv data " << a;
|
||||
return a;
|
||||
qDebug() << "recv data " << bufSize;
|
||||
return m_deviceSocket->read((char*)buf, bufSize);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Decoder::startDecode()
|
||||
{
|
||||
if (!m_deviceSocket) {
|
||||
return false;
|
||||
}
|
||||
m_quit = false;
|
||||
start();
|
||||
return true;
|
||||
}
|
||||
|
||||
void Decoder::stopDecode()
|
||||
{
|
||||
m_quit = true;
|
||||
wait();
|
||||
}
|
||||
|
||||
void Decoder::run()
|
||||
{
|
||||
unsigned char *decoderBuffer = Q_NULLPTR;
|
||||
|
@ -123,7 +144,7 @@ void Decoder::run()
|
|||
packet.data = Q_NULLPTR;
|
||||
packet.size = 0;
|
||||
|
||||
while (!av_read_frame(formatCtx, &packet)) {
|
||||
while (!m_quit && !av_read_frame(formatCtx, &packet)) {
|
||||
// the new decoding/encoding API has been introduced by:
|
||||
// <http://git.videolan.org/?p=ffmpeg.git;a=commitdiff;h=7fc329e2dd6226dfecaa4a1d7adf353bf2773726>
|
||||
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 37, 0)
|
||||
|
@ -180,5 +201,10 @@ runQuit:
|
|||
if (codecCtx) {
|
||||
avcodec_free_context(&codecCtx);
|
||||
}
|
||||
|
||||
if (m_deviceSocket) {
|
||||
m_deviceSocket->disconnectFromHost();
|
||||
delete m_deviceSocket;
|
||||
}
|
||||
//notify_stopped();
|
||||
}
|
||||
|
|
|
@ -23,12 +23,15 @@ public:
|
|||
|
||||
void setDeviceSocket(QTcpSocket* deviceSocket);
|
||||
qint32 recvData(quint8* buf, qint32 bufSize);
|
||||
bool startDecode();
|
||||
void stopDecode();
|
||||
|
||||
protected:
|
||||
void run();
|
||||
|
||||
private:
|
||||
QPointer<QTcpSocket> m_deviceSocket = Q_NULLPTR;
|
||||
bool m_quit = false;
|
||||
};
|
||||
|
||||
#endif // DECODER_H
|
||||
|
|
|
@ -20,7 +20,7 @@ Dialog::Dialog(QWidget *parent) :
|
|||
connect(server, &Server::connectToResult, this, [this](bool success){
|
||||
if (success) {
|
||||
decoder.setDeviceSocket(server->getDeviceSocketByThread(&decoder));
|
||||
decoder.start();
|
||||
decoder.startDecode();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -48,5 +48,6 @@ void Dialog::on_startServerBtn_clicked()
|
|||
|
||||
void Dialog::on_stopServerBtn_clicked()
|
||||
{
|
||||
decoder.stopDecode();
|
||||
server->stop();
|
||||
}
|
||||
|
|
|
@ -253,7 +253,6 @@ void Server::stop()
|
|||
m_serverCopiedToDevice = false;
|
||||
}
|
||||
m_serverSocket.close();
|
||||
qDebug() << "current thread"<< QThread::currentThread();
|
||||
if (m_deviceSocket) {
|
||||
m_deviceSocket->close();
|
||||
m_deviceSocket->deleteLater();
|
||||
|
|
Loading…
Add table
Reference in a new issue