~ubuntu-branches/ubuntu/utopic/sflphone/utopic-proposed

« back to all changes in this revision

Viewing changes to daemon/src/audio/audiolayer.h

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (4.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20140128182336-jrsv0k9u6cawc068
Tags: 1.3.0-1
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *  Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
 
2
 *  Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
3
3
 *  Author: Yan Morin <yan.morin@savoirfairelinux.com>
4
4
 *  Author:  Jerome Oufella <jerome.oufella@savoirfairelinux.com>
5
5
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
34
34
#ifndef AUDIO_LAYER_H_
35
35
#define AUDIO_LAYER_H_
36
36
 
37
 
#include <pthread.h>
 
37
#include <mutex>
38
38
#include <sys/time.h>
39
39
#include <vector>
40
40
#include "ringbuffer.h"
67
67
            SFL_PCM_RINGTONE = 0x0024       /** To open the ringtone device only */
68
68
        };
69
69
 
70
 
        enum PlaybackMode {
71
 
            NONE = 0,
72
 
            TONE,
73
 
            RINGTONE,
74
 
            VOICE,
75
 
            URGENT,
76
 
            ZEROS
77
 
        };
78
 
 
79
 
        AudioLayer();
 
70
        AudioLayer(const AudioPreference &);
80
71
        virtual ~AudioLayer();
81
72
 
82
73
        virtual std::vector<std::string> getCaptureDeviceList() const = 0;
109
100
            return isStarted_;
110
101
        }
111
102
 
112
 
        PlaybackMode getPlaybackMode() const {
113
 
            return playbackMode_;
114
 
        }
115
 
 
116
 
        void setPlaybackMode(PlaybackMode mode) {
117
 
            playbackMode_ = mode;
118
 
        }
119
 
 
120
103
        /**
121
104
         * Send a chunk of data to the hardware buffer to start the playback
122
105
         * Copy data in the urgent buffer.
123
106
         * @param buffer The buffer containing the data to be played ( ringtones )
124
 
         * @param toCopy The size of the buffer
125
107
         */
126
 
        void putUrgent(void* buffer, int toCopy);
 
108
        void putUrgent(AudioBuffer& buffer);
127
109
 
128
110
        /**
129
111
         * Flush main buffer
135
117
         */
136
118
        void flushUrgent();
137
119
 
138
 
        /**
139
 
         * Apply gain to audio frame
140
 
         */
141
 
        static void applyGain(SFLDataFormat *src , int samples, int gain);
142
 
 
143
 
        /**
144
 
         * Convert audio amplitude value from linear value to dB
145
 
         */
146
 
        static double amplitudeLinearToDB(double value) {
147
 
            return 20.0 * log10(value);
148
 
        }
149
 
 
150
 
        /**
151
 
         * Convert audio amplitude from dB to Linear value
152
 
         */
153
 
        static double ampluitudeDBToLinear(double value) {
154
 
            return pow(10.0, value / 20.0);
 
120
        bool isCaptureMuted() const {
 
121
            return isCaptureMuted_;
 
122
        }
 
123
 
 
124
        /**
 
125
         * Mute capture (microphone)
 
126
         */
 
127
        void muteCapture(bool muted) {
 
128
            isCaptureMuted_ = muted;
 
129
        }
 
130
 
 
131
        bool isPlaybackMuted() const {
 
132
            return isPlaybackMuted_;
 
133
        }
 
134
 
 
135
        /**
 
136
         * Mute playback
 
137
         */
 
138
        void mutePlayback(bool muted) {
 
139
            isPlaybackMuted_ = muted;
155
140
        }
156
141
 
157
142
        /**
158
143
         * Set capture stream gain (microphone)
 
144
         * Range should be [-1.0, 1.0]
159
145
         */
160
 
        void setCaptureGain(unsigned int gain) {
 
146
        void setCaptureGain(double gain) {
161
147
            captureGain_ = gain;
162
148
        }
163
149
 
164
150
        /**
165
 
         * Set capture stream gain (microphone)
 
151
         * Get capture stream gain (microphone)
166
152
         */
167
 
       unsigned int getCaptureGain(void) {
 
153
        double getCaptureGain() const {
168
154
            return captureGain_;
169
155
        }
170
156
 
171
157
        /**
172
158
         * Set playback stream gain (speaker)
 
159
         * Range should be [-1.0, 1.0]
173
160
         */
174
 
        void setPlaybackGain(unsigned int gain) {
 
161
        void setPlaybackGain(double gain) {
175
162
            playbackGain_ = gain;
176
163
        }
177
164
 
178
165
        /**
179
166
         * Get playback stream gain (speaker)
180
167
         */
181
 
        unsigned int getPlaybackGain(void) {
 
168
        double getPlaybackGain() const {
182
169
            return playbackGain_;
183
170
        }
184
171
 
196
183
         */
197
184
        void notifyIncomingCall();
198
185
 
 
186
        virtual void updatePreference(AudioPreference &pref, int index, PCMType type) = 0;
 
187
 
 
188
    protected:
 
189
 
 
190
        /**
 
191
         * True if capture is not to be used
 
192
         */
 
193
        bool isCaptureMuted_;
 
194
 
 
195
        /**
 
196
         * True if playback is not to be used
 
197
         */
 
198
        bool isPlaybackMuted_;
 
199
 
199
200
        /**
200
201
         * Gain applied to mic signal
201
202
         */
202
 
        static unsigned int captureGain_;
 
203
        double captureGain_;
203
204
 
204
205
        /**
205
206
         * Gain applied to playback signal
206
207
         */
207
 
        static unsigned int playbackGain_;
208
 
 
209
 
        virtual void updatePreference(AudioPreference &pref, int index, PCMType type) = 0;
210
 
 
211
 
    protected:
 
208
        double playbackGain_;
 
209
 
212
210
        /**
213
211
         * Whether or not the audio layer stream is started
214
212
         */
215
213
        bool isStarted_;
216
214
 
217
 
        PlaybackMode playbackMode_;
218
 
 
219
215
        /**
220
216
         * Urgent ring buffer used for ringtones
221
217
         */
230
226
        /**
231
227
         * Lock for the entire audio layer
232
228
         */
233
 
        pthread_mutex_t mutex_;
 
229
        std::mutex mutex_;
234
230
 
235
231
        /**
236
232
         * Remove audio offset that can be introduced by certain cheap audio device
243
239
        SamplerateConverter converter_;
244
240
 
245
241
    private:
 
242
 
246
243
        /**
247
244
         * Time of the last incoming call notification
248
245
         */