]> camargo.eng.br - camargo/neiasound.git/blob - src/nSoundStreamer.h
Initial commit
[camargo/neiasound.git] / src / nSoundStreamer.h
1 #ifndef NSOUNDSTREAMER_H
2 #define NSOUNDSTREAMER_H
3
4 #include <QObject>
5 #include <QThread>
6 #include <QMutex>
7
8 #include "nSoundFormat.h"
9
10 class nSoundSystem;
11 class nSoundSource;
12 class nSoundBag;
13 class nSoundStream;
14 class nSoundStreamerPlaylist;
15
16
17 class nSoundStreamerUpdater;
18
19 class nSoundStreamer : public QObject
20 {
21     Q_OBJECT
22     Q_PROPERTY(nSoundSource* source READ source WRITE setSource NOTIFY sourceChanged)
23     Q_PROPERTY(nSoundStreamerPlaylist* playlist READ playlist WRITE setPlaylist NOTIFY playlistChanged)
24 public:
25     explicit nSoundStreamer(QString name, nSoundSource * source,  nSoundStreamerPlaylist * playlist, nSoundSystem * parent);
26     virtual ~nSoundStreamer();
27
28     nSoundSource* source() const
29     {
30         return m_source;
31     }
32
33     nSoundStreamerPlaylist* playlist() const
34     {
35         return m_playlist;
36     }
37
38 signals:
39
40
41     void sourceChanged(nSoundSource* arg);
42
43     void playlistChanged(nSoundStreamerPlaylist* arg);
44
45 public slots:
46     void update(float);
47     void rewind();
48
49     void setSource(nSoundSource* arg)
50     {
51         if (m_source == arg)
52             return;
53
54         m_source = arg;
55         emit sourceChanged(arg);
56     }
57
58     void setPlaylist(nSoundStreamerPlaylist* arg)
59     {
60         if (m_playlist == arg)
61             return;
62
63         m_playlist = arg;
64         emit playlistChanged(arg);
65     }
66
67 private:
68     friend class nSoundStreamerUpdater;
69
70     bool fillAndQueueBuffer(unsigned int buffer);
71     int openalFormat(nSoundFormat format);
72
73     nSoundStreamerPlaylist * m_playlist;
74     int m_currentStream;
75
76     nSoundSource * m_source;
77     nSoundBag * m_bag;
78
79     bool m_keepStreaming;
80     unsigned int m_buffer0, m_buffer1, m_buffer2;
81
82     QMutex _mutex;
83     nSoundStreamerUpdater * m_updater;
84
85 };
86
87
88 class nSoundStreamerUpdater : public QObject
89 {
90     Q_OBJECT
91
92 public:
93     nSoundStreamerUpdater(nSoundStreamer * parent);
94     ~nSoundStreamerUpdater();
95
96     void setup();
97     void timerEvent(QTimerEvent *);
98 private:
99     friend class nSoundStreamer;
100     nSoundStreamer * _streamer;
101     bool _keepGoing;
102 };
103
104 #endif // NSOUNDSTREAMER_H