~ubuntu-branches/ubuntu/saucy/sflphone/saucy

« back to all changes in this revision

Viewing changes to sflphone-common/src/iax/iaxvoiplink.h

  • Committer: Bazaar Package Importer
  • Author(s): Francois Marier
  • Date: 2010-12-24 16:33:55 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20101224163355-tkvvikqxbrbav6up
Tags: 0.9.11-1
* New upstream release
* Add new build dependencies on libwebkit-dev and libyaml-dev

* Bump Standards-Version up to 3.9.1
* Bump debhelper compatibility to 8
* Patch another typo in the upstream code (lintian notice)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
4
4
 *  Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com>
5
5
 *  Author: Yan Morin <yan.morin@savoirfairelinux.com>
6
 
 *                                                                              
 
6
 *
7
7
 *  This program is free software; you can redistribute it and/or modify
8
8
 *  it under the terms of the GNU General Public License as published by
9
9
 *  the Free Software Foundation; either version 3 of the License, or
10
10
 *  (at your option) any later version.
11
 
 *                                                                                
 
11
 *
12
12
 *  This program is distributed in the hope that it will be useful,
13
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
15
 *  GNU General Public License for more details.
16
 
 *                                                                              
 
16
 *
17
17
 *  You should have received a copy of the GNU General Public License
18
18
 *  along with this program; if not, write to the Free Software
19
19
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
40
40
#include "audio/samplerateconverter.h"
41
41
#include "hooks/urlhook.h"
42
42
 
 
43
#include "im/InstantMessaging.h"
 
44
 
43
45
class EventThread;
44
46
class IAXCall;
45
47
 
48
50
 
49
51
/**
50
52
 * @file iaxvoiplink.h
51
 
 * @brief VoIPLink contains a thread that listen to external events 
 
53
 * @brief VoIPLink contains a thread that listen to external events
52
54
 * and contains IAX Call related functions
53
55
 */
54
56
 
55
57
class IAXVoIPLink : public VoIPLink
56
58
{
57
 
  public:
58
 
  
59
 
    /**
60
 
     * Constructor
61
 
     * @param accountID The account containing the voip link
62
 
     */
63
 
    IAXVoIPLink(const AccountID& accountID);
64
 
 
65
 
    /**
66
 
     * Destructor
67
 
     */
68
 
    ~IAXVoIPLink();
69
 
 
70
 
    /**
71
 
     *  Listen to events sent by the call manager ( asterisk, etc .. )
72
 
     */
73
 
    void getEvent(void);
74
 
    
75
 
    /**
76
 
     * Init the voip link
77
 
     * @return true if successful
78
 
     *        false otherwise
79
 
     */
80
 
    bool init (void);
81
 
    
82
 
    /**
83
 
     * Terminate a voip link by clearing the call list
84
 
     */
85
 
    void terminate (void);
86
 
 
87
 
    /**
88
 
     * Terminate on call
89
 
     */
90
 
    void terminateOneCall(const CallID& id);
91
 
 
92
 
    /**
93
 
     * Send out registration
94
 
     * @return bool The new registration state (are we registered ?)
95
 
     */
96
 
    int sendRegister (AccountID id);
97
 
 
98
 
    /**
99
 
     * Destroy registration session
100
 
     * @todo Send an IAX_COMMAND_REGREL to force unregistration upstream.
101
 
     *       Urgency: low
102
 
     * @return bool true if we're registered upstream
103
 
     *            false otherwise
104
 
     */
105
 
    int sendUnregister (AccountID id);
106
 
 
107
 
    /**
108
 
     * Create a new outgoing call
109
 
     * @param id  The ID of the call
110
 
     * @param toUrl The address to call
111
 
     * @return Call*  A pointer on the call
112
 
     */
113
 
    Call* newOutgoingCall(const CallID& id, const std::string& toUrl);
114
 
    
115
 
    /**
116
 
     * Answer a call 
117
 
     * @param id The ID of the call
118
 
     * @return bool true on success
119
 
     *            false otherwise
120
 
     */
121
 
    bool answer(const CallID& id);
122
 
 
123
 
    /**
124
 
     * Hangup a call 
125
 
     * @param id The ID of the call
126
 
     * @return bool true on success
127
 
     *            false otherwise
128
 
     */
129
 
    bool hangup(const CallID& id);
130
 
 
131
 
    /**
132
 
     * Peer Hungup a call 
133
 
     * @param id The ID of the call
134
 
     * @return bool true on success
135
 
     *            false otherwise
136
 
     */
137
 
    bool peerHungup(const CallID& id);
138
 
 
139
 
    /**
140
 
     * Cancel a call 
141
 
     * @param id The ID of the call
142
 
     * @return bool true on success
143
 
     *            false otherwise
144
 
     */
145
 
    bool cancel(const CallID& id UNUSED ) { return false; }
146
 
    
147
 
    /**
148
 
     * Put a call on hold 
149
 
     * @param id The ID of the call
150
 
     * @return bool true on success
151
 
     *            false otherwise
152
 
     */
153
 
    bool onhold(const CallID& id);
154
 
    
155
 
    /**
156
 
     * Put a call off hold
157
 
     * @param id The ID of the call
158
 
     * @return bool true on success
159
 
     *            false otherwise
160
 
     */
161
 
    bool offhold(const CallID& id);
162
 
    
163
 
    /**
164
 
     * Transfer a call 
165
 
     * @param id The ID of the call
166
 
     * @param to The recipient of the transfer
167
 
     * @return bool true on success
168
 
     *            false otherwise
169
 
     */
170
 
    bool transfer(const CallID& id, const std::string& to);
171
 
    
172
 
    /**
173
 
     * Refuse a call 
174
 
     * @param id The ID of the call
175
 
     * @return bool true on success
176
 
     *            false otherwise
177
 
     */
178
 
    bool refuse (const CallID& id);
179
 
 
180
 
    /**
181
 
     * Send DTMF  
182
 
     * @param id The ID of the call
183
 
     * @param code  The code of the DTMF
184
 
     * @return bool true on success
185
 
     *            false otherwise
186
 
     */
187
 
    bool carryingDTMFdigits(const CallID& id, char code);
188
 
    
189
 
    bool sendMessage(const std::string& to UNUSED, const std::string& body UNUSED) { return false; }
190
 
    
191
 
    bool isContactPresenceSupported() { return false; }
192
 
 
193
 
    /**
194
 
     * Return the codec protocol used for this call 
195
 
     * @param id The call identifier
196
 
     */
197
 
    std::string getCurrentCodecName();
198
 
 
199
 
 
200
 
  public: // iaxvoiplink only
201
 
   
202
 
    void updateAudiolayer( void ); 
203
 
 
204
 
  private:
205
 
 
206
 
    /* 
207
 
     * Decode the message count IAX send.
208
 
     * Returns only the new messages number
209
 
     * 
210
 
     * @param msgcount  The value sent by IAX in the REGACK message
211
 
     * @return int  The number of new messages waiting for the current registered user
212
 
     */
213
 
     int processIAXMsgCount( int msgcount );
214
 
 
215
 
 
216
 
    /**
217
 
     * Get IAX Call from an id
218
 
     * @param id CallId
219
 
     * @return IAXCall pointer or 0
220
 
     */
221
 
    IAXCall* getIAXCall(const CallID& id);
222
 
 
223
 
    /**
224
 
     * Delete every call 
225
 
     */
226
 
    void terminateIAXCall();
227
 
 
228
 
    /**
229
 
     * Find a iaxcall by iax session number
230
 
     * @param session an iax_session valid pointer
231
 
     * @return iaxcall or 0 if not found
232
 
     */
233
 
    IAXCall* iaxFindCallBySession(struct iax_session* session);
234
 
 
235
 
    /**
236
 
     * Handle IAX Event for a call
237
 
     * @param event An iax_event pointer
238
 
     * @param call  An IAXCall pointer 
239
 
     */
240
 
    void iaxHandleCallEvent(iax_event* event, IAXCall* call);
241
 
 
242
 
    /**
243
 
     * Handle the VOICE events specifically
244
 
     * @param event The iax_event containing the IAX_EVENT_VOICE
245
 
     * @param call  The associated IAXCall
246
 
     */
247
 
    void iaxHandleVoiceEvent(iax_event* event, IAXCall* call);
248
 
 
249
 
    /**
250
 
     * Handle IAX Registration Reply event
251
 
     * @param event An iax_event pointer
252
 
     */
253
 
    void iaxHandleRegReply(iax_event* event);
254
 
 
255
 
    /**
256
 
     * Handle IAX pre-call setup-related events
257
 
     * @param event An iax_event pointer
258
 
     */
259
 
    void iaxHandlePrecallEvent(iax_event* event);
260
 
 
261
 
    /**
262
 
     * Work out the audio data from Microphone to IAX2 channel
263
 
     */
264
 
    void sendAudioFromMic(void);
265
 
 
266
 
    /**
267
 
     * Send an outgoing call invite to iax
268
 
     * @param call An IAXCall pointer
269
 
     */
270
 
    bool iaxOutgoingInvite(IAXCall* call);
271
 
 
272
 
    /** Threading object */
273
 
    EventThread* _evThread;
274
 
 
275
 
    /** registration session : 0 if not register */
276
 
    struct iax_session* _regSession;
277
 
 
278
 
    /** Timestamp of when we should refresh the registration up with
279
 
     * the registrar.  Values can be: EPOCH timestamp, 0 if we want no registration, 1
280
 
     * to force a registration. */
281
 
    int _nextRefreshStamp;
282
 
 
283
 
    /** Mutex for iax_ calls, since we're the only one dealing with the incorporated
284
 
     * iax_stuff inside this class. */
285
 
    ost::Mutex _mutexIAX;
286
 
 
287
 
    /** Connection to audio card/device */
288
 
    AudioLayer* audiolayer;
289
 
 
290
 
    /** Mic-data related buffers */
291
 
    SFLDataFormat* micData;
292
 
    SFLDataFormat* micDataConverted;
293
 
    unsigned char* micDataEncoded;
294
 
 
295
 
    /** Speaker-data related buffers */
296
 
    SFLDataFormat* spkrDataDecoded;
297
 
    SFLDataFormat* spkrDataConverted;
298
 
 
299
 
    /** Sample rate converter object */
300
 
    SamplerateConverter* converter;
301
 
 
302
 
    int converterSamplingRate;
303
 
    
304
 
    /** number of sample */
305
 
    int nbSample_;
306
 
     
307
 
    /** number of sample before conversion (recording) */
308
 
    int nbSampleForRec_;
309
 
 
310
 
    /* URL hook */
311
 
    UrlHook *urlhook;
312
 
 
313
 
    /** Counter for IncomingCallNotification */
314
 
    int countTime;
 
59
    public:
 
60
 
 
61
        /**
 
62
         * Constructor
 
63
         * @param accountID     The account containing the voip link
 
64
         */
 
65
        IAXVoIPLink (const AccountID& accountID);
 
66
 
 
67
        /**
 
68
         * Destructor
 
69
         */
 
70
        ~IAXVoIPLink();
 
71
 
 
72
        /**
 
73
         *      Listen to events sent by the call manager ( asterisk, etc .. )
 
74
         */
 
75
        void getEvent (void);
 
76
 
 
77
        /**
 
78
         * Init the voip link
 
79
         * @return true if successful
 
80
         *            false otherwise
 
81
         */
 
82
        bool init (void);
 
83
 
 
84
        /**
 
85
         * Terminate a voip link by clearing the call list
 
86
         */
 
87
        void terminate (void);
 
88
 
 
89
        /**
 
90
         * Terminate on call
 
91
         */
 
92
        void terminateOneCall (const CallID& id);
 
93
 
 
94
        /**
 
95
         * Send out registration
 
96
         * @return bool The new registration state (are we registered ?)
 
97
         */
 
98
        int sendRegister (AccountID id);
 
99
 
 
100
        /**
 
101
         * Destroy registration session
 
102
         * @todo Send an IAX_COMMAND_REGREL to force unregistration upstream.
 
103
         *       Urgency: low
 
104
         * @return bool true if we're registered upstream
 
105
         *                false otherwise
 
106
         */
 
107
        int sendUnregister (AccountID id);
 
108
 
 
109
        /**
 
110
         * Create a new outgoing call
 
111
         * @param id  The ID of the call
 
112
         * @param toUrl The address to call
 
113
         * @return Call*  A pointer on the call
 
114
         */
 
115
        Call* newOutgoingCall (const CallID& id, const std::string& toUrl);
 
116
 
 
117
        /**
 
118
         * Answer a call
 
119
         * @param id The ID of the call
 
120
         * @return bool true on success
 
121
         *                false otherwise
 
122
         */
 
123
        bool answer (const CallID& id);
 
124
 
 
125
        /**
 
126
         * Hangup a call
 
127
         * @param id The ID of the call
 
128
         * @return bool true on success
 
129
         *                false otherwise
 
130
         */
 
131
        bool hangup (const CallID& id);
 
132
 
 
133
        /**
 
134
         * Peer Hungup a call
 
135
         * @param id The ID of the call
 
136
         * @return bool true on success
 
137
         *                false otherwise
 
138
         */
 
139
        bool peerHungup (const CallID& id);
 
140
 
 
141
        /**
 
142
         * Cancel a call
 
143
         * @param id The ID of the call
 
144
         * @return bool true on success
 
145
         *                false otherwise
 
146
         */
 
147
        bool cancel (const CallID& id UNUSED) {
 
148
            return false;
 
149
        }
 
150
 
 
151
        /**
 
152
         * Put a call on hold
 
153
         * @param id The ID of the call
 
154
         * @return bool true on success
 
155
         *                false otherwise
 
156
         */
 
157
        bool onhold (const CallID& id);
 
158
 
 
159
        /**
 
160
         * Put a call off hold
 
161
         * @param id The ID of the call
 
162
         * @return bool true on success
 
163
         *                false otherwise
 
164
         */
 
165
        bool offhold (const CallID& id);
 
166
 
 
167
        /**
 
168
         * Transfer a call
 
169
         * @param id The ID of the call
 
170
         * @param to The recipient of the transfer
 
171
         * @return bool true on success
 
172
         *                false otherwise
 
173
         */
 
174
        bool transfer (const CallID& id, const std::string& to);
 
175
 
 
176
        /**
 
177
         * Refuse a call
 
178
         * @param id The ID of the call
 
179
         * @return bool true on success
 
180
         *                false otherwise
 
181
         */
 
182
        bool refuse (const CallID& id);
 
183
 
 
184
        /**
 
185
         * Send DTMF
 
186
         * @param id The ID of the call
 
187
         * @param code  The code of the DTMF
 
188
         * @return bool true on success
 
189
         *                false otherwise
 
190
         */
 
191
        bool carryingDTMFdigits (const CallID& id, char code);
 
192
 
 
193
 
 
194
        bool sendTextMessage (sfl::InstantMessaging *module, const std::string& callID, const std::string& message, const std::string& from);
 
195
 
 
196
        bool isContactPresenceSupported() {
 
197
            return false;
 
198
        }
 
199
 
 
200
        /**
 
201
         * Return the codec protocol used for this call
 
202
         * @param id The call identifier
 
203
         */
 
204
        std::string getCurrentCodecName();
 
205
 
 
206
 
 
207
    public: // iaxvoiplink only
 
208
 
 
209
        void updateAudiolayer (void);
 
210
 
 
211
    private:
 
212
 
 
213
        /*
 
214
         * Decode the message count IAX send.
 
215
         * Returns only the new messages number
 
216
         *
 
217
         * @param msgcount  The value sent by IAX in the REGACK message
 
218
         * @return int  The number of new messages waiting for the current registered user
 
219
         */
 
220
        int processIAXMsgCount (int msgcount);
 
221
 
 
222
 
 
223
        /**
 
224
         * Get IAX Call from an id
 
225
         * @param id CallId
 
226
         * @return IAXCall pointer or 0
 
227
         */
 
228
        IAXCall* getIAXCall (const CallID& id);
 
229
 
 
230
        /**
 
231
         * Delete every call
 
232
         */
 
233
        void terminateIAXCall();
 
234
 
 
235
        /**
 
236
         * Find a iaxcall by iax session number
 
237
         * @param session an iax_session valid pointer
 
238
         * @return iaxcall or 0 if not found
 
239
         */
 
240
        IAXCall* iaxFindCallBySession (struct iax_session* session);
 
241
 
 
242
        /**
 
243
         * Handle IAX Event for a call
 
244
         * @param event An iax_event pointer
 
245
         * @param call  An IAXCall pointer
 
246
         */
 
247
        void iaxHandleCallEvent (iax_event* event, IAXCall* call);
 
248
 
 
249
        /**
 
250
         * Handle the VOICE events specifically
 
251
         * @param event The iax_event containing the IAX_EVENT_VOICE
 
252
         * @param call  The associated IAXCall
 
253
         */
 
254
        void iaxHandleVoiceEvent (iax_event* event, IAXCall* call);
 
255
 
 
256
        /**
 
257
         * Handle IAX Registration Reply event
 
258
         * @param event An iax_event pointer
 
259
         */
 
260
        void iaxHandleRegReply (iax_event* event);
 
261
 
 
262
        /**
 
263
         * Handle IAX pre-call setup-related events
 
264
         * @param event An iax_event pointer
 
265
         */
 
266
        void iaxHandlePrecallEvent (iax_event* event);
 
267
 
 
268
        /**
 
269
         * Work out the audio data from Microphone to IAX2 channel
 
270
         */
 
271
        void sendAudioFromMic (void);
 
272
 
 
273
        /**
 
274
         * Send an outgoing call invite to iax
 
275
         * @param call An IAXCall pointer
 
276
         */
 
277
        bool iaxOutgoingInvite (IAXCall* call);
 
278
 
 
279
        /** Threading object */
 
280
        EventThread* _evThread;
 
281
 
 
282
        /** registration session : 0 if not register */
 
283
        struct iax_session* _regSession;
 
284
 
 
285
        /** Timestamp of when we should refresh the registration up with
 
286
         * the registrar.  Values can be: EPOCH timestamp, 0 if we want no registration, 1
 
287
         * to force a registration. */
 
288
        int _nextRefreshStamp;
 
289
 
 
290
        /** Mutex for iax_ calls, since we're the only one dealing with the incorporated
 
291
         * iax_stuff inside this class. */
 
292
        ost::Mutex _mutexIAX;
 
293
 
 
294
        /** Connection to audio card/device */
 
295
        AudioLayer* audiolayer;
 
296
 
 
297
        /** Mic-data related buffers */
 
298
        SFLDataFormat* micData;
 
299
        SFLDataFormat* micDataConverted;
 
300
        unsigned char* micDataEncoded;
 
301
 
 
302
        /** Speaker-data related buffers */
 
303
        SFLDataFormat* spkrDataDecoded;
 
304
        SFLDataFormat* spkrDataConverted;
 
305
 
 
306
        /** Sample rate converter object */
 
307
        SamplerateConverter* converter;
 
308
 
 
309
        int converterSamplingRate;
 
310
 
 
311
        /** number of sample */
 
312
        int nbSample_;
 
313
 
 
314
        /** number of sample before conversion (recording) */
 
315
        int nbSampleForRec_;
 
316
 
 
317
        /* URL hook */
 
318
        UrlHook *urlhook;
 
319
 
 
320
        /** Counter for IncomingCallNotification */
 
321
        int countTime;
315
322
};
316
323
 
317
324
#endif