Changeset 9847

Show
Ignore:
Timestamp:
03/03/09 17:51:01 (6 years ago)
Author:
robert
Message:

Introduce FFmpegAudioStream implementation

Location:
OpenSceneGraph/trunk
Files:
2 added
12 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/CMakeLists.txt

    r9817 r9847  
    311311FIND_PACKAGE(LibVNCServer) 
    312312FIND_PACKAGE(OurDCMTK) 
     313FIND_PACKAGE(OpenAL) 
    313314FIND_PACKAGE(XUL) 
    314315FIND_PACKAGE(FFmpeg) 
  • OpenSceneGraph/trunk/examples/osgmovie/CMakeLists.txt

    r7025 r9847  
    1 #this file is automatically generated  
    2  
     1# INCLUDE_DIRECTORIES( ${OPENAL_INCLUDE_DIR} ) 
    32 
    43SET(TARGET_SRC osgmovie.cpp ) 
    54SET(TARGET_ADDED_LIBRARIES osgGA ) 
     5 
     6# SET(TARGET_EXTERNAL_LIBRARIES ${OPENAL_LIBRARY} alut) 
     7 
    68#### end var setup  ### 
    79SETUP_EXAMPLE(osgmovie) 
  • OpenSceneGraph/trunk/examples/osgmovie/osgmovie.cpp

    r9705 r9847  
    321321} 
    322322 
     323class CustomAudioSink : public osg::AudioSink 
     324{ 
     325    public: 
     326     
     327        CustomAudioSink(osg::AudioStream* audioStream): 
     328            _playing(false), 
     329            _audioStream(audioStream) {} 
     330         
     331        virtual void startPlaying() 
     332        { 
     333            _playing = true;  
     334            osg::notify(osg::NOTICE)<<"CustomAudioSink()::startPlaying()"<<std::endl; 
     335             
     336            osg::notify(osg::NOTICE)<<"  audioFrequency()="<<_audioStream->audioFrequency()<<std::endl; 
     337            osg::notify(osg::NOTICE)<<"  audioNbChannels()="<<_audioStream->audioNbChannels()<<std::endl; 
     338            osg::notify(osg::NOTICE)<<"  audioSampleFormat()="<<_audioStream->audioSampleFormat()<<std::endl; 
     339             
     340        } 
     341        virtual bool playing() const { return _playing; } 
     342 
     343        bool                                _playing; 
     344        osg::observer_ptr<osg::AudioStream> _audioStream; 
     345}; 
     346 
    323347int main(int argc, char** argv) 
    324348{ 
     
    426450 
    427451    bool xyPlane = fullscreen; 
     452     
     453    bool useOpenALAudio = false; 
     454    while(arguments.read("--OpenAL")) { useOpenALAudio = true; } 
    428455 
    429456    for(int i=1;i<arguments.argc();++i) 
     
    433460            osg::Image* image = osgDB::readImageFile(arguments[i]); 
    434461            osg::ImageStream* imagestream = dynamic_cast<osg::ImageStream*>(image); 
    435             if (imagestream) imagestream->play(); 
     462            if (imagestream)  
     463            { 
     464                osg::ImageStream::AudioStreams& audioStreams = imagestream->getAudioStreams(); 
     465                if (useOpenALAudio && !audioStreams.empty()) 
     466                { 
     467                    osg::AudioStream* audioStream = audioStreams[0].get(); 
     468                    osg::notify(osg::NOTICE)<<"AudioStream read ["<<audioStream->getName()<<"]"<<std::endl; 
     469                    audioStream->setAudioSink(new CustomAudioSink(audioStream)); 
     470                } 
     471 
     472 
     473                imagestream->play(); 
     474            } 
    436475 
    437476            if (image) 
  • OpenSceneGraph/trunk/include/osg/AudioStream

    r9827 r9847  
    1919namespace osg { 
    2020 
    21 /** Pure virtual AudioSinkInterface bass class that is used to connect the audio system with AudioStreams. */ 
    22 class OSG_EXPORT AudioSinkInterface : public osg::Object 
     21/** Pure virtual AudioSink bass class that is used to connect the audio system with AudioStreams. */ 
     22class OSG_EXPORT AudioSink : public osg::Object 
    2323{ 
    2424public: 
    2525 
    26     AudioSinkInterface(); 
     26    AudioSink(); 
    2727 
    2828    virtual void startPlaying() = 0; 
     
    3737private: 
    3838 
    39     virtual AudioSinkInterface * cloneType() const { return 0; } 
    40     virtual AudioSinkInterface * clone(const osg::CopyOp &) const { return 0; } 
     39    virtual AudioSink * cloneType() const { return 0; } 
     40    virtual AudioSink * clone(const osg::CopyOp &) const { return 0; } 
    4141 
    4242    double  _delay; 
     
    5656        virtual const char* className() const { return "AudioStream"; } 
    5757 
    58         virtual void setAudioSink(osg::AudioSinkInterface* audio_sink) = 0; 
     58        virtual void setAudioSink(osg::AudioSink* audio_sink) = 0; 
    5959         
    6060        virtual void consumeAudioBuffer(void * const buffer, const size_t size) = 0; 
  • OpenSceneGraph/trunk/src/osg/AudioStream.cpp

    r9827 r9847  
    1616using namespace osg; 
    1717 
    18 AudioSinkInterface::AudioSinkInterface() : 
     18AudioSink::AudioSink() : 
    1919    _delay(0.0) 
    2020{ 
  • OpenSceneGraph/trunk/src/osgPlugins/CMakeLists.txt

    r9817 r9847  
    201201ENDIF(FFMPEG_FOUND) 
    202202 
     203IF(OPENAL_FOUND) 
     204    ADD_SUBDIRECTORY(OpenAL) 
     205ENDIF(OPENAL_FOUND) 
     206 
    203207IF(QUICKTIME_FOUND) 
    204208    ADD_SUBDIRECTORY(quicktime) 
  • OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/CMakeLists.txt

    r9842 r9847  
    2020    FFmpegDecoderVideo.cpp 
    2121    FFmpegImageStream.cpp 
     22    FFmpegAudioStream.cpp 
    2223    ReaderWriterFFmpeg.cpp 
    2324) 
     
    3132    FFmpegHeaders.hpp 
    3233    FFmpegPacket.hpp 
     34    FFmpegImageStream.hpp 
     35    FFmpegAudioStream.hpp 
    3336    MessageQueue.hpp 
    3437) 
  • OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoder.hpp

    r9826 r9847  
    5757 
    5858 
    59 class FFmpegDecoder 
     59class FFmpegDecoder : public osg::Referenced 
    6060{ 
    6161public: 
  • OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp

    r9827 r9847  
    107107 
    108108 
    109 void FFmpegDecoderAudio::setAudioSink(osg::ref_ptr<osg::AudioSinkInterface> audio_sink) 
     109void FFmpegDecoderAudio::setAudioSink(osg::ref_ptr<osg::AudioSink> audio_sink) 
    110110{ 
    111111    // The FFmpegDecoderAudio object takes the responsability of destroying the audio_sink. 
     112    osg::notify(osg::NOTICE)<<"Assigning "<<audio_sink<<std::endl; 
    112113    m_audio_sink = audio_sink; 
    113114} 
  • OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.hpp

    r9827 r9847  
    3232    virtual void run(); 
    3333 
    34     void setAudioSink(osg::ref_ptr<osg::AudioSinkInterface> audio_sink); 
     34    void setAudioSink(osg::ref_ptr<osg::AudioSink> audio_sink); 
    3535    void fillBuffer(void * buffer, size_t size); 
    3636 
     
    4343 
    4444    //typedef boost::shared_ptr<AVFrame> FramePtr; 
    45     typedef osg::ref_ptr<osg::AudioSinkInterface> SinkPtr; 
     45    typedef osg::ref_ptr<osg::AudioSink> SinkPtr; 
    4646    typedef std::vector<uint8_t> Buffer; 
    4747 
  • OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegImageStream.cpp

    r9827 r9847  
    11 
    22#include "FFmpegImageStream.hpp" 
     3#include "FFmpegAudioStream.hpp" 
    34 
    45#include <OpenThreads/ScopedLock> 
    56#include <osg/Notify> 
    6  
    7 #include "FFmpegDecoder.hpp" 
    8 #include "MessageQueue.hpp" 
    97 
    108#include <memory> 
     
    4543 
    4644    delete m_commands; 
    47     delete m_decoder; 
    4845} 
    4946 
     
    6461    m_decoder->video_decoder().setUserData(this); 
    6562    m_decoder->video_decoder().setPublishCallback(publishNewFrame); 
     63     
     64    if (m_decoder->audio_decoder().validContext()) 
     65    { 
     66        osg::notify(osg::NOTICE)<<"Attaching FFmpegAudioStream"<<std::endl; 
     67     
     68        getAudioStreams().push_back(new FFmpegAudioStream(m_decoder.get())); 
     69    } 
    6670 
    6771    _status = PAUSED; 
     
    121125 
    122126 
    123  
    124 void FFmpegImageStream::setAudioSink(osg::AudioSinkInterface* audio_sink) 
    125 {  
    126     m_decoder->audio_decoder().setAudioSink(audio_sink);  
    127 } 
    128  
    129  
    130 void FFmpegImageStream::consumeAudioBuffer(void * const buffer, const size_t size) 
    131 {  
    132     m_decoder->audio_decoder().fillBuffer(buffer, size); 
    133 } 
    134  
    135  
    136  
    137127double FFmpegImageStream::duration() const 
    138128{  
     
    160150    return m_decoder->video_decoder().frameRate();  
    161151} 
    162  
    163  
    164  
    165 bool FFmpegImageStream::audioStream() const  
    166 {  
    167     return m_decoder->audio_decoder().validContext();  
    168 } 
    169  
    170  
    171  
    172 int FFmpegImageStream::audioFrequency() const  
    173 {  
    174     return m_decoder->audio_decoder().frequency();  
    175 } 
    176  
    177  
    178  
    179 int FFmpegImageStream::audioNbChannels() const  
    180 {  
    181     return m_decoder->audio_decoder().nbChannels(); 
    182 } 
    183  
    184  
    185  
    186 osg::AudioStream::SampleFormat FFmpegImageStream::audioSampleFormat() const  
    187 {  
    188     return m_decoder->audio_decoder().sampleFormat();  
    189 } 
    190  
    191152 
    192153 
  • OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegImageStream.hpp

    r9843 r9847  
    88#include <OpenThreads/Thread> 
    99 
     10#include "FFmpegDecoder.hpp" 
     11#include "MessageQueue.hpp" 
     12 
    1013namespace osgFFmpeg 
    1114{ 
    1215 
    13     class FFmpegDecoder; 
    14     class FFmpegDecoderAudio; 
    15     class FFmpegDecoderVideo; 
    16  
    1716    template <class T> 
    1817    class MessageQueue; 
    19  
    2018 
    2119    class FFmpegImageStream : public osg::ImageStream, public OpenThreads::Thread 
     
    3432        virtual void rewind(); 
    3533        virtual void quit(bool waitForThreadToExit = true); 
    36  
    37         virtual void setAudioSink(osg::AudioSinkInterface* audio_sink); 
    38          
    39         void consumeAudioBuffer(void * const buffer, const size_t size); 
    40          
    41         bool audioStream() const; 
    42         int audioFrequency() const; 
    43         int audioNbChannels() const; 
    44         osg::AudioStream::SampleFormat audioSampleFormat() const; 
    4534 
    4635        double duration() const; 
     
    7766        static void publishNewFrame(const FFmpegDecoderVideo &, void * user_data); 
    7867 
    79         FFmpegDecoder *    m_decoder; 
     68        osg::ref_ptr<FFmpegDecoder>    m_decoder; 
    8069        CommandQueue *    m_commands; 
    8170