
Originally Posted by
anda_skoa
Are you sure that the reading makes it slow, not the processing of the data? I.e. have you tried without processing the read data?
Cheers,
_
I tested the executable without processing the read data. it is fast:
while(sum > 0)
{
if(udpsocket->pendingDatagramSize() == -1){
// usleep(1000);
continue;
}
datagram.resize(udpsocket->pendingDatagramSize());
//qDebug() << "udp:" << udpsocket->pendingDatagramSize();
udpsocket->readDatagram(datagram.data(), datagram.size(), host, &myPort);
sumPacket.append(datagram);
sum -= datagram.size();
qDebug() << loop;
loop++;
}
if(sum == 0)
emit dataReceivedClientImage(sumPacket);
while(sum > 0)
{
QByteArray datagram;
if(udpsocket->pendingDatagramSize() == -1){
// usleep(1000);
continue;
}
datagram.resize(udpsocket->pendingDatagramSize());
//qDebug() << "udp:" << udpsocket->pendingDatagramSize();
udpsocket->readDatagram(datagram.data(), datagram.size(), host, &myPort);
sumPacket.append(datagram);
sum -= datagram.size();
qDebug() << loop;
loop++;
}
if(sum == 0)
emit dataReceivedClientImage(sumPacket);
To copy to clipboard, switch view to plain text mode
However, when it processes the data, it falls behind. That's why in socket read, I cannot read whole packets at one (8 packets), it reads for example 3 packets, pauses a bit and continues receiving the rest. This processing of data is inside the glWidget class:
void GlWidget
::createTextureFromBitmap(QByteArray btmp
) {
bytes.clear();
bytes.resize(size * 3 * sizeof(unsigned char));
for(int i = 0, j = 0; i < size*3, j < size; i += 3, j++)
{
bytes[i] = pixelColors[btmp[j]].r;
bytes[i+1] = pixelColors[btmp[j]].g;
bytes[i+2] = pixelColors[btmp[j]].b;
}
updateGL();
qDebug() << "updated..";
void GlWidget::createTextureFromBitmap(QByteArray btmp)
{
bytes.clear();
bytes.resize(size * 3 * sizeof(unsigned char));
for(int i = 0, j = 0; i < size*3, j < size; i += 3, j++)
{
bytes[i] = pixelColors[btmp[j]].r;
bytes[i+1] = pixelColors[btmp[j]].g;
bytes[i+2] = pixelColors[btmp[j]].b;
}
updateGL();
qDebug() << "updated..";
To copy to clipboard, switch view to plain text mode
I need to set rgb values according to the color table and then call updateGL() to render to the screen.
You know, I cannot think of any solution using threads as well, because if even a thread puts the burden of doing the for processing loop on its shoulders, It finally needs to signal glWidget again to call updateGL(), and as far as either of these processings (for loop or updateGL()) slows down the system, a thread might be of no use!
what do you suggest?
Bookmarks