root/OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegImageStream.hpp @ 10809

Revision 10809, 1.9 kB (checked in by robert, 4 years ago)

From Rafa Gaitan, "Current ffmpeg plugin didn't support pause and seek, I have added this
functionality and I also modified osgmovie example to support "seek"."

Note from Robert Osfield, changes osgmovie to use '>' for the seek as '+' was already used in a separate submission that had been merged.

Line 
1
2#ifndef HEADER_GUARD_OSGFFMPEG_FFMPEG_IMAGE_STREAM_H
3#define HEADER_GUARD_OSGFFMPEG_FFMPEG_IMAGE_STREAM_H
4
5#include <osg/ImageStream>
6
7#include <OpenThreads/Condition>
8#include <OpenThreads/Thread>
9
10#include "FFmpegDecoder.hpp"
11#include "MessageQueue.hpp"
12
13namespace osgFFmpeg
14{
15
16    template <class T>
17    class MessageQueue;
18
19    class FFmpegImageStream : public osg::ImageStream, public OpenThreads::Thread
20    {
21    public:
22
23        FFmpegImageStream();
24        FFmpegImageStream(const FFmpegImageStream & image, const osg::CopyOp & copyop = osg::CopyOp::SHALLOW_COPY);
25
26        META_Object(osgFFmpeg, FFmpegImageStream);
27
28        bool open(const std::string & filename);
29
30        virtual void play();
31        virtual void pause();
32        virtual void rewind();
33        virtual void seek(double time);
34        virtual void quit(bool waitForThreadToExit = true);
35
36        virtual double getLength() const;
37        virtual double getFrameRate() const;
38
39        virtual bool isImageTranslucent() const;
40
41    private:
42
43        enum Command
44        {
45            CMD_PLAY,
46            CMD_PAUSE,
47            CMD_STOP,
48            CMD_REWIND,
49            CMD_SEEK
50        };
51
52        typedef MessageQueue<Command> CommandQueue;
53        typedef OpenThreads::Mutex Mutex;
54        typedef OpenThreads::Condition Condition;
55
56        virtual ~FFmpegImageStream();
57        virtual void run();
58        virtual void applyLoopingMode();
59
60        bool handleCommand(Command cmd);
61
62        void cmdPlay();
63        void cmdPause();
64        void cmdRewind();
65        void cmdSeek(double time);
66
67        static void publishNewFrame(const FFmpegDecoderVideo &, void * user_data);
68
69        osg::ref_ptr<FFmpegDecoder>    m_decoder;
70        CommandQueue *    m_commands;
71
72        Mutex            m_mutex;
73        Condition        m_frame_published_cond;
74        bool            m_frame_published_flag;
75        double           m_seek_time;
76    };
77
78}
79
80
81
82#endif // HEADER_GUARD_OSGFFMPEG_FFMPEG_IMAGE_STREAM_H
Note: See TracBrowser for help on using the browser.