Image render optimization question
Added by Tom Puckett over 11 years ago
I would like to understand how to get the fastest possible effective frame rate when performing continuous image updates as described below. There is some network traffic that seems unnecessary and I wonder if I can get Wt to avoid it. ¶
During session initialization:
mpTheImage = new WImage(WLink(), "alternate text", root());
mpTheImage->setId("IMIImage");
...
mpTheImage->imageLoaded().connect(this, &ImageDisplayApp::HandleImageRequest);
The handler ImageDisplayApp::HandleImageRequest() renders the next frame's pixels and then:
WLink vLink.setResource(mpImageResource); // mpImageResource points to a WMemoryResource in heap
mpTheImage->setImageLink(vLink);
mpTheImage->refresh();
After the first frame is rendered, I see on the network that the onload event causes a POST command from the browser, a server response, and then a GET for the image resource. This means 2 round trips for each frame. Can this be avoided, perhaps by getting the imageLoaded event to issue a GET directly, or maybe a POST for the image resource directly without an intermediate step?
If standard Wt steps can't do this, do you have support for sockets so I could implement my own streamlined protocol?
Thanks for helping.
Replies (1)
RE: Image render optimization question - Added by Koen Deforche over 11 years ago
Hey,
You have two options:
1) you can connect a JavaScript function to the imageLoaded() signal, which immediately updates the URL.
e.g.:
mpTheImage->imageLoaded().connect("function(o) { o.src='next.png'; }");
2) you can base64-encode the image in the URL
e.g.
vLink.setUrl('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA
AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
9TXL0Y4OHwAAAABJRU5ErkJggg==');
Wt has a utility function to perform such base64-encoding: Wt::Utils::base64Encode()
Note that in older (mostly IE) browsers there are limitations to the size of the URL.
Regards,
koen