~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to daemon/src/audio/opensl/opensllayer.h

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (1.1.11)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20140128182336-3xenud1kbnwmf3mz
* 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
/*
 
2
 *  Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 Savoir-Faire Linux Inc.
 
3
 *  Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
 
4
 *
 
5
 *  This program is free software; you can redistribute it and/or modify
 
6
 *  it under the terms of the GNU General Public License as published by
 
7
 *  the Free Software Foundation; either version 3 of the License, or
 
8
 *  (at your option) any later version.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
18
 *
 
19
 *  Additional permission under GNU GPL version 3 section 7:
 
20
 *
 
21
 *  If you modify this program, or any covered work, by linking or
 
22
 *  combining it with the OpenSSL project's OpenSSL library (or a
 
23
 *  modified version of that library), containing parts covered by the
 
24
 *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
 
25
 *  grants you additional permission to convey the resulting work.
 
26
 *  Corresponding Source for a non-source form of such a combination
 
27
 *  shall include the source code for the parts of OpenSSL used as well
 
28
 *  as that of the covered work.
 
29
 */
 
30
 
 
31
#ifndef _OPENSL_LAYER_H
 
32
#define _OPENSL_LAYER_H
 
33
 
 
34
#include <SLES/OpenSLES.h>
 
35
#include <SLES/OpenSLES_Android.h>
 
36
#include <vector>
 
37
 
 
38
#include "audio/audiolayer.h"
 
39
 
 
40
 
 
41
 
 
42
enum PCMType {
 
43
    SFL_PCM_BOTH = 0x0021,          /** To open both playback and capture devices */
 
44
    SFL_PCM_PLAYBACK = 0x0022,      /** To open playback device only */
 
45
    SFL_PCM_CAPTURE = 0x0023,       /** To open capture device only */
 
46
    SFL_PCM_RINGTONE = 0x0024       /** To open the ringtone device only */
 
47
};
 
48
 
 
49
class AudioPreference;
 
50
 
 
51
#include "noncopyable.h"
 
52
 
 
53
class OpenSLThread;
 
54
 
 
55
#define ANDROID_BUFFER_QUEUE_LENGTH 2U
 
56
#define BUFFER_SIZE 80U
 
57
 
 
58
#define MAX_NUMBER_INTERFACES 5
 
59
#define MAX_NUMBER_INPUT_DEVICES 3
 
60
 
 
61
 
 
62
/**
 
63
 * @file  OpenSLLayer.h
 
64
 * @brief Main sound class for android. Manages the data transfers between the application and the hardware.
 
65
 */
 
66
 
 
67
class OpenSLLayer : public AudioLayer {
 
68
    public:
 
69
        /**
 
70
         * Constructor
 
71
         */
 
72
        OpenSLLayer(const AudioPreference &pref);
 
73
 
 
74
        /**
 
75
         * Destructor
 
76
         */
 
77
        ~OpenSLLayer();
 
78
 
 
79
        /**
 
80
         * Start the capture stream and prepare the playback stream.
 
81
         * The playback starts accordingly to its threshold
 
82
         */
 
83
        virtual void startStream();
 
84
 
 
85
        /**
 
86
         * Stop the playback and capture streams.
 
87
         * Drops the pending frames and put the capture and playback handles to PREPARED state
 
88
         */
 
89
        virtual void stopStream();
 
90
 
 
91
        /**
 
92
         * Scan the sound card available for capture on the system
 
93
         * @return std::vector<std::string> The vector containing the string description of the card
 
94
         */
 
95
        virtual std::vector<std::string> getCaptureDeviceList() const;
 
96
 
 
97
        /**
 
98
         * Scan the sound card available for capture on the system
 
99
         * @return std::vector<std::string> The vector containing the string description of the card
 
100
         */
 
101
        virtual std::vector<std::string> getPlaybackDeviceList() const;
 
102
 
 
103
        void initAudioEngine();
 
104
 
 
105
        void shutdownAudioEngine();
 
106
 
 
107
        void initAudioPlayback();
 
108
 
 
109
        void initAudioCapture();
 
110
 
 
111
        void startAudioPlayback();
 
112
 
 
113
        void startAudioCapture();
 
114
 
 
115
        void stopAudioPlayback();
 
116
 
 
117
        void stopAudioCapture();
 
118
 
 
119
        virtual int getAudioDeviceIndex(const std::string&) const {
 
120
            return 0;
 
121
        }
 
122
 
 
123
        virtual std::string getAudioDeviceName(int, AudioLayer::PCMType) const {
 
124
            return "";
 
125
        }
 
126
 
 
127
    private:
 
128
        typedef std::vector<AudioBuffer> AudioBufferStack;
 
129
 
 
130
 
 
131
        bool audioBufferFillWithZeros(AudioBuffer &buffer);
 
132
 
 
133
        /**
 
134
         * Here fill the input buffer with tone or ringtone samples
 
135
         */
 
136
        bool audioPlaybackFillWithToneOrRingtone(AudioBuffer &buffer);
 
137
 
 
138
        bool audioPlaybackFillWithUrgent(AudioBuffer &buffer, size_t bytesAvail);
 
139
 
 
140
        bool audioPlaybackFillWithVoice(AudioBuffer &buffer, size_t bytesAvail);
 
141
 
 
142
        void audioCaptureFillBuffer(AudioBuffer &buffer);
 
143
 
 
144
 
 
145
        /**
 
146
         * This is the main audio playabck callback called by the OpenSL layer
 
147
         */
 
148
        static void audioPlaybackCallback(SLAndroidSimpleBufferQueueItf bq, void *context);
 
149
 
 
150
        /**
 
151
         * This is the main audio capture callback called by the OpenSL layer
 
152
         */
 
153
        static void audioCaptureCallback(SLAndroidSimpleBufferQueueItf bq, void *context);
 
154
 
 
155
        /**
 
156
         * Get the index of the audio card for capture
 
157
         * @return int The index of the card used for capture
 
158
         *                     0 for the first available card on the system, 1 ...
 
159
         */
 
160
        virtual int getIndexCapture() const {
 
161
            return indexIn_;
 
162
        }
 
163
 
 
164
        /**
 
165
         * Get the index of the audio card for playback
 
166
         * @return int The index of the card used for playback
 
167
         *                     0 for the first available card on the system, 1 ...
 
168
         */
 
169
        virtual int getIndexPlayback() const {
 
170
            return indexOut_;
 
171
        }
 
172
 
 
173
        /**
 
174
         * Get the index of the audio card for ringtone (could be differnet from playback)
 
175
         * @return int The index of the card used for ringtone
 
176
         *                 0 for the first available card on the system, 1 ...
 
177
         */
 
178
        virtual int getIndexRingtone() const {
 
179
            return indexRing_;
 
180
        }
 
181
 
 
182
        AudioBuffer &getNextPlaybackBuffer(void) {
 
183
            return playbackBufferStack_[playbackBufferIndex_];
 
184
        }
 
185
 
 
186
        AudioBuffer &getNextRecordBuffer(void) {
 
187
            return recordBufferStack_[recordBufferIndex_];
 
188
        }
 
189
 
 
190
        void incrementPlaybackIndex(void) {
 
191
            playbackBufferIndex_ = (playbackBufferIndex_ + 1) % NB_BUFFER_PLAYBACK_QUEUE;
 
192
        }
 
193
 
 
194
        void incrementRecordIndex(void) {
 
195
            recordBufferIndex_ = (recordBufferIndex_ + 1) % NB_BUFFER_CAPTURE_QUEUE;
 
196
        }
 
197
 
 
198
                void CheckErr( SLresult res );
 
199
 
 
200
        void playback(SLAndroidSimpleBufferQueueItf queue);
 
201
        void capture(SLAndroidSimpleBufferQueueItf queue);
 
202
 
 
203
        void dumpAvailableEngineInterfaces();
 
204
        friend class OpenSLThread;
 
205
 
 
206
        static const int NB_BUFFER_PLAYBACK_QUEUE;
 
207
 
 
208
        static const int NB_BUFFER_CAPTURE_QUEUE;
 
209
 
 
210
        /**
 
211
         * Number of audio cards on which capture stream has been opened
 
212
         */
 
213
        int indexIn_;
 
214
 
 
215
        /**
 
216
         * Number of audio cards on which playback stream has been opened
 
217
         */
 
218
        int indexOut_;
 
219
 
 
220
        /**
 
221
         * Number of audio cards on which ringtone stream has been opened
 
222
         */
 
223
        int indexRing_;
 
224
 
 
225
        NON_COPYABLE(OpenSLLayer);
 
226
 
 
227
        virtual void updatePreference(AudioPreference &pref, int index, PCMType type);
 
228
 
 
229
        OpenSLThread *audioThread_;
 
230
 
 
231
        /**
 
232
         * OpenSL standard object interface
 
233
         */
 
234
        SLObjectItf engineObject_;
 
235
 
 
236
        /**
 
237
         * OpenSL sound engine interface
 
238
         */
 
239
        SLEngineItf engineInterface_;
 
240
 
 
241
        /**
 
242
         * Output mix interface
 
243
         */
 
244
        SLObjectItf outputMixer_;
 
245
        SLObjectItf playerObject_;
 
246
        SLObjectItf recorderObject_;
 
247
 
 
248
 
 
249
        SLOutputMixItf outputMixInterface_;
 
250
        SLPlayItf playerInterface_;
 
251
 
 
252
        SLRecordItf recorderInterface_;
 
253
 
 
254
                SLAudioIODeviceCapabilitiesItf AudioIODeviceCapabilitiesItf;
 
255
                SLAudioInputDescriptor AudioInputDescriptor;
 
256
 
 
257
        /**
 
258
         * OpenSL playback buffer
 
259
         */
 
260
        SLAndroidSimpleBufferQueueItf playbackBufferQueue_;
 
261
        SLAndroidSimpleBufferQueueItf recorderBufferQueue_;
 
262
 
 
263
        int playbackBufferIndex_;
 
264
        int recordBufferIndex_;
 
265
 
 
266
                bool bufferIsFilled_;
 
267
 
 
268
        AudioBufferStack playbackBufferStack_;
 
269
        AudioBufferStack recordBufferStack_;
 
270
};
 
271
 
 
272
#endif // _OPENSL_LAYER_H_