root/OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.hpp @ 9847

Revision 9847, 2.2 kB (checked in by robert, 6 years ago)

Introduce FFmpegAudioStream implementation

RevLine 
[9816]1
2#ifndef HEADER_GUARD_OSGFFMPEG_FFMPEG_DECODER_AUDIO_H
3#define HEADER_GUARD_OSGFFMPEG_FFMPEG_DECODER_AUDIO_H
4
5#include <OpenThreads/Thread>
6
7#include "FFmpegClocks.hpp"
8#include "FFmpegPacket.hpp"
9
[9827]10#include <osg/AudioStream>
11
[9818]12#include "BoundedMessageQueue.hpp"
[9816]13
14
[9818]15
[9827]16
[9816]17namespace osgFFmpeg {
18
19
20
21class FFmpegDecoderAudio : public OpenThreads::Thread
22{
23public:
24
25    typedef BoundedMessageQueue<FFmpegPacket> PacketQueue;
26    typedef void (* PublishFunc) (const FFmpegDecoderAudio & decoder, void * user_data);
27
28    FFmpegDecoderAudio(PacketQueue & packets, FFmpegClocks & clocks);
29    ~FFmpegDecoderAudio();
30
31    void open(AVStream * stream);
32    virtual void run();
33
[9847]34    void setAudioSink(osg::ref_ptr<osg::AudioSink> audio_sink);
[9816]35    void fillBuffer(void * buffer, size_t size);
36
37    bool validContext() const;
38    int frequency() const;
39    int nbChannels() const;
[9827]40    osg::AudioStream::SampleFormat sampleFormat() const;
[9816]41
42private:
43
44    //typedef boost::shared_ptr<AVFrame> FramePtr;
[9847]45    typedef osg::ref_ptr<osg::AudioSink> SinkPtr;
[9816]46    typedef std::vector<uint8_t> Buffer;
47
48    void decodeLoop();
49    void adjustBufferEndTps(size_t buffer_size);
50    size_t decodeFrame(void * buffer, size_t size);
51
52
53    PacketQueue &        m_packets;
54    FFmpegClocks &        m_clocks;
55    AVStream *            m_stream;
56    AVCodecContext *    m_context;
57    FFmpegPacket        m_packet;
58    const uint8_t *        m_packet_data;
59    int                    m_bytes_remaining;
60
61    Buffer                m_audio_buffer;
62    size_t                m_audio_buf_size;
63    size_t                m_audio_buf_index;
64
65    int                    m_frequency;
66    int                    m_nb_channels;
[9827]67    osg::AudioStream::SampleFormat    m_sample_format;
[9816]68
69    SinkPtr                m_audio_sink;
70
71    bool                m_end_of_stream;
72    volatile bool        m_exit;
73};
74
75
76
77
78
79inline bool FFmpegDecoderAudio::validContext() const
80{
81    return m_context != 0;
82}
83
84
85inline int FFmpegDecoderAudio::frequency() const
86{
87    return m_frequency;
88}
89
90
91inline int FFmpegDecoderAudio::nbChannels() const
92{
93    return m_nb_channels;
94}
95
96
[9827]97inline osg::AudioStream::SampleFormat FFmpegDecoderAudio::sampleFormat() const
[9816]98{
99    return m_sample_format;
100}
101
102
103
104} // namespace osgFFmpeg
105
106
107
108#endif // HEADER_GUARD_OSGFFMPEG_FFMPEG_DECODER_AUDIO_H
Note: See TracBrowser for help on using the browser.