mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-15 15:53:55 +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:
2
makefile
2
makefile
@@ -469,7 +469,7 @@ pi:
|
||||
strip meshagent_pi
|
||||
|
||||
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)
|
||||
$(STRIP)
|
||||
|
||||
|
||||
@@ -16,6 +16,12 @@ limitations under the License.
|
||||
|
||||
#include "linux_compression.h"
|
||||
|
||||
#if defined(JPEGMAXBUF)
|
||||
#define MAX_TILE_SIZE JPEGMAXBUF
|
||||
#else
|
||||
#define MAX_TILE_SIZE 65500
|
||||
#endif
|
||||
|
||||
unsigned char *jpeg_buffer = NULL;
|
||||
int jpeg_buffer_length = 0;
|
||||
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->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;
|
||||
}
|
||||
|
||||
@@ -61,11 +69,15 @@ void term_destination (j_compress_ptr cinfo)
|
||||
|
||||
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);
|
||||
jpeg_buffer = NULL;
|
||||
}
|
||||
else {
|
||||
else
|
||||
#endif
|
||||
{
|
||||
jpeg_buffer = (unsigned char *) realloc(jpeg_buffer, jpeg_buffer_length);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,6 +142,7 @@ typedef struct xfixes_struct
|
||||
Bool(*XFixesSelectCursorInput)(Display *d, Window w, int i);
|
||||
Bool(*XFixesQueryExtension)(Display *d, int *eventbase, int *errorbase);
|
||||
void*(*XFixesGetCursorImage)(Display *d);
|
||||
void*(*XFixesGetCursorImageAndName)(Display *d);
|
||||
}xfixes_struct;
|
||||
xfixes_struct *xfixes_exports = NULL;
|
||||
|
||||
@@ -160,6 +161,102 @@ void kvm_send_error(char *msg)
|
||||
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()
|
||||
{
|
||||
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)[2] = (void*)dlsym(xfixes_exports->xfixes_lib, "XFixesQueryExtension");
|
||||
((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
|
||||
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)
|
||||
@@ -899,63 +999,7 @@ void* kvm_server_mainloop(void* parm)
|
||||
else
|
||||
{
|
||||
// Name was NULL, so as a last ditch effort, lets try to look at the XFixesCursorImage
|
||||
cursor_image = (char*)xfixes_exports->XFixesGetCursorImage(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;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
curcursor = kvm_fetch_currentCursor(cursordisplay);
|
||||
}
|
||||
|
||||
if (sentHideCursor == 0)
|
||||
@@ -1030,7 +1074,7 @@ void* kvm_server_mainloop(void* parm)
|
||||
unsigned short xhot = ((unsigned short*)(cimage + 8))[0];
|
||||
unsigned short yhot = ((unsigned short*)(cimage + 10))[0];
|
||||
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, "[%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); }
|
||||
@@ -1145,17 +1189,32 @@ void kvm_relay_readSink(ILibProcessPipe_Pipe sender, char *buffer, int bufferLen
|
||||
unsigned short size;
|
||||
|
||||
if (bufferLen > 4)
|
||||
{
|
||||
if (ntohs(((unsigned short*)(buffer))[0]) == (unsigned short)MNG_JUMBO)
|
||||
{
|
||||
if (bufferLen > 8)
|
||||
{
|
||||
if (bufferLen >= (8 + (int)ntohl(((unsigned int*)(buffer))[1])))
|
||||
{
|
||||
*bytesConsumed = 8 + (int)ntohl(((unsigned int*)(buffer))[1]);
|
||||
writeHandler(buffer, *bytesConsumed, reserved);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
size = ntohs(((unsigned short*)(buffer))[1]);
|
||||
if (size <= bufferLen)
|
||||
{
|
||||
//printf("KVM Data: %u bytes\n", size);
|
||||
*bytesConsumed = size;
|
||||
writeHandler(buffer, size, reserved);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
*bytesConsumed = 0;
|
||||
|
||||
}
|
||||
|
||||
void kvm_relay_brokenPipeSink(ILibProcessPipe_Pipe sender)
|
||||
|
||||
@@ -18,6 +18,12 @@ limitations under the License.
|
||||
#include "meshcore/meshdefines.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_WIDTH;
|
||||
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);
|
||||
|
||||
if (jpeg_buffer_length > 65500) {
|
||||
#if MAX_TILE_SIZE > 0
|
||||
if (jpeg_buffer_length > MAX_TILE_SIZE)
|
||||
{
|
||||
return jpeg_buffer_length;
|
||||
}
|
||||
else {
|
||||
else
|
||||
#endif
|
||||
{
|
||||
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.
|
||||
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;
|
||||
--rightcol;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
g_tileInfo[row][rightcol].flag = TILE_MARKED_NOT_SENT;
|
||||
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;
|
||||
|
||||
// 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++;
|
||||
r_y = botrow * TILE_HEIGHT;
|
||||
int fail = 0;
|
||||
@@ -314,6 +333,9 @@ int getTileAt(int x, int y, void** buffer, long long *bufferSize, void *desktop,
|
||||
int retval = 0;
|
||||
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.
|
||||
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.
|
||||
@@ -321,7 +343,7 @@ int getTileAt(int x, int y, void** buffer, long long *bufferSize, void *desktop,
|
||||
if (retval != 0) {
|
||||
if (firstTime) {
|
||||
// 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; }
|
||||
firstTime = 0;
|
||||
}
|
||||
@@ -341,17 +363,34 @@ int getTileAt(int x, int y, void** buffer, long long *bufferSize, void *desktop,
|
||||
|
||||
}
|
||||
} while (retval != 0);
|
||||
#endif
|
||||
|
||||
//Set the flags to TILE_SENT
|
||||
if (jpeg_buffer != NULL) {
|
||||
*bufferSize = jpeg_buffer_length + 8;
|
||||
if (jpeg_buffer != NULL)
|
||||
{
|
||||
*bufferSize = jpeg_buffer_length + (jpeg_buffer_length > 65500 ? 16 : 8);
|
||||
*buffer = malloc(*bufferSize);
|
||||
|
||||
if ((*buffer = malloc(*bufferSize)) == NULL) ILIBCRITICALEXIT(254);
|
||||
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);
|
||||
}
|
||||
|
||||
free(jpeg_buffer);
|
||||
jpeg_buffer = NULL;
|
||||
jpeg_buffer_length = 0;
|
||||
|
||||
@@ -634,22 +634,32 @@ void kvm_relay_StdOutHandler(ILibProcessPipe_Process sender, char *buffer, int b
|
||||
void *reserved = ((void**)user)[1];
|
||||
|
||||
if (bufferLen > 4)
|
||||
{
|
||||
if (ntohs(((unsigned short*)(buffer))[0]) == (unsigned short)MNG_JUMBO)
|
||||
{
|
||||
if (bufferLen > 8)
|
||||
{
|
||||
if (bufferLen >= (8 + (int)ntohl(((unsigned int*)(buffer))[1])))
|
||||
{
|
||||
*bytesConsumed = 8 + (int)ntohl(((unsigned int*)(buffer))[1]);
|
||||
writeHandler(buffer, *bytesConsumed, reserved);
|
||||
printf("JUMBO PACKET: %d\n", *bytesConsumed);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
size = ntohs(((unsigned short*)(buffer))[1]);
|
||||
if (size <= bufferLen)
|
||||
{
|
||||
if (ntohs(((unsigned short*)(buffer))[0]) == MNG_DEBUG)
|
||||
{
|
||||
char tmp[255];
|
||||
int x = sprintf_s(tmp, sizeof(tmp), "DEBUG: %d\n", ((int*)buffer)[1]);
|
||||
|
||||
write(STDOUT_FILENO, tmp, x);
|
||||
}
|
||||
*bytesConsumed = size;
|
||||
writeHandler(buffer, size, reserved);
|
||||
printf("Normal PACKET: %d\n", *bytesConsumed);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
*bytesConsumed = 0;
|
||||
}
|
||||
void kvm_relay_StdErrHandler(ILibProcessPipe_Process sender, char *buffer, int bufferLen, int* bytesConsumed, void* user)
|
||||
|
||||
@@ -29,6 +29,13 @@ int tilebuffersize = 0;
|
||||
void* tilebuffer = NULL;
|
||||
int COMPRESSION_QUALITY = 50;
|
||||
|
||||
#if defined(JPEGMAXBUF)
|
||||
#define MAX_TILE_SIZE JPEGMAXBUF
|
||||
#else
|
||||
#define MAX_TILE_SIZE 65500
|
||||
#endif
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* 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);
|
||||
|
||||
if (jpeg_buffer_length > 65500) {
|
||||
#if MAX_TILE_SIZE > 0
|
||||
if (jpeg_buffer_length > MAX_TILE_SIZE)
|
||||
{
|
||||
return jpeg_buffer_length;
|
||||
}
|
||||
else {
|
||||
else
|
||||
#endif
|
||||
{
|
||||
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.
|
||||
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;
|
||||
--rightcol;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
g_tileInfo[row][rightcol].flag = TILE_MARKED_NOT_SENT;
|
||||
captureWidth += TILE_WIDTH;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
g_tileInfo[row][rightcol].flag = TILE_DONT_SEND;
|
||||
--rightcol;
|
||||
break;
|
||||
@@ -242,7 +258,12 @@ int getTileAt(int x, int y, void** buffer, long long *bufferSize, void *desktop,
|
||||
//int TOLERANCE = (rightcol - col) / 3;
|
||||
|
||||
// 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++;
|
||||
r_y = botrow * TILE_HEIGHT;
|
||||
int fail = 0;
|
||||
@@ -306,41 +327,37 @@ int getTileAt(int x, int y, void** buffer, long long *bufferSize, void *desktop,
|
||||
int retval = 0;
|
||||
int firstTime = 1;
|
||||
|
||||
////This loop is used to adjust the COMPRESSION_RATIO. This loop runs only once most of the time.
|
||||
do
|
||||
{
|
||||
#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.
|
||||
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 = calc_opt_compr_send(x, y, captureWidth, captureHeight, desktop, desktopsize, buffer, bufferSize);
|
||||
if (retval != 0)
|
||||
{
|
||||
//if (firstTime)
|
||||
//{
|
||||
// //Re-adjust the compression ratio.
|
||||
// COMPRESSION_RATIO = (int)(((double)COMPRESSION_RATIO/(double)retval) * 60000);//Magic number: 60000 ~= 65500
|
||||
// if (COMPRESSION_RATIO <= 1) {
|
||||
// COMPRESSION_RATIO = 2;
|
||||
// }
|
||||
//
|
||||
// firstTime = 0;
|
||||
//}
|
||||
if (retval != 0) {
|
||||
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
|
||||
if (COMPRESSION_RATIO <= 1) { COMPRESSION_RATIO = 2; }
|
||||
firstTime = 0;
|
||||
}
|
||||
|
||||
if (botrow > row) { //First time, try reducing the height.
|
||||
botrow = row + ((botrow - row + 1) / 2);
|
||||
captureHeight = (botrow - row + 1) * TILE_HEIGHT;
|
||||
}
|
||||
else if (rightcol > col)
|
||||
{ //If it is not possible, reduce the width
|
||||
else if (rightcol > col) { //If it is not possible, reduce the width
|
||||
rightcol = col + ((rightcol - col + 1) / 2);
|
||||
captureWidth = (rightcol - col + 1) * TILE_WIDTH;
|
||||
}
|
||||
else
|
||||
{ //This never happens in any case.
|
||||
else { //This never happens in any case.
|
||||
retval = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
} while (retval != 0);
|
||||
#endif
|
||||
|
||||
//Set the flags to TILE_SENT
|
||||
if (jpeg_buffer != NULL)
|
||||
|
||||
@@ -299,8 +299,11 @@ void KVM_InitMessagePump()
|
||||
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_APPSTARTING = KVM_GetCursorHash(LoadCursorA(NULL, IDC_APPSTARTING), 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_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();
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ typedef enum KVM_MouseCursors
|
||||
KVM_MouseCursor_WAIT = 13
|
||||
}KVM_MouseCursors;
|
||||
|
||||
void KVM_InitMouseCursors();
|
||||
void KVM_InitMouseCursors(void* pendingPackets);
|
||||
void KVM_UnInitMouseCursors();
|
||||
void MouseAction(double absX, double absY, int button, short wheel);
|
||||
void KeyAction(unsigned char keycode, int up);
|
||||
|
||||
@@ -823,7 +823,7 @@ DWORD WINAPI kvm_server_mainloop_ex(LPVOID parm)
|
||||
int sentHideCursor = 0;
|
||||
|
||||
gPendingPackets = ILibQueue_Create();
|
||||
KVM_InitMouseCursors();
|
||||
KVM_InitMouseCursors(gPendingPackets);
|
||||
|
||||
#ifdef _WINSERVICE
|
||||
if (!kvmConsoleMode)
|
||||
|
||||
Reference in New Issue
Block a user