1 // -*-c++-*- 2 3 /* 4 * Copyright (C) 2004 Stephan Huber http://digitalmind.de 5 * 6 * The Open Scene Graph (OSG) is a cross platform C++/OpenGL library for 7 * real-time rendering of large 3D photo-realistic models. 8 * The OSG homepage is http://www.openscenegraph.org/ 9 * 10 * This software is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License as published by 12 * the Free Software Foundation; either version 2 of the License, or 13 * (at your option) any later version. 14 * 15 * This software is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with this program; if not, write to the Free Software 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 */ 24 25 #ifndef _QUICKTIMEIMAGESTREAM_H_ 26 #define _QUICKTIMEIMAGESTREAM_H_ 27 28 #include <osg/ImageStream> 29 30 #include <OpenThreads/Thread> 31 #include <OpenThreads/Mutex> 32 33 #define NUM_CMD_INDEX 20 34 35 36 37 class MovieData; 38 39 /** 40 * Quicktime Image Stream class. streams a quicktime movie into an image 41 */ 42 class QuicktimeImageStream : public osg::ImageStream, public OpenThreads::Thread 43 { 44 public: 45 /** Constructor 46 * @param fileName movie to open */ 47 QuicktimeImageStream(std::string fileName = ""); clone()48 virtual Object* clone() const { return new QuicktimeImageStream; } isSameKindAs(const Object * obj)49 virtual bool isSameKindAs(const Object* obj) const { 50 return dynamic_cast<const QuicktimeImageStream*>(obj) != NULL; 51 } 52 className()53 virtual const char* className() const { return "QuicktimeImageStream"; } 54 55 /// Start or continue stream. play()56 virtual void play() 57 { 58 if (!isRunning()) start(); 59 60 setCmd(THREAD_START); 61 62 // ricky 63 _status = ImageStream::PLAYING; 64 } 65 66 /// sets the movierate of this movie setMovieRate(float rate)67 void setMovieRate(float rate) { 68 if (!isRunning()) start(); 69 setCmd(THREAD_SETRATE,rate); 70 } 71 72 /// Pause stream at current position. pause()73 virtual void pause() 74 { 75 setCmd(THREAD_STOP); 76 // ricky 77 _status = ImageStream::PAUSED; 78 } 79 80 /// Rewind stream to beginning. rewind()81 virtual void rewind() { setCmd(THREAD_REWIND); } 82 83 /// forward stream to the end forward()84 virtual void forward() { setCmd(THREAD_FORWARD); } 85 86 /// stop playing 87 virtual void quit(bool wiatForThreadToExit); 88 89 /// Get total length in seconds. getLength()90 virtual double getLength() const 91 { 92 return double(_len); 93 } 94 95 /// jumps to a specific position jumpTo(double pos)96 void jumpTo(double pos) { 97 setCmd(THREAD_SEEK, pos); 98 } 99 100 /// returns the current playing position getCurrentTime()101 virtual double getCurrentTime() const { return _current; } 102 103 /// @return the current moviedata-object getMovieData()104 MovieData* getMovieData() { return _movieData; } 105 106 /// loads a movie from fileName 107 void load(std::string fileName); 108 109 /// starts the thread 110 virtual void run(); 111 112 /// Go to a specific position in the stream. setReferenceTime(double time)113 virtual void setReferenceTime(double time) 114 { 115 jumpTo(time); 116 } 117 /// Return the current position in the stream. getReferenceTime()118 virtual double getReferenceTime() const 119 { 120 return double(getCurrentTime()); 121 } 122 123 // Set the time multiplier if you want to speed up, 124 // slow down, or go normal speed. setTimeMultiplier(double multiplier)125 virtual void setTimeMultiplier(double multiplier) 126 { 127 setMovieRate(multiplier); 128 } 129 getTimeMultiplier()130 virtual double getTimeMultiplier() 131 { 132 return 0.0; 133 } 134 135 // Get and Set the playback volume of the stream. 136 virtual void setVolume(float volume); 137 virtual float getVolume() const; 138 139 140 protected: 141 /// apply the looping mode to quicktime 142 virtual void applyLoopingMode(); 143 /// destructor 144 virtual ~QuicktimeImageStream(); 145 146 private: 147 double _lastUpdate; 148 double _len; 149 double _current; 150 double _currentRate; 151 152 MovieData* _movieData; 153 154 enum ThreadCommand { 155 THREAD_IDLE = 0, 156 THREAD_START, 157 THREAD_STOP, 158 THREAD_REWIND, 159 THREAD_FORWARD, 160 THREAD_SEEK, 161 THREAD_SETRATE, 162 THREAD_CLOSE, 163 THREAD_QUIT 164 }; 165 ThreadCommand _cmd[NUM_CMD_INDEX]; 166 double _rates[NUM_CMD_INDEX]; 167 int _wrIndex, _rdIndex; 168 169 OpenThreads::Mutex _mutex; 170 171 /// Set command. 172 void setCmd(ThreadCommand cmd, double rate = 0.0); 173 174 /// Get command. 175 ThreadCommand getCmd(); 176 177 // ricky 178 static int _qtInstanceCount; 179 }; 180 181 182 #endif 183