Introduce FFmpegAudioStream implementation
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
|
||||
using namespace osg;
|
||||
|
||||
AudioSinkInterface::AudioSinkInterface() :
|
||||
AudioSink::AudioSink() :
|
||||
_delay(0.0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -200,6 +200,10 @@ IF(FFMPEG_FOUND)
|
||||
ADD_SUBDIRECTORY(ffmpeg)
|
||||
ENDIF(FFMPEG_FOUND)
|
||||
|
||||
IF(OPENAL_FOUND)
|
||||
ADD_SUBDIRECTORY(OpenAL)
|
||||
ENDIF(OPENAL_FOUND)
|
||||
|
||||
IF(QUICKTIME_FOUND)
|
||||
ADD_SUBDIRECTORY(quicktime)
|
||||
ENDIF(QUICKTIME_FOUND)
|
||||
|
||||
@@ -19,6 +19,7 @@ SET(TARGET_SRC
|
||||
FFmpegDecoder.cpp
|
||||
FFmpegDecoderVideo.cpp
|
||||
FFmpegImageStream.cpp
|
||||
FFmpegAudioStream.cpp
|
||||
ReaderWriterFFmpeg.cpp
|
||||
)
|
||||
|
||||
@@ -30,6 +31,8 @@ SET(TARGET_H
|
||||
FFmpegDecoderVideo.hpp
|
||||
FFmpegHeaders.hpp
|
||||
FFmpegPacket.hpp
|
||||
FFmpegImageStream.hpp
|
||||
FFmpegAudioStream.hpp
|
||||
MessageQueue.hpp
|
||||
)
|
||||
|
||||
|
||||
79
src/osgPlugins/ffmpeg/FFmpegAudioStream.cpp
Normal file
79
src/osgPlugins/ffmpeg/FFmpegAudioStream.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
|
||||
#include "FFmpegAudioStream.hpp"
|
||||
|
||||
#include <OpenThreads/ScopedLock>
|
||||
#include <osg/Notify>
|
||||
|
||||
#include "FFmpegDecoder.hpp"
|
||||
#include "MessageQueue.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
||||
|
||||
namespace osgFFmpeg {
|
||||
|
||||
|
||||
|
||||
FFmpegAudioStream::FFmpegAudioStream(FFmpegDecoder* decoder):
|
||||
m_decoder(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
FFmpegAudioStream::FFmpegAudioStream(const FFmpegAudioStream & audio, const osg::CopyOp & copyop) :
|
||||
osg::AudioStream(audio, copyop)
|
||||
{
|
||||
}
|
||||
|
||||
FFmpegAudioStream::~FFmpegAudioStream()
|
||||
{
|
||||
}
|
||||
|
||||
void FFmpegAudioStream::setAudioSink(osg::AudioSink* audio_sink)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"FFmpegAudioStream::setAudioSink( "<<audio_sink<<")"<<std::endl;
|
||||
m_decoder->audio_decoder().setAudioSink(audio_sink);
|
||||
}
|
||||
|
||||
|
||||
void FFmpegAudioStream::consumeAudioBuffer(void * const buffer, const size_t size)
|
||||
{
|
||||
m_decoder->audio_decoder().fillBuffer(buffer, size);
|
||||
}
|
||||
|
||||
double FFmpegAudioStream::duration() const
|
||||
{
|
||||
return m_decoder->duration();
|
||||
}
|
||||
|
||||
|
||||
bool FFmpegAudioStream::audioStream() const
|
||||
{
|
||||
return m_decoder->audio_decoder().validContext();
|
||||
}
|
||||
|
||||
|
||||
|
||||
int FFmpegAudioStream::audioFrequency() const
|
||||
{
|
||||
return m_decoder->audio_decoder().frequency();
|
||||
}
|
||||
|
||||
|
||||
|
||||
int FFmpegAudioStream::audioNbChannels() const
|
||||
{
|
||||
return m_decoder->audio_decoder().nbChannels();
|
||||
}
|
||||
|
||||
|
||||
|
||||
osg::AudioStream::SampleFormat FFmpegAudioStream::audioSampleFormat() const
|
||||
{
|
||||
return m_decoder->audio_decoder().sampleFormat();
|
||||
}
|
||||
|
||||
|
||||
} // namespace osgFFmpeg
|
||||
43
src/osgPlugins/ffmpeg/FFmpegAudioStream.hpp
Normal file
43
src/osgPlugins/ffmpeg/FFmpegAudioStream.hpp
Normal file
@@ -0,0 +1,43 @@
|
||||
|
||||
#ifndef HEADER_GUARD_OSGFFMPEG_FFMPEG_AUDIO_STREAM_H
|
||||
#define HEADER_GUARD_OSGFFMPEG_FFMPEG_AUDIO_STREAM_H
|
||||
|
||||
#include <osg/AudioStream>
|
||||
#include "FFmpegDecoder.hpp"
|
||||
|
||||
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);
|
||||
|
||||
bool audioStream() const;
|
||||
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
|
||||
@@ -56,7 +56,7 @@ class FormatContextPtr
|
||||
};
|
||||
|
||||
|
||||
class FFmpegDecoder
|
||||
class FFmpegDecoder : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
@@ -106,9 +106,10 @@ void FFmpegDecoderAudio::run()
|
||||
|
||||
|
||||
|
||||
void FFmpegDecoderAudio::setAudioSink(osg::ref_ptr<osg::AudioSinkInterface> audio_sink)
|
||||
void FFmpegDecoderAudio::setAudioSink(osg::ref_ptr<osg::AudioSink> audio_sink)
|
||||
{
|
||||
// The FFmpegDecoderAudio object takes the responsability of destroying the audio_sink.
|
||||
osg::notify(osg::NOTICE)<<"Assigning "<<audio_sink<<std::endl;
|
||||
m_audio_sink = audio_sink;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
void open(AVStream * stream);
|
||||
virtual void run();
|
||||
|
||||
void setAudioSink(osg::ref_ptr<osg::AudioSinkInterface> audio_sink);
|
||||
void setAudioSink(osg::ref_ptr<osg::AudioSink> audio_sink);
|
||||
void fillBuffer(void * buffer, size_t size);
|
||||
|
||||
bool validContext() const;
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
private:
|
||||
|
||||
//typedef boost::shared_ptr<AVFrame> FramePtr;
|
||||
typedef osg::ref_ptr<osg::AudioSinkInterface> SinkPtr;
|
||||
typedef osg::ref_ptr<osg::AudioSink> SinkPtr;
|
||||
typedef std::vector<uint8_t> Buffer;
|
||||
|
||||
void decodeLoop();
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
|
||||
#include "FFmpegImageStream.hpp"
|
||||
#include "FFmpegAudioStream.hpp"
|
||||
|
||||
#include <OpenThreads/ScopedLock>
|
||||
#include <osg/Notify>
|
||||
|
||||
#include "FFmpegDecoder.hpp"
|
||||
#include "MessageQueue.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
||||
@@ -44,7 +42,6 @@ FFmpegImageStream::~FFmpegImageStream()
|
||||
quit(true);
|
||||
|
||||
delete m_commands;
|
||||
delete m_decoder;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,6 +60,13 @@ bool FFmpegImageStream::open(const std::string & filename)
|
||||
|
||||
m_decoder->video_decoder().setUserData(this);
|
||||
m_decoder->video_decoder().setPublishCallback(publishNewFrame);
|
||||
|
||||
if (m_decoder->audio_decoder().validContext())
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Attaching FFmpegAudioStream"<<std::endl;
|
||||
|
||||
getAudioStreams().push_back(new FFmpegAudioStream(m_decoder.get()));
|
||||
}
|
||||
|
||||
_status = PAUSED;
|
||||
applyLoopingMode();
|
||||
@@ -120,20 +124,6 @@ void FFmpegImageStream::quit(bool waitForThreadToExit)
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FFmpegImageStream::setAudioSink(osg::AudioSinkInterface* audio_sink)
|
||||
{
|
||||
m_decoder->audio_decoder().setAudioSink(audio_sink);
|
||||
}
|
||||
|
||||
|
||||
void FFmpegImageStream::consumeAudioBuffer(void * const buffer, const size_t size)
|
||||
{
|
||||
m_decoder->audio_decoder().fillBuffer(buffer, size);
|
||||
}
|
||||
|
||||
|
||||
|
||||
double FFmpegImageStream::duration() const
|
||||
{
|
||||
return m_decoder->duration();
|
||||
@@ -161,35 +151,6 @@ double FFmpegImageStream::videoFrameRate() const
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool FFmpegImageStream::audioStream() const
|
||||
{
|
||||
return m_decoder->audio_decoder().validContext();
|
||||
}
|
||||
|
||||
|
||||
|
||||
int FFmpegImageStream::audioFrequency() const
|
||||
{
|
||||
return m_decoder->audio_decoder().frequency();
|
||||
}
|
||||
|
||||
|
||||
|
||||
int FFmpegImageStream::audioNbChannels() const
|
||||
{
|
||||
return m_decoder->audio_decoder().nbChannels();
|
||||
}
|
||||
|
||||
|
||||
|
||||
osg::AudioStream::SampleFormat FFmpegImageStream::audioSampleFormat() const
|
||||
{
|
||||
return m_decoder->audio_decoder().sampleFormat();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FFmpegImageStream::run()
|
||||
{
|
||||
try
|
||||
|
||||
@@ -7,17 +7,15 @@
|
||||
#include <OpenThreads/Condition>
|
||||
#include <OpenThreads/Thread>
|
||||
|
||||
#include "FFmpegDecoder.hpp"
|
||||
#include "MessageQueue.hpp"
|
||||
|
||||
namespace osgFFmpeg
|
||||
{
|
||||
|
||||
class FFmpegDecoder;
|
||||
class FFmpegDecoderAudio;
|
||||
class FFmpegDecoderVideo;
|
||||
|
||||
template <class T>
|
||||
class MessageQueue;
|
||||
|
||||
|
||||
class FFmpegImageStream : public osg::ImageStream, public OpenThreads::Thread
|
||||
{
|
||||
public:
|
||||
@@ -34,15 +32,6 @@ namespace osgFFmpeg
|
||||
virtual void rewind();
|
||||
virtual void quit(bool waitForThreadToExit = true);
|
||||
|
||||
virtual void setAudioSink(osg::AudioSinkInterface* audio_sink);
|
||||
|
||||
void consumeAudioBuffer(void * const buffer, const size_t size);
|
||||
|
||||
bool audioStream() const;
|
||||
int audioFrequency() const;
|
||||
int audioNbChannels() const;
|
||||
osg::AudioStream::SampleFormat audioSampleFormat() const;
|
||||
|
||||
double duration() const;
|
||||
|
||||
bool videoAlphaChannel() const;
|
||||
@@ -76,7 +65,7 @@ namespace osgFFmpeg
|
||||
|
||||
static void publishNewFrame(const FFmpegDecoderVideo &, void * user_data);
|
||||
|
||||
FFmpegDecoder * m_decoder;
|
||||
osg::ref_ptr<FFmpegDecoder> m_decoder;
|
||||
CommandQueue * m_commands;
|
||||
|
||||
Mutex m_mutex;
|
||||
|
||||
Reference in New Issue
Block a user