From 6a296888968acf6a4e629dfdf7c00e519acc5c38 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 19 May 2007 14:00:39 +0000 Subject: [PATCH] From Stephan Huber, "I cleaned the code a little bit and improved the handling of loops: I added a new protected virtual method to ImageStream called applyLoopingMode() which is called from setLoopingMode. The quicktime-plugin has an implementation of applyLoopingMode which sets some flags for the quicktime, so that quicktime handles the loop playback by itself. This has some benefits: + no gaps when looping audio + simplified code Attached you'll find the modified files, hope you'll find them useful." --- src/osgPlugins/quicktime/MovieData.cpp | 2 +- src/osgPlugins/quicktime/MovieData.h | 19 ++++ .../quicktime/QuicktimeImageStream.cpp | 92 ++++--------------- .../quicktime/QuicktimeImageStream.h | 2 + 4 files changed, 40 insertions(+), 75 deletions(-) diff --git a/src/osgPlugins/quicktime/MovieData.cpp b/src/osgPlugins/quicktime/MovieData.cpp index ba96aff66..8fb0c82d6 100644 --- a/src/osgPlugins/quicktime/MovieData.cpp +++ b/src/osgPlugins/quicktime/MovieData.cpp @@ -16,7 +16,7 @@ -MovieData::MovieData() : _pointer(NULL), _movie(NULL), _gw(NULL), _fError(false) +MovieData::MovieData() : _pointer(NULL), _movie(NULL), _gw(NULL), _fError(false), _isLooping(false) { } diff --git a/src/osgPlugins/quicktime/MovieData.h b/src/osgPlugins/quicktime/MovieData.h index e68ec62e6..8947f73dc 100644 --- a/src/osgPlugins/quicktime/MovieData.h +++ b/src/osgPlugins/quicktime/MovieData.h @@ -75,6 +75,24 @@ f = balance; return f; } + + /** @return true, if this movie is looping */ + bool isLooping() const { return _isLooping; } + + /** sets the looping mode */ + void setLooping(bool loop) { + if (_isLooping != loop) { + _isLooping = loop; + switch (_isLooping) { + case true: + SetTimeBaseFlags(GetMovieTimeBase(_movie), loopTimeBase); + break; + case false: + SetTimeBaseFlags(GetMovieTimeBase(_movie), 0); + break; + } + } + } protected: @@ -87,6 +105,7 @@ bool _fError; float _movieRate; bool _preRolled; + bool _isLooping; /** inits the image for storage */ void _initImage(osg::Image* image); diff --git a/src/osgPlugins/quicktime/QuicktimeImageStream.cpp b/src/osgPlugins/quicktime/QuicktimeImageStream.cpp index 4344a241c..dbf9e0fbd 100644 --- a/src/osgPlugins/quicktime/QuicktimeImageStream.cpp +++ b/src/osgPlugins/quicktime/QuicktimeImageStream.cpp @@ -36,39 +36,26 @@ #define IDLE_TIMEOUT 150000L -#define ERR_MSG(no,msg) osg::notify(osg::WARN) << "QT-ImageStream: " << msg << " failed with error " << no << std::endl; int QuicktimeImageStream::_qtInstanceCount = 0; // Constructor: setup and start thread QuicktimeImageStream::QuicktimeImageStream(std::string fileName) : ImageStream() { - /* - // ricky - if(_qtInstanceCount == 0) - { - osg::notify(osg::NOTICE) << "quicktime Init" << std::endl; - initQuicktime(); - } - ++ _qtInstanceCount; - // end ricky - */ + _len = 0; + _data = new MovieData(); - - _len = 0; - _data = new MovieData(); - - for (int i = 0; i < NUM_CMD_INDEX; i++) + for (int i = 0; i < NUM_CMD_INDEX; i++) _cmd[i] = THREAD_IDLE; - _wrIndex = _rdIndex = 0; + _wrIndex = _rdIndex = 0; - load(fileName); + load(fileName); - if (!fileName.empty()) + if (!fileName.empty()) setFileName(fileName); - // ricky - _status = ImageStream::PAUSED; + // ricky + _status = ImageStream::PAUSED; } @@ -80,17 +67,7 @@ QuicktimeImageStream::~QuicktimeImageStream() quit(true); } - /* - // ricky - -- _qtInstanceCount; - if(_qtInstanceCount == 0) - { - osg::notify(osg::NOTICE) << "quicktime Exit" << std::endl; - exitQuicktime(); - } - // end ricky - */ - + // clean up quicktime movies. delete _data; @@ -158,12 +135,6 @@ void QuicktimeImageStream::run() bool playing = false; bool done = false; - /* - OSErr err; - err = EnterMoviesOnThread(0); - ERR_MSG(err,"EnterMoviesOnThread"); - err = AttachMovieToCurrentThread(_data->getMovie()); - */ while (!done) { @@ -175,6 +146,7 @@ void QuicktimeImageStream::run() osg::notify(osg::DEBUG_INFO) << "new cmd: " << cmd << std::endl; switch (cmd) { case THREAD_START: // Start or continue stream + applyLoopingMode(); _data->setMovieRate(1.0f); playing = true; @@ -233,37 +205,6 @@ void QuicktimeImageStream::run() dirty(); // update internal time and take care of looping _lastUpdate = _current; - - if (getLoopingMode() == LOOPING) - { - // loopen wir rueckwaerts? - if ((_current <= 0.0f) && (_data->getCachedMovieRate() < 0.0f)) { - forward(); - setMovieRate(_data->getCachedMovieRate()); - } - // loppen wir vorwŠrts? - else if ((_current >= _len) && (_data->getCachedMovieRate() > 0.0f)) - { - rewind(); - setMovieRate(_data->getCachedMovieRate()); - } - } - else - { // NO LOOPING - //ricky - if(_current >= _len) - { - pause(); - - // Don't rewind to the begining if the movie has completed. - // Someone may want to see the last frame displayed. - //rewind(); - } - // orig - //pause(); - - //end ricky - } } if (playing) @@ -275,9 +216,12 @@ void QuicktimeImageStream::run() OpenThreads::Thread::microSleep(IDLE_TIMEOUT); } } - /* - err = DetachMovieFromCurrentThread(_data->getMovie()); - err = ExitMoviesOnThread(); - ERR_MSG(err,"ExitMoviesOnThread"); - */ + + +} + + +void QuicktimeImageStream::applyLoopingMode() { + osg::notify(osg::ALWAYS) << "applying loop mode " << getLoopingMode() << std::endl; + _data->setLooping(getLoopingMode() == osg::ImageStream::LOOPING); } diff --git a/src/osgPlugins/quicktime/QuicktimeImageStream.h b/src/osgPlugins/quicktime/QuicktimeImageStream.h index e0e036c64..c4027b943 100644 --- a/src/osgPlugins/quicktime/QuicktimeImageStream.h +++ b/src/osgPlugins/quicktime/QuicktimeImageStream.h @@ -133,6 +133,8 @@ public: protected: + /// apply the looping mode to quicktime + virtual void applyLoopingMode(); /// destructor virtual ~QuicktimeImageStream();