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

Revision 3314, 2.9 kB (checked in by robert, 10 years ago)

Made the command buffer have 20 elements in it to protect against wrapping
around.

  • 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
35namespace osg {
36
37    class MovieData;
38
39    /**
40     * Quicktime Image Stream class.
41     */
42    class SG_EXPORT QuicktimeImageStream : public osg::ImageStream, public OpenThreads::Thread
43    {
44    public:
45        QuicktimeImageStream(std::string fileName = "");
46
47        virtual Object* clone() const { return new QuicktimeImageStream; }
48        virtual bool isSameKindAs(const Object* obj) const {
49            return dynamic_cast<const QuicktimeImageStream*>(obj) != NULL;
50        }
51        virtual const char* className() const { return "QuicktimeImageStream"; }
52
53        /// Start or continue stream.
54        virtual void play()
55        {
56            if (!isRunning()) start();
57           
58            setCmd(THREAD_START);
59        }
60
61        /// Pause stream at current position.
62        virtual void pause() { setCmd(THREAD_STOP); }
63
64        /// Rewind stream to beginning.
65        virtual void rewind() { setCmd(THREAD_REWIND); }
66
67        virtual void quit(bool wiatForThreadToExit);
68       
69        /// Get total length in seconds.
70        inline float getLength() const { return _len; }
71       
72        void load(std::string fileName);
73
74        virtual void run();
75
76    protected:
77        virtual ~QuicktimeImageStream();
78
79    private:
80        float _lastUpdate;
81        float _len;
82       
83        MovieData* _data;
84
85        enum ThreadCommand {
86            THREAD_IDLE = 0,
87            THREAD_START,
88            THREAD_STOP,
89            THREAD_REWIND,
90            THREAD_CLOSE,
91            THREAD_QUIT
92        };
93        ThreadCommand _cmd[NUM_CMD_INDEX];
94        int _wrIndex, _rdIndex;
95
96        OpenThreads::Mutex _mutex;
97
98        /// Set command.
99        void setCmd(ThreadCommand cmd);
100
101        /// Get command.
102        ThreadCommand getCmd();
103
104
105    };
106
107} // namespace
108
109#endif
Note: See TracBrowser for help on using the browser.