00001
00002
00003
00004
00005
00006
00007
00008 #ifndef DisplayReplicator_Header
00009 #define DisplayReplicator_Header
00010
00011 #include "socket.h"
00012 #include "timer.h"
00013 #ifndef SGI
00014 #include "jpeg.h"
00015 #endif
00016
00017 #define MAX_BUF_SIZE (32 * 1024)
00018 #define UDP_QUEUE_SIZE (4 * 1024) // In Blocks
00019 #define PORT 1200
00020 #define SYSTEM_INFO_CODE 0xe0
00021 #define CHANNEL_REQUEST_CODE 0xf2
00022 #define ECG_CODE 0x02
00023 #define RESPIRATION_CODE 0x07
00024
00025 class DisplayReplicator {
00026 public:
00027 enum source_type {source_screen, source_memory};
00028
00029 DisplayReplicator(int port=1200, source_type source = source_screen);
00030 ~DisplayReplicator();
00031 static const char* rcsid;
00032 static int debug;
00033
00034 int NumConnections();
00035
00036 void Connect(char* server, bool switchboard = true, char channel = -1, char* optBuffer = NULL, bool blocking = true);
00037 void Listen();
00038 void Disconnect(int connection_to_kill);
00039 void Reshape(int w, int h);
00040 void InitHeader(int conf_width, int conf_height);
00041
00042
00043 void SendScreenUpdates(int which_buffer, void* data_in=NULL);
00044 void ReceiveScreenUpdate(int which_buffer, char* buf, int JPEG_size = 0);
00045 void Update(int nonblocking);
00046
00047
00048 enum compression_type {color_24bit, color_16bit, color_8bit, greyscale, JPEG};
00049 void setCompression(compression_type comp);
00050 void SetParams(int res_reduction, compression_type compression,
00051 int comparison_threshold, int from_win = 0);
00052 void GetParams(int* res_reduction_p, compression_type* compression_p,
00053 int* comparison_threshold_p);
00054 void setOrigin(int val) {from_windows = val;}
00055
00056
00057 void RegisterEventHandlers(void(*keyfn)(unsigned char,int,int),
00058 void(*specialfn)(int,int,int), void(*mousefn)(int,int,int,int),
00059 void (*motionfn)(int,int));
00060 void SendKeyEvent(char key, int x, int y);
00061 void SendSpecialKeyEvent(int key, int x, int y);
00062 void SendMouseEvent(int button, int state, int x, int y);
00063 void SendMotionEvent(int x, int y);
00064
00065
00066 void Menu();
00067
00068
00069 public:
00070 enum {unknown, sender, receiver} mode;
00071 source_type source;
00072 int port;
00073 int session_alive;
00074 int num_socks;
00075 Socket* sock[100];
00076 int width, height;
00077 void (*keyfn)(unsigned char,int,int);
00078 void (*specialfn)(int,int,int);
00079 void (*mousefn)(int,int,int,int);
00080 void (*motionfn)(int,int);
00081
00082
00083 int block_size;
00084 char* block;
00085 int buf_size;
00086 char* buf;
00087 char* g_buf;
00088 char* gl_buf;
00089 char* JPEG_data;
00090 char *mySocketBuffer;
00091 int curBufLen;
00092 #ifndef SGI
00093 #ifndef __APPLE__
00094 BYTE *WHeader;
00095 #endif // __APPLE__
00096 #endif
00097
00098
00099 int res_reduction;
00100 enum compression_type compression;
00101 int comparison_threshold;
00102 int comp_size;
00103 int from_windows;
00104
00105
00106 Timer global_timer;
00107
00108
00109 void PaintBlock(int which_buffer, char x, char y, char* data,
00110 bool paintAll = false);
00111 int SendBlock(int buf_code, int x, int y, char* block,
00112 int which_socket=-1, int is_a_resend=0,
00113 bool flushBuffer = true);
00114 void SendWholeScreen(int which_buffer, int i);
00115 void SendScreenRefresh(int sock_index);
00116 static void Connect_CB(int);
00117 static void Params_CB(int);
00118 int encode_block_into_buf(int buf_code, int x, int y, int seq_id,
00119 char* block);
00120 void decode_block_from_buf(int* buf_code_p, int* x_p, int* y_p,
00121 int* seq_id, char* block, int JPEG_size = 0);
00122 int send_buf_out_socket(int sock_index, int size, char *whichBuf = NULL);
00123 int compare_blocks(char* block1, char* block2);
00124 };
00125
00126 inline int DisplayReplicator::NumConnections()
00127 { return(num_socks); }
00128
00129
00130 inline void DisplayReplicator::GetParams(int* res_p, compression_type* ct_p,
00131 int* comp_p)
00132 {
00133 *res_p = res_reduction;
00134 *ct_p = compression;
00135 *comp_p = comparison_threshold;
00136 }
00137
00138 #endif
00139