blob: c5c5da8d66261cd89c1f299e214f0da62b637e9c [file] [log] [blame]
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +00001/* Copyright (C) 2004 TightVNC Team. All Rights Reserved.
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18
19// -=- RfbPlayer.h
20
21#include <windows.h>
22
23#include <rfb_win32/DIBSectionBuffer.h>
24
george825e7af742005-03-10 14:26:00 +000025#include <rfbplayer/resource.h>
george82e09819b2005-09-04 10:41:50 +000026#include <rfbplayer/PixelFormatList.h>
27#include <rfbplayer/PlayerToolBar.h>
george825e7af742005-03-10 14:26:00 +000028#include <rfbplayer/OptionsDialog.h>
george82e09819b2005-09-04 10:41:50 +000029#include <rfbplayer/rfbSessionReader.h>
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +000030
31using namespace rfb;
32using namespace rfb::win32;
33
george82e09819b2005-09-04 10:41:50 +000034class PlayerToolBar;
35
george82b4915432005-01-30 17:10:57 +000036class RfbPlayer : public RfbProto {
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +000037 public:
george825e7af742005-03-10 14:26:00 +000038 RfbPlayer(char *fileName, PlayerOptions *options);
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +000039 ~RfbPlayer();
40
41 // -=- Window Message handling
42
43 LRESULT processMainMessage(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam);
44 LRESULT processFrameMessage(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam);
45
46 // -=- Window interface
47
48 HWND getMainHandle() const {return mainHwnd;}
49 HWND getFrameHandle() const {return frameHwnd;}
george82a21d2952005-02-12 11:30:03 +000050 void disableTBandMenuItems();
george82f5043162005-02-12 11:37:18 +000051 void enableTBandMenuItems();
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +000052 void setFrameSize(int width, int height);
53 void setVisible(bool visible);
54 void setTitle(const char *title);
55 void calculateScrollBars();
56 void close(const char* reason=0);
george82ee455792005-04-13 12:56:15 +000057 void init();
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +000058
59 // -=- Coordinate conversions
60
61 inline Point bufferToClient(const Point& p) {
62 Point pos = p;
63 if (client_size.width() > buffer->width())
64 pos.x += (client_size.width() - buffer->width()) / 2;
65 else if (client_size.width() < buffer->width())
66 pos.x -= scrolloffset.x;
67 if (client_size.height() > buffer->height())
68 pos.y += (client_size.height() - buffer->height()) / 2;
69 else if (client_size.height() < buffer->height())
70 pos.y -= scrolloffset.y;
71 return pos;
72 }
73 inline Rect bufferToClient(const Rect& r) {
74 return Rect(bufferToClient(r.tl), bufferToClient(r.br));
75 }
76
77 inline Point clientToBuffer(const Point& p) {
78 Point pos = p;
79 if (client_size.width() > buffer->width())
80 pos.x -= (client_size.width() - buffer->width()) / 2;
81 else if (client_size.width() < buffer->width())
82 pos.x += scrolloffset.x;
83 if (client_size.height() > buffer->height())
84 pos.y -= (client_size.height() - buffer->height()) / 2;
85 else if (client_size.height() < buffer->height())
86 pos.y += scrolloffset.y;
87 return pos;
88 }
89 inline Rect clientToBuffer(const Rect& r) {
90 return Rect(clientToBuffer(r.tl), clientToBuffer(r.br));
91 }
92
93 bool setViewportOffset(const Point& tl);
94
95 // -=- RfbProto interface overrides
96
george8223e08562005-01-31 15:16:42 +000097 virtual void processMsg();
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +000098 virtual void serverInit();
99 virtual void frameBufferUpdateEnd();
100 virtual void setColourMapEntries(int first, int count, U16* rgbs);
101 virtual void serverCutText(const char* str, int len);
102 virtual void bell();
103
104 virtual void beginRect(const Rect& r, unsigned int encoding);
105 virtual void endRect(const Rect& r, unsigned int encoding);
106 virtual void fillRect(const Rect& r, Pixel pix);
107 virtual void imageRect(const Rect& r, void* pixels);
108 virtual void copyRect(const Rect& r, int srcX, int srcY);
109
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000110 // -=- Player functions
111
george8257f13522005-02-05 08:48:22 +0000112 // calculateSessionTime() calculates the full session time in sec
113 long calculateSessionTime(char *fileName);
114
george826b87aff2005-02-13 10:48:21 +0000115 // closeSessionFile() closes the session file and blanks the frame buffer
116 void closeSessionFile();
117
george8217e92cb2005-01-31 16:01:02 +0000118 // openSessionFile() opens the new session file and starts play it
119 void openSessionFile(char *fileName);
120
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000121 // skipHandshaking() - is implemented to skip the initial handshaking when
122 // perform backward seeking OR replaying.
123 void skipHandshaking();
124
125 void blankBuffer();
126 void rewind();
127 void setPaused(bool paused);
george82006f2792005-02-05 07:40:47 +0000128 void stopPlayback();
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000129 long getTimeOffset();
130 bool isSeekMode();
131 bool isSeeking();
132 bool isPaused();
133 long getSeekOffset();
134 void setPos(long pos);
135 void setSpeed(double speed);
136 double getSpeed();
137
george820d2e19d2005-03-03 15:47:55 +0000138 protected:
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000139 bool seekMode;
george820d2e19d2005-03-03 15:47:55 +0000140 bool stopped;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000141 long lastPos;
george828a471482005-02-06 07:15:53 +0000142 long sliderStepMs;
george823c8fbbf2005-01-24 11:09:08 +0000143 char fullSessionTime[20];
144 int time_pos_m;
145 int time_pos_s;
george825e7af742005-03-10 14:26:00 +0000146 char *fileName;
george823c8fbbf2005-01-24 11:09:08 +0000147
george82ce8dc3a2005-01-31 13:06:54 +0000148 // rfbReader is a class which used to reading the rfb data from the file
149 rfbSessionReader *rfbReader;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000150
151 // Returns true if part of the supplied rect is visible, false otherwise
152 bool invalidateBufferRect(const Rect& crect);
153
george820d2e19d2005-03-03 15:47:55 +0000154 bool waitWhilePaused();
155
george821e846ff2005-02-24 13:13:33 +0000156 // rewindFlag is a flag wich disable the update of the frame buffer window
157 // while the rewind is performing.
158 bool rewindFlag;
george820d2e19d2005-03-03 15:47:55 +0000159
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000160 // Local window state
161 HWND mainHwnd;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000162 HWND frameHwnd;
george82006f2792005-02-05 07:40:47 +0000163 HMENU hMenu;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000164 Rect window_size;
165 Rect client_size;
166 Point scrolloffset;
167 Point maxscrolloffset;
168 char *cutText;
169 win32::DIBSectionBuffer* buffer;
george82e09819b2005-09-04 10:41:50 +0000170 PlayerToolBar tb;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000171
172 // The player's parameters
george825e7af742005-03-10 14:26:00 +0000173 PlayerOptions options;
george820981b342005-03-19 11:19:00 +0000174 PixelFormatList supportedPF;
george82b95503e2005-02-21 17:02:34 +0000175 long imageDataStartTime;
george828a471482005-02-06 07:15:53 +0000176 long sessionTimeMs;
george8226af7652005-04-13 12:46:25 +0000177 int currentEncoding;
Constantin Kaplinskyfbfbb922004-11-14 18:28:51 +0000178};
george82f0e42de2005-03-10 18:00:41 +0000179
180// -=- sessionTerminateThread class
181
182// It is a special thread class, wich is allow the rfbSessionReader class
183// terminate itself.
184
185class sessionTerminateThread : public rfb::Thread {
186public:
187 sessionTerminateThread(RfbPlayer *_player) : player(_player) {
188 setDeleteAfterRun();
189 }
190 virtual void run() {
191 player->closeSessionFile();
192 }
193protected:
194 RfbPlayer *player;
195};