Fixed thread exit problems

This commit is contained in:
Robert Osfield
2009-03-08 16:48:48 +00:00
parent 7473b06275
commit 73c2615d17
7 changed files with 48 additions and 5 deletions

View File

@@ -31,7 +31,7 @@ FFmpegDecoder::FFmpegDecoder() :
FFmpegDecoder::~FFmpegDecoder()
{
close();
close(true);
}
@@ -123,10 +123,13 @@ bool FFmpegDecoder::open(const std::string & filename)
void FFmpegDecoder::close()
void FFmpegDecoder::close(bool waitForThreadToExit)
{
flushAudioQueue();
flushVideoQueue();
m_audio_decoder.close(waitForThreadToExit);
m_video_decoder.close(waitForThreadToExit);
}

View File

@@ -64,7 +64,7 @@ public:
~FFmpegDecoder();
bool open(const std::string & filename);
void close();
void close(bool waitForThreadToExit);
bool readNextPacket();
void rewind();

View File

@@ -37,7 +37,11 @@ FFmpegDecoderAudio::~FFmpegDecoderAudio()
if (isRunning())
{
m_exit = true;
#if 0
while(isRunning()) { OpenThreads::YieldCurrentThread(); }
#else
join();
#endif
}
}
@@ -85,6 +89,16 @@ void FFmpegDecoderAudio::open(AVStream * const stream)
}
void FFmpegDecoderAudio::close(bool waitForThreadToExit)
{
m_exit = true;
if (isRunning() && waitForThreadToExit)
{
while(isRunning()) { OpenThreads::Thread::YieldCurrentThread(); }
}
}
void FFmpegDecoderAudio::run()
{
@@ -105,7 +119,6 @@ void FFmpegDecoderAudio::run()
}
void FFmpegDecoderAudio::setAudioSink(osg::ref_ptr<osg::AudioSink> audio_sink)
{
// The FFmpegDecoderAudio object takes the responsability of destroying the audio_sink.

View File

@@ -29,6 +29,8 @@ public:
~FFmpegDecoderAudio();
void open(AVStream * stream);
void close(bool waitForThreadToExit);
virtual void run();
void setAudioSink(osg::ref_ptr<osg::AudioSink> audio_sink);

View File

@@ -34,10 +34,15 @@ FFmpegDecoderVideo::~FFmpegDecoderVideo()
{
osg::notify(osg::NOTICE)<<"Destructing FFmpegDecoderVideo..."<<std::endl;
if (isRunning())
{
m_exit = true;
#if 0
while(isRunning()) { OpenThreads::YieldCurrentThread(); }
#else
join();
#endif
}
#ifdef USE_SWSCALE
@@ -102,6 +107,16 @@ void FFmpegDecoderVideo::open(AVStream * const stream)
}
void FFmpegDecoderVideo::close(bool waitForThreadToExit)
{
m_exit = true;
if (isRunning() && waitForThreadToExit)
{
while(isRunning()) { OpenThreads::Thread::YieldCurrentThread(); }
}
}
void FFmpegDecoderVideo::run()
{

View File

@@ -65,6 +65,8 @@ public:
~FFmpegDecoderVideo();
void open(AVStream * stream);
void close(bool waitForThreadToExit);
virtual void run();
void setUserData(void * user_data);

View File

@@ -42,6 +42,12 @@ FFmpegImageStream::~FFmpegImageStream()
osg::notify(osg::NOTICE)<<"Destructing FFMpegImageStream..."<<std::endl;
quit(true);
osg::notify(osg::NOTICE)<<"Have done quit"<<std::endl;
// release athe audio streams to make sure that the decoder doesn't retain any external
// refences.
getAudioStreams().clear();
// destroy the decoder and associated threads
m_decoder = 0;
@@ -130,7 +136,7 @@ void FFmpegImageStream::quit(bool waitForThreadToExit)
}
// Close the decoder (i.e. flush the decoder packet queues)
m_decoder->close();
m_decoder->close(waitForThreadToExit);
}
@@ -197,6 +203,8 @@ void FFmpegImageStream::run()
{
osg::notify(osg::WARN) << "FFmpegImageStream::run : unhandled exception" << std::endl;
}
osg::notify(osg::NOTICE)<<"Finished FFmpegImageStream::run()"<<std::endl;
}