35 |
#endif |
#endif |
36 |
#endif |
#endif |
37 |
|
|
38 |
|
#include <jpeglib.h> |
39 |
|
/* DJ globals begin */ |
40 |
|
extern unsigned long long g_time_last_write; |
41 |
|
extern unsigned long long g_time_last_change; |
42 |
|
extern uint32 g_pixels_changed; |
43 |
|
extern uint8 * g_bitmap_data; |
44 |
|
extern uint8 * g_bitmap_data_last_write; |
45 |
|
/* DJ globals end */ |
46 |
|
/* DJ tuning knobs begin */ |
47 |
|
const uint32 PIXELS_CHANGED_THRESHOLD = 8192; /* this many pixel changes */ |
48 |
|
const uint32 PIXELS_STABILIZE_DELAY = 100000; /* no change for .1 sec */ |
49 |
|
const uint32 PIXELS_RESET_INTERVAL = 10000000; /* within 10 second interval */ |
50 |
|
const uint32 MINIMUM_WRITE_INTERVAL = 1000000; /* and 1 sec from last write */ |
51 |
|
/* DJ tuning knobs end */ |
52 |
|
|
53 |
extern uint16 g_mcs_userid; |
extern uint16 g_mcs_userid; |
54 |
extern char *g_username; |
extern char *g_username; |
55 |
extern char g_codepage[16]; |
extern char g_codepage[16]; |
91 |
static RD_BOOL g_iconv_works = True; |
static RD_BOOL g_iconv_works = True; |
92 |
#endif |
#endif |
93 |
|
|
94 |
|
unsigned long long |
95 |
|
tod(void) |
96 |
|
{ |
97 |
|
struct timeval tim; |
98 |
|
unsigned long long ret; |
99 |
|
gettimeofday(&tim, NULL); |
100 |
|
ret=tim.tv_sec; |
101 |
|
ret*=1000000; |
102 |
|
ret+=tim.tv_usec; |
103 |
|
return ret; |
104 |
|
} |
105 |
|
|
106 |
/* Receive an RDP packet */ |
/* Receive an RDP packet */ |
107 |
static STREAM |
static STREAM |
108 |
rdp_recv(uint8 * type) |
rdp_recv(uint8 * type) |
110 |
static STREAM rdp_s; |
static STREAM rdp_s; |
111 |
uint16 length, pdu_type; |
uint16 length, pdu_type; |
112 |
uint8 rdpver; |
uint8 rdpver; |
113 |
|
unsigned long long current_time; |
114 |
|
|
115 |
if ((rdp_s == NULL) || (g_next_packet >= rdp_s->end) || (g_next_packet == NULL)) |
if ((rdp_s == NULL) || (g_next_packet >= rdp_s->end) || (g_next_packet == NULL)) |
116 |
{ |
{ |
117 |
rdp_s = sec_recv(&rdpver); |
rdp_s = sec_recv(&rdpver); |
118 |
|
current_time = tod(); |
119 |
|
|
120 |
|
if (g_pixels_changed >= PIXELS_CHANGED_THRESHOLD) |
121 |
|
{ |
122 |
|
if ((current_time - g_time_last_change) < PIXELS_STABILIZE_DELAY) |
123 |
|
{ |
124 |
|
printf("%llu still unstable\n", current_time); |
125 |
|
} |
126 |
|
else if ((current_time - g_time_last_write) < MINIMUM_WRITE_INTERVAL) |
127 |
|
{ |
128 |
|
printf("%llu too close to last write\n", current_time); |
129 |
|
} |
130 |
|
else |
131 |
|
write_file(); |
132 |
|
} |
133 |
|
else if ((current_time - g_time_last_write) > PIXELS_RESET_INTERVAL && g_bitmap_data) |
134 |
|
{ |
135 |
|
memcpy(g_bitmap_data_last_write, g_bitmap_data, g_width * g_height * 3); |
136 |
|
printf("reset at g_pixels_changed=%d\n",g_pixels_changed); |
137 |
|
g_pixels_changed=0; |
138 |
|
g_time_last_write = current_time; |
139 |
|
} |
140 |
|
|
141 |
if (rdp_s == NULL) |
if (rdp_s == NULL) |
142 |
return NULL; |
return NULL; |
143 |
if (rdpver == 0xff) |
if (rdpver == 0xff) |
960 |
g_use_rdp5 = False; |
g_use_rdp5 = False; |
961 |
} |
} |
962 |
|
|
963 |
|
|
964 |
|
void |
965 |
|
write_file(void) |
966 |
|
{ |
967 |
|
struct tm time_info; |
968 |
|
time_t time_seconds; |
969 |
|
char fname[4096]; |
970 |
|
uint32 divisor = 1000000000; |
971 |
|
char *c = fname + 25; |
972 |
|
|
973 |
|
/* as found in libjpeg sample */ |
974 |
|
struct jpeg_compress_struct cinfo; |
975 |
|
struct jpeg_error_mgr jerr; |
976 |
|
JSAMPROW row_pointer[1]; |
977 |
|
FILE *outfile; |
978 |
|
|
979 |
|
if (!g_pixels_changed) /* no change, no write */ |
980 |
|
return; |
981 |
|
|
982 |
|
time_seconds = (time_t) (g_time_last_change / 1000000); |
983 |
|
localtime_r(&time_seconds, &time_info); |
984 |
|
strftime((char *) fname, 4096, "/tmp/%Y-%m-%d %H:%M:%S ", &time_info); |
985 |
|
|
986 |
|
while (!((g_pixels_changed / divisor) % 10) && (divisor/=10) >1 ); |
987 |
|
|
988 |
|
do |
989 |
|
{ |
990 |
|
*c++ = '0' + (char) ((g_pixels_changed / divisor) % 10); |
991 |
|
} |
992 |
|
while ((divisor/=10) >= 1); |
993 |
|
|
994 |
|
*c = 0; |
995 |
|
|
996 |
|
strncat(fname, ".jpg", 4096); |
997 |
|
|
998 |
|
outfile = fopen(fname, "wb"); |
999 |
|
if (!outfile) |
1000 |
|
{ |
1001 |
|
error("can\'t open file %s for write\n", fname); |
1002 |
|
exit(1); |
1003 |
|
} |
1004 |
|
cinfo.err = jpeg_std_error(&jerr); |
1005 |
|
jpeg_create_compress(&cinfo); |
1006 |
|
jpeg_stdio_dest(&cinfo, outfile); |
1007 |
|
cinfo.image_width = g_width; |
1008 |
|
cinfo.image_height = g_height; |
1009 |
|
cinfo.input_components = 3; /* 3 bytes per pixel, R G B */ |
1010 |
|
cinfo.in_color_space = JCS_RGB; |
1011 |
|
jpeg_set_defaults(&cinfo); |
1012 |
|
jpeg_start_compress(&cinfo, TRUE); |
1013 |
|
while (cinfo.next_scanline < cinfo.image_height) |
1014 |
|
{ |
1015 |
|
row_pointer[0] = &g_bitmap_data[cinfo.next_scanline * cinfo.image_width * 3]; |
1016 |
|
jpeg_write_scanlines(&cinfo, row_pointer, 1); |
1017 |
|
} |
1018 |
|
jpeg_finish_compress(&cinfo); |
1019 |
|
jpeg_destroy_compress(&cinfo); |
1020 |
|
fclose(outfile); |
1021 |
|
|
1022 |
|
g_time_last_write = tod(); |
1023 |
|
printf("%llu (%u) write_file %s\n", g_time_last_write, g_pixels_changed, fname); |
1024 |
|
memcpy(g_bitmap_data_last_write, g_bitmap_data, g_width * g_height * 3); |
1025 |
|
g_pixels_changed = 0; |
1026 |
|
} |
1027 |
|
|
1028 |
/* Process a bitmap capability set */ |
/* Process a bitmap capability set */ |
1029 |
static void |
static void |
1030 |
rdp_process_bitmap_caps(STREAM s) |
rdp_process_bitmap_caps(STREAM s) |
1039 |
|
|
1040 |
DEBUG(("setting desktop size and depth to: %dx%dx%d\n", width, height, depth)); |
DEBUG(("setting desktop size and depth to: %dx%dx%d\n", width, height, depth)); |
1041 |
|
|
1042 |
|
if (g_bitmap_data) |
1043 |
|
{ |
1044 |
|
/* resolution change, force write of old screen |
1045 |
|
g_time_last_change = tod(); |
1046 |
|
write_file(); |
1047 |
|
*/ |
1048 |
|
xfree(g_bitmap_data); |
1049 |
|
xfree(g_bitmap_data_last_write); |
1050 |
|
} |
1051 |
|
g_bitmap_data = (uint8 *) xmalloc(width * height * 3); |
1052 |
|
g_bitmap_data_last_write = (uint8 *) xmalloc(width * height * 3); |
1053 |
|
bzero(g_bitmap_data, width * height * 3); |
1054 |
|
bzero(g_bitmap_data_last_write, width * height * 3); |
1055 |
|
g_pixels_changed = 0; |
1056 |
|
|
1057 |
/* |
/* |
1058 |
* The server may limit depth and change the size of the desktop (for |
* The server may limit depth and change the size of the desktop (for |
1059 |
* example when shadowing another session). |
* example when shadowing another session). |