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."
This commit is contained in:
Robert Osfield
2007-05-19 14:00:39 +00:00
parent e37ec98748
commit 6a29688896
4 changed files with 40 additions and 75 deletions

View File

@@ -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)
{
}

View File

@@ -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);

View File

@@ -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<72>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);
}

View File

@@ -133,6 +133,8 @@ public:
protected:
/// apply the looping mode to quicktime
virtual void applyLoopingMode();
/// destructor
virtual ~QuicktimeImageStream();