mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Drop video frames when lagging
Aka, all the time. We only drop received frames, we never stop sending
This commit is contained in:
parent
457a54d591
commit
5458b4b3ee
21
core.cpp
21
core.cpp
|
@ -35,11 +35,13 @@ QList<ToxFile> Core::fileRecvQueue;
|
|||
ToxCall Core::calls[TOXAV_MAX_CALLS];
|
||||
const int Core::videobufsize{TOXAV_MAX_VIDEO_WIDTH * TOXAV_MAX_VIDEO_HEIGHT * 4};
|
||||
uint8_t* Core::videobuf;
|
||||
int Core::videoBusyness;
|
||||
|
||||
Core::Core(Camera* cam, QThread *coreThread) :
|
||||
tox(nullptr), camera(cam)
|
||||
{
|
||||
videobuf = new uint8_t[videobufsize];
|
||||
videoBusyness=0;
|
||||
|
||||
toxTimer = new QTimer(this);
|
||||
toxTimer->setSingleShot(true);
|
||||
|
@ -1312,13 +1314,14 @@ void Core::sendCallAudio(int callId, ToxAv* toxav)
|
|||
|
||||
void Core::playCallVideo(ToxAv*, int32_t callId, vpx_image_t* img)
|
||||
{
|
||||
qDebug() << "Core: Got video frame";
|
||||
if (!calls[callId].active || !calls[callId].videoEnabled)
|
||||
return;
|
||||
|
||||
qDebug() << "Core: Got video frame, call's active";
|
||||
|
||||
emit Widget::getInstance()->getCore()->videoFrameReceived(*img);
|
||||
if (videoBusyness >= 2)
|
||||
qWarning() << "Core: playCallVideo: Busy, dropping current frame";
|
||||
else
|
||||
emit Widget::getInstance()->getCore()->videoFrameReceived(img);
|
||||
vpx_img_free(img);
|
||||
}
|
||||
|
||||
void Core::sendCallVideo(int callId)
|
||||
|
@ -1358,3 +1361,13 @@ void Core::createGroup()
|
|||
{
|
||||
emit emptyGroupCreated(tox_add_groupchat(tox));
|
||||
}
|
||||
|
||||
void Core::increaseVideoBusyness()
|
||||
{
|
||||
videoBusyness++;
|
||||
}
|
||||
|
||||
void Core::decreaseVideoBusyness()
|
||||
{
|
||||
videoBusyness--;
|
||||
}
|
||||
|
|
6
core.h
6
core.h
|
@ -122,6 +122,9 @@ public:
|
|||
QString getUsername();
|
||||
QString getStatusMessage();
|
||||
|
||||
void increaseVideoBusyness();
|
||||
void decreaseVideoBusyness();
|
||||
|
||||
public slots:
|
||||
void start();
|
||||
void process();
|
||||
|
@ -223,7 +226,7 @@ signals:
|
|||
void avRequestTimeout(int friendId, int callIndex);
|
||||
void avPeerTimeout(int friendId, int callIndex);
|
||||
|
||||
void videoFrameReceived(vpx_image frame);
|
||||
void videoFrameReceived(vpx_image* frame);
|
||||
|
||||
private:
|
||||
static void onFriendRequest(Tox* tox, const uint8_t* cUserId, const uint8_t* cMessage, uint16_t cMessageSize, void* core);
|
||||
|
@ -289,6 +292,7 @@ private:
|
|||
static const QString CONFIG_FILE_NAME;
|
||||
static const int videobufsize;
|
||||
static uint8_t* videobuf;
|
||||
static int videoBusyness; // Used to know when to drop frames
|
||||
};
|
||||
|
||||
#endif // CORE_HPP
|
||||
|
|
|
@ -15,6 +15,10 @@
|
|||
*/
|
||||
|
||||
#include "netcamview.h"
|
||||
#include "core.h"
|
||||
#include "widget.h"
|
||||
#include <QApplication>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
|
||||
NetCamView::NetCamView(QWidget* parent)
|
||||
: QWidget(parent), displayLabel{new QLabel},
|
||||
|
@ -29,13 +33,28 @@ NetCamView::NetCamView(QWidget* parent)
|
|||
mainLayout->addWidget(displayLabel);
|
||||
}
|
||||
|
||||
void NetCamView::updateDisplay(vpx_image frame)
|
||||
void NetCamView::updateDisplay(vpx_image* frame)
|
||||
{
|
||||
int w = frame.d_w, h = frame.d_h;
|
||||
|
||||
if (!frame.w || !frame.h || !w || !h)
|
||||
if (!frame->w || !frame->h)
|
||||
return;
|
||||
|
||||
Core* core = Widget::getInstance()->getCore();
|
||||
|
||||
core->increaseVideoBusyness();
|
||||
|
||||
QFuture<QImage> future = QtConcurrent::run(convert,*frame);
|
||||
qApp->processEvents();
|
||||
QImage img = future.result();
|
||||
|
||||
vpx_img_free(frame);
|
||||
displayLabel->setPixmap(QPixmap::fromImage(img));
|
||||
|
||||
core->decreaseVideoBusyness();
|
||||
}
|
||||
|
||||
QImage NetCamView::convert(vpx_image& frame)
|
||||
{
|
||||
int w = frame.d_w, h = frame.d_h;
|
||||
int bpl = frame.stride[VPX_PLANE_Y], cxbpl = frame.stride[VPX_PLANE_V];
|
||||
QImage img(w, h, QImage::Format_RGB32);
|
||||
|
||||
|
@ -58,7 +77,5 @@ void NetCamView::updateDisplay(vpx_image frame)
|
|||
scanline[j] = (0xFF<<24) + (R<<16) + (G<<8) + B;
|
||||
}
|
||||
}
|
||||
|
||||
vpx_img_free(&frame);
|
||||
displayLabel->setPixmap(QPixmap::fromImage(img));
|
||||
return img;
|
||||
}
|
||||
|
|
|
@ -35,7 +35,10 @@ public:
|
|||
NetCamView(QWidget *parent=0);
|
||||
|
||||
public slots:
|
||||
void updateDisplay(vpx_image frame);
|
||||
void updateDisplay(vpx_image* frame);
|
||||
|
||||
private:
|
||||
static QImage convert(vpx_image& frame);
|
||||
|
||||
private:
|
||||
QLabel *displayLabel;
|
||||
|
|
Loading…
Reference in New Issue
Block a user