root/OpenSceneGraph/trunk/src/osgPlugins/quicktime/QuicktimeImageStream.h @ 13041

Revision 13041, 4.3 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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
37class MovieData;
38
39/**
40* Quicktime Image Stream class. streams a quicktime movie into an image
41*/
42class QuicktimeImageStream : public osg::ImageStream, public OpenThreads::Thread
43{
44public:
45   /** Constructor
46   * @param fileName movie to open */
47   QuicktimeImageStream(std::string fileName = "");
48   virtual Object* clone() const { return new QuicktimeImageStream; }
49   virtual bool isSameKindAs(const Object* obj) const {
50      return dynamic_cast<const QuicktimeImageStream*>(obj) != NULL;
51   }
52
53   virtual const char* className() const { return "QuicktimeImageStream"; }
54
55   /// Start or continue stream.
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
67   void setMovieRate(float rate) {
68      if (!isRunning()) start();
69      setCmd(THREAD_SETRATE,rate);
70   }
71
72   /// Pause stream at current position.
73   virtual void pause()
74   {
75      setCmd(THREAD_STOP);
76      // ricky
77      _status = ImageStream::PAUSED;
78   }
79
80   /// Rewind stream to beginning.
81   virtual void rewind() { setCmd(THREAD_REWIND); }
82
83   /// forward stream to the end
84   virtual void forward() { setCmd(THREAD_FORWARD); }
85
86   /// stop playing
87   virtual void quit(bool wiatForThreadToExit);
88
89   /// Get total length in seconds.
90   virtual double getLength() const
91   {
92     return double(_len);
93   }
94
95   /// jumps to a specific position
96   void jumpTo(double pos) {
97      setCmd(THREAD_SEEK, pos);
98   }
99
100   /// returns the current playing position
101   virtual double getCurrentTime() const { return _current; }
102
103   /// @return the current moviedata-object
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.
113   virtual void setReferenceTime(double time)
114   {
115     jumpTo(time);
116   }
117   /// Return the current position in the stream.
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.
125   virtual void setTimeMultiplier(double multiplier)
126   {
127     setMovieRate(multiplier);
128   }
129
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
140protected:
141   /// apply the looping mode to quicktime
142   virtual void applyLoopingMode();
143   /// destructor
144   virtual ~QuicktimeImageStream();
145
146private:
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
Note: See TracBrowser for help on using the browser.