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

Revision 9816, 2.3 kB (checked in by robert, 5 years ago)

From Tanguy Fautre (Aris Technologies), ffmpeg plugin

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