iaxvoiplink.h 5.79 KB
Newer Older
yanmorin's avatar
 
yanmorin committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
 *  Copyright (C) 2006 Savoir-Faire Linux inc.
 *  Author: Yan Morin <yan.morin@savoirfairelinux.com>
 *                                                                              
 *  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.
 *                                                                                
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *                                                                              
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
#ifndef IAXVOIPLINK_H
#define IAXVOIPLINK_H

22
#include "voiplink.h"
23
#include <iax/iax-client.h>
24
#include "global.h"
25
#include <samplerate.h>
yanmorin's avatar
 
yanmorin committed
26

27

28
29
class EventThread;
class IAXCall;
yanmorin's avatar
 
yanmorin committed
30

31
32
33
34
class AudioCodec;
class AudioLayer;

 
yanmorin's avatar
 
yanmorin committed
35
/**
yanmorin's avatar
   
yanmorin committed
36
37
38
39
 * VoIPLink contains a thread that listen to external events 
 * and contains IAX Call related functions
 * @author Yan Morin <yan.morin@gmail.com>
 */
yanmorin's avatar
 
yanmorin committed
40
41
42
43
44
45
46
class IAXVoIPLink : public VoIPLink
{
public:
    IAXVoIPLink(const AccountID& accountID);

    ~IAXVoIPLink();

47
  void getEvent(void);
yanmorin's avatar
   
yanmorin committed
48
  bool init (void);
yanmorin's avatar
 
yanmorin committed
49
  bool checkNetwork (void) { return false; }
yanmorin's avatar
   
yanmorin committed
50
  void terminate (void);
yanmorin's avatar
 
yanmorin committed
51

52
53
54
55
56
  /**
   * Send out registration
   *
   * @return The new registration state (are we registered ?)
   */
57
  bool setRegister (void);
58
59
60
61
62
63
64
65
66

  /**
   * Destroy registration session
   *
   * @todo Send an IAX_COMMAND_REGREL to force unregistration upstream.
   *       Urgency: low
   *
   * @return bool If we're registered upstream
   */
67
  bool setUnregister (void);
yanmorin's avatar
 
yanmorin committed
68

69
  Call* newOutgoingCall(const CallID& id, const std::string& toUrl);
70
  bool answer(const CallID& id);
yanmorin's avatar
 
yanmorin committed
71

yanmorin's avatar
yanmorin committed
72
  bool hangup(const CallID& id);
yanmorin's avatar
 
yanmorin committed
73
  bool cancel(const CallID& id) { return false; }
74
75
  bool onhold(const CallID& id);
  bool offhold(const CallID& id);
76
77
78
  bool transfer(const CallID& id, const std::string& to);
  bool refuse (const CallID& id);
  bool carryingDTMFdigits(const CallID& id, char code);
yanmorin's avatar
 
yanmorin committed
79
  bool sendMessage(const std::string& to, const std::string& body) { return false; }
80

yanmorin's avatar
yanmorin committed
81
82
83
84
85
public: // iaxvoiplink only
  void setHost(const std::string& host) { _host = host; }
  void setUser(const std::string& user) { _user = user; }
  void setPass(const std::string& pass) { _pass = pass; }

86
87
private:
  /**
yanmorin's avatar
yanmorin committed
88
89
90
91
92
93
   * Get IAX Call from an id
   * @param id CallId
   * @return IAXCall pointer or 0
   */
  IAXCall* getIAXCall(const CallID& id);

94
95
96
97
98
99
  /**
   * Delete every call 
   */
  void terminateIAXCall();

  /**
100
101
102
103
   * Find a iaxcall by iax session number
   * @param session an iax_session valid pointer
   * @return iaxcall or 0 if not found
   */
yanmorin's avatar
yanmorin committed
104
  IAXCall* iaxFindCallBySession(struct iax_session* session);
105
106
107
108
109
110
111
112

  /**
   * Handle IAX Event for a call
   * @param event An iax_event pointer
   * @param call  An IAXCall pointer 
   */
  void iaxHandleCallEvent(iax_event* event, IAXCall* call);

113
114
115
116
117
118
119
  /**
   * Handle the VOICE events specifically
   * @param event The iax_event containing the IAX_EVENT_VOICE
   * @param call  The associated IAXCall
   */
  void iaxHandleVoiceEvent(iax_event* event, IAXCall* call);

yanmorin's avatar
yanmorin committed
120
121
122
123
124
  /**
   * Handle IAX Registration Reply event
   * @param event An iax_event pointer
   */
  void iaxHandleRegReply(iax_event* event);
125

126
127
128
129
130
131
  /**
   * Handle IAX pre-call setup-related events
   * @param event An iax_event pointer
   */
  void iaxHandlePrecallEvent(iax_event* event);

132
133
134
135
136
  /**
   * Work out the audio data from Microphone to IAX2 channel
   */
  void sendAudioFromMic(void);

137
138
  /**
   * Send an outgoing call invite to iax
139
140
141
142
143
144
145
146
   * @param call An IAXCall pointer
   */
  bool iaxOutgoingInvite(IAXCall* call);


  /**
   * Convert CodecMap to IAX format using IAX constants
   * @return `format` ready to go into iax_* calls
147
   */
148
  int iaxCodecMapToFormat(IAXCall* call);
149

150
  /** Threading object */
151
  EventThread* _evThread;
152

yanmorin's avatar
yanmorin committed
153
  /** registration session : 0 if not register */
yanmorin's avatar
yanmorin committed
154
  struct iax_session* _regSession;
yanmorin's avatar
yanmorin committed
155
156
157

  /** IAX Host */
  std::string _host;
158

yanmorin's avatar
yanmorin committed
159
160
  /** IAX User */
  std::string _user;
161

yanmorin's avatar
yanmorin committed
162
163
  /** IAX Password */
  std::string _pass;
164

165
166
167
  /** IAX full name */
  std::string _fullName;

168
169
170
171
172
173
174
  /** Timestamp of when we should refresh the registration up with
   * the registrar.  Values can be: EPOCH timestamp, 0 if we want no registration, 1
   * to force a registration. */
  int _nextRefreshStamp;

  /** Mutex for iax_ calls, since we're the only one dealing with the incorporated
   * iax_stuff inside this class. */
175
  ost::Mutex _mutexIAX;
176

177
  /** Connection to audio card/device */
178
  AudioLayer* audiolayer;
179
180
181
182
183
184

  /** When we receive data, we decode it inside this buffer */
  int16* _receiveDataDecoded;
  /** When we send data, we encode it inside this buffer*/
  unsigned char* _sendDataEncoded;

185
186
  /** After that we send the data inside this buffer if there is a format conversion or rate conversion. */
  /* Also use for getting mic-ringbuffer data */
187
188
189
190
191
192
193
194
195
  SFLDataFormat* _dataAudioLayer;

  /** Buffer for 8000hz samples in conversion */
  float32* _floatBuffer8000;
  /** Buffer for 48000hz samples in conversion */ 
  float32* _floatBuffer48000;

  /** Buffer for 8000hz samples for mic conversion */
  int16* _intBuffer8000;
yanmorin's avatar
yanmorin committed
196

197
198
199
200
201
202
203
204
205
  /** libsamplerate converter for incoming voice */
  SRC_STATE*    _src_state_spkr;

  /** libsamplerate converter for outgoing voice */
  SRC_STATE*    _src_state_mic;

  /** libsamplerate error */
  int           _src_err;

yanmorin's avatar
yanmorin committed
206
  /** Current IAX call pointer, used for sending, change when starting audio, switching */
207
  //IAXCall* _currentCall; 
yanmorin's avatar
 
yanmorin committed
208
209
210
};

#endif