| [9816] | 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 | |
|---|
| [9847] | 10 | #include "FFmpegDecoder.hpp" |
|---|
| 11 | #include "MessageQueue.hpp" |
|---|
| 12 | |
|---|
| [9816] | 13 | namespace osgFFmpeg |
|---|
| 14 | { |
|---|
| 15 | |
|---|
| 16 | template <class T> |
|---|
| 17 | class MessageQueue; |
|---|
| 18 | |
|---|
| [9843] | 19 | class FFmpegImageStream : public osg::ImageStream, public OpenThreads::Thread |
|---|
| [9816] | 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 quit(bool waitForThreadToExit = true); |
|---|
| 34 | |
|---|
| [9910] | 35 | virtual double getLength() const; |
|---|
| 36 | virtual double getFrameRate() const; |
|---|
| [9816] | 37 | |
|---|
| [9910] | 38 | virtual bool isImageTranslucent() const; |
|---|
| [9816] | 39 | |
|---|
| 40 | private: |
|---|
| 41 | |
|---|
| 42 | enum Command |
|---|
| 43 | { |
|---|
| 44 | CMD_PLAY, |
|---|
| 45 | CMD_PAUSE, |
|---|
| 46 | CMD_STOP, |
|---|
| 47 | CMD_REWIND |
|---|
| 48 | }; |
|---|
| 49 | |
|---|
| 50 | typedef MessageQueue<Command> CommandQueue; |
|---|
| 51 | typedef OpenThreads::Mutex Mutex; |
|---|
| 52 | typedef OpenThreads::Condition Condition; |
|---|
| 53 | |
|---|
| 54 | virtual ~FFmpegImageStream(); |
|---|
| 55 | virtual void run(); |
|---|
| 56 | virtual void applyLoopingMode(); |
|---|
| 57 | |
|---|
| 58 | bool handleCommand(Command cmd); |
|---|
| 59 | |
|---|
| 60 | void cmdPlay(); |
|---|
| 61 | void cmdPause(); |
|---|
| 62 | void cmdRewind(); |
|---|
| 63 | |
|---|
| 64 | static void publishNewFrame(const FFmpegDecoderVideo &, void * user_data); |
|---|
| 65 | |
|---|
| [9847] | 66 | osg::ref_ptr<FFmpegDecoder> m_decoder; |
|---|
| [9816] | 67 | CommandQueue * m_commands; |
|---|
| 68 | |
|---|
| 69 | Mutex m_mutex; |
|---|
| 70 | Condition m_frame_published_cond; |
|---|
| 71 | bool m_frame_published_flag; |
|---|
| 72 | }; |
|---|
| 73 | |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | #endif // HEADER_GUARD_OSGFFMPEG_FFMPEG_IMAGE_STREAM_H |
|---|