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

Revision 9818, 2.3 kB (checked in by robert, 6 years ago)

Tweaks to handle more modern version of ffmpeg compiled form source.

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