So a CPU is at 100% keeping up with displaying 10,368,000 bytes each second. Are you sure you are only doing the work you think you are? For example are you displaying only when you have a full frame to display and not every time a UDP packet arrives? Are you sure that receiving and assembling the UDP packets is not the bottleneck?
The crude example below sits on 34% (Intel(R) Core(TM)2 CPU 6400 @ 2.13GHz Linux) unless I generate a new page of static every frame using the inefficient method you see. If I display the same static frame every time the CPU is about 7%.
#include <cstdlib>
#include <QtGui>
#include <QDebug>
{
Q_OBJECT
public:
setCentralWidget(l);
frame = 0;
connect(t, SIGNAL(timeout()), this, SLOT(update()));
t->start(33); // 30 times per second
}
public slots:
void update() {
// create a fake frame of video every second frame
if (frame % 2 == 0) {
raw.clear();
for (int i = 0; i < 720 * 480; i++)
raw.append( rand() % 256 );
}
frame++;
pgm.clear();
pgm.append("P5 720 480 255\n");
pgm.append(raw);
bool ok = p.loadFromData(pgm, "ppm");
l->setPixmap(p);
};
private:
int frame;
};
int main(int argc, char *argv[])
{
mainwindow m;
m.show();
return app.exec();
}
#include "main.moc"
#include <cstdlib>
#include <QtGui>
#include <QDebug>
class mainwindow: public QMainWindow
{
Q_OBJECT
public:
mainwindow(QWidget *p = 0): QMainWindow(p) {
l = new QLabel(this);
setCentralWidget(l);
frame = 0;
QTimer *t = new QTimer(this);
connect(t, SIGNAL(timeout()), this, SLOT(update()));
t->start(33); // 30 times per second
}
public slots:
void update() {
// create a fake frame of video every second frame
if (frame % 2 == 0) {
raw.clear();
for (int i = 0; i < 720 * 480; i++)
raw.append( rand() % 256 );
}
frame++;
pgm.clear();
pgm.append("P5 720 480 255\n");
pgm.append(raw);
QPixmap p;
bool ok = p.loadFromData(pgm, "ppm");
l->setPixmap(p);
};
private:
QLabel *l;
QByteArray raw;
QByteArray pgm;
int frame;
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
mainwindow m;
m.show();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks