summaryrefslogtreecommitdiffstats
path: root/kradio3/plugins/oss-sound/oss-sound.h
blob: c8dadfddfd339a155337ba73ca8a3001945f295a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/***************************************************************************
                          oss-sound.h  -  description
                             -------------------
    begin                : Sun Mar 21 2004
    copyright            : (C) 2004 by Martin Witte
    email                : witte@kawo1.rwth-aachen.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef _KRADIO_OSS_SOUND_H
#define _KRADIO_OSS_SOUND_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "../../src/include/ringbuffer.h"
#include "../../src/include/plugins.h"
#include "../../src/include/soundstreamclient_interfaces.h"

#include <tqobject.h>
#include <tqtimer.h>

enum DUPLEX_MODE { DUPLEX_UNKNOWN, DUPLEX_FULL, DUPLEX_HALF };


struct SoundStreamConfig
{
    SoundStreamConfig()
        : m_ActiveMode(false),
          m_Channel(-1),
          m_Volume(-1)
       {}

    SoundStreamConfig(int _channel, bool active_mode = true)
        : m_ActiveMode(active_mode),
          m_Channel(_channel),
          m_Volume(-1)
       {}

    SoundStreamConfig(const SoundStreamConfig &c)
        : m_ActiveMode(c.m_ActiveMode),
          m_Channel(c.m_Channel),
          m_Volume(c.m_Volume)
       {}

    bool           m_ActiveMode;
    int            m_Channel;
    float          m_Volume;
};


class OSSSoundDevice : public TQObject,
                       public PluginBase,
                       public ISoundStreamClient
{
Q_OBJECT
  TQ_OBJECT

public:
    OSSSoundDevice (const TQString &name);
    virtual ~OSSSoundDevice ();

    virtual bool   connectI(Interface *i);
    virtual bool   disconnectI(Interface *i);

    // PluginBase

public:
    virtual void   saveState (KConfig *) const;
    virtual void   restoreState (KConfig *);

    virtual TQString pluginClassName() const { return "OSSSoundDevice"; }

    virtual const TQString &name() const { return PluginBase::name(); }
    virtual       TQString &name()       { return PluginBase::name(); }

    virtual ConfigPageInfo  createConfigurationPage();
    virtual AboutPageInfo   createAboutPage();

    // ISoundStreamClient: direct device access

RECEIVERS:
    void noticeConnectedI (ISoundStreamServer *s, bool pointer_valid);
    bool preparePlayback(SoundStreamID id, const TQString &channel, bool active_mode, bool start_immediately);
    bool prepareCapture(SoundStreamID id,  const TQString &channel);
    bool releasePlayback(SoundStreamID id);
    bool releaseCapture(SoundStreamID id);

ANSWERS:
    bool supportsPlayback() const;
    bool supportsCapture()  const;

    TQString getSoundStreamClientDescription() const;

    // ISoundStreamClient: mixer access

protected:
    void getMixerChannels(int query_playback_or_rec_tqmask, TQStringList &retval, TQMap<TQString, int> &revmap) const;

ANSWERS:
    const TQStringList &getPlaybackChannels() const;
    const TQStringList &getCaptureChannels() const;

RECEIVERS:
    bool setPlaybackVolume(SoundStreamID id, float volume);
    bool setCaptureVolume(SoundStreamID id,  float volume);
    bool getPlaybackVolume(SoundStreamID id, float &volume) const;
    bool getCaptureVolume(SoundStreamID id,  float &volume) const;

    // ISoundStreamClient: generic broadcasts

RECEIVERS:
    bool startPlayback(SoundStreamID id);
    bool pausePlayback(SoundStreamID id);
    bool stopPlayback(SoundStreamID id);
    bool isPlaybackRunning(SoundStreamID id, bool &b) const;

    bool startCaptureWithFormat(SoundStreamID      id,
                      const SoundFormat &proposed_format,
                      SoundFormat       &real_format,
                      bool               force_format);
    bool stopCapture(SoundStreamID id);
    bool isCaptureRunning(SoundStreamID id, bool &b, SoundFormat &sf) const;

    bool noticeSoundStreamClosed(SoundStreamID id);
    bool noticeSoundStreamRedirected(SoundStreamID oldID, SoundStreamID newID);

    bool noticeSoundStreamData(SoundStreamID id,
                               const SoundFormat &,
                               const char *data, size_t size, size_t &consumed_size,
                               const SoundMetaData &md
                              );


    // Config Access

    int            getBufferSize()      const { return m_BufferSize; }
    bool           isPlaybackEnabled()  const { return m_EnablePlayback; }
    bool           isCaptureEnabled()   const { return m_EnableCapture;  }
    const TQString &getDSPDeviceName()   const { return m_DSPDeviceName; }
    const TQString &getMixerDeviceName() const { return m_MixerDeviceName; }

    void           setBufferSize(int s);
    void           enablePlayback(bool on);
    void           enableCapture(bool on);
    void           setDSPDeviceName(const TQString &s);
    void           setMixerDeviceName(const TQString &dev_name);

    // own functions

    static int getOSSFormat(const SoundFormat &f);

protected slots:

    void   slotPoll();

signals:

    void   sigUpdateConfig();

protected:

    bool   openDSPDevice(const SoundFormat &format, bool reopen = false);
    bool   closeDSPDevice(bool force = false);

    bool   openMixerDevice(bool reopen = false);
    bool   closeMixerDevice(bool force = false);

    void   checkMixerVolume(SoundStreamID id);
    float  readMixerVolume(int channel) const;
    float  writeMixerVolume(int channel, float vol);

    void   selectCaptureChannel (int channel);

    TQString         m_DSPDeviceName,
                    m_MixerDeviceName;
    int             m_DSP_fd,
                    m_Mixer_fd;
    DUPLEX_MODE     m_DuplexMode;
    SoundFormat     m_DSPFormat;

    TQStringList          m_PlaybackChannels,
                         m_CaptureChannels;
    TQMap<TQString, int>   m_revPlaybackChannels,
                         m_revCaptureChannels;

    TQMap<SoundStreamID, SoundStreamConfig>
                    m_PlaybackStreams,
                    m_CaptureStreams;

    TQValueList<SoundStreamID>
                    m_PassivePlaybackStreams;
    SoundStreamID   m_PlaybackStreamID,
                    m_CaptureStreamID;

    size_t          m_BufferSize;
    RingBuffer      m_PlaybackBuffer,
                    m_CaptureBuffer;

    unsigned        m_CaptureRequestCounter;
    TQ_UINT64        m_CapturePos;
    time_t          m_CaptureStartTime;


    size_t          //m_PlaybackSkipCount,
                    m_CaptureSkipCount;

    bool            m_EnablePlayback,
                    m_EnableCapture;

    TQTimer          m_PollingTimer;
};



#endif