| [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 | |
|---|
| 10 | namespace osgFFmpeg |
|---|
| 11 | { |
|---|
| 12 | |
|---|
| 13 | class FFmpegDecoder; |
|---|
| 14 | class FFmpegDecoderAudio; |
|---|
| 15 | class FFmpegDecoderVideo; |
|---|
| 16 | |
|---|
| 17 | template <class T> |
|---|
| 18 | class MessageQueue; |
|---|
| 19 | |
|---|
| 20 | |
|---|
| [9843] | 21 | class FFmpegImageStream : public osg::ImageStream, public OpenThreads::Thread |
|---|
| [9816] | 22 | { |
|---|
| 23 | public: |
|---|
| 24 | |
|---|
| 25 | FFmpegImageStream(); |
|---|
| 26 | FFmpegImageStream(const FFmpegImageStream & image, const osg::CopyOp & copyop = osg::CopyOp::SHALLOW_COPY); |
|---|
| 27 | |
|---|
| 28 | META_Object(osgFFmpeg, FFmpegImageStream); |
|---|
| 29 | |
|---|
| 30 | bool open(const std::string & filename); |
|---|
| 31 | |
|---|
| 32 | virtual void play(); |
|---|
| 33 | virtual void pause(); |
|---|
| 34 | virtual void rewind(); |
|---|
| 35 | virtual void quit(bool waitForThreadToExit = true); |
|---|
| 36 | |
|---|
| [9826] | 37 | virtual void setAudioSink(osg::AudioSinkInterface* audio_sink); |
|---|
| 38 | |
|---|
| [9827] | 39 | void consumeAudioBuffer(void * const buffer, const size_t size); |
|---|
| 40 | |
|---|
| 41 | bool audioStream() const; |
|---|
| 42 | int audioFrequency() const; |
|---|
| 43 | int audioNbChannels() const; |
|---|
| 44 | osg::AudioStream::SampleFormat audioSampleFormat() const; |
|---|
| [9816] | 45 | |
|---|
| 46 | double duration() const; |
|---|
| 47 | |
|---|
| 48 | bool videoAlphaChannel() const; |
|---|
| 49 | double videoAspectRatio() const; |
|---|
| 50 | double videoFrameRate() const; |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | private: |
|---|
| 54 | |
|---|
| 55 | enum Command |
|---|
| 56 | { |
|---|
| 57 | CMD_PLAY, |
|---|
| 58 | CMD_PAUSE, |
|---|
| 59 | CMD_STOP, |
|---|
| 60 | CMD_REWIND |
|---|
| 61 | }; |
|---|
| 62 | |
|---|
| 63 | typedef MessageQueue<Command> CommandQueue; |
|---|
| 64 | typedef OpenThreads::Mutex Mutex; |
|---|
| 65 | typedef OpenThreads::Condition Condition; |
|---|
| 66 | |
|---|
| 67 | virtual ~FFmpegImageStream(); |
|---|
| 68 | virtual void run(); |
|---|
| 69 | virtual void applyLoopingMode(); |
|---|
| 70 | |
|---|
| 71 | bool handleCommand(Command cmd); |
|---|
| 72 | |
|---|
| 73 | void cmdPlay(); |
|---|
| 74 | void cmdPause(); |
|---|
| 75 | void cmdRewind(); |
|---|
| 76 | |
|---|
| 77 | static void publishNewFrame(const FFmpegDecoderVideo &, void * user_data); |
|---|
| 78 | |
|---|
| 79 | FFmpegDecoder * m_decoder; |
|---|
| 80 | CommandQueue * m_commands; |
|---|
| 81 | |
|---|
| 82 | Mutex m_mutex; |
|---|
| 83 | Condition m_frame_published_cond; |
|---|
| 84 | bool m_frame_published_flag; |
|---|
| 85 | }; |
|---|
| 86 | |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | #endif // HEADER_GUARD_OSGFFMPEG_FFMPEG_IMAGE_STREAM_H |
|---|