mirror of
https://github.com/lxsang/antd-wvnc-plugin.git
synced 2024-12-28 04:48:21 +01:00
more options, keyboard event
This commit is contained in:
parent
c81bd71534
commit
96ceffed2e
2
Makefile
2
Makefile
@ -15,7 +15,7 @@ endif
|
|||||||
|
|
||||||
PLUGINLIBS = libantd.$(EXT) -lvncclient -lpthread -lz -ljpeg# -lsqlite3
|
PLUGINLIBS = libantd.$(EXT) -lvncclient -lpthread -lz -ljpeg# -lsqlite3
|
||||||
|
|
||||||
PCFLAGS=-W -Wall -g -D DEBUG $(PPF_FLAG) $(DEP) -D USE_JPEG #-D USE_ZLIB
|
PCFLAGS=-W -Wall -g -D DEBUG $(PPF_FLAG) $(DEP) -D USE_JPEG -D USE_ZLIB
|
||||||
|
|
||||||
main: $(PLUGINSDEP) $(PLUGINS) #lib
|
main: $(PLUGINSDEP) $(PLUGINS) #lib
|
||||||
|
|
||||||
|
69
wvnc.c
69
wvnc.c
@ -26,8 +26,12 @@ typedef struct
|
|||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
void *client;
|
void *client;
|
||||||
int status;
|
uint8_t status;
|
||||||
void *vncl;
|
void *vncl;
|
||||||
|
uint8_t bbp;
|
||||||
|
uint8_t flag;
|
||||||
|
uint8_t quality;
|
||||||
|
int rate;
|
||||||
} wvnc_user_data_t;
|
} wvnc_user_data_t;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
@ -74,7 +78,7 @@ int zlib_compress(uint8_t *src, int len)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_JPEG
|
#ifdef USE_JPEG
|
||||||
int jpeg_compress(uint8_t *buff, int w, int h, int bbp)
|
int jpeg_compress(uint8_t *buff, int w, int h, int components)
|
||||||
{
|
{
|
||||||
uint8_t *tmp = buff;
|
uint8_t *tmp = buff;
|
||||||
/*if(bbp == 4)
|
/*if(bbp == 4)
|
||||||
@ -98,8 +102,8 @@ int jpeg_compress(uint8_t *buff, int w, int h, int bbp)
|
|||||||
jpeg_mem_dest(&cinfo, &out, &outbuffer_size);
|
jpeg_mem_dest(&cinfo, &out, &outbuffer_size);
|
||||||
cinfo.image_width = w;
|
cinfo.image_width = w;
|
||||||
cinfo.image_height = h;
|
cinfo.image_height = h;
|
||||||
cinfo.input_components = bbp;
|
cinfo.input_components = components;
|
||||||
cinfo.in_color_space = bbp==4?JCS_EXT_RGBA:JCS_RGB;
|
cinfo.in_color_space = components==4?JCS_EXT_RGBA:JCS_RGB;
|
||||||
jpeg_set_defaults(&cinfo);
|
jpeg_set_defaults(&cinfo);
|
||||||
jpeg_set_quality(&cinfo, 50, true);
|
jpeg_set_quality(&cinfo, 50, true);
|
||||||
jpeg_start_compress(&cinfo, true);
|
jpeg_start_compress(&cinfo, true);
|
||||||
@ -107,13 +111,13 @@ int jpeg_compress(uint8_t *buff, int w, int h, int bbp)
|
|||||||
JSAMPROW row_pointer[1];
|
JSAMPROW row_pointer[1];
|
||||||
while (cinfo.next_scanline < cinfo.image_height)
|
while (cinfo.next_scanline < cinfo.image_height)
|
||||||
{
|
{
|
||||||
row_pointer[0] = (JSAMPROW)(&tmp[cinfo.next_scanline * w * bbp]);
|
row_pointer[0] = (JSAMPROW)(&tmp[cinfo.next_scanline * w * components]);
|
||||||
unsigned return_code = jpeg_write_scanlines(&cinfo, row_pointer, 1);
|
unsigned return_code = jpeg_write_scanlines(&cinfo, row_pointer, 1);
|
||||||
}
|
}
|
||||||
jpeg_finish_compress(&cinfo);
|
jpeg_finish_compress(&cinfo);
|
||||||
jpeg_destroy_compress(&cinfo);
|
jpeg_destroy_compress(&cinfo);
|
||||||
//LOG("before %d after %d\n", w*h*bbp, );
|
//LOG("before %d after %d\n", w*h*bbp, );
|
||||||
if(outbuffer_size < w*h*bbp)
|
if(outbuffer_size < w*h*components)
|
||||||
{
|
{
|
||||||
memcpy(buff, out, outbuffer_size);
|
memcpy(buff, out, outbuffer_size);
|
||||||
}
|
}
|
||||||
@ -242,25 +246,23 @@ static rfbBool resize(rfbClient *client)
|
|||||||
{
|
{
|
||||||
int width = client->width;
|
int width = client->width;
|
||||||
int height = client->height;
|
int height = client->height;
|
||||||
int depth = client->format.bitsPerPixel;
|
//int depth = client->format.bitsPerPixel;
|
||||||
LOG("width %d, height %d, depth %d\n", width, height, depth);
|
|
||||||
client->updateRect.x = client->updateRect.y = 0;
|
client->updateRect.x = client->updateRect.y = 0;
|
||||||
client->updateRect.w = width;
|
client->updateRect.w = width;
|
||||||
client->updateRect.h = height;
|
client->updateRect.h = height;
|
||||||
//depth = 24;
|
|
||||||
void *data = rfbClientGetClientData(client, identify());
|
void *data = rfbClientGetClientData(client, identify());
|
||||||
wvnc_user_data_t *user_data = get_user_data(data);
|
wvnc_user_data_t *user_data = get_user_data(data);
|
||||||
//client->width = sdl->pitch / (depth / 8);
|
//client->width = sdl->pitch / (depth / 8);
|
||||||
if (client->frameBuffer)
|
if (client->frameBuffer)
|
||||||
free(client->frameBuffer);
|
free(client->frameBuffer);
|
||||||
client->frameBuffer = (uint8_t *)malloc(width * height * depth / 8);
|
client->frameBuffer = (uint8_t *)malloc(width * height * user_data->bbp / 8);
|
||||||
wvnc_pixel_format_t pxf;
|
wvnc_pixel_format_t pxf;
|
||||||
if (!get_pixel_format(depth, &pxf))
|
if (!get_pixel_format( user_data->bbp, &pxf))
|
||||||
{
|
{
|
||||||
vnc_fatal(user_data, "Cannot get pixel format");
|
vnc_fatal(user_data, "Cannot get pixel format");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
client->format.bitsPerPixel = depth;
|
client->format.bitsPerPixel = user_data->bbp;
|
||||||
client->format.redShift = pxf.r_shift;
|
client->format.redShift = pxf.r_shift;
|
||||||
client->format.greenShift = pxf.g_shift;
|
client->format.greenShift = pxf.g_shift;
|
||||||
client->format.blueShift = pxf.b_shift;
|
client->format.blueShift = pxf.b_shift;
|
||||||
@ -268,7 +270,7 @@ static rfbBool resize(rfbClient *client)
|
|||||||
client->format.greenMax = pxf.g_max;
|
client->format.greenMax = pxf.g_max;
|
||||||
client->format.blueMax = pxf.b_max;
|
client->format.blueMax = pxf.b_max;
|
||||||
SetFormatAndEncodings(client);
|
SetFormatAndEncodings(client);
|
||||||
|
LOG("width %d, height %d, depth %d\n", width, height, client->format.bitsPerPixel);
|
||||||
/* create or resize the window */
|
/* create or resize the window */
|
||||||
// send data to client
|
// send data to client
|
||||||
uint8_t cmd[6];
|
uint8_t cmd[6];
|
||||||
@ -277,7 +279,7 @@ static rfbBool resize(rfbClient *client)
|
|||||||
cmd[2] = (uint8_t)(width >> 8);
|
cmd[2] = (uint8_t)(width >> 8);
|
||||||
cmd[3] = (uint8_t)(height & 0xFF);
|
cmd[3] = (uint8_t)(height & 0xFF);
|
||||||
cmd[4] = (uint8_t)(height >> 8);
|
cmd[4] = (uint8_t)(height >> 8);
|
||||||
cmd[5] = (uint8_t)depth;
|
cmd[5] = (uint8_t)( user_data->bbp);
|
||||||
ws_b(user_data->client, cmd, 6);
|
ws_b(user_data->client, cmd, 6);
|
||||||
uint8_t *ack = (uint8_t *)process(user_data, 1);
|
uint8_t *ack = (uint8_t *)process(user_data, 1);
|
||||||
if (!ack || !(*ack))
|
if (!ack || !(*ack))
|
||||||
@ -294,8 +296,8 @@ static rfbBool resize(rfbClient *client)
|
|||||||
static void update(rfbClient *client, int x, int y, int w, int h)
|
static void update(rfbClient *client, int x, int y, int w, int h)
|
||||||
{
|
{
|
||||||
wvnc_user_data_t *user_data = get_user_data(rfbClientGetClientData(client, identify()));
|
wvnc_user_data_t *user_data = get_user_data(rfbClientGetClientData(client, identify()));
|
||||||
uint8_t bbp = (uint8_t)client->format.bitsPerPixel / 8;
|
uint8_t components = (uint8_t)client->format.bitsPerPixel / 8;
|
||||||
int size = w * h * bbp;
|
int size = w * h * components;
|
||||||
uint8_t *cmd = (uint8_t *)malloc(size + 10); // + 9
|
uint8_t *cmd = (uint8_t *)malloc(size + 10); // + 9
|
||||||
uint8_t *tmp = cmd + 10;
|
uint8_t *tmp = cmd + 10;
|
||||||
uint8_t flag = 0;
|
uint8_t flag = 0;
|
||||||
@ -316,12 +318,12 @@ static void update(rfbClient *client, int x, int y, int w, int h)
|
|||||||
int cw = client->width;
|
int cw = client->width;
|
||||||
for (int j = y; j < y + h; j++)
|
for (int j = y; j < y + h; j++)
|
||||||
{
|
{
|
||||||
src_ptr = client->frameBuffer + (j * cw * bbp + x * bbp);
|
src_ptr = client->frameBuffer + (j * cw * components + x * components);
|
||||||
memcpy(dest_ptr, src_ptr, w * bbp);
|
memcpy(dest_ptr, src_ptr, w * components);
|
||||||
if (bbp == 4)
|
if (components == 4)
|
||||||
for (int i = bbp - 1; i < w * bbp; i += bbp)
|
for (int i = components - 1; i < w * components; i += components)
|
||||||
dest_ptr[i] = 255;
|
dest_ptr[i] = 255;
|
||||||
dest_ptr += w * bbp;
|
dest_ptr += w * components;
|
||||||
}
|
}
|
||||||
cmd[0] = 0x84; //update command
|
cmd[0] = 0x84; //update command
|
||||||
cmd[1] = (uint8_t)(x & 0xFF);
|
cmd[1] = (uint8_t)(x & 0xFF);
|
||||||
@ -334,9 +336,9 @@ static void update(rfbClient *client, int x, int y, int w, int h)
|
|||||||
cmd[8] = (uint8_t)(h >> 8);
|
cmd[8] = (uint8_t)(h >> 8);
|
||||||
|
|
||||||
#ifdef USE_JPEG
|
#ifdef USE_JPEG
|
||||||
if(bbp == 3 || bbp == 4)
|
if((components == 3 || components == 4) && (user_data->flag ==1 || user_data->flag == 3))
|
||||||
{
|
{
|
||||||
int ret = jpeg_compress(tmp, w, h, bbp);
|
int ret = jpeg_compress(tmp, w, h, components);
|
||||||
if(ret > 0)
|
if(ret > 0)
|
||||||
{
|
{
|
||||||
flag |= 0x01;
|
flag |= 0x01;
|
||||||
@ -346,8 +348,11 @@ static void update(rfbClient *client, int x, int y, int w, int h)
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_ZLIB
|
#ifdef USE_ZLIB
|
||||||
|
if(user_data->flag >= 2)
|
||||||
|
{
|
||||||
flag |= 0x02;
|
flag |= 0x02;
|
||||||
size = zlib_compress(tmp, size);
|
size = zlib_compress(tmp, size);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
cmd[9] = flag;
|
cmd[9] = flag;
|
||||||
ws_b(user_data->client, cmd, size + 10);
|
ws_b(user_data->client, cmd, size + 10);
|
||||||
@ -423,6 +428,11 @@ void open_session(void *data, const char *addr)
|
|||||||
argv[0] = "-listennofork";
|
argv[0] = "-listennofork";
|
||||||
argv[1] = (char *)addr;
|
argv[1] = (char *)addr;
|
||||||
wvnc_user_data_t *user_data = get_user_data(data);
|
wvnc_user_data_t *user_data = get_user_data(data);
|
||||||
|
LOG("client.BBP: %d\n", user_data->bbp );
|
||||||
|
LOG("client.flag: %d\n", user_data->flag );
|
||||||
|
LOG("client.JPEG.quality: %d\n", user_data->quality );
|
||||||
|
LOG("Server: %s\n", addr);
|
||||||
|
LOG("Rate is %d\n", user_data->rate);
|
||||||
if (!rfbInitClient(user_data->vncl, &argc, argv))
|
if (!rfbInitClient(user_data->vncl, &argc, argv))
|
||||||
{
|
{
|
||||||
user_data->vncl = NULL; /* rfbInitClient has already freed the client struct */
|
user_data->vncl = NULL; /* rfbInitClient has already freed the client struct */
|
||||||
@ -440,7 +450,7 @@ void open_session(void *data, const char *addr)
|
|||||||
}
|
}
|
||||||
process(user_data, 0);
|
process(user_data, 0);
|
||||||
//LOG("ENd process \n");
|
//LOG("ENd process \n");
|
||||||
int status = WaitForMessage(user_data->vncl, 500); //500
|
int status = WaitForMessage(user_data->vncl, user_data->rate); //500
|
||||||
if (status < 0)
|
if (status < 0)
|
||||||
{
|
{
|
||||||
if (user_data->vncl)
|
if (user_data->vncl)
|
||||||
@ -495,7 +505,11 @@ void *consume_client(void *ptr, wvnc_cmd_t header)
|
|||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
case 0x01: /*client open a connection*/
|
case 0x01: /*client open a connection*/
|
||||||
open_session(user_data, (char *)header.data);
|
user_data->bbp = header.data[0];
|
||||||
|
user_data->flag = header.data[1];
|
||||||
|
user_data->quality = header.data[2];
|
||||||
|
user_data->rate = (header.data[3] | (header.data[4] << 8))*1000;
|
||||||
|
open_session(user_data, (char *)(header.data + 5));
|
||||||
break;
|
break;
|
||||||
case 0x02: //client enter a vnc password
|
case 0x02: //client enter a vnc password
|
||||||
if (!header.data)
|
if (!header.data)
|
||||||
@ -512,8 +526,13 @@ void *consume_client(void *ptr, wvnc_cmd_t header)
|
|||||||
return data;
|
return data;
|
||||||
break;
|
break;
|
||||||
case 0x05: //mouse event
|
case 0x05: //mouse event
|
||||||
|
//LOG("MOuse event %d\n", header.data[4]);
|
||||||
SendPointerEvent(user_data->vncl, header.data[0] | (header.data[1] << 8), header.data[2] | (header.data[3] << 8), header.data[4]);
|
SendPointerEvent(user_data->vncl, header.data[0] | (header.data[1] << 8), header.data[2] | (header.data[3] << 8), header.data[4]);
|
||||||
break;
|
break;
|
||||||
|
case 0x06: // key board event
|
||||||
|
//LOG("Key is %c\n", header.data[0]);
|
||||||
|
SendKeyEvent(user_data->vncl, header.data[0], header.data[1]?TRUE:FALSE);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return vnc_fatal(user_data, "Unknown client command");
|
return vnc_fatal(user_data, "Unknown client command");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user