I have been trying to write a simple VNC viewer which requests for framebuffer updates every 30ms on a nvidia Tegra K1 board.
// Data to be sent to the X11VNC server for requesting updates for 800x480 region.
unsigned char updateReqBuffer[] = {0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x03, 0x20, 0x01, 0xE0};
/**************************/
//Requesting for frames
while(isConnected) // Runnning on a thread
{
if(sockfd != -1) // sockfd is the x11vnc port(5900)
send(sockfd, updateReqBuffer, 10, 0);
usleep(30000);
}
/**************************/
//Receiving framebuffer updates
while(isConnected) // Runnning on a thread
{
// Read data from X11
n = recv(sockfd, recvline, MAXLINE,0);
if(n>0)
{
sentSize += n;
gettimeofday(&tmnow0, NULL);
timeinfo0 = localtime (&tmnow0.tv_sec);
strftime(buf0,30,"%Y:%m:%dT%H:%M:%S", timeinfo0);
sprintf(usec_buf0,"%d",(int)(tmnow0.tv_usec / 1000));
strcat(buf0, ".");
strcat(buf0,usec_buf0);
printf("Update received. Size: %d, TIME: %s\n", n, buf0);
}
}
I am able to receive the data. But I notice that there is a considerable lag of more than 100ms between each frame update which lowers the overall number of frames per second. Packet size of 4
marks the start of an frame.
Update received. Size: 4, TIME: 2017:09:08T14:45:53.543 //START OF FRAME
Update received. Size: 16304, TIME: 2017:09:08T14:45:53.544
Update received. Size: 16366, TIME: 2017:09:08T14:45:53.546
Update received. Size: 16, TIME: 2017:09:08T14:45:53.548
Update received. Size: 36738, TIME: 2017:09:08T14:45:53.548
Update received. Size: 15576, TIME: 2017:09:08T14:45:53.549
Update received. Size: 8854, TIME: 2017:09:08T14:45:53.549
Update received. Size: 6808, TIME: 2017:09:08T14:45:53.550
Update received. Size: 14691, TIME: 2017:09:08T14:45:53.551
Update received. Size: 8750, TIME: 2017:09:08T14:45:53.552
Update received. Size: 20602, TIME: 2017:09:08T14:45:53.553
Update received. Size: 4, TIME: 2017:09:08T14:45:53.662 //START OF FRAME
Update received. Size: 8881, TIME: 2017:09:08T14:45:53.663
Update received. Size: 2040, TIME: 2017:09:08T14:45:53.663
Update received. Size: 1052, TIME: 2017:09:08T14:45:53.663
Update received. Size: 15913, TIME: 2017:09:08T14:45:53.664
Update received. Size: 2055, TIME: 2017:09:08T14:45:53.665
Update received. Size: 1026, TIME: 2017:09:08T14:45:53.666
Update received. Size: 4496, TIME: 2017:09:08T14:45:53.669
Update received. Size: 6931, TIME: 2017:09:08T14:45:53.669
Update received. Size: 4, TIME: 2017:09:08T14:45:53.831 //START OF FRAME
This data was taken when a video was being playing in full screen mode.
Q1: Since I am requesting for updates every 30ms, shouldn't X11VNC be sending me updates as soon as possible? Why is there a 100ms lag between every update?
X11perf tests give the following data
ubuntu@tegra-ubuntu:~$ x11perf -getimage500 -shmget500
x11perf - X11 performance program, version 1.2
The X.Org Foundation server version 11501000 on :0
from tegra-ubuntu
Fri Sep 8 13:03:41 2017
Sync time adjustment is 0.1022 msecs.
8000 reps @ 1.1794 msec ( 848.0/sec): ShmGetImage 500x500 square
8000 reps @ 1.2038 msec ( 831.0/sec): ShmGetImage 500x500 square
8000 reps @ 1.2407 msec ( 806.0/sec): ShmGetImage 500x500 square
8000 reps @ 1.2027 msec ( 831.0/sec): ShmGetImage 500x500 square
8000 reps @ 1.1765 msec ( 850.0/sec): ShmGetImage 500x500 square
40000 trep @ 1.2006 msec ( 833.0/sec): ShmGetImage 500x500 square
1200 reps @ 5.0762 msec ( 197.0/sec): GetImage 500x500 square
1200 reps @ 5.0227 msec ( 199.0/sec): GetImage 500x500 square
1200 reps @ 5.0323 msec ( 199.0/sec): GetImage 500x500 square
1200 reps @ 5.0528 msec ( 198.0/sec): GetImage 500x500 square
1200 reps @ 5.0278 msec ( 199.0/sec): GetImage 500x500 square
6000 trep @ 5.0424 msec ( 198.0/sec): GetImage 500x500 square
Q2: Am I wrong in assuming that X11VNC is more than capable enough of retrieving and sending framebuffer updates than what I am getting from the above results? If so how do I interpret these results?