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