FFmpeg headers need __STDC_CONSTANT_MACROS defined before stdint.h is loaded.
The file FFmpegHeaders.hpp sets this definition. However, if stdint.h is
already included through other files, it won't take any effect.
Include FFmpeg headers as early as possible in order to avoid stdint.h being
included on other paths.
#ifndef HEADER_GUARD_OSGFFMPEG_FFMPEG_AUDIO_STREAM_H
#define HEADER_GUARD_OSGFFMPEG_FFMPEG_AUDIO_STREAM_H
#include "FFmpegDecoder.hpp"
#include <osg/AudioStream>
namespace osgFFmpeg
{
class FFmpegAudioStream : public osg::AudioStream
{
public:
FFmpegAudioStream(FFmpegDecoder* decoder=0);
FFmpegAudioStream(const FFmpegAudioStream & audio, const osg::CopyOp & copyop = osg::CopyOp::SHALLOW_COPY);
META_Object(osgFFmpeg, FFmpegAudioStream);
virtual void setAudioSink(osg::AudioSink* audio_sink);
void consumeAudioBuffer(void * const buffer, const size_t size);
int audioFrequency() const;
int audioNbChannels() const;
osg::AudioStream::SampleFormat audioSampleFormat() const;
double duration() const;
private:
virtual ~FFmpegAudioStream();
osg::ref_ptr<FFmpegDecoder> m_decoder;
};
}
#endif // HEADER_GUARD_OSGFFMPEG_FFMPEG_IMAGE_STREAM_H
#ifndef HEADER_GUARD_OSGFFMPEG_FFMPEG_IMAGE_STREAM_H
#define HEADER_GUARD_OSGFFMPEG_FFMPEG_IMAGE_STREAM_H
#include "FFmpegDecoder.hpp"
#include "MessageQueue.hpp"
#include <osg/ImageStream>
#include <OpenThreads/Condition>
#include <OpenThreads/Thread>
namespace osgFFmpeg
{
template <class T>
class MessageQueue;
class FFmpegImageStream : public osg::ImageStream, public OpenThreads::Thread
{
public:
FFmpegImageStream();
FFmpegImageStream(const FFmpegImageStream & image, const osg::CopyOp & copyop = osg::CopyOp::SHALLOW_COPY);
META_Object(osgFFmpeg, FFmpegImageStream);
bool open(const std::string & filename);
virtual void play();
virtual void pause();
virtual void rewind();
virtual void seek(double time);
virtual void quit(bool waitForThreadToExit = true);
virtual void setVolume(float volume);
virtual float getVolume() const;
virtual double getLength() const;
virtual double getReferenceTime () const;
virtual double getFrameRate() const;
virtual bool isImageTranslucent() const;
private:
enum Command
{
CMD_PLAY,
CMD_PAUSE,
CMD_STOP,
CMD_REWIND,
CMD_SEEK
};
typedef MessageQueue<Command> CommandQueue;
typedef OpenThreads::Mutex Mutex;
typedef OpenThreads::Condition Condition;
virtual ~FFmpegImageStream();
virtual void run();
virtual void applyLoopingMode();
bool handleCommand(Command cmd);
void cmdPlay();
void cmdPause();
void cmdRewind();
void cmdSeek(double time);
static void publishNewFrame(const FFmpegDecoderVideo &, void * user_data);
osg::ref_ptr<FFmpegDecoder> m_decoder;
CommandQueue * m_commands;
Mutex m_mutex;
Condition m_frame_published_cond;
bool m_frame_published_flag;
double m_seek_time;
};
}
#endif // HEADER_GUARD_OSGFFMPEG_FFMPEG_IMAGE_STREAM_H
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library 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
* OpenSceneGraph Public License for more details.
*/
#include "FFmpegHeaders.hpp"
#include "FFmpegImageStream.hpp"
#include <osgDB/Registry>
#include <osgDB/FileNameUtils>
#include <osgDB/FileUtils>
/** Implementation heavily inspired by http://www.dranger.com/ffmpeg/ */
class ReaderWriterFFmpeg : public osgDB::ReaderWriter
{
public:
ReaderWriterFFmpeg()
{
supportsProtocol("http","Read video/audio from http using ffmpeg.");
supportsProtocol("rtsp","Read video/audio from rtsp using ffmpeg.");
supportsExtension("ffmpeg", "");
supportsExtension("avi", "");
supportsExtension("flv", "Flash video");
supportsExtension("mov", "Quicktime");
supportsExtension("ogg", "Theora movie format");
supportsExtension("mpg", "Mpeg movie format");
supportsExtension("mpv", "Mpeg movie format");
supportsExtension("wmv", "Windows Media Video format");
supportsExtension("mkv", "Matroska");
supportsExtension("mjpeg", "Motion JPEG");
supportsExtension("mp4", "MPEG-4");
supportsExtension("sav", "MPEG-4");
supportsExtension("3gp", "MPEG-4");
supportsExtension("sdp", "MPEG-4");
// Register all FFmpeg formats/codecs
av_register_all();
}
virtual ~ReaderWriterFFmpeg()
{
}
virtual const char * className() const
{
return "ReaderWriterFFmpeg";
}
virtual ReadResult readImage(const std::string & filename, const osgDB::ReaderWriter::Options * options) const
{
const std::string ext = osgDB::getLowerCaseFileExtension(filename);
if (ext=="ffmpeg") return readImage(osgDB::getNameLessExtension(filename),options);
if (filename.compare(0, 5, "/dev/")==0)
{
return readImageStream(filename, options);
}
if (! acceptsExtension(ext))
return ReadResult::FILE_NOT_HANDLED;
const std::string path = osgDB::containsServerAddress(filename) ?
filename :
osgDB::findDataFile(filename, options);
if (path.empty())
return ReadResult::FILE_NOT_FOUND;
return readImageStream(path, options);
}
ReadResult readImageStream(const std::string& filename, const osgDB::ReaderWriter::Options * options) const
{
OSG_INFO << "ReaderWriterFFmpeg::readImage " << filename << std::endl;
osg::ref_ptr<osgFFmpeg::FFmpegImageStream> image_stream(new osgFFmpeg::FFmpegImageStream);
if (! image_stream->open(filename))
return ReadResult::FILE_NOT_HANDLED;
return image_stream.release();
}
private:
};
REGISTER_OSGPLUGIN(ffmpeg, ReaderWriterFFmpeg)
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org