Edit: I am not getting enough response for this question may be i am not able to explain properly. Let i try to explain background to this question.
Every screen sharing program there are two parties. Server and Viewer.
Server
Role of server
- capture desktop screen
- compare capture screen with previous sent screen
- calculate dirty region convert dirty region to byte array
- send byte array to tcp socket to viewer
Viewer
Role of Viewer
- receive bytes from server
- convert bytes to image
- Draw image to viewer picturebox/Panel
Problem to tackle
- There are many duplicate region/area server sends which is previously sent to viewer 10/20 frames back.I want to avoid this using hashing.
Below is my analysis
I am studying how screen transfer application like Team Viewer,Any desk works and identifying How they works well in very low bandwidth internet connection.
While studying i came across with Screen sharing app Any Desk. Which use xxHash to hash images and send image byte data along with his hash code.
I used network speed monitor on my mobile internet and started application.
I obverse that performing same activity (e.g open/close same directory,minimize and maximize any application) on desktop multiple times. app does not send any data/Regions to client except first request. I assume that it sends only hash code to client if it finds duplicate image/Dirty Region hash code.
My question is how feasible this method, because on client side. we need to store hashcode along with image bytedata in memory.How this apps are memory efficient. or is there any other way they doing it.
Edit
Screen sharing program does not send whole screen/Region each time.it just send only difference/Dirty reigon over the internet.along with if user has very bad internet connection it stores bytearray of each frame/Region along with hashcode.Send only hashcode if hascode matches with difference frame/region bytearray
Server Code assumption
List<uint> hashlist = new List<uint>();
byte[] imagesBytestosend = GetImageBytes();
uint hash = XXHash.XXH32(imagesBytestosend);
if (!hashlist.Contains(hash))
{
hashlist.Add(hash);
SendAllBytesData(imagesBytestosend);
}
else
{
SendOnlyHasCode(hash);
}
Client Code assumption
Dictionary<uint, byte[]> frameData = new Dictionary<uint, byte[]>();
bytes[] imageBytes = null;
if(frameData.ContainsKey(receivedHash))
{
imageBytes=frameData[receivedHash];
}
else
{
imageBytes=receivedBytes;;
frameData.Add(receivedHash, receivedBytes);
//My Question is how this is memory efficient to store frame bytes with his hash code in memory
}
DrawToPictureBox(imageBytes);