Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 1 | /* 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 | |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 25 | #include <rfbplayer/resource.h> |
george82 | e09819b | 2005-09-04 10:41:50 +0000 | [diff] [blame] | 26 | #include <rfbplayer/PixelFormatList.h> |
| 27 | #include <rfbplayer/PlayerToolBar.h> |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 28 | #include <rfbplayer/OptionsDialog.h> |
george82 | e09819b | 2005-09-04 10:41:50 +0000 | [diff] [blame] | 29 | #include <rfbplayer/rfbSessionReader.h> |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 30 | |
| 31 | using namespace rfb; |
| 32 | using namespace rfb::win32; |
| 33 | |
george82 | e09819b | 2005-09-04 10:41:50 +0000 | [diff] [blame] | 34 | class PlayerToolBar; |
| 35 | |
george82 | b491543 | 2005-01-30 17:10:57 +0000 | [diff] [blame] | 36 | class RfbPlayer : public RfbProto { |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 37 | public: |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 38 | RfbPlayer(char *fileName, PlayerOptions *options); |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 39 | ~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;} |
george82 | a21d295 | 2005-02-12 11:30:03 +0000 | [diff] [blame] | 50 | void disableTBandMenuItems(); |
george82 | f504316 | 2005-02-12 11:37:18 +0000 | [diff] [blame] | 51 | void enableTBandMenuItems(); |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 52 | 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); |
george82 | ee45579 | 2005-04-13 12:56:15 +0000 | [diff] [blame] | 57 | void init(); |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 58 | |
| 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 | |
george82 | 23e0856 | 2005-01-31 15:16:42 +0000 | [diff] [blame] | 97 | virtual void processMsg(); |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 98 | 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 Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 110 | // -=- Player functions |
| 111 | |
george82 | 57f1352 | 2005-02-05 08:48:22 +0000 | [diff] [blame] | 112 | // calculateSessionTime() calculates the full session time in sec |
| 113 | long calculateSessionTime(char *fileName); |
| 114 | |
george82 | 6b87aff | 2005-02-13 10:48:21 +0000 | [diff] [blame] | 115 | // closeSessionFile() closes the session file and blanks the frame buffer |
| 116 | void closeSessionFile(); |
| 117 | |
george82 | 17e92cb | 2005-01-31 16:01:02 +0000 | [diff] [blame] | 118 | // openSessionFile() opens the new session file and starts play it |
| 119 | void openSessionFile(char *fileName); |
| 120 | |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 121 | // 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); |
george82 | 006f279 | 2005-02-05 07:40:47 +0000 | [diff] [blame] | 128 | void stopPlayback(); |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 129 | 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 | |
george82 | 0d2e19d | 2005-03-03 15:47:55 +0000 | [diff] [blame] | 138 | protected: |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 139 | bool seekMode; |
george82 | 0d2e19d | 2005-03-03 15:47:55 +0000 | [diff] [blame] | 140 | bool stopped; |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 141 | long lastPos; |
george82 | 8a47148 | 2005-02-06 07:15:53 +0000 | [diff] [blame] | 142 | long sliderStepMs; |
george82 | 3c8fbbf | 2005-01-24 11:09:08 +0000 | [diff] [blame] | 143 | char fullSessionTime[20]; |
| 144 | int time_pos_m; |
| 145 | int time_pos_s; |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 146 | char *fileName; |
george82 | 3c8fbbf | 2005-01-24 11:09:08 +0000 | [diff] [blame] | 147 | |
george82 | ce8dc3a | 2005-01-31 13:06:54 +0000 | [diff] [blame] | 148 | // rfbReader is a class which used to reading the rfb data from the file |
| 149 | rfbSessionReader *rfbReader; |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 150 | |
| 151 | // Returns true if part of the supplied rect is visible, false otherwise |
| 152 | bool invalidateBufferRect(const Rect& crect); |
| 153 | |
george82 | 0d2e19d | 2005-03-03 15:47:55 +0000 | [diff] [blame] | 154 | bool waitWhilePaused(); |
| 155 | |
george82 | 1e846ff | 2005-02-24 13:13:33 +0000 | [diff] [blame] | 156 | // rewindFlag is a flag wich disable the update of the frame buffer window |
| 157 | // while the rewind is performing. |
| 158 | bool rewindFlag; |
george82 | 0d2e19d | 2005-03-03 15:47:55 +0000 | [diff] [blame] | 159 | |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 160 | // Local window state |
| 161 | HWND mainHwnd; |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 162 | HWND frameHwnd; |
george82 | 006f279 | 2005-02-05 07:40:47 +0000 | [diff] [blame] | 163 | HMENU hMenu; |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 164 | Rect window_size; |
| 165 | Rect client_size; |
| 166 | Point scrolloffset; |
| 167 | Point maxscrolloffset; |
| 168 | char *cutText; |
| 169 | win32::DIBSectionBuffer* buffer; |
george82 | e09819b | 2005-09-04 10:41:50 +0000 | [diff] [blame] | 170 | PlayerToolBar tb; |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 171 | |
| 172 | // The player's parameters |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 173 | PlayerOptions options; |
george82 | 0981b34 | 2005-03-19 11:19:00 +0000 | [diff] [blame] | 174 | PixelFormatList supportedPF; |
george82 | b95503e | 2005-02-21 17:02:34 +0000 | [diff] [blame] | 175 | long imageDataStartTime; |
george82 | 8a47148 | 2005-02-06 07:15:53 +0000 | [diff] [blame] | 176 | long sessionTimeMs; |
george82 | 26af765 | 2005-04-13 12:46:25 +0000 | [diff] [blame] | 177 | int currentEncoding; |
Constantin Kaplinsky | fbfbb92 | 2004-11-14 18:28:51 +0000 | [diff] [blame] | 178 | }; |
george82 | f0e42de | 2005-03-10 18:00:41 +0000 | [diff] [blame] | 179 | |
| 180 | // -=- sessionTerminateThread class |
| 181 | |
| 182 | // It is a special thread class, wich is allow the rfbSessionReader class |
| 183 | // terminate itself. |
| 184 | |
| 185 | class sessionTerminateThread : public rfb::Thread { |
| 186 | public: |
| 187 | sessionTerminateThread(RfbPlayer *_player) : player(_player) { |
| 188 | setDeleteAfterRun(); |
| 189 | } |
| 190 | virtual void run() { |
| 191 | player->closeSessionFile(); |
| 192 | } |
| 193 | protected: |
| 194 | RfbPlayer *player; |
| 195 | }; |