1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-17 00:33:33 +00:00

1. Added KVM Jumbo Support for Linux/FreeBSD/MacOS

2. Added compile switch for Jumbo eenable/disable
3. Updated Linux Mouse Cursor HAshing, so 32-bit and 64-bit interop
4. Updated KVM to fetch initial mouse cursor on connect
This commit is contained in:
Bryan Roe
2020-04-09 22:41:56 -07:00
parent aa48bfe70a
commit 7dd40ff52f
9 changed files with 274 additions and 124 deletions

View File

@@ -469,7 +469,7 @@ pi:
strip meshagent_pi strip meshagent_pi
linux: linux:
$(MAKE) EXENAME="$(EXENAME)_$(ARCHNAME)$(EXENAME2)" AID="$(ARCHID)" ADDITIONALSOURCES="$(LINUXKVMSOURCES)" ADDITIONALFLAGS="-lrt -z noexecstack -z relro -z now" CFLAGS="-DMESH_AGENTID=$(ARCHID) $(CFLAGS) $(CEXTRA)" LDFLAGS="$(LINUXSSL) $(LINUXFLAGS) $(LDFLAGS) $(LDEXTRA)" $(MAKE) EXENAME="$(EXENAME)_$(ARCHNAME)$(EXENAME2)" AID="$(ARCHID)" ADDITIONALSOURCES="$(LINUXKVMSOURCES)" ADDITIONALFLAGS="-lrt -z noexecstack -z relro -z now" CFLAGS="-DJPEGMAXBUF=0 -DMESH_AGENTID=$(ARCHID) $(CFLAGS) $(CEXTRA)" LDFLAGS="$(LINUXSSL) $(LINUXFLAGS) $(LDFLAGS) $(LDEXTRA)"
$(SYMBOLCP) $(SYMBOLCP)
$(STRIP) $(STRIP)

View File

@@ -16,6 +16,12 @@ limitations under the License.
#include "linux_compression.h" #include "linux_compression.h"
#if defined(JPEGMAXBUF)
#define MAX_TILE_SIZE JPEGMAXBUF
#else
#define MAX_TILE_SIZE 65500
#endif
unsigned char *jpeg_buffer = NULL; unsigned char *jpeg_buffer = NULL;
int jpeg_buffer_length = 0; int jpeg_buffer_length = 0;
char jpegLastError[JMSG_LENGTH_MAX]; char jpegLastError[JMSG_LENGTH_MAX];
@@ -51,7 +57,9 @@ boolean empty_output_buffer(j_compress_ptr cinfo)
cinfo->dest->next_output_byte = next_output_byte; cinfo->dest->next_output_byte = next_output_byte;
cinfo->dest->free_in_buffer = MAX_BUFFER; cinfo->dest->free_in_buffer = MAX_BUFFER;
if (jpeg_buffer_length > 65500) return FALSE; #if MAX_TILE_SIZE > 0
if ( jpeg_buffer_length > MAX_TILE_SIZE) return FALSE;
#endif
return TRUE; return TRUE;
} }
@@ -61,11 +69,15 @@ void term_destination (j_compress_ptr cinfo)
jpeg_buffer_length += remaining_buff_length; jpeg_buffer_length += remaining_buff_length;
if (jpeg_buffer_length > 65500) { #if MAX_TILE_SIZE > 0
if (jpeg_buffer_length > MAX_TILE_SIZE)
{
free(jpeg_buffer); free(jpeg_buffer);
jpeg_buffer = NULL; jpeg_buffer = NULL;
} }
else { else
#endif
{
jpeg_buffer = (unsigned char *) realloc(jpeg_buffer, jpeg_buffer_length); jpeg_buffer = (unsigned char *) realloc(jpeg_buffer, jpeg_buffer_length);
} }
} }

View File

@@ -142,6 +142,7 @@ typedef struct xfixes_struct
Bool(*XFixesSelectCursorInput)(Display *d, Window w, int i); Bool(*XFixesSelectCursorInput)(Display *d, Window w, int i);
Bool(*XFixesQueryExtension)(Display *d, int *eventbase, int *errorbase); Bool(*XFixesQueryExtension)(Display *d, int *eventbase, int *errorbase);
void*(*XFixesGetCursorImage)(Display *d); void*(*XFixesGetCursorImage)(Display *d);
void*(*XFixesGetCursorImageAndName)(Display *d);
}xfixes_struct; }xfixes_struct;
xfixes_struct *xfixes_exports = NULL; xfixes_struct *xfixes_exports = NULL;
@@ -160,6 +161,102 @@ void kvm_send_error(char *msg)
ILibQueue_UnLock(g_messageQ); ILibQueue_UnLock(g_messageQ);
} }
KVM_MouseCursors kvm_fetch_currentCursor(Display *cursordisplay)
{
// Name was NULL, so as a last ditch effort, lets try to look at the XFixesCursorImage
char *cursor_image = (char*)xfixes_exports->XFixesGetCursorImage(cursordisplay);
KVM_MouseCursors ret = KVM_MouseCursor_HELP;
unsigned short w = ((unsigned short*)(cursor_image + 4))[0];
unsigned short h = ((unsigned short*)(cursor_image + 6))[0];
char *pixels = cursor_image + (sizeof(void*) == 8 ? 24 : 16);
char alpha[65535];
int i;
if ((size_t)(w*h) <= sizeof(alpha))
{
for (i = 0; i < (w*h); ++i)
{
alpha[i] = pixels[(sizeof(void*)==8?(3 + (i * 8)):(3 + (i * 4)))];
}
switch (crc32c(0, (unsigned char*)alpha+6, (uint32_t)((w*h)-6)))
{
case 3911022957: // Ubuntu/Peppermint (Top)
case 315617398: // Ubuntu/Peppermint (Bottom)
case 313635327: // FreeBSD
case 399455764: // openSUSE
case 3867633865: // PuppyLinux (Top)
case 2405141328: // PuppyLinux (Bottom)
case 2017738775: // Raspian/CentOS (Top)
case 1820008802: // Raspian/CentOS (Bottom)
ret = KVM_MouseCursor_SIZENS;
break;
case 1206496159: // Ubuntu (Left)
case 3947249005: // Ubuntu (Right)
case 2065486748: // FreeBSD
case 3817177836: // openSUSE
case 2760825997: // PuppyLinux (Left)
case 222646089: // PuppyLinux (Right)
case 1924105758: // Raspian (Left)
case 18444308: // Raspian (Right)
ret = KVM_MouseCursor_SIZEWE;
break;
case 305612954: // Ubuntu (Bottom Left)
case 1245488815: // Ubuntu (Upper Right)
case 169817074: // FreeBSD + PuppyLinux (Bottom Left)
case 482480649: // FreeBSD + PuppyLinux (Upper Right)
case 1405624986: // openSUSE
case 2989878302: // Raspian (Bottom Left)
case 21344493: // Raspian (Upper Right)
ret = KVM_MouseCursor_SIZENESW;
break;
case 799529566: // Ubuntu (Upper Left)
case 4056118275: // Ubuntu (Bottom Right)
case 2757619196: // FreeBSD + PuppyLinux (Bottom Right)
case 3302778157: // FreeBSD + PuppyLinux (Upper Left)
case 924333740: // openSUSE
case 2843753620: // Raspian (Upper Left)
case 4110212903: // Raspian (Bottom Right)
ret = KVM_MouseCursor_SIZENWSE;
break;
case 2280086639: // Ubuntu
case 920009133: // FreeBSD + PuppyLinux
case 2321998854: // openSUSE
case 926331252: // Raspian
ret = KVM_MouseCursor_SIZEALL;
break;
case 3546300886: // Ubuntu
case 1038978227: // FreeBSD + PuppyLinux + openSUSE
case 4237429080: // Raspian
ret = KVM_MouseCursor_ARROW;
break;
case 1176251007: // Ubuntu
case 3320936845: // FreeBSD
case 795881928: // PuppyLinux
case 134935791: // Raspian
ret = KVM_MouseCursor_IBEAM;
break;
case 3673902152: // Ubuntu
case 27109234: // Raspian
case (uint32_t)-1421461853: // PuppyLinux
ret = KVM_MouseCursor_HAND;
break;
case 3463742778: // Ubuntu
ret = KVM_MouseCursor_WAIT;
break;
default:
break;
}
}
return(ret);
}
void kvm_send_resolution() void kvm_send_resolution()
{ {
char *buffer = (char*)ILibMemory_SmartAllocate(8); char *buffer = (char*)ILibMemory_SmartAllocate(8);
@@ -392,6 +489,7 @@ int kvm_init(int displayNo)
((void**)xfixes_exports)[1] = (void*)dlsym(xfixes_exports->xfixes_lib, "XFixesSelectCursorInput"); ((void**)xfixes_exports)[1] = (void*)dlsym(xfixes_exports->xfixes_lib, "XFixesSelectCursorInput");
((void**)xfixes_exports)[2] = (void*)dlsym(xfixes_exports->xfixes_lib, "XFixesQueryExtension"); ((void**)xfixes_exports)[2] = (void*)dlsym(xfixes_exports->xfixes_lib, "XFixesQueryExtension");
((void**)xfixes_exports)[3] = (void*)dlsym(xfixes_exports->xfixes_lib, "XFixesGetCursorImage"); ((void**)xfixes_exports)[3] = (void*)dlsym(xfixes_exports->xfixes_lib, "XFixesGetCursorImage");
((void**)xfixes_exports)[4] = (void*)dlsym(xfixes_exports->xfixes_lib, "XFixesGetCursorImageAndName");
} }
} }
@@ -839,6 +937,8 @@ void* kvm_server_mainloop(void* parm)
x11_exports->XSync(cursordisplay, 0); // Sync with XServer x11_exports->XSync(cursordisplay, 0); // Sync with XServer
cursor_descriptor = x11_exports->XConnectionNumber(cursordisplay); // Get the FD to use in select cursor_descriptor = x11_exports->XConnectionNumber(cursordisplay); // Get the FD to use in select
} }
curcursor = kvm_fetch_currentCursor(cursordisplay); // Cursor Type
} }
} }
else if (cursor_descriptor > 0) else if (cursor_descriptor > 0)
@@ -899,63 +999,7 @@ void* kvm_server_mainloop(void* parm)
else else
{ {
// Name was NULL, so as a last ditch effort, lets try to look at the XFixesCursorImage // Name was NULL, so as a last ditch effort, lets try to look at the XFixesCursorImage
cursor_image = (char*)xfixes_exports->XFixesGetCursorImage(cursordisplay); curcursor = kvm_fetch_currentCursor(cursordisplay);
if (sizeof(void*) == 8)
{
unsigned short w = ((unsigned short*)(cursor_image + 4))[0];
unsigned short h = ((unsigned short*)(cursor_image + 6))[0];
char *pixels = cursor_image + 24;
char alpha[65535];
int i;
if ((size_t)(w*h) <= sizeof(alpha))
{
for (i = 0; i < (w*h); ++i)
{
alpha[i] = pixels[7 + (i * 8)];
}
switch (crc32c(0, (unsigned char*)alpha, (uint32_t)(w*h)))
{
case 680869104: // FreeBSD
case 503303936: // openSUSE
case 424513050: // PuppyLinux (Top)
case (uint32_t)-1492434837: // PuppyLinux (Bottom)
curcursor = KVM_MouseCursor_SIZENS;
break;
case 1094213267: // FreeBSD
case 723082922: // openSUSE
case 1531198046: // PuppyLinux (Left)
case 622167154: // PuppyLinux (Right)
curcursor = KVM_MouseCursor_SIZEWE;
break;
case 318345513: // FreeBSD + PuppyLinux (Bottom Left)
case 69513426: // FreeBSD + PuppyLinux (Upper Right)
case 152373933: // openSUSE
curcursor = KVM_MouseCursor_SIZENESW;
break;
case (uint32_t)-1187377452: // FreeBSD + PuppyLinux (Bottom Right)
case (uint32_t)-600127498: // FreeBSD + PuppyLinux (Upper Left)
case (uint32_t)-2000746020: // openSUSE
curcursor = KVM_MouseCursor_SIZENWSE;
break;
case 733076101: // FreeBSD + PuppyLinux
case 261159321: // openSUSE
curcursor = KVM_MouseCursor_SIZEALL;
break;
case 728953462: // FreeBSD + PuppyLinux
case 310104114: // openSUSE
curcursor = KVM_MouseCursor_ARROW;
break;
case (uint32_t)-1347586305: // PuppyLinux
curcursor = KVM_MouseCursor_IBEAM;
break;
case (uint32_t)-1421461853: // PuppyLinux
curcursor = KVM_MouseCursor_HAND;
break;
}
}
}
} }
if (sentHideCursor == 0) if (sentHideCursor == 0)
@@ -1030,7 +1074,7 @@ void* kvm_server_mainloop(void* parm)
unsigned short xhot = ((unsigned short*)(cimage + 8))[0]; unsigned short xhot = ((unsigned short*)(cimage + 8))[0];
unsigned short yhot = ((unsigned short*)(cimage + 10))[0]; unsigned short yhot = ((unsigned short*)(cimage + 10))[0];
unsigned short mx = rx - xhot, my = ry - yhot; unsigned short mx = rx - xhot, my = ry - yhot;
char *pixels = cimage + 24; char *pixels = cimage + (sizeof(void*) == 8 ? 24 : 16);
//if (logFile) { fprintf(logFile, "BBP: %d, pad: %d, unit: %d, BPP: %d, F: %d, XO: %d: PW: %d\n", image->bytes_per_line, image->bitmap_pad, image->bitmap_unit, image->bits_per_pixel, image->format, image->xoffset, (adjust_screen_size(SCREEN_WIDTH) - image->width) * 3); fflush(logFile); } //if (logFile) { fprintf(logFile, "BBP: %d, pad: %d, unit: %d, BPP: %d, F: %d, XO: %d: PW: %d\n", image->bytes_per_line, image->bitmap_pad, image->bitmap_unit, image->bits_per_pixel, image->format, image->xoffset, (adjust_screen_size(SCREEN_WIDTH) - image->width) * 3); fflush(logFile); }
//if (logFile) { fprintf(logFile, "[%d/ %d x %d] (%d, %d) => (%d, %d | %u, %u)\n", image->bits_per_pixel, xa.width, xa.height, screen_width, screen_height, rx, ry,w , h); fflush(logFile); } //if (logFile) { fprintf(logFile, "[%d/ %d x %d] (%d, %d) => (%d, %d | %u, %u)\n", image->bits_per_pixel, xa.width, xa.height, screen_width, screen_height, rx, ry,w , h); fflush(logFile); }
@@ -1146,16 +1190,31 @@ void kvm_relay_readSink(ILibProcessPipe_Pipe sender, char *buffer, int bufferLen
if (bufferLen > 4) if (bufferLen > 4)
{ {
size = ntohs(((unsigned short*)(buffer))[1]); if (ntohs(((unsigned short*)(buffer))[0]) == (unsigned short)MNG_JUMBO)
if (size <= bufferLen)
{ {
//printf("KVM Data: %u bytes\n", size); if (bufferLen > 8)
*bytesConsumed = size; {
writeHandler(buffer, size, reserved); if (bufferLen >= (8 + (int)ntohl(((unsigned int*)(buffer))[1])))
return; {
*bytesConsumed = 8 + (int)ntohl(((unsigned int*)(buffer))[1]);
writeHandler(buffer, *bytesConsumed, reserved);
return;
}
}
}
else
{
size = ntohs(((unsigned short*)(buffer))[1]);
if (size <= bufferLen)
{
*bytesConsumed = size;
writeHandler(buffer, size, reserved);
return;
}
} }
} }
*bytesConsumed = 0; *bytesConsumed = 0;
} }
void kvm_relay_brokenPipeSink(ILibProcessPipe_Pipe sender) void kvm_relay_brokenPipeSink(ILibProcessPipe_Pipe sender)

View File

@@ -18,6 +18,12 @@ limitations under the License.
#include "meshcore/meshdefines.h" #include "meshcore/meshdefines.h"
#include "microstack/ILibParsers.h" #include "microstack/ILibParsers.h"
#if defined(JPEGMAXBUF)
#define MAX_TILE_SIZE JPEGMAXBUF
#else
#define MAX_TILE_SIZE 65500
#endif
extern int SCREEN_NUM; extern int SCREEN_NUM;
extern int SCREEN_WIDTH; extern int SCREEN_WIDTH;
extern int SCREEN_HEIGHT; extern int SCREEN_HEIGHT;
@@ -73,10 +79,14 @@ int calc_opt_compr_send(int x, int y, int captureWidth, int captureHeight, void*
write_JPEG_buffer(tilebuffer, captureWidth, captureHeight, COMPRESSION_QUALITY); write_JPEG_buffer(tilebuffer, captureWidth, captureHeight, COMPRESSION_QUALITY);
if (jpeg_buffer_length > 65500) { #if MAX_TILE_SIZE > 0
if (jpeg_buffer_length > MAX_TILE_SIZE)
{
return jpeg_buffer_length; return jpeg_buffer_length;
} }
else { else
#endif
{
return 0; return 0;
} }
} }
@@ -230,12 +240,16 @@ int getTileAt(int x, int y, void** buffer, long long *bufferSize, void *desktop,
if (CRC != g_tileInfo[row][rightcol].crc || g_tileInfo[row][rightcol].flag == TILE_MARKED_NOT_SENT) { //If the tile has changed, increment the capturewidth. if (CRC != g_tileInfo[row][rightcol].crc || g_tileInfo[row][rightcol].flag == TILE_MARKED_NOT_SENT) { //If the tile has changed, increment the capturewidth.
g_tileInfo[row][rightcol].crc = CRC; g_tileInfo[row][rightcol].crc = CRC;
//Here we check whether the size of the coalesced bitmap is greater than the threshold (65500)
if ((captureWidth + TILE_WIDTH) * TILE_HEIGHT * 3 / COMPRESSION_RATIO > 65500) { #if MAX_TILE_SIZE > 0
//Here we check whether the size of the coalesced bitmap is greater than the threshold (MAX_TILE_SIZE)
if ((captureWidth + TILE_WIDTH) * TILE_HEIGHT * 3 / COMPRESSION_RATIO > MAX_TILE_SIZE)
{
g_tileInfo[row][rightcol].flag = TILE_MARKED_NOT_SENT; g_tileInfo[row][rightcol].flag = TILE_MARKED_NOT_SENT;
--rightcol; --rightcol;
break; break;
} }
#endif
g_tileInfo[row][rightcol].flag = TILE_MARKED_NOT_SENT; g_tileInfo[row][rightcol].flag = TILE_MARKED_NOT_SENT;
captureWidth += TILE_WIDTH; captureWidth += TILE_WIDTH;
@@ -250,7 +264,12 @@ int getTileAt(int x, int y, void** buffer, long long *bufferSize, void *desktop,
//int TOLERANCE = (rightcol - col) / 3; //int TOLERANCE = (rightcol - col) / 3;
// Now go to the bottom tiles, check if they have changed and record them // Now go to the bottom tiles, check if they have changed and record them
while ((botrow + 1 < TILE_HEIGHT_COUNT) && ((captureHeight + TILE_HEIGHT) * captureWidth * 3 / COMPRESSION_RATIO <= 65500)) { #if MAX_TILE_SIZE > 0
while ((botrow + 1 < TILE_HEIGHT_COUNT) && ((captureHeight + TILE_HEIGHT) * captureWidth * 3 / COMPRESSION_RATIO <= MAX_TILE_SIZE))
#else
while ((botrow + 1 < TILE_HEIGHT_COUNT))
#endif
{
botrow++; botrow++;
r_y = botrow * TILE_HEIGHT; r_y = botrow * TILE_HEIGHT;
int fail = 0; int fail = 0;
@@ -314,6 +333,9 @@ int getTileAt(int x, int y, void** buffer, long long *bufferSize, void *desktop,
int retval = 0; int retval = 0;
int firstTime = 1; int firstTime = 1;
#if MAX_TILE_SIZE == 0
retval = calc_opt_compr_send(x, y, captureWidth, captureHeight, desktop, desktopsize, buffer, bufferSize);
#else
//This loop is used to adjust the COMPRESSION_RATIO. This loop runs only once most of the time. //This loop is used to adjust the COMPRESSION_RATIO. This loop runs only once most of the time.
do { do {
//retval here is 0 if everything was good. It is > 0 if it contains the size of the jpeg that was created and not sent. //retval here is 0 if everything was good. It is > 0 if it contains the size of the jpeg that was created and not sent.
@@ -321,7 +343,7 @@ int getTileAt(int x, int y, void** buffer, long long *bufferSize, void *desktop,
if (retval != 0) { if (retval != 0) {
if (firstTime) { if (firstTime) {
// Re-adjust the compression ratio. // Re-adjust the compression ratio.
COMPRESSION_RATIO = (int)(((double)COMPRESSION_RATIO/(double)retval) * 60000);//Magic number: 60000 ~= 65500 COMPRESSION_RATIO = (int)(((double)COMPRESSION_RATIO/(double)retval) * (0.92 * MAX_TILE_SIZE)); //Magic number: 92% of MAX_TILE_SIZE
if (COMPRESSION_RATIO <= 1) { COMPRESSION_RATIO = 2; } if (COMPRESSION_RATIO <= 1) { COMPRESSION_RATIO = 2; }
firstTime = 0; firstTime = 0;
} }
@@ -341,17 +363,34 @@ int getTileAt(int x, int y, void** buffer, long long *bufferSize, void *desktop,
} }
} while (retval != 0); } while (retval != 0);
#endif
//Set the flags to TILE_SENT //Set the flags to TILE_SENT
if (jpeg_buffer != NULL) { if (jpeg_buffer != NULL)
*bufferSize = jpeg_buffer_length + 8; {
*bufferSize = jpeg_buffer_length + (jpeg_buffer_length > 65500 ? 16 : 8);
*buffer = malloc(*bufferSize);
if (jpeg_buffer_length > 65500)
{
((unsigned short*)*buffer)[0] = (unsigned short)htons((unsigned short)MNG_JUMBO); // Write the type
((unsigned short*)*buffer)[1] = (unsigned short)htons((unsigned short)8); // Write the size
((unsigned int*)*buffer)[1] = (unsigned int)htonl(jpeg_buffer_length + 8); // Size of the Next Packet
((unsigned short*)*buffer)[4] = (unsigned short)htons((unsigned short)MNG_KVM_PICTURE); // Write the type
((unsigned short*)*buffer)[5] = 0; // RESERVED
((unsigned short*)*buffer)[6] = (unsigned short)htons((unsigned short)x); // X position
((unsigned short*)*buffer)[7] = (unsigned short)htons((unsigned short)y); // Y position
memcpy((char *)(*buffer) + 16, jpeg_buffer, jpeg_buffer_length);
}
else
{
((unsigned short*)*buffer)[0] = (unsigned short)htons((unsigned short)MNG_KVM_PICTURE); // Write the type
((unsigned short*)*buffer)[1] = (unsigned short)htons((unsigned short)*bufferSize); // Write the size
((unsigned short*)*buffer)[2] = (unsigned short)htons((unsigned short)x); // X position
((unsigned short*)*buffer)[3] = (unsigned short)htons((unsigned short)y); // Y position
memcpy((char *)(*buffer) + 8, jpeg_buffer, jpeg_buffer_length);
}
if ((*buffer = malloc(*bufferSize)) == NULL) ILIBCRITICALEXIT(254);
((unsigned short*)*buffer)[0] = (unsigned short)htons((unsigned short)MNG_KVM_PICTURE); // Write the type
((unsigned short*)*buffer)[1] = (unsigned short)htons((unsigned short)*bufferSize); // Write the size
((unsigned short*)*buffer)[2] = (unsigned short)htons((unsigned short)x); // X position
((unsigned short*)*buffer)[3] = (unsigned short)htons((unsigned short)y); // Y position
memcpy((char *)(*buffer) + 8, jpeg_buffer, jpeg_buffer_length);
free(jpeg_buffer); free(jpeg_buffer);
jpeg_buffer = NULL; jpeg_buffer = NULL;
jpeg_buffer_length = 0; jpeg_buffer_length = 0;

View File

@@ -635,19 +635,29 @@ void kvm_relay_StdOutHandler(ILibProcessPipe_Process sender, char *buffer, int b
if (bufferLen > 4) if (bufferLen > 4)
{ {
size = ntohs(((unsigned short*)(buffer))[1]); if (ntohs(((unsigned short*)(buffer))[0]) == (unsigned short)MNG_JUMBO)
if (size <= bufferLen)
{ {
if (ntohs(((unsigned short*)(buffer))[0]) == MNG_DEBUG) if (bufferLen > 8)
{ {
char tmp[255]; if (bufferLen >= (8 + (int)ntohl(((unsigned int*)(buffer))[1])))
int x = sprintf_s(tmp, sizeof(tmp), "DEBUG: %d\n", ((int*)buffer)[1]); {
*bytesConsumed = 8 + (int)ntohl(((unsigned int*)(buffer))[1]);
write(STDOUT_FILENO, tmp, x); writeHandler(buffer, *bytesConsumed, reserved);
printf("JUMBO PACKET: %d\n", *bytesConsumed);
return;
}
}
}
else
{
size = ntohs(((unsigned short*)(buffer))[1]);
if (size <= bufferLen)
{
*bytesConsumed = size;
writeHandler(buffer, size, reserved);
printf("Normal PACKET: %d\n", *bytesConsumed);
return;
} }
*bytesConsumed = size;
writeHandler(buffer, size, reserved);
return;
} }
} }
*bytesConsumed = 0; *bytesConsumed = 0;

View File

@@ -29,6 +29,13 @@ int tilebuffersize = 0;
void* tilebuffer = NULL; void* tilebuffer = NULL;
int COMPRESSION_QUALITY = 50; int COMPRESSION_QUALITY = 50;
#if defined(JPEGMAXBUF)
#define MAX_TILE_SIZE JPEGMAXBUF
#else
#define MAX_TILE_SIZE 65500
#endif
/****************************************************************************** /******************************************************************************
* INTERNAL FUNCTIONS * INTERNAL FUNCTIONS
******************************************************************************/ ******************************************************************************/
@@ -67,10 +74,14 @@ int calc_opt_compr_send(int x, int y, int captureWidth, int captureHeight, void*
write_JPEG_buffer(tilebuffer, captureWidth, captureHeight, COMPRESSION_QUALITY); write_JPEG_buffer(tilebuffer, captureWidth, captureHeight, COMPRESSION_QUALITY);
if (jpeg_buffer_length > 65500) { #if MAX_TILE_SIZE > 0
if (jpeg_buffer_length > MAX_TILE_SIZE)
{
return jpeg_buffer_length; return jpeg_buffer_length;
} }
else { else
#endif
{
return 0; return 0;
} }
} }
@@ -222,17 +233,22 @@ int getTileAt(int x, int y, void** buffer, long long *bufferSize, void *desktop,
if (CRC != g_tileInfo[row][rightcol].crc || g_tileInfo[row][rightcol].flag == TILE_MARKED_NOT_SENT) { //If the tile has changed, increment the capturewidth. if (CRC != g_tileInfo[row][rightcol].crc || g_tileInfo[row][rightcol].flag == TILE_MARKED_NOT_SENT) { //If the tile has changed, increment the capturewidth.
g_tileInfo[row][rightcol].crc = CRC; g_tileInfo[row][rightcol].crc = CRC;
//Here we check whether the size of the coalesced bitmap is greater than the threshold (65500)
if ((captureWidth + TILE_WIDTH) * TILE_HEIGHT * 3 / COMPRESSION_RATIO > 65500) { #if MAX_TILE_SIZE > 0
//Here we check whether the size of the coalesced bitmap is greater than the threshold (MAX_TILE_SIZE)
if ((captureWidth + TILE_WIDTH) * TILE_HEIGHT * 3 / COMPRESSION_RATIO > MAX_TILE_SIZE)
{
g_tileInfo[row][rightcol].flag = TILE_MARKED_NOT_SENT; g_tileInfo[row][rightcol].flag = TILE_MARKED_NOT_SENT;
--rightcol; --rightcol;
break; break;
} }
#endif
g_tileInfo[row][rightcol].flag = TILE_MARKED_NOT_SENT; g_tileInfo[row][rightcol].flag = TILE_MARKED_NOT_SENT;
captureWidth += TILE_WIDTH; captureWidth += TILE_WIDTH;
} }
else { else
{
g_tileInfo[row][rightcol].flag = TILE_DONT_SEND; g_tileInfo[row][rightcol].flag = TILE_DONT_SEND;
--rightcol; --rightcol;
break; break;
@@ -242,7 +258,12 @@ int getTileAt(int x, int y, void** buffer, long long *bufferSize, void *desktop,
//int TOLERANCE = (rightcol - col) / 3; //int TOLERANCE = (rightcol - col) / 3;
// Now go to the bottom tiles, check if they have changed and record them // Now go to the bottom tiles, check if they have changed and record them
while ((botrow + 1 < TILE_HEIGHT_COUNT) && ((captureHeight + TILE_HEIGHT) * captureWidth * 3 / COMPRESSION_RATIO <= 65500)) { #if MAX_TILE_SIZE > 0
while ((botrow + 1 < TILE_HEIGHT_COUNT) && ((captureHeight + TILE_HEIGHT) * captureWidth * 3 / COMPRESSION_RATIO <= MAX_TILE_SIZE))
#else
while ((botrow + 1 < TILE_HEIGHT_COUNT))
#endif
{
botrow++; botrow++;
r_y = botrow * TILE_HEIGHT; r_y = botrow * TILE_HEIGHT;
int fail = 0; int fail = 0;
@@ -306,42 +327,38 @@ int getTileAt(int x, int y, void** buffer, long long *bufferSize, void *desktop,
int retval = 0; int retval = 0;
int firstTime = 1; int firstTime = 1;
////This loop is used to adjust the COMPRESSION_RATIO. This loop runs only once most of the time. #if MAX_TILE_SIZE == 0
do retval = calc_opt_compr_send(x, y, captureWidth, captureHeight, desktop, desktopsize, buffer, bufferSize);
{ #else
//This loop is used to adjust the COMPRESSION_RATIO. This loop runs only once most of the time.
do {
//retval here is 0 if everything was good. It is > 0 if it contains the size of the jpeg that was created and not sent. //retval here is 0 if everything was good. It is > 0 if it contains the size of the jpeg that was created and not sent.
retval = calc_opt_compr_send(x, y, captureWidth, captureHeight, desktop, desktopsize, buffer, bufferSize); retval = calc_opt_compr_send(x, y, captureWidth, captureHeight, desktop, desktopsize, buffer, bufferSize);
if (retval != 0) if (retval != 0) {
{ if (firstTime) {
//if (firstTime) // Re-adjust the compression ratio.
//{ COMPRESSION_RATIO = (int)(((double)COMPRESSION_RATIO / (double)retval) * (0.92 * MAX_TILE_SIZE)); //Magic number: 92% of MAX_TILE_SIZE
// //Re-adjust the compression ratio. if (COMPRESSION_RATIO <= 1) { COMPRESSION_RATIO = 2; }
// COMPRESSION_RATIO = (int)(((double)COMPRESSION_RATIO/(double)retval) * 60000);//Magic number: 60000 ~= 65500 firstTime = 0;
// if (COMPRESSION_RATIO <= 1) { }
// COMPRESSION_RATIO = 2;
// }
//
// firstTime = 0;
//}
if (botrow > row) { //First time, try reducing the height. if (botrow > row) { //First time, try reducing the height.
botrow = row + ((botrow - row + 1) / 2); botrow = row + ((botrow - row + 1) / 2);
captureHeight = (botrow - row + 1) * TILE_HEIGHT; captureHeight = (botrow - row + 1) * TILE_HEIGHT;
} }
else if (rightcol > col) else if (rightcol > col) { //If it is not possible, reduce the width
{ //If it is not possible, reduce the width
rightcol = col + ((rightcol - col + 1) / 2); rightcol = col + ((rightcol - col + 1) / 2);
captureWidth = (rightcol - col + 1) * TILE_WIDTH; captureWidth = (rightcol - col + 1) * TILE_WIDTH;
} }
else else { //This never happens in any case.
{ //This never happens in any case.
retval = 0; retval = 0;
break; break;
} }
} }
} while (retval != 0); } while (retval != 0);
#endif
//Set the flags to TILE_SENT //Set the flags to TILE_SENT
if (jpeg_buffer != NULL) if (jpeg_buffer != NULL)
{ {

View File

@@ -299,8 +299,11 @@ void KVM_InitMessagePump()
CUR_WORKTHREAD = CreateThread(NULL, 0, KVM_InitMessagePumpEx, NULL, 0, 0); CUR_WORKTHREAD = CreateThread(NULL, 0, KVM_InitMessagePumpEx, NULL, 0, 0);
} }
void KVM_InitMouseCursors() void KVM_InitMouseCursors(void *pendingPackets)
{ {
CURSORINFO info = { 0 };
char *buffer;
CUR_ARROW = KVM_GetCursorHash(LoadCursorA(NULL, IDC_ARROW), NULL, 0); CUR_ARROW = KVM_GetCursorHash(LoadCursorA(NULL, IDC_ARROW), NULL, 0);
CUR_APPSTARTING = KVM_GetCursorHash(LoadCursorA(NULL, IDC_APPSTARTING), NULL, 0); CUR_APPSTARTING = KVM_GetCursorHash(LoadCursorA(NULL, IDC_APPSTARTING), NULL, 0);
CUR_CROSS = KVM_GetCursorHash(LoadCursorA(NULL, IDC_CROSS), NULL, 0); CUR_CROSS = KVM_GetCursorHash(LoadCursorA(NULL, IDC_CROSS), NULL, 0);
@@ -316,6 +319,16 @@ void KVM_InitMouseCursors()
CUR_UPARROW = KVM_GetCursorHash(LoadCursorA(NULL, IDC_UPARROW), NULL, 0); CUR_UPARROW = KVM_GetCursorHash(LoadCursorA(NULL, IDC_UPARROW), NULL, 0);
CUR_WAIT = KVM_GetCursorHash(LoadCursorA(NULL, IDC_WAIT), NULL, 0); CUR_WAIT = KVM_GetCursorHash(LoadCursorA(NULL, IDC_WAIT), NULL, 0);
info.cbSize = sizeof(info);
GetCursorInfo(&info);
gCurrentCursor = KVM_CursorHashToMSG(KVM_GetCursorHash(info.hCursor, NULL, 0));
buffer = (char*)ILibMemory_SmartAllocate(5);
((unsigned short*)buffer)[0] = (unsigned short)htons((unsigned short)MNG_KVM_MOUSE_CURSOR); // Write the type
((unsigned short*)buffer)[1] = (unsigned short)htons((unsigned short)5); // Write the size
buffer[4] = (char)gCurrentCursor; // Cursor Type
ILibQueue_EnQueue(pendingPackets, buffer);
KVM_InitMessagePump(); KVM_InitMessagePump();
} }

View File

@@ -37,7 +37,7 @@ typedef enum KVM_MouseCursors
KVM_MouseCursor_WAIT = 13 KVM_MouseCursor_WAIT = 13
}KVM_MouseCursors; }KVM_MouseCursors;
void KVM_InitMouseCursors(); void KVM_InitMouseCursors(void* pendingPackets);
void KVM_UnInitMouseCursors(); void KVM_UnInitMouseCursors();
void MouseAction(double absX, double absY, int button, short wheel); void MouseAction(double absX, double absY, int button, short wheel);
void KeyAction(unsigned char keycode, int up); void KeyAction(unsigned char keycode, int up);

View File

@@ -823,7 +823,7 @@ DWORD WINAPI kvm_server_mainloop_ex(LPVOID parm)
int sentHideCursor = 0; int sentHideCursor = 0;
gPendingPackets = ILibQueue_Create(); gPendingPackets = ILibQueue_Create();
KVM_InitMouseCursors(); KVM_InitMouseCursors(gPendingPackets);
#ifdef _WINSERVICE #ifdef _WINSERVICE
if (!kvmConsoleMode) if (!kvmConsoleMode)