Files
OpenSceneGraph/examples/osgmovie/MpegImageStream.h
Robert Osfield 9772b21e35 Added osgmovie example, derived from Ulrich Hertlien's original videotex
example, and brought up to date.
2004-01-30 14:06:29 +00:00

122 lines
3.4 KiB
C++

// -*-c++-*-
/*
* Copyright (C) 2001 Ulrich Hertlein <u.hertlein@web.de>
*
* Uses libmpeg3 by Adam Williams
* See http://www.heroinewarrior.com
*
* The Open Scene Graph (OSG) is a cross platform C++/OpenGL library for
* real-time rendering of large 3D photo-realistic models.
* The OSG homepage is http://www.openscenegraph.org/
*
* This software is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _MPEGIMAGESTREAM_H_
#define _MPEGIMAGESTREAM_H_
#include "ImageStream.h"
#include <pthread.h>
#define NUM_CMD_INDEX 4
namespace osg {
/**
* MPEG1/2 Image Stream class.
*/
class SG_EXPORT MpegImageStream : public ImageStream
{
public:
MpegImageStream(const char* fileName = NULL);
virtual Object* clone() const { return new MpegImageStream; }
virtual bool isSameKindAs(const Object* obj) const {
return dynamic_cast<const MpegImageStream*>(obj) != NULL;
}
virtual const char* className() const { return "MpegImageStream"; }
/// Start or continue stream.
virtual inline void start() { setCmd(THREAD_START); }
/// Stop stream at current position.
virtual inline void stop() { setCmd(THREAD_STOP); }
/// Rewind stream to beginning.
virtual inline void rewind() { setCmd(THREAD_REWIND); }
/// Enable/disable MMX.
inline void enableMMX(bool b) { _useMMX = b; }
/**
* Set frame rate in fps.
* This is overwritten by the actual frame rate of the stream when
* it is opened.
*/
inline void setFrameRate(float fps) { _fps = (fps < 0.0f ? 0.0f : fps); }
/// Get frame rate in fps.
inline float getFrameRate() const { return _fps; }
/// Get number of frames.
inline long getNumFrames() const { return _frames; }
/// Get total length in seconds.
inline float getLength() const { return _len; }
protected:
virtual ~MpegImageStream();
private:
bool _useMMX;
float _fps;
long _frames;
float _len;
enum ThreadCommand {
THREAD_IDLE = 0,
THREAD_START,
THREAD_STOP,
THREAD_REWIND,
THREAD_CLOSE,
THREAD_QUIT
};
ThreadCommand _cmd[NUM_CMD_INDEX];
int _wrIndex, _rdIndex;
pthread_mutex_t _mutex;
pthread_t _id;
// Lock/unlock object.
inline void lock() { ::pthread_mutex_lock(&_mutex); }
inline void unlock() { ::pthread_mutex_unlock(&_mutex); }
/// Set command.
void setCmd(ThreadCommand cmd);
/// Get command.
ThreadCommand getCmd();
/// Decoder hook.
static void* s_decode(void*);
void* decode(void*);
};
} // namespace
#endif