root/OpenSceneGraph/trunk/src/osgPlugins/mpeg/MpegImageStream.h @ 3314

Revision 3314, 3.8 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) 2001 Ulrich Hertlein <u.hertlein@web.de>
5 *
6 * Uses libmpeg3 by Adam Williams
7 * See http://www.heroinewarrior.com
8 *
9 * The Open Scene Graph (OSG) is a cross platform C++/OpenGL library for
10 * real-time rendering of large 3D photo-realistic models.
11 * The OSG homepage is http://www.openscenegraph.org/
12 *
13 * This software is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This software is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 */
27
28#ifndef _MPEGIMAGESTREAM_H_
29#define _MPEGIMAGESTREAM_H_
30
31#include <osg/ImageStream>
32#include <osg/Notify>
33
34#include <OpenThreads/Thread>
35#include <OpenThreads/Mutex>
36
37#define NUM_CMD_INDEX 20
38
39namespace osg {
40
41    /**
42     * MPEG1/2 Image Stream class.
43     */
44    class SG_EXPORT MpegImageStream : public osg::ImageStream, public OpenThreads::Thread
45    {
46    public:
47        MpegImageStream(const char* fileName = NULL);
48
49        virtual Object* clone() const { return new MpegImageStream; }
50        virtual bool isSameKindAs(const Object* obj) const {
51            return dynamic_cast<const MpegImageStream*>(obj) != NULL;
52        }
53        virtual const char* className() const { return "MpegImageStream"; }
54
55        /// Start or continue stream.
56        virtual void play()
57        {
58            if (!isRunning()) start();
59           
60            osg::notify(osg::INFO)<<"Play video"<<this<<std::endl;
61
62            setCmd(THREAD_START);
63        }
64
65        /// Pause stream at current position.
66        virtual void pause()
67        {
68            osg::notify(osg::INFO)<<"Pause video"<<this<<std::endl;
69            setCmd(THREAD_STOP);
70        }
71
72        /// Rewind stream to beginning.
73        virtual void rewind()
74        {
75            osg::notify(osg::INFO)<<"Rewind video"<<this<<std::endl;
76            setCmd(THREAD_REWIND);
77        }
78
79        virtual void quit(bool wiatForThreadToExit);
80
81        /// Enable/disable MMX.
82        inline void enableMMX(bool b) { _useMMX = b; }
83
84        /**
85         * Set frame rate in fps.
86         * This is overwritten by the actual frame rate of the stream when
87         * it is opened.
88         */
89        inline void setFrameRate(float fps) { _fps = (fps < 0.0f ? 0.0f : fps); }
90
91        /// Get frame rate in fps.
92        inline float getFrameRate() const { return _fps; }
93
94        /// Get number of frames.
95        inline long getNumFrames() const { return _frames; }
96
97        /// Get total length in seconds.
98        inline float getLength() const { return _len; }
99       
100        void load(const char* fileName);
101
102        virtual void run();
103
104    protected:
105        virtual ~MpegImageStream();
106
107        bool _useMMX;
108        float _fps;
109        long _frames;
110        float _len;
111       
112        void swapData();
113
114        enum ThreadCommand {
115            THREAD_IDLE = 0,
116            THREAD_START,
117            THREAD_STOP,
118            THREAD_REWIND,
119            THREAD_CLOSE,
120            THREAD_QUIT
121        };
122        ThreadCommand _cmd[NUM_CMD_INDEX];
123        int _wrIndex, _rdIndex;
124
125        OpenThreads::Mutex _mutex;
126
127        /// Set command.
128        void setCmd(ThreadCommand cmd);
129
130        /// Get command.
131        ThreadCommand getCmd();
132
133        /// Decoder hook.
134       
135        void* _mpg;
136        unsigned char** _rows;
137        unsigned char* _videoWriteData;
138
139    };
140
141} // namespace
142
143#endif
Note: See TracBrowser for help on using the browser.