From 697af707e4f2be30ce2b41caac3c86bb88104c83 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 10 Mar 2004 15:41:40 +0000 Subject: [PATCH] Ported mpeg plugin across to use OpenThreads instead of pthreads. --- src/osgPlugins/mpeg/GNUmakefile | 2 +- src/osgPlugins/mpeg/MpegImageStream.cpp | 37 +++++++++++++------------ src/osgPlugins/mpeg/MpegImageStream.h | 23 ++++++++------- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/osgPlugins/mpeg/GNUmakefile b/src/osgPlugins/mpeg/GNUmakefile index 41771ec8b..e6f19b0b1 100644 --- a/src/osgPlugins/mpeg/GNUmakefile +++ b/src/osgPlugins/mpeg/GNUmakefile @@ -5,7 +5,7 @@ CXXFILES =\ MpegImageStream.cpp\ ReaderWriterMPEG.cpp\ -MPEG_LIBS = -lmpeg3 -lpthread +MPEG_LIBS = -lmpeg3 LIBS += $(OSG_LIBS) $(MPEG_LIBS) $(OTHER_LIBS) diff --git a/src/osgPlugins/mpeg/MpegImageStream.cpp b/src/osgPlugins/mpeg/MpegImageStream.cpp index 8428243bc..fc9fea5ee 100644 --- a/src/osgPlugins/mpeg/MpegImageStream.cpp +++ b/src/osgPlugins/mpeg/MpegImageStream.cpp @@ -55,13 +55,10 @@ MpegImageStream::MpegImageStream(const char* fileName) : ImageStream() load(fileName); - ::pthread_mutex_init(&_mutex, NULL); - ::pthread_create(&_id, NULL, MpegImageStream::s_decode, this); - if (fileName) setFileName(fileName); - + startThread(); } @@ -69,9 +66,24 @@ MpegImageStream::MpegImageStream(const char* fileName) : ImageStream() MpegImageStream::~MpegImageStream() { stop(); + setCmd(THREAD_QUIT); - ::pthread_join(_id, NULL); - ::pthread_mutex_destroy(&_mutex); + + if( isRunning() ) + { + + // cancel the thread.. + cancel(); + //join(); + + // then wait for the the thread to stop running. + while(isRunning()) + { + osg::notify(osg::DEBUG_INFO)<<"Waiting for MpegImageStream to cancel"<decode(vp); -} - void MpegImageStream::load(const char* fileName) { mpeg3_t* mpg = mpeg3_open((char*) fileName); @@ -198,7 +202,7 @@ void MpegImageStream::load(const char* fileName) } -void* MpegImageStream::decode(void*) +void MpegImageStream::run() { bool playing = false; mpeg3_t* mpg = (mpeg3_t*)_mpg; @@ -283,7 +287,4 @@ void* MpegImageStream::decode(void*) } } - // Cleanup decoder - - return NULL; } diff --git a/src/osgPlugins/mpeg/MpegImageStream.h b/src/osgPlugins/mpeg/MpegImageStream.h index 233aac51e..58a0322b4 100644 --- a/src/osgPlugins/mpeg/MpegImageStream.h +++ b/src/osgPlugins/mpeg/MpegImageStream.h @@ -29,9 +29,9 @@ #define _MPEGIMAGESTREAM_H_ #include -//#include "ImageStream.h" -#include +#include +#include #define NUM_CMD_INDEX 4 @@ -40,7 +40,7 @@ namespace osg { /** * MPEG1/2 Image Stream class. */ - class SG_EXPORT MpegImageStream : public osg::ImageStream + class SG_EXPORT MpegImageStream : public osg::ImageStream, public OpenThreads::Thread { public: MpegImageStream(const char* fileName = NULL); @@ -52,13 +52,13 @@ namespace osg { virtual const char* className() const { return "MpegImageStream"; } /// Start or continue stream. - virtual inline void start() { setCmd(THREAD_START); } + virtual void start() { setCmd(THREAD_START); } /// Stop stream at current position. - virtual inline void stop() { setCmd(THREAD_STOP); } + virtual void stop() { setCmd(THREAD_STOP); } /// Rewind stream to beginning. - virtual inline void rewind() { setCmd(THREAD_REWIND); } + virtual void rewind() { setCmd(THREAD_REWIND); } /// Enable/disable MMX. inline void enableMMX(bool b) { _useMMX = b; } @@ -81,6 +81,8 @@ namespace osg { void load(const char* fileName); + virtual void run(); + protected: virtual ~MpegImageStream(); @@ -101,12 +103,11 @@ namespace osg { ThreadCommand _cmd[NUM_CMD_INDEX]; int _wrIndex, _rdIndex; - pthread_mutex_t _mutex; - pthread_t _id; + OpenThreads::Mutex _mutex; // Lock/unlock object. - inline void lock() { ::pthread_mutex_lock(&_mutex); } - inline void unlock() { ::pthread_mutex_unlock(&_mutex); } + inline void lock() { _mutex.lock(); } + inline void unlock() { _mutex.unlock(); } /// Set command. void setCmd(ThreadCommand cmd); @@ -115,8 +116,6 @@ namespace osg { ThreadCommand getCmd(); /// Decoder hook. - static void* s_decode(void*); - void* decode(void*); void* _mpg; unsigned char** _rows;