修复卡顿问题(recv接收数据方式不对)

This commit is contained in:
Barry 2018-10-28 12:21:31 +08:00
parent fe79ff1dad
commit ff10e0e376
4 changed files with 55 additions and 15 deletions

View file

@ -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 \

View file

@ -1,4 +1,5 @@
#include <QDebug>
#include <QTime>
#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();
}

View file

@ -1,3 +1,6 @@
#include <QFile>
#include <QTime>
#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:"<<t_frameWidth<<t_frameHeight<<"||"<<t_yPerRowBytes<<t_uPerRowBytes<<t_vPerRowBytes;
QFile t_file("E:\\receive_Frame.yuv");
t_file.open(QIODevice::WriteOnly | QIODevice::Append);
//t_file.write((char *)pFrame->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);
/*

View file

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>924</width>
<height>365</height>
<width>1309</width>
<height>707</height>
</rect>
</property>
<property name="windowTitle">
@ -57,8 +57,8 @@
<rect>
<x>230</x>
<y>20</y>
<width>651</width>
<height>301</height>
<width>1051</width>
<height>621</height>
</rect>
</property>
<property name="styleSheet">