diff --git a/src/QtScrcpy.pro b/src/QtScrcpy.pro index a7f34ff..d95bc6a 100644 --- a/src/QtScrcpy.pro +++ b/src/QtScrcpy.pro @@ -23,6 +23,7 @@ DEFINES += QT_DEPRECATED_WARNINGS # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 +#DEFINES += SKIP_FRAMES SOURCES += \ main.cpp \ diff --git a/src/decoder.cpp b/src/decoder.cpp index 1d86885..893fa65 100644 --- a/src/decoder.cpp +++ b/src/decoder.cpp @@ -1,4 +1,5 @@ #include +#include #include "decoder.h" #include "frames.h" @@ -55,18 +56,17 @@ qint32 Decoder::recvData(quint8* buf, qint32 bufSize) return 0; } if (m_deviceSocket) { - while (!m_quit && m_deviceSocket->bytesAvailable() < bufSize) { + while (!m_quit && m_deviceSocket->bytesAvailable() <= 0) { if (!m_deviceSocket->waitForReadyRead(300) && QTcpSocket::SocketTimeoutError != m_deviceSocket->error()) { - break; - } - if (QTcpSocket::SocketTimeoutError == m_deviceSocket->error()) { - //qDebug() << "QTcpSocket::SocketTimeoutError"; + qDebug() << "waitForReadyRead error " << m_deviceSocket->error(); + break; } } - qDebug() << "recv data " << bufSize; - return m_deviceSocket->read((char*)buf, bufSize); - } + qint64 readSize = qMin(m_deviceSocket->bytesAvailable(), (qint64)bufSize); + qDebug() << "ready recv data " << readSize; + return m_deviceSocket->read((char*)buf, readSize); + } return 0; } @@ -165,7 +165,7 @@ void Decoder::run() } if (decodingFrame) { ret = avcodec_receive_frame(codecCtx, decodingFrame); - } + } if (!ret) { // a frame was received pushFrame(); @@ -252,5 +252,6 @@ void Decoder::pushFrame() // the previous newFrame will consume this frame return; } + //qDebug() << "------------>" << QTime::currentTime(); emit newFrame(); } diff --git a/src/dialog.cpp b/src/dialog.cpp index e4e3187..4c2f76b 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -1,3 +1,6 @@ +#include +#include + #include "dialog.h" #include "ui_dialog.h" #include "adbprocess.h" @@ -5,7 +8,40 @@ #include "glyuvwidget.h" #include "yuvglwidget.h" -//#define OPENGL_PLAN2 +#define OPENGL_PLAN2 + +void saveAVFrame_YUV_ToTempFile(const AVFrame *pFrame) +{ + int t_frameWidth = pFrame->width; + int t_frameHeight = pFrame->height; + int t_yPerRowBytes = pFrame->linesize[0]; + int t_uPerRowBytes = pFrame->linesize[1]; + int t_vPerRowBytes = pFrame->linesize[2]; + qDebug()<<"robin:saveAVFrame_YUV_ToTempFile info:"<data[0],t_frameWidth * t_frameHeight); + //t_file.write((char *)pFrame->data[1],(t_frameWidth/2) * t_frameHeight / 2); + //t_file.write((char *)pFrame->data[2],(t_frameWidth/2) * t_frameHeight / 2); + + for(int i = 0;i< t_frameHeight ;i++) + { + t_file.write((char*)(pFrame->data[0]+i*t_yPerRowBytes),t_frameWidth); + } + + for(int i = 0;i< t_frameHeight/2 ;i++) + { + t_file.write((char*)(pFrame->data[1]+i*t_uPerRowBytes),t_frameWidth/2); + } + + for(int i = 0;i< t_frameHeight/2 ;i++) + { + t_file.write((char*)(pFrame->data[2]+i*t_vPerRowBytes),t_frameWidth/2); + } + + t_file.flush(); + +} Dialog::Dialog(QWidget *parent) : QDialog(parent), @@ -47,12 +83,14 @@ Dialog::Dialog(QWidget *parent) : QObject::connect(&decoder, &Decoder::newFrame, this, [this](){ frames.lock(); const AVFrame *frame = frames.consumeRenderedFrame(); + //saveAVFrame_YUV_ToTempFile(frame); #ifdef OPENGL_PLAN2 w2->setFrameSize(frame->width, frame->height); w2->setYPixels(frame->data[0], frame->linesize[0]); w2->setUPixels(frame->data[1], frame->linesize[1]); w2->setVPixels(frame->data[2], frame->linesize[2]); - w2->update(); + //w2->update(); + w2->repaint(); #else w->setVideoSize(frame->width, frame->height); /* diff --git a/src/dialog.ui b/src/dialog.ui index bf3d1c0..f0b2ec8 100644 --- a/src/dialog.ui +++ b/src/dialog.ui @@ -6,8 +6,8 @@ 0 0 - 924 - 365 + 1309 + 707 @@ -57,8 +57,8 @@ 230 20 - 651 - 301 + 1051 + 621