Changed the threading part of rfbplayer. Now threading function included
to the rfbplayer class. It allows the rfbplayer members to manage the rfb data thread.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@99 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/rfbplayer/rfbplayer.cxx b/rfbplayer/rfbplayer.cxx
index 2687306..e2d0200 100644
--- a/rfbplayer/rfbplayer.cxx
+++ b/rfbplayer/rfbplayer.cxx
@@ -45,56 +45,6 @@
#define strcasecmp _stricmp
-// -=- Custom thread class used to reading the rfb data
-
-class CRfbThread : public Thread {
- public:
- CRfbThread(RfbPlayer *_player) {
- p = _player;
- setDeleteAfterRun();
- };
- ~CRfbThread() {};
-
- void run() {
- long initTime = -1;
-
- // Process the rfb messages
- while (p->run) {
- try {
- if (initTime >= 0) {
- p->setPos(initTime);
- initTime = -1;
- }
- if (!p->isSeeking())
- p->updatePos();
- p->processMsg();
- } catch (rdr::Exception e) {
- if (strcmp(e.str(), "[End Of File]") == 0) {
- p->rewind();
- p->setPaused(true);
- continue;
- }
- // It's a special exception to perform backward seeking.
- // We only rewind the stream and seek the offset
- if (strcmp(e.str(), "[REWIND]") == 0) {
- initTime = p->getSeekOffset();
- double speed = p->getSpeed();
- bool play = !p->isPaused();
- p->rewind();
- p->setSpeed(speed);
- p->setPaused(!play);
- } else {
- MessageBox(p->getMainHandle(), e.str(), e.type(), MB_OK | MB_ICONERROR);
- return;
- }
- }
- }
- }
-
- private:
- RfbPlayer *p;
-};
-
//
// -=- RfbPlayerClass
@@ -117,7 +67,7 @@
SetWindowLong(hwnd, GWL_USERDATA, (long)((CREATESTRUCT*)lParam)->lpCreateParams);
else if (msg == WM_DESTROY) {
RfbPlayer* _this = (RfbPlayer*) GetWindowLong(hwnd, GWL_USERDATA);
- _this->run = false;
+ _this->fRun = false;
// Resume playback (It's need to quit from FbsInputStream::waitWhilePaused())
_this->setPaused(false);
@@ -241,7 +191,7 @@
bool _acceptBell = false)
: RfbProto(_fileName), initTime(_initTime), playbackSpeed(_playbackSpeed),
autoplay(_autoplay), showControls(_showControls), buffer(0), client_size(0, 0, 32, 32),
- window_size(0, 0, 32, 32), cutText(0), seekMode(false), fileName(_fileName), run(true),
+ window_size(0, 0, 32, 32), cutText(0), seekMode(false), fileName(_fileName), fRun(true),
serverInitTime(0), btnStart(0), txtPos(0), editPos(0), txtSpeed(0), editSpeed(0),
lastPos(0), acceptBell(_acceptBell) {
@@ -426,6 +376,42 @@
return DefWindowProc(hwnd, msg, wParam, lParam);
}
+void RfbPlayer::run() {
+ long initTime = -1;
+
+ // Process the rfb messages
+ while (fRun) {
+ try {
+ if (initTime >= 0) {
+ setPos(initTime);
+ initTime = -1;
+ }
+ if (!isSeeking())
+ updatePos();
+ processMsg();
+ } catch (rdr::Exception e) {
+ if (strcmp(e.str(), "[End Of File]") == 0) {
+ rewind();
+ setPaused(true);
+ continue;
+ }
+ // It's a special exception to perform backward seeking.
+ // We only rewind the stream and seek the offset
+ if (strcmp(e.str(), "[REWIND]") == 0) {
+ initTime = getSeekOffset();
+ double speed = getSpeed();
+ bool play = !isPaused();
+ rewind();
+ setSpeed(speed);
+ setPaused(!play);
+ } else {
+ MessageBox(getMainHandle(), e.str(), e.type(), MB_OK | MB_ICONERROR);
+ return;
+ }
+ }
+ }
+}
+
void RfbPlayer::setOptions(long _initTime = 0, double _playbackSpeed = 1.0,
bool _autoplay = false, bool _showControls = true) {
showControls = _showControls;
@@ -857,16 +843,14 @@
FreeConsole();
return 0;
- }
+ }
// Create the player and the thread which reading the rfb data
RfbPlayer *player = NULL;
- CRfbThread *rfbThread = NULL;
try {
player = new RfbPlayer(fileName, initTime, playbackSpeed, autoplay,
showControls, acceptBell);
- rfbThread = new CRfbThread(player);
- rfbThread->start();
+ player->start();
} catch (rdr::Exception e) {
MessageBox(NULL, e.str(), e.type(), MB_OK | MB_ICONERROR);
delete player;
@@ -885,7 +869,7 @@
// Wait while the thread destroying and then destroy the player
try{
- while (rfbThread->getState() == ThreadStarted) {}
+ while (player->getState() == ThreadStarted) {}
if (player) delete player;
} catch (rdr::Exception e) {
MessageBox(NULL, e.str(), e.type(), MB_OK | MB_ICONERROR);