Ported mpeg plugin across to use OpenThreads instead of pthreads.

This commit is contained in:
Robert Osfield 2004-03-10 15:41:40 +00:00
parent cdd9c2ae25
commit 697af707e4
3 changed files with 31 additions and 31 deletions

View File

@ -5,7 +5,7 @@ CXXFILES =\
MpegImageStream.cpp\ MpegImageStream.cpp\
ReaderWriterMPEG.cpp\ ReaderWriterMPEG.cpp\
MPEG_LIBS = -lmpeg3 -lpthread MPEG_LIBS = -lmpeg3
LIBS += $(OSG_LIBS) $(MPEG_LIBS) $(OTHER_LIBS) LIBS += $(OSG_LIBS) $(MPEG_LIBS) $(OTHER_LIBS)

View File

@ -55,13 +55,10 @@ MpegImageStream::MpegImageStream(const char* fileName) : ImageStream()
load(fileName); load(fileName);
::pthread_mutex_init(&_mutex, NULL);
::pthread_create(&_id, NULL, MpegImageStream::s_decode, this);
if (fileName) if (fileName)
setFileName(fileName); setFileName(fileName);
startThread();
} }
@ -69,9 +66,24 @@ MpegImageStream::MpegImageStream(const char* fileName) : ImageStream()
MpegImageStream::~MpegImageStream() MpegImageStream::~MpegImageStream()
{ {
stop(); stop();
setCmd(THREAD_QUIT); 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"<<std::endl;
OpenThreads::Thread::YieldCurrentThread();
}
}
mpeg3_t* mpg = (mpeg3_t*)_mpg; mpeg3_t* mpg = (mpeg3_t*)_mpg;
if (mpg) { if (mpg) {
@ -110,14 +122,6 @@ MpegImageStream::ThreadCommand MpegImageStream::getCmd()
} }
/*
* Decoder thread
*/
void* MpegImageStream::s_decode(void* vp)
{
return ((MpegImageStream*) vp)->decode(vp);
}
void MpegImageStream::load(const char* fileName) void MpegImageStream::load(const char* fileName)
{ {
mpeg3_t* mpg = mpeg3_open((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; bool playing = false;
mpeg3_t* mpg = (mpeg3_t*)_mpg; mpeg3_t* mpg = (mpeg3_t*)_mpg;
@ -283,7 +287,4 @@ void* MpegImageStream::decode(void*)
} }
} }
// Cleanup decoder
return NULL;
} }

View File

@ -29,9 +29,9 @@
#define _MPEGIMAGESTREAM_H_ #define _MPEGIMAGESTREAM_H_
#include <osg/ImageStream> #include <osg/ImageStream>
//#include "ImageStream.h"
#include <pthread.h> #include <OpenThreads/Thread>
#include <OpenThreads/Mutex>
#define NUM_CMD_INDEX 4 #define NUM_CMD_INDEX 4
@ -40,7 +40,7 @@ namespace osg {
/** /**
* MPEG1/2 Image Stream class. * MPEG1/2 Image Stream class.
*/ */
class SG_EXPORT MpegImageStream : public osg::ImageStream class SG_EXPORT MpegImageStream : public osg::ImageStream, public OpenThreads::Thread
{ {
public: public:
MpegImageStream(const char* fileName = NULL); MpegImageStream(const char* fileName = NULL);
@ -52,13 +52,13 @@ namespace osg {
virtual const char* className() const { return "MpegImageStream"; } virtual const char* className() const { return "MpegImageStream"; }
/// Start or continue stream. /// Start or continue stream.
virtual inline void start() { setCmd(THREAD_START); } virtual void start() { setCmd(THREAD_START); }
/// Stop stream at current position. /// Stop stream at current position.
virtual inline void stop() { setCmd(THREAD_STOP); } virtual void stop() { setCmd(THREAD_STOP); }
/// Rewind stream to beginning. /// Rewind stream to beginning.
virtual inline void rewind() { setCmd(THREAD_REWIND); } virtual void rewind() { setCmd(THREAD_REWIND); }
/// Enable/disable MMX. /// Enable/disable MMX.
inline void enableMMX(bool b) { _useMMX = b; } inline void enableMMX(bool b) { _useMMX = b; }
@ -81,6 +81,8 @@ namespace osg {
void load(const char* fileName); void load(const char* fileName);
virtual void run();
protected: protected:
virtual ~MpegImageStream(); virtual ~MpegImageStream();
@ -101,12 +103,11 @@ namespace osg {
ThreadCommand _cmd[NUM_CMD_INDEX]; ThreadCommand _cmd[NUM_CMD_INDEX];
int _wrIndex, _rdIndex; int _wrIndex, _rdIndex;
pthread_mutex_t _mutex; OpenThreads::Mutex _mutex;
pthread_t _id;
// Lock/unlock object. // Lock/unlock object.
inline void lock() { ::pthread_mutex_lock(&_mutex); } inline void lock() { _mutex.lock(); }
inline void unlock() { ::pthread_mutex_unlock(&_mutex); } inline void unlock() { _mutex.unlock(); }
/// Set command. /// Set command.
void setCmd(ThreadCommand cmd); void setCmd(ThreadCommand cmd);
@ -115,8 +116,6 @@ namespace osg {
ThreadCommand getCmd(); ThreadCommand getCmd();
/// Decoder hook. /// Decoder hook.
static void* s_decode(void*);
void* decode(void*);
void* _mpg; void* _mpg;
unsigned char** _rows; unsigned char** _rows;