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

Revision 3285, 3.7 kB (checked in by robert, 10 years ago)

Cleaned up output level of debugging messages

  • 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 4
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() { setCmd(THREAD_REWIND); }
74
75        virtual void quit(bool wiatForThreadToExit);
76
77        /// Enable/disable MMX.
78        inline void enableMMX(bool b) { _useMMX = b; }
79
80        /**
81         * Set frame rate in fps.
82         * This is overwritten by the actual frame rate of the stream when
83         * it is opened.
84         */
85        inline void setFrameRate(float fps) { _fps = (fps < 0.0f ? 0.0f : fps); }
86
87        /// Get frame rate in fps.
88        inline float getFrameRate() const { return _fps; }
89
90        /// Get number of frames.
91        inline long getNumFrames() const { return _frames; }
92
93        /// Get total length in seconds.
94        inline float getLength() const { return _len; }
95       
96        void load(const char* fileName);
97
98        virtual void run();
99
100    protected:
101        virtual ~MpegImageStream();
102
103        bool _useMMX;
104        float _fps;
105        long _frames;
106        float _len;
107       
108        void swapData();
109
110        enum ThreadCommand {
111            THREAD_IDLE = 0,
112            THREAD_START,
113            THREAD_STOP,
114            THREAD_REWIND,
115            THREAD_CLOSE,
116            THREAD_QUIT
117        };
118        ThreadCommand _cmd[NUM_CMD_INDEX];
119        int _wrIndex, _rdIndex;
120
121        OpenThreads::Mutex _mutex;
122
123        /// Set command.
124        void setCmd(ThreadCommand cmd);
125
126        /// Get command.
127        ThreadCommand getCmd();
128
129        /// Decoder hook.
130       
131        void* _mpg;
132        unsigned char** _rows;
133        unsigned char* _videoWriteData;
134
135    };
136
137} // namespace
138
139#endif
Note: See TracBrowser for help on using the browser.